add DQT3_SUPPORT
[kdenetwork.git] / kget / core / jobqueue.h
blob7e5f3f307cff522600d5702aa00115a0b3b01698
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; version 2
8 of the License.
9 */
12 #ifndef _JOBQUEUE_H
13 #define _JOBQUEUE_H
15 /**
16 * @brief JobQueue class
18 * This class abstracts the concept of queue. A queue is, basically, a
19 * group of jobs that should be executed by the scheduler (if the queue
20 * is marked as active). The scheduler will execute a maximum of n jobs
21 * belonging to this queue at a time, where n can be set calling the
22 * setMaxSimultaneousJobs(int n)
26 #include <QList>
27 #include "kget_export.h"
29 class Job;
30 class Scheduler;
32 class KGET_EXPORT JobQueue
34 public:
35 enum Status {Running, Stopped};
36 typedef QList<Job *>::iterator iterator;
38 JobQueue(Scheduler * scheduler);
39 virtual ~JobQueue();
41 /**
42 * Sets the JobQueue status
44 * @param queueStatus the new JobQueue status
46 virtual void setStatus(Status queueStatus);
48 /**
49 * @return the jobQueue status
51 Status status() const {return m_status;}
53 /**
54 * @return the begin of the job's list
56 iterator begin() {return m_jobs.begin();}
58 /**
59 * @return the end of the job's list
61 iterator end() {return m_jobs.end();}
63 /**
64 * @return the last job in the job's list
66 Job * last() {return m_jobs.last();}
68 /**
69 * @return the number of jobs in the queue
71 int size() const {return m_jobs.size();}
73 /**
74 * @param job The job for which we want to find the index
76 * @return the job index for the given job. If the given
77 * job can't be found, it returns -1
79 int indexOf(Job * job) const {return m_jobs.indexOf(job);}
81 /**
82 * @returns the Job in the queue at the given index i
84 Job * operator[] (int i) const;
86 /**
87 * @return a list with the running Jobs
89 const QList<Job *> runningJobs();
91 /**
92 * Sets the maximum number of jobs belonging to this queue that
93 * should executed simultaneously by the scheduler
95 * @param n The maximum number of jobs
97 void setMaxSimultaneousJobs(int n);
99 /**
100 * @return the maximum number of jobs the scheduler should ever
101 * execute simultaneously (in this queue).
103 int maxSimultaneousJobs() const;
105 protected:
107 * appends a job to the current queue
109 * @param job The job to append to the current queue
111 void append(Job * job);
114 * prepends a job to the current queue
116 * @param job The job to prepend to the current queue
118 void prepend(Job * job);
121 * inserts a job to the current queue after the given job
123 * @param job The job to add in the current queue
124 * @param after The job after which to add the job
126 void insert(Job * job, Job * after);
129 * removes a job from the current queue
131 * @param job The job to remove from the current queue
133 void remove(Job * job);
136 * Moves a job in the queue. Both the given jobs must belong to this queue
138 * @param job The job to move
139 * @param position The job after which we have to move the given job
141 void move(Job * job, Job * after);
143 Scheduler * scheduler() {return m_scheduler;}
145 private:
146 QList<Job *> m_jobs;
148 int m_maxSimultaneousJobs;
150 Scheduler * m_scheduler;
151 Status m_status;
154 #endif