update page info on download

This commit is contained in:
yggverse 2025-03-28 03:09:13 +02:00
parent 3ccf3d2e7e
commit d2a39f2770
2 changed files with 30 additions and 15 deletions

View File

@ -204,17 +204,17 @@ fn handle(
page.navigation.request.update_secondary_icon(&i);
match input {
// https://geminiprotocol.net/docs/protocol-specification.gmi#status-10
Input::Default(d) => page.input.set_new_response(
Input::Default(default) => page.input.set_new_response(
page.item_action.clone(),
uri,
Some(d.message_or_default()),
Some(default.message_or_default()),
Some(1024),
),
// https://geminiprotocol.net/docs/protocol-specification.gmi#status-11-sensitive-input
Input::Sensitive(s) => page.input.set_new_sensitive(
Input::Sensitive(sensitive) => page.input.set_new_sensitive(
page.item_action.clone(),
uri,
Some(s.message_or_default()),
Some(sensitive.message_or_default()),
Some(1024),
)
}
@ -222,6 +222,15 @@ fn handle(
// https://geminiprotocol.net/docs/protocol-specification.gmi#status-20
Response::Success(success) => match *feature {
Feature::Download => {
// Update page info
{
let mut i = page.navigation.request.info.borrow_mut();
i
.add_event("Header preload".to_string())
.set_header(Some(success.as_header_str().to_string()))
.set_mime(success.mime().ok());
page.navigation.request.update_secondary_icon(&i)
}
// Init download widget
let s = page.content.to_status_download(
crate::tool::uri_to_title(&uri).trim_matches(MAIN_SEPARATOR), // grab default filename from base URI,
@ -229,6 +238,7 @@ fn handle(
&cancellable,
{
let cancellable = cancellable.clone();
let page = page.clone();
let stream = connection.stream();
move |file, action| match file.replace(
None,
@ -256,16 +266,21 @@ fn handle(
// on chunk
{
let action = action.clone();
move |_, total| action.update.activate(&format!(
"Received {}...",
total.bytes()
))
let page = page.clone();
move |_, total| {
let mut i = page.navigation.request.info.borrow_mut();
i.set_size(Some(total));
action.update.activate(&format!("Received {}...", total.bytes()))
}
},
// on complete
{
let action = action.clone();
let page = page.clone();
move |result| match result {
Ok((_, total)) => {
let mut i = page.navigation.request.info.borrow_mut();
i.set_size(Some(total));
action.complete.activate(&format!(
"Saved to {} ({} total)",
file.parse_name(),

View File

@ -341,12 +341,6 @@ 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)
@ -355,7 +349,7 @@ fn update_secondary_icon(entry: &Entry, info: &Info) {
entry.set_secondary_icon_name(Some("pan-end-symbolic"));
entry.set_secondary_icon_tooltip_text(Some("Go to the location"))
} else {
if info.matches(&entry.text()) {
if info.matches(&prefix_less(&entry)) {
entry.set_secondary_icon_name(Some("help-about-symbolic"));
entry.set_secondary_icon_tooltip_text(Some("Page info"));
} else {
@ -366,6 +360,12 @@ fn update_secondary_icon(entry: &Entry, info: &Info) {
}
}
/// 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())
}
/// Present Identity [AlertDialog](https://gnome.pages.gitlab.gnome.org/libadwaita/doc/main/class.AlertDialog.html) for `Self`
fn show_identity_dialog(entry: &Entry, profile: &Arc<Profile>) {
// connect identity traits