gio/auto/file_info.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#![allow(deprecated)]
5
6use crate::{ffi, FileAttributeMatcher, FileAttributeStatus, FileAttributeType, FileType, Icon};
7use glib::{prelude::*, translate::*};
8
9glib::wrapper! {
10 /// Stores information about a file system object referenced by a [`File`][crate::File].
11 ///
12 /// Functionality for manipulating basic metadata for files. `GFileInfo`
13 /// implements methods for getting information that all files should
14 /// contain, and allows for manipulation of extended attributes.
15 ///
16 /// See the [file attributes](file-attributes.html) document for more
17 /// information on how GIO handles file attributes.
18 ///
19 /// To obtain a `GFileInfo` for a [`File`][crate::File], use
20 /// [`FileExt::query_info()`][crate::prelude::FileExt::query_info()] (or its async variant). To obtain a `GFileInfo`
21 /// for a file input or output stream, use [`FileInputStreamExt::query_info()`][crate::prelude::FileInputStreamExt::query_info()]
22 /// or [`FileOutputStreamExt::query_info()`][crate::prelude::FileOutputStreamExt::query_info()] (or their async variants).
23 ///
24 /// To change the actual attributes of a file, you should then set the
25 /// attribute in the `GFileInfo` and call [`FileExt::set_attributes_from_info()`][crate::prelude::FileExt::set_attributes_from_info()]
26 /// or [`FileExt::set_attributes_async()`][crate::prelude::FileExt::set_attributes_async()] on a `GFile`.
27 ///
28 /// However, not all attributes can be changed in the file. For instance,
29 /// the actual size of a file cannot be changed via [`set_size()`][Self::set_size()].
30 /// You may call [`FileExt::query_settable_attributes()`][crate::prelude::FileExt::query_settable_attributes()] and
31 /// [`FileExt::query_writable_namespaces()`][crate::prelude::FileExt::query_writable_namespaces()] to discover the settable attributes
32 /// of a particular file at runtime.
33 ///
34 /// The direct accessors, such as [`name()`][Self::name()], are slightly more
35 /// optimized than the generic attribute accessors, such as
36 /// [`attribute_byte_string()`][Self::attribute_byte_string()].This optimization will matter
37 /// only if calling the API in a tight loop.
38 ///
39 /// It is an error to call these accessors without specifying their required file
40 /// attributes when creating the `GFileInfo`. Use
41 /// [`has_attribute()`][Self::has_attribute()] or [`list_attributes()`][Self::list_attributes()]
42 /// to check what attributes are specified for a `GFileInfo`.
43 ///
44 /// [`FileAttributeMatcher`][crate::FileAttributeMatcher] allows for searching through a `GFileInfo`
45 /// for attributes.
46 ///
47 /// # Implements
48 ///
49 /// [`trait@glib::ObjectExt`]
50 #[doc(alias = "GFileInfo")]
51 pub struct FileInfo(Object<ffi::GFileInfo, ffi::GFileInfoClass>);
52
53 match fn {
54 type_ => || ffi::g_file_info_get_type(),
55 }
56}
57
58impl FileInfo {
59 /// Creates a new file info structure.
60 ///
61 /// # Returns
62 ///
63 /// a #GFileInfo.
64 #[doc(alias = "g_file_info_new")]
65 pub fn new() -> FileInfo {
66 unsafe { from_glib_full(ffi::g_file_info_new()) }
67 }
68
69 /// Clears the status information from @self.
70 #[doc(alias = "g_file_info_clear_status")]
71 pub fn clear_status(&self) {
72 unsafe {
73 ffi::g_file_info_clear_status(self.to_glib_none().0);
74 }
75 }
76
77 /// First clears all of the [GFileAttribute](file-attributes.html#file-attributes) of
78 /// @dest_info, and then copies all of the file attributes from @self to @dest_info.
79 /// ## `dest_info`
80 /// destination to copy attributes to.
81 #[doc(alias = "g_file_info_copy_into")]
82 pub fn copy_into(&self, dest_info: &FileInfo) {
83 unsafe {
84 ffi::g_file_info_copy_into(self.to_glib_none().0, dest_info.to_glib_none().0);
85 }
86 }
87
88 /// Duplicates a file info structure.
89 ///
90 /// # Returns
91 ///
92 /// a duplicate #GFileInfo of @self.
93 #[doc(alias = "g_file_info_dup")]
94 #[must_use]
95 pub fn dup(&self) -> FileInfo {
96 unsafe { from_glib_full(ffi::g_file_info_dup(self.to_glib_none().0)) }
97 }
98
99 /// Gets the access time of the current @self and returns it as a
100 /// #GDateTime.
101 ///
102 /// It is an error to call this if the #GFileInfo does not contain
103 /// [`FILE_ATTRIBUTE_TIME_ACCESS`][crate::FILE_ATTRIBUTE_TIME_ACCESS]. If [`FILE_ATTRIBUTE_TIME_ACCESS_USEC`][crate::FILE_ATTRIBUTE_TIME_ACCESS_USEC] is
104 /// provided, the resulting #GDateTime will additionally have microsecond
105 /// precision.
106 ///
107 /// If nanosecond precision is needed, [`FILE_ATTRIBUTE_TIME_ACCESS_NSEC`][crate::FILE_ATTRIBUTE_TIME_ACCESS_NSEC] must
108 /// be queried separately using g_file_info_get_attribute_uint32().
109 ///
110 /// # Returns
111 ///
112 /// access time, or [`None`] if unknown
113 #[cfg(feature = "v2_70")]
114 #[cfg_attr(docsrs, doc(cfg(feature = "v2_70")))]
115 #[doc(alias = "g_file_info_get_access_date_time")]
116 #[doc(alias = "get_access_date_time")]
117 pub fn access_date_time(&self) -> Option<glib::DateTime> {
118 unsafe { from_glib_full(ffi::g_file_info_get_access_date_time(self.to_glib_none().0)) }
119 }
120
121 /// Gets the value of an attribute, formatted as a string.
122 /// This escapes things as needed to make the string valid
123 /// UTF-8.
124 /// ## `attribute`
125 /// a file attribute key.
126 ///
127 /// # Returns
128 ///
129 /// a UTF-8 string associated with the given @attribute, or
130 /// [`None`] if the attribute wasn’t set.
131 /// When you're done with the string it must be freed with g_free().
132 #[doc(alias = "g_file_info_get_attribute_as_string")]
133 #[doc(alias = "get_attribute_as_string")]
134 pub fn attribute_as_string(&self, attribute: &str) -> Option<glib::GString> {
135 unsafe {
136 from_glib_full(ffi::g_file_info_get_attribute_as_string(
137 self.to_glib_none().0,
138 attribute.to_glib_none().0,
139 ))
140 }
141 }
142
143 /// Gets the value of a boolean attribute. If the attribute does not
144 /// contain a boolean value, [`false`] will be returned.
145 /// ## `attribute`
146 /// a file attribute key.
147 ///
148 /// # Returns
149 ///
150 /// the boolean value contained within the attribute.
151 #[doc(alias = "g_file_info_get_attribute_boolean")]
152 #[doc(alias = "get_attribute_boolean")]
153 pub fn boolean(&self, attribute: &str) -> bool {
154 unsafe {
155 from_glib(ffi::g_file_info_get_attribute_boolean(
156 self.to_glib_none().0,
157 attribute.to_glib_none().0,
158 ))
159 }
160 }
161
162 /// Gets the value of a byte string attribute. If the attribute does
163 /// not contain a byte string, [`None`] will be returned.
164 /// ## `attribute`
165 /// a file attribute key.
166 ///
167 /// # Returns
168 ///
169 /// the contents of the @attribute value as a byte string, or
170 /// [`None`] otherwise.
171 #[doc(alias = "g_file_info_get_attribute_byte_string")]
172 #[doc(alias = "get_attribute_byte_string")]
173 pub fn attribute_byte_string(&self, attribute: &str) -> Option<glib::GString> {
174 unsafe {
175 from_glib_none(ffi::g_file_info_get_attribute_byte_string(
176 self.to_glib_none().0,
177 attribute.to_glib_none().0,
178 ))
179 }
180 }
181
182 //#[doc(alias = "g_file_info_get_attribute_data")]
183 //#[doc(alias = "get_attribute_data")]
184 //pub fn attribute_data(&self, attribute: &str, value_pp: /*Unimplemented*/&mut Basic: Pointer) -> Option<(FileAttributeType, FileAttributeStatus)> {
185 // unsafe { TODO: call ffi:g_file_info_get_attribute_data() }
186 //}
187
188 /// Gets the value of a byte string attribute as a file path.
189 ///
190 /// If the attribute does not contain a byte string, `NULL` will be returned.
191 ///
192 /// This function is meant to be used by language bindings that have specific
193 /// handling for Unix paths.
194 /// ## `attribute`
195 /// a file attribute key.
196 ///
197 /// # Returns
198 ///
199 /// the contents of the @attribute value as
200 /// a file path, or [`None`] otherwise.
201 #[cfg(feature = "v2_78")]
202 #[cfg_attr(docsrs, doc(cfg(feature = "v2_78")))]
203 #[doc(alias = "g_file_info_get_attribute_file_path")]
204 #[doc(alias = "get_attribute_file_path")]
205 pub fn attribute_file_path(&self, attribute: &str) -> Option<std::path::PathBuf> {
206 unsafe {
207 from_glib_none(ffi::g_file_info_get_attribute_file_path(
208 self.to_glib_none().0,
209 attribute.to_glib_none().0,
210 ))
211 }
212 }
213
214 /// Gets a signed 32-bit integer contained within the attribute. If the
215 /// attribute does not contain a signed 32-bit integer, or is invalid,
216 /// 0 will be returned.
217 /// ## `attribute`
218 /// a file attribute key.
219 ///
220 /// # Returns
221 ///
222 /// a signed 32-bit integer from the attribute.
223 #[doc(alias = "g_file_info_get_attribute_int32")]
224 #[doc(alias = "get_attribute_int32")]
225 pub fn attribute_int32(&self, attribute: &str) -> i32 {
226 unsafe {
227 ffi::g_file_info_get_attribute_int32(self.to_glib_none().0, attribute.to_glib_none().0)
228 }
229 }
230
231 /// Gets a signed 64-bit integer contained within the attribute. If the
232 /// attribute does not contain a signed 64-bit integer, or is invalid,
233 /// 0 will be returned.
234 /// ## `attribute`
235 /// a file attribute key.
236 ///
237 /// # Returns
238 ///
239 /// a signed 64-bit integer from the attribute.
240 #[doc(alias = "g_file_info_get_attribute_int64")]
241 #[doc(alias = "get_attribute_int64")]
242 pub fn attribute_int64(&self, attribute: &str) -> i64 {
243 unsafe {
244 ffi::g_file_info_get_attribute_int64(self.to_glib_none().0, attribute.to_glib_none().0)
245 }
246 }
247
248 /// Gets the value of a #GObject attribute. If the attribute does
249 /// not contain a #GObject, [`None`] will be returned.
250 /// ## `attribute`
251 /// a file attribute key.
252 ///
253 /// # Returns
254 ///
255 /// a #GObject associated with the given @attribute,
256 /// or [`None`] otherwise.
257 #[doc(alias = "g_file_info_get_attribute_object")]
258 #[doc(alias = "get_attribute_object")]
259 pub fn attribute_object(&self, attribute: &str) -> Option<glib::Object> {
260 unsafe {
261 from_glib_none(ffi::g_file_info_get_attribute_object(
262 self.to_glib_none().0,
263 attribute.to_glib_none().0,
264 ))
265 }
266 }
267
268 /// Gets the attribute status for an attribute key.
269 /// ## `attribute`
270 /// a file attribute key
271 ///
272 /// # Returns
273 ///
274 /// a #GFileAttributeStatus for the given @attribute, or
275 /// [`FileAttributeStatus::Unset`][crate::FileAttributeStatus::Unset] if the key is invalid.
276 #[doc(alias = "g_file_info_get_attribute_status")]
277 #[doc(alias = "get_attribute_status")]
278 pub fn attribute_status(&self, attribute: &str) -> FileAttributeStatus {
279 unsafe {
280 from_glib(ffi::g_file_info_get_attribute_status(
281 self.to_glib_none().0,
282 attribute.to_glib_none().0,
283 ))
284 }
285 }
286
287 /// Gets the value of a string attribute. If the attribute does
288 /// not contain a string, [`None`] will be returned.
289 /// ## `attribute`
290 /// a file attribute key.
291 ///
292 /// # Returns
293 ///
294 /// the contents of the @attribute value as a UTF-8 string,
295 /// or [`None`] otherwise.
296 #[doc(alias = "g_file_info_get_attribute_string")]
297 #[doc(alias = "get_attribute_string")]
298 pub fn attribute_string(&self, attribute: &str) -> Option<glib::GString> {
299 unsafe {
300 from_glib_none(ffi::g_file_info_get_attribute_string(
301 self.to_glib_none().0,
302 attribute.to_glib_none().0,
303 ))
304 }
305 }
306
307 /// Gets the attribute type for an attribute key.
308 /// ## `attribute`
309 /// a file attribute key.
310 ///
311 /// # Returns
312 ///
313 /// a #GFileAttributeType for the given @attribute, or
314 /// [`FileAttributeType::Invalid`][crate::FileAttributeType::Invalid] if the key is not set.
315 #[doc(alias = "g_file_info_get_attribute_type")]
316 #[doc(alias = "get_attribute_type")]
317 pub fn attribute_type(&self, attribute: &str) -> FileAttributeType {
318 unsafe {
319 from_glib(ffi::g_file_info_get_attribute_type(
320 self.to_glib_none().0,
321 attribute.to_glib_none().0,
322 ))
323 }
324 }
325
326 /// Gets an unsigned 32-bit integer contained within the attribute. If the
327 /// attribute does not contain an unsigned 32-bit integer, or is invalid,
328 /// 0 will be returned.
329 /// ## `attribute`
330 /// a file attribute key.
331 ///
332 /// # Returns
333 ///
334 /// an unsigned 32-bit integer from the attribute.
335 #[doc(alias = "g_file_info_get_attribute_uint32")]
336 #[doc(alias = "get_attribute_uint32")]
337 pub fn attribute_uint32(&self, attribute: &str) -> u32 {
338 unsafe {
339 ffi::g_file_info_get_attribute_uint32(self.to_glib_none().0, attribute.to_glib_none().0)
340 }
341 }
342
343 /// Gets a unsigned 64-bit integer contained within the attribute. If the
344 /// attribute does not contain an unsigned 64-bit integer, or is invalid,
345 /// 0 will be returned.
346 /// ## `attribute`
347 /// a file attribute key.
348 ///
349 /// # Returns
350 ///
351 /// a unsigned 64-bit integer from the attribute.
352 #[doc(alias = "g_file_info_get_attribute_uint64")]
353 #[doc(alias = "get_attribute_uint64")]
354 pub fn attribute_uint64(&self, attribute: &str) -> u64 {
355 unsafe {
356 ffi::g_file_info_get_attribute_uint64(self.to_glib_none().0, attribute.to_glib_none().0)
357 }
358 }
359
360 /// Gets the file's content type.
361 ///
362 /// It is an error to call this if the #GFileInfo does not contain
363 /// [`FILE_ATTRIBUTE_STANDARD_CONTENT_TYPE`][crate::FILE_ATTRIBUTE_STANDARD_CONTENT_TYPE].
364 ///
365 /// # Returns
366 ///
367 /// a string containing the file's content type,
368 /// or [`None`] if unknown.
369 #[doc(alias = "g_file_info_get_content_type")]
370 #[doc(alias = "get_content_type")]
371 pub fn content_type(&self) -> Option<glib::GString> {
372 unsafe { from_glib_none(ffi::g_file_info_get_content_type(self.to_glib_none().0)) }
373 }
374
375 /// Gets the creation time of the current @self and returns it as a
376 /// #GDateTime.
377 ///
378 /// It is an error to call this if the #GFileInfo does not contain
379 /// [`FILE_ATTRIBUTE_TIME_CREATED`][crate::FILE_ATTRIBUTE_TIME_CREATED]. If [`FILE_ATTRIBUTE_TIME_CREATED_USEC`][crate::FILE_ATTRIBUTE_TIME_CREATED_USEC] is
380 /// provided, the resulting #GDateTime will additionally have microsecond
381 /// precision.
382 ///
383 /// If nanosecond precision is needed, [`FILE_ATTRIBUTE_TIME_CREATED_NSEC`][crate::FILE_ATTRIBUTE_TIME_CREATED_NSEC] must
384 /// be queried separately using g_file_info_get_attribute_uint32().
385 ///
386 /// # Returns
387 ///
388 /// creation time, or [`None`] if unknown
389 #[cfg(feature = "v2_70")]
390 #[cfg_attr(docsrs, doc(cfg(feature = "v2_70")))]
391 #[doc(alias = "g_file_info_get_creation_date_time")]
392 #[doc(alias = "get_creation_date_time")]
393 pub fn creation_date_time(&self) -> Option<glib::DateTime> {
394 unsafe {
395 from_glib_full(ffi::g_file_info_get_creation_date_time(
396 self.to_glib_none().0,
397 ))
398 }
399 }
400
401 /// Returns the #GDateTime representing the deletion date of the file, as
402 /// available in [`FILE_ATTRIBUTE_TRASH_DELETION_DATE`][crate::FILE_ATTRIBUTE_TRASH_DELETION_DATE]. If the
403 /// [`FILE_ATTRIBUTE_TRASH_DELETION_DATE`][crate::FILE_ATTRIBUTE_TRASH_DELETION_DATE] attribute is unset, [`None`] is returned.
404 ///
405 /// # Returns
406 ///
407 /// a #GDateTime, or [`None`].
408 #[doc(alias = "g_file_info_get_deletion_date")]
409 #[doc(alias = "get_deletion_date")]
410 pub fn deletion_date(&self) -> Option<glib::DateTime> {
411 unsafe { from_glib_full(ffi::g_file_info_get_deletion_date(self.to_glib_none().0)) }
412 }
413
414 /// Gets a display name for a file. This is guaranteed to always be set.
415 ///
416 /// It is an error to call this if the #GFileInfo does not contain
417 /// [`FILE_ATTRIBUTE_STANDARD_DISPLAY_NAME`][crate::FILE_ATTRIBUTE_STANDARD_DISPLAY_NAME].
418 ///
419 /// # Returns
420 ///
421 /// a string containing the display name.
422 #[doc(alias = "g_file_info_get_display_name")]
423 #[doc(alias = "get_display_name")]
424 pub fn display_name(&self) -> glib::GString {
425 unsafe { from_glib_none(ffi::g_file_info_get_display_name(self.to_glib_none().0)) }
426 }
427
428 /// Gets the edit name for a file.
429 ///
430 /// It is an error to call this if the #GFileInfo does not contain
431 /// [`FILE_ATTRIBUTE_STANDARD_EDIT_NAME`][crate::FILE_ATTRIBUTE_STANDARD_EDIT_NAME].
432 ///
433 /// # Returns
434 ///
435 /// a string containing the edit name.
436 #[doc(alias = "g_file_info_get_edit_name")]
437 #[doc(alias = "get_edit_name")]
438 pub fn edit_name(&self) -> glib::GString {
439 unsafe { from_glib_none(ffi::g_file_info_get_edit_name(self.to_glib_none().0)) }
440 }
441
442 /// Gets the [entity tag][`File`][crate::File]#entity-tags] for a given
443 /// #GFileInfo. See [`FILE_ATTRIBUTE_ETAG_VALUE`][crate::FILE_ATTRIBUTE_ETAG_VALUE].
444 ///
445 /// It is an error to call this if the #GFileInfo does not contain
446 /// [`FILE_ATTRIBUTE_ETAG_VALUE`][crate::FILE_ATTRIBUTE_ETAG_VALUE].
447 ///
448 /// # Returns
449 ///
450 /// a string containing the value of the "etag:value" attribute.
451 #[doc(alias = "g_file_info_get_etag")]
452 #[doc(alias = "get_etag")]
453 pub fn etag(&self) -> Option<glib::GString> {
454 unsafe { from_glib_none(ffi::g_file_info_get_etag(self.to_glib_none().0)) }
455 }
456
457 /// Gets a file's type (whether it is a regular file, symlink, etc).
458 /// This is different from the file's content type, see g_file_info_get_content_type().
459 ///
460 /// It is an error to call this if the #GFileInfo does not contain
461 /// [`FILE_ATTRIBUTE_STANDARD_TYPE`][crate::FILE_ATTRIBUTE_STANDARD_TYPE].
462 ///
463 /// # Returns
464 ///
465 /// a #GFileType for the given file.
466 #[doc(alias = "g_file_info_get_file_type")]
467 #[doc(alias = "get_file_type")]
468 pub fn file_type(&self) -> FileType {
469 unsafe { from_glib(ffi::g_file_info_get_file_type(self.to_glib_none().0)) }
470 }
471
472 /// Gets the icon for a file.
473 ///
474 /// It is an error to call this if the #GFileInfo does not contain
475 /// [`FILE_ATTRIBUTE_STANDARD_ICON`][crate::FILE_ATTRIBUTE_STANDARD_ICON].
476 ///
477 /// # Returns
478 ///
479 /// #GIcon for the given @self.
480 #[doc(alias = "g_file_info_get_icon")]
481 #[doc(alias = "get_icon")]
482 pub fn icon(&self) -> Option<Icon> {
483 unsafe { from_glib_none(ffi::g_file_info_get_icon(self.to_glib_none().0)) }
484 }
485
486 /// Checks if a file is a backup file.
487 ///
488 /// It is an error to call this if the #GFileInfo does not contain
489 /// [`FILE_ATTRIBUTE_STANDARD_IS_BACKUP`][crate::FILE_ATTRIBUTE_STANDARD_IS_BACKUP].
490 ///
491 /// # Returns
492 ///
493 /// [`true`] if file is a backup file, [`false`] otherwise.
494 #[doc(alias = "g_file_info_get_is_backup")]
495 #[doc(alias = "get_is_backup")]
496 pub fn is_backup(&self) -> bool {
497 unsafe { from_glib(ffi::g_file_info_get_is_backup(self.to_glib_none().0)) }
498 }
499
500 /// Checks if a file is hidden.
501 ///
502 /// It is an error to call this if the #GFileInfo does not contain
503 /// [`FILE_ATTRIBUTE_STANDARD_IS_HIDDEN`][crate::FILE_ATTRIBUTE_STANDARD_IS_HIDDEN].
504 ///
505 /// # Returns
506 ///
507 /// [`true`] if the file is a hidden file, [`false`] otherwise.
508 #[doc(alias = "g_file_info_get_is_hidden")]
509 #[doc(alias = "get_is_hidden")]
510 pub fn is_hidden(&self) -> bool {
511 unsafe { from_glib(ffi::g_file_info_get_is_hidden(self.to_glib_none().0)) }
512 }
513
514 /// Checks if a file is a symlink.
515 ///
516 /// It is an error to call this if the #GFileInfo does not contain
517 /// [`FILE_ATTRIBUTE_STANDARD_IS_SYMLINK`][crate::FILE_ATTRIBUTE_STANDARD_IS_SYMLINK].
518 ///
519 /// # Returns
520 ///
521 /// [`true`] if the given @self is a symlink.
522 #[doc(alias = "g_file_info_get_is_symlink")]
523 #[doc(alias = "get_is_symlink")]
524 pub fn is_symlink(&self) -> bool {
525 unsafe { from_glib(ffi::g_file_info_get_is_symlink(self.to_glib_none().0)) }
526 }
527
528 /// Gets the modification time of the current @self and returns it as a
529 /// #GDateTime.
530 ///
531 /// It is an error to call this if the #GFileInfo does not contain
532 /// [`FILE_ATTRIBUTE_TIME_MODIFIED`][crate::FILE_ATTRIBUTE_TIME_MODIFIED]. If [`FILE_ATTRIBUTE_TIME_MODIFIED_USEC`][crate::FILE_ATTRIBUTE_TIME_MODIFIED_USEC] is
533 /// provided, the resulting #GDateTime will additionally have microsecond
534 /// precision.
535 ///
536 /// If nanosecond precision is needed, [`FILE_ATTRIBUTE_TIME_MODIFIED_NSEC`][crate::FILE_ATTRIBUTE_TIME_MODIFIED_NSEC] must
537 /// be queried separately using g_file_info_get_attribute_uint32().
538 ///
539 /// # Returns
540 ///
541 /// modification time, or [`None`] if unknown
542 #[cfg(feature = "v2_62")]
543 #[cfg_attr(docsrs, doc(cfg(feature = "v2_62")))]
544 #[doc(alias = "g_file_info_get_modification_date_time")]
545 #[doc(alias = "get_modification_date_time")]
546 pub fn modification_date_time(&self) -> Option<glib::DateTime> {
547 unsafe {
548 from_glib_full(ffi::g_file_info_get_modification_date_time(
549 self.to_glib_none().0,
550 ))
551 }
552 }
553
554 /// Gets the name for a file. This is guaranteed to always be set.
555 ///
556 /// It is an error to call this if the #GFileInfo does not contain
557 /// [`FILE_ATTRIBUTE_STANDARD_NAME`][crate::FILE_ATTRIBUTE_STANDARD_NAME].
558 ///
559 /// # Returns
560 ///
561 /// a string containing the file name.
562 #[doc(alias = "g_file_info_get_name")]
563 #[doc(alias = "get_name")]
564 pub fn name(&self) -> std::path::PathBuf {
565 unsafe { from_glib_none(ffi::g_file_info_get_name(self.to_glib_none().0)) }
566 }
567
568 /// Gets the file's size (in bytes). The size is retrieved through the value of
569 /// the [`FILE_ATTRIBUTE_STANDARD_SIZE`][crate::FILE_ATTRIBUTE_STANDARD_SIZE] attribute and is converted
570 /// from #guint64 to #goffset before returning the result.
571 ///
572 /// It is an error to call this if the #GFileInfo does not contain
573 /// [`FILE_ATTRIBUTE_STANDARD_SIZE`][crate::FILE_ATTRIBUTE_STANDARD_SIZE].
574 ///
575 /// # Returns
576 ///
577 /// a #goffset containing the file's size (in bytes).
578 #[doc(alias = "g_file_info_get_size")]
579 #[doc(alias = "get_size")]
580 pub fn size(&self) -> i64 {
581 unsafe { ffi::g_file_info_get_size(self.to_glib_none().0) }
582 }
583
584 /// Gets the value of the sort_order attribute from the #GFileInfo.
585 /// See [`FILE_ATTRIBUTE_STANDARD_SORT_ORDER`][crate::FILE_ATTRIBUTE_STANDARD_SORT_ORDER].
586 ///
587 /// It is an error to call this if the #GFileInfo does not contain
588 /// [`FILE_ATTRIBUTE_STANDARD_SORT_ORDER`][crate::FILE_ATTRIBUTE_STANDARD_SORT_ORDER].
589 ///
590 /// # Returns
591 ///
592 /// a #gint32 containing the value of the "standard::sort_order" attribute.
593 #[doc(alias = "g_file_info_get_sort_order")]
594 #[doc(alias = "get_sort_order")]
595 pub fn sort_order(&self) -> i32 {
596 unsafe { ffi::g_file_info_get_sort_order(self.to_glib_none().0) }
597 }
598
599 /// Gets the symbolic icon for a file.
600 ///
601 /// It is an error to call this if the #GFileInfo does not contain
602 /// [`FILE_ATTRIBUTE_STANDARD_SYMBOLIC_ICON`][crate::FILE_ATTRIBUTE_STANDARD_SYMBOLIC_ICON].
603 ///
604 /// # Returns
605 ///
606 /// #GIcon for the given @self.
607 #[doc(alias = "g_file_info_get_symbolic_icon")]
608 #[doc(alias = "get_symbolic_icon")]
609 pub fn symbolic_icon(&self) -> Option<Icon> {
610 unsafe { from_glib_none(ffi::g_file_info_get_symbolic_icon(self.to_glib_none().0)) }
611 }
612
613 /// Gets the symlink target for a given #GFileInfo.
614 ///
615 /// It is an error to call this if the #GFileInfo does not contain
616 /// [`FILE_ATTRIBUTE_STANDARD_SYMLINK_TARGET`][crate::FILE_ATTRIBUTE_STANDARD_SYMLINK_TARGET].
617 ///
618 /// # Returns
619 ///
620 /// a string containing the symlink target.
621 #[doc(alias = "g_file_info_get_symlink_target")]
622 #[doc(alias = "get_symlink_target")]
623 pub fn symlink_target(&self) -> Option<std::path::PathBuf> {
624 unsafe { from_glib_none(ffi::g_file_info_get_symlink_target(self.to_glib_none().0)) }
625 }
626
627 /// Checks if a file info structure has an attribute named @attribute.
628 /// ## `attribute`
629 /// a file attribute key.
630 ///
631 /// # Returns
632 ///
633 /// [`true`] if @self has an attribute named @attribute,
634 /// [`false`] otherwise.
635 #[doc(alias = "g_file_info_has_attribute")]
636 pub fn has_attribute(&self, attribute: &str) -> bool {
637 unsafe {
638 from_glib(ffi::g_file_info_has_attribute(
639 self.to_glib_none().0,
640 attribute.to_glib_none().0,
641 ))
642 }
643 }
644
645 /// Checks if a file info structure has an attribute in the
646 /// specified @name_space.
647 /// ## `name_space`
648 /// a file attribute namespace.
649 ///
650 /// # Returns
651 ///
652 /// [`true`] if @self has an attribute in @name_space,
653 /// [`false`] otherwise.
654 #[doc(alias = "g_file_info_has_namespace")]
655 pub fn has_namespace(&self, name_space: &str) -> bool {
656 unsafe {
657 from_glib(ffi::g_file_info_has_namespace(
658 self.to_glib_none().0,
659 name_space.to_glib_none().0,
660 ))
661 }
662 }
663
664 /// Lists the file info structure's attributes.
665 /// ## `name_space`
666 /// a file attribute key's namespace, or [`None`] to list
667 /// all attributes.
668 ///
669 /// # Returns
670 ///
671 /// a
672 /// null-terminated array of strings of all of the possible attribute
673 /// types for the given @name_space, or [`None`] on error.
674 #[doc(alias = "g_file_info_list_attributes")]
675 pub fn list_attributes(&self, name_space: Option<&str>) -> Vec<glib::GString> {
676 unsafe {
677 FromGlibPtrContainer::from_glib_full(ffi::g_file_info_list_attributes(
678 self.to_glib_none().0,
679 name_space.to_glib_none().0,
680 ))
681 }
682 }
683
684 /// Removes all cases of @attribute from @self if it exists.
685 /// ## `attribute`
686 /// a file attribute key.
687 #[doc(alias = "g_file_info_remove_attribute")]
688 pub fn remove_attribute(&self, attribute: &str) {
689 unsafe {
690 ffi::g_file_info_remove_attribute(self.to_glib_none().0, attribute.to_glib_none().0);
691 }
692 }
693
694 /// Sets the [`FILE_ATTRIBUTE_TIME_ACCESS`][crate::FILE_ATTRIBUTE_TIME_ACCESS] and
695 /// [`FILE_ATTRIBUTE_TIME_ACCESS_USEC`][crate::FILE_ATTRIBUTE_TIME_ACCESS_USEC] attributes in the file info to the
696 /// given date/time value.
697 ///
698 /// [`FILE_ATTRIBUTE_TIME_ACCESS_NSEC`][crate::FILE_ATTRIBUTE_TIME_ACCESS_NSEC] will be cleared.
699 /// ## `atime`
700 /// a #GDateTime.
701 #[cfg(feature = "v2_70")]
702 #[cfg_attr(docsrs, doc(cfg(feature = "v2_70")))]
703 #[doc(alias = "g_file_info_set_access_date_time")]
704 pub fn set_access_date_time(&self, atime: &glib::DateTime) {
705 unsafe {
706 ffi::g_file_info_set_access_date_time(self.to_glib_none().0, atime.to_glib_none().0);
707 }
708 }
709
710 //#[doc(alias = "g_file_info_set_attribute")]
711 //pub fn set_attribute(&self, attribute: &str, type_: FileAttributeType, value_p: /*Unimplemented*/Basic: Pointer) {
712 // unsafe { TODO: call ffi:g_file_info_set_attribute() }
713 //}
714
715 /// Sets the @attribute to contain the given @attr_value,
716 /// if possible.
717 /// ## `attribute`
718 /// a file attribute key.
719 /// ## `attr_value`
720 /// a boolean value.
721 #[doc(alias = "g_file_info_set_attribute_boolean")]
722 pub fn set_attribute_boolean(&self, attribute: &str, attr_value: bool) {
723 unsafe {
724 ffi::g_file_info_set_attribute_boolean(
725 self.to_glib_none().0,
726 attribute.to_glib_none().0,
727 attr_value.into_glib(),
728 );
729 }
730 }
731
732 /// Sets the @attribute to contain the given @attr_value,
733 /// if possible.
734 /// ## `attribute`
735 /// a file attribute key.
736 /// ## `attr_value`
737 /// a byte string.
738 #[doc(alias = "g_file_info_set_attribute_byte_string")]
739 pub fn set_attribute_byte_string(&self, attribute: &str, attr_value: &str) {
740 unsafe {
741 ffi::g_file_info_set_attribute_byte_string(
742 self.to_glib_none().0,
743 attribute.to_glib_none().0,
744 attr_value.to_glib_none().0,
745 );
746 }
747 }
748
749 /// Sets the @attribute to contain the given @attr_value,
750 /// if possible.
751 ///
752 /// This function is meant to be used by language bindings that have specific
753 /// handling for Unix paths.
754 /// ## `attribute`
755 /// a file attribute key.
756 /// ## `attr_value`
757 /// a file path.
758 #[cfg(feature = "v2_78")]
759 #[cfg_attr(docsrs, doc(cfg(feature = "v2_78")))]
760 #[doc(alias = "g_file_info_set_attribute_file_path")]
761 pub fn set_attribute_file_path(
762 &self,
763 attribute: &str,
764 attr_value: impl AsRef<std::path::Path>,
765 ) {
766 unsafe {
767 ffi::g_file_info_set_attribute_file_path(
768 self.to_glib_none().0,
769 attribute.to_glib_none().0,
770 attr_value.as_ref().to_glib_none().0,
771 );
772 }
773 }
774
775 /// Sets the @attribute to contain the given @attr_value,
776 /// if possible.
777 /// ## `attribute`
778 /// a file attribute key.
779 /// ## `attr_value`
780 /// a signed 32-bit integer
781 #[doc(alias = "g_file_info_set_attribute_int32")]
782 pub fn set_attribute_int32(&self, attribute: &str, attr_value: i32) {
783 unsafe {
784 ffi::g_file_info_set_attribute_int32(
785 self.to_glib_none().0,
786 attribute.to_glib_none().0,
787 attr_value,
788 );
789 }
790 }
791
792 /// Sets the @attribute to contain the given @attr_value,
793 /// if possible.
794 /// ## `attribute`
795 /// attribute name to set.
796 /// ## `attr_value`
797 /// int64 value to set attribute to.
798 #[doc(alias = "g_file_info_set_attribute_int64")]
799 pub fn set_attribute_int64(&self, attribute: &str, attr_value: i64) {
800 unsafe {
801 ffi::g_file_info_set_attribute_int64(
802 self.to_glib_none().0,
803 attribute.to_glib_none().0,
804 attr_value,
805 );
806 }
807 }
808
809 /// Sets @mask on @self to match specific attribute types.
810 /// ## `mask`
811 /// a #GFileAttributeMatcher.
812 #[doc(alias = "g_file_info_set_attribute_mask")]
813 pub fn set_attribute_mask(&self, mask: &FileAttributeMatcher) {
814 unsafe {
815 ffi::g_file_info_set_attribute_mask(self.to_glib_none().0, mask.to_glib_none().0);
816 }
817 }
818
819 /// Sets the @attribute to contain the given @attr_value,
820 /// if possible.
821 /// ## `attribute`
822 /// a file attribute key.
823 /// ## `attr_value`
824 /// a #GObject.
825 #[doc(alias = "g_file_info_set_attribute_object")]
826 pub fn set_attribute_object(&self, attribute: &str, attr_value: &impl IsA<glib::Object>) {
827 unsafe {
828 ffi::g_file_info_set_attribute_object(
829 self.to_glib_none().0,
830 attribute.to_glib_none().0,
831 attr_value.as_ref().to_glib_none().0,
832 );
833 }
834 }
835
836 /// Sets the attribute status for an attribute key. This is only
837 /// needed by external code that implement g_file_set_attributes_from_info()
838 /// or similar functions.
839 ///
840 /// The attribute must exist in @self for this to work. Otherwise [`false`]
841 /// is returned and @self is unchanged.
842 /// ## `attribute`
843 /// a file attribute key
844 /// ## `status`
845 /// a #GFileAttributeStatus
846 ///
847 /// # Returns
848 ///
849 /// [`true`] if the status was changed, [`false`] if the key was not set.
850 #[doc(alias = "g_file_info_set_attribute_status")]
851 pub fn set_attribute_status(&self, attribute: &str, status: FileAttributeStatus) -> bool {
852 unsafe {
853 from_glib(ffi::g_file_info_set_attribute_status(
854 self.to_glib_none().0,
855 attribute.to_glib_none().0,
856 status.into_glib(),
857 ))
858 }
859 }
860
861 /// Sets the @attribute to contain the given @attr_value,
862 /// if possible.
863 /// ## `attribute`
864 /// a file attribute key.
865 /// ## `attr_value`
866 /// a UTF-8 string.
867 #[doc(alias = "g_file_info_set_attribute_string")]
868 pub fn set_attribute_string(&self, attribute: &str, attr_value: &str) {
869 unsafe {
870 ffi::g_file_info_set_attribute_string(
871 self.to_glib_none().0,
872 attribute.to_glib_none().0,
873 attr_value.to_glib_none().0,
874 );
875 }
876 }
877
878 /// Sets the @attribute to contain the given @attr_value,
879 /// if possible.
880 /// ## `attribute`
881 /// a file attribute key.
882 /// ## `attr_value`
883 /// an unsigned 32-bit integer.
884 #[doc(alias = "g_file_info_set_attribute_uint32")]
885 pub fn set_attribute_uint32(&self, attribute: &str, attr_value: u32) {
886 unsafe {
887 ffi::g_file_info_set_attribute_uint32(
888 self.to_glib_none().0,
889 attribute.to_glib_none().0,
890 attr_value,
891 );
892 }
893 }
894
895 /// Sets the @attribute to contain the given @attr_value,
896 /// if possible.
897 /// ## `attribute`
898 /// a file attribute key.
899 /// ## `attr_value`
900 /// an unsigned 64-bit integer.
901 #[doc(alias = "g_file_info_set_attribute_uint64")]
902 pub fn set_attribute_uint64(&self, attribute: &str, attr_value: u64) {
903 unsafe {
904 ffi::g_file_info_set_attribute_uint64(
905 self.to_glib_none().0,
906 attribute.to_glib_none().0,
907 attr_value,
908 );
909 }
910 }
911
912 /// Sets the content type attribute for a given #GFileInfo.
913 /// See [`FILE_ATTRIBUTE_STANDARD_CONTENT_TYPE`][crate::FILE_ATTRIBUTE_STANDARD_CONTENT_TYPE].
914 /// ## `content_type`
915 /// a [content type](content-types.html#content-types).
916 #[doc(alias = "g_file_info_set_content_type")]
917 pub fn set_content_type(&self, content_type: &str) {
918 unsafe {
919 ffi::g_file_info_set_content_type(self.to_glib_none().0, content_type.to_glib_none().0);
920 }
921 }
922
923 /// Sets the [`FILE_ATTRIBUTE_TIME_CREATED`][crate::FILE_ATTRIBUTE_TIME_CREATED] and
924 /// [`FILE_ATTRIBUTE_TIME_CREATED_USEC`][crate::FILE_ATTRIBUTE_TIME_CREATED_USEC] attributes in the file info to the
925 /// given date/time value.
926 ///
927 /// [`FILE_ATTRIBUTE_TIME_CREATED_NSEC`][crate::FILE_ATTRIBUTE_TIME_CREATED_NSEC] will be cleared.
928 /// ## `creation_time`
929 /// a #GDateTime.
930 #[cfg(feature = "v2_70")]
931 #[cfg_attr(docsrs, doc(cfg(feature = "v2_70")))]
932 #[doc(alias = "g_file_info_set_creation_date_time")]
933 pub fn set_creation_date_time(&self, creation_time: &glib::DateTime) {
934 unsafe {
935 ffi::g_file_info_set_creation_date_time(
936 self.to_glib_none().0,
937 creation_time.to_glib_none().0,
938 );
939 }
940 }
941
942 /// Sets the display name for the current #GFileInfo.
943 /// See [`FILE_ATTRIBUTE_STANDARD_DISPLAY_NAME`][crate::FILE_ATTRIBUTE_STANDARD_DISPLAY_NAME].
944 /// ## `display_name`
945 /// a string containing a display name.
946 #[doc(alias = "g_file_info_set_display_name")]
947 pub fn set_display_name(&self, display_name: &str) {
948 unsafe {
949 ffi::g_file_info_set_display_name(self.to_glib_none().0, display_name.to_glib_none().0);
950 }
951 }
952
953 /// Sets the edit name for the current file.
954 /// See [`FILE_ATTRIBUTE_STANDARD_EDIT_NAME`][crate::FILE_ATTRIBUTE_STANDARD_EDIT_NAME].
955 /// ## `edit_name`
956 /// a string containing an edit name.
957 #[doc(alias = "g_file_info_set_edit_name")]
958 pub fn set_edit_name(&self, edit_name: &str) {
959 unsafe {
960 ffi::g_file_info_set_edit_name(self.to_glib_none().0, edit_name.to_glib_none().0);
961 }
962 }
963
964 /// Sets the file type in a #GFileInfo to @type_.
965 /// See [`FILE_ATTRIBUTE_STANDARD_TYPE`][crate::FILE_ATTRIBUTE_STANDARD_TYPE].
966 /// ## `type_`
967 /// a #GFileType.
968 #[doc(alias = "g_file_info_set_file_type")]
969 pub fn set_file_type(&self, type_: FileType) {
970 unsafe {
971 ffi::g_file_info_set_file_type(self.to_glib_none().0, type_.into_glib());
972 }
973 }
974
975 /// Sets the icon for a given #GFileInfo.
976 /// See [`FILE_ATTRIBUTE_STANDARD_ICON`][crate::FILE_ATTRIBUTE_STANDARD_ICON].
977 /// ## `icon`
978 /// a #GIcon.
979 #[doc(alias = "g_file_info_set_icon")]
980 pub fn set_icon(&self, icon: &impl IsA<Icon>) {
981 unsafe {
982 ffi::g_file_info_set_icon(self.to_glib_none().0, icon.as_ref().to_glib_none().0);
983 }
984 }
985
986 /// Sets the "is_hidden" attribute in a #GFileInfo according to @is_hidden.
987 /// See [`FILE_ATTRIBUTE_STANDARD_IS_HIDDEN`][crate::FILE_ATTRIBUTE_STANDARD_IS_HIDDEN].
988 /// ## `is_hidden`
989 /// a #gboolean.
990 #[doc(alias = "g_file_info_set_is_hidden")]
991 pub fn set_is_hidden(&self, is_hidden: bool) {
992 unsafe {
993 ffi::g_file_info_set_is_hidden(self.to_glib_none().0, is_hidden.into_glib());
994 }
995 }
996
997 /// Sets the "is_symlink" attribute in a #GFileInfo according to @is_symlink.
998 /// See [`FILE_ATTRIBUTE_STANDARD_IS_SYMLINK`][crate::FILE_ATTRIBUTE_STANDARD_IS_SYMLINK].
999 /// ## `is_symlink`
1000 /// a #gboolean.
1001 #[doc(alias = "g_file_info_set_is_symlink")]
1002 pub fn set_is_symlink(&self, is_symlink: bool) {
1003 unsafe {
1004 ffi::g_file_info_set_is_symlink(self.to_glib_none().0, is_symlink.into_glib());
1005 }
1006 }
1007
1008 /// Sets the [`FILE_ATTRIBUTE_TIME_MODIFIED`][crate::FILE_ATTRIBUTE_TIME_MODIFIED] and
1009 /// [`FILE_ATTRIBUTE_TIME_MODIFIED_USEC`][crate::FILE_ATTRIBUTE_TIME_MODIFIED_USEC] attributes in the file info to the
1010 /// given date/time value.
1011 ///
1012 /// [`FILE_ATTRIBUTE_TIME_MODIFIED_NSEC`][crate::FILE_ATTRIBUTE_TIME_MODIFIED_NSEC] will be cleared.
1013 /// ## `mtime`
1014 /// a #GDateTime.
1015 #[cfg(feature = "v2_62")]
1016 #[cfg_attr(docsrs, doc(cfg(feature = "v2_62")))]
1017 #[doc(alias = "g_file_info_set_modification_date_time")]
1018 pub fn set_modification_date_time(&self, mtime: &glib::DateTime) {
1019 unsafe {
1020 ffi::g_file_info_set_modification_date_time(
1021 self.to_glib_none().0,
1022 mtime.to_glib_none().0,
1023 );
1024 }
1025 }
1026
1027 /// Sets the name attribute for the current #GFileInfo.
1028 /// See [`FILE_ATTRIBUTE_STANDARD_NAME`][crate::FILE_ATTRIBUTE_STANDARD_NAME].
1029 /// ## `name`
1030 /// a string containing a name.
1031 #[doc(alias = "g_file_info_set_name")]
1032 pub fn set_name(&self, name: impl AsRef<std::path::Path>) {
1033 unsafe {
1034 ffi::g_file_info_set_name(self.to_glib_none().0, name.as_ref().to_glib_none().0);
1035 }
1036 }
1037
1038 /// Sets the [`FILE_ATTRIBUTE_STANDARD_SIZE`][crate::FILE_ATTRIBUTE_STANDARD_SIZE] attribute in the file info
1039 /// to the given size.
1040 /// ## `size`
1041 /// a #goffset containing the file's size.
1042 #[doc(alias = "g_file_info_set_size")]
1043 pub fn set_size(&self, size: i64) {
1044 unsafe {
1045 ffi::g_file_info_set_size(self.to_glib_none().0, size);
1046 }
1047 }
1048
1049 /// Sets the sort order attribute in the file info structure. See
1050 /// [`FILE_ATTRIBUTE_STANDARD_SORT_ORDER`][crate::FILE_ATTRIBUTE_STANDARD_SORT_ORDER].
1051 /// ## `sort_order`
1052 /// a sort order integer.
1053 #[doc(alias = "g_file_info_set_sort_order")]
1054 pub fn set_sort_order(&self, sort_order: i32) {
1055 unsafe {
1056 ffi::g_file_info_set_sort_order(self.to_glib_none().0, sort_order);
1057 }
1058 }
1059
1060 /// Sets the symbolic icon for a given #GFileInfo.
1061 /// See [`FILE_ATTRIBUTE_STANDARD_SYMBOLIC_ICON`][crate::FILE_ATTRIBUTE_STANDARD_SYMBOLIC_ICON].
1062 /// ## `icon`
1063 /// a #GIcon.
1064 #[doc(alias = "g_file_info_set_symbolic_icon")]
1065 pub fn set_symbolic_icon(&self, icon: &impl IsA<Icon>) {
1066 unsafe {
1067 ffi::g_file_info_set_symbolic_icon(
1068 self.to_glib_none().0,
1069 icon.as_ref().to_glib_none().0,
1070 );
1071 }
1072 }
1073
1074 /// Sets the [`FILE_ATTRIBUTE_STANDARD_SYMLINK_TARGET`][crate::FILE_ATTRIBUTE_STANDARD_SYMLINK_TARGET] attribute in the file info
1075 /// to the given symlink target.
1076 /// ## `symlink_target`
1077 /// a static string containing a path to a symlink target.
1078 #[doc(alias = "g_file_info_set_symlink_target")]
1079 pub fn set_symlink_target(&self, symlink_target: impl AsRef<std::path::Path>) {
1080 unsafe {
1081 ffi::g_file_info_set_symlink_target(
1082 self.to_glib_none().0,
1083 symlink_target.as_ref().to_glib_none().0,
1084 );
1085 }
1086 }
1087
1088 /// Unsets a mask set by g_file_info_set_attribute_mask(), if one
1089 /// is set.
1090 #[doc(alias = "g_file_info_unset_attribute_mask")]
1091 pub fn unset_attribute_mask(&self) {
1092 unsafe {
1093 ffi::g_file_info_unset_attribute_mask(self.to_glib_none().0);
1094 }
1095 }
1096}
1097
1098impl Default for FileInfo {
1099 fn default() -> Self {
1100 Self::new()
1101 }
1102}