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

KDE's Doxygen guidelines are available online.