Fix Bug 362152 - Font selection is not honored
[kdepim.git] / kmail / messageactions.cpp
blob196893101c47b366b02f9717713504a25829b208
1 /*
2 Copyright (c) 2007 Volker Krause <vkrause@kde.org>
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; either version 2 of the License, or
7 (at your option) any later version.
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
14 You should have received a copy of the GNU General Public License
15 along with this program; if not, write to the Free Software
16 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
19 #include "messageactions.h"
21 #include "settings/kmailsettings.h"
22 #include "kmreaderwin.h"
23 #include "kmkernel.h"
24 #include "mailcommon/mailkernel.h"
25 #include "kmmainwidget.h"
26 #include "util.h"
27 #include "kmcommands.h"
28 #include <TemplateParser/CustomTemplatesMenu>
30 #include "PimCommon/AnnotationDialog"
31 #include "MessageCore/MessageCoreSettings"
32 #include "MessageCore/MailingList"
33 #include "messagecore/messagehelpers.h"
34 #include "MessageViewer/CSSHelper"
35 #include "messageviewer/messageviewersettings.h"
36 #include "messageviewer/headerstyleplugin.h"
38 #include <AkonadiCore/itemfetchjob.h>
39 #include <Akonadi/KMime/MessageParts>
40 #include <AkonadiCore/ChangeRecorder>
41 #include <QAction>
42 #include <AkonadiSearch/Debug/akonadisearchdebugdialog.h>
43 #include <KIO/KUriFilterSearchProviderActions>
45 #include "messagecomposer/followupreminderselectdatedialog.h"
46 #include "job/createfollowupreminderonexistingmessagejob.h"
48 #include <AkonadiCore/ItemFetchJob>
49 #include <KActionMenu>
50 #include <KActionCollection>
51 #include "kmail_debug.h"
52 #include <KLocalizedString>
53 #include <KXMLGUIClient>
54 #include <KRun>
55 #include <QMenu>
56 #include <KUriFilter>
57 #include <KStringHandler>
58 #include <QIcon>
60 #include <QVariant>
61 #include <qwidget.h>
62 #include <AkonadiCore/collection.h>
63 #include <AkonadiCore/entityannotationsattribute.h>
64 #include <mailcommon/mailutil.h>
66 using namespace KMail;
68 MessageActions::MessageActions(KActionCollection *ac, QWidget *parent)
69 : QObject(parent),
70 mParent(parent),
71 mMessageView(Q_NULLPTR),
72 mRedirectAction(Q_NULLPTR),
73 mPrintPreviewAction(Q_NULLPTR),
74 mCustomTemplatesMenu(Q_NULLPTR),
75 mAddFollowupReminderAction(Q_NULLPTR),
76 mDebugBalooAction(Q_NULLPTR)
78 mWebShortcutMenuManager = new KIO::KUriFilterSearchProviderActions(this);
79 mReplyActionMenu = new KActionMenu(QIcon::fromTheme(QStringLiteral("mail-reply-sender")), i18nc("Message->", "&Reply"), this);
80 ac->addAction(QStringLiteral("message_reply_menu"), mReplyActionMenu);
81 connect(mReplyActionMenu, &KActionMenu::triggered, this, &MessageActions::slotReplyToMsg);
83 mReplyAction = new QAction(QIcon::fromTheme(QStringLiteral("mail-reply-sender")), i18n("&Reply..."), this);
84 ac->addAction(QStringLiteral("reply"), mReplyAction);
85 ac->setDefaultShortcut(mReplyAction, Qt::Key_R);
86 connect(mReplyAction, &QAction::triggered, this, &MessageActions::slotReplyToMsg);
87 mReplyActionMenu->addAction(mReplyAction);
89 mReplyAuthorAction = new QAction(QIcon::fromTheme(QStringLiteral("mail-reply-sender")), i18n("Reply to A&uthor..."), this);
90 ac->addAction(QStringLiteral("reply_author"), mReplyAuthorAction);
91 ac->setDefaultShortcut(mReplyAuthorAction, Qt::SHIFT + Qt::Key_A);
92 connect(mReplyAuthorAction, &QAction::triggered, this, &MessageActions::slotReplyAuthorToMsg);
93 mReplyActionMenu->addAction(mReplyAuthorAction);
95 mReplyAllAction = new QAction(QIcon::fromTheme(QStringLiteral("mail-reply-all")), i18n("Reply to &All..."), this);
96 ac->addAction(QStringLiteral("reply_all"), mReplyAllAction);
97 ac->setDefaultShortcut(mReplyAllAction, Qt::Key_A);
98 connect(mReplyAllAction, &QAction::triggered, this, &MessageActions::slotReplyAllToMsg);
99 mReplyActionMenu->addAction(mReplyAllAction);
101 mReplyListAction = new QAction(QIcon::fromTheme(QStringLiteral("mail-reply-list")), i18n("Reply to Mailing-&List..."), this);
102 ac->addAction(QStringLiteral("reply_list"), mReplyListAction);
104 ac->setDefaultShortcut(mReplyListAction, Qt::Key_L);
105 connect(mReplyListAction, &QAction::triggered, this, &MessageActions::slotReplyListToMsg);
106 mReplyActionMenu->addAction(mReplyListAction);
108 mNoQuoteReplyAction = new QAction(i18n("Reply Without &Quote..."), this);
109 ac->addAction(QStringLiteral("noquotereply"), mNoQuoteReplyAction);
110 ac->setDefaultShortcut(mNoQuoteReplyAction, Qt::SHIFT + Qt::Key_R);
111 connect(mNoQuoteReplyAction, &QAction::triggered, this, &MessageActions::slotNoQuoteReplyToMsg);
113 mListFilterAction = new QAction(i18n("Filter on Mailing-&List..."), this);
114 ac->addAction(QStringLiteral("mlist_filter"), mListFilterAction);
115 connect(mListFilterAction, &QAction::triggered, this, &MessageActions::slotMailingListFilter);
117 mStatusMenu = new KActionMenu(i18n("Mar&k Message"), this);
118 ac->addAction(QStringLiteral("set_status"), mStatusMenu);
120 KMMainWidget *mainwin = kmkernel->getKMMainWidget();
121 if (mainwin) {
122 QAction *action = mainwin->akonadiStandardAction(Akonadi::StandardMailActionManager::MarkMailAsRead);
123 mStatusMenu->addAction(action);
125 action = mainwin->akonadiStandardAction(Akonadi::StandardMailActionManager::MarkMailAsUnread);
126 mStatusMenu->addAction(action);
128 mStatusMenu->addSeparator();
129 action = mainwin->akonadiStandardAction(Akonadi::StandardMailActionManager::MarkMailAsImportant);
130 mStatusMenu->addAction(action);
132 action = mainwin->akonadiStandardAction(Akonadi::StandardMailActionManager::MarkMailAsActionItem);
133 mStatusMenu->addAction(action);
137 mEditAction = new QAction(QIcon::fromTheme(QStringLiteral("accessories-text-editor")), i18n("&Edit Message"), this);
138 ac->addAction(QStringLiteral("edit"), mEditAction);
139 connect(mEditAction, &QAction::triggered, this, &MessageActions::editCurrentMessage);
140 ac->setDefaultShortcut(mEditAction, Qt::Key_T);
142 mAnnotateAction = new QAction(QIcon::fromTheme(QStringLiteral("view-pim-notes")), i18n("Add Note..."), this);
143 ac->addAction(QStringLiteral("annotate"), mAnnotateAction);
144 connect(mAnnotateAction, &QAction::triggered, this, &MessageActions::annotateMessage);
146 mPrintAction = KStandardAction::print(this, SLOT(slotPrintMsg()), ac);
147 mPrintPreviewAction = KStandardAction::printPreview(this, SLOT(slotPrintPreviewMsg()), ac);
149 mForwardActionMenu = new KActionMenu(QIcon::fromTheme(QStringLiteral("mail-forward")), i18nc("Message->", "&Forward"), this);
150 ac->addAction(QStringLiteral("message_forward"), mForwardActionMenu);
152 mForwardAttachedAction = new QAction(QIcon::fromTheme(QStringLiteral("mail-forward")),
153 i18nc("@action:inmenu Message->Forward->",
154 "As &Attachment..."),
155 this);
156 connect(mForwardAttachedAction, SIGNAL(triggered(bool)), parent, SLOT(slotForwardAttachedMessage()));
158 ac->addAction(QStringLiteral("message_forward_as_attachment"), mForwardAttachedAction);
160 mForwardInlineAction = new QAction(QIcon::fromTheme(QStringLiteral("mail-forward")),
161 i18nc("@action:inmenu Message->Forward->",
162 "&Inline..."),
163 this);
164 connect(mForwardInlineAction, SIGNAL(triggered(bool)), parent, SLOT(slotForwardInlineMsg()));
166 ac->addAction(QStringLiteral("message_forward_inline"), mForwardInlineAction);
168 setupForwardActions(ac);
170 mRedirectAction = new QAction(i18nc("Message->Forward->", "&Redirect..."), this);
171 ac->addAction(QStringLiteral("message_forward_redirect"), mRedirectAction);
172 connect(mRedirectAction, SIGNAL(triggered(bool)), parent, SLOT(slotRedirectMessage()));
174 ac->setDefaultShortcut(mRedirectAction, QKeySequence(Qt::Key_E));
175 mForwardActionMenu->addAction(mRedirectAction);
177 mMailingListActionMenu = new KActionMenu(QIcon::fromTheme(QStringLiteral("mail-message-new-list")), i18nc("Message->", "Mailing-&List"), this);
178 connect(mMailingListActionMenu->menu(), &QMenu::triggered, this, &MessageActions::slotRunUrl);
179 ac->addAction(QStringLiteral("mailing_list"), mMailingListActionMenu);
180 mMailingListActionMenu->setEnabled(false);
182 connect(kmkernel->folderCollectionMonitor(), &Akonadi::Monitor::itemChanged, this, &MessageActions::slotItemModified);
183 connect(kmkernel->folderCollectionMonitor(), &Akonadi::Monitor::itemRemoved, this, &MessageActions::slotItemRemoved);
185 mCustomTemplatesMenu = new TemplateParser::CustomTemplatesMenu(parent, ac);
187 connect(mCustomTemplatesMenu, SIGNAL(replyTemplateSelected(QString)), parent, SLOT(slotCustomReplyToMsg(QString)));
188 connect(mCustomTemplatesMenu, SIGNAL(replyAllTemplateSelected(QString)), parent, SLOT(slotCustomReplyAllToMsg(QString)));
189 connect(mCustomTemplatesMenu, SIGNAL(forwardTemplateSelected(QString)), parent, SLOT(slotCustomForwardMsg(QString)));
190 connect(KMKernel::self(), &KMKernel::customTemplatesChanged, mCustomTemplatesMenu, &TemplateParser::CustomTemplatesMenu::update);
192 forwardMenu()->addSeparator();
193 forwardMenu()->addAction(mCustomTemplatesMenu->forwardActionMenu());
194 replyMenu()->addSeparator();
195 replyMenu()->addAction(mCustomTemplatesMenu->replyActionMenu());
196 replyMenu()->addAction(mCustomTemplatesMenu->replyAllActionMenu());
198 //Don't translate it. Shown only when we set env variable KDEPIM_BALOO_DEBUG
199 mDebugBalooAction = new QAction(QStringLiteral("Debug Baloo..."), this);
200 connect(mDebugBalooAction, &QAction::triggered, this, &MessageActions::slotDebugBaloo);
202 mAddFollowupReminderAction = new QAction(i18n("Add Followup Reminder..."), this);
203 ac->addAction(QStringLiteral("message_followup_reminder"), mAddFollowupReminderAction);
204 connect(mAddFollowupReminderAction, &QAction::triggered, this, &MessageActions::slotAddFollowupReminder);
206 updateActions();
209 MessageActions::~MessageActions()
211 delete mCustomTemplatesMenu;
214 TemplateParser::CustomTemplatesMenu *MessageActions::customTemplatesMenu() const
216 return mCustomTemplatesMenu;
219 void MessageActions::setCurrentMessage(const Akonadi::Item &msg, const Akonadi::Item::List &items)
221 mCurrentItem = msg;
223 if (!items.isEmpty()) {
224 if (msg.isValid()) {
225 mVisibleItems = items;
226 } else {
227 mVisibleItems.clear();
231 if (!msg.isValid()) {
232 mVisibleItems.clear();
233 clearMailingListActions();
236 updateActions();
239 KActionMenu *MessageActions::replyMenu() const
241 return mReplyActionMenu;
244 QAction *MessageActions::replyListAction() const
246 return mReplyListAction;
249 QAction *MessageActions::forwardInlineAction() const
251 return mForwardInlineAction;
254 QAction *MessageActions::forwardAttachedAction() const
256 return mForwardAttachedAction;
259 QAction *MessageActions::redirectAction() const
261 return mRedirectAction;
264 KActionMenu *MessageActions::messageStatusMenu() const
266 return mStatusMenu;
269 KActionMenu *MessageActions::forwardMenu() const
271 return mForwardActionMenu;
274 QAction *MessageActions::editAction() const
276 return mEditAction;
279 QAction *MessageActions::annotateAction() const
281 return mAnnotateAction;
284 QAction *MessageActions::printAction() const
286 return mPrintAction;
289 QAction *MessageActions::printPreviewAction() const
291 return mPrintPreviewAction;
294 QAction *MessageActions::listFilterAction() const
296 return mListFilterAction;
299 KActionMenu *MessageActions::mailingListActionMenu() const
301 return mMailingListActionMenu;
304 void MessageActions::slotItemRemoved(const Akonadi::Item &item)
306 if (item == mCurrentItem) {
307 mCurrentItem = Akonadi::Item();
308 updateActions();
312 void MessageActions::slotItemModified(const Akonadi::Item &item, const QSet< QByteArray > &partIdentifiers)
314 Q_UNUSED(partIdentifiers);
315 if (item == mCurrentItem) {
316 mCurrentItem = item;
317 const int numberOfVisibleItems = mVisibleItems.count();
318 for (int i = 0; i < numberOfVisibleItems; ++i) {
319 Akonadi::Item it = mVisibleItems.at(i);
320 if (item == it) {
321 mVisibleItems[i] = item;
324 updateActions();
328 void MessageActions::updateActions()
330 const bool hasPayload = mCurrentItem.hasPayload<KMime::Message::Ptr>();
331 bool itemValid = mCurrentItem.isValid();
332 Akonadi::Collection parent;
333 if (itemValid) { //=> valid
334 parent = mCurrentItem.parentCollection();
336 if (parent.isValid()) {
337 if (CommonKernel->folderIsTemplates(parent)) {
338 itemValid = false;
342 const bool multiVisible = mVisibleItems.count() > 0 || mCurrentItem.isValid();
343 const bool uniqItem = (itemValid || hasPayload) && (mVisibleItems.count() <= 1);
344 mReplyActionMenu->setEnabled(hasPayload);
345 mReplyAction->setEnabled(hasPayload);
346 mNoQuoteReplyAction->setEnabled(hasPayload);
347 mReplyAuthorAction->setEnabled(hasPayload);
348 mReplyAllAction->setEnabled(hasPayload);
349 mReplyListAction->setEnabled(hasPayload);
350 mNoQuoteReplyAction->setEnabled(hasPayload);
352 mAnnotateAction->setEnabled(uniqItem);
353 if (!mCurrentItem.hasAttribute<Akonadi::EntityAnnotationsAttribute>()) {
354 mAnnotateAction->setText(i18n("Add Note..."));
355 } else {
356 mAnnotateAction->setText(i18n("Edit Note..."));
359 mStatusMenu->setEnabled(multiVisible);
361 if (mCurrentItem.hasPayload<KMime::Message::Ptr>()) {
362 if (mCurrentItem.loadedPayloadParts().contains("RFC822")) {
363 updateMailingListActions(mCurrentItem);
364 } else {
365 Akonadi::ItemFetchJob *job = new Akonadi::ItemFetchJob(mCurrentItem);
366 job->fetchScope().fetchAllAttributes();
367 job->fetchScope().fetchFullPayload(true);
368 job->fetchScope().fetchPayloadPart(Akonadi::MessagePart::Header);
369 job->fetchScope().fetchAttribute<Akonadi::EntityAnnotationsAttribute>();
370 connect(job, &Akonadi::ItemFetchJob::result, this, &MessageActions::slotUpdateActionsFetchDone);
373 mEditAction->setEnabled(uniqItem);
376 void MessageActions::slotUpdateActionsFetchDone(KJob *job)
378 if (job->error()) {
379 return;
382 Akonadi::ItemFetchJob *fetchJob = static_cast<Akonadi::ItemFetchJob *>(job);
383 if (fetchJob->items().isEmpty()) {
384 return;
386 Akonadi::Item messageItem = fetchJob->items().first();
387 if (messageItem == mCurrentItem) {
388 mCurrentItem = messageItem;
389 updateMailingListActions(messageItem);
393 void MessageActions::clearMailingListActions()
395 mMailingListActionMenu->setEnabled(false);
396 mListFilterAction->setEnabled(false);
397 mListFilterAction->setText(i18n("Filter on Mailing-List..."));
400 void MessageActions::updateMailingListActions(const Akonadi::Item &messageItem)
402 KMime::Message::Ptr message = messageItem.payload<KMime::Message::Ptr>();
403 const MessageCore::MailingList mailList = MessageCore::MailingList::detect(message);
405 if (mailList.features() == MessageCore::MailingList::None) {
406 clearMailingListActions();
407 } else {
408 // A mailing list menu with only a title is pretty boring
409 // so make sure theres at least some content
410 QString listId;
411 if (mailList.features() & MessageCore::MailingList::Id) {
412 // From a list-id in the form, "Birds of France <bof.yahoo.com>",
413 // take "Birds of France" if it exists otherwise "bof.yahoo.com".
414 listId = mailList.id();
415 const int start = listId.indexOf(QLatin1Char('<'));
416 if (start > 0) {
417 listId.truncate(start - 1);
418 } else if (start == 0) {
419 const int end = listId.lastIndexOf(QLatin1Char('>'));
420 if (end < 1) { // shouldn't happen but account for it anyway
421 listId.remove(0, 1);
422 } else {
423 listId = listId.mid(1, end - 1);
427 mMailingListActionMenu->menu()->clear();
428 qDeleteAll(mMailListActionList);
429 mMailListActionList.clear();
430 if (!listId.isEmpty()) {
431 mMailingListActionMenu->menu()->setTitle(listId);
433 if (mailList.features() & MessageCore::MailingList::ArchivedAt)
434 // IDEA: this may be something you want to copy - "Copy in submenu"?
436 addMailingListActions(i18n("Open Message in List Archive"), mailList.archivedAtUrls());
438 if (mailList.features() & MessageCore::MailingList::Post) {
439 addMailingListActions(i18n("Post New Message"), mailList.postUrls());
441 if (mailList.features() & MessageCore::MailingList::Archive) {
442 addMailingListActions(i18n("Go to Archive"), mailList.archiveUrls());
444 if (mailList.features() & MessageCore::MailingList::Help) {
445 addMailingListActions(i18n("Request Help"), mailList.helpUrls());
447 if (mailList.features() & MessageCore::MailingList::Owner) {
448 addMailingListActions(i18nc("Contact the owner of the mailing list", "Contact Owner"), mailList.ownerUrls());
450 if (mailList.features() & MessageCore::MailingList::Subscribe) {
451 addMailingListActions(i18n("Subscribe to List"), mailList.subscribeUrls());
453 if (mailList.features() & MessageCore::MailingList::Unsubscribe) {
454 addMailingListActions(i18n("Unsubscribe from List"), mailList.unsubscribeUrls());
456 mMailingListActionMenu->setEnabled(true);
458 QByteArray name;
459 QString value;
460 const QString lname = MailingList::name(message, name, value);
461 if (!lname.isEmpty()) {
462 mListFilterAction->setEnabled(true);
463 mListFilterAction->setText(i18n("Filter on Mailing-List %1...", lname));
468 void MessageActions::replyCommand(MessageComposer::ReplyStrategy strategy)
470 if (!mCurrentItem.hasPayload<KMime::Message::Ptr>()) {
471 return;
474 const QString text = mMessageView ? mMessageView->copyText() : QString();
475 KMCommand *command = new KMReplyCommand(mParent, mCurrentItem, strategy, text);
476 connect(command, &KMCommand::completed, this, &MessageActions::replyActionFinished);
477 command->start();
480 void MessageActions::setMessageView(KMReaderWin *msgView)
482 mMessageView = msgView;
485 void MessageActions::setupForwardActions(KActionCollection *ac)
487 disconnect(mForwardActionMenu, SIGNAL(triggered(bool)), Q_NULLPTR, Q_NULLPTR);
488 mForwardActionMenu->removeAction(mForwardInlineAction);
489 mForwardActionMenu->removeAction(mForwardAttachedAction);
491 if (KMailSettings::self()->forwardingInlineByDefault()) {
492 mForwardActionMenu->insertAction(mRedirectAction, mForwardInlineAction);
493 mForwardActionMenu->insertAction(mRedirectAction, mForwardAttachedAction);
494 ac->setDefaultShortcut(mForwardInlineAction, QKeySequence(Qt::Key_F));
495 ac->setDefaultShortcut(mForwardAttachedAction, QKeySequence(Qt::SHIFT + Qt::Key_F));
496 QObject::connect(mForwardActionMenu, SIGNAL(triggered(bool)),
497 mParent, SLOT(slotForwardInlineMsg()));
498 } else {
499 mForwardActionMenu->insertAction(mRedirectAction, mForwardAttachedAction);
500 mForwardActionMenu->insertAction(mRedirectAction, mForwardInlineAction);
501 ac->setDefaultShortcut(mForwardInlineAction, QKeySequence(Qt::Key_F));
502 ac->setDefaultShortcut(mForwardAttachedAction, QKeySequence(Qt::SHIFT + Qt::Key_F));
503 QObject::connect(mForwardActionMenu, SIGNAL(triggered(bool)),
504 mParent, SLOT(slotForwardAttachedMessage()));
508 void MessageActions::setupForwardingActionsList(KXMLGUIClient *guiClient)
510 QList<QAction *> forwardActionList;
511 guiClient->unplugActionList(QStringLiteral("forward_action_list"));
512 if (KMailSettings::self()->forwardingInlineByDefault()) {
513 forwardActionList.append(mForwardInlineAction);
514 forwardActionList.append(mForwardAttachedAction);
515 } else {
516 forwardActionList.append(mForwardAttachedAction);
517 forwardActionList.append(mForwardInlineAction);
519 forwardActionList.append(mRedirectAction);
520 guiClient->plugActionList(QStringLiteral("forward_action_list"), forwardActionList);
523 void MessageActions::slotReplyToMsg()
525 replyCommand(MessageComposer::ReplySmart);
528 void MessageActions::slotReplyAuthorToMsg()
530 replyCommand(MessageComposer::ReplyAuthor);
533 void MessageActions::slotReplyListToMsg()
535 replyCommand(MessageComposer::ReplyList);
538 void MessageActions::slotReplyAllToMsg()
540 replyCommand(MessageComposer::ReplyAll);
543 void MessageActions::slotNoQuoteReplyToMsg()
545 if (!mCurrentItem.hasPayload<KMime::Message::Ptr>()) {
546 return;
548 KMCommand *command = new KMReplyCommand(mParent, mCurrentItem, MessageComposer::ReplySmart, QString(), true);
549 command->start();
552 void MessageActions::slotRunUrl(QAction *urlAction)
554 const QVariant q = urlAction->data();
555 if (q.type() == QVariant::Url) {
556 new KRun(q.toUrl(), mParent);
560 void MessageActions::slotMailingListFilter()
562 if (!mCurrentItem.hasPayload<KMime::Message::Ptr>()) {
563 return;
566 KMCommand *command = new KMMailingListFilterCommand(mParent, mCurrentItem);
567 command->start();
570 void MessageActions::printMessage(bool preview)
572 if (mMessageView) {
573 bool result = false;
574 if (MessageViewer::MessageViewerSettings::self()->printSelectedText()) {
575 result = mMessageView->printSelectedText(preview);
577 if (!result) {
578 const bool useFixedFont = MessageViewer::MessageViewerSettings::self()->useFixedFont();
579 const QString overrideEncoding = MessageCore::MessageCoreSettings::self()->overrideCharacterEncoding();
581 const Akonadi::Item message = mCurrentItem;
582 KMPrintCommand *command =
583 new KMPrintCommand(mParent, message,
584 mMessageView->viewer()->headerStylePlugin(),
585 mMessageView->viewer()->displayFormatMessageOverwrite(), mMessageView->viewer()->htmlLoadExternal(),
586 useFixedFont, overrideEncoding);
587 command->setPrintPreview(preview);
588 command->start();
593 void MessageActions::slotPrintPreviewMsg()
595 printMessage(true);
598 void MessageActions::slotPrintMsg()
600 printMessage(false);
604 * This adds a list of actions to mMailingListActionMenu mapping the identifier item to
605 * the url.
607 * e.g.: item = "Contact Owner"
608 * "Contact Owner (email)" -> KRun( "mailto:bob@arthouseflowers.example.com" )
609 * "Contact Owner (web)" -> KRun( "http://arthouseflowers.example.com/contact-owner.php" )
611 void MessageActions::addMailingListActions(const QString &item, const QList<QUrl> &list)
613 foreach (const QUrl &url, list) {
614 addMailingListAction(item, url);
619 * This adds a action to mMailingListActionMenu mapping the identifier item to
620 * the url. See addMailingListActions above.
622 void MessageActions::addMailingListAction(const QString &item, const QUrl &url)
624 QString protocol = url.scheme().toLower();
625 QString prettyUrl = url.toDisplayString();
626 if (protocol == QLatin1String("mailto")) {
627 protocol = i18n("email");
628 prettyUrl.remove(0, 7); // length( "mailto:" )
629 } else if (protocol.startsWith(QStringLiteral("http"))) {
630 protocol = i18n("web");
632 // item is a mailing list url description passed from the updateActions method above.
633 QAction *act = new QAction(i18nc("%1 is a 'Contact Owner' or similar action. %2 is a protocol normally web or email though could be irc/ftp or other url variant", "%1 (%2)", item, protocol), this);
634 mMailListActionList.append(act);
635 const QVariant v(url);
636 act->setData(v);
637 KMail::Util::addQActionHelpText(act, prettyUrl);
638 mMailingListActionMenu->addAction(act);
641 void MessageActions::editCurrentMessage()
643 KMCommand *command = Q_NULLPTR;
644 if (mCurrentItem.isValid()) {
645 Akonadi::Collection col = mCurrentItem.parentCollection();
646 qCDebug(KMAIL_LOG) << " mCurrentItem.parentCollection()" << mCurrentItem.parentCollection();
647 // edit, unlike send again, removes the message from the folder
648 // we only want that for templates and drafts folders
649 if (col.isValid()
650 && (CommonKernel->folderIsDraftOrOutbox(col) ||
651 CommonKernel->folderIsTemplates(col))
653 command = new KMEditItemCommand(mParent, mCurrentItem, true);
654 } else {
655 command = new KMEditItemCommand(mParent, mCurrentItem, false);
657 command->start();
658 } else if (mCurrentItem.hasPayload<KMime::Message::Ptr>()) {
659 command = new KMEditMessageCommand(mParent, mCurrentItem.payload<KMime::Message::Ptr>());
660 command->start();
664 void MessageActions::annotateMessage()
666 if (!mCurrentItem.isValid()) {
667 return;
670 PimCommon::AnnotationEditDialog *dialog = new PimCommon::AnnotationEditDialog(mCurrentItem);
671 dialog->setAttribute(Qt::WA_DeleteOnClose);
672 dialog->exec();
675 void MessageActions::addWebShortcutsMenu(QMenu *menu, const QString &text)
677 mWebShortcutMenuManager->setSelectedText(text);
678 mWebShortcutMenuManager->addWebShortcutsToMenu(menu);
681 QAction *MessageActions::debugBalooAction() const
683 return mDebugBalooAction;
686 QAction *MessageActions::addFollowupReminderAction() const
688 return mAddFollowupReminderAction;
691 void MessageActions::slotDebugBaloo()
693 if (!mCurrentItem.isValid()) {
694 return;
696 QPointer<Akonadi::Search::AkonadiSearchDebugDialog> dlg = new Akonadi::Search::AkonadiSearchDebugDialog;
697 dlg->setAkonadiId(mCurrentItem.id());
698 dlg->setAttribute(Qt::WA_DeleteOnClose);
699 dlg->setSearchType(Akonadi::Search::AkonadiSearchDebugSearchPathComboBox::Emails);
700 dlg->doSearch();
701 dlg->show();
704 void MessageActions::slotAddFollowupReminder()
706 if (!mCurrentItem.isValid()) {
707 return;
710 QPointer<MessageComposer::FollowUpReminderSelectDateDialog> dlg = new MessageComposer::FollowUpReminderSelectDateDialog;
711 if (dlg->exec()) {
712 const QDate date = dlg->selectedDate();
713 CreateFollowupReminderOnExistingMessageJob *job = new CreateFollowupReminderOnExistingMessageJob(this);
714 job->setDate(date);
715 job->setCollection(dlg->collection());
716 job->setMessageItem(mCurrentItem);
717 job->start();
719 delete dlg;