From 63f7f1c7696be6a321d556e0a99614959a6d410e Mon Sep 17 00:00:00 2001 From: yggverse Date: Sat, 16 Nov 2024 21:32:42 +0200 Subject: [PATCH] add identity page for CertificateRequest status code --- src/app/browser/window/tab/item/page.rs | 18 ++++++++++++ .../browser/window/tab/item/page/content.rs | 10 +++++++ .../window/tab/item/page/content/status.rs | 11 +++++++ .../tab/item/page/content/status/identity.rs | 29 +++++++++++++++++++ 4 files changed, 68 insertions(+) create mode 100644 src/app/browser/window/tab/item/page/content/status/identity.rs diff --git a/src/app/browser/window/tab/item/page.rs b/src/app/browser/window/tab/item/page.rs index 8796b50b..0dc1f5c8 100644 --- a/src/app/browser/window/tab/item/page.rs +++ b/src/app/browser/window/tab/item/page.rs @@ -848,6 +848,24 @@ impl Page { update.activate(Some(&id)); }, + // https://geminiprotocol.net/docs/protocol-specification.gmi#status-60 + gemini::client::response::meta::Status::CertificateRequest => { + // Define common data + let status = Status::Success; + let title = "Identity"; + + // Update widget + content + .to_status_identity() + .set_title(title); + + // Update meta + meta.set_status(status) + .set_title(title); + + // Update window + update.activate(Some(&id)); + } _ => { // Define common data let status = Status::Failure; diff --git a/src/app/browser/window/tab/item/page/content.rs b/src/app/browser/window/tab/item/page/content.rs index 658de3a1..c65a3d54 100644 --- a/src/app/browser/window/tab/item/page/content.rs +++ b/src/app/browser/window/tab/item/page/content.rs @@ -55,6 +55,16 @@ impl Content { status } + /// Set new `content::Status` component for `Self` with new `status::Identity` preset + /// + /// * action removes previous children component from `Self` + pub fn to_status_identity(&self) -> Status { + self.clean(); + let status = Status::new_identity(); + self.gobject.append(status.gobject()); + status + } + /// Set new `content::Status` component for `Self` with new `status::Loading` preset /// /// * action removes previous children component from `Self` 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 9a3b575b..67aa4e00 100644 --- a/src/app/browser/window/tab/item/page/content/status.rs +++ b/src/app/browser/window/tab/item/page/content/status.rs @@ -1,4 +1,5 @@ mod failure; +mod identity; mod loading; use adw::StatusPage; @@ -20,6 +21,16 @@ impl Status { } } + /// Create new identity preset + /// + /// Useful as placeholder for 60 status code + /// https://geminiprotocol.net/docs/protocol-specification.gmi#status-60 + pub fn new_identity() -> Self { + Self { + gobject: identity::new_gobject(), + } + } + /// Create new loading preset /// /// Useful as placeholder widget for async operations diff --git a/src/app/browser/window/tab/item/page/content/status/identity.rs b/src/app/browser/window/tab/item/page/content/status/identity.rs new file mode 100644 index 00000000..191728b4 --- /dev/null +++ b/src/app/browser/window/tab/item/page/content/status/identity.rs @@ -0,0 +1,29 @@ +use adw::StatusPage; +use gtk::{prelude::ButtonExt, Align, Button}; + +// Defaults +const DEFAULT_ICON_NAME: &str = "avatar-default-symbolic"; +const DEFAULT_TITLE: &str = "Identity"; +const DEFAULT_DESCRIPTION: &str = "Client certificate required to continue!"; +const DEFAULT_BUTTON_LABEL: &str = "Select"; + +/// Create new default preset for `Identity` +/// [StatusPage](https://gnome.pages.gitlab.gnome.org/libadwaita/doc/main/class.StatusPage.html) +pub fn new_gobject() -> StatusPage { + // Init certificate selection + let button = &Button::builder() + .label(DEFAULT_BUTTON_LABEL) + .halign(Align::Center) + .build(); + + // Init events + button.connect_activate(|_| {}); // @TODO + + // Init status page + StatusPage::builder() + .description(DEFAULT_DESCRIPTION) + .icon_name(DEFAULT_ICON_NAME) + .title(DEFAULT_TITLE) + .child(button) + .build() +}