This commit is contained in:
Bleak Grey 2020-11-19 12:46:18 +03:00
parent 577f0c1b68
commit bc5a4a53fe
4 changed files with 80 additions and 34 deletions

View File

@ -0,0 +1,50 @@
<?xml version="1.0" encoding="UTF-8"?>
<!-- Generated with glade 3.22.2 -->
<interface>
<requires lib="gtk+" version="3.22"/>
<template class="TootleViewsTimelineFooter" parent="GtkListBoxRow">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="activatable">False</property>
<property name="selectable">False</property>
<child>
<object class="GtkRevealer" id="revealer">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="reveal_child">True</property>
<child>
<object class="GtkStack" id="stack">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="margin_left">8</property>
<property name="margin_right">8</property>
<property name="margin_top">8</property>
<property name="margin_bottom">8</property>
<property name="transition_duration">100</property>
<property name="transition_type">crossfade</property>
<child>
<object class="GtkLabel">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="label">Label</property>
<property name="single_line_mode">True</property>
</object>
</child>
<child>
<object class="GtkSpinner">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="active">True</property>
</object>
<packing>
<property name="name">page0</property>
<property name="title" translatable="yes">page0</property>
<property name="position">1</property>
</packing>
</child>
</object>
</child>
</object>
</child>
</template>
</interface>

View File

@ -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") {

View File

@ -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 ();
}

View File

@ -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]