2023-09-29 21:18:28 +02:00
|
|
|
use crate::player::MusicusPlayer;
|
2023-09-20 13:49:02 +02:00
|
|
|
use adw::subclass::{navigation_page::NavigationPageImpl, prelude::*};
|
2023-09-29 21:18:28 +02:00
|
|
|
use gtk::{glib, glib::Properties, prelude::*};
|
|
|
|
|
use std::cell::RefCell;
|
2023-09-20 13:49:02 +02:00
|
|
|
|
|
|
|
|
mod imp {
|
|
|
|
|
use crate::tile::MusicusTile;
|
|
|
|
|
|
|
|
|
|
use super::*;
|
|
|
|
|
|
2023-09-29 21:18:28 +02:00
|
|
|
#[derive(Properties, Debug, Default, gtk::CompositeTemplate)]
|
|
|
|
|
#[properties(wrapper_type = super::MusicusHomePage)]
|
2023-09-24 13:58:05 +02:00
|
|
|
#[template(file = "data/ui/home_page.blp")]
|
2023-09-20 13:49:02 +02:00
|
|
|
pub struct MusicusHomePage {
|
2023-09-29 21:18:28 +02:00
|
|
|
#[property(get, set)]
|
|
|
|
|
pub player: RefCell<MusicusPlayer>,
|
|
|
|
|
|
2023-09-20 13:49:02 +02:00
|
|
|
#[template_child]
|
|
|
|
|
pub search_entry: TemplateChild<gtk::SearchEntry>,
|
|
|
|
|
#[template_child]
|
|
|
|
|
pub persons_flow_box: TemplateChild<gtk::FlowBox>,
|
|
|
|
|
#[template_child]
|
|
|
|
|
pub works_flow_box: TemplateChild<gtk::FlowBox>,
|
|
|
|
|
#[template_child]
|
|
|
|
|
pub recordings_flow_box: TemplateChild<gtk::FlowBox>,
|
2023-09-21 17:19:31 +02:00
|
|
|
#[template_child]
|
|
|
|
|
pub play_button: TemplateChild<gtk::Button>,
|
2023-09-20 13:49:02 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[glib::object_subclass]
|
|
|
|
|
impl ObjectSubclass for MusicusHomePage {
|
|
|
|
|
const NAME: &'static str = "MusicusHomePage";
|
|
|
|
|
type Type = super::MusicusHomePage;
|
|
|
|
|
type ParentType = adw::NavigationPage;
|
|
|
|
|
|
|
|
|
|
fn class_init(klass: &mut Self::Class) {
|
|
|
|
|
klass.bind_template();
|
2023-09-21 17:19:31 +02:00
|
|
|
klass.bind_template_instance_callbacks();
|
2023-09-20 13:49:02 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fn instance_init(obj: &glib::subclass::InitializingObject<Self>) {
|
|
|
|
|
obj.init_template();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2023-09-29 21:18:28 +02:00
|
|
|
#[glib::derived_properties]
|
2023-09-20 13:49:02 +02:00
|
|
|
impl ObjectImpl for MusicusHomePage {
|
|
|
|
|
fn constructed(&self) {
|
|
|
|
|
self.parent_constructed();
|
|
|
|
|
self.search_entry
|
|
|
|
|
.set_key_capture_widget(Some(self.obj().as_ref()));
|
|
|
|
|
|
2023-09-29 21:18:28 +02:00
|
|
|
self.player
|
|
|
|
|
.borrow()
|
|
|
|
|
.bind_property("active", &self.play_button.get(), "visible")
|
|
|
|
|
.invert_boolean()
|
|
|
|
|
.sync_create()
|
|
|
|
|
.build();
|
|
|
|
|
|
2023-09-20 13:49:02 +02:00
|
|
|
for _ in 0..9 {
|
|
|
|
|
self.persons_flow_box.append(&MusicusTile::new());
|
|
|
|
|
self.works_flow_box.append(&MusicusTile::new());
|
|
|
|
|
self.recordings_flow_box.append(&MusicusTile::new());
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
impl WidgetImpl for MusicusHomePage {}
|
|
|
|
|
impl NavigationPageImpl for MusicusHomePage {}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
glib::wrapper! {
|
|
|
|
|
pub struct MusicusHomePage(ObjectSubclass<imp::MusicusHomePage>)
|
|
|
|
|
@extends gtk::Widget, adw::NavigationPage;
|
|
|
|
|
}
|
|
|
|
|
|
2023-09-21 17:19:31 +02:00
|
|
|
#[gtk::template_callbacks]
|
2023-09-20 13:49:02 +02:00
|
|
|
impl MusicusHomePage {
|
2023-09-29 21:18:28 +02:00
|
|
|
pub fn new(player: &MusicusPlayer) -> Self {
|
|
|
|
|
glib::Object::builder().property("player", player).build()
|
2023-09-20 13:49:02 +02:00
|
|
|
}
|
2023-09-21 17:19:31 +02:00
|
|
|
|
|
|
|
|
#[template_callback]
|
|
|
|
|
fn play(&self, _: >k::Button) {
|
|
|
|
|
log::info!("Play button clicked");
|
2023-09-29 21:18:28 +02:00
|
|
|
self.imp().player.borrow().play();
|
2023-09-21 17:19:31 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[template_callback]
|
|
|
|
|
fn search(&self, entry: >k::SearchEntry) {
|
|
|
|
|
log::info!("Search changed: \"{}\"", entry.text());
|
|
|
|
|
}
|
2023-09-20 13:49:02 +02:00
|
|
|
}
|