add sensitive input status code support

This commit is contained in:
yggverse 2024-10-17 16:34:35 +03:00
parent a15738f391
commit 861046e162
8 changed files with 231 additions and 18 deletions

View File

@ -284,12 +284,20 @@ impl Page {
let description = gformat!("{placeholder}");
// Make input form
input.set_new_response(
action_page_open, uri,
Some(&description),
Some(1024),
"11" == code.as_str() // sensitive input
);
if "11" == code.as_str() { // sensitive input
input.set_new_sensitive(
action_page_open, uri,
Some(&description),
Some(1024),
);
} else {
input.set_new_response(
action_page_open, uri,
Some(&description),
Some(1024),
);
}
// Update meta
meta.borrow_mut().status = Some(status);

View File

@ -1,8 +1,10 @@
mod response;
mod sensitive;
mod widget;
use gtk::{gio::SimpleAction, glib::Uri};
use response::Response;
use sensitive::Sensitive;
use widget::Widget;
use adw::Clamp;
@ -34,17 +36,21 @@ impl Input {
base: Uri,
title: Option<&str>,
size_limit: Option<usize>,
is_sensitive_input: bool,
) {
self.widget.update(Some(
&Response::new_arc(
action_page_open,
base,
title,
size_limit,
is_sensitive_input,
)
.gobject(),
&Response::new_arc(action_page_open, base, title, size_limit).gobject(),
));
}
pub fn set_new_sensitive(
&self,
action_page_open: Arc<SimpleAction>,
base: Uri,
title: Option<&str>,
max_length: Option<i32>,
) {
self.widget.update(Some(
&Sensitive::new_arc(action_page_open, base, title, max_length).gobject(),
));
}

View File

@ -28,7 +28,6 @@ impl Response {
base: Uri,
title: Option<&str>,
size_limit: Option<usize>,
is_sensitive_input: bool,
) -> Arc<Self> {
// Init local actions
let action_update = Arc::new(SimpleAction::new(&uuid_string_random(), None));
@ -36,7 +35,7 @@ impl Response {
// Init components
let control = Control::new_arc(action_send.clone());
let form = Form::new_arc(action_update.clone(), is_sensitive_input);
let form = Form::new_arc(action_update.clone());
let title = Title::new_arc(title);
// Init widget

View File

@ -11,7 +11,7 @@ pub struct Form {
impl Form {
// Construct
pub fn new_arc(action_update: Arc<SimpleAction>, is_sensitive_input: bool) -> Arc<Self> {
pub fn new_arc(action_update: Arc<SimpleAction>) -> Arc<Self> {
// Init widget
let widget = Widget::new_arc(action_update);

View File

@ -0,0 +1,71 @@
mod form;
mod widget;
use form::Form;
use widget::Widget;
use gtk::{
gio::SimpleAction,
glib::{uuid_string_random, Uri, UriHideFlags},
prelude::{ActionExt, ToVariant, WidgetExt},
Box,
};
use std::sync::Arc;
pub struct Sensitive {
// Components
widget: Arc<Widget>,
}
impl Sensitive {
// Construct
pub fn new_arc(
action_page_open: Arc<SimpleAction>,
base: Uri,
title: Option<&str>,
max_length: Option<i32>,
) -> Arc<Self> {
// Init local actions
let action_send = Arc::new(SimpleAction::new(&uuid_string_random(), None));
// Init components
let form = Form::new_arc(
action_send.clone(),
title,
match max_length {
Some(value) => {
Some(value - base.to_string_partial(UriHideFlags::QUERY).len() as i32)
}
None => None,
},
);
// Init widget
let widget = Widget::new_arc(form.gobject());
// Init events
action_send.connect_activate({
let form = form.clone();
move |_, _| {
action_page_open.activate(Some(
&format!(
"{}?{}",
base.to_string_partial(UriHideFlags::QUERY),
Uri::escape_string(form.text().as_str(), None, false),
)
.to_variant(),
));
}
});
widget.gobject().connect_realize(move |_| form.focus());
// Return activated struct
Arc::new(Self { widget })
}
// Getters
pub fn gobject(&self) -> &Box {
&self.widget.gobject()
}
}

View File

@ -0,0 +1,40 @@
mod widget;
use widget::Widget;
use adw::PasswordEntryRow;
use gtk::{gio::SimpleAction, glib::GString};
use std::sync::Arc;
pub struct Form {
widget: Arc<Widget>,
}
impl Form {
// Construct
pub fn new_arc(
action_send: Arc<SimpleAction>,
title: Option<&str>,
max_length: Option<i32>,
) -> Arc<Self> {
// Init widget
let widget = Widget::new_arc(action_send, title, max_length);
// Result
Arc::new(Self { widget })
}
// Actions
pub fn focus(&self) {
self.widget.focus();
}
// Getters
pub fn text(&self) -> GString {
self.widget.text()
}
pub fn gobject(&self) -> &PasswordEntryRow {
&self.widget.gobject()
}
}

View File

@ -0,0 +1,56 @@
use adw::{
prelude::{EntryRowExt, PreferencesRowExt},
PasswordEntryRow,
};
use gtk::{
gio::SimpleAction,
glib::GString,
prelude::{ActionExt, EditableExt, WidgetExt},
};
use std::sync::Arc;
pub struct Widget {
gobject: PasswordEntryRow,
}
impl Widget {
// Construct
pub fn new_arc(
action_send: Arc<SimpleAction>,
title: Option<&str>,
max_length: Option<i32>,
) -> Arc<Self> {
// Init gobject
let gobject = PasswordEntryRow::builder().show_apply_button(true).build();
if let Some(value) = title {
gobject.set_title(value);
}
if let Some(value) = max_length {
gobject.set_max_length(value);
}
// Init events
gobject.connect_apply(move |_| {
action_send.activate(None);
});
// Return activated struct
Arc::new(Self { gobject })
}
// Actions
pub fn focus(&self) {
self.gobject.grab_focus();
}
// Getters
pub fn text(&self) -> GString {
self.gobject.text()
}
pub fn gobject(&self) -> &PasswordEntryRow {
&self.gobject
}
}

View File

@ -0,0 +1,33 @@
use adw::PasswordEntryRow;
use gtk::{prelude::BoxExt, Box, Orientation};
use std::sync::Arc;
const MARGIN: i32 = 6;
const SPACING: i32 = 8;
pub struct Widget {
gobject: Box,
}
impl Widget {
// Construct
pub fn new_arc(response: &PasswordEntryRow) -> Arc<Self> {
let gobject = Box::builder()
.margin_bottom(MARGIN)
.margin_end(MARGIN)
.margin_start(MARGIN)
.margin_top(MARGIN)
.spacing(SPACING)
.orientation(Orientation::Vertical)
.build();
gobject.append(response);
Arc::new(Self { gobject })
}
// Getters
pub fn gobject(&self) -> &Box {
&self.gobject
}
}