Fix mem leak
[kdepim.git] / kmail / kmmainwidget.h
blob0665a0aa1195573f3643c56d4ce109de9b742c96
1 /*
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 "mailcommon/foldertreewidget.h"
30 #include <kxmlguiclient.h>
31 #include "messageactions.h"
32 #include <kactioncollection.h>
33 #include <mailcommon/foldercollection.h>
35 #include <QPointer>
36 #include <QTimer>
37 #include <Akonadi/KMime/StandardMailActionManager>
38 #include <AkonadiCore/tag.h>
39 #include <MessageList/View>
41 namespace MailTransport
43 class Transport;
45 namespace Akonadi
47 class Tag;
50 namespace KMime
52 class Message;
54 class QUrl;
55 class QVBoxLayout;
56 class QSplitter;
57 class KMLaunchExternalComponent;
58 class DisplayMessageFormatActionMenu;
59 class QAction;
60 class KActionMenu;
61 class KToggleAction;
62 class KMMetaFilterActionCommand;
63 class CollectionPane;
64 class KMCommand;
65 class KMMoveCommand;
66 class KRecentFilesAction;
67 class ManageShowCollectionProperties;
68 class KActionMenuTransport;
69 class KActionMenuAccount;
70 class KMailPluginInterface;
71 template <typename T, typename S> class QMap;
73 namespace KIO
75 class Job;
78 namespace KMail
80 class SearchWindow;
81 class VacationScriptIndicatorWidget;
82 class TagActionManager;
83 class FolderShortcutActionManager;
86 namespace KSieveUi
88 class SieveDebugDialog;
89 class ManageSieveScriptsDialog;
90 class VacationManager;
93 namespace MailCommon
95 class FolderSelectionDialog;
96 class FavoriteCollectionWidget;
99 class KMAIL_EXPORT KMMainWidget : public QWidget
101 Q_OBJECT
103 public:
104 typedef QList<KMMainWidget *> PtrList;
106 KMMainWidget(QWidget *parent, KXMLGUIClient *aGUIClient,
107 KActionCollection *actionCollection,
108 KSharedConfig::Ptr config = KMKernel::self()->config());
109 virtual ~KMMainWidget();
110 void destruct();
112 /** Read configuration options before widgets are created. */
113 void readPreConfig();
115 /** Read configuration for current folder. */
116 void readFolderConfig();
118 /** Write configuration for current folder. */
119 void writeFolderConfig();
121 /** Read configuration options after widgets are created. */
122 void readConfig();
124 /** Write configuration options. */
125 void writeConfig(bool force = true);
127 void writeReaderConfig();
129 /** Easy access to main components of the window. */
130 KMReaderWin *messageView() const;
131 /** Access to the header list pane. */
132 CollectionPane *messageListPane() const;
134 QSharedPointer<MailCommon::FolderCollection> currentFolder() const;
136 static void cleanup();
137 QAction *action(const QString &name)
139 return mActionCollection->action(name);
141 KActionMenu *filterMenu() const
143 return mFilterMenu;
145 KActionMenu *mailingListActionMenu() const
147 return mMsgActions->mailingListActionMenu();
149 QAction *editAction() const
151 return mMsgActions->editAction();
153 QAction *sendAgainAction() const
155 return mSendAgainAction;
157 QAction *sendQueuedAction() const
159 return mSendQueued;
161 KActionMenuTransport *sendQueueViaMenu() const
163 return mSendActionMenu;
166 KMail::MessageActions *messageActions() const
168 return mMsgActions;
172 Returns a list of all KMMainWidgets. Warning, the list itself can be 0.
173 @return the list of all main widgets, or 0 if it is not yet initialized
175 static const PtrList *mainWidgetList();
177 QWidget *vacationScriptIndicator() const;
178 void updateVacationScriptStatus();
180 MailCommon::FolderTreeView *folderTreeView() const
182 return mFolderTreeWidget->folderTreeView();
185 /** Returns the XML GUI client. */
186 KXMLGUIClient *guiClient() const
188 return mGUIClient;
191 KMail::TagActionManager *tagActionManager() const;
193 KMail::FolderShortcutActionManager *folderShortcutActionManager() const;
194 void savePaneSelection();
196 void updatePaneTagComboBox();
198 void clearViewer();
200 void addRecentFile(const QUrl &mUrl);
201 void updateQuickSearchLineText();
203 void populateMessageListStatusFilterCombo();
204 void initializePluginActions();
206 Akonadi::Item::List currentSelection() const;
208 public Q_SLOTS:
209 // Moving messages around
211 * This will ask for a destination folder and move the currently selected
212 * messages (in MessageListView) into it.
214 void slotMoveSelectedMessageToFolder();
216 // Copying messages around
219 * This will ask for a destination folder and copy the currently selected
220 * messages (in MessageListView) into it.
222 void slotCopySelectedMessagesToFolder();
225 * Implements the "move to trash" action
227 void slotTrashSelectedMessages();
229 void slotCheckMail();
231 void slotCheckMailOnStartup();
234 Select the given folder
235 If the folder is 0 the intro is shown
237 void folderSelected(const Akonadi::Collection &col);
240 Open a separate viewer window containing the specified message.
242 void slotMessageActivated(const Akonadi::Item &);
245 Opens mail in the internal viewer.
247 void slotMessageSelected(const Akonadi::Item &);
249 void slotItemsFetchedForActivation(KMCommand *command);
250 void slotMessageStatusChangeRequest(const Akonadi::Item &, const Akonadi::MessageStatus &, const Akonadi::MessageStatus &);
252 void slotReplaceMsgByUnencryptedVersion();
255 Update message menu
257 void updateMessageMenu();
260 Start a timer to update message actions
262 void startUpdateMessageActionsTimer();
264 /** Update message actions */
265 void updateMessageActions(bool fast = false);
266 void updateMessageActionsDelayed();
268 /** Clear and create actions for marked filters */
269 void clearFilterActions();
270 void initializeFilterActions();
272 /** Trigger the dialog for editing out-of-office scripts. */
273 void slotEditVacation(const QString &serverName = QString());
275 /** Adds if not existing/removes if existing the tag identified by @p aLabel
276 in all selected messages */
277 void slotUpdateMessageTagList(const Akonadi::Tag &tag);
278 void slotSelectMoreMessageTagList();
281 * Convenience function to get the action collection in a list.
283 * @return a list of action collections. The list only has one item, and
284 * that is the action collection of this main widget as returned
285 * by actionCollection().
287 QList<KActionCollection *> actionCollections() const;
289 QAction *akonadiStandardAction(Akonadi::StandardActionManager::Type type);
290 QAction *akonadiStandardAction(Akonadi::StandardMailActionManager::Type type);
291 Akonadi::StandardMailActionManager *standardMailActionManager() const
293 return mAkonadiStandardActionManager;
296 void refreshMessageListSelection();
298 void slotStartCheckMail();
299 void slotEndCheckMail();
301 void slotRemoveDuplicates();
303 void slotSelectCollectionFolder(const Akonadi::Collection &col);
305 void restoreCollectionFolderViewConfig();
306 void slotUpdateConfig();
307 Q_SIGNALS:
308 void messagesTransfered(bool);
309 void captionChangeRequest(const QString &caption);
310 void recreateGui();
312 protected:
313 void setupActions();
314 void createWidgets();
315 void deleteWidgets();
316 void layoutSplitters();
317 void newFromTemplate(const Akonadi::Item &);
318 void moveSelectedMessagesToFolder(const Akonadi::Collection &dest);
319 void copySelectedMessagesToFolder(const Akonadi::Collection &dest);
321 void showEvent(QShowEvent *event) Q_DECL_OVERRIDE;
323 KActionCollection *actionCollection() const
325 return mActionCollection;
329 @return the correct config dialog depending on whether the parent of
330 the mainWidget is a KPart or a KMMainWindow.
331 When dealing with geometries, use this pointer
333 KSharedConfig::Ptr config();
335 protected Q_SLOTS:
336 void updateFileMenu();
337 void slotHelp();
338 void slotFilter();
339 void slotManageSieveScripts();
340 void slotCompose();
341 void slotPostToML();
342 void slotExpireFolder();
343 void slotExpireAll();
344 void slotArchiveFolder();
345 void slotRemoveFolder();
346 void slotEmptyFolder();
347 void slotClearCurrentFolder();
348 void slotAddFavoriteFolder();
349 void slotShowSelectedFolderInPane();
350 void slotOverrideHtmlLoadExt();
351 void slotMessageQueuedOrDrafted();
352 void slotUseTemplate();
353 void slotDeleteMsg(bool confirmDelete = true); // completely delete message
354 void slotTrashThread();
355 void slotDeleteThread(bool confirmDelete = true); // completely delete thread
356 void slotUndo();
357 void slotReadOn();
358 void slotSaveMsg();
359 void slotOpenMsg();
360 void slotSaveAttachments();
361 void slotJumpToFolder();
362 void slotResendMsg();
363 void slotCheckVacation();
364 void slotDebugSieve();
365 void slotApplyFilters();
366 void slotApplyFiltersOnFolder();
367 void slotExpandThread();
368 void slotExpandAllThreads();
369 void slotCollapseThread();
370 void slotCollapseAllThreads();
371 void slotSetThreadStatusUnread();
372 void slotSetThreadStatusRead();
373 void slotSetThreadStatusImportant();
374 void slotSetThreadStatusToAct();
375 void slotSetThreadStatusWatched();
376 void slotSetThreadStatusIgnored();
377 void slotSendQueued();
378 void slotSendQueuedVia(MailTransport::Transport *transport);
379 void slotOnlineStatus();
380 void slotUpdateOnlineStatus(KMailSettings::EnumNetworkState::type);
381 void slotMessagePopup(const Akonadi::Item &, const QUrl &, const QUrl &imageUrl, const QPoint &);
382 void slotContactSearchJobForMessagePopupDone(KJob *job);
383 void slotSelectAllMessages();
384 void slotFocusQuickSearch();
385 bool slotSearch();
386 void slotIntro();
387 void slotShowStartupFolder();
389 /** Message navigation */
390 void slotSelectNextMessage();
391 void slotExtendSelectionToNextMessage();
392 void slotSelectNextUnreadMessage();
393 void slotSelectPreviousMessage();
394 void slotExtendSelectionToPreviousMessage();
395 void slotSelectPreviousUnreadMessage();
396 void slotFocusOnNextMessage();
397 void slotFocusOnPrevMessage();
398 void slotSelectFirstMessage();
399 void slotSelectLastMessage();
400 void slotSelectFocusedMessage();
402 void slotNextUnreadFolder();
403 void slotPrevUnreadFolder();
405 /** etc. */
406 void slotDisplayCurrentMessage();
408 void slotShowNewFromTemplate();
409 void slotDelayedShowNewFromTemplate(KJob *);
410 void slotNewFromTemplate(QAction *);
412 /** Update the undo action */
413 void slotUpdateUndo();
415 /** Update html and threaded messages preferences in Folder menu. */
416 void updateFolderMenu();
418 /** Settings menu */
420 /** XML-GUI stuff */
421 void slotEditNotifications();
423 /** Slot to reply to a message */
424 void slotCustomReplyToMsg(const QString &tmpl);
425 void slotCustomReplyAllToMsg(const QString &tmpl);
426 void slotForwardInlineMsg();
427 void slotForwardAttachedMessage();
428 void slotRedirectMessage();
429 void slotCustomForwardMsg(const QString &tmpl);
430 void slotSubjectFilter();
431 void slotFromFilter();
432 void slotToFilter();
434 void slotConfigChanged();
436 /** Show a splash screen for the longer-lasting operation */
437 void slotShowBusySplash();
440 Show a message screen explaining that we are currently offline, when
441 an online folder is selected.
443 void showOfflinePage();
444 void showResourceOfflinePage();
445 void updateVacationScriptStatus(bool active, const QString &serverName = QString());
447 void slotItemAdded(const Akonadi::Item &, const Akonadi::Collection &col);
448 void slotItemRemoved(const Akonadi::Item &);
449 void slotItemMoved(const Akonadi::Item &item, const Akonadi::Collection &from, const Akonadi::Collection &to);
450 void slotCollectionStatisticsChanged(Akonadi::Collection::Id, const Akonadi::CollectionStatistics &);
452 void slotAkonadiStandardActionUpdated();
453 void slotCollectionChanged(const Akonadi::Collection &, const QSet<QByteArray> &);
454 void slotCreateNewTab(bool);
455 void slotUpdateActionsAfterMailChecking();
456 void slotCreateAddressBookContact();
457 void slotOpenRecentMsg(const QUrl &url);
459 private:
460 void checkAkonadiServerManagerState();
461 void updateHtmlMenuEntry();
463 void updateMoveAction(const Akonadi::CollectionStatistics &statistic);
464 void updateMoveAction(bool hasUnreadMails, bool hasMails);
466 void updateAllToTrashAction(int statistics);
468 /** Get override character encoding. */
469 QString overrideEncoding() const;
471 void moveMessageSelected(MessageList::Core::MessageItemSetReference ref, const Akonadi::Collection &dest, bool confirmOnDeletion = true);
473 void copyMessageSelected(const Akonadi::Item::List &selectMsg, const Akonadi::Collection &dest);
476 * Move the messages referenced by the specified set to trash.
477 * The set parameter must not be null and the ownership is passed
478 * to this function.
480 void trashMessageSelected(MessageList::Core::MessageItemSetReference ref);
482 * Set the status of the messages referenced by the specified set, eventually toggling it.
483 * The set parameter must not be null and the ownership is passed to this function.
485 void setMessageSetStatus(const Akonadi::Item::List &select,
486 const Akonadi::MessageStatus &status,
487 bool toggle
490 * Toggles a tag for the messages referenced by the specified set.
491 * The set parameter must not be null and the ownership is passed to this function.
493 void toggleMessageSetTag(const Akonadi::Item::List &select, const Akonadi::Tag &tag);
495 * This applies setMessageSetStatus() on the current thread.
497 void setCurrentThreadStatus(const Akonadi::MessageStatus &status, bool toggle);
499 void applyFilters(const Akonadi::Item::List &selectedMessages);
502 * Internal helper that creates the folder selection dialog used for the
503 * move and copy to folder actions on demand. Only folders where items can
504 * be added are listed.
506 MailCommon::FolderSelectionDialog *moveOrCopyToDialog();
509 * Internal helper that creates the folder selection dialog used for
510 * jumping to folders, or adding them as favourites. All folders are listed.
512 MailCommon::FolderSelectionDialog *selectFromAllFoldersDialog();
515 * Internal helper that applies the current settings so the
516 * favorite folder view.
518 void refreshFavoriteFoldersViewProperties();
520 void openFilterDialog(const QByteArray &field, const QString &value);
522 void showMessagePopup(const Akonadi::Item &msg, const QUrl &aUrl, const QUrl &imageUrl, const QPoint &aPoint, bool contactAlreadyExists, bool uniqueContactFound);
524 private Q_SLOTS:
525 void slotMoveMessageToTrash();
527 * Called when a "move to trash" operation is completed
529 void slotTrashMessagesCompleted(KMMoveCommand *command);
532 * Called when a "move" operation is completed
534 void slotMoveMessagesCompleted(KMMoveCommand *command);
537 * Called when a "copy" operation is completed
539 void slotCopyMessagesCompleted(KMCommand *command);
541 void slotRequestFullSearchFromQuickSearch();
542 void slotFolderChanged(const Akonadi::Collection &);
543 void slotCollectionFetched(int collectionId);
545 void itemsReceived(const Akonadi::Item::List &list);
546 void itemsFetchDone(KJob *job);
548 void slotServerSideSubscription();
549 void slotFetchItemsForFolderDone(KJob *job);
550 void slotServerStateChanged(Akonadi::ServerManager::State state);
551 void slotArchiveMails();
552 void slotChangeDisplayMessageFormat(MessageViewer::Viewer::DisplayFormatMessage format);
554 void slotCollectionRemoved(const Akonadi::Collection &col);
555 void slotCcFilter();
556 void slotBandwidth(bool b);
557 void slotDeleteMessages();
559 void slotMarkAllMessageAsReadInCurrentFolderAndSubfolder();
560 void slotRemoveDuplicateRecursive();
561 void slotExecuteMailAction(MessageViewer::Viewer::MailAction action);
562 void slotRedirectCurrentMessage();
563 private:
564 void printCurrentMessage(bool preview);
565 void replyCurrentMessageCommand(MessageComposer::ReplyStrategy strategy);
566 // Message actions
567 QAction *mDeleteAction;
568 QAction *mTrashThreadAction;
569 QAction *mDeleteThreadAction;
570 QAction *mSaveAsAction;
571 QAction *mUseAction;
572 QAction *mSendAgainAction;
573 QAction *mApplyAllFiltersAction;
574 QAction *mSaveAttachmentsAction;
575 QAction *mOpenAction;
576 QAction *mMoveMsgToFolderAction;
577 QAction *mCollectionProperties;
578 QAction *mSendQueued;
579 QAction *mArchiveAction;
580 KActionMenuTransport *mSendActionMenu;
581 // Filter actions
582 KActionMenu *mFilterMenu;
583 QAction *mExpireConfigAction;
584 QAction *mApplyFiltersOnFolder;
585 // Custom template actions menu
586 KActionMenu *mTemplateMenu;
588 KActionMenu *mThreadStatusMenu, *mApplyFilterActionsMenu;
589 QAction *mCopyActionMenu;
590 QAction *mMoveActionMenu;
591 QAction *mMarkThreadAsReadAction;
592 QAction *mMarkThreadAsUnreadAction;
593 KToggleAction *mToggleThreadImportantAction;
594 KToggleAction *mToggleThreadToActAction;
596 KToggleAction *mWatchThreadAction, *mIgnoreThreadAction;
598 MailCommon::FavoriteCollectionWidget *mFavoriteCollectionsView;
599 Akonadi::FavoriteCollectionsModel *mFavoritesModel;
600 QWidget *mSearchAndTree;
601 KMReaderWin *mMsgView;
602 QSplitter *mSplitter1;
603 QSplitter *mSplitter2;
604 QSplitter *mFolderViewSplitter;
605 Akonadi::Collection mTemplateFolder;
606 bool mLongFolderList;
607 bool mStartupDone;
608 bool mWasEverShown;
609 bool mHtmlGlobalSetting;
610 bool mHtmlLoadExtGlobalSetting;
611 bool mFolderHtmlLoadExtPreference;
612 bool mReaderWindowActive;
613 bool mReaderWindowBelow;
614 bool mEnableFavoriteFolderView;
615 bool mEnableFolderQuickSearch;
617 QPointer<KMail::SearchWindow> mSearchWin;
619 QAction *mExpireFolderAction;
620 QAction *mFolderMailingListPropertiesAction;
621 QAction *mShowFolderShortcutDialogAction;
622 QAction *mArchiveFolderAction;
623 QAction *mMessageNewList;
624 KToggleAction *mPreferHtmlLoadExtAction;
626 QTimer *menutimer;
627 QTimer *mShowBusySplashTimer;
629 KSieveUi::VacationManager *mVacationManager;
630 #if !defined(NDEBUG)
631 QPointer<KSieveUi::SieveDebugDialog> mSieveDebugDialog;
632 #endif
633 KActionCollection *mActionCollection;
634 QAction *mToolbarActionSeparator;
635 QVBoxLayout *mTopLayout;
636 bool mDestructed;
637 QList<QAction *> mFilterMenuActions;
638 QList<QAction *> mFilterTBarActions;
639 QList<KMMetaFilterActionCommand *> mFilterCommands;
641 KMail::TagActionManager *mTagActionManager;
642 KMail::FolderShortcutActionManager *mFolderShortcutActionManager;
643 KSharedConfig::Ptr mConfig;
644 KXMLGUIClient *mGUIClient;
646 KMail::MessageActions *mMsgActions;
647 Akonadi::StandardMailActionManager *mAkonadiStandardActionManager;
648 CollectionPane *mMessagePane;
649 QSharedPointer<MailCommon::FolderCollection> mCurrentFolder;
651 MailCommon::FolderTreeWidget *mFolderTreeWidget;
653 KMail::VacationScriptIndicatorWidget *mVacationScriptIndicator;
654 bool mVacationIndicatorActive;
655 bool mGoToFirstUnreadMessageInSelectedFolder;
656 MessageList::Core::PreSelectionMode mPreSelectionMode;
658 QTimer mCheckMailTimer;
660 QPointer<MailCommon::FolderSelectionDialog> mMoveOrCopyToDialog;
661 QPointer<MailCommon::FolderSelectionDialog> mSelectFromAllFoldersDialog;
662 QAction *mServerSideSubscription;
663 KRecentFilesAction *mOpenRecentAction;
664 QPointer<KSieveUi::ManageSieveScriptsDialog> mManageSieveDialog;
665 QAction *mQuickSearchAction;
666 DisplayMessageFormatActionMenu *mDisplayMessageFormatMenu;
667 MessageViewer::Viewer::DisplayFormatMessage mFolderDisplayFormatPreference;
668 QAction *mSearchMessages;
669 KMLaunchExternalComponent *mLaunchExternalComponent;
670 ManageShowCollectionProperties *mManageShowCollectionProperties;
671 QAction *mShowIntroductionAction;
672 KToggleAction *mLowBandwithAction;
673 QAction *mMarkAllMessageAsReadAndInAllSubFolder;
674 KActionMenuAccount *mAccountActionMenu;
675 QAction *mRemoveDuplicateRecursiveAction;
676 KMailPluginInterface *mPluginInterface;
679 #endif