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