[gnome-clocks/wip/gnotification] Do not encapsulate the notification in the Bell class



commit d31c9850997128eff4969b59535c8d94ffa9e824
Author: Paolo Borelli <pborelli gnome org>
Date:   Sat Oct 26 19:41:06 2013 +0200

    Do not encapsulate the notification in the Bell class
    
    Now that the api is part of glib it is clearer to just use it directly
    in Alarm and Timer.

 src/alarm.vala |   11 ++++++++---
 src/timer.vala |    7 ++++++-
 src/utils.vala |   13 +------------
 3 files changed, 15 insertions(+), 16 deletions(-)
---
diff --git a/src/alarm.vala b/src/alarm.vala
index 4f1f663..22786fc 100644
--- a/src/alarm.vala
+++ b/src/alarm.vala
@@ -95,6 +95,7 @@ private class Item : Object, ContentItem {
     private GLib.DateTime snooze_time;
     private GLib.DateTime ring_end_time;
     private Utils.Bell bell;
+    private GLib.Notification notification;
 
     public Item () {
         id = GLib.DBus.generate_guid ();
@@ -110,9 +111,11 @@ private class Item : Object, ContentItem {
     }
 
     private void setup_bell () {
-        bell = new Utils.Bell ("alarm-clock-elapsed", _("Alarm"), name);
-        bell.add_action (_("Stop"), "app.stop-alarm::".concat(id));
-        bell.add_action (_("Snooze"), "app.snooze-alarm::".concat(id));
+        bell = new Utils.Bell ("alarm-clock-elapsed");
+        notification = new GLib.Notification (_("Alarm"));
+        notification.set_body (name);
+        notification.add_button (_("Stop"), "app.stop-alarm::".concat(id));
+        notification.add_button (_("Snooze"), "app.snooze-alarm::".concat(id));
     }
 
     public void reset () {
@@ -154,6 +157,8 @@ private class Item : Object, ContentItem {
     }
 
     public virtual signal void ring () {
+        var app = GLib.Application.get_default ();
+        app.send_notification (null, notification);
         bell.ring ();
     }
 
diff --git a/src/timer.vala b/src/timer.vala
index 77d5186..f7f88cc 100644
--- a/src/timer.vala
+++ b/src/timer.vala
@@ -82,6 +82,7 @@ public class MainPanel : Gtk.Stack, Clocks.Clock {
     private double span;
     private GLib.Timer timer;
     private Utils.Bell bell;
+    private GLib.Notification notification;
     [GtkChild]
     private AnalogFrame setup_frame;
     [GtkChild]
@@ -110,7 +111,9 @@ public class MainPanel : Gtk.Stack, Clocks.Clock {
         span = 0;
         timer = new GLib.Timer ();
 
-        bell = new Utils.Bell ("complete", _("Time is up!"), _("Timer countdown finished"));
+        bell = new Utils.Bell ("complete");
+        notification = new GLib.Notification (_("Time is up!"));
+        notification.set_body (_("Timer countdown finished"));
 
         // Force LTR since we do not want to reverse [hh] : [mm] : [ss]
         grid_spinbuttons.set_direction (Gtk.TextDirection.LTR);
@@ -119,6 +122,8 @@ public class MainPanel : Gtk.Stack, Clocks.Clock {
     }
 
     public virtual signal void ring () {
+        var app = GLib.Application.get_default ();
+        app.send_notification (null, notification);
         bell.ring_once ();
     }
 
diff --git a/src/utils.vala b/src/utils.vala
index 629d4be..f344e91 100644
--- a/src/utils.vala
+++ b/src/utils.vala
@@ -298,9 +298,8 @@ public class Bell : Object {
     private Canberra.Context? canberra;
     private string soundtheme;
     private string sound;
-    private GLib.Notification notification;
 
-    public Bell (string soundid, string title, string msg) {
+    public Bell (string soundid) {
         settings = new GLib.Settings("org.gnome.desktop.sound");
 
         if (Canberra.Context.create (out canberra) < 0) {
@@ -310,9 +309,6 @@ public class Bell : Object {
 
         soundtheme = settings.get_string ("theme-name");
         sound = soundid;
-
-        notification = new GLib.Notification (title);
-        notification.set_body (msg);
     }
 
     private bool keep_ringing () {
@@ -342,9 +338,6 @@ public class Bell : Object {
                 GLib.Idle.add (keep_ringing);
             }
         }
-
-        GLib.Application app = GLib.Application.get_default ();
-        app.send_notification (null, notification);
     }
 
     public void ring_once () {
@@ -360,10 +353,6 @@ public class Bell : Object {
             canberra.cancel (1);
         }
     }
-
-    public void add_action (string label, string action) {
-        notification.add_button (label, action);
-    }
 }
 
 } // namespace Utils


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