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.
 | /// A dialog for starting to import music.
 | ||||||
| pub struct SourceSelector { | pub struct SourceSelector { | ||||||
|     handle: NavigationHandle<()>, |     handle: NavigationHandle<()>, | ||||||
|     widget: gtk::Box, |     widget: gtk::Stack, | ||||||
|     stack: gtk::Stack, |     status_page: libadwaita::StatusPage, | ||||||
|     info_bar: gtk::InfoBar, |  | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| impl Screen<(), ()> for SourceSelector { | 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"); |         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::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, folder_button); | ||||||
|         get_widget!(builder, gtk::Button, disc_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 { |         let this = Rc::new(Self { | ||||||
|             handle, |             handle, | ||||||
|             widget, |             widget, | ||||||
|             stack, |             status_page, | ||||||
|             info_bar, |  | ||||||
|         }); |         }); | ||||||
| 
 | 
 | ||||||
|         // Connect signals and callbacks
 |         // Connect signals and callbacks
 | ||||||
|  | @ -59,12 +57,13 @@ impl Screen<(), ()> for SourceSelector { | ||||||
|             dialog.set_modal(true); |             dialog.set_modal(true); | ||||||
| 
 | 
 | ||||||
|             dialog.connect_response(clone!(@weak this => move |dialog, response| { |             dialog.connect_response(clone!(@weak this => move |dialog, response| { | ||||||
|                 this.stack.set_visible_child_name("loading"); |  | ||||||
|                 dialog.hide(); |                 dialog.hide(); | ||||||
| 
 | 
 | ||||||
|                 if let gtk::ResponseType::Accept = response { |                 if let gtk::ResponseType::Accept = response { | ||||||
|                     if let Some(file) = dialog.get_file() { |                     if let Some(file) = dialog.get_file() { | ||||||
|                         if let Some(path) = file.get_path() { |                         if let Some(path) = file.get_path() { | ||||||
|  |                             this.widget.set_visible_child_name("loading"); | ||||||
|  | 
 | ||||||
|                             spawn!(@clone this, async move { |                             spawn!(@clone this, async move { | ||||||
|                                 let folder = FolderSource::new(PathBuf::from(path)); |                                 let folder = FolderSource::new(PathBuf::from(path)); | ||||||
|                                 match folder.load().await { |                                 match folder.load().await { | ||||||
|  | @ -73,10 +72,9 @@ impl Screen<(), ()> for SourceSelector { | ||||||
|                                         push!(this.handle, MediumEditor, source).await; |                                         push!(this.handle, MediumEditor, source).await; | ||||||
|                                         this.handle.pop(Some(())); |                                         this.handle.pop(Some(())); | ||||||
|                                     } |                                     } | ||||||
|                                     Err(_) => { |                                     Err(err) => { | ||||||
|                                         // TODO: Present error.
 |                                         this.status_page.set_description(Some(&err.to_string())); | ||||||
|                                         this.info_bar.set_revealed(true); |                                         this.widget.set_visible_child_name("error"); | ||||||
|                                         this.stack.set_visible_child_name("start"); |  | ||||||
|                                     } |                                     } | ||||||
|                                 } |                                 } | ||||||
|                             }); |                             }); | ||||||
|  | @ -89,7 +87,7 @@ impl Screen<(), ()> for SourceSelector { | ||||||
|         })); |         })); | ||||||
| 
 | 
 | ||||||
|         disc_button.connect_clicked(clone!(@weak this => move |_| { |         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 { |             spawn!(@clone this, async move { | ||||||
|                 let disc = DiscSource::new().unwrap(); |                 let disc = DiscSource::new().unwrap(); | ||||||
|  | @ -99,15 +97,18 @@ impl Screen<(), ()> for SourceSelector { | ||||||
|                         push!(this.handle, MediumEditor, source).await; |                         push!(this.handle, MediumEditor, source).await; | ||||||
|                         this.handle.pop(Some(())); |                         this.handle.pop(Some(())); | ||||||
|                     } |                     } | ||||||
|                     Err(_) => { |                     Err(err) => { | ||||||
|                         // TODO: Present error.
 |                         this.status_page.set_description(Some(&err.to_string())); | ||||||
|                         this.info_bar.set_revealed(true); |                         this.widget.set_visible_child_name("error"); | ||||||
|                         this.stack.set_visible_child_name("start"); |  | ||||||
|                     } |                     } | ||||||
|                 } |                 } | ||||||
|             }); |             }); | ||||||
|         })); |         })); | ||||||
| 
 | 
 | ||||||
|  |         try_again_button.connect_clicked(clone!(@weak this => move |_| { | ||||||
|  |             this.widget.set_visible_child_name("content"); | ||||||
|  |         })); | ||||||
|  | 
 | ||||||
|         this |         this | ||||||
|     } |     } | ||||||
| } | } | ||||||
|  |  | ||||||
|  | @ -2,52 +2,28 @@ | ||||||
| <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"> | ||||||
|                 <property name="show-start-title-buttons">false</property> |                 <property name="show-start-title-buttons">false</property> | ||||||
|                 <property name="show-end-title-buttons">false</property> |                 <property name="show-end-title-buttons">false</property> | ||||||
|                 <property name="title-widget"> |                 <property name="title-widget"> | ||||||
|           <object class="GtkLabel"> |                   <object class="AdwWindowTitle" id="window_title"/> | ||||||
|             <property name="label" translatable="yes">Import music</property> |  | ||||||
|             <style> |  | ||||||
|               <class name="title"/> |  | ||||||
|             </style> |  | ||||||
|           </object> |  | ||||||
|                 </property> |                 </property> | ||||||
|                 <child> |                 <child> | ||||||
|                   <object class="GtkButton" id="back_button"> |                   <object class="GtkButton" id="back_button"> | ||||||
|             <child> |  | ||||||
|               <object class="GtkImage"> |  | ||||||
|                     <property name="icon-name">go-previous-symbolic</property> |                     <property name="icon-name">go-previous-symbolic</property> | ||||||
|                   </object> |                   </object> | ||||||
|                 </child> |                 </child> | ||||||
|               </object> |               </object> | ||||||
|             </child> |             </child> | ||||||
|       </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> |  | ||||||
|                 </child> |  | ||||||
|             <child> |             <child> | ||||||
|               <object class="AdwStatusPage"> |               <object class="AdwStatusPage"> | ||||||
|                 <property name="vexpand">true</property> |                 <property name="vexpand">true</property> | ||||||
|  | @ -82,17 +58,69 @@ | ||||||
|       <object class="GtkStackPage"> |       <object class="GtkStackPage"> | ||||||
|         <property name="name">loading</property> |         <property name="name">loading</property> | ||||||
|         <property name="child"> |         <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"> |               <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="hexpand">true</property> | ||||||
|                 <property name="vexpand">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> | ||||||
|  |                 <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> |           </object> | ||||||
|         </property> |         </property> | ||||||
|       </object> |       </object> | ||||||
|     </child> |     </child> | ||||||
|   </object> |   </object> | ||||||
|     </child> |  | ||||||
|   </object> |  | ||||||
| </interface> | </interface> | ||||||
|  |  | ||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 Elias Projahn
						Elias Projahn