[Xfce4-commits] <postler:master> Move notification and sound into the service

Christian Dywan noreply at xfce.org
Mon Dec 13 04:28:04 CET 2010


Updating branch refs/heads/master
         to 0da5691791c9808581f4e919a33b611e6629049a (commit)
       from 7cd1a90be8b788d5063243b78114c1b6e788497a (commit)

commit 0da5691791c9808581f4e919a33b611e6629049a
Author: Christian Dywan <christian at twotoasts.de>
Date:   Sun Dec 12 23:24:35 2010 +0100

    Move notification and sound into the service

 postler/postler-app.vala     |   24 ++++++++++++++++++++++++
 postler/postler-bureau.vala  |    2 --
 postler/postler-folders.vala |   20 --------------------
 postler/postler-service.vala |    6 ++++++
 4 files changed, 30 insertions(+), 22 deletions(-)

diff --git a/postler/postler-app.vala b/postler/postler-app.vala
index 76255a0..a6cca73 100644
--- a/postler/postler-app.vala
+++ b/postler/postler-app.vala
@@ -197,5 +197,29 @@ public class Postler.App : Unique.App {
         }
         return true;
     }
+
+    public static void send_notification (string message) {
+        try {
+            if (!Notify.is_initted ()) {
+                if (!Notify.init ("Postler"))
+                    throw new FileError.FAILED (_("Failed to initialize."));
+            }
+            var notification = (Notify.Notification)GLib.Object.new (
+                typeof (Notify.Notification),
+                "summary", GLib.Environment.get_application_name (),
+                "body", message,
+                "icon-name", STOCK_INTERNET_MAIL);
+            notification.show ();
+        } catch (Error error) {
+            GLib.warning (_("Failed to send notification: %s"), error.message);
+        }
+    }
+
+    static Canberra.Context sound_context = null;
+    public static void play_sound (string sound) {
+        if (sound_context == null)
+            Canberra.Context.create (out sound_context);
+        sound_context.play (0, Canberra.PROP_EVENT_ID, sound);
+    }
 }
 
diff --git a/postler/postler-bureau.vala b/postler/postler-bureau.vala
index 6ef4fa2..fcf8529 100644
--- a/postler/postler-bureau.vala
+++ b/postler/postler-bureau.vala
@@ -94,13 +94,11 @@ public class Postler.Bureau : Gtk.Window {
 
     private bool new_message_timer () {
         client.receive ();
-        folders.display_notify = true;
         return true;
     }
 
     void action_mail_receive () {
         client.receive ();
-        folders.display_notify = true;
     }
 
     void compose_message (string? prefix=null, string? recipient=null) {
diff --git a/postler/postler-folders.vala b/postler/postler-folders.vala
index b774a9f..9f13de4 100644
--- a/postler/postler-folders.vala
+++ b/postler/postler-folders.vala
@@ -15,7 +15,6 @@ public class Postler.Folders : Gtk.TreeView {
 
     public Postler.Messages messages { get; set; }
     public string? selected_location { get; private set; }
-    public bool display_notify { get; set; default = false; }
 
     public Postler.AccountInfo? get_selected_account () {
         return_val_if_fail (messages != null, null);
@@ -41,7 +40,6 @@ public class Postler.Folders : Gtk.TreeView {
 
     public Folders (Accounts accounts) {
         this.accounts = accounts;
-        Notify.init ("Postler");
         store = new Gtk.TreeStore (8,
             typeof (string), typeof (string), typeof (int), typeof (string),
             typeof (AccountInfo),
@@ -55,13 +53,6 @@ public class Postler.Folders : Gtk.TreeView {
         GLib.Idle.add (populate);
     }
 
-    static Canberra.Context sound_context = null;
-    void play_sound (string sound) {
-        if (sound_context == null)
-            Canberra.Context.create (out sound_context);
-        sound_context.play (0, Canberra.PROP_EVENT_ID, sound);
-    }
-
     void unread_monitor_changed (File msg_dir, string path, string account) {
         try {
             var msg_enumerator = msg_dir.enumerate_children ("", 0, null);
@@ -73,17 +64,6 @@ public class Postler.Folders : Gtk.TreeView {
             if (store.get_iter_from_string (out iter, path))
                 store.set (iter,
                     Columns.NAME, "%s (%d)".printf (account, unread));
-            if (unread > 0 && display_notify) {
-                var notification = (Notify.Notification)GLib.Object.new (
-                    typeof (Notify.Notification),
-                    "summary", GLib.Environment.get_application_name (),
-                    "body", ngettext ("You have %d message",
-                    "You have %d new messages", unread).printf (unread),
-                    "icon-name", STOCK_INTERNET_MAIL);
-                notification.show ();
-                play_sound ("message-new-email");
-                display_notify = false;
-            }
         } catch (GLib.Error error) {
             GLib.critical (_("Failed to monitor folder \"%s\": %s"),
                            msg_dir.get_path (), error.message);
diff --git a/postler/postler-service.vala b/postler/postler-service.vala
index 55cad78..65b1128 100644
--- a/postler/postler-service.vala
+++ b/postler/postler-service.vala
@@ -40,6 +40,12 @@ namespace Postler {
                     return false;
                 }
             }
+
+            /* FIXME: Determine the number of unread messages */
+            int unread = 0;
+            Postler.App.send_notification (ngettext ("You have %d message",
+                "You have %d new messages", unread).printf (unread));
+            Postler.App.play_sound ("message-new-email");
             return true;
         }
 



More information about the Xfce4-commits mailing list