00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025 #include "mainwindow.h"
00026 #include "akregator_part.h"
00027 #include "akregatorconfig.h"
00028
00029
00030
00031 #include <dcopclient.h>
00032
00033 #include <kaction.h>
00034 #include <kapplication.h>
00035 #include <kconfig.h>
00036 #include <kdebug.h>
00037 #include <kedittoolbar.h>
00038 #include <kfiledialog.h>
00039 #include <kglobal.h>
00040 #include <kkeydialog.h>
00041 #include <klibloader.h>
00042 #include <klocale.h>
00043 #include <kmessagebox.h>
00044 #include <kparts/partmanager.h>
00045 #include <ksqueezedtextlabel.h>
00046 #include <kstandarddirs.h>
00047 #include <kstatusbar.h>
00048 #include <kstdaction.h>
00049 #include <kurl.h>
00050
00051 #include "progressdialog.h"
00052 #include "statusbarprogresswidget.h"
00053 #include "trayicon.h"
00054
00055 #include <qmetaobject.h>
00056 #include <qpen.h>
00057 #include <qpainter.h>
00058 #include <private/qucomextra_p.h>
00059 #include <qtimer.h>
00060
00061
00062 namespace Akregator {
00063
00064 BrowserInterface::BrowserInterface( MainWindow *shell, const char *name )
00065 : KParts::BrowserInterface( shell, name )
00066 {
00067 m_shell = shell;
00068 }
00069
00070 MainWindow::MainWindow()
00071 : KParts::MainWindow( 0L, "akregator_mainwindow" ){
00072
00073 setXMLFile("akregator_shell.rc");
00074
00075 m_browserIface=new BrowserInterface(this, "browser_interface");
00076
00077 m_part=0;
00078
00079
00080
00081 toolBar()->show();
00082
00083 statusBar()->show();
00084
00085 int statH=fontMetrics().height()+2;
00086 m_statusLabel = new KSqueezedTextLabel(this);
00087 m_statusLabel->setTextFormat(Qt::RichText);
00088 m_statusLabel->setSizePolicy(QSizePolicy( QSizePolicy::Ignored, QSizePolicy::Fixed ));
00089 m_statusLabel->setMinimumWidth( 0 );
00090 m_statusLabel->setFixedHeight( statH );
00091 statusBar()->addWidget (m_statusLabel, 1, false);
00092
00093 setupActions();
00094 createGUI(0L);
00095 }
00096
00097 bool MainWindow::loadPart()
00098 {
00099
00100
00101
00102 KLibFactory *factory = KLibLoader::self()->factory("libakregatorpart");
00103 if (factory)
00104 {
00105
00106
00107 m_part = static_cast<Akregator::Part*>(factory->create(this, "akregator_part", "KParts::ReadOnlyPart" ));
00108
00109 if (m_part)
00110 {
00111
00112 setCentralWidget(m_part->widget());
00113
00114 connect(m_part, SIGNAL(setWindowCaption (const QString &)), this, SLOT(setCaption (const QString &)));
00115
00116 connect(TrayIcon::getInstance(), SIGNAL(quitSelected()), this, SLOT(slotQuit()));
00117
00118 connectActionCollection(m_part->actionCollection());
00119 createGUI(m_part);
00120 browserExtension(m_part)->setBrowserInterface(m_browserIface);
00121 setAutoSaveSettings();
00122 return true;
00123 }
00124 return false;
00125 }
00126 else
00127 {
00128 KMessageBox::error(this, i18n("Could not find the Akregator part; please check your installation."));
00129 return false;
00130 }
00131
00132 }
00133
00134 void MainWindow::setupProgressWidgets()
00135 {
00136 KPIM::ProgressDialog *progressDialog = new KPIM::ProgressDialog( statusBar(), this );
00137 progressDialog->raise();
00138 progressDialog->hide();
00139 m_progressBar = new KPIM::StatusbarProgressWidget( progressDialog, statusBar() );
00140 m_progressBar->show();
00141 statusBar()->addWidget( m_progressBar, 0, true );
00142 }
00143
00144 MainWindow::~MainWindow()
00145 {
00146 }
00147
00148 void MainWindow::setCaption(const QString &a)
00149 {
00150 KParts::MainWindow::setCaption(a);
00151 }
00152
00153 void MainWindow::setupActions()
00154 {
00155 connectActionCollection(actionCollection());
00156
00157 KStdAction::quit(kapp, SLOT(quit()), actionCollection());
00158
00159 setStandardToolBarMenuEnabled(true);
00160 createStandardStatusBarAction();
00161
00162 KStdAction::keyBindings(this, SLOT(optionsConfigureKeys()), actionCollection());
00163 KStdAction::configureToolbars(this, SLOT(optionsConfigureToolbars()), actionCollection());
00164 }
00165
00166 void MainWindow::saveProperties(KConfig* config)
00167 {
00168 if (!m_part)
00169 loadPart();
00170
00171 static_cast<Akregator::Part*>(m_part)->saveProperties(config);
00172 config->writeEntry("docked", isHidden());
00173
00174
00175 }
00176
00177 void MainWindow::readProperties(KConfig* config)
00178 {
00179 if (!m_part)
00180 loadPart();
00181 static_cast<Akregator::Part*>(m_part)->readProperties(config);
00182
00183 if (Settings::showTrayIcon() && config->readBoolEntry("docked", false))
00184 hide();
00185 else
00186 show();
00187 }
00188
00189 void MainWindow::optionsConfigureKeys()
00190 {
00191 KKeyDialog dlg( true, this );
00192
00193 dlg.insert(actionCollection());
00194 if (m_part)
00195 dlg.insert(m_part->actionCollection());
00196
00197 dlg.configure();
00198 }
00199
00200 void MainWindow::optionsConfigureToolbars()
00201 {
00202 saveMainWindowSettings(KGlobal::config(), autoSaveGroup());
00203
00204
00205 KEditToolbar dlg(factory());
00206 connect(&dlg, SIGNAL(newToolbarConfig()),
00207 this, SLOT(applyNewToolbarConfig()));
00208 dlg.exec();
00209 }
00210
00211
00212
00213 void MainWindow::applyNewToolbarConfig()
00214 {
00215 applyMainWindowSettings(KGlobal::config(), autoSaveGroup());
00216 }
00217
00218
00219 KParts::BrowserExtension *MainWindow::browserExtension(KParts::ReadOnlyPart *p)
00220 {
00221 return KParts::BrowserExtension::childObject( p );
00222 }
00223
00224
00225
00226 void MainWindow::connectActionCollection( KActionCollection *coll )
00227 {
00228 if (!coll) return;
00229 connect( coll, SIGNAL( actionStatusText( const QString & ) ),
00230 m_statusLabel, SLOT( setText( const QString & ) ) );
00231 connect( coll, SIGNAL( clearStatusText() ),
00232 this, SLOT( slotClearStatusText() ) );
00233 }
00234
00235 bool MainWindow::queryExit()
00236 {
00237 kdDebug() << "MainWindow::queryExit()" << endl;
00238 if ( !kapp->sessionSaving() )
00239 {
00240 delete m_part;
00241 m_part = 0;
00242 }
00243 else
00244 kdDebug("MainWindow::queryExit(): saving session");
00245
00246 return KMainWindow::queryExit();
00247 }
00248
00249 void MainWindow::slotQuit()
00250 {
00251 if (TrayIcon::getInstance())
00252 TrayIcon::getInstance()->hide();
00253 kapp->quit();
00254 }
00255
00256 bool MainWindow::queryClose()
00257 {
00258 if (kapp->sessionSaving() || TrayIcon::getInstance() == 0 || TrayIcon::getInstance()->isHidden() )
00259 {
00260 return true;
00261 }
00262 else
00263 {
00264 QPixmap shot = TrayIcon::getInstance()->takeScreenshot();
00265
00266
00267 QMimeSourceFactory::defaultFactory()->setPixmap("systray_shot", shot);
00268 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");
00269 hide();
00270 return false;
00271 }
00272 }
00273
00274
00275 void MainWindow::slotClearStatusText()
00276 {
00277 m_statusLabel->setText(QString());
00278 }
00279
00280 void MainWindow::slotSetStatusBarText( const QString & text )
00281 {
00282 m_statusLabel->setText(text);
00283 }
00284
00285 }
00286
00287 #include "mainwindow.moc"
00288
00289
00290