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 "kmsender.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 00023 #include "kmmainwin.moc" 00024 00025 KMMainWin::KMMainWin(QWidget *) 00026 : KMainWindow( 0, "kmail-mainwindow#" ), 00027 mReallyClose( false ) 00028 { 00029 kapp->ref(); 00030 mKMMainWidget = new KMMainWidget( this, "KMMainWidget", this, actionCollection() ); 00031 mKMMainWidget->resize( 450, 600 ); 00032 setCentralWidget(mKMMainWidget); 00033 setupStatusBar(); 00034 if (kmkernel->xmlGuiInstance()) 00035 setInstance( kmkernel->xmlGuiInstance() ); 00036 00037 setStandardToolBarMenuEnabled(true); 00038 00039 KStdAction::configureToolbars(this, SLOT(slotEditToolbars()), 00040 actionCollection()); 00041 00042 KStdAction::keyBindings(mKMMainWidget, SLOT(slotEditKeys()), 00043 actionCollection()); 00044 00045 KStdAction::quit( this, SLOT(slotQuit()), actionCollection()); 00046 createGUI( "kmmainwin.rc", false ); 00047 // Don't use conserveMemory() because this renders dynamic plugging 00048 // of actions unusable! 00049 00050 applyMainWindowSettings(KMKernel::config(), "Main Window"); 00051 00052 connect( KPIM::BroadcastStatus::instance(), SIGNAL( statusMsg( const QString& ) ), 00053 this, SLOT( displayStatusMsg(const QString&) ) ); 00054 00055 connect(kmkernel, SIGNAL(configChanged()), 00056 this, SLOT(slotConfigChanged())); 00057 00058 connect(mKMMainWidget, SIGNAL(captionChangeRequest(const QString&)), 00059 SLOT(setCaption(const QString&)) ); 00060 00061 // Enable mail checks again (see destructor) 00062 kmkernel->enableMailCheck(); 00063 } 00064 00065 KMMainWin::~KMMainWin() 00066 { 00067 saveMainWindowSettings(KMKernel::config(), "Main Window"); 00068 KMKernel::config()->sync(); 00069 kapp->deref(); 00070 00071 if ( !kmkernel->haveSystemTrayApplet() ) { 00072 // Check if this was the last KMMainWin 00073 int not_withdrawn = 0; 00074 QPtrListIterator<KMainWindow> it(*KMainWindow::memberList); 00075 for (it.toFirst(); it.current(); ++it){ 00076 if ( !it.current()->isHidden() && 00077 it.current()->isTopLevel() && 00078 it.current() != this && 00079 ::qt_cast<KMMainWin *>( it.current() ) 00080 ) 00081 not_withdrawn++; 00082 } 00083 00084 if ( not_withdrawn == 0 ) { 00085 kdDebug(5006) << "Closing last KMMainWin: stopping mail check" << endl; 00086 // Running KIO jobs prevent kapp from exiting, so we need to kill them 00087 // if they are only about checking mail (not important stuff like moving messages) 00088 kmkernel->abortMailCheck(); 00089 kmkernel->acctMgr()->cancelMailCheck(); 00090 } 00091 } 00092 } 00093 00094 void KMMainWin::displayStatusMsg(const QString& aText) 00095 { 00096 if ( !statusBar() || !mLittleProgress) return; 00097 int statusWidth = statusBar()->width() - mLittleProgress->width() 00098 - fontMetrics().maxWidth(); 00099 QString text = KStringHandler::rPixelSqueeze( " " + aText, fontMetrics(), 00100 statusWidth ); 00101 00102 // ### FIXME: We should disable richtext/HTML (to avoid possible denial of service attacks), 00103 // but this code would double the size of the satus bar if the user hovers 00104 // over an <foo@bar.com>-style email address :-( 00105 // text.replace("&", "&amp;"); 00106 // text.replace("<", "&lt;"); 00107 // text.replace(">", "&gt;"); 00108 00109 statusBar()->changeItem(text, mMessageStatusId); 00110 } 00111 00112 void KMMainWin::slotEditToolbars() 00113 { 00114 saveMainWindowSettings(KMKernel::config(), "Main Window"); 00115 KEditToolbar dlg(actionCollection(), "kmmainwin.rc"); 00116 00117 connect( &dlg, SIGNAL(newToolbarConfig()), 00118 SLOT(slotUpdateToolbars()) ); 00119 00120 dlg.exec(); 00121 } 00122 00123 void KMMainWin::slotUpdateToolbars() 00124 { 00125 createGUI("kmmainwin.rc"); 00126 applyMainWindowSettings(KMKernel::config(), "Main Window"); 00127 } 00128 00129 void KMMainWin::setupStatusBar() 00130 { 00131 mMessageStatusId = 1; 00132 00133 /* Create a progress dialog and hide it. */ 00134 mProgressDialog = new KPIM::ProgressDialog( statusBar(), this ); 00135 mProgressDialog->hide(); 00136 00137 mLittleProgress = new StatusbarProgressWidget( mProgressDialog, statusBar() ); 00138 mLittleProgress->show(); 00139 00140 statusBar()->addWidget( mLittleProgress, 0 , true ); 00141 statusBar()->insertItem(i18n(" Initializing..."), 1, 1 ); 00142 statusBar()->setItemAlignment( 1, AlignLeft | AlignVCenter ); 00143 mLittleProgress->show(); 00144 } 00145 00147 void KMMainWin::readConfig(void) 00148 { 00149 } 00150 00152 void KMMainWin::writeConfig(void) 00153 { 00154 mKMMainWidget->writeConfig(); 00155 } 00156 00157 void KMMainWin::slotQuit() 00158 { 00159 mReallyClose = true; 00160 close(); 00161 } 00162 00163 void KMMainWin::slotConfigChanged() 00164 { 00165 readConfig(); 00166 } 00167 00168 //----------------------------------------------------------------------------- 00169 bool KMMainWin::queryClose() 00170 { 00171 if ( kapp->sessionSaving() ) 00172 writeConfig(); 00173 00174 if ( kmkernel->shuttingDown() || kapp->sessionSaving() || mReallyClose ) 00175 return true; 00176 return kmkernel->canQueryClose(); 00177 }
KDE Logo
This file is part of the documentation for kmail Library Version 3.3.0.
Documentation copyright © 1996-2004 the KDE developers.
Generated on Fri Oct 1 15:19:23 2004 by doxygen 1.3.7 written by Dimitri van Heesch, © 1997-2003