mirror of
https://github.com/johrpan/musicus.git
synced 2025-10-26 11:47: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" }
|
||||
once_cell = "1.5.2"
|
||||
rand = "0.7.3"
|
||||
sanitize-filename = "0.3.0"
|
||||
|
||||
[dependencies.gdk]
|
||||
git = "https://github.com/gtk-rs/gtk4-rs/"
|
||||
|
|
|
|||
|
|
@ -27,7 +27,10 @@ pub struct MediumPreview {
|
|||
|
||||
impl Screen<(Arc<ImportSession>, Medium), ()> for MediumPreview {
|
||||
/// 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
|
||||
|
||||
let builder = gtk::Builder::from_resource("/de/johrpan/musicus/ui/medium_preview.ui");
|
||||
|
|
@ -66,7 +69,8 @@ impl Screen<(Arc<ImportSession>, Medium), ()> for MediumPreview {
|
|||
});
|
||||
}));
|
||||
|
||||
this.import_button.connect_clicked(clone!(@weak this => move |_| {
|
||||
this.import_button
|
||||
.connect_clicked(clone!(@weak this => move |_| {
|
||||
spawn!(@clone this, async move {
|
||||
this.import().await.unwrap();
|
||||
this.handle.pop(Some(()));
|
||||
|
|
@ -133,9 +137,7 @@ impl MediumPreview {
|
|||
list.append(&header);
|
||||
|
||||
if let Some(list) = &last_list {
|
||||
let frame = gtk::FrameBuilder::new()
|
||||
.margin_bottom(12)
|
||||
.build();
|
||||
let frame = gtk::FrameBuilder::new().margin_bottom(12).build();
|
||||
|
||||
frame.set_child(Some(list));
|
||||
self.medium_box.append(&frame);
|
||||
|
|
@ -168,9 +170,7 @@ impl MediumPreview {
|
|||
}
|
||||
|
||||
if let Some(list) = &last_list {
|
||||
let frame = gtk::FrameBuilder::new()
|
||||
.margin_bottom(12)
|
||||
.build();
|
||||
let frame = gtk::FrameBuilder::new().margin_bottom(12).build();
|
||||
|
||||
frame.set_child(Some(list));
|
||||
self.medium_box.append(&frame);
|
||||
|
|
@ -200,7 +200,17 @@ impl MediumPreview {
|
|||
// 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 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))?;
|
||||
|
||||
// Copy the tracks to the music library.
|
||||
|
|
@ -232,7 +242,8 @@ impl MediumPreview {
|
|||
tracks,
|
||||
};
|
||||
|
||||
self.handle.backend
|
||||
self.handle
|
||||
.backend
|
||||
.db()
|
||||
.update_medium(medium.clone())
|
||||
.await?;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue