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 4e7cfe38..9afdd43d 100644 --- a/src/app/browser/window/tab/item/page/content/status.rs +++ b/src/app/browser/window/tab/item/page/content/status.rs @@ -1,9 +1,6 @@ mod failure; mod loading; -use failure::Failure; -use loading::Loading; - use adw::StatusPage; use std::time::Duration; @@ -23,9 +20,7 @@ impl Status { icon_name: Option<&str>, ) -> Self { Self { - gobject: Failure::new(title, description, icon_name) - .gobject() - .clone(), + gobject: failure::new_gobject_from(title, description, icon_name), } } @@ -38,9 +33,7 @@ impl Status { show_with_delay: Option, ) -> Self { Self { - gobject: Loading::new(title, description, show_with_delay) - .gobject() - .clone(), + gobject: loading::new_gobject_from(title, description, show_with_delay), } } 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 a9f0aaf7..79939b39 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,36 +1,31 @@ use adw::StatusPage; +const DEFAULT_ICON_NAME: Option<&str> = Some("dialog-error"); const DEFAULT_TITLE: &str = "Oops"; const DEFAULT_DESCRIPTION: Option<&str> = None; -const DEFAULT_ICON_NAME: Option<&str> = Some("dialog-error"); -pub struct Failure { - gobject: StatusPage, -} - -impl Failure { - pub fn new(title: Option<&str>, description: Option<&str>, icon_name: Option<&str>) -> Self { - let gobject = StatusPage::new(); - - gobject.set_title(match title { - Some(value) => value, - None => DEFAULT_TITLE, - }); - - gobject.set_description(match description { - Some(value) => Some(value), - None => DEFAULT_DESCRIPTION, - }); - - gobject.set_icon_name(match icon_name { - Some(value) => Some(value), - None => DEFAULT_ICON_NAME, - }); - - Self { gobject } - } - - pub fn gobject(&self) -> &StatusPage { - &self.gobject - } +/// Create new `GObject` preset for failure [StatusPage](https://gnome.pages.gitlab.gnome.org/libadwaita/doc/main/class.StatusPage.html) +pub fn new_gobject_from( + title: Option<&str>, + description: Option<&str>, + icon_name: Option<&str>, +) -> StatusPage { + let gobject = StatusPage::new(); + + gobject.set_title(match title { + Some(value) => value, + None => DEFAULT_TITLE, + }); + + gobject.set_description(match description { + Some(value) => Some(value), + None => DEFAULT_DESCRIPTION, + }); + + gobject.set_icon_name(match icon_name { + Some(value) => Some(value), + None => DEFAULT_ICON_NAME, + }); + + gobject } diff --git a/src/app/browser/window/tab/item/page/content/status/loading.rs b/src/app/browser/window/tab/item/page/content/status/loading.rs index 754f6b77..8b9dd8c1 100644 --- a/src/app/browser/window/tab/item/page/content/status/loading.rs +++ b/src/app/browser/window/tab/item/page/content/status/loading.rs @@ -8,46 +8,37 @@ use std::time::Duration; /// 16-64 (px) const SPINNER_SIZE: i32 = 64; -pub struct Loading { - gobject: StatusPage, -} +/// Create new `GObject` preset for loading [StatusPage](https://gnome.pages.gitlab.gnome.org/libadwaita/doc/main/class.StatusPage.html) +pub fn new_gobject_from( + title: Option<&str>, + description: Option<&str>, + show_with_delay: Option, +) -> StatusPage { + let gobject = StatusPage::builder() + .child( + &Spinner::builder() + .width_request(SPINNER_SIZE) + .height_request(SPINNER_SIZE) + .build(), + ) + .build(); -impl Loading { - pub fn new( - title: Option<&str>, - description: Option<&str>, - show_with_delay: Option, - ) -> Self { - let gobject = StatusPage::builder() - .child( - &Spinner::builder() - .width_request(SPINNER_SIZE) - .height_request(SPINNER_SIZE) - .build(), - ) - .build(); - - if let Some(value) = title { - gobject.set_title(value); - } - - gobject.set_description(description); - - if let Some(duration) = show_with_delay { - gobject.set_visible(false); - timeout_add_local(duration, { - let this = gobject.clone(); - move || { - this.set_visible(true); - ControlFlow::Break - } - }); - } - - Self { gobject } + if let Some(value) = title { + gobject.set_title(value); } - pub fn gobject(&self) -> &StatusPage { - &self.gobject + gobject.set_description(description); + + if let Some(duration) = show_with_delay { + gobject.set_visible(false); + timeout_add_local(duration, { + let this = gobject.clone(); + move || { + this.set_visible(true); + ControlFlow::Break + } + }); } + + gobject }