mirror of
https://github.com/johrpan/musicus.git
synced 2025-10-25 20:37:24 +02: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());
|
||||
|
||||
for recording in &album.recordings {
|
||||
obj.imp()
|
||||
.recordings_flow_box
|
||||
.append(&RecordingTile::new(navigation, library, player, recording));
|
||||
obj.imp().recordings_flow_box.append(&RecordingTile::new(
|
||||
toast_overlay,
|
||||
navigation,
|
||||
library,
|
||||
player,
|
||||
recording,
|
||||
));
|
||||
}
|
||||
|
||||
obj.imp().album.set(album).unwrap();
|
||||
|
|
|
|||
|
|
@ -7,6 +7,7 @@ use std::{
|
|||
};
|
||||
|
||||
use adw::{prelude::*, subclass::prelude::*};
|
||||
use anyhow::Result;
|
||||
use gettextrs::gettext;
|
||||
use gtk::{
|
||||
gio,
|
||||
|
|
@ -20,6 +21,7 @@ use crate::{
|
|||
editor::recording::RecordingEditor,
|
||||
library::Library,
|
||||
selector::recording::RecordingSelectorPopover,
|
||||
util,
|
||||
};
|
||||
|
||||
mod imp {
|
||||
|
|
@ -29,6 +31,8 @@ mod imp {
|
|||
#[properties(wrapper_type = super::TracksEditor)]
|
||||
#[template(file = "data/ui/editor/tracks.blp")]
|
||||
pub struct TracksEditor {
|
||||
#[property(get, construct_only)]
|
||||
pub toast_overlay: OnceCell<adw::ToastOverlay>,
|
||||
#[property(get, construct_only)]
|
||||
pub navigation: OnceCell<adw::NavigationView>,
|
||||
#[property(get, construct_only)]
|
||||
|
|
@ -131,11 +135,13 @@ glib::wrapper! {
|
|||
#[gtk::template_callbacks]
|
||||
impl TracksEditor {
|
||||
pub fn new(
|
||||
toast_overlay: &adw::ToastOverlay,
|
||||
navigation: &adw::NavigationView,
|
||||
library: &Library,
|
||||
recording: Option<Recording>,
|
||||
) -> Self {
|
||||
let obj: Self = glib::Object::builder()
|
||||
.property("toast-overlay", toast_overlay)
|
||||
.property("navigation", navigation)
|
||||
.property("library", library)
|
||||
.build();
|
||||
|
|
@ -306,37 +312,43 @@ impl TracksEditor {
|
|||
#[template_callback]
|
||||
fn save(&self) {
|
||||
if let Some(recording) = &*self.imp().recording.borrow() {
|
||||
for track in self.imp().removed_tracks.borrow_mut().drain(..) {
|
||||
self.library().delete_track(&track).unwrap();
|
||||
}
|
||||
|
||||
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);
|
||||
if let Err(err) = self.import(recording) {
|
||||
util::error_toast("Failed to import tracks", err, &self.toast_overlay());
|
||||
}
|
||||
|
||||
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]
|
||||
pub performances_label: TemplateChild<gtk::Label>,
|
||||
|
||||
pub toast_overlay: OnceCell<adw::ToastOverlay>,
|
||||
pub navigation: OnceCell<adw::NavigationView>,
|
||||
pub library: OnceCell<Library>,
|
||||
pub player: OnceCell<Player>,
|
||||
|
|
@ -76,6 +77,7 @@ mod imp {
|
|||
let edit_tracks_action = gio::ActionEntry::builder("edit-tracks")
|
||||
.activate(move |_, _, _| {
|
||||
obj.imp().navigation.get().unwrap().push(&TracksEditor::new(
|
||||
obj.imp().toast_overlay.get().unwrap(),
|
||||
obj.imp().navigation.get().unwrap(),
|
||||
obj.imp().library.get().unwrap(),
|
||||
Some(obj.imp().recording.get().unwrap().clone()),
|
||||
|
|
@ -100,6 +102,7 @@ glib::wrapper! {
|
|||
|
||||
impl RecordingTile {
|
||||
pub fn new(
|
||||
toast_overlay: &adw::ToastOverlay,
|
||||
navigation: &adw::NavigationView,
|
||||
library: &Library,
|
||||
player: &Player,
|
||||
|
|
@ -118,6 +121,7 @@ impl RecordingTile {
|
|||
imp.performances_label
|
||||
.set_label(&recording.performers_string());
|
||||
|
||||
imp.toast_overlay.set(toast_overlay.to_owned()).unwrap();
|
||||
imp.navigation.set(navigation.to_owned()).unwrap();
|
||||
imp.library.set(library.to_owned()).unwrap();
|
||||
imp.player.set(player.to_owned()).unwrap();
|
||||
|
|
|
|||
|
|
@ -514,6 +514,7 @@ impl SearchPage {
|
|||
|
||||
for recording in &results.recordings {
|
||||
imp.recordings_flow_box.append(&RecordingTile::new(
|
||||
&self.toast_overlay(),
|
||||
&self.navigation(),
|
||||
&self.library(),
|
||||
&self.player(),
|
||||
|
|
|
|||
|
|
@ -71,7 +71,12 @@ mod imp {
|
|||
let import_action = gio::ActionEntry::builder("import")
|
||||
.activate(move |_, _, _| {
|
||||
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);
|
||||
}
|
||||
})
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue