diff options
author | gue5t <gue5t@midori.launchpad> | 2014-04-23 00:40:37 -0500 |
---|---|---|
committer | gue5t <gue5t@midori.launchpad> | 2014-04-23 00:40:37 -0500 |
commit | 2f171c30b29690cc10be69ffc0e89a46a11a3afb (patch) | |
tree | 96e23b2ac91ef92210af485f55bbd35f2f5ece2c | |
parent | 5718ffcb0b6d4e3d4c8f7a319e77e2d308eac56c (diff) | |
download | midori-2f171c30b29690cc10be69ffc0e89a46a11a3afb.tar.gz |
Use a real frame timer instead of connecting to download progress and rename get_tooltip to reflect its function
-rw-r--r-- | extensions/transfers.vala | 50 | ||||
-rw-r--r-- | midori/midori-download.vala | 2 | ||||
-rw-r--r-- | tests/download.vala | 4 |
3 files changed, 27 insertions, 29 deletions
diff --git a/extensions/transfers.vala b/extensions/transfers.vala index e9697214..098c355e 100644 --- a/extensions/transfers.vala +++ b/extensions/transfers.vala @@ -19,9 +19,14 @@ namespace Sokoke { namespace Transfers { private class Transfer : GLib.Object { + internal uint poll_source = 0; internal WebKit.Download download; - internal signal void changed (); + internal virtual signal void changed () + { + string tooltip = Midori.Download.calculate_tooltip (download); + this.set_data ("tooltip", tooltip); + } internal signal void remove (); internal signal void removed (); @@ -50,27 +55,35 @@ namespace Transfers { #endif internal Transfer (WebKit.Download download) { + poll_source = Timeout.add(1000/10, () => { + changed (); + return true; + }); this.download = download; #if HAVE_WEBKIT2 - download.notify["estimated-progress"].connect (transfer_changed); download.finished.connect (() => { succeeded = finished = true; changed (); + Source.remove (poll_source); + poll_source = 0; }); download.failed.connect (() => { succeeded = false; finished = true; changed (); + Source.remove (poll_source); + poll_source = 0; }); #else - download.notify["status"].connect (transfer_changed); - download.notify["progress"].connect (transfer_changed); + download.notify["status"].connect (() => { + changed (); + if (download.status == WebKit.DownloadStatus.FINISHED || download.status == WebKit.DownloadStatus.ERROR) { + Source.remove (poll_source); + poll_source = 0; + } + }); #endif } - - void transfer_changed (GLib.ParamSpec pspec) { - changed (); - } } static bool pending_transfers (Katze.Array array) { @@ -85,7 +98,7 @@ namespace Transfers { private class Sidebar : Gtk.VBox, Midori.Viewable { Gtk.Toolbar? toolbar = null; Gtk.ToolButton clear; - Gtk.ListStore store = new Gtk.ListStore (2, typeof (Transfer), typeof (string)); + Gtk.ListStore store = new Gtk.ListStore (1, typeof (Transfer)); Gtk.TreeView treeview; Katze.Array array; @@ -241,19 +254,6 @@ namespace Transfers { } void transfer_changed (GLib.Object item) { - var transfer = item as Transfer; - Gtk.TreeIter iter; - if (store.iter_children (out iter, null)) { - do { - Transfer at; - store.get (iter, 0, out at); - if (transfer == at) { - string tooltip = Midori.Download.get_tooltip (transfer.download); - store.set (iter, 1, tooltip); - break; - } - } while (store.iter_next (ref iter)); - } treeview.queue_draw (); } @@ -301,10 +301,8 @@ namespace Transfers { Gtk.TreeModel model, Gtk.TreeIter iter) { Transfer transfer; - string tooltip; model.get (iter, 0, out transfer); - model.get (iter, 1, out tooltip); - renderer.set ("text", tooltip, + renderer.set ("text", transfer.get_data<string>("tooltip") ?? "", "value", (int)(transfer.progress * 100)); } @@ -369,7 +367,7 @@ namespace Transfers { void transfer_changed () { progress.fraction = Midori.Download.get_progress (transfer.download); - progress.tooltip_text = Midori.Download.get_tooltip (transfer.download); + progress.tooltip_text = transfer.get_data<string>("tooltip") ?? ""; string stock_id = Midori.Download.action_stock_id (transfer.download); icon.set_from_stock (stock_id, Gtk.IconSize.MENU); } diff --git a/midori/midori-download.vala b/midori/midori-download.vala index 2213cec9..ed14e427 100644 --- a/midori/midori-download.vala +++ b/midori/midori-download.vala @@ -51,7 +51,7 @@ namespace Midori { #endif } - public static string get_tooltip (WebKit.Download download) { + public static string calculate_tooltip (WebKit.Download download) { #if !HAVE_WEBKIT2 string filename = Midori.Download.get_basename_for_display (download.destination_uri); /* i18n: Download tooltip (size): 4KB of 43MB */ diff --git a/tests/download.vala b/tests/download.vala index a5b4dcfd..a3dc561a 100644 --- a/tests/download.vala +++ b/tests/download.vala @@ -110,12 +110,12 @@ void download_properties () { download.destination_uri = uri; download.start (); #endif - string tee = Midori.Download.get_tooltip (download); + string tee = Midori.Download.calculate_tooltip (download); assert (tee.contains (Path.get_basename (filename))); assert (Midori.Download.get_progress (download) == 0.0); download.notify["progress"].connect ((pspec) => { - string tee2 = Midori.Download.get_tooltip (download); + string tee2 = Midori.Download.calculate_tooltip (download); assert (tee2.contains (Path.get_basename (filename))); }); var loop = MainContext.default (); |