Skip to content

Commit

Permalink
fix(attachments): audio thumbnail icon (#873)
Browse files Browse the repository at this point in the history
fix(Box): memory leak
  • Loading branch information
GeopJr committed Mar 24, 2024
1 parent 8ce515d commit 9652b28
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/Widgets/Attachment/Box.vala
Expand Up @@ -122,7 +122,7 @@ public class Tuba.Widgets.Attachment.Box : Adw.Bin {
widget.height_request = 334;
}

((Widgets.Attachment.Image) widget).on_any_attachment_click.connect (() => open_all_attachments (item.url));
((Widgets.Attachment.Image) widget).on_any_attachment_click.connect (open_all_attachments);
} catch (Oopsie e) {
warning (@"Error updating attachments: $(e.message)");
}
Expand Down
21 changes: 20 additions & 1 deletion src/Widgets/Attachment/Image.vala
Expand Up @@ -43,11 +43,15 @@ public class Tuba.Widgets.Attachment.Image : Widgets.Attachment.Item {
}

protected Gtk.Image? media_icon = null;
ulong pic_paintable_id = 0;
protected override void on_rebind () {
base.on_rebind ();
pic.alternative_text = entity == null ? null : entity.description;

Tuba.Helper.Image.request_paintable (entity.preview_url, entity.blurhash, on_cache_response);
if (pic_paintable_id != 0) {
pic.disconnect (pic_paintable_id);
pic_paintable_id = 0;
}

if (media_kind.is_video ()) {
media_icon = new Gtk.Image () {
Expand All @@ -59,6 +63,7 @@ public class Tuba.Widgets.Attachment.Image : Widgets.Attachment.Item {
media_icon.css_classes = { "osd", "circular", "attachment-overlay-icon" };
media_icon.icon_name = "media-playback-start-symbolic";
} else {
pic_paintable_id = pic.notify["paintable"].connect (on_audio_paintable_notify);
media_icon.icon_name = "tuba-music-note-symbolic";
}

Expand All @@ -68,9 +73,23 @@ public class Tuba.Widgets.Attachment.Image : Widgets.Attachment.Item {
media_icon.icon_size = Gtk.IconSize.LARGE;
}

Tuba.Helper.Image.request_paintable (entity.preview_url, entity.blurhash, on_cache_response);
copy_media_simple_action.set_enabled (media_kind.can_copy ());
}

private void on_audio_paintable_notify () {
if (media_icon == null) return;

// toggle icon size so it applies
media_icon.icon_size = Gtk.IconSize.NORMAL;
if (pic.paintable == null) {
media_icon.css_classes = {};
} else {
media_icon.css_classes = { "osd", "circular", "attachment-overlay-icon" };
}
media_icon.icon_size = Gtk.IconSize.LARGE;
}

protected override void copy_media () {
debug ("Begin copy-media action");
Host.download.begin (entity.url, (obj, res) => {
Expand Down

0 comments on commit 9652b28

Please sign in to comment.