1 /* GIO - GLib Input, Output and Streaming Library
3 * Copyright (C) 2006-2007 Red Hat, Inc.
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation; either
8 * version 2 of the License, or (at your option) any later version.
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
15 * You should have received a copy of the GNU Lesser General
16 * Public License along with this library; if not, write to the
17 * Free Software Foundation, Inc., 59 Temple Place, Suite 330,
18 * Boston, MA 02111-1307, USA.
20 * Author: Alexander Larsson <alexl@redhat.com>
25 * @short_description: File Information and Attributes
27 * @see_also: #GFile, <link linkend="gio-GFileAttribute">GFileAttribute</link>
29 * Functionality for manipulating basic metadata for files. #GFileInfo
30 * implements methods for getting information that all files should
31 * contain, and allows for manipulation of extended attributes.
33 * See <link linkend="gio-GFileAttribute">GFileAttribute</link> for more
34 * information on how GIO handles file attributes.
36 * To obtain a #GFileInfo for a #GFile, use g_file_query_info() (or its
37 * async variant). To obtain a #GFileInfo for a file input or output
38 * stream, use g_file_input_stream_query_info() or
39 * g_file_output_stream_query_info() (or their async variants).
41 * To change the actual attributes of a file, you should then set the
42 * attribute in the #GFileInfo and call g_file_set_attributes_from_info()
43 * or g_file_set_attributes_async() on a GFile.
45 * However, not all attributes can be changed in the file. For instance,
46 * the actual size of a file cannot be changed via g_file_info_set_size().
47 * You may call g_file_query_settable_attributes() and
48 * g_file_query_writable_namespaces() to discover the settable attributes
49 * of a particular file at runtime.
51 * #GFileAttributeMatcher allows for searching through a #GFileInfo for
59 #include "gfileinfo.h"
60 #include "gfileinfo-priv.h"
61 #include "gfileattribute-priv.h"
66 /* We use this nasty thing, because NULL is a valid attribute matcher (matches nothing) */
67 #define NO_ATTRIBUTE_MASK ((GFileAttributeMatcher *)1)
71 GFileAttributeValue value
;
76 GObject parent_instance
;
79 GFileAttributeMatcher
*mask
;
82 struct _GFileInfoClass
84 GObjectClass parent_class
;
88 G_DEFINE_TYPE (GFileInfo
, g_file_info
, G_TYPE_OBJECT
);
92 guint32 attribute_id_counter
;
95 G_LOCK_DEFINE_STATIC (attribute_hash
);
96 static int namespace_id_counter
= 0;
97 static GHashTable
*ns_hash
= NULL
;
98 static GHashTable
*attribute_hash
= NULL
;
99 static char ***attributes
= NULL
;
101 /* Attribute ids are 32bit, we split it up like this:
102 * |------------|--------------------|
104 * namespace attribute id
106 * This way the attributes gets sorted in namespace order
110 #define NS_MASK ((guint32)((1<<12) - 1))
112 #define ID_MASK ((guint32)((1<<20) - 1))
114 #define GET_NS(_attr_id) \
115 (((guint32) (_attr_id) >> NS_POS) & NS_MASK)
116 #define GET_ID(_attr_id) \
117 (((guint32)(_attr_id) >> ID_POS) & ID_MASK)
119 #define MAKE_ATTR_ID(_ns, _id) \
120 ( ((((guint32) _ns) & NS_MASK) << NS_POS) | \
121 ((((guint32) _id) & ID_MASK) << ID_POS) )
124 _lookup_namespace (const char *namespace)
128 ns_info
= g_hash_table_lookup (ns_hash
, namespace);
131 ns_info
= g_new0 (NSInfo
, 1);
132 ns_info
->id
= ++namespace_id_counter
;
133 g_hash_table_insert (ns_hash
, g_strdup (namespace), ns_info
);
134 attributes
= g_realloc (attributes
, (ns_info
->id
+ 1) * sizeof (char **));
135 attributes
[ns_info
->id
] = g_new (char *, 1);
136 attributes
[ns_info
->id
][0] = g_strconcat (namespace, "::*", NULL
);
142 _lookup_attribute (const char *attribute
)
149 attr_id
= GPOINTER_TO_UINT (g_hash_table_lookup (attribute_hash
, attribute
));
154 colon
= strstr (attribute
, "::");
156 ns
= g_strndup (attribute
, colon
- attribute
);
160 ns_info
= _lookup_namespace (ns
);
163 id
= ++ns_info
->attribute_id_counter
;
164 attributes
[ns_info
->id
] = g_realloc (attributes
[ns_info
->id
], (id
+ 1) * sizeof (char *));
165 attributes
[ns_info
->id
][id
] = g_strdup (attribute
);
167 attr_id
= MAKE_ATTR_ID (ns_info
->id
, id
);
169 g_hash_table_insert (attribute_hash
, attributes
[ns_info
->id
][id
], GUINT_TO_POINTER (attr_id
));
175 ensure_attribute_hash (void)
177 if (attribute_hash
!= NULL
)
180 ns_hash
= g_hash_table_new (g_str_hash
, g_str_equal
);
181 attribute_hash
= g_hash_table_new (g_str_hash
, g_str_equal
);
183 #define REGISTER_ATTRIBUTE(name) G_STMT_START{\
184 guint _u = _lookup_attribute (G_FILE_ATTRIBUTE_ ## name); \
185 /* use for generating the ID: g_print ("#define G_FILE_ATTRIBUTE_ID_%s (%u + %u)\n", #name + 17, _u & ~ID_MASK, _u & ID_MASK); */ \
186 g_assert (_u == G_FILE_ATTRIBUTE_ID_ ## name); \
189 REGISTER_ATTRIBUTE (STANDARD_TYPE
);
190 REGISTER_ATTRIBUTE (STANDARD_IS_HIDDEN
);
191 REGISTER_ATTRIBUTE (STANDARD_IS_BACKUP
);
192 REGISTER_ATTRIBUTE (STANDARD_IS_SYMLINK
);
193 REGISTER_ATTRIBUTE (STANDARD_IS_VIRTUAL
);
194 REGISTER_ATTRIBUTE (STANDARD_NAME
);
195 REGISTER_ATTRIBUTE (STANDARD_DISPLAY_NAME
);
196 REGISTER_ATTRIBUTE (STANDARD_EDIT_NAME
);
197 REGISTER_ATTRIBUTE (STANDARD_COPY_NAME
);
198 REGISTER_ATTRIBUTE (STANDARD_DESCRIPTION
);
199 REGISTER_ATTRIBUTE (STANDARD_ICON
);
200 REGISTER_ATTRIBUTE (STANDARD_CONTENT_TYPE
);
201 REGISTER_ATTRIBUTE (STANDARD_FAST_CONTENT_TYPE
);
202 REGISTER_ATTRIBUTE (STANDARD_SIZE
);
203 REGISTER_ATTRIBUTE (STANDARD_ALLOCATED_SIZE
);
204 REGISTER_ATTRIBUTE (STANDARD_SYMLINK_TARGET
);
205 REGISTER_ATTRIBUTE (STANDARD_TARGET_URI
);
206 REGISTER_ATTRIBUTE (STANDARD_SORT_ORDER
);
207 REGISTER_ATTRIBUTE (STANDARD_SYMBOLIC_ICON
);
208 REGISTER_ATTRIBUTE (ETAG_VALUE
);
209 REGISTER_ATTRIBUTE (ID_FILE
);
210 REGISTER_ATTRIBUTE (ID_FILESYSTEM
);
211 REGISTER_ATTRIBUTE (ACCESS_CAN_READ
);
212 REGISTER_ATTRIBUTE (ACCESS_CAN_WRITE
);
213 REGISTER_ATTRIBUTE (ACCESS_CAN_EXECUTE
);
214 REGISTER_ATTRIBUTE (ACCESS_CAN_DELETE
);
215 REGISTER_ATTRIBUTE (ACCESS_CAN_TRASH
);
216 REGISTER_ATTRIBUTE (ACCESS_CAN_RENAME
);
217 REGISTER_ATTRIBUTE (MOUNTABLE_CAN_MOUNT
);
218 REGISTER_ATTRIBUTE (MOUNTABLE_CAN_UNMOUNT
);
219 REGISTER_ATTRIBUTE (MOUNTABLE_CAN_EJECT
);
220 REGISTER_ATTRIBUTE (MOUNTABLE_UNIX_DEVICE
);
221 REGISTER_ATTRIBUTE (MOUNTABLE_UNIX_DEVICE_FILE
);
222 REGISTER_ATTRIBUTE (MOUNTABLE_HAL_UDI
);
223 REGISTER_ATTRIBUTE (MOUNTABLE_CAN_START
);
224 REGISTER_ATTRIBUTE (MOUNTABLE_CAN_START_DEGRADED
);
225 REGISTER_ATTRIBUTE (MOUNTABLE_CAN_STOP
);
226 REGISTER_ATTRIBUTE (MOUNTABLE_START_STOP_TYPE
);
227 REGISTER_ATTRIBUTE (MOUNTABLE_CAN_POLL
);
228 REGISTER_ATTRIBUTE (MOUNTABLE_IS_MEDIA_CHECK_AUTOMATIC
);
229 REGISTER_ATTRIBUTE (TIME_MODIFIED
);
230 REGISTER_ATTRIBUTE (TIME_MODIFIED_USEC
);
231 REGISTER_ATTRIBUTE (TIME_ACCESS
);
232 REGISTER_ATTRIBUTE (TIME_ACCESS_USEC
);
233 REGISTER_ATTRIBUTE (TIME_CHANGED
);
234 REGISTER_ATTRIBUTE (TIME_CHANGED_USEC
);
235 REGISTER_ATTRIBUTE (TIME_CREATED
);
236 REGISTER_ATTRIBUTE (TIME_CREATED_USEC
);
237 REGISTER_ATTRIBUTE (UNIX_DEVICE
);
238 REGISTER_ATTRIBUTE (UNIX_INODE
);
239 REGISTER_ATTRIBUTE (UNIX_MODE
);
240 REGISTER_ATTRIBUTE (UNIX_NLINK
);
241 REGISTER_ATTRIBUTE (UNIX_UID
);
242 REGISTER_ATTRIBUTE (UNIX_GID
);
243 REGISTER_ATTRIBUTE (UNIX_RDEV
);
244 REGISTER_ATTRIBUTE (UNIX_BLOCK_SIZE
);
245 REGISTER_ATTRIBUTE (UNIX_BLOCKS
);
246 REGISTER_ATTRIBUTE (UNIX_IS_MOUNTPOINT
);
247 REGISTER_ATTRIBUTE (DOS_IS_ARCHIVE
);
248 REGISTER_ATTRIBUTE (DOS_IS_SYSTEM
);
249 REGISTER_ATTRIBUTE (OWNER_USER
);
250 REGISTER_ATTRIBUTE (OWNER_USER_REAL
);
251 REGISTER_ATTRIBUTE (OWNER_GROUP
);
252 REGISTER_ATTRIBUTE (THUMBNAIL_PATH
);
253 REGISTER_ATTRIBUTE (THUMBNAILING_FAILED
);
254 REGISTER_ATTRIBUTE (PREVIEW_ICON
);
255 REGISTER_ATTRIBUTE (FILESYSTEM_SIZE
);
256 REGISTER_ATTRIBUTE (FILESYSTEM_FREE
);
257 REGISTER_ATTRIBUTE (FILESYSTEM_TYPE
);
258 REGISTER_ATTRIBUTE (FILESYSTEM_READONLY
);
259 REGISTER_ATTRIBUTE (FILESYSTEM_USE_PREVIEW
);
260 REGISTER_ATTRIBUTE (GVFS_BACKEND
);
261 REGISTER_ATTRIBUTE (SELINUX_CONTEXT
);
262 REGISTER_ATTRIBUTE (TRASH_ITEM_COUNT
);
263 REGISTER_ATTRIBUTE (TRASH_ORIG_PATH
);
264 REGISTER_ATTRIBUTE (TRASH_DELETION_DATE
);
266 #undef REGISTER_ATTRIBUTE
270 lookup_namespace (const char *namespace)
275 G_LOCK (attribute_hash
);
277 ensure_attribute_hash ();
279 ns_info
= _lookup_namespace (namespace);
284 G_UNLOCK (attribute_hash
);
290 get_attribute_for_id (int attribute
)
293 G_LOCK (attribute_hash
);
294 s
= attributes
[GET_NS(attribute
)][GET_ID(attribute
)];
295 G_UNLOCK (attribute_hash
);
300 lookup_attribute (const char *attribute
)
304 G_LOCK (attribute_hash
);
305 ensure_attribute_hash ();
307 attr_id
= _lookup_attribute (attribute
);
309 G_UNLOCK (attribute_hash
);
315 g_file_info_finalize (GObject
*object
)
319 GFileAttribute
*attrs
;
321 info
= G_FILE_INFO (object
);
323 attrs
= (GFileAttribute
*)info
->attributes
->data
;
324 for (i
= 0; i
< info
->attributes
->len
; i
++)
325 _g_file_attribute_value_clear (&attrs
[i
].value
);
326 g_array_free (info
->attributes
, TRUE
);
328 if (info
->mask
!= NO_ATTRIBUTE_MASK
)
329 g_file_attribute_matcher_unref (info
->mask
);
331 G_OBJECT_CLASS (g_file_info_parent_class
)->finalize (object
);
335 g_file_info_class_init (GFileInfoClass
*klass
)
337 GObjectClass
*gobject_class
= G_OBJECT_CLASS (klass
);
339 gobject_class
->finalize
= g_file_info_finalize
;
343 g_file_info_init (GFileInfo
*info
)
345 info
->mask
= NO_ATTRIBUTE_MASK
;
346 info
->attributes
= g_array_new (FALSE
, FALSE
,
347 sizeof (GFileAttribute
));
353 * Creates a new file info structure.
355 * Returns: a #GFileInfo.
358 g_file_info_new (void)
360 return g_object_new (G_TYPE_FILE_INFO
, NULL
);
364 * g_file_info_copy_into:
365 * @src_info: source to copy attributes from.
366 * @dest_info: destination to copy attributes to.
368 * Copies all of the <link linkend="gio-GFileAttribute">GFileAttribute</link>s
369 * from @src_info to @dest_info.
372 g_file_info_copy_into (GFileInfo
*src_info
,
373 GFileInfo
*dest_info
)
375 GFileAttribute
*source
, *dest
;
378 g_return_if_fail (G_IS_FILE_INFO (src_info
));
379 g_return_if_fail (G_IS_FILE_INFO (dest_info
));
381 dest
= (GFileAttribute
*)dest_info
->attributes
->data
;
382 for (i
= 0; i
< dest_info
->attributes
->len
; i
++)
383 _g_file_attribute_value_clear (&dest
[i
].value
);
385 g_array_set_size (dest_info
->attributes
,
386 src_info
->attributes
->len
);
388 source
= (GFileAttribute
*)src_info
->attributes
->data
;
389 dest
= (GFileAttribute
*)dest_info
->attributes
->data
;
391 for (i
= 0; i
< src_info
->attributes
->len
; i
++)
393 dest
[i
].attribute
= source
[i
].attribute
;
394 dest
[i
].value
.type
= G_FILE_ATTRIBUTE_TYPE_INVALID
;
395 _g_file_attribute_value_set (&dest
[i
].value
, &source
[i
].value
);
398 if (dest_info
->mask
!= NO_ATTRIBUTE_MASK
)
399 g_file_attribute_matcher_unref (dest_info
->mask
);
401 if (src_info
->mask
== NO_ATTRIBUTE_MASK
)
402 dest_info
->mask
= NO_ATTRIBUTE_MASK
;
404 dest_info
->mask
= g_file_attribute_matcher_ref (src_info
->mask
);
409 * @other: a #GFileInfo.
411 * Duplicates a file info structure.
413 * Returns: (transfer full): a duplicate #GFileInfo of @other.
416 g_file_info_dup (GFileInfo
*other
)
420 g_return_val_if_fail (G_IS_FILE_INFO (other
), NULL
);
422 new = g_file_info_new ();
423 g_file_info_copy_into (other
, new);
428 * g_file_info_set_attribute_mask:
429 * @info: a #GFileInfo.
430 * @mask: a #GFileAttributeMatcher.
432 * Sets @mask on @info to match specific attribute types.
435 g_file_info_set_attribute_mask (GFileInfo
*info
,
436 GFileAttributeMatcher
*mask
)
438 GFileAttribute
*attr
;
441 g_return_if_fail (G_IS_FILE_INFO (info
));
443 if (mask
!= info
->mask
)
445 if (info
->mask
!= NO_ATTRIBUTE_MASK
)
446 g_file_attribute_matcher_unref (info
->mask
);
447 info
->mask
= g_file_attribute_matcher_ref (mask
);
449 /* Remove non-matching attributes */
450 for (i
= 0; i
< info
->attributes
->len
; i
++)
452 attr
= &g_array_index (info
->attributes
, GFileAttribute
, i
);
453 if (!_g_file_attribute_matcher_matches_id (mask
,
456 _g_file_attribute_value_clear (&attr
->value
);
457 g_array_remove_index (info
->attributes
, i
);
465 * g_file_info_unset_attribute_mask:
468 * Unsets a mask set by g_file_info_set_attribute_mask(), if one
472 g_file_info_unset_attribute_mask (GFileInfo
*info
)
474 g_return_if_fail (G_IS_FILE_INFO (info
));
476 if (info
->mask
!= NO_ATTRIBUTE_MASK
)
477 g_file_attribute_matcher_unref (info
->mask
);
478 info
->mask
= NO_ATTRIBUTE_MASK
;
482 * g_file_info_clear_status:
483 * @info: a #GFileInfo.
485 * Clears the status information from @info.
488 g_file_info_clear_status (GFileInfo
*info
)
490 GFileAttribute
*attrs
;
493 g_return_if_fail (G_IS_FILE_INFO (info
));
495 attrs
= (GFileAttribute
*)info
->attributes
->data
;
496 for (i
= 0; i
< info
->attributes
->len
; i
++)
497 attrs
[i
].value
.status
= G_FILE_ATTRIBUTE_STATUS_UNSET
;
501 g_file_info_find_place (GFileInfo
*info
,
505 GFileAttribute
*attrs
;
506 /* Binary search for the place where attribute would be, if it's
510 max
= info
->attributes
->len
;
512 attrs
= (GFileAttribute
*)info
->attributes
->data
;
516 med
= min
+ (max
- min
) / 2;
517 if (attrs
[med
].attribute
== attribute
)
522 else if (attrs
[med
].attribute
< attribute
)
524 else /* attrs[med].attribute > attribute */
531 static GFileAttributeValue
*
532 g_file_info_find_value (GFileInfo
*info
,
535 GFileAttribute
*attrs
;
538 i
= g_file_info_find_place (info
, attr_id
);
539 attrs
= (GFileAttribute
*)info
->attributes
->data
;
540 if (i
< info
->attributes
->len
&&
541 attrs
[i
].attribute
== attr_id
)
542 return &attrs
[i
].value
;
547 static GFileAttributeValue
*
548 g_file_info_find_value_by_name (GFileInfo
*info
,
549 const char *attribute
)
553 attr_id
= lookup_attribute (attribute
);
554 return g_file_info_find_value (info
, attr_id
);
558 * g_file_info_has_attribute:
559 * @info: a #GFileInfo.
560 * @attribute: a file attribute key.
562 * Checks if a file info structure has an attribute named @attribute.
564 * Returns: %TRUE if @Ginfo has an attribute named @attribute,
568 g_file_info_has_attribute (GFileInfo
*info
,
569 const char *attribute
)
571 GFileAttributeValue
*value
;
573 g_return_val_if_fail (G_IS_FILE_INFO (info
), FALSE
);
574 g_return_val_if_fail (attribute
!= NULL
&& *attribute
!= '\0', FALSE
);
576 value
= g_file_info_find_value_by_name (info
, attribute
);
577 return value
!= NULL
;
581 * g_file_info_has_namespace:
582 * @info: a #GFileInfo.
583 * @name_space: a file attribute namespace.
585 * Checks if a file info structure has an attribute in the
586 * specified @name_space.
588 * Returns: %TRUE if @Ginfo has an attribute in @name_space,
594 g_file_info_has_namespace (GFileInfo
*info
,
595 const char *name_space
)
597 GFileAttribute
*attrs
;
601 g_return_val_if_fail (G_IS_FILE_INFO (info
), FALSE
);
602 g_return_val_if_fail (name_space
!= NULL
, FALSE
);
604 ns_id
= lookup_namespace (name_space
);
606 attrs
= (GFileAttribute
*)info
->attributes
->data
;
607 for (i
= 0; i
< info
->attributes
->len
; i
++)
609 if (GET_NS (attrs
[i
].attribute
) == ns_id
)
617 * g_file_info_list_attributes:
618 * @info: a #GFileInfo.
619 * @name_space: a file attribute key's namespace.
621 * Lists the file info structure's attributes.
623 * Returns: (array zero-terminated=1) (transfer full): a null-terminated array of strings of all of the
624 * possible attribute types for the given @name_space, or
628 g_file_info_list_attributes (GFileInfo
*info
,
629 const char *name_space
)
632 GFileAttribute
*attrs
;
634 guint32 ns_id
= (name_space
) ? lookup_namespace (name_space
) : 0;
637 g_return_val_if_fail (G_IS_FILE_INFO (info
), NULL
);
639 names
= g_ptr_array_new ();
640 attrs
= (GFileAttribute
*)info
->attributes
->data
;
641 for (i
= 0; i
< info
->attributes
->len
; i
++)
643 attribute
= attrs
[i
].attribute
;
644 if (ns_id
== 0 || GET_NS (attribute
) == ns_id
)
645 g_ptr_array_add (names
, g_strdup (get_attribute_for_id (attribute
)));
649 g_ptr_array_add (names
, NULL
);
651 return (char **)g_ptr_array_free (names
, FALSE
);
655 * g_file_info_get_attribute_type:
656 * @info: a #GFileInfo.
657 * @attribute: a file attribute key.
659 * Gets the attribute type for an attribute key.
661 * Returns: a #GFileAttributeType for the given @attribute, or
662 * %G_FILE_ATTRIBUTE_TYPE_INVALID if the key is not set.
665 g_file_info_get_attribute_type (GFileInfo
*info
,
666 const char *attribute
)
668 GFileAttributeValue
*value
;
670 g_return_val_if_fail (G_IS_FILE_INFO (info
), G_FILE_ATTRIBUTE_TYPE_INVALID
);
671 g_return_val_if_fail (attribute
!= NULL
&& *attribute
!= '\0', G_FILE_ATTRIBUTE_TYPE_INVALID
);
673 value
= g_file_info_find_value_by_name (info
, attribute
);
677 return G_FILE_ATTRIBUTE_TYPE_INVALID
;
681 * g_file_info_remove_attribute:
682 * @info: a #GFileInfo.
683 * @attribute: a file attribute key.
685 * Removes all cases of @attribute from @info if it exists.
688 g_file_info_remove_attribute (GFileInfo
*info
,
689 const char *attribute
)
692 GFileAttribute
*attrs
;
695 g_return_if_fail (G_IS_FILE_INFO (info
));
696 g_return_if_fail (attribute
!= NULL
&& *attribute
!= '\0');
698 attr_id
= lookup_attribute (attribute
);
700 i
= g_file_info_find_place (info
, attr_id
);
701 attrs
= (GFileAttribute
*)info
->attributes
->data
;
702 if (i
< info
->attributes
->len
&&
703 attrs
[i
].attribute
== attr_id
)
705 _g_file_attribute_value_clear (&attrs
[i
].value
);
706 g_array_remove_index (info
->attributes
, i
);
711 * g_file_info_get_attribute_data:
712 * @info: a #GFileInfo
713 * @attribute: a file attribute key
714 * @type: (out) (allow-none): return location for the attribute type, or %NULL
715 * @value_pp: (out) (allow-none): return location for the attribute value, or %NULL
716 * @status: (out) (allow-none): return location for the attribute status, or %NULL
718 * Gets the attribute type, value and status for an attribute key.
720 * Returns: (transfer none): %TRUE if @info has an attribute named @attribute,
724 g_file_info_get_attribute_data (GFileInfo
*info
,
725 const char *attribute
,
726 GFileAttributeType
*type
,
728 GFileAttributeStatus
*status
)
730 GFileAttributeValue
*value
;
732 value
= g_file_info_find_value_by_name (info
, attribute
);
737 *status
= value
->status
;
743 *value_pp
= _g_file_attribute_value_peek_as_pointer (value
);
749 * g_file_info_get_attribute_status:
750 * @info: a #GFileInfo
751 * @attribute: a file attribute key
753 * Gets the attribute status for an attribute key.
755 * Returns: a #GFileAttributeStatus for the given @attribute, or
756 * %G_FILE_ATTRIBUTE_STATUS_UNSET if the key is invalid.
760 g_file_info_get_attribute_status (GFileInfo
*info
,
761 const char *attribute
)
763 GFileAttributeValue
*val
;
765 g_return_val_if_fail (G_IS_FILE_INFO (info
), 0);
766 g_return_val_if_fail (attribute
!= NULL
&& *attribute
!= '\0', 0);
768 val
= g_file_info_find_value_by_name (info
, attribute
);
772 return G_FILE_ATTRIBUTE_STATUS_UNSET
;
776 * g_file_info_set_attribute_status:
777 * @info: a #GFileInfo
778 * @attribute: a file attribute key
779 * @status: a #GFileAttributeStatus
781 * Sets the attribute status for an attribute key. This is only
782 * needed by external code that implement g_file_set_attributes_from_info()
783 * or similar functions.
785 * The attribute must exist in @info for this to work. Otherwise %FALSE
786 * is returned and @info is unchanged.
788 * Returns: %TRUE if the status was changed, %FALSE if the key was not set.
793 g_file_info_set_attribute_status (GFileInfo
*info
,
794 const char *attribute
,
795 GFileAttributeStatus status
)
797 GFileAttributeValue
*val
;
799 g_return_val_if_fail (G_IS_FILE_INFO (info
), FALSE
);
800 g_return_val_if_fail (attribute
!= NULL
&& *attribute
!= '\0', FALSE
);
802 val
= g_file_info_find_value_by_name (info
, attribute
);
805 val
->status
= status
;
812 GFileAttributeValue
*
813 _g_file_info_get_attribute_value (GFileInfo
*info
,
814 const char *attribute
)
817 g_return_val_if_fail (G_IS_FILE_INFO (info
), NULL
);
818 g_return_val_if_fail (attribute
!= NULL
&& *attribute
!= '\0', NULL
);
820 return g_file_info_find_value_by_name (info
, attribute
);
824 * g_file_info_get_attribute_as_string:
825 * @info: a #GFileInfo.
826 * @attribute: a file attribute key.
828 * Gets the value of a attribute, formated as a string.
829 * This escapes things as needed to make the string valid
832 * Returns: a UTF-8 string associated with the given @attribute.
833 * When you're done with the string it must be freed with g_free().
836 g_file_info_get_attribute_as_string (GFileInfo
*info
,
837 const char *attribute
)
839 GFileAttributeValue
*val
;
840 val
= _g_file_info_get_attribute_value (info
, attribute
);
842 return _g_file_attribute_value_as_string (val
);
848 * g_file_info_get_attribute_object:
849 * @info: a #GFileInfo.
850 * @attribute: a file attribute key.
852 * Gets the value of a #GObject attribute. If the attribute does
853 * not contain a #GObject, %NULL will be returned.
855 * Returns: (transfer none): a #GObject associated with the given @attribute, or
859 g_file_info_get_attribute_object (GFileInfo
*info
,
860 const char *attribute
)
862 GFileAttributeValue
*value
;
864 g_return_val_if_fail (G_IS_FILE_INFO (info
), NULL
);
865 g_return_val_if_fail (attribute
!= NULL
&& *attribute
!= '\0', NULL
);
867 value
= g_file_info_find_value_by_name (info
, attribute
);
868 return _g_file_attribute_value_get_object (value
);
872 * g_file_info_get_attribute_string:
873 * @info: a #GFileInfo.
874 * @attribute: a file attribute key.
876 * Gets the value of a string attribute. If the attribute does
877 * not contain a string, %NULL will be returned.
879 * Returns: the contents of the @attribute value as a UTF-8 string, or
883 g_file_info_get_attribute_string (GFileInfo
*info
,
884 const char *attribute
)
886 GFileAttributeValue
*value
;
888 g_return_val_if_fail (G_IS_FILE_INFO (info
), NULL
);
889 g_return_val_if_fail (attribute
!= NULL
&& *attribute
!= '\0', NULL
);
891 value
= g_file_info_find_value_by_name (info
, attribute
);
892 return _g_file_attribute_value_get_string (value
);
896 * g_file_info_get_attribute_byte_string:
897 * @info: a #GFileInfo.
898 * @attribute: a file attribute key.
900 * Gets the value of a byte string attribute. If the attribute does
901 * not contain a byte string, %NULL will be returned.
903 * Returns: the contents of the @attribute value as a byte string, or
907 g_file_info_get_attribute_byte_string (GFileInfo
*info
,
908 const char *attribute
)
910 GFileAttributeValue
*value
;
912 g_return_val_if_fail (G_IS_FILE_INFO (info
), NULL
);
913 g_return_val_if_fail (attribute
!= NULL
&& *attribute
!= '\0', NULL
);
915 value
= g_file_info_find_value_by_name (info
, attribute
);
916 return _g_file_attribute_value_get_byte_string (value
);
920 * g_file_info_get_attribute_stringv:
921 * @info: a #GFileInfo.
922 * @attribute: a file attribute key.
924 * Gets the value of a stringv attribute. If the attribute does
925 * not contain a stringv, %NULL will be returned.
927 * Returns: (transfer none): the contents of the @attribute value as a stringv, or
928 * %NULL otherwise. Do not free. These returned strings are UTF-8.
933 g_file_info_get_attribute_stringv (GFileInfo
*info
,
934 const char *attribute
)
936 GFileAttributeValue
*value
;
938 g_return_val_if_fail (G_IS_FILE_INFO (info
), NULL
);
939 g_return_val_if_fail (attribute
!= NULL
&& *attribute
!= '\0', NULL
);
941 value
= g_file_info_find_value_by_name (info
, attribute
);
942 return _g_file_attribute_value_get_stringv (value
);
946 * g_file_info_get_attribute_boolean:
947 * @info: a #GFileInfo.
948 * @attribute: a file attribute key.
950 * Gets the value of a boolean attribute. If the attribute does not
951 * contain a boolean value, %FALSE will be returned.
953 * Returns: the boolean value contained within the attribute.
956 g_file_info_get_attribute_boolean (GFileInfo
*info
,
957 const char *attribute
)
959 GFileAttributeValue
*value
;
961 g_return_val_if_fail (G_IS_FILE_INFO (info
), FALSE
);
962 g_return_val_if_fail (attribute
!= NULL
&& *attribute
!= '\0', FALSE
);
964 value
= g_file_info_find_value_by_name (info
, attribute
);
965 return _g_file_attribute_value_get_boolean (value
);
969 * g_file_info_get_attribute_uint32:
970 * @info: a #GFileInfo.
971 * @attribute: a file attribute key.
973 * Gets an unsigned 32-bit integer contained within the attribute. If the
974 * attribute does not contain an unsigned 32-bit integer, or is invalid,
975 * 0 will be returned.
977 * Returns: an unsigned 32-bit integer from the attribute.
980 g_file_info_get_attribute_uint32 (GFileInfo
*info
,
981 const char *attribute
)
983 GFileAttributeValue
*value
;
985 g_return_val_if_fail (G_IS_FILE_INFO (info
), 0);
986 g_return_val_if_fail (attribute
!= NULL
&& *attribute
!= '\0', 0);
988 value
= g_file_info_find_value_by_name (info
, attribute
);
989 return _g_file_attribute_value_get_uint32 (value
);
993 * g_file_info_get_attribute_int32:
994 * @info: a #GFileInfo.
995 * @attribute: a file attribute key.
997 * Gets a signed 32-bit integer contained within the attribute. If the
998 * attribute does not contain a signed 32-bit integer, or is invalid,
999 * 0 will be returned.
1001 * Returns: a signed 32-bit integer from the attribute.
1004 g_file_info_get_attribute_int32 (GFileInfo
*info
,
1005 const char *attribute
)
1007 GFileAttributeValue
*value
;
1009 g_return_val_if_fail (G_IS_FILE_INFO (info
), 0);
1010 g_return_val_if_fail (attribute
!= NULL
&& *attribute
!= '\0', 0);
1012 value
= g_file_info_find_value_by_name (info
, attribute
);
1013 return _g_file_attribute_value_get_int32 (value
);
1017 * g_file_info_get_attribute_uint64:
1018 * @info: a #GFileInfo.
1019 * @attribute: a file attribute key.
1021 * Gets a unsigned 64-bit integer contained within the attribute. If the
1022 * attribute does not contain an unsigned 64-bit integer, or is invalid,
1023 * 0 will be returned.
1025 * Returns: a unsigned 64-bit integer from the attribute.
1028 g_file_info_get_attribute_uint64 (GFileInfo
*info
,
1029 const char *attribute
)
1031 GFileAttributeValue
*value
;
1033 g_return_val_if_fail (G_IS_FILE_INFO (info
), 0);
1034 g_return_val_if_fail (attribute
!= NULL
&& *attribute
!= '\0', 0);
1036 value
= g_file_info_find_value_by_name (info
, attribute
);
1037 return _g_file_attribute_value_get_uint64 (value
);
1041 * g_file_info_get_attribute_int64:
1042 * @info: a #GFileInfo.
1043 * @attribute: a file attribute key.
1045 * Gets a signed 64-bit integer contained within the attribute. If the
1046 * attribute does not contain an signed 64-bit integer, or is invalid,
1047 * 0 will be returned.
1049 * Returns: a signed 64-bit integer from the attribute.
1052 g_file_info_get_attribute_int64 (GFileInfo
*info
,
1053 const char *attribute
)
1055 GFileAttributeValue
*value
;
1057 g_return_val_if_fail (G_IS_FILE_INFO (info
), 0);
1058 g_return_val_if_fail (attribute
!= NULL
&& *attribute
!= '\0', 0);
1060 value
= g_file_info_find_value_by_name (info
, attribute
);
1061 return _g_file_attribute_value_get_int64 (value
);
1064 static GFileAttributeValue
*
1065 g_file_info_create_value (GFileInfo
*info
,
1068 GFileAttribute
*attrs
;
1071 if (info
->mask
!= NO_ATTRIBUTE_MASK
&&
1072 !_g_file_attribute_matcher_matches_id (info
->mask
, attr_id
))
1075 i
= g_file_info_find_place (info
, attr_id
);
1077 attrs
= (GFileAttribute
*)info
->attributes
->data
;
1078 if (i
< info
->attributes
->len
&&
1079 attrs
[i
].attribute
== attr_id
)
1080 return &attrs
[i
].value
;
1083 GFileAttribute attr
= { 0 };
1084 attr
.attribute
= attr_id
;
1085 g_array_insert_val (info
->attributes
, i
, attr
);
1087 attrs
= (GFileAttribute
*)info
->attributes
->data
;
1088 return &attrs
[i
].value
;
1093 _g_file_info_set_attribute_by_id (GFileInfo
*info
,
1095 GFileAttributeType type
,
1098 GFileAttributeValue
*value
;
1100 value
= g_file_info_create_value (info
, attribute
);
1103 _g_file_attribute_value_set_from_pointer (value
, type
, value_p
, TRUE
);
1107 * g_file_info_set_attribute:
1108 * @info: a #GFileInfo.
1109 * @attribute: a file attribute key.
1110 * @type: a #GFileAttributeType
1111 * @value_p: pointer to the value
1113 * Sets the @attribute to contain the given value, if possible. To unset the
1114 * attribute, use %G_ATTRIBUTE_TYPE_INVALID for @type.
1117 g_file_info_set_attribute (GFileInfo
*info
,
1118 const char *attribute
,
1119 GFileAttributeType type
,
1122 g_return_if_fail (G_IS_FILE_INFO (info
));
1123 g_return_if_fail (attribute
!= NULL
&& *attribute
!= '\0');
1125 _g_file_info_set_attribute_by_id (info
, lookup_attribute (attribute
), type
, value_p
);
1129 _g_file_info_set_attribute_object_by_id (GFileInfo
*info
,
1131 GObject
*attr_value
)
1133 GFileAttributeValue
*value
;
1135 value
= g_file_info_create_value (info
, attribute
);
1137 _g_file_attribute_value_set_object (value
, attr_value
);
1141 * g_file_info_set_attribute_object:
1142 * @info: a #GFileInfo.
1143 * @attribute: a file attribute key.
1144 * @attr_value: a #GObject.
1146 * Sets the @attribute to contain the given @attr_value,
1150 g_file_info_set_attribute_object (GFileInfo
*info
,
1151 const char *attribute
,
1152 GObject
*attr_value
)
1154 g_return_if_fail (G_IS_FILE_INFO (info
));
1155 g_return_if_fail (attribute
!= NULL
&& *attribute
!= '\0');
1156 g_return_if_fail (G_IS_OBJECT (attr_value
));
1158 _g_file_info_set_attribute_object_by_id (info
,
1159 lookup_attribute (attribute
),
1164 _g_file_info_set_attribute_stringv_by_id (GFileInfo
*info
,
1168 GFileAttributeValue
*value
;
1170 value
= g_file_info_create_value (info
, attribute
);
1172 _g_file_attribute_value_set_stringv (value
, attr_value
);
1176 * g_file_info_set_attribute_stringv:
1177 * @info: a #GFileInfo.
1178 * @attribute: a file attribute key
1179 * @attr_value: (array) (element-type utf8): a %NULL terminated array of UTF-8 strings.
1181 * Sets the @attribute to contain the given @attr_value,
1187 g_file_info_set_attribute_stringv (GFileInfo
*info
,
1188 const char *attribute
,
1191 g_return_if_fail (G_IS_FILE_INFO (info
));
1192 g_return_if_fail (attribute
!= NULL
&& *attribute
!= '\0');
1193 g_return_if_fail (attr_value
!= NULL
);
1195 _g_file_info_set_attribute_stringv_by_id (info
,
1196 lookup_attribute (attribute
),
1201 _g_file_info_set_attribute_string_by_id (GFileInfo
*info
,
1203 const char *attr_value
)
1205 GFileAttributeValue
*value
;
1207 value
= g_file_info_create_value (info
, attribute
);
1209 _g_file_attribute_value_set_string (value
, attr_value
);
1213 * g_file_info_set_attribute_string:
1214 * @info: a #GFileInfo.
1215 * @attribute: a file attribute key.
1216 * @attr_value: a UTF-8 string.
1218 * Sets the @attribute to contain the given @attr_value,
1222 g_file_info_set_attribute_string (GFileInfo
*info
,
1223 const char *attribute
,
1224 const char *attr_value
)
1226 g_return_if_fail (G_IS_FILE_INFO (info
));
1227 g_return_if_fail (attribute
!= NULL
&& *attribute
!= '\0');
1228 g_return_if_fail (attr_value
!= NULL
);
1230 _g_file_info_set_attribute_string_by_id (info
,
1231 lookup_attribute (attribute
),
1236 _g_file_info_set_attribute_byte_string_by_id (GFileInfo
*info
,
1238 const char *attr_value
)
1240 GFileAttributeValue
*value
;
1242 value
= g_file_info_create_value (info
, attribute
);
1244 _g_file_attribute_value_set_byte_string (value
, attr_value
);
1248 * g_file_info_set_attribute_byte_string:
1249 * @info: a #GFileInfo.
1250 * @attribute: a file attribute key.
1251 * @attr_value: a byte string.
1253 * Sets the @attribute to contain the given @attr_value,
1257 g_file_info_set_attribute_byte_string (GFileInfo
*info
,
1258 const char *attribute
,
1259 const char *attr_value
)
1261 g_return_if_fail (G_IS_FILE_INFO (info
));
1262 g_return_if_fail (attribute
!= NULL
&& *attribute
!= '\0');
1263 g_return_if_fail (attr_value
!= NULL
);
1265 _g_file_info_set_attribute_byte_string_by_id (info
,
1266 lookup_attribute (attribute
),
1271 _g_file_info_set_attribute_boolean_by_id (GFileInfo
*info
,
1273 gboolean attr_value
)
1275 GFileAttributeValue
*value
;
1277 value
= g_file_info_create_value (info
, attribute
);
1279 _g_file_attribute_value_set_boolean (value
, attr_value
);
1283 * g_file_info_set_attribute_boolean:
1284 * @info: a #GFileInfo.
1285 * @attribute: a file attribute key.
1286 * @attr_value: a boolean value.
1288 * Sets the @attribute to contain the given @attr_value,
1292 g_file_info_set_attribute_boolean (GFileInfo
*info
,
1293 const char *attribute
,
1294 gboolean attr_value
)
1296 g_return_if_fail (G_IS_FILE_INFO (info
));
1297 g_return_if_fail (attribute
!= NULL
&& *attribute
!= '\0');
1299 _g_file_info_set_attribute_boolean_by_id (info
,
1300 lookup_attribute (attribute
),
1305 _g_file_info_set_attribute_uint32_by_id (GFileInfo
*info
,
1309 GFileAttributeValue
*value
;
1311 value
= g_file_info_create_value (info
, attribute
);
1313 _g_file_attribute_value_set_uint32 (value
, attr_value
);
1317 * g_file_info_set_attribute_uint32:
1318 * @info: a #GFileInfo.
1319 * @attribute: a file attribute key.
1320 * @attr_value: an unsigned 32-bit integer.
1322 * Sets the @attribute to contain the given @attr_value,
1326 g_file_info_set_attribute_uint32 (GFileInfo
*info
,
1327 const char *attribute
,
1330 g_return_if_fail (G_IS_FILE_INFO (info
));
1331 g_return_if_fail (attribute
!= NULL
&& *attribute
!= '\0');
1333 _g_file_info_set_attribute_uint32_by_id (info
,
1334 lookup_attribute (attribute
),
1339 _g_file_info_set_attribute_int32_by_id (GFileInfo
*info
,
1343 GFileAttributeValue
*value
;
1345 value
= g_file_info_create_value (info
, attribute
);
1347 _g_file_attribute_value_set_int32 (value
, attr_value
);
1351 * g_file_info_set_attribute_int32:
1352 * @info: a #GFileInfo.
1353 * @attribute: a file attribute key.
1354 * @attr_value: a signed 32-bit integer
1356 * Sets the @attribute to contain the given @attr_value,
1360 g_file_info_set_attribute_int32 (GFileInfo
*info
,
1361 const char *attribute
,
1364 g_return_if_fail (G_IS_FILE_INFO (info
));
1365 g_return_if_fail (attribute
!= NULL
&& *attribute
!= '\0');
1367 _g_file_info_set_attribute_int32_by_id (info
,
1368 lookup_attribute (attribute
),
1373 _g_file_info_set_attribute_uint64_by_id (GFileInfo
*info
,
1377 GFileAttributeValue
*value
;
1379 value
= g_file_info_create_value (info
, attribute
);
1381 _g_file_attribute_value_set_uint64 (value
, attr_value
);
1385 * g_file_info_set_attribute_uint64:
1386 * @info: a #GFileInfo.
1387 * @attribute: a file attribute key.
1388 * @attr_value: an unsigned 64-bit integer.
1390 * Sets the @attribute to contain the given @attr_value,
1394 g_file_info_set_attribute_uint64 (GFileInfo
*info
,
1395 const char *attribute
,
1398 g_return_if_fail (G_IS_FILE_INFO (info
));
1399 g_return_if_fail (attribute
!= NULL
&& *attribute
!= '\0');
1401 _g_file_info_set_attribute_uint64_by_id (info
,
1402 lookup_attribute (attribute
),
1407 _g_file_info_set_attribute_int64_by_id (GFileInfo
*info
,
1411 GFileAttributeValue
*value
;
1413 value
= g_file_info_create_value (info
, attribute
);
1415 _g_file_attribute_value_set_int64 (value
, attr_value
);
1419 * g_file_info_set_attribute_int64:
1420 * @info: a #GFileInfo.
1421 * @attribute: attribute name to set.
1422 * @attr_value: int64 value to set attribute to.
1424 * Sets the @attribute to contain the given @attr_value,
1429 g_file_info_set_attribute_int64 (GFileInfo
*info
,
1430 const char *attribute
,
1433 g_return_if_fail (G_IS_FILE_INFO (info
));
1434 g_return_if_fail (attribute
!= NULL
&& *attribute
!= '\0');
1436 _g_file_info_set_attribute_int64_by_id (info
,
1437 lookup_attribute (attribute
),
1441 /* Helper getters */
1443 * g_file_info_get_deletion_date:
1444 * @info: a #GFileInfo.
1446 * Returns the #GDateTime representing the deletion date of the file, as
1447 * available in G_FILE_ATTRIBUTE_TRASH_DELETION_DATE. If the
1448 * G_FILE_ATTRIBUTE_TRASH_DELETION_DATE attribute is unset, %NULL is returned.
1450 * Returns: a #GDateTime, or %NULL.
1455 g_file_info_get_deletion_date (GFileInfo
*info
)
1457 static guint32 attr
= 0;
1458 GFileAttributeValue
*value
;
1459 const char *date_str
;
1462 g_return_val_if_fail (G_IS_FILE_INFO (info
), FALSE
);
1465 attr
= lookup_attribute (G_FILE_ATTRIBUTE_TRASH_DELETION_DATE
);
1467 value
= g_file_info_find_value (info
, attr
);
1468 date_str
= _g_file_attribute_value_get_string (value
);
1472 if (g_time_val_from_iso8601 (date_str
, &tv
) == FALSE
)
1475 return g_date_time_new_from_timeval_local (&tv
);
1479 * g_file_info_get_file_type:
1480 * @info: a #GFileInfo.
1482 * Gets a file's type (whether it is a regular file, symlink, etc).
1483 * This is different from the file's content type, see g_file_info_get_content_type().
1485 * Returns: a #GFileType for the given file.
1488 g_file_info_get_file_type (GFileInfo
*info
)
1490 static guint32 attr
= 0;
1491 GFileAttributeValue
*value
;
1493 g_return_val_if_fail (G_IS_FILE_INFO (info
), G_FILE_TYPE_UNKNOWN
);
1496 attr
= lookup_attribute (G_FILE_ATTRIBUTE_STANDARD_TYPE
);
1498 value
= g_file_info_find_value (info
, attr
);
1499 return (GFileType
)_g_file_attribute_value_get_uint32 (value
);
1503 * g_file_info_get_is_hidden:
1504 * @info: a #GFileInfo.
1506 * Checks if a file is hidden.
1508 * Returns: %TRUE if the file is a hidden file, %FALSE otherwise.
1511 g_file_info_get_is_hidden (GFileInfo
*info
)
1513 static guint32 attr
= 0;
1514 GFileAttributeValue
*value
;
1516 g_return_val_if_fail (G_IS_FILE_INFO (info
), FALSE
);
1519 attr
= lookup_attribute (G_FILE_ATTRIBUTE_STANDARD_IS_HIDDEN
);
1521 value
= g_file_info_find_value (info
, attr
);
1522 return (GFileType
)_g_file_attribute_value_get_boolean (value
);
1526 * g_file_info_get_is_backup:
1527 * @info: a #GFileInfo.
1529 * Checks if a file is a backup file.
1531 * Returns: %TRUE if file is a backup file, %FALSE otherwise.
1534 g_file_info_get_is_backup (GFileInfo
*info
)
1536 static guint32 attr
= 0;
1537 GFileAttributeValue
*value
;
1539 g_return_val_if_fail (G_IS_FILE_INFO (info
), FALSE
);
1542 attr
= lookup_attribute (G_FILE_ATTRIBUTE_STANDARD_IS_BACKUP
);
1544 value
= g_file_info_find_value (info
, attr
);
1545 return (GFileType
)_g_file_attribute_value_get_boolean (value
);
1549 * g_file_info_get_is_symlink:
1550 * @info: a #GFileInfo.
1552 * Checks if a file is a symlink.
1554 * Returns: %TRUE if the given @info is a symlink.
1557 g_file_info_get_is_symlink (GFileInfo
*info
)
1559 static guint32 attr
= 0;
1560 GFileAttributeValue
*value
;
1562 g_return_val_if_fail (G_IS_FILE_INFO (info
), FALSE
);
1565 attr
= lookup_attribute (G_FILE_ATTRIBUTE_STANDARD_IS_SYMLINK
);
1567 value
= g_file_info_find_value (info
, attr
);
1568 return (GFileType
)_g_file_attribute_value_get_boolean (value
);
1572 * g_file_info_get_name:
1573 * @info: a #GFileInfo.
1575 * Gets the name for a file.
1577 * Returns: a string containing the file name.
1580 g_file_info_get_name (GFileInfo
*info
)
1582 static guint32 attr
= 0;
1583 GFileAttributeValue
*value
;
1585 g_return_val_if_fail (G_IS_FILE_INFO (info
), NULL
);
1588 attr
= lookup_attribute (G_FILE_ATTRIBUTE_STANDARD_NAME
);
1590 value
= g_file_info_find_value (info
, attr
);
1591 return _g_file_attribute_value_get_byte_string (value
);
1595 * g_file_info_get_display_name:
1596 * @info: a #GFileInfo.
1598 * Gets a display name for a file.
1600 * Returns: a string containing the display name.
1603 g_file_info_get_display_name (GFileInfo
*info
)
1605 static guint32 attr
= 0;
1606 GFileAttributeValue
*value
;
1608 g_return_val_if_fail (G_IS_FILE_INFO (info
), NULL
);
1611 attr
= lookup_attribute (G_FILE_ATTRIBUTE_STANDARD_DISPLAY_NAME
);
1613 value
= g_file_info_find_value (info
, attr
);
1614 return _g_file_attribute_value_get_string (value
);
1618 * g_file_info_get_edit_name:
1619 * @info: a #GFileInfo.
1621 * Gets the edit name for a file.
1623 * Returns: a string containing the edit name.
1626 g_file_info_get_edit_name (GFileInfo
*info
)
1628 static guint32 attr
= 0;
1629 GFileAttributeValue
*value
;
1631 g_return_val_if_fail (G_IS_FILE_INFO (info
), NULL
);
1634 attr
= lookup_attribute (G_FILE_ATTRIBUTE_STANDARD_EDIT_NAME
);
1636 value
= g_file_info_find_value (info
, attr
);
1637 return _g_file_attribute_value_get_string (value
);
1641 * g_file_info_get_icon:
1642 * @info: a #GFileInfo.
1644 * Gets the icon for a file.
1646 * Returns: (transfer none): #GIcon for the given @info.
1649 g_file_info_get_icon (GFileInfo
*info
)
1651 static guint32 attr
= 0;
1652 GFileAttributeValue
*value
;
1655 g_return_val_if_fail (G_IS_FILE_INFO (info
), NULL
);
1658 attr
= lookup_attribute (G_FILE_ATTRIBUTE_STANDARD_ICON
);
1660 value
= g_file_info_find_value (info
, attr
);
1661 obj
= _g_file_attribute_value_get_object (value
);
1662 if (G_IS_ICON (obj
))
1663 return G_ICON (obj
);
1668 * g_file_info_get_symbolic_icon:
1669 * @info: a #GFileInfo.
1671 * Gets the symbolic icon for a file.
1673 * Returns: (transfer none): #GIcon for the given @info.
1678 g_file_info_get_symbolic_icon (GFileInfo
*info
)
1680 static guint32 attr
= 0;
1681 GFileAttributeValue
*value
;
1684 g_return_val_if_fail (G_IS_FILE_INFO (info
), NULL
);
1687 attr
= lookup_attribute (G_FILE_ATTRIBUTE_STANDARD_SYMBOLIC_ICON
);
1689 value
= g_file_info_find_value (info
, attr
);
1690 obj
= _g_file_attribute_value_get_object (value
);
1691 if (G_IS_ICON (obj
))
1692 return G_ICON (obj
);
1697 * g_file_info_get_content_type:
1698 * @info: a #GFileInfo.
1700 * Gets the file's content type.
1702 * Returns: a string containing the file's content type.
1705 g_file_info_get_content_type (GFileInfo
*info
)
1707 static guint32 attr
= 0;
1708 GFileAttributeValue
*value
;
1710 g_return_val_if_fail (G_IS_FILE_INFO (info
), NULL
);
1713 attr
= lookup_attribute (G_FILE_ATTRIBUTE_STANDARD_CONTENT_TYPE
);
1715 value
= g_file_info_find_value (info
, attr
);
1716 return _g_file_attribute_value_get_string (value
);
1720 * g_file_info_get_size:
1721 * @info: a #GFileInfo.
1723 * Gets the file's size.
1725 * Returns: a #goffset containing the file's size.
1728 g_file_info_get_size (GFileInfo
*info
)
1730 static guint32 attr
= 0;
1731 GFileAttributeValue
*value
;
1733 g_return_val_if_fail (G_IS_FILE_INFO (info
), (goffset
) 0);
1736 attr
= lookup_attribute (G_FILE_ATTRIBUTE_STANDARD_SIZE
);
1738 value
= g_file_info_find_value (info
, attr
);
1739 return (goffset
) _g_file_attribute_value_get_uint64 (value
);
1743 * g_file_info_get_modification_time:
1744 * @info: a #GFileInfo.
1745 * @result: (out caller-allocates): a #GTimeVal.
1747 * Gets the modification time of the current @info and sets it
1751 g_file_info_get_modification_time (GFileInfo
*info
,
1754 static guint32 attr_mtime
= 0, attr_mtime_usec
;
1755 GFileAttributeValue
*value
;
1757 g_return_if_fail (G_IS_FILE_INFO (info
));
1758 g_return_if_fail (result
!= NULL
);
1760 if (attr_mtime
== 0)
1762 attr_mtime
= lookup_attribute (G_FILE_ATTRIBUTE_TIME_MODIFIED
);
1763 attr_mtime_usec
= lookup_attribute (G_FILE_ATTRIBUTE_TIME_MODIFIED_USEC
);
1766 value
= g_file_info_find_value (info
, attr_mtime
);
1767 result
->tv_sec
= _g_file_attribute_value_get_uint64 (value
);
1768 value
= g_file_info_find_value (info
, attr_mtime_usec
);
1769 result
->tv_usec
= _g_file_attribute_value_get_uint32 (value
);
1773 * g_file_info_get_symlink_target:
1774 * @info: a #GFileInfo.
1776 * Gets the symlink target for a given #GFileInfo.
1778 * Returns: a string containing the symlink target.
1781 g_file_info_get_symlink_target (GFileInfo
*info
)
1783 static guint32 attr
= 0;
1784 GFileAttributeValue
*value
;
1786 g_return_val_if_fail (G_IS_FILE_INFO (info
), NULL
);
1789 attr
= lookup_attribute (G_FILE_ATTRIBUTE_STANDARD_SYMLINK_TARGET
);
1791 value
= g_file_info_find_value (info
, attr
);
1792 return _g_file_attribute_value_get_byte_string (value
);
1796 * g_file_info_get_etag:
1797 * @info: a #GFileInfo.
1799 * Gets the <link linkend="gfile-etag">entity tag</link> for a given
1800 * #GFileInfo. See %G_FILE_ATTRIBUTE_ETAG_VALUE.
1802 * Returns: a string containing the value of the "etag:value" attribute.
1805 g_file_info_get_etag (GFileInfo
*info
)
1807 static guint32 attr
= 0;
1808 GFileAttributeValue
*value
;
1810 g_return_val_if_fail (G_IS_FILE_INFO (info
), NULL
);
1813 attr
= lookup_attribute (G_FILE_ATTRIBUTE_ETAG_VALUE
);
1815 value
= g_file_info_find_value (info
, attr
);
1816 return _g_file_attribute_value_get_string (value
);
1820 * g_file_info_get_sort_order:
1821 * @info: a #GFileInfo.
1823 * Gets the value of the sort_order attribute from the #GFileInfo.
1824 * See %G_FILE_ATTRIBUTE_STANDARD_SORT_ORDER.
1826 * Returns: a #gint32 containing the value of the "standard::sort_order" attribute.
1829 g_file_info_get_sort_order (GFileInfo
*info
)
1831 static guint32 attr
= 0;
1832 GFileAttributeValue
*value
;
1834 g_return_val_if_fail (G_IS_FILE_INFO (info
), 0);
1837 attr
= lookup_attribute (G_FILE_ATTRIBUTE_STANDARD_SORT_ORDER
);
1839 value
= g_file_info_find_value (info
, attr
);
1840 return _g_file_attribute_value_get_int32 (value
);
1843 /* Helper setters: */
1845 * g_file_info_set_file_type:
1846 * @info: a #GFileInfo.
1847 * @type: a #GFileType.
1849 * Sets the file type in a #GFileInfo to @type.
1850 * See %G_FILE_ATTRIBUTE_STANDARD_TYPE.
1853 g_file_info_set_file_type (GFileInfo
*info
,
1856 static guint32 attr
= 0;
1857 GFileAttributeValue
*value
;
1859 g_return_if_fail (G_IS_FILE_INFO (info
));
1862 attr
= lookup_attribute (G_FILE_ATTRIBUTE_STANDARD_TYPE
);
1864 value
= g_file_info_create_value (info
, attr
);
1866 _g_file_attribute_value_set_uint32 (value
, type
);
1870 * g_file_info_set_is_hidden:
1871 * @info: a #GFileInfo.
1872 * @is_hidden: a #gboolean.
1874 * Sets the "is_hidden" attribute in a #GFileInfo according to @is_symlink.
1875 * See %G_FILE_ATTRIBUTE_STANDARD_IS_HIDDEN.
1878 g_file_info_set_is_hidden (GFileInfo
*info
,
1881 static guint32 attr
= 0;
1882 GFileAttributeValue
*value
;
1884 g_return_if_fail (G_IS_FILE_INFO (info
));
1887 attr
= lookup_attribute (G_FILE_ATTRIBUTE_STANDARD_IS_HIDDEN
);
1889 value
= g_file_info_create_value (info
, attr
);
1891 _g_file_attribute_value_set_boolean (value
, is_hidden
);
1895 * g_file_info_set_is_symlink:
1896 * @info: a #GFileInfo.
1897 * @is_symlink: a #gboolean.
1899 * Sets the "is_symlink" attribute in a #GFileInfo according to @is_symlink.
1900 * See %G_FILE_ATTRIBUTE_STANDARD_IS_SYMLINK.
1903 g_file_info_set_is_symlink (GFileInfo
*info
,
1904 gboolean is_symlink
)
1906 static guint32 attr
= 0;
1907 GFileAttributeValue
*value
;
1909 g_return_if_fail (G_IS_FILE_INFO (info
));
1912 attr
= lookup_attribute (G_FILE_ATTRIBUTE_STANDARD_IS_SYMLINK
);
1914 value
= g_file_info_create_value (info
, attr
);
1916 _g_file_attribute_value_set_boolean (value
, is_symlink
);
1920 * g_file_info_set_name:
1921 * @info: a #GFileInfo.
1922 * @name: a string containing a name.
1924 * Sets the name attribute for the current #GFileInfo.
1925 * See %G_FILE_ATTRIBUTE_STANDARD_NAME.
1928 g_file_info_set_name (GFileInfo
*info
,
1931 static guint32 attr
= 0;
1932 GFileAttributeValue
*value
;
1934 g_return_if_fail (G_IS_FILE_INFO (info
));
1935 g_return_if_fail (name
!= NULL
);
1938 attr
= lookup_attribute (G_FILE_ATTRIBUTE_STANDARD_NAME
);
1940 value
= g_file_info_create_value (info
, attr
);
1942 _g_file_attribute_value_set_byte_string (value
, name
);
1946 * g_file_info_set_display_name:
1947 * @info: a #GFileInfo.
1948 * @display_name: a string containing a display name.
1950 * Sets the display name for the current #GFileInfo.
1951 * See %G_FILE_ATTRIBUTE_STANDARD_DISPLAY_NAME.
1954 g_file_info_set_display_name (GFileInfo
*info
,
1955 const char *display_name
)
1957 static guint32 attr
= 0;
1958 GFileAttributeValue
*value
;
1960 g_return_if_fail (G_IS_FILE_INFO (info
));
1961 g_return_if_fail (display_name
!= NULL
);
1964 attr
= lookup_attribute (G_FILE_ATTRIBUTE_STANDARD_DISPLAY_NAME
);
1966 value
= g_file_info_create_value (info
, attr
);
1968 _g_file_attribute_value_set_string (value
, display_name
);
1972 * g_file_info_set_edit_name:
1973 * @info: a #GFileInfo.
1974 * @edit_name: a string containing an edit name.
1976 * Sets the edit name for the current file.
1977 * See %G_FILE_ATTRIBUTE_STANDARD_EDIT_NAME.
1980 g_file_info_set_edit_name (GFileInfo
*info
,
1981 const char *edit_name
)
1983 static guint32 attr
= 0;
1984 GFileAttributeValue
*value
;
1986 g_return_if_fail (G_IS_FILE_INFO (info
));
1987 g_return_if_fail (edit_name
!= NULL
);
1990 attr
= lookup_attribute (G_FILE_ATTRIBUTE_STANDARD_EDIT_NAME
);
1992 value
= g_file_info_create_value (info
, attr
);
1994 _g_file_attribute_value_set_string (value
, edit_name
);
1998 * g_file_info_set_icon:
1999 * @info: a #GFileInfo.
2002 * Sets the icon for a given #GFileInfo.
2003 * See %G_FILE_ATTRIBUTE_STANDARD_ICON.
2006 g_file_info_set_icon (GFileInfo
*info
,
2009 static guint32 attr
= 0;
2010 GFileAttributeValue
*value
;
2012 g_return_if_fail (G_IS_FILE_INFO (info
));
2013 g_return_if_fail (G_IS_ICON (icon
));
2016 attr
= lookup_attribute (G_FILE_ATTRIBUTE_STANDARD_ICON
);
2018 value
= g_file_info_create_value (info
, attr
);
2020 _g_file_attribute_value_set_object (value
, G_OBJECT (icon
));
2024 * g_file_info_set_symbolic_icon:
2025 * @info: a #GFileInfo.
2028 * Sets the symbolic icon for a given #GFileInfo.
2029 * See %G_FILE_ATTRIBUTE_STANDARD_SYMBOLIC_ICON.
2034 g_file_info_set_symbolic_icon (GFileInfo
*info
,
2037 static guint32 attr
= 0;
2038 GFileAttributeValue
*value
;
2040 g_return_if_fail (G_IS_FILE_INFO (info
));
2041 g_return_if_fail (G_IS_ICON (icon
));
2044 attr
= lookup_attribute (G_FILE_ATTRIBUTE_STANDARD_SYMBOLIC_ICON
);
2046 value
= g_file_info_create_value (info
, attr
);
2048 _g_file_attribute_value_set_object (value
, G_OBJECT (icon
));
2052 * g_file_info_set_content_type:
2053 * @info: a #GFileInfo.
2054 * @content_type: a content type. See <link linkend="gio-GContentType">GContentType</link>.
2056 * Sets the content type attribute for a given #GFileInfo.
2057 * See %G_FILE_ATTRIBUTE_STANDARD_CONTENT_TYPE.
2060 g_file_info_set_content_type (GFileInfo
*info
,
2061 const char *content_type
)
2063 static guint32 attr
= 0;
2064 GFileAttributeValue
*value
;
2066 g_return_if_fail (G_IS_FILE_INFO (info
));
2067 g_return_if_fail (content_type
!= NULL
);
2070 attr
= lookup_attribute (G_FILE_ATTRIBUTE_STANDARD_CONTENT_TYPE
);
2072 value
= g_file_info_create_value (info
, attr
);
2074 _g_file_attribute_value_set_string (value
, content_type
);
2078 * g_file_info_set_size:
2079 * @info: a #GFileInfo.
2080 * @size: a #goffset containing the file's size.
2082 * Sets the %G_FILE_ATTRIBUTE_STANDARD_SIZE attribute in the file info
2083 * to the given size.
2086 g_file_info_set_size (GFileInfo
*info
,
2089 static guint32 attr
= 0;
2090 GFileAttributeValue
*value
;
2092 g_return_if_fail (G_IS_FILE_INFO (info
));
2095 attr
= lookup_attribute (G_FILE_ATTRIBUTE_STANDARD_SIZE
);
2097 value
= g_file_info_create_value (info
, attr
);
2099 _g_file_attribute_value_set_uint64 (value
, size
);
2103 * g_file_info_set_modification_time:
2104 * @info: a #GFileInfo.
2105 * @mtime: a #GTimeVal.
2107 * Sets the %G_FILE_ATTRIBUTE_TIME_MODIFIED attribute in the file
2108 * info to the given time value.
2111 g_file_info_set_modification_time (GFileInfo
*info
,
2114 static guint32 attr_mtime
= 0, attr_mtime_usec
;
2115 GFileAttributeValue
*value
;
2117 g_return_if_fail (G_IS_FILE_INFO (info
));
2118 g_return_if_fail (mtime
!= NULL
);
2120 if (attr_mtime
== 0)
2122 attr_mtime
= lookup_attribute (G_FILE_ATTRIBUTE_TIME_MODIFIED
);
2123 attr_mtime_usec
= lookup_attribute (G_FILE_ATTRIBUTE_TIME_MODIFIED_USEC
);
2126 value
= g_file_info_create_value (info
, attr_mtime
);
2128 _g_file_attribute_value_set_uint64 (value
, mtime
->tv_sec
);
2129 value
= g_file_info_create_value (info
, attr_mtime_usec
);
2131 _g_file_attribute_value_set_uint32 (value
, mtime
->tv_usec
);
2135 * g_file_info_set_symlink_target:
2136 * @info: a #GFileInfo.
2137 * @symlink_target: a static string containing a path to a symlink target.
2139 * Sets the %G_FILE_ATTRIBUTE_STANDARD_SYMLINK_TARGET attribute in the file info
2140 * to the given symlink target.
2143 g_file_info_set_symlink_target (GFileInfo
*info
,
2144 const char *symlink_target
)
2146 static guint32 attr
= 0;
2147 GFileAttributeValue
*value
;
2149 g_return_if_fail (G_IS_FILE_INFO (info
));
2150 g_return_if_fail (symlink_target
!= NULL
);
2153 attr
= lookup_attribute (G_FILE_ATTRIBUTE_STANDARD_SYMLINK_TARGET
);
2155 value
= g_file_info_create_value (info
, attr
);
2157 _g_file_attribute_value_set_byte_string (value
, symlink_target
);
2161 * g_file_info_set_sort_order:
2162 * @info: a #GFileInfo.
2163 * @sort_order: a sort order integer.
2165 * Sets the sort order attribute in the file info structure. See
2166 * %G_FILE_ATTRIBUTE_STANDARD_SORT_ORDER.
2169 g_file_info_set_sort_order (GFileInfo
*info
,
2172 static guint32 attr
= 0;
2173 GFileAttributeValue
*value
;
2175 g_return_if_fail (G_IS_FILE_INFO (info
));
2178 attr
= lookup_attribute (G_FILE_ATTRIBUTE_STANDARD_SORT_ORDER
);
2180 value
= g_file_info_create_value (info
, attr
);
2182 _g_file_attribute_value_set_int32 (value
, sort_order
);
2191 struct _GFileAttributeMatcher
{
2195 GArray
*sub_matchers
;
2198 guint32 iterator_ns
;
2202 G_DEFINE_BOXED_TYPE (GFileAttributeMatcher
, g_file_attribute_matcher
,
2203 g_file_attribute_matcher_ref
,
2204 g_file_attribute_matcher_unref
)
2207 compare_sub_matchers (gconstpointer a
,
2210 const SubMatcher
*suba
= a
;
2211 const SubMatcher
*subb
= b
;
2214 diff
= suba
->id
- subb
->id
;
2219 return suba
->mask
- subb
->mask
;
2223 sub_matcher_matches (SubMatcher
*matcher
,
2224 SubMatcher
*submatcher
)
2226 if ((matcher
->mask
& submatcher
->mask
) != matcher
->mask
)
2229 return matcher
->id
== (submatcher
->id
& matcher
->mask
);
2232 /* Call this function after modifying a matcher.
2233 * It will ensure all the invariants other functions rely on.
2235 static GFileAttributeMatcher
*
2236 matcher_optimize (GFileAttributeMatcher
*matcher
)
2238 SubMatcher
*submatcher
, *compare
;
2241 /* remove sub_matchers if we match everything anyway */
2244 if (matcher
->sub_matchers
)
2246 g_array_free (matcher
->sub_matchers
, TRUE
);
2247 matcher
->sub_matchers
= NULL
;
2252 if (matcher
->sub_matchers
->len
== 0)
2254 g_file_attribute_matcher_unref (matcher
);
2258 /* sort sub_matchers by id (and then mask), so we can bsearch
2259 * and compare matchers in O(N) instead of O(N²) */
2260 g_array_sort (matcher
->sub_matchers
, compare_sub_matchers
);
2262 /* remove duplicates and specific matches when we match the whole namespace */
2264 compare
= &g_array_index (matcher
->sub_matchers
, SubMatcher
, j
);
2266 for (i
= 1; i
< matcher
->sub_matchers
->len
; i
++)
2268 submatcher
= &g_array_index (matcher
->sub_matchers
, SubMatcher
, i
);
2269 if (sub_matcher_matches (compare
, submatcher
))
2276 *compare
= *submatcher
;
2279 g_array_set_size (matcher
->sub_matchers
, j
+ 1);
2285 * g_file_attribute_matcher_new:
2286 * @attributes: an attribute string to match.
2288 * Creates a new file attribute matcher, which matches attributes
2289 * against a given string. #GFileAttributeMatcher<!-- -->s are reference
2290 * counted structures, and are created with a reference count of 1. If
2291 * the number of references falls to 0, the #GFileAttributeMatcher is
2292 * automatically destroyed.
2294 * The @attribute string should be formatted with specific keys separated
2295 * from namespaces with a double colon. Several "namespace::key" strings may be
2296 * concatenated with a single comma (e.g. "standard::type,standard::is-hidden").
2297 * The wildcard "*" may be used to match all keys and namespaces, or
2298 * "namespace::*" will match all keys in a given namespace.
2300 * Examples of strings to use:
2302 * <title>File Attribute Matcher strings and results</title>
2303 * <tgroup cols='2' align='left'><thead>
2304 * <row><entry> Matcher String </entry><entry> Matches </entry></row></thead>
2306 * <row><entry>"*"</entry><entry>matches all attributes.</entry></row>
2307 * <row><entry>"standard::is-hidden"</entry><entry>matches only the key is-hidden in the standard namespace.</entry></row>
2308 * <row><entry>"standard::type,unix::*"</entry><entry>matches the type key in the standard namespace and
2309 * all keys in the unix namespace.</entry></row>
2313 * Returns: a #GFileAttributeMatcher.
2315 GFileAttributeMatcher
*
2316 g_file_attribute_matcher_new (const char *attributes
)
2321 GFileAttributeMatcher
*matcher
;
2323 if (attributes
== NULL
|| *attributes
== '\0')
2326 matcher
= g_malloc0 (sizeof (GFileAttributeMatcher
));
2328 matcher
->sub_matchers
= g_array_new (FALSE
, FALSE
, sizeof (SubMatcher
));
2330 split
= g_strsplit (attributes
, ",", -1);
2332 for (i
= 0; split
[i
] != NULL
; i
++)
2334 if (strcmp (split
[i
], "*") == 0)
2335 matcher
->all
= TRUE
;
2340 colon
= strstr (split
[i
], "::");
2341 if (colon
!= NULL
&&
2346 s
.id
= lookup_attribute (split
[i
]);
2347 s
.mask
= 0xffffffff;
2354 s
.id
= lookup_namespace (split
[i
]) << NS_POS
;
2355 s
.mask
= NS_MASK
<< NS_POS
;
2358 g_array_append_val (matcher
->sub_matchers
, s
);
2364 matcher
= matcher_optimize (matcher
);
2370 * g_file_attribute_matcher_subtract:
2371 * @matcher: Matcher to subtract from
2372 * @subtract: The matcher to subtract
2374 * Subtracts all attributes of @subtract from @matcher and returns
2375 * a matcher that supports those attributes.
2377 * Note that currently it is not possible to remove a single
2378 * attribute when the @matcher matches the whole namespace - or remove
2379 * a namespace or attribute when the matcher matches everything. This
2380 * is a limitation of the current implementation, but may be fixed
2383 * Returns: A file attribute matcher matching all attributes of
2384 * @matcher that are not matched by @subtract
2386 GFileAttributeMatcher
*
2387 g_file_attribute_matcher_subtract (GFileAttributeMatcher
*matcher
,
2388 GFileAttributeMatcher
*subtract
)
2390 GFileAttributeMatcher
*result
;
2392 SubMatcher
*msub
, *ssub
;
2394 if (matcher
== NULL
)
2396 if (subtract
== NULL
)
2397 return g_file_attribute_matcher_ref (matcher
);
2401 return g_file_attribute_matcher_ref (matcher
);
2403 result
= g_malloc0 (sizeof (GFileAttributeMatcher
));
2405 result
->sub_matchers
= g_array_new (FALSE
, FALSE
, sizeof (SubMatcher
));
2408 g_assert (subtract
->sub_matchers
->len
> 0);
2409 ssub
= &g_array_index (subtract
->sub_matchers
, SubMatcher
, si
);
2411 for (mi
= 0; mi
< matcher
->sub_matchers
->len
; mi
++)
2413 msub
= &g_array_index (matcher
->sub_matchers
, SubMatcher
, mi
);
2416 if (sub_matcher_matches (ssub
, msub
))
2420 if (si
>= subtract
->sub_matchers
->len
)
2423 ssub
= &g_array_index (subtract
->sub_matchers
, SubMatcher
, si
);
2424 if (ssub
->id
<= msub
->id
)
2427 g_array_append_val (result
->sub_matchers
, *msub
);
2430 if (mi
< matcher
->sub_matchers
->len
)
2431 g_array_append_vals (result
->sub_matchers
,
2432 &g_array_index (matcher
->sub_matchers
, SubMatcher
, mi
),
2433 matcher
->sub_matchers
->len
- mi
);
2435 result
= matcher_optimize (result
);
2441 * g_file_attribute_matcher_ref:
2442 * @matcher: a #GFileAttributeMatcher.
2444 * References a file attribute matcher.
2446 * Returns: a #GFileAttributeMatcher.
2448 GFileAttributeMatcher
*
2449 g_file_attribute_matcher_ref (GFileAttributeMatcher
*matcher
)
2453 g_return_val_if_fail (matcher
->ref
> 0, NULL
);
2454 g_atomic_int_inc (&matcher
->ref
);
2460 * g_file_attribute_matcher_unref:
2461 * @matcher: a #GFileAttributeMatcher.
2463 * Unreferences @matcher. If the reference count falls below 1,
2464 * the @matcher is automatically freed.
2468 g_file_attribute_matcher_unref (GFileAttributeMatcher
*matcher
)
2472 g_return_if_fail (matcher
->ref
> 0);
2474 if (g_atomic_int_dec_and_test (&matcher
->ref
))
2476 if (matcher
->sub_matchers
)
2477 g_array_free (matcher
->sub_matchers
, TRUE
);
2485 * g_file_attribute_matcher_matches_only:
2486 * @matcher: a #GFileAttributeMatcher.
2487 * @attribute: a file attribute key.
2489 * Checks if a attribute matcher only matches a given attribute. Always
2490 * returns %FALSE if "*" was used when creating the matcher.
2492 * Returns: %TRUE if the matcher only matches @attribute. %FALSE otherwise.
2495 g_file_attribute_matcher_matches_only (GFileAttributeMatcher
*matcher
,
2496 const char *attribute
)
2498 SubMatcher
*sub_matcher
;
2501 g_return_val_if_fail (attribute
!= NULL
&& *attribute
!= '\0', FALSE
);
2503 if (matcher
== NULL
||
2507 if (matcher
->sub_matchers
->len
!= 1)
2510 id
= lookup_attribute (attribute
);
2512 sub_matcher
= &g_array_index (matcher
->sub_matchers
, SubMatcher
, 0);
2514 return sub_matcher
->id
== id
&&
2515 sub_matcher
->mask
== 0xffffffff;
2519 matcher_matches_id (GFileAttributeMatcher
*matcher
,
2522 SubMatcher
*sub_matchers
;
2525 if (matcher
->sub_matchers
)
2527 sub_matchers
= (SubMatcher
*)matcher
->sub_matchers
->data
;
2528 for (i
= 0; i
< matcher
->sub_matchers
->len
; i
++)
2530 if (sub_matchers
[i
].id
== (id
& sub_matchers
[i
].mask
))
2539 _g_file_attribute_matcher_matches_id (GFileAttributeMatcher
*matcher
,
2542 /* We return a NULL matcher for an empty match string, so handle this */
2543 if (matcher
== NULL
)
2549 return matcher_matches_id (matcher
, id
);
2553 * g_file_attribute_matcher_matches:
2554 * @matcher: a #GFileAttributeMatcher.
2555 * @attribute: a file attribute key.
2557 * Checks if an attribute will be matched by an attribute matcher. If
2558 * the matcher was created with the "*" matching string, this function
2559 * will always return %TRUE.
2561 * Returns: %TRUE if @attribute matches @matcher. %FALSE otherwise.
2564 g_file_attribute_matcher_matches (GFileAttributeMatcher
*matcher
,
2565 const char *attribute
)
2567 g_return_val_if_fail (attribute
!= NULL
&& *attribute
!= '\0', FALSE
);
2569 /* We return a NULL matcher for an empty match string, so handle this */
2570 if (matcher
== NULL
)
2576 return matcher_matches_id (matcher
, lookup_attribute (attribute
));
2579 /* return TRUE -> all */
2581 * g_file_attribute_matcher_enumerate_namespace:
2582 * @matcher: a #GFileAttributeMatcher.
2583 * @ns: a string containing a file attribute namespace.
2585 * Checks if the matcher will match all of the keys in a given namespace.
2586 * This will always return %TRUE if a wildcard character is in use (e.g. if
2587 * matcher was created with "standard::*" and @ns is "standard", or if matcher was created
2588 * using "*" and namespace is anything.)
2590 * TODO: this is awkwardly worded.
2592 * Returns: %TRUE if the matcher matches all of the entries
2593 * in the given @ns, %FALSE otherwise.
2596 g_file_attribute_matcher_enumerate_namespace (GFileAttributeMatcher
*matcher
,
2599 SubMatcher
*sub_matchers
;
2603 g_return_val_if_fail (ns
!= NULL
&& *ns
!= '\0', FALSE
);
2605 /* We return a NULL matcher for an empty match string, so handle this */
2606 if (matcher
== NULL
)
2612 ns_id
= lookup_namespace (ns
) << NS_POS
;
2614 if (matcher
->sub_matchers
)
2616 sub_matchers
= (SubMatcher
*)matcher
->sub_matchers
->data
;
2617 for (i
= 0; i
< matcher
->sub_matchers
->len
; i
++)
2619 if (sub_matchers
[i
].id
== ns_id
)
2624 matcher
->iterator_ns
= ns_id
;
2625 matcher
->iterator_pos
= 0;
2631 * g_file_attribute_matcher_enumerate_next:
2632 * @matcher: a #GFileAttributeMatcher.
2634 * Gets the next matched attribute from a #GFileAttributeMatcher.
2636 * Returns: a string containing the next attribute or %NULL if
2637 * no more attribute exist.
2640 g_file_attribute_matcher_enumerate_next (GFileAttributeMatcher
*matcher
)
2643 SubMatcher
*sub_matcher
;
2645 /* We return a NULL matcher for an empty match string, so handle this */
2646 if (matcher
== NULL
)
2651 i
= matcher
->iterator_pos
++;
2653 if (matcher
->sub_matchers
== NULL
)
2656 if (i
< matcher
->sub_matchers
->len
)
2657 sub_matcher
= &g_array_index (matcher
->sub_matchers
, SubMatcher
, i
);
2661 if (sub_matcher
->mask
== 0xffffffff &&
2662 (sub_matcher
->id
& (NS_MASK
<< NS_POS
)) == matcher
->iterator_ns
)
2663 return get_attribute_for_id (sub_matcher
->id
);
2668 * g_file_attribute_matcher_to_string:
2669 * @matcher: (allow-none): a #GFileAttributeMatcher.
2671 * Prints what the matcher is matching against. The format will be
2672 * equal to the format passed to g_file_attribute_matcher_new().
2673 * The output however, might not be identical, as the matcher may
2674 * decide to use a different order or omit needless parts.
2676 * Returns: a string describing the attributes the matcher matches
2677 * against or %NULL if @matcher was %NULL.
2682 g_file_attribute_matcher_to_string (GFileAttributeMatcher
*matcher
)
2687 if (matcher
== NULL
)
2691 return g_strdup ("*");
2693 string
= g_string_new ("");
2694 for (i
= 0; i
< matcher
->sub_matchers
->len
; i
++)
2696 SubMatcher
*submatcher
= &g_array_index (matcher
->sub_matchers
, SubMatcher
, i
);
2699 g_string_append_c (string
, ',');
2701 g_string_append (string
, get_attribute_for_id (submatcher
->id
));
2704 return g_string_free (string
, FALSE
);