mirror of
https://github.com/YGGverse/Yoda.git
synced 2026-04-02 17:45:28 +00:00
draft 10, 11 status codes
This commit is contained in:
parent
e865221598
commit
80aea6a653
6 changed files with 68 additions and 3 deletions
|
|
@ -37,6 +37,7 @@ pub struct Page {
|
||||||
// Components
|
// Components
|
||||||
navigation: Arc<Navigation>,
|
navigation: Arc<Navigation>,
|
||||||
content: Arc<Content>,
|
content: Arc<Content>,
|
||||||
|
request: Arc<Request>,
|
||||||
// Extras
|
// Extras
|
||||||
meta: Arc<RefCell<Meta>>,
|
meta: Arc<RefCell<Meta>>,
|
||||||
// GTK
|
// GTK
|
||||||
|
|
@ -116,6 +117,7 @@ impl Page {
|
||||||
// Components
|
// Components
|
||||||
content,
|
content,
|
||||||
navigation,
|
navigation,
|
||||||
|
request,
|
||||||
// Extras
|
// Extras
|
||||||
meta,
|
meta,
|
||||||
// GTK
|
// GTK
|
||||||
|
|
@ -163,6 +165,7 @@ impl Page {
|
||||||
let id = self.id.to_variant();
|
let id = self.id.to_variant();
|
||||||
let navigation = self.navigation.clone();
|
let navigation = self.navigation.clone();
|
||||||
let content = self.content.clone();
|
let content = self.content.clone();
|
||||||
|
let request = self.request.clone();
|
||||||
let meta = self.meta.clone();
|
let meta = self.meta.clone();
|
||||||
let action_update = self.action_update.clone();
|
let action_update = self.action_update.clone();
|
||||||
|
|
||||||
|
|
@ -267,6 +270,36 @@ impl Page {
|
||||||
// https://geminiprotocol.net/docs/protocol-specification.gmi#status-codes
|
// https://geminiprotocol.net/docs/protocol-specification.gmi#status-codes
|
||||||
match parts.get(1) {
|
match parts.get(1) {
|
||||||
Some(code) => match code.as_str() {
|
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" => {
|
"20" => {
|
||||||
match parts.get(2) {
|
match parts.get(2) {
|
||||||
Some(mime) => match mime.as_str() {
|
Some(mime) => match mime.as_str() {
|
||||||
|
|
|
||||||
|
|
@ -12,11 +12,13 @@ pub enum Mime {
|
||||||
pub enum Status {
|
pub enum Status {
|
||||||
Connect,
|
Connect,
|
||||||
Failure,
|
Failure,
|
||||||
|
Input,
|
||||||
Prepare,
|
Prepare,
|
||||||
Redirect,
|
Redirect,
|
||||||
Reload,
|
Reload,
|
||||||
Request,
|
Request,
|
||||||
Response,
|
Response,
|
||||||
|
SensitiveInput,
|
||||||
Success,
|
Success,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -8,10 +8,12 @@ use adw::ToolbarView;
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
|
|
||||||
pub struct Request {
|
pub struct Request {
|
||||||
|
content: Arc<Content>,
|
||||||
widget: Arc<Widget>,
|
widget: Arc<Widget>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Request {
|
impl Request {
|
||||||
|
// Construct
|
||||||
pub fn new_arc() -> Arc<Self> {
|
pub fn new_arc() -> Arc<Self> {
|
||||||
// Init components
|
// Init components
|
||||||
let content = Content::new_arc();
|
let content = Content::new_arc();
|
||||||
|
|
@ -20,7 +22,12 @@ impl Request {
|
||||||
let widget = Widget::new_arc(content.gobject());
|
let widget = Widget::new_arc(content.gobject());
|
||||||
|
|
||||||
// Result
|
// 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
|
// Getters
|
||||||
|
|
|
||||||
|
|
@ -10,10 +10,12 @@ use gtk::Box;
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
|
|
||||||
pub struct Content {
|
pub struct Content {
|
||||||
|
response: Arc<Response>,
|
||||||
widget: Arc<Widget>,
|
widget: Arc<Widget>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Content {
|
impl Content {
|
||||||
|
// Construct
|
||||||
pub fn new_arc() -> Arc<Self> {
|
pub fn new_arc() -> Arc<Self> {
|
||||||
// Init components
|
// Init components
|
||||||
let response = Response::new_arc();
|
let response = Response::new_arc();
|
||||||
|
|
@ -28,7 +30,12 @@ impl Content {
|
||||||
send.gobject().connect_clicked(|_| {}); */
|
send.gobject().connect_clicked(|_| {}); */
|
||||||
|
|
||||||
// Return activated struct
|
// 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
|
// Getters
|
||||||
|
|
|
||||||
|
|
@ -10,6 +10,7 @@ pub struct Response {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Response {
|
impl Response {
|
||||||
|
// Construct
|
||||||
pub fn new_arc() -> Arc<Self> {
|
pub fn new_arc() -> Arc<Self> {
|
||||||
// Init widget
|
// Init widget
|
||||||
let widget = Widget::new_arc();
|
let widget = Widget::new_arc();
|
||||||
|
|
@ -18,6 +19,11 @@ impl Response {
|
||||||
Arc::new(Self { widget })
|
Arc::new(Self { widget })
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Actions
|
||||||
|
pub fn set(&self, placeholder: &str, sensitive: bool) {
|
||||||
|
self.widget.set(placeholder, sensitive);
|
||||||
|
}
|
||||||
|
|
||||||
// Getters
|
// Getters
|
||||||
pub fn gobject(&self) -> &Entry {
|
pub fn gobject(&self) -> &Entry {
|
||||||
&self.widget.gobject()
|
&self.widget.gobject()
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,7 @@
|
||||||
use gtk::Entry;
|
use gtk::{
|
||||||
|
prelude::{EditableExt, EntryExt, WidgetExt},
|
||||||
|
Entry,
|
||||||
|
};
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
|
|
||||||
pub struct Widget {
|
pub struct Widget {
|
||||||
|
|
@ -13,6 +16,13 @@ impl Widget {
|
||||||
Arc::new(Self { gobject })
|
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
|
// Getters
|
||||||
pub fn gobject(&self) -> &Entry {
|
pub fn gobject(&self) -> &Entry {
|
||||||
&self.gobject
|
&self.gobject
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue