diff options
author | Christian Dywan <christian@twotoasts.de> | 2018-07-30 16:04:46 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-07-30 16:04:46 +0200 |
commit | 98394f10547645b007adb747102362ab8a78f908 (patch) | |
tree | 31a036b203b51184816821fab42d08819c3546f0 | |
parent | c6c16506a3fe4aab4a77515c7ef8c1bbab29269d (diff) | |
download | midori-git-98394f10547645b007adb747102362ab8a78f908.tar.gz |
Handle opening, cancelling and failing of downloads (#3)
Cancel cancels a download, Open opens the file, and an error icon is shown if something went wrong.
![screenshot from 2018-07-25 16-59-22](https://user-images.githubusercontent.com/1204189/43209127-36d4314a-902c-11e8-98e8-42a07f48d575.png)
-rw-r--r-- | core/download-button.vala | 39 | ||||
-rw-r--r-- | ui/download-row.ui | 24 |
2 files changed, 61 insertions, 2 deletions
diff --git a/core/download-button.vala b/core/download-button.vala index 215e5885..b0b6083d 100644 --- a/core/download-button.vala +++ b/core/download-button.vala @@ -63,6 +63,7 @@ namespace Midori { public double progress { get; protected set; default = 0.0; } public WebKit.Download? download { get; protected set; default = null; } public bool loading { get; protected set; default = false; } + public bool failed { get; protected set; default = false; } public void cancel () { if (download != null) { download.cancel (); @@ -91,6 +92,14 @@ namespace Midori { Object (download: download, loading: true); download.bind_property ("destination", this, "filename"); download.bind_property ("estimated-progress", this, "progress"); + download.finished.connect (() => { + download = null; + loading = false; + }); + download.failed.connect ((error) => { + loading = false; + failed = true; + }); } } @@ -106,6 +115,23 @@ namespace Midori { public Gtk.ProgressBar progress; [GtkChild] public Gtk.Button cancel; + [GtkChild] + public Gtk.Button open; + [GtkChild] + public Gtk.Image error; + + construct { + cancel.clicked.connect (() => { + item.cancel (); + }); + open.clicked.connect (() => { + try { + Gtk.show_uri (get_screen (), item.filename, Gtk.get_current_event_time ()); + } catch (Error error) { + critical ("Failed to open %s: %s", item.filename, error.message); + } + }); + } public DownloadRow (DownloadItem item) { Object (item: item); @@ -115,8 +141,19 @@ namespace Midori { item.bind_property ("basename", filename, "label"); progress.fraction = item.progress; item.bind_property ("progress", progress, "fraction"); + progress.visible = item.loading; + cancel.visible = item.loading; + open.visible = !item.loading && !item.failed; + item.notify["loading"].connect (update_buttons); + item.notify["failed"].connect (update_buttons); + error.visible = item.failed; + item.bind_property ("failed", error, "visible"); + } + + void update_buttons (ParamSpec pspec) { + progress.visible = item.loading; cancel.visible = item.loading; - item.bind_property ("loading", cancel, "visible"); + open.visible = !item.loading && !item.failed; } } } diff --git a/ui/download-row.ui b/ui/download-row.ui index 5bb04876..733527de 100644 --- a/ui/download-row.ui +++ b/ui/download-row.ui @@ -63,7 +63,29 @@ </child> </object> </child> - </object> + <child> + <object class="GtkButton" id="open"> + <property name="focus-on-click">no</property> + <property name="relief">none</property> + <property name="valign">center</property> + <property name="visible">no</property> + <child> + <object class="GtkImage"> + <property name="icon-name">document-open-symbolic</property> + <property name="use-fallback">yes</property> + <property name="visible">yes</property> + </object> + </child> + </object> + </child> + <child> + <object class="GtkImage" id="error"> + <property name="icon-name">error-symbolic</property> + <property name="use-fallback">yes</property> + <property name="visible">no</property> + </object> + </child> + </object> </child> </template> </interface> |