Changeset View
Changeset View
Standalone View
Standalone View
applets/systemmonitor/systemmonitor/systemmonitor.h
- This file was added.
1 | /*************************************************************************** | ||||
---|---|---|---|---|---|
2 | * Copyright (C) 2019 Marco Martin <mart@kde.org> * | ||||
3 | * | ||||
4 | * * | ||||
5 | * This program is free software; you can redistribute it and/or modify * | ||||
6 | * it under the terms of the GNU General Public License as published by * | ||||
7 | * the Free Software Foundation; either version 2 of the License, or * | ||||
8 | * (at your option) any later version. * | ||||
9 | * * | ||||
10 | * This program is distributed in the hope that it will be useful, * | ||||
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of * | ||||
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * | ||||
13 | * GNU General Public License for more details. * | ||||
14 | * * | ||||
15 | * You should have received a copy of the GNU General Public License * | ||||
16 | * along with this program; if not, write to the * | ||||
17 | * Free Software Foundation, Inc., * | ||||
18 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA . * | ||||
19 | ***************************************************************************/ | ||||
20 | | ||||
21 | #pragma once | ||||
22 | | ||||
23 | #include <QPointer> | ||||
24 | #include <QStandardItemModel> | ||||
25 | #include <Plasma/Applet> | ||||
26 | | ||||
27 | #include <KDesktopFile> | ||||
28 | #include <KPackage/Package> | ||||
29 | | ||||
30 | #include <KNewStuff3/KNS3/DownloadDialog> | ||||
31 | | ||||
32 | class ApplicationListModel; | ||||
33 | class QQuickItem; | ||||
34 | | ||||
35 | class KConfigLoader; | ||||
36 | | ||||
37 | namespace KDeclarative { | ||||
38 | class ConfigPropertyMap; | ||||
39 | } | ||||
40 | | ||||
41 | class FacesModel : public QStandardItemModel | ||||
42 | { | ||||
43 | Q_OBJECT | ||||
44 | public: | ||||
45 | enum AdditionalRoles { | ||||
46 | ModelDataRole = Qt::UserRole + 1, | ||||
47 | PluginIdRole | ||||
48 | }; | ||||
49 | Q_ENUM(AdditionalRoles) | ||||
50 | | ||||
51 | FacesModel(QObject *parent = nullptr); | ||||
52 | ~FacesModel() = default; | ||||
53 | | ||||
54 | void load(); | ||||
55 | | ||||
56 | Q_INVOKABLE QString pluginId(int row); | ||||
57 | | ||||
58 | QHash<int, QByteArray> roleNames() const override; | ||||
59 | }; | ||||
60 | | ||||
61 | class PresetsModel : public QStandardItemModel | ||||
62 | { | ||||
63 | Q_OBJECT | ||||
64 | public: | ||||
65 | enum AdditionalRoles { | ||||
66 | ModelDataRole = Qt::UserRole + 1, | ||||
67 | PluginIdRole, | ||||
68 | ConfigRole, | ||||
69 | WritableRole | ||||
70 | }; | ||||
71 | Q_ENUM(AdditionalRoles) | ||||
72 | | ||||
73 | PresetsModel(QObject *parent = nullptr); | ||||
74 | ~PresetsModel() = default; | ||||
75 | | ||||
76 | Q_INVOKABLE QString pluginId(int row) const; // really needed? | ||||
77 | | ||||
78 | QHash<int, QByteArray> roleNames() const override; | ||||
79 | }; | ||||
80 | | ||||
81 | class SystemMonitor : public Plasma::Applet | ||||
82 | { | ||||
83 | Q_OBJECT | ||||
84 | Q_PROPERTY(QString face READ face NOTIFY faceChanged) | ||||
85 | Q_PROPERTY(QString faceName READ faceName NOTIFY faceChanged) | ||||
86 | Q_PROPERTY(QString currentPreset READ currentPreset WRITE setCurrentPreset NOTIFY currentPresetChanged) | ||||
87 | Q_PROPERTY(QString faceIcon READ faceIcon NOTIFY faceChanged) | ||||
88 | Q_PROPERTY(QString compactRepresentationPath READ compactRepresentationPath NOTIFY faceChanged) | ||||
89 | Q_PROPERTY(QString fullRepresentationPath READ fullRepresentationPath NOTIFY faceChanged) | ||||
90 | Q_PROPERTY(QString configPath READ configPath NOTIFY faceChanged) | ||||
91 | | ||||
92 | Q_PROPERTY(bool supportsSensorsColors READ supportsSensorsColors NOTIFY faceChanged) | ||||
93 | Q_PROPERTY(bool supportsTotalSensor READ supportsTotalSensor NOTIFY faceChanged) | ||||
94 | Q_PROPERTY(bool supportsTextOnlySensors READ supportsTextOnlySensors NOTIFY faceChanged) | ||||
95 | | ||||
96 | Q_PROPERTY(QAbstractItemModel *availableFacesModel READ availableFacesModel CONSTANT) | ||||
97 | Q_PROPERTY(QAbstractItemModel *availablePresetsModel READ availablePresetsModel CONSTANT) | ||||
98 | | ||||
99 | /** | ||||
100 | * Configuration object: each config key will be a writable property of this object. property bindings work. | ||||
101 | */ | ||||
102 | Q_PROPERTY(QObject *faceConfiguration READ faceConfiguration NOTIFY faceChanged) | ||||
103 | | ||||
104 | public: | ||||
105 | SystemMonitor( QObject *parent, const QVariantList &args ); | ||||
106 | ~SystemMonitor() override; | ||||
107 | | ||||
108 | void init() override; | ||||
109 | | ||||
110 | // Getter, also for QML | ||||
111 | QString face() const; | ||||
112 | // Setter internal use only | ||||
113 | void setFace(const QString &face); | ||||
114 | | ||||
115 | QString faceName() const; | ||||
116 | QString faceIcon() const; | ||||
117 | | ||||
118 | QString currentPreset() const; | ||||
119 | void setCurrentPreset(const QString &preset); | ||||
120 | | ||||
121 | QString compactRepresentationPath() const; | ||||
122 | QString fullRepresentationPath() const; | ||||
123 | QString configPath() const; | ||||
124 | | ||||
125 | bool supportsSensorsColors() const; | ||||
126 | bool supportsTotalSensor() const; | ||||
127 | bool supportsTextOnlySensors() const; | ||||
128 | | ||||
129 | QAbstractItemModel *availableFacesModel(); | ||||
130 | QAbstractItemModel *availablePresetsModel(); | ||||
131 | | ||||
132 | QObject *faceConfiguration() const; | ||||
133 | | ||||
134 | void reloadAvailablePresetsModel(); | ||||
135 | | ||||
136 | // TODO: should there be a dialog that lets the user insert the metadata? | ||||
137 | void createNewPreset(const QString &pluginName, const QString &comment, const QString &author, const QString &email, const QString &license, const QString &website); | ||||
138 | | ||||
139 | Q_INVOKABLE void savePreset(); | ||||
140 | Q_INVOKABLE void getNewPresets(QQuickItem *ctx); | ||||
141 | Q_INVOKABLE void uninstallPreset(const QString &pluginId); | ||||
142 | | ||||
143 | Q_INVOKABLE void getNewFaces(QQuickItem *ctx); | ||||
144 | | ||||
145 | public Q_SLOTS: | ||||
146 | void configChanged() override; | ||||
147 | | ||||
148 | Q_SIGNALS: | ||||
149 | void faceChanged(); | ||||
150 | void currentPresetChanged(); | ||||
151 | | ||||
152 | private: | ||||
153 | void resetToCustomPresetUserConfiguring(); | ||||
154 | void resetToCustomPreset(); | ||||
155 | | ||||
156 | void getNewStuff(QQuickItem *ctx, const QString &knsrc, const QString &title); | ||||
157 | | ||||
158 | QString m_face; | ||||
159 | QString m_currentPreset; | ||||
160 | QString m_pendingStartupPreset; | ||||
161 | KPackage::Package m_facePackage; | ||||
162 | KDesktopFile *m_faceMetadata = nullptr; | ||||
163 | FacesModel *m_availableFacesModel = nullptr; | ||||
164 | PresetsModel *m_availablePresetsModel = nullptr; | ||||
165 | KConfigLoader *m_faceConfigLoader = nullptr; | ||||
166 | KDeclarative::ConfigPropertyMap *m_faceConfiguration = nullptr; | ||||
167 | | ||||
168 | QPointer<KNS3::DownloadDialog> m_newStuffDialog; | ||||
169 | }; | ||||
170 | |