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", 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 00048 conserveMemory(); 00049 applyMainWindowSettings(KMKernel::config(), "Main Window"); 00050 00051 connect( KPIM::BroadcastStatus::instance(), SIGNAL( statusMsg( const QString& ) ), 00052 this, SLOT( displayStatusMsg(const QString&) ) ); 00053 00054 connect(kmkernel, SIGNAL(configChanged()), 00055 this, SLOT(slotConfigChanged())); 00056 00057 connect(mKMMainWidget, SIGNAL(captionChangeRequest(const QString&)), 00058 SLOT(setCaption(const QString&)) ); 00059 connect(mKMMainWidget, SIGNAL(modifiedToolBarConfig()), 00060 SLOT(slotUpdateToolbars()) ); 00061 00062 // Enable mail checks again (see destructor) 00063 kmkernel->enableMailCheck(); 00064 } 00065 00066 KMMainWin::~KMMainWin() 00067 { 00068 saveMainWindowSettings(KMKernel::config(), "Main Window"); 00069 KMKernel::config()->sync(); 00070 kapp->deref(); 00071 00072 if ( !kmkernel->haveSystemTrayApplet() ) { 00073 // Check if this was the last KMMainWin 00074 int not_withdrawn = 0; 00075 QPtrListIterator<KMainWindow> it(*KMainWindow::memberList); 00076 for (it.toFirst(); it.current(); ++it){ 00077 if ( !it.current()->isHidden() && 00078 it.current()->isTopLevel() && 00079 it.current() != this && 00080 ::qt_cast<KMMainWin *>( it.current() ) 00081 ) 00082 not_withdrawn++; 00083 } 00084 00085 if ( not_withdrawn == 0 ) { 00086 kdDebug(5006) << "Closing last KMMainWin: stopping mail check" << endl; 00087 // Running KIO jobs prevent kapp from exiting, so we need to kill them 00088 // if they are only about checking mail (not important stuff like moving messages) 00089 kmkernel->abortMailCheck(); 00090 kmkernel->acctMgr()->cancelMailCheck(); 00091 } 00092 } 00093 } 00094 00095 void KMMainWin::displayStatusMsg(const QString& aText) 00096 { 00097 if ( !statusBar() || !mLittleProgress) return; 00098 int statusWidth = statusBar()->width() - mLittleProgress->width() 00099 - fontMetrics().maxWidth(); 00100 QString text = KStringHandler::rPixelSqueeze( " " + aText, fontMetrics(), 00101 statusWidth ); 00102 00103 // ### FIXME: We should disable richtext/HTML (to avoid possible denial of service attacks), 00104 // but this code would double the size of the satus bar if the user hovers 00105 // over an <foo@bar.com>-style email address :-( 00106 // text.replace("&", "&amp;"); 00107 // text.replace("<", "&lt;"); 00108 // text.replace(">", "&gt;"); 00109 00110 statusBar()->changeItem(text, mMessageStatusId); 00111 } 00112 00113 void KMMainWin::slotEditToolbars() 00114 { 00115 saveMainWindowSettings(KMKernel::config(), "Main Window"); 00116 KEditToolbar dlg(actionCollection(), "kmmainwin.rc"); 00117 00118 connect( &dlg, SIGNAL(newToolbarConfig()), 00119 SLOT(slotUpdateToolbars()) ); 00120 00121 dlg.exec(); 00122 } 00123 00124 void KMMainWin::slotUpdateToolbars() 00125 { 00126 createGUI("kmmainwin.rc"); 00127 applyMainWindowSettings(KMKernel::config(), "Main Window"); 00128 } 00129 00130 void KMMainWin::setupStatusBar() 00131 { 00132 mMessageStatusId = 1; 00133 00134 /* Create a progress dialog and hide it. */ 00135 mProgressDialog = new KPIM::ProgressDialog( statusBar(), this ); 00136 mProgressDialog->hide(); 00137 00138 mLittleProgress = new StatusbarProgressWidget( mProgressDialog, statusBar() ); 00139 mLittleProgress->show(); 00140 00141 statusBar()->addWidget( mLittleProgress, 0 , true ); 00142 statusBar()->insertItem(i18n(" Initializing..."), 1, 1 ); 00143 statusBar()->setItemAlignment( 1, AlignLeft | AlignVCenter ); 00144 mLittleProgress->show(); 00145 } 00146 00148 void KMMainWin::readConfig(void) 00149 { 00150 } 00151 00153 void KMMainWin::writeConfig(void) 00154 { 00155 mKMMainWidget->writeConfig(); 00156 } 00157 00158 void KMMainWin::slotQuit() 00159 { 00160 mReallyClose = true; 00161 close(); 00162 } 00163 00164 void KMMainWin::slotConfigChanged() 00165 { 00166 readConfig(); 00167 } 00168 00169 //----------------------------------------------------------------------------- 00170 bool KMMainWin::queryClose() 00171 { 00172 if ( kapp->sessionSaving() ) 00173 writeConfig(); 00174 00175 if ( kmkernel->shuttingDown() || kapp->sessionSaving() || mReallyClose ) 00176 return true; 00177 return kmkernel->canQueryClose(); 00178 }
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 Aug 27 12:52:45 2004 by doxygen 1.3.8 written by Dimitri van Heesch, © 1997-2003