File indexing completed on 2024-05-05 05:38:28
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 <QDBusContext> 0010 #include <QDBusObjectPath> 0011 #include <QDBusVariant> 0012 #include <QDateTime> 0013 #include <QObject> 0014 #include <QString> 0015 #include <QTimer> 0016 #include <QUrl> 0017 #include <memory> 0018 0019 #include <chrono> 0020 0021 #include "job.h" 0022 #include "notifications.h" 0023 0024 class KFilePlacesModel; 0025 0026 namespace NotificationManager 0027 { 0028 class JobPrivate : public QObject, protected QDBusContext 0029 { 0030 Q_OBJECT 0031 0032 public: 0033 JobPrivate(uint id, QObject *parent); 0034 ~JobPrivate() override; 0035 0036 enum class ShowCondition { 0037 OnTimeout = 1 << 0, 0038 OnSummary = 1 << 1, 0039 OnTermination = 1 << 2, 0040 }; 0041 Q_DECLARE_FLAGS(ShowConditions, ShowCondition) 0042 0043 QDBusObjectPath objectPath() const; 0044 QUrl descriptionUrl() const; 0045 QString text() const; 0046 0047 void delayedShow(std::chrono::milliseconds delay, ShowConditions showConditions); 0048 void kill(); 0049 0050 // DBus 0051 // JobViewV1 0052 void terminate(const QString &errorMessage); 0053 void setSuspended(bool suspended); 0054 void setTotalAmount(quint64 amount, const QString &unit); 0055 void setProcessedAmount(quint64 amount, const QString &unit); 0056 void setPercent(uint percent); 0057 void setSpeed(quint64 bytesPerSecond); 0058 void setInfoMessage(const QString &infoMessage); 0059 bool setDescriptionField(uint number, const QString &name, const QString &value); 0060 void clearDescriptionField(uint number); 0061 void setDestUrl(const QDBusVariant &urlVariant); 0062 void setError(uint errorCode); 0063 0064 // JobViewV2 0065 void terminate(uint errorCode, const QString &errorMessage, const QVariantMap &hints); 0066 void update(const QVariantMap &properties); 0067 0068 Q_SIGNALS: 0069 void showRequested(); 0070 void closed(); 0071 0072 void infoMessageChanged(); 0073 0074 // DBus 0075 // V1 and V2 0076 void suspendRequested(); 0077 void resumeRequested(); 0078 void cancelRequested(); 0079 // V2 0080 void updateRequested(); 0081 0082 private: 0083 friend class Job; 0084 0085 template<typename T> 0086 bool updateField(const T &newValue, T &target, void (Job::*changeSignal)()) 0087 { 0088 if (target != newValue) { 0089 target = newValue; 0090 Q_EMIT((static_cast<Job *>(parent()))->*changeSignal)(); 0091 return true; 0092 } 0093 return false; 0094 } 0095 0096 template<typename T> 0097 bool updateFieldFromProperties(const QVariantMap &properties, const QString &keyName, T &target, void (Job::*changeSignal)()) 0098 { 0099 auto it = properties.find(keyName); 0100 if (it == properties.end()) { 0101 return false; 0102 } 0103 0104 return updateField(it->value<T>(), target, changeSignal); 0105 } 0106 0107 static std::shared_ptr<KFilePlacesModel> createPlacesModel(); 0108 0109 static QUrl localFileOrUrl(const QString &stringUrl); 0110 static QString linkify(const QUrl &url, const QString &caption); 0111 0112 void requestShow(); 0113 0114 QUrl destUrl() const; 0115 QString prettyUrl(const QUrl &url) const; 0116 void updateHasDetails(); 0117 0118 void finish(); 0119 0120 QTimer m_showTimer; 0121 ShowConditions m_showConditions = {}; 0122 bool m_showRequested = false; 0123 0124 QTimer *m_killTimer = nullptr; 0125 0126 uint m_id = 0; 0127 QDBusObjectPath m_objectPath; 0128 0129 QDateTime m_created; 0130 QDateTime m_updated; 0131 0132 QString m_summary; 0133 QString m_infoMessage; 0134 0135 QString m_desktopEntry; 0136 QString m_applicationName; 0137 QString m_applicationIconName; 0138 0139 Notifications::JobState m_state = Notifications::JobStateRunning; 0140 int m_percentage = 0; 0141 int m_error = 0; 0142 QString m_errorText; 0143 bool m_suspendable = false; 0144 bool m_killable = false; 0145 bool m_transient = false; 0146 0147 QUrl m_destUrl; 0148 0149 qulonglong m_speed = 0; 0150 0151 qulonglong m_processedBytes = 0; 0152 qulonglong m_processedFiles = 0; 0153 qulonglong m_processedDirectories = 0; 0154 qulonglong m_processedItems = 0; 0155 0156 qulonglong m_totalBytes = 0; 0157 qulonglong m_totalFiles = 0; 0158 qulonglong m_totalDirectories = 0; 0159 qulonglong m_totalItems = 0; 0160 0161 QString m_descriptionLabel1; 0162 QString m_descriptionValue1; 0163 0164 QString m_descriptionLabel2; 0165 QString m_descriptionValue2; 0166 0167 bool m_hasDetails = false; 0168 0169 bool m_expired = false; 0170 bool m_dismissed = false; 0171 0172 mutable std::shared_ptr<KFilePlacesModel> m_placesModel; 0173 }; 0174 0175 } // namespace NotificationManager 0176 0177 Q_DECLARE_OPERATORS_FOR_FLAGS(NotificationManager::JobPrivate::ShowConditions)