2 * Copyright (C) 2010 Ixonos Plc.
3 * Copyright (C) 2011-2012 Philipp Spitzer, gregor herrmann, Stefan Stahl
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/>.
24 #include <QApplication>
30 int Alarm::addAlarm(int conferenceId, int eventId, QString eventTitle, const QDateTime &alarmDateTime) {
31 cookie_t alarmCookie = 0;
32 alarm_event_t *alarmEvent = 0;
33 alarm_action_t *alarmAction = 0;
35 /* Create alarm event structure and set application identifier */
36 alarmEvent = alarm_event_create();
37 alarm_event_set_alarm_appid(alarmEvent, APPID);
40 alarm_event_set_title(alarmEvent, "ConfClerk");
41 alarm_event_set_message(alarmEvent, eventTitle.toLocal8Bit().data());
43 // for deleting purposes
44 alarm_event_set_attr_int(alarmEvent, "conferenceId", conferenceId);
45 alarm_event_set_attr_int(alarmEvent, "eventId", eventId);
47 /* Use absolute time triggering */
48 QDateTime local(alarmDateTime);
49 local.setTimeSpec(Qt::LocalTime);
51 alarmEvent->alarm_time = local.toTime_t();
52 alarmEvent->flags = ALARM_EVENT_BOOT;
54 /* Add exec command action */
55 alarmAction = alarm_event_add_actions(alarmEvent, 1);
56 alarm_action_set_label(alarmAction, "ConfClerk");
58 QString command = QFileInfo(*qApp->argv()).absoluteFilePath() + QString(" %1 %2").arg(conferenceId).arg(eventId);
59 qDebug() << "Setting alarm: " << command;
60 alarm_action_set_exec_command(alarmAction, command.toLocal8Bit().data());
61 alarmAction->flags |= ALARM_ACTION_TYPE_EXEC;
62 alarmAction->flags |= ALARM_ACTION_WHEN_RESPONDED;
63 alarmAction->flags |= ALARM_ACTION_EXEC_ADD_COOKIE; // adds assigned cookie at the end of command string
65 /* Add stop button action */
66 alarmAction = alarm_event_add_actions(alarmEvent, 1);
67 alarm_action_set_label(alarmAction, "Stop");
68 alarmAction->flags |= ALARM_ACTION_WHEN_RESPONDED;
69 alarmAction->flags |= ALARM_ACTION_TYPE_NOP;
71 /* Add snooze button action */
72 alarmAction = alarm_event_add_actions(alarmEvent, 1);
73 alarm_action_set_label(alarmAction, "Snooze");
74 alarmAction->flags |= ALARM_ACTION_WHEN_RESPONDED;
75 alarmAction->flags |= ALARM_ACTION_TYPE_SNOOZE;
77 /* Send the alarm to alarmd */
78 alarmCookie = alarmd_event_add(alarmEvent);
80 /* Free all dynamic memory associated with the alarm event */
81 alarm_event_delete(alarmEvent);
86 void Alarm::deleteAlarm(int conferenceId, int eventId) {
87 cookie_t *alarmList = 0;
88 cookie_t alarmCookie = 0;
89 alarm_event_t *alarmEvent = 0;
91 // query the APPID's list of alarms
92 if( (alarmList = alarmd_event_query(0,0, 0,0, APPID)) != 0) { // query OK
93 for (int i = 0; (alarmCookie = alarmList[i]) != 0; ++i ) {
94 // get the event for specified alarm cookie (alarmId)
95 alarmEvent = alarmd_event_get(alarmCookie);
98 bool found = (conferenceId == alarm_event_get_attr_int(alarmEvent, "conferenceId", -1) && eventId == alarm_event_get_attr_int(alarmEvent, "eventId", -1));
99 if (found) alarmd_event_del(alarmCookie); // delete cookie
100 alarm_event_delete(alarmEvent);