mirror of
https://github.com/johrpan/musicus.git
synced 2025-10-26 19:57:25 +01:00
tracks editor: Report import errors
This commit is contained in:
parent
43b07c73dc
commit
0149da36e6
5 changed files with 58 additions and 32 deletions
|
|
@ -142,9 +142,13 @@ impl AlbumPage {
|
||||||
.set_label(&album.performers_string());
|
.set_label(&album.performers_string());
|
||||||
|
|
||||||
for recording in &album.recordings {
|
for recording in &album.recordings {
|
||||||
obj.imp()
|
obj.imp().recordings_flow_box.append(&RecordingTile::new(
|
||||||
.recordings_flow_box
|
toast_overlay,
|
||||||
.append(&RecordingTile::new(navigation, library, player, recording));
|
navigation,
|
||||||
|
library,
|
||||||
|
player,
|
||||||
|
recording,
|
||||||
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
obj.imp().album.set(album).unwrap();
|
obj.imp().album.set(album).unwrap();
|
||||||
|
|
|
||||||
|
|
@ -7,6 +7,7 @@ use std::{
|
||||||
};
|
};
|
||||||
|
|
||||||
use adw::{prelude::*, subclass::prelude::*};
|
use adw::{prelude::*, subclass::prelude::*};
|
||||||
|
use anyhow::Result;
|
||||||
use gettextrs::gettext;
|
use gettextrs::gettext;
|
||||||
use gtk::{
|
use gtk::{
|
||||||
gio,
|
gio,
|
||||||
|
|
@ -20,6 +21,7 @@ use crate::{
|
||||||
editor::recording::RecordingEditor,
|
editor::recording::RecordingEditor,
|
||||||
library::Library,
|
library::Library,
|
||||||
selector::recording::RecordingSelectorPopover,
|
selector::recording::RecordingSelectorPopover,
|
||||||
|
util,
|
||||||
};
|
};
|
||||||
|
|
||||||
mod imp {
|
mod imp {
|
||||||
|
|
@ -29,6 +31,8 @@ mod imp {
|
||||||
#[properties(wrapper_type = super::TracksEditor)]
|
#[properties(wrapper_type = super::TracksEditor)]
|
||||||
#[template(file = "data/ui/editor/tracks.blp")]
|
#[template(file = "data/ui/editor/tracks.blp")]
|
||||||
pub struct TracksEditor {
|
pub struct TracksEditor {
|
||||||
|
#[property(get, construct_only)]
|
||||||
|
pub toast_overlay: OnceCell<adw::ToastOverlay>,
|
||||||
#[property(get, construct_only)]
|
#[property(get, construct_only)]
|
||||||
pub navigation: OnceCell<adw::NavigationView>,
|
pub navigation: OnceCell<adw::NavigationView>,
|
||||||
#[property(get, construct_only)]
|
#[property(get, construct_only)]
|
||||||
|
|
@ -131,11 +135,13 @@ glib::wrapper! {
|
||||||
#[gtk::template_callbacks]
|
#[gtk::template_callbacks]
|
||||||
impl TracksEditor {
|
impl TracksEditor {
|
||||||
pub fn new(
|
pub fn new(
|
||||||
|
toast_overlay: &adw::ToastOverlay,
|
||||||
navigation: &adw::NavigationView,
|
navigation: &adw::NavigationView,
|
||||||
library: &Library,
|
library: &Library,
|
||||||
recording: Option<Recording>,
|
recording: Option<Recording>,
|
||||||
) -> Self {
|
) -> Self {
|
||||||
let obj: Self = glib::Object::builder()
|
let obj: Self = glib::Object::builder()
|
||||||
|
.property("toast-overlay", toast_overlay)
|
||||||
.property("navigation", navigation)
|
.property("navigation", navigation)
|
||||||
.property("library", library)
|
.property("library", library)
|
||||||
.build();
|
.build();
|
||||||
|
|
@ -306,37 +312,43 @@ impl TracksEditor {
|
||||||
#[template_callback]
|
#[template_callback]
|
||||||
fn save(&self) {
|
fn save(&self) {
|
||||||
if let Some(recording) = &*self.imp().recording.borrow() {
|
if let Some(recording) = &*self.imp().recording.borrow() {
|
||||||
for track in self.imp().removed_tracks.borrow_mut().drain(..) {
|
if let Err(err) = self.import(recording) {
|
||||||
self.library().delete_track(&track).unwrap();
|
util::error_toast("Failed to import tracks", err, &self.toast_overlay());
|
||||||
}
|
|
||||||
|
|
||||||
for (index, track_row) in self.imp().track_rows.borrow_mut().drain(..).enumerate() {
|
|
||||||
let track_data = track_row.track_data();
|
|
||||||
|
|
||||||
match track_data.location {
|
|
||||||
TrackLocation::Undefined => {
|
|
||||||
log::error!("Failed to save track: Undefined track location.");
|
|
||||||
}
|
|
||||||
TrackLocation::Library(track) => self
|
|
||||||
.library()
|
|
||||||
.update_track(&track.track_id, index as i32, track_data.parts)
|
|
||||||
.unwrap(),
|
|
||||||
TrackLocation::System(path) => {
|
|
||||||
self.library()
|
|
||||||
.import_track(
|
|
||||||
&path,
|
|
||||||
&recording.recording_id,
|
|
||||||
index as i32,
|
|
||||||
track_data.parts,
|
|
||||||
)
|
|
||||||
.unwrap();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
self.imp().track_list.remove(&track_row);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
self.navigation().pop();
|
self.navigation().pop();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn import(&self, recording: &Recording) -> Result<()> {
|
||||||
|
for track in self.imp().removed_tracks.borrow_mut().drain(..) {
|
||||||
|
self.library().delete_track(&track)?;
|
||||||
|
}
|
||||||
|
|
||||||
|
for (index, track_row) in self.imp().track_rows.borrow_mut().drain(..).enumerate() {
|
||||||
|
let track_data = track_row.track_data();
|
||||||
|
|
||||||
|
match track_data.location {
|
||||||
|
TrackLocation::Undefined => {
|
||||||
|
log::error!("Failed to save track: Undefined track location.");
|
||||||
|
}
|
||||||
|
TrackLocation::Library(track) => {
|
||||||
|
self.library()
|
||||||
|
.update_track(&track.track_id, index as i32, track_data.parts)?
|
||||||
|
}
|
||||||
|
TrackLocation::System(path) => {
|
||||||
|
self.library().import_track(
|
||||||
|
&path,
|
||||||
|
&recording.recording_id,
|
||||||
|
index as i32,
|
||||||
|
track_data.parts,
|
||||||
|
)?;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
self.imp().track_list.remove(&track_row);
|
||||||
|
}
|
||||||
|
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -21,6 +21,7 @@ mod imp {
|
||||||
#[template_child]
|
#[template_child]
|
||||||
pub performances_label: TemplateChild<gtk::Label>,
|
pub performances_label: TemplateChild<gtk::Label>,
|
||||||
|
|
||||||
|
pub toast_overlay: OnceCell<adw::ToastOverlay>,
|
||||||
pub navigation: OnceCell<adw::NavigationView>,
|
pub navigation: OnceCell<adw::NavigationView>,
|
||||||
pub library: OnceCell<Library>,
|
pub library: OnceCell<Library>,
|
||||||
pub player: OnceCell<Player>,
|
pub player: OnceCell<Player>,
|
||||||
|
|
@ -76,6 +77,7 @@ mod imp {
|
||||||
let edit_tracks_action = gio::ActionEntry::builder("edit-tracks")
|
let edit_tracks_action = gio::ActionEntry::builder("edit-tracks")
|
||||||
.activate(move |_, _, _| {
|
.activate(move |_, _, _| {
|
||||||
obj.imp().navigation.get().unwrap().push(&TracksEditor::new(
|
obj.imp().navigation.get().unwrap().push(&TracksEditor::new(
|
||||||
|
obj.imp().toast_overlay.get().unwrap(),
|
||||||
obj.imp().navigation.get().unwrap(),
|
obj.imp().navigation.get().unwrap(),
|
||||||
obj.imp().library.get().unwrap(),
|
obj.imp().library.get().unwrap(),
|
||||||
Some(obj.imp().recording.get().unwrap().clone()),
|
Some(obj.imp().recording.get().unwrap().clone()),
|
||||||
|
|
@ -100,6 +102,7 @@ glib::wrapper! {
|
||||||
|
|
||||||
impl RecordingTile {
|
impl RecordingTile {
|
||||||
pub fn new(
|
pub fn new(
|
||||||
|
toast_overlay: &adw::ToastOverlay,
|
||||||
navigation: &adw::NavigationView,
|
navigation: &adw::NavigationView,
|
||||||
library: &Library,
|
library: &Library,
|
||||||
player: &Player,
|
player: &Player,
|
||||||
|
|
@ -118,6 +121,7 @@ impl RecordingTile {
|
||||||
imp.performances_label
|
imp.performances_label
|
||||||
.set_label(&recording.performers_string());
|
.set_label(&recording.performers_string());
|
||||||
|
|
||||||
|
imp.toast_overlay.set(toast_overlay.to_owned()).unwrap();
|
||||||
imp.navigation.set(navigation.to_owned()).unwrap();
|
imp.navigation.set(navigation.to_owned()).unwrap();
|
||||||
imp.library.set(library.to_owned()).unwrap();
|
imp.library.set(library.to_owned()).unwrap();
|
||||||
imp.player.set(player.to_owned()).unwrap();
|
imp.player.set(player.to_owned()).unwrap();
|
||||||
|
|
|
||||||
|
|
@ -514,6 +514,7 @@ impl SearchPage {
|
||||||
|
|
||||||
for recording in &results.recordings {
|
for recording in &results.recordings {
|
||||||
imp.recordings_flow_box.append(&RecordingTile::new(
|
imp.recordings_flow_box.append(&RecordingTile::new(
|
||||||
|
&self.toast_overlay(),
|
||||||
&self.navigation(),
|
&self.navigation(),
|
||||||
&self.library(),
|
&self.library(),
|
||||||
&self.player(),
|
&self.player(),
|
||||||
|
|
|
||||||
|
|
@ -71,7 +71,12 @@ mod imp {
|
||||||
let import_action = gio::ActionEntry::builder("import")
|
let import_action = gio::ActionEntry::builder("import")
|
||||||
.activate(move |_, _, _| {
|
.activate(move |_, _, _| {
|
||||||
if let Some(library) = &*obj.imp().library.borrow() {
|
if let Some(library) = &*obj.imp().library.borrow() {
|
||||||
let editor = TracksEditor::new(&obj.imp().navigation_view, library, None);
|
let editor = TracksEditor::new(
|
||||||
|
&obj.imp().toast_overlay,
|
||||||
|
&obj.imp().navigation_view,
|
||||||
|
library,
|
||||||
|
None,
|
||||||
|
);
|
||||||
obj.imp().navigation_view.push(&editor);
|
obj.imp().navigation_view.push(&editor);
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue