1 /* Copyright (C) 2006 - 2016 Jan Kundrát <jkt@kde.org> 2 Copyright (C) 2014 - 2015 Stephan Platz <trojita@paalsteek.de> 3 4 This file is part of the Trojita Qt IMAP e-mail client, 5 http://trojita.flaska.net/ 6 7 This program is free software; you can redistribute it and/or 8 modify it under the terms of the GNU General Public License as 9 published by the Free Software Foundation; either version 2 of 10 the License or (at your option) version 3 or any later version 11 accepted by the membership of KDE e.V. (or its successor approved 12 by the membership of KDE e.V.), which shall act as a proxy 13 defined in Section 14 of version 3 of the license. 14 15 This program is distributed in the hope that it will be useful, 16 but WITHOUT ANY WARRANTY; without even the implied warranty of 17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 GNU General Public License for more details. 19 20 You should have received a copy of the GNU General Public License 21 along with this program. If not, see <http://www.gnu.org/licenses/>. 22 */ 23 #ifndef VIEW_MESSAGEVIEW_H 24 #define VIEW_MESSAGEVIEW_H 25 26 #include <QPersistentModelIndex> 27 #include <QPointer> 28 #include <QSet> 29 #include <QWidget> 30 #include "Composer/Recipients.h" 31 #include "Gui/PartWalker.h" 32 33 class QBoxLayout; 34 class QLabel; 35 class QLayout; 36 class QSettings; 37 class QStackedLayout; 38 class QTimer; 39 class QUrl; 40 class QWebView; 41 42 namespace Cryptography { 43 class MessageModel; 44 } 45 46 namespace Imap { 47 namespace Network { 48 class MsgPartNetAccessManager; 49 } 50 namespace Message { 51 class Envelope; 52 } 53 namespace Mailbox { 54 class NetworkWatcher; 55 } 56 } 57 58 namespace Plugins { 59 class PluginManager; 60 } 61 62 namespace Gui { 63 64 class AbstractPartWidget; 65 class EmbeddedWebView; 66 class EnvelopeView; 67 class MainWindow; 68 class ExternalElementsWidget; 69 class Spinner; 70 class TagListWidget; 71 72 73 /** @short Widget for displaying complete e-mail messages as available from the IMAP server 74 75 Widget which can render a regular message as exported by the Imap::Mailbox::Model model. 76 Notably, this class will not render message/rfc822 MIME parts. 77 */ 78 class MessageView : public QWidget 79 { 80 Q_OBJECT 81 public: 82 MessageView(QWidget *parent, QSettings *settings, Plugins::PluginManager *pluginManager); 83 ~MessageView(); 84 85 void setNetworkWatcher(Imap::Mailbox::NetworkWatcher *netWatcher); 86 void reply(MainWindow *mainWindow, Composer::ReplyMode mode); 87 void forward(MainWindow *mainWindow, const Composer::ForwardMode mode); 88 QModelIndex currentMessage() const; 89 Plugins::PluginManager *pluginManager() const; 90 public slots: 91 void setMessage(const QModelIndex &index); 92 void setEmpty(); 93 void setHomepageUrl(const QUrl &homepage); 94 void stopAutoMarkAsRead(); 95 void zoomIn(); 96 void zoomOut(); 97 void zoomOriginal(); 98 protected: 99 void showEvent(QShowEvent *se) override; 100 private slots: 101 void markAsRead(); 102 void externalsRequested(const QUrl &url); 103 void enableExternalData(); 104 void newLabelAction(const QString &tag); 105 void deleteLabelAction(const QString &tag); 106 void partContextMenuRequested(const QPoint &point); 107 void partLinkHovered(const QString &link, const QString &title, const QString &textContent); 108 void triggerSearchDialog(); 109 void onWebViewLoadStarted(); 110 void onWebViewLoadFinished(); 111 signals: 112 void messageChanged(); 113 void messageModelChanged(QAbstractItemModel *model); 114 void linkHovered(const QString &url); 115 void searchRequestedBy(EmbeddedWebView *webView); 116 void transferError(const QString &errorString); 117 private: 118 bool eventFilter(QObject *object, QEvent *event) override; 119 Imap::Message::Envelope envelope() const; 120 QString quoteText() const; 121 void showMessageNow(); 122 AbstractPartWidget *bodyWidget() const; 123 void unsetPreviousMessage(); 124 void clearWaitingConns(); 125 126 QStackedLayout *m_stack; 127 QWebView *m_homePage; 128 129 QWidget *m_messageWidget; 130 QBoxLayout *m_msgLayout; 131 EnvelopeView *m_envelope; 132 ExternalElementsWidget *externalElements; 133 TagListWidget *tags; 134 QPersistentModelIndex message; 135 Cryptography::MessageModel *messageModel; 136 Imap::Network::MsgPartNetAccessManager *netAccess; 137 QPointer<Imap::Mailbox::NetworkWatcher> m_netWatcher; 138 QTimer *markAsReadTimer; 139 QWidget *m_bodyWidget; 140 QAction *m_zoomIn, *m_zoomOut, *m_zoomOriginal; 141 142 std::unique_ptr<PartWidgetFactory> factory; 143 Spinner *m_loadingSpinner; 144 QSettings *m_settings; 145 Plugins::PluginManager *m_pluginManager; 146 QSet<QWebView*> m_loadingItems; 147 148 std::vector<QMetaObject::Connection> m_waitingMessageConns; 149 150 MessageView(const MessageView &); // don't implement 151 MessageView &operator=(const MessageView &); // don't implement 152 153 friend class SimplePartWidget; // needs access to onWebViewLoadStarted/onWebViewLoadFinished 154 }; 155 156 } 157 158 #endif // VIEW_MESSAGEVIEW_H 159