mirror of
https://github.com/johrpan/musicus.git
synced 2025-10-26 11:47:25 +01:00
Handle current item on playlist page
This commit is contained in:
parent
7d21617e9a
commit
7110401f61
8 changed files with 83 additions and 32 deletions
|
|
@ -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";
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue