The last part of typo fixes (I really hope)
[kdepim.git] / kmail / kmcommands.h
blob22113cf7d65d2407e914cfde0ed5cac5de01cc52
1 // -*- mode: C++; c-file-style: "gnu" -*-
3 #ifndef KMCommands_h
4 #define KMCommands_h
6 #include "kmail_export.h"
7 #include <kmime/kmime_message.h>
8 #include "messageviewer/viewer.h"
9 #include "messageviewer/editorwatcher.h"
10 #include "messageviewer/headerstrategy.h"
11 #include "messageviewer/headerstyle.h"
12 using MessageViewer::EditorWatcher;
13 #include <akonadi/kmime/messagestatus.h>
14 #include <messagelist/core/view.h>
15 using Akonadi::MessageStatus;
16 #include <kservice.h>
17 #include <ktemporaryfile.h>
18 #include <kio/job.h>
20 #include <QPointer>
21 #include <QList>
22 #include <akonadi/item.h>
23 #include <akonadi/itemfetchscope.h>
24 #include <akonadi/collection.h>
25 class KProgressDialog;
26 class KMMainWidget;
28 namespace MailCommon {
29 class FolderCollection;
30 class MailFilter;
33 template <typename T> class QSharedPointer;
35 namespace KIO { class Job; }
36 namespace KMail {
37 class Composer;
39 namespace GpgME { class Error; }
40 namespace Kleo { class SpecialJob; }
42 typedef QMap<KMime::Content*, Akonadi::Item> PartNodeMessageMap;
43 /// Small helper structure which encapsulates the KMMessage created when creating a reply, and
45 class KMAIL_EXPORT KMCommand : public QObject
47 Q_OBJECT
49 public:
50 enum Result { Undefined, OK, Canceled, Failed };
52 // Trival constructor, don't retrieve any messages
53 KMCommand( QWidget *parent = 0 );
54 KMCommand( QWidget *parent, const Akonadi::Item & );
55 // Retrieve all messages in msgList when start is called.
56 KMCommand( QWidget *parent, const QList<Akonadi::Item> &msgList );
57 // Retrieve the single message msgBase when start is called.
58 virtual ~KMCommand();
61 /** Returns the result of the command. Only call this method from the slot
62 connected to completed().
64 Result result() const;
66 public slots:
67 // Retrieve messages then calls execute
68 void start();
70 signals:
72 /// @param result The status of the command.
73 void messagesTransfered( KMCommand::Result result );
75 /// Emitted when the command has completed.
76 void completed( KMCommand *command );
78 protected:
79 /** Allows to configure how much data should be retrieved of the messages. */
80 Akonadi::ItemFetchScope& fetchScope() { return mFetchScope; }
82 // Returns list of messages retrieved
83 const QList<Akonadi::Item> retrievedMsgs() const;
84 // Returns the single message retrieved
85 Akonadi::Item retrievedMessage() const;
86 // Returns the parent widget
87 QWidget *parentWidget() const;
89 bool deletesItself() const { return mDeletesItself; }
90 /** Specify whether the subclass takes care of the deletion of the object.
91 By default the base class will delete the object.
92 @param deletesItself true if the subclass takes care of deletion, false
93 if the base class should take care of deletion
95 void setDeletesItself( bool deletesItself )
96 { mDeletesItself = deletesItself; }
98 bool emitsCompletedItself() const { return mEmitsCompletedItself; }
99 /** Specify whether the subclass takes care of emitting the completed()
100 signal. By default the base class will emit this signal.
101 @param emitsCompletedItself true if the subclass emits the completed
102 signal, false if the base class should emit
103 the signal
105 void setEmitsCompletedItself( bool emitsCompletedItself )
106 { mEmitsCompletedItself = emitsCompletedItself; }
108 /** Use this to set the result of the command.
109 @param result The result of the command.
111 void setResult( Result result )
112 { mResult = result; }
114 private:
115 // execute should be implemented by derived classes
116 virtual Result execute() = 0;
118 /** transfers the list of (imap)-messages
119 * this is a necessary preparation for e.g. forwarding */
120 void transferSelectedMsgs();
122 private slots:
123 void slotPostTransfer( KMCommand::Result result );
124 /** the msg has been transferred */
125 void slotMsgTransfered(const Akonadi::Item::List& msgs);
126 /** the KMImapJob is finished */
127 void slotJobFinished();
128 /** the transfer was canceled */
129 void slotTransferCancelled();
131 protected:
132 QList<Akonadi::Item> mRetrievedMsgs;
134 private:
135 // ProgressDialog for transferring messages
136 KProgressDialog* mProgressDialog;
137 //Currently only one async command allowed at a time
138 static int mCountJobs;
139 int mCountMsgs;
140 Result mResult;
141 bool mDeletesItself : 1;
142 bool mEmitsCompletedItself : 1;
144 QWidget *mParent;
145 QList<Akonadi::Item> mMsgList;
146 Akonadi::ItemFetchScope mFetchScope;
149 class KMAIL_EXPORT KMMailtoComposeCommand : public KMCommand
151 Q_OBJECT
153 public:
154 explicit KMMailtoComposeCommand( const KUrl &url, const Akonadi::Item &msg=Akonadi::Item() );
156 private:
157 virtual Result execute();
159 KUrl mUrl;
160 Akonadi::Item mMessage;
163 class KMAIL_EXPORT KMMailtoReplyCommand : public KMCommand
165 Q_OBJECT
167 public:
168 KMMailtoReplyCommand( QWidget *parent, const KUrl &url,
169 const Akonadi::Item &msg, const QString &selection );
171 private:
172 virtual Result execute();
174 KUrl mUrl;
175 QString mSelection;
178 class KMAIL_EXPORT KMMailtoForwardCommand : public KMCommand
180 Q_OBJECT
182 public:
183 KMMailtoForwardCommand( QWidget *parent, const KUrl &url,const Akonadi::Item& msg );
185 private:
186 virtual Result execute();
188 KUrl mUrl;
191 class KMAIL_EXPORT KMAddBookmarksCommand : public KMCommand
193 Q_OBJECT
195 public:
196 KMAddBookmarksCommand( const KUrl &url, QWidget *parent );
198 private:
199 virtual Result execute();
201 KUrl mUrl;
204 class KMAIL_EXPORT KMUrlSaveCommand : public KMCommand
206 Q_OBJECT
208 public:
209 KMUrlSaveCommand( const KUrl &url, QWidget *parent );
211 private slots:
212 void slotUrlSaveResult( KJob *job );
214 private:
215 virtual Result execute();
217 KUrl mUrl;
220 class KMAIL_EXPORT KMEditMsgCommand : public KMCommand
222 Q_OBJECT
224 public:
225 KMEditMsgCommand( QWidget *parent, const Akonadi::Item &msg, bool deleteFromSource = true );
226 private slots:
227 void slotDeleteItem( KJob *job );
228 private:
229 virtual Result execute();
230 bool mDeleteFromSource;
233 class KMAIL_EXPORT KMUseTemplateCommand : public KMCommand
235 Q_OBJECT
237 public:
238 KMUseTemplateCommand( QWidget *parent, const Akonadi::Item &msg );
240 private:
241 virtual Result execute();
244 class KMAIL_EXPORT KMSaveMsgCommand : public KMCommand
246 Q_OBJECT
248 public:
249 KMSaveMsgCommand( QWidget *parent, const QList<Akonadi::Item> &msgList );
250 KMSaveMsgCommand( QWidget *parent, const Akonadi::Item & msg );
251 KUrl url() const;
253 private:
254 virtual Result execute();
256 private:
257 KUrl mUrl;
260 class KMAIL_EXPORT KMOpenMsgCommand : public KMCommand
262 Q_OBJECT
264 public:
265 explicit KMOpenMsgCommand( QWidget *parent, const KUrl & url = KUrl(),
266 const QString & encoding = QString() );
268 private:
269 virtual Result execute();
271 private slots:
272 void slotDataArrived( KIO::Job *job, const QByteArray & data );
273 void slotResult( KJob *job );
275 private:
276 static const int MAX_CHUNK_SIZE = 64*1024;
277 KUrl mUrl;
278 QString mMsgString;
279 KIO::TransferJob *mJob;
280 const QString mEncoding;
283 class KMAIL_EXPORT KMSaveAttachmentsCommand : public KMCommand
285 Q_OBJECT
286 public:
287 /** Use this to save all attachments of the given message.
288 @param parent The parent widget of the command used for message boxes.
289 @param msg The message of which the attachments should be saved.
291 KMSaveAttachmentsCommand( QWidget *parent, const Akonadi::Item &msg );
292 /** Use this to save all attachments of the given messages.
293 @param parent The parent widget of the command used for message boxes.
294 @param msgs The messages of which the attachments should be saved.
296 KMSaveAttachmentsCommand( QWidget *parent, const QList<Akonadi::Item>& msgs );
298 private:
299 virtual Result execute();
302 class KMAIL_EXPORT KMReplyToCommand : public KMCommand
304 Q_OBJECT
306 public:
307 KMReplyToCommand( QWidget *parent, const Akonadi::Item &msg,
308 const QString &selection = QString() );
310 private:
311 virtual Result execute();
313 private:
314 QString mSelection;
317 class KMAIL_EXPORT KMNoQuoteReplyToCommand : public KMCommand
319 Q_OBJECT
321 public:
322 KMNoQuoteReplyToCommand( QWidget *parent, const Akonadi::Item &msg );
324 private:
325 virtual Result execute();
328 class KMReplyListCommand : public KMCommand
330 Q_OBJECT
332 public:
333 KMReplyListCommand( QWidget *parent, const Akonadi::Item &msg,
334 const QString &selection = QString() );
336 private:
337 virtual Result execute();
339 private:
340 QString mSelection;
343 class KMAIL_EXPORT KMReplyToAllCommand : public KMCommand
345 Q_OBJECT
347 public:
348 KMReplyToAllCommand( QWidget *parent, const Akonadi::Item &msg,
349 const QString &selection = QString() );
351 private:
352 virtual Result execute();
354 private:
355 QString mSelection;
358 class KMAIL_EXPORT KMReplyAuthorCommand : public KMCommand
360 Q_OBJECT
362 public:
363 KMReplyAuthorCommand( QWidget *parent, const Akonadi::Item &msg,
364 const QString &selection = QString() );
366 private:
367 virtual Result execute();
369 private:
370 QString mSelection;
373 class KMAIL_EXPORT KMForwardCommand : public KMCommand
375 Q_OBJECT
377 public:
378 KMForwardCommand( QWidget *parent, const QList<Akonadi::Item> &msgList,
379 uint identity = 0 );
380 KMForwardCommand( QWidget *parent, const Akonadi::Item& msg,
381 uint identity = 0 );
383 private:
384 virtual Result execute();
386 private:
387 uint mIdentity;
390 class KMAIL_EXPORT KMForwardAttachedCommand : public KMCommand
392 Q_OBJECT
394 public:
395 KMForwardAttachedCommand( QWidget *parent, const QList<Akonadi::Item> &msgList,
396 uint identity = 0, KMail::Composer *win = 0 );
397 KMForwardAttachedCommand( QWidget *parent, const Akonadi::Item & msg,
398 uint identity = 0, KMail::Composer *win = 0 );
400 private:
401 virtual Result execute();
403 uint mIdentity;
404 QPointer<KMail::Composer> mWin;
407 class KMAIL_EXPORT KMRedirectCommand : public KMCommand
409 Q_OBJECT
411 public:
412 KMRedirectCommand( QWidget *parent, const Akonadi::Item &msg );
414 private:
415 virtual Result execute();
418 class KMAIL_EXPORT KMCustomReplyToCommand : public KMCommand
420 Q_OBJECT
422 public:
423 KMCustomReplyToCommand( QWidget *parent, const Akonadi::Item &msg,
424 const QString &selection,
425 const QString &tmpl );
427 private:
428 virtual Result execute();
430 private:
431 QString mSelection;
432 QString mTemplate;
435 class KMAIL_EXPORT KMCustomReplyAllToCommand : public KMCommand
437 Q_OBJECT
439 public:
440 KMCustomReplyAllToCommand( QWidget *parent, const Akonadi::Item &msg,
441 const QString &selection,
442 const QString &tmpl );
444 private:
445 virtual Result execute();
447 private:
448 QString mSelection;
449 QString mTemplate;
452 class KMAIL_EXPORT KMCustomForwardCommand : public KMCommand
454 Q_OBJECT
456 public:
457 KMCustomForwardCommand( QWidget *parent, const QList<Akonadi::Item> &msgList,
458 uint identity, const QString &tmpl );
459 KMCustomForwardCommand( QWidget *parent, const Akonadi::Item& msg,
460 uint identity, const QString &tmpl );
462 private:
463 virtual Result execute();
465 uint mIdentity;
466 QString mTemplate;
469 class KMAIL_EXPORT KMPrintCommand : public KMCommand
471 Q_OBJECT
473 public:
474 KMPrintCommand( QWidget *parent, const Akonadi::Item &msg,
475 MessageViewer::HeaderStyle *headerStyle = 0,
476 const MessageViewer::HeaderStrategy *headerStrategy = 0,
477 bool htmlOverride = false,
478 bool htmlLoadExtOverride = false,
479 bool useFixedFont = false,
480 const QString & encoding = QString() );
482 void setOverrideFont( const QFont& );
483 void setAttachmentStrategy( const MessageViewer::AttachmentStrategy *strategy );
485 private:
486 virtual Result execute();
488 MessageViewer::HeaderStyle *mHeaderStyle;
489 const MessageViewer::HeaderStrategy *mHeaderStrategy;
490 const MessageViewer::AttachmentStrategy *mAttachmentStrategy;
491 bool mHtmlOverride;
492 bool mHtmlLoadExtOverride;
493 bool mUseFixedFont;
494 QFont mOverrideFont;
495 QString mEncoding;
498 class KMAIL_EXPORT KMSetStatusCommand : public KMCommand
500 Q_OBJECT
502 public:
503 // Serial numbers
504 KMSetStatusCommand( const MessageStatus& status, const Akonadi::Item::List &items,
505 bool invert=false );
507 protected slots:
508 void slotModifyItemDone( KJob * job );
510 private:
511 virtual Result execute();
512 MessageStatus mStatus;
513 bool mInvertMark;
516 /** This command is used to set or toggle a tag for a list of messages. If toggle is
517 true then the tag is deleted if it is already applied.
519 class KMAIL_EXPORT KMSetTagCommand : public KMCommand
521 Q_OBJECT
523 public:
524 enum SetTagMode { AddIfNotExisting, Toggle };
526 KMSetTagCommand( const QString &tagLabel, const QList<Akonadi::Item> &item,
527 SetTagMode mode=AddIfNotExisting );
529 private:
530 virtual Result execute();
532 QString mTagLabel;
533 QList<Akonadi::Item> mItem;
534 SetTagMode mMode;
537 /* This command is used to create a filter based on the user's
538 decision, e.g. filter by From header */
539 class KMAIL_EXPORT KMFilterCommand : public KMCommand
541 Q_OBJECT
543 public:
544 KMFilterCommand( const QByteArray &field, const QString &value );
546 private:
547 virtual Result execute();
549 QByteArray mField;
550 QString mValue;
554 /* This command is used to apply a single filter (AKA ad-hoc filter)
555 to a set of messages */
556 class KMAIL_EXPORT KMFilterActionCommand : public KMCommand
558 Q_OBJECT
560 public:
561 KMFilterActionCommand( QWidget *parent,
562 const QList<Akonadi::Item> &msgList, MailCommon::MailFilter *filter );
564 private:
565 virtual Result execute();
566 MailCommon::MailFilter *mFilter;
570 class KMAIL_EXPORT KMMetaFilterActionCommand : public QObject
572 Q_OBJECT
574 public:
575 KMMetaFilterActionCommand( MailCommon::MailFilter *filter, KMMainWidget *main );
577 public slots:
578 void start();
580 private:
581 MailCommon::MailFilter *mFilter;
582 KMMainWidget *mMainWidget;
586 class KMAIL_EXPORT KMMailingListFilterCommand : public KMCommand
588 Q_OBJECT
590 public:
591 KMMailingListFilterCommand( QWidget *parent, const Akonadi::Item &msg );
593 private:
594 virtual Result execute();
598 class KMAIL_EXPORT KMCopyCommand : public KMCommand
600 Q_OBJECT
602 public:
603 KMCopyCommand( const Akonadi::Collection &destFolder, const QList<Akonadi::Item> &msgList );
604 KMCopyCommand( const Akonadi::Collection& destFolder, const Akonadi::Item &msg );
606 protected slots:
607 void slotCopyResult( KJob * job );
608 private:
609 virtual Result execute();
611 Akonadi::Collection mDestFolder;
612 QList<Akonadi::Item> mMsgList;
615 namespace KPIM {
616 class ProgressItem;
618 class KMAIL_EXPORT KMMoveCommand : public KMCommand
620 Q_OBJECT
622 public:
623 KMMoveCommand( const Akonadi::Collection& destFolder, const QList<Akonadi::Item> &msgList, MessageList::Core::MessageItemSetReference ref );
624 KMMoveCommand( const Akonadi::Collection& destFolder, const Akonadi::Item & msg, MessageList::Core::MessageItemSetReference ref = MessageList::Core::MessageItemSetReference() );
625 Akonadi::Collection destFolder() const { return mDestFolder; }
627 MessageList::Core::MessageItemSetReference refSet() const { return mRef; }
629 public slots:
630 void slotMoveCanceled();
631 void slotMoveResult( KJob * job );
632 protected:
633 void setDestFolder( const Akonadi::Collection& folder ) { mDestFolder = folder; }
635 signals:
636 void moveDone( KMMoveCommand* );
638 private:
639 virtual Result execute();
640 void completeMove( Result result );
642 Akonadi::Collection mDestFolder;
643 KPIM::ProgressItem *mProgressItem;
644 MessageList::Core::MessageItemSetReference mRef;
645 bool mCompleteWithAddedMsg;
648 class KMAIL_EXPORT KMTrashMsgCommand : public KMMoveCommand
650 Q_OBJECT
652 public:
653 KMTrashMsgCommand( const Akonadi::Collection& srcFolder, const QList<Akonadi::Item> &msgList,MessageList::Core::MessageItemSetReference ref );
654 KMTrashMsgCommand( const Akonadi::Collection& srcFolder, const Akonadi::Item& msg,MessageList::Core::MessageItemSetReference ref );
656 private:
657 static Akonadi::Collection findTrashFolder( const Akonadi::Collection& srcFolder );
661 class KMAIL_EXPORT KMResendMessageCommand : public KMCommand
663 Q_OBJECT
665 public:
666 explicit KMResendMessageCommand( QWidget *parent, const Akonadi::Item & msg= Akonadi::Item() );
668 private:
669 virtual Result execute();
672 // TODO: Remove this class. There is no reason why the mailing list stuff should be based
673 // on KMCommand, they should instead be utilty methods.
674 class KMAIL_EXPORT KMMailingListCommand : public KMCommand
676 Q_OBJECT
677 public:
678 KMMailingListCommand( QWidget *parent, const QSharedPointer<MailCommon::FolderCollection> &parentFolder );
679 private:
680 virtual Result execute();
681 protected:
682 virtual KUrl::List urls() const =0;
683 protected:
684 QSharedPointer<MailCommon::FolderCollection> mFolder;
687 class KMAIL_EXPORT KMMailingListPostCommand : public KMMailingListCommand
689 Q_OBJECT
690 public:
691 KMMailingListPostCommand( QWidget *parent, const QSharedPointer<MailCommon::FolderCollection> &parentFolder );
692 protected:
693 virtual KUrl::List urls() const;
696 class KMAIL_EXPORT KMMailingListSubscribeCommand : public KMMailingListCommand
698 Q_OBJECT
699 public:
700 KMMailingListSubscribeCommand( QWidget *parent, const QSharedPointer<MailCommon::FolderCollection> &parentFolder );
701 protected:
702 virtual KUrl::List urls() const;
705 class KMAIL_EXPORT KMMailingListUnsubscribeCommand : public KMMailingListCommand
707 Q_OBJECT
708 public:
709 KMMailingListUnsubscribeCommand( QWidget *parent, const QSharedPointer<MailCommon::FolderCollection> &parentFolder );
710 protected:
711 virtual KUrl::List urls() const;
714 class KMAIL_EXPORT KMMailingListArchivesCommand : public KMMailingListCommand
716 Q_OBJECT
717 public:
718 KMMailingListArchivesCommand( QWidget *parent, const QSharedPointer<MailCommon::FolderCollection> &parentFolder );
719 protected:
720 virtual KUrl::List urls() const;
723 class KMAIL_EXPORT KMMailingListHelpCommand : public KMMailingListCommand
725 Q_OBJECT
726 public:
727 KMMailingListHelpCommand( QWidget *parent, const QSharedPointer<MailCommon::FolderCollection> &parentFolder );
728 protected:
729 virtual KUrl::List urls() const;
732 #endif /*KMCommands_h*/