Libksysguard

FaceLoader.cpp
1/*
2 * SPDX-FileCopyrightText: 2021 Arjen Hiemstra <ahiemstra@heimr.nl>
3 *
4 * SPDX-License-Identifier: LGPL-2.0-or-later
5 */
6
7#include "FaceLoader.h"
8
9using namespace KSysGuard;
10
11class Q_DECL_HIDDEN FaceLoader::Private
12{
13public:
14 Private(FaceLoader *qq)
15 : q(qq)
16 {
17 }
18 void setupController();
19
20 FaceLoader *q;
21
22 SensorFaceController *parentController = nullptr;
23 SensorFaceController *controller = nullptr;
24
25 QString groupName;
26
27 bool complete = false;
28
29 QJsonArray sensors;
30 QString faceId;
31 QVariantMap colors;
32 QVariantMap labels;
33 bool readOnly = true;
34 bool showTitle = false;
35};
36
37FaceLoader::FaceLoader(QObject *parent)
38 : QObject(parent)
39 , d(new Private{this})
40{
41}
42
43FaceLoader::~FaceLoader() = default;
44
46{
47 return d->parentController;
48}
49
50void FaceLoader::setParentController(SensorFaceController *newParentController)
51{
52 if (newParentController == d->parentController) {
53 return;
54 }
55
56 if (d->parentController) {
57 d->parentController->disconnect(this);
58 }
59
60 if (d->controller) {
61 d->controller->deleteLater();
62 }
63
64 d->parentController = newParentController;
65
66 d->setupController();
67
68 Q_EMIT parentControllerChanged();
69}
70
72{
73 return d->faceId;
74}
75
76void FaceLoader::setFaceId(const QString &newFaceId)
77{
78 if (newFaceId == d->faceId) {
79 return;
80 }
81
82 d->faceId = newFaceId;
83 if (d->controller) {
84 d->controller->setFaceId(d->faceId);
85 }
86
87 Q_EMIT faceIdChanged();
88}
89
91{
92 return d->groupName;
93}
94
95void FaceLoader::setGroupName(const QString &newGroupName)
96{
97 if (newGroupName == d->groupName) {
98 return;
99 }
100
101 d->groupName = newGroupName;
102
103 d->setupController();
104
105 Q_EMIT groupNameChanged();
106}
107
109{
110 return d->sensors;
111}
112
113void FaceLoader::setSensors(const QJsonArray &newSensors)
114{
115 if (newSensors == d->sensors) {
116 return;
117 }
118
119 d->sensors = newSensors;
120
121 if (d->controller) {
122 d->controller->setHighPrioritySensorIds(d->sensors);
123 }
124
125 Q_EMIT sensorsChanged();
126}
127
128QVariantMap FaceLoader::colors() const
129{
130 return d->colors;
131}
132
133void FaceLoader::setColors(const QVariantMap &newColors)
134{
135 if (newColors == d->colors) {
136 return;
137 }
138
139 d->colors = newColors;
140 if (d->controller) {
141 d->controller->setSensorColors(d->colors);
142 }
143 Q_EMIT colorsChanged();
144}
145
146QVariantMap FaceLoader::labels() const
147{
148 return d->labels;
149}
150
151void FaceLoader::setLabels(const QVariantMap &newLabels)
152{
153 if (newLabels == d->labels) {
154 return;
155 }
156
157 d->labels = newLabels;
158 if (d->controller) {
159 d->controller->setSensorLabels(d->labels);
160 }
161 Q_EMIT labelsChanged();
162}
163
164bool FaceLoader::readOnly() const
165{
166 return d->readOnly;
167}
168
169void FaceLoader::setReadOnly(bool newReadOnly)
170{
171 if (newReadOnly == d->readOnly) {
172 return;
173 }
174
175 d->readOnly = newReadOnly;
176 if (d->controller) {
177 d->controller->setShouldSync(!d->readOnly);
178 }
179 Q_EMIT readOnlyChanged();
180}
181
183{
184 return d->controller;
185}
186
187void FaceLoader::reload()
188{
189 d->controller->reloadFaceConfiguration();
190}
191
192void FaceLoader::classBegin()
193{
194}
195
196void FaceLoader::componentComplete()
197{
198 d->complete = true;
199 d->setupController();
200}
201
202void FaceLoader::Private::setupController()
203{
204 if (!parentController || groupName.isEmpty() || !complete) {
205 return;
206 }
207
208 auto configGroup = parentController->configGroup().group(groupName);
209 controller = new SensorFaceController(configGroup, qmlEngine(q));
210 controller->setShouldSync(readOnly);
211 controller->setHighPrioritySensorIds(sensors);
212 controller->setSensorColors(colors);
213 controller->setSensorLabels(labels);
214 controller->setShowTitle(showTitle);
215 controller->setFaceId(faceId);
216
217 Q_EMIT q->controllerChanged();
218}
KConfigGroup group(const QString &group)
A helper class to make it easier to load faces when used inside a face.
Definition FaceLoader.h:32
bool readOnly
Whether to allow modifying the face configuration.
Definition FaceLoader.h:77
KSysGuard::SensorFaceController * controller
The face controller that provides the loaded face.
Definition FaceLoader.h:81
QJsonArray sensors
The sensors to use for this face.
Definition FaceLoader.h:48
QVariantMap labels
A map of sensor labels to be used by the face.
Definition FaceLoader.h:66
QVariantMap colors
A map of sensor colors to be used by the face.
Definition FaceLoader.h:60
KSysGuard::SensorFaceController * parentController
The parent SensorFaceController that will be used for configuration storage.
Definition FaceLoader.h:38
QString groupName
The name of the config group to read configuration from.
Definition FaceLoader.h:42
QString faceId
The face to use.
Definition FaceLoader.h:54
The SensorFaceController links sensor faces and applications in which these faces are shown.
void setShouldSync(bool sync)
Specifies if the controller should automatically sync configuration changes.
KConfigGroup configGroup() const
Retrieve the KConfigGroup this controller is using to store configuration.
Q_EMITQ_EMIT
bool isEmpty() const const
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Tue Mar 26 2024 11:21:23 by doxygen 1.10.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.