diff --git a/src/app/browser/window/tab/item/page.rs b/src/app/browser/window/tab/item/page.rs index 9c1fc2f7..0e64a38f 100644 --- a/src/app/browser/window/tab/item/page.rs +++ b/src/app/browser/window/tab/item/page.rs @@ -190,7 +190,7 @@ impl Page { // Update widget self.content - .set_status_failure(title.as_str(), description.as_str()); + .set_status_failure(Some(title.as_str()), Some(description.as_str())); // Update meta self.meta.replace(Meta { @@ -523,8 +523,8 @@ impl Page { // Update widget content.set_status_failure( - title.as_str(), - description.as_str(), + Some(title.as_str()), + Some(description.as_str()) ); // Update meta @@ -545,6 +545,16 @@ impl Page { ClientMime::ImagePng | ClientMime::ImageGif | ClientMime::ImageJpeg | ClientMime::ImageWebp ) => { + // Init loading placeholder + /* @TODO count bytes on download + let title = gformat!("Loading.."); + let description = gformat!(""); // collect totals here, invisible on start + + content.set_status_loading( + Some(&title), + Some(&description) + ); */ + match Pixbuf::from_stream( // @TODO async &connection.input_stream(), None::<&Cancellable>, @@ -567,7 +577,10 @@ impl Page { let description = gformat!("{}", reason.message()); // Update widget - content.set_status_failure(title.as_str(), description.as_str()); + content.set_status_failure( + Some(title.as_str()), + Some(description.as_str()) + ); // Update meta meta.replace(Meta { @@ -601,8 +614,8 @@ impl Page { // Update widget content.set_status_failure( - title.as_str(), - description.as_str(), + Some(title.as_str()), + Some(description.as_str()), ); // Update meta @@ -642,8 +655,8 @@ impl Page { ); }, None => content.set_status_failure( - &"Oops", - &"Could not parse redirect meta" + Some(&"Oops"), + Some(&"Could not parse redirect meta") ), } @@ -679,8 +692,10 @@ impl Page { }; // Update widget - content - .set_status_failure(title.as_str(), description.as_str()); + content.set_status_failure( + Some(title.as_str()), + Some(description.as_str()) + ); // Update meta meta.replace(Meta { @@ -702,8 +717,10 @@ impl Page { let description = gformat!("Request error: {}", reason.message()); // Update widget - content - .set_status_failure(title.as_str(), description.as_str()); + content.set_status_failure( + Some(title.as_str()), + Some(description.as_str()) + ); // Update meta meta.replace(Meta { @@ -725,8 +742,10 @@ impl Page { let description = gformat!("Connection error: {}", reason.message()); // Update widget - content - .set_status_failure(title.as_str(), description.as_str()); + content.set_status_failure( + Some(title.as_str()), + Some(description.as_str()) + ); // Update meta meta.replace(Meta { diff --git a/src/app/browser/window/tab/item/page/content.rs b/src/app/browser/window/tab/item/page/content.rs index e45f4d69..bac6bda7 100644 --- a/src/app/browser/window/tab/item/page/content.rs +++ b/src/app/browser/window/tab/item/page/content.rs @@ -40,10 +40,10 @@ impl Content { self.gobject.append(image.gobject()); } - pub fn set_status_failure(&self, title: &str, description: &str) { + pub fn set_status_failure(&self, title: Option<&str>, description: Option<&str>) { self.clean(); - let status_default = Status::new_error(title, description); + let status_default = Status::new_failure(title, description); self.gobject.append(status_default.gobject()); } 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 82eacd19..21c8d253 100644 --- a/src/app/browser/window/tab/item/page/content/status.rs +++ b/src/app/browser/window/tab/item/page/content/status.rs @@ -1,6 +1,8 @@ mod failure; +mod loading; use failure::Failure; +use loading::Loading; use adw::StatusPage; @@ -9,14 +11,26 @@ pub struct Status { } impl Status { - // Construct - pub fn new_error(title: &str, description: &str) -> Self { + // Constructors + + /// Create new default failure component + pub fn new_failure(title: Option<&str>, description: Option<&str>) -> Self { Self { - gobject: Failure::new(title, description), + gobject: Failure::new(title, description).gobject().clone(), + } + } + + /// Create new default loading component + /// + /// Useful as the placeholder widget for async operations + pub fn new_loading(title: Option<&str>, description: Option<&str>) -> Self { + Self { + gobject: Loading::new(title, description).gobject().clone(), } } // Getters + pub fn gobject(&self) -> &StatusPage { &self.gobject } diff --git a/src/app/browser/window/tab/item/page/content/status/failure.rs b/src/app/browser/window/tab/item/page/content/status/failure.rs index f4cb2275..123ab629 100644 --- a/src/app/browser/window/tab/item/page/content/status/failure.rs +++ b/src/app/browser/window/tab/item/page/content/status/failure.rs @@ -1,15 +1,20 @@ +mod widget; +use widget::Widget; + use adw::StatusPage; pub struct Failure { - // nothing yet.. + widget: Widget, } impl Failure { - pub fn new(title: &str, description: &str) -> StatusPage { - StatusPage::builder() - .description(description) - .icon_name("dialog-error-symbolic") - .title(title) - .build() + pub fn new(title: Option<&str>, description: Option<&str>) -> Self { + Self { + widget: Widget::new(title, description), + } + } + + pub fn gobject(&self) -> &StatusPage { + &self.widget.gobject() } } diff --git a/src/app/browser/window/tab/item/page/content/status/failure/widget.rs b/src/app/browser/window/tab/item/page/content/status/failure/widget.rs new file mode 100644 index 00000000..25d21f43 --- /dev/null +++ b/src/app/browser/window/tab/item/page/content/status/failure/widget.rs @@ -0,0 +1,28 @@ +use adw::StatusPage; + +pub struct Widget { + gobject: StatusPage, +} + +impl Widget { + // Constructors + + /// Create new default widget configuration + pub fn new(title: Option<&str>, description: Option<&str>) -> Self { + let gobject = StatusPage::new(); + + if let Some(value) = title { + gobject.set_title(value); + } + + gobject.set_description(description); + + Self { gobject } + } + + // Getters + + pub fn gobject(&self) -> &StatusPage { + &self.gobject + } +}