kmail

kmmainwin.cpp

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