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



commit 28be09d630a31a9f075f756b52d44201e4e3521d
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 6339df6..6098860 100644
--- a/docs/reference/libedataserverui/libedataserverui-sections.txt
+++ b/docs/reference/libedataserverui/libedataserverui-sections.txt
@@ -255,6 +255,7 @@ MINIMUM_QUERY_LENGTH
 FORCE_SHOW_ADDRESS
 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 7826d8f..1aadf5f 100644
--- a/libedataserverui/e-name-selector-entry.c
+++ b/libedataserverui/e-name-selector-entry.c
@@ -31,6 +31,10 @@
 #include <libebook/e-contact.h>
 #include <libebook/e-destination.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 <libebackend/e-extensible.h>
 #include <libedataserverui/e-client-utils.h>
@@ -43,8 +47,9 @@
 
 struct _ENameSelectorEntryPrivate {
 
+	ESourceRegistry *registry;
+
 	PangoAttrList *attr_list;
-	ESourceList *source_list;
 	EContactStore *contact_store;
 	ETreeModelGenerator *email_generator;
 	EDestinationStore *destination_store;
@@ -73,6 +78,11 @@ struct _ENameSelectorEntryPrivate {
 };
 
 enum {
+	PROP_0,
+	PROP_REGISTRY
+};
+
+enum {
 	UPDATED,
 	LAST_SIGNAL
 };
@@ -109,12 +119,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;
@@ -247,6 +307,8 @@ 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;
 	object_class->constructed = name_selector_entry_constructed;
 
@@ -254,6 +316,18 @@ e_name_selector_entry_class_init (ENameSelectorEntryClass *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,
@@ -2101,9 +2175,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);
 
@@ -2111,36 +2186,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);
+
+		/* Skip disabled address books. */
+		if (!e_source_get_enabled (source))
+			continue;
 
-			cancellable = g_cancellable_new ();
+		/* Skip non-completion address books. */
+		if (!e_source_autocomplete_get_include_me (extension))
+			continue;
 
-			g_queue_push_tail (
-				&name_selector_entry->priv->cancellables,
-				cancellable);
+		cancellable = g_cancellable_new ();
 
-			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));
-		}
+		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);
 }
 
@@ -2398,7 +2478,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;
 		}
 	}
@@ -3009,13 +3089,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) {
@@ -3028,55 +3101,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 */
 
@@ -3093,9 +3195,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 4a4e71d..ab774c5 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>
@@ -80,7 +81,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]