diff --git a/src/app/browser/window/tab/item/page.rs b/src/app/browser/window/tab/item/page.rs index e8613ebb..5101704d 100644 --- a/src/app/browser/window/tab/item/page.rs +++ b/src/app/browser/window/tab/item/page.rs @@ -37,6 +37,7 @@ pub struct Page { // Components navigation: Arc, content: Arc, + request: Arc, // Extras meta: Arc>, // GTK @@ -116,6 +117,7 @@ impl Page { // Components content, navigation, + request, // Extras meta, // GTK @@ -163,6 +165,7 @@ impl Page { let id = self.id.to_variant(); let navigation = self.navigation.clone(); let content = self.content.clone(); + let request = self.request.clone(); let meta = self.meta.clone(); let action_update = self.action_update.clone(); @@ -267,6 +270,36 @@ impl Page { // https://geminiprotocol.net/docs/protocol-specification.gmi#status-codes match parts.get(1) { Some(code) => match code.as_str() { + // Input expected + "10" => { + match parts.get(4) { + Some(placeholder) => { + // Format response + meta.borrow_mut().status = Some(Status::Input); + meta.borrow_mut().description = None; // @TODO + meta.borrow_mut().title = Some(gformat!("Input expected")); + + request.show(&placeholder, false); + }, + None => todo!(), + } + + }, + // Sensitive input expected + "11" => { + match parts.get(4) { + Some(placeholder) => { + // Format response + meta.borrow_mut().status = Some(Status::SensitiveInput); + meta.borrow_mut().description = None; // @TODO + meta.borrow_mut().title = Some(gformat!("Input expected")); + + request.show(&placeholder, true); + }, + None => todo!(), + } + }, + // Success "20" => { match parts.get(2) { Some(mime) => match mime.as_str() { diff --git a/src/app/browser/window/tab/item/page/meta.rs b/src/app/browser/window/tab/item/page/meta.rs index ed70289f..29327107 100644 --- a/src/app/browser/window/tab/item/page/meta.rs +++ b/src/app/browser/window/tab/item/page/meta.rs @@ -12,11 +12,13 @@ pub enum Mime { pub enum Status { Connect, Failure, + Input, Prepare, Redirect, Reload, Request, Response, + SensitiveInput, Success, } diff --git a/src/app/browser/window/tab/item/page/request.rs b/src/app/browser/window/tab/item/page/request.rs index dcb9232d..faa5d995 100644 --- a/src/app/browser/window/tab/item/page/request.rs +++ b/src/app/browser/window/tab/item/page/request.rs @@ -8,10 +8,12 @@ use adw::ToolbarView; use std::sync::Arc; pub struct Request { + content: Arc, widget: Arc, } impl Request { + // Construct pub fn new_arc() -> Arc { // Init components let content = Content::new_arc(); @@ -20,7 +22,12 @@ impl Request { let widget = Widget::new_arc(content.gobject()); // Result - Arc::new(Self { widget }) + Arc::new(Self { content, widget }) + } + + // Actions + pub fn show(&self, placeholder: &str, sensitive: bool) { + self.content.set(placeholder, sensitive); } // Getters diff --git a/src/app/browser/window/tab/item/page/request/content.rs b/src/app/browser/window/tab/item/page/request/content.rs index 7bfdfb6e..c5069547 100644 --- a/src/app/browser/window/tab/item/page/request/content.rs +++ b/src/app/browser/window/tab/item/page/request/content.rs @@ -10,10 +10,12 @@ use gtk::Box; use std::sync::Arc; pub struct Content { + response: Arc, widget: Arc, } impl Content { + // Construct pub fn new_arc() -> Arc { // Init components let response = Response::new_arc(); @@ -28,7 +30,12 @@ impl Content { send.gobject().connect_clicked(|_| {}); */ // Return activated struct - Arc::new(Self { widget }) + Arc::new(Self { response, widget }) + } + + // Actions + pub fn set(&self, placeholder: &str, sensitive: bool) { + self.response.set(placeholder, sensitive); } // Getters diff --git a/src/app/browser/window/tab/item/page/request/content/response.rs b/src/app/browser/window/tab/item/page/request/content/response.rs index 44369dcc..8f6d9051 100644 --- a/src/app/browser/window/tab/item/page/request/content/response.rs +++ b/src/app/browser/window/tab/item/page/request/content/response.rs @@ -10,6 +10,7 @@ pub struct Response { } impl Response { + // Construct pub fn new_arc() -> Arc { // Init widget let widget = Widget::new_arc(); @@ -18,6 +19,11 @@ impl Response { Arc::new(Self { widget }) } + // Actions + pub fn set(&self, placeholder: &str, sensitive: bool) { + self.widget.set(placeholder, sensitive); + } + // Getters pub fn gobject(&self) -> &Entry { &self.widget.gobject() diff --git a/src/app/browser/window/tab/item/page/request/content/response/widget.rs b/src/app/browser/window/tab/item/page/request/content/response/widget.rs index bc7a95ed..4f529aaf 100644 --- a/src/app/browser/window/tab/item/page/request/content/response/widget.rs +++ b/src/app/browser/window/tab/item/page/request/content/response/widget.rs @@ -1,4 +1,7 @@ -use gtk::Entry; +use gtk::{ + prelude::{EditableExt, EntryExt, WidgetExt}, + Entry, +}; use std::sync::Arc; pub struct Widget { @@ -13,6 +16,13 @@ impl Widget { Arc::new(Self { gobject }) } + // Actions + pub fn set(&self, placeholder_text: &str, sensitive: bool) { + self.gobject.set_text(&""); // reset + self.gobject.set_placeholder_text(Some(placeholder_text)); + self.gobject.set_sensitive(sensitive); + } + // Getters pub fn gobject(&self) -> &Entry { &self.gobject