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
129public:
130 explicit Job(uint id, QObject *parent = nullptr);
131 ~Job() override;
132
133 uint id() const;
134
135 QDateTime created() const;
136
137 QDateTime updated() const;
138 void resetUpdated();
139
140 QString summary() const;
141 QString text() const;
142
143 QString desktopEntry() const;
144 // TODO remove and let only constructor do it?
145 void setDesktopEntry(const QString &desktopEntry);
146
147 QString applicationName() const;
148 // TODO remove and let only constructor do it?
149 void setApplicationName(const QString &applicationName);
150
151 QString applicationIconName() const;
152 // TODO remove and let only constructor do it?
153 void setApplicationIconName(const QString &applicationIconName);
154
155 Notifications::JobState state() const;
156 void setState(Notifications::JobState jobState);
157
158 int percentage() const;
159
160 int error() const;
161 void setError(int error);
162
163 QString errorText() const;
164 void setErrorText(const QString &errorText);
165
166 bool suspendable() const;
167 // TODO remove and let only constructor do it?
168 void setSuspendable(bool suspendable);
169
170 bool killable() const;
171 // TODO remove and let only constructor do it?
172 void setKillable(bool killable);
173
174 bool transient() const;
175 void setTransient(bool transient);
176
177 QUrl destUrl() const;
178
179 qulonglong speed() const;
180
181 qulonglong processedBytes() const;
182 qulonglong processedFiles() const;
183 qulonglong processedDirectories() const;
184 qulonglong processedItems() const;
185
186 qulonglong totalBytes() const;
187 qulonglong totalFiles() const;
188 qulonglong totalDirectories() const;
189 qulonglong totalItems() const;
190
191 QString descriptionLabel1() const;
192 QString descriptionValue1() const;
193
194 QString descriptionLabel2() const;
195 QString descriptionValue2() const;
196
197 bool hasDetails() const;
198
199 QUrl descriptionUrl() const;
200
201 bool expired() const;
202 void setExpired(bool expired);
203
204 bool dismissed() const;
205 void setDismissed(bool dismissed);
206
207 Q_INVOKABLE void suspend();
208 Q_INVOKABLE void resume();
209 Q_INVOKABLE void kill();
210
211Q_SIGNALS:
212 void updatedChanged();
213 void summaryChanged();
214 void textChanged();
215 void stateChanged(Notifications::JobState jobState);
216 void percentageChanged(int percentage);
217 void errorChanged(int error);
218 void errorTextChanged(const QString &errorText);
219 void destUrlChanged();
220 void speedChanged();
221 void processedBytesChanged();
222 void processedFilesChanged();
223 void processedDirectoriesChanged();
224 void processedItemsChanged();
225 void processedAmountChanged();
226 void totalBytesChanged();
227 void totalFilesChanged();
228 void totalDirectoriesChanged();
229 void totalItemsChanged();
230 void totalAmountChanged();
231 void descriptionLabel1Changed();
232 void descriptionValue1Changed();
233 void descriptionLabel2Changed();
234 void descriptionValue2Changed();
235 void descriptionUrlChanged();
236 void hasDetailsChanged();
237 void expiredChanged();
238 void dismissedChanged();
239
240private:
241 JobPrivate *d;
242
243 friend class JobsModel;
244 friend class JobsModelPrivate;
245};
246
247} // 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 Tue Mar 26 2024 11:17:42 by doxygen 1.10.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.