source: src/gui/alarmdialog.cpp @ 06570e9

qt5
Last change on this file since 06570e9 was 06570e9, checked in by korrco <korrco@…>, 12 years ago

exception handling changed

  • Property mode set to 100644
File size: 2.5 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    QString titleStr;
44    QString messageStr;
45    QString timeStr;
46    QString personsStr;
47    QString roomStr;
48    try
49    {
50        Event event = Event::getById(mEventId,confId);
51        titleStr = "Event alarm";
52        messageStr = event.title();
53        timeStr = event.start().toString("hh:mm") + "-" + event.start().addSecs(event.duration()).toString("hh:mm");
54        personsStr = event.persons().join(" and ");
55        roomStr = event.room();
56    }
57    catch(OrmNoObjectException&)
58    {
59        titleStr = QString("ERROR");
60        messageStr = QString("No such event in the DB: %1").arg(QString::number(mEventId));
61    }
62    catch(...) {} // TODO: implement
63    message->setText(messageStr);
64    setWindowTitle(titleStr);
65    time->setText(timeStr);
66    persons->setText(personsStr);
67    room->setText(roomStr);
68}
69
70void AlarmDialog::runApp()
71{
72    QString program = QDir::currentPath() + "/" + *qApp->argv();
73    QProcess::startDetached(program,QStringList()<<QString::number(mEventId));
74    closeDialog();
75}
76
77void AlarmDialog::snooze()
78{
79    if(mEventId==0) // not valid event ID
80        return;
81
82    Alarm alarm;
83    alarm.addAlarm(mEventId,QDateTime::currentDateTime().addSecs(60*SNOOZE_TIME));
84    qApp->quit();
85}
86
87void AlarmDialog::closeDialog()
88{
89    // before closing the dialog, it is necessary to remove alarm flag from the DB
90    try
91    {
92        Event event = Event::getById(mEventId,confId);
93        event.setHasAlarm(false);
94        event.update("alarm");
95    }
96    catch(OrmNoObjectException) {} // TODO: implement
97    catch(...) {} // just close dialog
98    qApp->quit();
99}
100
Note: See TracBrowser for help on using the repository browser.