1
/* This file is part of the KDE project
3
Copyright (C) 2005 Dario Massarin <nekkar@libero.it>
4
Copyright (C) 2009 Lukas Appelhans <l.appelhans@gmx.de>
6
This program is free software; you can redistribute it and/or
7
modify it under the terms of the GNU General Public
8
License as published by the Free Software Foundation; either
9
version 2 of the License, or (at your option) any later version.
18
* We want to abstract this common interface in order to simplify the
19
* Scheduler code. A Job can be either a Transfer or a search through the net.
20
* It is basically something you execute in background and that the scheduler
21
* can decide to start, stop or cancel. In this way we don't expose the complex
22
* API of a Transfer (or a Search), to the scheduler.
23
* By definition a job must always belong to a JobQueue (see jobqueue.h).
26
#include "../kget_export.h"
35
class KGET_EXPORT Job : public QObject
40
* The status property describes the current job status
43
Running = 0, /// The job is being executed
44
Stopped = 2, /// The job is stopped
45
Aborted = 3, /// The job is stopped, but this also indicates that it
46
/// stopped because an error occurred
47
Finished = 4, /// The job exited from its Running state successfully
48
FinishedKeepAlive = 5, /// The job exited from its Running state successfully
49
/// but wants to be restarted by the scheduler
50
Moving = 6 /// The associated files to that job (e.g. Download) are
51
/// moved to a different location
55
* The policy property describes how the scheduler should manage this job.
58
Start, /// The scheduler should start this job even if its queue
59
/// isn't in a Running status
60
Stop, /// The scheduler shouldn't never start this job, even if
61
/// if its queue is in a Running status
62
None /// The scheduler should start this job depending on its
66
* Describes different types of errors and how the scheduler should manage them.
79
Job(Scheduler * scheduler, JobQueue * parent);
83
virtual void start()=0;
84
virtual void stop()=0;
86
JobQueue * jobQueue() {return m_jobQueue;}
89
void setStatus(Status jobStatus);
90
void setPolicy(Policy jobPolicy);
91
void setError(const QString &text, const QPixmap &pixmap, ErrorType type = AutomaticRetry, int errorId = -1);
93
Status status() const {return m_status;}
94
Status startStatus() const { return m_startStatus;}
95
Policy policy() const {return m_policy;}
96
Error error() const {return m_error;}
98
virtual int elapsedTime() const =0;
99
virtual int remainingTime() const =0;
100
virtual bool isStalled() const =0;
101
virtual bool isWorking() const =0;
103
virtual void resolveError(int errorId);
106
Scheduler * scheduler() const {return m_scheduler;}
108
void read(QDomNode * n);
109
void write(QDomNode * n);
111
void setStartStatus(Status jobStatus);
114
* This one posts a job event to the scheduler
116
void postJobEvent(Status); //do we need a JobEvent instead of JobStatus?
118
JobQueue * m_jobQueue;
119
Scheduler * m_scheduler;
123
// our status when KGet is started
124
Status m_startStatus;