source: src/alarm/alarm.cpp

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

Bump copyright years.

  • Property mode set to 100644
File size: 3.8 KB
RevLine 
[ca90cb1]1/*
2 * Copyright (C) 2010 Ixonos Plc.
[ffb6be7]3 * Copyright (C) 2011-2021 Philipp Spitzer, gregor herrmann, Stefan Stahl
[ca90cb1]4 *
[6df32f2]5 * This file is part of ConfClerk.
[ca90cb1]6 *
[6df32f2]7 * ConfClerk is free software: you can redistribute it and/or modify it
[ca90cb1]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 *
[6df32f2]12 * ConfClerk is distributed in the hope that it will be useful, but
[ca90cb1]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
[6df32f2]18 * ConfClerk.  If not, see <http://www.gnu.org/licenses/>.
[ca90cb1]19 */
[6ae1026]20#include "alarm.h"
21
22#include <QDateTime>
23
[d4a8bbf]24#include <QApplication>
25#include <QDir>
[a7d8638]26#include <QFileInfo>
[6831c6a]27
[2104023]28
[11d3189]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;
[6ae1026]33
34    /* Create alarm event structure and set application identifier */
[11d3189]35    alarmEvent = alarm_event_create();
36    alarm_event_set_alarm_appid(alarmEvent, APPID);
[6197713]37
[11d3189]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);
[6ae1026]45
46    /* Use absolute time triggering */
[11d3189]47    QDateTime local(alarmDateTime);
[ba3fc20]48    local.setTimeSpec(Qt::LocalTime);
[5d9409d]49
[11d3189]50    alarmEvent->alarm_time = local.toTime_t();
51    alarmEvent->flags = ALARM_EVENT_BOOT;
[6197713]52
[6ae1026]53    /* Add exec command action */
[11d3189]54    alarmAction = alarm_event_add_actions(alarmEvent, 1);
55    alarm_action_set_label(alarmAction, "ConfClerk");
[6645e1f]56
[3ecfbf0]57    QString command = QFileInfo(*qApp->argv()).absoluteFilePath() + QString(" %1 %2").arg(conferenceId).arg(eventId);
[11d3189]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
[a7d8638]62
[6197713]63    /* Add stop button action */
[11d3189]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;
[6831c6a]68
[6197713]69    /* Add snooze button action */
[11d3189]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;
[6ae1026]74
75    /* Send the alarm to alarmd */
[11d3189]76    alarmCookie = alarmd_event_add(alarmEvent);
[6ae1026]77
78    /* Free all dynamic memory associated with the alarm event */
[11d3189]79    alarm_event_delete(alarmEvent);
[6ae1026]80
[11d3189]81    return alarmCookie;
[6ae1026]82}
83
[11d3189]84void Alarm::deleteAlarm(int conferenceId, int eventId) {
85    cookie_t *alarmList = 0;
86    cookie_t alarmCookie = 0;
87    alarm_event_t *alarmEvent = 0;
[6ae1026]88
89    // query the APPID's list of alarms
[11d3189]90    if( (alarmList = alarmd_event_query(0,0, 0,0, APPID)) != 0) { // query OK
91        for (int i = 0; (alarmCookie = alarmList[i]) != 0; ++i ) {
[6ae1026]92            // get the event for specified alarm cookie (alarmId)
[11d3189]93            alarmEvent = alarmd_event_get(alarmCookie);
94            Q_ASSERT(alarmEvent);
[b6cd05c]95
[11d3189]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;
[b6cd05c]100        }
101    }
[11d3189]102    free(alarmList);
[b6cd05c]103}
Note: See TracBrowser for help on using the repository browser.