source: src/alarm/alarm.cpp

Last change on this file was ffb6be7, checked in by gregor herrmann <gregor@…>, 4 months ago

Bump copyright years.

  • Property mode set to 100644
File size: 3.8 KB
Line 
1/*
2 * Copyright (C) 2010 Ixonos Plc.
3 * Copyright (C) 2011-2021 Philipp Spitzer, gregor herrmann, Stefan Stahl
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 "alarm.h"
21
22#include <QDateTime>
23
24#include <QApplication>
25#include <QDir>
26#include <QFileInfo>
27
28
29int Alarm::addAlarm(int conferenceId, int eventId, QString eventTitle, const QDateTime &alarmDateTime) {
30    cookie_t alarmCookie = 0;
31    alarm_event_t *alarmEvent = 0;
32    alarm_action_t *alarmAction = 0;
33
34    /* Create alarm event structure and set application identifier */
35    alarmEvent = alarm_event_create();
36    alarm_event_set_alarm_appid(alarmEvent, APPID);
37
38    // message
39    alarm_event_set_title(alarmEvent, "ConfClerk");
40    alarm_event_set_message(alarmEvent, eventTitle.toLocal8Bit().data());
41
42    // for deleting purposes
43    alarm_event_set_attr_int(alarmEvent, "conferenceId", conferenceId);
44    alarm_event_set_attr_int(alarmEvent, "eventId", eventId);
45
46    /* Use absolute time triggering */
47    QDateTime local(alarmDateTime);
48    local.setTimeSpec(Qt::LocalTime);
49
50    alarmEvent->alarm_time = local.toTime_t();
51    alarmEvent->flags = ALARM_EVENT_BOOT;
52
53    /* Add exec command action */
54    alarmAction = alarm_event_add_actions(alarmEvent, 1);
55    alarm_action_set_label(alarmAction, "ConfClerk");
56
57    QString command = QFileInfo(*qApp->argv()).absoluteFilePath() + QString(" %1 %2").arg(conferenceId).arg(eventId);
58    alarm_action_set_exec_command(alarmAction, command.toLocal8Bit().data());
59    alarmAction->flags |= ALARM_ACTION_TYPE_EXEC;
60    alarmAction->flags |= ALARM_ACTION_WHEN_RESPONDED;
61    alarmAction->flags |= ALARM_ACTION_EXEC_ADD_COOKIE; // adds assigned cookie at the end of command string
62
63    /* Add stop button action */
64    alarmAction = alarm_event_add_actions(alarmEvent, 1);
65    alarm_action_set_label(alarmAction, "Stop");
66    alarmAction->flags |= ALARM_ACTION_WHEN_RESPONDED;
67    alarmAction->flags |= ALARM_ACTION_TYPE_NOP;
68
69    /* Add snooze button action */
70    alarmAction = alarm_event_add_actions(alarmEvent, 1);
71    alarm_action_set_label(alarmAction, "Snooze");
72    alarmAction->flags |= ALARM_ACTION_WHEN_RESPONDED;
73    alarmAction->flags |= ALARM_ACTION_TYPE_SNOOZE;
74
75    /* Send the alarm to alarmd */
76    alarmCookie = alarmd_event_add(alarmEvent);
77
78    /* Free all dynamic memory associated with the alarm event */
79    alarm_event_delete(alarmEvent);
80
81    return alarmCookie;
82}
83
84void Alarm::deleteAlarm(int conferenceId, int eventId) {
85    cookie_t *alarmList = 0;
86    cookie_t alarmCookie = 0;
87    alarm_event_t *alarmEvent = 0;
88
89    // query the APPID's list of alarms
90    if( (alarmList = alarmd_event_query(0,0, 0,0, APPID)) != 0) { // query OK
91        for (int i = 0; (alarmCookie = alarmList[i]) != 0; ++i ) {
92            // get the event for specified alarm cookie (alarmId)
93            alarmEvent = alarmd_event_get(alarmCookie);
94            Q_ASSERT(alarmEvent);
95
96            bool found = (conferenceId == alarm_event_get_attr_int(alarmEvent, "conferenceId", -1) && eventId == alarm_event_get_attr_int(alarmEvent, "eventId", -1));
97            if (found) alarmd_event_del(alarmCookie); // delete cookie
98            alarm_event_delete(alarmEvent);
99            if (found) break;
100        }
101    }
102    free(alarmList);
103}
Note: See TracBrowser for help on using the repository browser.