mirror of
https://github.com/YGGverse/Yoda.git
synced 2025-03-13 06:01:21 +00:00
draft 10, 11 status codes
This commit is contained in:
parent
e865221598
commit
80aea6a653
@ -37,6 +37,7 @@ pub struct Page {
|
||||
// Components
|
||||
navigation: Arc<Navigation>,
|
||||
content: Arc<Content>,
|
||||
request: Arc<Request>,
|
||||
// Extras
|
||||
meta: Arc<RefCell<Meta>>,
|
||||
// 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() {
|
||||
|
@ -12,11 +12,13 @@ pub enum Mime {
|
||||
pub enum Status {
|
||||
Connect,
|
||||
Failure,
|
||||
Input,
|
||||
Prepare,
|
||||
Redirect,
|
||||
Reload,
|
||||
Request,
|
||||
Response,
|
||||
SensitiveInput,
|
||||
Success,
|
||||
}
|
||||
|
||||
|
@ -8,10 +8,12 @@ use adw::ToolbarView;
|
||||
use std::sync::Arc;
|
||||
|
||||
pub struct Request {
|
||||
content: Arc<Content>,
|
||||
widget: Arc<Widget>,
|
||||
}
|
||||
|
||||
impl Request {
|
||||
// Construct
|
||||
pub fn new_arc() -> Arc<Self> {
|
||||
// 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
|
||||
|
@ -10,10 +10,12 @@ use gtk::Box;
|
||||
use std::sync::Arc;
|
||||
|
||||
pub struct Content {
|
||||
response: Arc<Response>,
|
||||
widget: Arc<Widget>,
|
||||
}
|
||||
|
||||
impl Content {
|
||||
// Construct
|
||||
pub fn new_arc() -> Arc<Self> {
|
||||
// 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
|
||||
|
@ -10,6 +10,7 @@ pub struct Response {
|
||||
}
|
||||
|
||||
impl Response {
|
||||
// Construct
|
||||
pub fn new_arc() -> Arc<Self> {
|
||||
// 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()
|
||||
|
@ -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
|
||||
|
Loading…
x
Reference in New Issue
Block a user