kmail

kmmainwidget.cpp

00001 // -*- mode: C++; c-file-style: "gnu" -*-
00002 // kmmainwidget.cpp
00003 //#define MALLOC_DEBUG 1
00004 
00005 #ifdef HAVE_CONFIG_H
00006 #include <config.h>
00007 #endif
00008 
00009 #include <kwin.h>
00010 
00011 #ifdef MALLOC_DEBUG
00012 #include <malloc.h>
00013 #endif
00014 
00015 #undef Unsorted // X headers...
00016 #include <qaccel.h>
00017 #include <qlayout.h>
00018 #include <qhbox.h>
00019 #include <qvbox.h>
00020 #include <qpopupmenu.h>
00021 #include <qptrlist.h>
00022 
00023 #include <kopenwith.h>
00024 
00025 #include <kmessagebox.h>
00026 
00027 #include <kpopupmenu.h>
00028 #include <kaccelmanager.h>
00029 #include <kglobalsettings.h>
00030 #include <kstdaccel.h>
00031 #include <kkeydialog.h>
00032 #include <kcharsets.h>
00033 #include <knotifyclient.h>
00034 #include <kdebug.h>
00035 #include <kapplication.h>
00036 #include <kfiledialog.h>
00037 #include <ktip.h>
00038 #include <knotifydialog.h>
00039 #include <kstandarddirs.h>
00040 #include <dcopclient.h>
00041 #include <kaddrbook.h>
00042 #include <kaccel.h>
00043 #include <kstringhandler.h>
00044 
00045 #include <qvaluevector.h>
00046 
00047 #include "globalsettings.h"
00048 #include "kcursorsaver.h"
00049 #include "broadcaststatus.h"
00050 using KPIM::BroadcastStatus;
00051 #include "kmfoldermgr.h"
00052 #include "kmfolderdia.h"
00053 #include "accountmanager.h"
00054 using KMail::AccountManager;
00055 #include "kmfilter.h"
00056 #include "kmfoldertree.h"
00057 #include "kmreadermainwin.h"
00058 #include "kmfoldercachedimap.h"
00059 #include "kmfolderimap.h"
00060 #include "kmacctcachedimap.h"
00061 #include "composer.h"
00062 #include "kmfolderseldlg.h"
00063 #include "kmfiltermgr.h"
00064 #include "messagesender.h"
00065 #include "kmaddrbook.h"
00066 #include "kmversion.h"
00067 #include "searchwindow.h"
00068 using KMail::SearchWindow;
00069 #include "kmacctfolder.h"
00070 #include "undostack.h"
00071 #include "kmcommands.h"
00072 #include "kmmainwin.h"
00073 #include "kmsystemtray.h"
00074 #include "imapaccountbase.h"
00075 #include "transportmanager.h"
00076 using KMail::ImapAccountBase;
00077 #include "vacation.h"
00078 using KMail::Vacation;
00079 #include "favoritefolderview.h"
00080 
00081 #include <qsignalmapper.h>
00082 
00083 #include "subscriptiondialog.h"
00084 using KMail::SubscriptionDialog;
00085 #include "localsubscriptiondialog.h"
00086 using KMail::LocalSubscriptionDialog;
00087 #include "attachmentstrategy.h"
00088 using KMail::AttachmentStrategy;
00089 #include "headerstrategy.h"
00090 using KMail::HeaderStrategy;
00091 #include "headerstyle.h"
00092 using KMail::HeaderStyle;
00093 #include "folderjob.h"
00094 using KMail::FolderJob;
00095 #include "mailinglist-magic.h"
00096 #include "antispamwizard.h"
00097 using KMail::AntiSpamWizard;
00098 #include "filterlogdlg.h"
00099 using KMail::FilterLogDialog;
00100 #include <headerlistquicksearch.h>
00101 #include "klistviewindexedsearchline.h"
00102 using KMail::HeaderListQuickSearch;
00103 #include "kmheaders.h"
00104 #include "mailinglistpropertiesdialog.h"
00105 #include "templateparser.h"
00106 
00107 #if !defined(NDEBUG)
00108     #include "sievedebugdialog.h"
00109     using KMail::SieveDebugDialog;
00110 #endif
00111 
00112 #include <libkpimidentities/identity.h>
00113 #include <libkpimidentities/identitymanager.h>
00114 
00115 #include <assert.h>
00116 #include <kstatusbar.h>
00117 #include <kstaticdeleter.h>
00118 #include <kaction.h>
00119 
00120 #include <kmime_mdn.h>
00121 #include <kmime_header_parsing.h>
00122 using namespace KMime;
00123 using KMime::Types::AddrSpecList;
00124 
00125 #include "progressmanager.h"
00126 using KPIM::ProgressManager;
00127 
00128 #include "managesievescriptsdialog.h"
00129 #include <qstylesheet.h>
00130 
00131 #include "customtemplates.h"
00132 #include "customtemplates_kfg.h"
00133 
00134 #include "kmmainwidget.moc"
00135 
00136 QValueList<KMMainWidget*>* KMMainWidget::s_mainWidgetList = 0;
00137 static KStaticDeleter<QValueList<KMMainWidget*> > mwlsd;
00138 
00139 //-----------------------------------------------------------------------------
00140 KMMainWidget::KMMainWidget(QWidget *parent, const char *name,
00141                            KXMLGUIClient *aGUIClient,
00142                            KActionCollection *actionCollection, KConfig* config ) :
00143     QWidget(parent, name),
00144     mFavoritesCheckMailAction( 0 ),
00145     mFavoriteFolderView( 0 ),
00146     mFolderView( 0 ),
00147     mFolderViewParent( 0 ),
00148     mFolderViewSplitter( 0 ),
00149     mQuickSearchLine( 0 ),
00150     mShowBusySplashTimer( 0 ),
00151     mShowingOfflineScreen( false ),
00152     mMsgActions( 0 ),
00153     mVacationIndicatorActive( false )
00154 {
00155   // must be the first line of the constructor:
00156   mStartupDone = false;
00157   mSearchWin = 0;
00158   mIntegrated  = true;
00159   mFolder = 0;
00160   mTemplateFolder = 0;
00161   mFolderThreadPref = false;
00162   mFolderThreadSubjPref = true;
00163   mReaderWindowActive = true;
00164   mReaderWindowBelow = true;
00165   mFolderHtmlPref = false;
00166   mFolderHtmlLoadExtPref = false;
00167   mSystemTray = 0;
00168   mDestructed = false;
00169   mActionCollection = actionCollection;
00170   mTopLayout = new QVBoxLayout(this);
00171   mFilterMenuActions.setAutoDelete(true);
00172   mFilterTBarActions.setAutoDelete(false);
00173   mFilterCommands.setAutoDelete(true);
00174   mFolderShortcutCommands.setAutoDelete(true);
00175   mJob = 0;
00176   mConfig = config;
00177   mGUIClient = aGUIClient;
00178 
00179   mCustomReplyActionMenu = 0;
00180   mCustomReplyAllActionMenu = 0;
00181   mCustomForwardActionMenu = 0;
00182   mCustomReplyMapper = 0;
00183   mCustomReplyAllMapper = 0;
00184   mCustomForwardMapper = 0;
00185 
00186   // FIXME This should become a line separator as soon as the API
00187   // is extended in kdelibs.
00188   mToolbarActionSeparator = new KActionSeparator( actionCollection );
00189 
00190   if( !s_mainWidgetList )
00191     mwlsd.setObject( s_mainWidgetList, new QValueList<KMMainWidget*>() );
00192   s_mainWidgetList->append( this );
00193 
00194   mPanner1Sep << 1 << 1;
00195   mPanner2Sep << 1 << 1;
00196 
00197   setMinimumSize(400, 300);
00198 
00199   readPreConfig();
00200   createWidgets();
00201 
00202   setupActions();
00203 
00204   readConfig();
00205 
00206   activatePanners();
00207 
00208   QTimer::singleShot( 0, this, SLOT( slotShowStartupFolder() ));
00209 
00210   connect( kmkernel->acctMgr(), SIGNAL( checkedMail( bool, bool, const QMap<QString, int> & ) ),
00211            this, SLOT( slotMailChecked( bool, bool, const QMap<QString, int> & ) ) );
00212 
00213   connect( kmkernel->acctMgr(), SIGNAL( accountAdded( KMAccount* ) ),
00214            this, SLOT( initializeIMAPActions() ) );
00215   connect( kmkernel->acctMgr(), SIGNAL( accountRemoved( KMAccount* ) ),
00216            this, SLOT( initializeIMAPActions() ) );
00217 
00218   connect(kmkernel, SIGNAL( configChanged() ),
00219           this, SLOT( slotConfigChanged() ));
00220 
00221   // display the full path to the folder in the caption
00222   connect(mFolderTree, SIGNAL(currentChanged(QListViewItem*)),
00223       this, SLOT(slotChangeCaption(QListViewItem*)));
00224   connect(mFolderTree, SIGNAL(selectionChanged()),
00225           SLOT(updateFolderMenu()) );
00226 
00227   connect(kmkernel->folderMgr(), SIGNAL(folderRemoved(KMFolder*)),
00228           this, SLOT(slotFolderRemoved(KMFolder*)));
00229 
00230   connect(kmkernel->imapFolderMgr(), SIGNAL(folderRemoved(KMFolder*)),
00231           this, SLOT(slotFolderRemoved(KMFolder*)));
00232 
00233   connect(kmkernel->dimapFolderMgr(), SIGNAL(folderRemoved(KMFolder*)),
00234           this, SLOT(slotFolderRemoved(KMFolder*)));
00235 
00236   connect(kmkernel->searchFolderMgr(), SIGNAL(folderRemoved(KMFolder*)),
00237           this, SLOT(slotFolderRemoved(KMFolder*)));
00238 
00239   connect( kmkernel, SIGNAL( onlineStatusChanged( GlobalSettings::EnumNetworkState::type ) ),
00240            this, SLOT( slotUpdateOnlineStatus( GlobalSettings::EnumNetworkState::type ) ) );
00241 
00242   toggleSystemTray();
00243 
00244   // must be the last line of the constructor:
00245   mStartupDone = true;
00246 
00247 
00248   KMainWindow *mainWin = dynamic_cast<KMainWindow*>(topLevelWidget());
00249   KStatusBar *sb =  mainWin ? mainWin->statusBar() : 0;
00250   mVacationScriptIndicator = new KStatusBarLabel( QString(), 0, sb );
00251   mVacationScriptIndicator->hide();
00252   connect( mVacationScriptIndicator, SIGNAL(itemReleased(int)), SLOT(slotEditVacation()) );
00253   if ( GlobalSettings::checkOutOfOfficeOnStartup() )
00254     QTimer::singleShot( 0, this, SLOT(slotCheckVacation()) );
00255 }
00256 
00257 
00258 //-----------------------------------------------------------------------------
00259 //The kernel may have already been deleted when this method is called,
00260 //perform all cleanup that requires the kernel in destruct()
00261 KMMainWidget::~KMMainWidget()
00262 {
00263   s_mainWidgetList->remove( this );
00264   destruct();
00265 }
00266 
00267 
00268 //-----------------------------------------------------------------------------
00269 //This method performs all cleanup that requires the kernel to exist.
00270 void KMMainWidget::destruct()
00271 {
00272   if (mDestructed)
00273     return;
00274   if (mSearchWin)
00275     mSearchWin->close();
00276   writeConfig();
00277   writeFolderConfig();
00278   delete mHeaders;
00279   delete mFolderTree;
00280   delete mSystemTray;
00281   delete mMsgView;
00282   mDestructed = true;
00283 }
00284 
00285 
00286 //-----------------------------------------------------------------------------
00287 void KMMainWidget::readPreConfig(void)
00288 {
00289   const KConfigGroup geometry( KMKernel::config(), "Geometry" );
00290   const KConfigGroup reader( KMKernel::config(), "Reader" );
00291 
00292   mLongFolderList = geometry.readEntry( "FolderList", "long" ) != "short";
00293   mReaderWindowActive = geometry.readEntry( "readerWindowMode", "below" ) != "hide";
00294   mReaderWindowBelow = geometry.readEntry( "readerWindowMode", "below" ) == "below";
00295   mThreadPref = geometry.readBoolEntry( "nestedMessages", false );
00296 
00297   mHtmlPref = reader.readBoolEntry( "htmlMail", false );
00298   mHtmlLoadExtPref = reader.readBoolEntry( "htmlLoadExternal", false );
00299   mEnableFavoriteFolderView = GlobalSettings::self()->enableFavoriteFolderView();
00300 }
00301 
00302 
00303 //-----------------------------------------------------------------------------
00304 void KMMainWidget::readFolderConfig(void)
00305 {
00306   if (!mFolder)
00307     return;
00308 
00309   KConfig *config = KMKernel::config();
00310   KConfigGroupSaver saver(config, "Folder-" + mFolder->idString());
00311   mFolderThreadPref = config->readBoolEntry( "threadMessagesOverride", false );
00312   mFolderThreadSubjPref = config->readBoolEntry( "threadMessagesBySubject", true );
00313   mFolderHtmlPref = config->readBoolEntry( "htmlMailOverride", false );
00314   mFolderHtmlLoadExtPref = config->readBoolEntry( "htmlLoadExternalOverride", false );
00315 }
00316 
00317 
00318 //-----------------------------------------------------------------------------
00319 void KMMainWidget::writeFolderConfig(void)
00320 {
00321   if (!mFolder)
00322     return;
00323 
00324   KConfig *config = KMKernel::config();
00325   KConfigGroupSaver saver(config, "Folder-" + mFolder->idString());
00326   config->writeEntry( "threadMessagesOverride", mFolderThreadPref );
00327   config->writeEntry( "threadMessagesBySubject", mFolderThreadSubjPref );
00328   config->writeEntry( "htmlMailOverride", mFolderHtmlPref );
00329   config->writeEntry( "htmlLoadExternalOverride", mFolderHtmlLoadExtPref );
00330 }
00331 
00332 
00333 //-----------------------------------------------------------------------------
00334 void KMMainWidget::readConfig(void)
00335 {
00336   KConfig *config = KMKernel::config();
00337 
00338   bool oldLongFolderList =  mLongFolderList;
00339   bool oldReaderWindowActive = mReaderWindowActive;
00340   bool oldReaderWindowBelow = mReaderWindowBelow;
00341   bool oldFavoriteFolderView = mEnableFavoriteFolderView;
00342 
00343   QString str;
00344   QSize siz;
00345 
00346   if (mStartupDone)
00347   {
00348     writeConfig();
00349 
00350     readPreConfig();
00351     mHeaders->refreshNestedState();
00352 
00353     bool layoutChanged = ( oldLongFolderList != mLongFolderList )
00354                     || ( oldReaderWindowActive != mReaderWindowActive )
00355                     || ( oldReaderWindowBelow != mReaderWindowBelow )
00356                     || ( oldFavoriteFolderView != mEnableFavoriteFolderView );
00357 
00358 
00359     if( layoutChanged ) {
00360       hide();
00361       // delete all panners
00362       delete mPanner1; // will always delete the others
00363       createWidgets();
00364     }
00365 
00366   }
00367 
00368   { // area for config group "Geometry"
00369     KConfigGroupSaver saver(config, "Geometry");
00370     // size of the mainwin
00371     QSize defaultSize(750,560);
00372     siz = config->readSizeEntry("MainWin", &defaultSize);
00373     if (!siz.isEmpty())
00374       resize(siz);
00375     // default width of the foldertree
00376     static const int folderpanewidth = 250;
00377 
00378     const int folderW = config->readNumEntry( "FolderPaneWidth", folderpanewidth );
00379     const int headerW = config->readNumEntry( "HeaderPaneWidth", width()-folderpanewidth );
00380     const int headerH = config->readNumEntry( "HeaderPaneHeight", 180 );
00381     const int readerH = config->readNumEntry( "ReaderPaneHeight", 280 );
00382 
00383     mPanner1Sep.clear();
00384     mPanner2Sep.clear();
00385     QValueList<int> & widths = mLongFolderList ? mPanner1Sep : mPanner2Sep ;
00386     QValueList<int> & heights = mLongFolderList ? mPanner2Sep : mPanner1Sep ;
00387 
00388     widths << folderW << headerW;
00389     heights << headerH << readerH;
00390 
00391     bool layoutChanged = ( oldLongFolderList != mLongFolderList )
00392                     || ( oldReaderWindowActive != mReaderWindowActive )
00393                     || ( oldReaderWindowBelow != mReaderWindowBelow );
00394 
00395     if (!mStartupDone || layoutChanged )
00396     {
00400       // The columns are shown by default.
00401 
00402       const int unreadColumn = config->readNumEntry("UnreadColumn", 1);
00403       const int totalColumn = config->readNumEntry("TotalColumn", 2);
00404       const int sizeColumn = config->readNumEntry("SizeColumn", 3);
00405 
00406       /* we need to _activate_ them in the correct order
00407       * this is ugly because we can't use header()->moveSection
00408       * but otherwise the restoreLayout from KMFolderTree
00409       * doesn't know that to do */
00410       if (unreadColumn == 1)
00411         mFolderTree->addUnreadColumn( i18n("Unread"), 70 );
00412       else if (totalColumn == 1)
00413         mFolderTree->addTotalColumn( i18n("Total"), 70 );
00414       else if (sizeColumn == 1)
00415         mFolderTree->addSizeColumn( i18n("Size"), 70 );
00416 
00417       if (unreadColumn == 2)
00418         mFolderTree->addUnreadColumn( i18n("Unread"), 70 );
00419       else if (totalColumn == 2)
00420         mFolderTree->addTotalColumn( i18n("Total"), 70 );
00421       else if (sizeColumn == 2)
00422         mFolderTree->addSizeColumn( i18n("Size"), 70 );
00423 
00424       if (unreadColumn == 3)
00425         mFolderTree->addUnreadColumn( i18n("Unread"), 70 );
00426       else if (totalColumn == 3)
00427         mFolderTree->addTotalColumn( i18n("Total"), 70 );
00428       else if (sizeColumn == 3)
00429         mFolderTree->addSizeColumn( i18n("Size"), 70 );
00430 
00431       mUnreadColumnToggle->setChecked( mFolderTree->isUnreadActive() );
00432       mUnreadTextToggle->setChecked( !mFolderTree->isUnreadActive() );
00433       mTotalColumnToggle->setChecked( mFolderTree->isTotalActive() );
00434       mSizeColumnToggle->setChecked( mFolderTree->isSizeActive() );
00435 
00436       mFolderTree->updatePopup();
00437     }
00438   }
00439 
00440   if (mMsgView)
00441     mMsgView->readConfig();
00442 
00443   mHeaders->readConfig();
00444   mHeaders->restoreColumnLayout( KMKernel::config(), "Header-Geometry" );
00445 
00446   if ( mFolderViewSplitter && !GlobalSettings::self()->folderViewSplitterPosition().isEmpty() ) {
00447     mFolderViewSplitter->setSizes( GlobalSettings::self()->folderViewSplitterPosition() );
00448   } else {
00449     QValueList<int> defaults;
00450     defaults << (int)(height() * 0.2) << (int)(height() * 0.8);
00451     mFolderViewSplitter->setSizes( defaults );
00452   }
00453 
00454   mFolderTree->readConfig();
00455   if ( mFavoriteFolderView )
00456     mFavoriteFolderView->readConfig();
00457   mFavoritesCheckMailAction->setEnabled( GlobalSettings::self()->enableFavoriteFolderView() );
00458 
00459   { // area for config group "General"
00460     KConfigGroupSaver saver(config, "General");
00461     mBeepOnNew = config->readBoolEntry("beep-on-mail", false);
00462     mConfirmEmpty = config->readBoolEntry("confirm-before-empty", true);
00463     // startup-Folder, defaults to system-inbox
00464     mStartupFolder = config->readEntry("startupFolder", kmkernel->inboxFolder()->idString());
00465     if (!mStartupDone)
00466     {
00467       // check mail on startup
00468       bool check = config->readBoolEntry("checkmail-startup", false);
00469       if (check)
00470         // do it after building the kmmainwin, so that the progressdialog is available
00471         QTimer::singleShot( 0, this, SLOT( slotCheckMail() ) );
00472     }
00473   }
00474 
00475   // reload foldertree
00476   mFolderTree->reload();
00477 
00478   // Re-activate panners
00479   if (mStartupDone)
00480   {
00481     // Update systray
00482     toggleSystemTray();
00483 
00484     bool layoutChanged = ( oldLongFolderList != mLongFolderList )
00485                     || ( oldReaderWindowActive != mReaderWindowActive )
00486                     || ( oldReaderWindowBelow != mReaderWindowBelow )
00487                     || ( oldFavoriteFolderView != mEnableFavoriteFolderView );
00488     if ( layoutChanged ) {
00489       activatePanners();
00490     }
00491 
00492     mFolderTree->showFolder( mFolder );
00493 
00494     // sanders - New code
00495     mHeaders->setFolder(mFolder);
00496     if (mMsgView) {
00497       int aIdx = mHeaders->currentItemIndex();
00498       if (aIdx != -1)
00499         mMsgView->setMsg( mFolder->getMsg(aIdx), true );
00500       else
00501         mMsgView->clear( true );
00502     }
00503     updateMessageActions();
00504     show();
00505     // sanders - Maybe this fixes a bug?
00506 
00507   }
00508   updateMessageMenu();
00509   updateFileMenu();
00510 }
00511 
00512 
00513 //-----------------------------------------------------------------------------
00514 void KMMainWidget::writeConfig(void)
00515 {
00516   QString s;
00517   KConfig *config = KMKernel::config();
00518   KConfigGroup geometry( config, "Geometry" );
00519 
00520   if (mMsgView)
00521     mMsgView->writeConfig();
00522 
00523   if ( mFolderViewSplitter )
00524     GlobalSettings::setFolderViewSplitterPosition( mFolderViewSplitter->sizes() );
00525   mFolderTree->writeConfig();
00526   if ( mFavoriteFolderView )
00527     mFavoriteFolderView->writeConfig();
00528 
00529   geometry.writeEntry( "MainWin", this->geometry().size() );
00530 
00531   const QValueList<int> widths = ( mLongFolderList ? mPanner1 : mPanner2 )->sizes();
00532   const QValueList<int> heights = ( mLongFolderList ? mPanner2 : mPanner1 )->sizes();
00533 
00534   geometry.writeEntry( "FolderPaneWidth", widths[0] );
00535   geometry.writeEntry( "HeaderPaneWidth", widths[1] );
00536 
00537   // Only save when the widget is shown (to avoid saving a wrong value)
00538   if ( mSearchAndHeaders && mSearchAndHeaders->isShown() ) {
00539     geometry.writeEntry( "HeaderPaneHeight", heights[0] );
00540     geometry.writeEntry( "ReaderPaneHeight", heights[1] );
00541   }
00542 
00543   // save the state of the unread/total-columns
00544   geometry.writeEntry( "UnreadColumn", mFolderTree->unreadIndex() );
00545   geometry.writeEntry( "TotalColumn", mFolderTree->totalIndex() );
00546   geometry.writeEntry( "SizeColumn", mFolderTree->sizeIndex() );
00547 }
00548 
00549 
00550 //-----------------------------------------------------------------------------
00551 void KMMainWidget::createWidgets(void)
00552 {
00553   // Create the splitters according to the layout settings
00554   QWidget *headerParent = 0,
00555             *mimeParent = 0, *messageParent = 0;
00556 
00557   const bool opaqueResize = KGlobalSettings::opaqueResize();
00558   if ( mLongFolderList ) {
00559     // superior splitter: folder tree vs. rest
00560     // inferior splitter: headers vs. message vs. mime tree
00561     mPanner1 = new QSplitter( Qt::Horizontal, this, "panner 1" );
00562     mPanner1->setOpaqueResize( opaqueResize );
00563     Qt::Orientation orientation = mReaderWindowBelow ? Qt::Vertical : Qt::Horizontal;
00564     mPanner2 = new QSplitter( orientation, mPanner1, "panner 2" );
00565     mPanner2->setOpaqueResize( opaqueResize );
00566     mPanner2->setChildrenCollapsible( false );
00567     mFolderViewParent = mPanner1;
00568     headerParent = mimeParent = messageParent = mPanner2;
00569   } else /* !mLongFolderList */ {
00570     // superior splitter: ( folder tree + headers ) vs. message vs. mime
00571     // inferior splitter: folder tree vs. headers
00572     mPanner1 = new QSplitter( Qt::Vertical, this, "panner 1" );
00573     mPanner1->setOpaqueResize( opaqueResize );
00574     mPanner1->setChildrenCollapsible( false );
00575     mPanner2 = new QSplitter( Qt::Horizontal, mPanner1, "panner 2" );
00576     mPanner2->setOpaqueResize( opaqueResize );
00577     headerParent = mFolderViewParent = mPanner2;
00578     mimeParent = messageParent = mPanner1;
00579   }
00580 
00581 #ifndef NDEBUG
00582   if( mPanner1 ) mPanner1->dumpObjectTree();
00583   if( mPanner2 ) mPanner2->dumpObjectTree();
00584 #endif
00585 
00586   mTopLayout->add( mPanner1 );
00587 
00588   // BUG -sanders these accelerators stop working after switching
00589   // between long/short folder layout
00590   // Probably need to disconnect them first.
00591 
00592   // create list of messages
00593 #ifndef NDEBUG
00594   headerParent->dumpObjectTree();
00595 #endif
00596   mSearchAndHeaders = new QVBox( headerParent );
00597   mSearchToolBar = new KToolBar( mSearchAndHeaders, "search toolbar");
00598   mSearchToolBar->setMovingEnabled(false);
00599   mSearchToolBar->boxLayout()->setSpacing( KDialog::spacingHint() );
00600   QLabel *label = new QLabel( i18n("S&earch:"), mSearchToolBar, "kde toolbar widget" );
00601 
00602 
00603   mHeaders = new KMHeaders(this, mSearchAndHeaders, "headers");
00604 #ifdef HAVE_INDEXLIB
00605   mQuickSearchLine = new KListViewIndexedSearchLine( mSearchToolBar, mHeaders,
00606                                                     actionCollection(), "headers quick search line" );
00607 #else
00608   mQuickSearchLine = new HeaderListQuickSearch( mSearchToolBar, mHeaders,
00609                         actionCollection(), "headers quick search line" );
00610 #endif
00611   label->setBuddy( mQuickSearchLine );
00612   connect( mQuickSearchLine, SIGNAL( requestFullSearch() ),
00613            this, SLOT( slotRequestFullSearchFromQuickSearch() ) );
00614   mSearchToolBar->setStretchableWidget( mQuickSearchLine );
00615     connect( mHeaders, SIGNAL( messageListUpdated() ),
00616            mQuickSearchLine, SLOT( updateSearch() ) );
00617   if ( !GlobalSettings::self()->quickSearchActive() ) mSearchToolBar->hide();
00618 
00619   if (mReaderWindowActive) {
00620     connect(mHeaders, SIGNAL(selected(KMMessage*)),
00621             this, SLOT(slotMsgSelected(KMMessage*)));
00622   }
00623   connect(mHeaders, SIGNAL(activated(KMMessage*)),
00624           this, SLOT(slotMsgActivated(KMMessage*)));
00625   connect( mHeaders, SIGNAL( selectionChanged() ),
00626            SLOT( startUpdateMessageActionsTimer() ) );
00627   QAccel *accel = actionCollection()->kaccel();
00628   accel->connectItem(accel->insertItem(SHIFT+Key_Left),
00629                      mHeaders, SLOT(selectPrevMessage()));
00630   accel->connectItem(accel->insertItem(SHIFT+Key_Right),
00631                      mHeaders, SLOT(selectNextMessage()));
00632 
00633   if (mReaderWindowActive) {
00634     mMsgView = new KMReaderWin(messageParent, this, actionCollection(), 0 );
00635     if ( mMsgActions ) {
00636       mMsgActions->setMessageView( mMsgView );
00637     }
00638 
00639     connect(mMsgView, SIGNAL(replaceMsgByUnencryptedVersion()),
00640         this, SLOT(slotReplaceMsgByUnencryptedVersion()));
00641     connect(mMsgView, SIGNAL(popupMenu(KMMessage&,const KURL&,const QPoint&)),
00642         this, SLOT(slotMsgPopup(KMMessage&,const KURL&,const QPoint&)));
00643     connect(mMsgView, SIGNAL(urlClicked(const KURL&,int)),
00644         mMsgView, SLOT(slotUrlClicked()));
00645     connect(mHeaders, SIGNAL(maybeDeleting()),
00646         mMsgView, SLOT(clearCache()));
00647     connect(mMsgView, SIGNAL(noDrag()),
00648         mHeaders, SLOT(slotNoDrag()));
00649     accel->connectItem(accel->insertItem(Key_Up),
00650         mMsgView, SLOT(slotScrollUp()));
00651     accel->connectItem(accel->insertItem(Key_Down),
00652         mMsgView, SLOT(slotScrollDown()));
00653     accel->connectItem(accel->insertItem(Key_Prior),
00654         mMsgView, SLOT(slotScrollPrior()));
00655     accel->connectItem(accel->insertItem(Key_Next),
00656         mMsgView, SLOT(slotScrollNext()));
00657   } else {
00658     mMsgView = NULL;
00659   }
00660 
00661   KAction *action;
00662 
00663   mMoveMsgToFolderAction = new KAction( i18n("Move Message to Folder"), Key_M, this,
00664                SLOT(slotMoveMsg()), actionCollection(),
00665                "move_message_to_folder" );
00666   mMoveMsgToFolderAction->plugAccel( actionCollection()->kaccel() );
00667 
00668   action = new KAction( i18n("Copy Message to Folder"), Key_C, this,
00669                SLOT(slotCopyMsg()), actionCollection(),
00670                "copy_message_to_folder" );
00671   action->plugAccel( actionCollection()->kaccel() );
00672 
00673   action = new KAction( i18n("Jump to Folder"), Key_J, this,
00674                SLOT(slotJumpToFolder()), actionCollection(),
00675                "jump_to_folder" );
00676   action->plugAccel( actionCollection()->kaccel() );
00677 
00678   // create list of folders
00679   mFolderViewSplitter = new QSplitter( Qt::Vertical, mFolderViewParent );
00680   mFolderViewSplitter->setOpaqueResize( KGlobalSettings::opaqueResize() );
00681   mFavoriteFolderView = new KMail::FavoriteFolderView( this, mFolderViewSplitter );
00682   if ( mFavoritesCheckMailAction )
00683   connect( mFavoritesCheckMailAction, SIGNAL(activated()), mFavoriteFolderView, SLOT(checkMail()) );
00684   QWidget *folderTreeParent = mFolderViewParent;
00685   if ( GlobalSettings::enableFavoriteFolderView() ) {
00686     folderTreeParent = mFolderViewSplitter;
00687     mFolderView = mFolderViewSplitter;
00688   }
00689   mFolderTree = new KMFolderTree(this, folderTreeParent, "folderTree");
00690   if ( !GlobalSettings::enableFavoriteFolderView() ) {
00691      mFolderView = mFolderTree;
00692   }
00693   connect( mFolderTree, SIGNAL(folderSelected(KMFolder*)),
00694             mFavoriteFolderView, SLOT(folderTreeSelectionChanged(KMFolder*)) );
00695 
00696   connect(mFolderTree, SIGNAL(folderSelected(KMFolder*)),
00697       this, SLOT(folderSelected(KMFolder*)));
00698   connect( mFolderTree, SIGNAL( folderSelected( KMFolder* ) ),
00699            mQuickSearchLine, SLOT( reset() ) );
00700   connect(mFolderTree, SIGNAL(folderSelectedUnread(KMFolder*)),
00701       this, SLOT(folderSelectedUnread(KMFolder*)));
00702   connect(mFolderTree, SIGNAL(folderDrop(KMFolder*)),
00703       this, SLOT(slotMoveMsgToFolder(KMFolder*)));
00704   connect(mFolderTree, SIGNAL(folderDropCopy(KMFolder*)),
00705           this, SLOT(slotCopyMsgToFolder(KMFolder*)));
00706   connect(mFolderTree, SIGNAL(columnsChanged()),
00707           this, SLOT(slotFolderTreeColumnsChanged()));
00708 
00709   if ( mFavoriteFolderView ) {
00710     connect( mFavoriteFolderView, SIGNAL(folderDrop(KMFolder*)), SLOT(slotMoveMsgToFolder(KMFolder*)) );
00711     connect( mFavoriteFolderView, SIGNAL(folderDropCopy(KMFolder*)), SLOT(slotCopyMsgToFolder(KMFolder*)) );
00712   }
00713 
00714   //Commands not worthy of menu items, but that deserve configurable keybindings
00715   mRemoveDuplicatesAction = new KAction(
00716     i18n("Remove Duplicate Messages"), CTRL+Key_Asterisk, this,
00717     SLOT(removeDuplicates()), actionCollection(), "remove_duplicate_messages");
00718   action->plugAccel( actionCollection()->kaccel() );
00719 
00720   action = new KAction(
00721     i18n("Abort Current Operation"), Key_Escape, ProgressManager::instance(),
00722     SLOT(slotAbortAll()), actionCollection(), "cancel" );
00723   action->plugAccel( actionCollection()->kaccel() );
00724 
00725   action = new KAction(
00726    i18n("Focus on Next Folder"), CTRL+Key_Right, mFolderTree,
00727    SLOT(incCurrentFolder()), actionCollection(), "inc_current_folder");
00728   action->plugAccel( actionCollection()->kaccel() );
00729 
00730   action = new KAction(
00731    i18n("Focus on Previous Folder"), CTRL+Key_Left, mFolderTree,
00732    SLOT(decCurrentFolder()), actionCollection(), "dec_current_folder");
00733   action->plugAccel( actionCollection()->kaccel() );
00734 
00735   action = new KAction(
00736    i18n("Select Folder with Focus"), CTRL+Key_Space, mFolderTree,
00737    SLOT(selectCurrentFolder()), actionCollection(), "select_current_folder");
00738   action->plugAccel( actionCollection()->kaccel() );
00739 
00740   action = new KAction(
00741     i18n("Focus on Next Message"), ALT+Key_Right, mHeaders,
00742     SLOT(incCurrentMessage()), actionCollection(), "inc_current_message");
00743   action->plugAccel( actionCollection()->kaccel() );
00744 
00745   action = new KAction(
00746     i18n("Focus on Previous Message"), ALT+Key_Left, mHeaders,
00747     SLOT(decCurrentMessage()), actionCollection(), "dec_current_message");
00748   action->plugAccel( actionCollection()->kaccel() );
00749 
00750   action = new KAction(
00751     i18n("Select Message with Focus"), ALT+Key_Space, mHeaders,
00752     SLOT( selectCurrentMessage() ), actionCollection(), "select_current_message");
00753   action->plugAccel( actionCollection()->kaccel() );
00754 
00755   connect( kmkernel->outboxFolder(), SIGNAL( msgRemoved(int, QString) ),
00756            SLOT( startUpdateMessageActionsTimer() ) );
00757   connect( kmkernel->outboxFolder(), SIGNAL( msgAdded(int) ),
00758            SLOT( startUpdateMessageActionsTimer() ) );
00759 }
00760 
00761 
00762 //-----------------------------------------------------------------------------
00763 void KMMainWidget::activatePanners(void)
00764 {
00765   if (mMsgView) {
00766     QObject::disconnect( mMsgView->copyAction(),
00767         SIGNAL( activated() ),
00768         mMsgView, SLOT( slotCopySelectedText() ));
00769   }
00770 
00771   setupFolderView();
00772   if ( mLongFolderList ) {
00773     mSearchAndHeaders->reparent( mPanner2, 0, QPoint( 0, 0 ) );
00774     if (mMsgView) {
00775       mMsgView->reparent( mPanner2, 0, QPoint( 0, 0 ) );
00776       mPanner2->moveToLast( mMsgView );
00777     }
00778     mFolderViewParent = mPanner1;
00779     mFolderView->reparent( mFolderViewParent, 0, QPoint( 0, 0 ) );
00780     mPanner1->moveToLast( mPanner2 );
00781     mPanner1->setSizes( mPanner1Sep );
00782     mPanner1->setResizeMode( mFolderView, QSplitter::KeepSize );
00783     mPanner2->setSizes( mPanner2Sep );
00784     mPanner2->setResizeMode( mSearchAndHeaders, QSplitter::KeepSize );
00785   } else /* !mLongFolderList */ {
00786     mFolderViewParent = mPanner2;
00787     mFolderView->reparent( mFolderViewParent, 0, QPoint( 0, 0 ) );
00788     mSearchAndHeaders->reparent( mPanner2, 0, QPoint( 0, 0 ) );
00789     mPanner2->moveToLast( mSearchAndHeaders );
00790     mPanner1->moveToFirst( mPanner2 );
00791     if (mMsgView) {
00792       mMsgView->reparent( mPanner1, 0, QPoint( 0, 0 ) );
00793       mPanner1->moveToLast( mMsgView );
00794     }
00795     mPanner1->setSizes( mPanner1Sep );
00796     mPanner2->setSizes( mPanner2Sep );
00797     mPanner1->setResizeMode( mPanner2, QSplitter::KeepSize );
00798     mPanner2->setResizeMode( mFolderView, QSplitter::KeepSize );
00799   }
00800 
00801   if (mMsgView) {
00802     QObject::connect( mMsgView->copyAction(),
00803             SIGNAL( activated() ),
00804             mMsgView, SLOT( slotCopySelectedText() ));
00805   }
00806 }
00807 
00808 
00809 //-----------------------------------------------------------------------------
00810 void KMMainWidget::hide()
00811 {
00812   QWidget::hide();
00813 }
00814 
00815 
00816 //-----------------------------------------------------------------------------
00817 void KMMainWidget::show()
00818 {
00819   QWidget::show();
00820 }
00821 
00822 //-------------------------------------------------------------------------
00823 void KMMainWidget::slotSearch()
00824 {
00825   if(!mSearchWin)
00826   {
00827     mSearchWin = new SearchWindow(this, "Search", mFolder, false);
00828     connect(mSearchWin, SIGNAL(destroyed()),
00829         this, SLOT(slotSearchClosed()));
00830   }
00831   else
00832   {
00833     mSearchWin->activateFolder(mFolder);
00834   }
00835 
00836   mSearchWin->show();
00837   KWin::activateWindow( mSearchWin->winId() );
00838 }
00839 
00840 
00841 //-------------------------------------------------------------------------
00842 void KMMainWidget::slotSearchClosed()
00843 {
00844   mSearchWin = 0;
00845 }
00846 
00847 
00848 //-------------------------------------------------------------------------
00849 void KMMainWidget::slotFind()
00850 {
00851   if( mMsgView )
00852     mMsgView->slotFind();
00853 }
00854 
00855 
00856 //-----------------------------------------------------------------------------
00857 void KMMainWidget::slotHelp()
00858 {
00859   kapp->invokeHelp();
00860 }
00861 
00862 
00863 //-----------------------------------------------------------------------------
00864 void KMMainWidget::slotFilter()
00865 {
00866   kmkernel->filterMgr()->openDialog( this );
00867 }
00868 
00869 
00870 //-----------------------------------------------------------------------------
00871 void KMMainWidget::slotPopFilter()
00872 {
00873   kmkernel->popFilterMgr()->openDialog( this );
00874 }
00875 
00876 void KMMainWidget::slotManageSieveScripts()
00877 {
00878   if ( !kmkernel->askToGoOnline() ) {
00879     return;
00880   }
00881   KMail::ManageSieveScriptsDialog * dlg = new KMail::ManageSieveScriptsDialog( this );
00882   dlg->show();
00883 }
00884 
00885 
00886 //-----------------------------------------------------------------------------
00887 void KMMainWidget::slotAddrBook()
00888 {
00889   KAddrBookExternal::openAddressBook(this);
00890 }
00891 
00892 
00893 //-----------------------------------------------------------------------------
00894 void KMMainWidget::slotImport()
00895 {
00896   KRun::runCommand("kmailcvt");
00897 }
00898 
00899 //-----------------------------------------------------------------------------
00900 void KMMainWidget::slotCheckMail()
00901 {
00902   if ( !kmkernel->askToGoOnline() ) {
00903     return;
00904   }
00905   kmkernel->acctMgr()->checkMail(true);
00906 }
00907 
00908 //-----------------------------------------------------------------------------
00909 void KMMainWidget::slotCheckOneAccount(int item)
00910 {
00911   if ( !kmkernel->askToGoOnline() ) {
00912     return;
00913   }
00914   kmkernel->acctMgr()->intCheckMail(item);
00915 }
00916 
00917 //-----------------------------------------------------------------------------
00918 void KMMainWidget::slotMailChecked( bool newMail, bool sendOnCheck,
00919                                     const QMap<QString, int> & newInFolder )
00920 {
00921   const bool sendOnAll =
00922     GlobalSettings::self()->sendOnCheck() == GlobalSettings::EnumSendOnCheck::SendOnAllChecks;
00923   const bool sendOnManual =
00924     GlobalSettings::self()->sendOnCheck() == GlobalSettings::EnumSendOnCheck::SendOnManualChecks;
00925   if( !kmkernel->isOffline() && ( sendOnAll || (sendOnManual && sendOnCheck ) ) )
00926     slotSendQueued();
00927 
00928   if ( !newMail || newInFolder.isEmpty() )
00929     return;
00930 
00931   kapp->dcopClient()->emitDCOPSignal( "unreadCountChanged()", QByteArray() );
00932 
00933   // build summary for new mail message
00934   bool showNotification = false;
00935   QString summary;
00936   QStringList keys( newInFolder.keys() );
00937   keys.sort();
00938   for ( QStringList::const_iterator it = keys.begin();
00939         it != keys.end();
00940         ++it ) {
00941     kdDebug(5006) << newInFolder.find( *it ).data() << " new message(s) in "
00942                   << *it << endl;
00943 
00944     KMFolder *folder = kmkernel->findFolderById( *it );
00945 
00946     if ( folder && !folder->ignoreNewMail() ) {
00947       showNotification = true;
00948       if ( GlobalSettings::self()->verboseNewMailNotification() ) {
00949         summary += "<br>" + i18n( "1 new message in %1",
00950                                   "%n new messages in %1",
00951                                   newInFolder.find( *it ).data() )
00952                             .arg( folder->prettyURL() );
00953       }
00954     }
00955   }
00956 
00957   // update folder menus in case some mail got filtered to trash/current folder
00958   // and we can enable "empty trash/move all to trash" action etc.
00959   updateFolderMenu();
00960 
00961   if ( !showNotification )
00962     return;
00963 
00964   if ( GlobalSettings::self()->verboseNewMailNotification() ) {
00965     summary = i18n( "%1 is a list of the number of new messages per folder",
00966                     "<b>New mail arrived</b><br>%1" )
00967               .arg( summary );
00968   }
00969   else {
00970     summary = i18n( "New mail arrived" );
00971   }
00972 
00973   if(kmkernel->xmlGuiInstance()) {
00974     KNotifyClient::Instance instance(kmkernel->xmlGuiInstance());
00975     KNotifyClient::event( topLevelWidget()->winId(), "new-mail-arrived",
00976                           summary );
00977   }
00978   else
00979     KNotifyClient::event( topLevelWidget()->winId(), "new-mail-arrived",
00980                           summary );
00981 
00982   if (mBeepOnNew) {
00983     KNotifyClient::beep();
00984   }
00985 }
00986 
00987 
00988 //-----------------------------------------------------------------------------
00989 void KMMainWidget::slotCompose()
00990 {
00991   KMail::Composer * win;
00992   KMMessage* msg = new KMMessage;
00993 
00994   if ( mFolder ) {
00995       msg->initHeader( mFolder->identity() );
00996       TemplateParser parser( msg, TemplateParser::NewMessage,
00997     "", false, false, false, false );
00998       parser.process( NULL, mFolder );
00999       win = KMail::makeComposer( msg, mFolder->identity() );
01000   } else {
01001       msg->initHeader();
01002       TemplateParser parser( msg, TemplateParser::NewMessage,
01003     "", false, false, false, false );
01004       parser.process( NULL, NULL );
01005       win = KMail::makeComposer( msg );
01006   }
01007 
01008   win->show();
01009 
01010 }
01011 
01012 //-----------------------------------------------------------------------------
01013 // TODO: do we want the list sorted alphabetically?
01014 void KMMainWidget::slotShowNewFromTemplate()
01015 {
01016   if ( mFolder ) {
01017     const KPIM::Identity & ident =
01018       kmkernel->identityManager()->identityForUoidOrDefault( mFolder->identity() );
01019     mTemplateFolder = kmkernel->folderMgr()->findIdString( ident.templates() );
01020   }
01021   else mTemplateFolder = kmkernel->templatesFolder();
01022   if ( !mTemplateFolder )
01023     return;
01024 
01025   mTemplateMenu->popupMenu()->clear();
01026   for ( int idx = 0; idx<mTemplateFolder->count(); ++idx ) {
01027     KMMsgBase *mb = mTemplateFolder->getMsgBase( idx );
01028 
01029     QString subj = mb->subject();
01030     if ( subj.isEmpty() ) subj = i18n("No Subject");
01031     mTemplateMenu->popupMenu()->insertItem(
01032       KStringHandler::rsqueeze( subj.replace( "&", "&&" ) ), idx );
01033   }
01034 }
01035 
01036 //-----------------------------------------------------------------------------
01037 void KMMainWidget::slotNewFromTemplate( int id )
01038 {
01039   if ( !mTemplateFolder )
01040     return;
01041   newFromTemplate(mTemplateFolder->getMsg( id ) );
01042 }
01043 
01044 //-----------------------------------------------------------------------------
01045 void KMMainWidget::newFromTemplate( KMMessage *msg )
01046 {
01047   if ( !msg )
01048     return;
01049   KMCommand *command = new KMUseTemplateCommand( this, msg );
01050   command->start();
01051 }
01052 
01053 //-----------------------------------------------------------------------------
01054 void KMMainWidget::slotPostToML()
01055 {
01056   if ( mFolder && mFolder->isMailingListEnabled() ) {
01057     KMCommand *command = new KMMailingListPostCommand( this, mFolder );
01058     command->start();
01059   }
01060   else
01061     slotCompose();
01062 }
01063 
01064 //-----------------------------------------------------------------------------
01065 void KMMainWidget::slotFolderMailingListProperties()
01066 {
01067   if (!mFolderTree) return;
01068   KMFolderTreeItem *item = static_cast<KMFolderTreeItem*>( mFolderTree->currentItem() );
01069   if ( !item ) return;
01070   KMFolder* folder = item->folder();
01071   if ( folder ) {
01072     ( new KMail::MailingListFolderPropertiesDialog( this, folder ) )->show();
01073   }
01074 }
01075 
01076 //-----------------------------------------------------------------------------
01077 void KMMainWidget::slotFolderShortcutCommand()
01078 {
01079   if (!mFolderTree) return;
01080   KMFolderTreeItem *item = static_cast<KMFolderTreeItem*>( mFolderTree->currentItem() );
01081   if ( item )
01082     item->assignShortcut();
01083 }
01084 
01085 
01086 //-----------------------------------------------------------------------------
01087 void KMMainWidget::slotModifyFolder()
01088 {
01089   if (!mFolderTree) return;
01090   KMFolderTreeItem *item = static_cast<KMFolderTreeItem*>( mFolderTree->currentItem() );
01091   if ( item )
01092     modifyFolder( item );
01093 }
01094 
01095 //-----------------------------------------------------------------------------
01096 void KMMainWidget::modifyFolder( KMFolderTreeItem* folderItem )
01097 {
01098   KMFolder* folder = folderItem->folder();
01099   KMFolderTree* folderTree = static_cast<KMFolderTree *>( folderItem->listView() );
01100   KMFolderDialog props( folder, folder->parent(), folderTree,
01101                         i18n("Properties of Folder %1").arg( folder->label() ) );
01102   props.exec();
01103   updateFolderMenu();
01104   //Kolab issue 2152
01105   if ( mSystemTray )
01106     mSystemTray->foldersChanged();
01107 }
01108 
01109 //-----------------------------------------------------------------------------
01110 void KMMainWidget::slotExpireFolder()
01111 {
01112   QString     str;
01113   bool        canBeExpired = true;
01114 
01115   if (!mFolder) return;
01116 
01117   if (!mFolder->isAutoExpire()) {
01118     canBeExpired = false;
01119   } else if (mFolder->getUnreadExpireUnits()==expireNever &&
01120          mFolder->getReadExpireUnits()==expireNever) {
01121     canBeExpired = false;
01122   }
01123 
01124   if (!canBeExpired) {
01125     str = i18n("This folder does not have any expiry options set");
01126     KMessageBox::information(this, str);
01127     return;
01128   }
01129   KConfig           *config = KMKernel::config();
01130   KConfigGroupSaver saver(config, "General");
01131 
01132   if (config->readBoolEntry("warn-before-expire", true)) {
01133     str = i18n("<qt>Are you sure you want to expire the folder <b>%1</b>?</qt>").arg(QStyleSheet::escape( mFolder->label() ));
01134     if (KMessageBox::warningContinueCancel(this, str, i18n("Expire Folder"),
01135                        i18n("&Expire"))
01136     != KMessageBox::Continue) return;
01137   }
01138 
01139   mFolder->expireOldMessages( true /*immediate*/);
01140 }
01141 
01142 //-----------------------------------------------------------------------------
01143 void KMMainWidget::slotEmptyFolder()
01144 {
01145   QString str;
01146 
01147   if (!mFolder) return;
01148   bool isTrash = kmkernel->folderIsTrash(mFolder);
01149 
01150   if (mConfirmEmpty)
01151   {
01152     QString title = (isTrash) ? i18n("Empty Trash") : i18n("Move to Trash");
01153     QString text = (isTrash) ?
01154       i18n("Are you sure you want to empty the trash folder?") :
01155       i18n("<qt>Are you sure you want to move all messages from "
01156            "folder <b>%1</b> to the trash?</qt>").arg( QStyleSheet::escape( mFolder->label() ) );
01157 
01158     if (KMessageBox::warningContinueCancel(this, text, title, KGuiItem( title, "edittrash"))
01159       != KMessageBox::Continue) return;
01160   }
01161   KCursorSaver busy(KBusyPtr::busy());
01162   slotMarkAll();
01163   if (isTrash) {
01164     /* Don't ask for confirmation again when deleting, the user has already
01165        confirmed. */
01166     slotDeleteMsg( false );
01167   }
01168   else
01169     slotTrashMsg();
01170 
01171   if (mMsgView) mMsgView->clearCache();
01172 
01173   if ( !isTrash )
01174     BroadcastStatus::instance()->setStatusMsg(i18n("Moved all messages to the trash"));
01175 
01176   updateMessageActions();
01177 
01178   // Disable empty trash/move all to trash action - we've just deleted/moved all folder
01179   // contents.
01180   mEmptyFolderAction->setEnabled( false );
01181 }
01182 
01183 
01184 //-----------------------------------------------------------------------------
01185 void KMMainWidget::slotRemoveFolder()
01186 {
01187   QString str;
01188   QDir dir;
01189 
01190   if ( !mFolder ) return;
01191   if ( mFolder->isSystemFolder() ) return;
01192   if ( mFolder->isReadOnly() ) return;
01193 
01194   QString title;
01195   if ( mFolder->folderType() == KMFolderTypeSearch ) {
01196     title = i18n("Delete Search");
01197     str = i18n("<qt>Are you sure you want to delete the search <b>%1</b>?<br>"
01198                 "Any messages it shows will still be available in their original folder.</qt>")
01199            .arg( QStyleSheet::escape( mFolder->label() ) );
01200   } else {
01201     title = i18n("Delete Folder");
01202     if ( mFolder->count() == 0 ) {
01203       if ( !mFolder->child() || mFolder->child()->isEmpty() ) {
01204         str = i18n("<qt>Are you sure you want to delete the empty folder "
01205                    "<b>%1</b>?</qt>")
01206               .arg( QStyleSheet::escape( mFolder->label() ) );
01207       }
01208       else {
01209         str = i18n("<qt>Are you sure you want to delete the empty folder "
01210                    "<b>%1</b> and all its subfolders? Those subfolders might "
01211                    "not be empty and their contents will be discarded as well. "
01212                    "<p><b>Beware</b> that discarded messages are not saved "
01213                    "into your Trash folder and are permanently deleted.</qt>")
01214               .arg( QStyleSheet::escape( mFolder->label() ) );
01215       }
01216     } else {
01217       if ( !mFolder->child() || mFolder->child()->isEmpty() ) {
01218         str = i18n("<qt>Are you sure you want to delete the folder "
01219                    "<b>%1</b>, discarding its contents? "
01220                    "<p><b>Beware</b> that discarded messages are not saved "
01221                    "into your Trash folder and are permanently deleted.</qt>")
01222               .arg( QStyleSheet::escape( mFolder->label() ) );
01223       }
01224       else {
01225         str = i18n("<qt>Are you sure you want to delete the folder <b>%1</b> "
01226                    "and all its subfolders, discarding their contents? "
01227                    "<p><b>Beware</b> that discarded messages are not saved "
01228                    "into your Trash folder and are permanently deleted.</qt>")
01229             .arg( QStyleSheet::escape( mFolder->label() ) );
01230       }
01231     }
01232   }
01233 
01234   if (KMessageBox::warningContinueCancel(this, str, title,
01235                                          KGuiItem( i18n("&Delete"), "editdelete"))
01236       == KMessageBox::Continue)
01237   {
01238     if ( mFolder->hasAccounts() ) {
01239       // this folder has an account, so we need to change that to the inbox
01240       for ( AccountList::Iterator it (mFolder->acctList()->begin() ),
01241              end( mFolder->acctList()->end() ); it != end; ++it ) {
01242         (*it)->setFolder( kmkernel->inboxFolder() );
01243         KMessageBox::information(this,
01244             i18n("<qt>The folder you deleted was associated with the account "
01245               "<b>%1</b> which delivered mail into it. The folder the account "
01246               "delivers new mail into was reset to the main Inbox folder.</qt>").arg( (*it)->name()));
01247       }
01248     }
01249     if (mFolder->folderType() == KMFolderTypeImap)
01250       kmkernel->imapFolderMgr()->remove(mFolder);
01251     else if (mFolder->folderType() == KMFolderTypeCachedImap) {
01252       // Deleted by user -> tell the account (see KMFolderCachedImap::listDirectory2)
01253       KMFolderCachedImap* storage = static_cast<KMFolderCachedImap*>( mFolder->storage() );
01254       KMAcctCachedImap* acct = storage->account();
01255       if ( acct )
01256         acct->addDeletedFolder( mFolder );
01257 
01258       kmkernel->dimapFolderMgr()->remove(mFolder);
01259     }
01260     else if (mFolder->folderType() == KMFolderTypeSearch)
01261       kmkernel->searchFolderMgr()->remove(mFolder);
01262     else
01263       kmkernel->folderMgr()->remove(mFolder);
01264   }
01265 }
01266 
01267 //-----------------------------------------------------------------------------
01268 void KMMainWidget::slotMarkAllAsRead()
01269 {
01270   if (!mFolder)
01271     return;
01272   mFolder->markUnreadAsRead();
01273 }
01274 
01275 //-----------------------------------------------------------------------------
01276 void KMMainWidget::slotCompactFolder()
01277 {
01278   if (mFolder) {
01279     int idx = mHeaders->currentItemIndex();
01280     KCursorSaver busy(KBusyPtr::busy());
01281     mFolder->compact( KMFolder::CompactNow );
01282     // setCurrentItemByIndex will override the statusbar message, so save/restore it
01283     QString statusMsg = BroadcastStatus::instance()->statusMsg();
01284     mHeaders->setCurrentItemByIndex(idx);
01285     BroadcastStatus::instance()->setStatusMsg( statusMsg );
01286   }
01287 }
01288 
01289 
01290 //-----------------------------------------------------------------------------
01291 void KMMainWidget::slotRefreshFolder()
01292 {
01293   if (mFolder)
01294   {
01295     if ( mFolder->folderType() == KMFolderTypeImap || mFolder->folderType() == KMFolderTypeCachedImap ) {
01296       if ( !kmkernel->askToGoOnline() ) {
01297         return;
01298       }
01299     }
01300 
01301     if (mFolder->folderType() == KMFolderTypeImap)
01302     {
01303       KMFolderImap *imap = static_cast<KMFolderImap*>(mFolder->storage());
01304       imap->getAndCheckFolder();
01305     } else if ( mFolder->folderType() == KMFolderTypeCachedImap ) {
01306       KMFolderCachedImap* f = static_cast<KMFolderCachedImap*>( mFolder->storage() );
01307       f->account()->processNewMailInFolder( mFolder );
01308     }
01309   }
01310 }
01311 
01312 void KMMainWidget::slotTroubleshootFolder()
01313 {
01314   if (mFolder)
01315   {
01316     if ( mFolder->folderType() == KMFolderTypeCachedImap ) {
01317       KMFolderCachedImap* f = static_cast<KMFolderCachedImap*>( mFolder->storage() );
01318       f->slotTroubleshoot();
01319     }
01320   }
01321 }
01322 
01323 void KMMainWidget::slotInvalidateIMAPFolders() {
01324   if ( KMessageBox::warningContinueCancel( this,
01325           i18n("Are you sure you want to refresh the IMAP cache?\n"
01326            "This will remove all changes that you have done "
01327            "locally to your IMAP folders."),
01328       i18n("Refresh IMAP Cache"), i18n("&Refresh") ) == KMessageBox::Continue )
01329     kmkernel->acctMgr()->invalidateIMAPFolders();
01330 }
01331 
01332 //-----------------------------------------------------------------------------
01333 void KMMainWidget::slotExpireAll() {
01334   KConfig    *config = KMKernel::config();
01335   int        ret = 0;
01336 
01337   KConfigGroupSaver saver(config, "General");
01338 
01339   if (config->readBoolEntry("warn-before-expire", true)) {
01340     ret = KMessageBox::warningContinueCancel(KMainWindow::memberList->first(),
01341              i18n("Are you sure you want to expire all old messages?"),
01342              i18n("Expire Old Messages?"), i18n("Expire"));
01343     if (ret != KMessageBox::Continue) {
01344       return;
01345     }
01346   }
01347 
01348   kmkernel->expireAllFoldersNow();
01349 }
01350 
01351 //-----------------------------------------------------------------------------
01352 void KMMainWidget::slotCompactAll()
01353 {
01354   KCursorSaver busy(KBusyPtr::busy());
01355   kmkernel->compactAllFolders();
01356 }
01357 
01358 
01359 //-----------------------------------------------------------------------------
01360 void KMMainWidget::slotOverrideHtml()
01361 {
01362   if( mHtmlPref == mFolderHtmlPref ) {
01363     int result = KMessageBox::warningContinueCancel( this,
01364       // the warning text is taken from configuredialog.cpp:
01365       i18n( "Use of HTML in mail will make you more vulnerable to "
01366         "\"spam\" and may increase the likelihood that your system will be "
01367         "compromised by other present and anticipated security exploits." ),
01368       i18n( "Security Warning" ),
01369       i18n( "Use HTML" ),
01370       "OverrideHtmlWarning", false);
01371     if( result == KMessageBox::Cancel ) {
01372       mPreferHtmlAction->setChecked( false );
01373       return;
01374     }
01375   }
01376   mFolderHtmlPref = !mFolderHtmlPref;
01377   if (mMsgView) {
01378     mMsgView->setHtmlOverride(mFolderHtmlPref);
01379     mMsgView->update( true );
01380   }
01381 }
01382 
01383 //-----------------------------------------------------------------------------
01384 void KMMainWidget::slotOverrideHtmlLoadExt()
01385 {
01386   if( mHtmlLoadExtPref == mFolderHtmlLoadExtPref ) {
01387     int result = KMessageBox::warningContinueCancel( this,
01388       // the warning text is taken from configuredialog.cpp:
01389       i18n( "Loading external references in html mail will make you more vulnerable to "
01390         "\"spam\" and may increase the likelihood that your system will be "
01391         "compromised by other present and anticipated security exploits." ),
01392       i18n( "Security Warning" ),
01393       i18n( "Load External References" ),
01394       "OverrideHtmlLoadExtWarning", false);
01395     if( result == KMessageBox::Cancel ) {
01396       mPreferHtmlLoadExtAction->setChecked( false );
01397       return;
01398     }
01399   }
01400   mFolderHtmlLoadExtPref = !mFolderHtmlLoadExtPref;
01401   if (mMsgView) {
01402     mMsgView->setHtmlLoadExtOverride(mFolderHtmlLoadExtPref);
01403     mMsgView->update( true );
01404   }
01405 }
01406 
01407 //-----------------------------------------------------------------------------
01408 void KMMainWidget::slotOverrideThread()
01409 {
01410   mFolderThreadPref = !mFolderThreadPref;
01411   mHeaders->setNestedOverride(mFolderThreadPref);
01412   mThreadBySubjectAction->setEnabled(mThreadMessagesAction->isChecked());
01413 }
01414 
01415 //-----------------------------------------------------------------------------
01416 void KMMainWidget::slotToggleSubjectThreading()
01417 {
01418   mFolderThreadSubjPref = !mFolderThreadSubjPref;
01419   mHeaders->setSubjectThreading(mFolderThreadSubjPref);
01420 }
01421 
01422 //-----------------------------------------------------------------------------
01423 void KMMainWidget::slotToggleShowQuickSearch()
01424 {
01425   GlobalSettings::self()->setQuickSearchActive( !GlobalSettings::self()->quickSearchActive() );
01426   if ( GlobalSettings::self()->quickSearchActive() )
01427     mSearchToolBar->show();
01428   else {
01429     mQuickSearchLine->reset();
01430     mSearchToolBar->hide();
01431   }
01432 }
01433 
01434 //-----------------------------------------------------------------------------
01435 void KMMainWidget::slotMessageQueuedOrDrafted()
01436 {
01437   if (!kmkernel->folderIsDraftOrOutbox(mFolder))
01438       return;
01439   if (mMsgView)
01440     mMsgView->update(true);
01441 }
01442 
01443 
01444 //-----------------------------------------------------------------------------
01445 void KMMainWidget::slotForwardInlineMsg()
01446 {
01447   KMMessageList* selected = mHeaders->selectedMsgs();
01448   KMCommand *command = 0L;
01449   if(selected && !selected->isEmpty()) {
01450     command = new KMForwardInlineCommand( this, *selected,
01451                                           mFolder->identity() );
01452   } else {
01453     command = new KMForwardInlineCommand( this, mHeaders->currentMsg(),
01454                                           mFolder->identity() );
01455   }
01456 
01457   command->start();
01458 }
01459 
01460 
01461 //-----------------------------------------------------------------------------
01462 void KMMainWidget::slotForwardAttachedMsg()
01463 {
01464   KMMessageList* selected = mHeaders->selectedMsgs();
01465   KMCommand *command = 0L;
01466   if(selected && !selected->isEmpty()) {
01467     command = new KMForwardAttachedCommand( this, *selected, mFolder->identity() );
01468   } else {
01469     command = new KMForwardAttachedCommand( this, mHeaders->currentMsg(), mFolder->identity() );
01470   }
01471 
01472   command->start();
01473 }
01474 
01475 //-----------------------------------------------------------------------------
01476 void KMMainWidget::slotForwardDigestMsg()
01477 {
01478   KMMessageList* selected = mHeaders->selectedMsgs();
01479   KMCommand *command = 0L;
01480   if(selected && !selected->isEmpty()) {
01481     command = new KMForwardDigestCommand( this, *selected, mFolder->identity() );
01482   } else {
01483     command = new KMForwardDigestCommand( this, mHeaders->currentMsg(), mFolder->identity() );
01484   }
01485 
01486   command->start();
01487 }
01488 
01489 //-----------------------------------------------------------------------------
01490 void KMMainWidget::slotUseTemplate()
01491 {
01492   newFromTemplate( mHeaders->currentMsg() );
01493 }
01494 
01495 //-----------------------------------------------------------------------------
01496 void KMMainWidget::slotResendMsg()
01497 {
01498   KMCommand *command = new KMResendMessageCommand( this, mHeaders->currentMsg() );
01499   command->start();
01500 }
01501 
01502 
01503 //-----------------------------------------------------------------------------
01504 void KMMainWidget::slotTrashMsg()
01505 {
01506   mHeaders->deleteMsg();
01507 }
01508 
01509 //-----------------------------------------------------------------------------
01510 void KMMainWidget::slotDeleteMsg( bool confirmDelete )
01511 {
01512   mHeaders->moveMsgToFolder( 0, confirmDelete );
01513 }
01514 
01515 //-----------------------------------------------------------------------------
01516 void KMMainWidget::slotTrashThread()
01517 {
01518   mHeaders->highlightCurrentThread();
01519   mHeaders->deleteMsg();
01520 }
01521 
01522 //-----------------------------------------------------------------------------
01523 void KMMainWidget::slotDeleteThread( bool confirmDelete )
01524 {
01525   mHeaders->highlightCurrentThread();
01526   mHeaders->moveMsgToFolder( 0, confirmDelete );
01527 }
01528 
01529 //-----------------------------------------------------------------------------
01530 void KMMainWidget::slotRedirectMsg()
01531 {
01532   KMCommand *command = new KMRedirectCommand( this, mHeaders->currentMsg() );
01533   command->start();
01534 }
01535 
01536 
01537 //-----------------------------------------------------------------------------
01538 void KMMainWidget::slotCustomReplyToMsg( int tid )
01539 {
01540   QString text = mMsgView? mMsgView->copyText() : "";
01541   QString tmpl = mCustomTemplates[ tid ];
01542   kdDebug() << "Reply with template: " << tmpl << " (" << tid << ")" << endl;
01543   KMCommand *command = new KMCustomReplyToCommand( this,
01544                                                    mHeaders->currentMsg(),
01545                                                    text,
01546                                                    tmpl );
01547   command->start();
01548 }
01549 
01550 
01551 //-----------------------------------------------------------------------------
01552 void KMMainWidget::slotCustomReplyAllToMsg( int tid )
01553 {
01554   QString text = mMsgView? mMsgView->copyText() : "";
01555   QString tmpl = mCustomTemplates[ tid ];
01556   kdDebug() << "Reply to All with template: " << tmpl << " (" << tid << ")" << endl;
01557   KMCommand *command = new KMCustomReplyAllToCommand( this,
01558                                                    mHeaders->currentMsg(),
01559                                                    text,
01560                                                    tmpl );
01561   command->start();
01562 }
01563 
01564 
01565 //-----------------------------------------------------------------------------
01566 void KMMainWidget::slotCustomForwardMsg( int tid )
01567 {
01568   QString tmpl = mCustomTemplates[ tid ];
01569   kdDebug() << "Forward with template: " << tmpl << " (" << tid << ")" << endl;
01570   KMMessageList* selected = mHeaders->selectedMsgs();
01571   KMCommand *command = 0L;
01572   if(selected && !selected->isEmpty()) {
01573     command = new KMCustomForwardCommand( this, *selected,
01574                                           mFolder->identity(), tmpl );
01575   } else {
01576     command = new KMCustomForwardCommand( this, mHeaders->currentMsg(),
01577                                           mFolder->identity(), tmpl );
01578   }
01579   command->start();
01580 }
01581 
01582 
01583 //-----------------------------------------------------------------------------
01584 void KMMainWidget::slotNoQuoteReplyToMsg()
01585 {
01586   KMCommand *command = new KMNoQuoteReplyToCommand( this, mHeaders->currentMsg() );
01587   command->start();
01588 }
01589 
01590 //-----------------------------------------------------------------------------
01591 void KMMainWidget::slotSubjectFilter()
01592 {
01593   KMMessage *msg = mHeaders->currentMsg();
01594   if (!msg)
01595     return;
01596 
01597   KMCommand *command = new KMFilterCommand( "Subject", msg->subject() );
01598   command->start();
01599 }
01600 
01601 //-----------------------------------------------------------------------------
01602 void KMMainWidget::slotMailingListFilter()
01603 {
01604   KMMessage *msg = mHeaders->currentMsg();
01605   if (!msg)
01606     return;
01607 
01608   KMCommand *command = new KMMailingListFilterCommand( this, msg );
01609   command->start();
01610 }
01611 
01612 //-----------------------------------------------------------------------------
01613 void KMMainWidget::slotFromFilter()
01614 {
01615   KMMessage *msg = mHeaders->currentMsg();
01616   if (!msg)
01617     return;
01618 
01619   AddrSpecList al = msg->extractAddrSpecs( "From" );
01620   KMCommand *command;
01621   if ( al.empty() )
01622     command = new KMFilterCommand( "From",  msg->from() );
01623   else
01624     command = new KMFilterCommand( "From",  al.front().asString() );
01625   command->start();
01626 }
01627 
01628 //-----------------------------------------------------------------------------
01629 void KMMainWidget::slotToFilter()
01630 {
01631   KMMessage *msg = mHeaders->currentMsg();
01632   if (!msg)
01633     return;
01634 
01635   KMCommand *command = new KMFilterCommand( "To",  msg->to() );
01636   command->start();
01637 }
01638 
01639 //-----------------------------------------------------------------------------
01640 void KMMainWidget::updateListFilterAction()
01641 {
01642   //Proxy the mListFilterAction to update the action text
01643   QCString name;
01644   QString value;
01645   QString lname = MailingList::name( mHeaders->currentMsg(), name, value );
01646   mListFilterAction->setText( i18n("Filter on Mailing-List...") );
01647   if ( lname.isNull() )
01648     mListFilterAction->setEnabled( false );
01649   else {
01650     mListFilterAction->setEnabled( true );
01651     mListFilterAction->setText( i18n( "Filter on Mailing-List %1..." ).arg( lname ) );
01652   }
01653 }
01654 
01655 
01656 //-----------------------------------------------------------------------------
01657 void KMMainWidget::slotUndo()
01658 {
01659     mHeaders->undo();
01660     updateMessageActions();
01661     updateFolderMenu();
01662 }
01663 
01664 //-----------------------------------------------------------------------------
01665 void KMMainWidget::slotToggleUnread()
01666 {
01667   mFolderTree->toggleColumn(KMFolderTree::unread);
01668 }
01669 
01670 //-----------------------------------------------------------------------------
01671 void KMMainWidget::slotToggleTotalColumn()
01672 {
01673   mFolderTree->toggleColumn(KMFolderTree::total, true);
01674 }
01675 
01676 //-----------------------------------------------------------------------------
01677 void KMMainWidget::slotToggleSizeColumn()
01678 {
01679   mFolderTree->toggleColumn(KMFolderTree::foldersize);
01680 }
01681 
01682 
01683 //-----------------------------------------------------------------------------
01684 void KMMainWidget::slotJumpToFolder()
01685 {
01686   KMail::KMFolderSelDlg dlg( this, i18n("Jump to Folder"), true );
01687   KMFolder* dest;
01688 
01689   if (!dlg.exec()) return;
01690   if (!(dest = dlg.folder())) return;
01691 
01692   slotSelectFolder( dest );
01693 }
01694 
01695 //-----------------------------------------------------------------------------
01696 void KMMainWidget::slotMoveMsg()
01697 {
01698   KMail::KMFolderSelDlg dlg( this, i18n("Move Message to Folder"), true );
01699   KMFolder* dest;
01700 
01701   if (!dlg.exec()) return;
01702   if (!(dest = dlg.folder())) return;
01703 
01704   mHeaders->moveMsgToFolder(dest);
01705 }
01706 
01707 //-----------------------------------------------------------------------------
01708 void KMMainWidget::slotMoveMsgToFolder( KMFolder *dest)
01709 {
01710   mHeaders->moveMsgToFolder(dest);
01711 }
01712 
01713 //-----------------------------------------------------------------------------
01714 void KMMainWidget::slotCopyMsgToFolder( KMFolder *dest)
01715 {
01716   mHeaders->copyMsgToFolder(dest);
01717 }
01718 
01719 //-----------------------------------------------------------------------------
01720 void KMMainWidget::slotApplyFilters()
01721 {
01722   mHeaders->applyFiltersOnMsg();
01723 }
01724 
01725 //-----------------------------------------------------------------------------
01726 void KMMainWidget::slotCheckVacation()
01727 {
01728   updateVactionScriptStatus( false );
01729   if ( !kmkernel->askToGoOnline() )
01730     return;
01731 
01732   Vacation *vac = new Vacation( this, true /* check only */ );
01733   connect( vac, SIGNAL(scriptActive(bool)), SLOT(updateVactionScriptStatus(bool)) );
01734 }
01735 
01736 void KMMainWidget::slotEditVacation()
01737 {
01738   if ( !kmkernel->askToGoOnline() ) {
01739     return;
01740   }
01741 
01742   if ( mVacation )
01743     return;
01744 
01745   mVacation = new Vacation( this );
01746   connect( mVacation, SIGNAL(scriptActive(bool)), SLOT(updateVactionScriptStatus(bool)) );
01747   if ( mVacation->isUsable() ) {
01748     connect( mVacation, SIGNAL(result(bool)), mVacation, SLOT(deleteLater()) );
01749   } else {
01750     QString msg = i18n("KMail's Out of Office Reply functionality relies on "
01751                       "server-side filtering. You have not yet configured an "
01752                       "IMAP server for this.\n"
01753                       "You can do this on the \"Filtering\" tab of the IMAP "
01754                       "account configuration.");
01755     KMessageBox::sorry( this, msg, i18n("No Server-Side Filtering Configured") );
01756 
01757     delete mVacation; // QGuardedPtr sets itself to 0!
01758   }
01759 }
01760 
01761 //-----------------------------------------------------------------------------
01762 void KMMainWidget::slotDebugSieve()
01763 {
01764 #if !defined(NDEBUG)
01765   if ( mSieveDebugDialog )
01766     return;
01767 
01768   mSieveDebugDialog = new SieveDebugDialog( this );
01769   mSieveDebugDialog->exec();
01770   delete mSieveDebugDialog;
01771 #endif
01772 }
01773 
01774 //-----------------------------------------------------------------------------
01775 void KMMainWidget::slotStartCertManager()
01776 {
01777   KProcess certManagerProc; // save to create on the heap, since
01778   // there is no parent
01779   certManagerProc << "kleopatra";
01780 
01781   if( !certManagerProc.start( KProcess::DontCare ) )
01782     KMessageBox::error( this, i18n( "Could not start certificate manager; "
01783                                     "please check your installation." ),
01784                                     i18n( "KMail Error" ) );
01785   else
01786     kdDebug(5006) << "\nslotStartCertManager(): certificate manager started.\n" << endl;
01787   // process continues to run even after the KProcess object goes
01788   // out of scope here, since it is started in DontCare run mode.
01789 
01790 }
01791 
01792 //-----------------------------------------------------------------------------
01793 void KMMainWidget::slotStartWatchGnuPG()
01794 {
01795   KProcess certManagerProc;
01796   certManagerProc << "kwatchgnupg";
01797 
01798   if( !certManagerProc.start( KProcess::DontCare ) )
01799     KMessageBox::error( this, i18n( "Could not start GnuPG LogViewer (kwatchgnupg); "
01800                                     "please check your installation." ),
01801                                     i18n( "KMail Error" ) );
01802 }
01803 
01804 //-----------------------------------------------------------------------------
01805 void KMMainWidget::slotCopyMsg()
01806 {
01807   KMail::KMFolderSelDlg dlg( this, i18n("Copy Message to Folder"), true );
01808   KMFolder* dest;
01809 
01810   if (!dlg.exec()) return;
01811   if (!(dest = dlg.folder())) return;
01812 
01813   mHeaders->copyMsgToFolder(dest);
01814 }
01815 
01816 //-----------------------------------------------------------------------------
01817 void KMMainWidget::slotPrintMsg()
01818 {
01819   bool htmlOverride = mMsgView ? mMsgView->htmlOverride() : false;
01820   bool htmlLoadExtOverride = mMsgView ? mMsgView->htmlLoadExtOverride() : false;
01821   KConfigGroup reader( KMKernel::config(), "Reader" );
01822   bool useFixedFont = mMsgView ? mMsgView->isFixedFont()
01823                                : reader.readBoolEntry( "useFixedFont", false );
01824   KMCommand *command =
01825     new KMPrintCommand( this, mHeaders->currentMsg(),
01826                         htmlOverride, htmlLoadExtOverride,
01827                         useFixedFont, overrideEncoding() );
01828   command->start();
01829 }
01830 
01831 //-----------------------------------------------------------------------------
01832 void KMMainWidget::setupForwardActions()
01833 {
01834   disconnect( mForwardActionMenu, SIGNAL( activated() ), 0, 0 );
01835   mForwardActionMenu->remove( mForwardInlineAction );
01836   mForwardActionMenu->remove( mForwardAttachedAction );
01837 
01838   if ( GlobalSettings::self()->forwardingInlineByDefault() ) {
01839     mForwardActionMenu->insert( mForwardInlineAction, 0 );
01840     mForwardActionMenu->insert( mForwardAttachedAction, 1 );
01841     mForwardInlineAction->setShortcut( Key_F );
01842     mForwardAttachedAction->setShortcut( SHIFT+Key_F );
01843     connect( mForwardActionMenu, SIGNAL(activated()), this,
01844             SLOT(slotForwardInlineMsg()) );
01845 
01846   } else {
01847     mForwardActionMenu->insert( mForwardAttachedAction, 0 );
01848     mForwardActionMenu->insert( mForwardInlineAction, 1 );
01849     mForwardInlineAction->setShortcut( SHIFT+Key_F );
01850     mForwardAttachedAction->setShortcut( Key_F );
01851     connect( mForwardActionMenu, SIGNAL(activated()), this,
01852             SLOT(slotForwardAttachedMsg()) );
01853   }
01854 }
01855 
01856 //-----------------------------------------------------------------------------
01857 void KMMainWidget::slotConfigChanged()
01858 {
01859   readConfig();
01860   setupForwardActions();
01861   setupForwardingActionsList();
01862 }
01863 
01864 //-----------------------------------------------------------------------------
01865 void KMMainWidget::slotSaveMsg()
01866 {
01867   KMMessage *msg = mHeaders->currentMsg();
01868   if (!msg)
01869     return;
01870   KMSaveMsgCommand *saveCommand = new KMSaveMsgCommand( this,
01871     *mHeaders->selectedMsgs() );
01872 
01873   if (saveCommand->url().isEmpty())
01874     delete saveCommand;
01875   else
01876     saveCommand->start();
01877 }
01878 
01879 //-----------------------------------------------------------------------------
01880 void KMMainWidget::slotOpenMsg()
01881 {
01882   KMOpenMsgCommand *openCommand = new KMOpenMsgCommand( this, 0, overrideEncoding() );
01883 
01884   openCommand->start();
01885 }
01886 
01887 //-----------------------------------------------------------------------------
01888 void KMMainWidget::slotSaveAttachments()
01889 {
01890   KMMessage *msg = mHeaders->currentMsg();
01891   if (!msg)
01892     return;
01893   KMSaveAttachmentsCommand *saveCommand = new KMSaveAttachmentsCommand( this,
01894                                                                         *mHeaders->selectedMsgs() );
01895   saveCommand->start();
01896 }
01897 
01898 void KMMainWidget::slotOnlineStatus()
01899 {
01900   // KMKernel will emit a signal when we toggle the network state that is caught by
01901   // KMMainWidget::slotUpdateOnlineStatus to update our GUI
01902   if ( GlobalSettings::self()->networkState() == GlobalSettings::EnumNetworkState::Online ) {
01903     // if online; then toggle and set it offline.
01904     kmkernel->stopNetworkJobs();
01905   } else {
01906     kmkernel->resumeNetworkJobs();
01907   }
01908 }
01909 
01910 void KMMainWidget::slotUpdateOnlineStatus( GlobalSettings::EnumNetworkState::type )
01911 {
01912   if ( GlobalSettings::self()->networkState() == GlobalSettings::EnumNetworkState::Online )
01913     actionCollection()->action( "online_status" )->setText( i18n("Work Offline") );
01914   else
01915     actionCollection()->action( "online_status" )->setText( i18n("Work Online") );
01916 }
01917 
01918 
01919 //-----------------------------------------------------------------------------
01920 void KMMainWidget::slotSendQueued()
01921 {
01922   if ( !kmkernel->askToGoOnline() ) {
01923     return;
01924   }
01925 
01926   kmkernel->msgSender()->sendQueued();
01927 }
01928 
01929 //-----------------------------------------------------------------------------
01930 void KMMainWidget::slotSendQueuedVia( int item )
01931 {
01932   if ( !kmkernel->askToGoOnline() ) {
01933     return;
01934   }
01935 
01936   QStringList availTransports= KMail::TransportManager::transportNames();
01937   QString customTransport = availTransports[ item ];
01938 
01939   kmkernel->msgSender()->sendQueued( customTransport );
01940 }
01941 
01942 //-----------------------------------------------------------------------------
01943 void KMMainWidget::slotViewChange()
01944 {
01945   if(mBodyPartsMenu->isItemChecked(mBodyPartsMenu->idAt(0)))
01946   {
01947     mBodyPartsMenu->setItemChecked(mBodyPartsMenu->idAt(0),false);
01948     mBodyPartsMenu->setItemChecked(mBodyPartsMenu->idAt(1),true);
01949   }
01950   else if(mBodyPartsMenu->isItemChecked(mBodyPartsMenu->idAt(1)))
01951   {
01952     mBodyPartsMenu->setItemChecked(mBodyPartsMenu->idAt(1),false);
01953     mBodyPartsMenu->setItemChecked(mBodyPartsMenu->idAt(0),true);
01954   }
01955 
01956   //mMsgView->setInline(!mMsgView->isInline());
01957 }
01958 
01959 
01960 //-----------------------------------------------------------------------------
01961 void KMMainWidget::folderSelectedUnread( KMFolder* aFolder )
01962 {
01963   folderSelected( aFolder, true );
01964   slotChangeCaption( mFolderTree->currentItem() );
01965 }
01966 
01967 //-----------------------------------------------------------------------------
01968 void KMMainWidget::folderSelected()
01969 {
01970   folderSelected( mFolder );
01971   updateFolderMenu();
01972   // opened() before the getAndCheckFolder() in folderSelected
01973   if ( mFolder && mFolder->folderType() == KMFolderTypeImap )
01974     mFolder->close("mainwidget");
01975 }
01976 
01977 //-----------------------------------------------------------------------------
01978 void KMMainWidget::folderSelected( KMFolder* aFolder, bool forceJumpToUnread )
01979 {
01980   KCursorSaver busy(KBusyPtr::busy());
01981 
01982   if (mMsgView)
01983     mMsgView->clear(true);
01984 
01985   if ( mFolder && mFolder->folderType() == KMFolderTypeImap && !mFolder->noContent() )
01986   {
01987     KMFolderImap *imap = static_cast<KMFolderImap*>(mFolder->storage());
01988     if ( mFolder->needsCompacting() && imap->autoExpunge() )
01989       imap->expungeFolder(imap, true);
01990   }
01991 
01992   // Re-enable the msg list and quicksearch if we're showing a splash
01993   // screen. This is true either if there's no active folder, or if we
01994   // have a timer that is no longer active (i.e. it has already fired)
01995   // To make the if() a bit more complicated, we suppress the hiding
01996   // when the new folder is also an IMAP folder, because that's an
01997   // async operation and we don't want flicker if it results in just
01998   // a new splash.
01999   bool newFolder = ( (KMFolder*)mFolder != aFolder );
02000   bool isNewImapFolder = aFolder && aFolder->folderType() == KMFolderTypeImap && newFolder;
02001   if( !mFolder
02002       || ( !isNewImapFolder && mShowBusySplashTimer )
02003       || ( newFolder && mShowingOfflineScreen && !( isNewImapFolder && kmkernel->isOffline() ) ) ) {
02004     if ( mMsgView ) {
02005       mMsgView->enableMsgDisplay();
02006       mMsgView->clear( true );
02007     }
02008     if( mSearchAndHeaders && mHeaders )
02009       mSearchAndHeaders->show();
02010     mShowingOfflineScreen = false;
02011   }
02012 
02013   // Delete any pending timer, if needed it will be recreated below
02014   delete mShowBusySplashTimer;
02015   mShowBusySplashTimer = 0;
02016 
02017   if ( newFolder )
02018     writeFolderConfig();
02019   if ( mFolder ) {
02020     disconnect( mFolder, SIGNAL( changed() ),
02021            this, SLOT( updateMarkAsReadAction() ) );
02022     disconnect( mFolder, SIGNAL( msgHeaderChanged( KMFolder*, int ) ),
02023            this, SLOT( updateMarkAsReadAction() ) );
02024     disconnect( mFolder, SIGNAL( msgAdded( int ) ),
02025            this, SLOT( updateMarkAsReadAction() ) );
02026     disconnect( mFolder, SIGNAL( msgRemoved( KMFolder * ) ),
02027            this, SLOT( updateMarkAsReadAction() ) );
02028   }
02029 
02030   mFolder = aFolder;
02031 
02032   if ( aFolder && aFolder->folderType() == KMFolderTypeImap )
02033   {
02034     if ( kmkernel->isOffline() ) {
02035       showOfflinePage();
02036       return;
02037     }
02038     KMFolderImap *imap = static_cast<KMFolderImap*>(aFolder->storage());
02039     if ( newFolder && !mFolder->noContent() )
02040     {
02041       imap->open("mainwidget"); // will be closed in the folderSelected slot
02042       // first get new headers before we select the folder
02043       imap->setSelected( true );
02044       connect( imap, SIGNAL( folderComplete( KMFolderImap*, bool ) ),
02045           this, SLOT( folderSelected() ) );
02046       imap->getAndCheckFolder();
02047       mHeaders->setFolder( 0 );
02048       updateFolderMenu();
02049       mForceJumpToUnread = forceJumpToUnread;
02050 
02051       // Set a timer to show a splash screen if fetching folder contents
02052       // takes more than the amount of seconds configured in the kmailrc (default 1000 msec)
02053       mShowBusySplashTimer = new QTimer( this );
02054       connect( mShowBusySplashTimer, SIGNAL( timeout() ), this, SLOT( slotShowBusySplash() ) );
02055       mShowBusySplashTimer->start( GlobalSettings::self()->folderLoadingTimeout(), true );
02056       return;
02057     } else {
02058       // the folder is complete now - so go ahead
02059       disconnect( imap, SIGNAL( folderComplete( KMFolderImap*, bool ) ),
02060           this, SLOT( folderSelected() ) );
02061       forceJumpToUnread = mForceJumpToUnread;
02062     }
02063   }
02064 
02065   if ( mFolder ) { // == 0 -> pointing to toplevel ("Welcome to KMail") folder
02066     connect( mFolder, SIGNAL( changed() ),
02067            this, SLOT( updateMarkAsReadAction() ) );
02068     connect( mFolder, SIGNAL( msgHeaderChanged( KMFolder*, int ) ),
02069            this, SLOT( updateMarkAsReadAction() ) );
02070     connect( mFolder, SIGNAL( msgAdded( int ) ),
02071            this, SLOT( updateMarkAsReadAction() ) );
02072     connect( mFolder, SIGNAL( msgRemoved(KMFolder *) ),
02073            this, SLOT( updateMarkAsReadAction() ) );
02074   }
02075   readFolderConfig();
02076   if (mMsgView)
02077   {
02078     mMsgView->setHtmlOverride(mFolderHtmlPref);
02079     mMsgView->setHtmlLoadExtOverride(mFolderHtmlLoadExtPref);
02080   }
02081   mHeaders->setFolder( mFolder, forceJumpToUnread );
02082   updateMessageActions();
02083   updateFolderMenu();
02084   if (!aFolder)
02085     slotIntro();
02086 }
02087 
02088 //-----------------------------------------------------------------------------
02089 void KMMainWidget::slotShowBusySplash()
02090 {
02091   if ( mReaderWindowActive )
02092   {
02093     mMsgView->displayBusyPage();
02094     // hide widgets that are in the way:
02095     if ( mSearchAndHeaders && mHeaders && mLongFolderList )
02096       mSearchAndHeaders->hide();
02097   }
02098 }
02099 
02100 void KMMainWidget::showOfflinePage()
02101 {
02102   if ( !mReaderWindowActive ) return;
02103   mShowingOfflineScreen = true;
02104 
02105   mMsgView->displayOfflinePage();
02106   // hide widgets that are in the way:
02107   if ( mSearchAndHeaders && mHeaders && mLongFolderList )
02108     mSearchAndHeaders->hide();
02109 }
02110 
02111 //-----------------------------------------------------------------------------
02112 void KMMainWidget::slotMsgSelected(KMMessage *msg)
02113 {
02114   if ( msg && msg->parent() && !msg->isComplete() )
02115   {
02116     if ( msg->transferInProgress() )
02117       return;
02118     mMsgView->clear();
02119     mMsgView->setWaitingForSerNum( msg->getMsgSerNum() );
02120 
02121     if ( mJob ) {
02122        disconnect( mJob, 0, mMsgView, 0 );
02123        delete mJob;
02124     }
02125     mJob = msg->parent()->createJob( msg, FolderJob::tGetMessage, 0,
02126           "STRUCTURE", mMsgView->attachmentStrategy() );
02127     connect(mJob, SIGNAL(messageRetrieved(KMMessage*)),
02128             mMsgView, SLOT(slotMessageArrived(KMMessage*)));
02129     mJob->start();
02130   } else {
02131     mMsgView->setMsg(msg);
02132   }
02133   // reset HTML override to the folder setting
02134   mMsgView->setHtmlOverride(mFolderHtmlPref);
02135   mMsgView->setHtmlLoadExtOverride(mFolderHtmlLoadExtPref);
02136   mMsgView->setDecryptMessageOverwrite( false );
02137   mMsgView->setShowSignatureDetails( false );
02138 }
02139 
02140 //-----------------------------------------------------------------------------
02141 void KMMainWidget::slotMsgChanged()
02142 {
02143   mHeaders->msgChanged();
02144 }
02145 
02146 //-----------------------------------------------------------------------------
02147 void KMMainWidget::slotSelectFolder(KMFolder* folder)
02148 {
02149   QListViewItem* item = mFolderTree->indexOfFolder(folder);
02150   if ( item ) {
02151     mFolderTree->ensureItemVisible( item );
02152     mFolderTree->doFolderSelected( item );
02153   }
02154 }
02155 
02156 //-----------------------------------------------------------------------------
02157 void KMMainWidget::slotSelectMessage(KMMessage* msg)
02158 {
02159   int idx = mFolder->find(msg);
02160   if (idx != -1) {
02161     mHeaders->setCurrentMsg(idx);
02162     if (mMsgView)
02163       mMsgView->setMsg(msg);
02164     else
02165       slotMsgActivated(msg);
02166   }
02167 }
02168 
02169 //-----------------------------------------------------------------------------
02170 void KMMainWidget::slotReplaceMsgByUnencryptedVersion()
02171 {
02172   kdDebug(5006) << "KMMainWidget::slotReplaceMsgByUnencryptedVersion()" << endl;
02173   KMMessage* oldMsg = mHeaders->currentMsg();
02174   if( oldMsg ) {
02175     kdDebug(5006) << "KMMainWidget  -  old message found" << endl;
02176     if( oldMsg->hasUnencryptedMsg() ) {
02177       kdDebug(5006) << "KMMainWidget  -  extra unencrypted message found" << endl;
02178       KMMessage* newMsg = oldMsg->unencryptedMsg();
02179       // adjust the message id
02180       {
02181         QString msgId( oldMsg->msgId() );
02182         QString prefix("DecryptedMsg.");
02183         int oldIdx = msgId.find(prefix, 0, false);
02184         if( -1 == oldIdx ) {
02185           int leftAngle = msgId.findRev( '<' );
02186           msgId = msgId.insert( (-1 == leftAngle) ? 0 : ++leftAngle, prefix );
02187         }
02188         else {
02189           // toggle between "DecryptedMsg." and "DeCryptedMsg."
02190           // to avoid same message id
02191           QCharRef c = msgId[ oldIdx+2 ];
02192           if( 'C' == c )
02193             c = 'c';
02194           else
02195             c = 'C';
02196         }
02197         newMsg->setMsgId( msgId );
02198         mMsgView->setIdOfLastViewedMessage( msgId );
02199       }
02200       // insert the unencrypted message
02201       kdDebug(5006) << "KMMainWidget  -  adding unencrypted message to folder" << endl;
02202       mFolder->addMsg( newMsg );
02203       /* Figure out its index in the folder for selecting. This must be count()-1,
02204        * since we append. Be safe and do find, though, just in case. */
02205       int newMsgIdx = mFolder->find( newMsg );
02206       Q_ASSERT( newMsgIdx != -1 );
02207       /* we need this unget, to have the message displayed correctly initially */
02208       mFolder->unGetMsg( newMsgIdx );
02209       int idx = mFolder->find( oldMsg );
02210       Q_ASSERT( idx != -1 );
02211       /* only select here, so the old one is not un-Gotten before, which would
02212        * render the pointer we hold invalid so that find would fail */
02213       mHeaders->setCurrentItemByIndex( newMsgIdx );
02214       // remove the old one
02215       if ( idx != -1 ) {
02216         kdDebug(5006) << "KMMainWidget  -  deleting encrypted message" << endl;
02217         mFolder->take( idx );
02218       }
02219 
02220       kdDebug(5006) << "KMMainWidget  -  updating message actions" << endl;
02221       updateMessageActions();
02222 
02223       kdDebug(5006) << "KMMainWidget  -  done." << endl;
02224     } else
02225       kdDebug(5006) << "KMMainWidget  -  NO EXTRA UNENCRYPTED MESSAGE FOUND" << endl;
02226   } else
02227     kdDebug(5006) << "KMMainWidget  -  PANIC: NO OLD MESSAGE FOUND" << endl;
02228 }
02229 
02230 //-----------------------------------------------------------------------------
02231 void KMMainWidget::slotSetThreadStatusNew()
02232 {
02233   mHeaders->setThreadStatus(KMMsgStatusNew);
02234 }
02235 
02236 //-----------------------------------------------------------------------------
02237 void KMMainWidget::slotSetThreadStatusUnread()
02238 {
02239   mHeaders->setThreadStatus(KMMsgStatusUnread);
02240 }
02241 
02242 //-----------------------------------------------------------------------------
02243 void KMMainWidget::slotSetThreadStatusFlag()
02244 {
02245   mHeaders->setThreadStatus(KMMsgStatusFlag, true);
02246 }
02247 
02248 //-----------------------------------------------------------------------------
02249 void KMMainWidget::slotSetThreadStatusRead()
02250 {
02251   mHeaders->setThreadStatus(KMMsgStatusRead);
02252 }
02253 
02254 //-----------------------------------------------------------------------------
02255 void KMMainWidget::slotSetThreadStatusTodo()
02256 {
02257   mHeaders->setThreadStatus(KMMsgStatusTodo, true);
02258 }
02259 
02260 //-----------------------------------------------------------------------------
02261 void KMMainWidget::slotSetThreadStatusWatched()
02262 {
02263   mHeaders->setThreadStatus(KMMsgStatusWatched, true);
02264   if (mWatchThreadAction->isChecked()) {
02265     mIgnoreThreadAction->setChecked(false);
02266   }
02267 }
02268 
02269 //-----------------------------------------------------------------------------
02270 void KMMainWidget::slotSetThreadStatusIgnored()
02271 {
02272   mHeaders->setThreadStatus(KMMsgStatusIgnored, true);
02273   if (mIgnoreThreadAction->isChecked()) {
02274     mWatchThreadAction->setChecked(false);
02275   }
02276 }
02277 
02278 //-----------------------------------------------------------------------------
02279 void KMMainWidget::slotNextMessage()       { mHeaders->nextMessage(); }
02280 void KMMainWidget::slotNextUnreadMessage()
02281 {
02282   if ( !mHeaders->nextUnreadMessage() )
02283     if ( GlobalSettings::self()->loopOnGotoUnread() == GlobalSettings::EnumLoopOnGotoUnread::LoopInAllFolders )
02284       mFolderTree->nextUnreadFolder(true);
02285 }
02286 void KMMainWidget::slotNextImportantMessage() {
02287   //mHeaders->nextImportantMessage();
02288 }
02289 void KMMainWidget::slotPrevMessage()       { mHeaders->prevMessage(); }
02290 void KMMainWidget::slotPrevUnreadMessage()
02291 {
02292   if ( !mHeaders->prevUnreadMessage() )
02293     if ( GlobalSettings::self()->loopOnGotoUnread() == GlobalSettings::EnumLoopOnGotoUnread::LoopInAllFolders )
02294       mFolderTree->prevUnreadFolder();
02295 }
02296 void KMMainWidget::slotPrevImportantMessage() {
02297   //mHeaders->prevImportantMessage();
02298 }
02299 
02300 void KMMainWidget::slotDisplayCurrentMessage()
02301 {
02302   if ( mHeaders->currentMsg() )
02303     slotMsgActivated( mHeaders->currentMsg() );
02304 }
02305 
02306 //-----------------------------------------------------------------------------
02307 void KMMainWidget::slotMsgActivated(KMMessage *msg)
02308 {
02309   if ( !msg ) return;
02310   if ( msg->parent() && !msg->isComplete() ) {
02311     FolderJob *job = msg->parent()->createJob( msg );
02312     connect( job, SIGNAL( messageRetrieved( KMMessage* ) ),
02313              SLOT( slotMsgActivated( KMMessage* ) ) );
02314     job->start();
02315     return;
02316   }
02317 
02318   if (kmkernel->folderIsDraftOrOutbox( mFolder ) ) {
02319     mMsgActions->editCurrentMessage();
02320     return;
02321   }
02322   if ( kmkernel->folderIsTemplates( mFolder ) ) {
02323     slotUseTemplate();
02324     return;
02325   }
02326 
02327   assert( msg != 0 );
02328   KMReaderMainWin *win = new KMReaderMainWin( mFolderHtmlPref, mFolderHtmlLoadExtPref );
02329   KConfigGroup reader( KMKernel::config(), "Reader" );
02330   bool useFixedFont = mMsgView ? mMsgView->isFixedFont()
02331                                : reader.readBoolEntry( "useFixedFont", false );
02332   win->setUseFixedFont( useFixedFont );
02333   KMMessage *newMessage = new KMMessage(*msg);
02334   newMessage->setParent( msg->parent() );
02335   newMessage->setMsgSerNum( msg->getMsgSerNum() );
02336   newMessage->setReadyToShow( true );
02337   win->showMsg( overrideEncoding(), newMessage );
02338   win->show();
02339 }
02340 
02341 //-----------------------------------------------------------------------------
02342 void KMMainWidget::slotMarkAll()
02343 {
02344   mHeaders->selectAll( true );
02345 }
02346 
02347 //-----------------------------------------------------------------------------
02348 void KMMainWidget::slotMsgPopup(KMMessage&, const KURL &aUrl, const QPoint& aPoint)
02349 {
02350   KPopupMenu * menu = new KPopupMenu;
02351   updateMessageMenu();
02352   mUrlCurrent = aUrl;
02353 
02354   bool urlMenuAdded = false;
02355 
02356   if (!aUrl.isEmpty())
02357   {
02358     if (aUrl.protocol() == "mailto")
02359     {
02360       // popup on a mailto URL
02361       mMsgView->mailToComposeAction()->plug( menu );
02362       mMsgView->mailToReplyAction()->plug( menu );
02363       mMsgView->mailToForwardAction()->plug( menu );
02364 
02365       menu->insertSeparator();
02366       mMsgView->addAddrBookAction()->plug( menu );
02367       mMsgView->openAddrBookAction()->plug( menu );
02368       mMsgView->copyURLAction()->plug( menu );
02369       mMsgView->startImChatAction()->plug( menu );
02370       // only enable if our KIMProxy is functional
02371       mMsgView->startImChatAction()->setEnabled( kmkernel->imProxy()->initialize() );
02372 
02373     } else {
02374       // popup on a not-mailto URL
02375       mMsgView->urlOpenAction()->plug( menu );
02376       mMsgView->addBookmarksAction()->plug( menu );
02377       mMsgView->urlSaveAsAction()->plug( menu );
02378       mMsgView->copyURLAction()->plug( menu );
02379     }
02380     if ( aUrl.protocol() == "im" )
02381     {
02382       // popup on an IM address
02383       // no need to check the KIMProxy is initialized, as these protocols will
02384       // only be present if it is.
02385       mMsgView->startImChatAction()->plug( menu );
02386     }
02387 
02388     urlMenuAdded=true;
02389     kdDebug( 0 ) << k_funcinfo << " URL is: " << aUrl << endl;
02390   }
02391 
02392 
02393   if(mMsgView && !mMsgView->copyText().isEmpty()) {
02394     if ( urlMenuAdded )
02395       menu->insertSeparator();
02396     mMsgActions->replyMenu()->plug(menu);
02397     menu->insertSeparator();
02398 
02399     mMsgView->copyAction()->plug( menu );
02400     mMsgView->selectAllAction()->plug( menu );
02401   } else  if ( !urlMenuAdded )
02402   {
02403     // popup somewhere else (i.e., not a URL) on the message
02404 
02405     if (!mHeaders->currentMsg()) // no messages
02406     {
02407       delete menu;
02408       return;
02409     }
02410 
02411 
02412     if ( mFolder->isTemplates() ) {
02413       mUseAction->plug( menu );
02414     } else {
02415       mMsgActions->replyMenu()->plug( menu );
02416       mForwardActionMenu->plug( menu );
02417     }
02418     editAction()->plug(menu);
02419     menu->insertSeparator();
02420 
02421     mCopyActionMenu->plug( menu );
02422     mMoveActionMenu->plug( menu );
02423 
02424     menu->insertSeparator();
02425 
02426     mMsgActions->messageStatusMenu()->plug( menu );
02427     menu->insertSeparator();
02428 
02429     viewSourceAction()->plug(menu);
02430     if(mMsgView) {
02431       mMsgView->toggleFixFontAction()->plug(menu);
02432     }
02433     menu->insertSeparator();
02434     mPrintAction->plug( menu );
02435     mSaveAsAction->plug( menu );
02436     mSaveAttachmentsAction->plug( menu );
02437 
02438     menu->insertSeparator();
02439     if( mFolder->isTrash() )
02440       mDeleteAction->plug( menu );
02441     else
02442       mTrashAction->plug( menu );
02443 
02444     menu->insertSeparator();
02445     mMsgActions->createTodoAction()->plug( menu );
02446   }
02447   KAcceleratorManager::manage(menu);
02448   menu->exec(aPoint, 0);
02449   delete menu;
02450 }
02451 
02452 //-----------------------------------------------------------------------------
02453 void KMMainWidget::getAccountMenu()
02454 {
02455   QStringList actList;
02456 
02457   mActMenu->clear();
02458   actList = kmkernel->acctMgr()->getAccounts();
02459   QStringList::Iterator it;
02460   int id = 0;
02461   for(it = actList.begin(); it != actList.end() ; ++it, id++)
02462     mActMenu->insertItem((*it).replace("&", "&&"), id);
02463 }
02464 
02465 //-----------------------------------------------------------------------------
02466 void KMMainWidget::getTransportMenu()
02467 {
02468   QStringList availTransports;
02469 
02470   mSendMenu->clear();
02471   availTransports = KMail::TransportManager::transportNames();
02472   QStringList::Iterator it;
02473   int id = 0;
02474   for(it = availTransports.begin(); it != availTransports.end() ; ++it, id++)
02475     mSendMenu->insertItem((*it).replace("&", "&&"), id);
02476 }
02477 
02478 //-----------------------------------------------------------------------------
02479 void KMMainWidget::updateCustomTemplateMenus()
02480 {
02481   if ( !mCustomTemplateActions.isEmpty() ) {
02482     QPtrList<KAction>::iterator ait = mCustomTemplateActions.begin();
02483     for ( ; ait != mCustomTemplateActions.end() ; ++ait ) {
02484       (*ait)->unplugAll();
02485       delete (*ait);
02486     }
02487     mCustomTemplateActions.clear();
02488   }
02489 
02490   delete mCustomReplyActionMenu;
02491   delete mCustomReplyAllActionMenu;
02492   delete mCustomForwardActionMenu;
02493 
02494   delete mCustomReplyMapper;
02495   delete mCustomReplyAllMapper;
02496   delete mCustomForwardMapper;
02497 
02498   mCustomForwardActionMenu =
02499     new KActionMenu( i18n("Forward With Custom Template"),
02500                      "mail_custom_forward",
02501                      actionCollection(), "custom_forward" );
02502   QSignalMapper *mCustomForwardMapper = new QSignalMapper( this );
02503   connect( mCustomForwardMapper, SIGNAL( mapped( int ) ),
02504            this, SLOT( slotCustomForwardMsg( int ) ) );
02505   mForwardActionMenu->insert( mCustomForwardActionMenu );
02506 
02507   mCustomReplyActionMenu =
02508     new KActionMenu( i18n("Reply With Custom Template"), "mail_custom_reply",
02509                      actionCollection(), "custom_reply" );
02510   QSignalMapper *mCustomReplyMapper = new QSignalMapper( this );
02511   connect( mCustomReplyMapper, SIGNAL( mapped( int ) ),
02512            this, SLOT( slotCustomReplyToMsg( int ) ) );
02513   mMsgActions->replyMenu()->insert( mCustomReplyActionMenu );
02514 
02515   mCustomReplyAllActionMenu =
02516     new KActionMenu( i18n("Reply to All With Custom Template"),
02517                      "mail_custom_reply_all",
02518                      actionCollection(), "custom_reply_all" );
02519   QSignalMapper *mCustomReplyAllMapper = new QSignalMapper( this );
02520   connect( mCustomReplyAllMapper, SIGNAL( mapped( int ) ),
02521            this, SLOT( slotCustomReplyAllToMsg( int ) ) );
02522   mMsgActions->replyMenu()->insert( mCustomReplyAllActionMenu );
02523 
02524   mCustomTemplates.clear();
02525 
02526   QStringList list = GlobalSettingsBase::self()->customTemplates();
02527   QStringList::iterator it = list.begin();
02528   int idx = 0;
02529   int replyc = 0;
02530   int replyallc = 0;
02531   int forwardc = 0;
02532   for ( ; it != list.end(); ++it ) {
02533     CTemplates t( *it );
02534     mCustomTemplates.append( *it );
02535 
02536     KAction *action;
02537     switch ( t.type() ) {
02538     case CustomTemplates::TReply:
02539       action = new KAction( (*it).replace( "&", "&&" ),
02540                             KShortcut( t.shortcut() ),
02541                             mCustomReplyMapper,
02542                             SLOT( map() ),
02543                             actionCollection(),
02544                             (*it).utf8() );
02545       mCustomReplyMapper->setMapping( action, idx );
02546       mCustomReplyActionMenu->insert( action, idx );
02547       mCustomTemplateActions.append( action );
02548       ++replyc;
02549       break;
02550     case CustomTemplates::TReplyAll:
02551       action = new KAction( (*it).replace( "&", "&&" ),
02552                             KShortcut( t.shortcut() ),
02553                             mCustomReplyAllMapper,
02554                             SLOT( map() ),
02555                             actionCollection(),
02556                             (*it).utf8() );
02557       mCustomReplyAllMapper->setMapping( action, idx );
02558       mCustomReplyAllActionMenu->insert( action, idx );
02559       mCustomTemplateActions.append( action );
02560       ++replyallc;
02561       break;
02562     case CustomTemplates::TForward:
02563       action = new KAction( (*it).replace( "&", "&&" ),
02564                             KShortcut( t.shortcut() ),
02565                             mCustomForwardMapper,
02566                             SLOT( map() ),
02567                             actionCollection(),
02568                             (*it).utf8() );
02569       mCustomForwardMapper->setMapping( action, idx );
02570       mCustomForwardActionMenu->insert( action, idx );
02571       mCustomTemplateActions.append( action );
02572       ++forwardc;
02573       break;
02574     case CustomTemplates::TUniversal:
02575       action = new KAction( (*it).replace( "&", "&&" ),
02576                             KShortcut::null(),
02577                             mCustomReplyMapper,
02578                             SLOT( map() ),
02579                             actionCollection(),
02580                             (*it).utf8() );
02581       mCustomReplyMapper->setMapping( action, idx );
02582       mCustomReplyActionMenu->insert( action, idx );
02583       mCustomTemplateActions.append( action );
02584       ++replyc;
02585       action = new KAction( (*it).replace( "&", "&&" ),
02586                             KShortcut::null(),
02587                             mCustomReplyAllMapper,
02588                             SLOT( map() ),
02589                             actionCollection(),
02590                             (*it).utf8() );
02591       mCustomReplyAllMapper->setMapping( action, idx );
02592       mCustomReplyAllActionMenu->insert( action, idx );
02593       mCustomTemplateActions.append( action );
02594       ++replyallc;
02595       action = new KAction( (*it).replace( "&", "&&" ),
02596                             KShortcut::null(),
02597                             mCustomForwardMapper,
02598                             SLOT( map() ),
02599                             actionCollection(),
02600                             (*it).utf8() );
02601       mCustomForwardMapper->setMapping( action, idx );
02602       mCustomForwardActionMenu->insert( action, idx );
02603       mCustomTemplateActions.append( action );
02604       ++forwardc;
02605       break;
02606     }
02607 
02608     ++idx;
02609   }
02610   if ( !replyc ) {
02611       mCustomReplyActionMenu->popupMenu()->insertItem( i18n( "(no custom templates)" ), 0 );
02612       mCustomReplyActionMenu->popupMenu()->setItemEnabled( 0, false );
02613       mCustomReplyActionMenu->setEnabled(false);
02614   }
02615   if ( !replyallc ) {
02616       mCustomReplyAllActionMenu->popupMenu()->insertItem( i18n( "(no custom templates)" ), 0 );
02617       mCustomReplyAllActionMenu->popupMenu()->setItemEnabled( 0, false );
02618       mCustomReplyAllActionMenu->setEnabled(false);
02619   }
02620   if ( !forwardc ) {
02621       mCustomForwardActionMenu->popupMenu()->insertItem( i18n( "(no custom templates)" ), 0 );
02622       mCustomForwardActionMenu->popupMenu()->setItemEnabled( 0, false );
02623       mCustomForwardActionMenu->setEnabled(false);
02624   }
02625 
02626 }
02627 
02628 
02629 //-----------------------------------------------------------------------------
02630 void KMMainWidget::setupActions()
02631 {
02632   mMsgActions = new KMail::MessageActions( actionCollection(), this );
02633   mMsgActions->setMessageView( mMsgView );
02634 
02635   //----- File Menu
02636   mSaveAsAction = new KAction( i18n("Save &As..."), "filesave",
02637     KStdAccel::shortcut(KStdAccel::Save),
02638     this, SLOT(slotSaveMsg()), actionCollection(), "file_save_as" );
02639 
02640   mOpenAction = KStdAction::open( this, SLOT( slotOpenMsg() ),
02641                                   actionCollection() );
02642 
02643   (void) new KAction( i18n("&Compact All Folders"), 0,
02644               this, SLOT(slotCompactAll()),
02645               actionCollection(), "compact_all_folders" );
02646 
02647   (void) new KAction( i18n("&Expire All Folders"), 0,
02648               this, SLOT(slotExpireAll()),
02649               actionCollection(), "expire_all_folders" );
02650 
02651   (void) new KAction( i18n("&Refresh Local IMAP Cache"), "refresh",
02652               this, SLOT(slotInvalidateIMAPFolders()),
02653               actionCollection(), "file_invalidate_imap_cache" );
02654 
02655   (void) new KAction( i18n("Empty All &Trash Folders"), 0,
02656               KMKernel::self(), SLOT(slotEmptyTrash()),
02657               actionCollection(), "empty_trash" );
02658 
02659   (void) new KAction( i18n("Check &Mail"), "mail_get", CTRL+Key_L,
02660               this, SLOT(slotCheckMail()),
02661               actionCollection(), "check_mail" );
02662 
02663   mFavoritesCheckMailAction = new KAction( i18n("Check Mail in Favorite Folders"),
02664               "mail_get", CTRL+SHIFT+Key_L, 0, 0,
02665               actionCollection(), "favorite_check_mail" );
02666   if ( mFavoriteFolderView )
02667     connect( mFavoritesCheckMailAction, SIGNAL(activated()), mFavoriteFolderView, SLOT(checkMail()) );
02668 
02669   KActionMenu *actActionMenu = new
02670     KActionMenu( i18n("Check Mail &In"), "mail_get", actionCollection(),
02671                     "check_mail_in" );
02672   actActionMenu->setDelayed(true); //needed for checking "all accounts"
02673 
02674   connect(actActionMenu,SIGNAL(activated()),this,SLOT(slotCheckMail()));
02675 
02676   mActMenu = actActionMenu->popupMenu();
02677   connect(mActMenu,SIGNAL(activated(int)),this,SLOT(slotCheckOneAccount(int)));
02678   connect(mActMenu,SIGNAL(aboutToShow()),this,SLOT(getAccountMenu()));
02679 
02680   (void) new KAction( i18n("&Send Queued Messages"), "mail_send", 0, this,
02681              SLOT(slotSendQueued()), actionCollection(), "send_queued");
02682 
02683   (void) new KAction( i18n("Online Status (unknown)"), "online_status", 0, this,
02684                      SLOT(slotOnlineStatus()), actionCollection(), "online_status");
02685 
02686   KActionMenu *sendActionMenu = new
02687     KActionMenu( i18n("Send Queued Messages Via"), "mail_send_via", actionCollection(),
02688                                        "send_queued_via" );
02689   sendActionMenu->setDelayed(true);
02690 
02691   mSendMenu = sendActionMenu->popupMenu();
02692   connect(mSendMenu,SIGNAL(activated(int)), this, SLOT(slotSendQueuedVia(int)));
02693   connect(mSendMenu,SIGNAL(aboutToShow()),this,SLOT(getTransportMenu()));
02694 
02695   KAction *act;
02696   //----- Tools menu
02697   if (parent()->inherits("KMMainWin")) {
02698     act =  new KAction( i18n("&Address Book..."), "contents", 0, this,
02699             SLOT(slotAddrBook()), actionCollection(), "addressbook" );
02700     if (KStandardDirs::findExe("kaddressbook").isEmpty()) act->setEnabled(false);
02701   }
02702 
02703   act = new KAction( i18n("Certificate Manager..."), "pgp-keys", 0, this,
02704              SLOT(slotStartCertManager()), actionCollection(), "tools_start_certman");
02705   // disable action if no certman binary is around
02706   if (KStandardDirs::findExe("kleopatra").isEmpty()) act->setEnabled(false);
02707 
02708   act = new KAction( i18n("GnuPG Log Viewer..."), "pgp-keys", 0, this,
02709              SLOT(slotStartWatchGnuPG()), actionCollection(), "tools_start_kwatchgnupg");
02710   // disable action if no kwatchgnupg binary is around
02711   if (KStandardDirs::findExe("kwatchgnupg").isEmpty()) act->setEnabled(false);
02712 
02713   act = new KAction( i18n("&Import Messages..."), "fileopen", 0, this,
02714              SLOT(slotImport()), actionCollection(), "import" );
02715   if (KStandardDirs::findExe("kmailcvt").isEmpty()) act->setEnabled(false);
02716 
02717 #if !defined(NDEBUG)
02718   (void) new KAction( i18n("&Debug Sieve..."),
02719               "idea", 0, this, SLOT(slotDebugSieve()),
02720               actionCollection(), "tools_debug_sieve" );
02721 #endif
02722 
02723   if ( GlobalSettings::allowOutOfOfficeSettings() ) {
02724       (void) new KAction( i18n("Edit \"Out of Office\" Replies..."),
02725               "configure", 0, this, SLOT(slotEditVacation()),
02726               actionCollection(), "tools_edit_vacation" );
02727 
02728   }
02729 
02730   (void) new KAction( i18n("Filter &Log Viewer..."), 0, this,
02731               SLOT(slotFilterLogViewer()), actionCollection(), "filter_log_viewer" );
02732 
02733   (void) new KAction( i18n("&Anti-Spam Wizard..."), 0, this,
02734               SLOT(slotAntiSpamWizard()), actionCollection(), "antiSpamWizard" );
02735   (void) new KAction( i18n("&Anti-Virus Wizard..."), 0, this,
02736               SLOT(slotAntiVirusWizard()), actionCollection(), "antiVirusWizard" );
02737 
02738   //----- Edit Menu
02739   mTrashAction = new KAction( KGuiItem( i18n("&Move to Trash"), "edittrash",
02740                                        i18n("Move message to trashcan") ),
02741                              Key_Delete, this, SLOT(slotTrashMsg()),
02742                              actionCollection(), "move_to_trash" );
02743 
02744   /* The delete action is nowhere in the gui, by default, so we need to make
02745    * sure it is plugged into the KAccel now, since that won't happen on
02746    * XMLGui construction or manual ->plug(). This is only a problem when run
02747    * as a part, though. */
02748   mDeleteAction = new KAction( i18n("&Delete"), "editdelete", SHIFT+Key_Delete, this,
02749                               SLOT(slotDeleteMsg()), actionCollection(), "delete" );
02750   mDeleteAction->plugAccel( actionCollection()->kaccel() );
02751 
02752   mTrashThreadAction = new KAction( KGuiItem( i18n("M&ove Thread to Trash"), "edittrash",
02753                                        i18n("Move thread to trashcan") ),
02754                              CTRL+Key_Delete, this, SLOT(slotTrashThread()),
02755                              actionCollection(), "move_thread_to_trash" );
02756 
02757   mDeleteThreadAction = new KAction( i18n("Delete T&hread"), "editdelete", CTRL+SHIFT+Key_Delete, this,
02758                               SLOT(slotDeleteThread()), actionCollection(), "delete_thread" );
02759 
02760 
02761   (void) new KAction( i18n("&Find Messages..."), "mail_find", Key_S, this,
02762               SLOT(slotRequestFullSearchFromQuickSearch()), actionCollection(), "search_messages" );
02763 
02764   mFindInMessageAction = new KAction( i18n("&Find in Message..."), "find", KStdAccel::shortcut(KStdAccel::Find), this,
02765               SLOT(slotFind()), actionCollection(), "find_in_messages" );
02766 
02767   (void) new KAction( i18n("Select &All Messages"), KStdAccel::selectAll(), this,
02768               SLOT(slotMarkAll()), actionCollection(), "mark_all_messages" );
02769 
02770   //----- Folder Menu
02771   mNewFolderAction = new KAction( i18n("&New Folder..."), "folder_new", 0, mFolderTree,
02772               SLOT(addChildFolder()), actionCollection(), "new_folder" );
02773 
02774   mModifyFolderAction = new KAction( i18n("&Properties"), "configure", 0, this,
02775               SLOT(slotModifyFolder()), actionCollection(), "modify" );
02776 
02777   mFolderMailingListPropertiesAction = new KAction( i18n("&Mailing List Management..."),
02778       /*"folder_mailinglist_properties",*/ 0, this, SLOT( slotFolderMailingListProperties() ),
02779       actionCollection(), "folder_mailinglist_properties" );
02780 
02781   mFolderShortCutCommandAction = new KAction( i18n("&Assign Shortcut..."), "configure_shortcuts",
02782                       0, this, SLOT( slotFolderShortcutCommand() ), actionCollection(),
02783                       "folder_shortcut_command" );
02784 
02785 
02786   mMarkAllAsReadAction = new KAction( i18n("Mark All Messages as &Read"), "goto", 0, this,
02787               SLOT(slotMarkAllAsRead()), actionCollection(), "mark_all_as_read" );
02788 
02789   mExpireFolderAction = new KAction(i18n("&Expiration Settings"), 0, this, SLOT(slotExpireFolder()),
02790                    actionCollection(), "expire");
02791 
02792   mCompactFolderAction = new KAction( i18n("&Compact Folder"), 0, this,
02793               SLOT(slotCompactFolder()), actionCollection(), "compact" );
02794 
02795   mRefreshFolderAction = new KAction( i18n("Check Mail &in This Folder"), "reload",
02796                                       KStdAccel::shortcut( KStdAccel::Reload ), this,
02797                                       SLOT(slotRefreshFolder()),
02798                                       actionCollection(), "refresh_folder" );
02799   mTroubleshootFolderAction = 0; // set in initializeIMAPActions
02800 
02801   mEmptyFolderAction = new KAction( "foo" /*set in updateFolderMenu*/, "edittrash", 0, this,
02802               SLOT(slotEmptyFolder()), actionCollection(), "empty" );
02803 
02804   mRemoveFolderAction = new KAction( "foo" /*set in updateFolderMenu*/, "editdelete", 0, this,
02805               SLOT(slotRemoveFolder()), actionCollection(), "delete_folder" );
02806 
02807   mPreferHtmlAction = new KToggleAction( i18n("Prefer &HTML to Plain Text"), 0, this,
02808               SLOT(slotOverrideHtml()), actionCollection(), "prefer_html" );
02809 
02810   mPreferHtmlLoadExtAction = new KToggleAction( i18n("Load E&xternal References"), 0, this,
02811               SLOT(slotOverrideHtmlLoadExt()), actionCollection(), "prefer_html_external_refs" );
02812 
02813   mThreadMessagesAction = new KToggleAction( i18n("&Thread Messages"), 0, this,
02814               SLOT(slotOverrideThread()), actionCollection(), "thread_messages" );
02815 
02816   mThreadBySubjectAction = new KToggleAction( i18n("Thread Messages also by &Subject"), 0, this,
02817               SLOT(slotToggleSubjectThreading()), actionCollection(), "thread_messages_by_subject" );
02818 
02819   new KAction( i18n("Copy Folder"), "editcopy", SHIFT+CTRL+Key_C, folderTree(),
02820                SLOT(copyFolder()), actionCollection(), "copy_folder" );
02821   new KAction( i18n("Cut Folder"), "editcut", SHIFT+CTRL+Key_X, folderTree(),
02822                SLOT(cutFolder()), actionCollection(), "cut_folder" );
02823   new KAction( i18n("Paste Folder"), "editpaste", SHIFT+CTRL+Key_V, folderTree(),
02824                SLOT(pasteFolder()), actionCollection(), "paste_folder" );
02825 
02826   new KAction( i18n("Copy Messages"), "editcopy", ALT+CTRL+Key_C, headers(),
02827                SLOT(copyMessages()), actionCollection(), "copy_messages" );
02828   new KAction( i18n("Cut Messages"), "editcut", ALT+CTRL+Key_X, headers(),
02829                SLOT(cutMessages()), actionCollection(), "cut_messages" );
02830   new KAction( i18n("Paste Messages"), "editpaste", ALT+CTRL+Key_V, headers(),
02831                SLOT(pasteMessages()), actionCollection(), "paste_messages" );
02832 
02833   //----- Message Menu
02834   (void) new KAction( i18n("&New Message..."), "mail_new", KStdAccel::shortcut(KStdAccel::New), this,
02835               SLOT(slotCompose()), actionCollection(), "new_message" );
02836   mTemplateMenu =
02837     new KActionMenu( i18n("New Message From &Template"), "filenew",
02838                      actionCollection(), "new_from_template" );
02839   mTemplateMenu->setDelayed( true );
02840   connect( mTemplateMenu->popupMenu(), SIGNAL( aboutToShow() ), this,
02841            SLOT( slotShowNewFromTemplate() ) );
02842   connect( mTemplateMenu->popupMenu(), SIGNAL( activated(int) ), this,
02843            SLOT( slotNewFromTemplate(int) ) );
02844 
02845   KAction* newToML = new KAction( i18n("New Message t&o Mailing-List..."), "mail_post_to",
02846                       CTRL+SHIFT+Key_N, this,
02847               SLOT(slotPostToML()), actionCollection(), "post_message" );
02848   newToML->plugAccel( actionCollection()->kaccel() );
02849 
02850   mForwardActionMenu = new KActionMenu( i18n("Message->","&Forward"),
02851                     "mail_forward", actionCollection(),
02852                     "message_forward" );
02853 
02854       mForwardInlineAction = new KAction( i18n("&Inline..."),
02855                                       "mail_forward", 0, this,
02856                                       SLOT(slotForwardInlineMsg()),
02857                                       actionCollection(),
02858                                       "message_forward_inline" );
02859 
02860       mForwardAttachedAction = new KAction( i18n("Message->Forward->","As &Attachment..."),
02861                                         "mail_forward", 0, this,
02862                                         SLOT(slotForwardAttachedMsg()),
02863                                         actionCollection(),
02864                                         "message_forward_as_attachment" );
02865 
02866       mForwardDigestAction = new KAction( i18n("Message->Forward->","As Di&gest..."),
02867                                       "mail_forward", 0, this,
02868                                       SLOT(slotForwardDigestMsg()),
02869                                       actionCollection(),
02870                                       "message_forward_as_digest" );
02871 
02872       mRedirectAction = new KAction( i18n("Message->Forward->","&Redirect..."),
02873                                  "mail_forward", Key_E, this,
02874                                  SLOT(slotRedirectMsg()),
02875                                  actionCollection(),
02876                                  "message_forward_redirect" );
02877 
02878 
02879       setupForwardActions();
02880 
02881       mForwardActionMenu->insert( mForwardDigestAction );
02882       mForwardActionMenu->insert( mRedirectAction );
02883 
02884   mSendAgainAction = new KAction( i18n("Send A&gain..."), 0, this,
02885               SLOT(slotResendMsg()), actionCollection(), "send_again" );
02886 
02887 
02888   //----- Create filter actions
02889   mFilterMenu = new KActionMenu( i18n("&Create Filter"), "filter", actionCollection(), "create_filter" );
02890   connect( mFilterMenu, SIGNAL(activated()), this,
02891        SLOT(slotFilter()) );
02892   mSubjectFilterAction = new KAction( i18n("Filter on &Subject..."), 0, this,
02893                       SLOT(slotSubjectFilter()),
02894                       actionCollection(), "subject_filter");
02895   mFilterMenu->insert( mSubjectFilterAction );
02896 
02897   mFromFilterAction = new KAction( i18n("Filter on &From..."), 0, this,
02898                    SLOT(slotFromFilter()),
02899                    actionCollection(), "from_filter");
02900   mFilterMenu->insert( mFromFilterAction );
02901 
02902   mToFilterAction = new KAction( i18n("Filter on &To..."), 0, this,
02903                  SLOT(slotToFilter()),
02904                  actionCollection(), "to_filter");
02905   mFilterMenu->insert( mToFilterAction );
02906 
02907   mListFilterAction = new KAction( i18n("Filter on Mailing-&List..."), 0, this,
02908                                    SLOT(slotMailingListFilter()), actionCollection(),
02909                                    "mlist_filter");
02910   mFilterMenu->insert( mListFilterAction );
02911 
02912   mPrintAction = KStdAction::print (this, SLOT(slotPrintMsg()), actionCollection());
02913 
02914   mUseAction = new KAction( i18n("New Message From &Template"), "filenew",
02915                             Key_N, this, SLOT( slotUseTemplate() ),
02916                             actionCollection(), "use_template" );
02917   mUseAction->plugAccel( actionCollection()->kaccel() );
02918 
02919   //----- "Mark Thread" submenu
02920   mThreadStatusMenu = new KActionMenu ( i18n( "Mark &Thread" ),
02921                                        actionCollection(), "thread_status" );
02922 
02923   mMarkThreadAsReadAction = new KAction(KGuiItem(i18n("Mark Thread as &Read"), "kmmsgread",
02924                                                 i18n("Mark all messages in the selected thread as read")),
02925                                                 0, this, SLOT(slotSetThreadStatusRead()),
02926                                                 actionCollection(), "thread_read");
02927   mThreadStatusMenu->insert( mMarkThreadAsReadAction );
02928 
02929   mMarkThreadAsNewAction = new KAction(KGuiItem(i18n("Mark Thread as &New"), "kmmsgnew",
02930                                                i18n("Mark all messages in the selected thread as new")),
02931                                                0, this, SLOT(slotSetThreadStatusNew()),
02932                                                actionCollection(), "thread_new");
02933   mThreadStatusMenu->insert( mMarkThreadAsNewAction );
02934 
02935   mMarkThreadAsUnreadAction = new KAction(KGuiItem(i18n("Mark Thread as &Unread"), "kmmsgunseen",
02936                                                 i18n("Mark all messages in the selected thread as unread")),
02937                                                 0, this, SLOT(slotSetThreadStatusUnread()),
02938                                                 actionCollection(), "thread_unread");
02939   mThreadStatusMenu->insert( mMarkThreadAsUnreadAction );
02940 
02941   mThreadStatusMenu->insert( new KActionSeparator( this ) );
02942 
02943   //----- "Mark Thread" toggle actions
02944   mToggleThreadFlagAction = new KToggleAction(i18n("Mark Thread as &Important"), "mail_flag",
02945                                        0, this, SLOT(slotSetThreadStatusFlag()),
02946                                        actionCollection(), "thread_flag");
02947   mToggleThreadFlagAction->setCheckedState( i18n("Remove &Important Thread Mark") );
02948   mThreadStatusMenu->insert( mToggleThreadFlagAction );
02949 
02950   mToggleThreadTodoAction = new KToggleAction(i18n("Mark Thread as &Action Item"), "mail_todo",
02951                                        0, this, SLOT(slotSetThreadStatusTodo()),
02952                                        actionCollection(), "thread_todo");
02953   mToggleThreadTodoAction->setCheckedState( i18n("Remove &Action Item Thread Mark") );
02954   mThreadStatusMenu->insert( mToggleThreadTodoAction );
02955 
02956   //------- "Watch and ignore thread" actions
02957   mWatchThreadAction = new KToggleAction(i18n("&Watch Thread"), "kmmsgwatched",
02958                                        0, this, SLOT(slotSetThreadStatusWatched()),
02959                                        actionCollection(), "thread_watched");
02960 
02961   mIgnoreThreadAction = new KToggleAction(i18n("&Ignore Thread"), "mail_ignore",
02962                                        0, this, SLOT(slotSetThreadStatusIgnored()),
02963                                        actionCollection(), "thread_ignored");
02964 
02965   mThreadStatusMenu->insert( new KActionSeparator( this ) );
02966   mThreadStatusMenu->insert( mWatchThreadAction );
02967   mThreadStatusMenu->insert( mIgnoreThreadAction );
02968 
02969   mSaveAttachmentsAction = new KAction( i18n("Save A&ttachments..."), "attach",
02970                                 0, this, SLOT(slotSaveAttachments()),
02971                                 actionCollection(), "file_save_attachments" );
02972 
02973   mMoveActionMenu = new KActionMenu( i18n("&Move To" ),
02974                                     actionCollection(), "move_to" );
02975 
02976   mCopyActionMenu = new KActionMenu( i18n("&Copy To" ),
02977                                     actionCollection(), "copy_to" );
02978 
02979   mApplyAllFiltersAction = new KAction( i18n("Appl&y All Filters"), "filter",
02980                     CTRL+Key_J, this,
02981                     SLOT(slotApplyFilters()),
02982                     actionCollection(), "apply_filters" );
02983 
02984   mApplyFilterActionsMenu = new KActionMenu( i18n("A&pply Filter" ),
02985                         actionCollection(),
02986                         "apply_filter_actions" );
02987 
02988   //----- View Menu
02989   // Unread Submenu
02990   KActionMenu * unreadMenu =
02991     new KActionMenu( i18n("View->", "&Unread Count"),
02992              actionCollection(), "view_unread" );
02993   unreadMenu->setToolTip( i18n("Choose how to display the count of unread messages") );
02994 
02995   mUnreadColumnToggle = new KRadioAction( i18n("View->Unread Count", "View in &Separate Column"), 0, this,
02996                    SLOT(slotToggleUnread()),
02997                    actionCollection(), "view_unread_column" );
02998   mUnreadColumnToggle->setExclusiveGroup( "view_unread_group" );
02999   unreadMenu->insert( mUnreadColumnToggle );
03000 
03001   mUnreadTextToggle = new KRadioAction( i18n("View->Unread Count", "View After &Folder Name"), 0, this,
03002                    SLOT(slotToggleUnread()),
03003                    actionCollection(), "view_unread_text" );
03004   mUnreadTextToggle->setExclusiveGroup( "view_unread_group" );
03005   unreadMenu->insert( mUnreadTextToggle );
03006 
03007   // toggle for total column
03008   mTotalColumnToggle = new KToggleAction( i18n("View->", "&Total Column"), 0, this,
03009                    SLOT(slotToggleTotalColumn()),
03010                    actionCollection(), "view_columns_total" );
03011   mTotalColumnToggle->setToolTip( i18n("Toggle display of column showing the "
03012                                       "total number of messages in folders.") );
03013   mSizeColumnToggle = new KToggleAction( i18n("View->", "&Size Column"), 0, this,
03014                    SLOT(slotToggleSizeColumn()),
03015                    actionCollection(), "view_columns_size" );
03016   mSizeColumnToggle->setToolTip( i18n("Toggle display of column showing the "
03017                                       "total size of messages in folders.") );
03018 
03019   (void)new KAction( KGuiItem( i18n("View->","&Expand Thread"), QString::null,
03020                    i18n("Expand the current thread") ),
03021              Key_Period, this,
03022              SLOT(slotExpandThread()),
03023              actionCollection(), "expand_thread" );
03024 
03025   (void)new KAction( KGuiItem( i18n("View->","&Collapse Thread"), QString::null,
03026                    i18n("Collapse the current thread") ),
03027              Key_Comma, this,
03028              SLOT(slotCollapseThread()),
03029              actionCollection(), "collapse_thread" );
03030 
03031   (void)new KAction( KGuiItem( i18n("View->","Ex&pand All Threads"), QString::null,
03032                    i18n("Expand all threads in the current folder") ),
03033              CTRL+Key_Period, this,
03034              SLOT(slotExpandAllThreads()),
03035              actionCollection(), "expand_all_threads" );
03036 
03037   (void)new KAction( KGuiItem( i18n("View->","C&ollapse All Threads"), QString::null,
03038                    i18n("Collapse all threads in the current folder") ),
03039              CTRL+Key_Comma, this,
03040              SLOT(slotCollapseAllThreads()),
03041              actionCollection(), "collapse_all_threads" );
03042 
03043   mViewSourceAction = new KAction( i18n("&View Source"), Key_V, this,
03044                                    SLOT(slotShowMsgSrc()), actionCollection(),
03045                                    "view_source" );
03046 
03047   KAction* dukeOfMonmoth = new KAction( i18n("&Display Message"), Key_Return, this,
03048                         SLOT( slotDisplayCurrentMessage() ), actionCollection(),
03049                         "display_message" );
03050   dukeOfMonmoth->plugAccel( actionCollection()->kaccel() );
03051 
03052   //----- Go Menu
03053   new KAction( KGuiItem( i18n("&Next Message"), QString::null,
03054                          i18n("Go to the next message") ),
03055                          "N;Right", this, SLOT(slotNextMessage()),
03056                          actionCollection(), "go_next_message" );
03057 
03058   new KAction( KGuiItem( i18n("Next &Unread Message"),
03059                          QApplication::reverseLayout() ? "previous" : "next",
03060                          i18n("Go to the next unread message") ),
03061                          Key_Plus, this, SLOT(slotNextUnreadMessage()),
03062                          actionCollection(), "go_next_unread_message" );
03063 
03064   /* ### needs better support from folders:
03065   new KAction( KGuiItem( i18n("Next &Important Message"), QString::null,
03066                          i18n("Go to the next important message") ),
03067                          0, this, SLOT(slotNextImportantMessage()),
03068                          actionCollection(), "go_next_important_message" );
03069   */
03070 
03071   new KAction( KGuiItem( i18n("&Previous Message"), QString::null,
03072                          i18n("Go to the previous message") ),
03073                          "P;Left", this, SLOT(slotPrevMessage()),
03074                          actionCollection(), "go_prev_message" );
03075 
03076   new KAction( KGuiItem( i18n("Previous Unread &Message"),
03077                          QApplication::reverseLayout() ? "next" : "previous",
03078                          i18n("Go to the previous unread message") ),
03079                          Key_Minus, this, SLOT(slotPrevUnreadMessage()),
03080                          actionCollection(), "go_prev_unread_message" );
03081 
03082   /* needs better support from folders:
03083   new KAction( KGuiItem( i18n("Previous I&mportant Message"), QString::null,
03084                          i18n("Go to the previous important message") ),
03085                          0, this, SLOT(slotPrevImportantMessage()),
03086                          actionCollection(), "go_prev_important_message" );
03087   */
03088 
03089   KAction *action =
03090     new KAction( KGuiItem( i18n("Next Unread &Folder"), QString::null,
03091                            i18n("Go to the next folder with unread messages") ),
03092                            ALT+Key_Plus, this, SLOT(slotNextUnreadFolder()),
03093                            actionCollection(), "go_next_unread_folder" );
03094   KShortcut shortcut = action->shortcut();
03095   shortcut.append( KKey( CTRL+Key_Plus ) );
03096   action->setShortcut( shortcut );
03097 
03098   action =
03099     new KAction( KGuiItem( i18n("Previous Unread F&older"), QString::null,
03100                            i18n("Go to the previous folder with unread messages") ),
03101                            ALT+Key_Minus, this, SLOT(slotPrevUnreadFolder()),
03102                            actionCollection(), "go_prev_unread_folder" );
03103   shortcut = action->shortcut();
03104   shortcut.append( KKey( CTRL+Key_Minus ) );
03105   action->setShortcut( shortcut );
03106 
03107   new KAction( KGuiItem( i18n("Go->","Next Unread &Text"), QString::null,
03108                          i18n("Go to the next unread text"),
03109                          i18n("Scroll down current message. "
03110                               "If at end of current message, "
03111                               "go to next unread message.") ),
03112                          Key_Space, this, SLOT(slotReadOn()),
03113                          actionCollection(), "go_next_unread_text" );
03114 
03115   //----- Settings Menu
03116   mToggleShowQuickSearchAction = new KToggleAction(i18n("Show Quick Search"), QString::null,
03117                                        0, this, SLOT(slotToggleShowQuickSearch()),
03118                                        actionCollection(), "show_quick_search");
03119   mToggleShowQuickSearchAction->setChecked( GlobalSettings::self()->quickSearchActive() );
03120   mToggleShowQuickSearchAction->setWhatsThis(
03121         i18n( GlobalSettings::self()->quickSearchActiveItem()->whatsThis().utf8() ) );
03122 
03123   (void) new KAction( i18n("Configure &Filters..."), 0, this,
03124               SLOT(slotFilter()), actionCollection(), "filter" );
03125   (void) new KAction( i18n("Configure &POP Filters..."), 0, this,
03126               SLOT(slotPopFilter()), actionCollection(), "popFilter" );
03127   (void) new KAction( i18n("Manage &Sieve Scripts..."), 0, this,
03128                       SLOT(slotManageSieveScripts()), actionCollection(), "sieveFilters" );
03129 
03130   (void) new KAction( KGuiItem( i18n("KMail &Introduction"), 0,
03131                 i18n("Display KMail's Welcome Page") ),
03132               0, this, SLOT(slotIntro()),
03133               actionCollection(), "help_kmail_welcomepage" );
03134 
03135   // ----- Standard Actions
03136 //  KStdAction::configureNotifications(this, SLOT(slotEditNotifications()), actionCollection());
03137   (void) new KAction( i18n("Configure &Notifications..."),
03138               "knotify", 0, this,
03139               SLOT(slotEditNotifications()), actionCollection(),
03140               "kmail_configure_notifications" );
03141 //  KStdAction::preferences(this, SLOT(slotSettings()), actionCollection());
03142   (void) new KAction( i18n("&Configure KMail..."),
03143               "configure", 0, kmkernel,
03144                       SLOT(slotShowConfigurationDialog()), actionCollection(),
03145                       "kmail_configure_kmail" );
03146 
03147   KStdAction::undo(this, SLOT(slotUndo()), actionCollection(), "kmail_undo");
03148 
03149   KStdAction::tipOfDay( this, SLOT( slotShowTip() ), actionCollection() );
03150 
03151   menutimer = new QTimer( this, "menutimer" );
03152   connect( menutimer, SIGNAL( timeout() ), SLOT( updateMessageActions() ) );
03153   connect( kmkernel->undoStack(),
03154            SIGNAL( undoStackChanged() ), this, SLOT( slotUpdateUndo() ));
03155 
03156   initializeIMAPActions( false ); // don't set state, config not read yet
03157   updateMessageActions();
03158   updateCustomTemplateMenus();
03159   updateFolderMenu();
03160 }
03161 
03162 void KMMainWidget::setupForwardingActionsList()
03163 {
03164   QPtrList<KAction> mForwardActionList;
03165   if ( GlobalSettings::self()->forwardingInlineByDefault() ) {
03166       mGUIClient->unplugActionList( "forward_action_list" );
03167       mForwardActionList.append( mForwardInlineAction );
03168       mForwardActionList.append( mForwardAttachedAction );
03169       mForwardActionList.append( mForwardDigestAction );
03170       mForwardActionList.append( mRedirectAction );
03171       mGUIClient->plugActionList( "forward_action_list", mForwardActionList );
03172   } else {
03173       mGUIClient->unplugActionList( "forward_action_list" );
03174       mForwardActionList.append( mForwardAttachedAction );
03175       mForwardActionList.append( mForwardInlineAction );
03176       mForwardActionList.append( mForwardDigestAction );
03177       mForwardActionList.append( mRedirectAction );
03178       mGUIClient->plugActionList( "forward_action_list", mForwardActionList );
03179   }
03180 }
03181 
03182 //-----------------------------------------------------------------------------
03183 void KMMainWidget::slotEditNotifications()
03184 {
03185   if(kmkernel->xmlGuiInstance())
03186     KNotifyDialog::configure(this, 0, kmkernel->xmlGuiInstance()->aboutData());
03187   else
03188     KNotifyDialog::configure(this);
03189 }
03190 
03191 void KMMainWidget::slotEditKeys()
03192 {
03193   KKeyDialog::configure( actionCollection(),
03194              true /*allow one-letter shortcuts*/
03195              );
03196 }
03197 
03198 //-----------------------------------------------------------------------------
03199 void KMMainWidget::slotReadOn()
03200 {
03201     if ( !mMsgView )
03202         return;
03203 
03204     if ( !mMsgView->atBottom() ) {
03205         mMsgView->slotJumpDown();
03206         return;
03207     }
03208     slotNextUnreadMessage();
03209 }
03210 
03211 void KMMainWidget::slotNextUnreadFolder() {
03212   if ( !mFolderTree ) return;
03213   mFolderTree->nextUnreadFolder();
03214 }
03215 
03216 void KMMainWidget::slotPrevUnreadFolder() {
03217   if ( !mFolderTree ) return;
03218   mFolderTree->prevUnreadFolder();
03219 }
03220 
03221 void KMMainWidget::slotExpandThread()
03222 {
03223   mHeaders->slotExpandOrCollapseThread( true ); // expand
03224 }
03225 
03226 void KMMainWidget::slotCollapseThread()
03227 {
03228   mHeaders->slotExpandOrCollapseThread( false ); // collapse
03229 }
03230 
03231 void KMMainWidget::slotExpandAllThreads()
03232 {
03233   mHeaders->slotExpandOrCollapseAllThreads( true ); // expand
03234 }
03235 
03236 void KMMainWidget::slotCollapseAllThreads()
03237 {
03238   mHeaders->slotExpandOrCollapseAllThreads( false ); // collapse
03239 }
03240 
03241 //-----------------------------------------------------------------------------
03242 void KMMainWidget::slotShowMsgSrc()
03243 {
03244   if ( mMsgView )
03245     mMsgView->setUpdateAttachment( false );
03246   KMMessage *msg = mHeaders->currentMsg();
03247   if ( !msg )
03248     return;
03249   KMCommand *command = new KMShowMsgSrcCommand( this, msg,
03250                                                 mMsgView
03251                                                 ? mMsgView->isFixedFont()
03252                                                 : false );
03253   command->start();
03254 }
03255 
03256 
03257 //-----------------------------------------------------------------------------
03258 void KMMainWidget::moveSelectedToFolder( int menuId )
03259 {
03260   if (mMenuToFolder[menuId])
03261     mHeaders->moveMsgToFolder( mMenuToFolder[menuId] );
03262 }
03263 
03264 
03265 //-----------------------------------------------------------------------------
03266 void KMMainWidget::copySelectedToFolder(int menuId )
03267 {
03268   if (mMenuToFolder[menuId])
03269     mHeaders->copyMsgToFolder( mMenuToFolder[menuId] );
03270 }
03271 
03272 
03273 //-----------------------------------------------------------------------------
03274 void KMMainWidget::updateMessageMenu()
03275 {
03276   mMenuToFolder.clear();
03277   folderTree()->folderToPopupMenu( KMFolderTree::MoveMessage, this,
03278       &mMenuToFolder, mMoveActionMenu->popupMenu() );
03279   folderTree()->folderToPopupMenu( KMFolderTree::CopyMessage, this,
03280       &mMenuToFolder, mCopyActionMenu->popupMenu() );
03281   updateMessageActions();
03282 }
03283 
03284 void KMMainWidget::startUpdateMessageActionsTimer()
03285 {
03286     menutimer->stop();
03287     menutimer->start( 20, true );
03288 }
03289 
03290 void KMMainWidget::updateMessageActions()
03291 {
03292     int count = 0;
03293     QPtrList<QListViewItem> selectedItems;
03294 
03295     if ( mFolder ) {
03296       for (QListViewItem *item = mHeaders->firstChild(); item; item = item->itemBelow())
03297         if (item->isSelected() )
03298           selectedItems.append(item);
03299       if ( selectedItems.isEmpty() && mFolder->count() ) // there will always be one in mMsgView
03300         count = 1;
03301       else
03302         count = selectedItems.count();
03303       mMsgActions->setCurrentMessage( mHeaders->currentMsg() );
03304       mMsgActions->setSelectedSernums( mHeaders->selectedSernums() );
03305       mMsgActions->setSelectedVisibleSernums( mHeaders->selectedVisibleSernums() );
03306     } else {
03307       mMsgActions->setCurrentMessage( 0 );
03308     }
03309 
03310     updateListFilterAction();
03311 
03312     bool allSelectedInCommonThread = false;
03313     if ( mHeaders->isThreaded() && count > 1 ) {
03314       allSelectedInCommonThread = true;
03315       for ( QPtrListIterator<QListViewItem> it( selectedItems ) ;
03316             it.current() ; ++ it ) {
03317         QListViewItem * item = *it;
03318         if ( item->parent()==0 && item->childCount()==0 ) {
03319           allSelectedInCommonThread = false;
03320           break;
03321         }
03322       }
03323     }
03324     else if ( mHeaders->isThreaded() && count == 1 ) {
03325       allSelectedInCommonThread = true;
03326     }
03327 
03328     QListViewItem *curItemParent = mHeaders->currentItem();
03329     bool parent_thread = 0;
03330     if ( curItemParent && curItemParent->firstChild() != 0 ) parent_thread = 1;
03331 
03332     bool mass_actions = count >= 1;
03333     bool thread_actions = mass_actions && allSelectedInCommonThread &&
03334                           mHeaders->isThreaded();
03335     bool flags_available = GlobalSettings::self()->allowLocalFlags() || !(mFolder ? mFolder->isReadOnly() : true);
03336     mThreadStatusMenu->setEnabled( thread_actions );
03337     // these need to be handled individually, the user might have them
03338     // in the toolbar
03339     mWatchThreadAction->setEnabled( thread_actions && flags_available );
03340     mIgnoreThreadAction->setEnabled( thread_actions && flags_available );
03341     mMarkThreadAsNewAction->setEnabled( thread_actions );
03342     mMarkThreadAsReadAction->setEnabled( thread_actions );
03343     mMarkThreadAsUnreadAction->setEnabled( thread_actions );
03344     mToggleThreadTodoAction->setEnabled( thread_actions && flags_available );
03345     mToggleThreadFlagAction->setEnabled( thread_actions && flags_available );
03346     mTrashThreadAction->setEnabled( thread_actions && mFolder->canDeleteMessages() );
03347     mDeleteThreadAction->setEnabled( thread_actions && mFolder->canDeleteMessages() );
03348 
03349     if (mFolder && mHeaders && mHeaders->currentMsg()) {
03350       if (thread_actions) {
03351         mToggleThreadTodoAction->setChecked(mHeaders->currentMsg()->isTodo());
03352         mToggleThreadFlagAction->setChecked(mHeaders->currentMsg()->isImportant());
03353         mWatchThreadAction->setChecked( mHeaders->currentMsg()->isWatched());
03354         mIgnoreThreadAction->setChecked( mHeaders->currentMsg()->isIgnored());
03355       }
03356     }
03357 
03358     mMoveActionMenu->setEnabled( mass_actions && mFolder->canDeleteMessages() );
03359     mMoveMsgToFolderAction->setEnabled( mass_actions && mFolder->canDeleteMessages() );
03360     mCopyActionMenu->setEnabled( mass_actions );
03361     mTrashAction->setEnabled( mass_actions && mFolder->canDeleteMessages() );
03362     mDeleteAction->setEnabled( mass_actions && mFolder->canDeleteMessages() );
03363     mFindInMessageAction->setEnabled( mass_actions && !kmkernel->folderIsTemplates( mFolder ) );
03364     mForwardInlineAction->setEnabled( mass_actions && !kmkernel->folderIsTemplates( mFolder ));
03365     mForwardAttachedAction->setEnabled( mass_actions && !kmkernel->folderIsTemplates( mFolder ) );
03366     mForwardDigestAction->setEnabled( ( count > 1 || parent_thread ) && !kmkernel->folderIsTemplates( mFolder ) );
03367 
03368     forwardMenu()->setEnabled( mass_actions && !kmkernel->folderIsTemplates( mFolder ));
03369 
03370     bool single_actions = count == 1;
03371     mUseAction->setEnabled( single_actions &&
03372                             kmkernel->folderIsTemplates( mFolder ) );
03373     filterMenu()->setEnabled( single_actions );
03374     redirectAction()->setEnabled( single_actions && !kmkernel->folderIsTemplates( mFolder ) );
03375     printAction()->setEnabled( single_actions );
03376     viewSourceAction()->setEnabled( single_actions );
03377 
03378     mSendAgainAction->setEnabled( single_actions
03379           && ( mHeaders->currentMsg() && mHeaders->currentMsg()->isSent() )
03380           || ( mFolder && mHeaders->currentMsg() &&
03381                kmkernel->folderIsSentMailFolder( mFolder ) ) );
03382     mSaveAsAction->setEnabled( mass_actions );
03383     bool mails = mFolder && mFolder->count();
03384     bool enable_goto_unread = mails
03385        || (GlobalSettings::self()->loopOnGotoUnread() == GlobalSettings::EnumLoopOnGotoUnread::LoopInAllFolders);
03386     actionCollection()->action( "go_next_message" )->setEnabled( mails );
03387     actionCollection()->action( "go_next_unread_message" )->setEnabled( enable_goto_unread );
03388     actionCollection()->action( "go_prev_message" )->setEnabled( mails );
03389     actionCollection()->action( "go_prev_unread_message" )->setEnabled( enable_goto_unread );
03390     actionCollection()->action( "send_queued" )->setEnabled( kmkernel->outboxFolder()->count() > 0 );
03391     actionCollection()->action( "send_queued_via" )->setEnabled( kmkernel->outboxFolder()->count() > 0 );
03392     slotUpdateOnlineStatus( static_cast<GlobalSettingsBase::EnumNetworkState::type>( GlobalSettings::self()->networkState() ) );
03393     if (action( "edit_undo" ))
03394       action( "edit_undo" )->setEnabled( mHeaders->canUndo() );
03395 
03396     if ( count == 1 ) {
03397       KMMessage *msg;
03398       int aIdx;
03399       if((aIdx = mHeaders->currentItemIndex()) <= -1)
03400         return;
03401       if(!(msg = mFolder->getMsg(aIdx)))
03402         return;
03403 
03404       if ((KMFolder*)mFolder == kmkernel->outboxFolder())
03405         editAction()->setEnabled( !msg->transferInProgress() );
03406     }
03407 
03408     mApplyAllFiltersAction->setEnabled(count);
03409     mApplyFilterActionsMenu->setEnabled(count);
03410 }
03411 
03412 // This needs to be updated more often, so it is in its method.
03413 void KMMainWidget::updateMarkAsReadAction()
03414 {
03415   mMarkAllAsReadAction->setEnabled( mFolder && (mFolder->countUnread() > 0) );
03416 }
03417 
03418 //-----------------------------------------------------------------------------
03419 void KMMainWidget::updateFolderMenu()
03420 {
03421   bool folderWithContent = mFolder && !mFolder->noContent();
03422   bool multiFolder = folderTree()->selectedFolders().count() > 1;
03423   mModifyFolderAction->setEnabled( folderWithContent && !multiFolder );
03424   mFolderMailingListPropertiesAction->setEnabled( folderWithContent && !multiFolder );
03425   mCompactFolderAction->setEnabled( folderWithContent && !multiFolder );
03426 
03427   // This is the refresh-folder action in the menu. See kmfoldertree for the one in the RMB...
03428   bool imap = mFolder && mFolder->folderType() == KMFolderTypeImap;
03429   bool cachedImap = mFolder && mFolder->folderType() == KMFolderTypeCachedImap;
03430   // For dimap, check that the imap path is known before allowing "check mail in this folder".
03431   bool knownImapPath = cachedImap && !static_cast<KMFolderCachedImap*>( mFolder->storage() )->imapPath().isEmpty();
03432   mRefreshFolderAction->setEnabled( folderWithContent && ( imap
03433                                                            || ( cachedImap && knownImapPath ) ) && !multiFolder );
03434   if ( mTroubleshootFolderAction )
03435     mTroubleshootFolderAction->setEnabled( folderWithContent && ( cachedImap && knownImapPath ) && !multiFolder );
03436   mEmptyFolderAction->setEnabled( folderWithContent && ( mFolder->count() > 0 ) && mFolder->canDeleteMessages() && !multiFolder );
03437   mEmptyFolderAction->setText( (mFolder && kmkernel->folderIsTrash(mFolder))
03438     ? i18n("E&mpty Trash") : i18n("&Move All Messages to Trash") );
03439   mRemoveFolderAction->setEnabled( mFolder && !mFolder->isSystemFolder() && mFolder->canDeleteMessages() && !multiFolder);
03440   mRemoveFolderAction->setText( mFolder && mFolder->folderType() == KMFolderTypeSearch
03441         ? i18n("&Delete Search") : i18n("&Delete Folder") );
03442   mExpireFolderAction->setEnabled( mFolder && mFolder->isAutoExpire() && !multiFolder && mFolder->canDeleteMessages() );
03443   updateMarkAsReadAction();
03444   // the visual ones only make sense if we are showing a message list
03445   mPreferHtmlAction->setEnabled( mHeaders->folder() ? true : false );
03446   mPreferHtmlLoadExtAction->setEnabled( mHeaders->folder() && (mHtmlPref ? !mFolderHtmlPref : mFolderHtmlPref) ? true : false );
03447   mThreadMessagesAction->setEnabled( mHeaders->folder() ? true : false );
03448 
03449   mPreferHtmlAction->setChecked( mHtmlPref ? !mFolderHtmlPref : mFolderHtmlPref );
03450   mPreferHtmlLoadExtAction->setChecked( mHtmlLoadExtPref ? !mFolderHtmlLoadExtPref : mFolderHtmlLoadExtPref );
03451   mThreadMessagesAction->setChecked(
03452       mThreadPref ? !mFolderThreadPref : mFolderThreadPref );
03453   mThreadBySubjectAction->setEnabled(
03454       mHeaders->folder() ? ( mThreadMessagesAction->isChecked()) : false );
03455   mThreadBySubjectAction->setChecked( mFolderThreadSubjPref );
03456 
03457   mNewFolderAction->setEnabled( !multiFolder && ( mFolder && mFolder->folderType() != KMFolderTypeSearch ));
03458   mRemoveDuplicatesAction->setEnabled( !multiFolder && mFolder && mFolder->canDeleteMessages() );
03459   mFolderShortCutCommandAction->setEnabled( !multiFolder );
03460 }
03461 
03462 
03463 #ifdef MALLOC_DEBUG
03464 static QString fmt(long n) {
03465   char buf[32];
03466 
03467   if(n > 1024*1024*1024)
03468     sprintf(buf, "%0.2f GB", ((double)n)/1024.0/1024.0/1024.0);
03469   else if(n > 1024*1024)
03470     sprintf(buf, "%0.2f MB", ((double)n)/1024.0/1024.0);
03471   else if(n > 1024)
03472     sprintf(buf, "%0.2f KB", ((double)n)/1024.0);
03473   else
03474     sprintf(buf, "%ld Byte", n);
03475   return QString(buf);
03476 }
03477 #endif
03478 
03479 void KMMainWidget::slotMemInfo() {
03480 #ifdef MALLOC_DEBUG
03481   struct mallinfo mi;
03482 
03483   mi = mallinfo();
03484   QString s = QString("\nMALLOC - Info\n\n"
03485               "Number of mmapped regions : %1\n"
03486               "Memory allocated in use   : %2\n"
03487               "Memory allocated, not used: %3\n"
03488               "Memory total allocated    : %4\n"
03489               "Max. freeable memory      : %5\n")
03490     .arg(mi.hblks).arg(fmt(mi.uordblks)).arg(fmt(mi.fordblks))
03491     .arg(fmt(mi.arena)).arg(fmt(mi.keepcost));
03492   KMessageBox::information(0, s, "Malloc information", s);
03493 #endif
03494 }
03495 
03496 
03497 //-----------------------------------------------------------------------------
03498 void KMMainWidget::slotIntro()
03499 {
03500   if ( !mMsgView ) return;
03501 
03502   mMsgView->clear( true );
03503   // hide widgets that are in the way:
03504   if ( mSearchAndHeaders && mHeaders && mLongFolderList )
03505     mSearchAndHeaders->hide();
03506 
03507 
03508   mMsgView->displayAboutPage();
03509 
03510   mFolder = 0;
03511 }
03512 
03513 void KMMainWidget::slotShowStartupFolder()
03514 {
03515   if ( mFolderTree ) {
03516     mFolderTree->reload();
03517     mFolderTree->readConfig();
03518     // get rid of old-folders
03519     mFolderTree->cleanupConfigFile();
03520   }
03521 
03522   connect( kmkernel->filterMgr(), SIGNAL( filterListUpdated() ),
03523        this, SLOT( initializeFilterActions() ));
03524 
03525   // plug shortcut filter actions now
03526   initializeFilterActions();
03527 
03528   // plug folder shortcut actions
03529   initializeFolderShortcutActions();
03530 
03531   QString newFeaturesMD5 = KMReaderWin::newFeaturesMD5();
03532   if ( kmkernel->firstStart() ||
03533        GlobalSettings::self()->previousNewFeaturesMD5() != newFeaturesMD5 ) {
03534     GlobalSettings::self()->setPreviousNewFeaturesMD5( newFeaturesMD5 );
03535     slotIntro();
03536     return;
03537   }
03538 
03539   KMFolder* startup = 0;
03540   if ( !mStartupFolder.isEmpty() ) {
03541     // find the startup-folder
03542     startup = kmkernel->findFolderById( mStartupFolder );
03543   }
03544   if ( !startup )
03545     startup = kmkernel->inboxFolder();
03546 
03547   if ( mFolderTree ) {
03548     mFolderTree->showFolder( startup );
03549   }
03550 }
03551 
03552 void KMMainWidget::slotShowTip()
03553 {
03554   KTipDialog::showTip( this, QString::null, true );
03555 }
03556 
03557 //-----------------------------------------------------------------------------
03558 void KMMainWidget::slotChangeCaption(QListViewItem * i)
03559 {
03560   if ( !i ) return;
03561   // set the caption to the current full path
03562   QStringList names;
03563   for ( QListViewItem * item = i ; item ; item = item->parent() )
03564     names.prepend( item->text(0) );
03565   emit captionChangeRequest( names.join( "/" ) );
03566 }
03567 
03568 //-----------------------------------------------------------------------------
03569 void KMMainWidget::removeDuplicates()
03570 {
03571   if (!mFolder)
03572     return;
03573   KMFolder *oFolder = mFolder;
03574   mHeaders->setFolder(0);
03575   QMap< QString, QValueList<int> > idMD5s;
03576   QValueList<int> redundantIds;
03577   QValueList<int>::Iterator kt;
03578   mFolder->open("removedups");
03579   for (int i = mFolder->count() - 1; i >= 0; --i) {
03580     QString id = (*mFolder)[i]->msgIdMD5();
03581     if ( !id.isEmpty() ) {
03582       QString subjMD5 = (*mFolder)[i]->strippedSubjectMD5();
03583       int other = -1;
03584       if ( idMD5s.contains(id) )
03585         other = idMD5s[id].first();
03586       else
03587         idMD5s[id].append( i );
03588       if ( other != -1 ) {
03589         QString otherSubjMD5 = (*mFolder)[other]->strippedSubjectMD5();
03590         if (otherSubjMD5 == subjMD5)
03591           idMD5s[id].append( i );
03592       }
03593     }
03594   }
03595   QMap< QString, QValueList<int> >::Iterator it;
03596   for ( it = idMD5s.begin(); it != idMD5s.end() ; ++it ) {
03597     QValueList<int>::Iterator jt;
03598     bool finished = false;
03599     for ( jt = (*it).begin(); jt != (*it).end() && !finished; ++jt )
03600       if (!((*mFolder)[*jt]->isUnread())) {
03601         (*it).remove( jt );
03602         (*it).prepend( *jt );
03603         finished = true;
03604       }
03605     for ( jt = (*it).begin(), ++jt; jt != (*it).end(); ++jt )
03606       redundantIds.append( *jt );
03607   }
03608   qHeapSort( redundantIds );
03609   kt = redundantIds.end();
03610   int numDuplicates = 0;
03611   if (kt != redundantIds.begin()) do {
03612     mFolder->removeMsg( *(--kt) );
03613     ++numDuplicates;
03614   }
03615   while (kt != redundantIds.begin());
03616 
03617   mFolder->close("removedups");
03618   mHeaders->setFolder(oFolder);
03619   QString msg;
03620   if ( numDuplicates )
03621     msg = i18n("Removed %n duplicate message.",
03622                "Removed %n duplicate messages.", numDuplicates );
03623     else
03624       msg = i18n("No duplicate messages found.");
03625   BroadcastStatus::instance()->setStatusMsg( msg );
03626 }
03627 
03628 
03629 //-----------------------------------------------------------------------------
03630 void KMMainWidget::slotUpdateUndo()
03631 {
03632     if (actionCollection()->action( "edit_undo" ))
03633         actionCollection()->action( "edit_undo" )->setEnabled( mHeaders->canUndo() );
03634 }
03635 
03636 
03637 //-----------------------------------------------------------------------------
03638 void KMMainWidget::clearFilterActions()
03639 {
03640   if ( !mFilterTBarActions.isEmpty() ) {
03641     if ( mGUIClient->factory() )
03642       mGUIClient->unplugActionList( "toolbar_filter_actions" );
03643     mFilterTBarActions.clear();
03644   }
03645   mApplyFilterActionsMenu->popupMenu()->clear();
03646   if ( !mFilterMenuActions.isEmpty() ) {
03647     if ( mGUIClient->factory() )
03648       mGUIClient->unplugActionList( "menu_filter_actions" );
03649     mFilterMenuActions.clear();
03650   }
03651   mFilterCommands.clear();
03652 }
03653 
03654 //-----------------------------------------------------------------------------
03655 void KMMainWidget::initializeFolderShortcutActions()
03656 {
03657 
03658   // If we are loaded as a part, this will be set to fals, since the part
03659   // does xml loading. Temporarily set to true, in that case, so the
03660   // accels are added to the collection as expected.
03661   bool old = actionCollection()->isAutoConnectShortcuts();
03662 
03663   actionCollection()->setAutoConnectShortcuts( true );
03664   QValueList< QGuardedPtr< KMFolder > > folders = kmkernel->allFolders();
03665   QValueList< QGuardedPtr< KMFolder > >::Iterator it = folders.begin();
03666   while ( it != folders.end() ) {
03667     KMFolder *folder = (*it);
03668     ++it;
03669     slotShortcutChanged( folder ); // load the initial accel
03670   }
03671   actionCollection()->setAutoConnectShortcuts( old );
03672 }
03673 
03674 
03675 //-----------------------------------------------------------------------------
03676 void KMMainWidget::initializeFilterActions()
03677 {
03678   QString filterName, normalizedName;
03679   KMMetaFilterActionCommand *filterCommand;
03680   KAction *filterAction = 0;
03681 
03682   clearFilterActions();
03683   mApplyAllFiltersAction->plug(mApplyFilterActionsMenu->popupMenu());
03684   bool addedSeparator = false;
03685   QValueListConstIterator<KMFilter*> it = kmkernel->filterMgr()->filters().constBegin();
03686   for ( ;it != kmkernel->filterMgr()->filters().constEnd(); ++it ) {
03687     if (!(*it)->isEmpty() && (*it)->configureShortcut()) {
03688       filterName = QString("Filter %1").arg((*it)->name());
03689       normalizedName = filterName.replace(" ", "_");
03690       if (action(normalizedName.utf8()))
03691         continue;
03692       filterCommand = new KMMetaFilterActionCommand(*it, mHeaders, this);
03693       mFilterCommands.append(filterCommand);
03694       QString as = i18n("Filter %1").arg((*it)->name());
03695       QString icon = (*it)->icon();
03696       if ( icon.isEmpty() )
03697         icon = "gear";
03698       filterAction = new KAction(as, icon, (*it)->shortcut(), filterCommand,
03699                                  SLOT(start()), actionCollection(),
03700                                  normalizedName.local8Bit());
03701       if(!addedSeparator) {
03702         mApplyFilterActionsMenu->popupMenu()->insertSeparator();
03703         addedSeparator = !addedSeparator;
03704         mFilterMenuActions.append( new KActionSeparator());
03705       }
03706       filterAction->plug( mApplyFilterActionsMenu->popupMenu() );
03707       mFilterMenuActions.append(filterAction);
03708       if ( (*it)->configureToolbar() )
03709         mFilterTBarActions.append(filterAction);
03710     }
03711   }
03712   if ( !mFilterMenuActions.isEmpty() && mGUIClient->factory() )
03713     mGUIClient->plugActionList( "menu_filter_actions", mFilterMenuActions );
03714   if ( !mFilterTBarActions.isEmpty() && mGUIClient->factory() ) {
03715     mFilterTBarActions.prepend( mToolbarActionSeparator );
03716     mGUIClient->plugActionList( "toolbar_filter_actions", mFilterTBarActions );
03717   }
03718 }
03719 
03720 void KMMainWidget::slotFolderRemoved( KMFolder *folder )
03721 {
03722   mFolderShortcutCommands.remove( folder->idString() );
03723 }
03724 
03725 //-----------------------------------------------------------------------------
03726 void KMMainWidget::initializeIMAPActions( bool setState /* false the first time, true later on */ )
03727 {
03728   bool hasImapAccount = false;
03729   for( KMAccount *a = kmkernel->acctMgr()->first(); a;
03730        a = kmkernel->acctMgr()->next() ) {
03731     if ( a->type() == "cachedimap" ) {
03732       hasImapAccount = true;
03733       break;
03734     }
03735   }
03736   if ( hasImapAccount == ( mTroubleshootFolderAction != 0 ) )
03737     return; // nothing to do
03738 
03739   KXMLGUIFactory* factory = mGUIClient->factory();
03740   if ( factory )
03741     factory->removeClient( mGUIClient );
03742 
03743   if ( !mTroubleshootFolderAction ) {
03744     mTroubleshootFolderAction = new KAction( i18n("&Troubleshoot IMAP Cache..."), "wizard", 0,
03745      this, SLOT(slotTroubleshootFolder()), actionCollection(), "troubleshoot_folder" );
03746     if ( setState )
03747       updateFolderMenu(); // set initial state of the action
03748   } else {
03749     delete mTroubleshootFolderAction ;
03750     mTroubleshootFolderAction = 0;
03751   }
03752 
03753   if ( factory )
03754     factory->addClient( mGUIClient );
03755 }
03756 
03757 bool KMMainWidget::shortcutIsValid( const KShortcut &sc ) const
03758 {
03759   KActionPtrList actions = actionCollection()->actions();
03760   KActionPtrList::Iterator it( actions.begin() );
03761   for ( ; it != actions.end(); it++ ) {
03762     if ( (*it)->shortcut() == sc ) return false;
03763   }
03764   return true;
03765 }
03766 
03767 void KMMainWidget::slotShortcutChanged( KMFolder *folder )
03768 {
03769   // remove the old one, autodelete
03770   mFolderShortcutCommands.remove( folder->idString() );
03771   if ( folder->shortcut().isNull() )
03772     return;
03773 
03774   FolderShortcutCommand *c = new FolderShortcutCommand( this, folder );
03775   mFolderShortcutCommands.insert( folder->idString(), c );
03776 
03777   QString actionlabel = QString( "FolderShortcut %1").arg( folder->prettyURL() );
03778   QString actionname = QString( "FolderShortcut %1").arg( folder->idString() );
03779   QString normalizedName = actionname.replace(" ", "_");
03780   KAction* action =
03781     new KAction(actionlabel, folder->shortcut(), c, SLOT(start()),
03782                 actionCollection(), normalizedName.local8Bit());
03783   action->setIcon( folder->unreadIconPath() );
03784   c->setAction( action ); // will be deleted along with the command
03785 }
03786 
03787 //-----------------------------------------------------------------------------
03788 QString KMMainWidget::findCurrentImapPath()
03789 {
03790   QString startPath;
03791   if (!mFolder) return startPath;
03792   if (mFolder->folderType() == KMFolderTypeImap)
03793   {
03794     startPath = static_cast<KMFolderImap*>(mFolder->storage())->imapPath();
03795   } else if (mFolder->folderType() == KMFolderTypeCachedImap)
03796   {
03797     startPath = static_cast<KMFolderCachedImap*>(mFolder->storage())->imapPath();
03798   }
03799   return startPath;
03800 }
03801 
03802 //-----------------------------------------------------------------------------
03803 ImapAccountBase* KMMainWidget::findCurrentImapAccountBase()
03804 {
03805   ImapAccountBase* account = 0;
03806   if (!mFolder) return account;
03807   if (mFolder->folderType() == KMFolderTypeImap)
03808   {
03809     account = static_cast<KMFolderImap*>(mFolder->storage())->account();
03810   } else if (mFolder->folderType() == KMFolderTypeCachedImap)
03811   {
03812     account = static_cast<KMFolderCachedImap*>(mFolder->storage())->account();
03813   }
03814   return account;
03815 }
03816 
03817 //-----------------------------------------------------------------------------
03818 void KMMainWidget::slotSubscriptionDialog()
03819 {
03820   if ( !kmkernel->askToGoOnline() )
03821     return;
03822   ImapAccountBase* account = findCurrentImapAccountBase();
03823   if ( !account ) return;
03824   const QString startPath = findCurrentImapPath();
03825 
03826   // KSubscription sets "DestruciveClose"
03827   SubscriptionDialog * dialog =
03828       new SubscriptionDialog(this, i18n("Subscription"), account, startPath);
03829   if ( dialog->exec() ) {
03830     // start a new listing
03831     if (mFolder->folderType() == KMFolderTypeImap)
03832       static_cast<KMFolderImap*>(mFolder->storage())->account()->listDirectory();
03833   }
03834 }
03835 
03836 //-----------------------------------------------------------------------------
03837 void KMMainWidget::slotLocalSubscriptionDialog()
03838 {
03839   ImapAccountBase* account = findCurrentImapAccountBase();
03840   if ( !account ) return;
03841 
03842   const QString startPath = findCurrentImapPath();
03843   // KSubscription sets "DestruciveClose"
03844   LocalSubscriptionDialog *dialog =
03845       new LocalSubscriptionDialog(this, i18n("Local Subscription"), account, startPath);
03846   if ( dialog->exec() ) {
03847     // start a new listing
03848     if (mFolder->folderType() == KMFolderTypeImap)
03849       static_cast<KMFolderImap*>(mFolder->storage())->account()->listDirectory();
03850   }
03851 }
03852 
03853 //-----------------------------------------------------------------------------
03854 void KMMainWidget::slotFolderTreeColumnsChanged()
03855 {
03856   mTotalColumnToggle->setChecked( mFolderTree->isTotalActive() );
03857   mUnreadColumnToggle->setChecked( mFolderTree->isUnreadActive() );
03858   mSizeColumnToggle->setChecked( mFolderTree->isSizeActive() );
03859   mUnreadTextToggle->setChecked( !mFolderTree->isUnreadActive() );
03860 }
03861 
03862 void KMMainWidget::toggleSystemTray()
03863 {
03864   if ( !mSystemTray && GlobalSettings::self()->systemTrayEnabled() ) {
03865     mSystemTray = new KMSystemTray();
03866   }
03867   else if ( mSystemTray && !GlobalSettings::self()->systemTrayEnabled() ) {
03868     // Get rid of system tray on user's request
03869     kdDebug(5006) << "deleting systray" << endl;
03870     delete mSystemTray;
03871     mSystemTray = 0;
03872   }
03873 
03874   // Set mode of systemtray. If mode has changed, tray will handle this.
03875   if ( mSystemTray )
03876     mSystemTray->setMode( GlobalSettings::self()->systemTrayPolicy() );
03877 }
03878 
03879 //-----------------------------------------------------------------------------
03880 void KMMainWidget::slotAntiSpamWizard()
03881 {
03882   AntiSpamWizard wiz( AntiSpamWizard::AntiSpam, this, folderTree() );
03883   wiz.exec();
03884 }
03885 
03886 //-----------------------------------------------------------------------------
03887 void KMMainWidget::slotAntiVirusWizard()
03888 {
03889   AntiSpamWizard wiz( AntiSpamWizard::AntiVirus, this, folderTree() );
03890   wiz.exec();
03891 }
03892 
03893 //-----------------------------------------------------------------------------
03894 void KMMainWidget::slotFilterLogViewer()
03895 {
03896   FilterLogDialog * dlg = new FilterLogDialog( 0 );
03897   dlg->show();
03898 }
03899 
03900 //-----------------------------------------------------------------------------
03901 void KMMainWidget::updateFileMenu()
03902 {
03903   QStringList actList = kmkernel->acctMgr()->getAccounts();
03904 
03905   actionCollection()->action("check_mail")->setEnabled( actList.size() > 0 );
03906   actionCollection()->action("check_mail_in")->setEnabled( actList.size() > 0 );
03907   actionCollection()->action("favorite_check_mail")->setEnabled( actList.size() > 0 );
03908 }
03909 
03910 
03911 //-----------------------------------------------------------------------------
03912 void KMMainWidget::setAccelsEnabled( bool enabled )
03913 {
03914   actionCollection()->kaccel()->setEnabled( enabled );
03915 }
03916 
03917 
03918 //-----------------------------------------------------------------------------
03919 KMSystemTray *KMMainWidget::systray() const
03920 {
03921   return mSystemTray;
03922 }
03923 
03924 //-----------------------------------------------------------------------------
03925 QString KMMainWidget::overrideEncoding() const
03926 {
03927   if ( mMsgView )
03928     return mMsgView->overrideEncoding();
03929   else
03930     return GlobalSettings::self()->overrideCharacterEncoding();
03931 }
03932 
03933 void KMMainWidget::slotCreateTodo()
03934 {
03935   KMMessage *msg = mHeaders->currentMsg();
03936   if ( !msg )
03937     return;
03938   KMCommand *command = new CreateTodoCommand( this, msg );
03939   command->start();
03940 }
03941 
03942 void KMMainWidget::setupFolderView()
03943 {
03944   if ( GlobalSettings::self()->enableFavoriteFolderView() ) {
03945     mFolderView = mFolderViewSplitter;
03946     mFolderTree->reparent( mFolderViewSplitter, 0, QPoint( 0, 0 ) );
03947     mFolderViewSplitter->show();
03948     mFavoriteFolderView->show();
03949   } else {
03950     mFolderView = mFolderTree;
03951     mFolderViewSplitter->hide();
03952     mFavoriteFolderView->hide();
03953   }
03954   mFolderView->reparent( mFolderViewParent, 0, QPoint( 0, 0 ) );
03955   mFolderViewParent->moveToFirst( mFolderView );
03956   mFolderTree->show();
03957 }
03958 
03959 
03960 void KMMainWidget::slotRequestFullSearchFromQuickSearch()
03961 {
03962     slotSearch();
03963 #ifdef HAVE_INDEXLIB
03964     return;
03965 #endif
03966     assert( mSearchWin );
03967     KMSearchPattern pattern;
03968     pattern.append( KMSearchRule::createInstance( "<message>", KMSearchRule::FuncContains, mQuickSearchLine->currentSearchTerm() ) );
03969     int status = mQuickSearchLine->currentStatus();
03970     if ( status != 0 ) {
03971         pattern.append( new KMSearchRuleStatus( status ) );
03972     }
03973     mSearchWin->setSearchPattern( pattern );
03974 }
03975 
03976 void KMMainWidget::updateVactionScriptStatus(bool active)
03977 {
03978   mVacationIndicatorActive = active;
03979   if ( active ) {
03980     mVacationScriptIndicator->setText( i18n("Out of office reply active") );
03981     mVacationScriptIndicator->setPaletteBackgroundColor( Qt::yellow );
03982     mVacationScriptIndicator->setCursor( QCursor( Qt::PointingHandCursor ) );
03983     mVacationScriptIndicator->show();
03984   } else {
03985     mVacationScriptIndicator->hide();
03986   }
03987 }
03988