kmail
jobscheduler.h
Go to the documentation of this file.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 Qt library by Trolltech AS, Norway (or with modified versions 00020 * of Qt that use the same license as Qt), 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 * Qt. 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 <qobject.h> 00033 #include <qvaluelist.h> 00034 #include <qguardedptr.h> 00035 #include <qtimer.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 QGuardedPtr<KMFolder> mCurrentFolder; 00085 bool mImmediate; 00086 }; 00087 00096 class JobScheduler : public QObject 00097 { 00098 Q_OBJECT 00099 public: 00100 JobScheduler( QObject* parent, const char* name = 0 ); 00101 ~JobScheduler(); 00102 00105 void registerTask( ScheduledTask* task ); 00106 00109 void notifyOpeningFolder( KMFolder* folder ); 00110 00111 // DCOP calls 00112 void pause(); 00113 void resume(); 00114 00115 private slots: 00117 void slotRunNextJob(); 00118 00120 void slotJobFinished(); 00121 00122 private: 00123 void restartTimer(); 00124 void interruptCurrentTask(); 00125 void runTaskNow( ScheduledTask* task ); 00126 typedef QValueList<ScheduledTask *> TaskList; 00127 void removeTask( TaskList::Iterator& it ); 00128 private: 00129 TaskList mTaskList; // FIFO of tasks to be run 00130 00131 QTimer mTimer; 00132 int mPendingImmediateTasks; 00133 00135 ScheduledTask* mCurrentTask; 00136 ScheduledJob* mCurrentJob; 00137 }; 00138 00142 class ScheduledJob : public FolderJob 00143 { 00144 public: 00145 ScheduledJob( KMFolder* folder, bool immediate ); 00146 00147 bool isOpeningFolder() const { return mOpeningFolder; } 00148 00149 protected: 00150 bool mImmediate; 00151 bool mOpeningFolder; 00152 }; 00153 00154 } // namespace 00155 00156 #endif /* KMAIL_JOBSCHEDULER_H */