delegate home url parse to request component

This commit is contained in:
yggverse 2025-01-22 20:52:34 +02:00
parent eae35d5ab8
commit 137301200f
8 changed files with 56 additions and 88 deletions

View file

@ -106,7 +106,7 @@ impl Request {
/// Try get current request value as [Uri](https://docs.gtk.org/glib/struct.Uri.html)
/// * `strip_prefix` on parse
pub fn as_uri(&self) -> Option<Uri> {
pub fn uri(&self) -> Option<Uri> {
match Uri::parse(&strip_prefix(self.widget.entry.text()), UriFlags::NONE) {
Ok(uri) => Some(uri),
_ => None,
@ -119,6 +119,24 @@ impl Request {
strip_prefix(self.widget.entry.text())
}
/// Parse home [Uri](https://docs.gtk.org/glib/struct.Uri.html) for self
pub fn home(&self) -> Option<GString> {
match self.uri() {
Some(uri) => {
let scheme = uri.scheme().replace("titan", "gemini");
let port = uri.port();
uri.host().map(|host| {
if port.is_positive() {
gformat!("{scheme}://{host}:{port}/")
} else {
gformat!("{scheme}://{host}/")
}
})
}
None => None,
}
}
/// Get request value in `download:` format
pub fn download(&self) -> GString {
gformat!("download:{}", self.strip_prefix())