kmail

actionscheduler.h

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   int tempOpenFolder(KMFolder* aFolder);
00119   void tempCloseFolders();
00120 
00121   //Fetching slots
00122   void fetchMessage();
00123   void messageFetched( KMMessage *msg );
00124   void msgAdded( KMFolder*, Q_UINT32 );
00125   void enqueue(Q_UINT32 serNum);
00126 
00127   //Filtering slots
00128   void processMessage();
00129   void messageRetrieved(KMMessage*);
00130   void filterMessage();
00131   void moveMessage();
00132   void moveMessageFinished( KMCommand *command );
00133   void timeOut();
00134   void fetchTimeOut();
00135 
00136 private:
00137   static QValueList<ActionScheduler*> *schedulerList; // for debugging
00138   static KMFolderMgr *tempFolderMgr;
00139   static int refCount, count;
00140   static bool sEnabled, sEnabledChecked;
00141   QValueListIterator<Q_UINT32> mMessageIt;
00142   QValueListIterator<KMFilter> mFilterIt;
00143   QValueList<Q_UINT32> mSerNums, mFetchSerNums;
00144   QValueList<QGuardedPtr<KMFolder> > mOpenFolders;
00145   QValueList<KMFilter> mFilters, mQueuedFilters;
00146   KMFilterAction* mFilterAction;
00147   KMFilterMgr::FilterSet mSet;
00148   KMHeaders *mHeaders;
00149   QGuardedPtr<KMFolder> mSrcFolder, mDestFolder;
00150   bool mExecuting, mExecutingLock, mFetchExecuting;
00151   bool mUnget, mFetchUnget;
00152   bool mIgnore;
00153   bool mFiltersAreQueued;
00154   bool mAutoDestruct;
00155   bool mAlwaysMatch;
00156   bool mAccount;
00157   uint mAccountId;
00158   Q_UINT32 mOriginalSerNum;
00159   bool mDeleteSrcFolder;
00160   ReturnCode mResult;
00161   QTimer *finishTimer, *fetchMessageTimer, *tempCloseFoldersTimer;
00162   QTimer *processMessageTimer, *filterMessageTimer;
00163   QTimer *timeOutTimer, *fetchTimeOutTimer;
00164   QTime timeOutTime, fetchTimeOutTime;
00165   KMCommand *lastCommand;
00166   FolderJob *lastJob;
00167 };
00168 
00169 }
00170 
00171 #endif /*actionscheduler_h*/
KDE Home | KDE Accessibility Home | Description of Access Keys