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#include <QQmlEngine>
9
10using namespace KSysGuard;
11
12class Q_DECL_HIDDEN FaceLoader::Private
13{
14public:
15 Private(FaceLoader *qq)
16 : q(qq)
17 {
18 }
19 void setupController();
20
21 FaceLoader *q;
22
23 SensorFaceController *parentController = nullptr;
24 SensorFaceController *controller = nullptr;
25
26 QString groupName;
27
28 bool complete = false;
29
30 QJsonArray sensors;
31 QString faceId;
32 QVariantMap colors;
33 QVariantMap labels;
34 bool readOnly = true;
35 bool showTitle = false;
36};
37
38FaceLoader::FaceLoader(QObject *parent)
39 : QObject(parent)
40 , d(new Private{this})
41{
42}
43
44FaceLoader::~FaceLoader() = default;
45
47{
48 return d->parentController;
49}
50
51void FaceLoader::setParentController(SensorFaceController *newParentController)
52{
53 if (newParentController == d->parentController) {
54 return;
55 }
56
57 if (d->parentController) {
58 d->parentController->disconnect(this);
59 }
60
61 if (d->controller) {
62 d->controller->deleteLater();
63 }
64
65 d->parentController = newParentController;
66
67 d->setupController();
68
69 Q_EMIT parentControllerChanged();
70}
71
73{
74 return d->faceId;
75}
76
77void FaceLoader::setFaceId(const QString &newFaceId)
78{
79 if (newFaceId == d->faceId) {
80 return;
81 }
82
83 d->faceId = newFaceId;
84 if (d->controller) {
85 d->controller->setFaceId(d->faceId);
86 }
87
88 Q_EMIT faceIdChanged();
89}
90
92{
93 return d->groupName;
94}
95
96void FaceLoader::setGroupName(const QString &newGroupName)
97{
98 if (newGroupName == d->groupName) {
99 return;
100 }
101
102 d->groupName = newGroupName;
103
104 d->setupController();
105
106 Q_EMIT groupNameChanged();
107}
108
110{
111 return d->sensors;
112}
113
114void FaceLoader::setSensors(const QJsonArray &newSensors)
115{
116 if (newSensors == d->sensors) {
117 return;
118 }
119
120 d->sensors = newSensors;
121
122 if (d->controller) {
123 d->controller->setHighPrioritySensorIds(d->sensors);
124 }
125
126 Q_EMIT sensorsChanged();
127}
128
129QVariantMap FaceLoader::colors() const
130{
131 return d->colors;
132}
133
134void FaceLoader::setColors(const QVariantMap &newColors)
135{
136 if (newColors == d->colors) {
137 return;
138 }
139
140 d->colors = newColors;
141 if (d->controller) {
142 d->controller->setSensorColors(d->colors);
143 }
144 Q_EMIT colorsChanged();
145}
146
147QVariantMap FaceLoader::labels() const
148{
149 return d->labels;
150}
151
152void FaceLoader::setLabels(const QVariantMap &newLabels)
153{
154 if (newLabels == d->labels) {
155 return;
156 }
157
158 d->labels = newLabels;
159 if (d->controller) {
160 d->controller->setSensorLabels(d->labels);
161 }
162 Q_EMIT labelsChanged();
163}
164
165bool FaceLoader::readOnly() const
166{
167 return d->readOnly;
168}
169
170void FaceLoader::setReadOnly(bool newReadOnly)
171{
172 if (newReadOnly == d->readOnly) {
173 return;
174 }
175
176 d->readOnly = newReadOnly;
177 if (d->controller) {
178 d->controller->setShouldSync(!d->readOnly);
179 }
180 Q_EMIT readOnlyChanged();
181}
182
184{
185 return d->controller;
186}
187
188void FaceLoader::reload()
189{
190 d->controller->reloadFaceConfiguration();
191}
192
193void FaceLoader::classBegin()
194{
195}
196
197void FaceLoader::componentComplete()
198{
199 d->complete = true;
200 d->setupController();
201}
202
203void FaceLoader::Private::setupController()
204{
205 if (!parentController || groupName.isEmpty() || !complete) {
206 return;
207 }
208
209 auto configGroup = parentController->configGroup().group(groupName);
210 controller = new SensorFaceController(configGroup, qmlEngine(q), new QQmlEngine(q));
211 controller->setShouldSync(readOnly);
212 controller->setHighPrioritySensorIds(sensors);
213 controller->setSensorColors(colors);
214 controller->setSensorLabels(labels);
215 controller->setShowTitle(showTitle);
216 controller->setFaceId(faceId);
217
218 Q_EMIT q->controllerChanged();
219}
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:78
KSysGuard::SensorFaceController * controller
The face controller that provides the loaded face.
Definition FaceLoader.h:82
QJsonArray sensors
The sensors to use for this face.
Definition FaceLoader.h:49
QVariantMap labels
A map of sensor labels to be used by the face.
Definition FaceLoader.h:67
QVariantMap colors
A map of sensor colors to be used by the face.
Definition FaceLoader.h:61
QString groupName
The name of the config group to read configuration from.
Definition FaceLoader.h:43
QString faceId
The face to use.
Definition FaceLoader.h:55
QML_ELEMENTKSysGuard::SensorFaceController * parentController
The parent SensorFaceController that will be used for configuration storage.
Definition FaceLoader.h:39
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 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.