This commit is contained in:
Erica Z 2024-11-17 12:28:02 +01:00
parent 23cd75e4eb
commit 0dae3a9f27
3 changed files with 80 additions and 14 deletions

View file

@ -43,22 +43,22 @@ template $AudreyUiWindow: Adw.ApplicationWindow {
$AudreyUiAlbumCarousel {
title: _("Most played");
model: StringList { strings [ "a", "b", "c", "d", "e", "f" ] };
type: frequent;
}
$AudreyUiAlbumCarousel {
title: _("Explore from your library");
model: StringList { strings [ "a", "b", "c", "d", "e", "f" ] };
type: random;
}
$AudreyUiAlbumCarousel {
title: _("Newly added releases");
model: StringList { strings [ "a", "b", "c", "d", "e", "f" ] };
type: newest;
}
$AudreyUiAlbumCarousel {
title: _("Recently played");
model: StringList { strings [ "a", "b", "c", "d", "e", "f" ] };
type: recent;
}
};
};

View file

@ -10,6 +10,7 @@ pub enum AlbumListType {
Recent,
AlphabeticalByName,
AlphabeticalByArtist,
Starred,
ByYear { from: u32, to: u32 },
ByGenre(String),
}

View file

@ -2,20 +2,33 @@ use adw::prelude::*;
use adw::subclass::prelude::*;
use adw::{gio, glib};
use glib::subclass::InitializingObject;
use std::cell::RefCell;
use std::cell::{Cell, OnceCell, RefCell};
use std::sync::OnceLock;
#[derive(Debug, Copy, Clone, PartialEq, Eq, glib::Enum)]
#[enum_type(name = "AudreyUiAlbumCarouselType")]
pub enum Type {
Frequent,
Random,
Newest,
Recent,
}
impl Default for Type {
fn default() -> Self {
Self::Frequent
}
}
mod imp {
use super::*;
#[derive(glib::Properties, gtk::CompositeTemplate, Default)]
#[properties(wrapper_type = super::AlbumCarousel)]
#[derive(gtk::CompositeTemplate, Default)]
#[template(resource = "/eu/callcc/audrey/album_carousel.ui")]
pub struct AlbumCarousel {
#[property(get, set)]
title: RefCell<String>,
#[property(get, set)]
model: RefCell<Option<gio::ListModel>>,
model: OnceCell<gio::ListStore>,
r#type: Cell<Type>,
}
#[glib::object_subclass]
@ -34,15 +47,67 @@ mod imp {
}
}
#[glib::derived_properties]
impl ObjectImpl for AlbumCarousel {}
impl ObjectImpl for AlbumCarousel {
fn properties() -> &'static [glib::ParamSpec] {
static PROPS: OnceLock<Vec<glib::ParamSpec>> = OnceLock::new();
PROPS.get_or_init(|| {
vec![
glib::ParamSpecString::builder("title").build(),
glib::ParamSpecEnum::builder::<Type>("type").build(),
glib::ParamSpecObject::builder::<gio::ListModel>("model")
.read_only()
.build(),
]
})
}
fn property(&self, id: usize, _pspec: &glib::ParamSpec) -> glib::Value {
match id {
1 => self.title.borrow().clone().into(),
2 => self.r#type.get().into(),
3 => self.model().into(),
_ => unreachable!(),
}
}
fn set_property(&self, id: usize, value: &glib::Value, _pspec: &glib::ParamSpec) {
dbg!(id, value);
match id {
1 => {
self.title.replace(value.get_owned().unwrap());
}
2 => {
self.r#type.replace(value.get_owned().unwrap());
self.update_model();
}
_ => unreachable!(),
}
}
}
impl WidgetImpl for AlbumCarousel {}
impl BinImpl for AlbumCarousel {}
#[gtk::template_callbacks]
impl AlbumCarousel {}
impl AlbumCarousel {
fn model(&self) -> &gio::ListStore {
self.model
.get_or_init(|| gio::ListStore::new::<crate::model::Album>())
}
fn update_model(&self) {
let window: crate::ui::Window = match self.obj().root() {
None => return,
Some(root) => root.dynamic_cast().unwrap(),
};
let api = window.api();
match self.r#type.get() {
_ => todo!(),
}
}
}
}
glib::wrapper! {