2020-07-10 16:30:57 +02:00
|
|
|
using Gtk;
|
|
|
|
using Gdk;
|
|
|
|
|
|
|
|
[GtkTemplate (ui = "/com/github/bleakgrey/tootle/ui/widgets/attachment_slot.ui")]
|
|
|
|
public class Tootle.Widgets.Attachment.Slot : FlowBoxChild {
|
|
|
|
|
2020-10-24 05:42:24 +02:00
|
|
|
[GtkChild] Button button;
|
|
|
|
[GtkChild] Label chip;
|
|
|
|
[GtkChild] Image play_icon;
|
|
|
|
[GtkChild] Stack stack;
|
2020-07-10 16:30:57 +02:00
|
|
|
|
|
|
|
public API.Attachment attachment { get; construct set; }
|
|
|
|
|
|
|
|
public Slot (API.Attachment obj) {
|
|
|
|
Object (attachment: obj);
|
|
|
|
|
|
|
|
if (attachment.preview_url != null) {
|
|
|
|
var img = new Widgets.Attachment.Picture (attachment.preview_url);
|
|
|
|
img.notify["visible"].connect (() => {
|
|
|
|
stack.visible_child_name = img.visible ? "content" : "loading";
|
|
|
|
});
|
|
|
|
stack.add_named (img, "content");
|
|
|
|
img.on_request ();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (attachment.kind != "image") {
|
|
|
|
chip.label = attachment.kind;
|
|
|
|
chip.show ();
|
|
|
|
}
|
|
|
|
|
|
|
|
switch (attachment.kind) {
|
|
|
|
case "audio":
|
|
|
|
case "video":
|
|
|
|
case "gifv":
|
|
|
|
play_icon.show ();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
construct {
|
2020-10-24 05:42:24 +02:00
|
|
|
button.tooltip_text = attachment.description;
|
2020-07-10 16:30:57 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void download () {
|
|
|
|
Desktop.download (attachment.url, path => {
|
2020-08-01 19:56:12 +02:00
|
|
|
app.toast (_("File saved to Downloads"));
|
|
|
|
},
|
|
|
|
() => {});
|
2020-07-10 16:30:57 +02:00
|
|
|
}
|
2020-08-01 19:56:12 +02:00
|
|
|
|
2020-07-10 16:30:57 +02:00
|
|
|
void open () {
|
|
|
|
Desktop.download (attachment.url, path => {
|
|
|
|
Desktop.open_uri (path);
|
2020-08-01 19:56:12 +02:00
|
|
|
},
|
|
|
|
() => {});
|
2020-07-10 16:30:57 +02:00
|
|
|
}
|
|
|
|
|
2020-10-24 05:42:24 +02:00
|
|
|
[GtkCallback]
|
|
|
|
protected virtual void on_clicked () {
|
2020-07-10 16:30:57 +02:00
|
|
|
open ();
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|