format request, begin download feature implementation

This commit is contained in:
yggverse 2024-12-09 14:55:20 +02:00
parent 88b3adaf2d
commit 09f2a17f22
6 changed files with 533 additions and 187 deletions

View file

@ -0,0 +1,34 @@
use gtk::glib::{Uri, UriFlags};
/// Request type for `Page` with optional value parsed
pub enum Request {
Default(Uri),
Download(Uri),
Source(Uri),
Search(String),
}
impl Request {
// Constructors
/// Create new `Self` from `request` string
pub fn from(request: &str) -> Self {
if let Some(postfix) = request.strip_prefix("source:") {
if let Ok(uri) = Uri::parse(postfix, UriFlags::NONE) {
return Self::Source(uri);
}
}
if let Some(postfix) = request.strip_prefix("download:") {
if let Ok(uri) = Uri::parse(postfix, UriFlags::NONE) {
return Self::Download(uri);
}
}
if let Ok(uri) = Uri::parse(request, UriFlags::NONE) {
return Self::Default(uri);
}
Self::Search(request.to_string())
}
}