[Xfce4-commits] <postler:master> Implement infobar in bureau for fetching errors

Christian Dywan noreply at xfce.org
Fri Feb 11 03:38:02 CET 2011


Updating branch refs/heads/master
         to d454447d43d983460f55b558fbf1f5b51554b314 (commit)
       from 80a0da4c5a10f5fdcac0b9e025dd4e0aa83d2d7f (commit)

commit d454447d43d983460f55b558fbf1f5b51554b314
Author: Christian Dywan <christian at twotoasts.de>
Date:   Thu Feb 10 23:41:08 2011 +0100

    Implement infobar in bureau for fetching errors
    
    The Progress method takes an account argument now and the
    HelperProcess keeps track of the name.
    
    Errors while fetching trigger fatal errors per account now,
    the infobars close when switching folders or fetching again.

 postler/postler-bureau.vala  |   46 +++++++++++++++++++++++++++++++++++++++--
 postler/postler-client.vala  |   22 ++++++++++++-------
 postler/postler-service.vala |   44 ++++++++++++++++++++++++---------------
 3 files changed, 84 insertions(+), 28 deletions(-)

diff --git a/postler/postler-bureau.vala b/postler/postler-bureau.vala
index 4208cdd..13c2961 100644
--- a/postler/postler-bureau.vala
+++ b/postler/postler-bureau.vala
@@ -23,6 +23,7 @@ public class Postler.Bureau : Gtk.Window {
     public Postler.Folders folders;
     Gtk.ProgressBar progressbar;
     Gtk.Label statuslabel;
+    Gtk.VBox messages_box;
     public Postler.Messages messages;
     Postler.Content content;
 
@@ -439,6 +440,37 @@ public class Postler.Bureau : Gtk.Window {
             }
     }
 
+    Gtk.InfoBar show_fetch_error_infobar (string account, string error_message) {
+        var infobar = new Gtk.InfoBar ();
+        infobar.set_message_type (Gtk.MessageType.ERROR);
+        messages_box.pack_start (infobar, false, false, 0);
+        var infobox = infobar.get_content_area () as Gtk.Box;
+        var image = new Gtk.Image.from_stock (Gtk.STOCK_DIALOG_ERROR,
+                                              Gtk.IconSize.BUTTON);
+        infobox.pack_start (image, false, false, 0);
+        var infolabel = new Gtk.Label (_("%s: %s").printf (
+                                       account, error_message));
+        infolabel.wrap = true;
+        var attrlist = new Pango.AttrList ();
+        attrlist.insert (Pango.attr_weight_new (Pango.Weight.BOLD));
+        infolabel.attributes = attrlist;
+        infobox.pack_start (infolabel, true, false, 0);
+        infobar.show_all ();
+
+        /* Infobar closes on button, folder change or fetching mail */
+        infobar.response.connect ((response) => {
+            infobar.destroy ();
+        });
+        messages.notify["selected-location"].connect ((object, pspec) => {
+            infobar.destroy ();
+        });
+        client.progress.connect ((account_name, text, fraction) => {
+            if (account == account_name && text != null && fraction == 0.0)
+                infobar.destroy ();
+        });
+        return infobar;
+    }
+
     public Bureau () {
         GLib.Object (icon_name: STOCK_INTERNET_MAIL,
                      title: GLib.Environment.get_application_name ());
@@ -524,6 +556,7 @@ public class Postler.Bureau : Gtk.Window {
         });
         toolbar.insert (toolitem, -1);
         shelf.pack_start (toolbar, false, false, 0);
+
         var hpaned = new Gtk.HPaned ();
         hpaned.name = "SidebarHandleLeft";
         folders = new Postler.Folders (accounts);
@@ -550,7 +583,7 @@ public class Postler.Bureau : Gtk.Window {
         hpaned.pack1 (panebox, false, false); /* don't expand, don't shrink */
         progressbar.set_no_show_all (true);
         statuslabel.set_no_show_all (true);
-        client.progress.connect ((text, fraction) => {
+        client.progress.connect ((account, text, fraction) => {
             if (text != null) {
                 statuslabel.label = text;
                 progressbar.fraction = fraction;
@@ -571,7 +604,7 @@ public class Postler.Bureau : Gtk.Window {
         shelf.pack_start (hpaned, true, true, 0);
         var vpaned = new Gtk.VPaned ();
         hpaned.pack2 (vpaned, true, false); /* do expand, don't shrink */
-        var messages_box = new Gtk.VBox (false, 0);
+        messages_box = new Gtk.VBox (false, 0);
         vpaned.pack1 (messages_box, false, false); /* no expand, no shrink */
         search_options = ui.get_widget ("/search_options") as Gtk.Toolbar;
         actions.get_action ("SearchSubject").is_important = true;
@@ -589,6 +622,13 @@ public class Postler.Bureau : Gtk.Window {
         }
         messages_box.pack_start (search_options, false, false, 0);
 
+        client.received.connect ((account, error_message) => {
+            if (error_message == null)
+                return;
+
+            var infobar = show_fetch_error_infobar (account, error_message);
+        });
+
         messages = new Postler.Messages (accounts);
         messages.set_size_request (250, 250);
         actions.get_action ("MessageFlag").sensitive = false;
@@ -626,7 +666,7 @@ public class Postler.Bureau : Gtk.Window {
             }
         });
         scrolled = new Postler.ScrolledWindow (messages);
-        messages_box.pack_start (scrolled, true, true, 0);
+        messages_box.pack_end (scrolled, true, true, 0);
 
         /* Welcome the new user with an account form embedded in the window */
         if (accounts.get_infos ().length () == 0) {
diff --git a/postler/postler-client.vala b/postler/postler-client.vala
index 77d7bb8..20f69da 100644
--- a/postler/postler-client.vala
+++ b/postler/postler-client.vala
@@ -13,8 +13,9 @@ namespace Postler {
 
     [DBus (name = "org.elementary.Postler")]
     interface PostlerClient : Object {
-        public signal void progress (string text, double fraction);
-        public abstract bool receive (string account) throws IOError;
+        public signal void progress (string account, string text, double fraction);
+        public abstract void receive (string account) throws IOError;
+        public signal void received (string account, string error_message);
         public abstract bool fetch (string account) throws IOError;
         public abstract void send (string account, string filename) throws IOError;
         public signal void sent (string account, string filename, string error_message);
@@ -29,8 +30,11 @@ namespace Postler {
                 client = Bus.get_proxy_sync (BusType.SESSION,
                                              "org.elementary.Postler",
                                              "/org/elementary/postler");
-                client.progress.connect ((text, fraction) => {
-                    progress (text != "" ? text : null, fraction);
+                client.progress.connect ((account, text, fraction) => {
+                    progress (account, text != "" ? text : null, fraction);
+                });
+                client.received.connect ((account, error_message) => {
+                    received (account, error_message != "" ? error_message : null);
                 });
                 client.sent.connect ((account, filename, error_message) => {
                     sent (account, filename, error_message != "" ? error_message : null);
@@ -43,16 +47,18 @@ namespace Postler {
             } catch (GLib.Error error) { }
         }
 
-        public signal void progress (string? text, double fraction);
+        public signal void progress (string account, string? text, double fraction);
 
-        public bool receive (string account="") {
+        public void receive (string account="") {
             try {
-                return client.receive (account);
+                client.receive (account);
             } catch (GLib.Error error) {
-                return false;
+                received (account, error.message);
             }
         }
 
+        public signal void received (string account, string? error_message);
+
         public bool fetch (string account="") {
             try {
                 return client.fetch (account);
diff --git a/postler/postler-service.vala b/postler/postler-service.vala
index 830a29b..6de7552 100644
--- a/postler/postler-service.vala
+++ b/postler/postler-service.vala
@@ -11,10 +11,15 @@
 
 namespace Postler {
     internal class HelperProcess {
+        internal string? display_name;
         string? command = null;
         IOChannel inputc;
         IOChannel errorc;
 
+        internal HelperProcess (string? display_name=null) {
+            this.display_name = display_name;
+        }
+
         internal void execute (string command) {
             this.command = command;
 
@@ -162,7 +167,7 @@ namespace Postler {
         }
 #endif
 
-        void display_status (string msg) {
+        void display_status (string account, string msg) {
             if (msg.contains ("master: ")) {
                 total = (msg.split (" ") [1]).to_double ();
             }
@@ -180,7 +185,7 @@ namespace Postler {
                     folder = folder.split ("/") [1];
                 string state = _("Fetching %d of %d").printf ((int)count, (int)total);
                 folder = Postler.Folders.decode_foldername (folder);
-                progress (folder + "\n" + state,
+                progress (account, folder + "\n" + state,
                           total > count ? count / total : 0);
             }
             else if (!(msg.contains ("Synchronizing")) ) {
@@ -191,9 +196,9 @@ namespace Postler {
             }
         }
 
-        public signal void progress (string text, double fraction);
+        public signal void progress (string account, string text, double fraction);
 
-        public bool receive (string account) {
+        public void receive (string account) {
             var infos = new GLib.List<AccountInfo> ();
             var accounts = new Accounts ();
             if (account == "") {
@@ -209,24 +214,27 @@ namespace Postler {
                 }
             }
 
-            if (infos.length () == 0)
-                return false;
+            if (infos.length () == 0) {
+                received (account, _("The account doesn't exist"));
+                return;
+            }
 
             unread = 0;
             foreach (var info in infos) {
                 try {
-                    progress (_("Fetching..."), 0.0);
+                    progress (info.display_name, _("Fetching..."), 0.0);
                     string command = accounts.get_receive_command (info);
-                    var helper = new HelperProcess ();
-                    helper.line_read.connect ((line) => {
+                    var helper = new HelperProcess (info.display_name);
+                    helper.line_read.connect ((line, is_error) => {
                         /* FIXME: the status itself isn't updated - escape chars? */
-                        display_status (line.split ("\n") [0]);
+                        display_status (helper.display_name, line.split ("\n") [0]);
+                        if (is_error)
+                            helper.finnish (line);
                     });
-                    helper.done.connect ((error_message) => {
-                        progress ("", 0.0);
-                        /* FIXME: Handle error_message */
+                    helper.done.connect ((helper, error_message) => {
+                        progress (helper.display_name, "", 0.0);
                         if (error_message != "") {
-                            GLib.critical (error_message);
+                            received (helper.display_name, error_message);
                             return;
                         }
                         GLib.debug ("Done: %d new messages", unread);
@@ -236,16 +244,18 @@ namespace Postler {
                                 "You have %d new messages", unread).printf (unread));
                             Postler.App.play_sound ("message-new-email");
                         }
+                        received (helper.display_name, "");
                     });
                     helper.execute (command);
                 } catch (Error error) {
-                    return false;
+                    received (info.display_name, error.message);
+                    return;
                 }
             }
-
-            return true;
         }
 
+        public signal void received (string account, string error_message);
+
         public bool fetch (string account) {
             var infos = new GLib.List<AccountInfo> ();
             var accounts = new Accounts ();



More information about the Xfce4-commits mailing list