Plasma-workspace

job.h
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#pragma once
8
9#include <QDateTime>
10#include <QString>
11#include <QUrl>
12
13#include <qqmlregistration.h>
14
15#include "notifications.h"
16
17#include "notificationmanager_export.h"
18
19namespace NotificationManager
20{
21class JobPrivate;
22
23/**
24 * @short Represents a single job.
25 *
26 * A Job represents a special notification that has some progress information and in
27 * some cases can be suspended or killed.
28 *
29 * @author Kai Uwe Broulik <kde@privat.broulik.de>
30 */
31class NOTIFICATIONMANAGER_EXPORT Job : public QObject
32{
34 QML_ELEMENT
35 QML_UNCREATABLE("Can only access Job via JobDetailsRole of JobsModel")
36
37 /**
38 * The job infoMessage, e.g. "Copying".
39 */
40 Q_PROPERTY(QString summary READ summary NOTIFY summaryChanged)
41 /**
42 * User-friendly compact description text of the job,
43 * for example "42 of 1337 files to "~/some/folder", or
44 * "SomeFile.txt to Downloads".
45 */
46 Q_PROPERTY(QString text READ text NOTIFY textChanged)
47
48 /**
49 * The desktop entry of the application owning the job, e.g. "org.kde.dolphin".
50 */
52 /**
53 * The user-visible name of the application owning the job, e.g. "Dolphin".
54 */
56 /**
57 * The icon name of the application owning the job, e.g. "system-file-manager".
58 */
60 /**
61 * The state the job is currently in.
62 */
63 Q_PROPERTY(Notifications::JobState state READ state NOTIFY stateChanged)
64 /**
65 * The total percentage (0-100) of job completion.
66 */
67 Q_PROPERTY(int percentage READ percentage NOTIFY percentageChanged)
68 /**
69 * The error code of the job failure.
70 */
71 Q_PROPERTY(int error READ error NOTIFY errorChanged)
72 /**
73 * Whether the job can be suspended.
74 *
75 * @sa Notifications::suspendJob
76 * @sa Notifications::resumeJob
77 */
79 /**
80 * Whether the job can be aborted.
81 *
82 * @sa Notifications::killJob
83 */
84 Q_PROPERTY(bool killable READ killable CONSTANT)
85
86 /**
87 * The destination URL of a job.
88 */
89 Q_PROPERTY(QUrl destUrl READ destUrl NOTIFY destUrlChanged)
90
91 /**
92 * Current transfer rate in Byte/s
93 */
94 Q_PROPERTY(qulonglong speed READ speed NOTIFY speedChanged)
95
96 Q_PROPERTY(qulonglong elapsedTime READ elapsedTime NOTIFY elapsedTimeChanged)
97
98 Q_PROPERTY(qulonglong processedBytes READ processedBytes NOTIFY processedBytesChanged)
99 Q_PROPERTY(qulonglong processedFiles READ processedFiles NOTIFY processedFilesChanged)
100 Q_PROPERTY(qulonglong processedDirectories READ processedDirectories NOTIFY processedDirectoriesChanged)
101 Q_PROPERTY(qulonglong processedItems READ processedItems NOTIFY processedItemsChanged)
102
103 Q_PROPERTY(qulonglong totalBytes READ totalBytes NOTIFY totalBytesChanged)
104 Q_PROPERTY(qulonglong totalFiles READ totalFiles NOTIFY totalFilesChanged)
105 Q_PROPERTY(qulonglong totalDirectories READ totalDirectories NOTIFY totalDirectoriesChanged)
106 Q_PROPERTY(qulonglong totalItems READ totalItems NOTIFY totalItemsChanged)
107
108 Q_PROPERTY(QString descriptionLabel1 READ descriptionLabel1 NOTIFY descriptionLabel1Changed)
109 Q_PROPERTY(QString descriptionValue1 READ descriptionValue1 NOTIFY descriptionValue1Changed)
110
111 Q_PROPERTY(QString descriptionLabel2 READ descriptionLabel2 NOTIFY descriptionLabel2Changed)
112 Q_PROPERTY(QString descriptionValue2 READ descriptionValue2 NOTIFY descriptionValue2Changed)
113
114 /**
115 * Whether there are any details available for this job.
116 *
117 * This is true as soon as any of the following are available:
118 * - processed amount (of any unit)
119 * - total amount (of any unit)
120 * - description label or value (of any row)
121 * - speed
122 */
123 Q_PROPERTY(bool hasDetails READ hasDetails NOTIFY hasDetailsChanged)
124
125 /**
126 * This tries to generate a valid URL for a file that's being processed by converting descriptionValue2
127 * (which is assumed to be the Destination) and if that isn't valid, descriptionValue1 to a URL.
128 */
129 Q_PROPERTY(QUrl descriptionUrl READ descriptionUrl NOTIFY descriptionUrlChanged)
130
131 /**
132 * The final destination url: it's the final copied file if is single, the destination folder url if
133 * more than one, it will be empty if the job is still running or if the destination is within trash:/
134 */
135 Q_PROPERTY(QUrl effectiveDestUrl READ effectiveDestUrl NOTIFY effectiveDestUrlChanged)
136
137public:
138 explicit Job(uint id, QObject *parent = nullptr);
139 ~Job() override;
140
141 uint id() const;
142
143 QDateTime created() const;
144
145 QDateTime updated() const;
146 void resetUpdated();
147
148 QString summary() const;
149 QString text() const;
150
151 QString desktopEntry() const;
152 // TODO remove and let only constructor do it?
153 void setDesktopEntry(const QString &desktopEntry);
154
155 QString applicationName() const;
156 // TODO remove and let only constructor do it?
157 void setApplicationName(const QString &applicationName);
158
160 // TODO remove and let only constructor do it?
161 void setApplicationIconName(const QString &applicationIconName);
162
163 Notifications::JobState state() const;
164 void setState(Notifications::JobState jobState);
165
166 int percentage() const;
167
168 int error() const;
169 void setError(int error);
170
171 QString errorText() const;
172 void setErrorText(const QString &errorText);
173
174 bool suspendable() const;
175 // TODO remove and let only constructor do it?
176 void setSuspendable(bool suspendable);
177
178 bool killable() const;
179 // TODO remove and let only constructor do it?
180 void setKillable(bool killable);
181
182 bool transient() const;
183 void setTransient(bool transient);
184
185 QUrl destUrl() const;
186
187 QUrl effectiveDestUrl() const;
188
189 qulonglong speed() const;
190
191 qint64 elapsedTime() const;
192
193 qulonglong processedBytes() const;
194 qulonglong processedFiles() const;
195 qulonglong processedDirectories() const;
196 qulonglong processedItems() const;
197
198 qulonglong totalBytes() const;
199 qulonglong totalFiles() const;
200 qulonglong totalDirectories() const;
201 qulonglong totalItems() const;
202
203 QString descriptionLabel1() const;
204 QString descriptionValue1() const;
205
206 QString descriptionLabel2() const;
207 QString descriptionValue2() const;
208
209 bool hasDetails() const;
210
211 QUrl descriptionUrl() const;
212
213 bool expired() const;
214 void setExpired(bool expired);
215
216 bool dismissed() const;
217 void setDismissed(bool dismissed);
218
219 Q_INVOKABLE void suspend();
220 Q_INVOKABLE void resume();
221 Q_INVOKABLE void kill();
222
224 void updatedChanged();
225 void summaryChanged();
226 void textChanged();
227 void stateChanged(Notifications::JobState jobState);
228 void percentageChanged(int percentage);
229 void errorChanged(int error);
230 void errorTextChanged(const QString &errorText);
231 void destUrlChanged();
232 void effectiveDestUrlChanged();
233 void speedChanged();
234 void elapsedTimeChanged();
235 void processedBytesChanged();
236 void processedFilesChanged();
237 void processedDirectoriesChanged();
238 void processedItemsChanged();
239 void processedAmountChanged();
240 void totalBytesChanged();
241 void totalFilesChanged();
242 void totalDirectoriesChanged();
243 void totalItemsChanged();
244 void totalAmountChanged();
245 void descriptionLabel1Changed();
246 void descriptionValue1Changed();
247 void descriptionLabel2Changed();
248 void descriptionValue2Changed();
249 void descriptionUrlChanged();
250 void hasDetailsChanged();
251 void expiredChanged();
252 void dismissedChanged();
253
254private:
255 JobPrivate *d;
256
257 friend class JobsModel;
258 friend class JobsModelPrivate;
259};
260
261} // namespace NotificationManager
bool hasDetails
Whether there are any details available for this job.
Definition job.h:123
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:129
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:135
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
A model with notifications and jobs.
QObject(QObject *parent)
Q_INVOKABLEQ_INVOKABLE
Q_OBJECTQ_OBJECT
Q_PROPERTY(...)
Q_SIGNALSQ_SIGNALS
QObject * parent() const const
This file is part of the KDE documentation.
Documentation copyright © 1996-2025 The KDE developers.
Generated on Fri Mar 28 2025 11:53:53 by doxygen 1.13.2 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.