[libgnome-keyring] Allow bindings to use GnomeKeyringAttributeList



commit 3833ffbf621e03ce5a3283aa61abe81dadb7b909
Author: Martin Pitt <martin pitt ubuntu com>
Date:   Sat Jan 14 14:01:02 2012 +0100

    Allow bindings to use GnomeKeyringAttributeList
    
    GArray is not usable for language bindings. Replace the
    gnome_keyring_attribute_list_new() macro with a real constructor and provide a
    gnome_keyring_attribute_list_to_glist() accessor to convert a
    GnomeKeyringAttributeList to a GList.

 library/gnome-keyring-utils.c |   43 +++++++++++++++++++++++++++++++++++++++++
 library/gnome-keyring.h       |    3 +-
 2 files changed, 45 insertions(+), 1 deletions(-)
---
diff --git a/library/gnome-keyring-utils.c b/library/gnome-keyring-utils.c
index 56a7547..d44f6a7 100644
--- a/library/gnome-keyring-utils.c
+++ b/library/gnome-keyring-utils.c
@@ -379,6 +379,19 @@ gnome_keyring_attribute_list_append_uint32 (GnomeKeyringAttributeList *attribute
 }
 
 /**
+ * gnome_keyring_attribute_list_new:
+ *
+ * Create a new #GnomeKeyringAttributeList.
+ *
+ * Return value: (transfer full): The new #GnomeKeyringAttributeList
+ **/
+GnomeKeyringAttributeList *
+gnome_keyring_attribute_list_new (void)
+{
+	return g_array_new (FALSE, FALSE, sizeof (GnomeKeyringAttribute));
+}
+
+/**
  * gnome_keyring_attribute_list_free:
  * @attributes: A #GnomeKeyringAttributeList
  *
@@ -439,6 +452,36 @@ gnome_keyring_attribute_list_copy (GnomeKeyringAttributeList *attributes)
 	return copy;
 }
 
+/**
+ * gnome_keyring_attribute_list_to_glist:
+ * @attributes: A #GnomeKeyringAttributeList
+ *
+ * Create #GList of #GnomeKeyringAttribute pointers from @attributes. This is
+ * mostly useful in language bindings which cannot directly use a #GArray.
+ *
+ * Returns: (transfer full) (element-type GnomeKeyringAttribute): #GList
+ * of #GnomeKeyringAttribute.
+ *
+ * Since: 3.4
+ **/
+GList*
+gnome_keyring_attribute_list_to_glist (GnomeKeyringAttributeList *attributes)
+{
+	GList *list = NULL;
+	GnomeKeyringAttribute *attr;
+	guint i;
+
+	if (attributes == NULL)
+		return NULL;
+
+	for (i = 0; i < attributes->len; ++i) {
+		attr = &g_array_index (attributes, GnomeKeyringAttribute, i);
+		list = g_list_append (list, gnome_keyring_attribute_copy (attr));
+	}
+
+	return list;
+}
+
 G_DEFINE_BOXED_TYPE (GnomeKeyringAttributeList,
 	gnome_keyring_attribute_list,
 	gnome_keyring_attribute_list_copy,
diff --git a/library/gnome-keyring.h b/library/gnome-keyring.h
index f279f09..13165bc 100644
--- a/library/gnome-keyring.h
+++ b/library/gnome-keyring.h
@@ -117,16 +117,17 @@ GType                      gnome_keyring_attribute_get_type           (void) G_G
 #define GNOME_KEYRING_TYPE_ATTRIBUTE (gnome_keyring_attribute_get_type ())
 
 #define gnome_keyring_attribute_list_index(a, i) g_array_index ((a), GnomeKeyringAttribute, (i))
-#define gnome_keyring_attribute_list_new() (g_array_new (FALSE, FALSE, sizeof (GnomeKeyringAttribute)))
 void                       gnome_keyring_attribute_list_append_string (GnomeKeyringAttributeList *attributes,
                                                                        const char                *name,
                                                                        const char                *value);
 void                       gnome_keyring_attribute_list_append_uint32 (GnomeKeyringAttributeList *attributes,
                                                                        const char                *name,
                                                                        guint32                    value);
+GnomeKeyringAttributeList *gnome_keyring_attribute_list_new           (void);
 void                       gnome_keyring_attribute_list_free          (GnomeKeyringAttributeList *attributes);
 GnomeKeyringAttributeList *gnome_keyring_attribute_list_copy          (GnomeKeyringAttributeList *attributes);
 GType                      gnome_keyring_attribute_list_get_type      (void) G_GNUC_CONST;
+GList                     *gnome_keyring_attribute_list_to_glist      (GnomeKeyringAttributeList *attributes);
 
 #define GNOME_KEYRING_TYPE_ATTRIBUTE_LIST (gnome_keyring_attribute_list_get_type ())
 



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