diff --git a/src/main.rs b/src/main.rs index e8ec642..8e1f4b6 100644 --- a/src/main.rs +++ b/src/main.rs @@ -15,6 +15,7 @@ use crate :: data_manager :: * ; use crate :: error :: * ; use crate :: error :: ZoodexError :: * ; use crate :: ui :: * ; +use crate :: utility :: * ; @@ -38,13 +39,26 @@ fn add_style_provider ( _ : & Application ) { } fn show_window ( application : & Application ) { - let ui = UI :: new (application) ; - ui . show_window () ; + let window = leak ( + ApplicationWindow :: builder () + . application (application) + . title ("Zoödex") + . build () + ) ; spawn_future_local ( async move { async_result_context ! ( async { - let data_manager = DataManager :: new () . await ? ; + let data_manager = leak ( DataManager :: new () . await ? ) ; + + let ui = UI :: new ( + window , + |film_uuid| Box :: pin ( async { + data_manager . get_film_details (film_uuid) . await . unwrap () + } ) , + ) ; + window . set_visible (true) ; + let collection = data_manager . get_collection_overview () . await ? ; ui . render_collection_overview (collection) . await ; Ok (()) @@ -53,7 +67,7 @@ fn show_window ( application : & Application ) { match error { CollectionFileReadError => eprintln ! ("Could not read collection file") , } ; - ui . close_window () ; + window . close () ; } , ) ; } ) ; diff --git a/src/ui/mod.rs b/src/ui/mod.rs index 4d93e8f..07c0e86 100644 --- a/src/ui/mod.rs +++ b/src/ui/mod.rs @@ -3,6 +3,7 @@ mod component ; mod utility ; use futures :: * ; +use futures :: future :: * ; use gtk4 :: Orientation :: * ; use gtk4 :: prelude :: * ; use libadwaita :: * ; @@ -18,41 +19,45 @@ use crate :: utility :: * ; pub struct UI { - window : & 'static ApplicationWindow , films_component : CollatableMediaContainer , series_component : CollatableMediaContainer , } impl UI { - pub fn new ( application : & Application ) -> UI { - let window = leak ( application_window ! ( - @ application : application ; - @ title : "Zoödex" ; - ) ) ; + pub fn new ( + window : & 'static ApplicationWindow , + get_film_details : impl Fn (String) -> BoxFuture < 'static , FilmDetails > + 'static , + ) -> UI { + let get_film_details = leak (get_film_details) ; - let films_component = CollatableMediaContainer :: :: new ( - |film| dialog ! ( - & g_box ! ( - @ option_children ; - @ orientation : Vertical ; - @ css_classes : & [ "media-modal" ] ; + let films_component = CollatableMediaContainer :: :: new ( |film| { + glib :: spawn_future_local ( async { + let film_details = get_film_details ( film . uuid ) . await ; - Some ( label ! ( - @ css_classes : & [ "title-1" ] ; - film . name . as_str () , - ) ) . as_ref () , + dialog ! ( + & g_box ! ( + @ option_children ; + @ orientation : Vertical ; + @ css_classes : & [ "media-modal" ] ; - film . original_name . map ( - |original_name| label ! ( original_name . as_str () ) , - ) . as_ref () , + Some ( label ! ( + @ css_classes : & [ "title-1" ] ; + film_details . name . as_str () , + ) ) . as_ref () , - Some ( label ! ( - @ css_classes : & [ "top-padding" ] ; - & format ! ( "Release date: {}" , film . release_date ) , - ) ) . as_ref () , - ) , - ) . present ( Some (window) ) , - ) ; + film_details . original_name . map ( + |original_name| label ! ( original_name . as_str () ) , + ) . as_ref () , + + Some ( label ! ( + @ css_classes : & [ "top-padding" ] ; + & format ! ( "Release date: {}" , film_details . release_date ) , + ) ) . as_ref () , + ) , + ) . present ( Some (window) ) + + } ) ; + } ) ; let series_component = CollatableMediaContainer :: :: new ( |series| dialog ! () . present ( Some (window) ) , ) ; @@ -68,13 +73,9 @@ impl UI { & toolbar_view ! ( @ top_bar : & header_bar ; & switched ) , ) ) ; - UI { window , films_component , series_component } + UI { films_component , series_component } } - pub fn show_window ( & self ) { self . window . set_visible (true) } - - pub fn close_window ( & self ) { self . window . close () } - pub async fn render_collection_overview ( & self , collection : CollectionOverview ) { join ! ( self . films_component . set_media ( collection . films ) , diff --git a/src/ui/utility.rs b/src/ui/utility.rs index 53178b6..4f5e210 100644 --- a/src/ui/utility.rs +++ b/src/ui/utility.rs @@ -253,7 +253,7 @@ macro_rules ! pango_attributes { ( -pub (crate) use { +# [ allow (unused_imports) ] pub (crate) use { application_window , bin , button ,