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();
24 QString command = QDir::currentPath() + "/" + *qApp->argv() +
25 QString(" %1").arg(QString::number(aEventId));
27 /* Add exec command action */
28 act = alarm_event_add_actions(eve, 1);
29 alarm_action_set_label(act, "FOSDEM'10");
30 // alarm_event_set_icon(eve, "fosdem");
31 // alarm_event_set_title(eve, "FOSDEM'10");
32 act->flags |= ALARM_ACTION_TYPE_EXEC;
33 act->flags |= ALARM_ACTION_WHEN_RESPONDED;
34 // adds assigned cookie at the end of command string
35 // act->flags |= ALARM_ACTION_EXEC_ADD_COOKIE;
36 alarm_action_set_exec_command(act, command.toLocal8Bit().data());
38 /* Add stop button action */
39 act = alarm_event_add_actions(eve, 1);
40 alarm_action_set_label(act, "Stop");
41 act->flags |= ALARM_ACTION_WHEN_RESPONDED;
42 act->flags |= ALARM_ACTION_TYPE_NOP;
44 /* Add snooze button action */
45 act = alarm_event_add_actions(eve, 1);
46 alarm_action_set_label(act, "Snooze");
47 act->flags |= ALARM_ACTION_WHEN_RESPONDED;
48 act->flags |= ALARM_ACTION_TYPE_SNOOZE;
50 /* Send the alarm to alarmd */
51 cookie = alarmd_event_add(eve);
53 // adding alarm failed
55 emit(addAlarmFailed(aEventId));
57 emit(alarmAdded(aEventId));
59 /* Free all dynamic memory associated with the alarm event */
60 alarm_event_delete(eve);
65 void Alarm::deleteAlarm(int aEventId)
69 alarm_event_t *event = 0;
71 // query the APPID's list of alarms
72 if( (list = alarmd_event_query(0,0, 0,0, APPID)) != 0 ) // query OK
74 for( int i = 0; (cookie = list[i]) != 0; ++i )
76 alarm_event_delete(event);
78 // get the event for specified alarm cookie (alarmId)
79 if( (event = alarmd_event_get(cookie)) == 0 )
81 // should we inform user about it ???
85 if(aEventId==atoi(alarm_event_get_message(event)))
88 if( alarmd_event_del(cookie) == -1 )
90 // was not able to delete alarm for given aEventId
91 emit(deleteAlarmFailed(aEventId));
96 emit(alarmDeleted(aEventId));
108 alarm_event_delete(event);
111 bool Alarm::hasEventAlarm(int aEventId)
115 alarm_event_t *event = 0;
117 bool eventHasAlarm = false;
119 // query the APPID's list of alarms
120 if( (list = alarmd_event_query(0,0, 0,0, APPID)) != 0 ) // query OK
122 for( int i = 0; (cookie = list[i]) != 0; ++i )
124 alarm_event_delete(event);
126 // get the event for specified alarm cookie (alarmId)
127 if( (event = alarmd_event_get(cookie)) == 0 )
129 // should we inform user about it ???
133 if(aEventId==atoi(alarm_event_get_message(event)))
135 eventHasAlarm = true;
146 alarm_event_delete(event);
148 return eventHasAlarm;