2 This file is part of KMail, the KDE mail client.
3 Copyright (c) 1997 Markus Wuebben <markus.wuebben@kde.org>
4 Copyright (c) 2009-2016 Laurent Montel <montel@kde.org>
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License along
17 with this program; if not, write to the Free Software Foundation, Inc.,
18 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
21 // define this to copy all html that is written to the readerwindow to
22 // filehtmlwriter.out in the current working directory
23 #include "kmreaderwin.h"
25 #include "settings/kmailsettings.h"
26 #include "kmmainwidget.h"
27 #include "kmreadermainwin.h"
28 #include "mailcommon/mailkernel.h"
29 #include "dialog/addemailtoexistingcontactdialog.h"
30 #include "job/addemailtoexistingcontactjob.h"
32 #include "kdepim-version.h"
33 #include <KEmailAddress>
34 #include <Libkdepim/AddEmailAddressJob>
35 #include <Libkdepim/OpenEmailAddressJob>
36 #include <Libkdepim/AddEmailDisplayJob>
37 #include <Libkdepim/BroadcastStatus>
38 #include "kmcommands.h"
39 #include "MailCommon/SendMdnHandler"
40 #include <QVBoxLayout>
41 #include "messageviewer/headerstrategy.h"
42 #include "messageviewer/mailwebview.h"
43 #include "messageviewer/markmessagereadhandler.h"
44 #include "messageviewer/messageviewersettings.h"
45 #include "MessageViewer/CSSHelper"
46 using MessageViewer::CSSHelper
;
48 #include "MessageCore/StringUtil"
49 #include <QCryptographicHash>
50 #include <kmime/kmime_mdn.h>
51 #include <akonadi/kmime/messageflags.h>
53 #include "messageviewer/viewer.h"
54 using namespace MessageViewer
;
55 #include <MessageCore/MessageCoreSettings>
57 #include <MimeTreeParser/AttachmentStrategy>
58 #include "MessageComposer/MessageSender"
59 #include "MessageComposer/MessageFactory"
60 #include "MessageComposer/Composer"
61 #include "MessageComposer/TextPart"
62 #include "MessageComposer/InfoPart"
64 #include <KIO/JobUiDelegate>
65 using MessageComposer::MessageFactory
;
67 #include "messagecore/messagehelpers.h"
69 #include <Akonadi/Contact/ContactEditorDialog>
71 #include "kmail_debug.h"
72 #include <KLocalizedString>
75 #include <ktoggleaction.h>
77 #include <KActionCollection>
78 #include <KMessageBox>
93 #include <mailcommon/mailutil.h>
95 using namespace KMail
;
96 using namespace MailCommon
;
98 KMReaderWin::KMReaderWin(QWidget
*aParent
,
100 KActionCollection
*actionCollection
,
101 Qt::WindowFlags aFlags
)
102 : QWidget(aParent
, aFlags
),
103 mMainWindow(mainWindow
),
104 mActionCollection(actionCollection
),
105 mMailToComposeAction(Q_NULLPTR
),
106 mMailToReplyAction(Q_NULLPTR
),
107 mMailToForwardAction(Q_NULLPTR
),
108 mAddAddrBookAction(Q_NULLPTR
),
109 mOpenAddrBookAction(Q_NULLPTR
),
110 mUrlSaveAsAction(Q_NULLPTR
),
111 mAddBookmarksAction(Q_NULLPTR
),
112 mAddEmailToExistingContactAction(Q_NULLPTR
)
115 QVBoxLayout
*vlay
= new QVBoxLayout(this);
117 mViewer
= new Viewer(this, mainWindow
, mActionCollection
);
118 mViewer
->setExternalWindow(true);
119 mViewer
->setAppName(QStringLiteral("KMail"));
120 connect(mViewer
, SIGNAL(urlClicked(Akonadi::Item
,QUrl
)), this, SLOT(slotUrlClicked(Akonadi::Item
,QUrl
)));
121 connect(mViewer
, &Viewer::requestConfigSync
, kmkernel
, &KMKernel::slotRequestConfigSync
, Qt::QueuedConnection
); // happens anyway on shutdown, so we can skip it there with using a queued connection
122 connect(mViewer
, &Viewer::makeResourceOnline
, kmkernel
, &KMKernel::makeResourceOnline
);
123 connect(mViewer
, &MessageViewer::Viewer::showReader
, this, &KMReaderWin::slotShowReader
);
124 connect(mViewer
, &MessageViewer::Viewer::showMessage
, this, &KMReaderWin::slotShowMessage
);
125 connect(mViewer
, &MessageViewer::Viewer::showStatusBarMessage
, this, &KMReaderWin::showStatusBarMessage
);
126 connect(mViewer
, SIGNAL(deleteMessage(Akonadi::Item
)), this, SLOT(slotDeleteMessage(Akonadi::Item
)));
128 mViewer
->addMessageLoadedHandler(new MessageViewer::MarkMessageReadHandler(this));
129 mViewer
->addMessageLoadedHandler(new MailCommon::SendMdnHandler(kmkernel
, this));
131 vlay
->addWidget(mViewer
);
136 void KMReaderWin::createActions()
138 KActionCollection
*ac
= mActionCollection
;
146 mMailToComposeAction
= new QAction(QIcon::fromTheme(QStringLiteral("mail-message-new")),
147 i18n("New Message To..."), this);
148 ac
->addAction(QStringLiteral("mail_new"), mMailToComposeAction
);
149 ac
->setShortcutsConfigurable(mMailToComposeAction
, false);
150 connect(mMailToComposeAction
, &QAction::triggered
, this, &KMReaderWin::slotMailtoCompose
);
153 mMailToReplyAction
= new QAction(QIcon::fromTheme(QStringLiteral("mail-reply-sender")),
154 i18n("Reply To..."), this);
155 ac
->addAction(QStringLiteral("mailto_reply"), mMailToReplyAction
);
156 ac
->setShortcutsConfigurable(mMailToReplyAction
, false);
157 connect(mMailToReplyAction
, &QAction::triggered
, this, &KMReaderWin::slotMailtoReply
);
160 mMailToForwardAction
= new QAction(QIcon::fromTheme(QStringLiteral("mail-forward")),
161 i18n("Forward To..."), this);
162 ac
->setShortcutsConfigurable(mMailToForwardAction
, false);
163 ac
->addAction(QStringLiteral("mailto_forward"), mMailToForwardAction
);
164 connect(mMailToForwardAction
, &QAction::triggered
, this, &KMReaderWin::slotMailtoForward
);
166 // add to addressbook
167 mAddAddrBookAction
= new QAction(QIcon::fromTheme(QStringLiteral("contact-new")),
168 i18n("Add to Address Book"), this);
169 ac
->setShortcutsConfigurable(mAddAddrBookAction
, false);
170 ac
->addAction(QStringLiteral("add_addr_book"), mAddAddrBookAction
);
171 connect(mAddAddrBookAction
, &QAction::triggered
, this, &KMReaderWin::slotMailtoAddAddrBook
);
173 mAddEmailToExistingContactAction
= new QAction(QIcon::fromTheme(QStringLiteral("contact-new")),
174 i18n("Add to Existing Contact"), this);
175 ac
->setShortcutsConfigurable(mAddEmailToExistingContactAction
, false);
176 ac
->addAction(QStringLiteral("add_to_existing_contact"), mAddAddrBookAction
);
177 connect(mAddEmailToExistingContactAction
, &QAction::triggered
, this, &KMReaderWin::slotMailToAddToExistingContact
);
179 // open in addressbook
180 mOpenAddrBookAction
= new QAction(QIcon::fromTheme(QStringLiteral("view-pim-contacts")),
181 i18n("Open in Address Book"), this);
182 ac
->setShortcutsConfigurable(mOpenAddrBookAction
, false);
183 ac
->addAction(QStringLiteral("openin_addr_book"), mOpenAddrBookAction
);
184 connect(mOpenAddrBookAction
, &QAction::triggered
, this, &KMReaderWin::slotMailtoOpenAddrBook
);
186 mAddBookmarksAction
= new QAction(QIcon::fromTheme(QStringLiteral("bookmark-new")), i18n("Bookmark This Link"), this);
187 ac
->setShortcutsConfigurable(mAddBookmarksAction
, false);
188 ac
->addAction(QStringLiteral("add_bookmarks"), mAddBookmarksAction
);
189 connect(mAddBookmarksAction
, &QAction::triggered
, this, &KMReaderWin::slotAddBookmarks
);
191 mEditContactAction
= new QAction(QIcon::fromTheme(QStringLiteral("view-pim-contacts")),
192 i18n("Edit contact..."), this);
193 ac
->setShortcutsConfigurable(mEditContactAction
, false);
194 ac
->addAction(QStringLiteral("edit_contact"), mOpenAddrBookAction
);
195 connect(mEditContactAction
, &QAction::triggered
, this, &KMReaderWin::slotEditContact
);
198 mUrlSaveAsAction
= new QAction(i18n("Save Link As..."), this);
199 ac
->addAction(QStringLiteral("saveas_url"), mUrlSaveAsAction
);
200 ac
->setShortcutsConfigurable(mUrlSaveAsAction
, false);
201 connect(mUrlSaveAsAction
, &QAction::triggered
, this, &KMReaderWin::slotUrlSave
);
204 QAction
*action
= new QAction(QIcon::fromTheme(QStringLiteral("edit-find")), i18n("&Find in Message..."), this);
205 ac
->addAction(QStringLiteral("find_in_messages"), action
);
206 connect(action
, &QAction::triggered
, this, &KMReaderWin::slotFind
);
207 ac
->setDefaultShortcut(action
, KStandardShortcut::find().first());
209 // save Image On Disk
210 mImageUrlSaveAsAction
= new QAction(i18n("Save Image On Disk..."), this);
211 ac
->addAction(QStringLiteral("saveas_imageurl"), mImageUrlSaveAsAction
);
212 ac
->setShortcutsConfigurable(mImageUrlSaveAsAction
, false);
213 connect(mImageUrlSaveAsAction
, &QAction::triggered
, this, &KMReaderWin::slotSaveImageOnDisk
);
216 mViewHtmlOptions
= new QMenu(i18n("Show HTML Format"));
217 mViewAsHtml
= new QAction(i18n("Show HTML format when mail comes from this contact"), mViewHtmlOptions
);
218 ac
->setShortcutsConfigurable(mViewAsHtml
, false);
219 connect(mViewAsHtml
, &QAction::triggered
, this, &KMReaderWin::slotContactHtmlOptions
);
220 mViewAsHtml
->setCheckable(true);
221 mViewHtmlOptions
->addAction(mViewAsHtml
);
223 mLoadExternalReference
= new QAction(i18n("Load external reference when mail comes for this contact"), mViewHtmlOptions
);
224 ac
->setShortcutsConfigurable(mLoadExternalReference
, false);
225 connect(mLoadExternalReference
, &QAction::triggered
, this, &KMReaderWin::slotContactHtmlOptions
);
226 mLoadExternalReference
->setCheckable(true);
227 mViewHtmlOptions
->addAction(mLoadExternalReference
);
229 mShareImage
= new QAction(i18n("Share image..."), this);
230 ac
->addAction(QStringLiteral("share_imageurl"), mShareImage
);
231 ac
->setShortcutsConfigurable(mShareImage
, false);
232 connect(mShareImage
, &QAction::triggered
, this, &KMReaderWin::slotShareImage
);
236 void KMReaderWin::setUseFixedFont(bool useFixedFont
)
238 mViewer
->setUseFixedFont(useFixedFont
);
241 Viewer
*KMReaderWin::viewer()
246 bool KMReaderWin::isFixedFont() const
248 return mViewer
->isFixedFont();
251 KMReaderWin::~KMReaderWin()
255 void KMReaderWin::readConfig(void)
257 mViewer
->readConfig();
260 void KMReaderWin::setAttachmentStrategy(const MimeTreeParser::AttachmentStrategy
*strategy
)
262 mViewer
->setAttachmentStrategy(strategy
);
265 void KMReaderWin::setOverrideEncoding(const QString
&encoding
)
267 mViewer
->setOverrideEncoding(encoding
);
270 void KMReaderWin::clearCache()
275 // enter items for the "Important changes" list here:
276 static const char *const kmailChanges
[] = {
277 I18N_NOOP("KMail is now based on the Akonadi Personal Information Management framework, which brings many "
278 "changes all around.")
280 static const int numKMailChanges
=
281 sizeof kmailChanges
/ sizeof * kmailChanges
;
283 // enter items for the "new features" list here, so the main body of
284 // the welcome page can be left untouched (probably much easier for
285 // the translators). Note that the <li>...</li> tags are added
286 // automatically below:
287 static const char *const kmailNewFeatures
[] = {
288 I18N_NOOP("Push email (IMAP IDLE)"),
289 I18N_NOOP("Improved virtual folders"),
290 I18N_NOOP("Improved searches"),
291 I18N_NOOP("Support for adding notes (annotations) to mails"),
292 I18N_NOOP("Tag folders"),
293 I18N_NOOP("Less GUI freezes, mail checks happen in the background")
295 static const int numKMailNewFeatures
=
296 sizeof kmailNewFeatures
/ sizeof * kmailNewFeatures
;
299 QString
KMReaderWin::newFeaturesMD5()
302 for (int i
= 0; i
< numKMailChanges
; ++i
) {
303 str
+= kmailChanges
[i
];
305 for (int i
= 0; i
< numKMailNewFeatures
; ++i
) {
306 str
+= kmailNewFeatures
[i
];
308 QCryptographicHash
md5(QCryptographicHash::Md5
);
310 return QLatin1String(md5
.result().toBase64());
313 void KMReaderWin::displaySplashPage(const QString
&templateName
, const QVariantHash
&_data
)
315 QVariantHash data
= _data
;
316 if (!data
.contains(QStringLiteral("icon"))) {
317 data
[QStringLiteral("icon")] = QStringLiteral("kmail");
319 if (!data
.contains(QStringLiteral("name"))) {
320 data
[QStringLiteral("name")] = i18n("KMail");
322 if (!data
.contains(QStringLiteral("subtitle"))) {
323 data
[QStringLiteral("subtitle")] = i18n("The KDE Mail Client");
326 mViewer
->displaySplashPage(templateName
, data
);
329 void KMReaderWin::displayBusyPage()
331 displaySplashPage(QStringLiteral("status.html"), {
332 { QStringLiteral("title"), i18n("Retrieving Folder Contents") },
333 { QStringLiteral("subtext"), i18n("Please wait . . .") }
337 void KMReaderWin::displayOfflinePage()
339 displaySplashPage(QStringLiteral("status.html"), {
340 { QStringLiteral("title"), i18n("Offline") },
342 QStringLiteral("subtext"), i18n("KMail is currently in offline mode. "
343 "Click <a href=\"kmail:goOnline\">here</a> to go online . . .</p>")
348 void KMReaderWin::displayResourceOfflinePage()
350 displaySplashPage(QStringLiteral("status.html"), {
351 { QStringLiteral("title"), i18n("Offline") },
353 QStringLiteral("subtext"), i18n("Account is currently in offline mode. "
354 "Click <a href=\"kmail:goResourceOnline\">here</a> to go online . . .</p>")
359 void KMReaderWin::displayAboutPage()
362 data
[QStringLiteral("version")] = QStringLiteral(KDEPIM_VERSION
);
363 data
[QStringLiteral("firstStart")] = kmkernel
->firstStart();
365 QVariantList features
;
366 features
.reserve(numKMailNewFeatures
);
367 for (int i
= 0; i
< numKMailNewFeatures
; ++i
) {
368 features
.push_back(i18n(kmailNewFeatures
[i
]));
370 data
[QStringLiteral("newFeatures")] = features
;
372 QVariantList changes
;
373 changes
.reserve(numKMailChanges
);
374 for (int i
= 0; i
< numKMailChanges
; ++i
) {
375 features
.push_back(i18n(kmailChanges
[i
]));
377 data
[QStringLiteral("importantChanges")] = changes
;
379 displaySplashPage(QStringLiteral("introduction_kmail.html"), data
);
382 void KMReaderWin::slotFind()
387 void KMReaderWin::slotCopySelectedText()
389 QString selection
= mViewer
->selectedText();
390 selection
.replace(QChar::Nbsp
, QLatin1Char(' '));
391 QApplication::clipboard()->setText(selection
);
394 void KMReaderWin::setMsgPart(KMime::Content
*aMsgPart
)
396 mViewer
->setMessagePart(aMsgPart
);
399 QString
KMReaderWin::copyText() const
401 return mViewer
->selectedText();
404 MessageViewer::Viewer::DisplayFormatMessage
KMReaderWin::displayFormatMessageOverwrite() const
406 return mViewer
->displayFormatMessageOverwrite();
409 void KMReaderWin::setDisplayFormatMessageOverwrite(MessageViewer::Viewer::DisplayFormatMessage format
)
411 mViewer
->setDisplayFormatMessageOverwrite(format
);
414 void KMReaderWin::setHtmlLoadExtOverride(bool Q_DECL_OVERRIDE
)
416 mViewer
->setHtmlLoadExtOverride(Q_DECL_OVERRIDE
);
419 bool KMReaderWin::htmlMail() const
421 return mViewer
->htmlMail();
424 bool KMReaderWin::htmlLoadExternal()
426 return mViewer
->htmlLoadExternal();
429 Akonadi::Item
KMReaderWin::message() const
431 return mViewer
->messageItem();
434 QWidget
*KMReaderWin::mainWindow()
439 void KMReaderWin::slotMailtoCompose()
441 KMCommand
*command
= new KMMailtoComposeCommand(urlClicked(), message());
445 void KMReaderWin::slotMailtoForward()
447 KMCommand
*command
= new KMMailtoForwardCommand(mMainWindow
, urlClicked(),
452 void KMReaderWin::slotMailtoAddAddrBook()
454 const QUrl url
= urlClicked();
458 const QString emailString
= KEmailAddress::decodeMailtoUrl(url
);
460 KPIM::AddEmailAddressJob
*job
= new KPIM::AddEmailAddressJob(emailString
, mMainWindow
, this);
464 void KMReaderWin::slotMailToAddToExistingContact()
466 const QUrl url
= urlClicked();
470 const QString emailString
= KEmailAddress::decodeMailtoUrl(url
);
471 QPointer
<AddEmailToExistingContactDialog
> dlg
= new AddEmailToExistingContactDialog(this);
473 Akonadi::Item item
= dlg
->selectedContact();
474 if (item
.isValid()) {
475 AddEmailToExistingContactJob
*job
= new AddEmailToExistingContactJob(item
, emailString
, this);
482 void KMReaderWin::slotMailtoOpenAddrBook()
484 const QUrl url
= urlClicked();
488 const QString emailString
= KEmailAddress::decodeMailtoUrl(url
).toLower();
490 KPIM::OpenEmailAddressJob
*job
= new KPIM::OpenEmailAddressJob(emailString
, mMainWindow
, this);
494 void KMReaderWin::slotAddBookmarks()
496 const QUrl url
= urlClicked();
500 KMCommand
*command
= new KMAddBookmarksCommand(url
, this);
504 void KMReaderWin::slotUrlSave()
506 const QUrl url
= urlClicked();
510 KMCommand
*command
= new KMUrlSaveCommand(url
, mMainWindow
);
514 void KMReaderWin::slotSaveImageOnDisk()
516 const QUrl url
= imageUrlClicked();
520 KMCommand
*command
= new KMUrlSaveCommand(url
, mMainWindow
);
524 void KMReaderWin::slotMailtoReply()
526 KMCommand
*command
= new KMMailtoReplyCommand(mMainWindow
, urlClicked(),
527 message(), copyText());
531 CSSHelper
*KMReaderWin::cssHelper() const
533 return mViewer
->cssHelper();
536 bool KMReaderWin::htmlLoadExtOverride() const
538 return mViewer
->htmlLoadExtOverride();
540 void KMReaderWin::setDecryptMessageOverwrite(bool overwrite
)
542 mViewer
->setDecryptMessageOverwrite(overwrite
);
544 const MimeTreeParser::AttachmentStrategy
*KMReaderWin::attachmentStrategy() const
546 return mViewer
->attachmentStrategy();
549 QString
KMReaderWin::overrideEncoding() const
551 return mViewer
->overrideEncoding();
554 KToggleAction
*KMReaderWin::toggleFixFontAction() const
556 return mViewer
->toggleFixFontAction();
559 QAction
*KMReaderWin::mailToComposeAction() const
561 return mMailToComposeAction
;
564 QAction
*KMReaderWin::mailToReplyAction() const
566 return mMailToReplyAction
;
569 QAction
*KMReaderWin::mailToForwardAction() const
571 return mMailToForwardAction
;
574 QAction
*KMReaderWin::addAddrBookAction() const
576 return mAddAddrBookAction
;
579 QAction
*KMReaderWin::openAddrBookAction() const
581 return mOpenAddrBookAction
;
584 bool KMReaderWin::mimePartTreeIsEmpty() const
586 return mViewer
->mimePartTreeIsEmpty();
589 QAction
*KMReaderWin::toggleMimePartTreeAction() const
591 return mViewer
->toggleMimePartTreeAction();
594 KActionMenu
*KMReaderWin::shareServiceUrlMenu() const
596 return mViewer
->shareServiceUrlMenu();
599 QList
<QAction
*> KMReaderWin::viewerPluginActionList(ViewerPluginInterface::SpecificFeatureTypes features
)
601 return mViewer
->viewerPluginActionList(features
);
604 QAction
*KMReaderWin::selectAllAction() const
606 return mViewer
->selectAllAction();
609 QAction
*KMReaderWin::copyURLAction() const
611 return mViewer
->copyURLAction();
614 QAction
*KMReaderWin::copyImageLocation() const
616 return mViewer
->copyImageLocation();
619 QAction
*KMReaderWin::copyAction() const
621 return mViewer
->copyAction();
624 QAction
*KMReaderWin::viewSourceAction() const
626 return mViewer
->viewSourceAction();
629 QAction
*KMReaderWin::saveAsAction() const
631 return mViewer
->saveAsAction();
634 QAction
*KMReaderWin::findInMessageAction() const
636 return mViewer
->findInMessageAction();
639 QAction
*KMReaderWin::urlOpenAction() const
641 return mViewer
->urlOpenAction();
644 QAction
*KMReaderWin::urlSaveAsAction() const
646 return mUrlSaveAsAction
;
649 QAction
*KMReaderWin::addBookmarksAction() const
651 return mAddBookmarksAction
;
653 void KMReaderWin::setPrinting(bool enable
)
655 mViewer
->setPrinting(enable
);
658 QAction
*KMReaderWin::speakTextAction() const
660 return mViewer
->speakTextAction();
663 QAction
*KMReaderWin::downloadImageToDiskAction() const
665 return mImageUrlSaveAsAction
;
668 void KMReaderWin::clear(bool force
)
670 mViewer
->clear(force
? MimeTreeParser::Force
: MimeTreeParser::Delayed
);
673 void KMReaderWin::setMessage(const Akonadi::Item
&item
, MimeTreeParser::UpdateMode updateMode
)
675 qCDebug(KMAIL_LOG
) << Q_FUNC_INFO
<< parentWidget();
676 mViewer
->setMessageItem(item
, updateMode
);
679 void KMReaderWin::setMessage(const KMime::Message::Ptr
&message
)
681 mViewer
->setMessage(message
);
684 QUrl
KMReaderWin::urlClicked() const
686 return mViewer
->urlClicked();
689 QUrl
KMReaderWin::imageUrlClicked() const
691 return mViewer
->imageUrlClicked();
694 void KMReaderWin::update(bool force
)
696 mViewer
->update(force
? MimeTreeParser::Force
: MimeTreeParser::Delayed
);
699 void KMReaderWin::slotUrlClicked(const Akonadi::Item
&item
, const QUrl
&url
)
701 if (item
.isValid() && item
.parentCollection().isValid()) {
702 QSharedPointer
<FolderCollection
> fd
= FolderCollection::forCollection(
703 MailCommon::Util::updatedCollection(item
.parentCollection()), false);
704 KMail::Util::handleClickedURL(url
, fd
);
707 //No folder so we can't have identity and template.
708 KMail::Util::handleClickedURL(url
);
711 void KMReaderWin::slotShowReader(KMime::Content
*msgPart
, bool html
, const QString
&encoding
)
713 const MessageViewer::Viewer::DisplayFormatMessage format
= html
? MessageViewer::Viewer::Html
: MessageViewer::Viewer::Text
;
714 KMReaderMainWin
*win
= new KMReaderMainWin(msgPart
, format
, encoding
);
718 void KMReaderWin::slotShowMessage(const KMime::Message::Ptr
&message
, const QString
&encoding
)
720 KMReaderMainWin
*win
= new KMReaderMainWin();
721 win
->showMessage(encoding
, message
);
725 void KMReaderWin::slotDeleteMessage(const Akonadi::Item
&item
)
727 if (!item
.isValid()) {
730 KMTrashMsgCommand
*command
= new KMTrashMsgCommand(item
.parentCollection(), item
, -1);
734 bool KMReaderWin::printSelectedText(bool preview
)
736 const QString str
= mViewer
->selectedText();
740 ::MessageComposer::Composer
*composer
= new ::MessageComposer::Composer
;
741 composer
->textPart()->setCleanPlainText(str
);
742 composer
->textPart()->setWrappedPlainText(str
);
743 KMime::Message::Ptr messagePtr
= message().payload
<KMime::Message::Ptr
>();
744 composer
->infoPart()->setFrom(messagePtr
->from()->asUnicodeString());
745 composer
->infoPart()->setTo(QStringList() << messagePtr
->to()->asUnicodeString());
746 composer
->infoPart()->setCc(QStringList() << messagePtr
->cc()->asUnicodeString());
747 composer
->infoPart()->setSubject(messagePtr
->subject()->asUnicodeString());
748 composer
->setProperty("preview", preview
);
749 connect(composer
, &::MessageComposer::Composer::result
, this, &KMReaderWin::slotPrintComposeResult
);
754 void KMReaderWin::slotPrintComposeResult(KJob
*job
)
756 const bool preview
= job
->property("preview").toBool();
757 ::MessageComposer::Composer
*composer
= dynamic_cast< ::MessageComposer::Composer
* >(job
);
759 if (composer
->error() == ::MessageComposer::Composer::NoError
) {
761 Q_ASSERT(composer
->resultMessages().size() == 1);
762 Akonadi::Item printItem
;
763 printItem
.setPayload
<KMime::Message::Ptr
>(composer
->resultMessages().first());
764 Akonadi::MessageFlags::copyMessageFlags(*(composer
->resultMessages().first()), printItem
);
765 const bool useFixedFont
= MessageViewer::MessageViewerSettings::self()->useFixedFont();
766 const QString overrideEncoding
= MessageCore::MessageCoreSettings::self()->overrideCharacterEncoding();
768 KMPrintCommand
*command
= new KMPrintCommand(this, printItem
, mViewer
->headerStylePlugin(),
769 mViewer
->displayFormatMessageOverwrite(), mViewer
->htmlLoadExternal(), useFixedFont
, overrideEncoding
);
770 command
->setPrintPreview(preview
);
773 if (static_cast<KIO::Job
*>(job
)->ui()) {
774 static_cast<KIO::Job
*>(job
)->ui()->showErrorMessage();
776 qCWarning(KMAIL_LOG
) << "Composer for printing failed:" << composer
->errorString();
781 void KMReaderWin::clearContactItem()
783 mSearchedContact
= Akonadi::Item();
784 mSearchedAddress
= KContacts::Addressee();
785 mLoadExternalReference
->setChecked(false);
786 mViewAsHtml
->setChecked(false);
789 void KMReaderWin::setContactItem(const Akonadi::Item
&contact
, const KContacts::Addressee
&address
)
791 mSearchedContact
= contact
;
792 mSearchedAddress
= address
;
796 void KMReaderWin::updateHtmlActions()
798 if (!mSearchedContact
.isValid()) {
799 mLoadExternalReference
->setChecked(false);
800 mViewAsHtml
->setChecked(false);
802 const QStringList customs
= mSearchedAddress
.customs();
803 Q_FOREACH (const QString
&custom
, customs
) {
804 if (custom
.contains(QStringLiteral("MailPreferedFormatting"))) {
805 const QString value
= mSearchedAddress
.custom(QStringLiteral("KADDRESSBOOK"), QStringLiteral("MailPreferedFormatting"));
806 mViewAsHtml
->setChecked(value
== QLatin1String("HTML"));
807 } else if (custom
.contains(QStringLiteral("MailAllowToRemoteContent"))) {
808 const QString value
= mSearchedAddress
.custom(QStringLiteral("KADDRESSBOOK"), QStringLiteral("MailAllowToRemoteContent"));
809 mLoadExternalReference
->setChecked((value
== QLatin1String("TRUE")));
815 void KMReaderWin::slotContactHtmlOptions()
817 const QUrl url
= urlClicked();
821 const QString emailString
= KEmailAddress::decodeMailtoUrl(url
).toLower();
823 KPIM::AddEmailDiplayJob
*job
= new KPIM::AddEmailDiplayJob(emailString
, mMainWindow
, this);
824 job
->setRemoteContent(mLoadExternalReference
->isChecked());
825 job
->setShowAsHTML(mViewAsHtml
->isChecked());
826 job
->setContact(mSearchedContact
);
830 void KMReaderWin::slotEditContact()
832 if (mSearchedContact
.isValid()) {
833 QPointer
<Akonadi::ContactEditorDialog
> dlg
=
834 new Akonadi::ContactEditorDialog(Akonadi::ContactEditorDialog::EditMode
, this);
835 connect(dlg
.data(), &Akonadi::ContactEditorDialog::contactStored
, this, &KMReaderWin::contactStored
);
836 connect(dlg
.data(), &Akonadi::ContactEditorDialog::error
, this, &KMReaderWin::slotContactEditorError
);
837 dlg
->setContact(mSearchedContact
);
843 void KMReaderWin::slotContactEditorError(const QString
&error
)
845 KMessageBox::error(this, i18n("Contact cannot be stored: %1", error
), i18n("Failed to store contact"));
848 void KMReaderWin::contactStored(const Akonadi::Item
&item
)
851 KPIM::BroadcastStatus::instance()->setStatusMsg(i18n("Contact modified successfully"));
854 QAction
*KMReaderWin::saveMessageDisplayFormatAction() const
856 return mViewer
->saveMessageDisplayFormatAction();
859 QAction
*KMReaderWin::resetMessageDisplayFormatAction() const
861 return mViewer
->resetMessageDisplayFormatAction();
864 QAction
*KMReaderWin::blockImage() const
866 return mViewer
->blockImage();
869 bool KMReaderWin::adblockEnabled() const
871 return mViewer
->adblockEnabled();
874 QAction
*KMReaderWin::openBlockableItems() const
876 return mViewer
->openBlockableItems();
879 QAction
*KMReaderWin::editContactAction() const
881 return mEditContactAction
;
884 QMenu
*KMReaderWin::viewHtmlOption() const
886 return mViewHtmlOptions
;
889 QAction
*KMReaderWin::shareImage() const
894 QAction
*KMReaderWin::addToExistingContactAction() const
896 return mAddEmailToExistingContactAction
;
899 void KMReaderWin::slotShareImage()
901 KMCommand
*command
= new KMShareImageCommand(imageUrlClicked(), this);
905 #ifdef MESSAGEVIEWER_USE_QTWEBENGINE
906 QList
<QAction
*> KMReaderWin::interceptorUrlActions(const MessageViewer::WebHitTestResult
&result
) const
908 return mViewer
->interceptorUrlActions(result
);