source: src/gui/alarmdialog.cpp @ 95596f6

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

implemented some error handling

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