1 | /* |
---|
2 | * Copyright (C) 2010 Ixonos Plc. |
---|
3 | * Copyright (C) 2011 Philipp Spitzer, gregor herrmann |
---|
4 | * |
---|
5 | * This file is part of ConfClerk. |
---|
6 | * |
---|
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) |
---|
10 | * any later version. |
---|
11 | * |
---|
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 |
---|
15 | * more details. |
---|
16 | * |
---|
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/>. |
---|
19 | */ |
---|
20 | #include "alarmdialog.h" |
---|
21 | #include <conference.h> |
---|
22 | |
---|
23 | #include <QApplication> |
---|
24 | #include <alarm.h> |
---|
25 | #include <event.h> |
---|
26 | |
---|
27 | #include <QDir> |
---|
28 | #include <QProcess> |
---|
29 | |
---|
30 | const int SNOOZE_TIME = 5; // in minutes |
---|
31 | |
---|
32 | AlarmDialog::AlarmDialog(int argc, char *argv[], QWidget *aParent) |
---|
33 | : QDialog(aParent) |
---|
34 | , mEventId(0) |
---|
35 | , mAlarmId(0) |
---|
36 | { |
---|
37 | setupUi(this); |
---|
38 | |
---|
39 | if(argc<3) |
---|
40 | { |
---|
41 | // not enough arguments passed to the dialog |
---|
42 | // Usage: $ ./dialog eventId alarmId |
---|
43 | // Example: $ ./dialog 521 13 |
---|
44 | // |
---|
45 | // TODO: handle this case |
---|
46 | } |
---|
47 | else |
---|
48 | { |
---|
49 | mEventId = QString(argv[1]).toInt(); |
---|
50 | mAlarmId = QString(argv[2]).toInt(); |
---|
51 | } |
---|
52 | |
---|
53 | connect(stopPB, SIGNAL(clicked()), SLOT(closeDialog())); |
---|
54 | connect(appPB, SIGNAL(clicked()), SLOT(runApp())); |
---|
55 | connect(snoozePB, SIGNAL(clicked()), SLOT(snooze())); |
---|
56 | |
---|
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); |
---|
62 | database.open(); |
---|
63 | |
---|
64 | QString titleStr; |
---|
65 | QString messageStr; |
---|
66 | QString timeStr; |
---|
67 | QString personsStr; |
---|
68 | QString roomStr; |
---|
69 | try |
---|
70 | { |
---|
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(); |
---|
77 | } |
---|
78 | catch(OrmNoObjectException&) |
---|
79 | { |
---|
80 | titleStr = QString("ERROR"); |
---|
81 | messageStr = QString("No such event in the DB: %1").arg(QString::number(mEventId)); |
---|
82 | } |
---|
83 | catch(...) {} // TODO: implement |
---|
84 | message->setText(messageStr); |
---|
85 | setWindowTitle(titleStr); |
---|
86 | time->setText(timeStr); |
---|
87 | persons->setText(personsStr); |
---|
88 | room->setText(roomStr); |
---|
89 | } |
---|
90 | |
---|
91 | void AlarmDialog::runApp() |
---|
92 | { |
---|
93 | QString program = QDir::currentPath() + "/" + *qApp->argv(); |
---|
94 | QProcess::startDetached(program,QStringList()<<QString::number(mEventId)); |
---|
95 | closeDialog(); |
---|
96 | } |
---|
97 | |
---|
98 | void AlarmDialog::snooze() |
---|
99 | { |
---|
100 | if(mEventId==0) // not valid event ID |
---|
101 | return; |
---|
102 | |
---|
103 | Alarm alarm; |
---|
104 | alarm.addAlarm(mEventId,QDateTime::currentDateTime().addSecs(60*SNOOZE_TIME)); |
---|
105 | qApp->quit(); |
---|
106 | } |
---|
107 | |
---|
108 | void AlarmDialog::closeDialog() |
---|
109 | { |
---|
110 | // before closing the dialog, it is necessary to remove alarm flag from the DB |
---|
111 | try |
---|
112 | { |
---|
113 | Event event = Event::getById(mEventId,Conference::activeConference()); |
---|
114 | event.setHasAlarm(false); |
---|
115 | event.update("alarm"); |
---|
116 | } |
---|
117 | catch(OrmNoObjectException &) {} // TODO: implement |
---|
118 | catch(...) {} // just close dialog |
---|
119 | qApp->quit(); |
---|
120 | } |
---|
121 | |
---|