X-Git-Url: http://review.tizen.org/git/?a=blobdiff_plain;f=gio%2Fgfileattribute.c;h=09f01c00af46fde66231a2676050d2584ed7e9c4;hb=c8d10470939847069b1a346d4c44f2adde3469f6;hp=d9492be470ec511263548107f12f85593c6d882f;hpb=6f605509fd7fc67c33fbf56cf34f98c19e1b2058;p=platform%2Fupstream%2Fglib.git diff --git a/gio/gfileattribute.c b/gio/gfileattribute.c index d9492be..09f01c0 100644 --- a/gio/gfileattribute.c +++ b/gio/gfileattribute.c @@ -1,5 +1,5 @@ /* GIO - GLib Input, Output and Streaming Library - * + * * Copyright (C) 2006-2007 Red Hat, Inc. * * This library is free software; you can redistribute it and/or @@ -13,211 +13,168 @@ * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General - * Public License along with this library; if not, write to the - * Free Software Foundation, Inc., 59 Temple Place, Suite 330, - * Boston, MA 02111-1307, USA. + * Public License along with this library; if not, see . * * Author: Alexander Larsson */ -#include +#include "config.h" #include #include "gfileattribute.h" +#include "gfileattribute-priv.h" #include #include "glibintl.h" -#include "gioalias.h" /** * SECTION:gfileattribute * @short_description: Key-Value Paired File Attributes + * @include: gio/gio.h * @see_also: #GFile, #GFileInfo - * - * File attributes in GIO consist of a list of key-value pairs. - * + * + * File attributes in GIO consist of a list of key-value pairs. + * * Keys are strings that contain a key namespace and a key name, separated - * by a colon, e.g. "namespace:keyname". Namespaces are included to sort - * key-value pairs by namespaces for relevance. Keys can be searched - * for using wildcards, e.g. "std:*" will return all of the keys in the - * "std" namespace. - * - * Values are stored within the list in #GFileAttributeValue structures. - * Values can store different types, listed in the enum #GFileAttributeType. - * Upon creation of a #GFileAttributeValue, the type will be set to - * %G_FILE_ATTRIBUTE_TYPE_INVALID. - * - * The Key-value list is stored within the #GFile structure as a - * #GFileAttributeInfoList. This list is queryable by key names + * by a colon, e.g. "namespace::keyname". Namespaces are included to sort + * key-value pairs by namespaces for relevance. Keys can be retrived + * using wildcards, e.g. "standard::*" will return all of the keys in the + * "standard" namespace. + * + * The list of possible attributes for a filesystem (pointed to by a #GFile) is + * available as a #GFileAttributeInfoList. This list is queryable by key names * as indicated earlier. - * - * Classes that implement #GFileIface will create a #GFileAttributeInfoList and - * install default keys and values for their given file system, architecture, - * and other possible implementation details (e.g., on a UNIX system, a file - * attribute key will be registered for the user id for a given file). Other - * attributes can be appended to a #GFileAttributeList later by - * g_file_attribute_info_list_add(). - * - * - * - * GFileAttributes Namespaces - * - * NamspaceDescription - * - * - * "std"The "Standard" namespace. General file - * information that any application may need should be put in this namespace. - * Examples include the file's name, type, and size. - * "etag"The "Entity Tag" - * namespace. Currently, the only key in this namespace is "value", which contains - * the value of the current entity tag. - * "id"The "Identification" namespace. This - * namespace is used by file managers and applications that list directories - * to check for loops and to uniquely identify files. - * "access"The "Access" namespace. Used to check - * if a user has the proper privilidges to access files and perform - * file operations. Keys in this namespace are made to be generic - * and easily understood, e.g. the "can_read" key is %TRUE if - * the current user has permission to read the file. UNIX permissions and - * NTFS ACLs in Windows should be mapped to these values. - * "mountable"The "Mountable" namespace. Includes - * simple boolean keys for checking if a file or path supports mount operations, e.g. - * mount, unmount, eject. - * "time"The "Time" namespace. Includes file - * access, changed, created times. - * "unix"The "Unix" namespace. Includes UNIX-specific - * information and may not be available for all files. Examples include - * the UNIX "UID", "GID", etc. - * "dos"The "DOS" namespace. Includes DOS-specific - * information and may not be available for all files. Examples include - * "is_system" for checking if a file is marked as a system file, and "is_archive" - * for checking if a file is marked as an archive file. - * "owner"The "Owner" namespace. Includes information - * about who owns a file. May not be available for all file systems. Examples include - * "user" for getting the user name of the file owner. - * "thumbnail"The "Thumbnail" namespace. Includes - * information about file thumbnails and their location within the file system. Exaples of - * keys in this namespace include "path" to get the location of a thumbnail, and "failed" - * to check if thumbnailing failed. - * "fs"The "Filesystem" namespace. Gets information - * about the file system where a file is located, such as its type, how much - * space is left available, and the overall size of the file system. - * "gvfs"The "GVFS" namespace. Keys in this namespace - * contain information about the current GVFS backend in use. - * - * - *
- *
- * - * More namespaces can be added from GIO modules or by individual applications. + * + * Information is stored within the list in #GFileAttributeInfo structures. + * The info structure can store different types, listed in the enum + * #GFileAttributeType. Upon creation of a #GFileAttributeInfo, the type will + * be set to %G_FILE_ATTRIBUTE_TYPE_INVALID. + * + * Classes that implement #GFileIface will create a #GFileAttributeInfoList and + * install default keys and values for their given file system, architecture, + * and other possible implementation details (e.g., on a UNIX system, a file + * attribute key will be registered for the user id for a given file). + * + * ## Default Namespaces + * + * - `"standard"`: The "Standard" namespace. General file information that + * any application may need should be put in this namespace. Examples + * include the file's name, type, and size. + * - `"etag`: The [Entity Tag][gfile-etag] namespace. Currently, the only key + * in this namespace is "value", which contains the value of the current + * entity tag. + * - `"id"`: The "Identification" namespace. This namespace is used by file + * managers and applications that list directories to check for loops and + * to uniquely identify files. + * - `"access"`: The "Access" namespace. Used to check if a user has the + * proper privileges to access files and perform file operations. Keys in + * this namespace are made to be generic and easily understood, e.g. the + * "can_read" key is %TRUE if the current user has permission to read the + * file. UNIX permissions and NTFS ACLs in Windows should be mapped to + * these values. + * - `"mountable"`: The "Mountable" namespace. Includes simple boolean keys + * for checking if a file or path supports mount operations, e.g. mount, + * unmount, eject. These are used for files of type %G_FILE_TYPE_MOUNTABLE. + * - `"time"`: The "Time" namespace. Includes file access, changed, created + * times. + * - `"unix"`: The "Unix" namespace. Includes UNIX-specific information and + * may not be available for all files. Examples include the UNIX "UID", + * "GID", etc. + * - `"dos"`: The "DOS" namespace. Includes DOS-specific information and may + * not be available for all files. Examples include "is_system" for checking + * if a file is marked as a system file, and "is_archive" for checking if a + * file is marked as an archive file. + * - `"owner"`: The "Owner" namespace. Includes information about who owns a + * file. May not be available for all file systems. Examples include "user" + * for getting the user name of the file owner. This information is often + * mapped from some backend specific data such as a UNIX UID. + * - `"thumbnail"`: The "Thumbnail" namespace. Includes information about file + * thumbnails and their location within the file system. Examples of keys in + * this namespace include "path" to get the location of a thumbnail, "failed" + * to check if thumbnailing of the file failed, and "is-valid" to check if + * the thumbnail is outdated. + * - `"filesystem"`: The "Filesystem" namespace. Gets information about the + * file system where a file is located, such as its type, how much space is + * left available, and the overall size of the file system. + * - `"gvfs"`: The "GVFS" namespace. Keys in this namespace contain information + * about the current GVFS backend in use. + * - `"xattr"`: The "xattr" namespace. Gets information about extended + * user attributes. See attr(5). The "user." prefix of the extended user + * attribute name is stripped away when constructing keys in this namespace, + * e.g. "xattr::mime_type" for the extended attribute with the name + * "user.mime_type". Note that this information is only available if + * GLib has been built with extended attribute support. + * - `"xattr-sys"`: The "xattr-sys" namespace. Gets information about + * extended attributes which are not user-specific. See attr(5). Note + * that this information is only available if GLib has been built with + * extended attribute support. + * - `"selinux"`: The "SELinux" namespace. Includes information about the + * SELinux context of files. Note that this information is only available + * if GLib has been built with SELinux support. + * + * Please note that these are not all of the possible namespaces. + * More namespaces can be added from GIO modules or by individual applications. * For more information about writing GIO modules, see #GIOModule. - * - * - * GFileAttributes Built-in Keys and Value Types - * - * Enum ValueNamespace:KeyValue Type - * - * %G_FILE_ATTRIBUTE_STD_TYPEstd:typeuint32 (#GFileType) - * %G_FILE_ATTRIBUTE_STD_IS_HIDDENstd:is_hiddenboolean - * %G_FILE_ATTRIBUTE_STD_IS_BACKUPstd:is_backupboolean - * %G_FILE_ATTRIBUTE_STD_IS_SYMLINKstd:is_symlinkboolean - * %G_FILE_ATTRIBUTE_STD_IS_VIRTUALstd:is_virtualboolean - * %G_FILE_ATTRIBUTE_STD_NAMEstd:namebyte string - * %G_FILE_ATTRIBUTE_STD_DISPLAY_NAMEstd:display_namestring - * %G_FILE_ATTRIBUTE_STD_EDIT_NAMEstd:edit_namestring - * %G_FILE_ATTRIBUTE_STD_ICONstd:iconobject (#GIcon) - * %G_FILE_ATTRIBUTE_STD_CONTENT_TYPEstd:content_typestring - * %G_FILE_ATTRIBUTE_STD_FAST_CONTENT_TYPEstd:fast_content_typestring - * %G_FILE_ATTRIBUTE_STD_SIZEstd:sizeuint64 - * %G_FILE_ATTRIBUTE_STD_SYMLINK_TARGETstd:symlink_targetbyte string - * %G_FILE_ATTRIBUTE_STD_TARGET_URIstd:target_uristring - * %G_FILE_ATTRIBUTE_STD_SORT_ORDERstd:sort_orderint32 - * %G_FILE_ATTRIBUTE_ETAG_VALUEetag:valuestring - * %G_FILE_ATTRIBUTE_ID_FILEid:filestring - * %G_FILE_ATTRIBUTE_ID_FSid:fsstring - * %G_FILE_ATTRIBUTE_ACCESS_CAN_READaccess:can_readboolean - * %G_FILE_ATTRIBUTE_ACCESS_CAN_WRITEaccess:can_writeboolean - * %G_FILE_ATTRIBUTE_ACCESS_CAN_EXECUTEaccess:can_executeboolean - * %G_FILE_ATTRIBUTE_ACCESS_CAN_DELETEaccess:can_deleteboolean - * %G_FILE_ATTRIBUTE_ACCESS_CAN_TRASHaccess:can_trashboolean - * %G_FILE_ATTRIBUTE_ACCESS_CAN_RENAMEaccess:can_renameboolean - * %G_FILE_ATTRIBUTE_MOUNTABLE_CAN_MOUNTmountable:can_mountboolean - * %G_FILE_ATTRIBUTE_MOUNTABLE_CAN_UNMOUNTmountable:can_unmountboolean - * %G_FILE_ATTRIBUTE_MOUNTABLE_CAN_EJECTmountable:can_ejectboolean - * %G_FILE_ATTRIBUTE_MOUNTABLE_UNIX_DEVICEmountable:unix_deviceuint32 - * %G_FILE_ATTRIBUTE_MOUNTABLE_HAL_UDImountable:hal_udistring - * %G_FILE_ATTRIBUTE_TIME_MODIFIEDtime:modifieduint64 - * %G_FILE_ATTRIBUTE_TIME_MODIFIED_USECtime:modified_usecuint32 - * %G_FILE_ATTRIBUTE_TIME_ACCESStime:accessuint64 - * %G_FILE_ATTRIBUTE_TIME_ACCESS_USECtime:access_usecuint32 - * %G_FILE_ATTRIBUTE_TIME_CHANGEDtime:changeduint64 - * %G_FILE_ATTRIBUTE_TIME_CHANGED_USECtime:changed_usecuint32 - * %G_FILE_ATTRIBUTE_TIME_CREATEDtime:createduint64 - * %G_FILE_ATTRIBUTE_TIME_CREATED_USECtime:created_usecuint32 - * %G_FILE_ATTRIBUTE_UNIX_DEVICEunix:deviceuint32 - * %G_FILE_ATTRIBUTE_UNIX_INODEunix:inodeuint64 - * %G_FILE_ATTRIBUTE_UNIX_MODEunix:modeuint32 - * %G_FILE_ATTRIBUTE_UNIX_NLINKunix:nlinkuint32 - * %G_FILE_ATTRIBUTE_UNIX_UIDunix:uiduint32 - * %G_FILE_ATTRIBUTE_UNIX_GIDunix:giduint32 - * %G_FILE_ATTRIBUTE_UNIX_RDEVunix:rdevuint32 - * %G_FILE_ATTRIBUTE_UNIX_BLOCK_SIZEunix:block_sizeuint32 - * %G_FILE_ATTRIBUTE_UNIX_BLOCKSunix:blocksuint64 - * %G_FILE_ATTRIBUTE_UNIX_IS_MOUNTPOINTunix:is_mountpointboolean - * %G_FILE_ATTRIBUTE_DOS_IS_ARCHIVEdos:is_archiveboolean - * %G_FILE_ATTRIBUTE_DOS_IS_SYSTEMdos:is_systemboolean - * %G_FILE_ATTRIBUTE_OWNER_USERowner:userstring - * %G_FILE_ATTRIBUTE_OWNER_USER_REALowner:user_realstring - * %G_FILE_ATTRIBUTE_OWNER_GROUPowner:groupstring - * %G_FILE_ATTRIBUTE_THUMBNAIL_PATHthumbnail:pathbytestring - * %G_FILE_ATTRIBUTE_THUMBNAILING_FAILEDthumbnail:failedboolean - * %G_FILE_ATTRIBUTE_FS_SIZEfs:sizeuint64 - * %G_FILE_ATTRIBUTE_FS_FREEfs:freeuint64 - * %G_FILE_ATTRIBUTE_FS_TYPEfs:typestring - * %G_FILE_ATTRIBUTE_FS_READONLYfs:readonlyboolean - * %G_FILE_ATTRIBUTE_GVFS_BACKENDgvfs:backendstring - *
- * - **/ + * + * + * + * ## Default Keys + * + * For a list of the built-in keys and their types, see the + * [GFileInfo][GFileInfo] documentation. + * + * Note that there are no predefined keys in the "xattr" and "xattr-sys" + * namespaces. Keys for the "xattr" namespace are constructed by stripping + * away the "user." prefix from the extended user attribute, and prepending + * "xattr::". Keys for the "xattr-sys" namespace are constructed by + * concatenating "xattr-sys::" with the extended attribute name. All extended + * attribute values are returned as hex-encoded strings in which bytes outside + * the ASCII range are encoded as escape sequences of the form \x`nn` + * where `nn` is a 2-digit hexadecimal number. + */ /** - * g_file_attribute_value_free: - * @attr: a #GFileAttributeValue. - * + * _g_file_attribute_value_free: + * @attr: a #GFileAttributeValue. + * * Frees the memory used by @attr. * **/ void -g_file_attribute_value_free (GFileAttributeValue *attr) +_g_file_attribute_value_free (GFileAttributeValue *attr) { g_return_if_fail (attr != NULL); - g_file_attribute_value_clear (attr); + _g_file_attribute_value_clear (attr); g_free (attr); } /** - * g_file_attribute_value_clear: + * _g_file_attribute_value_clear: * @attr: a #GFileAttributeValue. * - * Clears the value of @attr and sets its type to + * Clears the value of @attr and sets its type to * %G_FILE_ATTRIBUTE_TYPE_INVALID. - * + * **/ void -g_file_attribute_value_clear (GFileAttributeValue *attr) +_g_file_attribute_value_clear (GFileAttributeValue *attr) { g_return_if_fail (attr != NULL); if (attr->type == G_FILE_ATTRIBUTE_TYPE_STRING || attr->type == G_FILE_ATTRIBUTE_TYPE_BYTE_STRING) g_free (attr->u.string); - + + if (attr->type == G_FILE_ATTRIBUTE_TYPE_STRINGV) + g_strfreev (attr->u.stringv); + if (attr->type == G_FILE_ATTRIBUTE_TYPE_OBJECT && attr->u.obj != NULL) g_object_unref (attr->u.obj); - + attr->type = G_FILE_ATTRIBUTE_TYPE_INVALID; } @@ -225,37 +182,40 @@ g_file_attribute_value_clear (GFileAttributeValue *attr) * g_file_attribute_value_set: * @attr: a #GFileAttributeValue to set the value in. * @new_value: a #GFileAttributeValue to get the value from. - * + * * Sets an attribute's value from another attribute. **/ void -g_file_attribute_value_set (GFileAttributeValue *attr, - const GFileAttributeValue *new_value) +_g_file_attribute_value_set (GFileAttributeValue *attr, + const GFileAttributeValue *new_value) { g_return_if_fail (attr != NULL); g_return_if_fail (new_value != NULL); - g_file_attribute_value_clear (attr); + _g_file_attribute_value_clear (attr); *attr = *new_value; if (attr->type == G_FILE_ATTRIBUTE_TYPE_STRING || attr->type == G_FILE_ATTRIBUTE_TYPE_BYTE_STRING) attr->u.string = g_strdup (attr->u.string); - + + if (attr->type == G_FILE_ATTRIBUTE_TYPE_STRINGV) + attr->u.stringv = g_strdupv (attr->u.stringv); + if (attr->type == G_FILE_ATTRIBUTE_TYPE_OBJECT && attr->u.obj != NULL) g_object_ref (attr->u.obj); } /** - * g_file_attribute_value_new: - * + * _g_file_attribute_value_new: + * * Creates a new file attribute. - * + * * Returns: a #GFileAttributeValue. **/ GFileAttributeValue * -g_file_attribute_value_new (void) +_g_file_attribute_value_new (void) { GFileAttributeValue *attr; @@ -264,17 +224,32 @@ g_file_attribute_value_new (void) return attr; } +gpointer +_g_file_attribute_value_peek_as_pointer (GFileAttributeValue *attr) +{ + switch (attr->type) { + case G_FILE_ATTRIBUTE_TYPE_STRING: + case G_FILE_ATTRIBUTE_TYPE_BYTE_STRING: + return attr->u.string; + case G_FILE_ATTRIBUTE_TYPE_STRINGV: + return attr->u.stringv; + case G_FILE_ATTRIBUTE_TYPE_OBJECT: + return attr->u.obj; + default: + return (gpointer) &attr->u; + } +} /** * g_file_attribute_value_dup: * @other: a #GFileAttributeValue to duplicate. - * + * * Duplicates a file attribute. - * + * * Returns: a duplicate of the @other. **/ GFileAttributeValue * -g_file_attribute_value_dup (const GFileAttributeValue *other) +_g_file_attribute_value_dup (const GFileAttributeValue *other) { GFileAttributeValue *attr; @@ -282,10 +257,14 @@ g_file_attribute_value_dup (const GFileAttributeValue *other) attr = g_new (GFileAttributeValue, 1); attr->type = G_FILE_ATTRIBUTE_TYPE_INVALID; - g_file_attribute_value_set (attr, other); + _g_file_attribute_value_set (attr, other); return attr; } +G_DEFINE_BOXED_TYPE (GFileAttributeInfoList, g_file_attribute_info_list, + g_file_attribute_info_list_dup, + g_file_attribute_info_list_unref) + static gboolean valid_char (char c) { @@ -299,17 +278,17 @@ escape_byte_string (const char *str) int num_invalid, i; char *escaped_val, *p; unsigned char c; - char *hex_digits = "0123456789abcdef"; - + const char hex_digits[] = "0123456789abcdef"; + len = strlen (str); - + num_invalid = 0; for (i = 0; i < len; i++) { if (!valid_char (str[i])) num_invalid++; } - + if (num_invalid == 0) return g_strdup (str); else @@ -326,7 +305,7 @@ escape_byte_string (const char *str) { *p++ = '\\'; *p++ = 'x'; - *p++ = hex_digits[(c >> 8) & 0xf]; + *p++ = hex_digits[(c >> 4) & 0xf]; *p++ = hex_digits[c & 0xf]; } } @@ -336,18 +315,20 @@ escape_byte_string (const char *str) } /** - * g_file_attribute_value_as_string: + * _g_file_attribute_value_as_string: * @attr: a #GFileAttributeValue. * * Converts a #GFileAttributeValue to a string for display. * The returned string should be freed when no longer needed. - * - * Returns: a string from the @attr, %NULL on error, or "<invalid>" + * + * Returns: a string from the @attr, %NULL on error, or "" * if @attr is of type %G_FILE_ATTRIBUTE_TYPE_INVALID. - **/ + */ char * -g_file_attribute_value_as_string (const GFileAttributeValue *attr) +_g_file_attribute_value_as_string (const GFileAttributeValue *attr) { + GString *s; + int i; char *str; g_return_val_if_fail (attr != NULL, NULL); @@ -357,6 +338,17 @@ g_file_attribute_value_as_string (const GFileAttributeValue *attr) case G_FILE_ATTRIBUTE_TYPE_STRING: str = g_strdup (attr->u.string); break; + case G_FILE_ATTRIBUTE_TYPE_STRINGV: + s = g_string_new ("["); + for (i = 0; attr->u.stringv[i] != NULL; i++) + { + g_string_append (s, attr->u.stringv[i]); + if (attr->u.stringv[i+1] != NULL) + g_string_append (s, ", "); + } + g_string_append (s, "]"); + str = g_string_free (s, FALSE); + break; case G_FILE_ATTRIBUTE_TYPE_BYTE_STRING: str = escape_byte_string (attr->u.string); break; @@ -380,26 +372,29 @@ g_file_attribute_value_as_string (const GFileAttributeValue *attr) ((GTypeInstance *) attr->u.obj), attr->u.obj); break; + case G_FILE_ATTRIBUTE_TYPE_INVALID: + str = g_strdup (""); + break; default: g_warning ("Invalid type in GFileInfo attribute"); str = g_strdup (""); break; } - + return str; } /** - * g_file_attribute_value_get_string: + * _g_file_attribute_value_get_string: * @attr: a #GFileAttributeValue. - * + * * Gets the string from a file attribute value. If the value is not the * right type then %NULL will be returned. - * - * Returns: the string value contained within the attribute, or %NULL. - **/ + * + * Returns: the UTF-8 string value contained within the attribute, or %NULL. + */ const char * -g_file_attribute_value_get_string (const GFileAttributeValue *attr) +_g_file_attribute_value_get_string (const GFileAttributeValue *attr) { if (attr == NULL) return NULL; @@ -410,16 +405,16 @@ g_file_attribute_value_get_string (const GFileAttributeValue *attr) } /** - * g_file_attribute_value_get_byte_string: + * _g_file_attribute_value_get_byte_string: * @attr: a #GFileAttributeValue. - * + * * Gets the byte string from a file attribute value. If the value is not the * right type then %NULL will be returned. - * + * * Returns: the byte string contained within the attribute or %NULL. - **/ + */ const char * -g_file_attribute_value_get_byte_string (const GFileAttributeValue *attr) +_g_file_attribute_value_get_byte_string (const GFileAttributeValue *attr) { if (attr == NULL) return NULL; @@ -428,18 +423,29 @@ g_file_attribute_value_get_byte_string (const GFileAttributeValue *attr) return attr->u.string; } - + +char ** +_g_file_attribute_value_get_stringv (const GFileAttributeValue *attr) +{ + if (attr == NULL) + return NULL; + + g_return_val_if_fail (attr->type == G_FILE_ATTRIBUTE_TYPE_STRINGV, NULL); + + return attr->u.stringv; +} + /** - * g_file_attribute_value_get_boolean: + * _g_file_attribute_value_get_boolean: * @attr: a #GFileAttributeValue. - * + * * Gets the boolean value from a file attribute value. If the value is not the * right type then %FALSE will be returned. - * + * * Returns: the boolean value contained within the attribute, or %FALSE. - **/ + */ gboolean -g_file_attribute_value_get_boolean (const GFileAttributeValue *attr) +_g_file_attribute_value_get_boolean (const GFileAttributeValue *attr) { if (attr == NULL) return FALSE; @@ -448,18 +454,18 @@ g_file_attribute_value_get_boolean (const GFileAttributeValue *attr) return attr->u.boolean; } - + /** - * g_file_attribute_value_get_uint32: + * _g_file_attribute_value_get_uint32: * @attr: a #GFileAttributeValue. - * - * Gets the unsigned 32-bit integer from a file attribute value. If the value - * is not the right type then %0 will be returned. - * - * Returns: the unsigned 32-bit integer from the attribute, or %0. - **/ + * + * Gets the unsigned 32-bit integer from a file attribute value. If the value + * is not the right type then 0 will be returned. + * + * Returns: the unsigned 32-bit integer from the attribute, or 0. + */ guint32 -g_file_attribute_value_get_uint32 (const GFileAttributeValue *attr) +_g_file_attribute_value_get_uint32 (const GFileAttributeValue *attr) { if (attr == NULL) return 0; @@ -470,16 +476,16 @@ g_file_attribute_value_get_uint32 (const GFileAttributeValue *attr) } /** - * g_file_attribute_value_get_int32: + * _g_file_attribute_value_get_int32: * @attr: a #GFileAttributeValue. - * - * Gets the signed 32-bit integer from a file attribute value. If the value - * is not the right type then %0 will be returned. - * - * Returns: the signed 32-bit integer from the attribute, or %0. - **/ + * + * Gets the signed 32-bit integer from a file attribute value. If the value + * is not the right type then 0 will be returned. + * + * Returns: the signed 32-bit integer from the attribute, or 0. + */ gint32 -g_file_attribute_value_get_int32 (const GFileAttributeValue *attr) +_g_file_attribute_value_get_int32 (const GFileAttributeValue *attr) { if (attr == NULL) return 0; @@ -490,16 +496,16 @@ g_file_attribute_value_get_int32 (const GFileAttributeValue *attr) } /** - * g_file_attribute_value_get_uint64: + * _g_file_attribute_value_get_uint64: * @attr: a #GFileAttributeValue. - * - * Gets the unsigned 64-bit integer from a file attribute value. If the value - * is not the right type then %0 will be returned. - * - * Returns: the unsigned 64-bit integer from the attribute, or %0. - **/ + * + * Gets the unsigned 64-bit integer from a file attribute value. If the value + * is not the right type then 0 will be returned. + * + * Returns: the unsigned 64-bit integer from the attribute, or 0. + */ guint64 -g_file_attribute_value_get_uint64 (const GFileAttributeValue *attr) +_g_file_attribute_value_get_uint64 (const GFileAttributeValue *attr) { if (attr == NULL) return 0; @@ -510,16 +516,16 @@ g_file_attribute_value_get_uint64 (const GFileAttributeValue *attr) } /** - * g_file_attribute_value_get_int64: + * _g_file_attribute_value_get_int64: * @attr: a #GFileAttributeValue. - * - * Gets the signed 64-bit integer from a file attribute value. If the value - * is not the right type then %0 will be returned. - * - * Returns: the signed 64-bit integer from the attribute, or %0. - **/ + * + * Gets the signed 64-bit integer from a file attribute value. If the value + * is not the right type then 0 will be returned. + * + * Returns: the signed 64-bit integer from the attribute, or 0. + */ gint64 -g_file_attribute_value_get_int64 (const GFileAttributeValue *attr) +_g_file_attribute_value_get_int64 (const GFileAttributeValue *attr) { if (attr == NULL) return 0; @@ -530,16 +536,16 @@ g_file_attribute_value_get_int64 (const GFileAttributeValue *attr) } /** - * g_file_attribute_value_get_object: + * _g_file_attribute_value_get_object: * @attr: a #GFileAttributeValue. - * - * Gets the GObject from a file attribute value. If the value + * + * Gets the GObject from a file attribute value. If the value * is not the right type then %NULL will be returned. - * - * Returns: the GObject from the attribute, or %0. + * + * Returns: the GObject from the attribute, or %NULL. **/ GObject * -g_file_attribute_value_get_object (const GFileAttributeValue *attr) +_g_file_attribute_value_get_object (const GFileAttributeValue *attr) { if (attr == NULL) return NULL; @@ -548,159 +554,226 @@ g_file_attribute_value_get_object (const GFileAttributeValue *attr) return attr->u.obj; } - + + +void +_g_file_attribute_value_set_from_pointer (GFileAttributeValue *value, + GFileAttributeType type, + gpointer value_p, + gboolean dup) +{ + _g_file_attribute_value_clear (value); + value->type = type; + switch (type) + { + case G_FILE_ATTRIBUTE_TYPE_STRING: + case G_FILE_ATTRIBUTE_TYPE_BYTE_STRING: + if (dup) + value->u.string = g_strdup (value_p); + else + value->u.string = value_p; + break; + + case G_FILE_ATTRIBUTE_TYPE_STRINGV: + if (dup) + value->u.stringv = g_strdupv (value_p); + else + value->u.stringv = value_p; + break; + + case G_FILE_ATTRIBUTE_TYPE_OBJECT: + if (dup) + value->u.obj = g_object_ref (value_p); + else + value->u.obj = value_p; + break; + + case G_FILE_ATTRIBUTE_TYPE_BOOLEAN: + value->u.boolean = *(gboolean *)value_p; + break; + + case G_FILE_ATTRIBUTE_TYPE_UINT32: + value->u.uint32 = *(guint32 *)value_p; + break; + + case G_FILE_ATTRIBUTE_TYPE_INT32: + value->u.int32 = *(gint32 *)value_p; + break; + + case G_FILE_ATTRIBUTE_TYPE_UINT64: + value->u.uint64 = *(guint64 *)value_p; + break; + + case G_FILE_ATTRIBUTE_TYPE_INT64: + value->u.int64 = *(gint64 *)value_p; + break; + + case G_FILE_ATTRIBUTE_TYPE_INVALID: + break; + + default: + g_warning ("Unknown type specified in g_file_info_set_attribute\n"); + break; + } +} + /** - * g_file_attribute_value_set_string: + * _g_file_attribute_value_set_string: * @attr: a #GFileAttributeValue. - * @string: a string to set within the type. - * - * Sets the attribute value to a given string. - * - **/ + * @string: a UTF-8 string to set within the type. + * + * Sets the attribute value to a given UTF-8 string. + */ void -g_file_attribute_value_set_string (GFileAttributeValue *attr, - const char *string) +_g_file_attribute_value_set_string (GFileAttributeValue *attr, + const char *string) { g_return_if_fail (attr != NULL); g_return_if_fail (string != NULL); - g_file_attribute_value_clear (attr); + _g_file_attribute_value_clear (attr); attr->type = G_FILE_ATTRIBUTE_TYPE_STRING; attr->u.string = g_strdup (string); } /** - * g_file_attribute_value_set_byte_string: + * _g_file_attribute_value_set_byte_string: * @attr: a #GFileAttributeValue. * @string: a byte string to set within the type. - * + * * Sets the attribute value to a given byte string. - * - **/ + */ void -g_file_attribute_value_set_byte_string (GFileAttributeValue *attr, - const char *string) +_g_file_attribute_value_set_byte_string (GFileAttributeValue *attr, + const char *string) { g_return_if_fail (attr != NULL); g_return_if_fail (string != NULL); - g_file_attribute_value_clear (attr); + _g_file_attribute_value_clear (attr); attr->type = G_FILE_ATTRIBUTE_TYPE_BYTE_STRING; attr->u.string = g_strdup (string); } +void +_g_file_attribute_value_set_stringv (GFileAttributeValue *attr, + char **value) +{ + g_return_if_fail (attr != NULL); + g_return_if_fail (value != NULL); + + _g_file_attribute_value_clear (attr); + attr->type = G_FILE_ATTRIBUTE_TYPE_STRINGV; + attr->u.stringv = g_strdupv (value); +} + + /** - * g_file_attribute_value_set_boolean: + * _g_file_attribute_value_set_boolean: * @attr: a #GFileAttributeValue. * @value: a #gboolean to set within the type. - * - * Sets the attribute value to the given boolean value. - * - **/ + * + * Sets the attribute value to the given boolean value. + */ void -g_file_attribute_value_set_boolean (GFileAttributeValue *attr, - gboolean value) +_g_file_attribute_value_set_boolean (GFileAttributeValue *attr, + gboolean value) { g_return_if_fail (attr != NULL); - g_file_attribute_value_clear (attr); + _g_file_attribute_value_clear (attr); attr->type = G_FILE_ATTRIBUTE_TYPE_BOOLEAN; attr->u.boolean = !!value; } /** - * g_file_attribute_value_set_uint32: + * _g_file_attribute_value_set_uint32: * @attr: a #GFileAttributeValue. * @value: a #guint32 to set within the type. - * + * * Sets the attribute value to the given unsigned 32-bit integer. - * - **/ + */ void -g_file_attribute_value_set_uint32 (GFileAttributeValue *attr, - guint32 value) +_g_file_attribute_value_set_uint32 (GFileAttributeValue *attr, + guint32 value) { g_return_if_fail (attr != NULL); - g_file_attribute_value_clear (attr); + _g_file_attribute_value_clear (attr); attr->type = G_FILE_ATTRIBUTE_TYPE_UINT32; attr->u.uint32 = value; } /** - * g_file_attribute_value_set_int32: + * _g_file_attribute_value_set_int32: * @attr: a #GFileAttributeValue. * @value: a #gint32 to set within the type. - * + * * Sets the attribute value to the given signed 32-bit integer. - * - **/ + */ void -g_file_attribute_value_set_int32 (GFileAttributeValue *attr, - gint32 value) +_g_file_attribute_value_set_int32 (GFileAttributeValue *attr, + gint32 value) { g_return_if_fail (attr != NULL); - g_file_attribute_value_clear (attr); + _g_file_attribute_value_clear (attr); attr->type = G_FILE_ATTRIBUTE_TYPE_INT32; attr->u.int32 = value; } /** - * g_file_attribute_value_set_uint64: + * _g_file_attribute_value_set_uint64: * @attr: a #GFileAttributeValue. * @value: a #guint64 to set within the type. - * + * * Sets the attribute value to a given unsigned 64-bit integer. - * - **/ + */ void -g_file_attribute_value_set_uint64 (GFileAttributeValue *attr, - guint64 value) +_g_file_attribute_value_set_uint64 (GFileAttributeValue *attr, + guint64 value) { g_return_if_fail (attr != NULL); - g_file_attribute_value_clear (attr); + _g_file_attribute_value_clear (attr); attr->type = G_FILE_ATTRIBUTE_TYPE_UINT64; attr->u.uint64 = value; } /** - * g_file_attribute_value_set_int64: + * _g_file_attribute_value_set_int64: * @attr: a #GFileAttributeValue. * @value: a #gint64 to set within the type. - * - * Sets the attribute value to a given signed 64-bit integer. - * - **/ + * + * Sets the attribute value to a given signed 64-bit integer. + */ void -g_file_attribute_value_set_int64 (GFileAttributeValue *attr, - gint64 value) +_g_file_attribute_value_set_int64 (GFileAttributeValue *attr, + gint64 value) { g_return_if_fail (attr != NULL); - g_file_attribute_value_clear (attr); + _g_file_attribute_value_clear (attr); attr->type = G_FILE_ATTRIBUTE_TYPE_INT64; attr->u.int64 = value; } /** - * g_file_attribute_value_set_object: + * _g_file_attribute_value_set_object: * @attr: a #GFileAttributeValue. * @obj: a #GObject. * * Sets the attribute to contain the value @obj. * The @attr references the GObject internally. - * - **/ + */ void -g_file_attribute_value_set_object (GFileAttributeValue *attr, - GObject *obj) +_g_file_attribute_value_set_object (GFileAttributeValue *attr, + GObject *obj) { g_return_if_fail (attr != NULL); g_return_if_fail (obj != NULL); - g_file_attribute_value_clear (attr); + _g_file_attribute_value_clear (attr); attr->type = G_FILE_ATTRIBUTE_TYPE_OBJECT; attr->u.obj = g_object_ref (obj); } @@ -720,40 +793,40 @@ list_update_public (GFileAttributeInfoListPriv *priv) /** * g_file_attribute_info_list_new: - * + * * Creates a new file attribute info list. - * + * * Returns: a #GFileAttributeInfoList. - **/ + */ GFileAttributeInfoList * g_file_attribute_info_list_new (void) { GFileAttributeInfoListPriv *priv; priv = g_new0 (GFileAttributeInfoListPriv, 1); - + priv->ref_count = 1; priv->array = g_array_new (TRUE, FALSE, sizeof (GFileAttributeInfo)); - + list_update_public (priv); - + return (GFileAttributeInfoList *)priv; } /** * g_file_attribute_info_list_dup: * @list: a #GFileAttributeInfoList to duplicate. - * + * * Makes a duplicate of a file attribute info list. - * - * Returns: a copy of the given @list. - **/ + * + * Returns: a copy of the given @list. + */ GFileAttributeInfoList * g_file_attribute_info_list_dup (GFileAttributeInfoList *list) { GFileAttributeInfoListPriv *new; int i; - + g_return_val_if_fail (list != NULL, NULL); new = g_new0 (GFileAttributeInfoListPriv, 1); @@ -768,52 +841,53 @@ g_file_attribute_info_list_dup (GFileAttributeInfoList *list) new->public.infos[i].type = list->infos[i].type; new->public.infos[i].flags = list->infos[i].flags; } - + return (GFileAttributeInfoList *)new; } /** * g_file_attribute_info_list_ref: * @list: a #GFileAttributeInfoList to reference. - * + * * References a file attribute info list. - * + * * Returns: #GFileAttributeInfoList or %NULL on error. - **/ + */ GFileAttributeInfoList * g_file_attribute_info_list_ref (GFileAttributeInfoList *list) { GFileAttributeInfoListPriv *priv = (GFileAttributeInfoListPriv *)list; - + g_return_val_if_fail (list != NULL, NULL); g_return_val_if_fail (priv->ref_count > 0, NULL); - + g_atomic_int_inc (&priv->ref_count); - + return list; } /** * g_file_attribute_info_list_unref: * @list: The #GFileAttributeInfoList to unreference. - * + * * Removes a reference from the given @list. If the reference count * falls to zero, the @list is deleted. - **/ + */ void g_file_attribute_info_list_unref (GFileAttributeInfoList *list) { GFileAttributeInfoListPriv *priv = (GFileAttributeInfoListPriv *)list; int i; - + g_return_if_fail (list != NULL); g_return_if_fail (priv->ref_count > 0); - + if (g_atomic_int_dec_and_test (&priv->ref_count)) { for (i = 0; i < list->n_infos; i++) g_free (list->infos[i].name); g_array_free (priv->array, TRUE); + g_free (list); } } @@ -822,7 +896,7 @@ g_file_attribute_info_list_bsearch (GFileAttributeInfoList *list, const char *name) { int start, end, mid; - + start = 0; end = list->n_infos; @@ -844,26 +918,26 @@ g_file_attribute_info_list_bsearch (GFileAttributeInfoList *list, * g_file_attribute_info_list_lookup: * @list: a #GFileAttributeInfoList. * @name: the name of the attribute to lookup. - * + * * Gets the file attribute with the name @name from @list. * - * Returns: a #GFileAttributeInfo for the @name, or %NULL if an + * Returns: a #GFileAttributeInfo for the @name, or %NULL if an * attribute isn't found. - **/ + */ const GFileAttributeInfo * g_file_attribute_info_list_lookup (GFileAttributeInfoList *list, const char *name) { int i; - + g_return_val_if_fail (list != NULL, NULL); g_return_val_if_fail (name != NULL, NULL); - + i = g_file_attribute_info_list_bsearch (list, name); if (i < list->n_infos && strcmp (list->infos[i].name, name) == 0) return &list->infos[i]; - + return NULL; } @@ -872,21 +946,21 @@ g_file_attribute_info_list_lookup (GFileAttributeInfoList *list, * @list: a #GFileAttributeInfoList. * @name: the name of the attribute to add. * @type: the #GFileAttributeType for the attribute. - * @flags: #GFileAttributeFlags for the attribute. - * + * @flags: #GFileAttributeInfoFlags for the attribute. + * * Adds a new attribute with @name to the @list, setting - * its @type and @flags. - **/ + * its @type and @flags. + */ void -g_file_attribute_info_list_add (GFileAttributeInfoList *list, - const char *name, - GFileAttributeType type, - GFileAttributeFlags flags) +g_file_attribute_info_list_add (GFileAttributeInfoList *list, + const char *name, + GFileAttributeType type, + GFileAttributeInfoFlags flags) { GFileAttributeInfoListPriv *priv = (GFileAttributeInfoListPriv *)list; GFileAttributeInfo info; int i; - + g_return_if_fail (list != NULL); g_return_if_fail (name != NULL); @@ -905,6 +979,3 @@ g_file_attribute_info_list_add (GFileAttributeInfoList *list, list_update_public (priv); } - -#define __G_FILE_ATTRIBUTE_C__ -#include "gioaliasdef.c"