From 549c3fd946dea20fe11e71b92b4e8c1071bf0398 Mon Sep 17 00:00:00 2001 From: yggverse Date: Thu, 12 Dec 2024 12:24:16 +0200 Subject: [PATCH] delegate status info to widget implementation --- src/app/browser/window/tab/item/page.rs | 18 +++++------------- .../browser/window/tab/item/page/content.rs | 4 ++-- .../window/tab/item/page/content/status.rs | 6 +++--- .../tab/item/page/content/status/mime.rs | 10 ++++------ 4 files changed, 14 insertions(+), 24 deletions(-) diff --git a/src/app/browser/window/tab/item/page.rs b/src/app/browser/window/tab/item/page.rs index 6c79094f..16609fc3 100644 --- a/src/app/browser/window/tab/item/page.rs +++ b/src/app/browser/window/tab/item/page.rs @@ -678,20 +678,12 @@ impl Page { ); }, mime => { - // Define common data - let status = Status::Failure; - let title = "Oops"; - let description = gformat!("Content type `{mime}` yet not supported!"); + // Init children widget + let status = content.to_status_mime(mime); - // Update widget - content - .to_status_mime() - .set_title(title) - .set_description(Some(&description)); - - // Update meta - meta.set_status(status) - .set_title(title); + // Update page meta + meta.set_status(Status::Failure) + .set_title(status.gobject.title().as_str()); // Update window 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 a7c9f9cc..82b79162 100644 --- a/src/app/browser/window/tab/item/page/content.rs +++ b/src/app/browser/window/tab/item/page/content.rs @@ -74,9 +74,9 @@ impl Content { /// Set new `content::Status` component for `Self` with new `status::Mime` issue preset /// /// * action removes previous children component from `Self` - pub fn to_status_mime(&self) -> Status { + pub fn to_status_mime(&self, mime: &str) -> Status { self.clean(); - let status = Status::new_mime(); + let status = Status::new_mime(mime); self.gobject.append(status.gobject()); status } 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 1c794b42..8a62defc 100644 --- a/src/app/browser/window/tab/item/page/content/status.rs +++ b/src/app/browser/window/tab/item/page/content/status.rs @@ -9,7 +9,7 @@ use gtk::gio::{Cancellable, File}; use std::{rc::Rc, time::Duration}; pub struct Status { - gobject: StatusPage, + pub gobject: StatusPage, } impl Status { @@ -38,9 +38,9 @@ impl Status { /// Create new mime issue preset /// /// Useful as placeholder widget for mime issue handlers - pub fn new_mime() -> Self { + pub fn new_mime(mime: &str) -> Self { Self { - gobject: mime::new_gobject(), + gobject: mime::new_gobject(mime), } } diff --git a/src/app/browser/window/tab/item/page/content/status/mime.rs b/src/app/browser/window/tab/item/page/content/status/mime.rs index 1e017be5..86567f7a 100644 --- a/src/app/browser/window/tab/item/page/content/status/mime.rs +++ b/src/app/browser/window/tab/item/page/content/status/mime.rs @@ -1,13 +1,11 @@ use adw::StatusPage; -const DEFAULT_TITLE: &str = "Oops"; -const DEFAULT_ICON_NAME: &str = "dialog-question-symbolic"; - /// Create new default `GObject` preset for mime issue /// [StatusPage](https://gnome.pages.gitlab.gnome.org/libadwaita/doc/main/class.StatusPage.html) -pub fn new_gobject() -> StatusPage { +pub fn new_gobject(mime: &str) -> StatusPage { StatusPage::builder() - .title(DEFAULT_TITLE) - .icon_name(DEFAULT_ICON_NAME) + .title("Oops") + .description(format!("Content type `{mime}` not supported!")) + .icon_name("dialog-question-symbolic") .build() }