2 * Copyright (C) 2010 Ixonos Plc.
4 * This file is part of fosdem-schedule.
6 * fosdem-schedule is free software: you can redistribute it and/or modify it
7 * under the terms of the GNU General Public License as published by the Free
8 * Software Foundation, either version 2 of the License, or (at your option)
11 * fosdem-schedule is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
13 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
16 * You should have received a copy of the GNU General Public License along with
17 * fosdem-schedule. If not, see <http://www.gnu.org/licenses/>.
19 #include "alarmdialog.h"
20 #include <conference.h>
22 #include <QApplication>
29 const int SNOOZE_TIME = 5; // in minutes
31 AlarmDialog::AlarmDialog(int argc, char *argv[], QWidget *aParent)
40 // not enough arguments passed to the dialog
41 // Usage: $ ./dialog eventId alarmId
42 // Example: $ ./dialog 521 13
44 // TODO: handle this case
48 mEventId = QString(argv[1]).toInt();
49 mAlarmId = QString(argv[2]).toInt();
52 connect(stopPB, SIGNAL(clicked()), SLOT(closeDialog()));
53 connect(appPB, SIGNAL(clicked()), SLOT(runApp()));
54 connect(snoozePB, SIGNAL(clicked()), SLOT(snooze()));
56 QSqlDatabase database = QSqlDatabase::addDatabase("QSQLITE");
57 database.setDatabaseName(QDir::homePath() + "/.fosdem/fosdem.sqlite");
67 Event event = Event::getById(mEventId,Conference::activeConference());
68 titleStr = "Event alarm";
69 messageStr = event.title();
70 timeStr = event.start().toString("hh:mm") + "-" + event.start().addSecs(event.duration()).toString("hh:mm");
71 personsStr = event.persons().join(" and ");
72 roomStr = event.room();
74 catch(OrmNoObjectException&)
76 titleStr = QString("ERROR");
77 messageStr = QString("No such event in the DB: %1").arg(QString::number(mEventId));
79 catch(...) {} // TODO: implement
80 message->setText(messageStr);
81 setWindowTitle(titleStr);
82 time->setText(timeStr);
83 persons->setText(personsStr);
84 room->setText(roomStr);
87 void AlarmDialog::runApp()
89 QString program = QDir::currentPath() + "/" + *qApp->argv();
90 QProcess::startDetached(program,QStringList()<<QString::number(mEventId));
94 void AlarmDialog::snooze()
96 if(mEventId==0) // not valid event ID
100 alarm.addAlarm(mEventId,QDateTime::currentDateTime().addSecs(60*SNOOZE_TIME));
104 void AlarmDialog::closeDialog()
106 // before closing the dialog, it is necessary to remove alarm flag from the DB
109 Event event = Event::getById(mEventId,Conference::activeConference());
110 event.setHasAlarm(false);
111 event.update("alarm");
113 catch(OrmNoObjectException &) {} // TODO: implement
114 catch(...) {} // just close dialog