mirror of
https://github.com/johrpan/musicus.git
synced 2025-10-26 11:47:25 +01:00
Add wip program tiles
This commit is contained in:
parent
3dc601e0f0
commit
6d11ee9705
7 changed files with 255 additions and 22 deletions
|
|
@ -5,6 +5,7 @@ use crate::{
|
|||
library::{LibraryQuery, MusicusLibrary},
|
||||
player::MusicusPlayer,
|
||||
playlist_item::PlaylistItem,
|
||||
program_tile::{MusicusProgramTile, Program, ProgramTileDesign},
|
||||
recording_tile::MusicusRecordingTile,
|
||||
search_entry::MusicusSearchEntry,
|
||||
search_tag::Tag,
|
||||
|
|
@ -53,6 +54,8 @@ mod imp {
|
|||
#[template_child]
|
||||
pub subtitle_label: TemplateChild<gtk::Label>,
|
||||
#[template_child]
|
||||
pub programs_flow_box: TemplateChild<gtk::FlowBox>,
|
||||
#[template_child]
|
||||
pub composers_flow_box: TemplateChild<gtk::FlowBox>,
|
||||
#[template_child]
|
||||
pub performers_flow_box: TemplateChild<gtk::FlowBox>,
|
||||
|
|
@ -104,6 +107,30 @@ mod imp {
|
|||
.sync_create()
|
||||
.build();
|
||||
|
||||
self.programs_flow_box
|
||||
.append(&MusicusProgramTile::new(Program {
|
||||
title: "Just play some music".to_string(),
|
||||
description: "Randomly select some music. Customize programs using the button in the top right."
|
||||
.to_string(),
|
||||
design: Some(ProgramTileDesign::Program1)
|
||||
},
|
||||
));
|
||||
|
||||
self.programs_flow_box
|
||||
.append(&MusicusProgramTile::new(Program {
|
||||
title: "What's new?".to_string(),
|
||||
description: "Recordings that you recently added to your music library."
|
||||
.to_string(),
|
||||
design: Some(ProgramTileDesign::Program2),
|
||||
}));
|
||||
|
||||
self.programs_flow_box
|
||||
.append(&MusicusProgramTile::new(Program {
|
||||
title: "A long time ago".to_string(),
|
||||
description: "Works that you haven't listend to for a long time.".to_string(),
|
||||
design: Some(ProgramTileDesign::Program3),
|
||||
}));
|
||||
|
||||
self.obj().query(&LibraryQuery::default());
|
||||
}
|
||||
}
|
||||
|
|
@ -167,32 +194,44 @@ impl MusicusHomePage {
|
|||
fn select(&self, search_entry: &MusicusSearchEntry) {
|
||||
let imp = self.imp();
|
||||
|
||||
let (composer, performer, ensemble, work, recording, album) = {
|
||||
(
|
||||
imp.composers.borrow().first().cloned(),
|
||||
imp.performers.borrow().first().cloned(),
|
||||
imp.ensembles.borrow().first().cloned(),
|
||||
imp.works.borrow().first().cloned(),
|
||||
imp.recordings.borrow().first().cloned(),
|
||||
imp.albums.borrow().first().cloned(),
|
||||
)
|
||||
};
|
||||
if imp.programs_flow_box.is_visible() {
|
||||
log::info!("Program selected");
|
||||
} else {
|
||||
let (composer, performer, ensemble, work, recording, album) = {
|
||||
(
|
||||
imp.composers.borrow().first().cloned(),
|
||||
imp.performers.borrow().first().cloned(),
|
||||
imp.ensembles.borrow().first().cloned(),
|
||||
imp.works.borrow().first().cloned(),
|
||||
imp.recordings.borrow().first().cloned(),
|
||||
imp.albums.borrow().first().cloned(),
|
||||
)
|
||||
};
|
||||
|
||||
if let Some(person) = composer {
|
||||
search_entry.add_tag(Tag::Composer(person));
|
||||
} else if let Some(person) = performer {
|
||||
search_entry.add_tag(Tag::Performer(person));
|
||||
} else if let Some(ensemble) = ensemble {
|
||||
search_entry.add_tag(Tag::Ensemble(ensemble));
|
||||
} else if let Some(work) = work {
|
||||
search_entry.add_tag(Tag::Work(work));
|
||||
} else if let Some(recording) = recording {
|
||||
self.play_recording(&recording);
|
||||
} else if let Some(album) = album {
|
||||
self.show_album(&album);
|
||||
if let Some(person) = composer {
|
||||
search_entry.add_tag(Tag::Composer(person));
|
||||
} else if let Some(person) = performer {
|
||||
search_entry.add_tag(Tag::Performer(person));
|
||||
} else if let Some(ensemble) = ensemble {
|
||||
search_entry.add_tag(Tag::Ensemble(ensemble));
|
||||
} else if let Some(work) = work {
|
||||
search_entry.add_tag(Tag::Work(work));
|
||||
} else if let Some(recording) = recording {
|
||||
self.play_recording(&recording);
|
||||
} else if let Some(album) = album {
|
||||
self.show_album(&album);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[template_callback]
|
||||
fn program_selected(&self, tile: >k::FlowBoxChild, _: >k::FlowBox) {
|
||||
log::info!(
|
||||
"Program selected: {:?}",
|
||||
tile.downcast_ref::<MusicusProgramTile>().unwrap().program()
|
||||
);
|
||||
}
|
||||
|
||||
#[template_callback]
|
||||
fn tile_selected(&self, tile: >k::FlowBoxChild, _: >k::FlowBox) {
|
||||
self.imp()
|
||||
|
|
@ -303,6 +342,8 @@ impl MusicusHomePage {
|
|||
}
|
||||
}
|
||||
|
||||
imp.programs_flow_box.set_visible(query.is_empty());
|
||||
|
||||
if let Some(tag) = imp.search_entry.tags().first() {
|
||||
match tag {
|
||||
Tag::Composer(person) | Tag::Performer(person) => {
|
||||
|
|
|
|||
|
|
@ -496,6 +496,16 @@ pub struct LibraryQuery {
|
|||
pub search: String,
|
||||
}
|
||||
|
||||
impl LibraryQuery {
|
||||
pub fn is_empty(&self) -> bool {
|
||||
self.composer.is_none()
|
||||
&& self.performer.is_none()
|
||||
&& self.ensemble.is_none()
|
||||
&& self.work.is_none()
|
||||
&& self.search.is_empty()
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Default, Debug)]
|
||||
pub struct LibraryResults {
|
||||
pub composers: Vec<Person>,
|
||||
|
|
|
|||
|
|
@ -11,6 +11,7 @@ mod player_bar;
|
|||
mod playlist_item;
|
||||
mod playlist_page;
|
||||
mod playlist_tile;
|
||||
mod program_tile;
|
||||
mod recording_tile;
|
||||
mod search_entry;
|
||||
mod search_tag;
|
||||
|
|
|
|||
90
src/program_tile.rs
Normal file
90
src/program_tile.rs
Normal file
|
|
@ -0,0 +1,90 @@
|
|||
use adw::prelude::WidgetExt;
|
||||
use gtk::{glib, subclass::prelude::*};
|
||||
use std::cell::OnceCell;
|
||||
|
||||
mod imp {
|
||||
use super::*;
|
||||
|
||||
#[derive(Debug, Default, gtk::CompositeTemplate)]
|
||||
#[template(file = "data/ui/program_tile.blp")]
|
||||
pub struct MusicusProgramTile {
|
||||
#[template_child]
|
||||
pub edit_button: TemplateChild<gtk::Button>,
|
||||
#[template_child]
|
||||
pub title_label: TemplateChild<gtk::Label>,
|
||||
#[template_child]
|
||||
pub description_label: TemplateChild<gtk::Label>,
|
||||
|
||||
pub program: OnceCell<Program>,
|
||||
}
|
||||
|
||||
#[glib::object_subclass]
|
||||
impl ObjectSubclass for MusicusProgramTile {
|
||||
const NAME: &'static str = "MusicusProgramTile";
|
||||
type Type = super::MusicusProgramTile;
|
||||
type ParentType = gtk::FlowBoxChild;
|
||||
|
||||
fn class_init(klass: &mut Self::Class) {
|
||||
klass.bind_template();
|
||||
}
|
||||
|
||||
fn instance_init(obj: &glib::subclass::InitializingObject<Self>) {
|
||||
obj.init_template();
|
||||
}
|
||||
}
|
||||
|
||||
impl ObjectImpl for MusicusProgramTile {}
|
||||
impl WidgetImpl for MusicusProgramTile {}
|
||||
impl FlowBoxChildImpl for MusicusProgramTile {}
|
||||
}
|
||||
|
||||
glib::wrapper! {
|
||||
pub struct MusicusProgramTile(ObjectSubclass<imp::MusicusProgramTile>)
|
||||
@extends gtk::Widget, gtk::FlowBoxChild;
|
||||
}
|
||||
|
||||
impl MusicusProgramTile {
|
||||
pub fn new(program: Program) -> Self {
|
||||
let obj: Self = glib::Object::new();
|
||||
let imp = obj.imp();
|
||||
|
||||
if let Some(design) = program.design {
|
||||
obj.add_css_class("highlight");
|
||||
obj.add_css_class(match design {
|
||||
ProgramTileDesign::Program1 => "program1",
|
||||
ProgramTileDesign::Program2 => "program2",
|
||||
ProgramTileDesign::Program3 => "program3",
|
||||
ProgramTileDesign::Program4 => "program4",
|
||||
ProgramTileDesign::Program5 => "program5",
|
||||
ProgramTileDesign::Program6 => "program6",
|
||||
})
|
||||
}
|
||||
|
||||
imp.title_label.set_label(&program.title);
|
||||
imp.description_label.set_label(&program.description);
|
||||
imp.program.set(program).unwrap();
|
||||
|
||||
obj
|
||||
}
|
||||
|
||||
pub fn program(&self) -> &Program {
|
||||
self.imp().program.get().unwrap()
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Default)]
|
||||
pub struct Program {
|
||||
pub title: String,
|
||||
pub description: String,
|
||||
pub design: Option<ProgramTileDesign>,
|
||||
}
|
||||
|
||||
#[derive(Clone, Copy, Debug)]
|
||||
pub enum ProgramTileDesign {
|
||||
Program1,
|
||||
Program2,
|
||||
Program3,
|
||||
Program4,
|
||||
Program5,
|
||||
Program6,
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue