source: src/alarm/alarm.cpp @ 21e0eb1

qt5
Last change on this file since 21e0eb1 was 21e0eb1, checked in by gregor herrmann <gregoa@…>, 10 years ago

Rip out unused DBUS stuff.

  • Property mode set to 100644
File size: 3.9 KB
Line 
1/*
2 * Copyright (C) 2010 Ixonos Plc.
3 * Copyright (C) 2011-2012 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#include <QDebug>
29
30int 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;
34
35    /* Create alarm event structure and set application identifier */
36    alarmEvent = alarm_event_create();
37    alarm_event_set_alarm_appid(alarmEvent, APPID);
38
39    // message
40    alarm_event_set_title(alarmEvent, "ConfClerk");
41    alarm_event_set_message(alarmEvent, eventTitle.toLocal8Bit().data());
42
43    // for deleting purposes
44    alarm_event_set_attr_int(alarmEvent, "conferenceId", conferenceId);
45    alarm_event_set_attr_int(alarmEvent, "eventId", eventId);
46
47    /* Use absolute time triggering */
48    QDateTime local(alarmDateTime);
49    local.setTimeSpec(Qt::LocalTime);
50
51    alarmEvent->alarm_time = local.toTime_t();
52    alarmEvent->flags = ALARM_EVENT_BOOT;
53
54    /* Add exec command action */
55    alarmAction = alarm_event_add_actions(alarmEvent, 1);
56    alarm_action_set_label(alarmAction, "ConfClerk");
57
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
64
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;
70
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;
76
77    /* Send the alarm to alarmd */
78    alarmCookie = alarmd_event_add(alarmEvent);
79
80    /* Free all dynamic memory associated with the alarm event */
81    alarm_event_delete(alarmEvent);
82
83    return alarmCookie;
84}
85
86void Alarm::deleteAlarm(int conferenceId, int eventId) {
87    cookie_t *alarmList = 0;
88    cookie_t alarmCookie = 0;
89    alarm_event_t *alarmEvent = 0;
90
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);
96            Q_ASSERT(alarmEvent);
97
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);
101            if (found) break;
102        }
103    }
104    free(alarmList);
105}
Note: See TracBrowser for help on using the repository browser.