Handle current item on playlist page

This commit is contained in:
Elias Projahn 2023-10-26 11:48:42 +02:00
parent 7d21617e9a
commit 7110401f61
8 changed files with 83 additions and 32 deletions

View file

@ -14,10 +14,26 @@ mod imp {
pub playing: Cell<bool>,
#[property(get, construct_only)]
pub playlist: OnceCell<gio::ListStore>,
#[property(get, set)]
#[property(get, set = Self::set_current_index)]
pub current_index: Cell<u32>,
}
impl MusicusPlayer {
pub fn set_current_index(&self, index: u32) {
let playlist = self.playlist.get().unwrap();
if let Some(item) = playlist.item(self.current_index.get()) {
item.downcast::<PlaylistItem>().unwrap().set_is_playing(false);
}
self.current_index.set(index);
if let Some(item) = playlist.item(index) {
item.downcast::<PlaylistItem>().unwrap().set_is_playing(true);
}
}
}
#[glib::object_subclass]
impl ObjectSubclass for MusicusPlayer {
const NAME: &'static str = "MusicusPlayer";