diff options
Diffstat (limited to 'src/app.cpp')
| -rw-r--r-- | src/app.cpp | 62 |
1 files changed, 43 insertions, 19 deletions
diff --git a/src/app.cpp b/src/app.cpp index 1b63b72..bb7c777 100644 --- a/src/app.cpp +++ b/src/app.cpp @@ -136,40 +136,64 @@ App::loadScreen(QScreen* screen) void App::loadSensor(QScreen* screen, QString name, int x, int y, int w, int h) { + QString sensorNameKey = screen->name() + "/" + name; - QString action = screen->name() + "/" + name + "-" + "action"; - QString interval = screen->name() + "/" + name + "-" + "interval"; + if (settings.contains (sensorNameKey) == false) + { + return; + } + + QString sensorName = settings.value (sensorNameKey).toString (); + QString sensorEnterAction = sensorName + "/enterAction"; + QString sensorExitAction = sensorName + "/exitAction"; + QString sensorEnterDelay = sensorName + "/enterDelay"; + QString sensorExitDelay = sensorName + "/exitDelay"; + int emptyCount = 0; - if (!settings.contains(interval)) + if (sensorName.isEmpty () == true) { - qDebug() << "App::loadSensor() interval for " << name << " not found; setting to 0"; + return; + } - // set default - settings.setValue(interval, QVariant(0)); + if (!settings.contains (sensorEnterAction)) + { + emptyCount ++; } - if (!settings.contains(action)) + if (!settings.contains (sensorExitAction)) { - qDebug() << "App::loadSensor() action for " << name << " not found; creating empty key"; - - // restore missing action - settings.setValue(action, QString()); - return; + emptyCount ++; } - if (settings.value(action).toString().isEmpty()) + if (emptyCount == 2) { - qDebug() << "App::loadSensor() action for " << name << " is empty"; + // to not make this a breaking change, keep compatibility with old configurations + sensors.append (new Sensor (x, y, w, h, sensorName, "", 0, 0)); return; } - - // create sensor and save in list so we can delete all sensors on delete + if (!settings.contains (sensorEnterDelay)) + { + qDebug () << "App::loadSensor () sensor " << sensorName << " does not have delay; setting to 0"; + settings.setValue (sensorEnterDelay, QVariant (0)); + } - qDebug() << "App::loadSensor() action for " << name << " is " << settings.value(action).toString(); - qDebug() << "App::loadSensor() interval for " << name << " is " << settings.value(interval).toInt(); + if (!settings.contains (sensorExitDelay)) + { + qDebug () << "App::loadSensor () sensor " << sensorName << " does not have exit delay; setting to 0"; + settings.setValue (sensorExitDelay, QVariant (0)); + } - sensors.append( new Sensor(x, y, w, h, settings.value(action).toString(), settings.value(interval).toInt()) ); + qDebug () << "App::loadSensor () loaded sensor " << sensorName << " on screen " + screen->name(); + sensors.append ( + new Sensor ( + x, y, w, h, + settings.value (sensorEnterAction).toString (), + settings.value (sensorExitAction).toString (), + settings.value (sensorEnterDelay).toInt (), + settings.value (sensorExitDelay).toInt () + ) + ); } |
