Libksysguard

SensorFaceController.h
1/*
2 SPDX-FileCopyrightText: 2020 Marco Martin <mart@kde.org>
3
4 SPDX-License-Identifier: LGPL-2.0-or-later
5*/
6
7#pragma once
8
9#include <QAbstractItemModel>
10#include <QObject>
11#include <QPointer>
12#include <QQuickItem>
13
14#include <KConfigGroup>
15
16#include "sensorfaces_export.h"
17
19class QQmlEngine;
20class KDesktopFile;
21class KConfigLoader;
22
23namespace KSysGuard
24{
25class SensorFace;
26class SensorFaceControllerPrivate;
27
28/**
29 * The SensorFaceController links sensor faces and applications in which these faces are shown. It
30 * abstracts the configuration and properties of faces.
31 *
32 * For faces it offers information about which sensors should be displayed and hints set by the
33 * application about how the information should be displayed. It can be accessed by faces using
34 * the `SensorFace::controller` property.
35 *
36 * Applications can use this class to instantiate faces from a given config and for querying the
37 * capabilities of faces.
38 *
39 * @since 5.19
40 */
41class SENSORFACES_EXPORT SensorFaceController : public QObject
42{
43 Q_OBJECT
44 QML_ELEMENT
45 QML_UNCREATABLE("It's not possible to create objects of type SensorFaceController")
46 /**
47 * A title for the face.
48 * @see showTitle
49 */
50 Q_PROPERTY(QString title READ title WRITE setTitle NOTIFY titleChanged)
51 /** Whether the title should be displayed or if it should be hidden instead
52 * @see title
53 */
54 Q_PROPERTY(bool showTitle READ showTitle WRITE setShowTitle NOTIFY showTitleChanged)
55 /**
56 * The id of the current face. For example `org.kde.ksysguard.textonly`
57 */
58 Q_PROPERTY(QString faceId READ faceId WRITE setFaceId NOTIFY faceIdChanged)
59 /**
60 * Sensors that are typically used to display a total in some way or form. For example in the pie
61 * char face they are not drawn as part of the chart but appear in the centre of it.
62 */
63 Q_PROPERTY(QJsonArray totalSensors READ totalSensors WRITE setTotalSensors NOTIFY totalSensorsChanged)
64 /**
65 * Sensors that should always be shown in the face. This is the main list of sensors that are of
66 * the most interest.
67 */
68 Q_PROPERTY(QJsonArray highPrioritySensorIds READ highPrioritySensorIds WRITE setHighPrioritySensorIds NOTIFY highPrioritySensorIdsChanged)
69 /**
70 * Maps sensorIds to colors that can be used when a color for something relating to a
71 * specific sensor is needed.
72 */
73 Q_PROPERTY(QVariantMap sensorColors READ sensorColors WRITE setSensorColors NOTIFY sensorColorsChanged)
74
75 /**
76 * Maps sensorIds to user configurable labels than should be displayed instead of the name of the sensor.
77 */
78 Q_PROPERTY(QVariantMap sensorLabels READ sensorLabels WRITE setSensorLabels NOTIFY sensorLabelsChanged)
79
80 /**
81 * Secondary list of sensors. These sensors do not necessarily appear in main part of the face.
82 * For example in most faces they are just added to the legend.
83 */
84 Q_PROPERTY(QJsonArray lowPrioritySensorIds READ lowPrioritySensorIds WRITE setLowPrioritySensorIds NOTIFY lowPrioritySensorIdsChanged)
85
86 /**
87 * The name of the current face
88 */
89 Q_PROPERTY(QString name READ name NOTIFY faceIdChanged)
90 /**
91 * The icon of the current face
92 */
93 Q_PROPERTY(QString icon READ icon NOTIFY faceIdChanged)
94 /**
95 * Whether the current face supports sensor colors
96 */
97 Q_PROPERTY(bool supportsSensorsColors READ supportsSensorsColors NOTIFY faceIdChanged)
98 /**
99 * Whether the current face can display total sensors
100 */
101 Q_PROPERTY(bool supportsTotalSensors READ supportsTotalSensors NOTIFY faceIdChanged)
102 /**
103 * Whether the current face can display low priority sensors
104 */
105 Q_PROPERTY(bool supportsLowPrioritySensors READ supportsLowPrioritySensors NOTIFY faceIdChanged)
106 /**
107 * The amount of total sensors the current face supports
108 */
109 Q_PROPERTY(int maxTotalSensors READ maxTotalSensors NOTIFY faceIdChanged)
110 /**
111 * A map of config options and values that are specific to the current face as defined by the
112 * `main.xml` of the face.
113 * @see faceConfigUi
114 */
115 Q_PROPERTY(KConfigPropertyMap *faceConfiguration READ faceConfiguration NOTIFY faceConfigurationChanged)
116
117 /**
118 * The full representation of the current face. Typically includes additional elements like
119 * a legend or title
120 */
121 Q_PROPERTY(QQuickItem *fullRepresentation READ fullRepresentation NOTIFY faceIdChanged)
122 /**
123 * The compact representation of the current face. Typically only includes the main visualization
124 * of the data without legend, title, etc.
125 */
126 Q_PROPERTY(QQuickItem *compactRepresentation READ compactRepresentation NOTIFY faceIdChanged)
127 /**
128 * A user interface that is suited for configuring the face specific options.
129 * Emits `configurationChanged` if a config value changed. To apply the changes call `saveConfig`
130 * on it.
131 * @see faceConfiguration
132 */
133 Q_PROPERTY(QQuickItem *faceConfigUi READ faceConfigUi NOTIFY faceIdChanged)
134 /**
135 * A user interface for configuring the general appearance of a face like the title and the used
136 * face.
137 * Emits `configurationChanged` if a config value changed. To apply the changes call `saveConfig`
138 * on it.
139 */
140 Q_PROPERTY(QQuickItem *appearanceConfigUi READ appearanceConfigUi NOTIFY faceIdChanged)
141 /**
142 * A user interface for configuring which sensors are displayed in a face
143 * Emits `configurationChanged` if a config value changed. To apply the changes call `saveConfig`
144 * on it.
145 */
146 Q_PROPERTY(QQuickItem *sensorsConfigUi READ sensorsConfigUi NOTIFY faceIdChanged)
147
148 /**
149 * A list of all available faces. The name is available as the display role and the id as `pluginId`
150 */
151 Q_PROPERTY(QAbstractItemModel *availableFacesModel READ availableFacesModel CONSTANT)
152 /**
153 * A list of available face presets. The name is available as the display role, the id as `pluginId`.
154 * The properties of the preset can be accessed via the `config` role.
155 */
156 Q_PROPERTY(QAbstractItemModel *availablePresetsModel READ availablePresetsModel CONSTANT)
157 /**
158 * The minimum time that needs to elapse, in milliseconds, between updates of the face.
159 */
160 Q_PROPERTY(int updateRateLimit READ updateRateLimit WRITE setUpdateRateLimit NOTIFY updateRateLimitChanged)
161 /**
162 * Contains the paths of missing sensors, if there are any.
163 */
164 Q_PROPERTY(QJsonArray missingSensors READ missingSensors NOTIFY missingSensorsChanged)
165
166public:
167 /**
168 * Creates a new SensorFaceController.
169 * This is only useful for applications that want display SensorFaces.
170 *
171 * SensorFaces can access the controller that created them using their `SensorFace::controller`
172 * property.
173 * @param config The controller uses this config group to read and save the face configuration
174 * @param engine This engine will be used for creating the Qml components
175 */
176 SensorFaceController(KConfigGroup &config, QQmlEngine *engine, QQmlEngine *configEngine);
177 ~SensorFaceController() override;
178
179 /**
180 * Retrieve the KConfigGroup this controller is using to store configuration.
181 *
182 * This is primarily intended to allow adding child groups to the face
183 * configuration.
184 */
185 KConfigGroup configGroup() const;
186
187 void setFaceId(const QString &face);
188 QString faceId() const;
189
190 QQuickItem *fullRepresentation();
191 QQuickItem *compactRepresentation();
192 QQuickItem *faceConfigUi();
193 QQuickItem *appearanceConfigUi();
194 QQuickItem *sensorsConfigUi();
195
196 KConfigPropertyMap *faceConfiguration() const;
197
198 QString title() const;
199 void setTitle(const QString &title);
200
201 bool showTitle() const;
202 void setShowTitle(bool show);
203
204 QJsonArray totalSensors() const;
205 void setTotalSensors(const QJsonArray &sensor);
206
207 QJsonArray highPrioritySensorIds() const;
208 void setHighPrioritySensorIds(const QJsonArray &ids);
209
210 QJsonArray sensors() const;
211
212 QJsonArray lowPrioritySensorIds() const;
213 void setLowPrioritySensorIds(const QJsonArray &ids);
214
215 QJsonArray missingSensors() const;
216
217 QVariantMap sensorColors() const;
218 void setSensorColors(const QVariantMap &colors);
219
220 QVariantMap sensorLabels() const;
221 void setSensorLabels(const QVariantMap &labels);
222
223 int updateRateLimit() const;
224 void setUpdateRateLimit(int limit);
225
226 // from face config, immutable by the user
227 QString name() const;
228 const QString icon() const;
229
230 bool supportsSensorsColors() const;
231 bool supportsTotalSensors() const;
232 bool supportsLowPrioritySensors() const;
233
234 int maxTotalSensors() const;
235
236 QAbstractItemModel *availableFacesModel();
237 QAbstractItemModel *availablePresetsModel();
238
239 /**
240 * Reload the configuration.
241 */
242 Q_INVOKABLE void reloadConfig();
243 /**
244 * Loads a specific preset
245 * @see availablePresetsModel
246 */
247 Q_INVOKABLE void loadPreset(const QString &preset);
248 /**
249 * Save the current configuration as a preset
250 */
251 Q_INVOKABLE void savePreset();
252 /**
253 * Uninstall a specific preset
254 */
255 Q_INVOKABLE void uninstallPreset(const QString &pluginId);
256
257 /**
258 * Whether the controller should sync configuration changes
259 * @see setShouldSync
260 */
261 bool shouldSync() const;
262 /**
263 * Specifies if the controller should automatically sync configuration changes.
264 * @param sync If `true` applied config changes are written to the KConfigGroup that was
265 * specified in the @ref SensorFaceController::SensorFaceController "constructor". If `false`
266 * config changes are applied after calling `saveConfig` on a configuration ui but not written
267 * to the KConfigGroup.
268 */
269 void setShouldSync(bool sync);
270
271 /**
272 * Reload only the face configuration.
273 *
274 * This does not touch sensors, colors or anything else, only the config
275 * loaded from the face package is reloaded.
276 */
277 Q_INVOKABLE void reloadFaceConfiguration();
278
279 /**
280 * Replace one sensor with another.
281 *
282 * This replaces a configured sensor with a new one. This replacement happens
283 * inside the configuration, bypassing thing like the sensor properties which
284 * are populated with resolved sensor ids rather than the configured entries.
285 *
286 * You should call @ref reloadConfig once you have made all replacements.
287 */
288 Q_INVOKABLE void replaceSensors(const QString &from, const QString &to);
289
290Q_SIGNALS:
291 void faceIdChanged();
292 void titleChanged();
293 void showTitleChanged();
294 void totalSensorsChanged();
295 void highPrioritySensorIdsChanged();
296 void lowPrioritySensorIdsChanged();
297 void sensorsChanged();
298 void sensorColorsChanged();
299 void sensorLabelsChanged();
300 void updateRateLimitChanged();
301 void faceConfigurationChanged();
302 void missingSensorsChanged();
303
304private:
305 const std::unique_ptr<SensorFaceControllerPrivate> d;
306};
307}
The SensorFaceController links sensor faces and applications in which these faces are shown.
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Fri Oct 11 2024 12:17:19 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.