Ignore:
Timestamp:
03/21/12 21:42:02 (10 years ago)
Author:
Philipp Spitzer <philipp@…>
Branches:
master, qt5
Children:
a9eca6f
Parents:
9a896cc
Message:

Hopefully fixed bug #38: As the alarm message was used to identify the event by setting it to the eventId and in r1359 the alarm message was changed to show the event title, alarms could not be deleted anymore. Therefore, two alarm attributes (int values) were introduced with this commit: "conferenceId" and "eventId" to identify the event and therefore, deleting alarms should work again. Additionally a second (not reported) bug was fixed: Activating an alarm in the treeview set the alarm to the current time plus 10 seconds.

However, I don't know for sure whether this commit fixed bug #38 becaus I don't have a maemo device to test it.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/alarm/alarm.cpp

    r9a896cc r11d3189  
    3030//#include <dbus-1.0/dbus/dbus-protocol.h>
    3131
    32 int Alarm::addAlarm(int aEventId, QString aEventTitle, const QDateTime &aDateTime)
    33 {
    34     cookie_t cookie = 0;
    35     alarm_event_t *eve = 0;
    36     alarm_action_t *act = 0;
     32int Alarm::addAlarm(int conferenceId, int eventId, QString eventTitle, const QDateTime &alarmDateTime) {
     33    cookie_t alarmCookie = 0;
     34    alarm_event_t *alarmEvent = 0;
     35    alarm_action_t *alarmAction = 0;
    3736
    3837    /* Create alarm event structure and set application identifier */
    39     eve = alarm_event_create();
    40     alarm_event_set_alarm_appid(eve, APPID);
     38    alarmEvent = alarm_event_create();
     39    alarm_event_set_alarm_appid(alarmEvent, APPID);
    4140
    42     /* for Deleting purposes */
    43     // ?!
    44     //alarm_event_set_message(eve, QString::number(aEventId).toLocal8Bit().data());
    45     alarm_event_set_message(eve, aEventTitle.toLocal8Bit().data());
     41    // message
     42    alarm_event_set_title(alarmEvent, "ConfClerk");
     43    alarm_event_set_message(alarmEvent, eventTitle.toLocal8Bit().data());
     44
     45    // for deleting purposes
     46    alarm_event_set_attr_int(alarmEvent, "conferenceId", conferenceId);
     47    alarm_event_set_attr_int(alarmEvent, "eventId", eventId);
    4648
    4749    /* Use absolute time triggering */
    48     //eve->alarm_time = time(0) + 5; // for testing (5 seconds from now)
    49     QDateTime local( aDateTime);
    50     qDebug() << "UTC: " << local.toTime_t();
     50    QDateTime local(alarmDateTime);
    5151    local.setTimeSpec(Qt::LocalTime);
    52     qDebug() << "LocalTime: " << local.toTime_t();
    5352
    54     eve->alarm_time = local.toTime_t();
    55     eve->flags = ALARM_EVENT_BOOT;
     53    alarmEvent->alarm_time = local.toTime_t();
     54    alarmEvent->flags = ALARM_EVENT_BOOT;
    5655
    5756    /* Add exec command action */
    58     act = alarm_event_add_actions(eve, 1);
    59     alarm_action_set_label(act, "ConfClerk");
     57    alarmAction = alarm_event_add_actions(alarmEvent, 1);
     58    alarm_action_set_label(alarmAction, "ConfClerk");
    6059
    61     QString command = QFileInfo(*qApp->argv()).absoluteFilePath() + QString(" %1").arg(QString::number(aEventId));
     60    QString command = QFileInfo(*qApp->argv()).absoluteFilePath() + QString(" %1").arg(QString::number(eventId));
    6261    qDebug() << "Setting alarm: " << command;
    63     alarm_action_set_exec_command(act, command.toLocal8Bit().data());
    64     act->flags |= ALARM_ACTION_TYPE_EXEC;
    65     act->flags |= ALARM_ACTION_WHEN_RESPONDED;
    66     act->flags |= ALARM_ACTION_EXEC_ADD_COOKIE; // adds assigned cookie at the end of command string
     62    alarm_action_set_exec_command(alarmAction, command.toLocal8Bit().data());
     63    alarmAction->flags |= ALARM_ACTION_TYPE_EXEC;
     64    alarmAction->flags |= ALARM_ACTION_WHEN_RESPONDED;
     65    alarmAction->flags |= ALARM_ACTION_EXEC_ADD_COOKIE; // adds assigned cookie at the end of command string
    6766
    6867//    // setup this action to be a "DBus command"
     
    8887    /* Add stop button action */
    8988    /* TODO: send a DBus message to remove that alarm from database */
    90     act = alarm_event_add_actions(eve, 1);
    91     alarm_action_set_label(act, "Stop");
    92     act->flags |= ALARM_ACTION_WHEN_RESPONDED;
    93     act->flags |= ALARM_ACTION_TYPE_NOP;
     89    alarmAction = alarm_event_add_actions(alarmEvent, 1);
     90    alarm_action_set_label(alarmAction, "Stop");
     91    alarmAction->flags |= ALARM_ACTION_WHEN_RESPONDED;
     92    alarmAction->flags |= ALARM_ACTION_TYPE_NOP;
    9493
    9594    /* Add snooze button action */
    96     act = alarm_event_add_actions(eve, 1);
    97     alarm_action_set_label(act, "Snooze");
    98     act->flags |= ALARM_ACTION_WHEN_RESPONDED;
    99     act->flags |= ALARM_ACTION_TYPE_SNOOZE;
     95    alarmAction = alarm_event_add_actions(alarmEvent, 1);
     96    alarm_action_set_label(alarmAction, "Snooze");
     97    alarmAction->flags |= ALARM_ACTION_WHEN_RESPONDED;
     98    alarmAction->flags |= ALARM_ACTION_TYPE_SNOOZE;
    10099
    101100    /* Send the alarm to alarmd */
    102     cookie = alarmd_event_add(eve);
    103 
    104     // adding alarm failed
    105     if (cookie == 0)
    106         emit(addAlarmFailed(aEventId));
    107     else
    108         emit(alarmAdded(aEventId));
     101    alarmCookie = alarmd_event_add(alarmEvent);
    109102
    110103    /* Free all dynamic memory associated with the alarm event */
    111     alarm_event_delete(eve);
     104    alarm_event_delete(alarmEvent);
    112105
    113     return cookie;
     106    return alarmCookie;
    114107}
    115108
    116 void Alarm::deleteAlarm(int aEventId)
    117 {
    118     cookie_t *list = 0;
    119     cookie_t cookie = 0;
    120     alarm_event_t *event = 0;
     109void Alarm::deleteAlarm(int conferenceId, int eventId) {
     110    cookie_t *alarmList = 0;
     111    cookie_t alarmCookie = 0;
     112    alarm_event_t *alarmEvent = 0;
    121113
    122114    // query the APPID's list of alarms
    123     if( (list = alarmd_event_query(0,0, 0,0, APPID)) != 0 ) // query OK
    124     {
    125         for( int i = 0; (cookie = list[i]) != 0; ++i )
    126         {
    127             alarm_event_delete(event);
     115    if( (alarmList = alarmd_event_query(0,0, 0,0, APPID)) != 0) { // query OK
     116        for (int i = 0; (alarmCookie = alarmList[i]) != 0; ++i ) {
     117            // get the event for specified alarm cookie (alarmId)
     118            alarmEvent = alarmd_event_get(alarmCookie);
     119            Q_ASSERT(alarmEvent);
    128120
    129             // get the event for specified alarm cookie (alarmId)
    130             if( (event = alarmd_event_get(cookie)) == 0 )
    131             {
    132                 // should we inform user about it ???
    133                 continue;
    134             }
    135 
    136             if(aEventId==atoi(alarm_event_get_message(event)))
    137             {
    138                 // delete cookie
    139                 if( alarmd_event_del(cookie) == -1 )
    140                 {
    141                     // was not able to delete alarm for given aEventId
    142                     emit(deleteAlarmFailed(aEventId));
    143                     break;
    144                 }
    145                 else
    146                 {
    147                     emit(alarmDeleted(aEventId));
    148                     break;
    149                 }
    150             }
     121            bool found = (conferenceId == alarm_event_get_attr_int(alarmEvent, "conferenceId", -1) && eventId == alarm_event_get_attr_int(alarmEvent, "eventId", -1));
     122            if (found) alarmd_event_del(alarmCookie); // delete cookie
     123            alarm_event_delete(alarmEvent);
     124            if (found) break;
    151125        }
    152126    }
    153     else
    154     {
    155         // query failed
    156     }
    157 
    158     free(list);
    159     alarm_event_delete(event);
     127    free(alarmList);
    160128}
    161 
    162 bool Alarm::hasEventAlarm(int aEventId)
    163 {
    164     cookie_t *list = 0;
    165     cookie_t cookie = 0;
    166     alarm_event_t *event = 0;
    167 
    168     bool eventHasAlarm = false;
    169 
    170     // query the APPID's list of alarms
    171     if( (list = alarmd_event_query(0,0, 0,0, APPID)) != 0 ) // query OK
    172     {
    173         for( int i = 0; (cookie = list[i]) != 0; ++i )
    174         {
    175             alarm_event_delete(event);
    176 
    177             // get the event for specified alarm cookie (alarmId)
    178             if( (event = alarmd_event_get(cookie)) == 0 )
    179             {
    180                 // should we inform user about it ???
    181                 continue;
    182             }
    183 
    184             if(aEventId==atoi(alarm_event_get_message(event)))
    185             {
    186                 eventHasAlarm = true;
    187                 break;
    188             }
    189         }
    190     }
    191     else
    192     {
    193         // query failed
    194     }
    195 
    196     free(list);
    197     alarm_event_delete(event);
    198 
    199     return eventHasAlarm;
    200 }
    201 
Note: See TracChangeset for help on using the changeset viewer.