1 /* Copyright (C) 2006 - 2015 Jan Kundrát <jkt@kde.org>
2 
3    This file is part of the Trojita Qt IMAP e-mail client,
4    http://trojita.flaska.net/
5 
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.
13 
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.
18 
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/>.
21 */
22 
23 #ifndef TROJITA_WINDOW_H
24 #define TROJITA_WINDOW_H
25 
26 #include <QMainWindow>
27 #include <QModelIndex>
28 #include <QPointer>
29 #include <QSystemTrayIcon>
30 
31 #include "Composer/Recipients.h"
32 #include "Imap/ConnectionState.h"
33 #include "Imap/Model/Cache.h"
34 
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;
48 
49 namespace Composer
50 {
51 class SenderIdentitiesModel;
52 }
53 
54 namespace Imap
55 {
56 
57 class ImapAccess;
58 
59 namespace Mailbox
60 {
61 
62 class Model;
63 class PrettyMailboxModel;
64 class ThreadingMsgListModel;
65 class PrettyMsgListModel;
66 
67 }
68 }
69 
70 namespace Plugins
71 {
72 class PluginManager;
73 }
74 
75 namespace MSA
76 {
77 class MSAFactory;
78 }
79 namespace Gui
80 {
81 
82 class CompleteMessageWidget;
83 class ComposeWidget;
84 class MailBoxTreeView;
85 class MessageListWidget;
86 class ProtocolLoggerWidget;
87 class TaskProgressIndicator;
88 
89 class MainWindow: public QMainWindow
90 {
91     Q_OBJECT
92     typedef QList<QPair<Composer::RecipientKind,QString> > RecipientsType;
93 
94     typedef enum { LAYOUT_COMPACT, LAYOUT_WIDE, LAYOUT_ONE_AT_TIME } LayoutMode;
95 public:
96     MainWindow(QSettings *settings);
97     void showMainWindow();
98     QSize sizeHint() const;
99 
100     Imap::Mailbox::Model *imapModel() const;
101 
senderIdentitiesModel()102     Composer::SenderIdentitiesModel *senderIdentitiesModel() { return m_senderIdentities; }
pluginManager()103     Plugins::PluginManager *pluginManager() { return m_pluginManager; }
settings()104     QSettings *settings() const { return m_settings; }
105     MSA::MSAFactory *msaFactory();
106 
107     // FIXME: this should be changed to some wrapper when support for multiple accounts is available
108     Imap::ImapAccess *imapAccess() const;
109 
110     void enableLoggingToDisk();
111 
112     static QWidget *messageSourceWidget(const QModelIndex &message);
113 
114 public slots:
115     void slotComposeMailUrl(const QUrl &url);
116     void slotComposeMail();
117     void invokeContactEditor();
118 protected:
119     void closeEvent(QCloseEvent *event);
120     bool eventFilter(QObject *o, QEvent *e);
121 private slots:
122     void showContextMenuMboxTree(const QPoint &position);
123     void showContextMenuMsgListTree(const QPoint &position);
124     void slotReloadMboxList();
125     void slotResyncMbox();
126     void alertReceived(const QString &message);
127     void networkPolicyOffline();
128     void networkPolicyExpensive();
129     void networkPolicyOnline();
130     void slotShowSettings();
131     void slotShowImapInfo();
132     void slotExpunge();
133     void imapError(const QString &message);
134     void networkError(const QString &message);
135     void cacheError(const QString &message);
136     void authenticationRequested();
137     void authenticationContinue(const QString &pass, const QString &errorMessage = QString());
138     void checkSslPolicy();
139     void slotManageContact(const QUrl &url);
140     void slotEditDraft();
141     void slotReplyTo();
142     void slotReplyAllButMe();
143     void slotReplyAll();
144     void slotReplyList();
145     void slotReplyGuess();
146     void slotForwardAsAttachment();
147     void slotUpdateMessageActions();
148     void handleMarkAsRead(bool);
149     void handleMarkAsDeleted(bool);
150     void handleMarkAsFlagged(const bool);
151     void handleMarkAsJunk(const bool);
152     void handleMarkAsNotJunk(const bool);
153     void slotNextUnread();
154     void slotPreviousUnread();
155     void msgListClicked(const QModelIndex &);
156     void msgListDoubleClicked(const QModelIndex &);
157     void slotCreateMailboxBelowCurrent();
158     void slotMarkCurrentMailboxRead();
159     void slotCreateTopMailbox();
160     void slotDeleteCurrentMailbox();
161     void handleTrayIconChange();
162 #ifdef XTUPLE_CONNECT
163     void slotXtSyncCurrentMailbox();
164 #endif
165     void slotSubscribeCurrentMailbox();
166     void slotShowOnlySubscribed();
167     void updateMessageFlags();
168     void updateMessageFlagsOf(const QModelIndex &index);
169     void scrollMessageUp();
170     void slotMessageModelChanged(QAbstractItemModel *model);
171     void showConnectionStatus(uint parserId, Imap::ConnectionState state);
172     void slotShowLinkTarget(const QString &link);
173     void slotShowAboutTrojita();
174     void slotDonateToTrojita();
175 
176     void slotSaveCurrentMessageBody();
177     void slotViewMsgSource();
178     void slotViewMsgHeaders();
179     void slotThreadMsgList();
180     void slotHideRead();
181     void slotSortingPreferenceChanged();
182     void slotSortingConfirmed(int column, Qt::SortOrder order);
183     void slotSearchRequested(const QStringList &searchConditions);
184     void slotCapabilitiesUpdated(const QStringList &capabilities);
185 
186     void slotMailboxDeleteFailed(const QString &mailbox, const QString &msg);
187     void slotMailboxCreateFailed(const QString &mailbox, const QString &msg);
188     void slotMailboxSyncFailed(const QString &mailbox, const QString &msg);
189     void slotMailboxChanged(const QModelIndex &mailbox);
190 
191     void slotDownloadTransferError(const QString &errorString);
192     void slotDownloadMessageFileNameRequested(QString *fileName);
193     void slotScrollToUnseenMessage();
194     void slotScrollToCurrent();
195     void slotUpdateWindowTitle();
196 
197     void slotLayoutCompact();
198     void slotLayoutWide();
199     void slotLayoutOneAtTime();
200     void saveSizesAndState();
201     void saveRawStateSetting(bool enabled);
202     void possiblyLoadMessageOnSplittersChanged();
203     void updateNetworkIndication();
204 
205     void desktopGeometryChanged();
206 
207     void slotIconActivated(const QSystemTrayIcon::ActivationReason reason);
208     void slotToggleSysTray();
209 
210     void slotResetReconnectState();
211 
212     void slotPluginsChanged();
213 
214     void showStatusMessage(const QString &message);
215 
216 protected:
217     void resizeEvent(QResizeEvent *);
218 
219 private:
220     void defineActions();
221     void createMenus();
222     void createActions();
223     void createWidgets();
224     void setupModels();
225 
226     void nukeModels();
227     void connectModelActions();
228 
229     void createMailboxBelow(const QModelIndex &index);
230 
231     void updateActionsOnlineOffline(bool online);
232 
233     void applySizesAndState();
234     QString settingsKeyForLayout(const LayoutMode layout);
235 
236     void recoverDrafts();
237     void createSysTray();
238     void removeSysTray();
239 
240     QModelIndexList translatedSelection() const;
241 
242     Imap::ImapAccess *m_imapAccess;
243 
244     Imap::Mailbox::PrettyMailboxModel *prettyMboxModel;
245     Imap::Mailbox::PrettyMsgListModel *prettyMsgListModel;
246     Composer::SenderIdentitiesModel *m_senderIdentities;
247 
248     MailBoxTreeView *mboxTree;
249     MessageListWidget *msgListWidget;
250     QTreeView *allTree;
251     QDockWidget *allDock;
252     QTreeView *taskTree;
253     QDockWidget *taskDock;
254     QTreeView *mailMimeTree;
255     QDockWidget *mailMimeDock;
256 
257     CompleteMessageWidget *m_messageWidget;
258 
259     ProtocolLoggerWidget *imapLogger;
260     QDockWidget *imapLoggerDock;
261 
262     QPointer<QSplitter> m_mainHSplitter;
263     QPointer<QSplitter> m_mainVSplitter;
264     QPointer<QStackedWidget> m_mainStack;
265 
266     LayoutMode m_layoutMode;
267     bool m_skipSavingOfUI;
268     QTimer *m_delayedStateSaving;
269 
270     QAction *reloadMboxList;
271     QAction *reloadAllMailboxes;
272     QAction *resyncMbox;
273     QAction *netOffline;
274     QAction *netExpensive;
275     QAction *netOnline;
276     QAction *m_netToolbarDefaultAction;
277     QAction *exitAction;
278     QAction *showFullView;
279     QAction *showTaskView;
280     QAction *showMimeView;
281     QAction *showImapLogger;
282     QAction *logPersistent;
283     QAction *showImapCapabilities;
284     QAction *showMenuBar;
285     QAction *showToolBar;
286     QAction *configSettings;
287     QAction *m_oneAtTimeGoBack;
288     QAction *composeMail;
289     QAction *m_editDraft;
290     QAction *m_replyPrivate;
291     QAction *m_replyAllButMe;
292     QAction *m_replyAll;
293     QAction *m_replyList;
294     QAction *m_replyGuess;
295     QAction *m_forwardAsAttachment;
296     QAction *expunge;
297     QAction *createChildMailbox;
298     QAction *createTopMailbox;
299     QAction *deleteCurrentMailbox;
300 #ifdef XTUPLE_CONNECT
301     QAction *xtIncludeMailboxInSync;
302 #endif
303     QAction *aboutTrojita;
304     QAction *donateToTrojita;
305 
306     QAction *markAsRead;
307     QAction *markAsDeleted;
308     QAction *markAsFlagged;
309     QAction *markAsJunk;
310     QAction *markAsNotJunk;
311     QAction *saveWholeMessage;
312     QAction *viewMsgSource;
313     QAction *viewMsgHeaders;
314     QAction *m_nextMessage;
315     QAction *m_previousMessage;
316 
317     QAction *actionThreadMsgList;
318     QAction *actionHideRead;
319     QAction *m_actionSortByArrival;
320     QAction *m_actionSortByCc;
321     QAction *m_actionSortByDate;
322     QAction *m_actionSortByFrom;
323     QAction *m_actionSortBySize;
324     QAction *m_actionSortBySubject;
325     QAction *m_actionSortByTo;
326     QAction *m_actionSortThreading;
327     QAction *m_actionSortNone;
328     QAction *m_actionSortAscending;
329     QAction *m_actionSortDescending;
330     QAction *m_actionLayoutCompact;
331     QAction *m_actionLayoutWide;
332     QAction *m_actionLayoutOneAtTime;
333     QAction *m_actionMarkMailboxAsRead;
334 
335     QAction *m_actionSubscribeMailbox;
336     QAction *m_actionShowOnlySubscribed;
337 
338     QAction *m_actionContactEditor;
339 
340     QToolBar *m_mainToolbar;
341     QToolButton *m_menuFromToolBar;
342     QToolButton *m_replyButton;
343     QMenu *m_replyMenu;
344     QToolButton *m_composeButton;
345     QMenu *m_composeMenu;
346 
347     TaskProgressIndicator *busyParsersIndicator;
348     QToolButton *networkIndicator;
349 
350     bool m_ignoreStoredPassword;
351 
352     QSettings *m_settings;
353     Plugins::PluginManager *m_pluginManager;
354 
355     QMessageBox *m_networkErrorMessageBox;
356 
357     MainWindow(const MainWindow &); // don't implement
358     MainWindow &operator=(const MainWindow &); // don't implement
359 
360     QSystemTrayIcon *m_trayIcon;
361     QPoint m_headerDragStart;
362 };
363 
364 }
365 
366 #endif
367