-
-
Notifications
You must be signed in to change notification settings - Fork 124
Add gio::File, gio::FileEnumerator, gio::FileMonitor, gio::Vfs subclasses #1676
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
Very interesting, thanks! OOC, what are you planning to implement with this? |
gio/src/subclass/file_enumerator.rs
Outdated
unsafe impl Send for MyFileEnumerator {} | ||
unsafe impl Sync for MyFileEnumerator {} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These are implemented automatically if possible. Are they not, and why are they required here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Removed. It was old code while implementing the tests.
gio/src/subclass/file_monitor.rs
Outdated
|
||
impl MyFileMonitor { | ||
pub async fn tick(&self) { | ||
std::thread::sleep(std::time::Duration::from_millis(10)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As this is an async function it should probably use an async sleep mechanism. glib::timeout_future()
for example
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
gio/src/subclass/vfs.rs
Outdated
self.parent_is_active() | ||
} | ||
|
||
fn get_file_for_path(&self, path: &GString) -> File { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You probably also need to implement the required pieces to implement gio::File
for this to be useful, or not?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
Initially i through I would have to implement 70+ methods of gio::File
, but finally only few ones are required for tests of gio::Vfs subclass
, so it is ok.
Just shortly looked over it, will do a proper review one of these days but generally it looks correct. |
94aacc1
to
bbfa6db
Compare
gio/src/subclass/vfs.rs
Outdated
self.parent_is_active() | ||
} | ||
|
||
fn get_file_for_path(&self, path: &GString) -> File { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should it take a GString or a PathBuf?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
path
parameter in VfsExt::file_for_path
is a &str
, so I think it should be a &str
.
Another alternative is to change path
parameter in VfsExt::file_for_path
and in gio::VfsImpl::get_file_for_path
to impl AsRef<std::path::Path>
as in gio::File::for_path
.
What do you think ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should fix the annotation upstream for VfsExt::file_for_path then
bbfa6db
to
ce47c8b
Compare
OOC I'm planning to implement some nautilus extension in Rust (very challenging 😅) |
gio/src/subclass/vfs.rs
Outdated
} | ||
} | ||
|
||
unsafe impl IsImplementable<MyFile> for File { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you split this into subclass/file.rs even if it only implements a small subset of the vfuncs, the rest can be added later.
would you mind rebasing & finishing the small remaining bits here? |
Yes, I'm adding subclass/file.rs (with almost all vfuncs), tests and a complete example to show how to implement a custom Vfs. I will share it during next week. |
ce47c8b
to
b4e9183
Compare
c7d3812
to
7e9bab9
Compare
Signed-off-by: fbrouille <fbrouille@users.noreply.github.com>
7e9bab9
to
e49b57d
Compare
Signed-off-by: fbrouille <fbrouille@users.noreply.github.com>
Signed-off-by: fbrouille <fbrouille@users.noreply.github.com>
47a3003
to
e9842cc
Compare
Signed-off-by: fbrouille <fbrouille@users.noreply.github.com>
Signed-off-by: fbrouille <fbrouille@users.noreply.github.com>
Signed-off-by: fbrouille <fbrouille@users.noreply.github.com>
e9842cc
to
10bb6d0
Compare
|
||
// Support parent implementation of virtual functions defined in `gio::ffi::GFileMonitorClass`. | ||
pub trait FileMonitorImplExt: FileMonitorImpl { | ||
fn parent_cancel(&self) -> bool { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the return of this vfunc doesn't seem to be used https://gitlab.gnome.org/GNOME/glib/-/blob/main/gio/gfilemonitor.c#L254, weird but maybe we can make it return Option and fallback to TRUE if the user has no clue what to return (which is expected, i guess?)
// default implementation provided by GIO | ||
// klass.next_files_async = Some(next_files_async::<T>); | ||
// klass.next_files_finish = Some(next_files_finish::<T>); | ||
// klass.close_async = Some(close_async::<T>); | ||
// klass.close_finish = Some(close_finish::<T>); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe add a TODO comment so they can easily be grep-ed for ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
or at least document the why it is like this
@@ -1111,6 +1113,98 @@ pub trait FileExtManual: IsA<File> + Sized { | |||
|
|||
(fut, Box::pin(receiver)) | |||
} | |||
|
|||
#[doc(alias = "g_file_set_attribute")] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this could be split and we can land it already
use gio::{Cancellable, File, FileMonitorFlags}; | ||
let _ = File::for_uri("resource:/").monitor_file(FileMonitorFlags::NONE, Cancellable::NONE); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can't you create a GType from the names and then calling T::ensure_type on it?
glib::wrapper! { | ||
#[doc(alias = "GResourceFileMonitor")] | ||
pub struct ResourceFileMonitor(Object<ffi::GResourceFileMonitor, ffi::GResourceFileMonitorClass>) @extends FileMonitor; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ResourceFileMonitor why is this here? i don't feel like it should be part of the test...
Allow custom implementation of gio::Vfs, gio::File, gio::FileEnumerator and gio::FileMonitor