* Paint a styled progressbar instead of our home-brown one.
[kdenetwork.git] / kget / core / job.h
blob48f4d13d2ab628cf1fd63b3ae5f79352c0ea8001
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 */
11 #ifndef JOB_H
12 #define JOB_H
14 /**
15 * @brief Job class
17 * We want to abstract this common interface in order to simplify the
18 * Scheduler code. A Job can be either a Transfer or a search through the net.
19 * It is basically something you execute in background and that the scheduler
20 * can decide to start, stop or cancel. In this way we don't expose the complex
21 * API of a Transfer (or a Search), to the scheduler.
22 * By definition a job must always belong to a JobQueue (see jobqueue.h).
23 **/
25 #include "kget_export.h"
27 class QDomNode;
29 class Scheduler;
30 class JobQueue;
32 class KGET_EXPORT Job
34 public:
35 /**
36 * The status property describes the current job status
38 enum Status {
39 Running, /// The job is being executed
40 Delayed, /// The job is delayed. This means that the scheduler should
41 /// not start it until it exits from the delayed state
42 Stopped, /// The job is stopped
43 Aborted, /// The job is stopped, but this also indicates that it
44 /// stopped because an error occurred
45 Finished /// The job exited from its Running state successfully
48 /**
49 * The policy property describes how the scheduler should manage this job.
51 enum Policy {
52 Start, /// The scheduler should start this job even if its queue
53 /// isn't in a Running status
54 Stop, /// The scheduler shouldn't never start this job, even if
55 /// if its queue is in a Running status
56 None /// The scheduler should start this job depending on its
57 /// queue status
60 Job(JobQueue * parent, Scheduler * scheduler);
61 virtual ~Job();
63 //Job commands
64 virtual void start()=0;
65 virtual void stop()=0;
67 virtual void setDelay(int seconds)=0;
68 virtual void delayTimerEvent()=0;
70 JobQueue * jobQueue() {return m_jobQueue;}
72 //Job properties
73 void setStatus(Status jobStatus);
74 void setPolicy(Policy jobPolicy);
76 Status status() const {return m_status;}
77 Policy policy() const {return m_policy;}
79 virtual int elapsedTime() const =0;
80 virtual int remainingTime() const =0;
82 //Job capabilities
83 virtual bool isResumable() const =0;
85 protected:
86 Scheduler * scheduler() const {return m_scheduler;}
88 void read(QDomNode * n);
89 void write(QDomNode * n);
91 /**
92 * This one posts a job event to the scheduler
94 void postJobEvent(Status); //do we need a JobEvent instead of JobStatus?
96 JobQueue * m_jobQueue;
97 Scheduler * m_scheduler;
99 private:
100 Status m_status;
101 Policy m_policy;
104 #endif