Skip to content

Commit

Permalink
optimize identity dialog mod
Browse files Browse the repository at this point in the history
  • Loading branch information
yggverse committed Jan 29, 2025
1 parent fc8c967 commit a8008ad
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 56 deletions.
9 changes: 6 additions & 3 deletions src/app/browser/window/tab/item/page/navigation/request.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down Expand Up @@ -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<Profile>) {
// 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({
Expand All @@ -264,7 +267,7 @@ impl Request for Entry {
.present(Some(self));
}
}
identity::unsupported().present(Some(self));
AlertDialog::unsupported().present(Some(self));
}

// Setters
Expand Down
Original file line number Diff line number Diff line change
@@ -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<Profile>,
request: &Uri,
callback: &Rc<impl Fn(bool) + 'static>,
) -> 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;
Original file line number Diff line number Diff line change
@@ -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 {
Expand All @@ -37,6 +23,17 @@ impl Common for AlertDialog {
request: &Uri,
callback: &Rc<impl Fn(bool) + 'static>,
) -> 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());

Expand All @@ -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)
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -16,29 +9,35 @@ 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)
.default_response(RESPONSE_QUIT.0)
.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
}
}

0 comments on commit a8008ad

Please sign in to comment.