Delay draft recovery
[trojita.git] / src / Gui / Window.h
blob738a8826a95d9a426d5fba776a57c48ccc9c0ddb
1 /* Copyright (C) 2006 - 2015 Jan Kundrát <jkt@kde.org>
3 This file is part of the Trojita Qt IMAP e-mail client,
4 http://trojita.flaska.net/
6 This program is free software; you can redistribute it and/or
7 modify it under the terms of the GNU General Public License as
8 published by the Free Software Foundation; either version 2 of
9 the License or (at your option) version 3 or any later version
10 accepted by the membership of KDE e.V. (or its successor approved
11 by the membership of KDE e.V.), which shall act as a proxy
12 defined in Section 14 of version 3 of the license.
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
19 You should have received a copy of the GNU General Public License
20 along with this program. If not, see <http://www.gnu.org/licenses/>.
23 #ifndef TROJITA_WINDOW_H
24 #define TROJITA_WINDOW_H
26 #include <QMainWindow>
27 #include <QModelIndex>
28 #include <QPointer>
29 #include <QSystemTrayIcon>
31 #include "Composer/Recipients.h"
32 #include "Imap/ConnectionState.h"
33 #include "Imap/Model/Cache.h"
35 class QAuthenticator;
36 class QCloseEvent;
37 class QItemSelection;
38 class QMessageBox;
39 class QModelIndex;
40 class QScrollArea;
41 class QSettings;
42 class QSplitter;
43 class QSslCertificate;
44 class QSslError;
45 class QStackedWidget;
46 class QToolButton;
47 class QTreeView;
49 namespace Composer
51 class SenderIdentitiesModel;
54 namespace Imap
57 class ImapAccess;
59 namespace Mailbox
62 class Model;
63 class PrettyMailboxModel;
64 class ThreadingMsgListModel;
65 class PrettyMsgListModel;
66 class FavoriteTagsModel;
71 namespace Plugins
73 class PluginManager;
76 namespace MSA
78 class MSAFactory;
80 namespace Gui
83 class CompleteMessageWidget;
84 class ComposeWidget;
85 class MailBoxTreeView;
86 class MessageListWidget;
87 class ProtocolLoggerWidget;
88 class TaskProgressIndicator;
90 class MainWindow: public QMainWindow
92 Q_OBJECT
93 typedef QList<QPair<Composer::RecipientKind,QString> > RecipientsType;
95 typedef enum { LAYOUT_COMPACT, LAYOUT_WIDE, LAYOUT_ONE_AT_TIME } LayoutMode;
96 public:
97 MainWindow(QSettings *settings);
98 void showMainWindow();
99 QSize sizeHint() const;
101 Imap::Mailbox::Model *imapModel() const;
103 Composer::SenderIdentitiesModel *senderIdentitiesModel() { return m_senderIdentities; }
104 Imap::Mailbox::FavoriteTagsModel *favoriteTagsModel() { return m_favoriteTags; }
105 Plugins::PluginManager *pluginManager() { return m_pluginManager; }
106 QSettings *settings() const { return m_settings; }
107 MSA::MSAFactory *msaFactory();
109 // FIXME: this should be changed to some wrapper when support for multiple accounts is available
110 Imap::ImapAccess *imapAccess() const;
112 void enableLoggingToDisk();
114 static QWidget *messageSourceWidget(const QModelIndex &message);
116 void registerComposeWindow(ComposeWidget* widget);
118 public slots:
119 void slotComposeMailUrl(const QUrl &url);
120 void slotComposeMail();
121 void invokeContactEditor();
122 protected:
123 void closeEvent(QCloseEvent *event);
124 bool eventFilter(QObject *o, QEvent *e);
125 private slots:
126 void showContextMenuMboxTree(const QPoint &position);
127 void showContextMenuMsgListTree(const QPoint &position);
128 void slotReloadMboxList();
129 void slotResyncMbox();
130 void alertReceived(const QString &message);
131 void networkPolicyOffline();
132 void networkPolicyExpensive();
133 void networkPolicyOnline();
134 void slotShowSettings();
135 void slotShowImapInfo();
136 void slotExpunge();
137 void imapError(const QString &message);
138 void networkError(const QString &message);
139 void cacheError(const QString &message);
140 void authenticationRequested();
141 void authenticationContinue(const QString &pass, const QString &errorMessage = QString());
142 void checkSslPolicy();
143 void slotManageContact(const QUrl &url);
144 void slotEditDraft();
145 void slotReplyTo();
146 void slotReplyAllButMe();
147 void slotReplyAll();
148 void slotReplyList();
149 void slotReplyGuess();
150 void slotForwardAsAttachment();
151 void slotBounce();
152 void slotUpdateMessageActions();
153 void handleTag(const bool checked, const int index);
154 void handleMarkAsRead(bool);
155 void handleMarkAsDeleted(bool);
156 void handleMarkAsFlagged(const bool);
157 void handleMarkAsJunk(const bool);
158 void handleMarkAsNotJunk(const bool);
159 void slotMoveToArchiveFailed(const QString &error);
160 void handleMoveToArchive();
161 void slotNextUnread();
162 void slotPreviousUnread();
163 void msgListClicked(const QModelIndex &);
164 void openCompleteMessageWidget();
165 void slotCreateMailboxBelowCurrent();
166 void slotMarkCurrentMailboxRead();
167 void slotCreateTopMailbox();
168 void slotDeleteCurrentMailbox();
169 void handleTrayIconChange();
170 #ifdef XTUPLE_CONNECT
171 void slotXtSyncCurrentMailbox();
172 #endif
173 void slotSubscribeCurrentMailbox();
174 void slotShowOnlySubscribed();
175 void updateMessageFlags();
176 void updateMessageFlagsOf(const QModelIndex &index);
177 void scrollMessageUp();
178 void slotMessageModelChanged(QAbstractItemModel *model);
179 void showConnectionStatus(uint parserId, Imap::ConnectionState state);
180 void slotShowLinkTarget(const QString &link);
181 void slotShowAboutTrojita();
182 void slotDonateToTrojita();
184 void slotSaveCurrentMessageBody();
185 void slotViewMsgSource();
186 void slotViewMsgHeaders();
187 void slotThreadMsgList();
188 void slotHideRead();
189 void slotSortingPreferenceChanged();
190 void slotSortingConfirmed(int column, Qt::SortOrder order);
191 void slotSearchRequested(const QStringList &searchConditions);
192 void slotCapabilitiesUpdated(const QStringList &capabilities);
194 void slotMailboxDeleteFailed(const QString &mailbox, const QString &msg);
195 void slotMailboxCreateFailed(const QString &mailbox, const QString &msg);
196 void slotMailboxSyncFailed(const QString &mailbox, const QString &msg);
197 void slotMailboxChanged(const QModelIndex &mailbox);
199 void slotDownloadTransferError(const QString &errorString);
200 void slotDownloadMessageFileNameRequested(QString *fileName);
201 void slotScrollToUnseenMessage();
202 void slotScrollToCurrent();
203 void slotUpdateWindowTitle();
205 void slotLayoutCompact();
206 void slotLayoutWide();
207 void slotLayoutOneAtTime();
208 void saveSizesAndState();
209 void saveRawStateSetting(bool enabled);
210 void possiblyLoadMessageOnSplittersChanged();
211 void updateNetworkIndication();
213 void desktopGeometryChanged();
215 void slotIconActivated(const QSystemTrayIcon::ActivationReason reason);
216 void slotToggleSysTray();
218 void slotResetReconnectState();
220 void slotPluginsChanged();
222 void showStatusMessage(const QString &message);
224 void slotFavoriteTagsChanged();
226 void recoverDrafts();
228 protected:
229 void resizeEvent(QResizeEvent *);
231 private:
232 void defineActions();
233 void createMenus();
234 void createActions();
235 void createWidgets();
236 void setupModels();
238 void nukeModels();
239 void connectModelActions();
241 void createMailboxBelow(const QModelIndex &index);
243 void updateActionsOnlineOffline(bool online);
245 void applySizesAndState();
246 QString settingsKeyForLayout(const LayoutMode layout);
248 void createSysTray();
249 void removeSysTray();
251 QModelIndexList translatedSelection() const;
253 Imap::ImapAccess *m_imapAccess;
255 Imap::Mailbox::PrettyMailboxModel *prettyMboxModel;
256 Imap::Mailbox::PrettyMsgListModel *prettyMsgListModel;
257 Composer::SenderIdentitiesModel *m_senderIdentities;
258 Imap::Mailbox::FavoriteTagsModel *m_favoriteTags;
260 MailBoxTreeView *mboxTree;
261 MessageListWidget *msgListWidget;
262 QTreeView *allTree;
263 QDockWidget *allDock;
264 QTreeView *taskTree;
265 QDockWidget *taskDock;
266 QTreeView *mailMimeTree;
267 QDockWidget *mailMimeDock;
269 CompleteMessageWidget *m_messageWidget;
271 ProtocolLoggerWidget *imapLogger;
272 QDockWidget *imapLoggerDock;
274 QPointer<QSplitter> m_mainHSplitter;
275 QPointer<QSplitter> m_mainVSplitter;
276 QPointer<QStackedWidget> m_mainStack;
278 LayoutMode m_layoutMode;
279 bool m_skipSavingOfUI;
280 QTimer *m_delayedStateSaving;
282 QAction *reloadMboxList;
283 QAction *reloadAllMailboxes;
284 QAction *resyncMbox;
285 QAction *netOffline;
286 QAction *netExpensive;
287 QAction *netOnline;
288 QAction *m_netToolbarDefaultAction;
289 QAction *exitAction;
290 QAction *showFullView;
291 QAction *showTaskView;
292 QAction *showMimeView;
293 QAction *showImapLogger;
294 QAction *logPersistent;
295 QAction *showImapCapabilities;
296 QAction *showMenuBar;
297 QAction *showToolBar;
298 QAction *configSettings;
299 QAction *m_oneAtTimeGoBack;
300 QAction *composeMail;
301 QAction *m_editDraft;
302 QAction *m_replyPrivate;
303 QAction *m_replyAllButMe;
304 QAction *m_replyAll;
305 QAction *m_replyList;
306 QAction *m_replyGuess;
307 QAction *m_forwardAsAttachment;
308 QAction *m_bounce;
309 QAction *expunge;
310 QAction *createChildMailbox;
311 QAction *createTopMailbox;
312 QAction *deleteCurrentMailbox;
313 #ifdef XTUPLE_CONNECT
314 QAction *xtIncludeMailboxInSync;
315 #endif
316 QAction *aboutTrojita;
317 QAction *donateToTrojita;
319 QAction *tag1;
320 QAction *tag2;
321 QAction *tag3;
322 QAction *tag4;
323 QAction *tag5;
324 QAction *tag6;
325 QAction *tag7;
326 QAction *tag8;
327 QAction *tag9;
328 QAction *markAsRead;
329 QAction *markAsDeleted;
330 QAction *markAsFlagged;
331 QAction *markAsJunk;
332 QAction *markAsNotJunk;
333 QAction *moveToArchive;
334 QAction *saveWholeMessage;
335 QAction *viewMsgSource;
336 QAction *viewMsgHeaders;
337 QAction *m_nextMessage;
338 QAction *m_previousMessage;
340 QAction *actionThreadMsgList;
341 QAction *actionHideRead;
342 QAction *m_actionSortByArrival;
343 QAction *m_actionSortByCc;
344 QAction *m_actionSortByDate;
345 QAction *m_actionSortByFrom;
346 QAction *m_actionSortBySize;
347 QAction *m_actionSortBySubject;
348 QAction *m_actionSortByTo;
349 QAction *m_actionSortThreading;
350 QAction *m_actionSortNone;
351 QAction *m_actionSortAscending;
352 QAction *m_actionSortDescending;
353 QAction *m_actionLayoutCompact;
354 QAction *m_actionLayoutWide;
355 QAction *m_actionLayoutOneAtTime;
356 QAction *m_actionMarkMailboxAsRead;
358 QAction *m_actionSubscribeMailbox;
359 QAction *m_actionShowOnlySubscribed;
361 QAction *m_actionContactEditor;
363 QToolBar *m_mainToolbar;
364 QToolButton *m_menuFromToolBar;
365 QToolButton *m_replyButton;
366 QMenu *m_replyMenu;
367 QToolButton *m_composeButton;
368 QMenu *m_composeMenu;
370 TaskProgressIndicator *busyParsersIndicator;
371 QToolButton *networkIndicator;
373 bool m_ignoreStoredPassword;
375 QSettings *m_settings;
376 Plugins::PluginManager *m_pluginManager;
378 QMessageBox *m_networkErrorMessageBox;
380 MainWindow(const MainWindow &); // don't implement
381 MainWindow &operator=(const MainWindow &); // don't implement
383 QSystemTrayIcon *m_trayIcon;
384 QPoint m_headerDragStart;
389 #endif