aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorMageJohn <MageJohn@users.noreply.github.com>2019-02-19 16:59:06 +0000
committerGitHub <noreply@github.com>2019-02-19 16:59:06 +0000
commit7e9c4e1b9bfa3966cca992256b885f75c8660753 (patch)
treed1126cb0e6975ae678cd021c004ccf51f02b3079 /src
parenta1ddbe5b94b21877c1a082256857d2e6feb692fe (diff)
parentd843e6a66a11e07595c8c4964fb8a1d343172990 (diff)
downloadlead-7e9c4e1b9bfa3966cca992256b885f75c8660753.tar
lead-7e9c4e1b9bfa3966cca992256b885f75c8660753.tar.gz
lead-7e9c4e1b9bfa3966cca992256b885f75c8660753.zip
Merge pull request #1 from Almamu/master
Merge changes from Almamu
Diffstat (limited to 'src')
-rw-r--r--src/app.cpp62
-rw-r--r--src/sensor.cpp70
-rw-r--r--src/sensor.h15
3 files changed, 106 insertions, 41 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 ()
+ )
+ );
}
diff --git a/src/sensor.cpp b/src/sensor.cpp
index 49fd149..597d4f9 100644
--- a/src/sensor.cpp
+++ b/src/sensor.cpp
@@ -34,18 +34,32 @@ SOFTWARE.
namespace Lead {
-Sensor::Sensor(int x, int y, int w, int h, QString action, int interval):
+Sensor::Sensor(int x, int y, int w, int h, QString enterAction, QString exitAction, int enterInterval, int exitInterval):
QWidget(),
- action(action),
- interval(interval)
+ enterAction(enterAction),
+ exitAction(exitAction),
+ enterInterval(enterInterval),
+ exitInterval(exitInterval)
{
- qDebug() << "lead::Sensor() " << x << "," << y << "," << w << "," << h << " : action=" << action << " : interval=" << interval;
+ qDebug()
+ << "lead::Sensor() " << x << "," << y << "," << w << "," << h
+ << " : enterAction=" << enterAction
+ << " : exitAction=" << exitAction
+ << " : enterInterval=" << enterInterval
+ << " : exitInterval=" << exitInterval;
- this->timer = new QTimer(this);
- this->timer->setSingleShot(true);
- this->timer->setInterval(interval);
+ this->canTriggerExit = false;
- connect(this->timer, SIGNAL(timeout()), this, SLOT(activate()));
+ this->enterTimer = new QTimer(this);
+ this->enterTimer->setSingleShot(true);
+ this->enterTimer->setInterval(enterInterval);
+
+ this->exitTimer = new QTimer (this);
+ this->exitTimer->setSingleShot (true);
+ this->exitTimer->setInterval (exitInterval);
+
+ connect(this->enterTimer, SIGNAL(timeout()), this, SLOT(activateEnter()));
+ connect(this->exitTimer, SIGNAL(timeout()), this, SLOT(activateExit()));
//setStyleSheet("background-color:red;");
setGeometry(x, y, w, h);
@@ -58,34 +72,56 @@ Sensor::Sensor(int x, int y, int w, int h, QString action, int interval):
Sensor::~Sensor()
{
- delete this->timer;
+ delete this->enterTimer;
+ delete this->exitTimer;
}
void
Sensor::enterEvent(QEvent * event)
{
- qDebug() << "lead::Sensor::enterEvent() " << this->x() << ":" << this->y() << " interval: " << this->interval;
+ qDebug()
+ << "lead::Sensor::enterEvent() "<< this->x() << ":" << this->y()
+ << " enterInterval: " << this->enterTimer
+ << " exitInterval: " << this->exitTimer;
- this->timer->start();
+ this->enterTimer->start();
+ this->exitTimer->start();
}
void
Sensor::leaveEvent(QEvent * event)
{
- qDebug() << "lead::Sensor::leaveEvent() " << this->x() << ":" << this->y() << " interval: " << this->interval;
-
- this->timer->stop();
+ qDebug()
+ << "lead::Sensor::leaveEvent() "<< this->x() << ":" << this->y()
+ << " enterInterval: " << this->enterTimer
+ << " exitInterval: " << this->exitTimer;
+
+ if (this->canTriggerExit)
+ {
+ QProcess::startDetached(exitAction);
+ }
+
+ this->enterTimer->stop();
+ this->exitTimer->stop();
+ this->canTriggerExit = false;
}
void
-Sensor::activate()
+Sensor::activateEnter()
+{
+ qDebug() << "lead::Sensor::activateEnter() " << this->x() << ":" << this->y() << " action: " << this->enterAction;
+
+ QProcess::startDetached(enterAction);
+}
+
+void Sensor::activateExit()
{
- qDebug() << "lead::Sensor::activate() " << this->x() << ":" << this->y() << " action: " << this->action;
+ qDebug () << "lead::Sensor::activateExit() " << this->x() << ":" << this->y() << " action: " << this->exitAction << " can run now";
- QProcess::startDetached(action);
+ this->canTriggerExit = true;
}
diff --git a/src/sensor.h b/src/sensor.h
index ed5add8..bc4857b 100644
--- a/src/sensor.h
+++ b/src/sensor.h
@@ -41,7 +41,7 @@ class Sensor : public QWidget
Q_OBJECT
public:
- explicit Sensor(int x, int y, int w, int h, QString action, int interval);
+ explicit Sensor(int x, int y, int w, int h, QString enterAction, QString exitAction, int enterInterval, int exitInterval);
~Sensor();
protected:
@@ -49,12 +49,17 @@ protected:
void leaveEvent(QEvent * event);
private:
- QString action;
- QTimer *timer;
- int interval;
+ QString enterAction;
+ QString exitAction;
+ QTimer *enterTimer;
+ QTimer *exitTimer;
+ int enterInterval;
+ int exitInterval;
+ bool canTriggerExit;
public slots:
- void activate();
+ void activateEnter();
+ void activateExit();
};