+/*
+ * Copyright (C) 2010 Ixonos Plc.
+ * Copyright (C) 2011-2024 Philipp Spitzer, gregor herrmann, Stefan Stahl
+ *
+ * This file is part of ConfClerk.
+ *
+ * ConfClerk is free software: you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License as published by the Free
+ * Software Foundation, either version 2 of the License, or (at your option)
+ * any later version.
+ *
+ * ConfClerk is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+ * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
+ * more details.
+ *
+ * You should have received a copy of the GNU General Public License along with
+ * ConfClerk. If not, see <http://www.gnu.org/licenses/>.
+ */
#include "alarm.h"
#include <QDateTime>
#include <QApplication>
#include <QDir>
+#include <QFileInfo>
-int Alarm::addAlarm(int aEventId, const QDateTime &aDateTime)
-{
- cookie_t cookie = 0;
- alarm_event_t *eve = 0;
- alarm_action_t *act = 0;
+
+int Alarm::addAlarm(int conferenceId, int eventId, QString eventTitle, const QDateTime &alarmDateTime) {
+ cookie_t alarmCookie = 0;
+ alarm_event_t *alarmEvent = 0;
+ alarm_action_t *alarmAction = 0;
/* Create alarm event structure and set application identifier */
- eve = alarm_event_create();
- alarm_event_set_alarm_appid(eve, APPID);
+ alarmEvent = alarm_event_create();
+ alarm_event_set_alarm_appid(alarmEvent, APPID);
+
+ // message
+ alarm_event_set_title(alarmEvent, "ConfClerk");
+ alarm_event_set_message(alarmEvent, eventTitle.toLocal8Bit().data());
- /* for Deleting purposes */
- alarm_event_set_message(eve, QString::number(aEventId).toLocal8Bit().data());
+ // for deleting purposes
+ alarm_event_set_attr_int(alarmEvent, "conferenceId", conferenceId);
+ alarm_event_set_attr_int(alarmEvent, "eventId", eventId);
/* Use absolute time triggering */
- eve->alarm_time = time(0) + 5; //aDateTime.toTime_t();
+ QDateTime local(alarmDateTime);
+ local.setTimeSpec(Qt::LocalTime);
- QString command = QDir::currentPath() + "/" + *qApp->argv() +
- QString(" %1").arg(QString::number(aEventId));
+ alarmEvent->alarm_time = local.toTime_t();
+ alarmEvent->flags = ALARM_EVENT_BOOT;
/* Add exec command action */
- act = alarm_event_add_actions(eve, 1);
- alarm_action_set_label(act, "FOSDEM'10");
- // alarm_event_set_icon(eve, "fosdem");
- // alarm_event_set_title(eve, "FOSDEM'10");
- act->flags |= ALARM_ACTION_TYPE_EXEC;
- act->flags |= ALARM_ACTION_WHEN_RESPONDED;
- // adds assigned cookie at the end of command string
- // act->flags |= ALARM_ACTION_EXEC_ADD_COOKIE;
- alarm_action_set_exec_command(act, command.toLocal8Bit().data());
+ alarmAction = alarm_event_add_actions(alarmEvent, 1);
+ alarm_action_set_label(alarmAction, "ConfClerk");
+
+ QString command = QFileInfo(*qApp->argv()).absoluteFilePath() + QString(" %1 %2").arg(conferenceId).arg(eventId);
+ alarm_action_set_exec_command(alarmAction, command.toLocal8Bit().data());
+ alarmAction->flags |= ALARM_ACTION_TYPE_EXEC;
+ alarmAction->flags |= ALARM_ACTION_WHEN_RESPONDED;
+ alarmAction->flags |= ALARM_ACTION_EXEC_ADD_COOKIE; // adds assigned cookie at the end of command string
/* Add stop button action */
- act = alarm_event_add_actions(eve, 1);
- alarm_action_set_label(act, "Stop");
- act->flags |= ALARM_ACTION_WHEN_RESPONDED;
- act->flags |= ALARM_ACTION_TYPE_NOP;
-
+ alarmAction = alarm_event_add_actions(alarmEvent, 1);
+ alarm_action_set_label(alarmAction, "Stop");
+ alarmAction->flags |= ALARM_ACTION_WHEN_RESPONDED;
+ alarmAction->flags |= ALARM_ACTION_TYPE_NOP;
+
/* Add snooze button action */
- act = alarm_event_add_actions(eve, 1);
- alarm_action_set_label(act, "Snooze");
- act->flags |= ALARM_ACTION_WHEN_RESPONDED;
- act->flags |= ALARM_ACTION_TYPE_SNOOZE;
+ alarmAction = alarm_event_add_actions(alarmEvent, 1);
+ alarm_action_set_label(alarmAction, "Snooze");
+ alarmAction->flags |= ALARM_ACTION_WHEN_RESPONDED;
+ alarmAction->flags |= ALARM_ACTION_TYPE_SNOOZE;
/* Send the alarm to alarmd */
- cookie = alarmd_event_add(eve);
-
- // adding alarm failed
- if (cookie == 0)
- emit(addAlarmFailed(aEventId));
- else
- emit(alarmAdded(aEventId));
+ alarmCookie = alarmd_event_add(alarmEvent);
/* Free all dynamic memory associated with the alarm event */
- alarm_event_delete(eve);
+ alarm_event_delete(alarmEvent);
- return cookie;
+ return alarmCookie;
}
-void Alarm::deleteAlarm(int aEventId)
-{
- cookie_t *list = 0;
- cookie_t cookie = 0;
- alarm_event_t *event = 0;
+void Alarm::deleteAlarm(int conferenceId, int eventId) {
+ cookie_t *alarmList = 0;
+ cookie_t alarmCookie = 0;
+ alarm_event_t *alarmEvent = 0;
// query the APPID's list of alarms
- if( (list = alarmd_event_query(0,0, 0,0, APPID)) != 0 ) // query OK
- {
- for( int i = 0; (cookie = list[i]) != 0; ++i )
- {
- alarm_event_delete(event);
-
+ if( (alarmList = alarmd_event_query(0,0, 0,0, APPID)) != 0) { // query OK
+ for (int i = 0; (alarmCookie = alarmList[i]) != 0; ++i ) {
// get the event for specified alarm cookie (alarmId)
- if( (event = alarmd_event_get(cookie)) == 0 )
- {
- // should we inform user about it ???
- continue;
- }
-
- if(aEventId==atoi(alarm_event_get_message(event)))
- {
- // delete cookie
- if( alarmd_event_del(cookie) == -1 )
- {
- // was not able to delete alarm for given aEventId
- emit(deleteAlarmFailed(aEventId));
- break;
- }
- else
- {
- emit(alarmDeleted(aEventId));
- break;
- }
- }
- }
- }
- else
- {
- // query failed
- }
-
- free(list);
- alarm_event_delete(event);
-}
-
-bool Alarm::hasEventAlarm(int aEventId)
-{
- cookie_t *list = 0;
- cookie_t cookie = 0;
- alarm_event_t *event = 0;
-
- bool eventHasAlarm = false;
-
- // query the APPID's list of alarms
- if( (list = alarmd_event_query(0,0, 0,0, APPID)) != 0 ) // query OK
- {
- for( int i = 0; (cookie = list[i]) != 0; ++i )
- {
- alarm_event_delete(event);
+ alarmEvent = alarmd_event_get(alarmCookie);
+ Q_ASSERT(alarmEvent);
- // get the event for specified alarm cookie (alarmId)
- if( (event = alarmd_event_get(cookie)) == 0 )
- {
- // should we inform user about it ???
- continue;
- }
-
- if(aEventId==atoi(alarm_event_get_message(event)))
- {
- eventHasAlarm = true;
- break;
- }
+ bool found = (conferenceId == alarm_event_get_attr_int(alarmEvent, "conferenceId", -1) && eventId == alarm_event_get_attr_int(alarmEvent, "eventId", -1));
+ if (found) alarmd_event_del(alarmCookie); // delete cookie
+ alarm_event_delete(alarmEvent);
+ if (found) break;
}
}
- else
- {
- // query failed
- }
-
- free(list);
- alarm_event_delete(event);
-
- return eventHasAlarm;
+ free(alarmList);
}
-