2025-01-15 11:23:04 +01:00
|
|
|
use crate::{
|
|
|
|
|
db::models::Recording, editor::recording_editor::MusicusRecordingEditor,
|
|
|
|
|
library::MusicusLibrary,
|
|
|
|
|
};
|
2024-03-23 18:06:46 +01:00
|
|
|
|
2025-02-16 08:46:40 +01:00
|
|
|
use gettextrs::gettext;
|
|
|
|
|
use gtk::{gio, glib, prelude::*, subclass::prelude::*};
|
|
|
|
|
use std::cell::OnceCell;
|
|
|
|
|
|
2023-10-08 16:40:59 +02:00
|
|
|
mod imp {
|
2025-02-16 17:12:47 +01:00
|
|
|
use crate::editor::tracks_editor::TracksEditor;
|
|
|
|
|
|
2023-10-08 16:40:59 +02:00
|
|
|
use super::*;
|
|
|
|
|
|
|
|
|
|
#[derive(Debug, Default, gtk::CompositeTemplate)]
|
|
|
|
|
#[template(file = "data/ui/recording_tile.blp")]
|
|
|
|
|
pub struct MusicusRecordingTile {
|
|
|
|
|
#[template_child]
|
|
|
|
|
pub composer_label: TemplateChild<gtk::Label>,
|
|
|
|
|
#[template_child]
|
|
|
|
|
pub work_label: TemplateChild<gtk::Label>,
|
|
|
|
|
#[template_child]
|
|
|
|
|
pub performances_label: TemplateChild<gtk::Label>,
|
|
|
|
|
|
2025-01-15 11:23:04 +01:00
|
|
|
pub navigation: OnceCell<adw::NavigationView>,
|
|
|
|
|
pub library: OnceCell<MusicusLibrary>,
|
2023-10-08 16:40:59 +02:00
|
|
|
pub recording: OnceCell<Recording>,
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[glib::object_subclass]
|
|
|
|
|
impl ObjectSubclass for MusicusRecordingTile {
|
|
|
|
|
const NAME: &'static str = "MusicusRecordingTile";
|
|
|
|
|
type Type = super::MusicusRecordingTile;
|
|
|
|
|
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();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2025-01-15 11:23:04 +01:00
|
|
|
impl ObjectImpl for MusicusRecordingTile {
|
|
|
|
|
fn constructed(&self) {
|
|
|
|
|
self.parent_constructed();
|
|
|
|
|
|
|
|
|
|
let obj = self.obj().to_owned();
|
2025-02-16 17:12:47 +01:00
|
|
|
let edit_recording_action = gio::ActionEntry::builder("edit-recording")
|
2025-01-15 11:23:04 +01:00
|
|
|
.activate(move |_, _, _| {
|
|
|
|
|
obj.imp()
|
|
|
|
|
.navigation
|
|
|
|
|
.get()
|
|
|
|
|
.unwrap()
|
|
|
|
|
.push(&MusicusRecordingEditor::new(
|
|
|
|
|
obj.imp().navigation.get().unwrap(),
|
|
|
|
|
obj.imp().library.get().unwrap(),
|
|
|
|
|
Some(&obj.imp().recording.get().unwrap()),
|
|
|
|
|
));
|
|
|
|
|
})
|
|
|
|
|
.build();
|
|
|
|
|
|
2025-02-16 17:12:47 +01:00
|
|
|
let obj = self.obj().to_owned();
|
|
|
|
|
let edit_tracks_action = gio::ActionEntry::builder("edit-tracks")
|
|
|
|
|
.activate(move |_, _, _| {
|
|
|
|
|
obj.imp().navigation.get().unwrap().push(&TracksEditor::new(
|
|
|
|
|
obj.imp().navigation.get().unwrap(),
|
|
|
|
|
obj.imp().library.get().unwrap(),
|
|
|
|
|
Some(obj.imp().recording.get().unwrap().clone()),
|
|
|
|
|
));
|
|
|
|
|
})
|
|
|
|
|
.build();
|
|
|
|
|
|
2025-01-15 11:23:04 +01:00
|
|
|
let actions = gio::SimpleActionGroup::new();
|
2025-02-16 17:12:47 +01:00
|
|
|
actions.add_action_entries([edit_recording_action, edit_tracks_action]);
|
2025-01-15 11:23:04 +01:00
|
|
|
self.obj().insert_action_group("recording", Some(&actions));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2023-10-08 16:40:59 +02:00
|
|
|
impl WidgetImpl for MusicusRecordingTile {}
|
|
|
|
|
impl FlowBoxChildImpl for MusicusRecordingTile {}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
glib::wrapper! {
|
|
|
|
|
pub struct MusicusRecordingTile(ObjectSubclass<imp::MusicusRecordingTile>)
|
|
|
|
|
@extends gtk::Widget, gtk::FlowBoxChild;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
impl MusicusRecordingTile {
|
2025-01-15 11:23:04 +01:00
|
|
|
pub fn new(
|
|
|
|
|
navigation: &adw::NavigationView,
|
|
|
|
|
library: &MusicusLibrary,
|
|
|
|
|
recording: &Recording,
|
|
|
|
|
) -> Self {
|
2023-10-08 16:40:59 +02:00
|
|
|
let obj: Self = glib::Object::new();
|
|
|
|
|
let imp = obj.imp();
|
|
|
|
|
|
2024-03-23 18:06:46 +01:00
|
|
|
imp.work_label.set_label(&recording.work.name.get());
|
2025-02-16 08:46:40 +01:00
|
|
|
imp.composer_label.set_label(
|
|
|
|
|
&recording
|
|
|
|
|
.work
|
|
|
|
|
.composers_string()
|
|
|
|
|
.unwrap_or_else(|| gettext("No composers")),
|
|
|
|
|
);
|
2025-01-15 11:23:04 +01:00
|
|
|
imp.performances_label
|
|
|
|
|
.set_label(&recording.performers_string());
|
2024-03-23 18:06:46 +01:00
|
|
|
|
2025-01-15 11:23:04 +01:00
|
|
|
imp.navigation.set(navigation.to_owned()).unwrap();
|
|
|
|
|
imp.library.set(library.to_owned()).unwrap();
|
|
|
|
|
imp.recording.set(recording.to_owned()).unwrap();
|
2023-10-08 16:40:59 +02:00
|
|
|
|
|
|
|
|
obj
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
pub fn recording(&self) -> &Recording {
|
|
|
|
|
self.imp().recording.get().unwrap()
|
|
|
|
|
}
|
|
|
|
|
}
|