~ubuntu-branches/ubuntu/saucy/kget/saucy-updates

« back to all changes in this revision

Viewing changes to core/job.h

  • Committer: Package Import Robot
  • Author(s): Jonathan Riddell
  • Date: 2013-06-21 02:25:26 UTC
  • Revision ID: package-import@ubuntu.com-20130621022526-8ctjdwsa0twvsgks
Tags: upstream-4.10.80
ImportĀ upstreamĀ versionĀ 4.10.80

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* This file is part of the KDE project
 
2
 
 
3
   Copyright (C) 2005 Dario Massarin <nekkar@libero.it>
 
4
   Copyright (C) 2009 Lukas Appelhans <l.appelhans@gmx.de>
 
5
 
 
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.
 
10
*/
 
11
 
 
12
#ifndef JOB_H
 
13
#define JOB_H
 
14
 
 
15
/**
 
16
 *  @brief Job class
 
17
 *
 
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).
 
24
 **/
 
25
 
 
26
#include "../kget_export.h"
 
27
 
 
28
#include <QPixmap>
 
29
 
 
30
class QDomNode;
 
31
 
 
32
class Scheduler;
 
33
class JobQueue;
 
34
 
 
35
class KGET_EXPORT Job : public QObject
 
36
{
 
37
    Q_OBJECT
 
38
    public:
 
39
        /**
 
40
         * The status property describes the current job status
 
41
         */
 
42
        enum 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
 
52
        };
 
53
 
 
54
        /**
 
55
         * The policy property describes how the scheduler should manage this job.
 
56
         */
 
57
        enum Policy {
 
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
 
63
                   /// queue status
 
64
        };
 
65
        /**
 
66
         * Describes different types of errors and how the scheduler should manage them.
 
67
         */
 
68
        enum ErrorType {
 
69
            AutomaticRetry,
 
70
            ManualSolve,
 
71
            NotSolveable
 
72
        };
 
73
        struct Error {
 
74
            int id;
 
75
            QString text;
 
76
            QPixmap pixmap;
 
77
            ErrorType type;
 
78
        };
 
79
        Job(Scheduler * scheduler, JobQueue * parent);
 
80
        virtual ~Job();
 
81
 
 
82
        //Job commands
 
83
        virtual void start()=0;
 
84
        virtual void stop()=0;
 
85
 
 
86
        JobQueue * jobQueue() {return m_jobQueue;}
 
87
 
 
88
        //Job properties
 
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);
 
92
 
 
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;}
 
97
 
 
98
        virtual int elapsedTime() const =0;
 
99
        virtual int remainingTime() const =0;
 
100
        virtual bool isStalled() const =0;
 
101
        virtual bool isWorking() const =0;
 
102
        
 
103
        virtual void resolveError(int errorId);
 
104
 
 
105
    protected:
 
106
        Scheduler * scheduler() const {return m_scheduler;}
 
107
 
 
108
        void read(QDomNode * n);
 
109
        void write(QDomNode * n);
 
110
 
 
111
        void setStartStatus(Status jobStatus);
 
112
 
 
113
        /**
 
114
         * This one posts a job event to the scheduler
 
115
         */
 
116
        void postJobEvent(Status); //do we need a JobEvent instead of JobStatus?
 
117
 
 
118
        JobQueue *  m_jobQueue;
 
119
        Scheduler * m_scheduler;
 
120
 
 
121
    private:
 
122
        Status m_status;
 
123
        // our status when KGet is started
 
124
        Status m_startStatus;
 
125
        Policy m_policy;
 
126
        Error m_error;
 
127
};
 
128
 
 
129
#endif