Add string vector attribute type to GFileInfo

This is needed for the new metadata backend since nautilus has a
string-list metadata type, and we want to use this for nautilus.
This commit is contained in:
Alexander Larsson 2009-06-22 19:25:32 +02:00
parent c1ab6454fe
commit 0ed9201ad2
6 changed files with 117 additions and 1 deletions

View File

@ -39,6 +39,7 @@ typedef struct {
guint64 uint64; guint64 uint64;
char *string; char *string;
GObject *obj; GObject *obj;
char **stringv;
} u; } u;
} GFileAttributeValue; } GFileAttributeValue;
@ -60,6 +61,7 @@ gint32 _g_file_attribute_value_get_int32 (const GFileAttribu
guint64 _g_file_attribute_value_get_uint64 (const GFileAttributeValue *attr); guint64 _g_file_attribute_value_get_uint64 (const GFileAttributeValue *attr);
gint64 _g_file_attribute_value_get_int64 (const GFileAttributeValue *attr); gint64 _g_file_attribute_value_get_int64 (const GFileAttributeValue *attr);
GObject * _g_file_attribute_value_get_object (const GFileAttributeValue *attr); GObject * _g_file_attribute_value_get_object (const GFileAttributeValue *attr);
char ** _g_file_attribute_value_get_stringv (const GFileAttributeValue *attr);
void _g_file_attribute_value_set_from_pointer(GFileAttributeValue *attr, void _g_file_attribute_value_set_from_pointer(GFileAttributeValue *attr,
GFileAttributeType type, GFileAttributeType type,
@ -81,6 +83,8 @@ void _g_file_attribute_value_set_int64 (GFileAttributeValu
gint64 value); gint64 value);
void _g_file_attribute_value_set_object (GFileAttributeValue *attr, void _g_file_attribute_value_set_object (GFileAttributeValue *attr,
GObject *obj); GObject *obj);
void _g_file_attribute_value_set_stringv (GFileAttributeValue *attr,
char **value);
GFileAttributeValue *_g_file_info_get_attribute_value (GFileInfo *info, GFileAttributeValue *_g_file_info_get_attribute_value (GFileInfo *info,

View File

@ -243,6 +243,9 @@ _g_file_attribute_value_clear (GFileAttributeValue *attr)
attr->type == G_FILE_ATTRIBUTE_TYPE_BYTE_STRING) attr->type == G_FILE_ATTRIBUTE_TYPE_BYTE_STRING)
g_free (attr->u.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 && if (attr->type == G_FILE_ATTRIBUTE_TYPE_OBJECT &&
attr->u.obj != NULL) attr->u.obj != NULL)
g_object_unref (attr->u.obj); g_object_unref (attr->u.obj);
@ -271,6 +274,9 @@ _g_file_attribute_value_set (GFileAttributeValue *attr,
attr->type == G_FILE_ATTRIBUTE_TYPE_BYTE_STRING) attr->type == G_FILE_ATTRIBUTE_TYPE_BYTE_STRING)
attr->u.string = g_strdup (attr->u.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 && if (attr->type == G_FILE_ATTRIBUTE_TYPE_OBJECT &&
attr->u.obj != NULL) attr->u.obj != NULL)
g_object_ref (attr->u.obj); g_object_ref (attr->u.obj);
@ -300,6 +306,8 @@ _g_file_attribute_value_peek_as_pointer (GFileAttributeValue *attr)
case G_FILE_ATTRIBUTE_TYPE_STRING: case G_FILE_ATTRIBUTE_TYPE_STRING:
case G_FILE_ATTRIBUTE_TYPE_BYTE_STRING: case G_FILE_ATTRIBUTE_TYPE_BYTE_STRING:
return attr->u.string; return attr->u.string;
case G_FILE_ATTRIBUTE_TYPE_STRINGV:
return attr->u.stringv;
case G_FILE_ATTRIBUTE_TYPE_OBJECT: case G_FILE_ATTRIBUTE_TYPE_OBJECT:
return attr->u.obj; return attr->u.obj;
default: default:
@ -408,6 +416,8 @@ escape_byte_string (const char *str)
char * 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; char *str;
g_return_val_if_fail (attr != NULL, NULL); g_return_val_if_fail (attr != NULL, NULL);
@ -417,6 +427,17 @@ _g_file_attribute_value_as_string (const GFileAttributeValue *attr)
case G_FILE_ATTRIBUTE_TYPE_STRING: case G_FILE_ATTRIBUTE_TYPE_STRING:
str = g_strdup (attr->u.string); str = g_strdup (attr->u.string);
break; 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: case G_FILE_ATTRIBUTE_TYPE_BYTE_STRING:
str = escape_byte_string (attr->u.string); str = escape_byte_string (attr->u.string);
break; break;
@ -489,6 +510,17 @@ _g_file_attribute_value_get_byte_string (const GFileAttributeValue *attr)
return attr->u.string; 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. * @attr: a #GFileAttributeValue.
@ -628,6 +660,13 @@ _g_file_attribute_value_set_from_pointer (GFileAttributeValue *value,
value->u.string = value_p; value->u.string = value_p;
break; 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: case G_FILE_ATTRIBUTE_TYPE_OBJECT:
if (dup) if (dup)
value->u.obj = g_object_ref (value_p); value->u.obj = g_object_ref (value_p);
@ -698,6 +737,19 @@ _g_file_attribute_value_set_byte_string (GFileAttributeValue *attr,
attr->u.string = g_strdup (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. * @attr: a #GFileAttributeValue.

View File

@ -751,6 +751,30 @@ g_file_info_get_attribute_byte_string (GFileInfo *info,
return _g_file_attribute_value_get_byte_string (value); return _g_file_attribute_value_get_byte_string (value);
} }
/**
* g_file_info_get_attribute_stringv:
* @info: a #GFileInfo.
* @attribute: a file attribute key.
*
* Gets the value of a stringv attribute. If the attribute does
* not contain a stringv, %NULL will be returned.
*
* Returns: the contents of the @attribute value as a stringv, or
* %NULL otherwise. Do not free.
**/
char **
g_file_info_get_attribute_stringv (GFileInfo *info,
const char *attribute)
{
GFileAttributeValue *value;
g_return_val_if_fail (G_IS_FILE_INFO (info), NULL);
g_return_val_if_fail (attribute != NULL && *attribute != '\0', NULL);
value = g_file_info_find_value_by_name (info, attribute);
return _g_file_attribute_value_get_stringv (value);
}
/** /**
* g_file_info_get_attribute_boolean: * g_file_info_get_attribute_boolean:
* @info: a #GFileInfo. * @info: a #GFileInfo.
@ -960,6 +984,33 @@ g_file_info_set_attribute_object (GFileInfo *info,
_g_file_attribute_value_set_object (value, attr_value); _g_file_attribute_value_set_object (value, attr_value);
} }
/**
* g_file_info_set_attribute_stringv:
* @info: a #GFileInfo.
* @attribute: a file attribute key.
* @attr_value: a %NULL terminated string array
*
* Sets the @attribute to contain the given @attr_value,
* if possible.
*
* Sinze: 2.22
**/
void
g_file_info_set_attribute_stringv (GFileInfo *info,
const char *attribute,
char **attr_value)
{
GFileAttributeValue *value;
g_return_if_fail (G_IS_FILE_INFO (info));
g_return_if_fail (attribute != NULL && *attribute != '\0');
g_return_if_fail (attr_value != NULL);
value = g_file_info_create_value_by_name (info, attribute);
if (value)
_g_file_attribute_value_set_stringv (value, attr_value);
}
/** /**
* g_file_info_set_attribute_string: * g_file_info_set_attribute_string:
* @info: a #GFileInfo. * @info: a #GFileInfo.

View File

@ -780,6 +780,8 @@ gint64 g_file_info_get_attribute_int64 (GFileInfo *info,
const char *attribute); const char *attribute);
GObject * g_file_info_get_attribute_object (GFileInfo *info, GObject * g_file_info_get_attribute_object (GFileInfo *info,
const char *attribute); const char *attribute);
char ** g_file_info_get_attribute_stringv (GFileInfo *info,
const char *attribute);
void g_file_info_set_attribute (GFileInfo *info, void g_file_info_set_attribute (GFileInfo *info,
const char *attribute, const char *attribute,
@ -809,6 +811,9 @@ void g_file_info_set_attribute_int64 (GFileInfo *info,
void g_file_info_set_attribute_object (GFileInfo *info, void g_file_info_set_attribute_object (GFileInfo *info,
const char *attribute, const char *attribute,
GObject *attr_value); GObject *attr_value);
void g_file_info_set_attribute_stringv (GFileInfo *info,
const char *attribute,
char **attr_value);
void g_file_info_clear_status (GFileInfo *info); void g_file_info_clear_status (GFileInfo *info);

View File

@ -391,6 +391,7 @@ g_file_info_get_attribute_int32
g_file_info_get_attribute_uint64 g_file_info_get_attribute_uint64
g_file_info_get_attribute_int64 g_file_info_get_attribute_int64
g_file_info_get_attribute_object g_file_info_get_attribute_object
g_file_info_get_attribute_stringv
g_file_info_set_attribute g_file_info_set_attribute
g_file_info_set_attribute_string g_file_info_set_attribute_string
g_file_info_set_attribute_byte_string g_file_info_set_attribute_byte_string
@ -400,6 +401,7 @@ g_file_info_set_attribute_int32
g_file_info_set_attribute_uint64 g_file_info_set_attribute_uint64
g_file_info_set_attribute_int64 g_file_info_set_attribute_int64
g_file_info_set_attribute_object g_file_info_set_attribute_object
g_file_info_set_attribute_stringv
g_file_info_clear_status g_file_info_clear_status
g_file_info_get_file_type g_file_info_get_file_type
g_file_info_get_is_hidden g_file_info_get_is_hidden

View File

@ -92,6 +92,7 @@ typedef enum {
* @G_FILE_ATTRIBUTE_TYPE_UINT64: an unsigned 8-byte/64-bit integer. * @G_FILE_ATTRIBUTE_TYPE_UINT64: an unsigned 8-byte/64-bit integer.
* @G_FILE_ATTRIBUTE_TYPE_INT64: a signed 8-byte/64-bit integer. * @G_FILE_ATTRIBUTE_TYPE_INT64: a signed 8-byte/64-bit integer.
* @G_FILE_ATTRIBUTE_TYPE_OBJECT: a #GObject. * @G_FILE_ATTRIBUTE_TYPE_OBJECT: a #GObject.
* @G_FILE_ATTRIBUTE_TYPE_STRINGV: a %NULL terminated char **. Since 2.22
* *
* The data types for file attributes. * The data types for file attributes.
**/ **/
@ -104,7 +105,8 @@ typedef enum {
G_FILE_ATTRIBUTE_TYPE_INT32, G_FILE_ATTRIBUTE_TYPE_INT32,
G_FILE_ATTRIBUTE_TYPE_UINT64, G_FILE_ATTRIBUTE_TYPE_UINT64,
G_FILE_ATTRIBUTE_TYPE_INT64, G_FILE_ATTRIBUTE_TYPE_INT64,
G_FILE_ATTRIBUTE_TYPE_OBJECT G_FILE_ATTRIBUTE_TYPE_OBJECT,
G_FILE_ATTRIBUTE_TYPE_STRINGV
} GFileAttributeType; } GFileAttributeType;