From a8008ad92cbf8c61ee06d316729bcbbf010ef83e Mon Sep 17 00:00:00 2001 From: yggverse Date: Wed, 29 Jan 2025 19:49:54 +0200 Subject: [PATCH] optimize identity dialog mod --- .../tab/item/page/navigation/request.rs | 9 +++-- .../item/page/navigation/request/identity.rs | 23 ++---------- .../navigation/request/identity/common.rs | 35 +++++++++---------- .../request/identity/unsupported.rs | 25 +++++++------ 4 files changed, 36 insertions(+), 56 deletions(-) diff --git a/src/app/browser/window/tab/item/page/navigation/request.rs b/src/app/browser/window/tab/item/page/navigation/request.rs index 75d60db0..9029ed86 100644 --- a/src/app/browser/window/tab/item/page/navigation/request.rs +++ b/src/app/browser/window/tab/item/page/navigation/request.rs @@ -2,7 +2,7 @@ mod database; mod identity; mod primary_icon; -use adw::prelude::AdwDialogExt; +use adw::{prelude::AdwDialogExt, AlertDialog}; use primary_icon::PrimaryIcon; use super::{ItemAction, Profile}; @@ -244,10 +244,13 @@ impl Request for Entry { } } + /// Present identity [AlertDialog](https://gnome.pages.gitlab.gnome.org/libadwaita/doc/main/class.AlertDialog.html) for `Self` fn identity(&self, profile: &Rc) { + // connect identity traits + use identity::{Common, Unsupported}; if let Some(uri) = self.uri() { if ["gemini", "titan"].contains(&uri.scheme().as_str()) { - return identity::common( + return AlertDialog::common( profile, &uri, &Rc::new({ @@ -264,7 +267,7 @@ impl Request for Entry { .present(Some(self)); } } - identity::unsupported().present(Some(self)); + AlertDialog::unsupported().present(Some(self)); } // Setters diff --git a/src/app/browser/window/tab/item/page/navigation/request/identity.rs b/src/app/browser/window/tab/item/page/navigation/request/identity.rs index f4577ed1..58d3f156 100644 --- a/src/app/browser/window/tab/item/page/navigation/request/identity.rs +++ b/src/app/browser/window/tab/item/page/navigation/request/identity.rs @@ -1,24 +1,5 @@ mod common; mod unsupported; -use adw::AlertDialog; -use common::Common; -use unsupported::Unsupported; - -use super::Profile; -use gtk::glib::Uri; -use std::rc::Rc; - -/// Create new identity widget for Gemini protocol match given URI -pub fn common( - profile: &Rc, - request: &Uri, - callback: &Rc, -) -> AlertDialog { - AlertDialog::common(profile, request, callback) -} - -/// Create new identity widget for unknown request -pub fn unsupported() -> AlertDialog { - AlertDialog::unsupported() -} +pub use common::Common; +pub use unsupported::Unsupported; diff --git a/src/app/browser/window/tab/item/page/navigation/request/identity/common.rs b/src/app/browser/window/tab/item/page/navigation/request/identity/common.rs index ea77c6e4..052fd32b 100644 --- a/src/app/browser/window/tab/item/page/navigation/request/identity/common.rs +++ b/src/app/browser/window/tab/item/page/navigation/request/identity/common.rs @@ -1,26 +1,12 @@ mod action; -pub mod form; - -use action::Action as WidgetAction; -use form::{list::item::value::Value, Form}; +mod form; use crate::Profile; -use adw::{ - prelude::{AlertDialogExt, AlertDialogExtManual}, - AlertDialog, ResponseAppearance, -}; +use action::Action as WidgetAction; +use adw::AlertDialog; use gtk::glib::Uri; use std::rc::Rc; -// Defaults -const HEADING: &str = "Identity"; -const BODY: &str = "Select identity certificate"; - -// Response variants -const RESPONSE_APPLY: (&str, &str) = ("apply", "Apply"); -const RESPONSE_CANCEL: (&str, &str) = ("cancel", "Cancel"); -// const RESPONSE_MANAGE: (&str, &str) = ("manage", "Manage"); - // Select options pub trait Common { @@ -37,6 +23,17 @@ impl Common for AlertDialog { request: &Uri, callback: &Rc, ) -> Self { + use adw::{ + prelude::{AlertDialogExt, AlertDialogExtManual}, + ResponseAppearance, + }; + use form::{list::item::value::Value, Form}; + + // Response variants + const RESPONSE_APPLY: (&str, &str) = ("apply", "Apply"); + const RESPONSE_CANCEL: (&str, &str) = ("cancel", "Cancel"); + // const RESPONSE_MANAGE: (&str, &str) = ("manage", "Manage"); + // Init actions let action = Rc::new(WidgetAction::new()); @@ -45,8 +42,8 @@ impl Common for AlertDialog { // Init main widget let alert_dialog = AlertDialog::builder() - .heading(HEADING) - .body(BODY) + .heading("Identity") + .body("Select identity certificate") .close_response(RESPONSE_CANCEL.0) .default_response(RESPONSE_APPLY.0) .extra_child(&form.g_box) diff --git a/src/app/browser/window/tab/item/page/navigation/request/identity/unsupported.rs b/src/app/browser/window/tab/item/page/navigation/request/identity/unsupported.rs index b664a12b..dd20ef28 100644 --- a/src/app/browser/window/tab/item/page/navigation/request/identity/unsupported.rs +++ b/src/app/browser/window/tab/item/page/navigation/request/identity/unsupported.rs @@ -1,11 +1,4 @@ -use adw::{ - prelude::{AdwDialogExt, AlertDialogExt, AlertDialogExtManual}, - AlertDialog, -}; - -const HEADING: &str = "Oops"; -const BODY: &str = "Identity not supported for this request"; -const RESPONSE_QUIT: (&str, &str) = ("close", "Close"); +use adw::AlertDialog; pub trait Unsupported { fn unsupported() -> Self; @@ -16,8 +9,14 @@ impl Unsupported for AlertDialog { /// Create new `Self` fn unsupported() -> Self { + use adw::prelude::{AdwDialogExt, AlertDialogExt, AlertDialogExtManual}; + + const HEADING: &str = "Oops"; + const BODY: &str = "Identity not supported for this request"; + const RESPONSE_QUIT: (&str, &str) = ("close", "Close"); + // Init gobject - let this = AlertDialog::builder() + let alert_dialog = AlertDialog::builder() .heading(HEADING) .body(BODY) .close_response(RESPONSE_QUIT.0) @@ -25,20 +24,20 @@ impl Unsupported for AlertDialog { .build(); // Set response variants - this.add_responses(&[RESPONSE_QUIT]); + alert_dialog.add_responses(&[RESPONSE_QUIT]); // Decorate default response preset /* contrast issue with Ubuntu orange accents - this.set_response_appearance(RESPONSE_QUIT.0, ResponseAppearance::Destructive); */ + alert_dialog.set_response_appearance(RESPONSE_QUIT.0, ResponseAppearance::Destructive); */ // Init events - this.connect_response(None, move |dialog, response| { + alert_dialog.connect_response(None, move |dialog, response| { if response == RESPONSE_QUIT.0 { dialog.close(); } }); // Return new activated `Self` - this + alert_dialog } }