From d2a39f2770502e41f59b97a97a52f0904542a52c Mon Sep 17 00:00:00 2001 From: yggverse Date: Fri, 28 Mar 2025 03:09:13 +0200 Subject: [PATCH] update page info on download --- .../window/tab/item/client/driver/gemini.rs | 31 ++++++++++++++----- .../tab/item/page/navigation/request.rs | 14 ++++----- 2 files changed, 30 insertions(+), 15 deletions(-) diff --git a/src/app/browser/window/tab/item/client/driver/gemini.rs b/src/app/browser/window/tab/item/client/driver/gemini.rs index 5bc7c11d..64f477ee 100644 --- a/src/app/browser/window/tab/item/client/driver/gemini.rs +++ b/src/app/browser/window/tab/item/client/driver/gemini.rs @@ -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(), diff --git a/src/app/browser/window/tab/item/page/navigation/request.rs b/src/app/browser/window/tab/item/page/navigation/request.rs index 310315f6..807b4fdc 100644 --- a/src/app/browser/window/tab/item/page/navigation/request.rs +++ b/src/app/browser/window/tab/item/page/navigation/request.rs @@ -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) { // connect identity traits