[evolution-data-server/account-mgmt: 33/38] Adapt ESourceSelectorDialog to the new ESource API.



commit 03e11062b98e0dcc968fe8aff693ff9c305e53c8
Author: Matthew Barnes <mbarnes redhat com>
Date:   Sun Dec 5 14:43:50 2010 -0600

    Adapt ESourceSelectorDialog to the new ESource API.

 .../libedataserverui/libedataserverui-sections.txt |    2 +
 libedataserverui/e-name-selector-dialog.c          |  270 +++++++++----
 libedataserverui/e-name-selector-dialog.h          |    9 +-
 libedataserverui/e-source-selector-dialog.c        |  431 +++++++++++++-------
 libedataserverui/e-source-selector-dialog.h        |    8 +-
 5 files changed, 481 insertions(+), 239 deletions(-)
---
diff --git a/docs/reference/libedataserverui/libedataserverui-sections.txt b/docs/reference/libedataserverui/libedataserverui-sections.txt
index 507ec70..44fd093 100644
--- a/docs/reference/libedataserverui/libedataserverui-sections.txt
+++ b/docs/reference/libedataserverui/libedataserverui-sections.txt
@@ -231,6 +231,7 @@ e_name_selector_get_type
 <TITLE>ENameSelectorDialog</TITLE>
 ENameSelectorDialog
 e_name_selector_dialog_new
+e_name_selector_dialog_get_registry
 e_name_selector_dialog_peek_model
 e_name_selector_dialog_set_model
 e_name_selector_dialog_set_destination_index
@@ -436,6 +437,7 @@ e_source_selector_get_type
 <TITLE>ESourceSelectorDialog</TITLE>
 ESourceSelectorDialog
 e_source_selector_dialog_new
+e_source_selector_dialog_get_selector
 e_source_selector_dialog_select_default_source
 e_source_selector_dialog_peek_primary_selection
 <SUBSECTION Standard>
diff --git a/libedataserverui/e-name-selector-dialog.c b/libedataserverui/e-name-selector-dialog.c
index e7650fb..f329db3 100644
--- a/libedataserverui/e-name-selector-dialog.c
+++ b/libedataserverui/e-name-selector-dialog.c
@@ -33,11 +33,11 @@
 
 #include <libedataserver/e-sexp.h>
 #include <libedataserver/e-categories.h>
+#include <libedataserver/e-source-address-book.h>
 
 #include <libebook/e-book-client.h>
 #include <libebook/e-book-client-view.h>
 #include <libebook/e-book-query.h>
-#include <libebook/e-source-address-book.h>
 
 #include "e-source-combo-box.h"
 #include "e-destination-store.h"
@@ -46,6 +46,10 @@
 #include "e-name-selector-dialog.h"
 #include "e-name-selector-entry.h"
 
+#define E_NAME_SELECTOR_DIALOG_GET_PRIVATE(obj) \
+	(G_TYPE_INSTANCE_GET_PRIVATE \
+	((obj), E_TYPE_NAME_SELECTOR_DIALOG, ENameSelectorDialogPrivate))
+
 typedef struct {
 	gchar        *name;
 
@@ -64,6 +68,7 @@ typedef struct {
 } SelData;
 
 struct _ENameSelectorDialogPrivate {
+	ESourceRegistry *registry;
 	ENameSelectorModel *name_selector_model;
 	GtkTreeModelSort *contact_sort;
 	GCancellable *cancellable;
@@ -83,6 +88,11 @@ struct _ENameSelectorDialogPrivate {
 	GtkSizeGroup *dest_label_size_group;
 };
 
+enum {
+	PROP_0,
+	PROP_REGISTRY
+};
+
 static void     search_changed                (ENameSelectorDialog *name_selector_dialog);
 static void     source_changed                (ENameSelectorDialog *name_selector_dialog, ESourceComboBox *source_combo_box);
 static void     transfer_button_clicked       (ENameSelectorDialog *name_selector_dialog, GtkButton *transfer_button);
@@ -109,7 +119,7 @@ static void     destination_column_formatter  (GtkTreeViewColumn *column, GtkCel
 G_DEFINE_TYPE (ENameSelectorDialog, e_name_selector_dialog, GTK_TYPE_DIALOG)
 
 static void
-e_name_selector_dialog_populate_categories (ENameSelectorDialog *name_selector_dialog)
+name_selector_dialog_populate_categories (ENameSelectorDialog *name_selector_dialog)
 {
 	GtkWidget *combo_box;
 	GList *category_list, *iter;
@@ -138,8 +148,91 @@ e_name_selector_dialog_populate_categories (ENameSelectorDialog *name_selector_d
 }
 
 static void
-e_name_selector_dialog_init (ENameSelectorDialog *name_selector_dialog)
+name_selector_dialog_set_registry (ENameSelectorDialog *name_selector_dialog,
+                                   ESourceRegistry *registry)
+{
+	g_return_if_fail (E_IS_SOURCE_REGISTRY (registry));
+	g_return_if_fail (name_selector_dialog->priv->registry == NULL);
+
+	name_selector_dialog->priv->registry = g_object_ref (registry);
+}
+
+static void
+name_selector_dialog_set_property (GObject *object,
+                                   guint property_id,
+                                   const GValue *value,
+                                   GParamSpec *pspec)
+{
+	switch (property_id) {
+		case PROP_REGISTRY:
+			name_selector_dialog_set_registry (
+				E_NAME_SELECTOR_DIALOG (object),
+				g_value_get_object (value));
+			return;
+	}
+
+	G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
+}
+
+static void
+name_selector_dialog_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_dialog_get_registry (
+				E_NAME_SELECTOR_DIALOG (object)));
+			return;
+	}
+
+	G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
+}
+
+static void
+name_selector_dialog_dispose (GObject *object)
+{
+	ENameSelectorDialogPrivate *priv;
+
+	priv = E_NAME_SELECTOR_DIALOG_GET_PRIVATE (object);
+
+	remove_books (E_NAME_SELECTOR_DIALOG (object));
+	shutdown_name_selector_model (E_NAME_SELECTOR_DIALOG (object));
+
+	if (priv->registry != NULL) {
+		g_object_unref (priv->registry);
+		priv->registry = NULL;
+	}
+
+	/* Chain up to parent's dispose() method. */
+	G_OBJECT_CLASS (e_name_selector_dialog_parent_class)->dispose (object);
+}
+
+static void
+name_selector_dialog_finalize (GObject *object)
+{
+	ENameSelectorDialogPrivate *priv;
+
+	priv = E_NAME_SELECTOR_DIALOG_GET_PRIVATE (object);
+
+	g_slist_foreach (priv->user_query_fields, (GFunc) g_free, NULL);
+	g_slist_free (priv->user_query_fields);
+
+	g_array_free (priv->sections, TRUE);
+	g_object_unref (priv->button_size_group);
+	g_object_unref (priv->dest_label_size_group);
+
+	/* Chain up to parent's finalize() method. */
+	G_OBJECT_CLASS (e_name_selector_dialog_parent_class)->finalize (object);
+}
+
+static void
+name_selector_dialog_constructed (GObject *object)
 {
+	ENameSelectorDialogPrivate *priv;
 	GtkTreeSelection  *contact_selection;
 	GtkTreeViewColumn *column;
 	GtkCellRenderer   *cell_renderer;
@@ -172,11 +265,12 @@ e_name_selector_dialog_init (ENameSelectorDialog *name_selector_dialog)
 	GtkWidget *destination_box;
 	GtkWidget *status_message;
 	GtkWidget *source_combo;
-	ESourceRegistry *registry;
+	const gchar *extension_name;
+
+	priv = E_NAME_SELECTOR_DIALOG_GET_PRIVATE (object);
 
-	name_selector_dialog->priv = G_TYPE_INSTANCE_GET_PRIVATE (
-		name_selector_dialog, E_TYPE_NAME_SELECTOR_DIALOG,
-		ENameSelectorDialogPrivate);
+	/* Chain up to parent's constructed() method. */
+	G_OBJECT_CLASS (e_name_selector_dialog_parent_class)->constructed (object);
 
 	name_selector_box = gtk_vbox_new (FALSE, 6);
 	gtk_widget_show (name_selector_box);
@@ -259,7 +353,7 @@ e_name_selector_dialog_init (ENameSelectorDialog *name_selector_dialog)
 	g_free (tmp_str);
 
 	scrolledwindow0 = gtk_scrolled_window_new (NULL, NULL);
-	name_selector_dialog->priv->contact_window = scrolledwindow0;
+	priv->contact_window = scrolledwindow0;
 	gtk_widget_show (scrolledwindow0);
 	gtk_box_pack_start (GTK_BOX (name_selector_box), scrolledwindow0,
 			    TRUE, TRUE, 0);
@@ -320,24 +414,24 @@ e_name_selector_dialog_init (ENameSelectorDialog *name_selector_dialog)
 	g_object_unref (G_OBJECT (tmp_relation));
 	g_object_unref (G_OBJECT (tmp_relation_set));
 
-	gtk_box_pack_start (GTK_BOX (gtk_dialog_get_content_area (GTK_DIALOG (name_selector_dialog))), name_selector_box, TRUE, TRUE, 0);
+	gtk_box_pack_start (GTK_BOX (gtk_dialog_get_content_area (GTK_DIALOG (object))), name_selector_box, TRUE, TRUE, 0);
 
 	/* Store pointers to relevant widgets */
 
-	name_selector_dialog->priv->contact_view = GTK_TREE_VIEW (source_tree_view);
-	name_selector_dialog->priv->status_label = GTK_LABEL (status_message);
-	name_selector_dialog->priv->destination_box = GTK_BOX (destination_box);
-	name_selector_dialog->priv->search_entry = GTK_ENTRY (search);
-	name_selector_dialog->priv->category_combobox = combobox_category;
+	priv->contact_view = GTK_TREE_VIEW (source_tree_view);
+	priv->status_label = GTK_LABEL (status_message);
+	priv->destination_box = GTK_BOX (destination_box);
+	priv->search_entry = GTK_ENTRY (search);
+	priv->category_combobox = combobox_category;
 
 	/* Create size group for transfer buttons */
 
-	name_selector_dialog->priv->button_size_group =
+	priv->button_size_group =
 		gtk_size_group_new (GTK_SIZE_GROUP_HORIZONTAL);
 
 	/* Create size group for destination labels */
 
-	name_selector_dialog->priv->dest_label_size_group =
+	priv->dest_label_size_group =
 		gtk_size_group_new (GTK_SIZE_GROUP_HORIZONTAL);
 
 	/* Set up contacts view */
@@ -345,50 +439,46 @@ e_name_selector_dialog_init (ENameSelectorDialog *name_selector_dialog)
 	column = gtk_tree_view_column_new ();
 	cell_renderer = GTK_CELL_RENDERER (gtk_cell_renderer_text_new ());
 	gtk_tree_view_column_pack_start (column, cell_renderer, TRUE);
-	gtk_tree_view_column_set_cell_data_func (column, cell_renderer,
-						 (GtkTreeCellDataFunc) contact_column_formatter,
-						 name_selector_dialog, NULL);
+	gtk_tree_view_column_set_cell_data_func (
+		column, cell_renderer, (GtkTreeCellDataFunc)
+		contact_column_formatter, object, NULL);
 
-	selection = gtk_tree_view_get_selection (
-		name_selector_dialog->priv->contact_view);
+	selection = gtk_tree_view_get_selection (priv->contact_view);
 	gtk_tree_selection_set_mode (selection, GTK_SELECTION_MULTIPLE);
-	gtk_tree_view_append_column (
-		name_selector_dialog->priv->contact_view, column);
+	gtk_tree_view_append_column (priv->contact_view, column);
 	g_signal_connect_swapped (
-		name_selector_dialog->priv->contact_view, "row-activated",
-		G_CALLBACK (contact_activated), name_selector_dialog);
+		priv->contact_view, "row-activated",
+		G_CALLBACK (contact_activated), object);
 
 	/* Listen for changes to the contact selection */
 
-	contact_selection = gtk_tree_view_get_selection (
-		name_selector_dialog->priv->contact_view);
-	g_signal_connect_swapped (contact_selection, "changed",
-				  G_CALLBACK (contact_selection_changed), name_selector_dialog);
+	contact_selection = gtk_tree_view_get_selection (priv->contact_view);
+	g_signal_connect_swapped (
+		contact_selection, "changed",
+		G_CALLBACK (contact_selection_changed), object);
 
 	/* Set up our data structures */
 
-	name_selector_dialog->priv->name_selector_model =
-		e_name_selector_model_new ();
-	name_selector_dialog->priv->sections =
-		g_array_new (FALSE, FALSE, sizeof (Section));
+	priv->name_selector_model = e_name_selector_model_new ();
+	priv->sections = g_array_new (FALSE, FALSE, sizeof (Section));
 
 	gconf_client = gconf_client_get_default ();
 	uid = gconf_client_get_string (gconf_client, "/apps/evolution/addressbook/display/primary_addressbook",
 			NULL);
 	/* read user_query_fields here, because we are using it in call of setup_name_selector_model */
-	name_selector_dialog->priv->user_query_fields = gconf_client_get_list (
+	priv->user_query_fields = gconf_client_get_list (
 		gconf_client, USER_QUERY_FIELDS, GCONF_VALUE_STRING, NULL);
 	g_object_unref (gconf_client);
 
-	setup_name_selector_model (name_selector_dialog);
+	setup_name_selector_model (E_NAME_SELECTOR_DIALOG (object));
 
 	/* Create source menu */
 
-	registry = e_source_registry_get_default ();
-	source_combo = e_source_combo_box_new (registry, "address-book");
+	extension_name = E_SOURCE_EXTENSION_ADDRESS_BOOK;
+	source_combo = e_source_combo_box_new (priv->registry, extension_name);
 	g_signal_connect_swapped (
 		source_combo, "changed",
-		G_CALLBACK (source_changed), name_selector_dialog);
+		G_CALLBACK (source_changed), object);
 
 	if (uid) {
 		e_source_combo_box_set_active_uid (
@@ -400,11 +490,14 @@ e_name_selector_dialog_init (ENameSelectorDialog *name_selector_dialog)
 	gtk_widget_show (source_combo);
 	gtk_box_pack_start (GTK_BOX (source_menu_box), source_combo, TRUE, TRUE, 0);
 
-	e_name_selector_dialog_populate_categories (name_selector_dialog);
+	name_selector_dialog_populate_categories (
+		E_NAME_SELECTOR_DIALOG (object));
 
 	/* Set up search-as-you-type signal */
 
-	g_signal_connect_swapped (search, "changed", G_CALLBACK (search_changed), name_selector_dialog);
+	g_signal_connect_swapped (
+		search, "changed",
+		G_CALLBACK (search_changed), object);
 
 	/* Display initial source */
 
@@ -412,48 +505,24 @@ e_name_selector_dialog_init (ENameSelectorDialog *name_selector_dialog)
 
 	/* Set up dialog defaults */
 
-	gtk_dialog_add_buttons (GTK_DIALOG (name_selector_dialog),
-				GTK_STOCK_CLOSE, GTK_RESPONSE_CLOSE,
-				NULL);
-
-	gtk_dialog_set_default_response (GTK_DIALOG (name_selector_dialog), GTK_RESPONSE_CLOSE);
-	gtk_window_set_modal            (GTK_WINDOW (name_selector_dialog), TRUE);
-	gtk_window_set_default_size     (GTK_WINDOW (name_selector_dialog), 700, -1);
-	gtk_window_set_resizable        (GTK_WINDOW (name_selector_dialog), TRUE);
-	gtk_container_set_border_width  (GTK_CONTAINER (name_selector_dialog), 4);
-	gtk_window_set_title            (GTK_WINDOW (name_selector_dialog), _("Select Contacts from Address Book"));
+	gtk_dialog_add_buttons (
+		GTK_DIALOG (object),
+		GTK_STOCK_CLOSE, GTK_RESPONSE_CLOSE,
+		NULL);
+
+	gtk_dialog_set_default_response (
+		GTK_DIALOG (object), GTK_RESPONSE_CLOSE);
+	gtk_window_set_modal (GTK_WINDOW (object), TRUE);
+	gtk_window_set_default_size (GTK_WINDOW (object), 700, -1);
+	gtk_window_set_resizable (GTK_WINDOW (object), TRUE);
+	gtk_container_set_border_width (GTK_CONTAINER (object), 4);
+	gtk_window_set_title (
+		GTK_WINDOW (object),
+		_("Select Contacts from Address Book"));
 	gtk_widget_grab_focus (search);
 }
 
 static void
-e_name_selector_dialog_dispose (GObject *object)
-{
-	remove_books (E_NAME_SELECTOR_DIALOG (object));
-	shutdown_name_selector_model (E_NAME_SELECTOR_DIALOG (object));
-
-	/* Chain up to parent's dispose() method. */
-	G_OBJECT_CLASS (e_name_selector_dialog_parent_class)->dispose (object);
-}
-
-static void
-e_name_selector_dialog_finalize (GObject *object)
-{
-	ENameSelectorDialogPrivate *priv;
-
-	priv = E_NAME_SELECTOR_DIALOG (object)->priv;
-
-	g_slist_foreach (priv->user_query_fields, (GFunc) g_free, NULL);
-	g_slist_free (priv->user_query_fields);
-
-	g_array_free (priv->sections, TRUE);
-	g_object_unref (priv->button_size_group);
-	g_object_unref (priv->dest_label_size_group);
-
-	/* Chain up to parent's finalize() method. */
-	G_OBJECT_CLASS (e_name_selector_dialog_parent_class)->finalize (object);
-}
-
-static void
 e_name_selector_dialog_class_init (ENameSelectorDialogClass *class)
 {
 	GObjectClass *object_class;
@@ -461,21 +530,57 @@ e_name_selector_dialog_class_init (ENameSelectorDialogClass *class)
 	g_type_class_add_private (class, sizeof (ENameSelectorDialogPrivate));
 
 	object_class = G_OBJECT_CLASS (class);
-	object_class->dispose = e_name_selector_dialog_dispose;
-	object_class->finalize = e_name_selector_dialog_finalize;
+	object_class->set_property = name_selector_dialog_set_property;
+	object_class->get_property = name_selector_dialog_get_property;
+	object_class->dispose = name_selector_dialog_dispose;
+	object_class->finalize = name_selector_dialog_finalize;
+	object_class->constructed = name_selector_dialog_constructed;
+
+	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));
+}
+
+static void
+e_name_selector_dialog_init (ENameSelectorDialog *name_selector_dialog)
+{
+	name_selector_dialog->priv =
+		E_NAME_SELECTOR_DIALOG_GET_PRIVATE (name_selector_dialog);
 }
 
 /**
  * e_name_selector_dialog_new:
+ * @registry: an #ESourceRegistry
  *
  * Creates a new #ENameSelectorDialog.
  *
  * Returns: A new #ENameSelectorDialog.
  **/
 ENameSelectorDialog *
-e_name_selector_dialog_new (void)
+e_name_selector_dialog_new (ESourceRegistry *registry)
+{
+	g_return_val_if_fail (E_IS_SOURCE_REGISTRY (registry), NULL);
+
+	return g_object_new (
+		E_TYPE_NAME_SELECTOR_DIALOG,
+		"registry", registry, NULL);
+}
+
+ESourceRegistry *
+e_name_selector_dialog_get_registry (ENameSelectorDialog *name_selector_dialog)
 {
-	  return g_object_new (E_TYPE_NAME_SELECTOR_DIALOG, NULL);
+	g_return_val_if_fail (
+		E_IS_NAME_SELECTOR_DIALOG (name_selector_dialog), NULL);
+
+	return name_selector_dialog->priv->registry;
 }
 
 /* --------- *
@@ -992,7 +1097,6 @@ source_changed (ENameSelectorDialog *name_selector_dialog,
 	/* Start loading selected book */
 	e_client_utils_open_new (
 		source, E_CLIENT_SOURCE_TYPE_CONTACTS, TRUE, cancellable,
-		e_client_utils_authenticate_handler, parent,
 		book_loaded_cb, g_object_ref (name_selector_dialog));
 }
 
diff --git a/libedataserverui/e-name-selector-dialog.h b/libedataserverui/e-name-selector-dialog.h
index e3280cc..35d93b3 100644
--- a/libedataserverui/e-name-selector-dialog.h
+++ b/libedataserverui/e-name-selector-dialog.h
@@ -25,6 +25,7 @@
 #define E_NAME_SELECTOR_DIALOG_H
 
 #include <gtk/gtk.h>
+#include <libedataserver/e-source-registry.h>
 #include <libedataserverui/e-contact-store.h>
 #include <libedataserverui/e-name-selector-model.h>
 
@@ -64,11 +65,15 @@ struct _ENameSelectorDialogClass {
 
 GType		e_name_selector_dialog_get_type	(void);
 ENameSelectorDialog *
-		e_name_selector_dialog_new	(void);
+		e_name_selector_dialog_new	(ESourceRegistry *registry);
+ESourceRegistry *
+		e_name_selector_dialog_get_registry
+						(ENameSelectorDialog *name_selector_dialog);
 ENameSelectorModel *
 		e_name_selector_dialog_peek_model
 						(ENameSelectorDialog *name_selector_dialog);
-void		e_name_selector_dialog_set_model (ENameSelectorDialog *name_selector_dialog,
+void		e_name_selector_dialog_set_model
+						(ENameSelectorDialog *name_selector_dialog,
 						 ENameSelectorModel  *model);
 void		e_name_selector_dialog_set_destination_index
 						(ENameSelectorDialog *name_selector_dialog,
diff --git a/libedataserverui/e-source-selector-dialog.c b/libedataserverui/e-source-selector-dialog.c
index cdd7064..721b79b 100644
--- a/libedataserverui/e-source-selector-dialog.c
+++ b/libedataserverui/e-source-selector-dialog.c
@@ -29,206 +29,351 @@
 #include "e-source-selector.h"
 #include "e-source-selector-dialog.h"
 
+#define E_SOURCE_SELECTOR_DIALOG_GET_PRIVATE(obj) \
+	(G_TYPE_INSTANCE_GET_PRIVATE \
+	((obj), E_TYPE_SOURCE_SELECTOR_DIALOG, ESourceSelectorDialogPrivate))
+
 struct _ESourceSelectorDialogPrivate {
-	GtkWidget *source_selector;
-	ESourceList *source_list;
+	GtkWidget *selector;
+	ESourceRegistry *registry;
 	ESource *selected_source;
+	gchar *extension_name;
 };
 
-static GObjectClass *parent_class = NULL;
+enum {
+	PROP_0,
+	PROP_EXTENSION_NAME,
+	PROP_REGISTRY,
+	PROP_SELECTOR
+};
 
-/* GObject methods */
+G_DEFINE_TYPE (
+	ESourceSelectorDialog,
+	e_source_selector_dialog, GTK_TYPE_DIALOG)
 
-G_DEFINE_TYPE (ESourceSelectorDialog, e_source_selector_dialog, GTK_TYPE_DIALOG)
+static void
+source_selector_dialog_row_activated_cb (GtkTreeView *tree_view,
+                                         GtkTreePath *path,
+                                         GtkTreeViewColumn *column,
+                                         GtkWidget *dialog)
+{
+	gtk_dialog_response (GTK_DIALOG (dialog), GTK_RESPONSE_OK);
+}
 
 static void
-e_source_selector_dialog_dispose (GObject *object)
+primary_selection_changed_cb (ESourceSelector *selector,
+                              ESourceSelectorDialog *dialog)
 {
-	ESourceSelectorDialogPrivate *priv = E_SOURCE_SELECTOR_DIALOG (object)->priv;
+	ESourceSelectorDialogPrivate *priv = dialog->priv;
 
-	if (priv->source_list) {
-		g_object_unref (priv->source_list);
-		priv->source_list = NULL;
-	}
+	if (priv->selected_source != NULL)
+		g_object_unref (priv->selected_source);
+	priv->selected_source =
+		e_source_selector_get_primary_selection (selector);
 
+	/* FIXME Add an API for "except-source" or to
+	 *       get the ESourceSelector from outside. */
 	if (priv->selected_source) {
-		g_object_unref (priv->selected_source);
-		priv->selected_source = NULL;
+		ESource *except_source;
+
+		except_source = g_object_get_data (
+			G_OBJECT (dialog), "except-source");
+
+		if (except_source != NULL)
+			if (e_source_equal (except_source, priv->selected_source))
+				priv->selected_source = NULL;
 	}
 
-	(*G_OBJECT_CLASS (parent_class)->dispose) (object);
+	if (priv->selected_source != NULL) {
+		g_object_ref (priv->selected_source);
+		gtk_dialog_set_response_sensitive (
+			GTK_DIALOG (dialog), GTK_RESPONSE_OK, TRUE);
+	} else
+		gtk_dialog_set_response_sensitive (
+			GTK_DIALOG (dialog), GTK_RESPONSE_OK, FALSE);
 }
 
 static void
-e_source_selector_dialog_finalize (GObject *object)
+source_selector_dialog_set_extension_name (ESourceSelectorDialog *dialog,
+                                           const gchar *extension_name)
 {
-	ESourceSelectorDialogPrivate *priv = E_SOURCE_SELECTOR_DIALOG (object)->priv;
+	g_return_if_fail (extension_name != NULL);
+	g_return_if_fail (dialog->priv->extension_name == NULL);
 
-	g_free (priv);
-	E_SOURCE_SELECTOR_DIALOG (object)->priv = NULL;
-
-	(* G_OBJECT_CLASS (parent_class)->finalize) (object);
+	dialog->priv->extension_name = g_strdup (extension_name);
 }
 
 static void
-e_source_selector_dialog_class_init (ESourceSelectorDialogClass *klass)
+source_selector_dialog_set_registry (ESourceSelectorDialog *dialog,
+                                     ESourceRegistry *registry)
 {
-	GObjectClass *object_class = G_OBJECT_CLASS (klass);
-
-	object_class->dispose = e_source_selector_dialog_dispose;
-	object_class->finalize = e_source_selector_dialog_finalize;
+	g_return_if_fail (E_IS_SOURCE_REGISTRY (registry));
+	g_return_if_fail (dialog->priv->registry == NULL);
 
-	parent_class = g_type_class_peek_parent (klass);
+	dialog->priv->registry = g_object_ref (registry);
 }
 
 static void
-e_source_selector_dialog_init (ESourceSelectorDialog *dialog)
+source_selector_dialog_set_property (GObject *object,
+                                     guint property_id,
+                                     const GValue *value,
+                                     GParamSpec *pspec)
 {
-	ESourceSelectorDialogPrivate *priv;
-	GtkWidget *action_area;
-	GtkWidget *content_area;
-
-	priv = g_new0 (ESourceSelectorDialogPrivate, 1);
-	priv->selected_source = NULL;
-	dialog->priv = priv;
-
-	action_area = gtk_dialog_get_action_area (GTK_DIALOG (dialog));
-	content_area = gtk_dialog_get_content_area (GTK_DIALOG (dialog));
+	switch (property_id) {
+		case PROP_EXTENSION_NAME:
+			source_selector_dialog_set_extension_name (
+				E_SOURCE_SELECTOR_DIALOG (object),
+				g_value_get_string (value));
+			return;
+
+		case PROP_REGISTRY:
+			source_selector_dialog_set_registry (
+				E_SOURCE_SELECTOR_DIALOG (object),
+				g_value_get_object (value));
+			return;
+	}
 
-	/* prepare the dialog */
-	gtk_window_set_title (GTK_WINDOW (dialog), _("Select destination"));
-	gtk_window_set_default_size (GTK_WINDOW (dialog), 320, 240);
-	gtk_container_set_border_width (GTK_CONTAINER (content_area), 0);
-	gtk_container_set_border_width (GTK_CONTAINER (action_area), 12);
-	gtk_dialog_add_buttons (GTK_DIALOG (dialog),
-				GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
-				GTK_STOCK_OK, GTK_RESPONSE_OK,
-				NULL);
-	gtk_dialog_set_default_response (GTK_DIALOG (dialog), GTK_RESPONSE_OK);
-	gtk_dialog_set_response_sensitive (GTK_DIALOG (dialog), GTK_RESPONSE_OK, FALSE);
+	G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
 }
 
-/* Public API */
-
 static void
-row_activated_cb (GtkTreeView *tree_view,
-                  GtkTreePath *path,
-                  GtkTreeViewColumn *column,
-                  GtkWidget *dialog)
+source_selector_dialog_get_property (GObject *object,
+                                     guint property_id,
+                                     GValue *value,
+                                     GParamSpec *pspec)
 {
-	gtk_dialog_response (GTK_DIALOG (dialog), GTK_RESPONSE_OK);
+	switch (property_id) {
+		case PROP_SELECTOR:
+			g_value_set_object (
+				value,
+				e_source_selector_dialog_get_selector (
+				E_SOURCE_SELECTOR_DIALOG (object)));
+			return;
+	}
+
+	G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
 }
 
 static void
-primary_selection_changed_cb (ESourceSelector *selector,
-                              gpointer user_data)
+source_selector_dialog_dispose (GObject *object)
 {
-	ESourceSelectorDialog *dialog = user_data;
-	ESourceSelectorDialogPrivate *priv = dialog->priv;
+	ESourceSelectorDialogPrivate *priv;
 
-	if (priv->selected_source)
+	priv = E_SOURCE_SELECTOR_DIALOG_GET_PRIVATE (object);
+
+	if (priv->registry != NULL) {
+		g_object_unref (priv->registry);
+		priv->registry = NULL;
+	}
+
+	if (priv->selected_source != NULL) {
 		g_object_unref (priv->selected_source);
-	priv->selected_source = e_source_selector_get_primary_selection (selector);
+		priv->selected_source = NULL;
+	}
 
-	/* FIXME: add an API to "except-source" or to get the ESourceSelector from outside */
-	if (priv->selected_source) {
-		ESource *except_source = g_object_get_data (G_OBJECT (dialog), "except-source");
+	/* Chain up to parent's dispose() method. */
+	G_OBJECT_CLASS (e_source_selector_dialog_parent_class)->dispose (object);
+}
 
-		if (except_source) {
-			const gchar *except_uid, *selected_uid;
+static void
+source_selector_dialog_finalize (GObject *object)
+{
+	ESourceSelectorDialogPrivate *priv;
 
-			except_uid = e_source_peek_uid (except_source);
-			selected_uid = e_source_peek_uid (priv->selected_source);
+	priv = E_SOURCE_SELECTOR_DIALOG_GET_PRIVATE (object);
 
-			if (except_uid && selected_uid && g_str_equal (except_uid, selected_uid))
-				priv->selected_source = NULL;
-		}
-	}
+	g_free (priv->extension_name);
 
-	if (priv->selected_source) {
-		g_object_ref (priv->selected_source);
-		gtk_dialog_set_response_sensitive (GTK_DIALOG (dialog), GTK_RESPONSE_OK, TRUE);
-	} else
-		gtk_dialog_set_response_sensitive (GTK_DIALOG (dialog), GTK_RESPONSE_OK, FALSE);
+	/* Chain up to parent's finalize() method. */
+	G_OBJECT_CLASS (e_source_selector_dialog_parent_class)->finalize (object);
 }
 
-static GtkWidget *
-setup_dialog (GtkWindow *parent,
-              ESourceSelectorDialog *dialog,
-              ESourceList *source_list)
+static void
+source_selector_dialog_constructed (GObject *object)
 {
-	GtkWidget *vbox, *label, *scroll, *hbox, *spacer;
-	GtkWidget *content_area;
+	ESourceSelectorDialog *dialog;
+	GtkWidget *label, *hbox;
+	GtkWidget *container;
+	GtkWidget *widget;
 	gchar *label_text;
-	ESourceSelectorDialogPrivate *priv = dialog->priv;
 
-	priv->source_list = g_object_ref (source_list);
+	dialog = E_SOURCE_SELECTOR_DIALOG (object);
 
-	content_area = gtk_dialog_get_content_area (GTK_DIALOG (dialog));
+	container = gtk_dialog_get_content_area (GTK_DIALOG (dialog));
 
-	vbox = gtk_vbox_new (FALSE, 12);
-	gtk_container_set_border_width (GTK_CONTAINER (vbox), 12);
-	gtk_box_pack_start (GTK_BOX (content_area), vbox, TRUE, TRUE, 0);
-	gtk_widget_show (vbox);
+	widget = gtk_vbox_new (FALSE, 12);
+	gtk_container_set_border_width (GTK_CONTAINER (widget), 12);
+	gtk_box_pack_start (GTK_BOX (container), widget, TRUE, TRUE, 0);
+	gtk_widget_show (widget);
+
+	container = widget;
 
 	label_text = g_strdup_printf ("<b>%s</b>", _("_Destination"));
 	label = gtk_label_new_with_mnemonic (label_text);
 	gtk_label_set_use_markup (GTK_LABEL (label), TRUE);
 	gtk_misc_set_alignment (GTK_MISC (label), 0, 0.5);
-	g_free (label_text);
+	gtk_box_pack_start (GTK_BOX (container), label, FALSE, FALSE, 0);
 	gtk_widget_show (label);
-	gtk_box_pack_start (GTK_BOX (vbox), label, FALSE, FALSE, 0);
+	g_free (label_text);
 
 	hbox = gtk_hbox_new (FALSE, 12);
-	gtk_box_pack_start (GTK_BOX (vbox), hbox, TRUE, TRUE, 0);
+	gtk_box_pack_start (GTK_BOX (container), hbox, TRUE, TRUE, 0);
 	gtk_widget_show (hbox);
 
-	spacer = gtk_label_new ("");
-	gtk_box_pack_start (GTK_BOX (hbox), spacer, FALSE, FALSE, 0);
-	gtk_widget_show (spacer);
-
-	scroll = gtk_scrolled_window_new (NULL, NULL);
-	gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scroll),
-					GTK_POLICY_AUTOMATIC,
-					GTK_POLICY_AUTOMATIC);
-	gtk_scrolled_window_set_shadow_type (GTK_SCROLLED_WINDOW (scroll),
-					     GTK_SHADOW_IN);
-	gtk_widget_show (scroll);
-	priv->source_selector = e_source_selector_new (source_list);
-	e_source_selector_show_selection (E_SOURCE_SELECTOR (priv->source_selector), FALSE);
-	g_signal_connect (G_OBJECT (priv->source_selector), "row_activated",
-			  G_CALLBACK (row_activated_cb), dialog);
-	g_signal_connect (G_OBJECT (priv->source_selector), "primary_selection_changed",
-			  G_CALLBACK (primary_selection_changed_cb), dialog);
-	gtk_widget_show (priv->source_selector);
-	gtk_container_add (GTK_CONTAINER (scroll), priv->source_selector);
-	gtk_box_pack_start (GTK_BOX (hbox), scroll, TRUE, TRUE, 0);
-
-	gtk_label_set_mnemonic_widget (GTK_LABEL (label), priv->source_selector);
-
-	return GTK_WIDGET (dialog);
+	widget = gtk_label_new ("");
+	gtk_box_pack_start (GTK_BOX (hbox), widget, FALSE, FALSE, 0);
+	gtk_widget_show (widget);
+
+	widget = gtk_scrolled_window_new (NULL, NULL);
+	gtk_scrolled_window_set_policy (
+		GTK_SCROLLED_WINDOW (widget),
+		GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC);
+	gtk_scrolled_window_set_shadow_type (
+		GTK_SCROLLED_WINDOW (widget), GTK_SHADOW_IN);
+	gtk_box_pack_start (GTK_BOX (hbox), widget, TRUE, TRUE, 0);
+	gtk_widget_show (widget);
+
+	container = widget;
+
+	widget = e_source_selector_new (
+		dialog->priv->registry,
+		dialog->priv->extension_name);
+	e_source_selector_show_selection (E_SOURCE_SELECTOR (widget), FALSE);
+	gtk_label_set_mnemonic_widget (GTK_LABEL (label), widget);
+	gtk_container_add (GTK_CONTAINER (container), widget);
+	dialog->priv->selector = widget;
+	gtk_widget_show (widget);
+
+	g_signal_connect (
+		G_OBJECT (widget), "row_activated",
+		G_CALLBACK (source_selector_dialog_row_activated_cb), dialog);
+	g_signal_connect (
+		G_OBJECT (widget), "primary_selection_changed",
+		G_CALLBACK (primary_selection_changed_cb), dialog);
+}
+
+static void
+e_source_selector_dialog_class_init (ESourceSelectorDialogClass *class)
+{
+	GObjectClass *object_class;
+
+	g_type_class_add_private (class, sizeof (ESourceSelectorDialogPrivate));
+
+	object_class = G_OBJECT_CLASS (class);
+	object_class->set_property = source_selector_dialog_set_property;
+	object_class->get_property = source_selector_dialog_get_property;
+	object_class->dispose = source_selector_dialog_dispose;
+	object_class->finalize = source_selector_dialog_finalize;
+	object_class->constructed = source_selector_dialog_constructed;
+
+	g_object_class_install_property (
+		object_class,
+		PROP_EXTENSION_NAME,
+		g_param_spec_string (
+			"extension-name",
+			NULL,
+			NULL,
+			NULL,
+			G_PARAM_WRITABLE |
+			G_PARAM_CONSTRUCT_ONLY));
+
+	g_object_class_install_property (
+		object_class,
+		PROP_REGISTRY,
+		g_param_spec_object (
+			"registry",
+			NULL,
+			NULL,
+			E_TYPE_SOURCE_REGISTRY,
+			G_PARAM_WRITABLE |
+			G_PARAM_CONSTRUCT_ONLY));
+
+	g_object_class_install_property (
+		object_class,
+		PROP_SELECTOR,
+		g_param_spec_object (
+			"selector",
+			NULL,
+			NULL,
+			E_TYPE_SOURCE_SELECTOR,
+			G_PARAM_READABLE));
+}
+
+static void
+e_source_selector_dialog_init (ESourceSelectorDialog *dialog)
+{
+	GtkWidget *action_area;
+	GtkWidget *content_area;
+
+	dialog->priv = E_SOURCE_SELECTOR_DIALOG_GET_PRIVATE (dialog);
+
+	action_area = gtk_dialog_get_action_area (GTK_DIALOG (dialog));
+	content_area = gtk_dialog_get_content_area (GTK_DIALOG (dialog));
+
+	gtk_window_set_title (GTK_WINDOW (dialog), _("Select destination"));
+	gtk_window_set_default_size (GTK_WINDOW (dialog), 320, 240);
+#if !GTK_CHECK_VERSION(2,90,7)
+	g_object_set (dialog, "has-separator", FALSE, NULL);
+#endif
+
+	gtk_widget_ensure_style (GTK_WIDGET (dialog));
+	gtk_container_set_border_width (GTK_CONTAINER (content_area), 0);
+	gtk_container_set_border_width (GTK_CONTAINER (action_area), 12);
+
+	gtk_dialog_add_buttons (
+		GTK_DIALOG (dialog),
+		GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
+		GTK_STOCK_OK, GTK_RESPONSE_OK, NULL);
+	gtk_dialog_set_default_response (
+		GTK_DIALOG (dialog), GTK_RESPONSE_OK);
+	gtk_dialog_set_response_sensitive (
+		GTK_DIALOG (dialog), GTK_RESPONSE_OK, FALSE);
 }
 
 /**
  * e_source_selector_dialog_new:
  * @parent: a parent window
- * @source_list: an #ESourceList
+ * @registry: an #ESourceRegistry
+ * @extension_name: the name of an #ESource extension
  *
- * Create a new source selector dialog for the given @list.
+ * Displays a list of sources from @registry having an extension named
+ * @extension_name in a dialog window.  The sources are grouped by backend
+ * or groupware account, which are described by the parent source.
  *
  * Returns: a new #ESourceSelectorDialog
  **/
 GtkWidget *
 e_source_selector_dialog_new (GtkWindow *parent,
-                              ESourceList *source_list)
+                              ESourceRegistry *registry,
+                              const gchar *extension_name)
 {
-	ESourceSelectorDialog *dialog;
-
-	g_return_val_if_fail (E_IS_SOURCE_LIST (source_list), NULL);
+	g_return_val_if_fail (E_IS_SOURCE_REGISTRY (registry), NULL);
+	g_return_val_if_fail (extension_name != NULL, NULL);
+
+	return g_object_new (
+		E_TYPE_SOURCE_SELECTOR_DIALOG,
+		"transient-for", parent,
+		"registry", registry,
+		"extension-name", extension_name,
+		NULL);
+}
 
-	dialog = g_object_new (E_TYPE_SOURCE_SELECTOR_DIALOG, NULL);
+/**
+ * e_source_selector_dialog_get_selector:
+ * @dialog: an #ESourceSelectorDialog
+ *
+ * Returns the #ESourceSelector widget embedded in @dialog.
+ *
+ * Returns: the #ESourceSelector widget
+ *
+ * Since: 3.4
+ **/
+ESourceSelector *
+e_source_selector_dialog_get_selector (ESourceSelectorDialog *dialog)
+{
+	g_return_val_if_fail (E_IS_SOURCE_SELECTOR_DIALOG (dialog), NULL);
 
-	return setup_dialog (parent, dialog, source_list);
+	return E_SOURCE_SELECTOR (dialog->priv->selector);
 }
 
 /**
@@ -244,39 +389,21 @@ e_source_selector_dialog_new (GtkWindow *parent,
 gboolean
 e_source_selector_dialog_select_default_source (ESourceSelectorDialog *dialog)
 {
-	ESourceSelectorDialogPrivate *priv;
+	ESourceSelector *selector;
+	ESource *default_source;
 
 	g_return_val_if_fail (E_IS_SOURCE_SELECTOR_DIALOG (dialog), FALSE);
 
-	priv = dialog->priv;
-
-	if (priv->source_list) {
-		ESource *default_source = NULL;
-		GSList *groups, *g;
+	selector = e_source_selector_dialog_get_selector (dialog);
+	default_source = e_source_selector_get_default_source (selector);
 
-		groups = e_source_list_peek_groups (priv->source_list);
-		for (g = groups; g != NULL && !default_source; g = g->next) {
-			ESourceGroup *group = E_SOURCE_GROUP (g->data);
-			GSList *sources, *s;
+	if (!E_IS_SOURCE (default_source))
+		return FALSE;
 
-			sources = e_source_group_peek_sources (group);
-
-			for (s = sources; s != NULL && !default_source; s = s->next) {
-				ESource *source = E_SOURCE (s->data);
-
-				if (source && e_source_get_property (source, "default"))
-					default_source = source;
-			}
-
-		}
-
-		if (default_source)
-			e_source_selector_set_primary_selection (E_SOURCE_SELECTOR (priv->source_selector), default_source);
-
-		return default_source != NULL;
-	}
+	/* FIXME This assumes the source is valid for selector. */
+	e_source_selector_set_primary_selection (selector, default_source);
 
-	return FALSE;
+	return TRUE;
 }
 
 /**
diff --git a/libedataserverui/e-source-selector-dialog.h b/libedataserverui/e-source-selector-dialog.h
index 66b8cf1..5680ef4 100644
--- a/libedataserverui/e-source-selector-dialog.h
+++ b/libedataserverui/e-source-selector-dialog.h
@@ -25,7 +25,7 @@
 #define E_SOURCE_SELECTOR_DIALOG_H
 
 #include <gtk/gtk.h>
-#include <libedataserver/e-source-list.h>
+#include <libedataserverui/e-source-selector.h>
 
 /* Standard GObject macros */
 #define E_TYPE_SOURCE_SELECTOR_DIALOG \
@@ -63,7 +63,11 @@ struct _ESourceSelectorDialogClass {
 
 GType		e_source_selector_dialog_get_type (void);
 GtkWidget *	e_source_selector_dialog_new	(GtkWindow *parent,
-						 ESourceList *source_list);
+						 ESourceRegistry *registry,
+						 const gchar *extension_name);
+ESourceSelector *
+		e_source_selector_dialog_get_selector
+						(ESourceSelectorDialog *dialog);
 gboolean	e_source_selector_dialog_select_default_source
 						(ESourceSelectorDialog *dialog);
 ESource *	e_source_selector_dialog_peek_primary_selection



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