From 2f84c2b86e2ff0770791c19d488f0ebba0150609 Mon Sep 17 00:00:00 2001 From: yggverse Date: Thu, 16 Jan 2025 22:04:29 +0200 Subject: [PATCH] filter FS entities from subject filename, rename `new` constructor to `build` --- .../item/identity/gemini/widget/form/save.rs | 5 ++++- src/app/browser/window/tab/item/page.rs | 17 ++++++++--------- src/app/browser/window/tab/item/page/content.rs | 2 +- .../tab/item/page/content/status/download.rs | 2 +- 4 files changed, 14 insertions(+), 12 deletions(-) diff --git a/src/app/browser/window/tab/item/identity/gemini/widget/form/save.rs b/src/app/browser/window/tab/item/identity/gemini/widget/form/save.rs index d8fb45d0..9ee5cad0 100644 --- a/src/app/browser/window/tab/item/identity/gemini/widget/form/save.rs +++ b/src/app/browser/window/tab/item/identity/gemini/widget/form/save.rs @@ -66,7 +66,10 @@ impl Save { .filters(&filters) .initial_name(format!( "{}.pem", - certificate.name.replace(MAIN_SEPARATOR, "-") + certificate + .name + .trim_matches(MAIN_SEPARATOR) + .replace(MAIN_SEPARATOR, "-") )) .build() .save(Window::NONE, Cancellable::NONE, { diff --git a/src/app/browser/window/tab/item/page.rs b/src/app/browser/window/tab/item/page.rs index e009811c..049e35db 100644 --- a/src/app/browser/window/tab/item/page.rs +++ b/src/app/browser/window/tab/item/page.rs @@ -27,7 +27,7 @@ use gtk::{ prelude::{EditableExt, FileExt}, }; use sqlite::Transaction; -use std::{cell::RefCell, rc::Rc, time::Duration}; +use std::{cell::RefCell, path::MAIN_SEPARATOR, rc::Rc, time::Duration}; pub struct Page { id: Rc, @@ -331,7 +331,8 @@ impl Page { Response::Download { base, cancellable, stream } => { // Init download widget let status_page = content.to_status_download( - &uri_to_title(&base), // grab default filename from base URI + uri_to_title(&base).trim_matches(MAIN_SEPARATOR), // grab default filename from base URI, + // format FS entities &cancellable, { let cancellable = cancellable.clone(); @@ -609,19 +610,17 @@ pub fn migrate(tx: &Transaction) -> Result<(), String> { } /// Helper function, extract readable title from [Uri](https://docs.gtk.org/glib/struct.Uri.html) -/// -/// Useful as common placeholder when page title could not be detected -/// +/// * useful as common placeholder when page title could not be detected /// * this feature may be improved and moved outside @TODO fn uri_to_title(uri: &Uri) -> GString { - let title = uri.path(); - if title.split('/').last().unwrap_or_default().is_empty() { + let path = uri.path(); + if path.split('/').last().unwrap_or_default().is_empty() { match uri.host() { Some(host) => host, - None => gformat!("Untitled"), + None => "Untitled".into(), } } else { - title + path } } diff --git a/src/app/browser/window/tab/item/page/content.rs b/src/app/browser/window/tab/item/page/content.rs index 5b205bd8..50eeccd8 100644 --- a/src/app/browser/window/tab/item/page/content.rs +++ b/src/app/browser/window/tab/item/page/content.rs @@ -56,7 +56,7 @@ impl Content { on_choose: impl Fn(File, Rc) + 'static, ) -> StatusPage { self.clean(); - let status = status::download::new(initial_filename, cancellable, on_choose); + let status = status::download::build(initial_filename, cancellable, on_choose); self.g_box.append(&status); status } diff --git a/src/app/browser/window/tab/item/page/content/status/download.rs b/src/app/browser/window/tab/item/page/content/status/download.rs index 6bea5d01..ace3beee 100644 --- a/src/app/browser/window/tab/item/page/content/status/download.rs +++ b/src/app/browser/window/tab/item/page/content/status/download.rs @@ -31,7 +31,7 @@ const TITLE: &str = "Download"; /// preset with children widget contain download UI /// * apply callback function on destination [File](https://docs.gtk.org/gio/iface.File.html) selected /// * require external IOStream read/write implementation (depending of protocol) -pub fn new( +pub fn build( initial_filename: &str, cancellable: &Cancellable, on_choose: impl Fn(File, Rc) + 'static,