source: src/gui/alarmdialog.cpp @ 1735f55

qt5
Last change on this file since 1735f55 was 30e2bdf, checked in by pavelpa <pavelpa@…>, 13 years ago

added 'Conference' tab - to list conference details

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