[evolution-data-server/account-mgmt: 29/42] Adapt ENameSelectorEntry to the new ESource API.



commit f806bb47369897b6b13803bdc8e8cba06cc0f57d
Author: Matthew Barnes <mbarnes redhat com>
Date:   Tue Nov 30 20:25:58 2010 -0600

    Adapt ENameSelectorEntry to the new ESource API.

 .../libedataserverui/libedataserverui-sections.txt |    1 +
 libedataserverui/e-name-selector-entry.c           |  231 +++++++++++++++-----
 libedataserverui/e-name-selector-entry.h           |    6 +-
 3 files changed, 179 insertions(+), 59 deletions(-)
---
diff --git a/docs/reference/libedataserverui/libedataserverui-sections.txt b/docs/reference/libedataserverui/libedataserverui-sections.txt
index d91a26f..b0738cf 100644
--- a/docs/reference/libedataserverui/libedataserverui-sections.txt
+++ b/docs/reference/libedataserverui/libedataserverui-sections.txt
@@ -256,6 +256,7 @@ FORCE_SHOW_ADDRESS
 USER_QUERY_FIELDS
 ENameSelectorEntry
 e_name_selector_entry_new
+e_name_selector_entry_get_registry
 e_name_selector_entry_peek_contact_store
 e_name_selector_entry_set_contact_store
 e_name_selector_entry_peek_destination_store
diff --git a/libedataserverui/e-name-selector-entry.c b/libedataserverui/e-name-selector-entry.c
index 1e2a6b1..82a0859 100644
--- a/libedataserverui/e-name-selector-entry.c
+++ b/libedataserverui/e-name-selector-entry.c
@@ -30,7 +30,11 @@
 #include <libebook/e-book-client.h>
 #include <libebook/e-contact.h>
 #include <libebook/e-destination.h>
+#include <libedataserverui/e-book-auth-util.h>
 #include <libedataserverui/e-client-utils.h>
+#include <libedataserver/e-source-address-book.h>
+#include <libedataserver/e-source-autocomplete.h>
+#include <libedataserver/e-source-registry.h>
 #include <libedataserver/e-sexp.h>
 
 #include "e-name-selector-entry.h"
@@ -41,8 +45,9 @@
 
 struct _ENameSelectorEntryPrivate {
 
+	ESourceRegistry *registry;
+
 	PangoAttrList *attr_list;
-	ESourceList *source_list;
 	EContactStore *contact_store;
 	ETreeModelGenerator *email_generator;
 	EDestinationStore *destination_store;
@@ -71,6 +76,11 @@ struct _ENameSelectorEntryPrivate {
 };
 
 enum {
+	PROP_0,
+	PROP_REGISTRY
+};
+
+enum {
 	UPDATED,
 	LAST_SIGNAL
 };
@@ -102,12 +112,62 @@ static void setup_default_contact_store (ENameSelectorEntry *name_selector_entry
 static void deep_free_list (GList *list);
 
 static void
+name_selector_entry_set_registry (ENameSelectorEntry *name_selector_entry,
+                                  ESourceRegistry *registry)
+{
+	g_return_if_fail (E_IS_SOURCE_REGISTRY (registry));
+	g_return_if_fail (name_selector_entry->priv->registry == NULL);
+
+	name_selector_entry->priv->registry = g_object_ref (registry);
+}
+
+static void
+name_selector_entry_set_property (GObject *object,
+                                  guint property_id,
+                                  const GValue *value,
+                                  GParamSpec *pspec)
+{
+	switch (property_id) {
+		case PROP_REGISTRY:
+			name_selector_entry_set_registry (
+				E_NAME_SELECTOR_ENTRY (object),
+				g_value_get_object (value));
+			return;
+	}
+
+	G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
+}
+
+static void
+name_selector_entry_get_property (GObject *object,
+                                  guint property_id,
+                                  GValue *value,
+                                  GParamSpec *pspec)
+{
+	switch (property_id) {
+		case PROP_REGISTRY:
+			g_value_set_object (
+				value,
+				e_name_selector_entry_get_registry (
+				E_NAME_SELECTOR_ENTRY (object)));
+			return;
+	}
+
+	G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
+}
+
+static void
 name_selector_entry_dispose (GObject *object)
 {
 	ENameSelectorEntryPrivate *priv;
 
 	priv = E_NAME_SELECTOR_ENTRY_GET_PRIVATE (object);
 
+	if (priv->registry != NULL) {
+		g_object_unref (priv->registry);
+		priv->registry = NULL;
+	}
+
 	if (priv->attr_list != NULL) {
 		pango_attr_list_unref (priv->attr_list);
 		priv->attr_list = NULL;
@@ -230,12 +290,26 @@ e_name_selector_entry_class_init (ENameSelectorEntryClass *class)
 	g_type_class_add_private (class, sizeof (ENameSelectorEntryPrivate));
 
 	object_class = G_OBJECT_CLASS (class);
+	object_class->set_property = name_selector_entry_set_property;
+	object_class->get_property = name_selector_entry_get_property;
 	object_class->dispose = name_selector_entry_dispose;
 
 	widget_class = GTK_WIDGET_CLASS (class);
 	widget_class->realize = name_selector_entry_realize;
 	widget_class->drag_data_received = name_selector_entry_drag_data_received;
 
+	g_object_class_install_property (
+		object_class,
+		PROP_REGISTRY,
+		g_param_spec_object (
+			"registry",
+			"Registry",
+			"Data source registry",
+			E_TYPE_SOURCE_REGISTRY,
+			G_PARAM_READWRITE |
+			G_PARAM_CONSTRUCT_ONLY |
+			G_PARAM_STATIC_STRINGS));
+
 	signals[UPDATED] = g_signal_new (
 		"updated",
 		E_TYPE_NAME_SELECTOR_ENTRY,
@@ -2083,9 +2157,10 @@ book_loaded_cb (GObject *source_object,
 static void
 setup_default_contact_store (ENameSelectorEntry *name_selector_entry)
 {
+	ESourceRegistry *registry;
 	EContactStore *contact_store;
-	GSList *groups;
-	GSList *l;
+	GList *list, *iter;
+	const gchar *extension_name;
 
 	g_return_if_fail (name_selector_entry->priv->contact_store == NULL);
 
@@ -2093,36 +2168,41 @@ setup_default_contact_store (ENameSelectorEntry *name_selector_entry)
 
 	contact_store = e_contact_store_new ();
 	name_selector_entry->priv->contact_store = contact_store;
-	groups = e_source_list_peek_groups (name_selector_entry->priv->source_list);
 
-	for (l = groups; l; l = g_slist_next (l)) {
-		ESourceGroup *group   = l->data;
-		GSList       *sources = e_source_group_peek_sources (group);
-		GSList       *m;
+	extension_name = E_SOURCE_EXTENSION_ADDRESS_BOOK;
+	registry = e_name_selector_entry_get_registry (name_selector_entry);
+	list = e_source_registry_list_sources (registry, extension_name);
 
-		for (m = sources; m; m = g_slist_next (m)) {
-			ESource *source = m->data;
-			GCancellable *cancellable;
-			const gchar *completion;
+	for (iter = list; iter != NULL; iter = g_list_next (iter)) {
+		ESource *source = E_SOURCE (iter->data);
+		ESourceAutocomplete *extension;
+		GCancellable *cancellable;
+		const gchar *extension_name;
 
-			/* Skip non-completion sources */
-			completion = e_source_get_property (source, "completion");
-			if (!completion || g_ascii_strcasecmp (completion, "true"))
-				continue;
+		extension_name = E_SOURCE_EXTENSION_AUTOCOMPLETE;
+		extension = e_source_get_extension (source, extension_name);
 
-			cancellable = g_cancellable_new ();
+		/* Skip disabled address books. */
+		if (!e_source_get_enabled (source))
+			continue;
 
-			g_queue_push_tail (
-				&name_selector_entry->priv->cancellables,
-				cancellable);
+		/* Skip non-completion address books. */
+		if (!e_source_autocomplete_get_include_me (extension))
+			continue;
 
-			e_client_utils_open_new (
-				source, E_CLIENT_SOURCE_TYPE_CONTACTS, TRUE, cancellable,
-				e_client_utils_authenticate_handler, NULL,
-				book_loaded_cb, g_object_ref (contact_store));
-		}
+		cancellable = g_cancellable_new ();
+
+		g_queue_push_tail (
+			&name_selector_entry->priv->cancellables,
+			cancellable);
+
+		e_client_utils_open_new (
+			source, E_CLIENT_SOURCE_TYPE_CONTACTS, TRUE, cancellable,
+			book_loaded_cb, g_object_ref (contact_store));
 	}
 
+	g_list_free_full (list, (GDestroyNotify) g_object_unref);
+
 	setup_contact_store (name_selector_entry);
 }
 
@@ -2380,7 +2460,7 @@ find_client_by_contact (GSList *clients,
 			if (!source)
 				continue;
 
-			if (g_strcmp0 (source_uid, e_source_peek_uid (source)) == 0)
+			if (g_strcmp0 (source_uid, e_source_get_uid (source)) == 0)
 				return client;
 		}
 	}
@@ -2991,13 +3071,6 @@ e_name_selector_entry_init (ENameSelectorEntry *name_selector_entry)
 
 	g_queue_init (&name_selector_entry->priv->cancellables);
 
-	/* Source list */
-
-	if (!e_book_client_get_sources (&name_selector_entry->priv->source_list, NULL)) {
-		g_warning ("ENameSelectorEntry can't find any addressbooks!");
-		return;
-	}
-
 	/* read minimum_query_length from gconf*/
 	gconf = gconf_client_get_default ();
 	if (COMPLETION_CUE_MIN_LEN == 0) {
@@ -3012,55 +3085,84 @@ e_name_selector_entry_init (ENameSelectorEntry *name_selector_entry)
 
 	/* Edit signals */
 
-	g_signal_connect (name_selector_entry, "insert-text", G_CALLBACK (user_insert_text), name_selector_entry);
-	g_signal_connect (name_selector_entry, "delete-text", G_CALLBACK (user_delete_text), name_selector_entry);
-	g_signal_connect (name_selector_entry, "focus-out-event", G_CALLBACK (user_focus_out), name_selector_entry);
-	g_signal_connect_after (name_selector_entry, "focus-in-event", G_CALLBACK (user_focus_in), name_selector_entry);
+	g_signal_connect (
+		name_selector_entry, "insert-text",
+		G_CALLBACK (user_insert_text), name_selector_entry);
+	g_signal_connect (
+		name_selector_entry, "delete-text",
+		G_CALLBACK (user_delete_text), name_selector_entry);
+	g_signal_connect (
+		name_selector_entry, "focus-out-event",
+		G_CALLBACK (user_focus_out), name_selector_entry);
+	g_signal_connect_after (
+		name_selector_entry, "focus-in-event",
+		G_CALLBACK (user_focus_in), name_selector_entry);
 
 	/* Drawing */
 
-	g_signal_connect (name_selector_entry, "draw", G_CALLBACK (draw_event), name_selector_entry);
+	g_signal_connect (
+		name_selector_entry, "draw",
+		G_CALLBACK (draw_event), name_selector_entry);
 
 	/* Activation: Complete current entry if possible */
 
-	g_signal_connect (name_selector_entry, "activate", G_CALLBACK (entry_activate), name_selector_entry);
+	g_signal_connect (
+		name_selector_entry, "activate",
+		G_CALLBACK (entry_activate), name_selector_entry);
 
 	/* Pop-up menu */
 
-	g_signal_connect (name_selector_entry, "button-press-event", G_CALLBACK (prepare_popup_destination), name_selector_entry);
-	g_signal_connect (name_selector_entry, "populate-popup", G_CALLBACK (populate_popup), name_selector_entry);
+	g_signal_connect (
+		name_selector_entry, "button-press-event",
+		G_CALLBACK (prepare_popup_destination), name_selector_entry);
+	g_signal_connect (
+		name_selector_entry, "populate-popup",
+		G_CALLBACK (populate_popup), name_selector_entry);
 
 	/* Clipboard signals */
-	g_signal_connect (name_selector_entry, "copy-clipboard", G_CALLBACK (copy_clipboard), name_selector_entry);
-	g_signal_connect (name_selector_entry, "cut-clipboard", G_CALLBACK (cut_clipboard), name_selector_entry);
+	g_signal_connect (
+		name_selector_entry, "copy-clipboard",
+		G_CALLBACK (copy_clipboard), name_selector_entry);
+	g_signal_connect (
+		name_selector_entry, "cut-clipboard",
+		G_CALLBACK (cut_clipboard), name_selector_entry);
 
 	/* Completion */
 
 	name_selector_entry->priv->email_generator = NULL;
 
 	name_selector_entry->priv->entry_completion = gtk_entry_completion_new ();
-	gtk_entry_completion_set_match_func (name_selector_entry->priv->entry_completion,
-				       (GtkEntryCompletionMatchFunc) completion_match_cb, NULL, NULL);
-	g_signal_connect_swapped (name_selector_entry->priv->entry_completion, "match-selected",
-			    G_CALLBACK (completion_match_selected), name_selector_entry);
+	gtk_entry_completion_set_match_func (
+		name_selector_entry->priv->entry_completion,
+		(GtkEntryCompletionMatchFunc) completion_match_cb, NULL, NULL);
+	g_signal_connect_swapped (
+		name_selector_entry->priv->entry_completion, "match-selected",
+		G_CALLBACK (completion_match_selected), name_selector_entry);
 
-	gtk_entry_set_completion (GTK_ENTRY (name_selector_entry), name_selector_entry->priv->entry_completion);
+	gtk_entry_set_completion (
+		GTK_ENTRY (name_selector_entry),
+		name_selector_entry->priv->entry_completion);
 
 	renderer = gtk_cell_renderer_pixbuf_new ();
-	gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (name_selector_entry->priv->entry_completion), renderer, FALSE);
-	gtk_cell_layout_set_cell_data_func (GTK_CELL_LAYOUT (name_selector_entry->priv->entry_completion),
+	gtk_cell_layout_pack_start (
+		GTK_CELL_LAYOUT (name_selector_entry->priv->entry_completion),
+		renderer, FALSE);
+	gtk_cell_layout_set_cell_data_func (
+		GTK_CELL_LAYOUT (name_selector_entry->priv->entry_completion),
 		GTK_CELL_RENDERER (renderer),
 		(GtkCellLayoutDataFunc) contact_layout_pixbuffer,
 		name_selector_entry, NULL);
 
 	/* Completion list name renderer */
 	renderer = gtk_cell_renderer_text_new ();
-	gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (name_selector_entry->priv->entry_completion),
-			      renderer, TRUE);
-	gtk_cell_layout_set_cell_data_func (GTK_CELL_LAYOUT (name_selector_entry->priv->entry_completion),
-				      GTK_CELL_RENDERER (renderer),
-				      (GtkCellLayoutDataFunc) contact_layout_formatter,
-				      name_selector_entry, NULL);
+	gtk_cell_layout_pack_start (
+		GTK_CELL_LAYOUT (name_selector_entry->priv->entry_completion),
+		renderer, TRUE);
+	gtk_cell_layout_set_cell_data_func (
+		GTK_CELL_LAYOUT (name_selector_entry->priv->entry_completion),
+		GTK_CELL_RENDERER (renderer),
+		(GtkCellLayoutDataFunc) contact_layout_formatter,
+		name_selector_entry, NULL);
 
 	/* Destination store */
 
@@ -3077,9 +3179,22 @@ e_name_selector_entry_init (ENameSelectorEntry *name_selector_entry)
  * Returns: A new #ENameSelectorEntry.
  **/
 ENameSelectorEntry *
-e_name_selector_entry_new (void)
+e_name_selector_entry_new (ESourceRegistry *registry)
 {
-	  return g_object_new (e_name_selector_entry_get_type (), NULL);
+	g_return_val_if_fail (E_IS_SOURCE_REGISTRY (registry), NULL);
+
+	return g_object_new (
+		E_TYPE_NAME_SELECTOR_ENTRY,
+		"registry", registry, NULL);
+}
+
+ESourceRegistry *
+e_name_selector_entry_get_registry (ENameSelectorEntry *name_selector_entry)
+{
+	g_return_val_if_fail (
+		E_IS_NAME_SELECTOR_ENTRY (name_selector_entry), NULL);
+
+	return name_selector_entry->priv->registry;
 }
 
 /**
diff --git a/libedataserverui/e-name-selector-entry.h b/libedataserverui/e-name-selector-entry.h
index 99a18ab..bae834d 100644
--- a/libedataserverui/e-name-selector-entry.h
+++ b/libedataserverui/e-name-selector-entry.h
@@ -26,6 +26,7 @@
 
 #include <gtk/gtk.h>
 #include <libebook/e-contact.h>
+#include <libedataserver/e-source-registry.h>
 #include <libedataserverui/e-contact-store.h>
 #include <libedataserverui/e-destination-store.h>
 #include <libedataserverui/e-tree-model-generator.h>
@@ -87,7 +88,10 @@ struct _ENameSelectorEntryClass {
 
 GType		e_name_selector_entry_get_type	(void);
 ENameSelectorEntry *
-		e_name_selector_entry_new	(void);
+		e_name_selector_entry_new	(ESourceRegistry *registry);
+ESourceRegistry *
+		e_name_selector_entry_get_registry
+						(ENameSelectorEntry *name_selector_entry);
 EContactStore *	e_name_selector_entry_peek_contact_store
 						(ENameSelectorEntry *name_selector_entry);
 void		e_name_selector_entry_set_contact_store



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