5 #include <QApplication>
8 int Alarm::addAlarm(int aEventId, const QDateTime &aDateTime)
11 alarm_event_t *event = 0;
12 alarm_action_t *action = 0;
14 /* Create alarm event structure and set application identifier */
15 event = alarm_event_create();
16 alarm_event_set_alarm_appid(event, APPID);
17 alarm_event_set_message(event, QString::number(aEventId).toLocal8Bit().data()); // for Deleting purposes
19 /* Use absolute time triggering */
20 event->alarm_time = aDateTime.toTime_t();
22 /* Add exec command action */
23 action = alarm_event_add_actions(event, 1);
24 QString command = QDir::currentPath() + "/" + *qApp->argv() + QString(" %1").arg(QString::number(aEventId));
25 alarm_action_set_exec_command(action, command.toLocal8Bit().data());
26 action->flags |= ALARM_ACTION_TYPE_EXEC;
27 action->flags |= ALARM_ACTION_WHEN_TRIGGERED;
28 action->flags |= ALARM_ACTION_EXEC_ADD_COOKIE; // adds assigned cookie at the end of command string
30 /* Send the alarm to alarmd */
31 cookie = alarmd_event_add(event);
32 if(cookie==0) // adding alarm failed
33 emit(addAlarmFailed(aEventId));
35 emit(alarmAdded(aEventId));
37 /* Free all dynamic memory associated with the alarm event */
38 alarm_event_delete(event);
43 void Alarm::deleteAlarm(int aEventId)
47 alarm_event_t *event = 0;
49 // query the APPID's list of alarms
50 if( (list = alarmd_event_query(0,0, 0,0, APPID)) != 0 ) // query OK
52 for( int i = 0; (cookie = list[i]) != 0; ++i )
54 alarm_event_delete(event);
56 // get the event for specified alarm cookie (alarmId)
57 if( (event = alarmd_event_get(cookie)) == 0 )
59 // should we inform user about it ???
63 if(aEventId==atoi(alarm_event_get_message(event)))
66 if( alarmd_event_del(cookie) == -1 )
68 // was not able to delete alarm for given aEventId
69 emit(deleteAlarmFailed(aEventId));
74 emit(alarmDeleted(aEventId));
86 alarm_event_delete(event);
89 bool Alarm::hasEventAlarm(int aEventId)
93 alarm_event_t *event = 0;
95 bool eventHasAlarm = false;
97 // query the APPID's list of alarms
98 if( (list = alarmd_event_query(0,0, 0,0, APPID)) != 0 ) // query OK
100 for( int i = 0; (cookie = list[i]) != 0; ++i )
102 alarm_event_delete(event);
104 // get the event for specified alarm cookie (alarmId)
105 if( (event = alarmd_event_get(cookie)) == 0 )
107 // should we inform user about it ???
111 if(aEventId==atoi(alarm_event_get_message(event)))
113 eventHasAlarm = true;
124 alarm_event_delete(event);
126 return eventHasAlarm;