Messagelib

viewer.h
1/*
2 This file is part of KMail, the KDE mail client.
3 SPDX-FileCopyrightText: 1997 Markus Wuebben <markus.wuebben@kde.org>
4 SPDX-FileCopyrightText: 2009 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.net
5 SPDX-FileCopyrightText: 2009 Andras Mantia <andras@kdab.net>
6
7 SPDX-License-Identifier: GPL-2.0-or-later
8*/
9
10#pragma once
11
12#include "messageviewer/viewerplugininterface.h"
13#include "messageviewer_export.h"
14#include <MimeTreeParser/Enums>
15
16#include <KMime/MDN>
17#include <KMime/Message>
18#include <MessageViewer/MDNWarningWidget>
19
20#include <QWidget>
21#include <memory>
22
23namespace Akonadi
24{
25class Item;
26class ItemFetchJob;
27}
28
29namespace KIdentityManagementCore
30{
31class IdentityManager;
32}
33
35class QAction;
36class KToggleAction;
37class KActionMenu;
38
40class QCloseEvent;
41class QEvent;
42class QResizeEvent;
43
44namespace WebEngineViewer
45{
46class WebHitTestResult;
47}
48
49namespace MessageViewer
50{
51class WebHitTestResult;
52class DKIMWidgetInfo;
53class DKIMViewerMenu;
54class AttachmentStrategy;
55class HeaderStylePlugin;
56class CSSHelper;
57class ViewerPrivate;
58class Viewer;
59class RemoteContentMenu;
60class MDNWarningWidget;
61
62/**
63 * An interface to plug in a handler that is called when
64 * an message item has been loaded into the view.
65 */
66class MESSAGEVIEWER_EXPORT AbstractMessageLoadedHandler
67{
68public:
71
72 /**
73 * This method is called whenever a message item has been loaded
74 * into the view.
75 *
76 * @param item The message item that has been loaded.
77 */
78 virtual void setItem(const Akonadi::Item &item) = 0;
79
80protected:
81 Akonadi::Session *session() const;
82
83private:
84 MESSAGEVIEWER_NO_EXPORT void setSession(Akonadi::Session *session);
85
86 friend class Viewer;
87 class AbstractMessageLoadedHandlerPrivate;
88 std::unique_ptr<AbstractMessageLoadedHandlerPrivate> const d;
89};
90
91/**
92 * This is the main widget for the viewer.
93 * See the documentation of ViewerPrivate for implementation details.
94 * See Mainpage.dox for an overview of the classes in the messageviewer library.
95 */
96class MESSAGEVIEWER_EXPORT Viewer : public QWidget
97{
98 Q_OBJECT
99
100 Q_DECLARE_PRIVATE(Viewer)
101
102public:
103 /**
104 * Create a mail viewer widget
105 * @param parent parent widget
106 * @param widget the application's main widget
107 * @param actionCollection the action collection where the widget's actions will belong to
108 */
109 explicit Viewer(QWidget *parent, QWidget *widget = nullptr, KActionCollection *actionCollection = nullptr);
110 ~Viewer() override;
111
112 /**
113 * Returns the current message displayed in the viewer.
114 */
115 [[nodiscard]] KMime::Message::Ptr message() const;
116
117 /**
118 * Returns the current message item displayed in the viewer.
119 */
120 [[nodiscard]] Akonadi::Item messageItem() const;
121
122 enum DisplayFormatMessage {
123 UseGlobalSetting = 0,
124 Text = 1,
125 Html = 2,
126 Unknown = 3,
127 ICal = 4,
128 };
129
130 enum AttachmentAction {
131 Open = 1,
132 OpenWith,
133 View,
134 Save,
135 Properties,
136 Delete,
137 Copy,
138 ScrollTo,
139 ReplyMessageToAuthor,
140 ReplyMessageToAll,
141 };
142
143 enum ResourceOnlineMode {
144 AllResources = 0,
145 SelectedResource = 1,
146 };
147
148 /**
149 * Set the message that shall be shown.
150 * @param message - the message to be shown. If 0, an empty page is displayed.
151 * @param updateMode - update the display immediately or not. See UpdateMode.
152 */
153 void setMessage(const KMime::Message::Ptr &message, MimeTreeParser::UpdateMode updateMode = MimeTreeParser::Delayed);
154
155 /**
156 * Set the Akonadi item that will be displayed.
157 * @param item - the Akonadi item to be displayed. If it doesn't hold a mail (KMime::Message::Ptr as payload data),
158 * an empty page is shown.
159 * @param updateMode - update the display immediately or not. See UpdateMode.
160 */
161 void setMessageItem(const Akonadi::Item &item, MimeTreeParser::UpdateMode updateMode = MimeTreeParser::Delayed);
162
163 /**
164 * The path to the message in terms of Akonadi collection hierarchy.
165 */
166 [[nodiscard]] QString messagePath() const;
167
168 /**
169 * Set the path to the message in terms of Akonadi collection hierarchy.
170 */
171 void setMessagePath(const QString &path);
172
173 /**
174 * Instead of settings a message to be shown sets a message part
175 * to be shown
176 */
177 void setMessagePart(KMime::Content *aMsgPart);
178
179 /**
180 * Convenience method to clear the reader and discard the current message. Sets the internal message pointer
181 * returned by message() to 0.
182 * @param updateMode - update the display immediately or not. See UpdateMode.
183 */
184 void clear(MimeTreeParser::UpdateMode updateMode = MimeTreeParser::Delayed);
185
186 void update(MimeTreeParser::UpdateMode updateMode = MimeTreeParser::Delayed);
187
188 /**
189 * Sets a message as the current one and print it immediately.
190 * @param msg the message to display and print
191 */
192 void printMessage(const Akonadi::Item &msg);
193
194 void printPreviewMessage(const Akonadi::Item &message);
195
196 /** Print the currently displayed message */
197 void print();
198 void printPreview();
199
200 /** Get the html override setting */
201 [[nodiscard]] Viewer::DisplayFormatMessage displayFormatMessageOverwrite() const;
202
203 /** Override default html mail setting */
204 void setDisplayFormatMessageOverwrite(Viewer::DisplayFormatMessage format);
205
206 /** Get the load external references override setting */
207 [[nodiscard]] bool htmlLoadExtOverride() const;
208
209 /** Default behavior for loading external references.
210 * Use this for specifying the external reference loading behavior as
211 * specified in the user settings.
212 * @see setHtmlLoadExtOverride
213 */
214 void setHtmlLoadExtDefault(bool loadExtDefault);
215
216 /** Override default load external references setting
217 * @warning This must only be called when the user has explicitly
218 * been asked to retrieve external references!
219 * @see setHtmlLoadExtDefault
220 */
221 void setHtmlLoadExtOverride(bool loadExtOverride);
222
223 /** Is html mail to be supported? Takes into account override */
224 [[nodiscard]] bool htmlMail() const;
225
226 /** Is loading ext. references to be supported? Takes into account override */
227 [[nodiscard]] bool htmlLoadExternal() const;
228
229 /**
230 * Display a generic HTML splash page instead of a message.
231 * @param templateName - the template to be loaded
232 * @param data - data for the template
233 * @param domain the domain.
234 */
235 void displaySplashPage(const QString &templateName, const QVariantHash &data, const QByteArray &domain = QByteArray());
236
237 /** Enable the displaying of messages again after an splash (or other) page was displayed */
238 void enableMessageDisplay();
239
240 /** Returns true if the message view is scrolled to the bottom. */
241 void atBottom();
242
243 [[nodiscard]] bool isFixedFont() const;
244 void setUseFixedFont(bool useFixedFont);
245
246 [[nodiscard]] QWidget *mainWindow();
247
248 /** Enforce message decryption. */
249 void setDecryptMessageOverwrite(bool overwrite = true);
250
251 /**
252 * Initiates a delete, by sending a signal to delete the message item */
253 void deleteMessage();
254
255 [[nodiscard]] const AttachmentStrategy *attachmentStrategy() const;
256 void setAttachmentStrategy(const AttachmentStrategy *strategy);
257
258 [[nodiscard]] QString overrideEncoding() const;
259 void setOverrideEncoding(const QString &encoding);
260 [[nodiscard]] CSSHelper *cssHelper() const;
261 void setPrinting(bool enable);
262
263 void selectAll();
264 void copySelectionToClipboard();
265
266 void setZoomFactor(qreal zoomFactor);
267
268 [[nodiscard]] KToggleAction *toggleFixFontAction() const;
269
270 [[nodiscard]] KToggleAction *toggleMimePartTreeAction() const;
271
272 [[nodiscard]] QAction *selectAllAction() const;
273 [[nodiscard]] QAction *copyURLAction() const;
274 [[nodiscard]] QAction *copyAction() const;
275 [[nodiscard]] QAction *urlOpenAction() const;
276 [[nodiscard]] QAction *speakTextAction() const;
277 [[nodiscard]] QAction *copyImageLocation() const;
278 [[nodiscard]] QAction *viewSourceAction() const;
279 [[nodiscard]] QAction *findInMessageAction() const;
280 [[nodiscard]] QAction *saveAsAction() const;
281 [[nodiscard]] QAction *saveMessageDisplayFormatAction() const;
282 [[nodiscard]] QAction *resetMessageDisplayFormatAction() const;
283 [[nodiscard]] QAction *shareTextAction() const;
284
285 [[nodiscard]] QAction *developmentToolsAction() const;
286 [[nodiscard]] KToggleAction *disableEmoticonAction() const;
287 [[nodiscard]] KActionMenu *shareServiceUrlMenu() const;
288 [[nodiscard]] HeaderStylePlugin *headerStylePlugin() const;
289 [[nodiscard]] MessageViewer::DKIMViewerMenu *dkimViewerMenu();
290
291 [[nodiscard]] MessageViewer::RemoteContentMenu *remoteContentMenu() const;
292
293 void setPluginName(const QString &pluginName);
294
295 void writeConfig(bool withSync = true);
296
297 [[nodiscard]] QUrl urlClicked() const;
298 [[nodiscard]] QUrl imageUrlClicked() const;
299
300 void readConfig();
301
302 /** A QAIM tree model of the message structure. */
303 QAbstractItemModel *messageTreeModel() const;
304
305 /**
306 * Create an item fetch job that is suitable for using to fetch the message item that will
307 * be displayed on this viewer.
308 * It will set the correct fetch scope.
309 * You still need to connect to the job's result signal.
310 */
311 Akonadi::ItemFetchJob *createFetchJob(const Akonadi::Item &item);
312
313 /**
314 * Adds a @p handler for actions that will be executed when the message
315 * has been loaded into the view.
316 */
317 void addMessageLoadedHandler(AbstractMessageLoadedHandler *handler);
318
319 /**
320 * Removes the @p handler for actions that will be executed when the message
321 * has been loaded into the view.
322 */
323 void removeMessageLoadedHandler(AbstractMessageLoadedHandler *handler);
324
325 [[nodiscard]] QString selectedText() const;
326
327 void saveMainFrameScreenshotInFile(const QString &filename);
328 [[nodiscard]] bool mimePartTreeIsEmpty() const;
329
330 void showOpenAttachmentFolderWidget(const QList<QUrl> &urls);
331 [[nodiscard]] QList<QAction *> viewerPluginActionList(MessageViewer::ViewerPluginInterface::SpecificFeatureTypes features);
332 [[nodiscard]] QList<QAction *> interceptorUrlActions(const WebEngineViewer::WebHitTestResult &result) const;
333
334 void runJavaScript(const QString &code);
335 void setPrintElementBackground(bool printElementBackground);
336
337 [[nodiscard]] bool printingMode() const;
338
339 [[nodiscard]] bool showSignatureDetails() const;
340 void setShowSignatureDetails(bool showDetails);
341
342 [[nodiscard]] qreal webViewZoomFactor() const;
343 void setWebViewZoomFactor(qreal factor);
344
345 [[nodiscard]] bool showEncryptionDetails() const;
346 void setShowEncryptionDetails(bool showDetails);
347
348 void hasMultiMessages(bool messages);
349 void updateShowMultiMessagesButton(bool enablePreviousButton, bool enableNextButton);
350 [[nodiscard]] MessageViewer::DKIMWidgetInfo *dkimWidgetInfo();
351
352 void exportToPdf(const QString &fileName);
353
354 void showDevelopmentTools();
355
356 void setIdentityManager(KIdentityManagementCore::IdentityManager *ident);
357 void setFolderIdentity(uint folderIdentity);
358 void showMdnInformations(const QPair<QString, bool> &mdnInfo);
359 void mdnWarningAnimatedHide();
360Q_SIGNALS:
361 void moveMessageToTrash();
362 void pageIsScrolledToBottom(bool);
363
364 /**
365 * Emitted when a status bar message is shown. Note that the status bar message is also set to
366 * KPIM::BroadcastStatus in addition.
367 */
368 void showStatusBarMessage(const QString &message);
369
370 /** The user presses the right mouse button. 'url' may be 0. */
371 void popupMenu(const Akonadi::Item &msg, const QUrl &url, const QUrl &imageUrl, const QPoint &mousePos);
372 void displayPopupMenu(const Akonadi::Item &msg, const WebEngineViewer::WebHitTestResult &result, const QPoint &mousePos);
373 /**
374 * The message viewer handles some types of urls itself, most notably http(s)
375 * and ftp(s). When it can't handle the url it will Q_EMIT this signal.
376 */
377 void urlClicked(const Akonadi::Item &, const QUrl &);
378
379 void requestConfigSync();
380
381 /// Emitted when the content should be shown in a separate window
382 void showReader(KMime::Content *aMsgPart, bool aHTML, const QString &encoding);
383
384 /// Emitted when the message should be shown in a separate window
385 void showMessage(const KMime::Message::Ptr &message, const QString &encoding);
386
387 void replyMessageTo(const KMime::Message::Ptr &message, bool replyToAll);
388
389 void deleteMessage(const Akonadi::Item &);
390
391 /// Emitted when the item, previously set with setMessageItem, has been removed.
393
394 void makeResourceOnline(MessageViewer::Viewer::ResourceOnlineMode mode);
395
396 void printingFinished();
397 void zoomChanged(qreal zoomFactor);
398 void showNextMessage();
399 void showPreviousMessage();
400 void sendResponse(MessageViewer::MDNWarningWidget::ResponseType type, KMime::MDN::SendingMode sendingMode);
401
402private:
403 MESSAGEVIEWER_NO_EXPORT void initialize();
404 MESSAGEVIEWER_NO_EXPORT void slotGeneralPaletteChanged();
405
406public Q_SLOTS:
407
408 /**
409 * HTML Widget scrollbar and layout handling.
410 *
411 * Scrolling always happens in the direction of the slot that is called. I.e.
412 * the methods take the absolute value of
413 */
414 void slotScrollUp();
415 void slotScrollDown();
416 void slotScrollPrior();
417 void slotScrollNext();
418 void slotJumpDown();
419 void slotFind();
420 void slotSaveMessage();
421 void slotAttachmentSaveAs();
422 void slotAttachmentSaveAll();
423 void slotShowMessageSource();
424 void slotZoomIn();
425 void slotZoomOut();
426 void slotZoomReset();
427 void slotChangeDisplayMail(Viewer::DisplayFormatMessage, bool);
428
429protected:
430 /** Some necessary event handling. */
431 void closeEvent(QCloseEvent *) override;
432 void resizeEvent(QResizeEvent *) override;
433 /** Watch for palette changes */
434 [[nodiscard]] bool event(QEvent *e) override;
435 [[nodiscard]] bool eventFilter(QObject *obj, QEvent *event) override;
436 void changeEvent(QEvent *event) override;
437
438 ViewerPrivate *const d_ptr;
439};
440}
An interface to plug in a handler that is called when an message item has been loaded into the view.
Definition viewer.h:67
virtual void setItem(const Akonadi::Item &item)=0
This method is called whenever a message item has been loaded into the view.
The AttachmentStrategy class.
The CSSHelper class.
Definition csshelper.h:22
The DKIMViewerMenu class.
The DKIMWidgetInfo class.
The HeaderStylePlugin class.
The RemoteContentMenu class.
This is the main widget for the viewer.
Definition viewer.h:97
void showReader(KMime::Content *aMsgPart, bool aHTML, const QString &encoding)
Emitted when the content should be shown in a separate window.
void itemRemoved()
Emitted when the item, previously set with setMessageItem, has been removed.
void showMessage(const KMime::Message::Ptr &message, const QString &encoding)
Emitted when the message should be shown in a separate window.
void showStatusBarMessage(const QString &message)
Emitted when a status bar message is shown.
void popupMenu(const Akonadi::Item &msg, const QUrl &url, const QUrl &imageUrl, const QPoint &mousePos)
The user presses the right mouse button.
void urlClicked(const Akonadi::Item &, const QUrl &)
The message viewer handles some types of urls itself, most notably http(s) and ftp(s).
The WebHitTestResult class.
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Fri May 24 2024 11:55:44 by doxygen 1.10.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.