File indexing completed on 2024-05-12 05:20:44
0001 /* 0002 This file is part of KMail, the KDE mail client. 0003 SPDX-FileCopyrightText: 1997 Markus Wuebben <markus.wuebben@kde.org> 0004 SPDX-FileCopyrightText: 2013-2024 Laurent Montel <montel@kde.org> 0005 0006 SPDX-License-Identifier: GPL-2.0-or-later 0007 */ 0008 0009 #pragma once 0010 0011 #include "kmail_export.h" 0012 0013 #include <Akonadi/Item> 0014 #include <KContacts/Addressee> 0015 #include <MessageViewer/MDNWarningWidget> 0016 #include <MessageViewer/Viewer> 0017 #include <MimeTreeParser/BodyPart> 0018 #include <QUrl> 0019 #include <QWidget> 0020 class KActionCollection; 0021 class QAction; 0022 class KToggleAction; 0023 class QMenu; 0024 namespace MessageViewer 0025 { 0026 class CSSHelper; 0027 class DKIMViewerMenu; 0028 } 0029 0030 namespace MimeTreeParser 0031 { 0032 class AttachmentStrategy; 0033 } 0034 0035 class KJob; 0036 0037 /** 0038 This class implements a "reader window", that is a window 0039 used for reading or viewing messages. 0040 */ 0041 0042 class KMAIL_EXPORT KMReaderWin : public QWidget 0043 { 0044 Q_OBJECT 0045 0046 public: 0047 explicit KMReaderWin(QWidget *parent, QWidget *mainWindow, KActionCollection *actionCollection); 0048 ~KMReaderWin() override; 0049 0050 /** Read settings from app's config file. */ 0051 void readConfig(); 0052 0053 /** Get/set the message attachment strategy. */ 0054 const MessageViewer::AttachmentStrategy *attachmentStrategy() const; 0055 0056 void setAttachmentStrategy(const MessageViewer::AttachmentStrategy *strategy); 0057 0058 /** Get selected override character encoding. 0059 @return The encoding selected by the user or an empty string if auto-detection 0060 is selected. */ 0061 [[nodiscard]] QString overrideEncoding() const; 0062 /** Set the override character encoding. */ 0063 void setOverrideEncoding(const QString &encoding); 0064 void setPrinting(bool enable); 0065 0066 void setMessage(const Akonadi::Item &item, MimeTreeParser::UpdateMode updateMode = MimeTreeParser::Delayed); 0067 0068 void setMessage(const KMime::Message::Ptr &message); 0069 0070 /** Instead of settings a message to be shown sets a message part 0071 to be shown */ 0072 void setMsgPart(KMime::Content *aMsgPart); 0073 0074 /** Clear the reader and discard the current message. */ 0075 void clear(bool force = false); 0076 0077 void update(bool force = false); 0078 0079 /** Return selected text */ 0080 [[nodiscard]] QString copyText() const; 0081 0082 /** Override default html mail setting */ 0083 [[nodiscard]] MessageViewer::Viewer::DisplayFormatMessage displayFormatMessageOverwrite() const; 0084 void setDisplayFormatMessageOverwrite(MessageViewer::Viewer::DisplayFormatMessage format); 0085 0086 /** Override default load external references setting */ 0087 [[nodiscard]] bool htmlLoadExtOverride() const; 0088 void setHtmlLoadExtDefault(bool loadExtDefault); 0089 void setHtmlLoadExtOverride(bool loadExtOverride); 0090 0091 /** Is html mail to be supported? Takes into account override */ 0092 [[nodiscard]] bool htmlMail() const; 0093 0094 /** Is loading ext. references to be supported? Takes into account override */ 0095 [[nodiscard]] bool htmlLoadExternal(); 0096 0097 /** Returns the MD5 hash for the list of new features */ 0098 [[nodiscard]] static QString newFeaturesMD5(); 0099 0100 /** Display a generic HTML splash page instead of a message */ 0101 void displaySplashPage(const QString &templateName, const QVariantHash &data); 0102 0103 /** Display the about page instead of a message */ 0104 void displayAboutPage(); 0105 0106 /** Display the 'please wait' page instead of a message */ 0107 void displayBusyPage(); 0108 /** Display the 'we are currently in offline mode' page instead of a message */ 0109 void displayOfflinePage(); 0110 0111 void displayResourceOfflinePage(); 0112 0113 [[nodiscard]] bool isFixedFont() const; 0114 void setUseFixedFont(bool useFixedFont); 0115 [[nodiscard]] MessageViewer::Viewer *viewer() const; 0116 [[nodiscard]] KToggleAction *toggleFixFontAction() const; 0117 [[nodiscard]] QAction *mailToComposeAction() const; 0118 [[nodiscard]] QAction *mailToReplyAction() const; 0119 [[nodiscard]] QAction *mailToForwardAction() const; 0120 [[nodiscard]] QAction *addAddrBookAction() const; 0121 [[nodiscard]] QAction *openAddrBookAction() const; 0122 [[nodiscard]] QAction *copyAction() const; 0123 [[nodiscard]] QAction *selectAllAction() const; 0124 [[nodiscard]] QAction *copyURLAction() const; 0125 [[nodiscard]] QAction *copyImageLocation() const; 0126 [[nodiscard]] QAction *urlOpenAction() const; 0127 [[nodiscard]] QAction *urlSaveAsAction() const; 0128 [[nodiscard]] QAction *addUrlToBookmarkAction() const; 0129 [[nodiscard]] QAction *toggleMimePartTreeAction() const; 0130 [[nodiscard]] QAction *speakTextAction() const; 0131 [[nodiscard]] QAction *downloadImageToDiskAction() const; 0132 [[nodiscard]] QAction *viewSourceAction() const; 0133 [[nodiscard]] QAction *findInMessageAction() const; 0134 [[nodiscard]] QAction *saveAsAction() const; 0135 [[nodiscard]] QAction *saveMessageDisplayFormatAction() const; 0136 [[nodiscard]] QAction *resetMessageDisplayFormatAction() const; 0137 [[nodiscard]] QAction *editContactAction() const; 0138 [[nodiscard]] QAction *developmentToolsAction() const; 0139 [[nodiscard]] QAction *shareTextAction() const; 0140 0141 [[nodiscard]] QMenu *viewHtmlOption() const; 0142 [[nodiscard]] QAction *shareImage() const; 0143 0144 [[nodiscard]] QAction *addToExistingContactAction() const; 0145 0146 [[nodiscard]] Akonadi::Item messageItem() const; 0147 0148 [[nodiscard]] QWidget *mainWindow() const; 0149 [[nodiscard]] QAction *openImageAction() const; 0150 0151 /** Enforce message decryption. */ 0152 void setDecryptMessageOverwrite(bool overwrite = true); 0153 0154 [[nodiscard]] MessageViewer::CSSHelper *cssHelper() const; 0155 0156 [[nodiscard]] bool printSelectedText(bool preview); 0157 0158 void setContactItem(const Akonadi::Item &contact, const KContacts::Addressee &address); 0159 void clearContactItem(); 0160 0161 [[nodiscard]] bool mimePartTreeIsEmpty() const; 0162 [[nodiscard]] KActionMenu *shareServiceUrlMenu() const; 0163 [[nodiscard]] MessageViewer::DKIMViewerMenu *dkimViewerMenu() const; 0164 [[nodiscard]] QList<QAction *> viewerPluginActionList(MessageViewer::ViewerPluginInterface::SpecificFeatureTypes features); 0165 0166 [[nodiscard]] QList<QAction *> interceptorUrlActions(const WebEngineViewer::WebHitTestResult &result) const; 0167 0168 void setPrintElementBackground(bool printElementBackground); 0169 /** Force update even if message is the same */ 0170 void clearCache(); 0171 0172 void hasMultiMessages(bool multi); 0173 0174 void updateShowMultiMessagesButton(bool enablePreviousButton, bool enableNextButton); 0175 MessageViewer::RemoteContentMenu *remoteContentMenu() const; 0176 void addImageMenuActions(QMenu *menu); 0177 Q_SIGNALS: 0178 void showStatusBarMessage(const QString &message); 0179 void zoomChanged(qreal factor); 0180 void showPreviousMessage(); 0181 void showNextMessage(); 0182 0183 public Q_SLOTS: 0184 0185 /** The user selected "Find" from the menu. */ 0186 void slotFind(); 0187 /** Copy the selected text to the clipboard */ 0188 void slotCopySelectedText(); 0189 /** Operations on mailto: URLs. */ 0190 void slotMailtoReply(); 0191 void slotMailtoCompose(); 0192 void slotMailtoForward(); 0193 void slotMailtoAddAddrBook(); 0194 void slotMailtoOpenAddrBook(); 0195 /** Save the page to a file */ 0196 void slotUrlSave(); 0197 void slotAddUrlToBookmark(); 0198 void slotUrlClicked(const Akonadi::Item &, const QUrl &); 0199 void slotShowReader(KMime::Content *, bool html, const QString &); 0200 void slotShowMessage(const KMime::Message::Ptr &message, const QString &encoding); 0201 void slotDeleteMessage(const Akonadi::Item &); 0202 void slotSaveImageOnDisk(); 0203 0204 void slotPrintComposeResult(KJob *job); 0205 void slotEditContact(); 0206 void contactStored(const Akonadi::Item &item); 0207 void slotContactEditorError(const QString &error); 0208 0209 void slotContactHtmlOptions(); 0210 void slotShareImage(); 0211 void slotMailToAddToExistingContact(); 0212 void slotPrintingFinished(); 0213 0214 protected: 0215 [[nodiscard]] QUrl urlClicked() const; 0216 [[nodiscard]] QUrl imageUrlClicked() const; 0217 0218 private: 0219 void createActions(); 0220 void updateHtmlActions(); 0221 void slotContactHtmlPreferencesUpdated(const Akonadi::Item &contact, Akonadi::Item::Id id, bool showAsHTML, bool remoteContent); 0222 void slotSendMdnResponse(MessageViewer::MDNWarningWidget::ResponseType type, KMime::MDN::SendingMode sendingMode); 0223 void sendMdnInfo(const Akonadi::Item &item); 0224 void slotShowMdnInfo(const QPair<QString, bool> &mdnInfo); 0225 void slotItemModified(const Akonadi::Item &item, const QSet<QByteArray> &partIdentifiers); 0226 void slotOpenImage(); 0227 0228 private: 0229 KContacts::Addressee mSearchedAddress; 0230 Akonadi::Item mSearchedContact; 0231 QWidget *const mMainWindow; 0232 KActionCollection *const mActionCollection; 0233 0234 QAction *mMailToComposeAction = nullptr; 0235 QAction *mMailToReplyAction = nullptr; 0236 QAction *mMailToForwardAction = nullptr; 0237 QAction *mAddAddrBookAction = nullptr; 0238 QAction *mOpenAddrBookAction = nullptr; 0239 QAction *mUrlSaveAsAction = nullptr; 0240 QAction *mAddUrlToBookmarkAction = nullptr; 0241 QAction *mImageUrlSaveAsAction = nullptr; 0242 QAction *mOpenImageAction = nullptr; 0243 QAction *mEditContactAction = nullptr; 0244 QAction *mViewAsHtml = nullptr; 0245 QAction *mLoadExternalReference = nullptr; 0246 QAction *mShareImage = nullptr; 0247 QAction *mAddEmailToExistingContactAction = nullptr; 0248 0249 QMenu *mViewHtmlOptions = nullptr; 0250 0251 MessageViewer::Viewer *mViewer = nullptr; 0252 };