1/*****************************************************************************
2* Copyright (C) 2009 by Shaun Reich <shaun.reich@kdemail.net> *
3* Copyright (C) 2006-2008 Rafael Fernández López <ereslibre@kde.org> *
4* Copyright (C) 2000 Matej Koss <koss@miesto.sk> *
5* Copyright (C) 2000 David Faure <faure@kde.org> *
6* *
7* This program is free software; you can redistribute it and/or *
8* modify it under the terms of the GNU General Public License as *
9* published by the Free Software Foundation; either version 2 of *
10* the License, or (at your option) any later version. *
11* *
12* This program is distributed in the hope that it will be useful, *
13* but WITHOUT ANY WARRANTY; without even the implied warranty of *
14* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
15* GNU General Public License for more details. *
16* *
17* You should have received a copy of the GNU General Public License *
18* along with this program. If not, see <http://www.gnu.org/licenses/>. *
19*****************************************************************************/
20
21
22#ifndef JOBVIEW_H
23#define JOBVIEW_H
24
25#include <QListView>
26#include <QtDBus/QDBusObjectPath>
27
28#include <kio/global.h>
29
30#include <kuiserversettings.h>
31
32class QDBusAbstractInterface;
33class RequestViewCallWatcher;
34
35class JobView : public QObject
36{
37 Q_OBJECT
38 Q_CLASSINFO("D-Bus Interface", "org.kde.JobViewV2")
39
40public:
41
42 enum DataType {
43 Capabilities = 33,
44 ApplicationName,
45 Icon,
46 SizeTotal,
47 SizeProcessed,
48 TimeTotal,
49 TimeElapsed,
50 Speed,
51 Percent,
52 InfoMessage,
53 DescFields,
54 State,
55 JobViewRole
56 };
57
58 enum JobState {
59 Running = 0,
60 Suspended = 1,
61 Stopped = 2
62 };
63
64 JobView(uint jobId, QObject *parent = 0);
65 ~JobView();
66
67 void terminate(const QString &errorMessage);
68
69 void setSuspended(bool suspended);
70
71 void setTotalAmount(qulonglong amount, const QString &unit);
72 QString sizeTotal() const;
73
74 void setProcessedAmount(qulonglong amount, const QString &unit);
75 QString sizeProcessed() const;
76
77 void setPercent(uint percent);
78 uint percent() const;
79
80 void setSpeed(qulonglong bytesPerSecond);
81 QString speed() const;
82
83 void setInfoMessage(const QString &infoMessage);
84 QString infoMessage() const;
85
86 bool setDescriptionField(uint number, const QString &name, const QString &value);
87 void clearDescriptionField(uint number);
88
89 void setAppName(const QString &appName);
90 QString appName() const;
91
92 void setAppIconName(const QString &appIconName);
93 QString appIconName() const;
94
95 void setCapabilities(int capabilities);
96 int capabilities() const;
97
98 QString error() const;
99
100 uint state() const;
101
102 uint jobId() const;
103
104 QDBusObjectPath objectPath() const;
105
106
107
108 /**
109 * Set the dest Url of the job...
110 * sent from the jobtracker (once upon construction)
111 * @param destUrl will be a QVariant, likely to have 1
112 * dest Url...OR it can be non-existent (only srcUrl would
113 * be there), in that case it is a delete a directory job
114 * etc..
115 */
116 void setDestUrl(const QDBusVariant& destUrl);
117
118 QVariant destUrl() const;
119
120 /**
121 * The below methods force an emission of the respective signal.
122 * Only use case is kuiserver's delegate, where we need to control
123 * the state of a job, but can't emit them because they are signals
124 *
125 * Note: it isn't used for job's propagating their children jobs
126 * all the way up to KJob, use the other signals in here for that.
127 * (although it does the same thing).
128 */
129 void requestSuspend();
130 void requestResume();
131 void requestCancel();
132
133
134 /**
135 * Called by the model.
136 * Lets us know that a job at @p objectPath is
137 * open for business. @p address is only for data-keeping of our
138 * hash, later on. We will remove it when that address drops,
139 * due to some signal magic from the model.
140 */
141 void addJobContact(const QString& objectPath, const QString& address);
142
143 /**
144 * Return the list of job contacts (jobs we are currently forwarding information
145 * to over the wire). They *should* be valid. If they are not, something is probably
146 * fishy.
147 * This method is only for D-BUS debug purposes, for his pleasure.
148 * So betting on this method and trying to parse it would not be the best of ideas.
149 */
150 QStringList jobContacts();
151
152 void pendingCallStarted();
153
154public Q_SLOTS:
155 void pendingCallFinished(RequestViewCallWatcher *watcher);
156
157Q_SIGNALS:
158 void suspendRequested();
159 void resumeRequested();
160 void cancelRequested();
161
162 void finished(JobView*);
163
164 /**
165 * Triggered when an internal data type changes. It is triggered
166 * once for each data type of this JobView, that has changed.
167 *
168 * @param uint unique job identifier
169 */
170 void changed(uint);
171
172 void destUrlSet();
173
174private Q_SLOTS:
175
176 /**
177 * Called when the model finds out that the client that was
178 * registered, has just died. Meaning notifications to the
179 * given path, are no longer required(remove them from the list).
180 */
181 void serviceDropped(const QString &address);
182
183private:
184
185 int m_capabilities; ///< The capabilities of the job
186
187 QString m_applicationName; ///< The application name
188
189 QString m_appIconName; ///< The icon name
190
191 QString m_sizeTotal; ///< The total size of the operation
192
193 QString m_sizeProcessed; ///< The processed size at the moment(amount completed)
194
195 QString m_speed; ///< The current speed of the operation (human readable, example, "3Mb/s")
196
197 int m_percent; ///< The current percent completed of the job
198
199 QString m_infoMessage; ///< The information message to be shown
200
201 QString m_error; ///< The error message of the job, set when it's terminated
202
203 QString m_totalUnit; ///< The unit used in setTotalAmount
204
205 qulonglong m_totalAmount; ///< The amount used in setTotalAmount
206
207 QString m_processUnit; ///< The unit used in setProcessedAmount
208
209 qulonglong m_processAmount; ///< The processed amount (setProcessedAmount)
210
211 QHash<uint, QPair<QString, QString> > m_descFields;
212
213 QVariant m_destUrl;
214
215 QDBusObjectPath m_objectPath;
216
217 /**
218 * All for the client:
219 * <address name, <objectPath, interface> >
220 */
221 QHash<QString, QPair<QString, QDBusAbstractInterface*> > m_objectPaths;
222
223 const uint m_jobId;
224 JobState m_state; ///< Current state of this job
225
226 // if the job has been terminated (but it could still be awaiting a pendingReply)
227 bool m_isTerminated;
228
229 // number of pending async calls to "requestView" that progresslistmodel has made.
230 // 0 means that this job can be deleted and all is well. Else it has to kind of wait until it comes back.
231 int m_currentPendingCalls;
232};
233
234#endif //JOBVIEW_H
235