-
Notifications
You must be signed in to change notification settings - Fork 8
/
snooze.cpp
87 lines (72 loc) · 1.91 KB
/
snooze.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
#include <QTimer>
#include <QTime>
#include "snooze.h"
#include "alarm.h"
#include "schedules.h"
#include "ui_snooze.h"
snooze::snooze(QWidget *parent,Alarm *curAlarm, Schedules * schedule_list) :
QDialog(parent),
ui(new Ui::snooze)
{
ui->setupUi(this);
this->_curAlarm=curAlarm;
this->_snoozeTimer=new QTimer(this);
this->_schedule_list = schedule_list;
this->_otherAlarmCheckTimer=new QTimer(this);
this->isDismissed=false;
SetupClock();
//setup connections
connect(ui->snzBtn,SIGNAL(clicked()),SLOT(SnoozeClicked()));
connect(ui->DismissBtn,SIGNAL(clicked()),SLOT(DismissClicked()));
connect(this->_otherAlarmCheckTimer,SIGNAL(timeout()),SLOT(OtherAlarmCheck()));
connect(this->_snoozeTimer,SIGNAL(timeout()),SLOT(timerOut()));
}
snooze::~snooze()
{
delete ui;
}
void snooze::SetupClock()
{
//Set up clock display
UpdateClock();
QTimer *CurrentTime=new QTimer(this);
connect(CurrentTime,SIGNAL(timeout()),this,SLOT(UpdateClock()));
CurrentTime->start(500);
}
void snooze::UpdateClock()
{
ui->time->setText(QTime::currentTime().toString("h:mm:ss ap"));
}
void snooze::SnoozeClicked()
{
this->_snoozeTimer->start(300000);//5 minutes
this->_curAlarm->Stop();
this->_otherAlarmCheckTimer->start(500);
}
void snooze::DismissClicked()
{
this->_snoozeTimer->stop();
this->_curAlarm->Stop();
if(this->_curAlarm->isOneshot)
{
this->_schedule_list->removeScheduleByIndex(this->_curAlarm->listId);
}
this->hide();
this->~snooze();
}
void snooze::timerOut()
{
this->_otherAlarmCheckTimer->stop();
this->_curAlarm->Start(this->_curAlarm->UsingCustomPath);
this->_curAlarm->canResume=false;
this->_snoozeTimer->stop();
}
void snooze::OtherAlarmCheck()
{
//If another alarm is playing, destroy this snooze
if(this->_curAlarm->isPlaying())
{
this->hide();
this->~snooze();
}
}