From cc2f9f14667e5a2109d34e0dff5db94fd07ce6c4 Mon Sep 17 00:00:00 2001 From: Erica Z Date: Sat, 19 Oct 2024 14:39:44 +0200 Subject: [PATCH] remove track from playlist --- src/playbin.vala | 9 +++++++++ src/ui/play_queue.blp | 1 + src/ui/play_queue.vala | 17 +++++++++++++++++ src/ui/play_queue_song.blp | 8 ++++++++ src/ui/window.vala | 1 + 5 files changed, 36 insertions(+) diff --git a/src/playbin.vala b/src/playbin.vala index 48a265b..0dfc4e8 100644 --- a/src/playbin.vala +++ b/src/playbin.vala @@ -63,6 +63,15 @@ public class Playbin : GLib.Object { (position+i).to_string (), }) >= 0); } + + if (this.play_queue_position == position && removed > 0) { + if (this.play_queue_position < this.play_queue.get_n_items ()) { + // edge case: new track plays, playlist-pos doesn't change, so now_playing never n gets triggered + this.now_playing ( + (Subsonic.Song) this.play_queue.get_item (this.play_queue_position), + (Subsonic.Song?) this.play_queue.get_item (this.play_queue_position+1)); + } + } } public Playbin () { diff --git a/src/ui/play_queue.blp b/src/ui/play_queue.blp index 552a47d..e40555f 100644 --- a/src/ui/play_queue.blp +++ b/src/ui/play_queue.blp @@ -27,6 +27,7 @@ template $UiPlayQueue: Adw.NavigationPage { factory: SignalListItemFactory { setup => $on_song_list_setup (); bind => $on_song_list_bind (); + unbind => $on_song_list_unbind (); }; } } diff --git a/src/ui/play_queue.vala b/src/ui/play_queue.vala index e834e54..73b06a0 100644 --- a/src/ui/play_queue.vala +++ b/src/ui/play_queue.vala @@ -19,6 +19,16 @@ class Ui.PlayQueueSong : Gtk.ListBoxRow { 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; @@ -95,6 +105,13 @@ public class Ui.PlayQueue : Adw.NavigationPage { 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); } diff --git a/src/ui/play_queue_song.blp b/src/ui/play_queue_song.blp index 2fac9c8..5d69ea9 100644 --- a/src/ui/play_queue_song.blp +++ b/src/ui/play_queue_song.blp @@ -112,6 +112,10 @@ template $UiPlayQueueSong: ListBoxRow { focusable: true; icon-name: "view-more"; styles [ "flat" ] + + popover: PopoverMenu { + menu-model: song-menu; + }; } } @@ -135,3 +139,7 @@ SizeGroup { mode: horizontal; widgets [title_box, artist_box, album_duration_box] } + +menu song-menu { + item ("Remove", "song.remove") +} diff --git a/src/ui/window.vala b/src/ui/window.vala index 8625341..f499053 100644 --- a/src/ui/window.vala +++ b/src/ui/window.vala @@ -83,6 +83,7 @@ class Ui.Window : Adw.ApplicationWindow { this.playbin.stopped.connect (() => { this.playing_cover_art = Gdk.Paintable.empty (1, 1); + this.song = null; }); this.shuffle_all_tracks.sensitive = true;