[glib] Add string vector attribute type to GFileInfo



commit 0ed9201ad2051c33f5d049754bd8a1644d19ab7c
Author: Alexander Larsson <alexl redhat com>
Date:   Mon Jun 22 19:25:32 2009 +0200

    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.

 gio/gfileattribute-priv.h |    4 +++
 gio/gfileattribute.c      |   52 +++++++++++++++++++++++++++++++++++++++++++++
 gio/gfileinfo.c           |   51 ++++++++++++++++++++++++++++++++++++++++++++
 gio/gfileinfo.h           |    5 ++++
 gio/gio.symbols           |    2 +
 gio/gioenums.h            |    4 ++-
 6 files changed, 117 insertions(+), 1 deletions(-)
---
diff --git a/gio/gfileattribute-priv.h b/gio/gfileattribute-priv.h
index 99c3481..731c50b 100644
--- a/gio/gfileattribute-priv.h
+++ b/gio/gfileattribute-priv.h
@@ -39,6 +39,7 @@ typedef struct  {
     guint64 uint64;
     char *string;
     GObject *obj;
+    char **stringv;
   } u;
 } GFileAttributeValue;
 
@@ -60,6 +61,7 @@ gint32               _g_file_attribute_value_get_int32       (const GFileAttribu
 guint64              _g_file_attribute_value_get_uint64      (const GFileAttributeValue *attr);
 gint64               _g_file_attribute_value_get_int64       (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,
 							      GFileAttributeType   type,
@@ -81,6 +83,8 @@ void                 _g_file_attribute_value_set_int64       (GFileAttributeValu
 							      gint64               value);
 void                 _g_file_attribute_value_set_object      (GFileAttributeValue *attr,
 							      GObject             *obj);
+void                 _g_file_attribute_value_set_stringv     (GFileAttributeValue *attr,
+							      char               **value);
 
 
 GFileAttributeValue *_g_file_info_get_attribute_value (GFileInfo  *info,
diff --git a/gio/gfileattribute.c b/gio/gfileattribute.c
index a0dfcbf..671c7cc 100644
--- a/gio/gfileattribute.c
+++ b/gio/gfileattribute.c
@@ -243,6 +243,9 @@ _g_file_attribute_value_clear (GFileAttributeValue *attr)
       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);
@@ -271,6 +274,9 @@ _g_file_attribute_value_set (GFileAttributeValue        *attr,
       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);
@@ -300,6 +306,8 @@ _g_file_attribute_value_peek_as_pointer (GFileAttributeValue *attr)
   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:
@@ -408,6 +416,8 @@ escape_byte_string (const char *str)
 char *
 _g_file_attribute_value_as_string (const GFileAttributeValue *attr)
 {
+  GString *s;
+  int i;
   char *str;
 
   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:
       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;
@@ -489,6 +510,17 @@ _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:
  * @attr: a #GFileAttributeValue.
@@ -628,6 +660,13 @@ _g_file_attribute_value_set_from_pointer (GFileAttributeValue *value,
 	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);
@@ -698,6 +737,19 @@ _g_file_attribute_value_set_byte_string (GFileAttributeValue *attr,
   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:
  * @attr: a #GFileAttributeValue.
diff --git a/gio/gfileinfo.c b/gio/gfileinfo.c
index 5131bdb..0ae9527 100644
--- a/gio/gfileinfo.c
+++ b/gio/gfileinfo.c
@@ -752,6 +752,30 @@ g_file_info_get_attribute_byte_string (GFileInfo  *info,
 }
 
 /**
+ * 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:
  * @info: a #GFileInfo.
  * @attribute: a file attribute key.
@@ -961,6 +985,33 @@ g_file_info_set_attribute_object (GFileInfo  *info,
 }
 
 /**
+ * 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:
  * @info: a #GFileInfo.
  * @attribute: a file attribute key.
diff --git a/gio/gfileinfo.h b/gio/gfileinfo.h
index 0d0c49c..6163cab 100644
--- a/gio/gfileinfo.h
+++ b/gio/gfileinfo.h
@@ -780,6 +780,8 @@ gint64             g_file_info_get_attribute_int64       (GFileInfo  *info,
 							  const char *attribute);
 GObject *          g_file_info_get_attribute_object      (GFileInfo  *info,
 							  const char *attribute);
+char **            g_file_info_get_attribute_stringv     (GFileInfo  *info,
+							  const char *attribute);
 
 void               g_file_info_set_attribute             (GFileInfo  *info,
 							  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,
 							  const char *attribute,
 							  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);
 
diff --git a/gio/gio.symbols b/gio/gio.symbols
index 1eaf373..07a6c78 100644
--- a/gio/gio.symbols
+++ b/gio/gio.symbols
@@ -391,6 +391,7 @@ g_file_info_get_attribute_int32
 g_file_info_get_attribute_uint64 
 g_file_info_get_attribute_int64 
 g_file_info_get_attribute_object 
+g_file_info_get_attribute_stringv
 g_file_info_set_attribute 
 g_file_info_set_attribute_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_int64 
 g_file_info_set_attribute_object 
+g_file_info_set_attribute_stringv
 g_file_info_clear_status 
 g_file_info_get_file_type 
 g_file_info_get_is_hidden 
diff --git a/gio/gioenums.h b/gio/gioenums.h
index f061172..42e27af 100644
--- a/gio/gioenums.h
+++ b/gio/gioenums.h
@@ -92,6 +92,7 @@ typedef enum {
  * @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_OBJECT: a #GObject.
+ * @G_FILE_ATTRIBUTE_TYPE_STRINGV: a %NULL terminated char **. Since 2.22
  *
  * The data types for file attributes.
  **/
@@ -104,7 +105,8 @@ typedef enum {
   G_FILE_ATTRIBUTE_TYPE_INT32,
   G_FILE_ATTRIBUTE_TYPE_UINT64,
   G_FILE_ATTRIBUTE_TYPE_INT64,
-  G_FILE_ATTRIBUTE_TYPE_OBJECT
+  G_FILE_ATTRIBUTE_TYPE_OBJECT,
+  G_FILE_ATTRIBUTE_TYPE_STRINGV
 } GFileAttributeType;
 
 



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]