[evolution-data-server] backends/ldap: Prefer e_book_backend_list_views().



commit a909d533bb87d067a088e862cf5bdc9998edaed3
Author: Matthew Barnes <mbarnes redhat com>
Date:   Sun Oct 7 13:22:24 2012 -0400

    backends/ldap: Prefer e_book_backend_list_views().
    
    Less klunky than e_book_backend_foreach_view().

 addressbook/backends/ldap/e-book-backend-ldap.c |   66 ++++++++---------------
 1 files changed, 22 insertions(+), 44 deletions(-)
---
diff --git a/addressbook/backends/ldap/e-book-backend-ldap.c b/addressbook/backends/ldap/e-book-backend-ldap.c
index 63282a0..eade88e 100644
--- a/addressbook/backends/ldap/e-book-backend-ldap.c
+++ b/addressbook/backends/ldap/e-book-backend-ldap.c
@@ -453,61 +453,39 @@ can_browse (EBookBackend *backend)
 	return e_source_ldap_get_can_browse (extension);
 }
 
-static gboolean
-pick_view_cb (EDataBookView *view,
-              gpointer user_data)
-{
-	EDataBookView **pick = user_data;
-
-	g_return_val_if_fail (user_data != NULL, FALSE);
-
-	/* just always use the first book view */
-	*pick = view;
-
-	return view == NULL;
-}
-
 static EDataBookView *
 find_book_view (EBookBackendLDAP *bl)
 {
-	EDataBookView *pick = NULL;
-
-	e_book_backend_foreach_view (E_BOOK_BACKEND (bl), pick_view_cb, &pick);
-
-	return pick;
-}
-
-struct check_data
-{
-	EDataBookView *to_find;
-	gboolean found;
-};
-
-static gboolean
-check_view_cb (EDataBookView *view,
-               gpointer user_data)
-{
-	struct check_data *cd = user_data;
+	EDataBookView *view = NULL;
+	GList *list;
 
-	g_return_val_if_fail (user_data != NULL, FALSE);
+	list = e_book_backend_list_views (E_BOOK_BACKEND (bl));
 
-	cd->found = view == cd->to_find;
+	if (list != NULL) {
+		/* FIXME Drop the EDataBookView reference for backward-
+		 *       compatibility, but at some point the LDAP backend
+		 *       should learn to expect a new reference from this
+		 *       function and clean up after itself.  Currently
+		 *       this is not thread-safe. */
+		view = E_DATA_BOOK_VIEW (list->data);
+		g_list_free_full (list, (GDestroyNotify) g_object_unref);
+	}
 
-	return !cd->found;
+	return view;
 }
 
 static gboolean
 book_view_is_valid (EBookBackendLDAP *bl,
                     EDataBookView *book_view)
 {
-	struct check_data cd;
-
-	cd.to_find = book_view;
-	cd.found = FALSE;
+	GList *list;
+	gboolean found;
 
-	e_book_backend_foreach_view (E_BOOK_BACKEND (bl), check_view_cb, &cd);
+	list = e_book_backend_list_views (E_BOOK_BACKEND (bl));
+	found = (g_list_find (list, book_view) != NULL);
+	g_list_free_full (list, (GDestroyNotify) g_object_unref);
 
-	return cd.found;
+	return found;
 }
 
 static void



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