[libgdata] contacts: Don't return deleted groups in gdata_contacts_contact_get_groups()



commit 29f7b1582d5b7a4bed51ef2497bb0b04b644b052
Author: Philip Withnall <philip tecnocode co uk>
Date:   Tue Dec 21 17:48:50 2010 +0000

    contacts: Don't return deleted groups in gdata_contacts_contact_get_groups()
    
    Also take the opportunity to rewrite it to use GHashTableIter instead of
    a tiny little callback function.

 gdata/services/contacts/gdata-contacts-contact.c |   17 ++++++++++-------
 1 files changed, 10 insertions(+), 7 deletions(-)
---
diff --git a/gdata/services/contacts/gdata-contacts-contact.c b/gdata/services/contacts/gdata-contacts-contact.c
index cef834e..165971d 100644
--- a/gdata/services/contacts/gdata-contacts-contact.c
+++ b/gdata/services/contacts/gdata-contacts-contact.c
@@ -2850,12 +2850,6 @@ gdata_contacts_contact_is_group_deleted (GDataContactsContact *self, const gchar
 	return GPOINTER_TO_UINT (g_hash_table_lookup (self->priv->groups, href));
 }
 
-static void
-get_groups_cb (const gchar *href, gpointer deleted, GList **groups)
-{
-	*groups = g_list_prepend (*groups, (gchar*) href);
-}
-
 /**
  * gdata_contacts_contact_get_groups:
  * @self: a #GDataContactsContact
@@ -2869,11 +2863,20 @@ get_groups_cb (const gchar *href, gpointer deleted, GList **groups)
 GList *
 gdata_contacts_contact_get_groups (GDataContactsContact *self)
 {
+	GHashTableIter iter;
+	const gchar *href;
+	gpointer value;
 	GList *groups = NULL;
 
 	g_return_val_if_fail (GDATA_IS_CONTACTS_CONTACT (self), NULL);
 
-	g_hash_table_foreach (self->priv->groups, (GHFunc) get_groups_cb, &groups);
+	g_hash_table_iter_init (&iter, self->priv->groups);
+	while (g_hash_table_iter_next (&iter, (gpointer*) &href, &value) == TRUE) {
+		/* Add the group to the list as long as it hasn't been deleted */
+		if (GPOINTER_TO_UINT (value) == FALSE)
+			groups = g_list_prepend (groups, (gpointer) href);
+	}
+
 	return g_list_reverse (groups);
 }
 



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