akregator/src

mainwindow.cpp
1/*
2 This file is part of Akregator.
3
4 Copyright (C) 2004 Stanislav Karchebny <Stanislav.Karchebny@kdemail.net>
5
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
10
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
15
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
19
20 As a special exception, permission is given to link this program
21 with any edition of TQt, and distribute the resulting executable,
22 without including the source code for TQt in the source distribution.
23*/
24
25#include "mainwindow.h"
26#include "akregator_part.h"
27#include "akregatorconfig.h"
28
29//settings
30
31#include <dcopclient.h>
32
33#include <tdeaction.h>
34#include <tdeapplication.h>
35#include <tdeconfig.h>
36#include <kdebug.h>
37#include <kedittoolbar.h>
38#include <tdefiledialog.h>
39#include <tdeglobal.h>
40#include <kkeydialog.h>
41#include <klibloader.h>
42#include <tdelocale.h>
43#include <tdemessagebox.h>
44#include <tdeparts/partmanager.h>
45#include <ksqueezedtextlabel.h>
46#include <tdestandarddirs.h>
47#include <kstatusbar.h>
48#include <kstdaction.h>
49#include <kurl.h>
50
51#include "progressdialog.h"
52#include "statusbarprogresswidget.h"
53#include "trayicon.h"
54
55#include <tqmetaobject.h>
56#include <tqpen.h>
57#include <tqpainter.h>
58#include <private/tqucomextra_p.h>
59#include <tqtimer.h>
60
61
62namespace Akregator {
63
64BrowserInterface::BrowserInterface( MainWindow *shell, const char *name )
65 : KParts::BrowserInterface( shell, name )
66{
67 m_shell = shell;
68}
69
70MainWindow::MainWindow()
71 : KParts::MainWindow( 0L, "akregator_mainwindow" ){
72 // set the shell's ui resource file
73 setXMLFile("akregator_shell.rc");
74
75 m_browserIface=new BrowserInterface(this, "browser_interface");
76
77 m_part=0;
78
79 // then, setup our actions
80
81 toolBar()->show();
82 // and a status bar
83 statusBar()->show();
84
85 int statH=fontMetrics().height()+2;
86 m_statusLabel = new KSqueezedTextLabel(this);
87 m_statusLabel->setTextFormat(TQt::RichText);
88 m_statusLabel->setSizePolicy(TQSizePolicy( TQSizePolicy::Ignored, TQSizePolicy::Fixed ));
89 m_statusLabel->setMinimumWidth( 0 );
90 m_statusLabel->setFixedHeight( statH );
91 statusBar()->addWidget (m_statusLabel, 1, false);
92
93 setupActions();
94 createGUI(0L);
95}
96
97bool MainWindow::loadPart()
98{
99 // this routine will find and load our Part. it finds the Part by
100 // name which is a bad idea usually.. but it's alright in this
101 // case since our Part is made for this Shell
102 KLibFactory *factory = KLibLoader::self()->factory("libakregatorpart");
103 if (factory)
104 {
105 // now that the Part is loaded, we cast it to a Part to get
106 // our hands on it
107 m_part = static_cast<Akregator::Part*>(factory->create(this, "akregator_part", "KParts::ReadOnlyPart" ));
108
109 if (m_part)
110 {
111 // tell the KParts::MainWindow that this is indeed the main widget
112 setCentralWidget(m_part->widget());
113
114 connect(m_part, TQ_SIGNAL(setWindowCaption (const TQString &)), this, TQ_SLOT(setCaption (const TQString &)));
115
116 connect(TrayIcon::getInstance(), TQ_SIGNAL(quitSelected()), this, TQ_SLOT(slotQuit()));
117 // and integrate the part's GUI with the shell's
118 connectActionCollection(m_part->actionCollection());
119 createGUI(m_part);
120 browserExtension(m_part)->setBrowserInterface(m_browserIface);
121 setAutoSaveSettings();
122 return true;
123 }
124 return false;
125 }
126 else
127 {
128 KMessageBox::error(this, i18n("Could not find the Akregator part; please check your installation."));
129 return false;
130 }
131
132}
133
134void MainWindow::setupProgressWidgets()
135{
136 KPIM::ProgressDialog *progressDialog = new KPIM::ProgressDialog( statusBar(), this );
137 progressDialog->raise();
138 progressDialog->hide();
139 m_progressBar = new KPIM::StatusbarProgressWidget( progressDialog, statusBar() );
140 m_progressBar->show();
141 statusBar()->addWidget( m_progressBar, 0, true );
142}
143
144MainWindow::~MainWindow()
145{
146}
147
148void MainWindow::setCaption(const TQString &a)
149{
150 KParts::MainWindow::setCaption(a);
151}
152
153void MainWindow::setupActions()
154{
155 connectActionCollection(actionCollection());
156
157 KStdAction::quit(tdeApp, TQ_SLOT(quit()), actionCollection());
158
159 setStandardToolBarMenuEnabled(true);
160 createStandardStatusBarAction();
161
162 KStdAction::keyBindings(this, TQ_SLOT(optionsConfigureKeys()), actionCollection());
163 KStdAction::configureToolbars(this, TQ_SLOT(optionsConfigureToolbars()), actionCollection());
164}
165
166void MainWindow::saveProperties(TDEConfig* config)
167{
168 if (!m_part)
169 loadPart();
170
171 static_cast<Akregator::Part*>(m_part)->saveProperties(config);
172 config->writeEntry("docked", isHidden());
173
174 //delete m_part;
175}
176
177void MainWindow::readProperties(TDEConfig* config)
178{
179 if (!m_part)
180 loadPart();
181 static_cast<Akregator::Part*>(m_part)->readProperties(config);
182
183 if (Settings::showTrayIcon() && config->readBoolEntry("docked", false))
184 hide();
185 else
186 show();
187}
188
189void MainWindow::optionsConfigureKeys()
190{
191 KKeyDialog dlg( true, this );
192
193 dlg.insert(actionCollection());
194 if (m_part)
195 dlg.insert(m_part->actionCollection());
196
197 dlg.configure();
198}
199
200void MainWindow::optionsConfigureToolbars()
201{
202 saveMainWindowSettings(TDEGlobal::config(), autoSaveGroup());
203
204 // use the standard toolbar editor
205 KEditToolbar dlg(factory());
206 connect(&dlg, TQ_SIGNAL(newToolbarConfig()),
207 this, TQ_SLOT(applyNewToolbarConfig()));
208 dlg.exec();
209}
210
211
212
213void MainWindow::applyNewToolbarConfig()
214{
215 applyMainWindowSettings(TDEGlobal::config(), autoSaveGroup());
216}
217
218
219KParts::BrowserExtension *MainWindow::browserExtension(KParts::ReadOnlyPart *p)
220{
221 return KParts::BrowserExtension::childObject( p );
222}
223
224
225// from konqmainwindow
226void MainWindow::connectActionCollection( TDEActionCollection *coll )
227{
228 if (!coll) return;
229 connect( coll, TQ_SIGNAL( actionStatusText( const TQString & ) ),
230 m_statusLabel, TQ_SLOT( setText( const TQString & ) ) );
231 connect( coll, TQ_SIGNAL( clearStatusText() ),
232 this, TQ_SLOT( slotClearStatusText() ) );
233}
234
235bool MainWindow::queryExit()
236{
237 kdDebug() << "MainWindow::queryExit()" << endl;
238 if ( !tdeApp->sessionSaving() )
239 {
240 delete m_part; // delete that here instead of dtor to ensure nested tdehtmlparts are deleted before singleton objects like TDEHTMLPageCache
241 m_part = 0;
242 }
243 else
244 kdDebug("MainWindow::queryExit(): saving session");
245
246 return TDEMainWindow::queryExit();
247}
248
249void MainWindow::slotQuit()
250{
251 if (TrayIcon::getInstance())
252 TrayIcon::getInstance()->hide();
253 tdeApp->quit();
254}
255
256bool MainWindow::queryClose()
257{
258 if (tdeApp->sessionSaving() || TrayIcon::getInstance() == 0 || TrayIcon::getInstance()->isHidden() )
259 {
260 return true;
261 }
262 else
263 {
264 TQPixmap shot = TrayIcon::getInstance()->takeScreenshot();
265
266 // Associate source to image and show the dialog:
267 TQMimeSourceFactory::defaultFactory()->setPixmap("systray_shot", shot);
268 KMessageBox::information(this, i18n( "<qt><p>Closing the main window will keep Akregator running in the system tray. Use 'Quit' from the 'File' menu to quit the application.</p><p><center><img source=\"systray_shot\"></center></p></qt>" ), i18n( "Docking in System Tray" ), "hideOnCloseInfo");
269 hide();
270 return false;
271 }
272}
273
274
275void MainWindow::slotClearStatusText()
276{
277 m_statusLabel->setText(TQString());
278}
279
280void MainWindow::slotSetStatusBarText( const TQString & text )
281{
282 m_statusLabel->setText(text);
283}
284
285} // namespace Akregator
286
287#include "mainwindow.moc"
This is a RSS Aggregator "Part".