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 qString databaseFileName;
58 databaseFileName = QDesktopServices::storageLocation(QDesktopServices::DataLocation + "ConfClerk.sqlite"
59 // TODO: check existence
60 QSqlDatabase database = QSqlDatabase::addDatabase("QSQLITE");
61 database.setDatabaseName(databaseFileName);
71 Event event = Event::getById(mEventId,Conference::activeConference());
72 titleStr = "Event alarm";
73 messageStr = event.title();
74 timeStr = event.start().toString("hh:mm") + "-" + event.start().addSecs(event.duration()).toString("hh:mm");
75 personsStr = event.persons().join(" and ");
76 roomStr = event.room();
78 catch(OrmNoObjectException&)
80 titleStr = QString("ERROR");
81 messageStr = QString("No such event in the DB: %1").arg(QString::number(mEventId));
83 catch(...) {} // TODO: implement
84 message->setText(messageStr);
85 setWindowTitle(titleStr);
86 time->setText(timeStr);
87 persons->setText(personsStr);
88 room->setText(roomStr);
91 void AlarmDialog::runApp()
93 QString program = QDir::currentPath() + "/" + *qApp->argv();
94 QProcess::startDetached(program,QStringList()<<QString::number(mEventId));
98 void AlarmDialog::snooze()
100 if(mEventId==0) // not valid event ID
104 alarm.addAlarm(mEventId,QDateTime::currentDateTime().addSecs(60*SNOOZE_TIME));
108 void AlarmDialog::closeDialog()
110 // before closing the dialog, it is necessary to remove alarm flag from the DB
113 Event event = Event::getById(mEventId,Conference::activeConference());
114 event.setHasAlarm(false);
115 event.update("alarm");
117 catch(OrmNoObjectException &) {} // TODO: implement
118 catch(...) {} // just close dialog