File indexing completed on 2024-05-26 05:28:20

0001 /* Copyright (C) 2006 - 2015 Jan Kundrát <jkt@kde.org>
0002 
0003    This file is part of the Trojita Qt IMAP e-mail client,
0004    http://trojita.flaska.net/
0005 
0006    This program is free software; you can redistribute it and/or
0007    modify it under the terms of the GNU General Public License as
0008    published by the Free Software Foundation; either version 2 of
0009    the License or (at your option) version 3 or any later version
0010    accepted by the membership of KDE e.V. (or its successor approved
0011    by the membership of KDE e.V.), which shall act as a proxy
0012    defined in Section 14 of version 3 of the license.
0013 
0014    This program is distributed in the hope that it will be useful,
0015    but WITHOUT ANY WARRANTY; without even the implied warranty of
0016    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
0017    GNU General Public License for more details.
0018 
0019    You should have received a copy of the GNU General Public License
0020    along with this program.  If not, see <http://www.gnu.org/licenses/>.
0021 */
0022 
0023 #ifndef TROJITA_WINDOW_H
0024 #define TROJITA_WINDOW_H
0025 
0026 #include <QMainWindow>
0027 #include <QModelIndex>
0028 #include <QPointer>
0029 #include <QSystemTrayIcon>
0030 
0031 #include "Composer/Recipients.h"
0032 #include "Imap/ConnectionState.h"
0033 #include "Imap/Model/Cache.h"
0034 
0035 class QAuthenticator;
0036 class QCloseEvent;
0037 class QItemSelection;
0038 class QMessageBox;
0039 class QModelIndex;
0040 class QScrollArea;
0041 class QSettings;
0042 class QSplitter;
0043 class QSslCertificate;
0044 class QSslError;
0045 class QStackedWidget;
0046 class QToolButton;
0047 class QTreeView;
0048 
0049 namespace Composer
0050 {
0051 class SenderIdentitiesModel;
0052 }
0053 
0054 namespace Imap
0055 {
0056 
0057 class ImapAccess;
0058 
0059 namespace Mailbox
0060 {
0061 
0062 class Model;
0063 class PrettyMailboxModel;
0064 class ThreadingMsgListModel;
0065 class PrettyMsgListModel;
0066 class FavoriteTagsModel;
0067 
0068 }
0069 }
0070 
0071 namespace Plugins
0072 {
0073 class PluginManager;
0074 }
0075 
0076 namespace MSA
0077 {
0078 class MSAFactory;
0079 }
0080 namespace Gui
0081 {
0082 
0083 class CompleteMessageWidget;
0084 class ComposeWidget;
0085 class MailBoxTreeView;
0086 class MessageListWidget;
0087 class ProtocolLoggerWidget;
0088 class TaskProgressIndicator;
0089 
0090 class MainWindow: public QMainWindow
0091 {
0092     Q_OBJECT
0093     typedef QList<QPair<Composer::RecipientKind,QString> > RecipientsType;
0094 
0095     typedef enum { LAYOUT_COMPACT, LAYOUT_WIDE, LAYOUT_ONE_AT_TIME } LayoutMode;
0096 public:
0097     MainWindow(QSettings *settings);
0098     void showMainWindow();
0099     QSize sizeHint() const;
0100 
0101     Imap::Mailbox::Model *imapModel() const;
0102 
0103     Composer::SenderIdentitiesModel *senderIdentitiesModel() { return m_senderIdentities; }
0104     Imap::Mailbox::FavoriteTagsModel *favoriteTagsModel() { return m_favoriteTags; }
0105     Plugins::PluginManager *pluginManager() { return m_pluginManager; }
0106     QSettings *settings() const { return m_settings; }
0107     MSA::MSAFactory *msaFactory();
0108 
0109     // FIXME: this should be changed to some wrapper when support for multiple accounts is available
0110     Imap::ImapAccess *imapAccess() const;
0111 
0112     void enableLoggingToDisk();
0113 
0114     static QWidget *messageSourceWidget(const QModelIndex &message);
0115 
0116     void registerComposeWindow(ComposeWidget* widget);
0117 
0118 public slots:
0119     void slotComposeMailUrl(const QUrl &url);
0120     void slotComposeMail();
0121     void invokeContactEditor();
0122 protected:
0123     void closeEvent(QCloseEvent *event);
0124     bool eventFilter(QObject *o, QEvent *e);
0125 private slots:
0126     void showContextMenuMboxTree(const QPoint &position);
0127     void showContextMenuMsgListTree(const QPoint &position);
0128     void slotReloadMboxList();
0129     void slotResyncMbox();
0130     void alertReceived(const QString &message);
0131     void networkPolicyOffline();
0132     void networkPolicyExpensive();
0133     void networkPolicyOnline();
0134     void slotShowSettings();
0135     void slotShowImapInfo();
0136     void slotExpunge();
0137     void imapError(const QString &message);
0138     void networkError(const QString &message);
0139     void cacheError(const QString &message);
0140     void authenticationRequested();
0141     void authenticationContinue(const QString &pass, const QString &errorMessage = QString());
0142     void checkSslPolicy();
0143     void slotManageContact(const QUrl &url);
0144     void slotEditDraft();
0145     void slotReplyTo();
0146     void slotReplyAllButMe();
0147     void slotReplyAll();
0148     void slotReplyList();
0149     void slotReplyGuess();
0150     void slotForwardAsAttachment();
0151     void slotResend();
0152     void slotUpdateMessageActions();
0153     void handleTag(const bool checked, const int index);
0154     void handleMarkAsRead(bool);
0155     void handleMarkAsDeleted(bool);
0156     void handleMarkAsFlagged(const bool);
0157     void handleMarkAsJunk(const bool);
0158     void handleMarkAsNotJunk(const bool);
0159     void slotMoveToArchiveFailed(const QString &error);
0160     void handleMoveToArchive();
0161     void slotNextUnread();
0162     void slotPreviousUnread();
0163     void msgListClicked(const QModelIndex &);
0164     void openCompleteMessageWidget();
0165     void slotCreateMailboxBelowCurrent();
0166     void slotMarkCurrentMailboxRead();
0167     void slotCreateTopMailbox();
0168     void slotDeleteCurrentMailbox();
0169     void handleTrayIconChange();
0170     void slotSubscribeCurrentMailbox();
0171     void slotShowOnlySubscribed();
0172     void updateMessageFlags();
0173     void updateMessageFlagsOf(const QModelIndex &index);
0174     void scrollMessageUp();
0175     void slotMessageModelChanged(QAbstractItemModel *model);
0176     void showConnectionStatus(uint parserId, Imap::ConnectionState state);
0177     void slotShowLinkTarget(const QString &link);
0178     void slotShowAboutTrojita();
0179     void slotDonateToTrojita();
0180 
0181     void slotSaveCurrentMessageBody();
0182     void slotViewMsgSource();
0183     void slotViewMsgHeaders();
0184     void slotThreadMsgList();
0185     void slotHideRead();
0186     void slotSortingPreferenceChanged();
0187     void slotSortingConfirmed(int column, Qt::SortOrder order);
0188     void slotSearchRequested(const QStringList &searchConditions);
0189     void slotCapabilitiesUpdated(const QStringList &capabilities);
0190 
0191     void slotMailboxDeleteFailed(const QString &mailbox, const QString &msg);
0192     void slotMailboxCreateFailed(const QString &mailbox, const QString &msg);
0193     void slotMailboxSyncFailed(const QString &mailbox, const QString &msg);
0194     void slotMailboxChanged(const QModelIndex &mailbox);
0195 
0196     void slotDownloadTransferError(const QString &errorString);
0197     void slotDownloadMessageFileNameRequested(QString *fileName);
0198     void slotScrollToUnseenMessage();
0199     void slotScrollToCurrent();
0200     void slotUpdateWindowTitle();
0201 
0202     void slotLayoutCompact();
0203     void slotLayoutWide();
0204     void slotLayoutOneAtTime();
0205     void saveSizesAndState();
0206     void saveRawStateSetting(bool enabled);
0207     void possiblyLoadMessageOnSplittersChanged();
0208     void updateNetworkIndication();
0209 
0210     void desktopGeometryChanged();
0211 
0212     void slotIconActivated(const QSystemTrayIcon::ActivationReason reason);
0213     void slotToggleSysTray();
0214 
0215     void slotResetReconnectState();
0216 
0217     void slotPluginsChanged();
0218 
0219     void showStatusMessage(const QString &message);
0220 
0221     void slotFavoriteTagsChanged();
0222 
0223     void recoverDrafts();
0224 
0225 protected:
0226     void resizeEvent(QResizeEvent *);
0227 
0228 private:
0229     void defineActions();
0230     void createMenus();
0231     void createActions();
0232     void createWidgets();
0233     void setupModels();
0234 
0235     void nukeModels();
0236     void connectModelActions();
0237 
0238     void createMailboxBelow(const QModelIndex &index);
0239 
0240     void updateActionsOnlineOffline(bool online);
0241 
0242     void applySizesAndState();
0243     QString settingsKeyForLayout(const LayoutMode layout);
0244 
0245     void createSysTray();
0246     void removeSysTray();
0247 
0248     QModelIndexList translatedSelection() const;
0249 
0250     Imap::ImapAccess *m_imapAccess;
0251 
0252     Imap::Mailbox::PrettyMailboxModel *prettyMboxModel;
0253     Imap::Mailbox::PrettyMsgListModel *prettyMsgListModel;
0254     Composer::SenderIdentitiesModel *m_senderIdentities;
0255     Imap::Mailbox::FavoriteTagsModel *m_favoriteTags;
0256 
0257     MailBoxTreeView *mboxTree;
0258     MessageListWidget *msgListWidget;
0259     QTreeView *allTree;
0260     QDockWidget *allDock;
0261     QTreeView *taskTree;
0262     QDockWidget *taskDock;
0263     QTreeView *mailMimeTree;
0264     QDockWidget *mailMimeDock;
0265 
0266     CompleteMessageWidget *m_messageWidget;
0267 
0268     ProtocolLoggerWidget *protocolLogger;
0269     QDockWidget *protocolLoggerDock;
0270 
0271     QPointer<QSplitter> m_mainHSplitter;
0272     QPointer<QSplitter> m_mainVSplitter;
0273     QPointer<QStackedWidget> m_mainStack;
0274 
0275     LayoutMode m_layoutMode;
0276     bool m_skipSavingOfUI;
0277     QTimer *m_delayedStateSaving;
0278 
0279     QAction *reloadMboxList;
0280     QAction *reloadAllMailboxes;
0281     QAction *resyncMbox;
0282     QAction *netOffline;
0283     QAction *netExpensive;
0284     QAction *netOnline;
0285     QAction *m_netToolbarDefaultAction;
0286     QAction *exitAction;
0287     QAction *showFullView;
0288     QAction *showTaskView;
0289     QAction *showMimeView;
0290     QAction *showProtocolLogger;
0291     QAction *logPersistent;
0292     QAction *showImapCapabilities;
0293     QAction *showMenuBar;
0294     QAction *showToolBar;
0295     QAction *configSettings;
0296     QAction *m_oneAtTimeGoBack;
0297     QAction *composeMail;
0298     QAction *m_editDraft;
0299     QAction *m_replyPrivate;
0300     QAction *m_replyAllButMe;
0301     QAction *m_replyAll;
0302     QAction *m_replyList;
0303     QAction *m_replyGuess;
0304     QAction *m_forwardAsAttachment;
0305     QAction *m_resend;
0306     QAction *expunge;
0307     QAction *createChildMailbox;
0308     QAction *createTopMailbox;
0309     QAction *deleteCurrentMailbox;
0310     QAction *aboutTrojita;
0311     QAction *donateToTrojita;
0312 
0313     QAction *tag1;
0314     QAction *tag2;
0315     QAction *tag3;
0316     QAction *tag4;
0317     QAction *tag5;
0318     QAction *tag6;
0319     QAction *tag7;
0320     QAction *tag8;
0321     QAction *tag9;
0322     QAction *markAsRead;
0323     QAction *markAsDeleted;
0324     QAction *markAsFlagged;
0325     QAction *markAsJunk;
0326     QAction *markAsNotJunk;
0327     QAction *moveToArchive;
0328     QAction *saveWholeMessage;
0329     QAction *viewMsgSource;
0330     QAction *viewMsgHeaders;
0331     QAction *m_nextMessage;
0332     QAction *m_previousMessage;
0333 
0334     QAction *actionThreadMsgList;
0335     QAction *actionHideRead;
0336     QAction *m_actionSortByArrival;
0337     QAction *m_actionSortByCc;
0338     QAction *m_actionSortByDate;
0339     QAction *m_actionSortByFrom;
0340     QAction *m_actionSortBySize;
0341     QAction *m_actionSortBySubject;
0342     QAction *m_actionSortByTo;
0343     QAction *m_actionSortThreading;
0344     QAction *m_actionSortNone;
0345     QAction *m_actionSortAscending;
0346     QAction *m_actionSortDescending;
0347     QAction *m_actionLayoutCompact;
0348     QAction *m_actionLayoutWide;
0349     QAction *m_actionLayoutOneAtTime;
0350     QAction *m_actionMarkMailboxAsRead;
0351 
0352     QAction *m_actionSubscribeMailbox;
0353     QAction *m_actionShowOnlySubscribed;
0354 
0355     QAction *m_actionContactEditor;
0356 
0357     QToolBar *m_mainToolbar;
0358     QToolButton *m_menuFromToolBar;
0359     QToolButton *m_replyButton;
0360     QMenu *m_replyMenu;
0361     QToolButton *m_composeButton;
0362     QMenu *m_composeMenu;
0363 
0364     TaskProgressIndicator *busyParsersIndicator;
0365     QToolButton *networkIndicator;
0366 
0367     bool m_ignoreStoredPassword;
0368 
0369     QSettings *m_settings;
0370     Plugins::PluginManager *m_pluginManager;
0371 
0372     QMessageBox *m_networkErrorMessageBox;
0373 
0374     MainWindow(const MainWindow &); // don't implement
0375     MainWindow &operator=(const MainWindow &); // don't implement
0376 
0377     QSystemTrayIcon *m_trayIcon;
0378     QPoint m_headerDragStart;
0379 };
0380 
0381 }
0382 
0383 #endif