Fix Bug 359872 - Big icon when trying to drag a attached pdf file
[kdepim.git] / kmail / messageactions.cpp
blob5221bedef0a5926b2501149781dd46cb45f51a6c
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(slotForwardAttachedMsg()));
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(slotRedirectMsg()));
174 ac->setDefaultShortcut(mRedirectAction, QKeySequence(Qt::Key_E));
175 mForwardActionMenu->addAction(mRedirectAction);
177 //FIXME add QIcon::fromTheme("mail-list") as first arguement. Icon can be derived from
178 // mail-reply-list icon by removing top layers off svg
179 mMailingListActionMenu = new KActionMenu(i18nc("Message->", "Mailing-&List"), this);
180 connect(mMailingListActionMenu->menu(), &QMenu::triggered, this, &MessageActions::slotRunUrl);
181 ac->addAction(QStringLiteral("mailing_list"), mMailingListActionMenu);
182 mMailingListActionMenu->setEnabled(false);
184 connect(kmkernel->folderCollectionMonitor(), &Akonadi::Monitor::itemChanged, this, &MessageActions::slotItemModified);
185 connect(kmkernel->folderCollectionMonitor(), &Akonadi::Monitor::itemRemoved, this, &MessageActions::slotItemRemoved);
187 mCustomTemplatesMenu = new TemplateParser::CustomTemplatesMenu(parent, ac);
189 connect(mCustomTemplatesMenu, SIGNAL(replyTemplateSelected(QString)), parent, SLOT(slotCustomReplyToMsg(QString)));
190 connect(mCustomTemplatesMenu, SIGNAL(replyAllTemplateSelected(QString)), parent, SLOT(slotCustomReplyAllToMsg(QString)));
191 connect(mCustomTemplatesMenu, SIGNAL(forwardTemplateSelected(QString)), parent, SLOT(slotCustomForwardMsg(QString)));
192 connect(KMKernel::self(), &KMKernel::customTemplatesChanged, mCustomTemplatesMenu, &TemplateParser::CustomTemplatesMenu::update);
194 forwardMenu()->addSeparator();
195 forwardMenu()->addAction(mCustomTemplatesMenu->forwardActionMenu());
196 replyMenu()->addSeparator();
197 replyMenu()->addAction(mCustomTemplatesMenu->replyActionMenu());
198 replyMenu()->addAction(mCustomTemplatesMenu->replyAllActionMenu());
200 //Don't translate it. Shown only when we set env variable KDEPIM_BALOO_DEBUG
201 mDebugBalooAction = new QAction(QStringLiteral("Debug Baloo..."), this);
202 connect(mDebugBalooAction, &QAction::triggered, this, &MessageActions::slotDebugBaloo);
204 mAddFollowupReminderAction = new QAction(i18n("Add Followup Reminder..."), this);
205 ac->addAction(QStringLiteral("message_followup_reminder"), mAddFollowupReminderAction);
206 connect(mAddFollowupReminderAction, &QAction::triggered, this, &MessageActions::slotAddFollowupReminder);
208 updateActions();
211 MessageActions::~MessageActions()
213 delete mCustomTemplatesMenu;
216 TemplateParser::CustomTemplatesMenu *MessageActions::customTemplatesMenu() const
218 return mCustomTemplatesMenu;
221 void MessageActions::setCurrentMessage(const Akonadi::Item &msg, const Akonadi::Item::List &items)
223 mCurrentItem = msg;
225 if (!items.isEmpty()) {
226 if (msg.isValid()) {
227 mVisibleItems = items;
228 } else {
229 mVisibleItems.clear();
233 if (!msg.isValid()) {
234 mVisibleItems.clear();
235 clearMailingListActions();
238 updateActions();
241 KActionMenu *MessageActions::replyMenu() const
243 return mReplyActionMenu;
246 QAction *MessageActions::replyListAction() const
248 return mReplyListAction;
251 QAction *MessageActions::forwardInlineAction() const
253 return mForwardInlineAction;
256 QAction *MessageActions::forwardAttachedAction() const
258 return mForwardAttachedAction;
261 QAction *MessageActions::redirectAction() const
263 return mRedirectAction;
266 KActionMenu *MessageActions::messageStatusMenu() const
268 return mStatusMenu;
271 KActionMenu *MessageActions::forwardMenu() const
273 return mForwardActionMenu;
276 QAction *MessageActions::editAction() const
278 return mEditAction;
281 QAction *MessageActions::annotateAction() const
283 return mAnnotateAction;
286 QAction *MessageActions::printAction() const
288 return mPrintAction;
291 QAction *MessageActions::printPreviewAction() const
293 return mPrintPreviewAction;
296 QAction *MessageActions::listFilterAction() const
298 return mListFilterAction;
301 KActionMenu *MessageActions::mailingListActionMenu() const
303 return mMailingListActionMenu;
306 void MessageActions::slotItemRemoved(const Akonadi::Item &item)
308 if (item == mCurrentItem) {
309 mCurrentItem = Akonadi::Item();
310 updateActions();
314 void MessageActions::slotItemModified(const Akonadi::Item &item, const QSet< QByteArray > &partIdentifiers)
316 Q_UNUSED(partIdentifiers);
317 if (item == mCurrentItem) {
318 mCurrentItem = item;
319 const int numberOfVisibleItems = mVisibleItems.count();
320 for (int i = 0; i < numberOfVisibleItems; ++i) {
321 Akonadi::Item it = mVisibleItems.at(i);
322 if (item == it) {
323 mVisibleItems[i] = item;
326 updateActions();
330 void MessageActions::updateActions()
332 const bool hasPayload = mCurrentItem.hasPayload<KMime::Message::Ptr>();
333 bool itemValid = mCurrentItem.isValid();
334 Akonadi::Collection parent;
335 if (itemValid) { //=> valid
336 parent = mCurrentItem.parentCollection();
338 if (parent.isValid()) {
339 if (CommonKernel->folderIsTemplates(parent)) {
340 itemValid = false;
344 const bool multiVisible = mVisibleItems.count() > 0 || mCurrentItem.isValid();
345 const bool uniqItem = (itemValid || hasPayload) && (mVisibleItems.count() <= 1);
346 mReplyActionMenu->setEnabled(hasPayload);
347 mReplyAction->setEnabled(hasPayload);
348 mNoQuoteReplyAction->setEnabled(hasPayload);
349 mReplyAuthorAction->setEnabled(hasPayload);
350 mReplyAllAction->setEnabled(hasPayload);
351 mReplyListAction->setEnabled(hasPayload);
352 mNoQuoteReplyAction->setEnabled(hasPayload);
354 mAnnotateAction->setEnabled(uniqItem);
355 if (!mCurrentItem.hasAttribute<Akonadi::EntityAnnotationsAttribute>()) {
356 mAnnotateAction->setText(i18n("Add Note..."));
357 } else {
358 mAnnotateAction->setText(i18n("Edit Note..."));
361 mStatusMenu->setEnabled(multiVisible);
363 if (mCurrentItem.hasPayload<KMime::Message::Ptr>()) {
364 if (mCurrentItem.loadedPayloadParts().contains("RFC822")) {
365 updateMailingListActions(mCurrentItem);
366 } else {
367 Akonadi::ItemFetchJob *job = new Akonadi::ItemFetchJob(mCurrentItem);
368 job->fetchScope().fetchAllAttributes();
369 job->fetchScope().fetchFullPayload(true);
370 job->fetchScope().fetchPayloadPart(Akonadi::MessagePart::Header);
371 job->fetchScope().fetchAttribute<Akonadi::EntityAnnotationsAttribute>();
372 connect(job, &Akonadi::ItemFetchJob::result, this, &MessageActions::slotUpdateActionsFetchDone);
375 mEditAction->setEnabled(uniqItem);
378 void MessageActions::slotUpdateActionsFetchDone(KJob *job)
380 if (job->error()) {
381 return;
384 Akonadi::ItemFetchJob *fetchJob = static_cast<Akonadi::ItemFetchJob *>(job);
385 if (fetchJob->items().isEmpty()) {
386 return;
388 Akonadi::Item messageItem = fetchJob->items().first();
389 if (messageItem == mCurrentItem) {
390 mCurrentItem = messageItem;
391 updateMailingListActions(messageItem);
395 void MessageActions::clearMailingListActions()
397 mMailingListActionMenu->setEnabled(false);
398 mListFilterAction->setEnabled(false);
399 mListFilterAction->setText(i18n("Filter on Mailing-List..."));
402 void MessageActions::updateMailingListActions(const Akonadi::Item &messageItem)
404 KMime::Message::Ptr message = messageItem.payload<KMime::Message::Ptr>();
405 const MessageCore::MailingList mailList = MessageCore::MailingList::detect(message);
407 if (mailList.features() == MessageCore::MailingList::None) {
408 clearMailingListActions();
409 } else {
410 // A mailing list menu with only a title is pretty boring
411 // so make sure theres at least some content
412 QString listId;
413 if (mailList.features() & MessageCore::MailingList::Id) {
414 // From a list-id in the form, "Birds of France <bof.yahoo.com>",
415 // take "Birds of France" if it exists otherwise "bof.yahoo.com".
416 listId = mailList.id();
417 const int start = listId.indexOf(QLatin1Char('<'));
418 if (start > 0) {
419 listId.truncate(start - 1);
420 } else if (start == 0) {
421 const int end = listId.lastIndexOf(QLatin1Char('>'));
422 if (end < 1) { // shouldn't happen but account for it anyway
423 listId.remove(0, 1);
424 } else {
425 listId = listId.mid(1, end - 1);
429 mMailingListActionMenu->menu()->clear();
430 qDeleteAll(mMailListActionList);
431 mMailListActionList.clear();
432 if (!listId.isEmpty()) {
433 mMailingListActionMenu->menu()->setTitle(listId);
435 if (mailList.features() & MessageCore::MailingList::ArchivedAt)
436 // IDEA: this may be something you want to copy - "Copy in submenu"?
438 addMailingListActions(i18n("Open Message in List Archive"), mailList.archivedAtUrls());
440 if (mailList.features() & MessageCore::MailingList::Post) {
441 addMailingListActions(i18n("Post New Message"), mailList.postUrls());
443 if (mailList.features() & MessageCore::MailingList::Archive) {
444 addMailingListActions(i18n("Go to Archive"), mailList.archiveUrls());
446 if (mailList.features() & MessageCore::MailingList::Help) {
447 addMailingListActions(i18n("Request Help"), mailList.helpUrls());
449 if (mailList.features() & MessageCore::MailingList::Owner) {
450 addMailingListActions(i18nc("Contact the owner of the mailing list", "Contact Owner"), mailList.ownerUrls());
452 if (mailList.features() & MessageCore::MailingList::Subscribe) {
453 addMailingListActions(i18n("Subscribe to List"), mailList.subscribeUrls());
455 if (mailList.features() & MessageCore::MailingList::Unsubscribe) {
456 addMailingListActions(i18n("Unsubscribe from List"), mailList.unsubscribeUrls());
458 mMailingListActionMenu->setEnabled(true);
460 QByteArray name;
461 QString value;
462 const QString lname = MailingList::name(message, name, value);
463 if (!lname.isEmpty()) {
464 mListFilterAction->setEnabled(true);
465 mListFilterAction->setText(i18n("Filter on Mailing-List %1...", lname));
470 void MessageActions::replyCommand(MessageComposer::ReplyStrategy strategy)
472 if (!mCurrentItem.hasPayload<KMime::Message::Ptr>()) {
473 return;
476 const QString text = mMessageView ? mMessageView->copyText() : QString();
477 KMCommand *command = new KMReplyCommand(mParent, mCurrentItem, strategy, text);
478 connect(command, &KMCommand::completed, this, &MessageActions::replyActionFinished);
479 command->start();
482 void MessageActions::setMessageView(KMReaderWin *msgView)
484 mMessageView = msgView;
487 void MessageActions::setupForwardActions(KActionCollection *ac)
489 disconnect(mForwardActionMenu, SIGNAL(triggered(bool)), Q_NULLPTR, Q_NULLPTR);
490 mForwardActionMenu->removeAction(mForwardInlineAction);
491 mForwardActionMenu->removeAction(mForwardAttachedAction);
493 if (KMailSettings::self()->forwardingInlineByDefault()) {
494 mForwardActionMenu->insertAction(mRedirectAction, mForwardInlineAction);
495 mForwardActionMenu->insertAction(mRedirectAction, mForwardAttachedAction);
496 ac->setDefaultShortcut(mForwardInlineAction, QKeySequence(Qt::Key_F));
497 ac->setDefaultShortcut(mForwardAttachedAction, QKeySequence(Qt::SHIFT + Qt::Key_F));
498 QObject::connect(mForwardActionMenu, SIGNAL(triggered(bool)),
499 mParent, SLOT(slotForwardInlineMsg()));
500 } else {
501 mForwardActionMenu->insertAction(mRedirectAction, mForwardAttachedAction);
502 mForwardActionMenu->insertAction(mRedirectAction, mForwardInlineAction);
503 ac->setDefaultShortcut(mForwardInlineAction, QKeySequence(Qt::Key_F));
504 ac->setDefaultShortcut(mForwardAttachedAction, QKeySequence(Qt::SHIFT + Qt::Key_F));
505 QObject::connect(mForwardActionMenu, SIGNAL(triggered(bool)),
506 mParent, SLOT(slotForwardAttachedMsg()));
510 void MessageActions::setupForwardingActionsList(KXMLGUIClient *guiClient)
512 QList<QAction *> forwardActionList;
513 guiClient->unplugActionList(QStringLiteral("forward_action_list"));
514 if (KMailSettings::self()->forwardingInlineByDefault()) {
515 forwardActionList.append(mForwardInlineAction);
516 forwardActionList.append(mForwardAttachedAction);
517 } else {
518 forwardActionList.append(mForwardAttachedAction);
519 forwardActionList.append(mForwardInlineAction);
521 forwardActionList.append(mRedirectAction);
522 guiClient->plugActionList(QStringLiteral("forward_action_list"), forwardActionList);
525 void MessageActions::slotReplyToMsg()
527 replyCommand(MessageComposer::ReplySmart);
530 void MessageActions::slotReplyAuthorToMsg()
532 replyCommand(MessageComposer::ReplyAuthor);
535 void MessageActions::slotReplyListToMsg()
537 replyCommand(MessageComposer::ReplyList);
540 void MessageActions::slotReplyAllToMsg()
542 replyCommand(MessageComposer::ReplyAll);
545 void MessageActions::slotNoQuoteReplyToMsg()
547 if (!mCurrentItem.hasPayload<KMime::Message::Ptr>()) {
548 return;
550 KMCommand *command = new KMReplyCommand(mParent, mCurrentItem, MessageComposer::ReplySmart, QString(), true);
551 command->start();
554 void MessageActions::slotRunUrl(QAction *urlAction)
556 const QVariant q = urlAction->data();
557 if (q.type() == QVariant::Url) {
558 new KRun(q.toUrl(), mParent);
562 void MessageActions::slotMailingListFilter()
564 if (!mCurrentItem.hasPayload<KMime::Message::Ptr>()) {
565 return;
568 KMCommand *command = new KMMailingListFilterCommand(mParent, mCurrentItem);
569 command->start();
572 void MessageActions::printMessage(bool preview)
574 bool result = false;
575 if (mMessageView) {
576 if (MessageViewer::MessageViewerSettings::self()->printSelectedText()) {
577 result = mMessageView->printSelectedText(preview);
580 if (!result) {
581 const bool useFixedFont = MessageViewer::MessageViewerSettings::self()->useFixedFont();
582 const QString overrideEncoding = MessageCore::MessageCoreSettings::self()->overrideCharacterEncoding();
584 const Akonadi::Item message = mCurrentItem;
585 KMPrintCommand *command =
586 new KMPrintCommand(mParent, message,
587 mMessageView->viewer()->headerStylePlugin(),
588 mMessageView->viewer()->displayFormatMessageOverwrite(), mMessageView->viewer()->htmlLoadExternal(),
589 useFixedFont, overrideEncoding);
590 command->setPrintPreview(preview);
591 command->start();
595 void MessageActions::slotPrintPreviewMsg()
597 printMessage(true);
600 void MessageActions::slotPrintMsg()
602 printMessage(false);
606 * This adds a list of actions to mMailingListActionMenu mapping the identifier item to
607 * the url.
609 * e.g.: item = "Contact Owner"
610 * "Contact Owner (email)" -> KRun( "mailto:bob@arthouseflowers.example.com" )
611 * "Contact Owner (web)" -> KRun( "http://arthouseflowers.example.com/contact-owner.php" )
613 void MessageActions::addMailingListActions(const QString &item, const QList<QUrl> &list)
615 foreach (const QUrl &url, list) {
616 addMailingListAction(item, url);
621 * This adds a action to mMailingListActionMenu mapping the identifier item to
622 * the url. See addMailingListActions above.
624 void MessageActions::addMailingListAction(const QString &item, const QUrl &url)
626 QString protocol = url.scheme().toLower();
627 QString prettyUrl = url.toDisplayString();
628 if (protocol == QLatin1String("mailto")) {
629 protocol = i18n("email");
630 prettyUrl.remove(0, 7); // length( "mailto:" )
631 } else if (protocol.startsWith(QStringLiteral("http"))) {
632 protocol = i18n("web");
634 // item is a mailing list url description passed from the updateActions method above.
635 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);
636 mMailListActionList.append(act);
637 const QVariant v(url);
638 act->setData(v);
639 KMail::Util::addQActionHelpText(act, prettyUrl);
640 mMailingListActionMenu->addAction(act);
643 void MessageActions::editCurrentMessage()
645 KMCommand *command = Q_NULLPTR;
646 if (mCurrentItem.isValid()) {
647 Akonadi::Collection col = mCurrentItem.parentCollection();
648 qCDebug(KMAIL_LOG) << " mCurrentItem.parentCollection()" << mCurrentItem.parentCollection();
649 // edit, unlike send again, removes the message from the folder
650 // we only want that for templates and drafts folders
651 if (col.isValid()
652 && (CommonKernel->folderIsDraftOrOutbox(col) ||
653 CommonKernel->folderIsTemplates(col))
655 command = new KMEditItemCommand(mParent, mCurrentItem, true);
656 } else {
657 command = new KMEditItemCommand(mParent, mCurrentItem, false);
659 command->start();
660 } else if (mCurrentItem.hasPayload<KMime::Message::Ptr>()) {
661 command = new KMEditMessageCommand(mParent, mCurrentItem.payload<KMime::Message::Ptr>());
662 command->start();
666 void MessageActions::annotateMessage()
668 if (!mCurrentItem.isValid()) {
669 return;
672 PimCommon::AnnotationEditDialog *dialog = new PimCommon::AnnotationEditDialog(mCurrentItem);
673 dialog->setAttribute(Qt::WA_DeleteOnClose);
674 dialog->exec();
677 void MessageActions::addWebShortcutsMenu(QMenu *menu, const QString &text)
679 mWebShortcutMenuManager->setSelectedText(text);
680 mWebShortcutMenuManager->addWebShortcutsToMenu(menu);
683 QAction *MessageActions::debugBalooAction() const
685 return mDebugBalooAction;
688 QAction *MessageActions::addFollowupReminderAction() const
690 return mAddFollowupReminderAction;
693 void MessageActions::slotDebugBaloo()
695 if (!mCurrentItem.isValid()) {
696 return;
698 QPointer<Akonadi::Search::AkonadiSearchDebugDialog> dlg = new Akonadi::Search::AkonadiSearchDebugDialog;
699 dlg->setAkonadiId(mCurrentItem.id());
700 dlg->setAttribute(Qt::WA_DeleteOnClose);
701 dlg->setSearchType(Akonadi::Search::AkonadiSearchDebugSearchPathComboBox::Emails);
702 dlg->doSearch();
703 dlg->show();
706 void MessageActions::slotAddFollowupReminder()
708 if (!mCurrentItem.isValid()) {
709 return;
712 QPointer<MessageComposer::FollowUpReminderSelectDateDialog> dlg = new MessageComposer::FollowUpReminderSelectDateDialog;
713 if (dlg->exec()) {
714 const QDate date = dlg->selectedDate();
715 CreateFollowupReminderOnExistingMessageJob *job = new CreateFollowupReminderOnExistingMessageJob(this);
716 job->setDate(date);
717 job->setCollection(dlg->collection());
718 job->setMessageItem(mCurrentItem);
719 job->start();
721 delete dlg;