audrey/src/ui/play_queue.vala
2024-10-19 13:55:25 +02:00

70 lines
2.3 KiB
Vala

[GtkTemplate (ui = "/eu/callcc/audrey/ui/play_queue_song.ui")]
class Ui.PlayQueueSong : Gtk.ListBoxRow {
public uint position { get; set; }
public Subsonic.Song song { get; set; }
[GtkCallback] private string format_duration (int duration) {
return "%02d:%02d".printf(duration/60, duration%60);
}
[GtkCallback] private string star_button_icon_name (DateTime? starred) {
return starred == null ? "non-starred" : "starred";
}
[GtkCallback] private Gdk.ContentProvider? on_drag_prepare (double x, double y) {
return new Gdk.ContentProvider.for_value (this);
}
[GtkCallback] private bool on_drop (Value value, double x, double y) {
var source = value as PlayQueueSong;
print ("dropped %u on %u", source.position, this.position);
return false;
}
}
[GtkTemplate (ui = "/eu/callcc/audrey/ui/play_queue.ui")]
public class Ui.PlayQueue : Adw.NavigationPage {
private Playbin _playbin;
public Playbin playbin {
get { return _playbin; }
set {
assert (_playbin == null); // only set once
_playbin = value;
_playbin.play_queue.items_changed.connect (this.on_store_items_changed);
this.can_clear_all = _playbin.play_queue.get_n_items () > 0;
_playbin.notify["play-queue-position"].connect (() => {
});
}
}
public bool can_clear_all { get; private set; }
[GtkCallback] private void on_clear () {
this.playbin.play_queue.remove_all ();
}
private void on_store_items_changed (GLib.ListModel store, uint position, uint removed, uint added) {
this.can_clear_all = store.get_n_items () > 0;
}
[GtkCallback] private void on_song_list_setup (Gtk.SignalListItemFactory factory, Object object) {
var item = object as Gtk.ListItem;
var child = new PlayQueueSong ();
item.child = child;
}
[GtkCallback] private void on_song_list_bind (Gtk.SignalListItemFactory factory, Object object) {
var item = object as Gtk.ListItem;
var child = item.child as PlayQueueSong;
child.position = item.position+1;
child.song = item.item as Subsonic.Song;
}
[GtkCallback] private void on_row_activated (uint position) {
playbin.select_track (position);
}
}