update page info on local files browse

This commit is contained in:
yggverse 2025-03-28 04:03:30 +02:00
parent 6a100c48ee
commit 2f68e80a83
5 changed files with 118 additions and 39 deletions

View file

@ -37,6 +37,12 @@ impl File {
use status::Status;
use text::Text;
{
let mut i = self.page.navigation.request.info.borrow_mut();
i.set_request(Some(uri.to_string()));
self.page.navigation.request.update_secondary_icon(&i)
}
let url = uri.to_string();
let file = File::for_uri(&url);
let page = self.page.clone();
@ -44,52 +50,81 @@ impl File {
match file.query_file_type(FileQueryInfoFlags::NONE, Some(&cancellable)) {
FileType::Directory => Directory { file }.handle(&page, is_snap_history),
_ => file.clone().query_info_async(
"standard::content-type",
"standard::content-type,standard::size",
FileQueryInfoFlags::NONE,
Priority::DEFAULT,
Some(&cancellable.clone()),
move |result| match result {
Ok(file_info) => match file_info.content_type() {
Some(content_type) => match content_type.as_str() {
"text/plain" => {
if matches!(*feature, Feature::Source) {
load_contents_async(file, cancellable, move |result| {
match result {
Ok(data) => Text::Source(uri, data).handle(&page),
Err(message) => Status::Failure(message).handle(&page),
Ok(file_info) => {
page.navigation
.request
.info
.borrow_mut()
.set_size(Some(file_info.size() as usize));
match file_info.content_type() {
Some(content_type) => {
{
page.navigation
.request
.info
.borrow_mut()
.set_mime(Some(content_type.to_string()));
}
match content_type.as_str() {
"text/plain" => {
if matches!(*feature, Feature::Source) {
load_contents_async(file, cancellable, move |result| {
match result {
Ok(data) => {
Text::Source(uri, data).handle(&page)
}
Err(message) => {
Status::Failure(message).handle(&page)
}
}
})
} else if url.ends_with(".txt") {
load_contents_async(file, cancellable, move |result| {
match result {
Ok(data) => {
Text::Plain(uri, data).handle(&page)
}
Err(message) => {
Status::Failure(message).handle(&page)
}
}
});
} else {
load_contents_async(file, cancellable, move |result| {
match result {
Ok(data) => {
Text::Gemini(uri, data).handle(&page)
}
Err(message) => {
Status::Failure(message).handle(&page)
}
}
})
}
})
} else if url.ends_with(".txt") {
load_contents_async(file, cancellable, move |result| {
match result {
Ok(data) => Text::Plain(uri, data).handle(&page),
Err(message) => Status::Failure(message).handle(&page),
}
"image/png" | "image/gif" | "image/jpeg" | "image/webp" => {
match gtk::gdk::Texture::from_file(&file) {
Ok(texture) => {
Image::Bitmap(uri, texture).handle(&page)
}
Err(e) => Status::Failure(e.to_string()).handle(&page),
}
});
} else {
load_contents_async(file, cancellable, move |result| {
match result {
Ok(data) => Text::Gemini(uri, data).handle(&page),
Err(message) => Status::Failure(message).handle(&page),
}
})
}
mime => Status::Failure(format!(
"Content type `{mime}` yet not supported"
))
.handle(&page),
}
}
"image/png" | "image/gif" | "image/jpeg" | "image/webp" => {
match gtk::gdk::Texture::from_file(&file) {
Ok(texture) => Image::Bitmap(uri, texture).handle(&page),
Err(e) => Status::Failure(e.to_string()).handle(&page),
}
}
mime => {
Status::Failure(format!("Content type `{mime}` yet not supported"))
.handle(&page)
}
},
None => {
Status::Failure("Undetectable content type".to_string()).handle(&page)
None => Status::Failure("Undetectable content type".to_string())
.handle(&page),
}
},
}
Err(e) => Status::Failure(e.to_string()).handle(&page),
},
),

View file

@ -14,7 +14,14 @@ impl Directory {
// on ready
{
let page = page.clone();
move || page.set_progress(0.0)
move || {
page.navigation
.request
.info
.borrow_mut()
.add_event("Build directory tree".to_string());
page.set_progress(0.0)
}
},
// on activate
{

View file

@ -7,6 +7,11 @@ pub enum Image {
impl Image {
pub fn handle(&self, page: &super::Page) {
page.navigation
.request
.info
.borrow_mut()
.add_event("Rendering".to_string());
let uri = match self {
Self::Bitmap(uri, texture) => {
page.content.to_image(texture);
@ -17,5 +22,10 @@ impl Image {
page.set_progress(0.0);
page.snap_history();
page.window_action.find.simple_action.set_enabled(false);
page.navigation
.request
.info
.borrow_mut()
.add_event("Rendered".to_string());
}
}

View file

@ -4,6 +4,11 @@ pub enum Status {
impl Status {
pub fn handle(&self, page: &super::Page) {
page.navigation
.request
.info
.borrow_mut()
.add_event("Parsing".to_string());
let (message, widget) = match self {
Self::Failure(message) => (message, page.content.to_status_failure()),
};
@ -12,5 +17,10 @@ impl Status {
page.set_progress(0.0);
page.snap_history();
page.window_action.find.simple_action.set_enabled(false);
page.navigation
.request
.info
.borrow_mut()
.add_event("Parsed".to_string());
}
}

View file

@ -8,8 +8,20 @@ pub enum Text {
impl Text {
pub fn handle(&self, page: &super::Page) {
page.navigation
.request
.info
.borrow_mut()
.add_event("Parsing".to_string());
let (uri, widget) = match self {
Self::Gemini(uri, data) => (uri, page.content.to_text_gemini(uri, data)),
Self::Gemini(uri, data) => (uri, {
page.navigation
.request
.info
.borrow_mut()
.set_mime(Some("text/gemini".to_string()));
page.content.to_text_gemini(uri, data)
}),
Self::Plain(uri, data) => (uri, page.content.to_text_plain(data)),
Self::Source(uri, data) => (uri, page.content.to_text_source(data)),
};
@ -21,5 +33,10 @@ impl Text {
page.set_progress(0.0);
page.snap_history();
page.window_action.find.simple_action.set_enabled(true);
page.navigation
.request
.info
.borrow_mut()
.add_event("Parsed".to_string());
}
}