Skip to main content

gtk4/auto/
directory_list.rs

1// This file was generated by gir (https://github.com/gtk-rs/gir)
2// from gir-files (https://github.com/gtk-rs/gir-files)
3// DO NOT EDIT
4
5use crate::ffi;
6use glib::{
7    prelude::*,
8    signal::{SignalHandlerId, connect_raw},
9    translate::*,
10};
11use std::boxed::Box as Box_;
12
13glib::wrapper! {
14    /// A list model that wraps [`FileExtManual::enumerate_children_async()`][crate::gio::prelude::FileExtManual::enumerate_children_async()].
15    ///
16    /// It presents a `GListModel` and fills it asynchronously with the `GFileInfo`s
17    /// returned from that function.
18    ///
19    /// Enumeration will start automatically when the
20    /// [`file`][struct@crate::DirectoryList#file] property is set.
21    ///
22    /// While the [`DirectoryList`][crate::DirectoryList] is being filled, the
23    /// [`loading`][struct@crate::DirectoryList#loading] property will be set to [`true`]. You can
24    /// listen to that property if you want to show information like a [`Spinner`][crate::Spinner]
25    /// or a "Loading..." text.
26    ///
27    /// If loading fails at any point, the [`error`][struct@crate::DirectoryList#error]
28    /// property will be set to give more indication about the failure.
29    ///
30    /// The `GFileInfo`s returned from a [`DirectoryList`][crate::DirectoryList] have the "standard::file"
31    /// attribute set to the `GFile` they refer to. This way you can get at the file
32    /// that is referred to in the same way you would via g_file_enumerator_get_child().
33    /// This means you do not need access to the [`DirectoryList`][crate::DirectoryList], but can access
34    /// the `GFile` directly from the `GFileInfo` when operating with a [`ListView`][crate::ListView]
35    /// or similar.
36    ///
37    /// ## Properties
38    ///
39    ///
40    /// #### `attributes`
41    ///  The attributes to query.
42    ///
43    /// Readable | Writeable
44    ///
45    ///
46    /// #### `error`
47    ///  Error encountered while loading files.
48    ///
49    /// Readable
50    ///
51    ///
52    /// #### `file`
53    ///  File to query.
54    ///
55    /// Readable | Writeable
56    ///
57    ///
58    /// #### `io-priority`
59    ///  Priority used when loading.
60    ///
61    /// Readable | Writeable
62    ///
63    ///
64    /// #### `item-type`
65    ///  The type of items. See [`ListModelExtManual::item_type()`][crate::gio::prelude::ListModelExtManual::item_type()].
66    ///
67    /// Readable
68    ///
69    ///
70    /// #### `loading`
71    ///  [`true`] if files are being loaded.
72    ///
73    /// Readable
74    ///
75    ///
76    /// #### `monitored`
77    ///  [`true`] if the directory is monitored for changed.
78    ///
79    /// Readable | Writeable
80    ///
81    ///
82    /// #### `n-items`
83    ///  The number of items. See [`ListModelExtManual::n_items()`][crate::gio::prelude::ListModelExtManual::n_items()].
84    ///
85    /// Readable
86    ///
87    /// # Implements
88    ///
89    /// [`trait@glib::ObjectExt`], [`trait@gio::prelude::ListModelExt`]
90    #[doc(alias = "GtkDirectoryList")]
91    pub struct DirectoryList(Object<ffi::GtkDirectoryList, ffi::GtkDirectoryListClass>) @implements gio::ListModel;
92
93    match fn {
94        type_ => || ffi::gtk_directory_list_get_type(),
95    }
96}
97
98impl DirectoryList {
99    /// Creates a new [`DirectoryList`][crate::DirectoryList].
100    ///
101    /// The [`DirectoryList`][crate::DirectoryList] is querying the given @file
102    /// with the given @attributes.
103    /// ## `attributes`
104    /// The attributes to query with
105    /// ## `file`
106    /// The file to query
107    ///
108    /// # Returns
109    ///
110    /// a new [`DirectoryList`][crate::DirectoryList]
111    #[doc(alias = "gtk_directory_list_new")]
112    pub fn new(attributes: Option<&str>, file: Option<&impl IsA<gio::File>>) -> DirectoryList {
113        assert_initialized_main_thread!();
114        unsafe {
115            from_glib_full(ffi::gtk_directory_list_new(
116                attributes.to_glib_none().0,
117                file.map(|p| p.as_ref()).to_glib_none().0,
118            ))
119        }
120    }
121
122    /// Gets the attributes queried on the children.
123    ///
124    /// # Returns
125    ///
126    /// The queried attributes
127    #[doc(alias = "gtk_directory_list_get_attributes")]
128    #[doc(alias = "get_attributes")]
129    pub fn attributes(&self) -> Option<glib::GString> {
130        unsafe {
131            from_glib_none(ffi::gtk_directory_list_get_attributes(
132                self.to_glib_none().0,
133            ))
134        }
135    }
136
137    /// Gets the loading error, if any.
138    ///
139    /// If an error occurs during the loading process, the loading process
140    /// will finish and this property allows querying the error that happened.
141    /// This error will persist until a file is loaded again.
142    ///
143    /// An error being set does not mean that no files were loaded, and all
144    /// successfully queried files will remain in the list.
145    ///
146    /// # Returns
147    ///
148    /// The loading error or [`None`] if
149    ///   loading finished successfully
150    #[doc(alias = "gtk_directory_list_get_error")]
151    #[doc(alias = "get_error")]
152    pub fn error(&self) -> Option<glib::Error> {
153        unsafe { from_glib_none(ffi::gtk_directory_list_get_error(self.to_glib_none().0)) }
154    }
155
156    /// Gets the file whose children are currently enumerated.
157    ///
158    /// # Returns
159    ///
160    /// The file whose children are enumerated
161    #[doc(alias = "gtk_directory_list_get_file")]
162    #[doc(alias = "get_file")]
163    pub fn file(&self) -> Option<gio::File> {
164        unsafe { from_glib_none(ffi::gtk_directory_list_get_file(self.to_glib_none().0)) }
165    }
166
167    /// Returns whether the directory list is monitoring
168    /// the directory for changes.
169    ///
170    /// # Returns
171    ///
172    /// [`true`] if the directory is monitored
173    #[doc(alias = "gtk_directory_list_get_monitored")]
174    #[doc(alias = "get_monitored")]
175    #[doc(alias = "monitored")]
176    pub fn is_monitored(&self) -> bool {
177        unsafe { from_glib(ffi::gtk_directory_list_get_monitored(self.to_glib_none().0)) }
178    }
179
180    /// Returns [`true`] if the children enumeration is currently in
181    /// progress.
182    ///
183    /// Files will be added to @self from time to time while loading is
184    /// going on. The order in which are added is undefined and may change
185    /// in between runs.
186    ///
187    /// # Returns
188    ///
189    /// [`true`] if @self is loading
190    #[doc(alias = "gtk_directory_list_is_loading")]
191    #[doc(alias = "loading")]
192    pub fn is_loading(&self) -> bool {
193        unsafe { from_glib(ffi::gtk_directory_list_is_loading(self.to_glib_none().0)) }
194    }
195
196    /// Sets the @attributes to be enumerated and starts the enumeration.
197    ///
198    /// If @attributes is [`None`], the list of file infos will still be created, it will just
199    /// not contain any extra attributes.
200    /// ## `attributes`
201    /// the attributes to enumerate
202    #[doc(alias = "gtk_directory_list_set_attributes")]
203    #[doc(alias = "attributes")]
204    pub fn set_attributes(&self, attributes: Option<&str>) {
205        unsafe {
206            ffi::gtk_directory_list_set_attributes(
207                self.to_glib_none().0,
208                attributes.to_glib_none().0,
209            );
210        }
211    }
212
213    /// Sets the @file to be enumerated and starts the enumeration.
214    ///
215    /// If @file is [`None`], the result will be an empty list.
216    /// ## `file`
217    /// the `GFile` to be enumerated
218    #[doc(alias = "gtk_directory_list_set_file")]
219    #[doc(alias = "file")]
220    pub fn set_file(&self, file: Option<&impl IsA<gio::File>>) {
221        unsafe {
222            ffi::gtk_directory_list_set_file(
223                self.to_glib_none().0,
224                file.map(|p| p.as_ref()).to_glib_none().0,
225            );
226        }
227    }
228
229    /// Sets whether the directory list will monitor the directory
230    /// for changes.
231    ///
232    /// If monitoring is enabled, the ::items-changed signal will
233    /// be emitted when the directory contents change.
234    ///
235    ///
236    /// When monitoring is turned on after the initial creation
237    /// of the directory list, the directory is reloaded to avoid
238    /// missing files that appeared between the initial loading
239    /// and when monitoring was turned on.
240    /// ## `monitored`
241    /// [`true`] to monitor the directory for changes
242    #[doc(alias = "gtk_directory_list_set_monitored")]
243    #[doc(alias = "monitored")]
244    pub fn set_monitored(&self, monitored: bool) {
245        unsafe {
246            ffi::gtk_directory_list_set_monitored(self.to_glib_none().0, monitored.into_glib());
247        }
248    }
249
250    #[doc(alias = "attributes")]
251    pub fn connect_attributes_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
252        unsafe extern "C" fn notify_attributes_trampoline<F: Fn(&DirectoryList) + 'static>(
253            this: *mut ffi::GtkDirectoryList,
254            _param_spec: glib::ffi::gpointer,
255            f: glib::ffi::gpointer,
256        ) {
257            unsafe {
258                let f: &F = &*(f as *const F);
259                f(&from_glib_borrow(this))
260            }
261        }
262        unsafe {
263            let f: Box_<F> = Box_::new(f);
264            connect_raw(
265                self.as_ptr() as *mut _,
266                c"notify::attributes".as_ptr(),
267                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
268                    notify_attributes_trampoline::<F> as *const (),
269                )),
270                Box_::into_raw(f),
271            )
272        }
273    }
274
275    #[doc(alias = "error")]
276    pub fn connect_error_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
277        unsafe extern "C" fn notify_error_trampoline<F: Fn(&DirectoryList) + 'static>(
278            this: *mut ffi::GtkDirectoryList,
279            _param_spec: glib::ffi::gpointer,
280            f: glib::ffi::gpointer,
281        ) {
282            unsafe {
283                let f: &F = &*(f as *const F);
284                f(&from_glib_borrow(this))
285            }
286        }
287        unsafe {
288            let f: Box_<F> = Box_::new(f);
289            connect_raw(
290                self.as_ptr() as *mut _,
291                c"notify::error".as_ptr(),
292                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
293                    notify_error_trampoline::<F> as *const (),
294                )),
295                Box_::into_raw(f),
296            )
297        }
298    }
299
300    #[doc(alias = "file")]
301    pub fn connect_file_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
302        unsafe extern "C" fn notify_file_trampoline<F: Fn(&DirectoryList) + 'static>(
303            this: *mut ffi::GtkDirectoryList,
304            _param_spec: glib::ffi::gpointer,
305            f: glib::ffi::gpointer,
306        ) {
307            unsafe {
308                let f: &F = &*(f as *const F);
309                f(&from_glib_borrow(this))
310            }
311        }
312        unsafe {
313            let f: Box_<F> = Box_::new(f);
314            connect_raw(
315                self.as_ptr() as *mut _,
316                c"notify::file".as_ptr(),
317                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
318                    notify_file_trampoline::<F> as *const (),
319                )),
320                Box_::into_raw(f),
321            )
322        }
323    }
324
325    #[doc(alias = "io-priority")]
326    pub fn connect_io_priority_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
327        unsafe extern "C" fn notify_io_priority_trampoline<F: Fn(&DirectoryList) + 'static>(
328            this: *mut ffi::GtkDirectoryList,
329            _param_spec: glib::ffi::gpointer,
330            f: glib::ffi::gpointer,
331        ) {
332            unsafe {
333                let f: &F = &*(f as *const F);
334                f(&from_glib_borrow(this))
335            }
336        }
337        unsafe {
338            let f: Box_<F> = Box_::new(f);
339            connect_raw(
340                self.as_ptr() as *mut _,
341                c"notify::io-priority".as_ptr(),
342                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
343                    notify_io_priority_trampoline::<F> as *const (),
344                )),
345                Box_::into_raw(f),
346            )
347        }
348    }
349
350    #[doc(alias = "loading")]
351    pub fn connect_loading_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
352        unsafe extern "C" fn notify_loading_trampoline<F: Fn(&DirectoryList) + 'static>(
353            this: *mut ffi::GtkDirectoryList,
354            _param_spec: glib::ffi::gpointer,
355            f: glib::ffi::gpointer,
356        ) {
357            unsafe {
358                let f: &F = &*(f as *const F);
359                f(&from_glib_borrow(this))
360            }
361        }
362        unsafe {
363            let f: Box_<F> = Box_::new(f);
364            connect_raw(
365                self.as_ptr() as *mut _,
366                c"notify::loading".as_ptr(),
367                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
368                    notify_loading_trampoline::<F> as *const (),
369                )),
370                Box_::into_raw(f),
371            )
372        }
373    }
374
375    #[doc(alias = "monitored")]
376    pub fn connect_monitored_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
377        unsafe extern "C" fn notify_monitored_trampoline<F: Fn(&DirectoryList) + 'static>(
378            this: *mut ffi::GtkDirectoryList,
379            _param_spec: glib::ffi::gpointer,
380            f: glib::ffi::gpointer,
381        ) {
382            unsafe {
383                let f: &F = &*(f as *const F);
384                f(&from_glib_borrow(this))
385            }
386        }
387        unsafe {
388            let f: Box_<F> = Box_::new(f);
389            connect_raw(
390                self.as_ptr() as *mut _,
391                c"notify::monitored".as_ptr(),
392                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
393                    notify_monitored_trampoline::<F> as *const (),
394                )),
395                Box_::into_raw(f),
396            )
397        }
398    }
399}