Changes
4 changed files (+73/-26)
-
-
@@ -107,6 +107,7 @@ // Neither GTK4 nor Libadwaita provides SVG rendering. We need to use librsvg for// that purpose, whilst undocumented. "librsvg-2.0", "gee-0.8", "libsoup-3.0", }; // A directory containing C source files compiled from Vala source code.
-
-
-
@@ -24,6 +24,7 @@ lib,libjpeg, libadwaita, librsvg, libsoup_3, libgee, vala, coreutils,
-
@@ -96,6 +97,11 @@ # Necessary library to use collection types such as HashMap and ArrayList in Vala.# https://wiki.gnome.org/Projects/Libgee # https://valadoc.org/gee-0.8/index.htm libgee # > HTTP client/server library for GNOME # https://gitlab.gnome.org/GNOME/libsoup # https://valadoc.org/libsoup-3.0/index.htm libsoup_3 # This helper takes care of GLib/GTK's messy runtime things. # https://nixos.org/manual/nixpkgs/stable/#sec-language-gnome
-
-
-
@@ -250,5 +250,9 @@yield; return (owned) result; } public string? get_image_url(string image_key, Image.GetOptions options) { return conn.get_image_url(image_key, options); } } }
-
-
-
@@ -15,7 +15,27 @@ //// SPDX-License-Identifier: Apache-2.0 namespace PlacGtkAdwaita { [SingleInstance] private class ArtworkDownloader : Object { public Soup.Session session = new Soup.Session.with_options( "max_conns", 6, "max_conns_per_host", 6, "user_agent", "plac-for-gtk4/0.0 " ); // This class does not use Soup's cache feature: it's undocumented, // obscure usage (due both to API design and lack of documentation,) // and frequently crashes. As Roon Server seems to handle our current // request size/window/rate, this class avoids dealing with libsoup's // cache. public ArtworkDownloader() { Object(); } } class Artwork : Gtk.Box { private ArtworkDownloader downloader = new ArtworkDownloader(); private uint16 _width = 100; public uint16 width { get { return _width; }
-
@@ -113,37 +133,53 @@ var opts = new Plac.Image.GetOptions();opts.set_size(scaling, _width, _height); opts.set_content_type(JPEG); _conn.get_image.begin(_image_key, opts, (obj, res) => { var result = _conn.get_image.end(res); if (result == null) { GLib.log("Plac", LEVEL_WARNING, "Failed to download image: Out of memory"); error_icon.visible = true; spinner.visible = false; return; } GLib.Uri url; try { var raw = _conn.get_image_url(_image_key, opts); if (raw == null) { GLib.log("Plac", LEVEL_WARNING, "Failed to build image download URL for %s", _image_key); error_icon.visible = true; spinner.visible = false; return; } if (result.code != OK) { GLib.log("Plac", LEVEL_WARNING, "Failed to download image: %s", result.code.to_string()); error_icon.visible = true; spinner.visible = false; return; } url = GLib.Uri.parse(raw, NONE); } catch (GLib.UriError error) { GLib.log("Plac", LEVEL_WARNING, "Failed to build image download URL for %s: %s", _image_key, error.message); error_icon.visible = true; spinner.visible = false; return; } if (result.image == null) { GLib.log("Plac", LEVEL_WARNING, "Failed to download image: image_field_missing"); error_icon.visible = true; spinner.visible = false; return; } var msg = new Soup.Message.from_uri("GET", url); var bytes = GLib.Bytes.new_with_owner(result.image.data, result.image); downloader.session.send_and_read_async.begin(msg, 0, null, (obj, res) => { try { var texture = Gdk.Texture.from_bytes(bytes); picture.paintable = texture; spinner.visible = false; picture.visible = true; var bytes = downloader.session.send_and_read_async.end(res); // We don't cache, so 3xx response is error here if (msg.status_code != 200) { GLib.log("Plac", LEVEL_WARNING, "Failed to download artwork: HTTP %u (key=%s)", msg.status_code, _image_key); error_icon.visible = true; spinner.visible = false; return; } try { var texture = Gdk.Texture.from_bytes(bytes); picture.paintable = texture; spinner.visible = false; picture.visible = true; } catch (GLib.Error error) { GLib.log("Plac", LEVEL_WARNING, "Failed to generate artwork texture: %s", error.message); error_icon.visible = true; spinner.visible = false; } } catch (GLib.Error error) { GLib.log("Plac", LEVEL_WARNING, "Failed to generate artwork texture: %s", error.message); GLib.log("Plac", LEVEL_WARNING, "Failed to download image: %s", error.message); error_icon.visible = true; spinner.visible = false; return; } }); }
-