6 #include "MessageComposer/MessageFactory"
7 #include "MessageList/View"
8 #include "mailcommon/searchpattern.h"
9 #include "messageviewer/viewer.h"
11 #include <Akonadi/KMime/MessageStatus>
13 #include <kmime/kmime_message.h>
17 #include <AkonadiCore/item.h>
18 #include <AkonadiCore/itemfetchscope.h>
19 #include <AkonadiCore/collection.h>
26 using Akonadi::MessageStatus
;
28 class QProgressDialog
;
31 template <typename T
> class QSharedPointer
;
33 namespace MessageViewer
36 class AttachmentStrategy
;
47 typedef QMap
<KMime::Content
*, Akonadi::Item
> PartNodeMessageMap
;
48 /// Small helper structure which encapsulates the KMMessage created when creating a reply, and
50 class KMCommand
: public QObject
55 enum Result
{ Undefined
, OK
, Canceled
, Failed
};
57 // Trival constructor, don't retrieve any messages
58 explicit KMCommand(QWidget
*parent
= Q_NULLPTR
);
59 KMCommand(QWidget
*parent
, const Akonadi::Item
&);
60 // Retrieve all messages in msgList when start is called.
61 KMCommand(QWidget
*parent
, const Akonadi::Item::List
&msgList
);
62 // Retrieve the single message msgBase when start is called.
65 /** Returns the result of the command. Only call this method from the slot
66 connected to completed().
68 Result
result() const;
71 // Retrieve messages then calls execute
76 /// @param result The status of the command.
77 void messagesTransfered(KMCommand::Result result
);
79 /// Emitted when the command has completed.
80 void completed(KMCommand
*command
);
83 virtual Akonadi::ItemFetchJob
*createFetchJob(const Akonadi::Item::List
&items
);
85 /** Allows to configure how much data should be retrieved of the messages. */
86 Akonadi::ItemFetchScope
&fetchScope()
91 // Returns list of messages retrieved
92 const Akonadi::Item::List
retrievedMsgs() const;
93 // Returns the single message retrieved
94 Akonadi::Item
retrievedMessage() const;
95 // Returns the parent widget
96 QWidget
*parentWidget() const;
98 bool deletesItself() const;
99 /** Specify whether the subclass takes care of the deletion of the object.
100 By default the base class will delete the object.
101 @param deletesItself true if the subclass takes care of deletion, false
102 if the base class should take care of deletion
104 void setDeletesItself(bool deletesItself
);
106 bool emitsCompletedItself() const;
107 /** Specify whether the subclass takes care of emitting the completed()
108 signal. By default the base class will Q_EMIT this signal.
109 @param emitsCompletedItself true if the subclass emits the completed
110 signal, false if the base class should Q_EMIT
113 void setEmitsCompletedItself(bool emitsCompletedItself
);
115 /** Use this to set the result of the command.
116 @param result The result of the command.
118 void setResult(Result result
);
121 // execute should be implemented by derived classes
122 virtual Result
execute() = 0;
124 /** transfers the list of (imap)-messages
125 * this is a necessary preparation for e.g. forwarding */
126 void transferSelectedMsgs();
129 void slotPostTransfer(KMCommand::Result result
);
130 /** the msg has been transferred */
131 void slotMsgTransfered(const Akonadi::Item::List
&msgs
);
132 /** the KMImapJob is finished */
133 void slotJobFinished();
134 /** the transfer was canceled */
135 void slotTransferCancelled();
138 Akonadi::Item::List mRetrievedMsgs
;
141 // ProgressDialog for transferring messages
142 QWeakPointer
<QProgressDialog
> mProgressDialog
;
143 //Currently only one async command allowed at a time
144 static int mCountJobs
;
147 bool mDeletesItself
: 1;
148 bool mEmitsCompletedItself
: 1;
151 Akonadi::Item::List mMsgList
;
152 Akonadi::ItemFetchScope mFetchScope
;
155 class KMMailtoComposeCommand
: public KMCommand
160 explicit KMMailtoComposeCommand(const QUrl
&url
, const Akonadi::Item
&msg
= Akonadi::Item());
163 Result
execute() Q_DECL_OVERRIDE
;
166 Akonadi::Item mMessage
;
169 class KMMailtoReplyCommand
: public KMCommand
174 KMMailtoReplyCommand(QWidget
*parent
, const QUrl
&url
,
175 const Akonadi::Item
&msg
, const QString
&selection
);
178 Result
execute() Q_DECL_OVERRIDE
;
184 class KMMailtoForwardCommand
: public KMCommand
189 KMMailtoForwardCommand(QWidget
*parent
, const QUrl
&url
, const Akonadi::Item
&msg
);
192 Result
execute() Q_DECL_OVERRIDE
;
196 class KMAddBookmarksCommand
: public KMCommand
201 KMAddBookmarksCommand(const QUrl
&url
, QWidget
*parent
);
204 Result
execute() Q_DECL_OVERRIDE
;
209 class KMUrlSaveCommand
: public KMCommand
214 KMUrlSaveCommand(const QUrl
&url
, QWidget
*parent
);
217 void slotUrlSaveResult(KJob
*job
);
220 Result
execute() Q_DECL_OVERRIDE
;
225 class KMEditItemCommand
: public KMCommand
230 explicit KMEditItemCommand(QWidget
*parent
, const Akonadi::Item
&msg
, bool deleteFromSource
= true);
231 ~KMEditItemCommand();
233 void slotDeleteItem(KJob
*job
);
235 Result
execute() Q_DECL_OVERRIDE
;
236 bool mDeleteFromSource
;
239 class KMEditMessageCommand
: public KMCommand
244 explicit KMEditMessageCommand(QWidget
*parent
, const KMime::Message::Ptr
&msg
);
246 Result
execute() Q_DECL_OVERRIDE
;
247 KMime::Message::Ptr mMessage
;
250 class KMUseTemplateCommand
: public KMCommand
255 KMUseTemplateCommand(QWidget
*parent
, const Akonadi::Item
&msg
);
258 Result
execute() Q_DECL_OVERRIDE
;
261 class KMSaveMsgCommand
: public KMCommand
266 KMSaveMsgCommand(QWidget
*parent
, const Akonadi::Item::List
&msgList
);
269 Result
execute() Q_DECL_OVERRIDE
;
273 class KMOpenMsgCommand
: public KMCommand
278 explicit KMOpenMsgCommand(QWidget
*parent
, const QUrl
&url
= QUrl(),
279 const QString
&encoding
= QString(), KMMainWidget
*main
= Q_NULLPTR
);
282 Result
execute() Q_DECL_OVERRIDE
;
285 void slotDataArrived(KIO::Job
*job
, const QByteArray
&data
);
286 void slotResult(KJob
*job
);
289 void doesNotContainMessage();
290 static const int MAX_CHUNK_SIZE
= 64 * 1024;
293 KIO::TransferJob
*mJob
;
294 const QString mEncoding
;
295 KMMainWidget
*mMainWidget
;
298 class KMSaveAttachmentsCommand
: public KMCommand
302 /** Use this to save all attachments of the given message.
303 @param parent The parent widget of the command used for message boxes.
304 @param msg The message of which the attachments should be saved.
306 KMSaveAttachmentsCommand(QWidget
*parent
, const Akonadi::Item
&msg
, MessageViewer::Viewer
*viewer
);
307 /** Use this to save all attachments of the given messages.
308 @param parent The parent widget of the command used for message boxes.
309 @param msgs The messages of which the attachments should be saved.
311 KMSaveAttachmentsCommand(QWidget
*parent
, const Akonadi::Item::List
&msgs
);
314 Result
execute() Q_DECL_OVERRIDE
;
315 MessageViewer::Viewer
*mViewer
;
318 class KMReplyCommand
: public KMCommand
322 KMReplyCommand(QWidget
*parent
, const Akonadi::Item
&msg
,
323 MessageComposer::ReplyStrategy replyStrategy
,
324 const QString
&selection
= QString(), bool noquote
= false, const QString
&templateName
= QString());
326 Result
execute() Q_DECL_OVERRIDE
;
331 MessageComposer::ReplyStrategy m_replyStrategy
;
335 class KMForwardCommand
: public KMCommand
340 KMForwardCommand(QWidget
*parent
, const Akonadi::Item::List
&msgList
,
341 uint identity
= 0, const QString
&templateName
= QString());
342 KMForwardCommand(QWidget
*parent
, const Akonadi::Item
&msg
,
343 uint identity
= 0, const QString
&templateName
= QString());
346 KMCommand::Result
createComposer(const Akonadi::Item
&item
);
347 Result
execute() Q_DECL_OVERRIDE
;
354 class KMForwardAttachedCommand
: public KMCommand
359 KMForwardAttachedCommand(QWidget
*parent
, const Akonadi::Item::List
&msgList
,
360 uint identity
= 0, KMail::Composer
*win
= Q_NULLPTR
);
361 KMForwardAttachedCommand(QWidget
*parent
, const Akonadi::Item
&msg
,
362 uint identity
= 0, KMail::Composer
*win
= Q_NULLPTR
);
365 Result
execute() Q_DECL_OVERRIDE
;
368 QPointer
<KMail::Composer
> mWin
;
371 class KMRedirectCommand
: public KMCommand
376 KMRedirectCommand(QWidget
*parent
, const Akonadi::Item
&msg
);
377 KMRedirectCommand(QWidget
*parent
, const Akonadi::Item::List
&msgList
);
380 Result
execute() Q_DECL_OVERRIDE
;
383 class KMPrintCommand
: public KMCommand
388 KMPrintCommand(QWidget
*parent
, const Akonadi::Item
&msg
,
389 MessageViewer::HeaderStylePlugin
*plugin
= Q_NULLPTR
,
390 MessageViewer::Viewer::DisplayFormatMessage format
= MessageViewer::Viewer::UseGlobalSetting
,
391 bool htmlLoadExtOverride
= false,
392 bool useFixedFont
= false,
393 const QString
&encoding
= QString());
395 void setOverrideFont(const QFont
&);
396 void setAttachmentStrategy(const MessageViewer::AttachmentStrategy
*strategy
);
397 void setPrintPreview(bool preview
);
400 Result
execute() Q_DECL_OVERRIDE
;
402 MessageViewer::HeaderStylePlugin
*mHeaderStylePlugin
;
403 const MessageViewer::AttachmentStrategy
*mAttachmentStrategy
;
406 MessageViewer::Viewer::DisplayFormatMessage mFormat
;
407 bool mHtmlLoadExtOverride
;
412 class KMSetStatusCommand
: public KMCommand
418 KMSetStatusCommand(const MessageStatus
&status
, const Akonadi::Item::List
&items
,
419 bool invert
= false);
422 void slotModifyItemDone(KJob
*job
);
425 Result
execute() Q_DECL_OVERRIDE
;
426 MessageStatus mStatus
;
430 /** This command is used to set or toggle a tag for a list of messages. If toggle is
431 true then the tag is deleted if it is already applied.
433 class KMSetTagCommand
: public KMCommand
438 enum SetTagMode
{ AddIfNotExisting
, Toggle
, CleanExistingAndAddNew
};
440 KMSetTagCommand(const Akonadi::Tag::List
&tags
, const Akonadi::Item::List
&item
,
441 SetTagMode mode
= AddIfNotExisting
);
444 void slotModifyItemDone(KJob
*job
);
447 Result
execute() Q_DECL_OVERRIDE
;
450 Akonadi::Tag::List mTags
;
451 Akonadi::Tag::List mCreatedTags
;
452 Akonadi::Item::List mItem
;
456 /* This command is used to apply a single filter (AKA ad-hoc filter)
457 to a set of messages */
458 class KMFilterActionCommand
: public KMCommand
463 KMFilterActionCommand(QWidget
*parent
,
464 const QVector
<qlonglong
> &msgListId
, const QString
&filterId
);
467 Result
execute() Q_DECL_OVERRIDE
;
468 QVector
<qlonglong
> mMsgListId
;
472 class KMMetaFilterActionCommand
: public QObject
477 KMMetaFilterActionCommand(const QString
&filterId
, KMMainWidget
*main
);
484 KMMainWidget
*mMainWidget
;
487 class KMMailingListFilterCommand
: public KMCommand
492 KMMailingListFilterCommand(QWidget
*parent
, const Akonadi::Item
&msg
);
495 Result
execute() Q_DECL_OVERRIDE
;
498 class KMCopyCommand
: public KMCommand
503 KMCopyCommand(const Akonadi::Collection
&destFolder
, const Akonadi::Item::List
&msgList
);
504 KMCopyCommand(const Akonadi::Collection
&destFolder
, const Akonadi::Item
&msg
);
507 void slotCopyResult(KJob
*job
);
509 Result
execute() Q_DECL_OVERRIDE
;
511 Akonadi::Collection mDestFolder
;
518 class KMMoveCommand
: public KMCommand
523 KMMoveCommand(const Akonadi::Collection
&destFolder
, const Akonadi::Item::List
&msgList
, MessageList::Core::MessageItemSetReference ref
);
524 KMMoveCommand(const Akonadi::Collection
&destFolder
, const Akonadi::Item
&msg
, MessageList::Core::MessageItemSetReference ref
= MessageList::Core::MessageItemSetReference());
525 Akonadi::Collection
destFolder() const
530 MessageList::Core::MessageItemSetReference
refSet() const
536 void slotMoveCanceled();
537 void slotMoveResult(KJob
*job
);
539 void setDestFolder(const Akonadi::Collection
&folder
)
541 mDestFolder
= folder
;
545 void moveDone(KMMoveCommand
*);
548 Result
execute() Q_DECL_OVERRIDE
;
549 void completeMove(Result result
);
551 Akonadi::Collection mDestFolder
;
552 KPIM::ProgressItem
*mProgressItem
;
553 MessageList::Core::MessageItemSetReference mRef
;
556 class KMTrashMsgCommand
: public KMMoveCommand
561 KMTrashMsgCommand(const Akonadi::Collection
&srcFolder
, const Akonadi::Item::List
&msgList
, MessageList::Core::MessageItemSetReference ref
);
562 KMTrashMsgCommand(const Akonadi::Collection
&srcFolder
, const Akonadi::Item
&msg
, MessageList::Core::MessageItemSetReference ref
);
565 static Akonadi::Collection
findTrashFolder(const Akonadi::Collection
&srcFolder
);
569 class KMResendMessageCommand
: public KMCommand
574 explicit KMResendMessageCommand(QWidget
*parent
, const Akonadi::Item
&msg
= Akonadi::Item());
577 Result
execute() Q_DECL_OVERRIDE
;
580 class KMShareImageCommand
: public KMCommand
585 explicit KMShareImageCommand(const QUrl
&url
, QWidget
*parent
);
588 Result
execute() Q_DECL_OVERRIDE
;
592 class KMFetchMessageCommand
: public KMCommand
596 explicit KMFetchMessageCommand(QWidget
*parent
, const Akonadi::Item
&item
);
598 Akonadi::Item
item() const;
601 Akonadi::ItemFetchJob
*createFetchJob(const Akonadi::Item::List
&items
) Q_DECL_OVERRIDE
;
602 Result
execute() Q_DECL_OVERRIDE
;
607 #endif /*KMCommands_h*/