1 /* This file is part of the KDE project
3 Copyright (C) 2005 Dario Massarin <nekkar@libero.it>
5 This program is free software; you can redistribute it and/or
6 modify it under the terms of the GNU General Public
7 License as published by the Free Software Foundation; either
8 version 2 of the License, or (at your option) any later version.
16 #include <QTimerEvent>
19 #include "core/jobqueue.h"
22 * @brief Scheduler class: what handle all the jobs in kget.
24 * This class handles all the jobs in kget. See job.h for further details.
25 * When we want a job to be executed in kget, we have to add the queue
26 * that owns the job in the scheduler calling the addQueue(JobQueue *) function.
30 class Scheduler
: public QObject
39 * Starts globally the execution of the jobs
46 * Stops globally the execution of the jobs
53 * Adds a queue to the scheduler.
55 * @param queue The queue that should be added
57 void addQueue(JobQueue
* queue
);
60 * Deletes a queue from the scheduler.
61 * If some jobs in the given queue are being executed, they are
62 * first stopped, then removed from the scheduler.
64 * @param queue The queue that should be removed
66 void delQueue(JobQueue
* queue
);
69 * @returns the number of jobs that are currently in a Running state
71 int countRunningJobs();
73 //JobQueue notifications
74 virtual void jobQueueChangedEvent(JobQueue
* queue
, JobQueue::Status status
);
75 virtual void jobQueueMovedJobEvent(JobQueue
* queue
, Job
* job
);
76 virtual void jobQueueAddedJobEvent(JobQueue
* queue
, Job
* job
);
77 virtual void jobQueueRemovedJobEvent(JobQueue
* queue
, Job
* job
);
80 virtual void jobChangedEvent(Job
* job
, Job::Status status
);
81 virtual void jobChangedEvent(Job
* job
, Job::Policy status
);
84 void startDelayTimer(Job
* job
, int seconds
);
85 void stopDelayTimer(Job
* job
);
89 * Updates the given queue, starting the jobs that come first in the queue
90 * and stopping all the other
92 * @param queue the queue to update
94 void updateQueue( JobQueue
* queue
);
97 * @return true if the given job should be running (and this depends
98 * on the job policy and on its jobQueue status)
100 * @param job the job to evaluate
102 bool shouldBeRunning( Job
* job
);
105 //Virtual QObject method
106 void timerEvent ( QTimerEvent
* event
);
108 QList
<JobQueue
*> m_queues
;
109 QMap
<int, Job
*> m_activeTimers
;