[Xfce4-commits] <postler:master> Track unread messages and notify when account done

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


Updating branch refs/heads/master
         to d9f2232913e720fb179da5d724dd07efccec7f33 (commit)
       from 7b34cb0cfe9dde04b0f73053175bf3b07b1792e7 (commit)

commit d9f2232913e720fb179da5d724dd07efccec7f33
Author: Christian Dywan <christian at twotoasts.de>
Date:   Mon Dec 13 01:18:22 2010 +0100

    Track unread messages and notify when account done

 postler/postler-service.vala |   22 ++++++++++++++++------
 1 files changed, 16 insertions(+), 6 deletions(-)

diff --git a/postler/postler-service.vala b/postler/postler-service.vala
index 7182882..aa99381 100644
--- a/postler/postler-service.vala
+++ b/postler/postler-service.vala
@@ -14,6 +14,7 @@ namespace Postler {
     [DBus (name = "org.elementary.Postler")]
     class PostlerService : Object {
         double total = 0;
+        int unread = 0;
         string folder = "";
 
         bool execute_command_with_status (string command) {
@@ -26,6 +27,7 @@ namespace Postler {
                     null, out pid, null, out out_fd, null);
                 IOChannel ioc = new IOChannel.unix_new (out_fd);
                 ioc.add_watch (IOCondition.IN, mbsync_input);
+                ioc.add_watch (IOCondition.HUP, mbsync_done);
             }
             catch (GLib.Error error) {
                 var error_dialog = new Gtk.MessageDialog (null, 0,
@@ -62,12 +64,24 @@ namespace Postler {
             return true;
         }
 
+        bool mbsync_done (IOChannel gio, IOCondition condition) {
+            GLib.debug ("Done: %d new messages", unread);
+            if (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 false;
+        }
+
         void display_status (string msg) {
             if (msg.contains ("master: ")) {
                 total = (msg.split (" ") [1]).to_double ();
             }
             else if (msg.contains ("slave: ")) {
-                total = total - (msg.split (" ") [1]).to_double ();
+                string[] pieces = msg.split (" ");
+                total = total - pieces[1].to_double ();
+                unread += pieces[3].to_int ();
             }
             else if (msg.contains ("S: ?")) {
                 double count = (((msg.split ("/"))[2]).split (" ") [0]).to_double ();
@@ -108,6 +122,7 @@ namespace Postler {
             if (infos.length () == 0)
                 return false;
 
+            unread = 0;
             foreach (var info in infos) {
                 try {
                     string command = accounts.get_receive_command (info);
@@ -117,11 +132,6 @@ namespace Postler {
                 }
             }
 
-            /* 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