switched from qsettings to json added editng of actors

This commit is contained in:
2019-06-06 21:19:12 +02:00
parent b04fbfb5bc
commit df27b622a0
141 changed files with 4402 additions and 5068 deletions

145
src/actors/alarmtime.cpp Normal file
View File

@ -0,0 +1,145 @@
#include "alarmtime.h"
AlarmTime::AlarmTime(const QDateTime time, QObject *parent) : Actor(parent), time_(time)
{
connect(&timer, SIGNAL(timeout()), this, SLOT(doTick()));
timer.setInterval(1000);
}
AlarmTime::~AlarmTime()
{
makeInactive();
}
void AlarmTime::run()
{
makeInactive();
active = true;
timer.start();
qDebug()<<"Start Alarm Time Manager\n";
}
void AlarmTime::makeActive()
{
run();
}
QString AlarmTime::getName()
{
if(name.size() > 0)return name;
else
{
QString string;
string = "Alarm: ";
if(repeat_ == REPEAT_DAILY)
{
string.append("daily ");
string.append(time_.toString("HH:mm"));
}
else if(repeat_ == REPEAT_WEEKLY)
{
string.append("weekly ");
string.append(time_.toString("ddd HH:mm"));
}
else if(repeat_ == REPEAT_MONTHLY)
{
string.append("monthly ");
string.append(time_.toString("dd HH:mm"));
}
else if(repeat_ == REPEAT_YEARLY)
{
string.append("yearly ");
string.append(time_.toString("dd.mm HH:mm"));
}
else string.append(time_.toString("dd.mm.yyyy HH:mm"));
return string;
}
}
void AlarmTime::setRepeat(const uint8_t repeat)
{
repeat_=repeat;
}
uint8_t AlarmTime::getRepeat()
{
return repeat_;
}
QDateTime AlarmTime::getDateTime()
{
return time_;
}
void AlarmTime::makeInactive()
{
timer.stop();
active = false;
}
void AlarmTime::doTick()
{
if(
(
(triggerd_ == false) &&
(time_.date().year() == QDate::currentDate().year() || repeat_ != REPEAT_NEVER) &&
(time_.date().month() == QDate::currentDate().month() || repeat_ == REPEAT_MONTHLY || repeat_ == REPEAT_DAILY) &&
(time_.date().day() == QDate::currentDate().day() || repeat_ == REPEAT_DAILY)
)
||
(
(repeat_ == REPEAT_WEEKLY) &&
(time_.date().dayOfWeek() == QDate::currentDate().dayOfWeek())
)
)
{
if(time_.time().hour() == QTime::currentTime().hour() && time_.time().minute() == QTime::currentTime().minute())
{
qDebug()<<"Trigger\n";
triggerd_=true;
performAction();
if(repeat_ == REPEAT_NEVER) exausted = true;
}
}
else if( repeat_ != REPEAT_NEVER && time_.time().hour() != QTime::currentTime().hour() ) triggerd_=false;
}
void AlarmTime::changeTime(const QDateTime& time)
{
time_=time;
}
void AlarmTime::store(QJsonObject& json)
{
json["Type"] = "Alarm";
Actor::store(json);
json["Time"] = time_.toString();
json["Repeat"] = repeat_;
}
void AlarmTime::load(const QJsonObject& json)
{
Actor::load(json);
time_ = QDateTime::fromString(json["Time"].toString(""));
repeat_ = json["Repeat"].toInt(REPEAT_NEVER);
}
void AlarmTime::store(QString subsecton, QSettings* settings)
{
settings->setValue(subsecton + "Type", "Alarm");
Actor::store(subsecton, settings);
settings->setValue(subsecton + "Time", time_);
settings->setValue(subsecton + "Repeat", repeat_);
}
void AlarmTime::load(QString subsecton, QSettings* settings)
{
Actor::load(subsecton, settings);
time_ = settings->value(subsecton + "Time").toDateTime();
repeat_ = settings->value(subsecton + "Repeat").toUInt();
}