diff --git a/src/app/browser/window/tab/item/page.rs b/src/app/browser/window/tab/item/page.rs index becb8178..2cf461b7 100644 --- a/src/app/browser/window/tab/item/page.rs +++ b/src/app/browser/window/tab/item/page.rs @@ -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); diff --git a/src/app/browser/window/tab/item/page/input.rs b/src/app/browser/window/tab/item/page/input.rs index 85994e71..41351f7d 100644 --- a/src/app/browser/window/tab/item/page/input.rs +++ b/src/app/browser/window/tab/item/page/input.rs @@ -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, - 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, + base: Uri, + title: Option<&str>, + max_length: Option, + ) { + self.widget.update(Some( + &Sensitive::new_arc(action_page_open, base, title, max_length).gobject(), )); } diff --git a/src/app/browser/window/tab/item/page/input/response.rs b/src/app/browser/window/tab/item/page/input/response.rs index d17a2565..5c0138fe 100644 --- a/src/app/browser/window/tab/item/page/input/response.rs +++ b/src/app/browser/window/tab/item/page/input/response.rs @@ -28,7 +28,6 @@ impl Response { base: Uri, title: Option<&str>, size_limit: Option, - is_sensitive_input: bool, ) -> Arc { // 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 diff --git a/src/app/browser/window/tab/item/page/input/response/form.rs b/src/app/browser/window/tab/item/page/input/response/form.rs index 5a2430ed..a80d7fd1 100644 --- a/src/app/browser/window/tab/item/page/input/response/form.rs +++ b/src/app/browser/window/tab/item/page/input/response/form.rs @@ -11,7 +11,7 @@ pub struct Form { impl Form { // Construct - pub fn new_arc(action_update: Arc, is_sensitive_input: bool) -> Arc { + pub fn new_arc(action_update: Arc) -> Arc { // Init widget let widget = Widget::new_arc(action_update); diff --git a/src/app/browser/window/tab/item/page/input/sensitive.rs b/src/app/browser/window/tab/item/page/input/sensitive.rs new file mode 100644 index 00000000..48de60c4 --- /dev/null +++ b/src/app/browser/window/tab/item/page/input/sensitive.rs @@ -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, +} + +impl Sensitive { + // Construct + pub fn new_arc( + action_page_open: Arc, + base: Uri, + title: Option<&str>, + max_length: Option, + ) -> Arc { + // 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() + } +} diff --git a/src/app/browser/window/tab/item/page/input/sensitive/form.rs b/src/app/browser/window/tab/item/page/input/sensitive/form.rs new file mode 100644 index 00000000..3118baa2 --- /dev/null +++ b/src/app/browser/window/tab/item/page/input/sensitive/form.rs @@ -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, +} + +impl Form { + // Construct + pub fn new_arc( + action_send: Arc, + title: Option<&str>, + max_length: Option, + ) -> Arc { + // 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() + } +} diff --git a/src/app/browser/window/tab/item/page/input/sensitive/form/widget.rs b/src/app/browser/window/tab/item/page/input/sensitive/form/widget.rs new file mode 100644 index 00000000..498f94ef --- /dev/null +++ b/src/app/browser/window/tab/item/page/input/sensitive/form/widget.rs @@ -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, + title: Option<&str>, + max_length: Option, + ) -> Arc { + // 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 + } +} diff --git a/src/app/browser/window/tab/item/page/input/sensitive/widget.rs b/src/app/browser/window/tab/item/page/input/sensitive/widget.rs new file mode 100644 index 00000000..525bac42 --- /dev/null +++ b/src/app/browser/window/tab/item/page/input/sensitive/widget.rs @@ -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 { + 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 + } +}