mirror of
https://github.com/johrpan/musicus.git
synced 2025-10-26 19:57:25 +01:00
Display errors in source selector
This commit is contained in:
parent
d72a0583ff
commit
93c55d8892
2 changed files with 122 additions and 93 deletions
|
|
@ -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
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,96 +2,124 @@
|
|||
<interface>
|
||||
<requires lib="gtk" version="4.0"/>
|
||||
<requires lib="libadwaita" version="1.0"/>
|
||||
<object class="GtkBox" id="widget">
|
||||
<property name="orientation">vertical</property>
|
||||
<object class="GtkStack" id="widget">
|
||||
<property name="transition-type">crossfade</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="GtkLabel">
|
||||
<property name="label" translatable="yes">Import music</property>
|
||||
<style>
|
||||
<class name="title"/>
|
||||
</style>
|
||||
</object>
|
||||
</property>
|
||||
<child>
|
||||
<object class="GtkButton" id="back_button">
|
||||
<object class="GtkStackPage">
|
||||
<property name="name">content</property>
|
||||
<property name="child">
|
||||
<object class="GtkBox">
|
||||
<property name="orientation">vertical</property>
|
||||
<child>
|
||||
<object class="GtkImage">
|
||||
<property name="icon-name">go-previous-symbolic</property>
|
||||
<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" id="window_title"/>
|
||||
</property>
|
||||
<child>
|
||||
<object class="GtkButton" id="back_button">
|
||||
<property name="icon-name">go-previous-symbolic</property>
|
||||
</object>
|
||||
</child>
|
||||
</object>
|
||||
</child>
|
||||
<child>
|
||||
<object class="AdwStatusPage">
|
||||
<property name="vexpand">true</property>
|
||||
<property name="icon-name">folder-music-symbolic</property>
|
||||
<property name="title" translatable="yes">Import music</property>
|
||||
<property name="description" translatable="yes">Select the source which contains the new audio files below.</property>
|
||||
<child>
|
||||
<object class="GtkBox">
|
||||
<property name="orientation">horizontal</property>
|
||||
<property name="homogeneous">true</property>
|
||||
<property name="spacing">6</property>
|
||||
<property name="halign">center</property>
|
||||
<child>
|
||||
<object class="GtkButton" id="folder_button">
|
||||
<property name="label" translatable="true">Select folder</property>
|
||||
</object>
|
||||
</child>
|
||||
<child>
|
||||
<object class="GtkButton" id="disc_button">
|
||||
<property name="label" translatable="true">Copy audio CD</property>
|
||||
</object>
|
||||
</child>
|
||||
</object>
|
||||
</child>
|
||||
</object>
|
||||
</child>
|
||||
</object>
|
||||
</child>
|
||||
</property>
|
||||
</object>
|
||||
</child>
|
||||
<child>
|
||||
<object class="GtkStack" id="stack">
|
||||
<property name="transition-type">crossfade</property>
|
||||
<child>
|
||||
<object class="GtkStackPage">
|
||||
<property name="name">start</property>
|
||||
<property name="child">
|
||||
<object class="GtkBox">
|
||||
<property name="orientation">vertical</property>
|
||||
<child>
|
||||
<object class="GtkInfoBar" id="info_bar">
|
||||
<property name="message-type">error</property>
|
||||
<property name="revealed">False</property>
|
||||
<child>
|
||||
<object class="GtkLabel">
|
||||
<property name="label" translatable="yes">Failed to load the CD. Make sure you have inserted it into your drive.</property>
|
||||
<property name="wrap">True</property>
|
||||
</object>
|
||||
</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>
|
||||
</child>
|
||||
<child>
|
||||
<object class="AdwStatusPage">
|
||||
<property name="vexpand">true</property>
|
||||
<property name="icon-name">folder-music-symbolic</property>
|
||||
<property name="title" translatable="yes">Import music</property>
|
||||
<property name="description" translatable="yes">Select the source which contains the new audio files below.</property>
|
||||
<child>
|
||||
<object class="GtkBox">
|
||||
<property name="orientation">horizontal</property>
|
||||
<property name="homogeneous">true</property>
|
||||
<property name="spacing">6</property>
|
||||
<property name="halign">center</property>
|
||||
<child>
|
||||
<object class="GtkButton" id="folder_button">
|
||||
<property name="label" translatable="true">Select folder</property>
|
||||
</object>
|
||||
</child>
|
||||
<child>
|
||||
<object class="GtkButton" id="disc_button">
|
||||
<property name="label" translatable="true">Copy audio CD</property>
|
||||
</object>
|
||||
</child>
|
||||
</object>
|
||||
</child>
|
||||
</object>
|
||||
</child>
|
||||
</property>
|
||||
</object>
|
||||
</property>
|
||||
</object>
|
||||
</child>
|
||||
<child>
|
||||
<object class="GtkStackPage">
|
||||
<property name="name">loading</property>
|
||||
<property name="child">
|
||||
</child>
|
||||
<child>
|
||||
<object class="GtkSpinner">
|
||||
<property name="spinning">True</property>
|
||||
<property name="halign">center</property>
|
||||
<property name="valign">center</property>
|
||||
<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>
|
||||
</property>
|
||||
</child>
|
||||
</object>
|
||||
</child>
|
||||
</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>
|
||||
<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>
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue