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> 00033 00034 #include <QPointer> 00035 #include <QTimer> 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 virtual ~ScheduledTask(); 00061 00069 virtual ScheduledJob* run() = 0; 00070 00075 virtual int taskTypeId() const = 0; 00076 00078 KMFolder* folder() const { return mCurrentFolder; } 00079 00080 bool isImmediate() const { return mImmediate; } 00081 00082 private: 00083 QPointer<KMFolder> mCurrentFolder; 00084 bool mImmediate; 00085 }; 00086 00095 class JobScheduler : public QObject 00096 { 00097 Q_OBJECT 00098 public: 00099 explicit JobScheduler( QObject* parent, const char* name = 0 ); 00100 ~JobScheduler(); 00101 00104 void registerTask( ScheduledTask* task ); 00105 00108 void notifyOpeningFolder( KMFolder* folder ); 00109 00110 // D-Bus calls, called from KMKernel 00111 void pause(); 00112 void resume(); 00113 00114 private slots: 00116 void slotRunNextJob(); 00117 00119 void slotJobFinished(); 00120 00121 private: 00122 void restartTimer(); 00123 void interruptCurrentTask(); 00124 void runTaskNow( ScheduledTask* task ); 00125 typedef QList<ScheduledTask *> TaskList; 00126 void removeTask( TaskList::Iterator& it ); 00127 private: 00128 TaskList mTaskList; // FIFO of tasks to be run 00129 00130 QTimer mTimer; 00131 int mPendingImmediateTasks; 00132 00134 ScheduledTask* mCurrentTask; 00135 ScheduledJob* mCurrentJob; 00136 }; 00137 00141 class ScheduledJob : public FolderJob 00142 { 00143 public: 00144 ScheduledJob( KMFolder* folder, bool immediate ); 00145 ~ScheduledJob(); 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 */
KDE 4.2 API Reference