viewer.h 13.3 KB
Newer Older
1 2
/*
  This file is part of KMail, the KDE mail client.
3 4 5
  SPDX-FileCopyrightText: 1997 Markus Wuebben <markus.wuebben@kde.org>
  SPDX-FileCopyrightText: 2009 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.net
  SPDX-FileCopyrightText: 2009 Andras Mantia <andras@kdab.net>
6

7
  SPDX-License-Identifier: GPL-2.0-or-later
8 9 10 11 12 13
*/

#ifndef MESSAGEVIEWER_H
#define MESSAGEVIEWER_H

#include "messageviewer_export.h"
14
#include "config-messageviewer.h"
15
#include "messageviewer/viewerplugininterface.h"
16
#include <MimeTreeParser/Enums>
17

18
#include <KMime/Message>
19 20 21

#include <QWidget>

Laurent Montel's avatar
Laurent Montel committed
22
namespace Akonadi {
23 24 25 26 27 28 29 30 31 32 33 34 35 36
class Item;
class ItemFetchJob;
}

class KActionCollection;
class QAction;
class KToggleAction;
class KActionMenu;

class QAbstractItemModel;
class QCloseEvent;
class QEvent;
class QResizeEvent;

Laurent Montel's avatar
Laurent Montel committed
37
namespace WebEngineViewer {
Laurent Montel's avatar
Laurent Montel committed
38 39 40
class WebHitTestResult;
}

Laurent Montel's avatar
Laurent Montel committed
41
namespace MessageViewer {
Laurent Montel's avatar
Laurent Montel committed
42
class WebHitTestResult;
43
class DKIMWidgetInfo;
Laurent Montel's avatar
Laurent Montel committed
44
class DKIMViewerMenu;
45
class AttachmentStrategy;
46 47 48
class HeaderStylePlugin;
class CSSHelper;
class ViewerPrivate;
49
class Viewer;
50 51 52 53 54

/**
 * An interface to plug in a handler that is called when
 * an message item has been loaded into the view.
 */
55
class MESSAGEVIEWER_EXPORT AbstractMessageLoadedHandler
56 57
{
public:
58 59
    AbstractMessageLoadedHandler();
    virtual ~AbstractMessageLoadedHandler();
60 61 62 63 64 65 66 67

    /**
     * This method is called whenever a message item has been loaded
     * into the view.
     *
     * @param item The message item that has been loaded.
     */
    virtual void setItem(const Akonadi::Item &item) = 0;
68 69 70 71 72 73 74 75 76

protected:
    Akonadi::Session *session() const;

private:
    void setSession(Akonadi::Session *session);

    friend class Viewer;
    class Private;
Laurent Montel's avatar
Laurent Montel committed
77
    Private *const d;
78 79 80 81 82 83 84
};

/**
 * This is the main widget for the viewer.
 * See the documentation of ViewerPrivate for implementation details.
 * See Mainpage.dox for an overview of the classes in the messageviewer library.
 */
Laurent Montel's avatar
Laurent Montel committed
85
class MESSAGEVIEWER_EXPORT Viewer : public QWidget
86 87 88 89 90 91 92 93 94
{
    Q_OBJECT

    Q_DECLARE_PRIVATE(Viewer)

public:
    /**
    * Create a mail viewer widget
    * @param parent parent widget
95
    * @param widget the application's main widget
96 97
    * @param actionCollection the action collection where the widget's actions will belong to
    */
Laurent Montel's avatar
Laurent Montel committed
98
    explicit Viewer(QWidget *parent, QWidget *widget = nullptr, KActionCollection *actionCollection = nullptr);
Laurent Montel's avatar
Laurent Montel committed
99
    ~Viewer() override;
100 101 102 103

    /**
    * Returns the current message displayed in the viewer.
    */
Laurent Montel's avatar
Laurent Montel committed
104
    Q_REQUIRED_RESULT KMime::Message::Ptr message() const;
105 106 107 108

    /**
    * Returns the current message item displayed in the viewer.
    */
Laurent Montel's avatar
Laurent Montel committed
109
    Q_REQUIRED_RESULT Akonadi::Item messageItem() const;
110 111 112 113

    enum DisplayFormatMessage {
        UseGlobalSetting = 0,
        Text = 1,
Laurent Montel's avatar
Laurent Montel committed
114
        Html = 2,
115 116
        Unknown = 3,
        ICal = 4
117 118 119 120
    };

    enum AttachmentAction {
        Open = 1,
Laurent Montel's avatar
Laurent Montel committed
121 122 123 124 125 126 127 128 129
        OpenWith,
        View,
        Save,
        Properties,
        Delete,
        Copy,
        ScrollTo,
        ReplyMessageToAuthor,
        ReplyMessageToAll
130 131 132 133 134 135 136 137 138
    };

    enum ResourceOnlineMode {
        AllResources = 0,
        SelectedResource = 1
    };

    /**
    * Set the message that shall be shown.
139
    * @param message - the message to be shown. If 0, an empty page is displayed.
140 141
    * @param updateMode - update the display immediately or not. See UpdateMode.
    */
Laurent Montel's avatar
Laurent Montel committed
142
    void setMessage(const KMime::Message::Ptr &message, MimeTreeParser::UpdateMode updateMode = MimeTreeParser::Delayed);
143 144 145 146 147 148 149

    /**
    * Set the Akonadi item that will be displayed.
    * @param item - the Akonadi item to be displayed. If it doesn't hold a mail (KMime::Message::Ptr as payload data),
    *               an empty page is shown.
    * @param updateMode - update the display immediately or not. See UpdateMode.
    */
Laurent Montel's avatar
Laurent Montel committed
150
    void setMessageItem(const Akonadi::Item &item, MimeTreeParser::UpdateMode updateMode = MimeTreeParser::Delayed);
151 152 153 154

    /**
    * The path to the message in terms of Akonadi collection hierarchy.
    */
Laurent Montel's avatar
Laurent Montel committed
155
    Q_REQUIRED_RESULT QString messagePath() const;
156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172

    /**
    * Set the path to the message in terms of Akonadi collection hierarchy.
    */
    void setMessagePath(const QString &path);

    /**
    * Instead of settings a message to be shown sets a message part
    * to be shown
    */
    void setMessagePart(KMime::Content *aMsgPart);

    /**
    * Convenience method to clear the reader and discard the current message. Sets the internal message pointer
    * returned by message() to 0.
    * @param updateMode - update the display immediately or not. See UpdateMode.
    */
173
    void clear(MimeTreeParser::UpdateMode updateMode = MimeTreeParser::Delayed);
174

175
    void update(MimeTreeParser::UpdateMode updateMode = MimeTreeParser::Delayed);
176 177 178

    /**
    * Sets a message as the current one and print it immediately.
179
    * @param msg the message to display and print
180 181 182 183 184 185 186 187 188 189
    */
    void printMessage(const Akonadi::Item &msg);

    void printPreviewMessage(const Akonadi::Item &message);

    /** Print the currently displayed message */
    void print();
    void printPreview();

    /** Get the html override setting */
Laurent Montel's avatar
Laurent Montel committed
190
    Q_REQUIRED_RESULT Viewer::DisplayFormatMessage displayFormatMessageOverwrite() const;
191 192 193 194 195 196 197

    /** Override default html mail setting */
    void setDisplayFormatMessageOverwrite(Viewer::DisplayFormatMessage format);

    /** Get the load external references override setting */
    bool htmlLoadExtOverride() const;

198 199 200 201 202 203 204 205 206 207 208 209 210
    /** Default behavior for loading external references.
     *  Use this for specifying the external reference loading behavior as
     *  specified in the user settings.
     *  @see setHtmlLoadExtOverride
     */
    void setHtmlLoadExtDefault(bool loadExtDefault);

    /** Override default load external references setting
     *  @warning This must only be called when the user has explicitly
     *  been asked to retrieve external references!
     *  @see setHtmlLoadExtDefault
     */
    void setHtmlLoadExtOverride(bool loadExtOverride);
211 212

    /** Is html mail to be supported? Takes into account override */
Laurent Montel's avatar
Laurent Montel committed
213
    Q_REQUIRED_RESULT bool htmlMail() const;
214 215

    /** Is loading ext. references to be supported? Takes into account override */
Laurent Montel's avatar
Laurent Montel committed
216
    Q_REQUIRED_RESULT bool htmlLoadExternal() const;
217 218 219 220 221

    /**
    * Display a generic HTML splash page instead of a message.
    * @param templateName - the template to be loaded
    * @param data - data for the template
Yuri Chornoivan's avatar
Yuri Chornoivan committed
222
    * @param domain the domain.
223
    */
Laurent Montel's avatar
Laurent Montel committed
224
    void displaySplashPage(const QString &templateName, const QVariantHash &data, const QByteArray &domain = QByteArray());
225 226 227 228 229

    /** Enable the displaying of messages again after an splash (or other) page was displayed */
    void enableMessageDisplay();

    /** Returns true if the message view is scrolled to the bottom. */
230
    void atBottom();
231

Laurent Montel's avatar
Laurent Montel committed
232
    Q_REQUIRED_RESULT bool isFixedFont() const;
233 234
    void setUseFixedFont(bool useFixedFont);

Laurent Montel's avatar
Laurent Montel committed
235
    Q_REQUIRED_RESULT QWidget *mainWindow();
236 237 238 239 240 241 242 243

    /** Enforce message decryption. */
    void setDecryptMessageOverwrite(bool overwrite = true);

    /**
    * Initiates a delete, by sending a signal to delete the message item */
    void deleteMessage();

Laurent Montel's avatar
Laurent Montel committed
244
    Q_REQUIRED_RESULT const AttachmentStrategy *attachmentStrategy() const;
245
    void setAttachmentStrategy(const AttachmentStrategy *strategy);
246

Laurent Montel's avatar
Laurent Montel committed
247
    Q_REQUIRED_RESULT QString overrideEncoding() const;
248
    void setOverrideEncoding(const QString &encoding);
Laurent Montel's avatar
Laurent Montel committed
249
    Q_REQUIRED_RESULT CSSHelper *cssHelper() const;
250 251 252 253 254 255 256
    void setPrinting(bool enable);

    void selectAll();
    void copySelectionToClipboard();

    void setZoomFactor(qreal zoomFactor);

Laurent Montel's avatar
Laurent Montel committed
257 258 259 260 261 262 263 264 265 266 267 268 269 270 271
    Q_REQUIRED_RESULT KToggleAction *toggleFixFontAction() const;

    Q_REQUIRED_RESULT KToggleAction *toggleMimePartTreeAction() const;

    Q_REQUIRED_RESULT QAction *selectAllAction() const;
    Q_REQUIRED_RESULT QAction *copyURLAction() const;
    Q_REQUIRED_RESULT QAction *copyAction() const;
    Q_REQUIRED_RESULT QAction *urlOpenAction() const;
    Q_REQUIRED_RESULT QAction *speakTextAction() const;
    Q_REQUIRED_RESULT QAction *copyImageLocation() const;
    Q_REQUIRED_RESULT QAction *viewSourceAction() const;
    Q_REQUIRED_RESULT QAction *findInMessageAction() const;
    Q_REQUIRED_RESULT QAction *saveAsAction() const;
    Q_REQUIRED_RESULT QAction *saveMessageDisplayFormatAction() const;
    Q_REQUIRED_RESULT QAction *resetMessageDisplayFormatAction() const;
Laurent Montel's avatar
Laurent Montel committed
272 273
    Q_REQUIRED_RESULT QAction *shareTextAction() const;

274
    Q_REQUIRED_RESULT QAction *developmentToolsAction() const;
Laurent Montel's avatar
Laurent Montel committed
275 276 277
    Q_REQUIRED_RESULT KToggleAction *disableEmoticonAction() const;
    Q_REQUIRED_RESULT KActionMenu *shareServiceUrlMenu() const;
    Q_REQUIRED_RESULT HeaderStylePlugin *headerStylePlugin() const;
Laurent Montel's avatar
Laurent Montel committed
278 279
    Q_REQUIRED_RESULT MessageViewer::DKIMViewerMenu *dkimViewerMenu();

280 281 282 283
    void setPluginName(const QString &pluginName);

    void writeConfig(bool withSync = true);

Laurent Montel's avatar
Laurent Montel committed
284 285
    Q_REQUIRED_RESULT QUrl urlClicked() const;
    Q_REQUIRED_RESULT QUrl imageUrlClicked() const;
286 287 288 289 290 291 292 293 294 295 296 297

    void readConfig();

    /** A QAIM tree model of the message structure. */
    QAbstractItemModel *messageTreeModel() const;

    /**
    * Create an item fetch job that is suitable for using to fetch the message item that will
    * be displayed on this viewer.
    * It will set the correct fetch scope.
    * You still need to connect to the job's result signal.
    */
298
    Akonadi::ItemFetchJob *createFetchJob(const Akonadi::Item &item);
299 300 301 302 303 304 305 306 307 308 309 310 311

    /**
    * Adds a @p handler for actions that will be executed when the message
    * has been loaded into the view.
    */
    void addMessageLoadedHandler(AbstractMessageLoadedHandler *handler);

    /**
    * Removes the @p handler for actions that will be executed when the message
    * has been loaded into the view.
    */
    void removeMessageLoadedHandler(AbstractMessageLoadedHandler *handler);

Laurent Montel's avatar
Laurent Montel committed
312
    Q_REQUIRED_RESULT QString selectedText() const;
313 314 315 316

    void saveMainFrameScreenshotInFile(const QString &filename);
    bool mimePartTreeIsEmpty() const;

317
    void showOpenAttachmentFolderWidget(const QList<QUrl> &urls);
Laurent Montel's avatar
Laurent Montel committed
318
    Q_REQUIRED_RESULT QList<QAction *> viewerPluginActionList(
Laurent Montel's avatar
Laurent Montel committed
319
        MessageViewer::ViewerPluginInterface::SpecificFeatureTypes features);
Laurent Montel's avatar
Laurent Montel committed
320
    Q_REQUIRED_RESULT QList<QAction *> interceptorUrlActions(const WebEngineViewer::WebHitTestResult &result) const;
321

Laurent Montel's avatar
Laurent Montel committed
322
    void runJavaScript(const QString &code);
Laurent Montel's avatar
Laurent Montel committed
323
    void setPrintElementBackground(bool printElementBackground);
324

Laurent Montel's avatar
Laurent Montel committed
325
    Q_REQUIRED_RESULT bool printingMode() const;
326

327
    Q_REQUIRED_RESULT bool showSignatureDetails() const;
Laurent Montel's avatar
Laurent Montel committed
328
    void setShowSignatureDetails(bool showDetails);
329 330 331 332

    Q_REQUIRED_RESULT qreal webViewZoomFactor() const;
    void setWebViewZoomFactor(qreal factor);

333 334 335
    Q_REQUIRED_RESULT bool showEncryptionDetails() const;
    void setShowEncryptionDetails(bool showDetails);

336
    void hasMultiMessages(bool messages);
337
    void updateShowMultiMessagesButton(bool enablePreviousButton, bool enableNextButton);
Laurent Montel's avatar
Laurent Montel committed
338
    Q_REQUIRED_RESULT MessageViewer::DKIMWidgetInfo *dkimWidgetInfo();
339

Laurent Montel's avatar
Laurent Montel committed
340 341
    void exportToPdf(const QString &fileName);

Laurent Montel's avatar
Laurent Montel committed
342
    void showDevelopmentTools();
343 344
Q_SIGNALS:
    void moveMessageToTrash();
345
    void pageIsScrolledToBottom(bool);
346 347 348 349 350 351 352 353

    /**
    * Emitted when a status bar message is shown. Note that the status bar message is also set to
    * KPIM::BroadcastStatus in addition.
    */
    void showStatusBarMessage(const QString &message);

    /** The user presses the right mouse button. 'url' may be 0. */
Laurent Montel's avatar
Laurent Montel committed
354 355
    void popupMenu(const Akonadi::Item &msg, const QUrl &url, const QUrl &imageUrl, const QPoint &mousePos);
    void displayPopupMenu(const Akonadi::Item &msg, const WebEngineViewer::WebHitTestResult &result, const QPoint &mousePos);
356 357 358 359 360 361 362 363 364 365 366 367 368 369
    /**
    * The message viewer handles some types of urls itself, most notably http(s)
    * and ftp(s). When it can't handle the url it will Q_EMIT this signal.
    */
    void urlClicked(const Akonadi::Item &, const QUrl &);

    void requestConfigSync();

    /// Emitted when the content should be shown in a separate window
    void showReader(KMime::Content *aMsgPart, bool aHTML, const QString &encoding);

    /// Emitted when the message should be shown in a separate window
    void showMessage(const KMime::Message::Ptr &message, const QString &encoding);

370 371
    void replyMessageTo(const KMime::Message::Ptr &message, bool replyToAll);

372 373 374 375 376 377 378
    void deleteMessage(const Akonadi::Item &);

    /// Emitted when the item, previously set with setMessageItem, has been removed.
    void itemRemoved();

    void makeResourceOnline(MessageViewer::Viewer::ResourceOnlineMode mode);

379
    void printingFinished();
Laurent Montel's avatar
Laurent Montel committed
380
    void zoomChanged(qreal zoomFactor);
381 382 383
    void showNextMessage();
    void showPreviousMessage();

384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410
private:
    void initialize();

public Q_SLOTS:

    /**
    * HTML Widget scrollbar and layout handling.
    *
    * Scrolling always happens in the direction of the slot that is called. I.e.
    * the methods take the absolute value of
    */
    void slotScrollUp();
    void slotScrollDown();
    void slotScrollPrior();
    void slotScrollNext();
    void slotJumpDown();
    void slotFind();
    void slotSaveMessage();
    void slotAttachmentSaveAs();
    void slotAttachmentSaveAll();
    void slotShowMessageSource();
    void slotZoomIn();
    void slotZoomOut();
    void slotZoomReset();
    void slotChangeDisplayMail(Viewer::DisplayFormatMessage, bool);
protected:
    /** Some necessary event handling. */
411 412
    void closeEvent(QCloseEvent *) override;
    void resizeEvent(QResizeEvent *) override;
413
    /** Watch for palette changes */
Laurent Montel's avatar
Laurent Montel committed
414
    Q_REQUIRED_RESULT bool event(QEvent *e) override;
415
    void changeEvent(QEvent *event) override;
416 417 418 419 420 421

    ViewerPrivate *const d_ptr;
};
}

#endif