Implement add to playlist

This commit is contained in:
Elias Projahn 2025-03-08 08:35:15 +01:00
parent 714722bd89
commit 4a33ed3fc5
5 changed files with 164 additions and 21 deletions

View file

@ -34,7 +34,7 @@ mod imp {
pub active: Cell<bool>,
#[property(get, set)]
pub playing: Cell<bool>,
#[property(get, set)]
#[property(get, set = Self::set_program)]
pub program: RefCell<Option<Program>>,
#[property(get, construct_only)]
pub playlist: OnceCell<gio::ListStore>,
@ -51,6 +51,25 @@ mod imp {
}
impl Player {
pub fn set_program(&self, program: Option<&Program>) {
self.program.replace(program.cloned());
if let Some(program) = program {
if !self.obj().active() {
match self.obj().generate_items(program) {
Ok(index) => {
self.obj().set_active(true);
self.obj().set_current_index(index);
self.obj().pause();
}
Err(err) => {
log::warn!("Failed to play from program: {err}");
}
}
}
}
}
pub fn set_current_index(&self, index: u32) {
let playlist = self.playlist.get().unwrap();