[Xfce4-commits] <postler:master> Show progressbar and text while retreiving mail
Christian Dywan
noreply at xfce.org
Mon Dec 13 04:28:06 CET 2010
Updating branch refs/heads/master
to 7b34cb0cfe9dde04b0f73053175bf3b07b1792e7 (commit)
from 37240b2c09c2fd2fbce94b3625e6baee28eb0242 (commit)
commit 7b34cb0cfe9dde04b0f73053175bf3b07b1792e7
Author: Bernd Prünster <bernd.pruenster at gmail.com>
Date: Mon Dec 13 00:05:17 2010 +0100
Show progressbar and text while retreiving mail
postler/postler-bureau.vala | 27 ++++++++++++++-
postler/postler-service.vala | 76 +++++++++++++++++++++++++++++++++++++++++-
2 files changed, 101 insertions(+), 2 deletions(-)
diff --git a/postler/postler-bureau.vala b/postler/postler-bureau.vala
index fcf8529..d2efb55 100644
--- a/postler/postler-bureau.vala
+++ b/postler/postler-bureau.vala
@@ -21,6 +21,8 @@ public class Postler.Bureau : Gtk.Window {
Gtk.Entry search;
Gtk.Toolbar search_options;
Postler.Folders folders;
+ Gtk.ProgressBar progressbar;
+ Gtk.Label statuslabel;
public Postler.Messages messages;
Postler.Content content;
@@ -524,8 +526,31 @@ public class Postler.Bureau : Gtk.Window {
folders.notify["selected-location"].connect ((object, pspec) => {
search.sensitive = folders.selected_location != null;
});
+ var folderbox = new Gtk.HBox (false, 4);
var scrolled = new Postler.ScrolledWindow (folders);
- hpaned.pack1 (scrolled, false, false); /* don't expand, don't shrink */
+ folderbox.pack_start (scrolled, true, true, 0);
+
+ progressbar = new Gtk.ProgressBar ();
+ statuslabel = new Gtk.Label ("");
+ var panebox = new Gtk.VBox (false, 0);
+ panebox.pack_start (folderbox, true, true, 0);
+ panebox.pack_end (progressbar, false, false, 0);
+ panebox.pack_end (statuslabel, false, false, 0);
+ 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) => {
+ if (text != null) {
+ statuslabel.label = text;
+ progressbar.fraction = fraction;
+ statuslabel.show ();
+ progressbar.show ();
+ } else {
+ statuslabel.hide ();
+ progressbar.hide ();
+ }
+ });
+
shelf.pack_start (hpaned, true, true, 0);
var vpaned = new Gtk.VPaned ();
hpaned.pack2 (vpaned, true, false); /* do expand, don't shrink */
diff --git a/postler/postler-service.vala b/postler/postler-service.vala
index 8b9c2d5..7182882 100644
--- a/postler/postler-service.vala
+++ b/postler/postler-service.vala
@@ -13,6 +13,80 @@ namespace Postler {
[DBus (name = "org.elementary.Postler")]
class PostlerService : Object {
+ double total = 0;
+ string folder = "";
+
+ bool execute_command_with_status (string command) {
+ try {
+ Pid pid;
+ int out_fd;
+ Process.spawn_async_with_pipes (null, command.split (" "), null,
+ SpawnFlags.LEAVE_DESCRIPTORS_OPEN
+ | SpawnFlags.SEARCH_PATH,
+ null, out pid, null, out out_fd, null);
+ IOChannel ioc = new IOChannel.unix_new (out_fd);
+ ioc.add_watch (IOCondition.IN, mbsync_input);
+ }
+ catch (GLib.Error error) {
+ var error_dialog = new Gtk.MessageDialog (null, 0,
+ Gtk.MessageType.ERROR, Gtk.ButtonsType.OK,
+ _("Failed to execute external command."));
+ error_dialog.format_secondary_text (error.message);
+ error_dialog.response.connect ((dialog, response) => {
+ dialog.destroy ();
+ });
+ error_dialog.show ();
+ }
+ return true;
+ }
+
+ bool mbsync_input (IOChannel gio, IOCondition condition) {
+ IOStatus ret;
+ StringBuilder msg = new StringBuilder ();
+ size_t len;
+
+ if ((condition & IOCondition.HUP) == IOCondition.HUP)
+ GLib.warning ("Read end of pipe died!");
+
+ try {
+ ret = gio.read_line_string (msg, out len);
+ }
+ catch (Error error) {
+ GLib.warning ("Error reading: %s", error.message);
+ }
+ GLib.debug ("Read %u bytes: %s", (uint)len, msg.str);
+
+ /* FIXME: for whatever reason the satus itself is not updated
+ * in the label... escape chars, anyone?*/
+ display_status (msg.str.split ("\n") [0]);
+ return true;
+ }
+
+ 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 ();
+ }
+ else if (msg.contains ("S: ?")) {
+ double count = (((msg.split ("/"))[2]).split (" ") [0]).to_double ();
+ if (folder.contains ("/"))
+ folder = folder.split ("/") [1];
+ string state = _("Retrieving %d/%d").printf (count, total);
+ progress (folder + "\n" + state,
+ total > count ? count / total : 0);
+ }
+ else if (!(msg.contains ("Synchronizing")) ) {
+ if (msg.contains ("Selecting master ")) {
+ var tmp = msg.replace ("Selecting master ", "");
+ folder = tmp.replace ("...", "");
+ }
+ } else {
+ progress ("", 0.0);
+ }
+ }
+
public signal void progress (string text, double fraction);
public bool receive (string account) {
@@ -37,7 +111,7 @@ namespace Postler {
foreach (var info in infos) {
try {
string command = accounts.get_receive_command (info);
- Postler.App.execute_command (command);
+ execute_command_with_status (command);
} catch (Error error) {
return false;
}
More information about the Xfce4-commits
mailing list