118 lines
3.8 KiB
Vala
118 lines
3.8 KiB
Vala
[GtkTemplate (ui = "/eu/callcc/audrey/ui/play_queue_song.ui")]
|
|
class Ui.PlayQueueSong : Gtk.ListBoxRow {
|
|
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; }
|
|
public Subsonic.Song song { get; set; }
|
|
|
|
public string play_icon_name { get; set; default = ""; }
|
|
|
|
private Playbin playbin;
|
|
public PlayQueueSong (Playbin playbin) {
|
|
this.playbin = playbin;
|
|
|
|
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);
|
|
}
|
|
|
|
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);
|
|
}
|
|
|
|
[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;
|
|
debug ("dropped %u on %u", source.displayed_position, this.displayed_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 (this.playbin);
|
|
|
|
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.bind (item.position, item.item as Subsonic.Song);
|
|
}
|
|
|
|
[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 ();
|
|
}
|
|
|
|
[GtkCallback] private void on_row_activated (uint position) {
|
|
playbin.select_track (position);
|
|
}
|
|
}
|