Initial: added urpo files!
[urpo] / src / urpojob.h
1 /**************************************************************************
2
3     URPO
4
5     Unix Remote Printing Operation
6     Copyright (c) Arto Hyvättinen 2010
7
8     This file is part of URPO.
9
10     URPO is free software: you can redistribute it and/or modify
11     it under the terms of the GNU General Public License as published by
12     the Free Software Foundation, either version 3 of the License, or
13     (at your option) any later version.
14
15     URPO is distributed in the hope that it will be useful,
16     but WITHOUT ANY WARRANTY; without even the implied warranty of
17     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18     GNU General Public License for more details.
19
20
21 **************************************************************************/
22
23 #ifndef URPOJOB_H
24 #define URPOJOB_H
25
26 #include <QObject>
27
28 #include "urpoprocess.h"
29 class UrpoConnection;
30
31 /*!  Base class for jobs (abstract)
32
33   @author Arto Hyvättinen
34   @version 0
35   @date 2010-06-11
36
37
38
39   */
40 class UrpoJob : public QObject
41 {
42     Q_OBJECT
43 public:
44     explicit UrpoJob(UrpoConnection* connection);
45
46
47     enum JobStatus {
48         Ready,
49         Running,
50         Successed,
51         Failed,
52         Cancelled
53     };
54
55     /*! Job status
56
57       @return Job status (Ready, Running, Successed, Failed
58       */
59     JobStatus getStatus() const { return status_; }
60
61 signals:
62     void debugMessage(QString message);
63     /*! Job finished (successed of failed)
64
65       @param successed True if job successed, false if failed */
66     void finished(bool successed, QString errorStr = QString());
67
68 public slots:
69     /*! Start job */
70     void start() { startJob(); }
71     /*! Cancel job */
72     void cancel() { cancelJob(); }
73
74
75 protected:
76     virtual void startJob() = 0;
77     virtual void cancelJob() = 0;
78     /*! Finish job
79       @arg status Job status (Successed, Failed, Cancelled) */
80     void finish(JobStatus status);
81     /*! Finish failed job
82
83       emit finished() with error status and message */
84     void fail(QString errorString);
85     /*! Get connection pointer */
86     UrpoConnection* getConnection() { return connection_; }
87
88     /*! Send debug message
89
90       @param message Message to debug monitor
91
92       If debug monitor has been connected, send message to debug monitor
93
94       */
95     void sendDebugMessage(QString message);
96
97     /*! Create new UrpoProcess */
98     UrpoProcess* newProcess();
99
100     /*! Set job status */
101     void setStatus(JobStatus status) { status_ = status; }
102
103 private:
104     UrpoConnection* connection_;
105     JobStatus status_;
106
107 };
108
109 #endif // URPOJOB_H