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
RevLine 
[6ae1026]1#include "alarmdialog.h"
2
3#include <QApplication>
4#include <alarm.h>
[cfd615d]5#include <event.h>
6
7#include <QDir>
[d4a8bbf]8#include <QProcess>
[6ae1026]9
10const int SNOOZE_TIME = 5; // in minutes
11
[cfd615d]12const int confId = 1;
13
[6ae1026]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
[cfd615d]35    connect(stopPB, SIGNAL(clicked()), SLOT(closeDialog()));
[6ae1026]36    connect(appPB, SIGNAL(clicked()), SLOT(runApp()));
37    connect(snoozePB, SIGNAL(clicked()), SLOT(snooze()));
38
[cfd615d]39    QSqlDatabase database = QSqlDatabase::addDatabase("QSQLITE");
40    database.setDatabaseName(QDir::homePath() + "/.fosdem/fosdem.sqlite");
41    database.open();
42
[7ec8838]43    QString titleStr;
44    QString messageStr;
45    QString timeStr;
46    QString personsStr;
47    QString roomStr;
[95596f6]48    try
49    {
50        Event event = Event::getById(mEventId,confId);
[7ec8838]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();
[95596f6]56    }
[06570e9]57    catch(OrmNoObjectException&)
[95596f6]58    {
[7ec8838]59        titleStr = QString("ERROR");
60        messageStr = QString("No such event in the DB: %1").arg(QString::number(mEventId));
[95596f6]61    }
62    catch(...) {} // TODO: implement
[7ec8838]63    message->setText(messageStr);
64    setWindowTitle(titleStr);
65    time->setText(timeStr);
66    persons->setText(personsStr);
67    room->setText(roomStr);
[6ae1026]68}
69
70void AlarmDialog::runApp()
71{
[d4a8bbf]72    QString program = QDir::currentPath() + "/" + *qApp->argv();
73    QProcess::startDetached(program,QStringList()<<QString::number(mEventId));
[7ec8838]74    closeDialog();
[6ae1026]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
[cfd615d]87void AlarmDialog::closeDialog()
88{
89    // before closing the dialog, it is necessary to remove alarm flag from the DB
[95596f6]90    try
91    {
92        Event event = Event::getById(mEventId,confId);
93        event.setHasAlarm(false);
94        event.update("alarm");
95    }
[06570e9]96    catch(OrmNoObjectException) {} // TODO: implement
[95596f6]97    catch(...) {} // just close dialog
[cfd615d]98    qApp->quit();
99}
100
Note: See TracBrowser for help on using the repository browser.