kmail

jobscheduler.h
1 /*
2  * Copyright (c) 2004 David Faure <faure@kde.org>
3  *
4  * This program is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation; version 2 of the License
7  *
8  * This program is distributed in the hope that it will be useful,
9  * but WITHOUT ANY WARRANTY; without even the implied warranty of
10  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11  * GNU General Public License for more details.
12  *
13  * You should have received a copy of the GNU General Public License
14  * along with this program; if not, write to the Free Software
15  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
16  *
17  * In addition, as a special exception, the copyright holders give
18  * permission to link the code of this program with any edition of
19  * the TQt library by Trolltech AS, Norway (or with modified versions
20  * of TQt that use the same license as TQt), and distribute linked
21  * combinations including the two. You must obey the GNU General
22  * Public License in all respects for all of the code used other than
23  * TQt. If you modify this file, you may extend this exception to
24  * your version of the file, but you are not obligated to do so. If
25  * you do not wish to do so, delete this exception statement from
26  * your version.
27  */
28 
29 #ifndef KMAIL_JOBSCHEDULER_H
30 #define KMAIL_JOBSCHEDULER_H
31 
32 #include <tqobject.h>
33 #include <tqvaluelist.h>
34 #include <tqguardedptr.h>
35 #include <tqtimer.h>
36 
37 #include "folderjob.h"
38 
39 // If this define is set, JobScheduler will show debug output, and related kmkernel timers will be shortened
40 // This is for debugging purposes only, don't commit with it.
41 //#define DEBUG_SCHEDULER
42 
43 class KMFolder;
44 namespace KMail {
45 
46 class FolderJob;
47 class ScheduledJob;
48 
55 public:
59  ScheduledTask( KMFolder* folder, bool immediate )
60  : mCurrentFolder( folder ), mImmediate( immediate ) {}
61  virtual ~ScheduledTask() {}
62 
70  virtual ScheduledJob* run() = 0;
71 
76  virtual int taskTypeId() const = 0;
77 
79  KMFolder* folder() const { return mCurrentFolder; }
80 
81  bool isImmediate() const { return mImmediate; }
82 
83 private:
84  TQGuardedPtr<KMFolder> mCurrentFolder;
85  bool mImmediate;
86 };
87 
96 class JobScheduler : public TQObject
97 {
98  TQ_OBJECT
99 
100 public:
101  JobScheduler( TQObject* parent, const char* name = 0 );
102  ~JobScheduler();
103 
106  void registerTask( ScheduledTask* task );
107 
110  void notifyOpeningFolder( KMFolder* folder );
111 
112  // DCOP calls
113  void pause();
114  void resume();
115 
116 private slots:
118  void slotRunNextJob();
119 
121  void slotJobFinished();
122 
123 private:
124  void restartTimer();
125  void interruptCurrentTask();
126  void runTaskNow( ScheduledTask* task );
127  typedef TQValueList<ScheduledTask *> TaskList;
128  void removeTask( TaskList::Iterator& it );
129 private:
130  TaskList mTaskList; // FIFO of tasks to be run
131 
132  TQTimer mTimer;
133  int mPendingImmediateTasks;
134 
136  ScheduledTask* mCurrentTask;
137  ScheduledJob* mCurrentJob;
138 };
139 
143 class ScheduledJob : public FolderJob
144 {
145 public:
146  ScheduledJob( KMFolder* folder, bool immediate );
147 
148  bool isOpeningFolder() const { return mOpeningFolder; }
149 
150 protected:
151  bool mImmediate;
152  bool mOpeningFolder;
153 };
154 
155 } // namespace
156 
157 #endif /* KMAIL_JOBSCHEDULER_H */
Mail folder.
Definition: kmfolder.h:69
The unique JobScheduler instance (owned by kmkernel) implements "background processing" of folder ope...
Definition: jobscheduler.h:97
void notifyOpeningFolder(KMFolder *folder)
Called by [implementations of] FolderStorage::open() Interrupt any running job for this folder and re...
void registerTask(ScheduledTask *task)
Register a task to be done for a given folder The ownership of the task is transferred to the JobSche...
Base class for scheduled jobs.
Definition: jobscheduler.h:144
A scheduled task is some information about a folder job that should be run later.
Definition: jobscheduler.h:54
ScheduledTask(KMFolder *folder, bool immediate)
Create a scheduled task for a given folder If immediate is true, the scheduler will run this task as ...
Definition: jobscheduler.h:59
KMFolder * folder() const
The folder which this task is about, 0 if it was deleted meanwhile.
Definition: jobscheduler.h:79
virtual int taskTypeId() const =0
An identifier for the type of task (a bit like TQListViewItem::rtti) This allows to automatically pre...
virtual ScheduledJob * run()=0
Run this task, i.e.
folderdiaquotatab.h
Definition: aboutdata.cpp:40