1 /* -*- mode: C++; c-file-style: "gnu" -*-
2 This file is part of KMail, the KDE mail client.
3 Copyright (c) 2002 Don Sanders <sanders@kde.org>
5 Based on the work of Stefan Taferner <taferner@kde.org>
7 KMail is free software; you can redistribute it and/or modify it
8 under the terms of the GNU General Public License, version 2, as
9 published by the Free Software Foundation.
11 KMail is distributed in the hope that it will be useful, but
12 WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 General Public License for more details.
16 You should have received a copy of the GNU General Public License along
17 with this program; if not, write to the Free Software Foundation, Inc.,
18 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
21 #ifndef __KMMAINWIDGET
22 #define __KMMAINWIDGET
24 #include "kmail_export.h"
25 #include "kmreaderwin.h" //for inline actions
26 #include "kmkernel.h" // for access to config
29 #include <kxmlguiclient.h>
30 #include "messageactions.h"
32 #include <kactioncollection.h>
34 #include <foldercollection.h>
37 #include <QVBoxLayout>
42 #include <akonadi/standardactionmanager.h>
43 #include <messagelist/core/view.h>
44 #include "foldertreewidget.h"
60 class KMMetaFilterActionCommand
;
62 class CustomTemplatesMenu
;
65 template <typename T
, typename S
> class QMap
;
73 class SieveDebugDialog
;
76 class TagActionManager
;
77 class FolderShortcutActionManager
;
80 class FolderTreeWidget
;
82 class KMAIL_EXPORT KMMainWidget
: public QWidget
87 typedef QList
<KMMainWidget
*> PtrList
;
97 KMMainWidget(QWidget
*parent
, KXMLGUIClient
*aGUIClient
,
98 KActionCollection
*actionCollection
,
99 KSharedConfig::Ptr config
= KMKernel::config() );
100 virtual ~KMMainWidget();
103 /** Read configuration options before widgets are created. */
104 virtual void readPreConfig();
106 /** Read configuration for current folder. */
107 virtual void readFolderConfig();
109 /** Write configuration for current folder. */
110 virtual void writeFolderConfig();
112 /** Read configuration options after widgets are created. */
113 virtual void readConfig();
115 /** Write configuration options. */
116 virtual void writeConfig();
118 /** Easy access to main components of the window. */
119 KMReaderWin
* messageView() const { return mMsgView
; }
120 /** Access to the header list pane. */
121 CollectionPane
* messageListPane() const { return mMessagePane
; }
123 QSharedPointer
<FolderCollection
> currentFolder() const;
125 static void cleanup();
127 QAction
*action( const char *name
) { return mActionCollection
->action( name
); }
128 KActionMenu
*filterMenu() const { return mFilterMenu
; }
129 KActionMenu
*mailingListActionMenu() const { return mMsgActions
->mailingListActionMenu(); }
130 KAction
*trashAction() const { return mTrashAction
; }
131 KAction
*deleteAction() const { return mDeleteAction
; }
132 KAction
*trashThreadAction() const { return mTrashThreadAction
; }
133 KAction
*deleteThreadAction() const { return mDeleteThreadAction
; }
134 KAction
*saveAsAction() const { return mSaveAsAction
; }
135 KAction
*editAction() const { return mMsgActions
->editAction(); }
136 KAction
*useAction() const { return mUseAction
; }
137 KAction
*sendAgainAction() const { return mSendAgainAction
; }
138 KAction
*applyAllFiltersAction() const { return mApplyAllFiltersAction
; }
139 KAction
*findInMessageAction() const { return mFindInMessageAction
; }
140 KAction
*saveAttachmentsAction() const { return mSaveAttachmentsAction
; }
141 KAction
*openAction() const { return mOpenAction
; }
142 KAction
*viewSourceAction() const { return mViewSourceAction
; }
143 KMail::MessageActions
*messageActions() const { return mMsgActions
; }
145 KActionMenu
*threadStatusMenu() const { return mThreadStatusMenu
; }
146 KAction
*moveActionMenu() const{ return mMoveActionMenu
; }
147 KAction
*mopyActionMenu() const { return mCopyActionMenu
; }
148 KActionMenu
*applyFilterActionsMenu() const { return mApplyFilterActionsMenu
; }
150 KToggleAction
*watchThreadAction() const { return mWatchThreadAction
; }
151 KToggleAction
*ignoreThreadAction() const { return mIgnoreThreadAction
; }
154 void toggleSystemTray();
156 void updateListFilterAction();
159 Returns a list of all KMMainWidgets. Warning, the list itself can be 0.
160 @return the list of all main widgets, or 0 if it is not yet initialized
162 static const PtrList
*mainWidgetList();
164 KMSystemTray
*systray() const;
167 Return the list of all action, in order to check shortcuts conflicts against them.
169 QList
<QAction
*> actionList();
171 QLabel
* vacationScriptIndicator() const;
172 void updateVacationScriptStatus() { updateVacationScriptStatus( mVacationIndicatorActive
); }
173 void selectCollectionFolder( const Akonadi::Collection
& col
);
175 FolderTreeView
*folderTreeView() const {
176 return mFolderTreeWidget
->folderTreeView();
179 /** Returns the XML GUI client. */
180 KXMLGUIClient
* guiClient() const { return mGUIClient
; }
182 KMail::TagActionManager
*tagActionManager() const {
183 return mTagActionManager
;
186 KMail::FolderShortcutActionManager
*folderShortcutActionManager() const {
187 return mFolderShortcutActionManager
;
191 // Moving messages around
193 * This will ask for a destination folder and move the currently selected
194 * messages (in MessageListView) into it.
196 void slotMoveSelectedMessageToFolder();
198 // Copying messages around
201 * This will ask for a destination folder and copy the currently selected
202 * messages (in MessageListView) into it.
204 void slotCopySelectedMessagesToFolder();
207 * Implements the "move to trash" action
209 void slotTrashSelectedMessages();
211 void slotCheckMail();
213 void slotCheckMailOnStartup();
216 Select the given folder
217 If the folder is 0 the intro is shown
219 void folderSelected( const Akonadi::Collection
& col
);
222 Open a separate viewer window containing the specified message.
224 void slotMessageActivated( const Akonadi::Item
& );
227 Opens mail in the internal viewer.
229 void slotMessageSelected( const Akonadi::Item
& );
231 void slotItemsFetchedForActivation( const Akonadi::Item::List
&list
);
232 void slotMessageStatusChangeRequest( const Akonadi::Item
&, const KPIM::MessageStatus
&, const KPIM::MessageStatus
& );
235 void slotReplaceMsgByUnencryptedVersion();
240 void updateMessageMenu();
243 Start a timer to update message actions
245 void startUpdateMessageActionsTimer();
247 /** Update message actions */
248 void updateMessageActions( bool fast
= false );
249 void updateMessageActionsDelayed();
251 /** Clear and create actions for marked filters */
252 void clearFilterActions();
253 void initializeFilterActions();
256 /** Trigger the dialog for editing out-of-office scripts. */
257 void slotEditVacation();
259 /** Adds if not existing/removes if existing the tag identified by @p aLabel
260 in all selected messages */
261 void slotUpdateMessageTagList( const QString
&aLabel
);
264 * Convenience function to get the action collection in a list.
266 * @return a list of action collections. The list only has one item, and
267 * that is the action collection of this main widget as returned
268 * by actionCollection().
270 QList
<KActionCollection
*> actionCollections() const;
273 KAction
*akonadiStandardAction( Akonadi::StandardActionManager::Type type
);
275 void refreshMessageListSelection();
277 void slotStartCheckMail();
278 void slotEndCheckMail();
281 void messagesTransfered( bool );
282 void captionChangeRequest( const QString
&caption
);
285 void restoreCollectionFolderViewConfig();
287 void createWidgets();
288 void deleteWidgets();
289 void layoutSplitters();
290 void updateFileMenu();
291 void newFromTemplate( const Akonadi::Item
& );
292 void moveSelectedMessagesToFolder( const Akonadi::Collection
& dest
);
293 void copySelectedMessagesToFolder( const Akonadi::Collection
& dest
);
296 virtual void showEvent( QShowEvent
*event
);
298 KActionCollection
*actionCollection() const { return mActionCollection
; }
301 @return the correct config dialog depending on whether the parent of
302 the mainWidget is a KPart or a KMMainWindow.
303 When dealing with geometries, use this pointer
305 KSharedConfig::Ptr
config();
308 void slotCheckOneAccount( QAction
* );
310 void slotMailChecked( bool newMail
, bool sendOnCheck
,
311 const QMap
<QString
, int> & newInFolder
);
313 void getAccountMenu();
314 void getTransportMenu();
317 void slotPopFilter();
318 void slotManageSieveScripts();
323 void slotFolderMailingListProperties();
324 void slotShowFolderShortcutDialog();
325 void slotExpireFolder();
326 void slotExpireAll();
327 void slotMarkAllAsRead();
328 void slotArchiveFolder();
329 void slotRemoveFolder();
330 void slotDelayedRemoveFolder( KJob
* );
331 void slotEmptyFolder();
332 void slotAddFavoriteFolder();
333 void slotShowSelectedForderInPane();
334 void slotOverrideHtml();
335 void slotOverrideHtmlLoadExt();
336 void slotMessageQueuedOrDrafted();
337 void slotUseTemplate();
338 void slotDeleteMsg( bool confirmDelete
= true ); // completely delete message
339 void slotTrashThread();
340 void slotDeleteThread( bool confirmDelete
= true ); // completely delete thread
345 void slotSaveAttachments();
346 void slotJumpToFolder();
347 void slotResendMsg();
348 void slotCheckVacation();
349 void slotDebugSieve();
350 void slotStartCertManager();
351 void slotStartWatchGnuPG();
352 void slotApplyFilters();
353 int slotFilterMsg( const Akonadi::Item
&msg
);
354 void slotExpandThread();
355 void slotExpandAllThreads();
356 void slotCollapseThread();
357 void slotCollapseAllThreads();
358 void slotShowMsgSrc();
359 void slotSetThreadStatusUnread();
360 void slotSetThreadStatusRead();
361 void slotSetThreadStatusImportant();
362 void slotSetThreadStatusToAct();
363 void slotSetThreadStatusWatched();
364 void slotSetThreadStatusIgnored();
365 void slotSendQueued();
366 void slotSendQueuedVia( QAction
* item
);
367 void slotOnlineStatus();
368 void slotUpdateOnlineStatus( GlobalSettings::EnumNetworkState::type
);
369 void slotMessagePopup(const Akonadi::Item
& ,const KUrl
&,const QPoint
& );
370 void slotDelayedMessagePopup( KJob
*job
);
372 void slotFocusQuickSearch();
374 void slotSearchClosed();
377 void slotShowStartupFolder();
378 /** Show tip-of-the-day, forced */
380 void slotAntiSpamWizard();
381 void slotAntiVirusWizard();
382 void slotFilterLogViewer();
383 void slotAccountWizard();
384 /** Message navigation */
385 void slotSelectNextMessage();
386 void slotExtendSelectionToNextMessage();
387 void slotSelectNextUnreadMessage();
388 void slotSelectPreviousMessage();
389 void slotExtendSelectionToPreviousMessage();
390 void slotSelectPreviousUnreadMessage();
391 void slotFocusOnNextMessage();
392 void slotFocusOnPrevMessage();
393 void slotSelectFocusedMessage();
395 void slotNextUnreadFolder();
396 void slotPrevUnreadFolder();
399 void slotDisplayCurrentMessage();
401 void slotShowNewFromTemplate();
402 void slotDelayedShowNewFromTemplate( KJob
* );
403 void slotNewFromTemplate( QAction
* );
405 /** Update the undo action */
406 void slotUpdateUndo();
408 /** Update html and threaded messages preferences in Folder menu. */
409 void updateFolderMenu();
411 Enable or disable the "mark all as read" action. Needs to happen more
412 often than the other updates and is therefor in its own method.
414 void updateMarkAsReadAction();
419 void slotEditNotifications();
422 void removeDuplicates();
424 /** Slot to reply to a message */
425 void slotCustomReplyToMsg( const QString
&tmpl
);
426 void slotCustomReplyAllToMsg( const QString
&tmpl
);
427 void slotForwardInlineMsg();
428 void slotForwardAttachedMsg();
429 void slotRedirectMsg();
430 void slotCustomForwardMsg( const QString
&tmpl
);
431 void slotNoQuoteReplyToMsg();
432 void slotSubjectFilter();
433 void slotMailingListFilter();
434 void slotFromFilter();
436 void slotCreateTodo();
438 void slotConfigChanged();
440 /** Show a splash screen for the longer-lasting operation */
441 void slotShowBusySplash();
444 Show a message screen explaining that we are currently offline, when
445 an online folder is selected.
447 void showOfflinePage();
449 void updateVacationScriptStatus( bool active
);
452 void slotShowExpiryProperties();
453 void slotItemAdded( const Akonadi::Item
&, const Akonadi::Collection
& col
);
454 void slotItemRemoved( const Akonadi::Item
& );
455 void slotItemMoved( Akonadi::Item item
, Akonadi::Collection from
, Akonadi::Collection to
);
457 void slotAkonadiStandardActionUpdated();
459 /** Get override character encoding. */
460 QString
overrideEncoding() const;
462 /** Update the custom template menus. */
463 void updateCustomTemplateMenus();
466 void moveMessageSelected( MessageList::Core::MessageItemSetReference ref
, const Akonadi::Collection
&dest
, bool confirmOnDeletion
= true );
468 void copyMessageSelected( const QList
<Akonadi::Item
> &selectMsg
, const Akonadi::Collection
&dest
);
472 * Move the messages referenced by the specified set to trash.
473 * The set parameter must not be null and the ownership is passed
476 void trashMessageSelected( MessageList::Core::MessageItemSetReference ref
);
478 * Set the status of the messages referenced by the specified set, eventually toggling it.
479 * The set parameter must not be null and the ownership is passed to this function.
481 void setMessageSetStatus( const QList
<Akonadi::Item
> &select
,
482 const KPIM::MessageStatus
&status
,
486 * Toggles a tag for the messages referenced by the specified set.
487 * The set parameter must not be null and the ownership is passed to this function.
489 void toggleMessageSetTag( const QList
<Akonadi::Item
> &select
, const QString
&taglabel
);
491 * This applies setMessageSetStatus() on the current thread.
493 void setCurrentThreadStatus( const KPIM::MessageStatus
&status
, bool toggle
);
496 * Called when a "move to trash" operation is completed
498 void slotTrashMessagesCompleted( KMMoveCommand
*command
);
501 * Called when a "move" operation is completed
503 void slotMoveMessagesCompleted( KMMoveCommand
*command
);
506 * Called when a "copy" operation is completed
508 void slotCopyMessagesCompleted( KMCommand
*command
);
510 void slotRequestFullSearchFromQuickSearch();
511 void slotFolderChanged( const Akonadi::Collection
& );
513 void itemsReceived(const Akonadi::Item::List
&list
);
514 void itemsFetchDone( KJob
*job
);
515 void itemsFetchJobForFilterDone( KJob
*job
);
516 void slotItemsFetchedForFilter( const Akonadi::Item::List
& );
519 KAction
*mTrashAction
, *mDeleteAction
, *mTrashThreadAction
,
520 *mDeleteThreadAction
, *mSaveAsAction
, *mUseAction
,
521 *mSendAgainAction
, *mApplyAllFiltersAction
, *mFindInMessageAction
,
522 *mSaveAttachmentsAction
, *mOpenAction
, *mViewSourceAction
,
523 *mMoveMsgToFolderAction
, *mCollectionProperties
, *mSendQueued
;
525 KActionMenu
*mFilterMenu
;
526 KAction
*mSubjectFilterAction
, *mFromFilterAction
, *mToFilterAction
,
529 KAction
*mNextMessageAction
, *mPreviousMessageAction
;
530 KAction
*mExpireConfigAction
;
531 KAction
*mAddFavoriteFolder
;
532 // Custom template actions menu
533 KActionMenu
*mTemplateMenu
;
534 CustomTemplatesMenu
*mCustomTemplateMenus
;
536 KActionMenu
*mThreadStatusMenu
, *mApplyFilterActionsMenu
;
537 KAction
*mCopyActionMenu
;
538 KAction
*mMoveActionMenu
;
539 KAction
*mMarkThreadAsReadAction
;
540 KAction
*mMarkThreadAsUnreadAction
;
541 KToggleAction
*mToggleThreadImportantAction
;
542 KToggleAction
*mToggleThreadToActAction
;
543 KToggleAction
*mToggleThreadFlagAction
;
544 KToggleAction
* mSizeColumnToggle
;
546 KToggleAction
*mWatchThreadAction
, *mIgnoreThreadAction
;
548 Akonadi::EntityListView
*mFavoriteCollectionsView
;
549 Akonadi::FavoriteCollectionsModel
*mFavoritesModel
;
550 QWidget
*mSearchAndTree
;
551 KMReaderWin
*mMsgView
;
552 QSplitter
*mSplitter1
, *mSplitter2
, *mFolderViewSplitter
;
553 Akonadi::Collection mTemplateFolder
;
554 QMenu
*mViewMenu
, *mBodyPartsMenu
;
555 KAction
*mlistFilterAction
;
559 int mMessageStatusId
;
564 bool mLongFolderList
;
567 int copyId
, moveId
, htmlId
, threadId
;
568 bool mHtmlPref
, mHtmlLoadExtPref
,
569 mFolderHtmlPref
, mFolderHtmlLoadExtPref
,
570 mReaderWindowActive
, mReaderWindowBelow
;
571 bool mEnableFavoriteFolderView
;
572 bool mEnableFolderQuickSearch
;
574 // QPopupMenu *mMessageMenu;
575 KMail::SearchWindow
*mSearchWin
;
577 KAction
*mRemoveFolderAction
,
578 *mExpireFolderAction
,
579 *mEmptyFolderAction
, *mMarkAllAsReadAction
, *mFolderMailingListPropertiesAction
,
580 *mShowFolderShortcutDialogAction
,
581 *mRemoveDuplicatesAction
, *mArchiveFolderAction
,
582 *mPostToMailinglistAction
;
583 KToggleAction
*mPreferHtmlAction
, *mPreferHtmlLoadExtAction
;
584 KToggleAction
*mFolderAction
, *mHeaderAction
, *mMimeAction
;
587 QTimer
*mShowBusySplashTimer
;
589 QPointer
<KMail::Vacation
> mVacation
;
591 QPointer
<KMail::SieveDebugDialog
> mSieveDebugDialog
;
593 KActionCollection
*mActionCollection
;
594 QAction
*mToolbarActionSeparator
;
595 QVBoxLayout
*mTopLayout
;
596 bool mDestructed
, mForceJumpToUnread
, mShowingOfflineScreen
;
597 QList
<QAction
*> mFilterMenuActions
;
598 QList
<QAction
*> mFilterTBarActions
;
599 QList
<KMMetaFilterActionCommand
*> mFilterCommands
;
601 KMail::TagActionManager
*mTagActionManager
;
602 KMail::FolderShortcutActionManager
*mFolderShortcutActionManager
;
603 KMSystemTray
*mSystemTray
;
604 KSharedConfig::Ptr mConfig
;
605 KXMLGUIClient
*mGUIClient
;
607 KMail::MessageActions
*mMsgActions
;
608 Akonadi::StandardActionManager
*mAkonadiStandardActionManager
;
609 CollectionPane
*mMessagePane
;
610 QSharedPointer
<FolderCollection
> mCurrentFolder
;
612 FolderTreeWidget
*mFolderTreeWidget
;
613 bool mOpenedImapFolder
;
615 KMail::StatusBarLabel
*mVacationScriptIndicator
;
616 bool mVacationIndicatorActive
;
617 bool mGoToFirstUnreadMessageInSelectedFolder
;
618 MessageList::Core::PreSelectionMode mPreSelectionMode
;
620 KPIM::ProgressItem
*mFilterProgressItem
;
622 struct collectionInfo
{
623 collectionInfo( const Akonadi::Collection
& collection
= Akonadi::Collection(), int nb
= 0 ) {
627 collectionInfo
& operator=( const collectionInfo
& other
) {
628 if ( this == &other
)
631 nbMail
= other
.nbMail
;
634 Akonadi::Collection col
;
638 QMap
<QString
, collectionInfo
> mCheckMail
;
639 bool mCheckMailInProgress
;