Changeset View
Changeset View
Standalone View
Standalone View
libnotificationmanager/job.h
- This file was added.
1 | /* | ||||
---|---|---|---|---|---|
2 | * Copyright 2019 Kai Uwe Broulik <kde@privat.broulik.de> | ||||
3 | * | ||||
4 | * This library is free software; you can redistribute it and/or | ||||
5 | * modify it under the terms of the GNU Lesser General Public | ||||
6 | * License as published by the Free Software Foundation; either | ||||
7 | * version 2.1 of the License, or (at your option) version 3, or any | ||||
8 | * later version accepted by the membership of KDE e.V. (or its | ||||
9 | * successor approved by the membership of KDE e.V.), which shall | ||||
10 | * act as a proxy defined in Section 6 of version 3 of the license. | ||||
11 | * | ||||
12 | * This library 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 GNU | ||||
15 | * Lesser General Public License for more details. | ||||
16 | * | ||||
17 | * You should have received a copy of the GNU Lesser General Public | ||||
18 | * License along with this library. If not, see <http://www.gnu.org/licenses/>. | ||||
19 | */ | ||||
20 | | ||||
21 | #pragma once | ||||
22 | | ||||
23 | #include <QDateTime> | ||||
24 | #include <QString> | ||||
25 | #include <QUrl> | ||||
26 | | ||||
27 | #include "notifications.h" | ||||
28 | | ||||
29 | #include "notificationmanager_export.h" | ||||
30 | | ||||
31 | namespace NotificationManager | ||||
32 | { | ||||
33 | | ||||
34 | class JobPrivate; | ||||
35 | | ||||
36 | class NOTIFICATIONMANAGER_EXPORT Job : public QObject | ||||
37 | { | ||||
38 | Q_OBJECT | ||||
39 | | ||||
40 | /** | ||||
41 | * The job infoMessage, e.g. "Copying". | ||||
42 | */ | ||||
43 | Q_PROPERTY(QString summary READ summary NOTIFY summaryChanged) | ||||
44 | /** | ||||
45 | * User-friendly compact description text of the job, | ||||
46 | * for example "42 of 1337 files to "~/some/folder", or | ||||
47 | * "SomeFile.txt to Downloads". | ||||
48 | */ | ||||
49 | Q_PROPERTY(QString text READ text NOTIFY textChanged) | ||||
50 | | ||||
51 | /** | ||||
52 | * The desktop entry of the application owning the job, e.g. "org.kde.dolphin". | ||||
53 | */ | ||||
54 | Q_PROPERTY(QString desktopEntry READ desktopEntry CONSTANT) | ||||
55 | /** | ||||
56 | * The user-visible name of the application owning the job, e.g. "Dolphin". | ||||
57 | */ | ||||
58 | Q_PROPERTY(QString applicationName READ applicationName CONSTANT) | ||||
59 | /** | ||||
60 | * The icon name of the application owning the job, e.g. "system-file-manager". | ||||
61 | */ | ||||
62 | Q_PROPERTY(QString applicationIconName READ applicationIconName CONSTANT) | ||||
63 | /** | ||||
64 | * The state the job is currently in. | ||||
65 | */ | ||||
66 | Q_PROPERTY(Notifications::JobState state READ state NOTIFY stateChanged) | ||||
67 | /** | ||||
68 | * The total percentage (0-100) of job completion. | ||||
69 | */ | ||||
70 | Q_PROPERTY(int percentage READ percentage NOTIFY percentageChanged) | ||||
71 | /** | ||||
72 | * The error code of the job failure. | ||||
73 | */ | ||||
74 | Q_PROPERTY(int error READ error NOTIFY errorChanged) | ||||
75 | /** | ||||
76 | * Whether the job can be suspended. | ||||
77 | * | ||||
78 | * @sa Notifications::suspendJob | ||||
79 | * @sa Notifications::resumeJob | ||||
80 | */ | ||||
81 | Q_PROPERTY(bool suspendable READ suspendable CONSTANT) | ||||
82 | /** | ||||
83 | * Whether the job can be aborted. | ||||
84 | * | ||||
85 | * @sa Notifications::killJob | ||||
86 | */ | ||||
87 | Q_PROPERTY(bool killable READ killable CONSTANT) | ||||
88 | | ||||
89 | /** | ||||
90 | * The destination URL of a job. | ||||
91 | */ | ||||
92 | Q_PROPERTY(QUrl destUrl READ destUrl NOTIFY destUrlChanged) | ||||
93 | | ||||
94 | /** | ||||
95 | * Current transfer rate in Byte/s | ||||
96 | */ | ||||
97 | Q_PROPERTY(qulonglong speed READ speed NOTIFY speedChanged) | ||||
98 | | ||||
99 | Q_PROPERTY(qulonglong processedBytes READ processedBytes NOTIFY processedBytesChanged) | ||||
100 | Q_PROPERTY(qulonglong processedFiles READ processedFiles NOTIFY processedFilesChanged) | ||||
101 | Q_PROPERTY(qulonglong processedDirectories READ processedDirectories NOTIFY processedDirectoriesChanged) | ||||
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 | | ||||
107 | Q_PROPERTY(QString descriptionLabel1 READ descriptionLabel1 NOTIFY descriptionLabel1Changed) | ||||
108 | Q_PROPERTY(QString descriptionValue1 READ descriptionValue1 NOTIFY descriptionValue1Changed) | ||||
109 | | ||||
110 | Q_PROPERTY(QString descriptionLabel2 READ descriptionLabel2 NOTIFY descriptionLabel2Changed) | ||||
111 | Q_PROPERTY(QString descriptionValue2 READ descriptionValue2 NOTIFY descriptionValue2Changed) | ||||
112 | | ||||
113 | /** | ||||
114 | * Whether there are any details available for this job. | ||||
115 | * | ||||
116 | * This is true as soon as any of the following are available: | ||||
117 | * - processed amount (of any unit) | ||||
118 | * - total amount (of any unit) | ||||
119 | * - description label or value (of any row) | ||||
120 | * - speed | ||||
121 | */ | ||||
122 | Q_PROPERTY(bool hasDetails READ hasDetails NOTIFY hasDetailsChanged) | ||||
123 | | ||||
124 | /** | ||||
125 | * This tries to generate a valid URL for a file that's being processed by converting descriptionValue2 | ||||
126 | * (which is assumed to be the Destination) and if that isn't valid, descriptionValue1 to a URL. | ||||
127 | */ | ||||
128 | Q_PROPERTY(QUrl descriptionUrl READ descriptionUrl NOTIFY descriptionUrlChanged) | ||||
129 | | ||||
130 | public: | ||||
131 | explicit Job(uint id, QObject *parent = nullptr); | ||||
132 | ~Job() override; | ||||
133 | | ||||
134 | uint id() const; | ||||
135 | | ||||
136 | QDateTime created() const; | ||||
137 | | ||||
138 | QDateTime updated() const; | ||||
139 | void resetUpdated(); | ||||
140 | | ||||
141 | QString summary() const; | ||||
142 | QString text() const; | ||||
143 | | ||||
144 | QString desktopEntry() const; | ||||
145 | // TODO remove and let only constructor do it? | ||||
146 | void setDesktopEntry(const QString &desktopEntry); | ||||
147 | | ||||
148 | QString applicationName() const; | ||||
149 | // TODO remove and let only constructor do it? | ||||
150 | void setApplicationName(const QString &applicationName); | ||||
151 | | ||||
152 | QString applicationIconName() const; | ||||
153 | // TODO remove and let only constructor do it? | ||||
154 | void setApplicationIconName(const QString &applicationIconName); | ||||
155 | | ||||
156 | Notifications::JobState state() const; | ||||
157 | void setState(Notifications::JobState jobState); | ||||
158 | | ||||
159 | int percentage() const; | ||||
160 | | ||||
161 | int error() const; | ||||
162 | void setError(int error); | ||||
163 | | ||||
164 | QString errorText() const; | ||||
165 | void setErrorText(const QString &errorText); | ||||
166 | | ||||
167 | bool suspendable() const; | ||||
168 | // TODO remove and let only constructor do it? | ||||
169 | void setSuspendable(bool suspendable); | ||||
170 | | ||||
171 | bool killable() const; | ||||
172 | // TODO remove and let only constructor do it? | ||||
173 | void setKillable(bool killable); | ||||
174 | | ||||
175 | QUrl destUrl() const; | ||||
176 | | ||||
177 | qulonglong speed() const; | ||||
178 | | ||||
179 | qulonglong processedBytes() const; | ||||
180 | qulonglong processedFiles() const; | ||||
181 | qulonglong processedDirectories() const; | ||||
182 | | ||||
183 | qulonglong totalBytes() const; | ||||
184 | qulonglong totalFiles() const; | ||||
185 | qulonglong totalDirectories() const; | ||||
186 | | ||||
187 | QString descriptionLabel1() const; | ||||
188 | QString descriptionValue1() const; | ||||
189 | | ||||
190 | QString descriptionLabel2() const; | ||||
191 | QString descriptionValue2() const; | ||||
192 | | ||||
193 | bool hasDetails() const; | ||||
194 | | ||||
195 | QUrl descriptionUrl() const; | ||||
196 | | ||||
197 | bool expired() const; | ||||
198 | void setExpired(bool expired); | ||||
199 | | ||||
200 | bool dismissed() const; | ||||
201 | void setDismissed(bool dismissed); | ||||
202 | | ||||
203 | Q_INVOKABLE void suspend(); | ||||
204 | Q_INVOKABLE void resume(); | ||||
205 | Q_INVOKABLE void kill(); | ||||
206 | | ||||
207 | signals: | ||||
208 | void updatedChanged(); | ||||
209 | void summaryChanged(); | ||||
210 | void textChanged(); | ||||
211 | void stateChanged(Notifications::JobState jobState); | ||||
212 | void percentageChanged(int percentage); | ||||
213 | void errorChanged(int error); | ||||
214 | void errorTextChanged(const QString &errorText); | ||||
215 | void destUrlChanged(); | ||||
216 | void speedChanged(); | ||||
217 | void processedBytesChanged(); | ||||
218 | void processedFilesChanged(); | ||||
219 | void processedDirectoriesChanged(); | ||||
220 | void processedAmountChanged(); | ||||
221 | void totalBytesChanged(); | ||||
222 | void totalFilesChanged(); | ||||
223 | void totalDirectoriesChanged(); | ||||
224 | void totalAmountChanged(); | ||||
225 | void descriptionLabel1Changed(); | ||||
226 | void descriptionValue1Changed(); | ||||
227 | void descriptionLabel2Changed(); | ||||
228 | void descriptionValue2Changed(); | ||||
229 | void descriptionUrlChanged(); | ||||
230 | void hasDetailsChanged(); | ||||
231 | void expiredChanged(); | ||||
232 | void dismissedChanged(); | ||||
233 | | ||||
234 | private: | ||||
235 | JobPrivate *d; | ||||
236 | | ||||
237 | friend class JobsModel; | ||||
238 | friend class JobsModelPrivate; | ||||
239 | | ||||
240 | }; | ||||
241 | | ||||
242 | } // namespace NotificationManager |