Commit f0600a7e authored by David Redondo's avatar David Redondo 🏎
Browse files

Do the sensor setters in two stages

When saveConfig() in ConfigSensors.qml is called we started resolving sensors,
when during this time loadConfig() was called we returned the old sensors, which
when then triggeded another saveConfig() call by  plasma-systemmonitor leading us to
effectively reset ourselves.
The setters are now in two stages, during resolving time we set the properties
to the unresolved value, so we are in sync with what the qml part did. Also we not
do another resolve when something tries to set the current unresolved ids.
BUG:432254
parent 59a0b9e3
......@@ -446,15 +446,24 @@ QJsonArray SensorFaceController::totalSensors() const
void SensorFaceController::setTotalSensors(const QJsonArray &totalSensors)
{
d->resolveSensors(totalSensors, [this, totalSensors] (const QJsonArray &resolvedSensors) {
if (totalSensors == d->totalSensors) {
return;
}
const auto currentEntry = QJsonDocument::fromJson(d->sensorsGroup.readEntry("totalSensors").toUtf8()).array();
if (totalSensors == currentEntry) {
return;
}
d->sensorsGroup.writeEntry("totalSensors", QJsonDocument(totalSensors).toJson(QJsonDocument::Compact));
// Until we have resolved
d->totalSensors = totalSensors;
d->syncTimer->start();
Q_EMIT totalSensorsChanged();
d->resolveSensors(totalSensors, [this] (const QJsonArray &resolvedSensors) {
if (resolvedSensors == d->totalSensors) {
return;
}
d->totalSensors = resolvedSensors;
d->sensorsGroup.writeEntry("totalSensors", QJsonDocument(totalSensors).toJson(QJsonDocument::Compact));
d->syncTimer->start();
emit totalSensorsChanged();
Q_EMIT totalSensorsChanged();
});
}
......@@ -466,15 +475,24 @@ QJsonArray SensorFaceController::highPrioritySensorIds() const
void SensorFaceController::setHighPrioritySensorIds(const QJsonArray &highPrioritySensorIds)
{
d->resolveSensors(highPrioritySensorIds, [this, highPrioritySensorIds] (const QJsonArray &resolvedSensors) {
if (highPrioritySensorIds == d->highPrioritySensorIds) {
return;
}
const auto currentEntry = QJsonDocument::fromJson(d->sensorsGroup.readEntry("highPrioritySensorIds").toUtf8()).array();
if (highPrioritySensorIds == currentEntry) {
return;
}
d->sensorsGroup.writeEntry("highPrioritySensorIds", QJsonDocument(highPrioritySensorIds).toJson(QJsonDocument::Compact));
// Until we have resolved
d->syncTimer->start();
d->highPrioritySensorIds = highPrioritySensorIds;
Q_EMIT highPrioritySensorIdsChanged();
d->resolveSensors(highPrioritySensorIds, [this] (const QJsonArray &resolvedSensors) {
if (resolvedSensors == d->highPrioritySensorIds) {
return;
}
d->highPrioritySensorIds = resolvedSensors;
d->sensorsGroup.writeEntry("highPrioritySensorIds", QJsonDocument(highPrioritySensorIds).toJson(QJsonDocument::Compact));
d->syncTimer->start();
emit highPrioritySensorIdsChanged();
Q_EMIT highPrioritySensorIdsChanged();
});
}
......@@ -516,15 +534,24 @@ QJsonArray SensorFaceController::lowPrioritySensorIds() const
void SensorFaceController::setLowPrioritySensorIds(const QJsonArray &lowPrioritySensorIds)
{
d->resolveSensors(lowPrioritySensorIds, [this, lowPrioritySensorIds] (const QJsonArray &resolvedSensors) {
if (lowPrioritySensorIds == d->lowPrioritySensorIds) {
return;
}
const auto currentEntry = QJsonDocument::fromJson(d->sensorsGroup.readEntry("lowPrioritySensorIds").toUtf8()).array();
if (lowPrioritySensorIds == currentEntry) {
return;
}
d->sensorsGroup.writeEntry("lowPrioritySensorIds", QJsonDocument(lowPrioritySensorIds).toJson(QJsonDocument::Compact));
// Until we have resolved
d->lowPrioritySensorIds = lowPrioritySensorIds;
d->syncTimer->start();
Q_EMIT lowPrioritySensorIdsChanged();
d->resolveSensors(lowPrioritySensorIds, [this] (const QJsonArray &resolvedSensors) {
if (resolvedSensors == d->lowPrioritySensorIds) {
return;
}
d->lowPrioritySensorIds = lowPrioritySensorIds;
d->sensorsGroup.writeEntry("lowPrioritySensorIds", QJsonDocument(lowPrioritySensorIds).toJson(QJsonDocument::Compact));
d->syncTimer->start();
emit lowPrioritySensorIdsChanged();
d->lowPrioritySensorIds = resolvedSensors;
Q_EMIT lowPrioritySensorIdsChanged();
});
}
......
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