51 lines
922 B
C++
51 lines
922 B
C++
#include "alarmtime.h"
|
|
|
|
AlarmTime::AlarmTime(const QTime time, QObject *parent) : QObject(parent), time_(time)
|
|
{
|
|
connect(&timer, SIGNAL(timeout()), this, SLOT(doTick()));
|
|
timer.setInterval(1000);
|
|
}
|
|
|
|
AlarmTime::~AlarmTime()
|
|
{
|
|
abort();
|
|
}
|
|
|
|
void AlarmTime::run()
|
|
{
|
|
abort();
|
|
|
|
timer.start();
|
|
|
|
qDebug()<<"Start Alarm Time Manager\n";
|
|
}
|
|
|
|
|
|
void AlarmTime::abort()
|
|
{
|
|
timer.stop();
|
|
qDebug()<<"Stop Alarm Time Manager\n";
|
|
}
|
|
|
|
void AlarmTime::doTick()
|
|
{
|
|
if(time_.hour() == QTime::currentTime().hour() && time_.minute() == QTime::currentTime().minute() && triggerd_==false )
|
|
{
|
|
qDebug()<<"Trigger\n";
|
|
triggerd_=true;
|
|
trigger();
|
|
}
|
|
else if( time_.hour() != QTime::currentTime().hour() ) triggerd_=false;
|
|
}
|
|
|
|
void AlarmTime::changeTime(QTime time)
|
|
{
|
|
time_=time;
|
|
qDebug()<<"Time Changed\n";
|
|
}
|
|
|
|
void AlarmTime::runOrAbort(int state)
|
|
{
|
|
state ? run() : abort();
|
|
}
|