mirror of
https://github.com/johrpan/musicus.git
synced 2025-10-26 11:47:25 +01:00
68 lines
1.6 KiB
Rust
68 lines
1.6 KiB
Rust
use crate::playlist_item::PlaylistItem;
|
|
use gtk::{gio, glib, glib::Properties, prelude::*, subclass::prelude::*};
|
|
use std::cell::{Cell, OnceCell};
|
|
|
|
mod imp {
|
|
use super::*;
|
|
|
|
#[derive(Properties, Debug, Default)]
|
|
#[properties(wrapper_type = super::MusicusPlayer)]
|
|
pub struct MusicusPlayer {
|
|
#[property(get, set)]
|
|
pub active: Cell<bool>,
|
|
#[property(get, set)]
|
|
pub playing: Cell<bool>,
|
|
#[property(get, construct_only)]
|
|
pub playlist: OnceCell<gio::ListStore>,
|
|
#[property(get, set)]
|
|
pub current_index: Cell<u32>,
|
|
}
|
|
|
|
#[glib::object_subclass]
|
|
impl ObjectSubclass for MusicusPlayer {
|
|
const NAME: &'static str = "MusicusPlayer";
|
|
type Type = super::MusicusPlayer;
|
|
}
|
|
|
|
#[glib::derived_properties]
|
|
impl ObjectImpl for MusicusPlayer {}
|
|
}
|
|
|
|
glib::wrapper! {
|
|
pub struct MusicusPlayer(ObjectSubclass<imp::MusicusPlayer>);
|
|
}
|
|
|
|
impl MusicusPlayer {
|
|
pub fn new() -> Self {
|
|
glib::Object::builder()
|
|
.property("active", false)
|
|
.property("playing", false)
|
|
.property("playlist", gio::ListStore::new::<PlaylistItem>())
|
|
.property("current-index", 0u32)
|
|
.build()
|
|
}
|
|
|
|
pub fn append(&self, tracks: Vec<PlaylistItem>) {
|
|
let playlist = self.playlist();
|
|
|
|
for track in tracks {
|
|
playlist.append(&track);
|
|
}
|
|
|
|
self.set_active(true);
|
|
}
|
|
|
|
pub fn play(&self) {
|
|
self.set_playing(true)
|
|
}
|
|
|
|
pub fn pause(&self) {
|
|
self.set_playing(false)
|
|
}
|
|
}
|
|
|
|
impl Default for MusicusPlayer {
|
|
fn default() -> Self {
|
|
Self::new()
|
|
}
|
|
}
|