From 0574ab81fd50cc58d948f77a3b92b724018c76be Mon Sep 17 00:00:00 2001 From: yggverse Date: Thu, 13 Feb 2025 09:44:09 +0200 Subject: [PATCH] draft file type router --- .../window/tab/item/client/driver/file.rs | 57 +++++++++++++++---- 1 file changed, 47 insertions(+), 10 deletions(-) diff --git a/src/app/browser/window/tab/item/client/driver/file.rs b/src/app/browser/window/tab/item/client/driver/file.rs index fb421033..9cc34964 100644 --- a/src/app/browser/window/tab/item/client/driver/file.rs +++ b/src/app/browser/window/tab/item/client/driver/file.rs @@ -4,25 +4,62 @@ use std::rc::Rc; /// Local files client driver pub struct File { - // page: Rc, + page: Rc, } impl File { // Constructors /// Create new `Self` - pub fn init(_page: &Rc) -> Self { - Self { /*page: page.clone()*/ } // @TODO + pub fn init(page: &Rc) -> Self { + Self { page: page.clone() } // @TODO } pub fn handle(&self, uri: Uri, _feature: Rc, 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!(), + }, + ), + } + }, + ) } }