mirror of
https://github.com/johrpan/musicus.git
synced 2025-10-26 19:57:25 +01:00
Handle import errors
This commit is contained in:
parent
aa2fb7ec08
commit
f92a80be87
2 changed files with 167 additions and 73 deletions
|
|
@ -2,7 +2,13 @@
|
||||||
<interface>
|
<interface>
|
||||||
<requires lib="gtk" version="4.0"/>
|
<requires lib="gtk" version="4.0"/>
|
||||||
<requires lib="libadwaita" version="1.0"/>
|
<requires lib="libadwaita" version="1.0"/>
|
||||||
<object class="GtkBox" id="widget">
|
<object class="GtkStack" id="widget">
|
||||||
|
<property name="transition-type">crossfade</property>
|
||||||
|
<child>
|
||||||
|
<object class="GtkStackPage">
|
||||||
|
<property name="name">content</property>
|
||||||
|
<property name="child">
|
||||||
|
<object class="GtkBox">
|
||||||
<property name="orientation">vertical</property>
|
<property name="orientation">vertical</property>
|
||||||
<child>
|
<child>
|
||||||
<object class="AdwHeaderBar">
|
<object class="AdwHeaderBar">
|
||||||
|
|
@ -93,4 +99,77 @@
|
||||||
</object>
|
</object>
|
||||||
</child>
|
</child>
|
||||||
</object>
|
</object>
|
||||||
|
</property>
|
||||||
|
</object>
|
||||||
|
</child>
|
||||||
|
<child>
|
||||||
|
<object class="GtkStackPage">
|
||||||
|
<property name="name">loading</property>
|
||||||
|
<property name="child">
|
||||||
|
<object class="GtkBox">
|
||||||
|
<property name="orientation">vertical</property>
|
||||||
|
<child>
|
||||||
|
<object class="AdwHeaderBar">
|
||||||
|
<property name="show-start-title-buttons">false</property>
|
||||||
|
<property name="show-end-title-buttons">false</property>
|
||||||
|
<property name="title-widget">
|
||||||
|
<object class="AdwWindowTitle">
|
||||||
|
<property name="title" translatable="true">Loading</property>
|
||||||
|
</object>
|
||||||
|
</property>
|
||||||
|
</object>
|
||||||
|
</child>
|
||||||
|
<child>
|
||||||
|
<object class="GtkSpinner">
|
||||||
|
<property name="hexpand">true</property>
|
||||||
|
<property name="vexpand">true</property>
|
||||||
|
<property name="halign">center</property>
|
||||||
|
<property name="valign">center</property>
|
||||||
|
<property name="width-request">32</property>
|
||||||
|
<property name="height-request">32</property>
|
||||||
|
<property name="spinning">true</property>
|
||||||
|
</object>
|
||||||
|
</child>
|
||||||
|
</object>
|
||||||
|
</property>
|
||||||
|
</object>
|
||||||
|
</child>
|
||||||
|
<child>
|
||||||
|
<object class="GtkStackPage">
|
||||||
|
<property name="name">error</property>
|
||||||
|
<property name="child">
|
||||||
|
<object class="GtkBox">
|
||||||
|
<property name="orientation">vertical</property>
|
||||||
|
<child>
|
||||||
|
<object class="AdwHeaderBar">
|
||||||
|
<property name="show-start-title-buttons">false</property>
|
||||||
|
<property name="show-end-title-buttons">false</property>
|
||||||
|
<property name="title-widget">
|
||||||
|
<object class="AdwWindowTitle">
|
||||||
|
<property name="title" translatable="yes">Error</property>
|
||||||
|
</object>
|
||||||
|
</property>
|
||||||
|
</object>
|
||||||
|
</child>
|
||||||
|
<child>
|
||||||
|
<object class="AdwStatusPage" id="status_page">
|
||||||
|
<property name="icon-name">dialog-error-symbolic</property>
|
||||||
|
<property name="title">Error</property>
|
||||||
|
<property name="vexpand">true</property>
|
||||||
|
<child>
|
||||||
|
<object class="GtkButton" id="try_again_button">
|
||||||
|
<property name="label" translatable="yes">Try again</property>
|
||||||
|
<property name="hexpand">true</property>
|
||||||
|
<property name="vexpand">true</property>
|
||||||
|
<property name="halign">center</property>
|
||||||
|
<property name="valign">center</property>
|
||||||
|
</object>
|
||||||
|
</child>
|
||||||
|
</object>
|
||||||
|
</child>
|
||||||
|
</object>
|
||||||
|
</property>
|
||||||
|
</object>
|
||||||
|
</child>
|
||||||
|
</object>
|
||||||
</interface>
|
</interface>
|
||||||
|
|
@ -18,11 +18,12 @@ pub struct MediumPreview {
|
||||||
handle: NavigationHandle<()>,
|
handle: NavigationHandle<()>,
|
||||||
session: Arc<ImportSession>,
|
session: Arc<ImportSession>,
|
||||||
medium: RefCell<Option<Medium>>,
|
medium: RefCell<Option<Medium>>,
|
||||||
widget: gtk::Box,
|
widget: gtk::Stack,
|
||||||
import_button: gtk::Button,
|
import_button: gtk::Button,
|
||||||
done_stack: gtk::Stack,
|
done_stack: gtk::Stack,
|
||||||
name_label: gtk::Label,
|
name_label: gtk::Label,
|
||||||
medium_box: gtk::Box,
|
medium_box: gtk::Box,
|
||||||
|
status_page: libadwaita::StatusPage,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Screen<(Arc<ImportSession>, Medium), ()> for MediumPreview {
|
impl Screen<(Arc<ImportSession>, Medium), ()> for MediumPreview {
|
||||||
|
|
@ -35,13 +36,15 @@ impl Screen<(Arc<ImportSession>, Medium), ()> for MediumPreview {
|
||||||
|
|
||||||
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");
|
||||||
|
|
||||||
get_widget!(builder, gtk::Box, widget);
|
get_widget!(builder, gtk::Stack, widget);
|
||||||
get_widget!(builder, gtk::Button, back_button);
|
get_widget!(builder, gtk::Button, back_button);
|
||||||
get_widget!(builder, gtk::Button, edit_button);
|
get_widget!(builder, gtk::Button, edit_button);
|
||||||
get_widget!(builder, gtk::Button, import_button);
|
get_widget!(builder, gtk::Button, import_button);
|
||||||
get_widget!(builder, gtk::Stack, done_stack);
|
get_widget!(builder, gtk::Stack, done_stack);
|
||||||
get_widget!(builder, gtk::Box, medium_box);
|
get_widget!(builder, gtk::Box, medium_box);
|
||||||
get_widget!(builder, gtk::Label, name_label);
|
get_widget!(builder, gtk::Label, name_label);
|
||||||
|
get_widget!(builder, libadwaita::StatusPage, status_page);
|
||||||
|
get_widget!(builder, gtk::Button, try_again_button);
|
||||||
|
|
||||||
let this = Rc::new(Self {
|
let this = Rc::new(Self {
|
||||||
handle,
|
handle,
|
||||||
|
|
@ -52,6 +55,7 @@ impl Screen<(Arc<ImportSession>, Medium), ()> for MediumPreview {
|
||||||
done_stack,
|
done_stack,
|
||||||
name_label,
|
name_label,
|
||||||
medium_box,
|
medium_box,
|
||||||
|
status_page,
|
||||||
});
|
});
|
||||||
|
|
||||||
// Connect signals and callbacks
|
// Connect signals and callbacks
|
||||||
|
|
@ -71,12 +75,23 @@ impl Screen<(Arc<ImportSession>, Medium), ()> for MediumPreview {
|
||||||
|
|
||||||
this.import_button
|
this.import_button
|
||||||
.connect_clicked(clone!(@weak this => move |_| {
|
.connect_clicked(clone!(@weak this => move |_| {
|
||||||
|
this.widget.set_visible_child_name("loading");
|
||||||
|
|
||||||
spawn!(@clone this, async move {
|
spawn!(@clone this, async move {
|
||||||
this.import().await.unwrap();
|
match this.import().await {
|
||||||
this.handle.pop(Some(()));
|
Ok(()) => this.handle.pop(Some(())),
|
||||||
|
Err(err) => {
|
||||||
|
this.widget.set_visible_child_name("error");
|
||||||
|
this.status_page.set_description(Some(&err.to_string()));
|
||||||
|
}
|
||||||
|
}
|
||||||
});
|
});
|
||||||
}));
|
}));
|
||||||
|
|
||||||
|
try_again_button.connect_clicked(clone!(@weak this => move |_| {
|
||||||
|
this.widget.set_visible_child_name("content");
|
||||||
|
}));
|
||||||
|
|
||||||
this.set_medium(medium);
|
this.set_medium(medium);
|
||||||
|
|
||||||
this.handle_state(&this.session.state());
|
this.handle_state(&this.session.state());
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue