File indexing completed on 2024-04-28 16:54:33
0001 /* 0002 SPDX-FileCopyrightText: 2019 Kai Uwe Broulik <kde@privat.broulik.de> 0003 0004 SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL 0005 */ 0006 0007 #pragma once 0008 0009 #include <QDateTime> 0010 #include <QString> 0011 #include <QUrl> 0012 0013 #include "notifications.h" 0014 0015 #include "notificationmanager_export.h" 0016 0017 namespace NotificationManager 0018 { 0019 class JobPrivate; 0020 0021 /** 0022 * @short Represents a single job. 0023 * 0024 * A Job represents a special notification that has some progress information and in 0025 * some cases can be suspended or killed. 0026 * 0027 * @author Kai Uwe Broulik <kde@privat.broulik.de> 0028 */ 0029 class NOTIFICATIONMANAGER_EXPORT Job : public QObject 0030 { 0031 Q_OBJECT 0032 0033 /** 0034 * The job infoMessage, e.g. "Copying". 0035 */ 0036 Q_PROPERTY(QString summary READ summary NOTIFY summaryChanged) 0037 /** 0038 * User-friendly compact description text of the job, 0039 * for example "42 of 1337 files to "~/some/folder", or 0040 * "SomeFile.txt to Downloads". 0041 */ 0042 Q_PROPERTY(QString text READ text NOTIFY textChanged) 0043 0044 /** 0045 * The desktop entry of the application owning the job, e.g. "org.kde.dolphin". 0046 */ 0047 Q_PROPERTY(QString desktopEntry READ desktopEntry CONSTANT) 0048 /** 0049 * The user-visible name of the application owning the job, e.g. "Dolphin". 0050 */ 0051 Q_PROPERTY(QString applicationName READ applicationName CONSTANT) 0052 /** 0053 * The icon name of the application owning the job, e.g. "system-file-manager". 0054 */ 0055 Q_PROPERTY(QString applicationIconName READ applicationIconName CONSTANT) 0056 /** 0057 * The state the job is currently in. 0058 */ 0059 Q_PROPERTY(Notifications::JobState state READ state NOTIFY stateChanged) 0060 /** 0061 * The total percentage (0-100) of job completion. 0062 */ 0063 Q_PROPERTY(int percentage READ percentage NOTIFY percentageChanged) 0064 /** 0065 * The error code of the job failure. 0066 */ 0067 Q_PROPERTY(int error READ error NOTIFY errorChanged) 0068 /** 0069 * Whether the job can be suspended. 0070 * 0071 * @sa Notifications::suspendJob 0072 * @sa Notifications::resumeJob 0073 */ 0074 Q_PROPERTY(bool suspendable READ suspendable CONSTANT) 0075 /** 0076 * Whether the job can be aborted. 0077 * 0078 * @sa Notifications::killJob 0079 */ 0080 Q_PROPERTY(bool killable READ killable CONSTANT) 0081 0082 /** 0083 * The destination URL of a job. 0084 */ 0085 Q_PROPERTY(QUrl destUrl READ destUrl NOTIFY destUrlChanged) 0086 0087 /** 0088 * Current transfer rate in Byte/s 0089 */ 0090 Q_PROPERTY(qulonglong speed READ speed NOTIFY speedChanged) 0091 0092 Q_PROPERTY(qulonglong processedBytes READ processedBytes NOTIFY processedBytesChanged) 0093 Q_PROPERTY(qulonglong processedFiles READ processedFiles NOTIFY processedFilesChanged) 0094 Q_PROPERTY(qulonglong processedDirectories READ processedDirectories NOTIFY processedDirectoriesChanged) 0095 Q_PROPERTY(qulonglong processedItems READ processedItems NOTIFY processedItemsChanged) 0096 0097 Q_PROPERTY(qulonglong totalBytes READ totalBytes NOTIFY totalBytesChanged) 0098 Q_PROPERTY(qulonglong totalFiles READ totalFiles NOTIFY totalFilesChanged) 0099 Q_PROPERTY(qulonglong totalDirectories READ totalDirectories NOTIFY totalDirectoriesChanged) 0100 Q_PROPERTY(qulonglong totalItems READ totalItems NOTIFY totalItemsChanged) 0101 0102 Q_PROPERTY(QString descriptionLabel1 READ descriptionLabel1 NOTIFY descriptionLabel1Changed) 0103 Q_PROPERTY(QString descriptionValue1 READ descriptionValue1 NOTIFY descriptionValue1Changed) 0104 0105 Q_PROPERTY(QString descriptionLabel2 READ descriptionLabel2 NOTIFY descriptionLabel2Changed) 0106 Q_PROPERTY(QString descriptionValue2 READ descriptionValue2 NOTIFY descriptionValue2Changed) 0107 0108 /** 0109 * Whether there are any details available for this job. 0110 * 0111 * This is true as soon as any of the following are available: 0112 * - processed amount (of any unit) 0113 * - total amount (of any unit) 0114 * - description label or value (of any row) 0115 * - speed 0116 */ 0117 Q_PROPERTY(bool hasDetails READ hasDetails NOTIFY hasDetailsChanged) 0118 0119 /** 0120 * This tries to generate a valid URL for a file that's being processed by converting descriptionValue2 0121 * (which is assumed to be the Destination) and if that isn't valid, descriptionValue1 to a URL. 0122 */ 0123 Q_PROPERTY(QUrl descriptionUrl READ descriptionUrl NOTIFY descriptionUrlChanged) 0124 0125 public: 0126 explicit Job(uint id, QObject *parent = nullptr); 0127 ~Job() override; 0128 0129 uint id() const; 0130 0131 QDateTime created() const; 0132 0133 QDateTime updated() const; 0134 void resetUpdated(); 0135 0136 QString summary() const; 0137 QString text() const; 0138 0139 QString desktopEntry() const; 0140 // TODO remove and let only constructor do it? 0141 void setDesktopEntry(const QString &desktopEntry); 0142 0143 QString applicationName() const; 0144 // TODO remove and let only constructor do it? 0145 void setApplicationName(const QString &applicationName); 0146 0147 QString applicationIconName() const; 0148 // TODO remove and let only constructor do it? 0149 void setApplicationIconName(const QString &applicationIconName); 0150 0151 Notifications::JobState state() const; 0152 void setState(Notifications::JobState jobState); 0153 0154 int percentage() const; 0155 0156 int error() const; 0157 void setError(int error); 0158 0159 QString errorText() const; 0160 void setErrorText(const QString &errorText); 0161 0162 bool suspendable() const; 0163 // TODO remove and let only constructor do it? 0164 void setSuspendable(bool suspendable); 0165 0166 bool killable() const; 0167 // TODO remove and let only constructor do it? 0168 void setKillable(bool killable); 0169 0170 bool transient() const; 0171 void setTransient(bool transient); 0172 0173 QUrl destUrl() const; 0174 0175 qulonglong speed() const; 0176 0177 qulonglong processedBytes() const; 0178 qulonglong processedFiles() const; 0179 qulonglong processedDirectories() const; 0180 qulonglong processedItems() const; 0181 0182 qulonglong totalBytes() const; 0183 qulonglong totalFiles() const; 0184 qulonglong totalDirectories() const; 0185 qulonglong totalItems() const; 0186 0187 QString descriptionLabel1() const; 0188 QString descriptionValue1() const; 0189 0190 QString descriptionLabel2() const; 0191 QString descriptionValue2() const; 0192 0193 bool hasDetails() const; 0194 0195 QUrl descriptionUrl() const; 0196 0197 bool expired() const; 0198 void setExpired(bool expired); 0199 0200 bool dismissed() const; 0201 void setDismissed(bool dismissed); 0202 0203 Q_INVOKABLE void suspend(); 0204 Q_INVOKABLE void resume(); 0205 Q_INVOKABLE void kill(); 0206 0207 Q_SIGNALS: 0208 void updatedChanged(); 0209 void summaryChanged(); 0210 void textChanged(); 0211 void stateChanged(Notifications::JobState jobState); 0212 void percentageChanged(int percentage); 0213 void errorChanged(int error); 0214 void errorTextChanged(const QString &errorText); 0215 void destUrlChanged(); 0216 void speedChanged(); 0217 void processedBytesChanged(); 0218 void processedFilesChanged(); 0219 void processedDirectoriesChanged(); 0220 void processedItemsChanged(); 0221 void processedAmountChanged(); 0222 void totalBytesChanged(); 0223 void totalFilesChanged(); 0224 void totalDirectoriesChanged(); 0225 void totalItemsChanged(); 0226 void totalAmountChanged(); 0227 void descriptionLabel1Changed(); 0228 void descriptionValue1Changed(); 0229 void descriptionLabel2Changed(); 0230 void descriptionValue2Changed(); 0231 void descriptionUrlChanged(); 0232 void hasDetailsChanged(); 0233 void expiredChanged(); 0234 void dismissedChanged(); 0235 0236 private: 0237 JobPrivate *d; 0238 0239 friend class JobsModel; 0240 friend class JobsModelPrivate; 0241 }; 0242 0243 } // namespace NotificationManager