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(TQWidget *) 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 TQT_TQOBJECT(this), TQT_SLOT(slotNewMailReader()), 00040 actionCollection(), "new_mail_client" ); 00041 00042 mKMMainWidget = new KMMainWidget( TQT_TQWIDGET(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 TQTimer::singleShot( 200, this, TQT_SLOT(slotShowTipOnStart()) ); 00051 00052 setStandardToolBarMenuEnabled(true); 00053 00054 KStdAction::configureToolbars(TQT_TQOBJECT(this), TQT_SLOT(slotEditToolbars()), 00055 actionCollection()); 00056 00057 KStdAction::keyBindings(TQT_TQOBJECT(mKMMainWidget), TQT_SLOT(slotEditKeys()), 00058 actionCollection()); 00059 00060 KStdAction::quit( TQT_TQOBJECT(this), TQT_SLOT(slotQuit()), actionCollection()); 00061 createGUI( "kmmainwin.rc", false ); 00062 // Don't use conserveMemory() because this renders dynamic plugging 00063 // of actions unusable! 00064 00065 mKMMainWidget->setupForwardingActionsList(); 00066 00067 applyMainWindowSettings(KMKernel::config(), "Main Window"); 00068 00069 connect( KPIM::BroadcastStatus::instance(), TQT_SIGNAL( statusMsg( const TQString& ) ), 00070 this, TQT_SLOT( displayStatusMsg(const TQString&) ) ); 00071 00072 connect(kmkernel, TQT_SIGNAL(configChanged()), 00073 this, TQT_SLOT(slotConfigChanged())); 00074 00075 connect(mKMMainWidget, TQT_SIGNAL(captionChangeRequest(const TQString&)), 00076 TQT_SLOT(setCaption(const TQString&)) ); 00077 00078 // Enable mail checks again (see destructor) 00079 kmkernel->enableMailCheck(); 00080 00081 if ( kmkernel->firstStart() ) 00082 AccountWizard::start( kmkernel, this ); 00083 } 00084 00085 KMMainWin::~KMMainWin() 00086 { 00087 saveMainWindowSettings(KMKernel::config(), "Main Window"); 00088 KMKernel::config()->sync(); 00089 kapp->deref(); 00090 00091 if ( !kmkernel->haveSystemTrayApplet() ) { 00092 // Check if this was the last KMMainWin 00093 int not_withdrawn = 0; 00094 TQPtrListIterator<KMainWindow> it(*KMainWindow::memberList); 00095 for (it.toFirst(); it.current(); ++it){ 00096 if ( !it.current()->isHidden() && 00097 it.current()->isTopLevel() && 00098 it.current() != this && 00099 ::tqqt_cast<KMMainWin *>( it.current() ) 00100 ) 00101 not_withdrawn++; 00102 } 00103 00104 if ( not_withdrawn == 0 ) { 00105 kdDebug(5006) << "Closing last KMMainWin: stopping mail check" << endl; 00106 // Running KIO jobs prevent kapp from exiting, so we need to kill them 00107 // if they are only about checking mail (not important stuff like moving messages) 00108 kmkernel->abortMailCheck(); 00109 kmkernel->acctMgr()->cancelMailCheck(); 00110 } 00111 } 00112 } 00113 00114 void KMMainWin::displayStatusMsg(const TQString& aText) 00115 { 00116 if ( !statusBar() || !mLittleProgress) return; 00117 int statusWidth = statusBar()->width() - mLittleProgress->width() 00118 - fontMetrics().maxWidth(); 00119 TQString text = KStringHandler::rPixelSqueeze( " " + aText, fontMetrics(), 00120 statusWidth ); 00121 00122 // ### FIXME: We should disable richtext/HTML (to avoid possible denial of service attacks), 00123 // but this code would double the size of the satus bar if the user hovers 00124 // over an <foo@bar.com>-style email address :-( 00125 // text.replace("&", "&"); 00126 // text.replace("<", "<"); 00127 // text.replace(">", ">"); 00128 00129 statusBar()->changeItem(text, mMessageStatusId); 00130 } 00131 00132 //----------------------------------------------------------------------------- 00133 void KMMainWin::slotNewMailReader() 00134 { 00135 KMMainWin *d; 00136 00137 d = new KMMainWin(); 00138 d->show(); 00139 d->resize(d->size()); 00140 } 00141 00142 00143 void KMMainWin::slotEditToolbars() 00144 { 00145 saveMainWindowSettings(KMKernel::config(), "Main Window"); 00146 KEditToolbar dlg(actionCollection(), "kmmainwin.rc"); 00147 00148 connect( &dlg, TQT_SIGNAL(newToolbarConfig()), 00149 TQT_SLOT(slotUpdateToolbars()) ); 00150 00151 dlg.exec(); 00152 } 00153 00154 void KMMainWin::slotUpdateToolbars() 00155 { 00156 // remove dynamically created actions before editing 00157 mKMMainWidget->clearFilterActions(); 00158 00159 createGUI("kmmainwin.rc", false); 00160 applyMainWindowSettings(KMKernel::config(), "Main Window"); 00161 00162 // plug dynamically created actions again 00163 mKMMainWidget->initializeFilterActions(); 00164 } 00165 00166 void KMMainWin::setupStatusBar() 00167 { 00168 mMessageStatusId = 1; 00169 00170 /* Create a progress dialog and hide it. */ 00171 mProgressDialog = new KPIM::ProgressDialog( statusBar(), this ); 00172 mProgressDialog->hide(); 00173 00174 mLittleProgress = new StatusbarProgressWidget( mProgressDialog, statusBar() ); 00175 mLittleProgress->show(); 00176 00177 statusBar()->addWidget( mLittleProgress, 0 , true ); 00178 statusBar()->insertItem(i18n(" Initializing..."), 1, 4 ); 00179 statusBar()->setItemAlignment( 1, AlignLeft | AlignVCenter ); 00180 statusBar()->addWidget( mKMMainWidget->vacationScriptIndicator(), 1 ); 00181 mLittleProgress->show(); 00182 } 00183 00185 void KMMainWin::readConfig(void) 00186 { 00187 } 00188 00190 void KMMainWin::writeConfig(void) 00191 { 00192 mKMMainWidget->writeConfig(); 00193 } 00194 00195 void KMMainWin::slotQuit() 00196 { 00197 mReallyClose = true; 00198 close(); 00199 } 00200 00201 void KMMainWin::slotConfigChanged() 00202 { 00203 readConfig(); 00204 } 00205 00206 //----------------------------------------------------------------------------- 00207 bool KMMainWin::queryClose() 00208 { 00209 if ( kapp->sessionSaving() ) 00210 writeConfig(); 00211 00212 if ( kmkernel->shuttingDown() || kapp->sessionSaving() || mReallyClose ) 00213 return true; 00214 return kmkernel->canQueryClose(); 00215 } 00216 00217 void KMMainWin::slotShowTipOnStart() 00218 { 00219 KTipDialog::showTip( this ); 00220 } 00221 00222