Show next deadline
[gregoa/zavai.git] / src / clock.vala
index 727b32de5c3c8288de1233dc0a5c027682a064cd..394ff29e08e5622fe55859e394a526b52be3d138 100644 (file)
@@ -51,7 +51,7 @@ private int alarm_compare(void* a, void* b)
 [DBus (name = "org.freesmartphone.Notification")]
 public class AlarmNotification : Object {
     public void Alarm () {
-        clock.on_alarm();
+        clock.check_alarms();
     }
 }
 
@@ -73,6 +73,7 @@ public class Clock: zavai.Service
 
     // Ticks once a minute
     public signal void minute_changed(long time, SourceType source);
+    public signal void schedule_changed();
 
        public Clock()
        {
@@ -107,18 +108,26 @@ public class Clock: zavai.Service
         //notification.Alarm += on_alarm;
        }
 
+    public Alarm? next_alarm()
+    {
+        if (alarms == null)
+            return null;
+        return alarms.data;
+    }
+
     public void schedule(Alarm a)
     {
         alarms.insert_sorted(a, alarm_compare);
-        zavai.log.info("Next alarm: " + alarms.data.label + " at " + Time.local(alarms.data.deadline).to_string());
         otimed_reschedule();
     }
 
     private void otimed_reschedule()
     {
-        stderr.printf("ALARM: %p BN %s\n", otimed_alarm, zavai.registry.bus_name);
+        zavai.log.info("No alarms left to reschedule");
         if (alarms != null)
         {
+            zavai.log.info("Scheduling next alarm: " + alarms.data.label + " at " + Time.local(alarms.data.deadline).to_string());
+            
             try {
                 otimed_alarm.ClearAlarm(zavai.registry.bus_name);
             } catch (Error e) {
@@ -130,12 +139,7 @@ public class Clock: zavai.Service
                 zavai.log.error("Cannot reschedule alarms: " + e.message);
             }
         }
-    }
-
-    public void on_alarm()
-    {
-stderr.printf("ON ALARM\n");
-        check_alarms();
+        schedule_changed();
     }
 
     public void check_alarms()