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
28 #include "foldertreewidget.h"
31 #include <kxmlguiclient.h>
32 #include "messageactions.h"
34 #include <kactioncollection.h>
36 #include <foldercollection.h>
39 #include <QVBoxLayout>
44 #include <akonadi/kmime/standardmailactionmanager.h>
45 #include <messagelist/core/view.h>
46 #include <Solid/Networking>
61 class KMMetaFilterActionCommand
;
63 class CustomTemplatesMenu
;
66 template <typename T
, typename S
> class QMap
;
75 class TagActionManager
;
76 class FolderShortcutActionManager
;
80 class SieveDebugDialog
;
84 namespace MailCommon
{
85 class FolderSelectionDialog
;
88 class KMAIL_EXPORT KMMainWidget
: public QWidget
93 typedef QList
<KMMainWidget
*> PtrList
;
103 KMMainWidget(QWidget
*parent
, KXMLGUIClient
*aGUIClient
,
104 KActionCollection
*actionCollection
,
105 KSharedConfig::Ptr config
= KMKernel::self()->config() );
106 virtual ~KMMainWidget();
109 /** Read configuration options before widgets are created. */
110 virtual void readPreConfig();
112 /** Read configuration for current folder. */
113 virtual void readFolderConfig();
115 /** Write configuration for current folder. */
116 virtual void writeFolderConfig();
118 /** Read configuration options after widgets are created. */
119 virtual void readConfig();
121 /** Write configuration options. */
122 virtual void writeConfig();
124 /** Easy access to main components of the window. */
125 KMReaderWin
* messageView() const { return mMsgView
; }
126 /** Access to the header list pane. */
127 CollectionPane
* messageListPane() const { return mMessagePane
; }
129 QSharedPointer
<MailCommon::FolderCollection
> currentFolder() const;
131 static void cleanup();
133 QAction
*action( const char *name
) { return mActionCollection
->action( name
); }
134 KActionMenu
*filterMenu() const { return mFilterMenu
; }
135 KActionMenu
*mailingListActionMenu() const { return mMsgActions
->mailingListActionMenu(); }
136 KAction
*deleteAction() const { return mDeleteAction
; }
137 KAction
*trashThreadAction() const { return mTrashThreadAction
; }
138 KAction
*deleteThreadAction() const { return mDeleteThreadAction
; }
139 KAction
*saveAsAction() const { return mSaveAsAction
; }
140 KAction
*editAction() const { return mMsgActions
->editAction(); }
141 KAction
*useAction() const { return mUseAction
; }
142 KAction
*sendAgainAction() const { return mSendAgainAction
; }
143 KAction
*applyAllFiltersAction() const { return mApplyAllFiltersAction
; }
144 KAction
*findInMessageAction() const { return mFindInMessageAction
; }
145 KAction
*saveAttachmentsAction() const { return mSaveAttachmentsAction
; }
146 KAction
*openAction() const { return mOpenAction
; }
147 KAction
*viewSourceAction() const { return mViewSourceAction
; }
148 KMail::MessageActions
*messageActions() const { return mMsgActions
; }
150 KActionMenu
*threadStatusMenu() const { return mThreadStatusMenu
; }
151 KAction
*moveActionMenu() const{ return mMoveActionMenu
; }
152 KAction
*mopyActionMenu() const { return mCopyActionMenu
; }
153 KActionMenu
*applyFilterActionsMenu() const { return mApplyFilterActionsMenu
; }
155 KToggleAction
*watchThreadAction() const { return mWatchThreadAction
; }
156 KToggleAction
*ignoreThreadAction() const { return mIgnoreThreadAction
; }
159 void toggleSystemTray();
161 void updateListFilterAction();
164 Returns a list of all KMMainWidgets. Warning, the list itself can be 0.
165 @return the list of all main widgets, or 0 if it is not yet initialized
167 static const PtrList
*mainWidgetList();
169 KMSystemTray
*systray() const;
172 Return the list of all action, in order to check shortcuts conflicts against them.
174 QList
<QAction
*> actionList();
176 QLabel
* vacationScriptIndicator() const;
177 void updateVacationScriptStatus() { updateVacationScriptStatus( mVacationIndicatorActive
); }
179 MailCommon::FolderTreeView
*folderTreeView() const {
180 return mFolderTreeWidget
->folderTreeView();
183 /** Returns the XML GUI client. */
184 KXMLGUIClient
* guiClient() const { return mGUIClient
; }
186 KMail::TagActionManager
*tagActionManager() const {
187 return mTagActionManager
;
190 KMail::FolderShortcutActionManager
*folderShortcutActionManager() const {
191 return mFolderShortcutActionManager
;
195 // Moving messages around
197 * This will ask for a destination folder and move the currently selected
198 * messages (in MessageListView) into it.
200 void slotMoveSelectedMessageToFolder();
202 // Copying messages around
205 * This will ask for a destination folder and copy the currently selected
206 * messages (in MessageListView) into it.
208 void slotCopySelectedMessagesToFolder();
211 * Implements the "move to trash" action
213 void slotTrashSelectedMessages();
215 void slotCheckMail();
217 void slotCheckMailOnStartup();
220 Select the given folder
221 If the folder is 0 the intro is shown
223 void folderSelected( const Akonadi::Collection
& col
);
226 Open a separate viewer window containing the specified message.
228 void slotMessageActivated( const Akonadi::Item
& );
231 Opens mail in the internal viewer.
233 void slotMessageSelected( const Akonadi::Item
& );
235 void slotItemsFetchedForActivation( const Akonadi::Item::List
&list
);
236 void slotMessageStatusChangeRequest( const Akonadi::Item
&, const Akonadi::MessageStatus
&, const Akonadi::MessageStatus
& );
239 void slotReplaceMsgByUnencryptedVersion();
244 void updateMessageMenu();
247 Start a timer to update message actions
249 void startUpdateMessageActionsTimer();
251 /** Update message actions */
252 void updateMessageActions( bool fast
= false );
253 void updateMessageActionsDelayed();
255 /** Clear and create actions for marked filters */
256 void clearFilterActions();
257 void initializeFilterActions();
260 /** Trigger the dialog for editing out-of-office scripts. */
261 void slotEditVacation();
263 /** Adds if not existing/removes if existing the tag identified by @p aLabel
264 in all selected messages */
265 void slotUpdateMessageTagList( const QString
&aLabel
);
268 * Convenience function to get the action collection in a list.
270 * @return a list of action collections. The list only has one item, and
271 * that is the action collection of this main widget as returned
272 * by actionCollection().
274 QList
<KActionCollection
*> actionCollections() const;
277 KAction
*akonadiStandardAction( Akonadi::StandardActionManager::Type type
);
278 KAction
*akonadiStandardAction( Akonadi::StandardMailActionManager::Type type
);
279 void refreshMessageListSelection();
281 void slotStartCheckMail();
282 void slotEndCheckMail();
284 void slotCollectionProperties();
286 void slotSelectCollectionFolder( const Akonadi::Collection
& col
);
289 void messagesTransfered( bool );
290 void captionChangeRequest( const QString
&caption
);
293 void restoreCollectionFolderViewConfig();
295 void createWidgets();
296 void deleteWidgets();
297 void layoutSplitters();
298 void newFromTemplate( const Akonadi::Item
& );
299 void moveSelectedMessagesToFolder( const Akonadi::Collection
& dest
);
300 void copySelectedMessagesToFolder( const Akonadi::Collection
& dest
);
303 virtual void showEvent( QShowEvent
*event
);
305 KActionCollection
*actionCollection() const { return mActionCollection
; }
308 @return the correct config dialog depending on whether the parent of
309 the mainWidget is a KPart or a KMMainWindow.
310 When dealing with geometries, use this pointer
312 KSharedConfig::Ptr
config();
315 void updateFileMenu();
316 void slotCheckOneAccount( QAction
* );
318 void slotMailChecked( bool newMail
, bool sendOnCheck
,
319 const QMap
<QString
, int> & newInFolder
);
321 void getAccountMenu();
322 void getTransportMenu();
325 void slotManageSieveScripts();
330 void slotFolderMailingListProperties();
331 void slotShowFolderShortcutDialog();
332 void slotExpireFolder();
333 void slotExpireAll();
334 void slotArchiveFolder();
335 void slotRemoveFolder();
336 void slotDelayedRemoveFolder( KJob
* );
337 void slotEmptyFolder();
338 void slotAddFavoriteFolder();
339 void slotShowSelectedFolderInPane();
340 void slotOverrideHtml();
341 void slotOverrideHtmlLoadExt();
342 void slotMessageQueuedOrDrafted();
343 void slotUseTemplate();
344 void slotDeleteMsg( bool confirmDelete
= true ); // completely delete message
345 void slotTrashThread();
346 void slotDeleteThread( bool confirmDelete
= true ); // completely delete thread
351 void slotSaveAttachments();
352 void slotJumpToFolder();
353 void slotResendMsg();
354 void slotCheckVacation();
355 void slotDebugSieve();
356 void slotStartCertManager();
357 void slotStartWatchGnuPG();
358 void slotApplyFilters();
359 int slotFilterMsg( const Akonadi::Item
&msg
);
360 void slotExpandThread();
361 void slotExpandAllThreads();
362 void slotCollapseThread();
363 void slotCollapseAllThreads();
364 void slotShowMsgSrc();
365 void slotSetThreadStatusUnread();
366 void slotSetThreadStatusRead();
367 void slotSetThreadStatusImportant();
368 void slotSetThreadStatusToAct();
369 void slotSetThreadStatusWatched();
370 void slotSetThreadStatusIgnored();
371 void slotSendQueued();
372 void slotSendQueuedVia( QAction
* item
);
373 void slotOnlineStatus();
374 void slotUpdateOnlineStatus( GlobalSettings::EnumNetworkState::type
);
375 void slotNetworkStatusChanged ( Solid::Networking::Status
);
376 void slotMessagePopup(const Akonadi::Item
& ,const KUrl
&,const QPoint
& );
377 void slotDelayedMessagePopup( KJob
*job
);
379 void slotFocusQuickSearch();
383 void slotShowStartupFolder();
384 /** Show tip-of-the-day, forced */
386 void slotAntiSpamWizard();
387 void slotAntiVirusWizard();
388 void slotFilterLogViewer();
389 void slotAccountWizard();
390 /** Message navigation */
391 void slotSelectNextMessage();
392 void slotExtendSelectionToNextMessage();
393 void slotSelectNextUnreadMessage();
394 void slotSelectPreviousMessage();
395 void slotExtendSelectionToPreviousMessage();
396 void slotSelectPreviousUnreadMessage();
397 void slotFocusOnNextMessage();
398 void slotFocusOnPrevMessage();
399 void slotSelectFocusedMessage();
401 void slotNextUnreadFolder();
402 void slotPrevUnreadFolder();
405 void slotDisplayCurrentMessage();
407 void slotShowNewFromTemplate();
408 void slotDelayedShowNewFromTemplate( KJob
* );
409 void slotNewFromTemplate( QAction
* );
411 /** Update the undo action */
412 void slotUpdateUndo();
414 /** Update html and threaded messages preferences in Folder menu. */
415 void updateFolderMenu();
420 void slotEditNotifications();
422 /** Slot to reply to a message */
423 void slotCustomReplyToMsg( const QString
&tmpl
);
424 void slotCustomReplyAllToMsg( const QString
&tmpl
);
425 void slotForwardInlineMsg();
426 void slotForwardAttachedMsg();
427 void slotRedirectMsg();
428 void slotCustomForwardMsg( const QString
&tmpl
);
429 void slotNoQuoteReplyToMsg();
430 void slotSubjectFilter();
431 void slotMailingListFilter();
432 void slotFromFilter();
434 void slotCreateTodo();
436 void slotConfigChanged();
438 /** Show a splash screen for the longer-lasting operation */
439 void slotShowBusySplash();
442 Show a message screen explaining that we are currently offline, when
443 an online folder is selected.
445 void showOfflinePage();
447 void updateVacationScriptStatus( bool active
);
450 void slotShowExpiryProperties();
451 void slotItemAdded( const Akonadi::Item
&, const Akonadi::Collection
& col
);
452 void slotItemRemoved( const Akonadi::Item
& );
453 void slotItemMoved( Akonadi::Item item
, Akonadi::Collection from
, Akonadi::Collection to
);
454 void slotCollectionStatisticsChanged( const Akonadi::Collection::Id
, const Akonadi::CollectionStatistics
& );
456 void slotAkonadiStandardActionUpdated();
457 void slotCollectionChanged( const Akonadi::Collection
&, const QSet
<QByteArray
>& );
458 void slotCreateNewTab( bool );
462 /** Get override character encoding. */
463 QString
overrideEncoding() const;
465 /** Update the custom template menus. */
466 void updateCustomTemplateMenus();
469 void moveMessageSelected( MessageList::Core::MessageItemSetReference ref
, const Akonadi::Collection
&dest
, bool confirmOnDeletion
= true );
471 void copyMessageSelected( const QList
<Akonadi::Item
> &selectMsg
, const Akonadi::Collection
&dest
);
475 * Move the messages referenced by the specified set to trash.
476 * The set parameter must not be null and the ownership is passed
479 void trashMessageSelected( MessageList::Core::MessageItemSetReference ref
);
481 * Set the status of the messages referenced by the specified set, eventually toggling it.
482 * The set parameter must not be null and the ownership is passed to this function.
484 void setMessageSetStatus( const QList
<Akonadi::Item
> &select
,
485 const Akonadi::MessageStatus
&status
,
489 * Toggles a tag for the messages referenced by the specified set.
490 * The set parameter must not be null and the ownership is passed to this function.
492 void toggleMessageSetTag( const QList
<Akonadi::Item
> &select
, const QString
&taglabel
);
494 * This applies setMessageSetStatus() on the current thread.
496 void setCurrentThreadStatus( const Akonadi::MessageStatus
&status
, bool toggle
);
498 void applyFilters( const QList
<Akonadi::Item
>& selectedMessages
);
501 * Internal helper that creates the folder selection dialog used for the
502 * move and copy to folder actions on demand. Only folders where items can
503 * be added are listed.
505 MailCommon::FolderSelectionDialog
* moveOrCopyToDialog();
508 * Internal helper that creates the folder selection dialog used for
509 * jumping to folders, or adding them as favourites. All folders are listed.
511 MailCommon::FolderSelectionDialog
* selectFromAllFoldersDialog();
514 void addInfoInNotification( const Akonadi::Collection
&col
);
518 * Called when a "move to trash" operation is completed
520 void slotTrashMessagesCompleted( KMMoveCommand
*command
);
523 * Called when a "move" operation is completed
525 void slotMoveMessagesCompleted( KMMoveCommand
*command
);
528 * Called when a "copy" operation is completed
530 void slotCopyMessagesCompleted( KMCommand
*command
);
532 void slotRequestFullSearchFromQuickSearch();
533 void slotFolderChanged( const Akonadi::Collection
& );
535 void itemsReceived(const Akonadi::Item::List
&list
);
536 void itemsFetchDone( KJob
*job
);
538 void slotItemNotMovedByFilters( const Akonadi::Item
& item
);
540 void slotCollectionPropertiesContinued( KJob
* job
);
543 KAction
*mDeleteAction
, *mTrashThreadAction
,
544 *mDeleteThreadAction
, *mSaveAsAction
, *mUseAction
,
545 *mSendAgainAction
, *mApplyAllFiltersAction
, *mFindInMessageAction
,
546 *mSaveAttachmentsAction
, *mOpenAction
, *mViewSourceAction
,
547 *mMoveMsgToFolderAction
, *mCollectionProperties
, *mSendQueued
;
549 KActionMenu
*mFilterMenu
;
550 KAction
*mSubjectFilterAction
, *mFromFilterAction
, *mToFilterAction
,
552 KAction
*mNextMessageAction
, *mPreviousMessageAction
;
553 KAction
*mExpireConfigAction
;
554 KAction
*mAddFavoriteFolder
;
555 // Custom template actions menu
556 KActionMenu
*mTemplateMenu
;
557 CustomTemplatesMenu
*mCustomTemplateMenus
;
559 KActionMenu
*mThreadStatusMenu
, *mApplyFilterActionsMenu
;
560 KAction
*mCopyActionMenu
;
561 KAction
*mMoveActionMenu
;
562 KAction
*mMarkThreadAsReadAction
;
563 KAction
*mMarkThreadAsUnreadAction
;
564 KToggleAction
*mToggleThreadImportantAction
;
565 KToggleAction
*mToggleThreadToActAction
;
566 KToggleAction
*mToggleThreadFlagAction
;
568 KToggleAction
*mWatchThreadAction
, *mIgnoreThreadAction
;
570 Akonadi::EntityListView
*mFavoriteCollectionsView
;
571 Akonadi::FavoriteCollectionsModel
*mFavoritesModel
;
572 QWidget
*mSearchAndTree
;
573 KMReaderWin
*mMsgView
;
574 QSplitter
*mSplitter1
, *mSplitter2
, *mFolderViewSplitter
;
575 Akonadi::Collection mTemplateFolder
;
576 QMenu
*mViewMenu
, *mBodyPartsMenu
;
577 KAction
*mlistFilterAction
;
582 bool mLongFolderList
;
585 bool mHtmlPref
, mHtmlLoadExtPref
,
586 mFolderHtmlPref
, mFolderHtmlLoadExtPref
,
587 mReaderWindowActive
, mReaderWindowBelow
;
588 bool mEnableFavoriteFolderView
;
589 bool mEnableFolderQuickSearch
;
591 QPointer
<KMail::SearchWindow
> mSearchWin
;
593 KAction
*mExpireFolderAction
,
594 *mFolderMailingListPropertiesAction
,
595 *mShowFolderShortcutDialogAction
,
596 *mArchiveFolderAction
,
597 *mPostToMailinglistAction
;
598 KToggleAction
*mPreferHtmlAction
, *mPreferHtmlLoadExtAction
;
599 KToggleAction
*mFolderAction
, *mHeaderAction
, *mMimeAction
;
602 QTimer
*mShowBusySplashTimer
;
604 QPointer
<KSieveUi::Vacation
> mVacation
;
606 QPointer
<KSieveUi::SieveDebugDialog
> mSieveDebugDialog
;
608 KActionCollection
*mActionCollection
;
609 QAction
*mToolbarActionSeparator
;
610 QVBoxLayout
*mTopLayout
;
611 bool mDestructed
, mForceJumpToUnread
, mShowingOfflineScreen
;
612 QList
<QAction
*> mFilterMenuActions
;
613 QList
<QAction
*> mFilterTBarActions
;
614 QList
<KMMetaFilterActionCommand
*> mFilterCommands
;
616 KMail::TagActionManager
*mTagActionManager
;
617 KMail::FolderShortcutActionManager
*mFolderShortcutActionManager
;
618 KMSystemTray
*mSystemTray
;
619 KSharedConfig::Ptr mConfig
;
620 KXMLGUIClient
*mGUIClient
;
622 KMail::MessageActions
*mMsgActions
;
623 Akonadi::StandardMailActionManager
*mAkonadiStandardActionManager
;
624 CollectionPane
*mMessagePane
;
625 QSharedPointer
<MailCommon::FolderCollection
> mCurrentFolder
;
627 MailCommon::FolderTreeWidget
*mFolderTreeWidget
;
629 KMail::StatusBarLabel
*mVacationScriptIndicator
;
630 bool mVacationIndicatorActive
;
631 bool mGoToFirstUnreadMessageInSelectedFolder
;
632 MessageList::Core::PreSelectionMode mPreSelectionMode
;
634 /// Used during mail check to remember how many mails there are in the folders
635 QMap
<Akonadi::Collection::Id
, int> mCheckMail
;
637 bool mCheckMailInProgress
;
638 MailCommon::FolderSelectionDialog
* mMoveOrCopyToDialog
;
639 MailCommon::FolderSelectionDialog
* mSelectFromAllFoldersDialog
;