From 6447b2279f06165e267a05b8e5313d70764f743d Mon Sep 17 00:00:00 2001 From: yggverse Date: Tue, 29 Oct 2024 19:20:25 +0200 Subject: [PATCH] update totals on loading --- src/app/browser/window/tab/item/page.rs | 20 +++++++++++-------- .../browser/window/tab/item/page/content.rs | 20 ++++++++----------- .../window/tab/item/page/content/status.rs | 17 +++++++++++++--- 3 files changed, 34 insertions(+), 23 deletions(-) diff --git a/src/app/browser/window/tab/item/page.rs b/src/app/browser/window/tab/item/page.rs index bb60386e..9ae284d4 100644 --- a/src/app/browser/window/tab/item/page.rs +++ b/src/app/browser/window/tab/item/page.rs @@ -457,7 +457,7 @@ impl Page { None => title.clone(), }; - // Make input form + // Toggle input form variant match header.status() { ClientStatus::SensitiveInput => input.set_new_sensitive( @@ -546,7 +546,7 @@ impl Page { ClientMime::ImageJpeg | ClientMime::ImageWebp ) => { // Final image size unknown, show loading widget - content.set_status_loading( + let status = content.set_status_loading( Some(&gformat!("Loading..")), None ); @@ -559,9 +559,11 @@ impl Page { Priority::DEFAULT, 0x400, // 1024 bytes per chunk, optional step for images download tracking 0xA00000, // 10M bytes max to prevent memory overflow if server play with promises @TODO optional? - move |(_, _total)| { + move |(_, total)| { // Update loading progress - // description = gformat!("{total}"); + status.set_description( + Some(&gformat!("Download: {total} bytes")) + ); }, move |result| match result { Ok(memory_input_stream) => { @@ -695,10 +697,12 @@ impl Page { } ); }, - None => content.set_status_failure( - Some(&"Oops"), - Some(&"Could not parse redirect meta") - ), + None => { + content.set_status_failure( + Some(&"Oops"), + Some(&"Could not parse redirect meta") + ); + }, } action_update.activate(Some(&id)); diff --git a/src/app/browser/window/tab/item/page/content.rs b/src/app/browser/window/tab/item/page/content.rs index 3f10f592..3453b036 100644 --- a/src/app/browser/window/tab/item/page/content.rs +++ b/src/app/browser/window/tab/item/page/content.rs @@ -34,27 +34,23 @@ impl Content { // Actions pub fn set_image(&self, buffer: &Pixbuf) { self.clean(); - let image = Image::new_from_pixbuf(buffer); - self.gobject.append(image.gobject()); } - pub fn set_status_failure(&self, title: Option<&str>, description: Option<&str>) { + pub fn set_status_failure(&self, title: Option<&str>, description: Option<&str>) -> Status { self.clean(); - - let status_default = Status::new_failure(title, description); - - self.gobject.append(status_default.gobject()); + let status = Status::new_failure(title, description); + self.gobject.append(status.gobject()); + status } /// Loading placeholder - pub fn set_status_loading(&self, title: Option<&str>, description: Option<&str>) { + pub fn set_status_loading(&self, title: Option<&str>, description: Option<&str>) -> Status { self.clean(); - - let status_default = Status::new_loading(title, description); - - self.gobject.append(status_default.gobject()); + let status = Status::new_loading(title, description); + self.gobject.append(status.gobject()); + status } /// Default reading widget for [Gemtext](https://geminiprotocol.net/docs/gemtext.gmi), diff --git a/src/app/browser/window/tab/item/page/content/status.rs b/src/app/browser/window/tab/item/page/content/status.rs index 21c8d253..b68472f2 100644 --- a/src/app/browser/window/tab/item/page/content/status.rs +++ b/src/app/browser/window/tab/item/page/content/status.rs @@ -13,22 +13,33 @@ pub struct Status { impl Status { // Constructors - /// Create new default failure component + /// Create new failure preset + /// + /// Useful as placeholder widget for error handlers pub fn new_failure(title: Option<&str>, description: Option<&str>) -> Self { Self { gobject: Failure::new(title, description).gobject().clone(), } } - /// Create new default loading component + /// Create new loading preset /// - /// Useful as the placeholder widget for async operations + /// Useful as placeholder widget for async operations pub fn new_loading(title: Option<&str>, description: Option<&str>) -> Self { Self { gobject: Loading::new(title, description).gobject().clone(), } } + // Setters + + /// Set new description for status component + /// + /// Useful for loading widgets to update byte totals and other dynamically changed information + pub fn set_description(&self, description: Option<&str>) { + self.gobject.set_description(description); + } + // Getters pub fn gobject(&self) -> &StatusPage {