Plasma-workspace

job.cpp
1/*
2 SPDX-FileCopyrightText: 2019 Kai Uwe Broulik <kde@privat.broulik.de>
3
4 SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL
5*/
6
7#include "job.h"
8#include "job_p.h"
9
10#include <QDebug>
11
12using namespace NotificationManager;
13
14Job::Job(uint id, QObject *parent)
15 : QObject(parent)
16 , d(new JobPrivate(id, this))
17{
18 d->m_created = QDateTime::currentDateTimeUtc();
19
20 // These properties are used in generating the pretty job text
21 connect(d, &JobPrivate::infoMessageChanged, this, &Job::textChanged);
22 connect(this, &Job::processedFilesChanged, this, &Job::textChanged);
23 connect(this, &Job::processedItemsChanged, this, &Job::textChanged);
24 connect(this, &Job::totalFilesChanged, this, &Job::textChanged);
25 connect(this, &Job::totalItemsChanged, this, &Job::textChanged);
26 connect(this, &Job::descriptionValue1Changed, this, &Job::textChanged);
27 connect(this, &Job::descriptionValue2Changed, this, &Job::textChanged);
28 connect(this, &Job::destUrlChanged, this, &Job::textChanged);
29 connect(this, &Job::errorTextChanged, this, &Job::textChanged);
30 connect(this, &Job::destUrlChanged, this, &Job::effectiveDestUrlChanged);
31 connect(this, &Job::descriptionUrlChanged, this, &Job::effectiveDestUrlChanged);
32 connect(this, &Job::stateChanged, this, &Job::effectiveDestUrlChanged);
33}
34
35Job::~Job() = default;
36
37uint Job::id() const
38{
39 return d->m_id;
40}
41
42QDateTime Job::created() const
43{
44 return d->m_created;
45}
46
47QDateTime Job::updated() const
48{
49 return d->m_updated;
50}
51
52void Job::resetUpdated()
53{
54 d->m_updated = QDateTime::currentDateTimeUtc();
55 Q_EMIT updatedChanged();
56}
57
59{
60 return d->m_summary;
61}
62
63QString Job::text() const
64{
65 return d->text();
66}
67
69{
70 return d->m_desktopEntry;
71}
72
73void Job::setDesktopEntry(const QString &desktopEntry)
74{
75 Q_ASSERT(d->m_desktopEntry.isNull());
76 d->m_desktopEntry = desktopEntry;
77}
78
80{
81 return d->m_applicationName;
82}
83
84void Job::setApplicationName(const QString &applicationName)
85{
86 Q_ASSERT(d->m_applicationName.isNull());
87 d->m_applicationName = applicationName;
88}
89
91{
92 return d->m_applicationIconName;
93}
94
95void Job::setApplicationIconName(const QString &applicationIconName)
96{
97 Q_ASSERT(d->m_applicationIconName.isNull());
98 d->m_applicationIconName = applicationIconName;
99}
100
102{
103 return d->m_state;
104}
105
106void Job::setState(Notifications::JobState state)
107{
108 if (d->m_state != state) {
109 d->m_state = state;
110 Q_EMIT stateChanged(state);
111 }
112}
113
114int Job::percentage() const
115{
116 return d->m_percentage;
117}
118
119int Job::error() const
120{
121 return d->m_error;
122}
123
124void Job::setError(int error)
125{
126 if (d->m_error != error) {
127 d->m_error = error;
128 Q_EMIT errorChanged(error);
129 }
130}
131
132QString Job::errorText() const
133{
134 return d->m_errorText;
135}
136
137void Job::setErrorText(const QString &errorText)
138{
139 if (d->m_errorText != errorText) {
140 d->m_errorText = errorText;
141 Q_EMIT errorTextChanged(errorText);
142 }
143}
144
145bool Job::suspendable() const
146{
147 return d->m_suspendable;
148}
149
150void Job::setSuspendable(bool suspendable)
151{
152 // Cannot change after job started
153 d->m_suspendable = suspendable;
154}
155
156bool Job::killable() const
157{
158 return d->m_killable;
159}
160
161void Job::setKillable(bool killable)
162{
163 // Cannot change after job started
164 d->m_killable = killable;
165}
166
167bool Job::transient() const
168{
169 return d->m_transient;
170}
171
172void Job::setTransient(bool transient)
173{
174 d->m_transient = transient;
175}
176
177QUrl Job::destUrl() const
178{
179 return d->m_destUrl;
180}
181
183{
184 if (d->m_state != Notifications::JobState::JobStateStopped || d->m_error != 0) {
185 return QUrl();
186 }
187
188 QUrl url;
189 // For a single file show the file url
190 // Otherwise the destination folder
191 if (d->m_totalFiles == 1) {
192 url = d->descriptionUrl();
193 } else {
194 url = d->m_destUrl;
195 }
196
197 // Don't offer opening files in Trash
198 if (url.scheme() == QStringLiteral("trash")) {
199 return QUrl();
200 }
201
202 return url;
203}
204
205qulonglong Job::speed() const
206{
207 return d->m_speed;
208}
209
210qulonglong Job::processedBytes() const
211{
212 return d->m_processedBytes;
213}
214
215qulonglong Job::processedFiles() const
216{
217 return d->m_processedFiles;
218}
219
220qulonglong Job::processedDirectories() const
221{
222 return d->m_processedDirectories;
223}
224
225qulonglong Job::processedItems() const
226{
227 return d->m_processedItems;
228}
229
230qulonglong Job::totalBytes() const
231{
232 return d->m_totalBytes;
233}
234
235qulonglong Job::totalFiles() const
236{
237 return d->m_totalFiles;
238}
239
240qulonglong Job::totalDirectories() const
241{
242 return d->m_totalDirectories;
243}
244
245qulonglong Job::totalItems() const
246{
247 return d->m_totalItems;
248}
249
250QString Job::descriptionLabel1() const
251{
252 return d->m_descriptionLabel1;
253}
254
255QString Job::descriptionValue1() const
256{
257 return d->m_descriptionValue1;
258}
259
260QString Job::descriptionLabel2() const
261{
262 return d->m_descriptionLabel2;
263}
264
265QString Job::descriptionValue2() const
266{
267 return d->m_descriptionValue2;
268}
269
270bool Job::hasDetails() const
271{
272 return d->m_hasDetails;
273}
274
276{
277 return d->descriptionUrl();
278}
279
280bool Job::expired() const
281{
282 return d->m_expired;
283}
284
285void Job::setExpired(bool expired)
286{
287 if (d->m_expired != expired) {
288 d->m_expired = expired;
289 Q_EMIT expiredChanged();
290 }
291}
292
293bool Job::dismissed() const
294{
295 return d->m_dismissed;
296}
297
298void Job::setDismissed(bool dismissed)
299{
300 if (d->m_dismissed != dismissed) {
301 d->m_dismissed = dismissed;
302 Q_EMIT dismissedChanged();
303 }
304}
305
306void Job::suspend()
307{
308 Q_EMIT d->suspendRequested();
309}
310
311void Job::resume()
312{
313 Q_EMIT d->resumeRequested();
314}
315
316void Job::kill()
317{
318 d->kill();
319}
bool hasDetails
Whether there are any details available for this job.
Definition job.h:121
qulonglong speed
Current transfer rate in Byte/s.
Definition job.h:94
QString text
User-friendly compact description text of the job, for example "42 of 1337 files to "~/some/folder",...
Definition job.h:46
bool suspendable
Whether the job can be suspended.
Definition job.h:78
QUrl descriptionUrl
This tries to generate a valid URL for a file that's being processed by converting descriptionValue2 ...
Definition job.h:127
int error
The error code of the job failure.
Definition job.h:71
QString desktopEntry
The desktop entry of the application owning the job, e.g.
Definition job.h:51
QString applicationIconName
The icon name of the application owning the job, e.g.
Definition job.h:59
QML_ELEMENTQString summary
The job infoMessage, e.g.
Definition job.h:40
QUrl effectiveDestUrl
The final destination url: it's the final copied file if is single, the destination folder url if mor...
Definition job.h:133
QUrl destUrl
The destination URL of a job.
Definition job.h:89
bool killable
Whether the job can be aborted.
Definition job.h:84
Notifications::JobState state
The state the job is currently in.
Definition job.h:63
QString applicationName
The user-visible name of the application owning the job, e.g.
Definition job.h:55
int percentage
The total percentage (0-100) of job completion.
Definition job.h:67
JobState
The state an application job is in.
@ JobStateStopped
The job is stopped. It has either finished (error is 0) or failed (error is not 0)
void transient(const QString &message, const QString &title)
QDateTime currentDateTimeUtc()
Q_EMITQ_EMIT
QFuture< ArgsType< Signal > > connect(Sender *sender, Signal signal)
QString scheme() const const
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Mon Nov 18 2024 12:14:59 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.