From 93c55d88921b45feb3570f1dd6a3de6536bc731e Mon Sep 17 00:00:00 2001 From: Elias Projahn Date: Sat, 6 Feb 2021 22:45:33 +0100 Subject: [PATCH] Display errors in source selector --- crates/musicus/src/import/source_selector.rs | 37 ++-- res/ui/source_selector.ui | 178 +++++++++++-------- 2 files changed, 122 insertions(+), 93 deletions(-) diff --git a/crates/musicus/src/import/source_selector.rs b/crates/musicus/src/import/source_selector.rs index 7045fa2..60f5dc9 100644 --- a/crates/musicus/src/import/source_selector.rs +++ b/crates/musicus/src/import/source_selector.rs @@ -14,9 +14,8 @@ use std::rc::Rc; /// A dialog for starting to import music. pub struct SourceSelector { handle: NavigationHandle<()>, - widget: gtk::Box, - stack: gtk::Stack, - info_bar: gtk::InfoBar, + widget: gtk::Stack, + status_page: libadwaita::StatusPage, } impl Screen<(), ()> for SourceSelector { @@ -26,18 +25,17 @@ impl Screen<(), ()> for SourceSelector { let builder = gtk::Builder::from_resource("/de/johrpan/musicus/ui/source_selector.ui"); - get_widget!(builder, gtk::Box, widget); + get_widget!(builder, gtk::Stack, widget); get_widget!(builder, gtk::Button, back_button); - get_widget!(builder, gtk::Stack, stack); - get_widget!(builder, gtk::InfoBar, info_bar); get_widget!(builder, gtk::Button, folder_button); get_widget!(builder, gtk::Button, disc_button); + get_widget!(builder, libadwaita::StatusPage, status_page); + get_widget!(builder, gtk::Button, try_again_button); let this = Rc::new(Self { handle, widget, - stack, - info_bar, + status_page, }); // Connect signals and callbacks @@ -59,12 +57,13 @@ impl Screen<(), ()> for SourceSelector { dialog.set_modal(true); dialog.connect_response(clone!(@weak this => move |dialog, response| { - this.stack.set_visible_child_name("loading"); dialog.hide(); if let gtk::ResponseType::Accept = response { if let Some(file) = dialog.get_file() { if let Some(path) = file.get_path() { + this.widget.set_visible_child_name("loading"); + spawn!(@clone this, async move { let folder = FolderSource::new(PathBuf::from(path)); match folder.load().await { @@ -73,10 +72,9 @@ impl Screen<(), ()> for SourceSelector { push!(this.handle, MediumEditor, source).await; this.handle.pop(Some(())); } - Err(_) => { - // TODO: Present error. - this.info_bar.set_revealed(true); - this.stack.set_visible_child_name("start"); + Err(err) => { + this.status_page.set_description(Some(&err.to_string())); + this.widget.set_visible_child_name("error"); } } }); @@ -89,7 +87,7 @@ impl Screen<(), ()> for SourceSelector { })); disc_button.connect_clicked(clone!(@weak this => move |_| { - this.stack.set_visible_child_name("loading"); + this.widget.set_visible_child_name("loading"); spawn!(@clone this, async move { let disc = DiscSource::new().unwrap(); @@ -99,15 +97,18 @@ impl Screen<(), ()> for SourceSelector { push!(this.handle, MediumEditor, source).await; this.handle.pop(Some(())); } - Err(_) => { - // TODO: Present error. - this.info_bar.set_revealed(true); - this.stack.set_visible_child_name("start"); + Err(err) => { + this.status_page.set_description(Some(&err.to_string())); + this.widget.set_visible_child_name("error"); } } }); })); + try_again_button.connect_clicked(clone!(@weak this => move |_| { + this.widget.set_visible_child_name("content"); + })); + this } } diff --git a/res/ui/source_selector.ui b/res/ui/source_selector.ui index 3b7b711..9c0a46e 100644 --- a/res/ui/source_selector.ui +++ b/res/ui/source_selector.ui @@ -2,96 +2,124 @@ - - vertical + + crossfade - - false - false - - - Import music - - - - - + + content + + + vertical - - go-previous-symbolic + + false + false + + + + + + go-previous-symbolic + + + + + + + true + folder-music-symbolic + Import music + Select the source which contains the new audio files below. + + + horizontal + true + 6 + center + + + Select folder + + + + + Copy audio CD + + + + - + - - crossfade - - - start - - - vertical - - - error - False - - - Failed to load the CD. Make sure you have inserted it into your drive. - True - - + + loading + + + vertical + + + false + false + + + Loading - - - - true - folder-music-symbolic - Import music - Select the source which contains the new audio files below. - - - horizontal - true - 6 - center - - - Select folder - - - - - Copy audio CD - - - - - - + - - - - - - loading - + + - True - center - center true true + center + center + 32 + 32 + true - + - + + + + + + error + + + vertical + + + false + false + + + Error + + + + + + + dialog-error-symbolic + Error + + + Try again + true + true + center + center + + + + + +