-
-
Notifications
You must be signed in to change notification settings - Fork 127
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
e9842cc
to
10bb6d0
Compare
gio/src/subclass/file_monitor.rs
Outdated
|
||
// 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?)
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 documentation states that this cancel
must always return true
.(https://docs.gtk.org/gio/vfunc.FileMonitor.cancel.html)
so I suggest to simply debug_assert!
the value returned by parent.
And maybe document the method to indicate that the return value must be true
.
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 docs will get embedded automatically, so maybe a debug_assert with an in-code comment is good enough
gio/src/subclass/file_enumerator.rs
Outdated
// 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
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 (also in subclass/file.rs
)
gio/src/file.rs
Outdated
@@ -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
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.
in a separate Pull Request ?
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.
yes, to avoid having a very big PR here that will take forever to review
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. See #1713
gio/tests/file_monitor.rs
Outdated
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?
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.
unfortunately it does not work and parent type is not initialized, that is why it was indirectly initialized by calling File::monitor_file, as a workaround.
gio/tests/file_monitor.rs
Outdated
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...
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.
Yes it seems strange, but ResourceFileMonitor
(which is not a public GType) is the easier existing type to subclass for this test.
Anyway, I reviewed the code to not rely on existing type. Therefore, this test defines 2 custom types: MyCustomFileMonitor
which subclasses MyFileMonitor
.
Maybe I will have to review in the same way tests for FileEnumerator
, File
and Vfs
.
260cf0e
to
0cb4a44
Compare
0cb4a44
to
a0345a9
Compare
gio/src/subclass/file_monitor.rs
Outdated
@@ -0,0 +1,56 @@ | |||
// Take a look at the license at the top of the repository in the LICENSE 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.
Given that this one is very simple, we can review/merge it in a separate PR already.
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.
see #1725
@@ -0,0 +1,184 @@ | |||
// Take a look at the license at the top of the repository in the LICENSE file. | |||
|
|||
use glib::{prelude::*, subclass::prelude::*, translate::*, GString}; |
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 split this one as well
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.
see #1726
Signed-off-by: fbrouille <[email protected]>
Signed-off-by: fbrouille <[email protected]>
Signed-off-by: fbrouille <[email protected]>
Signed-off-by: fbrouille <[email protected]>
a0345a9
to
72eca83
Compare
@@ -0,0 +1,154 @@ | |||
// Take a look at the license at the top of the repository in the LICENSE 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 pull this into a separate PR as well? so you only keep GFile for this one.
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.
see #1740
Allow custom implementation of gio::Vfs, gio::File, gio::FileEnumerator and gio::FileMonitor