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::{connect_raw, SignalHandlerId},
9 translate::*,
10};
11use std::boxed::Box as Box_;
12
13glib::wrapper! {
14 /// [`DirectoryList`][crate::DirectoryList] is a list model that wraps g_file_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 let f: &F = &*(f as *const F);
258 f(&from_glib_borrow(this))
259 }
260 unsafe {
261 let f: Box_<F> = Box_::new(f);
262 connect_raw(
263 self.as_ptr() as *mut _,
264 b"notify::attributes\0".as_ptr() as *const _,
265 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
266 notify_attributes_trampoline::<F> as *const (),
267 )),
268 Box_::into_raw(f),
269 )
270 }
271 }
272
273 #[doc(alias = "error")]
274 pub fn connect_error_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
275 unsafe extern "C" fn notify_error_trampoline<F: Fn(&DirectoryList) + 'static>(
276 this: *mut ffi::GtkDirectoryList,
277 _param_spec: glib::ffi::gpointer,
278 f: glib::ffi::gpointer,
279 ) {
280 let f: &F = &*(f as *const F);
281 f(&from_glib_borrow(this))
282 }
283 unsafe {
284 let f: Box_<F> = Box_::new(f);
285 connect_raw(
286 self.as_ptr() as *mut _,
287 b"notify::error\0".as_ptr() as *const _,
288 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
289 notify_error_trampoline::<F> as *const (),
290 )),
291 Box_::into_raw(f),
292 )
293 }
294 }
295
296 #[doc(alias = "file")]
297 pub fn connect_file_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
298 unsafe extern "C" fn notify_file_trampoline<F: Fn(&DirectoryList) + 'static>(
299 this: *mut ffi::GtkDirectoryList,
300 _param_spec: glib::ffi::gpointer,
301 f: glib::ffi::gpointer,
302 ) {
303 let f: &F = &*(f as *const F);
304 f(&from_glib_borrow(this))
305 }
306 unsafe {
307 let f: Box_<F> = Box_::new(f);
308 connect_raw(
309 self.as_ptr() as *mut _,
310 b"notify::file\0".as_ptr() as *const _,
311 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
312 notify_file_trampoline::<F> as *const (),
313 )),
314 Box_::into_raw(f),
315 )
316 }
317 }
318
319 #[doc(alias = "io-priority")]
320 pub fn connect_io_priority_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
321 unsafe extern "C" fn notify_io_priority_trampoline<F: Fn(&DirectoryList) + 'static>(
322 this: *mut ffi::GtkDirectoryList,
323 _param_spec: glib::ffi::gpointer,
324 f: glib::ffi::gpointer,
325 ) {
326 let f: &F = &*(f as *const F);
327 f(&from_glib_borrow(this))
328 }
329 unsafe {
330 let f: Box_<F> = Box_::new(f);
331 connect_raw(
332 self.as_ptr() as *mut _,
333 b"notify::io-priority\0".as_ptr() as *const _,
334 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
335 notify_io_priority_trampoline::<F> as *const (),
336 )),
337 Box_::into_raw(f),
338 )
339 }
340 }
341
342 #[doc(alias = "loading")]
343 pub fn connect_loading_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
344 unsafe extern "C" fn notify_loading_trampoline<F: Fn(&DirectoryList) + 'static>(
345 this: *mut ffi::GtkDirectoryList,
346 _param_spec: glib::ffi::gpointer,
347 f: glib::ffi::gpointer,
348 ) {
349 let f: &F = &*(f as *const F);
350 f(&from_glib_borrow(this))
351 }
352 unsafe {
353 let f: Box_<F> = Box_::new(f);
354 connect_raw(
355 self.as_ptr() as *mut _,
356 b"notify::loading\0".as_ptr() as *const _,
357 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
358 notify_loading_trampoline::<F> as *const (),
359 )),
360 Box_::into_raw(f),
361 )
362 }
363 }
364
365 #[doc(alias = "monitored")]
366 pub fn connect_monitored_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
367 unsafe extern "C" fn notify_monitored_trampoline<F: Fn(&DirectoryList) + 'static>(
368 this: *mut ffi::GtkDirectoryList,
369 _param_spec: glib::ffi::gpointer,
370 f: glib::ffi::gpointer,
371 ) {
372 let f: &F = &*(f as *const F);
373 f(&from_glib_borrow(this))
374 }
375 unsafe {
376 let f: Box_<F> = Box_::new(f);
377 connect_raw(
378 self.as_ptr() as *mut _,
379 b"notify::monitored\0".as_ptr() as *const _,
380 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
381 notify_monitored_trampoline::<F> as *const (),
382 )),
383 Box_::into_raw(f),
384 )
385 }
386 }
387}