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{
33 Q_OBJECT
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 */
51 Q_PROPERTY(QString desktopEntry READ desktopEntry CONSTANT)
52 /**
53 * The user-visible name of the application owning the job, e.g. "Dolphin".
54 */
55 Q_PROPERTY(QString applicationName READ applicationName CONSTANT)
56 /**
57 * The icon name of the application owning the job, e.g. "system-file-manager".
58 */
59 Q_PROPERTY(QString applicationIconName READ applicationIconName CONSTANT)
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 */
78 Q_PROPERTY(bool suspendable READ suspendable CONSTANT)
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 processedBytes READ processedBytes NOTIFY processedBytesChanged)
97 Q_PROPERTY(qulonglong processedFiles READ processedFiles NOTIFY processedFilesChanged)
98 Q_PROPERTY(qulonglong processedDirectories READ processedDirectories NOTIFY processedDirectoriesChanged)
99 Q_PROPERTY(qulonglong processedItems READ processedItems NOTIFY processedItemsChanged)
100
101 Q_PROPERTY(qulonglong totalBytes READ totalBytes NOTIFY totalBytesChanged)
102 Q_PROPERTY(qulonglong totalFiles READ totalFiles NOTIFY totalFilesChanged)
103 Q_PROPERTY(qulonglong totalDirectories READ totalDirectories NOTIFY totalDirectoriesChanged)
104 Q_PROPERTY(qulonglong totalItems READ totalItems NOTIFY totalItemsChanged)
105
106 Q_PROPERTY(QString descriptionLabel1 READ descriptionLabel1 NOTIFY descriptionLabel1Changed)
107 Q_PROPERTY(QString descriptionValue1 READ descriptionValue1 NOTIFY descriptionValue1Changed)
108
109 Q_PROPERTY(QString descriptionLabel2 READ descriptionLabel2 NOTIFY descriptionLabel2Changed)
110 Q_PROPERTY(QString descriptionValue2 READ descriptionValue2 NOTIFY descriptionValue2Changed)
111
112 /**
113 * Whether there are any details available for this job.
114 *
115 * This is true as soon as any of the following are available:
116 * - processed amount (of any unit)
117 * - total amount (of any unit)
118 * - description label or value (of any row)
119 * - speed
120 */
121 Q_PROPERTY(bool hasDetails READ hasDetails NOTIFY hasDetailsChanged)
122
123 /**
124 * This tries to generate a valid URL for a file that's being processed by converting descriptionValue2
125 * (which is assumed to be the Destination) and if that isn't valid, descriptionValue1 to a URL.
126 */
127 Q_PROPERTY(QUrl descriptionUrl READ descriptionUrl NOTIFY descriptionUrlChanged)
128
129 /**
130 * The final destination url: it's the final copied file if is single, the destination folder url if
131 * more than one, it will be empty if the job is still running or if the destination is within trash:/
132 */
133 Q_PROPERTY(QUrl effectiveDestUrl READ effectiveDestUrl NOTIFY effectiveDestUrlChanged)
134
135public:
136 explicit Job(uint id, QObject *parent = nullptr);
137 ~Job() override;
138
139 uint id() const;
140
141 QDateTime created() const;
142
143 QDateTime updated() const;
144 void resetUpdated();
145
146 QString summary() const;
147 QString text() const;
148
149 QString desktopEntry() const;
150 // TODO remove and let only constructor do it?
151 void setDesktopEntry(const QString &desktopEntry);
152
153 QString applicationName() const;
154 // TODO remove and let only constructor do it?
155 void setApplicationName(const QString &applicationName);
156
157 QString applicationIconName() const;
158 // TODO remove and let only constructor do it?
159 void setApplicationIconName(const QString &applicationIconName);
160
161 Notifications::JobState state() const;
162 void setState(Notifications::JobState jobState);
163
164 int percentage() const;
165
166 int error() const;
167 void setError(int error);
168
169 QString errorText() const;
170 void setErrorText(const QString &errorText);
171
172 bool suspendable() const;
173 // TODO remove and let only constructor do it?
174 void setSuspendable(bool suspendable);
175
176 bool killable() const;
177 // TODO remove and let only constructor do it?
178 void setKillable(bool killable);
179
180 bool transient() const;
181 void setTransient(bool transient);
182
183 QUrl destUrl() const;
184
185 QUrl effectiveDestUrl() const;
186
187 qulonglong speed() const;
188
189 qulonglong processedBytes() const;
190 qulonglong processedFiles() const;
191 qulonglong processedDirectories() const;
192 qulonglong processedItems() const;
193
194 qulonglong totalBytes() const;
195 qulonglong totalFiles() const;
196 qulonglong totalDirectories() const;
197 qulonglong totalItems() const;
198
199 QString descriptionLabel1() const;
200 QString descriptionValue1() const;
201
202 QString descriptionLabel2() const;
203 QString descriptionValue2() const;
204
205 bool hasDetails() const;
206
207 QUrl descriptionUrl() const;
208
209 bool expired() const;
210 void setExpired(bool expired);
211
212 bool dismissed() const;
213 void setDismissed(bool dismissed);
214
215 Q_INVOKABLE void suspend();
216 Q_INVOKABLE void resume();
217 Q_INVOKABLE void kill();
218
219Q_SIGNALS:
220 void updatedChanged();
221 void summaryChanged();
222 void textChanged();
223 void stateChanged(Notifications::JobState jobState);
224 void percentageChanged(int percentage);
225 void errorChanged(int error);
226 void errorTextChanged(const QString &errorText);
227 void destUrlChanged();
228 void effectiveDestUrlChanged();
229 void speedChanged();
230 void processedBytesChanged();
231 void processedFilesChanged();
232 void processedDirectoriesChanged();
233 void processedItemsChanged();
234 void processedAmountChanged();
235 void totalBytesChanged();
236 void totalFilesChanged();
237 void totalDirectoriesChanged();
238 void totalItemsChanged();
239 void totalAmountChanged();
240 void descriptionLabel1Changed();
241 void descriptionValue1Changed();
242 void descriptionLabel2Changed();
243 void descriptionValue2Changed();
244 void descriptionUrlChanged();
245 void hasDetailsChanged();
246 void expiredChanged();
247 void dismissedChanged();
248
249private:
250 JobPrivate *d;
251
252 friend class JobsModel;
253 friend class JobsModelPrivate;
254};
255
256} // namespace NotificationManager
Represents a single job.
Definition job.h:32
A model used for listing Job.
Definition jobsmodel.h:23
A model with notifications and jobs.
void suspend()
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.