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