Fix Bug 359872 - Big icon when trying to drag a attached pdf file
[kdepim.git] / kmail / kmcommands.h
blobf8092bdde76fe81037ac2dc8c4014144c5d7d967
1 //
3 #ifndef KMCommands_h
4 #define KMCommands_h
6 #include "MessageComposer/MessageFactory"
7 #include "MessageList/View"
8 #include "mailcommon/searchpattern.h"
9 #include "messageviewer/viewer.h"
11 #include <Akonadi/KMime/MessageStatus>
12 #include <kio/job.h>
13 #include <kmime/kmime_message.h>
15 #include <QPointer>
16 #include <QList>
17 #include <AkonadiCore/item.h>
18 #include <AkonadiCore/itemfetchscope.h>
19 #include <AkonadiCore/collection.h>
20 #include <QUrl>
21 namespace Akonadi
23 class Tag;
26 using Akonadi::MessageStatus;
28 class QProgressDialog;
29 class KMMainWidget;
31 template <typename T> class QSharedPointer;
33 namespace MessageViewer
35 class HeaderStyle;
36 class AttachmentStrategy;
39 namespace KIO
41 class Job;
43 namespace KMail
45 class Composer;
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
52 Q_OBJECT
54 public:
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.
63 virtual ~KMCommand();
65 /** Returns the result of the command. Only call this method from the slot
66 connected to completed().
68 Result result() const;
70 public Q_SLOTS:
71 // Retrieve messages then calls execute
72 void start();
74 Q_SIGNALS:
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);
82 protected:
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()
88 return mFetchScope;
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
111 the signal
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);
120 private:
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();
128 private Q_SLOTS:
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();
137 protected:
138 Akonadi::Item::List mRetrievedMsgs;
140 private:
141 // ProgressDialog for transferring messages
142 QWeakPointer<QProgressDialog> mProgressDialog;
143 //Currently only one async command allowed at a time
144 static int mCountJobs;
145 int mCountMsgs;
146 Result mResult;
147 bool mDeletesItself : 1;
148 bool mEmitsCompletedItself : 1;
150 QWidget *mParent;
151 Akonadi::Item::List mMsgList;
152 Akonadi::ItemFetchScope mFetchScope;
155 class KMMailtoComposeCommand : public KMCommand
157 Q_OBJECT
159 public:
160 explicit KMMailtoComposeCommand(const QUrl &url, const Akonadi::Item &msg = Akonadi::Item());
162 private:
163 Result execute() Q_DECL_OVERRIDE;
165 QUrl mUrl;
166 Akonadi::Item mMessage;
169 class KMMailtoReplyCommand : public KMCommand
171 Q_OBJECT
173 public:
174 KMMailtoReplyCommand(QWidget *parent, const QUrl &url,
175 const Akonadi::Item &msg, const QString &selection);
177 private:
178 Result execute() Q_DECL_OVERRIDE;
180 QUrl mUrl;
181 QString mSelection;
184 class KMMailtoForwardCommand : public KMCommand
186 Q_OBJECT
188 public:
189 KMMailtoForwardCommand(QWidget *parent, const QUrl &url, const Akonadi::Item &msg);
191 private:
192 Result execute() Q_DECL_OVERRIDE;
193 QUrl mUrl;
196 class KMAddBookmarksCommand : public KMCommand
198 Q_OBJECT
200 public:
201 KMAddBookmarksCommand(const QUrl &url, QWidget *parent);
203 private:
204 Result execute() Q_DECL_OVERRIDE;
206 QUrl mUrl;
209 class KMUrlSaveCommand : public KMCommand
211 Q_OBJECT
213 public:
214 KMUrlSaveCommand(const QUrl &url, QWidget *parent);
216 private Q_SLOTS:
217 void slotUrlSaveResult(KJob *job);
219 private:
220 Result execute() Q_DECL_OVERRIDE;
222 QUrl mUrl;
225 class KMEditItemCommand : public KMCommand
227 Q_OBJECT
229 public:
230 explicit KMEditItemCommand(QWidget *parent, const Akonadi::Item &msg, bool deleteFromSource = true);
231 ~KMEditItemCommand();
232 private Q_SLOTS:
233 void slotDeleteItem(KJob *job);
234 private:
235 Result execute() Q_DECL_OVERRIDE;
236 bool mDeleteFromSource;
239 class KMEditMessageCommand : public KMCommand
241 Q_OBJECT
243 public:
244 explicit KMEditMessageCommand(QWidget *parent, const KMime::Message::Ptr &msg);
245 private:
246 Result execute() Q_DECL_OVERRIDE;
247 KMime::Message::Ptr mMessage;
250 class KMUseTemplateCommand : public KMCommand
252 Q_OBJECT
254 public:
255 KMUseTemplateCommand(QWidget *parent, const Akonadi::Item &msg);
257 private:
258 Result execute() Q_DECL_OVERRIDE;
261 class KMSaveMsgCommand : public KMCommand
263 Q_OBJECT
265 public:
266 KMSaveMsgCommand(QWidget *parent, const Akonadi::Item::List &msgList);
268 private:
269 Result execute() Q_DECL_OVERRIDE;
273 class KMOpenMsgCommand : public KMCommand
275 Q_OBJECT
277 public:
278 explicit KMOpenMsgCommand(QWidget *parent, const QUrl &url = QUrl(),
279 const QString &encoding = QString(), KMMainWidget *main = Q_NULLPTR);
281 private:
282 Result execute() Q_DECL_OVERRIDE;
284 private Q_SLOTS:
285 void slotDataArrived(KIO::Job *job, const QByteArray &data);
286 void slotResult(KJob *job);
288 private:
289 void doesNotContainMessage();
290 static const int MAX_CHUNK_SIZE = 64 * 1024;
291 QUrl mUrl;
292 QString mMsgString;
293 KIO::TransferJob *mJob;
294 const QString mEncoding;
295 KMMainWidget *mMainWidget;
298 class KMSaveAttachmentsCommand : public KMCommand
300 Q_OBJECT
301 public:
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);
313 private:
314 Result execute() Q_DECL_OVERRIDE;
315 MessageViewer::Viewer *mViewer;
318 class KMReplyCommand : public KMCommand
320 Q_OBJECT
321 public:
322 KMReplyCommand(QWidget *parent, const Akonadi::Item &msg,
323 MessageComposer::ReplyStrategy replyStrategy,
324 const QString &selection = QString(), bool noquote = false, const QString &templateName = QString());
325 private:
326 Result execute() Q_DECL_OVERRIDE;
328 private:
329 QString mSelection;
330 QString mTemplate;
331 MessageComposer::ReplyStrategy m_replyStrategy;
332 bool mNoQuote;
335 class KMForwardCommand : public KMCommand
337 Q_OBJECT
339 public:
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());
345 private:
346 KMCommand::Result createComposer(const Akonadi::Item &item);
347 Result execute() Q_DECL_OVERRIDE;
349 private:
350 uint mIdentity;
351 QString mTemplate;
354 class KMForwardAttachedCommand : public KMCommand
356 Q_OBJECT
358 public:
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);
364 private:
365 Result execute() Q_DECL_OVERRIDE;
367 uint mIdentity;
368 QPointer<KMail::Composer> mWin;
371 class KMRedirectCommand : public KMCommand
373 Q_OBJECT
375 public:
376 KMRedirectCommand(QWidget *parent, const Akonadi::Item &msg);
377 KMRedirectCommand(QWidget *parent, const Akonadi::Item::List &msgList);
379 private:
380 Result execute() Q_DECL_OVERRIDE;
383 class KMPrintCommand : public KMCommand
385 Q_OBJECT
387 public:
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);
399 private:
400 Result execute() Q_DECL_OVERRIDE;
402 MessageViewer::HeaderStylePlugin *mHeaderStylePlugin;
403 const MessageViewer::AttachmentStrategy *mAttachmentStrategy;
404 QFont mOverrideFont;
405 QString mEncoding;
406 MessageViewer::Viewer::DisplayFormatMessage mFormat;
407 bool mHtmlLoadExtOverride;
408 bool mUseFixedFont;
409 bool mPrintPreview;
412 class KMSetStatusCommand : public KMCommand
414 Q_OBJECT
416 public:
417 // Serial numbers
418 KMSetStatusCommand(const MessageStatus &status, const Akonadi::Item::List &items,
419 bool invert = false);
421 protected Q_SLOTS:
422 void slotModifyItemDone(KJob *job);
424 private:
425 Result execute() Q_DECL_OVERRIDE;
426 MessageStatus mStatus;
427 bool mInvertMark;
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
435 Q_OBJECT
437 public:
438 enum SetTagMode { AddIfNotExisting, Toggle, CleanExistingAndAddNew };
440 KMSetTagCommand(const Akonadi::Tag::List &tags, const Akonadi::Item::List &item,
441 SetTagMode mode = AddIfNotExisting);
443 protected Q_SLOTS:
444 void slotModifyItemDone(KJob *job);
446 private:
447 Result execute() Q_DECL_OVERRIDE;
448 void setTags();
450 Akonadi::Tag::List mTags;
451 Akonadi::Tag::List mCreatedTags;
452 Akonadi::Item::List mItem;
453 SetTagMode mMode;
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
460 Q_OBJECT
462 public:
463 KMFilterActionCommand(QWidget *parent,
464 const QVector<qlonglong> &msgListId, const QString &filterId);
466 private:
467 Result execute() Q_DECL_OVERRIDE;
468 QVector<qlonglong> mMsgListId;
469 QString mFilterId;
472 class KMMetaFilterActionCommand : public QObject
474 Q_OBJECT
476 public:
477 KMMetaFilterActionCommand(const QString &filterId, KMMainWidget *main);
479 public Q_SLOTS:
480 void start();
482 private:
483 QString mFilterId;
484 KMMainWidget *mMainWidget;
487 class KMMailingListFilterCommand : public KMCommand
489 Q_OBJECT
491 public:
492 KMMailingListFilterCommand(QWidget *parent, const Akonadi::Item &msg);
494 private:
495 Result execute() Q_DECL_OVERRIDE;
498 class KMCopyCommand : public KMCommand
500 Q_OBJECT
502 public:
503 KMCopyCommand(const Akonadi::Collection &destFolder, const Akonadi::Item::List &msgList);
504 KMCopyCommand(const Akonadi::Collection &destFolder, const Akonadi::Item &msg);
506 protected Q_SLOTS:
507 void slotCopyResult(KJob *job);
508 private:
509 Result execute() Q_DECL_OVERRIDE;
511 Akonadi::Collection mDestFolder;
514 namespace KPIM
516 class ProgressItem;
518 class KMMoveCommand : public KMCommand
520 Q_OBJECT
522 public:
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
527 return mDestFolder;
530 MessageList::Core::MessageItemSetReference refSet() const
532 return mRef;
535 public Q_SLOTS:
536 void slotMoveCanceled();
537 void slotMoveResult(KJob *job);
538 protected:
539 void setDestFolder(const Akonadi::Collection &folder)
541 mDestFolder = folder;
544 Q_SIGNALS:
545 void moveDone(KMMoveCommand *);
547 private:
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
558 Q_OBJECT
560 public:
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);
564 private:
565 static Akonadi::Collection findTrashFolder(const Akonadi::Collection &srcFolder);
569 class KMResendMessageCommand : public KMCommand
571 Q_OBJECT
573 public:
574 explicit KMResendMessageCommand(QWidget *parent, const Akonadi::Item &msg = Akonadi::Item());
576 private:
577 Result execute() Q_DECL_OVERRIDE;
580 class KMShareImageCommand : public KMCommand
582 Q_OBJECT
584 public:
585 explicit KMShareImageCommand(const QUrl &url, QWidget *parent);
587 private:
588 Result execute() Q_DECL_OVERRIDE;
589 QUrl mUrl;
592 class KMFetchMessageCommand : public KMCommand
594 Q_OBJECT
595 public:
596 explicit KMFetchMessageCommand(QWidget *parent, const Akonadi::Item &item);
598 Akonadi::Item item() const;
600 private:
601 Akonadi::ItemFetchJob *createFetchJob(const Akonadi::Item::List &items) Q_DECL_OVERRIDE;
602 Result execute() Q_DECL_OVERRIDE;
604 Akonadi::Item mItem;
607 #endif /*KMCommands_h*/