From 930430d5ec3ce492ecb94d327d0db5ec842e929b Mon Sep 17 00:00:00 2001 From: Erica Z Date: Tue, 5 Nov 2024 15:38:46 +0100 Subject: [PATCH] thingks --- resources/playbar.blp | 6 +++--- src/ui/play_queue.rs | 4 +++- src/ui/playbar.rs | 38 ++++++++++++++++++++++++++++++++++---- src/ui/window.rs | 20 +++++++++++++++----- 4 files changed, 55 insertions(+), 13 deletions(-) diff --git a/resources/playbar.blp b/resources/playbar.blp index 323791f..807c5bc 100644 --- a/resources/playbar.blp +++ b/resources/playbar.blp @@ -46,7 +46,7 @@ template $AudreyUiPlaybar: Adw.Bin { xalign: 0; halign: start; - label: bind template.song as <$AudreyPlaybinSong>.title; + label: bind $song_title(template.song) as ; ellipsize: end; } @@ -56,7 +56,7 @@ template $AudreyUiPlaybar: Adw.Bin { ] xalign: 0; - label: bind template.song as <$AudreyPlaybinSong>.artist; + label: bind $song_artist(template.song) as ; ellipsize: end; } @@ -66,7 +66,7 @@ template $AudreyUiPlaybar: Adw.Bin { ] xalign: 0; - label: bind template.song as <$AudreyPlaybinSong>.album; + label: bind $song_album(template.song) as ; ellipsize: end; } } diff --git a/src/ui/play_queue.rs b/src/ui/play_queue.rs index 78adbf3..3bc8ca3 100644 --- a/src/ui/play_queue.rs +++ b/src/ui/play_queue.rs @@ -87,7 +87,9 @@ mod imp { #[template_callback] fn on_row_activated(&self, position: u32) { - self.obj().window().playlist_play_index(position as i64); + self.obj() + .window() + .playlist_play_index(Some(position as i64)); } } diff --git a/src/ui/playbar.rs b/src/ui/playbar.rs index 92ffa81..767bf8a 100644 --- a/src/ui/playbar.rs +++ b/src/ui/playbar.rs @@ -15,7 +15,7 @@ mod imp { #[property(get)] pulse_bar: TemplateChild, - #[property(get, set)] + #[property(get, set, nullable)] song: RefCell>, #[property(get, set)] playing_cover_art: RefCell>, @@ -95,12 +95,20 @@ mod imp { #[template_callback] fn on_skip_forward_clicked(&self) { - self.window().playlist_next(); + if self.window().playlist_pos() + 1 < self.window().playlist_count() as i32 { + self.window().playlist_next(); + } else { + self.window().playlist_play_index(None); + } } #[template_callback] fn on_skip_backward_clicked(&self) { - self.window().playlist_prev(); + if self.window().playlist_pos() > 0 { + self.window().playlist_prev(); + } else { + self.window().playlist_play_index(None); + } } #[template_callback] @@ -126,7 +134,12 @@ mod imp { #[template_callback] fn on_play_pause_clicked(&self, _button: >k::Button) { - self.window().set_pause(!self.window().pause()); + if self.window().idle_active() { + self.window().playlist_play_index(Some(0)); + self.window().set_pause(false); + } else { + self.window().set_pause(!self.window().pause()); + } } #[template_callback] @@ -151,6 +164,23 @@ mod imp { fn window(&self) -> crate::ui::Window { self.obj().root().unwrap().dynamic_cast().unwrap() } + + // these are nedeed because with regular bindings, if song becomes None, the labes are not + // updated + #[template_callback] + fn song_title(&self, song: Option<&PlaybinSong>) -> String { + song.map(PlaybinSong::title).unwrap_or("".to_string()) + } + + #[template_callback] + fn song_artist(&self, song: Option<&PlaybinSong>) -> String { + song.map(PlaybinSong::artist).unwrap_or("".to_string()) + } + + #[template_callback] + fn song_album(&self, song: Option<&PlaybinSong>) -> String { + song.map(PlaybinSong::album).unwrap_or("".to_string()) + } } impl Drop for Playbar { diff --git a/src/ui/window.rs b/src/ui/window.rs index e188b01..8722a8b 100644 --- a/src/ui/window.rs +++ b/src/ui/window.rs @@ -305,6 +305,8 @@ mod imp { Event::EndFile(event) => { event!(Level::INFO, "end file event: {event:?}"); + window.notify("song"); + window.imp().buffering_end(); if let Err(err) = event.reason { event!(Level::ERROR, "end file error: {err}"); @@ -575,11 +577,19 @@ impl Window { todo!() } - pub fn playlist_play_index(&self, index: i64) { - self.imp() - .mpv - .command(["playlist-play-index", &index.to_string()]) - .unwrap(); + pub fn playlist_play_index(&self, index: Option) { + match index.as_ref() { + Some(index) => self + .imp() + .mpv + .command(["playlist-play-index", &index.to_string()]) + .unwrap(), + None => self + .imp() + .mpv + .command(["playlist-play-index", "none"]) + .unwrap(), + }; } pub fn playlist_remove(&self, index: i64) {