source: src/gui/alarmdialog.cpp @ cfd615d

qt5
Last change on this file since cfd615d was cfd615d, checked in by pavelpa <pavelpa@…>, 12 years ago

work on alarm

  • Property mode set to 100644
File size: 1.7 KB
Line 
1#include "alarmdialog.h"
2
3#include <QApplication>
4#include <alarm.h>
5#include <event.h>
6
7#include <QDir>
8
9const int SNOOZE_TIME = 5; // in minutes
10
11const int confId = 1;
12
13AlarmDialog::AlarmDialog(int argc, char *argv[], QWidget *aParent)
14    : QDialog(aParent)
15    , mEventId(0)
16    , mAlarmId(0)
17{
18    setupUi(this);
19
20    if(argc<3)
21    {
22        // not enough arguments passed to the dialog
23        // Usage: $ ./dialog eventId alarmId
24        // Example: $ ./dialog 521 13
25        //
26        // TODO: handle this case
27    }
28    else
29    {
30        mEventId = QString(argv[1]).toInt();
31        mAlarmId = QString(argv[2]).toInt();
32    }
33
34    connect(stopPB, SIGNAL(clicked()), SLOT(closeDialog()));
35    connect(appPB, SIGNAL(clicked()), SLOT(runApp()));
36    connect(snoozePB, SIGNAL(clicked()), SLOT(snooze()));
37
38    QSqlDatabase database = QSqlDatabase::addDatabase("QSQLITE");
39    database.setDatabaseName(QDir::homePath() + "/.fosdem/fosdem.sqlite");
40    database.open();
41
42    Event event = Event::getById(mEventId,confId);
43    message->setText(QString(argv[1]).append("-").append(QString(argv[2])));
44    message->setText(event.title());
45    setWindowTitle(event.title());
46}
47
48void AlarmDialog::runApp()
49{
50    qWarning("runApp(): NOT IMPLEMENTED YET");
51}
52
53void AlarmDialog::snooze()
54{
55    if(mEventId==0) // not valid event ID
56        return;
57
58    Alarm alarm;
59    alarm.addAlarm(mEventId,QDateTime::currentDateTime().addSecs(60*SNOOZE_TIME));
60    qApp->quit();
61}
62
63void AlarmDialog::closeDialog()
64{
65    // before closing the dialog, it is necessary to remove alarm flag from the DB
66    Event event = Event::getById(mEventId,confId);
67    event.setHasAlarm(false);
68    event.update("alarm");
69    qApp->quit();
70}
71
Note: See TracBrowser for help on using the repository browser.