jobscheduler.h
00001 /* 00002 * Copyright (c) 2004 David Faure <faure@kde.org> 00003 * 00004 * This program is free software; you can redistribute it and/or modify 00005 * it under the terms of the GNU General Public License as published by 00006 * the Free Software Foundation; version 2 of the License 00007 * 00008 * This program is distributed in the hope that it will be useful, 00009 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00010 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00011 * GNU General Public License for more details. 00012 * 00013 * You should have received a copy of the GNU General Public License 00014 * along with this program; if not, write to the Free Software 00015 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 00016 * 00017 * In addition, as a special exception, the copyright holders give 00018 * permission to link the code of this program with any edition of 00019 * the TQt library by Trolltech AS, Norway (or with modified versions 00020 * of TQt that use the same license as TQt), and distribute linked 00021 * combinations including the two. You must obey the GNU General 00022 * Public License in all respects for all of the code used other than 00023 * TQt. If you modify this file, you may extend this exception to 00024 * your version of the file, but you are not obligated to do so. If 00025 * you do not wish to do so, delete this exception statement from 00026 * your version. 00027 */ 00028 00029 #ifndef KMAIL_JOBSCHEDULER_H 00030 #define KMAIL_JOBSCHEDULER_H 00031 00032 #include <tqobject.h> 00033 #include <tqvaluelist.h> 00034 #include <tqguardedptr.h> 00035 #include <tqtimer.h> 00036 00037 #include "folderjob.h" 00038 00039 // If this define is set, JobScheduler will show debug output, and related kmkernel timers will be shortened 00040 // This is for debugging purposes only, don't commit with it. 00041 //#define DEBUG_SCHEDULER 00042 00043 class KMFolder; 00044 namespace KMail { 00045 00046 class FolderJob; 00047 class ScheduledJob; 00048 00054 class ScheduledTask { 00055 public: 00059 ScheduledTask( KMFolder* folder, bool immediate ) 00060 : mCurrentFolder( folder ), mImmediate( immediate ) {} 00061 virtual ~ScheduledTask() {} 00062 00070 virtual ScheduledJob* run() = 0; 00071 00076 virtual int taskTypeId() const = 0; 00077 00079 KMFolder* folder() const { return mCurrentFolder; } 00080 00081 bool isImmediate() const { return mImmediate; } 00082 00083 private: 00084 TQGuardedPtr<KMFolder> mCurrentFolder; 00085 bool mImmediate; 00086 }; 00087 00096 class JobScheduler : public TQObject 00097 { 00098 Q_OBJECT 00099 TQ_OBJECT 00100 public: 00101 JobScheduler( TQObject* parent, const char* name = 0 ); 00102 ~JobScheduler(); 00103 00106 void registerTask( ScheduledTask* task ); 00107 00110 void notifyOpeningFolder( KMFolder* folder ); 00111 00112 // DCOP calls 00113 void pause(); 00114 void resume(); 00115 00116 private slots: 00118 void slotRunNextJob(); 00119 00121 void slotJobFinished(); 00122 00123 private: 00124 void restartTimer(); 00125 void interruptCurrentTask(); 00126 void runTaskNow( ScheduledTask* task ); 00127 typedef TQValueList<ScheduledTask *> TaskList; 00128 void removeTask( TaskList::Iterator& it ); 00129 private: 00130 TaskList mTaskList; // FIFO of tasks to be run 00131 00132 TQTimer mTimer; 00133 int mPendingImmediateTasks; 00134 00136 ScheduledTask* mCurrentTask; 00137 ScheduledJob* mCurrentJob; 00138 }; 00139 00143 class ScheduledJob : public FolderJob 00144 { 00145 public: 00146 ScheduledJob( KMFolder* folder, bool immediate ); 00147 00148 bool isOpeningFolder() const { return mOpeningFolder; } 00149 00150 protected: 00151 bool mImmediate; 00152 bool mOpeningFolder; 00153 }; 00154 00155 } // namespace 00156 00157 #endif /* KMAIL_JOBSCHEDULER_H */