diff --git a/data/ui/widgets/timeline_footer.ui b/data/ui/widgets/timeline_footer.ui new file mode 100644 index 0000000..d247101 --- /dev/null +++ b/data/ui/widgets/timeline_footer.ui @@ -0,0 +1,50 @@ + + + + + + diff --git a/src/Desktop.vala b/src/Desktop.vala index f80392c..d4135fa 100644 --- a/src/Desktop.vala +++ b/src/Desktop.vala @@ -38,8 +38,7 @@ public class Tootle.Desktop { } // Download a file from the web to a user's configured Downloads folder - public delegate void DownloadCallback (string path); - public static void download (string url, owned DownloadCallback cb, owned Network.ErrorCallback ecb) { + public async static string download (string url) throws Error { message (@"Downloading file: $url..."); var file_name = Path.get_basename (url); @@ -56,29 +55,26 @@ public class Tootle.Desktop { dir_path, str_hash (dir_name).to_string () + file_name); - new Request.GET (url) - .then ((sess, msg) => { - try { - var dir = File.new_for_path (dir_path); - if (!dir.query_exists ()) - dir.make_directory (); + var dir = File.new_for_path (dir_path); + if (!dir.query_exists ()) + dir.make_directory_with_parents (); - var file = File.new_for_path (file_path); - if (!file.query_exists ()) { - var data = msg.response_body.data; - FileOutputStream stream = file.create (FileCreateFlags.PRIVATE); - stream.write (data); - } - message (@"OK: File written to: $file_path"); - cb (file_path); + var file = File.new_for_path (file_path); - } catch (Error e) { - warning ("Error: %s\n", e.message); - ecb (0, e.message); - } - }) - .on_error ((owned) ecb) - .exec (); + if (!file.query_exists ()) { + var msg = yield new Request.GET (url) + .await (); + + var data = msg.response_body.data; + FileOutputStream stream = file.create (FileCreateFlags.PRIVATE); + stream.write (data); + + message (@"OK: File written to: $file_path"); + } + else + message ("OK: File exists already"); + + return file_path; } public static string fallback_icon (string normal, string fallback, string fallback2 = "broken") { diff --git a/src/Views/Timeline.vala b/src/Views/Timeline.vala index 96f4f9c..339c97c 100644 --- a/src/Views/Timeline.vala +++ b/src/Views/Timeline.vala @@ -51,6 +51,7 @@ public class Tootle.Views.Timeline : IAccountListener, IStreamListener, Views.Ba this.page_prev = null; this.page_next = null; this.is_last_page = false; + this.needs_attention = false; base.clear (); } diff --git a/src/Widgets/Attachment/Slot.vala b/src/Widgets/Attachment/Slot.vala index 857ab6b..f28a5fe 100644 --- a/src/Widgets/Attachment/Slot.vala +++ b/src/Widgets/Attachment/Slot.vala @@ -41,18 +41,17 @@ public class Tootle.Widgets.Attachment.Slot : FlowBoxChild { button.tooltip_text = attachment.description; } - void download () { - Desktop.download (attachment.url, path => { - app.toast (_("File saved to Downloads")); - }, - () => {}); - } - void open () { - Desktop.download (attachment.url, path => { - Desktop.open_uri (path); - }, - () => {}); + Desktop.download.begin (attachment.url, (obj, res) => { + try { + var path = Desktop.download.end (res); + Desktop.open_uri (path); + } + catch (Error e) { + app.error (_("Error"), e.message); + warning ("!!!" + e.message); + } + }); } [GtkCallback]