mirror of
https://github.com/YGGverse/Yoda.git
synced 2026-03-31 16:45:27 +00:00
draft page info dialog components, enshort local variables name
This commit is contained in:
parent
20cbde8ce6
commit
731a55cf47
5 changed files with 305 additions and 85 deletions
|
|
@ -34,28 +34,54 @@ impl Gemini {
|
||||||
pub fn init(page: &Rc<Page>) -> Self {
|
pub fn init(page: &Rc<Page>) -> Self {
|
||||||
// Init supported protocol libraries
|
// Init supported protocol libraries
|
||||||
let client = Rc::new(ggemini::Client::new());
|
let client = Rc::new(ggemini::Client::new());
|
||||||
|
|
||||||
// Listen for [SocketClient](https://docs.gtk.org/gio/class.SocketClient.html) updates
|
// Listen for [SocketClient](https://docs.gtk.org/gio/class.SocketClient.html) updates
|
||||||
client.socket.connect_event({
|
client.socket.connect_event({
|
||||||
let page = page.clone();
|
let p = page.clone();
|
||||||
move |_, event, _, _| {
|
move |_, event, _, _| {
|
||||||
page.set_progress(match event {
|
let mut i = p.info.borrow_mut();
|
||||||
|
p.set_progress(match event {
|
||||||
// 0.1 reserved for handle begin
|
// 0.1 reserved for handle begin
|
||||||
SocketClientEvent::Resolving => 0.2,
|
SocketClientEvent::Resolving => {
|
||||||
SocketClientEvent::Resolved => 0.3,
|
i.add_event("Resolving".to_string());
|
||||||
SocketClientEvent::Connecting => 0.4,
|
0.2
|
||||||
SocketClientEvent::Connected => 0.5,
|
}
|
||||||
SocketClientEvent::ProxyNegotiating => 0.6,
|
SocketClientEvent::Resolved => {
|
||||||
SocketClientEvent::ProxyNegotiated => 0.7,
|
i.add_event("Resolved".to_string());
|
||||||
|
0.3
|
||||||
|
}
|
||||||
|
SocketClientEvent::Connecting => {
|
||||||
|
i.add_event("Connecting".to_string());
|
||||||
|
0.4
|
||||||
|
}
|
||||||
|
SocketClientEvent::Connected => {
|
||||||
|
i.add_event("Connected".to_string());
|
||||||
|
0.5
|
||||||
|
}
|
||||||
|
SocketClientEvent::ProxyNegotiating => {
|
||||||
|
i.add_event("Proxy negotiating".to_string());
|
||||||
|
0.6
|
||||||
|
}
|
||||||
|
SocketClientEvent::ProxyNegotiated => {
|
||||||
|
i.add_event("Proxy negotiated".to_string());
|
||||||
|
0.7
|
||||||
|
}
|
||||||
// * `TlsHandshaking` | `TlsHandshaked` has effect only for guest connections!
|
// * `TlsHandshaking` | `TlsHandshaked` has effect only for guest connections!
|
||||||
SocketClientEvent::TlsHandshaking => 0.8,
|
SocketClientEvent::TlsHandshaking => {
|
||||||
SocketClientEvent::TlsHandshaked => 0.9,
|
i.add_event("TLS handshaking".to_string());
|
||||||
SocketClientEvent::Complete => 1.0,
|
0.8
|
||||||
_ => todo!(), // alert on API change
|
}
|
||||||
|
SocketClientEvent::TlsHandshaked => {
|
||||||
|
i.add_event("TLS handshaked".to_string());
|
||||||
|
0.9
|
||||||
|
}
|
||||||
|
SocketClientEvent::Complete => {
|
||||||
|
i.add_event("Complete".to_string());
|
||||||
|
1.0
|
||||||
|
}
|
||||||
|
_ => panic!(), // alert on API change
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
Self {
|
Self {
|
||||||
client,
|
client,
|
||||||
redirects: Rc::new(Cell::new(0)),
|
redirects: Rc::new(Cell::new(0)),
|
||||||
|
|
@ -73,7 +99,6 @@ impl Gemini {
|
||||||
is_snap_history: bool,
|
is_snap_history: bool,
|
||||||
) {
|
) {
|
||||||
use ggemini::client::connection::Request;
|
use ggemini::client::connection::Request;
|
||||||
|
|
||||||
match uri.scheme().as_str() {
|
match uri.scheme().as_str() {
|
||||||
"gemini" => handle(
|
"gemini" => handle(
|
||||||
Request::Gemini { uri },
|
Request::Gemini { uri },
|
||||||
|
|
@ -153,26 +178,27 @@ fn handle(
|
||||||
Ok((response, connection)) => match response {
|
Ok((response, connection)) => match response {
|
||||||
// https://geminiprotocol.net/docs/protocol-specification.gmi#input-expected
|
// https://geminiprotocol.net/docs/protocol-specification.gmi#input-expected
|
||||||
Response::Input(input) => {
|
Response::Input(input) => {
|
||||||
let title = input.to_string();
|
let t = input.to_string();
|
||||||
page.set_progress(0.0);
|
page.set_progress(0.0);
|
||||||
page.set_title(&title);
|
page.set_title(&t);
|
||||||
if is_snap_history {
|
if is_snap_history {
|
||||||
page.snap_history();
|
page.snap_history();
|
||||||
}
|
}
|
||||||
redirects.replace(0); // reset
|
redirects.replace(0); // reset
|
||||||
|
update_page_info(&page, &uri, "Done");
|
||||||
match input {
|
match input {
|
||||||
// https://geminiprotocol.net/docs/protocol-specification.gmi#status-10
|
// https://geminiprotocol.net/docs/protocol-specification.gmi#status-10
|
||||||
Input::Default { message } => page.input.set_new_response(
|
Input::Default { message } => page.input.set_new_response(
|
||||||
page.item_action.clone(),
|
page.item_action.clone(),
|
||||||
uri,
|
uri,
|
||||||
Some(message.as_ref().unwrap_or(&title)),
|
Some(message.as_ref().unwrap_or(&t)),
|
||||||
Some(1024),
|
Some(1024),
|
||||||
),
|
),
|
||||||
// https://geminiprotocol.net/docs/protocol-specification.gmi#status-11-sensitive-input
|
// https://geminiprotocol.net/docs/protocol-specification.gmi#status-11-sensitive-input
|
||||||
Input::Sensitive { message } => page.input.set_new_sensitive(
|
Input::Sensitive { message } => page.input.set_new_sensitive(
|
||||||
page.item_action.clone(),
|
page.item_action.clone(),
|
||||||
uri,
|
uri,
|
||||||
Some(message.as_ref().unwrap_or(&title)),
|
Some(message.as_ref().unwrap_or(&t)),
|
||||||
Some(1024),
|
Some(1024),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
@ -181,7 +207,7 @@ fn handle(
|
||||||
Response::Success(success) => match *feature {
|
Response::Success(success) => match *feature {
|
||||||
Feature::Download => {
|
Feature::Download => {
|
||||||
// Init download widget
|
// Init download widget
|
||||||
let status = page.content.to_status_download(
|
let s = page.content.to_status_download(
|
||||||
crate::tool::uri_to_title(&uri).trim_matches(MAIN_SEPARATOR), // grab default filename from base URI,
|
crate::tool::uri_to_title(&uri).trim_matches(MAIN_SEPARATOR), // grab default filename from base URI,
|
||||||
// format FS entities
|
// format FS entities
|
||||||
&cancellable,
|
&cancellable,
|
||||||
|
|
@ -241,7 +267,7 @@ fn handle(
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
page.set_progress(0.0);
|
page.set_progress(0.0);
|
||||||
page.set_title(&status.title());
|
page.set_title(&s.title());
|
||||||
if is_snap_history {
|
if is_snap_history {
|
||||||
page.snap_history();
|
page.snap_history();
|
||||||
}
|
}
|
||||||
|
|
@ -266,7 +292,13 @@ fn handle(
|
||||||
move |result| match result {
|
move |result| match result {
|
||||||
Ok((buffer, _ ,_)) => match std::str::from_utf8(&buffer) {
|
Ok((buffer, _ ,_)) => match std::str::from_utf8(&buffer) {
|
||||||
Ok(data) => {
|
Ok(data) => {
|
||||||
let widget = if matches!(*feature, Feature::Source) {
|
let mut i = page.info.borrow_mut();
|
||||||
|
i
|
||||||
|
.add_event("Parsing".to_string())
|
||||||
|
.set_mime(Some(success.mime().to_string()))
|
||||||
|
.set_request(Some(uri.to_string()))
|
||||||
|
.set_size(Some(data.len()));
|
||||||
|
let w = if matches!(*feature, Feature::Source) {
|
||||||
page.content.to_text_source(data)
|
page.content.to_text_source(data)
|
||||||
} else {
|
} else {
|
||||||
match success.mime() {
|
match success.mime() {
|
||||||
|
|
@ -275,9 +307,10 @@ fn handle(
|
||||||
_ => panic!() // unexpected
|
_ => panic!() // unexpected
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
page.search.set(Some(widget.text_view));
|
i.add_event("Parsed".to_string());
|
||||||
page.set_title(&match widget.meta.title {
|
page.search.set(Some(w.text_view));
|
||||||
Some(title) => title.into(), // @TODO
|
page.set_title(&match w.meta.title {
|
||||||
|
Some(t) => t.into(), // @TODO
|
||||||
None => crate::tool::uri_to_title(&uri),
|
None => crate::tool::uri_to_title(&uri),
|
||||||
});
|
});
|
||||||
page.set_progress(0.0);
|
page.set_progress(0.0);
|
||||||
|
|
@ -289,39 +322,43 @@ fn handle(
|
||||||
page.snap_history();
|
page.snap_history();
|
||||||
}
|
}
|
||||||
redirects.replace(0); // reset
|
redirects.replace(0); // reset
|
||||||
|
i.add_event("Done".to_string());
|
||||||
},
|
},
|
||||||
Err(e) => {
|
Err(e) => {
|
||||||
let status = page.content.to_status_failure();
|
let s = page.content.to_status_failure();
|
||||||
status.set_description(Some(&e.to_string()));
|
s.set_description(Some(&e.to_string()));
|
||||||
page.set_progress(0.0);
|
page.set_progress(0.0);
|
||||||
page.set_title(&status.title());
|
page.set_title(&s.title());
|
||||||
if is_snap_history {
|
if is_snap_history {
|
||||||
page.snap_history();
|
page.snap_history();
|
||||||
}
|
}
|
||||||
redirects.replace(0); // reset
|
redirects.replace(0); // reset
|
||||||
|
update_page_info(&page, &uri, "Done");
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
Err((_, e)) => {
|
Err((_, e)) => {
|
||||||
let status = page.content.to_status_failure();
|
let s = page.content.to_status_failure();
|
||||||
status.set_description(Some(&e.to_string()));
|
s.set_description(Some(&e.to_string()));
|
||||||
page.set_progress(0.0);
|
page.set_progress(0.0);
|
||||||
page.set_title(&status.title());
|
page.set_title(&s.title());
|
||||||
if is_snap_history {
|
if is_snap_history {
|
||||||
page.snap_history();
|
page.snap_history();
|
||||||
}
|
}
|
||||||
redirects.replace(0); // reset
|
redirects.replace(0); // reset
|
||||||
|
update_page_info(&page, &uri, "Done");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
),
|
),
|
||||||
Err(e) => {
|
Err(e) => {
|
||||||
let status = page.content.to_status_failure();
|
let s = page.content.to_status_failure();
|
||||||
status.set_description(Some(&e.to_string()));
|
s.set_description(Some(&e.to_string()));
|
||||||
page.set_progress(0.0);
|
page.set_progress(0.0);
|
||||||
page.set_title(&status.title());
|
page.set_title(&s.title());
|
||||||
if is_snap_history {
|
if is_snap_history {
|
||||||
page.snap_history();
|
page.snap_history();
|
||||||
}
|
}
|
||||||
redirects.replace(0); // reset
|
redirects.replace(0); // reset
|
||||||
|
update_page_info(&page, &uri, "Done");
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
@ -357,11 +394,27 @@ fn handle(
|
||||||
Ok(buffer) => {
|
Ok(buffer) => {
|
||||||
page.set_title(&crate::tool::uri_to_title(&uri));
|
page.set_title(&crate::tool::uri_to_title(&uri));
|
||||||
page.content.to_image(&Texture::for_pixbuf(&buffer));
|
page.content.to_image(&Texture::for_pixbuf(&buffer));
|
||||||
|
{
|
||||||
|
let mut i = page.info.borrow_mut();
|
||||||
|
i
|
||||||
|
.add_event("Done".to_string())
|
||||||
|
.set_mime(Some(success.mime().to_string()))
|
||||||
|
.set_request(Some(uri.to_string()))
|
||||||
|
.set_size(Some(buffer.byte_length()));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
Err(e) => {
|
Err(e) => {
|
||||||
let status = page.content.to_status_failure();
|
let s = page.content.to_status_failure();
|
||||||
status.set_description(Some(e.message()));
|
s.set_description(Some(e.message()));
|
||||||
page.set_title(&status.title());
|
page.set_title(&s.title());
|
||||||
|
{
|
||||||
|
let mut i = page.info.borrow_mut();
|
||||||
|
i
|
||||||
|
.add_event("Done".to_string())
|
||||||
|
.set_mime(Some(success.mime().to_string()))
|
||||||
|
.set_request(Some(uri.to_string()))
|
||||||
|
.set_size(None);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
page.set_progress(0.0);
|
page.set_progress(0.0);
|
||||||
|
|
@ -373,14 +426,22 @@ fn handle(
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
Err(e) => {
|
Err(e) => {
|
||||||
let status = page.content.to_status_failure();
|
let s = page.content.to_status_failure();
|
||||||
status.set_description(Some(&e.to_string()));
|
s.set_description(Some(&e.to_string()));
|
||||||
page.set_progress(0.0);
|
page.set_progress(0.0);
|
||||||
page.set_title(&status.title());
|
page.set_title(&s.title());
|
||||||
if is_snap_history {
|
if is_snap_history {
|
||||||
page.snap_history();
|
page.snap_history();
|
||||||
}
|
}
|
||||||
redirects.replace(0); // reset
|
redirects.replace(0); // reset
|
||||||
|
{
|
||||||
|
let mut i = page.info.borrow_mut();
|
||||||
|
i
|
||||||
|
.add_event("Done".to_string())
|
||||||
|
.set_mime(Some(success.mime().to_string()))
|
||||||
|
.set_request(Some(uri.to_string()))
|
||||||
|
.set_size(None);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -388,16 +449,24 @@ fn handle(
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
mime => {
|
mime => {
|
||||||
let status = page
|
let s = page
|
||||||
.content
|
.content
|
||||||
.to_status_mime(mime, Some((&page.item_action, &uri)));
|
.to_status_mime(mime, Some((&page.item_action, &uri)));
|
||||||
status.set_description(Some(&format!("Content type `{mime}` yet not supported")));
|
s.set_description(Some(&format!("Content type `{mime}` yet not supported")));
|
||||||
page.set_progress(0.0);
|
page.set_progress(0.0);
|
||||||
page.set_title(&status.title());
|
page.set_title(&s.title());
|
||||||
if is_snap_history {
|
if is_snap_history {
|
||||||
page.snap_history();
|
page.snap_history();
|
||||||
}
|
}
|
||||||
redirects.replace(0); // reset
|
redirects.replace(0); // reset
|
||||||
|
{
|
||||||
|
let mut i = page.info.borrow_mut();
|
||||||
|
i
|
||||||
|
.add_event("Done".to_string())
|
||||||
|
.set_mime(Some(mime.to_string()))
|
||||||
|
.set_request(Some(uri.to_string()))
|
||||||
|
.set_size(None);
|
||||||
|
}
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
@ -410,49 +479,63 @@ fn handle(
|
||||||
// > Client MUST limit the number of redirections they follow to 5 redirections
|
// > Client MUST limit the number of redirections they follow to 5 redirections
|
||||||
// > https://geminiprotocol.net/docs/protocol-specification.gmi#redirection
|
// > https://geminiprotocol.net/docs/protocol-specification.gmi#redirection
|
||||||
if total > 5 {
|
if total > 5 {
|
||||||
let status = page.content.to_status_failure();
|
let s = page.content.to_status_failure();
|
||||||
status.set_description(Some("Redirection limit reached"));
|
s.set_description(Some("Redirection limit reached"));
|
||||||
page.set_progress(0.0);
|
page.set_progress(0.0);
|
||||||
page.set_title(&status.title());
|
page.set_title(&s.title());
|
||||||
redirects.replace(0); // reset
|
redirects.replace(0); // reset
|
||||||
|
update_page_info(&page, &uri, "Done");
|
||||||
// Disallow external redirection by default as potentially unsafe
|
// Disallow external redirection by default as potentially unsafe
|
||||||
// even not specified, require follow confirmation @TODO optional
|
// even not specified, require follow confirmation @TODO optional
|
||||||
} else if uri.host() != target.host() {
|
} else if uri.host() != target.host() {
|
||||||
let url = target.to_string();
|
let u = target.to_string();
|
||||||
let status = page.content.to_status_failure();
|
let s = page.content.to_status_failure();
|
||||||
let title = "External redirection";
|
let t = "External redirection";
|
||||||
status.set_title(title);
|
s.set_title(t);
|
||||||
status.set_icon_name(Some("dialog-warning-symbolic"));
|
s.set_icon_name(Some("dialog-warning-symbolic"));
|
||||||
status.set_description(Some(&url));
|
s.set_description(Some(&u));
|
||||||
status.set_child(Some(&{
|
s.set_child(Some(&{
|
||||||
let button = gtk::Button::builder()
|
let b = gtk::Button::builder()
|
||||||
.css_classes(["suggested-action"])
|
.css_classes(["suggested-action"])
|
||||||
.halign(gtk::Align::Center)
|
.halign(gtk::Align::Center)
|
||||||
.label("Follow")
|
.label("Follow")
|
||||||
.build();
|
.build();
|
||||||
button.connect_clicked({
|
b.connect_clicked({
|
||||||
let page = page.clone();
|
let p = page.clone();
|
||||||
move |_| page.item_action.load.activate(Some(&url), false)
|
move |_| p.item_action.load.activate(Some(&u), false)
|
||||||
});
|
});
|
||||||
button
|
b
|
||||||
}));
|
}));
|
||||||
page.set_progress(0.0);
|
page.set_progress(0.0);
|
||||||
page.set_title(title);
|
page.set_title(t);
|
||||||
redirects.replace(0); // reset
|
redirects.replace(0); // reset
|
||||||
|
update_page_info(&page, &uri, "Done");
|
||||||
} else {
|
} else {
|
||||||
|
let t = target.to_string();
|
||||||
if matches!(redirect, Redirect::Permanent { .. }) {
|
if matches!(redirect, Redirect::Permanent { .. }) {
|
||||||
page.navigation.set_request(&target.to_string());
|
page.navigation.set_request(&t);
|
||||||
}
|
}
|
||||||
redirects.replace(total);
|
redirects.replace(total);
|
||||||
page.item_action.load.activate(Some(&target.to_string()), false);
|
{
|
||||||
|
let mut i = page.info.take();
|
||||||
|
i
|
||||||
|
.add_event("Done".to_string())
|
||||||
|
.set_mime(None)
|
||||||
|
.set_request(Some(uri.to_string()))
|
||||||
|
.set_size(None);
|
||||||
|
|
||||||
|
page.info.replace(i.into_redirect());
|
||||||
|
}
|
||||||
|
page.item_action.load.activate(Some(&t), false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Err(e) => {
|
Err(e) => {
|
||||||
let status = page.content.to_status_failure();
|
let s = page.content.to_status_failure();
|
||||||
status.set_description(Some(&e.to_string()));
|
s.set_description(Some(&e.to_string()));
|
||||||
page.set_progress(0.0);
|
page.set_progress(0.0);
|
||||||
page.set_title(&status.title());
|
page.set_title(&s.title());
|
||||||
redirects.replace(0); // reset
|
redirects.replace(0); // reset
|
||||||
|
update_page_info(&page, &uri, "Done");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Response::Certificate(ref certificate) => match certificate {
|
Response::Certificate(ref certificate) => match certificate {
|
||||||
|
|
@ -462,14 +545,15 @@ fn handle(
|
||||||
Certificate::NotAuthorized { message } |
|
Certificate::NotAuthorized { message } |
|
||||||
// https://geminiprotocol.net/docs/protocol-specification.gmi#status-62-certificate-not-valid
|
// https://geminiprotocol.net/docs/protocol-specification.gmi#status-62-certificate-not-valid
|
||||||
Certificate::NotValid { message } => {
|
Certificate::NotValid { message } => {
|
||||||
let status = page.content.to_status_identity();
|
let s = page.content.to_status_identity();
|
||||||
status.set_description(Some(message.as_ref().unwrap_or(&certificate.to_string())));
|
s.set_description(Some(message.as_ref().unwrap_or(&certificate.to_string())));
|
||||||
page.set_progress(0.0);
|
page.set_progress(0.0);
|
||||||
page.set_title(&status.title());
|
page.set_title(&s.title());
|
||||||
if is_snap_history {
|
if is_snap_history {
|
||||||
page.snap_history();
|
page.snap_history();
|
||||||
}
|
}
|
||||||
redirects.replace(0); // reset
|
redirects.replace(0); // reset
|
||||||
|
update_page_info(&page, &uri, "Done");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Response::Failure(failure) => match failure {
|
Response::Failure(failure) => match failure {
|
||||||
|
|
@ -479,14 +563,15 @@ fn handle(
|
||||||
Temporary::ProxyError { message } |
|
Temporary::ProxyError { message } |
|
||||||
Temporary::ServerUnavailable { message } |
|
Temporary::ServerUnavailable { message } |
|
||||||
Temporary::SlowDown { message } => {
|
Temporary::SlowDown { message } => {
|
||||||
let status = page.content.to_status_failure();
|
let s = page.content.to_status_failure();
|
||||||
status.set_description(Some(message.as_ref().unwrap_or(&temporary.to_string())));
|
s.set_description(Some(message.as_ref().unwrap_or(&temporary.to_string())));
|
||||||
page.set_progress(0.0);
|
page.set_progress(0.0);
|
||||||
page.set_title(&status.title());
|
page.set_title(&s.title());
|
||||||
if is_snap_history {
|
if is_snap_history {
|
||||||
page.snap_history();
|
page.snap_history();
|
||||||
}
|
}
|
||||||
redirects.replace(0); // reset
|
redirects.replace(0); // reset
|
||||||
|
update_page_info(&page, &uri, "Done");
|
||||||
if let Some(callback) = on_failure {
|
if let Some(callback) = on_failure {
|
||||||
callback()
|
callback()
|
||||||
}
|
}
|
||||||
|
|
@ -498,14 +583,15 @@ fn handle(
|
||||||
Permanent::Gone { message } |
|
Permanent::Gone { message } |
|
||||||
Permanent::NotFound { message } |
|
Permanent::NotFound { message } |
|
||||||
Permanent::ProxyRequestRefused { message } => {
|
Permanent::ProxyRequestRefused { message } => {
|
||||||
let status = page.content.to_status_failure();
|
let s = page.content.to_status_failure();
|
||||||
status.set_description(Some(message.as_ref().unwrap_or(&permanent.to_string())));
|
s.set_description(Some(message.as_ref().unwrap_or(&permanent.to_string())));
|
||||||
page.set_progress(0.0);
|
page.set_progress(0.0);
|
||||||
page.set_title(&status.title());
|
page.set_title(&s.title());
|
||||||
if is_snap_history {
|
if is_snap_history {
|
||||||
page.snap_history();
|
page.snap_history();
|
||||||
}
|
}
|
||||||
redirects.replace(0); // reset
|
redirects.replace(0); // reset
|
||||||
|
update_page_info(&page, &uri, "Done");
|
||||||
if let Some(callback) = on_failure {
|
if let Some(callback) = on_failure {
|
||||||
callback()
|
callback()
|
||||||
}
|
}
|
||||||
|
|
@ -514,16 +600,26 @@ fn handle(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Err(e) => {
|
Err(e) => {
|
||||||
let status = page.content.to_status_failure();
|
let s = page.content.to_status_failure();
|
||||||
status.set_description(Some(&e.to_string()));
|
s.set_description(Some(&e.to_string()));
|
||||||
page.set_progress(0.0);
|
page.set_progress(0.0);
|
||||||
page.set_title(&status.title());
|
page.set_title(&s.title());
|
||||||
if is_snap_history {
|
if is_snap_history {
|
||||||
page.snap_history();
|
page.snap_history();
|
||||||
}
|
}
|
||||||
redirects.replace(0); // reset
|
redirects.replace(0); // reset
|
||||||
|
update_page_info(&page, &uri, "Done")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Apply common page info pattern
|
||||||
|
fn update_page_info(page: &Page, uri: &Uri, event_name: &str) {
|
||||||
|
let mut i = page.info.borrow_mut();
|
||||||
|
i.add_event(event_name.to_string())
|
||||||
|
.set_mime(None)
|
||||||
|
.set_request(Some(uri.to_string()))
|
||||||
|
.set_size(None);
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,6 @@
|
||||||
mod content;
|
mod content;
|
||||||
mod database;
|
mod database;
|
||||||
|
mod info;
|
||||||
mod input;
|
mod input;
|
||||||
mod navigation;
|
mod navigation;
|
||||||
mod search;
|
mod search;
|
||||||
|
|
@ -8,11 +9,12 @@ use super::{Action as ItemAction, BrowserAction, Profile, TabAction, WindowActio
|
||||||
use adw::TabPage;
|
use adw::TabPage;
|
||||||
use anyhow::Result;
|
use anyhow::Result;
|
||||||
use content::Content;
|
use content::Content;
|
||||||
|
use info::Info;
|
||||||
use input::Input;
|
use input::Input;
|
||||||
use navigation::Navigation;
|
use navigation::Navigation;
|
||||||
use search::Search;
|
use search::Search;
|
||||||
use sqlite::Transaction;
|
use sqlite::Transaction;
|
||||||
use std::{rc::Rc, sync::Arc};
|
use std::{cell::RefCell, rc::Rc, sync::Arc};
|
||||||
|
|
||||||
pub struct Page {
|
pub struct Page {
|
||||||
pub profile: Arc<Profile>,
|
pub profile: Arc<Profile>,
|
||||||
|
|
@ -21,6 +23,7 @@ pub struct Page {
|
||||||
pub item_action: Rc<ItemAction>,
|
pub item_action: Rc<ItemAction>,
|
||||||
pub window_action: Rc<WindowAction>,
|
pub window_action: Rc<WindowAction>,
|
||||||
// Components
|
// Components
|
||||||
|
pub info: Rc<RefCell<Info>>,
|
||||||
pub content: Rc<Content>,
|
pub content: Rc<Content>,
|
||||||
pub input: Rc<Input>,
|
pub input: Rc<Input>,
|
||||||
pub navigation: Rc<Navigation>,
|
pub navigation: Rc<Navigation>,
|
||||||
|
|
@ -55,6 +58,7 @@ impl Page {
|
||||||
(window_action, tab_action, item_action),
|
(window_action, tab_action, item_action),
|
||||||
));
|
));
|
||||||
let input = Rc::new(Input::new());
|
let input = Rc::new(Input::new());
|
||||||
|
let info = Rc::new(RefCell::new(Info::new()));
|
||||||
|
|
||||||
// Done
|
// Done
|
||||||
Self {
|
Self {
|
||||||
|
|
@ -65,6 +69,7 @@ impl Page {
|
||||||
item_action: item_action.clone(),
|
item_action: item_action.clone(),
|
||||||
window_action: window_action.clone(),
|
window_action: window_action.clone(),
|
||||||
// Components
|
// Components
|
||||||
|
info,
|
||||||
content,
|
content,
|
||||||
input,
|
input,
|
||||||
navigation,
|
navigation,
|
||||||
|
|
|
||||||
87
src/app/browser/window/tab/item/page/info.rs
Normal file
87
src/app/browser/window/tab/item/page/info.rs
Normal file
|
|
@ -0,0 +1,87 @@
|
||||||
|
// Public dependencies
|
||||||
|
|
||||||
|
pub mod event;
|
||||||
|
pub use event::Event;
|
||||||
|
|
||||||
|
// Local dependencies
|
||||||
|
|
||||||
|
use gtk::gio::NetworkAddress;
|
||||||
|
|
||||||
|
/// Common, shared `Page` information holder
|
||||||
|
/// * used for the Information dialog window on request indicator activate
|
||||||
|
/// * collecting by the page driver implementation, using public API
|
||||||
|
pub struct Info {
|
||||||
|
/// Hold page events like connection phase and parsing time
|
||||||
|
event: Vec<Event>,
|
||||||
|
/// Page content type
|
||||||
|
mime: Option<String>,
|
||||||
|
/// Hold redirections chain with handled details
|
||||||
|
/// * the `referrer` member name is reserved for other protocols
|
||||||
|
redirect: Option<Box<Self>>,
|
||||||
|
/// Optional remote host details
|
||||||
|
/// * useful also for geo-location feature
|
||||||
|
remote: Option<NetworkAddress>,
|
||||||
|
/// Key to relate data collected with the specific request
|
||||||
|
request: Option<String>,
|
||||||
|
/// Hold page content size
|
||||||
|
size: Option<usize>,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Info {
|
||||||
|
// Constructors
|
||||||
|
|
||||||
|
/// Create new empty `Self` with expected default capacity
|
||||||
|
pub fn new() -> Self {
|
||||||
|
Self {
|
||||||
|
event: Vec::with_capacity(50), // estimated max events quantity for all drivers
|
||||||
|
mime: None,
|
||||||
|
redirect: None,
|
||||||
|
remote: None,
|
||||||
|
request: None,
|
||||||
|
size: None,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Setters
|
||||||
|
// useful to update `Self` as chain of values
|
||||||
|
|
||||||
|
/// Take `Self`, convert it into the redirect member,
|
||||||
|
/// then, return new `Self` back
|
||||||
|
/// * tip: use on driver redirection events
|
||||||
|
pub fn into_redirect(self) -> Self {
|
||||||
|
let mut this = Self::new();
|
||||||
|
this.redirect = Some(Box::new(self));
|
||||||
|
this
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn add_event(&mut self, name: String) -> &mut Self {
|
||||||
|
self.event.push(Event::now(name));
|
||||||
|
self
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn set_mime(&mut self, mime: Option<String>) -> &mut Self {
|
||||||
|
self.mime = mime;
|
||||||
|
self
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn set_remote(&mut self, remote: Option<NetworkAddress>) -> &mut Self {
|
||||||
|
self.remote = remote;
|
||||||
|
self
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn set_request(&mut self, request: Option<String>) -> &mut Self {
|
||||||
|
self.request = request;
|
||||||
|
self
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn set_size(&mut self, size: Option<usize>) -> &mut Self {
|
||||||
|
self.size = size;
|
||||||
|
self
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Default for Info {
|
||||||
|
fn default() -> Self {
|
||||||
|
Self::new()
|
||||||
|
}
|
||||||
|
}
|
||||||
22
src/app/browser/window/tab/item/page/info/event.rs
Normal file
22
src/app/browser/window/tab/item/page/info/event.rs
Normal file
|
|
@ -0,0 +1,22 @@
|
||||||
|
// Local dependencies
|
||||||
|
|
||||||
|
use gtk::glib::DateTime;
|
||||||
|
|
||||||
|
/// Single event holder
|
||||||
|
/// * used in page info dialog to track page load and parse timings
|
||||||
|
pub struct Event {
|
||||||
|
name: String,
|
||||||
|
time: DateTime,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Event {
|
||||||
|
// Constructors
|
||||||
|
|
||||||
|
/// Create new `Self` with auto-completed current local timestamp
|
||||||
|
pub fn now(name: String) -> Self {
|
||||||
|
Self {
|
||||||
|
name,
|
||||||
|
time: DateTime::now_local().unwrap(),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -34,7 +34,6 @@ impl Request {
|
||||||
// Init main widget
|
// Init main widget
|
||||||
let entry = Entry::builder()
|
let entry = Entry::builder()
|
||||||
.placeholder_text("URL or search term...")
|
.placeholder_text("URL or search term...")
|
||||||
.secondary_icon_tooltip_text("Go to the location")
|
|
||||||
.hexpand(true)
|
.hexpand(true)
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
|
|
@ -317,11 +316,22 @@ fn update_primary_icon(entry: &Entry, profile: &Profile) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// GTK `is_focus` / `has_focus` not an option here
|
||||||
|
/// also, this method requires from the `Entry`` to be not empty
|
||||||
|
fn is_focused(entry: &Entry) -> bool {
|
||||||
|
entry.text_length() > 0 && entry.focus_child().is_some_and(|child| child.has_focus())
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Secondary icon has two modes:
|
||||||
|
/// * navigate to the location button (on the entry is focused / has edit mode)
|
||||||
|
/// * page info button with dialog window activation (on the entry is inactive)
|
||||||
fn update_secondary_icon(entry: &Entry) {
|
fn update_secondary_icon(entry: &Entry) {
|
||||||
if !entry.text().is_empty() && entry.focus_child().is_some_and(|text| text.has_focus()) {
|
if is_focused(entry) {
|
||||||
entry.set_secondary_icon_name(Some("pan-end-symbolic"));
|
entry.set_secondary_icon_name(Some("pan-end-symbolic"));
|
||||||
|
entry.set_secondary_icon_tooltip_text(Some("Go to the location"))
|
||||||
} else {
|
} else {
|
||||||
entry.set_secondary_icon_name(None);
|
entry.set_secondary_icon_name(Some("help-about-symbolic"));
|
||||||
|
entry.set_secondary_icon_tooltip_text(Some("Page info"));
|
||||||
entry.select_region(0, 0);
|
entry.select_region(0, 0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -336,12 +346,12 @@ fn show_identity_dialog(entry: &Entry, profile: &Arc<Profile>) {
|
||||||
profile,
|
profile,
|
||||||
&uri,
|
&uri,
|
||||||
&Rc::new({
|
&Rc::new({
|
||||||
let profile = profile.clone();
|
let p = profile.clone();
|
||||||
let entry = entry.clone();
|
let e = entry.clone();
|
||||||
move |is_reload| {
|
move |is_reload| {
|
||||||
update_primary_icon(&entry, &profile);
|
update_primary_icon(&e, &p);
|
||||||
if is_reload {
|
if is_reload {
|
||||||
entry.emit_activate();
|
e.emit_activate();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}),
|
}),
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue