Cache Nepomuk tag information.
[kdepim.git] / knode / scheduler.h
blob4852babcece96e15e595a284cc5df79ddb9ba84e
1 /*
2 KNode, the KDE newsreader
3 Copyright (c) 1999-2005 the KNode authors.
4 See file AUTHORS for details
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
10 You should have received a copy of the GNU General Public License
11 along with this program; if not, write to the Free Software Foundation,
12 Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, US
15 #ifndef KNODE_SCHEDULER_H
16 #define KNODE_SCHEDULER_H
18 #include <QObject>
19 #include <QMutex>
20 #include <QList>
22 namespace KPIM {
23 class ProgressItem;
26 class KNJobData;
28 namespace KNode {
30 /** The job scheduler.
31 * This class manages three diffrent queues of all created jobs:
32 * - a queue for all NNTP jobs
33 * - a queue for all SMTP jobs
34 * - a queue for jobs that are waiting for KWallet
35 * At most two jobs (one NNTP, one SMTP job) are executed at once.
37 * @todo Add per-account queues and execute one job per account.
39 * @see KNGlobals::scheduler()
41 class Scheduler : public QObject {
43 Q_OBJECT
45 public:
47 /** Create a new Scheduler object
48 * @param parent The parent QObject.
50 Scheduler( QObject *parent = 0 );
51 ~Scheduler();
53 /** Adds a new job to the scheduler queue.
54 * @param job The new job.
56 void addJob(KNJobData *job);
58 QMutex& nntpMutex() { return nntp_Mutex; }
60 /** Cancel the selected jobs.
61 * @param type Cancel all jobs of the given type, 0 means all.
62 * @param item Cancel the job associated with this progress item.
63 * If item is 0, only the job type is evaluated.
65 void cancelJobs( int type = 0, KPIM::ProgressItem* item = 0 );
67 protected:
68 /// the currently active NNTP job
69 KNJobData *currentNntpJob;
70 /// the currently active SMTP job
71 KNJobData *currentSmtpJob;
72 QMutex nntp_Mutex;
74 signals:
75 /** Indicates whether there are currently active jobs, useful to e.g. enable
76 * a cancel button.
78 void netActive(bool);
80 private:
81 /** Checks if there is a free slot available for a waiting job and executes
82 * it.
84 void schedule();
86 /** Starts the given job.
87 * @param job The job to start.
89 void startJob( KNJobData *job );
91 /** Update activitiy status, i.e. emit netActive signal. */
92 void updateStatus();
94 private slots:
95 /** Connected to the finished() signal of all active jobs.
96 * @param job The job that has been finished.
98 void slotJobFinished( KNJobData *job );
100 /** Connected to the cancel signal of the progress item of each job.
101 * @param item The progress item which has been canceled.
103 void slotCancelJob( KPIM::ProgressItem *item );
105 void slotPasswordsChanged();
107 private:
108 /// queue for NNTP jobs
109 QList<KNJobData*> nntpJobQueue;
110 /// all SMTP jobs
111 QList<KNJobData*> smtpJobs;
112 /// jobs waiting for async wallet loading
113 QList<KNJobData*> mWalletQueue;
119 #endif