kmail Library API Documentation

kmmainwin.cpp

00001 #ifdef HAVE_CONFIG_H
00002 #include <config.h>
00003 #endif
00004 
00005 #include "kmmainwin.h"
00006 #include "kmmainwidget.h"
00007 #include "kstatusbar.h"
00008 #include "kmkernel.h"
00009 #include "messagesender.h"
00010 #include "progressdialog.h"
00011 #include "statusbarprogresswidget.h"
00012 #include "broadcaststatus.h"
00013 #include "kmglobal.h"
00014 #include "kmacctmgr.h"
00015 #include <kapplication.h>
00016 #include <klocale.h>
00017 #include <kedittoolbar.h>
00018 #include <kconfig.h>
00019 #include <kmessagebox.h>
00020 #include <kstringhandler.h>
00021 #include <kdebug.h>
00022 #include <ktip.h>
00023 
00024 #include "kmmainwin.moc"
00025 
00026 KMMainWin::KMMainWin(QWidget *)
00027     : KMainWindow( 0, "kmail-mainwindow#" ),
00028       mReallyClose( false )
00029 {
00030   // Set this to be the group leader for all subdialogs - this means
00031   // modal subdialogs will only affect this dialog, not the other windows
00032   setWFlags( getWFlags() | WGroupLeader );
00033 
00034   kapp->ref();
00035   mKMMainWidget = new KMMainWidget( this, "KMMainWidget", this, actionCollection() );
00036   mKMMainWidget->resize( 450, 600 );
00037   setCentralWidget(mKMMainWidget);
00038   setupStatusBar();
00039   if (kmkernel->xmlGuiInstance())
00040     setInstance( kmkernel->xmlGuiInstance() );
00041 
00042   if ( kmkernel->firstInstance() )
00043     QTimer::singleShot( 200, this, SLOT(slotShowTipOnStart()) );
00044 
00045   setStandardToolBarMenuEnabled(true);
00046 
00047   KStdAction::configureToolbars(this, SLOT(slotEditToolbars()),
00048                 actionCollection());
00049 
00050   KStdAction::keyBindings(mKMMainWidget, SLOT(slotEditKeys()),
00051                           actionCollection());
00052 
00053   KStdAction::quit( this, SLOT(slotQuit()), actionCollection());
00054   createGUI( "kmmainwin.rc", false );
00055   // Don't use conserveMemory() because this renders dynamic plugging
00056   // of actions unusable!
00057 
00058   applyMainWindowSettings(KMKernel::config(), "Main Window");
00059 
00060   connect( KPIM::BroadcastStatus::instance(), SIGNAL( statusMsg( const QString& ) ),
00061            this, SLOT( displayStatusMsg(const QString&) ) );
00062 
00063   connect(kmkernel, SIGNAL(configChanged()),
00064     this, SLOT(slotConfigChanged()));
00065 
00066   connect(mKMMainWidget, SIGNAL(captionChangeRequest(const QString&)),
00067       SLOT(setCaption(const QString&)) );
00068 
00069   // Enable mail checks again (see destructor)
00070   kmkernel->enableMailCheck();
00071 }
00072 
00073 KMMainWin::~KMMainWin()
00074 {
00075   saveMainWindowSettings(KMKernel::config(), "Main Window");
00076   KMKernel::config()->sync();
00077   kapp->deref();
00078 
00079   if ( !kmkernel->haveSystemTrayApplet() ) {
00080     // Check if this was the last KMMainWin
00081     int not_withdrawn = 0;
00082     QPtrListIterator<KMainWindow> it(*KMainWindow::memberList);
00083     for (it.toFirst(); it.current(); ++it){
00084       if ( !it.current()->isHidden() &&
00085            it.current()->isTopLevel() &&
00086            it.current() != this &&
00087            ::qt_cast<KMMainWin *>( it.current() )
00088         )
00089         not_withdrawn++;
00090     }
00091 
00092     if ( not_withdrawn == 0 ) {
00093       kdDebug(5006) << "Closing last KMMainWin: stopping mail check" << endl;
00094       // Running KIO jobs prevent kapp from exiting, so we need to kill them
00095       // if they are only about checking mail (not important stuff like moving messages)
00096       kmkernel->abortMailCheck();
00097       kmkernel->acctMgr()->cancelMailCheck();
00098     }
00099   }
00100 }
00101 
00102 void KMMainWin::displayStatusMsg(const QString& aText)
00103 {
00104   if ( !statusBar() || !mLittleProgress) return;
00105   int statusWidth = statusBar()->width() - mLittleProgress->width()
00106                     - fontMetrics().maxWidth();
00107   QString text = KStringHandler::rPixelSqueeze( " " + aText, fontMetrics(),
00108                                                 statusWidth );
00109 
00110   // ### FIXME: We should disable richtext/HTML (to avoid possible denial of service attacks),
00111   // but this code would double the size of the satus bar if the user hovers
00112   // over an <foo@bar.com>-style email address :-(
00113 //  text.replace("&", "&amp;");
00114 //  text.replace("<", "&lt;");
00115 //  text.replace(">", "&gt;");
00116 
00117   statusBar()->changeItem(text, mMessageStatusId);
00118 }
00119 
00120 void KMMainWin::slotEditToolbars()
00121 {
00122   // remove dynamically created actions before editing
00123   mKMMainWidget->clearFilterActions();
00124 
00125   saveMainWindowSettings(KMKernel::config(), "Main Window");
00126   KEditToolbar dlg(actionCollection(), "kmmainwin.rc");
00127 
00128   connect( &dlg, SIGNAL(newToolbarConfig()),
00129        SLOT(slotUpdateToolbars()) );
00130 
00131   dlg.exec();
00132   // plug dynamically created actions again
00133   mKMMainWidget->initializeFilterActions();
00134 }
00135 
00136 void KMMainWin::slotUpdateToolbars()
00137 {
00138   createGUI("kmmainwin.rc");
00139   applyMainWindowSettings(KMKernel::config(), "Main Window");
00140 }
00141 
00142 void KMMainWin::setupStatusBar()
00143 {
00144   mMessageStatusId = 1;
00145 
00146   /* Create a progress dialog and hide it. */
00147   mProgressDialog = new KPIM::ProgressDialog( statusBar(), this );
00148   mProgressDialog->hide();
00149 
00150   mLittleProgress = new StatusbarProgressWidget( mProgressDialog, statusBar() );
00151   mLittleProgress->show();
00152 
00153   statusBar()->addWidget( mLittleProgress, 0 , true );
00154   statusBar()->insertItem(i18n(" Initializing..."), 1, 1 );
00155   statusBar()->setItemAlignment( 1, AlignLeft | AlignVCenter );
00156   mLittleProgress->show();
00157 }
00158 
00160 void KMMainWin::readConfig(void)
00161 {
00162 }
00163 
00165 void KMMainWin::writeConfig(void)
00166 {
00167   mKMMainWidget->writeConfig();
00168 }
00169 
00170 void KMMainWin::slotQuit()
00171 {
00172   mReallyClose = true;
00173   close();
00174 }
00175 
00176 void KMMainWin::slotConfigChanged()
00177 {
00178   readConfig();
00179 }
00180 
00181 //-----------------------------------------------------------------------------
00182 bool KMMainWin::queryClose()
00183 {
00184   if ( kapp->sessionSaving() )
00185     writeConfig();
00186 
00187   if ( kmkernel->shuttingDown() || kapp->sessionSaving() || mReallyClose )
00188     return true;
00189   return kmkernel->canQueryClose();
00190 }
00191 
00192 void KMMainWin::slotShowTipOnStart()
00193 {
00194   KTipDialog::showTip( this );
00195 }
00196 
00197 
KDE Logo
This file is part of the documentation for kmail Library Version 3.3.2.
Documentation copyright © 1996-2004 the KDE developers.
Generated on Thu Aug 23 18:21:27 2007 by doxygen 1.4.2 written by Dimitri van Heesch, © 1997-2003