SVN_SILENT made messages (after extraction)
[kdepim.git] / kmail / kmreadermainwin.cpp
blob507684760610080336c7c583a34560179bd8e583
1 /*
2 This file is part of KMail, the KDE mail client.
3 Copyright (c) 2002 Don Sanders <sanders@kde.org>
4 Copyright (c) 2011-2016 Montel Laurent <montel@kde.org>
6 KMail is free software; you can redistribute it and/or modify it
7 under the terms of the GNU General Public License, version 2, as
8 published by the Free Software Foundation.
10 KMail is distributed in the hope that it will be useful, but
11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software
17 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20 // A toplevel KMainWindow derived class for displaying
21 // single messages or single message parts.
23 // Could be extended to include support for normal main window
24 // widgets like a toolbar.
26 #include "kmreadermainwin.h"
27 #include "kmreaderwin.h"
29 #include <kactionmenu.h>
30 #include <kedittoolbar.h>
31 #include <KLocalizedString>
32 #include <kstandardshortcut.h>
33 #include <kwindowsystem.h>
34 #include <QAction>
35 #include <kfontaction.h>
36 #include <kstandardaction.h>
37 #include <ktoggleaction.h>
38 #include <ktoolbar.h>
39 #include "kmail_debug.h"
40 #include <KFontAction>
41 #include <KFontSizeAction>
42 #include <QStatusBar>
43 #include <KMessageBox>
44 #include <KAcceleratorManager>
45 #include "kmcommands.h"
46 #include <QMenuBar>
47 #include <qmenu.h>
48 #include "kmmainwidget.h"
49 #include "MessageViewer/CSSHelper"
50 #include <TemplateParser/CustomTemplatesMenu>
51 #include "messageactions.h"
52 #include "util.h"
53 #include "mailcommon/mailkernel.h"
54 #include "MailCommon/FolderCollection"
55 #include "messageviewer/headerstyleplugin.h"
56 #include "messageviewer/headerstyle.h"
58 #include <KActionCollection>
59 #include <Akonadi/Contact/ContactSearchJob>
60 #include <KEmailAddress>
61 #ifdef QTWEBENGINE_SUPPORT_OPTION
62 #include <WebEngineViewer/WebHitTestResult>
63 #endif
64 #include <kmime/kmime_message.h>
66 #include <messageviewer/viewer.h>
67 #include <AkonadiCore/item.h>
68 #include <AkonadiCore/itemcopyjob.h>
69 #include <AkonadiCore/itemcreatejob.h>
70 #include <AkonadiCore/itemmovejob.h>
71 #include <Akonadi/KMime/MessageFlags>
72 #include "kpimtextedit/texttospeech.h"
73 #include "messagecore/messagehelpers.h"
74 #include <mailcommon/mailutil.h>
76 using namespace MailCommon;
78 KMReaderMainWin::KMReaderMainWin(MessageViewer::Viewer::DisplayFormatMessage format, bool htmlLoadExtOverride,
79 char *name)
80 : KMail::SecondaryWindow(name ? name : "readerwindow#")
82 mReaderWin = new KMReaderWin(this, this, actionCollection());
83 //mReaderWin->setShowCompleteMessage( true );
84 mReaderWin->setDisplayFormatMessageOverwrite(format);
85 mReaderWin->setHtmlLoadExtOverride(htmlLoadExtOverride);
86 mReaderWin->setDecryptMessageOverwrite(true);
87 initKMReaderMainWin();
90 KMReaderMainWin::KMReaderMainWin(char *name)
91 : KMail::SecondaryWindow(name ? name : "readerwindow#")
93 mReaderWin = new KMReaderWin(this, this, actionCollection());
94 initKMReaderMainWin();
97 KMReaderMainWin::KMReaderMainWin(KMime::Content *aMsgPart, MessageViewer::Viewer::DisplayFormatMessage format, const QString &encoding, char *name)
98 : KMail::SecondaryWindow(name ? name : "readerwindow#")
100 mReaderWin = new KMReaderWin(this, this, actionCollection());
101 mReaderWin->setOverrideEncoding(encoding);
102 mReaderWin->setDisplayFormatMessageOverwrite(format);
103 mReaderWin->setMsgPart(aMsgPart);
104 initKMReaderMainWin();
107 void KMReaderMainWin::initKMReaderMainWin()
109 setCentralWidget(mReaderWin);
110 setupAccel();
111 setupGUI(Keys | StatusBar | Create, QStringLiteral("kmreadermainwin.rc"));
112 mMsgActions->setupForwardingActionsList(this);
113 applyMainWindowSettings(KMKernel::self()->config()->group("Separate Reader Window"));
114 if (! mReaderWin->message().isValid()) {
115 menuBar()->hide();
116 toolBar(QStringLiteral("mainToolBar"))->hide();
118 connect(kmkernel, &KMKernel::configChanged, this, &KMReaderMainWin::slotConfigChanged);
119 connect(mReaderWin, SIGNAL(showStatusBarMessage(QString)), statusBar(), SLOT(showMessage(QString)));
122 KMReaderMainWin::~KMReaderMainWin()
124 KConfigGroup grp(KMKernel::self()->config()->group("Separate Reader Window"));
125 saveMainWindowSettings(grp);
128 void KMReaderMainWin::setUseFixedFont(bool useFixedFont)
130 mReaderWin->setUseFixedFont(useFixedFont);
133 void KMReaderMainWin::showMessage(const QString &encoding, const Akonadi::Item &msg, const Akonadi::Collection &parentCollection)
136 mParentCollection = parentCollection;
137 mReaderWin->setOverrideEncoding(encoding);
138 mReaderWin->setMessage(msg, MimeTreeParser::Force);
139 KMime::Message::Ptr message = MessageCore::Util::message(msg);
140 QString caption;
141 if (message) {
142 caption = message->subject()->asUnicodeString();
144 if (mParentCollection.isValid()) {
145 caption += QLatin1String(" - ");
146 caption += MailCommon::Util::fullCollectionPath(mParentCollection);
148 if (!caption.isEmpty()) {
149 setCaption(caption);
151 mMsg = msg;
152 mMsgActions->setCurrentMessage(msg);
154 const bool canChange = mParentCollection.isValid() ? (bool)(mParentCollection.rights() & Akonadi::Collection::CanDeleteItem) : false;
155 mTrashAction->setEnabled(canChange);
157 mReaderWin->viewer()->headerStylePlugin()->headerStyle()->setReadOnlyMessage(!canChange);
159 menuBar()->show();
160 toolBar(QStringLiteral("mainToolBar"))->show();
163 void KMReaderMainWin::showMessage(const QString &encoding, const KMime::Message::Ptr &message)
165 if (!message) {
166 return;
169 Akonadi::Item item;
171 item.setPayload<KMime::Message::Ptr>(message);
172 Akonadi::MessageFlags::copyMessageFlags(*message, item);
173 item.setMimeType(KMime::Message::mimeType());
175 mMsg = item;
176 mMsgActions->setCurrentMessage(item);
178 mReaderWin->setOverrideEncoding(encoding);
179 mReaderWin->setMessage(message);
180 setCaption(message->subject()->asUnicodeString());
182 mTrashAction->setEnabled(false);
184 menuBar()->show();
185 toolBar(QStringLiteral("mainToolBar"))->show();
188 void KMReaderMainWin::slotReplyOrForwardFinished()
190 if (KMailSettings::self()->closeAfterReplyOrForward()) {
191 close();
195 Akonadi::Collection KMReaderMainWin::parentCollection() const
197 if (mParentCollection.isValid()) {
198 return mParentCollection;
199 } else {
200 return mMsg.parentCollection();
204 void KMReaderMainWin::slotExecuteMailAction(MessageViewer::Viewer::MailAction action)
206 switch (action) {
207 case MessageViewer::Viewer::Trash:
208 slotTrashMessage();
209 break;
210 case MessageViewer::Viewer::Reply:
211 slotCustomReplyToMsg(QString());
212 break;
213 case MessageViewer::Viewer::ReplyToAll:
214 break;
215 case MessageViewer::Viewer::Forward:
216 slotRedirectMessage();
217 break;
218 case MessageViewer::Viewer::NewMessage:
219 break;
220 case MessageViewer::Viewer::Print:
221 break;
222 case MessageViewer::Viewer::PrintPreview:
223 break;
227 void KMReaderMainWin::slotTrashMessage()
229 if (!mMsg.isValid()) {
230 return;
232 KMTrashMsgCommand *command = new KMTrashMsgCommand(parentCollection(), mMsg, -1);
233 command->start();
234 close();
237 void KMReaderMainWin::slotForwardInlineMsg()
239 if (!mReaderWin->message().hasPayload<KMime::Message::Ptr>()) {
240 return;
242 KMCommand *command = Q_NULLPTR;
243 const Akonadi::Collection parentCol = mReaderWin->message().parentCollection();
244 if (parentCol.isValid()) {
245 QSharedPointer<FolderCollection> fd = FolderCollection::forCollection(parentCol, false);
246 if (fd)
247 command = new KMForwardCommand(this, mReaderWin->message(),
248 fd->identity());
249 else {
250 command = new KMForwardCommand(this, mReaderWin->message());
252 } else {
253 command = new KMForwardCommand(this, mReaderWin->message());
255 connect(command, &KMTrashMsgCommand::completed, this, &KMReaderMainWin::slotReplyOrForwardFinished);
256 command->start();
259 void KMReaderMainWin::slotForwardAttachedMessage()
261 if (!mReaderWin->message().hasPayload<KMime::Message::Ptr>()) {
262 return;
264 KMCommand *command = Q_NULLPTR;
265 const Akonadi::Collection parentCol = mReaderWin->message().parentCollection();
266 if (parentCol.isValid()) {
267 QSharedPointer<FolderCollection> fd = FolderCollection::forCollection(parentCol, false);
268 if (fd)
269 command = new KMForwardAttachedCommand(this, mReaderWin->message(),
270 fd->identity());
271 else {
272 command = new KMForwardAttachedCommand(this, mReaderWin->message());
274 } else {
275 command = new KMForwardAttachedCommand(this, mReaderWin->message());
278 connect(command, &KMTrashMsgCommand::completed, this, &KMReaderMainWin::slotReplyOrForwardFinished);
279 command->start();
282 void KMReaderMainWin::slotRedirectMessage()
284 const Akonadi::Item currentItem = mReaderWin->message();
285 if (!currentItem.hasPayload<KMime::Message::Ptr>()) {
286 return;
288 KMCommand *command = new KMRedirectCommand(this, currentItem);
289 connect(command, &KMTrashMsgCommand::completed, this, &KMReaderMainWin::slotReplyOrForwardFinished);
290 command->start();
293 void KMReaderMainWin::slotCustomReplyToMsg(const QString &tmpl)
295 const Akonadi::Item currentItem = mReaderWin->message();
296 if (!currentItem.hasPayload<KMime::Message::Ptr>()) {
297 return;
299 KMCommand *command = new KMReplyCommand(this,
300 currentItem,
301 MessageComposer::ReplySmart,
302 mReaderWin->copyText(),
303 false, tmpl);
304 connect(command, &KMTrashMsgCommand::completed, this, &KMReaderMainWin::slotReplyOrForwardFinished);
305 command->start();
308 void KMReaderMainWin::slotCustomReplyAllToMsg(const QString &tmpl)
310 const Akonadi::Item currentItem = mReaderWin->message();
311 if (!currentItem.hasPayload<KMime::Message::Ptr>()) {
312 return;
314 KMCommand *command = new KMReplyCommand(this,
315 currentItem,
316 MessageComposer::ReplyAll,
317 mReaderWin->copyText(),
318 false, tmpl);
319 connect(command, &KMTrashMsgCommand::completed, this, &KMReaderMainWin::slotReplyOrForwardFinished);
321 command->start();
324 void KMReaderMainWin::slotCustomForwardMsg(const QString &tmpl)
326 const Akonadi::Item currentItem = mReaderWin->message();
327 if (!currentItem.hasPayload<KMime::Message::Ptr>()) {
328 return;
330 KMCommand *command = new KMForwardCommand(this,
331 currentItem,
332 0, tmpl);
333 connect(command, &KMTrashMsgCommand::completed, this, &KMReaderMainWin::slotReplyOrForwardFinished);
335 command->start();
338 void KMReaderMainWin::slotConfigChanged()
340 //readConfig();
341 mMsgActions->setupForwardActions(actionCollection());
342 mMsgActions->setupForwardingActionsList(this);
345 void KMReaderMainWin::setupAccel()
347 if (!kmkernel->xmlGuiInstanceName().isEmpty()) {
348 setComponentName(kmkernel->xmlGuiInstanceName(), i18n("kmail2"));
350 mMsgActions = new KMail::MessageActions(actionCollection(), this);
351 mMsgActions->setMessageView(mReaderWin);
352 connect(mMsgActions, &KMail::MessageActions::replyActionFinished, this, &KMReaderMainWin::slotReplyOrForwardFinished);
354 //----- File Menu
356 mSaveAtmAction = new QAction(QIcon::fromTheme(QStringLiteral("mail-attachment")), i18n("Save A&ttachments..."), actionCollection());
357 connect(mSaveAtmAction, &QAction::triggered, mReaderWin->viewer(), &MessageViewer::Viewer::slotAttachmentSaveAll);
359 mTrashAction = new QAction(QIcon::fromTheme(QStringLiteral("user-trash")), i18n("&Move to Trash"), this);
360 mTrashAction->setIconText(i18nc("@action:intoolbar Move to Trash", "Trash"));
361 KMail::Util::addQActionHelpText(mTrashAction, i18n("Move message to trashcan"));
362 actionCollection()->addAction(QStringLiteral("move_to_trash"), mTrashAction);
363 actionCollection()->setDefaultShortcut(mTrashAction, QKeySequence(Qt::Key_Delete));
364 connect(mTrashAction, &QAction::triggered, this, &KMReaderMainWin::slotTrashMessage);
366 QAction *closeAction = KStandardAction::close(this, SLOT(close()), actionCollection());
367 QList<QKeySequence> closeShortcut = closeAction->shortcuts();
368 closeAction->setShortcuts(closeShortcut << QKeySequence(Qt::Key_Escape));
370 //----- Message Menu
371 #ifdef QTWEBENGINE_SUPPORT_OPTION
372 connect(mReaderWin->viewer(), &MessageViewer::Viewer::displayPopupMenu, this, &KMReaderMainWin::slotMessagePopup);
373 #else
374 connect(mReaderWin->viewer(), &MessageViewer::Viewer::popupMenu, this, &KMReaderMainWin::slotMessagePopup);
375 #endif
377 connect(mReaderWin->viewer(), &MessageViewer::Viewer::itemRemoved, this, &QWidget::close);
379 setStandardToolBarMenuEnabled(true);
380 KStandardAction::configureToolbars(this, SLOT(slotEditToolbars()), actionCollection());
381 connect(mReaderWin->viewer(), &MessageViewer::Viewer::moveMessageToTrash, this, &KMReaderMainWin::slotTrashMessage);
382 connect(mReaderWin->viewer(), &MessageViewer::Viewer::executeMailAction, this, &KMReaderMainWin::slotExecuteMailAction);
385 QAction *KMReaderMainWin::copyActionMenu(QMenu *menu)
387 KMMainWidget *mainwin = kmkernel->getKMMainWidget();
388 if (mainwin) {
389 KActionMenu *action = new KActionMenu(menu);
390 action->setIcon(QIcon::fromTheme(QStringLiteral("edit-copy")));
391 action->setText(i18n("Copy Message To..."));
392 mainwin->standardMailActionManager()->standardActionManager()->createActionFolderMenu(action->menu(), Akonadi::StandardActionManager::CopyItemToMenu);
393 connect(action->menu(), &QMenu::triggered, this, &KMReaderMainWin::slotCopyItem);
394 return action;
396 return Q_NULLPTR;
399 QAction *KMReaderMainWin::moveActionMenu(QMenu *menu)
401 KMMainWidget *mainwin = kmkernel->getKMMainWidget();
402 if (mainwin) {
403 KActionMenu *action = new KActionMenu(menu);
404 action->setText(i18n("Move Message To..."));
405 mainwin->standardMailActionManager()->standardActionManager()->createActionFolderMenu(action->menu(), Akonadi::StandardActionManager::MoveItemToMenu);
406 connect(action->menu(), &QMenu::triggered, this, &KMReaderMainWin::slotMoveItem);
408 return action;
410 return Q_NULLPTR;
414 void KMReaderMainWin::slotMoveItem(QAction *action)
416 if (action) {
417 const QModelIndex index = action->data().value<QModelIndex>();
418 const Akonadi::Collection collection = index.data(Akonadi::EntityTreeModel::CollectionRole).value<Akonadi::Collection>();
419 copyOrMoveItem(collection, true);
423 void KMReaderMainWin::copyOrMoveItem(const Akonadi::Collection &collection, bool move)
425 if (mMsg.isValid()) {
426 if (move) {
427 Akonadi::ItemMoveJob *job = new Akonadi::ItemMoveJob(mMsg, collection, this);
428 connect(job, &KJob::result, this, &KMReaderMainWin::slotCopyMoveResult);
429 } else {
430 Akonadi::ItemCopyJob *job = new Akonadi::ItemCopyJob(mMsg, collection, this);
431 connect(job, &KJob::result, this, &KMReaderMainWin::slotCopyMoveResult);
433 } else {
434 Akonadi::ItemCreateJob *job = new Akonadi::ItemCreateJob(mMsg, collection, this);
435 connect(job, &KJob::result, this, &KMReaderMainWin::slotCopyMoveResult);
439 void KMReaderMainWin::slotCopyItem(QAction *action)
441 if (action) {
442 const QModelIndex index = action->data().value<QModelIndex>();
443 const Akonadi::Collection collection = index.data(Akonadi::EntityTreeModel::CollectionRole).value<Akonadi::Collection>();
444 copyOrMoveItem(collection, false);
448 void KMReaderMainWin::slotCopyMoveResult(KJob *job)
450 if (job->error()) {
451 KMessageBox::sorry(this, i18n("Cannot copy item. %1", job->errorString()));
455 #ifdef QTWEBENGINE_SUPPORT_OPTION
456 void KMReaderMainWin::slotMessagePopup(const Akonadi::Item &aMsg, const WebEngineViewer::WebHitTestResult &result, const QPoint &aPoint)
457 #else
458 void KMReaderMainWin::slotMessagePopup(const Akonadi::Item &aMsg, const QUrl &aUrl, const QUrl &imageUrl, const QPoint &aPoint)
459 #endif
461 #ifdef QTWEBENGINE_SUPPORT_OPTION
462 QUrl aUrl = result.linkUrl();
463 QUrl imageUrl = result.imageUrl();
464 #endif
465 mMsg = aMsg;
467 const QString email = KEmailAddress::firstEmailAddress(aUrl.path()).toLower();
468 if (aUrl.scheme() == QLatin1String("mailto") && !email.isEmpty()) {
469 Akonadi::ContactSearchJob *job = new Akonadi::ContactSearchJob(this);
470 job->setLimit(1);
471 job->setQuery(Akonadi::ContactSearchJob::Email, email, Akonadi::ContactSearchJob::ExactMatch);
472 job->setProperty("msg", QVariant::fromValue(mMsg));
473 job->setProperty("point", aPoint);
474 job->setProperty("imageUrl", imageUrl);
475 job->setProperty("url", aUrl);
476 connect(job, &Akonadi::ItemCopyJob::result, this, &KMReaderMainWin::slotContactSearchJobForMessagePopupDone);
477 } else {
478 showMessagePopup(mMsg, aUrl, imageUrl, aPoint, false, false);
482 void KMReaderMainWin::slotContactSearchJobForMessagePopupDone(KJob *job)
484 const Akonadi::ContactSearchJob *searchJob = qobject_cast<Akonadi::ContactSearchJob *>(job);
485 const bool contactAlreadyExists = !searchJob->contacts().isEmpty();
487 const Akonadi::Item::List listContact = searchJob->items();
488 const bool uniqueContactFound = (listContact.count() == 1);
489 if (uniqueContactFound) {
490 mReaderWin->setContactItem(listContact.first(), searchJob->contacts().at(0));
491 } else {
492 mReaderWin->clearContactItem();
495 const Akonadi::Item msg = job->property("msg").value<Akonadi::Item>();
496 const QPoint aPoint = job->property("point").toPoint();
497 const QUrl imageUrl = job->property("imageUrl").toUrl();
498 const QUrl url = job->property("url").toUrl();
500 showMessagePopup(msg, url, imageUrl, aPoint, contactAlreadyExists, uniqueContactFound);
503 void KMReaderMainWin::showMessagePopup(const Akonadi::Item &msg, const QUrl &url, const QUrl &imageUrl, const QPoint &aPoint, bool contactAlreadyExists, bool uniqueContactFound)
505 QMenu *menu = Q_NULLPTR;
507 bool urlMenuAdded = false;
508 bool copyAdded = false;
509 const bool messageHasPayload = msg.hasPayload<KMime::Message::Ptr>();
510 if (!url.isEmpty()) {
511 if (url.scheme() == QLatin1String("mailto")) {
512 // popup on a mailto URL
513 menu = new QMenu;
514 menu->addAction(mReaderWin->mailToComposeAction());
515 if (messageHasPayload) {
516 menu->addAction(mReaderWin->mailToReplyAction());
517 menu->addAction(mReaderWin->mailToForwardAction());
518 menu->addSeparator();
521 if (contactAlreadyExists) {
522 if (uniqueContactFound) {
523 menu->addAction(mReaderWin->editContactAction());
524 } else {
525 menu->addAction(mReaderWin->openAddrBookAction());
527 } else {
528 menu->addAction(mReaderWin->addAddrBookAction());
529 menu->addAction(mReaderWin->addToExistingContactAction());
531 menu->addSeparator();
532 menu->addMenu(mReaderWin->viewHtmlOption());
533 menu->addSeparator();
534 menu->addAction(mReaderWin->copyURLAction());
535 copyAdded = true;
536 urlMenuAdded = true;
537 } else if (url.scheme() != QLatin1String("attachment")) {
538 // popup on a not-mailto URL
539 menu = new QMenu;
540 menu->addAction(mReaderWin->urlOpenAction());
541 menu->addAction(mReaderWin->addBookmarksAction());
542 menu->addAction(mReaderWin->urlSaveAsAction());
543 menu->addAction(mReaderWin->copyURLAction());
544 menu->addSeparator();
545 menu->addAction(mReaderWin->shareServiceUrlMenu());
546 menu->addSeparator();
547 menu->addActions(mReaderWin->viewerPluginActionList(MessageViewer::ViewerPluginInterface::NeedUrl));
548 if (!imageUrl.isEmpty()) {
549 menu->addSeparator();
550 menu->addAction(mReaderWin->copyImageLocation());
551 menu->addAction(mReaderWin->downloadImageToDiskAction());
552 menu->addAction(mReaderWin->shareImage());
553 if (mReaderWin->adblockEnabled()) {
554 menu->addSeparator();
555 menu->addAction(mReaderWin->blockImage());
558 urlMenuAdded = true;
561 const QString selectedText(mReaderWin->copyText());
562 if (!selectedText.isEmpty()) {
563 if (!menu) {
564 menu = new QMenu;
566 if (urlMenuAdded) {
567 menu->addSeparator();
569 if (messageHasPayload) {
570 menu->addAction(mMsgActions->replyMenu());
571 menu->addSeparator();
572 menu->addAction(mMsgActions->mailingListActionMenu());
573 menu->addSeparator();
575 if (!copyAdded) {
576 menu->addAction(mReaderWin->copyAction());
578 menu->addAction(mReaderWin->selectAllAction());
579 menu->addSeparator();
580 mMsgActions->addWebShortcutsMenu(menu, selectedText);
581 menu->addSeparator();
582 menu->addActions(mReaderWin->viewerPluginActionList(MessageViewer::ViewerPluginInterface::NeedSelection));
583 if (KPIMTextEdit::TextToSpeech::self()->isReady()) {
584 menu->addSeparator();
585 menu->addAction(mReaderWin->speakTextAction());
587 } else if (!urlMenuAdded) {
588 if (!menu) {
589 menu = new QMenu;
592 // popup somewhere else (i.e., not a URL) on the message
593 if (messageHasPayload) {
594 bool replyForwardMenu = false;
595 Akonadi::Collection col = parentCollection();
596 if (col.isValid()) {
597 if (!(CommonKernel->folderIsSentMailFolder(col) ||
598 CommonKernel->folderIsDrafts(col) ||
599 CommonKernel->folderIsTemplates(col))) {
600 replyForwardMenu = true;
602 } else if (messageHasPayload) {
603 replyForwardMenu = true;
605 if (replyForwardMenu) {
606 // add the reply and forward actions only if we are not in a sent-mail,
607 // templates or drafts folder
608 menu->addAction(mMsgActions->replyMenu());
609 menu->addAction(mMsgActions->forwardMenu());
610 menu->addSeparator();
612 menu->addAction(copyActionMenu(menu));
613 menu->addAction(moveActionMenu(menu));
614 menu->addSeparator();
615 menu->addAction(mMsgActions->mailingListActionMenu());
617 menu->addSeparator();
618 if (!imageUrl.isEmpty()) {
619 menu->addSeparator();
620 menu->addAction(mReaderWin->copyImageLocation());
621 menu->addAction(mReaderWin->downloadImageToDiskAction());
622 menu->addAction(mReaderWin->shareImage());
623 menu->addSeparator();
624 if (mReaderWin->adblockEnabled()) {
625 menu->addAction(mReaderWin->blockImage());
626 menu->addSeparator();
630 menu->addAction(mReaderWin->viewSourceAction());
631 menu->addAction(mReaderWin->toggleFixFontAction());
632 if (!mReaderWin->mimePartTreeIsEmpty()) {
633 menu->addAction(mReaderWin->toggleMimePartTreeAction());
635 menu->addSeparator();
637 #ifdef QTWEBENGINE_SUPPORT_OPTION
638 #if QT_VERSION >= QT_VERSION_CHECK(5, 7, 0)
639 menu->addAction(mMsgActions->printPreviewAction());
640 menu->addAction(mMsgActions->printAction());
641 #endif
642 #else
643 menu->addAction(mMsgActions->printPreviewAction());
644 menu->addAction(mMsgActions->printAction());
645 #endif
646 menu->addAction(mReaderWin->saveAsAction());
647 menu->addAction(mSaveAtmAction);
648 if (msg.isValid()) {
649 menu->addSeparator();
650 menu->addActions(mReaderWin->viewerPluginActionList(MessageViewer::ViewerPluginInterface::NeedMessage));
651 menu->addSeparator();
652 menu->addAction(mReaderWin->saveMessageDisplayFormatAction());
653 menu->addAction(mReaderWin->resetMessageDisplayFormatAction());
655 } else {
656 menu->addAction(mReaderWin->toggleFixFontAction());
657 if (!mReaderWin->mimePartTreeIsEmpty()) {
658 menu->addAction(mReaderWin->toggleMimePartTreeAction());
661 if (mReaderWin->adblockEnabled()) {
662 menu->addSeparator();
663 menu->addAction(mReaderWin->openBlockableItems());
665 if (msg.isValid()) {
666 menu->addAction(mMsgActions->addFollowupReminderAction());
668 if (msg.isValid()) {
669 menu->addSeparator();
670 menu->addAction(mMsgActions->addFollowupReminderAction());
672 if (kmkernel->allowToDebugBalooSupport()) {
673 menu->addSeparator();
674 menu->addAction(mMsgActions->debugBalooAction());
677 #ifdef QTWEBENGINE_SUPPORT_OPTION
678 //TODO use interceptorUrlActions
679 //QList<QAction *> mMsgActions->interceptorUrlActions(const MessageViewer::WebHitTestResult &result) const;
680 #endif
682 if (menu) {
683 KAcceleratorManager::manage(menu);
684 menu->exec(aPoint, Q_NULLPTR);
685 delete menu;
689 void KMReaderMainWin::slotEditToolbars()
691 KConfigGroup grp(KMKernel::self()->config(), "ReaderWindow");
692 saveMainWindowSettings(grp);
693 KEditToolBar dlg(guiFactory(), this);
694 connect(&dlg, &KEditToolBar::newToolBarConfig, this, &KMReaderMainWin::slotUpdateToolbars);
695 dlg.exec();
698 void KMReaderMainWin::slotUpdateToolbars()
700 createGUI(QStringLiteral("kmreadermainwin.rc"));
701 applyMainWindowSettings(KConfigGroup(KMKernel::self()->config(), "ReaderWindow"));