Changeset View
Changeset View
Standalone View
Standalone View
applets/taskmanager/plugin/smartlaunchers/smartlauncherbackend.h
1 | /*************************************************************************** | 1 | /*************************************************************************** | ||
---|---|---|---|---|---|
2 | * Copyright (C) 2016 Kai Uwe Broulik <kde@privat.broulik.de> * | 2 | * Copyright (C) 2016, 2019 Kai Uwe Broulik <kde@privat.broulik.de> * | ||
3 | * * | 3 | * * | ||
4 | * This program is free software; you can redistribute it and/or modify * | 4 | * This program is free software; you can redistribute it and/or modify * | ||
5 | * it under the terms of the GNU General Public License as published by * | 5 | * it under the terms of the GNU General Public License as published by * | ||
6 | * the Free Software Foundation; either version 2 of the License, or * | 6 | * the Free Software Foundation; either version 2 of the License, or * | ||
7 | * (at your option) any later version. * | 7 | * (at your option) any later version. * | ||
8 | * * | 8 | * * | ||
9 | * This program is distributed in the hope that it will be useful, * | 9 | * This program is distributed in the hope that it will be useful, * | ||
10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of * | 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of * | ||
Show All 9 Lines | |||||
20 | #ifndef SMARTLAUNCHER_BACKEND_H | 20 | #ifndef SMARTLAUNCHER_BACKEND_H | ||
21 | #define SMARTLAUNCHER_BACKEND_H | 21 | #define SMARTLAUNCHER_BACKEND_H | ||
22 | 22 | | |||
23 | #include <QObject> | 23 | #include <QObject> | ||
24 | #include <QDBusContext> | 24 | #include <QDBusContext> | ||
25 | #include <QHash> | 25 | #include <QHash> | ||
26 | #include <QVariantMap> | 26 | #include <QVariantMap> | ||
27 | 27 | | |||
28 | #include <Plasma/DataEngine> | 28 | #include <notificationmanager/jobsmodel.h> | ||
29 | 29 | | |||
30 | class QDBusServiceWatcher; | 30 | class QDBusServiceWatcher; | ||
31 | class QString; | 31 | class QString; | ||
32 | 32 | | |||
33 | namespace Plasma { | 33 | namespace NotificationManager | ||
34 | class DataEngineConsumer; | 34 | { | ||
35 | class Settings; | ||||
35 | } | 36 | } | ||
36 | 37 | | |||
37 | namespace SmartLauncher { | 38 | namespace SmartLauncher { | ||
38 | 39 | | |||
39 | struct Entry | 40 | struct Entry | ||
40 | { | 41 | { | ||
41 | int count = 0; | 42 | int count = 0; | ||
42 | bool countVisible = false; | 43 | bool countVisible = false; | ||
43 | int progress = 0; | 44 | int progress = 0; | ||
44 | bool progressVisible = false; | 45 | bool progressVisible = false; | ||
45 | bool urgent = false; | 46 | bool urgent = false; | ||
46 | }; | 47 | }; | ||
47 | 48 | | |||
48 | class Backend : public QObject, protected QDBusContext | 49 | class Backend : public QObject, protected QDBusContext | ||
49 | { | 50 | { | ||
50 | Q_OBJECT | 51 | Q_OBJECT | ||
51 | 52 | | |||
52 | public: | 53 | public: | ||
53 | explicit Backend(QObject *parent = nullptr); | 54 | explicit Backend(QObject *parent = nullptr); | ||
54 | ~Backend() override; | 55 | ~Backend() override; | ||
55 | 56 | | |||
56 | bool available() const; | | |||
57 | bool hasLauncher(const QString &storageId) const; | 57 | bool hasLauncher(const QString &storageId) const; | ||
58 | 58 | | |||
59 | int count(const QString &uri) const; | 59 | int count(const QString &uri) const; | ||
60 | bool countVisible(const QString &uri) const; | 60 | bool countVisible(const QString &uri) const; | ||
61 | int progress(const QString &uri) const; | 61 | int progress(const QString &uri) const; | ||
62 | bool progressVisible(const QString &uri) const; | 62 | bool progressVisible(const QString &uri) const; | ||
63 | bool urgent(const QString &uri) const; | 63 | bool urgent(const QString &uri) const; | ||
64 | 64 | | |||
65 | QHash<QString, QString> unityMappingRules() const; | 65 | QHash<QString, QString> unityMappingRules() const; | ||
66 | 66 | | |||
67 | public slots: | | |||
68 | void dataUpdated(const QString &sourceName, const Plasma::DataEngine::Data &data); | | |||
69 | | ||||
70 | signals: | 67 | signals: | ||
71 | void countChanged(const QString &uri, int count); | 68 | void countChanged(const QString &uri, int count); | ||
72 | void countVisibleChanged(const QString &uri, bool countVisible); | 69 | void countVisibleChanged(const QString &uri, bool countVisible); | ||
73 | void progressChanged(const QString &uri, int progress); | 70 | void progressChanged(const QString &uri, int progress); | ||
74 | void progressVisibleChanged(const QString &uri, bool progressVisible); | 71 | void progressVisibleChanged(const QString &uri, bool progressVisible); | ||
75 | void urgentChanged(const QString &uri, bool urgent); | 72 | void urgentChanged(const QString &uri, bool urgent); | ||
76 | 73 | | |||
74 | void reloadRequested(const QString &uri); | ||||
77 | void launcherRemoved(const QString &uri); | 75 | void launcherRemoved(const QString &uri); | ||
78 | 76 | | |||
79 | private slots: | 77 | private slots: | ||
80 | void update(const QString &uri, const QMap<QString, QVariant> &properties); | 78 | void update(const QString &uri, const QMap<QString, QVariant> &properties); | ||
81 | 79 | | |||
82 | private: | 80 | private: | ||
83 | bool setupUnity(); | 81 | void reload(); | ||
84 | bool setupApplicationJobs(); | 82 | void setupUnity(); | ||
83 | void setupApplicationJobs(); | ||||
85 | 84 | | |||
86 | void onServiceUnregistered(const QString &service); | 85 | void onServiceUnregistered(const QString &service); | ||
87 | 86 | | |||
88 | template <typename T> | 87 | template <typename T> | ||
89 | void updateLauncherProperty(const QString &storageId, // our KService storage id | 88 | void updateLauncherProperty(const QString &storageId, // our KService storage id | ||
90 | const QVariantMap &properties, // the map of properties we're given by DBus | 89 | const QVariantMap &properties, // the map of properties we're given by DBus | ||
91 | const QString &property, // the property we're looking for | 90 | const QString &property, // the property we're looking for | ||
92 | T *entryMember, // the member variable we're going to write our result in | 91 | T *entryMember, // the member variable we're going to write our result in | ||
92 | // the getter for this property which might return something different from the raw value | ||||
93 | T (Backend::*getter)(const QString &) const, | ||||
93 | // the change signal that will be emitted if the property has changed | 94 | // the change signal that will be emitted if the property has changed | ||
94 | void (Backend::*changeSignal)(const QString &, T)) | 95 | void (Backend::*changeSignal)(const QString &, T)) | ||
95 | { | 96 | { | ||
96 | auto foundProperty = properties.constFind(property); | 97 | auto foundProperty = properties.constFind(property); | ||
97 | if (foundProperty != properties.constEnd()) { | 98 | if (foundProperty != properties.constEnd()) { | ||
98 | T newValue = foundProperty->value<T>(); | 99 | const T oldSanitizedValue = ((this)->*getter)(storageId); | ||
99 | 100 | | |||
100 | if (newValue != *entryMember) { | 101 | T newValue = foundProperty->value<T>(); | ||
101 | *entryMember = newValue; | 102 | *entryMember = newValue; | ||
102 | emit ((this)->*changeSignal)(storageId, newValue); | 103 | | ||
104 | const T newSanitizedValue = ((this)->*getter)(storageId); | ||||
105 | | ||||
106 | if (newSanitizedValue != oldSanitizedValue) { | ||||
107 | emit ((this)->*changeSignal)(storageId, newSanitizedValue); | ||||
103 | } | 108 | } | ||
104 | } | 109 | } | ||
105 | } | 110 | } | ||
106 | 111 | | |||
107 | void onApplicationJobAdded(const QString &source); | 112 | bool doNotDisturbMode() const; | ||
108 | void onApplicationJobRemoved(const QString &source); | | |||
109 | void updateApplicationJobPercent(const QString &storageId, Entry *entry); | | |||
110 | 113 | | |||
111 | // Unity Launchers | 114 | // Unity Launchers | ||
112 | QDBusServiceWatcher *m_watcher; | 115 | QDBusServiceWatcher *m_watcher; | ||
113 | QHash<QString, QString> m_dbusServiceToLauncherUrl; | 116 | QHash<QString, QString> m_dbusServiceToLauncherUrl; | ||
114 | QHash<QString, QString> m_launcherUrlToStorageId; | 117 | QHash<QString, QString> m_launcherUrlToStorageId; | ||
115 | // these rules can be configured in the taskmanagerrulesrc in the "Unity Launcher Mapping" section | 118 | // these rules can be configured in the taskmanagerrulesrc in the "Unity Launcher Mapping" section | ||
116 | // key is the actual desktop file name of the application (some-broken-app-beta.desktop) | 119 | // key is the actual desktop file name of the application (some-broken-app-beta.desktop) | ||
117 | // vaue is how it actually announces itself on the Unity API (some-broken-app.desktop) | 120 | // vaue is how it actually announces itself on the Unity API (some-broken-app.desktop) | ||
118 | QHash<QString, QString> m_unityMappingRules; | 121 | QHash<QString, QString> m_unityMappingRules; | ||
119 | 122 | | |||
120 | // Application Jobs | 123 | // Application Jobs | ||
121 | Plasma::DataEngineConsumer *m_dataEngineConsumer; | 124 | NotificationManager::JobsModel::Ptr m_jobsModel; | ||
122 | Plasma::DataEngine *m_dataEngine; | 125 | | ||
123 | QHash<QString, QString> m_dataSourceToStorageId; // <Job 1, foo.desktop> | 126 | NotificationManager::Settings *m_settings = nullptr; | ||
124 | QHash<QString, QStringList> m_storageIdToJobs; // <foo.desktop, <Job 1, Job 2, ..>> | | |||
125 | QHash<QString, int> m_jobProgress; // <Job 1, 42> | | |||
126 | 127 | | |||
127 | QHash<QString, Entry> m_launchers; | 128 | QHash<QString, Entry> m_launchers; | ||
128 | 129 | | |||
130 | QStringList m_badgeBlacklist; | ||||
131 | | ||||
129 | bool m_available = false; | 132 | bool m_available = false; | ||
130 | 133 | | |||
131 | }; | 134 | }; | ||
132 | 135 | | |||
133 | } // namespace SmartLauncher | 136 | } // namespace SmartLauncher | ||
134 | 137 | | |||
135 | #endif // SMARTLAUNCHER_BACKEND_H | 138 | #endif // SMARTLAUNCHER_BACKEND_H |