| 
									
										
										
										
											2023-09-30 18:26:11 +02:00
										 |  |  | use crate::{
 | 
					
						
							| 
									
										
										
										
											2024-06-05 13:26:47 +02:00
										 |  |  |     album_tile::MusicusAlbumTile,
 | 
					
						
							| 
									
										
										
										
											2024-03-23 18:06:46 +01:00
										 |  |  |     db::models::*,
 | 
					
						
							| 
									
										
										
										
											2024-06-05 19:03:04 +02:00
										 |  |  |     editor::{person_editor::MusicusPersonEditor, work_editor::MusicusWorkEditor},
 | 
					
						
							| 
									
										
										
										
											2024-03-23 18:06:46 +01:00
										 |  |  |     library::{LibraryQuery, MusicusLibrary},
 | 
					
						
							| 
									
										
										
										
											2023-10-07 22:49:20 +02:00
										 |  |  |     player::MusicusPlayer,
 | 
					
						
							| 
									
										
										
										
											2023-10-25 17:45:32 +02:00
										 |  |  |     playlist_item::PlaylistItem,
 | 
					
						
							| 
									
										
										
										
											2023-10-08 16:40:59 +02:00
										 |  |  |     recording_tile::MusicusRecordingTile,
 | 
					
						
							| 
									
										
										
										
											2023-10-07 22:49:20 +02:00
										 |  |  |     search_entry::MusicusSearchEntry,
 | 
					
						
							| 
									
										
										
										
											2023-10-08 00:16:41 +02:00
										 |  |  |     search_tag::Tag,
 | 
					
						
							| 
									
										
										
										
											2023-10-08 16:40:59 +02:00
										 |  |  |     tag_tile::MusicusTagTile,
 | 
					
						
							| 
									
										
										
										
											2023-09-30 18:26:11 +02:00
										 |  |  | };
 | 
					
						
							| 
									
										
										
										
											2024-06-05 13:26:47 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-09-20 13:49:02 +02:00
										 |  |  | use adw::subclass::{navigation_page::NavigationPageImpl, prelude::*};
 | 
					
						
							| 
									
										
										
										
											2023-10-07 22:49:20 +02:00
										 |  |  | use gtk::{
 | 
					
						
							|  |  |  |     glib::{self, clone, Properties},
 | 
					
						
							|  |  |  |     prelude::*,
 | 
					
						
							|  |  |  | };
 | 
					
						
							| 
									
										
										
										
											2024-06-05 13:26:47 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-10-08 00:16:41 +02:00
										 |  |  | use std::cell::{OnceCell, RefCell};
 | 
					
						
							| 
									
										
										
										
											2023-09-20 13:49:02 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | mod imp {
 | 
					
						
							|  |  |  |     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 {
 | 
					
						
							| 
									
										
										
										
											2024-06-05 19:03:04 +02:00
										 |  |  |         #[property(get, construct_only)]
 | 
					
						
							|  |  |  |         pub navigation: OnceCell<adw::NavigationView>,
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-10-07 22:49:20 +02:00
										 |  |  |         #[property(get, construct_only)]
 | 
					
						
							| 
									
										
										
										
											2023-09-30 18:26:11 +02:00
										 |  |  |         pub library: OnceCell<MusicusLibrary>,
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-10-07 22:49:20 +02:00
										 |  |  |         #[property(get, construct_only)]
 | 
					
						
							|  |  |  |         pub player: OnceCell<MusicusPlayer>,
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-10-08 15:11:47 +02:00
										 |  |  |         pub composers: RefCell<Vec<Person>>,
 | 
					
						
							|  |  |  |         pub performers: RefCell<Vec<Person>>,
 | 
					
						
							| 
									
										
										
										
											2023-10-08 00:16:41 +02:00
										 |  |  |         pub ensembles: RefCell<Vec<Ensemble>>,
 | 
					
						
							|  |  |  |         pub works: RefCell<Vec<Work>>,
 | 
					
						
							|  |  |  |         pub recordings: RefCell<Vec<Recording>>,
 | 
					
						
							| 
									
										
										
										
											2024-06-05 13:26:47 +02:00
										 |  |  |         pub albums: RefCell<Vec<Album>>,
 | 
					
						
							| 
									
										
										
										
											2023-10-08 00:16:41 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-09-20 13:49:02 +02:00
										 |  |  |         #[template_child]
 | 
					
						
							| 
									
										
										
										
											2023-09-30 00:22:33 +02:00
										 |  |  |         pub search_entry: TemplateChild<MusicusSearchEntry>,
 | 
					
						
							| 
									
										
										
										
											2023-09-20 13:49:02 +02:00
										 |  |  |         #[template_child]
 | 
					
						
							| 
									
										
										
										
											2023-10-07 23:13:32 +02:00
										 |  |  |         pub stack: TemplateChild<gtk::Stack>,
 | 
					
						
							|  |  |  |         #[template_child]
 | 
					
						
							| 
									
										
										
										
											2024-06-05 19:03:04 +02:00
										 |  |  |         pub header_box: TemplateChild<gtk::Box>,
 | 
					
						
							|  |  |  |         #[template_child]
 | 
					
						
							|  |  |  |         pub title_label: TemplateChild<gtk::Label>,
 | 
					
						
							|  |  |  |         #[template_child]
 | 
					
						
							|  |  |  |         pub subtitle_label: TemplateChild<gtk::Label>,
 | 
					
						
							|  |  |  |         #[template_child]
 | 
					
						
							| 
									
										
										
										
											2023-10-08 15:11:47 +02:00
										 |  |  |         pub composers_flow_box: TemplateChild<gtk::FlowBox>,
 | 
					
						
							|  |  |  |         #[template_child]
 | 
					
						
							|  |  |  |         pub performers_flow_box: TemplateChild<gtk::FlowBox>,
 | 
					
						
							| 
									
										
										
										
											2023-09-20 13:49:02 +02:00
										 |  |  |         #[template_child]
 | 
					
						
							| 
									
										
										
										
											2023-10-07 23:13:32 +02:00
										 |  |  |         pub ensembles_flow_box: TemplateChild<gtk::FlowBox>,
 | 
					
						
							|  |  |  |         #[template_child]
 | 
					
						
							| 
									
										
										
										
											2023-09-20 13:49:02 +02:00
										 |  |  |         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]
 | 
					
						
							| 
									
										
										
										
											2024-06-05 13:26:47 +02:00
										 |  |  |         pub albums_flow_box: TemplateChild<gtk::FlowBox>,
 | 
					
						
							|  |  |  |         #[template_child]
 | 
					
						
							| 
									
										
										
										
											2023-09-21 17:19:31 +02:00
										 |  |  |         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();
 | 
					
						
							| 
									
										
										
										
											2023-09-30 00:22:33 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |             self.search_entry.set_key_capture_widget(&*self.obj());
 | 
					
						
							| 
									
										
										
										
											2023-09-20 13:49:02 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-10-07 22:49:20 +02:00
										 |  |  |             self.search_entry
 | 
					
						
							|  |  |  |                 .connect_query_changed(clone!(@weak self as _self => move |entry| {
 | 
					
						
							|  |  |  |                     _self.obj().query(&entry.query());
 | 
					
						
							|  |  |  |                 }));
 | 
					
						
							| 
									
										
										
										
											2023-09-30 19:10:32 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-09-29 21:18:28 +02:00
										 |  |  |             self.player
 | 
					
						
							| 
									
										
										
										
											2023-10-07 22:49:20 +02:00
										 |  |  |                 .get()
 | 
					
						
							|  |  |  |                 .unwrap()
 | 
					
						
							| 
									
										
										
										
											2023-09-29 21:18:28 +02:00
										 |  |  |                 .bind_property("active", &self.play_button.get(), "visible")
 | 
					
						
							|  |  |  |                 .invert_boolean()
 | 
					
						
							|  |  |  |                 .sync_create()
 | 
					
						
							|  |  |  |                 .build();
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-10-07 22:49:20 +02:00
										 |  |  |             self.obj().query(&LibraryQuery::default());
 | 
					
						
							| 
									
										
										
										
											2023-09-20 13:49:02 +02:00
										 |  |  |         }
 | 
					
						
							|  |  |  |     }
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     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 {
 | 
					
						
							| 
									
										
										
										
											2024-06-05 19:03:04 +02:00
										 |  |  |     pub fn new(
 | 
					
						
							|  |  |  |         navigation: &adw::NavigationView,
 | 
					
						
							|  |  |  |         library: &MusicusLibrary,
 | 
					
						
							|  |  |  |         player: &MusicusPlayer,
 | 
					
						
							|  |  |  |     ) -> Self {
 | 
					
						
							| 
									
										
										
										
											2023-10-07 22:49:20 +02:00
										 |  |  |         glib::Object::builder()
 | 
					
						
							| 
									
										
										
										
											2024-06-05 19:03:04 +02:00
										 |  |  |             .property("navigation", navigation)
 | 
					
						
							| 
									
										
										
										
											2023-10-07 22:49:20 +02:00
										 |  |  |             .property("library", library)
 | 
					
						
							|  |  |  |             .property("player", player)
 | 
					
						
							|  |  |  |             .build()
 | 
					
						
							| 
									
										
										
										
											2023-09-20 13:49:02 +02:00
										 |  |  |     }
 | 
					
						
							| 
									
										
										
										
											2023-09-21 17:19:31 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-06-05 19:03:04 +02:00
										 |  |  |     #[template_callback]
 | 
					
						
							|  |  |  |     fn back_button_clicked(&self, _: >k::Button) {
 | 
					
						
							|  |  |  |         self.imp().search_entry.reset();
 | 
					
						
							|  |  |  |     }
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     #[template_callback]
 | 
					
						
							|  |  |  |     fn edit_button_clicked(&self, _: >k::Button) {
 | 
					
						
							|  |  |  |         if let Some(tag) = self.imp().search_entry.tags().first() {
 | 
					
						
							|  |  |  |             match tag {
 | 
					
						
							|  |  |  |                 Tag::Composer(person) | Tag::Performer(person) => {
 | 
					
						
							|  |  |  |                     self.navigation()
 | 
					
						
							|  |  |  |                         .push(&MusicusPersonEditor::new(Some(person)));
 | 
					
						
							|  |  |  |                 }
 | 
					
						
							|  |  |  |                 Tag::Ensemble(_) => todo!(),
 | 
					
						
							|  |  |  |                 Tag::Work(work) => self.navigation().push(&MusicusWorkEditor::new(
 | 
					
						
							|  |  |  |                     &self.navigation(),
 | 
					
						
							|  |  |  |                     &self.library(),
 | 
					
						
							|  |  |  |                     Some(work),
 | 
					
						
							|  |  |  |                 )),
 | 
					
						
							|  |  |  |             }
 | 
					
						
							|  |  |  |         }
 | 
					
						
							|  |  |  |     }
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-09-21 17:19:31 +02:00
										 |  |  |     #[template_callback]
 | 
					
						
							|  |  |  |     fn play(&self, _: >k::Button) {
 | 
					
						
							|  |  |  |         log::info!("Play button clicked");
 | 
					
						
							| 
									
										
										
										
											2023-10-07 22:49:20 +02:00
										 |  |  |         self.player().play();
 | 
					
						
							| 
									
										
										
										
											2023-09-21 17:19:31 +02:00
										 |  |  |     }
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     #[template_callback]
 | 
					
						
							| 
									
										
										
										
											2023-09-30 00:22:33 +02:00
										 |  |  |     fn select(&self, search_entry: &MusicusSearchEntry) {
 | 
					
						
							| 
									
										
										
										
											2023-10-08 00:16:41 +02:00
										 |  |  |         let imp = self.imp();
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-06-05 13:26:47 +02:00
										 |  |  |         let (composer, performer, ensemble, work, recording, album) = {
 | 
					
						
							| 
									
										
										
										
											2023-10-08 00:30:30 +02:00
										 |  |  |             (
 | 
					
						
							| 
									
										
										
										
											2023-10-08 15:11:47 +02:00
										 |  |  |                 imp.composers.borrow().first().cloned(),
 | 
					
						
							|  |  |  |                 imp.performers.borrow().first().cloned(),
 | 
					
						
							| 
									
										
										
										
											2023-10-08 00:30:30 +02:00
										 |  |  |                 imp.ensembles.borrow().first().cloned(),
 | 
					
						
							|  |  |  |                 imp.works.borrow().first().cloned(),
 | 
					
						
							| 
									
										
										
										
											2023-10-11 12:04:49 +02:00
										 |  |  |                 imp.recordings.borrow().first().cloned(),
 | 
					
						
							| 
									
										
										
										
											2024-06-05 13:26:47 +02:00
										 |  |  |                 imp.albums.borrow().first().cloned(),
 | 
					
						
							| 
									
										
										
										
											2023-10-08 00:30:30 +02:00
										 |  |  |             )
 | 
					
						
							|  |  |  |         };
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-10-08 15:11:47 +02:00
										 |  |  |         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));
 | 
					
						
							| 
									
										
										
										
											2023-10-08 00:30:30 +02:00
										 |  |  |         } 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));
 | 
					
						
							| 
									
										
										
										
											2023-10-11 12:04:49 +02:00
										 |  |  |         } else if let Some(recording) = recording {
 | 
					
						
							|  |  |  |             self.play_recording(&recording);
 | 
					
						
							| 
									
										
										
										
											2024-06-05 13:26:47 +02:00
										 |  |  |         } else if let Some(album) = album {
 | 
					
						
							|  |  |  |             self.show_album(&album);
 | 
					
						
							| 
									
										
										
										
											2023-10-08 00:16:41 +02:00
										 |  |  |         }
 | 
					
						
							| 
									
										
										
										
											2023-09-21 17:19:31 +02:00
										 |  |  |     }
 | 
					
						
							| 
									
										
										
										
											2023-10-07 22:49:20 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-10-11 12:04:49 +02:00
										 |  |  |     #[template_callback]
 | 
					
						
							|  |  |  |     fn tile_selected(&self, tile: >k::FlowBoxChild, _: >k::FlowBox) {
 | 
					
						
							|  |  |  |         self.imp()
 | 
					
						
							|  |  |  |             .search_entry
 | 
					
						
							|  |  |  |             .add_tag(tile.downcast_ref::<MusicusTagTile>().unwrap().tag().clone())
 | 
					
						
							|  |  |  |     }
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     #[template_callback]
 | 
					
						
							|  |  |  |     fn recording_selected(&self, tile: >k::FlowBoxChild, _: >k::FlowBox) {
 | 
					
						
							|  |  |  |         self.play_recording(
 | 
					
						
							|  |  |  |             tile.downcast_ref::<MusicusRecordingTile>()
 | 
					
						
							|  |  |  |                 .unwrap()
 | 
					
						
							|  |  |  |                 .recording(),
 | 
					
						
							|  |  |  |         );
 | 
					
						
							|  |  |  |     }
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-06-05 13:26:47 +02:00
										 |  |  |     #[template_callback]
 | 
					
						
							|  |  |  |     fn album_selected(&self, tile: >k::FlowBoxChild, _: >k::FlowBox) {
 | 
					
						
							|  |  |  |         self.show_album(tile.downcast_ref::<MusicusAlbumTile>().unwrap().album());
 | 
					
						
							|  |  |  |     }
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-10-11 12:04:49 +02:00
										 |  |  |     fn play_recording(&self, recording: &Recording) {
 | 
					
						
							| 
									
										
										
										
											2024-03-23 18:06:46 +01:00
										 |  |  |         let tracks = &recording.tracks;
 | 
					
						
							| 
									
										
										
										
											2023-10-25 17:45:32 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |         if tracks.is_empty() {
 | 
					
						
							|  |  |  |             log::warn!("Ignoring recording without tracks being added to the playlist.");
 | 
					
						
							|  |  |  |             return;
 | 
					
						
							|  |  |  |         }
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         let title = format!(
 | 
					
						
							|  |  |  |             "{}: {}",
 | 
					
						
							| 
									
										
										
										
											2024-03-23 18:06:46 +01:00
										 |  |  |             recording.work.composers_string(),
 | 
					
						
							|  |  |  |             recording.work.name.get(),
 | 
					
						
							| 
									
										
										
										
											2023-10-25 17:45:32 +02:00
										 |  |  |         );
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-03-23 18:06:46 +01:00
										 |  |  |         let performances = recording.performers_string();
 | 
					
						
							| 
									
										
										
										
											2023-10-25 17:45:32 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |         let mut items = Vec::new();
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         if tracks.len() == 1 {
 | 
					
						
							|  |  |  |             items.push(PlaylistItem::new(
 | 
					
						
							| 
									
										
										
										
											2023-10-27 14:15:05 +02:00
										 |  |  |                 true,
 | 
					
						
							| 
									
										
										
										
											2023-10-25 17:45:32 +02:00
										 |  |  |                 &title,
 | 
					
						
							| 
									
										
										
										
											2024-03-23 18:06:46 +01:00
										 |  |  |                 Some(&performances),
 | 
					
						
							| 
									
										
										
										
											2023-10-25 17:45:32 +02:00
										 |  |  |                 None,
 | 
					
						
							|  |  |  |                 &tracks[0].path,
 | 
					
						
							| 
									
										
										
										
											2023-10-27 14:15:05 +02:00
										 |  |  |             ));
 | 
					
						
							| 
									
										
										
										
											2023-10-25 17:45:32 +02:00
										 |  |  |         } else {
 | 
					
						
							|  |  |  |             let mut tracks = tracks.into_iter();
 | 
					
						
							|  |  |  |             let first_track = tracks.next().unwrap();
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-11-24 14:26:12 +01:00
										 |  |  |             let track_title = |track: &Track, number: usize| -> String {
 | 
					
						
							|  |  |  |                 let title = track
 | 
					
						
							| 
									
										
										
										
											2024-03-23 18:06:46 +01:00
										 |  |  |                     .works
 | 
					
						
							| 
									
										
										
										
											2023-10-25 17:45:32 +02:00
										 |  |  |                     .iter()
 | 
					
						
							| 
									
										
										
										
											2024-03-23 18:06:46 +01:00
										 |  |  |                     .map(|w| w.name.get().to_string())
 | 
					
						
							| 
									
										
										
										
											2023-10-25 17:45:32 +02:00
										 |  |  |                     .collect::<Vec<String>>()
 | 
					
						
							| 
									
										
										
										
											2023-11-24 14:26:12 +01:00
										 |  |  |                     .join(", ");
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |                 if title.is_empty() {
 | 
					
						
							|  |  |  |                     format!("Track {number}")
 | 
					
						
							|  |  |  |                 } else {
 | 
					
						
							|  |  |  |                     title
 | 
					
						
							|  |  |  |                 }
 | 
					
						
							| 
									
										
										
										
											2023-10-25 17:45:32 +02:00
										 |  |  |             };
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |             items.push(PlaylistItem::new(
 | 
					
						
							| 
									
										
										
										
											2023-10-27 14:15:05 +02:00
										 |  |  |                 true,
 | 
					
						
							| 
									
										
										
										
											2023-10-25 17:45:32 +02:00
										 |  |  |                 &title,
 | 
					
						
							| 
									
										
										
										
											2024-03-23 18:06:46 +01:00
										 |  |  |                 Some(&performances),
 | 
					
						
							| 
									
										
										
										
											2023-11-24 14:26:12 +01:00
										 |  |  |                 Some(&track_title(&first_track, 1)),
 | 
					
						
							| 
									
										
										
										
											2023-10-25 17:45:32 +02:00
										 |  |  |                 &first_track.path,
 | 
					
						
							|  |  |  |             ));
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-11-24 14:26:12 +01:00
										 |  |  |             for (index, track) in tracks.enumerate() {
 | 
					
						
							| 
									
										
										
										
											2023-10-27 14:15:05 +02:00
										 |  |  |                 items.push(PlaylistItem::new(
 | 
					
						
							|  |  |  |                     false,
 | 
					
						
							|  |  |  |                     &title,
 | 
					
						
							| 
									
										
										
										
											2024-03-23 18:06:46 +01:00
										 |  |  |                     Some(&performances),
 | 
					
						
							| 
									
										
										
										
											2023-11-24 14:26:12 +01:00
										 |  |  |                     // track number = track index + 1 (first track) + 1 (zero based)
 | 
					
						
							|  |  |  |                     Some(&track_title(&track, index + 2)),
 | 
					
						
							| 
									
										
										
										
											2023-10-27 14:15:05 +02:00
										 |  |  |                     &track.path,
 | 
					
						
							|  |  |  |                 ));
 | 
					
						
							| 
									
										
										
										
											2023-10-25 17:45:32 +02:00
										 |  |  |             }
 | 
					
						
							|  |  |  |         }
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         self.player().append(items);
 | 
					
						
							| 
									
										
										
										
											2023-10-11 12:04:49 +02:00
										 |  |  |     }
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-06-05 13:26:47 +02:00
										 |  |  |     fn show_album(&self, _album: &Album) {
 | 
					
						
							|  |  |  |         todo!("Show album");
 | 
					
						
							|  |  |  |     }
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-10-07 22:49:20 +02:00
										 |  |  |     fn query(&self, query: &LibraryQuery) {
 | 
					
						
							| 
									
										
										
										
											2023-10-07 23:13:32 +02:00
										 |  |  |         let imp = self.imp();
 | 
					
						
							| 
									
										
										
										
											2024-03-23 18:06:46 +01:00
										 |  |  |         let results = self.library().query(query).unwrap();
 | 
					
						
							| 
									
										
										
										
											2023-10-07 22:49:20 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-10-07 23:13:32 +02:00
										 |  |  |         for flowbox in [
 | 
					
						
							| 
									
										
										
										
											2023-10-08 15:11:47 +02:00
										 |  |  |             &imp.composers_flow_box,
 | 
					
						
							|  |  |  |             &imp.performers_flow_box,
 | 
					
						
							| 
									
										
										
										
											2023-10-07 23:13:32 +02:00
										 |  |  |             &imp.ensembles_flow_box,
 | 
					
						
							|  |  |  |             &imp.works_flow_box,
 | 
					
						
							|  |  |  |             &imp.recordings_flow_box,
 | 
					
						
							| 
									
										
										
										
											2024-06-05 13:26:47 +02:00
										 |  |  |             &imp.albums_flow_box,
 | 
					
						
							| 
									
										
										
										
											2023-10-07 23:13:32 +02:00
										 |  |  |         ] {
 | 
					
						
							|  |  |  |             while let Some(widget) = flowbox.first_child() {
 | 
					
						
							|  |  |  |                 flowbox.remove(&widget);
 | 
					
						
							|  |  |  |             }
 | 
					
						
							| 
									
										
										
										
											2023-10-07 22:49:20 +02:00
										 |  |  |         }
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-06-05 19:03:04 +02:00
										 |  |  |         if let Some(tag) = imp.search_entry.tags().first() {
 | 
					
						
							|  |  |  |             match tag {
 | 
					
						
							|  |  |  |                 Tag::Composer(person) | Tag::Performer(person) => {
 | 
					
						
							|  |  |  |                     imp.title_label.set_text(&person.name.get());
 | 
					
						
							|  |  |  |                     imp.subtitle_label.set_visible(false);
 | 
					
						
							|  |  |  |                 }
 | 
					
						
							|  |  |  |                 Tag::Ensemble(ensemble) => {
 | 
					
						
							|  |  |  |                     imp.title_label.set_text(&ensemble.name.get());
 | 
					
						
							|  |  |  |                     imp.subtitle_label.set_visible(false);
 | 
					
						
							|  |  |  |                 }
 | 
					
						
							|  |  |  |                 Tag::Work(work) => {
 | 
					
						
							|  |  |  |                     imp.title_label.set_text(&work.name.get());
 | 
					
						
							|  |  |  |                     imp.subtitle_label.set_text(&work.composers_string());
 | 
					
						
							|  |  |  |                     imp.subtitle_label.set_visible(true);
 | 
					
						
							|  |  |  |                 }
 | 
					
						
							|  |  |  |             }
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |             imp.header_box.set_visible(true);
 | 
					
						
							|  |  |  |         } else {
 | 
					
						
							|  |  |  |             imp.header_box.set_visible(false);
 | 
					
						
							|  |  |  |         }
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-10-07 23:13:32 +02:00
										 |  |  |         if results.is_empty() {
 | 
					
						
							|  |  |  |             imp.stack.set_visible_child_name("empty");
 | 
					
						
							|  |  |  |         } else {
 | 
					
						
							|  |  |  |             imp.stack.set_visible_child_name("results");
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-10-08 15:11:47 +02:00
										 |  |  |             imp.composers_flow_box
 | 
					
						
							|  |  |  |                 .set_visible(!results.composers.is_empty());
 | 
					
						
							|  |  |  |             imp.performers_flow_box
 | 
					
						
							|  |  |  |                 .set_visible(!results.performers.is_empty());
 | 
					
						
							| 
									
										
										
										
											2023-10-07 23:13:32 +02:00
										 |  |  |             imp.ensembles_flow_box
 | 
					
						
							|  |  |  |                 .set_visible(!results.ensembles.is_empty());
 | 
					
						
							|  |  |  |             imp.works_flow_box.set_visible(!results.works.is_empty());
 | 
					
						
							|  |  |  |             imp.recordings_flow_box
 | 
					
						
							|  |  |  |                 .set_visible(!results.recordings.is_empty());
 | 
					
						
							| 
									
										
										
										
											2024-06-05 13:26:47 +02:00
										 |  |  |             imp.albums_flow_box.set_visible(!results.albums.is_empty());
 | 
					
						
							| 
									
										
										
										
											2023-10-07 23:13:32 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-10-08 15:11:47 +02:00
										 |  |  |             for composer in &results.composers {
 | 
					
						
							|  |  |  |                 imp.composers_flow_box
 | 
					
						
							| 
									
										
										
										
											2023-10-08 16:40:59 +02:00
										 |  |  |                     .append(&MusicusTagTile::new(Tag::Composer(composer.clone())));
 | 
					
						
							| 
									
										
										
										
											2023-10-08 15:11:47 +02:00
										 |  |  |             }
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |             for performer in &results.performers {
 | 
					
						
							|  |  |  |                 imp.performers_flow_box
 | 
					
						
							| 
									
										
										
										
											2023-10-08 16:40:59 +02:00
										 |  |  |                     .append(&MusicusTagTile::new(Tag::Performer(performer.clone())));
 | 
					
						
							| 
									
										
										
										
											2023-10-07 23:13:32 +02:00
										 |  |  |             }
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-10-08 00:16:41 +02:00
										 |  |  |             for ensemble in &results.ensembles {
 | 
					
						
							| 
									
										
										
										
											2023-10-07 23:13:32 +02:00
										 |  |  |                 imp.ensembles_flow_box
 | 
					
						
							| 
									
										
										
										
											2023-10-08 16:40:59 +02:00
										 |  |  |                     .append(&MusicusTagTile::new(Tag::Ensemble(ensemble.clone())));
 | 
					
						
							| 
									
										
										
										
											2023-10-07 23:13:32 +02:00
										 |  |  |             }
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-10-08 00:16:41 +02:00
										 |  |  |             for work in &results.works {
 | 
					
						
							| 
									
										
										
										
											2023-10-08 16:40:59 +02:00
										 |  |  |                 imp.works_flow_box
 | 
					
						
							|  |  |  |                     .append(&MusicusTagTile::new(Tag::Work(work.clone())));
 | 
					
						
							| 
									
										
										
										
											2023-10-07 23:13:32 +02:00
										 |  |  |             }
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-10-08 00:16:41 +02:00
										 |  |  |             for recording in &results.recordings {
 | 
					
						
							| 
									
										
										
										
											2023-10-08 16:40:59 +02:00
										 |  |  |                 imp.recordings_flow_box
 | 
					
						
							| 
									
										
										
										
											2024-03-23 18:06:46 +01:00
										 |  |  |                     .append(&MusicusRecordingTile::new(recording));
 | 
					
						
							| 
									
										
										
										
											2023-10-07 23:13:32 +02:00
										 |  |  |             }
 | 
					
						
							| 
									
										
										
										
											2023-10-08 00:16:41 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-06-05 13:26:47 +02:00
										 |  |  |             for album in &results.albums {
 | 
					
						
							|  |  |  |                 imp.albums_flow_box.append(&MusicusAlbumTile::new(album));
 | 
					
						
							|  |  |  |             }
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-10-08 15:11:47 +02:00
										 |  |  |             imp.composers.replace(results.composers);
 | 
					
						
							|  |  |  |             imp.performers.replace(results.performers);
 | 
					
						
							| 
									
										
										
										
											2023-10-08 00:16:41 +02:00
										 |  |  |             imp.ensembles.replace(results.ensembles);
 | 
					
						
							|  |  |  |             imp.works.replace(results.works);
 | 
					
						
							|  |  |  |             imp.recordings.replace(results.recordings);
 | 
					
						
							| 
									
										
										
										
											2024-06-05 13:26:47 +02:00
										 |  |  |             imp.albums.replace(results.albums);
 | 
					
						
							| 
									
										
										
										
											2023-10-07 23:13:32 +02:00
										 |  |  |         }
 | 
					
						
							| 
									
										
										
										
											2023-10-07 22:49:20 +02:00
										 |  |  |     }
 | 
					
						
							| 
									
										
										
										
											2023-09-20 13:49:02 +02:00
										 |  |  | }
 |