2024-10-19 11:07:22 +00:00
|
|
|
[GtkTemplate (ui = "/eu/callcc/audrey/ui/play_queue_song.ui")]
|
|
|
|
class Ui.PlayQueueSong : Gtk.ListBoxRow {
|
2024-10-19 12:04:52 +00:00
|
|
|
public bool current {
|
|
|
|
set {
|
|
|
|
if (value) {
|
|
|
|
this.play_icon_name = "media-playback-start";
|
|
|
|
this.add_css_class ("playing");
|
|
|
|
} else {
|
|
|
|
this.play_icon_name = "";
|
|
|
|
this.remove_css_class ("playing");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
public uint displayed_position { get; set; }
|
2024-10-19 11:07:22 +00:00
|
|
|
public Subsonic.Song song { get; set; }
|
|
|
|
|
2024-10-19 12:04:52 +00:00
|
|
|
public string play_icon_name { get; set; default = ""; }
|
|
|
|
|
|
|
|
private Playbin playbin;
|
|
|
|
public PlayQueueSong (Playbin playbin) {
|
|
|
|
this.playbin = playbin;
|
2024-10-19 12:39:44 +00:00
|
|
|
|
|
|
|
var action_group = new SimpleActionGroup ();
|
|
|
|
|
|
|
|
var remove = new SimpleAction ("remove", null);
|
|
|
|
remove.activate.connect (() => {
|
|
|
|
this.playbin.play_queue.remove (this.displayed_position-1);
|
|
|
|
});
|
|
|
|
action_group.add_action (remove);
|
|
|
|
|
|
|
|
this.insert_action_group ("song", action_group);
|
2024-10-19 12:04:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
private ulong connection;
|
|
|
|
public void bind (uint position, Subsonic.Song song) {
|
|
|
|
this.displayed_position = position+1;
|
|
|
|
this.song = song;
|
|
|
|
this.current = this.playbin.play_queue_position == position;
|
|
|
|
this.connection = this.playbin.notify["play-queue-position"].connect (() => {
|
|
|
|
this.current = this.playbin.play_queue_position == position;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
public void unbind () {
|
|
|
|
this.playbin.disconnect (this.connection);
|
|
|
|
}
|
|
|
|
|
2024-10-19 11:07:22 +00:00
|
|
|
[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";
|
|
|
|
}
|
2024-10-19 11:55:25 +00:00
|
|
|
|
|
|
|
[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;
|
2024-10-20 06:33:25 +00:00
|
|
|
debug ("dropped %u on %u", source.displayed_position, this.displayed_position);
|
2024-10-19 11:55:25 +00:00
|
|
|
return false;
|
|
|
|
}
|
2024-10-19 11:07:22 +00:00
|
|
|
}
|
|
|
|
|
2024-10-13 14:24:25 +00:00
|
|
|
[GtkTemplate (ui = "/eu/callcc/audrey/ui/play_queue.ui")]
|
|
|
|
public class Ui.PlayQueue : Adw.NavigationPage {
|
2024-10-19 11:29:39 +00:00
|
|
|
private Playbin _playbin;
|
|
|
|
public Playbin playbin {
|
|
|
|
get { return _playbin; }
|
2024-10-16 09:43:11 +00:00
|
|
|
set {
|
2024-10-19 11:29:39 +00:00
|
|
|
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 (() => {
|
|
|
|
});
|
2024-10-16 09:43:11 +00:00
|
|
|
}
|
|
|
|
}
|
2024-10-13 14:24:25 +00:00
|
|
|
|
2024-10-16 09:43:11 +00:00
|
|
|
public bool can_clear_all { get; private set; }
|
2024-10-13 15:21:29 +00:00
|
|
|
|
2024-10-15 11:27:47 +00:00
|
|
|
[GtkCallback] private void on_clear () {
|
2024-10-19 11:29:39 +00:00
|
|
|
this.playbin.play_queue.remove_all ();
|
2024-10-16 09:43:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
private void on_store_items_changed (GLib.ListModel store, uint position, uint removed, uint added) {
|
|
|
|
this.can_clear_all = store.get_n_items () > 0;
|
|
|
|
}
|
2024-10-19 11:07:22 +00:00
|
|
|
|
|
|
|
[GtkCallback] private void on_song_list_setup (Gtk.SignalListItemFactory factory, Object object) {
|
|
|
|
var item = object as Gtk.ListItem;
|
2024-10-19 12:04:52 +00:00
|
|
|
var child = new PlayQueueSong (this.playbin);
|
2024-10-19 11:29:39 +00:00
|
|
|
|
|
|
|
item.child = child;
|
2024-10-19 11:07:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
[GtkCallback] private void on_song_list_bind (Gtk.SignalListItemFactory factory, Object object) {
|
|
|
|
var item = object as Gtk.ListItem;
|
|
|
|
var child = item.child as PlayQueueSong;
|
|
|
|
|
2024-10-19 12:04:52 +00:00
|
|
|
child.bind (item.position, item.item as Subsonic.Song);
|
2024-10-19 11:07:22 +00:00
|
|
|
}
|
2024-10-16 09:43:11 +00:00
|
|
|
|
2024-10-19 12:39:44 +00:00
|
|
|
[GtkCallback] private void on_song_list_unbind (Gtk.SignalListItemFactory factory, Object object) {
|
|
|
|
var item = object as Gtk.ListItem;
|
|
|
|
var child = item.child as PlayQueueSong;
|
|
|
|
|
|
|
|
child.unbind ();
|
|
|
|
}
|
|
|
|
|
2024-10-19 11:29:39 +00:00
|
|
|
[GtkCallback] private void on_row_activated (uint position) {
|
|
|
|
playbin.select_track (position);
|
2024-10-12 12:28:05 +00:00
|
|
|
}
|
2024-10-10 09:53:52 +00:00
|
|
|
}
|