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