kmail

actionscheduler.h

Go to the documentation of this file.
00001 /*  -*- mode: C++ -*-
00002     Action Scheduler
00003 
00004     This file is part of KMail, the KDE mail client.
00005     Copyright (c) Don Sanders <sanders@kde.org>
00006 
00007     KMail is free software; you can redistribute it and/or modify it
00008     under the terms of the GNU General Public License, version 2, as
00009     published by the Free Software Foundation.
00010 
00011     KMail is distributed in the hope that it will be useful, but
00012     WITHOUT ANY WARRANTY; without even the implied warranty of
00013     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00014     General Public License for more details.
00015 
00016     You should have received a copy of the GNU General Public License
00017     along with this program; if not, write to the Free Software
00018     Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
00019 
00020     In addition, as a special exception, the copyright holders give
00021     permission to link the code of this program with any edition of
00022     the Qt library by Trolltech AS, Norway (or with modified versions
00023     of Qt that use the same license as Qt), and distribute linked
00024     combinations including the two.  You must obey the GNU General
00025     Public License in all respects for all of the code used other than
00026     Qt.  If you modify this file, you may extend this exception to
00027     your version of the file, but you are not obligated to do so.  If
00028     you do not wish to do so, delete this exception statement from
00029     your version.
00030 */
00031 
00032 #ifndef actionscheduler_h
00033 #define actionscheduler_h
00034 
00035 #include "kmfilteraction.h" // for KMFilterAction::ReturnCode
00036 #include "kmfilter.h"
00037 #include "kmfiltermgr.h" // KMFilterMgr::FilterSet
00038 #include "kmcommands.h"
00039 
00040 #include <qobject.h>
00041 #include <qguardedptr.h>
00042 #include <qtimer.h>
00043 
00044 class KMHeaders;
00045 
00046 namespace KMail {
00047 
00048 /* A class for asynchronous filtering of messages */
00049 class ActionScheduler : public QObject
00050 {
00051   Q_OBJECT
00052 
00053 public:
00054   enum ReturnCode { ResultOk, ResultError, ResultCriticalError };
00055 
00056   ActionScheduler(KMFilterMgr::FilterSet set,
00057           QValueList<KMFilter*> filters,
00058                   KMHeaders *headers = 0,
00059           KMFolder *srcFolder = 0);
00060   ~ActionScheduler();
00061 
00064   void setAutoDestruct( bool );
00065 
00067   void setAlwaysMatch( bool );
00068 
00070   void setDefaultDestinationFolder( KMFolder* );
00071 
00073   void setSourceFolder( KMFolder* );
00074 
00078   void setFilterList( QValueList<KMFilter*> filters );
00079 
00081   void setAccountId( uint id  ) { mAccountId = id; mAccount = true; }
00082 
00084   void clearAccountId() { mAccountId = 0; mAccount = false; }
00085 
00087   void execFilters(const QValueList<Q_UINT32> serNums);
00088   void execFilters(const QPtrList<KMMsgBase> msgList);
00089   void execFilters(KMMsgBase* msgBase);
00090   void execFilters(Q_UINT32 serNum);
00091 
00092   static QString debug();
00093   static bool isEnabled();
00094 
00099   bool ignoreChanges( bool ignore );
00100 
00101 signals:
00103   void result(ReturnCode);
00104   void filtered(Q_UINT32);
00105 
00106 public slots:
00108   void actionMessage(KMFilterAction::ReturnCode = KMFilterAction::GoOn);
00109 
00111   void copyMessageFinished( KMCommand *command );
00112 
00113 private slots:
00114   KMMsgBase* messageBase(Q_UINT32 serNum);
00115   KMMessage* message(Q_UINT32 serNum);
00116   void finish();
00117 
00118   void folderClosedOrExpunged();
00119 
00120   int tempOpenFolder(KMFolder* aFolder);
00121   void tempCloseFolders();
00122 
00123   //Fetching slots
00124   void fetchMessage();
00125   void messageFetched( KMMessage *msg );
00126   void msgAdded( KMFolder*, Q_UINT32 );
00127   void enqueue(Q_UINT32 serNum);
00128 
00129   //Filtering slots
00130   void processMessage();
00131   void messageRetrieved(KMMessage*);
00132   void filterMessage();
00133   void moveMessage();
00134   void moveMessageFinished( KMCommand *command );
00135   void timeOut();
00136   void fetchTimeOut();
00137 
00138 private:
00139   static QValueList<ActionScheduler*> *schedulerList; // for debugging
00140   static KMFolderMgr *tempFolderMgr;
00141   static int refCount, count;
00142   static bool sEnabled, sEnabledChecked;
00143   QValueListIterator<Q_UINT32> mMessageIt;
00144   QValueListIterator<KMFilter> mFilterIt;
00145   QValueList<Q_UINT32> mSerNums, mFetchSerNums;
00146   QValueList<QGuardedPtr<KMFolder> > mOpenFolders;
00147   QValueList<KMFilter> mFilters, mQueuedFilters;
00148   KMFilterAction* mFilterAction;
00149   KMFilterMgr::FilterSet mSet;
00150   KMHeaders *mHeaders;
00151   QGuardedPtr<KMFolder> mSrcFolder, mDestFolder;
00152   bool mExecuting, mExecutingLock, mFetchExecuting;
00153   bool mUnget, mFetchUnget;
00154   bool mIgnore;
00155   bool mFiltersAreQueued;
00156   bool mAutoDestruct;
00157   bool mAlwaysMatch;
00158   bool mAccount;
00159   uint mAccountId;
00160   Q_UINT32 mOriginalSerNum;
00161   bool mDeleteSrcFolder;
00162   ReturnCode mResult;
00163   QTimer *finishTimer, *fetchMessageTimer, *tempCloseFoldersTimer;
00164   QTimer *processMessageTimer, *filterMessageTimer;
00165   QTimer *timeOutTimer, *fetchTimeOutTimer;
00166   QTime timeOutTime, fetchTimeOutTime;
00167   KMCommand *lastCommand;
00168   FolderJob *lastJob;
00169 };
00170 
00171 }
00172 
00173 #endif /*actionscheduler_h*/