mirror of
https://github.com/YGGverse/Yoda.git
synced 2026-03-31 16:45:27 +00:00
update page info on local files browse
This commit is contained in:
parent
6a100c48ee
commit
2f68e80a83
5 changed files with 118 additions and 39 deletions
|
|
@ -37,6 +37,12 @@ impl File {
|
||||||
use status::Status;
|
use status::Status;
|
||||||
use text::Text;
|
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 url = uri.to_string();
|
||||||
let file = File::for_uri(&url);
|
let file = File::for_uri(&url);
|
||||||
let page = self.page.clone();
|
let page = self.page.clone();
|
||||||
|
|
@ -44,52 +50,81 @@ impl File {
|
||||||
match file.query_file_type(FileQueryInfoFlags::NONE, Some(&cancellable)) {
|
match file.query_file_type(FileQueryInfoFlags::NONE, Some(&cancellable)) {
|
||||||
FileType::Directory => Directory { file }.handle(&page, is_snap_history),
|
FileType::Directory => Directory { file }.handle(&page, is_snap_history),
|
||||||
_ => file.clone().query_info_async(
|
_ => file.clone().query_info_async(
|
||||||
"standard::content-type",
|
"standard::content-type,standard::size",
|
||||||
FileQueryInfoFlags::NONE,
|
FileQueryInfoFlags::NONE,
|
||||||
Priority::DEFAULT,
|
Priority::DEFAULT,
|
||||||
Some(&cancellable.clone()),
|
Some(&cancellable.clone()),
|
||||||
move |result| match result {
|
move |result| match result {
|
||||||
Ok(file_info) => match file_info.content_type() {
|
Ok(file_info) => {
|
||||||
Some(content_type) => match content_type.as_str() {
|
page.navigation
|
||||||
"text/plain" => {
|
.request
|
||||||
if matches!(*feature, Feature::Source) {
|
.info
|
||||||
load_contents_async(file, cancellable, move |result| {
|
.borrow_mut()
|
||||||
match result {
|
.set_size(Some(file_info.size() as usize));
|
||||||
Ok(data) => Text::Source(uri, data).handle(&page),
|
match file_info.content_type() {
|
||||||
Err(message) => Status::Failure(message).handle(&page),
|
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") {
|
"image/png" | "image/gif" | "image/jpeg" | "image/webp" => {
|
||||||
load_contents_async(file, cancellable, move |result| {
|
match gtk::gdk::Texture::from_file(&file) {
|
||||||
match result {
|
Ok(texture) => {
|
||||||
Ok(data) => Text::Plain(uri, data).handle(&page),
|
Image::Bitmap(uri, texture).handle(&page)
|
||||||
Err(message) => Status::Failure(message).handle(&page),
|
}
|
||||||
|
Err(e) => Status::Failure(e.to_string()).handle(&page),
|
||||||
}
|
}
|
||||||
});
|
}
|
||||||
} else {
|
mime => Status::Failure(format!(
|
||||||
load_contents_async(file, cancellable, move |result| {
|
"Content type `{mime}` yet not supported"
|
||||||
match result {
|
))
|
||||||
Ok(data) => Text::Gemini(uri, data).handle(&page),
|
.handle(&page),
|
||||||
Err(message) => Status::Failure(message).handle(&page),
|
|
||||||
}
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
"image/png" | "image/gif" | "image/jpeg" | "image/webp" => {
|
None => Status::Failure("Undetectable content type".to_string())
|
||||||
match gtk::gdk::Texture::from_file(&file) {
|
.handle(&page),
|
||||||
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)
|
|
||||||
}
|
}
|
||||||
},
|
}
|
||||||
Err(e) => Status::Failure(e.to_string()).handle(&page),
|
Err(e) => Status::Failure(e.to_string()).handle(&page),
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
|
|
|
||||||
|
|
@ -14,7 +14,14 @@ impl Directory {
|
||||||
// on ready
|
// on ready
|
||||||
{
|
{
|
||||||
let page = page.clone();
|
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
|
// on activate
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -7,6 +7,11 @@ pub enum Image {
|
||||||
|
|
||||||
impl Image {
|
impl Image {
|
||||||
pub fn handle(&self, page: &super::Page) {
|
pub fn handle(&self, page: &super::Page) {
|
||||||
|
page.navigation
|
||||||
|
.request
|
||||||
|
.info
|
||||||
|
.borrow_mut()
|
||||||
|
.add_event("Rendering".to_string());
|
||||||
let uri = match self {
|
let uri = match self {
|
||||||
Self::Bitmap(uri, texture) => {
|
Self::Bitmap(uri, texture) => {
|
||||||
page.content.to_image(texture);
|
page.content.to_image(texture);
|
||||||
|
|
@ -17,5 +22,10 @@ impl Image {
|
||||||
page.set_progress(0.0);
|
page.set_progress(0.0);
|
||||||
page.snap_history();
|
page.snap_history();
|
||||||
page.window_action.find.simple_action.set_enabled(false);
|
page.window_action.find.simple_action.set_enabled(false);
|
||||||
|
page.navigation
|
||||||
|
.request
|
||||||
|
.info
|
||||||
|
.borrow_mut()
|
||||||
|
.add_event("Rendered".to_string());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -4,6 +4,11 @@ pub enum Status {
|
||||||
|
|
||||||
impl Status {
|
impl Status {
|
||||||
pub fn handle(&self, page: &super::Page) {
|
pub fn handle(&self, page: &super::Page) {
|
||||||
|
page.navigation
|
||||||
|
.request
|
||||||
|
.info
|
||||||
|
.borrow_mut()
|
||||||
|
.add_event("Parsing".to_string());
|
||||||
let (message, widget) = match self {
|
let (message, widget) = match self {
|
||||||
Self::Failure(message) => (message, page.content.to_status_failure()),
|
Self::Failure(message) => (message, page.content.to_status_failure()),
|
||||||
};
|
};
|
||||||
|
|
@ -12,5 +17,10 @@ impl Status {
|
||||||
page.set_progress(0.0);
|
page.set_progress(0.0);
|
||||||
page.snap_history();
|
page.snap_history();
|
||||||
page.window_action.find.simple_action.set_enabled(false);
|
page.window_action.find.simple_action.set_enabled(false);
|
||||||
|
page.navigation
|
||||||
|
.request
|
||||||
|
.info
|
||||||
|
.borrow_mut()
|
||||||
|
.add_event("Parsed".to_string());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -8,8 +8,20 @@ pub enum Text {
|
||||||
|
|
||||||
impl Text {
|
impl Text {
|
||||||
pub fn handle(&self, page: &super::Page) {
|
pub fn handle(&self, page: &super::Page) {
|
||||||
|
page.navigation
|
||||||
|
.request
|
||||||
|
.info
|
||||||
|
.borrow_mut()
|
||||||
|
.add_event("Parsing".to_string());
|
||||||
let (uri, widget) = match self {
|
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::Plain(uri, data) => (uri, page.content.to_text_plain(data)),
|
||||||
Self::Source(uri, data) => (uri, page.content.to_text_source(data)),
|
Self::Source(uri, data) => (uri, page.content.to_text_source(data)),
|
||||||
};
|
};
|
||||||
|
|
@ -21,5 +33,10 @@ impl Text {
|
||||||
page.set_progress(0.0);
|
page.set_progress(0.0);
|
||||||
page.snap_history();
|
page.snap_history();
|
||||||
page.window_action.find.simple_action.set_enabled(true);
|
page.window_action.find.simple_action.set_enabled(true);
|
||||||
|
page.navigation
|
||||||
|
.request
|
||||||
|
.info
|
||||||
|
.borrow_mut()
|
||||||
|
.add_event("Parsed".to_string());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue