From 77995667585ecf1bd0b3fbe7852e74b50ea64509 Mon Sep 17 00:00:00 2001 From: Erica Z Date: Mon, 28 Oct 2024 10:26:12 +0100 Subject: [PATCH] expose play queue length as playbin property --- src/playbin.vala | 9 ++++++--- src/ui/play_queue.blp | 3 +-- src/ui/playbar.blp | 3 +-- 3 files changed, 8 insertions(+), 7 deletions(-) diff --git a/src/playbin.vala b/src/playbin.vala index a9baf39..296394b 100644 --- a/src/playbin.vala +++ b/src/playbin.vala @@ -54,8 +54,9 @@ public class Playbin : GLib.Object { public weak Subsonic.Client api { get; set; default = null; } - public ListStore _play_queue; + private ListStore _play_queue = new ListStore (typeof (Subsonic.Song)); public ListModel play_queue { get { return this._play_queue; } } + public uint play_queue_length { get; private set; default = 0; } // try to prevent wait_event to be called twice private bool is_handling_event = false; @@ -71,8 +72,6 @@ public class Playbin : GLib.Object { } public Playbin () { - this._play_queue = new ListStore (typeof (Subsonic.Song)); - assert (this.mpv.initialize () >= 0); assert (this.mpv.set_property_string ("audio-client-name", "audrey") >= 0); assert (this.mpv.set_property_string ("user-agent", Audrey.Const.user_agent) >= 0); @@ -280,6 +279,7 @@ public class Playbin : GLib.Object { { assert (this.mpv.command({"playlist-remove", position.to_string ()}) >= 0); this._play_queue.remove (position); + this.play_queue_length -= 1; if (this.play_queue_position > position) this.play_queue_position -= 1; if (this.play_queue_position == this._play_queue.get_n_items ()) { // we just killed the last track @@ -296,6 +296,7 @@ public class Playbin : GLib.Object { } this.state = PlaybinState.STOPPED; this._play_queue.remove_all (); + this.play_queue_length = 0; this.play_queue_position = -1; this.stopped (); @@ -308,6 +309,7 @@ public class Playbin : GLib.Object { "append", }) >= 0); this._play_queue.append (song); + this.play_queue_length += 1; } public async void append_track_async (Subsonic.Song song) { @@ -319,6 +321,7 @@ public class Playbin : GLib.Object { assert (err >= 0); this._play_queue.append (song); + this.play_queue_length += 1; } public void move_track (uint from, uint to) diff --git a/src/ui/play_queue.blp b/src/ui/play_queue.blp index 6f6f3f6..58eb6fc 100644 --- a/src/ui/play_queue.blp +++ b/src/ui/play_queue.blp @@ -1,12 +1,11 @@ using Gtk 4.0; using Adw 1; -using Gio 2.0; template $UiPlayQueue: Adw.Bin { name: "play-queue"; child: Stack { - visible-child-name: bind $visible_child_name (template.playbin as <$Playbin>.play_queue as .n-items) as ; + visible-child-name: bind $visible_child_name (template.playbin as <$Playbin>.play-queue-length) as ; StackPage { name: "empty"; diff --git a/src/ui/playbar.blp b/src/ui/playbar.blp index 1ee9160..0a2e10b 100644 --- a/src/ui/playbar.blp +++ b/src/ui/playbar.blp @@ -1,6 +1,5 @@ using Gtk 4.0; using Adw 1; -using Gio 2.0; template $UiPlaybar: Adw.Bin { child: CenterBox { @@ -120,7 +119,7 @@ template $UiPlaybar: Adw.Bin { Button { icon-name: bind $play_pause_icon_name (template.playbin as <$Playbin>.state as <$PlaybinState>) as ; valign: center; - sensitive: bind $can_press_play (template.playbin as <$Playbin>.state as <$PlaybinState>, template.playbin as <$Playbin>.play_queue as .n-items) as ; + sensitive: bind $can_press_play (template.playbin as <$Playbin>.state as <$PlaybinState>, template.playbin as <$Playbin>.play-queue-length) as ; clicked => $on_play_pause_clicked (); }