expose play queue length as playbin property
This commit is contained in:
parent
e925dc33cc
commit
7799566758
3 changed files with 8 additions and 7 deletions
|
@ -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)
|
||||
|
|
|
@ -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 <Gio.ListStore>.n-items) as <string>;
|
||||
visible-child-name: bind $visible_child_name (template.playbin as <$Playbin>.play-queue-length) as <string>;
|
||||
|
||||
StackPage {
|
||||
name: "empty";
|
||||
|
|
|
@ -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 <string>;
|
||||
valign: center;
|
||||
sensitive: bind $can_press_play (template.playbin as <$Playbin>.state as <$PlaybinState>, template.playbin as <$Playbin>.play_queue as <Gio.ListStore>.n-items) as <bool>;
|
||||
sensitive: bind $can_press_play (template.playbin as <$Playbin>.state as <$PlaybinState>, template.playbin as <$Playbin>.play-queue-length) as <bool>;
|
||||
|
||||
clicked => $on_play_pause_clicked ();
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue