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 TQt library by Trolltech AS, Norway (or with modified versions 00023 of TQt that use the same license as TQt), 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 TQt. 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 <tqobject.h> 00041 #include <tqguardedptr.h> 00042 #include <tqtimer.h> 00043 00044 class KMHeaders; 00045 00046 namespace KMail { 00047 00048 /* A class for asynchronous filtering of messages */ 00049 class ActionScheduler : public TQObject 00050 { 00051 Q_OBJECT 00052 00053 00054 public: 00055 enum ReturnCode { ResultOk, ResultError, ResultCriticalError }; 00056 00057 ActionScheduler(KMFilterMgr::FilterSet set, 00058 TQValueList<KMFilter*> filters, 00059 KMHeaders *headers = 0, 00060 KMFolder *srcFolder = 0); 00061 ~ActionScheduler(); 00062 00065 void setAutoDestruct( bool ); 00066 00068 void setAlwaysMatch( bool ); 00069 00071 void setDefaultDestinationFolder( KMFolder* ); 00072 00074 void setSourceFolder( KMFolder* ); 00075 00079 void setFilterList( TQValueList<KMFilter*> filters ); 00080 00082 void setAccountId( uint id ) { mAccountId = id; mAccount = true; } 00083 00085 void clearAccountId() { mAccountId = 0; mAccount = false; } 00086 00088 void execFilters(const TQValueList<TQ_UINT32> serNums); 00089 void execFilters(const TQPtrList<KMMsgBase> msgList); 00090 void execFilters(KMMsgBase* msgBase); 00091 void execFilters(TQ_UINT32 serNum); 00092 00093 static TQString debug(); 00094 static bool isEnabled(); 00095 00100 bool ignoreChanges( bool ignore ); 00101 00102 signals: 00104 void result(ReturnCode); 00105 void filtered(TQ_UINT32); 00106 00107 public slots: 00109 void actionMessage(KMFilterAction::ReturnCode = KMFilterAction::GoOn); 00110 00112 void copyMessageFinished( KMCommand *command ); 00113 00114 private slots: 00115 KMMsgBase* messageBase(TQ_UINT32 serNum); 00116 KMMessage* message(TQ_UINT32 serNum); 00117 void finish(); 00118 00119 void folderClosedOrExpunged(); 00120 00121 int tempOpenFolder(KMFolder* aFolder); 00122 void tempCloseFolders(); 00123 00124 //Fetching slots 00125 void fetchMessage(); 00126 void messageFetched( KMMessage *msg ); 00127 void msgAdded( KMFolder*, TQ_UINT32 ); 00128 void enqueue(TQ_UINT32 serNum); 00129 00130 //Filtering slots 00131 void processMessage(); 00132 void messageRetrieved(KMMessage*); 00133 void filterMessage(); 00134 void moveMessage(); 00135 void moveMessageFinished( KMCommand *command ); 00136 void timeOut(); 00137 void fetchTimeOut(); 00138 00139 private: 00140 static TQValueList<ActionScheduler*> *schedulerList; // for debugging 00141 static KMFolderMgr *tempFolderMgr; 00142 static int refCount, count; 00143 static bool sEnabled, sEnabledChecked; 00144 TQValueListIterator<TQ_UINT32> mMessageIt; 00145 TQValueListIterator<KMFilter> mFilterIt; 00146 TQValueList<TQ_UINT32> mSerNums, mFetchSerNums; 00147 TQValueList<TQGuardedPtr<KMFolder> > mOpenFolders; 00148 TQValueList<KMFilter> mFilters, mQueuedFilters; 00149 KMFilterAction* mFilterAction; 00150 KMFilterMgr::FilterSet mSet; 00151 KMHeaders *mHeaders; 00152 TQGuardedPtr<KMFolder> mSrcFolder, mDestFolder; 00153 bool mExecuting, mExecutingLock, mFetchExecuting; 00154 bool mUnget, mFetchUnget; 00155 bool mIgnore; 00156 bool mFiltersAreQueued; 00157 bool mAutoDestruct; 00158 bool mAlwaysMatch; 00159 bool mAccount; 00160 uint mAccountId; 00161 TQ_UINT32 mOriginalSerNum; 00162 bool mDeleteSrcFolder; 00163 ReturnCode mResult; 00164 TQTimer *finishTimer, *fetchMessageTimer, *tempCloseFoldersTimer; 00165 TQTimer *processMessageTimer, *filterMessageTimer; 00166 TQTimer *timeOutTimer, *fetchTimeOutTimer; 00167 TQTime timeOutTime, fetchTimeOutTime; 00168 KMCommand *lastCommand; 00169 FolderJob *lastJob; 00170 }; 00171 00172 } 00173 00174 #endif /*actionscheduler_h*/