mainwindow.cpp
00001 /* 00002 This file is part of Akregator. 00003 00004 Copyright (C) 2004 Stanislav Karchebny <Stanislav.Karchebny@kdemail.net> 00005 00006 This program is free software; you can redistribute it and/or modify 00007 it under the terms of the GNU General Public License as published by 00008 the Free Software Foundation; either version 2 of the License, or 00009 (at your option) any later version. 00010 00011 This program is distributed in the hope that it will be useful, 00012 but WITHOUT ANY WARRANTY; without even the implied warranty of 00013 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00014 GNU General Public License for more details. 00015 00016 You should have received a copy of the GNU General Public License 00017 along with this program; if not, write to the Free Software 00018 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 00019 00020 As a special exception, permission is given to link this program 00021 with any edition of TQt, and distribute the resulting executable, 00022 without including the source code for TQt in the source distribution. 00023 */ 00024 00025 #include "mainwindow.h" 00026 #include "akregator_part.h" 00027 #include "akregatorconfig.h" 00028 00029 //settings 00030 00031 #include <dcopclient.h> 00032 00033 #include <tdeaction.h> 00034 #include <tdeapplication.h> 00035 #include <tdeconfig.h> 00036 #include <kdebug.h> 00037 #include <kedittoolbar.h> 00038 #include <tdefiledialog.h> 00039 #include <tdeglobal.h> 00040 #include <kkeydialog.h> 00041 #include <klibloader.h> 00042 #include <tdelocale.h> 00043 #include <tdemessagebox.h> 00044 #include <tdeparts/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 <tqmetaobject.h> 00056 #include <tqpen.h> 00057 #include <tqpainter.h> 00058 #include <tqucomextra_p.h> 00059 #include <tqtimer.h> 00060 00061 00062 namespace Akregator { 00063 00064 BrowserInterface::BrowserInterface( MainWindow *shell, const char *name ) 00065 : KParts::BrowserInterface( TQT_TQOBJECT(shell), name ) 00066 { 00067 m_shell = shell; 00068 } 00069 00070 MainWindow::MainWindow() 00071 : KParts::MainWindow( 0L, "akregator_mainwindow" ){ 00072 // set the shell's ui resource file 00073 setXMLFile("akregator_shell.rc"); 00074 00075 m_browserIface=new BrowserInterface(this, "browser_interface"); 00076 00077 m_part=0; 00078 00079 // then, setup our actions 00080 00081 toolBar()->show(); 00082 // and a status bar 00083 statusBar()->show(); 00084 00085 int statH=fontMetrics().height()+2; 00086 m_statusLabel = new KSqueezedTextLabel(this); 00087 m_statusLabel->setTextFormat(TQt::RichText); 00088 m_statusLabel->setSizePolicy(TQSizePolicy( TQSizePolicy::Ignored, TQSizePolicy::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 // this routine will find and load our Part. it finds the Part by 00100 // name which is a bad idea usually.. but it's alright in this 00101 // case since our Part is made for this Shell 00102 KLibFactory *factory = KLibLoader::self()->factory("libakregatorpart"); 00103 if (factory) 00104 { 00105 // now that the Part is loaded, we cast it to a Part to get 00106 // our hands on it 00107 m_part = static_cast<Akregator::Part*>(factory->create(TQT_TQOBJECT(this), "akregator_part", "KParts::ReadOnlyPart" )); 00108 00109 if (m_part) 00110 { 00111 // tell the KParts::MainWindow that this is indeed the main widget 00112 setCentralWidget(m_part->widget()); 00113 00114 connect(m_part, TQT_SIGNAL(setWindowCaption (const TQString &)), this, TQT_SLOT(setCaption (const TQString &))); 00115 00116 connect(TrayIcon::getInstance(), TQT_SIGNAL(quitSelected()), this, TQT_SLOT(slotQuit())); 00117 // and integrate the part's GUI with the shell's 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 TQString &a) 00149 { 00150 KParts::MainWindow::setCaption(a); 00151 } 00152 00153 void MainWindow::setupActions() 00154 { 00155 connectActionCollection(actionCollection()); 00156 00157 KStdAction::quit(TQT_TQOBJECT(kapp), TQT_SLOT(quit()), actionCollection()); 00158 00159 setStandardToolBarMenuEnabled(true); 00160 createStandardStatusBarAction(); 00161 00162 KStdAction::keyBindings(TQT_TQOBJECT(this), TQT_SLOT(optionsConfigureKeys()), actionCollection()); 00163 KStdAction::configureToolbars(TQT_TQOBJECT(this), TQT_SLOT(optionsConfigureToolbars()), actionCollection()); 00164 } 00165 00166 void MainWindow::saveProperties(TDEConfig* 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 //delete m_part; 00175 } 00176 00177 void MainWindow::readProperties(TDEConfig* 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(TDEGlobal::config(), autoSaveGroup()); 00203 00204 // use the standard toolbar editor 00205 KEditToolbar dlg(factory()); 00206 connect(&dlg, TQT_SIGNAL(newToolbarConfig()), 00207 this, TQT_SLOT(applyNewToolbarConfig())); 00208 dlg.exec(); 00209 } 00210 00211 00212 00213 void MainWindow::applyNewToolbarConfig() 00214 { 00215 applyMainWindowSettings(TDEGlobal::config(), autoSaveGroup()); 00216 } 00217 00218 00219 KParts::BrowserExtension *MainWindow::browserExtension(KParts::ReadOnlyPart *p) 00220 { 00221 return KParts::BrowserExtension::childObject( p ); 00222 } 00223 00224 00225 // from konqmainwindow 00226 void MainWindow::connectActionCollection( TDEActionCollection *coll ) 00227 { 00228 if (!coll) return; 00229 connect( coll, TQT_SIGNAL( actionStatusText( const TQString & ) ), 00230 m_statusLabel, TQT_SLOT( setText( const TQString & ) ) ); 00231 connect( coll, TQT_SIGNAL( clearStatusText() ), 00232 this, TQT_SLOT( slotClearStatusText() ) ); 00233 } 00234 00235 bool MainWindow::queryExit() 00236 { 00237 kdDebug() << "MainWindow::queryExit()" << endl; 00238 if ( !kapp->sessionSaving() ) 00239 { 00240 delete m_part; // delete that here instead of dtor to ensure nested tdehtmlparts are deleted before singleton objects like TDEHTMLPageCache 00241 m_part = 0; 00242 } 00243 else 00244 kdDebug("MainWindow::queryExit(): saving session"); 00245 00246 return TDEMainWindow::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 TQPixmap shot = TrayIcon::getInstance()->takeScreenshot(); 00265 00266 // Associate source to image and show the dialog: 00267 TQMimeSourceFactory::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(TQString()); 00278 } 00279 00280 void MainWindow::slotSetStatusBarText( const TQString & text ) 00281 { 00282 m_statusLabel->setText(text); 00283 } 00284 00285 } // namespace Akregator 00286 00287 #include "mainwindow.moc" 00288 00289 00290 // vim: set et ts=4 sts=4 sw=4: