mirror of
https://github.com/johrpan/musicus.git
synced 2025-10-26 19:57:25 +01:00
Use sanitized directory names
This commit is contained in:
parent
b45d1704c9
commit
641a6306ec
2 changed files with 27 additions and 15 deletions
|
|
@ -15,6 +15,7 @@ log = "0.4.14"
|
||||||
musicus_backend = { version = "0.1.0", path = "../backend" }
|
musicus_backend = { version = "0.1.0", path = "../backend" }
|
||||||
once_cell = "1.5.2"
|
once_cell = "1.5.2"
|
||||||
rand = "0.7.3"
|
rand = "0.7.3"
|
||||||
|
sanitize-filename = "0.3.0"
|
||||||
|
|
||||||
[dependencies.gdk]
|
[dependencies.gdk]
|
||||||
git = "https://github.com/gtk-rs/gtk4-rs/"
|
git = "https://github.com/gtk-rs/gtk4-rs/"
|
||||||
|
|
|
||||||
|
|
@ -27,7 +27,10 @@ pub struct MediumPreview {
|
||||||
|
|
||||||
impl Screen<(Arc<ImportSession>, Medium), ()> for MediumPreview {
|
impl Screen<(Arc<ImportSession>, Medium), ()> for MediumPreview {
|
||||||
/// Create a new medium preview screen.
|
/// Create a new medium preview screen.
|
||||||
fn new((session, medium): (Arc<ImportSession>, Medium), handle: NavigationHandle<()>) -> Rc<Self> {
|
fn new(
|
||||||
|
(session, medium): (Arc<ImportSession>, Medium),
|
||||||
|
handle: NavigationHandle<()>,
|
||||||
|
) -> Rc<Self> {
|
||||||
// Create UI
|
// Create UI
|
||||||
|
|
||||||
let builder = gtk::Builder::from_resource("/de/johrpan/musicus/ui/medium_preview.ui");
|
let builder = gtk::Builder::from_resource("/de/johrpan/musicus/ui/medium_preview.ui");
|
||||||
|
|
@ -66,12 +69,13 @@ impl Screen<(Arc<ImportSession>, Medium), ()> for MediumPreview {
|
||||||
});
|
});
|
||||||
}));
|
}));
|
||||||
|
|
||||||
this.import_button.connect_clicked(clone!(@weak this => move |_| {
|
this.import_button
|
||||||
spawn!(@clone this, async move {
|
.connect_clicked(clone!(@weak this => move |_| {
|
||||||
this.import().await.unwrap();
|
spawn!(@clone this, async move {
|
||||||
this.handle.pop(Some(()));
|
this.import().await.unwrap();
|
||||||
});
|
this.handle.pop(Some(()));
|
||||||
}));
|
});
|
||||||
|
}));
|
||||||
|
|
||||||
this.set_medium(medium);
|
this.set_medium(medium);
|
||||||
|
|
||||||
|
|
@ -133,9 +137,7 @@ impl MediumPreview {
|
||||||
list.append(&header);
|
list.append(&header);
|
||||||
|
|
||||||
if let Some(list) = &last_list {
|
if let Some(list) = &last_list {
|
||||||
let frame = gtk::FrameBuilder::new()
|
let frame = gtk::FrameBuilder::new().margin_bottom(12).build();
|
||||||
.margin_bottom(12)
|
|
||||||
.build();
|
|
||||||
|
|
||||||
frame.set_child(Some(list));
|
frame.set_child(Some(list));
|
||||||
self.medium_box.append(&frame);
|
self.medium_box.append(&frame);
|
||||||
|
|
@ -168,9 +170,7 @@ impl MediumPreview {
|
||||||
}
|
}
|
||||||
|
|
||||||
if let Some(list) = &last_list {
|
if let Some(list) = &last_list {
|
||||||
let frame = gtk::FrameBuilder::new()
|
let frame = gtk::FrameBuilder::new().margin_bottom(12).build();
|
||||||
.margin_bottom(12)
|
|
||||||
.build();
|
|
||||||
|
|
||||||
frame.set_child(Some(list));
|
frame.set_child(Some(list));
|
||||||
self.medium_box.append(&frame);
|
self.medium_box.append(&frame);
|
||||||
|
|
@ -200,7 +200,17 @@ impl MediumPreview {
|
||||||
// Create a new directory in the music library path for the imported medium.
|
// Create a new directory in the music library path for the imported medium.
|
||||||
|
|
||||||
let music_library_path = self.handle.backend.get_music_library_path().unwrap();
|
let music_library_path = self.handle.backend.get_music_library_path().unwrap();
|
||||||
let directory = PathBuf::from(&medium.id);
|
|
||||||
|
let directory_name = sanitize_filename::sanitize_with_options(
|
||||||
|
&medium.name,
|
||||||
|
sanitize_filename::Options {
|
||||||
|
windows: true,
|
||||||
|
truncate: true,
|
||||||
|
replacement: "",
|
||||||
|
},
|
||||||
|
);
|
||||||
|
|
||||||
|
let directory = PathBuf::from(&directory_name);
|
||||||
std::fs::create_dir(&music_library_path.join(&directory))?;
|
std::fs::create_dir(&music_library_path.join(&directory))?;
|
||||||
|
|
||||||
// Copy the tracks to the music library.
|
// Copy the tracks to the music library.
|
||||||
|
|
@ -232,7 +242,8 @@ impl MediumPreview {
|
||||||
tracks,
|
tracks,
|
||||||
};
|
};
|
||||||
|
|
||||||
self.handle.backend
|
self.handle
|
||||||
|
.backend
|
||||||
.db()
|
.db()
|
||||||
.update_medium(medium.clone())
|
.update_medium(medium.clone())
|
||||||
.await?;
|
.await?;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue