mirror of
https://github.com/YGGverse/Yoda.git
synced 2026-04-01 00:55:28 +00:00
implement exit button as trait, set disconnect button status update by total
This commit is contained in:
parent
e1345a4922
commit
91cd9cbae9
4 changed files with 41 additions and 26 deletions
|
|
@ -14,19 +14,22 @@ use save::Save;
|
|||
|
||||
use super::WidgetAction;
|
||||
use crate::Profile;
|
||||
use gtk::{glib::Uri, prelude::BoxExt, Box, Orientation};
|
||||
use gtk::{
|
||||
glib::Uri,
|
||||
prelude::{BoxExt, WidgetExt},
|
||||
Box, Button, Orientation,
|
||||
};
|
||||
use std::rc::Rc;
|
||||
|
||||
pub struct Form {
|
||||
// pub action_widget: Rc<Action>,
|
||||
pub drop: Rc<Drop>,
|
||||
pub exit: Rc<Exit>,
|
||||
pub exit: Button,
|
||||
pub file: Rc<File>,
|
||||
pub list: Rc<List>,
|
||||
pub name: Rc<Name>,
|
||||
pub save: Rc<Save>,
|
||||
pub g_box: Box,
|
||||
request: Uri,
|
||||
profile: Rc<Profile>,
|
||||
}
|
||||
|
||||
|
|
@ -41,7 +44,7 @@ impl Form {
|
|||
let name = Rc::new(Name::build(widget_action));
|
||||
let save = Rc::new(Save::build(profile, &list));
|
||||
let drop = Rc::new(Drop::build(profile, &list));
|
||||
let exit = Rc::new(Exit::build(widget_action, profile, &list, request));
|
||||
let exit = Button::exit(widget_action, profile, &list, request);
|
||||
|
||||
// Init main container
|
||||
let g_box = Box::builder().orientation(Orientation::Vertical).build();
|
||||
|
|
@ -49,7 +52,7 @@ impl Form {
|
|||
g_box.append(&list.dropdown);
|
||||
g_box.append(&name.entry);
|
||||
g_box.append(&file.button);
|
||||
g_box.append(&exit.button);
|
||||
g_box.append(&exit);
|
||||
g_box.append(&drop.button);
|
||||
g_box.append(&save.button);
|
||||
|
||||
|
|
@ -63,7 +66,6 @@ impl Form {
|
|||
name,
|
||||
save,
|
||||
g_box,
|
||||
request: request.clone(),
|
||||
profile: profile.clone(),
|
||||
}
|
||||
}
|
||||
|
|
@ -90,18 +92,15 @@ impl Form {
|
|||
match value {
|
||||
Value::ProfileIdentityId(profile_identity_id) => {
|
||||
self.drop.update(true);
|
||||
self.exit.update(
|
||||
true,
|
||||
self.profile
|
||||
.identity
|
||||
.auth
|
||||
.is_matches(&self.request.to_string(), profile_identity_id),
|
||||
);
|
||||
self.exit.set_visible(true);
|
||||
self.exit
|
||||
.set_sensitive(self.profile.identity.auth.total(profile_identity_id) > 0);
|
||||
self.save.update(true);
|
||||
}
|
||||
_ => {
|
||||
self.drop.update(false);
|
||||
self.exit.update(false, false);
|
||||
self.exit.set_visible(false);
|
||||
self.exit.set_sensitive(false);
|
||||
self.save.update(false);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -25,15 +25,20 @@ const BODY: &str = "Stop use selected identity for all scopes?";
|
|||
const RESPONSE_CANCEL: (&str, &str) = ("cancel", "Cancel");
|
||||
const RESPONSE_CONFIRM: (&str, &str) = ("confirm", "Confirm");
|
||||
|
||||
pub struct Exit {
|
||||
pub button: Button,
|
||||
pub trait Exit {
|
||||
fn exit(
|
||||
widget_action: &Rc<WidgetAction>,
|
||||
profile: &Rc<Profile>,
|
||||
list: &Rc<List>,
|
||||
request: &Uri,
|
||||
) -> Self;
|
||||
}
|
||||
|
||||
impl Exit {
|
||||
impl Exit for Button {
|
||||
// Constructors
|
||||
|
||||
/// Create new `Self`
|
||||
pub fn build(
|
||||
fn exit(
|
||||
widget_action: &Rc<WidgetAction>,
|
||||
profile: &Rc<Profile>,
|
||||
list: &Rc<List>,
|
||||
|
|
@ -122,13 +127,6 @@ impl Exit {
|
|||
});
|
||||
|
||||
// Return activated `Self`
|
||||
Self { button }
|
||||
}
|
||||
|
||||
// Actions
|
||||
|
||||
pub fn update(&self, is_visible: bool, is_sensitive: bool) {
|
||||
self.button.set_visible(is_visible);
|
||||
self.button.set_sensitive(is_sensitive);
|
||||
button
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -124,6 +124,11 @@ impl Auth {
|
|||
.is_some_and(|auth| auth.profile_identity_id == profile_identity_id)
|
||||
}
|
||||
|
||||
/// Check request string matches condition
|
||||
pub fn total(&self, profile_identity_id: i64) -> usize {
|
||||
self.memory.total(profile_identity_id)
|
||||
}
|
||||
|
||||
/// Collect certificate scope vector from `Profile` database for `profile_identity_id`
|
||||
pub fn scope(&self, profile_identity_id: i64) -> Vec<String> {
|
||||
let mut scope = Vec::new();
|
||||
|
|
|
|||
|
|
@ -79,4 +79,17 @@ impl Memory {
|
|||
// Get first copy
|
||||
result.first().cloned()
|
||||
}
|
||||
|
||||
/// Get identity exactly match `scope`
|
||||
/// * [Client certificates specification](https://geminiprotocol.net/docs/protocol-specification.gmi#client-certificates)
|
||||
/// * see also parent `is_match_request`
|
||||
pub fn total(&self, profile_identity_id: i64) -> usize {
|
||||
let mut total = 0;
|
||||
for (_, _profile_identity_id) in self.index.borrow().iter() {
|
||||
if *_profile_identity_id == profile_identity_id {
|
||||
total += 1
|
||||
}
|
||||
}
|
||||
total
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue