source: src/alarm/alarm.cpp @ f9db452

qt5
Last change on this file since f9db452 was b6cd05c, checked in by pavelpa <pavelpa@…>, 13 years ago

added 'alarm' columnt to the 'EVENT' table to signalize
that the event has/hasn't alarm set

  • Property mode set to 100644
File size: 3.3 KB
Line 
1#include "alarm.h"
2
3#include <QDateTime>
4
5int Alarm::addAlarm(int aEventId, const QDateTime &aDateTime)
6{
7    cookie_t cookie = 0;
8    alarm_event_t *event = 0;
9    alarm_action_t *action = 0;
10
11    /* Create alarm event structure and set application identifier */
12    event = alarm_event_create();
13    alarm_event_set_alarm_appid(event, APPID);
14    alarm_event_set_message(event, QString::number(aEventId).toLocal8Bit().data()); // for Deleting purposes
15
16    /* Use absolute time triggering */
17    event->alarm_time = aDateTime.toTime_t();
18
19    /* Add exec command action */
20    action = alarm_event_add_actions(event, 1);
21    QString command = QString("/home/maemo/work/alarm/bin/alarmdialog %1").arg(QString::number(aEventId));
22    alarm_action_set_exec_command(action, command.toLocal8Bit().data());
23    action->flags |= ALARM_ACTION_TYPE_EXEC;
24    action->flags |= ALARM_ACTION_WHEN_TRIGGERED;
25    action->flags |= ALARM_ACTION_EXEC_ADD_COOKIE; // adds assigned cookie at the end of command string
26
27    /* Send the alarm to alarmd */
28    cookie = alarmd_event_add(event);
29    if(cookie==0) // adding alarm failed
30        emit(addAlarmFailed(aEventId));
31    else
32        emit(alarmAdded(aEventId));
33
34    /* Free all dynamic memory associated with the alarm event */
35    alarm_event_delete(event);
36
37    return cookie;
38}
39
40void Alarm::deleteAlarm(int aEventId)
41{
42    cookie_t *list = 0;
43    cookie_t cookie = 0;
44    alarm_event_t *event = 0;
45
46    // query the APPID's list of alarms
47    if( (list = alarmd_event_query(0,0, 0,0, APPID)) != 0 ) // query OK
48    {
49        for( int i = 0; (cookie = list[i]) != 0; ++i )
50        {
51            alarm_event_delete(event);
52
53            // get the event for specified alarm cookie (alarmId)
54            if( (event = alarmd_event_get(cookie)) == 0 )
55            {
56                // should we inform user about it ???
57                continue;
58            }
59
60            if(aEventId==atoi(alarm_event_get_message(event)))
61            {
62                // delete cookie
63                if( alarmd_event_del(cookie) == -1 )
64                {
65                    // was not able to delete alarm for given aEventId
66                    emit(deleteAlarmFailed(aEventId));
67                    break;
68                }
69                else
70                {
71                    emit(alarmDeleted(aEventId));
72                    break;
73                }
74            }
75        }
76    }
77    else
78    {
79        // query failed
80    }
81
82    free(list);
83    alarm_event_delete(event);
84}
85
86bool Alarm::hasEventAlarm(int aEventId)
87{
88    cookie_t *list = 0;
89    cookie_t cookie = 0;
90    alarm_event_t *event = 0;
91
92    bool eventHasAlarm = false;
93
94    // query the APPID's list of alarms
95    if( (list = alarmd_event_query(0,0, 0,0, APPID)) != 0 ) // query OK
96    {
97        for( int i = 0; (cookie = list[i]) != 0; ++i )
98        {
99            alarm_event_delete(event);
100
101            // get the event for specified alarm cookie (alarmId)
102            if( (event = alarmd_event_get(cookie)) == 0 )
103            {
104                // should we inform user about it ???
105                continue;
106            }
107
108            if(aEventId==atoi(alarm_event_get_message(event)))
109            {
110                eventHasAlarm = true;
111                break;
112            }
113        }
114    }
115    else
116    {
117        // query failed
118    }
119
120    free(list);
121    alarm_event_delete(event);
122
123    return eventHasAlarm;
124}
125
Note: See TracBrowser for help on using the repository browser.