draft file type router

This commit is contained in:
yggverse 2025-02-13 09:44:09 +02:00
parent 9e1fb9c5ca
commit 0574ab81fd

View file

@ -4,25 +4,62 @@ use std::rc::Rc;
/// Local files client driver
pub struct File {
// page: Rc<Page>,
page: Rc<Page>,
}
impl File {
// Constructors
/// Create new `Self`
pub fn init(_page: &Rc<Page>) -> Self {
Self { /*page: page.clone()*/ } // @TODO
pub fn init(page: &Rc<Page>) -> Self {
Self { page: page.clone() } // @TODO
}
pub fn handle(&self, uri: Uri, _feature: Rc<Feature>, cancellable: Cancellable) {
use gtk::{gio::File, prelude::FileExtManual};
use gtk::{
gio::{File, FileQueryInfoFlags, FileType},
glib::Priority,
prelude::FileExtManual,
};
File::for_uri(&uri.to_string()).load_contents_async(Some(&cancellable), |result| {
match result {
Ok(_) => todo!(),
Err(_) => todo!(),
}
});
// try handle as directory
File::for_uri(&uri.to_string()).enumerate_children_async(
"standard::content-type",
FileQueryInfoFlags::NONE,
Priority::DEFAULT,
Some(&cancellable),
{
let cancellable = cancellable.clone();
let uri = uri.clone();
let _page = self.page.clone();
move |result| match result {
Ok(file_enumerator) => {
for entry in file_enumerator {
match entry {
Ok(file_info) => match file_info.file_type() {
FileType::Unknown => todo!(),
FileType::Regular => todo!(),
FileType::Directory => todo!(),
FileType::SymbolicLink => todo!(),
FileType::Special => todo!(),
FileType::Shortcut => todo!(),
FileType::Mountable => todo!(),
_ => todo!(),
},
Err(_) => todo!(),
}
}
}
// is not a directory, try handle as file
Err(_) => File::for_uri(&uri.to_string()).load_contents_async(
Some(&cancellable),
|result| match result {
Ok(_) => todo!(),
Err(_) => todo!(),
},
),
}
},
)
}
}