Commit f69def64 authored by Arjen Hiemstra's avatar Arjen Hiemstra
Browse files

Faces: Add a method to the controller to replace sensors

This will go through the configured sensors and if it finds a match,
replace the sensor with a new one. This change happens in the
configuration, bypassing most of the relevant properties, since the
configuration is the only place where sensor ids that are missing are
parent eda127cb
......@@ -1062,4 +1062,25 @@ void SensorFaceController::reloadFaceConfiguration()
void KSysGuard::SensorFaceController::replaceSensors(const QString &from, const QString &to)
auto replaceSensors = [this, from, to](const QString &configEntry) {
auto array = QJsonDocument::fromJson(d->sensorsGroup.readEntry(configEntry, QString()).toUtf8()).array();
for (auto itr = array.begin(); itr != array.end(); ++itr) {
if (itr->toString() == from) {
*itr = QJsonValue(to);
return QJsonDocument(array).toJson(QJsonDocument::Compact);
d->sensorsGroup.writeEntry("totalSensors", replaceSensors(QStringLiteral("totalSensors")));
d->sensorsGroup.writeEntry("highPrioritySensorIds", replaceSensors(QStringLiteral("highPrioritySensorIds")));
d->sensorsGroup.writeEntry("lowPrioritySensorIds", replaceSensors(QStringLiteral("lowPrioritySensorIds")));
if (d->shouldSync) {
#include "moc_SensorFaceController.cpp"
......@@ -274,6 +274,17 @@ public:
Q_INVOKABLE void reloadFaceConfiguration();
* Replace one sensor with another.
* This replaces a configured sensor with a new one. This replacement happens
* inside the configuration, bypassing thing like the sensor properties which
* are populated with resolved sensor ids rather than the configured entries.
* You should call @ref reloadConfig once you have made all replacements.
Q_INVOKABLE void replaceSensors(const QString &from, const QString &to);
void faceIdChanged();
void titleChanged();
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment