2025-01-15 11:23:04 +01:00
|
|
|
use adw::subclass::prelude::*;
|
|
|
|
|
use gtk::glib;
|
2023-11-07 16:21:47 +01:00
|
|
|
use std::cell::OnceCell;
|
|
|
|
|
|
2025-01-15 11:23:04 +01:00
|
|
|
use crate::{
|
|
|
|
|
editor::{
|
|
|
|
|
ensemble_editor::MusicusEnsembleEditor, instrument_editor::MusicusInstrumentEditor,
|
|
|
|
|
person_editor::MusicusPersonEditor, recording_editor::MusicusRecordingEditor,
|
|
|
|
|
role_editor::MusicusRoleEditor, work_editor::MusicusWorkEditor,
|
|
|
|
|
},
|
|
|
|
|
library::MusicusLibrary,
|
|
|
|
|
};
|
2024-04-01 16:57:34 +02:00
|
|
|
|
2023-11-07 16:21:47 +01:00
|
|
|
mod imp {
|
|
|
|
|
use super::*;
|
|
|
|
|
|
2025-01-15 11:23:04 +01:00
|
|
|
#[derive(Debug, Default, gtk::CompositeTemplate)]
|
2023-11-07 16:21:47 +01:00
|
|
|
#[template(file = "data/ui/library_manager.blp")]
|
|
|
|
|
pub struct LibraryManager {
|
2025-01-15 11:23:04 +01:00
|
|
|
pub navigation: OnceCell<adw::NavigationView>,
|
2023-11-07 16:21:47 +01:00
|
|
|
pub library: OnceCell<MusicusLibrary>,
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[glib::object_subclass]
|
|
|
|
|
impl ObjectSubclass for LibraryManager {
|
|
|
|
|
const NAME: &'static str = "MusicusLibraryManager";
|
|
|
|
|
type Type = super::LibraryManager;
|
|
|
|
|
type ParentType = adw::NavigationPage;
|
|
|
|
|
|
|
|
|
|
fn class_init(klass: &mut Self::Class) {
|
|
|
|
|
klass.bind_template();
|
|
|
|
|
klass.bind_template_instance_callbacks();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fn instance_init(obj: &glib::subclass::InitializingObject<Self>) {
|
|
|
|
|
obj.init_template();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2024-06-05 19:03:04 +02:00
|
|
|
impl ObjectImpl for LibraryManager {}
|
2023-11-07 16:21:47 +01:00
|
|
|
impl WidgetImpl for LibraryManager {}
|
|
|
|
|
impl NavigationPageImpl for LibraryManager {}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
glib::wrapper! {
|
|
|
|
|
pub struct LibraryManager(ObjectSubclass<imp::LibraryManager>)
|
|
|
|
|
@extends gtk::Widget, adw::NavigationPage;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[gtk::template_callbacks]
|
|
|
|
|
impl LibraryManager {
|
2025-01-15 11:23:04 +01:00
|
|
|
pub fn new(navigation: &adw::NavigationView, library: &MusicusLibrary) -> Self {
|
|
|
|
|
let obj: Self = glib::Object::new();
|
|
|
|
|
let imp = obj.imp();
|
|
|
|
|
|
|
|
|
|
imp.navigation.set(navigation.to_owned()).unwrap();
|
|
|
|
|
imp.library.set(library.to_owned()).unwrap();
|
|
|
|
|
|
|
|
|
|
obj
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[template_callback]
|
|
|
|
|
fn add_person(&self, _: >k::Button) {
|
|
|
|
|
self.imp()
|
|
|
|
|
.navigation
|
|
|
|
|
.get()
|
|
|
|
|
.unwrap()
|
|
|
|
|
.push(&MusicusPersonEditor::new(
|
|
|
|
|
&self.imp().navigation.get().unwrap(),
|
|
|
|
|
&self.imp().library.get().unwrap(),
|
|
|
|
|
None,
|
|
|
|
|
));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[template_callback]
|
|
|
|
|
fn add_role(&self, _: >k::Button) {
|
|
|
|
|
self.imp()
|
|
|
|
|
.navigation
|
|
|
|
|
.get()
|
|
|
|
|
.unwrap()
|
|
|
|
|
.push(&MusicusRoleEditor::new(
|
|
|
|
|
&self.imp().navigation.get().unwrap(),
|
|
|
|
|
&self.imp().library.get().unwrap(),
|
|
|
|
|
None,
|
|
|
|
|
));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[template_callback]
|
|
|
|
|
fn add_instrument(&self, _: >k::Button) {
|
|
|
|
|
self.imp()
|
|
|
|
|
.navigation
|
|
|
|
|
.get()
|
|
|
|
|
.unwrap()
|
|
|
|
|
.push(&MusicusInstrumentEditor::new(
|
|
|
|
|
&self.imp().navigation.get().unwrap(),
|
|
|
|
|
&self.imp().library.get().unwrap(),
|
|
|
|
|
None,
|
|
|
|
|
));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[template_callback]
|
|
|
|
|
fn add_work(&self, _: >k::Button) {
|
|
|
|
|
self.imp()
|
|
|
|
|
.navigation
|
|
|
|
|
.get()
|
|
|
|
|
.unwrap()
|
|
|
|
|
.push(&MusicusWorkEditor::new(
|
|
|
|
|
&self.imp().navigation.get().unwrap(),
|
|
|
|
|
&self.imp().library.get().unwrap(),
|
|
|
|
|
None,
|
|
|
|
|
));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[template_callback]
|
|
|
|
|
fn add_ensemble(&self, _: >k::Button) {
|
|
|
|
|
self.imp()
|
|
|
|
|
.navigation
|
|
|
|
|
.get()
|
|
|
|
|
.unwrap()
|
|
|
|
|
.push(&MusicusEnsembleEditor::new(
|
|
|
|
|
&self.imp().navigation.get().unwrap(),
|
|
|
|
|
&self.imp().library.get().unwrap(),
|
|
|
|
|
None,
|
|
|
|
|
));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[template_callback]
|
|
|
|
|
fn add_recording(&self, _: >k::Button) {
|
|
|
|
|
self.imp()
|
|
|
|
|
.navigation
|
|
|
|
|
.get()
|
|
|
|
|
.unwrap()
|
|
|
|
|
.push(&MusicusRecordingEditor::new(
|
|
|
|
|
&self.imp().navigation.get().unwrap(),
|
|
|
|
|
&self.imp().library.get().unwrap(),
|
|
|
|
|
None,
|
|
|
|
|
));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[template_callback]
|
|
|
|
|
fn add_medium(&self, _: >k::Button) {
|
|
|
|
|
todo!("Medium import");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[template_callback]
|
|
|
|
|
fn add_album(&self, _: >k::Button) {
|
|
|
|
|
todo!("Album editor");
|
|
|
|
|
// self.imp()
|
|
|
|
|
// .navigation
|
|
|
|
|
// .get()
|
|
|
|
|
// .unwrap()
|
|
|
|
|
// .push(&MusicusAlbumEditor::new(
|
|
|
|
|
// &self.imp().navigation.get().unwrap(),
|
|
|
|
|
// &self.imp().library.get().unwrap(),
|
|
|
|
|
// None,
|
|
|
|
|
// ));
|
2023-11-07 16:21:47 +01:00
|
|
|
}
|
|
|
|
|
}
|