[evolution-data-server/account-mgmt: 24/28] Adapt ENameSelector to the new ESource API.



commit 2c27ad00202a2a46b18b3ff0740703057313eb4c
Author: Matthew Barnes <mbarnes redhat com>
Date:   Wed Nov 24 10:09:58 2010 -0500

    Adapt ENameSelector to the new ESource API.

 libedataserverui/e-name-selector.c |   76 +++++++++++++-----------------------
 libedataserverui/e-name-selector.h |    1 -
 2 files changed, 27 insertions(+), 50 deletions(-)
---
diff --git a/libedataserverui/e-name-selector.c b/libedataserverui/e-name-selector.c
index c537ada..7967b9d 100644
--- a/libedataserverui/e-name-selector.c
+++ b/libedataserverui/e-name-selector.c
@@ -30,6 +30,9 @@
 #include <glib/gi18n-lib.h>
 #include <libebook/e-book.h>
 #include <libebook/e-contact.h>
+#include <libebook/e-source-address-book.h>
+#include <libedataserver/e-source-autocomplete.h>
+#include <libedataserver/e-source-registry.h>
 #include <libedataserverui/e-contact-store.h>
 #include <libedataserverui/e-destination-store.h>
 #include <libedataserverui/e-book-auth-util.h>
@@ -54,7 +57,7 @@ struct _ENameSelectorPrivate {
 	ENameSelectorDialog *dialog;
 
 	GArray *sections;
-	ESourceList *source_list;
+	/*ESourceList *source_list;*/
 
 	gboolean load_cancelled;
 	GArray *source_books;
@@ -98,7 +101,7 @@ name_selector_book_loaded_cb (ESource *source,
 	if (error != NULL) {
 		g_warning (
 			"ENameSelector: Could not load \"%s\": %s",
-			e_source_peek_name (source), error->message);
+			e_source_get_display_name (source), error->message);
 		g_error_free (error);
 		goto exit;
 	}
@@ -133,54 +136,34 @@ exit:
 static void
 name_selector_load_books (ENameSelector *name_selector)
 {
-	ESourceList *source_list;
-	GSList *groups;
-	GSList *iter1;
+	ESourceRegistry *registry;
+	GList *list, *iter;
+	const gchar *extension_name;
 
-	if (!e_book_get_addressbooks (&source_list, NULL)) {
-		g_warning ("ENameSelector can't find any addressbooks!");
-		return;
-	}
-
-	/* This keeps the source groups alive while the async operation
-	 * is running, without which e_book_new() can't obtain an absolute
-	 * URI for the ESource.   We drop the reference in dispose(). */
-	name_selector->priv->source_list = source_list;
-
-	groups = e_source_list_peek_groups (source_list);
-
-	for (iter1 = groups; iter1 != NULL; iter1 = iter1->next) {
-		ESourceGroup *source_group;
-		GSList *sources;
-		GSList *iter2;
-
-		source_group = E_SOURCE_GROUP (iter1->data);
-		sources = e_source_group_peek_sources (source_group);
+	registry = e_source_registry_get_default ();
 
-		for (iter2 = sources; iter2 != NULL; iter2 = iter2->next) {
-			ESource *source;
-			const gchar *property;
+	extension_name = E_SOURCE_EXTENSION_ADDRESS_BOOK;
+	list = e_source_registry_list_sources (registry, extension_name);
 
-			source = E_SOURCE (iter2->data);
+	for (iter = list; iter != NULL; iter = g_list_next (iter)) {
+		ESource *source = E_SOURCE (iter->data);
+		ESourceAutocomplete *extension;
+		const gchar *extension_name;
 
-			/* We're only loading completion books for now,
-			 * as we don't want unnecessary authentication
-			 * prompts. */
-			property = e_source_get_property (source, "completion");
+		extension_name = E_SOURCE_EXTENSION_AUTOCOMPLETE;
+		extension = e_source_get_extension (source, extension_name);
 
-			if (property == NULL)
-				continue;
-
-			if (g_ascii_strcasecmp (property, "true") != 0)
-				continue;
+		/* Only load address books with autocomplete enabled,
+		 * so as to avoid unnecessary authentication prompts. */
+		if (!e_source_autocomplete_get_include_me (extension))
+			continue;
 
-			/* XXX Should we allow for cancellation? */
-			e_load_book_source_async (
-				source, NULL, NULL,
-				(GAsyncReadyCallback)
-				name_selector_book_loaded_cb,
-				g_object_ref (name_selector));
-		}
+		/* XXX Should we allow for cancellation? */
+		e_load_book_source_async (
+			source, NULL, NULL,
+			(GAsyncReadyCallback)
+			name_selector_book_loaded_cb,
+			g_object_ref (name_selector));
 	}
 }
 
@@ -192,11 +175,6 @@ name_selector_dispose (GObject *object)
 
 	priv = E_NAME_SELECTOR_GET_PRIVATE (object);
 
-	if (priv->source_list != NULL) {
-		g_object_unref (priv->source_list);
-		priv->source_list = NULL;
-	}
-
 	for (ii = 0; ii < priv->source_books->len; ii++) {
 		SourceBook *source_book;
 
diff --git a/libedataserverui/e-name-selector.h b/libedataserverui/e-name-selector.h
index 2416661..411dc97 100644
--- a/libedataserverui/e-name-selector.h
+++ b/libedataserverui/e-name-selector.h
@@ -25,7 +25,6 @@
 
 #include <glib.h>
 
-#include "libedataserver/e-source-list.h"
 #include <libedataserverui/e-name-selector-model.h>
 #include <libedataserverui/e-name-selector-dialog.h>
 #include <libedataserverui/e-name-selector-entry.h>



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