more wip
This commit is contained in:
parent
23cd75e4eb
commit
0dae3a9f27
3 changed files with 80 additions and 14 deletions
|
@ -43,22 +43,22 @@ template $AudreyUiWindow: Adw.ApplicationWindow {
|
||||||
|
|
||||||
$AudreyUiAlbumCarousel {
|
$AudreyUiAlbumCarousel {
|
||||||
title: _("Most played");
|
title: _("Most played");
|
||||||
model: StringList { strings [ "a", "b", "c", "d", "e", "f" ] };
|
type: frequent;
|
||||||
}
|
}
|
||||||
|
|
||||||
$AudreyUiAlbumCarousel {
|
$AudreyUiAlbumCarousel {
|
||||||
title: _("Explore from your library");
|
title: _("Explore from your library");
|
||||||
model: StringList { strings [ "a", "b", "c", "d", "e", "f" ] };
|
type: random;
|
||||||
}
|
}
|
||||||
|
|
||||||
$AudreyUiAlbumCarousel {
|
$AudreyUiAlbumCarousel {
|
||||||
title: _("Newly added releases");
|
title: _("Newly added releases");
|
||||||
model: StringList { strings [ "a", "b", "c", "d", "e", "f" ] };
|
type: newest;
|
||||||
}
|
}
|
||||||
|
|
||||||
$AudreyUiAlbumCarousel {
|
$AudreyUiAlbumCarousel {
|
||||||
title: _("Recently played");
|
title: _("Recently played");
|
||||||
model: StringList { strings [ "a", "b", "c", "d", "e", "f" ] };
|
type: recent;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
|
@ -10,6 +10,7 @@ pub enum AlbumListType {
|
||||||
Recent,
|
Recent,
|
||||||
AlphabeticalByName,
|
AlphabeticalByName,
|
||||||
AlphabeticalByArtist,
|
AlphabeticalByArtist,
|
||||||
|
Starred,
|
||||||
ByYear { from: u32, to: u32 },
|
ByYear { from: u32, to: u32 },
|
||||||
ByGenre(String),
|
ByGenre(String),
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,20 +2,33 @@ use adw::prelude::*;
|
||||||
use adw::subclass::prelude::*;
|
use adw::subclass::prelude::*;
|
||||||
use adw::{gio, glib};
|
use adw::{gio, glib};
|
||||||
use glib::subclass::InitializingObject;
|
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 {
|
mod imp {
|
||||||
use super::*;
|
use super::*;
|
||||||
|
|
||||||
#[derive(glib::Properties, gtk::CompositeTemplate, Default)]
|
#[derive(gtk::CompositeTemplate, Default)]
|
||||||
#[properties(wrapper_type = super::AlbumCarousel)]
|
|
||||||
#[template(resource = "/eu/callcc/audrey/album_carousel.ui")]
|
#[template(resource = "/eu/callcc/audrey/album_carousel.ui")]
|
||||||
pub struct AlbumCarousel {
|
pub struct AlbumCarousel {
|
||||||
#[property(get, set)]
|
|
||||||
title: RefCell<String>,
|
title: RefCell<String>,
|
||||||
|
model: OnceCell<gio::ListStore>,
|
||||||
#[property(get, set)]
|
r#type: Cell<Type>,
|
||||||
model: RefCell<Option<gio::ListModel>>,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[glib::object_subclass]
|
#[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 WidgetImpl for AlbumCarousel {}
|
||||||
|
|
||||||
impl BinImpl for AlbumCarousel {}
|
impl BinImpl for AlbumCarousel {}
|
||||||
|
|
||||||
#[gtk::template_callbacks]
|
#[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! {
|
glib::wrapper! {
|
||||||
|
|
Loading…
Reference in a new issue