From 0dae3a9f27b02905ddd5f66d5f1a3ef882a791be Mon Sep 17 00:00:00 2001 From: Erica Z Date: Sun, 17 Nov 2024 12:28:02 +0100 Subject: [PATCH] more wip --- resources/window.blp | 8 ++-- src/subsonic/album_list.rs | 1 + src/ui/album_carousel.rs | 85 +++++++++++++++++++++++++++++++++----- 3 files changed, 80 insertions(+), 14 deletions(-) diff --git a/resources/window.blp b/resources/window.blp index b5022b3..88597cd 100644 --- a/resources/window.blp +++ b/resources/window.blp @@ -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; } }; }; diff --git a/src/subsonic/album_list.rs b/src/subsonic/album_list.rs index 1d28c56..b3ca0a2 100644 --- a/src/subsonic/album_list.rs +++ b/src/subsonic/album_list.rs @@ -10,6 +10,7 @@ pub enum AlbumListType { Recent, AlphabeticalByName, AlphabeticalByArtist, + Starred, ByYear { from: u32, to: u32 }, ByGenre(String), } diff --git a/src/ui/album_carousel.rs b/src/ui/album_carousel.rs index ac76463..df22130 100644 --- a/src/ui/album_carousel.rs +++ b/src/ui/album_carousel.rs @@ -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, - - #[property(get, set)] - model: RefCell>, + model: OnceCell, + r#type: Cell, } #[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> = OnceLock::new(); + PROPS.get_or_init(|| { + vec![ + glib::ParamSpecString::builder("title").build(), + glib::ParamSpecEnum::builder::("type").build(), + glib::ParamSpecObject::builder::("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::()) + } + + 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! {