aboutsummaryrefslogtreecommitdiff
path: root/src/app.cpp
diff options
context:
space:
mode:
authorAlexis Maiquez Murcia <almamu@almamu.com>2019-02-19 16:25:04 +0100
committerAlexis Maiquez Murcia <almamu@almamu.com>2019-02-19 16:25:04 +0100
commitd2d6f9acd776f00f961fe4fca78ce4ec13be12c5 (patch)
treea74c59cda8b35bf393337f16b0cc217818a8046f /src/app.cpp
parentc5403e9c5fb08319e984d939b975915dddf59791 (diff)
downloadlead-d2d6f9acd776f00f961fe4fca78ce4ec13be12c5.tar
lead-d2d6f9acd776f00f961fe4fca78ce4ec13be12c5.tar.gz
lead-d2d6f9acd776f00f961fe4fca78ce4ec13be12c5.zip
~ Simplified sensor's configuration load to make the ini more configurable and re-usable across screens
Signed-off-by: Alexis Maiquez Murcia <almamu@almamu.com>
Diffstat (limited to 'src/app.cpp')
-rw-r--r--src/app.cpp50
1 files changed, 23 insertions, 27 deletions
diff --git a/src/app.cpp b/src/app.cpp
index 1b63b72..93f7384 100644
--- a/src/app.cpp
+++ b/src/app.cpp
@@ -136,40 +136,36 @@ App::loadScreen(QScreen* screen)
void
App::loadSensor(QScreen* screen, QString name, int x, int y, int w, int h)
{
+ QString sensorsListKey = screen->name() + "/" + name;
- QString action = screen->name() + "/" + name + "-" + "action";
- QString interval = screen->name() + "/" + name + "-" + "interval";
-
- if (!settings.contains(interval))
- {
- qDebug() << "App::loadSensor() interval for " << name << " not found; setting to 0";
-
- // set default
- settings.setValue(interval, QVariant(0));
- }
-
- if (!settings.contains(action))
+ if (settings.contains (sensorsListKey) == false)
{
- qDebug() << "App::loadSensor() action for " << name << " not found; creating empty key";
-
- // restore missing action
- settings.setValue(action, QString());
return;
}
- if (settings.value(action).toString().isEmpty())
+ QStringList sensorsList = settings.value (sensorsListKey).toString ().split (';', QString::SkipEmptyParts);
+
+ for (int i = 0; i < sensorsList.size (); i ++)
{
- qDebug() << "App::loadSensor() action for " << name << " is empty";
- return;
+ QString sensorName = sensorsList.at (i);
+ QString sensorAction = sensorName + "/action";
+ QString sensorDelay = sensorName + "/delay";
+
+ if (!settings.contains (sensorAction))
+ {
+ qDebug () << "App::loadSensor () sensor " << sensorName << " does not have action; ignoring...";
+ continue;
+ }
+
+ if (!settings.contains (sensorDelay))
+ {
+ qDebug () << "App::loadSensor () sensor " << sensorName << " does not have delay; setting to 0";
+ settings.setValue (sensorDelay, QVariant (0));
+ }
+
+ qDebug () << "App::loadSensor () loaded sensor " << sensorName << " on screen " + screen->name();
+ sensors.append (new Sensor (x, y, w, h, settings.value (sensorAction).toString (), settings.value (sensorDelay).toInt ()));
}
-
-
- // create sensor and save in list so we can delete all sensors on delete
-
- qDebug() << "App::loadSensor() action for " << name << " is " << settings.value(action).toString();
- qDebug() << "App::loadSensor() interval for " << name << " is " << settings.value(interval).toInt();
-
- sensors.append( new Sensor(x, y, w, h, settings.value(action).toString(), settings.value(interval).toInt()) );
}