5 #include <QApplication>
8 int Alarm::addAlarm(int aEventId, const QDateTime &aDateTime)
11 alarm_event_t *eve = 0;
12 alarm_action_t *act = 0;
14 /* Create alarm event structure and set application identifier */
15 eve = alarm_event_create();
16 alarm_event_set_alarm_appid(eve, APPID);
18 /* for Deleting purposes */
19 alarm_event_set_message(eve, QString::number(aEventId).toLocal8Bit().data());
21 /* Use absolute time triggering */
22 eve->alarm_time = time(0) + 5; //aDateTime.toTime_t();
23 eve->flags = ALARM_EVENT_BOOT;
25 QString command = QDir::currentPath() + "/" + *qApp->argv() +
26 QString(" %1").arg(QString::number(aEventId));
28 /* Add exec command action */
29 act = alarm_event_add_actions(eve, 1);
30 alarm_action_set_label(act, "FOSDEM'10");
32 // setup this action to be a "DBus command"
33 act->flags |= ALARM_ACTION_WHEN_RESPONDED;
34 act->flags |= ALARM_ACTION_TYPE_DBUS;
36 // DBus params for this action
37 alarm_action_set_dbus_interface(act, "org.freedesktop.Notifications");
38 alarm_action_set_dbus_service(act, "org.freedesktop.Notifications");
39 alarm_action_set_dbus_path(act, "/org/freedesktop/Notifications");
40 alarm_action_set_dbus_name(act, "SystemNoteDialog");
42 // DBus arguments for the action
43 alarm_action_set_dbus_args(act, aEventId);
45 // act->flags |= ALARM_ACTION_TYPE_EXEC;
46 // alarm_action_set_exec_command(act, command.toLocal8Bit().data());
47 // alarm_event_set_icon(eve, "fosdem");
48 // alarm_event_set_title(eve, "FOSDEM'10");
49 // adds assigned cookie at the end of command string
50 // act->flags |= ALARM_ACTION_EXEC_ADD_COOKIE;
52 /* Add stop button action */
53 /* TODO: send a DBus message to remove that alarm from database */
54 act = alarm_event_add_actions(eve, 1);
55 alarm_action_set_label(act, "Stop");
56 act->flags |= ALARM_ACTION_WHEN_RESPONDED;
57 act->flags |= ALARM_ACTION_TYPE_NOP;
59 /* Add snooze button action */
60 act = alarm_event_add_actions(eve, 1);
61 alarm_action_set_label(act, "Snooze");
62 act->flags |= ALARM_ACTION_WHEN_RESPONDED;
63 act->flags |= ALARM_ACTION_TYPE_SNOOZE;
65 /* Send the alarm to alarmd */
66 cookie = alarmd_event_add(eve);
68 // adding alarm failed
70 emit(addAlarmFailed(aEventId));
72 emit(alarmAdded(aEventId));
74 /* Free all dynamic memory associated with the alarm event */
75 alarm_event_delete(eve);
80 void Alarm::deleteAlarm(int aEventId)
84 alarm_event_t *event = 0;
86 // query the APPID's list of alarms
87 if( (list = alarmd_event_query(0,0, 0,0, APPID)) != 0 ) // query OK
89 for( int i = 0; (cookie = list[i]) != 0; ++i )
91 alarm_event_delete(event);
93 // get the event for specified alarm cookie (alarmId)
94 if( (event = alarmd_event_get(cookie)) == 0 )
96 // should we inform user about it ???
100 if(aEventId==atoi(alarm_event_get_message(event)))
103 if( alarmd_event_del(cookie) == -1 )
105 // was not able to delete alarm for given aEventId
106 emit(deleteAlarmFailed(aEventId));
111 emit(alarmDeleted(aEventId));
123 alarm_event_delete(event);
126 bool Alarm::hasEventAlarm(int aEventId)
130 alarm_event_t *event = 0;
132 bool eventHasAlarm = false;
134 // query the APPID's list of alarms
135 if( (list = alarmd_event_query(0,0, 0,0, APPID)) != 0 ) // query OK
137 for( int i = 0; (cookie = list[i]) != 0; ++i )
139 alarm_event_delete(event);
141 // get the event for specified alarm cookie (alarmId)
142 if( (event = alarmd_event_get(cookie)) == 0 )
144 // should we inform user about it ???
148 if(aEventId==atoi(alarm_event_get_message(event)))
150 eventHasAlarm = true;
161 alarm_event_delete(event);
163 return eventHasAlarm;