changed conditions for conflicts
[toast/confclerk.git] / src / alarm / alarm.cpp
index af3120e40e2bdd2eeddd78195245fbf8def3e7b5..a8c42f968c65b8ff0662058de6583aa24e609711 100644 (file)
@@ -2,37 +2,62 @@
 
 #include <QDateTime>
 
+#include <QApplication>
+#include <QDir>
+
 int Alarm::addAlarm(int aEventId, const QDateTime &aDateTime)
 {
     cookie_t cookie = 0;
-    alarm_event_t *event = 0;
-    alarm_action_t *action = 0;
+    alarm_event_t *eve = 0;
+    alarm_action_t *act = 0;
 
     /* Create alarm event structure and set application identifier */
-    event = alarm_event_create();
-    alarm_event_set_alarm_appid(event, APPID);
-    alarm_event_set_message(event, QString::number(aEventId).toLocal8Bit().data()); // for Deleting purposes
+    eve = alarm_event_create();
+    alarm_event_set_alarm_appid(eve, APPID);
+
+    /* for Deleting purposes */
+    alarm_event_set_message(eve, QString::number(aEventId).toLocal8Bit().data()); 
 
     /* Use absolute time triggering */
-    event->alarm_time = aDateTime.toTime_t();
+    eve->alarm_time = time(0) + 5; //aDateTime.toTime_t();
+
+    QString command = QDir::currentPath() + "/" + *qApp->argv() + 
+      QString(" %1").arg(QString::number(aEventId));
 
     /* Add exec command action */
-    action = alarm_event_add_actions(event, 1);
-    QString command = QString("/home/maemo/work/alarm/bin/alarmdialog %1").arg(QString::number(aEventId));
-    alarm_action_set_exec_command(action, command.toLocal8Bit().data());
-    action->flags |= ALARM_ACTION_TYPE_EXEC;
-    action->flags |= ALARM_ACTION_WHEN_TRIGGERED;
-    action->flags |= ALARM_ACTION_EXEC_ADD_COOKIE; // adds assigned cookie at the end of command string
+    act = alarm_event_add_actions(eve, 1);
+    alarm_action_set_label(act, "FOSDEM'10");
+    //    alarm_event_set_icon(eve, "fosdem");
+    //    alarm_event_set_title(eve, "FOSDEM'10");
+    act->flags |= ALARM_ACTION_TYPE_EXEC;
+    act->flags |= ALARM_ACTION_WHEN_RESPONDED;
+    // adds assigned cookie at the end of command string 
+    //    act->flags |= ALARM_ACTION_EXEC_ADD_COOKIE; 
+    alarm_action_set_exec_command(act, command.toLocal8Bit().data());
+
+    /* Add stop button action */
+    act = alarm_event_add_actions(eve, 1);
+    alarm_action_set_label(act, "Stop");
+    act->flags |= ALARM_ACTION_WHEN_RESPONDED;
+    act->flags |= ALARM_ACTION_TYPE_NOP;
+  
+    /* Add snooze button action */
+    act = alarm_event_add_actions(eve, 1);
+    alarm_action_set_label(act, "Snooze");
+    act->flags |= ALARM_ACTION_WHEN_RESPONDED;
+    act->flags |= ALARM_ACTION_TYPE_SNOOZE;
 
     /* Send the alarm to alarmd */
-    cookie = alarmd_event_add(event);
-    if(cookie==0) // adding alarm failed
+    cookie = alarmd_event_add(eve);
+
+    // adding alarm failed
+    if (cookie == 0)
         emit(addAlarmFailed(aEventId));
     else
         emit(alarmAdded(aEventId));
 
     /* Free all dynamic memory associated with the alarm event */
-    alarm_event_delete(event);
+    alarm_event_delete(eve);
 
     return cookie;
 }
@@ -83,3 +108,43 @@ void Alarm::deleteAlarm(int aEventId)
     alarm_event_delete(event);
 }
 
+bool Alarm::hasEventAlarm(int aEventId)
+{
+    cookie_t *list = 0;
+    cookie_t cookie = 0;
+    alarm_event_t *event = 0;
+
+    bool eventHasAlarm = false;
+
+    // query the APPID's list of alarms
+    if( (list = alarmd_event_query(0,0, 0,0, APPID)) != 0 ) // query OK
+    {
+        for( int i = 0; (cookie = list[i]) != 0; ++i )
+        {
+            alarm_event_delete(event);
+
+            // get the event for specified alarm cookie (alarmId)
+            if( (event = alarmd_event_get(cookie)) == 0 )
+            {
+                // should we inform user about it ???
+                continue;
+            }
+
+            if(aEventId==atoi(alarm_event_get_message(event)))
+            {
+                eventHasAlarm = true;
+                break;
+            }
+        }
+    }
+    else
+    {
+        // query failed
+    }
+
+    free(list);
+    alarm_event_delete(event);
+
+    return eventHasAlarm;
+}
+