[gnome-clocks] Show Stop/Snooze actions in the alarm notification



commit 52fa3408bb21dffa2dab1ce4850281e34ad0ae59
Author: Paolo Borelli <pborelli gnome org>
Date:   Fri Feb 22 00:07:02 2013 +0100

    Show Stop/Snooze actions in the alarm notification
    
    Add the actions to the notification and rework code so that the
    ringing panel dismisses itself even when the alarm is stopped or
    snoozed from the notification.

 src/alarm.vala |   45 +++++++++++++++++++++++++++++++++++++--------
 src/utils.vala |    6 ++++++
 2 files changed, 43 insertions(+), 8 deletions(-)
---
diff --git a/src/alarm.vala b/src/alarm.vala
index 806f291..e96da56 100644
--- a/src/alarm.vala
+++ b/src/alarm.vala
@@ -38,7 +38,7 @@ private class Item : Object {
 
         set {
             _name = value;
-            bell = new Utils.Bell ("alarm-clock-elapsed", _("Alarm"), _name);
+            setup_bell ();
         }
     }
 
@@ -91,18 +91,26 @@ private class Item : Object {
     private Utils.Bell bell;
 
     public Item () {
-        bell = new Utils.Bell ("alarm-clock-elapsed", _("Alarm"), "");
         days = new Utils.Weekdays ();
     }
 
     public Item.with_data (string name, bool active, int hour, int minute, Utils.Weekdays days) {
         Object (name: name, active: active, hour: hour, minute: minute, days: days);
 
-        bell = new Utils.Bell ("alarm-clock-elapsed", _("Alarm"), name);
-
+        setup_bell ();
         reset ();
     }
 
+    private void setup_bell () {
+        bell = new Utils.Bell ("alarm-clock-elapsed", _("Alarm"), name);
+        bell.add_action ("stop", _("Stop"), () => {
+            stop ();
+        });
+        bell.add_action ("snooze", _("Snooze"), () => {
+            snooze ();
+        });
+    }
+
     public void reset () {
         update_alarm_time ();
         update_snooze_time (alarm_time);
@@ -378,8 +386,29 @@ private class SetupDialog : Gtk.Dialog {
 }
 
 private class StandalonePanel : Gtk.EventBox {
-    public Item alarm { get; set; }
+    public Item alarm {
+        get {
+            return _alarm;
+        }
+        set {
+            if (_alarm != null) {
+                _alarm.disconnect (alarm_state_handler);
+            }
+
+            _alarm = value;
+
+            if (_alarm != null) {
+                alarm_state_handler = _alarm.notify["state"].connect (() => {
+                    if (alarm.state != Item.State.RINGING) {
+                        dismiss ();
+                    }
+                });
+            }
+        }
+    }
 
+    private Item? _alarm;
+    private ulong alarm_state_handler;
     private Gtk.Label time_label;
     private Gtk.Button stop_button;
     private Gtk.Button snooze_button;
@@ -396,18 +425,18 @@ private class StandalonePanel : Gtk.EventBox {
 
         stop_button.clicked.connect (() => {
             alarm.stop ();
-            dismiss ();
         });
 
         snooze_button.clicked.connect (() => {
             alarm.snooze ();
-            dismiss ();
         });
 
         add (grid);
     }
 
-    public signal void dismiss ();
+    public virtual signal void dismiss () {
+        alarm = null;
+    }
 
     public void update () {
         if (alarm != null) {
diff --git a/src/utils.vala b/src/utils.vala
index afd07ce..6005a84 100644
--- a/src/utils.vala
+++ b/src/utils.vala
@@ -352,6 +352,12 @@ public class Bell : Object {
             canberra.cancel (1);
         }
     }
+
+    public void add_action (string action, string label, owned Notify.ActionCallback callback) {
+        if (notification != null) {
+            notification.add_action (action, label, (owned) callback);
+        }
+    }
 }
 
 } // namespace Utils


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]