[gnome-clocks/wip/gnotification: 3/3] Port to the new GLib notification API



commit 118b48b2b417574edc9f60b34128964e53ff3068
Author: Florian Müllner <fmuellner gnome org>
Date:   Sat Oct 26 11:48:05 2013 +0200

    Port to the new GLib notification API
    
    https://bugzilla.gnome.org/show_bug.cgi?id=710913

 Makefile.am          |    1 -
 configure.ac         |    1 -
 src/alarm.vala       |   34 ++++++++++++++++++++++++++++------
 src/application.vala |    2 ++
 src/utils.vala       |   30 +++++++-----------------------
 5 files changed, 37 insertions(+), 31 deletions(-)
---
diff --git a/Makefile.am b/Makefile.am
index d9dde0d..b64979a 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -100,7 +100,6 @@ AM_VALAFLAGS = \
        --pkg gtk+-3.0 \
        --pkg gweather-3.0 \
        --pkg libcanberra \
-       --pkg libnotify \
        --pkg geocode-glib-1.0 \
        --gresources  $(top_srcdir)/data/gnome-clocks.gresource.xml
 
diff --git a/configure.ac b/configure.ac
index 9a97dff..15181ee 100644
--- a/configure.ac
+++ b/configure.ac
@@ -55,7 +55,6 @@ PKG_CHECK_MODULES(CLOCKS, [
     libcanberra >= 0.30
     gweather-3.0 >= 3.9.91
     gnome-desktop-3.0 >= 3.7.90
-    libnotify >= 0.7.0
     geocode-glib-1.0 >= 0.99.4
     geoclue-2.0 >= 1.99.3
 ])
diff --git a/src/alarm.vala b/src/alarm.vala
index 0216533..4f1f663 100644
--- a/src/alarm.vala
+++ b/src/alarm.vala
@@ -111,12 +111,8 @@ private class Item : Object, ContentItem {
 
     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 ();
-        });
+        bell.add_action (_("Stop"), "app.stop-alarm::".concat(id));
+        bell.add_action (_("Snooze"), "app.snooze-alarm::".concat(id));
     }
 
     public void reset () {
@@ -491,6 +487,23 @@ public class MainPanel : Gtk.Stack, Clocks.Clock {
         alarms = new List<Item> ();
         settings = new GLib.Settings ("org.gnome.clocks");
 
+        var app = GLib.Application.get_default();
+        var action = app.lookup_action ("stop-alarm");
+        ((GLib.SimpleAction)action).activate.connect ((action, param) => {
+            var item = find_item (param.get_string());
+            if (item != null) {
+                item.stop();
+            }
+        });
+
+        action = app.lookup_action ("snooze-alarm");
+        ((GLib.SimpleAction)action).activate.connect ((action, param) => {
+            var item = find_item (param.get_string());
+            if (item != null) {
+                item.snooze();
+            }
+        });
+
         // Translators: "New" refers to an alarm
         new_button = new Gtk.Button.with_label (_("New"));
         new_button.valign = Gtk.Align.CENTER;
@@ -557,6 +570,15 @@ public class MainPanel : Gtk.Stack, Clocks.Clock {
 
     public signal void ring ();
 
+    private Item? find_item (string id) {
+        foreach (var i in alarms) {
+            if (i.id == id) {
+                return i;
+            }
+        }
+        return null;
+    }
+
     private void load () {
         foreach (var a in settings.get_value ("alarms")) {
             Item? alarm = Item.deserialize (a);
diff --git a/src/application.vala b/src/application.vala
index 711e8cf..c2792a3 100644
--- a/src/application.vala
+++ b/src/application.vala
@@ -26,6 +26,8 @@ public class Application : Gtk.Application {
     };
 
     const GLib.ActionEntry[] action_entries = {
+        { "stop-alarm", null, "s" },
+        { "snooze-alarm", null, "s" },
         { "quit", on_quit_activate }
     };
 
diff --git a/src/utils.vala b/src/utils.vala
index 30d28cf..629d4be 100644
--- a/src/utils.vala
+++ b/src/utils.vala
@@ -298,9 +298,7 @@ public class Bell : Object {
     private Canberra.Context? canberra;
     private string soundtheme;
     private string sound;
-    private Notify.Notification? notification;
-
-    public delegate void ActionCallback ();
+    private GLib.Notification notification;
 
     public Bell (string soundid, string title, string msg) {
         settings = new GLib.Settings("org.gnome.desktop.sound");
@@ -313,13 +311,8 @@ public class Bell : Object {
         soundtheme = settings.get_string ("theme-name");
         sound = soundid;
 
-        notification = null;
-        if (Notify.is_initted() || Notify.init ("GNOME Clocks")) {
-            notification = new Notify.Notification (title, msg, "gnome-clocks");
-            notification.set_hint_string ("desktop-entry", "gnome-clocks");
-        } else {
-            warning ("Could not initialize notification");
-        }
+        notification = new GLib.Notification (title);
+        notification.set_body (msg);
     }
 
     private bool keep_ringing () {
@@ -350,13 +343,8 @@ public class Bell : Object {
             }
         }
 
-        if (notification != null) {
-            try {
-                notification.show ();
-            } catch (GLib.Error error) {
-                warning (error.message);
-            }
-        }
+        GLib.Application app = GLib.Application.get_default ();
+        app.send_notification (null, notification);
     }
 
     public void ring_once () {
@@ -373,12 +361,8 @@ public class Bell : Object {
         }
     }
 
-    public void add_action (string action, string label, owned ActionCallback callback) {
-        if (notification != null) {
-            notification.add_action (action, label, (n, a) => {
-                callback ();
-            });
-        }
+    public void add_action (string label, string action) {
+        notification.add_button (label, action);
     }
 }
 


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