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



commit 7f6dd929ed6fa7625228eafe9438590017e40626
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 |    3 +-
 libedataserverui/e-name-selector-dialog.c          |  274 +++++++++-----
 libedataserverui/e-name-selector-dialog.h          |    6 +-
 libedataserverui/e-source-selector-dialog.c        |  412 ++++++++++++--------
 libedataserverui/e-source-selector-dialog.h        |    8 +-
 5 files changed, 455 insertions(+), 248 deletions(-)
---
diff --git a/docs/reference/libedataserverui/libedataserverui-sections.txt b/docs/reference/libedataserverui/libedataserverui-sections.txt
index d04adfe..1889003 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
@@ -434,7 +435,7 @@ e_source_selector_get_type
 <TITLE>ESourceSelectorDialog</TITLE>
 ESourceSelectorDialog
 e_source_selector_dialog_new
-e_source_selector_dialog_select_default_source
+e_source_selector_dialog_get_selector
 e_source_selector_dialog_peek_primary_selection
 <SUBSECTION Standard>
 E_SOURCE_SELECTOR_DIALOG
diff --git a/libedataserverui/e-name-selector-dialog.c b/libedataserverui/e-name-selector-dialog.c
index 14e3870..b1edf0b 100644
--- a/libedataserverui/e-name-selector-dialog.c
+++ b/libedataserverui/e-name-selector-dialog.c
@@ -32,13 +32,13 @@
 
 #include <libedataserver/e-sexp.h>
 #include <libedataserver/e-categories.h>
+#include <libedataserver/e-source-address-book.h>
 
 #include <libebackend/e-extensible.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"
@@ -69,6 +69,7 @@ typedef struct {
 } SelData;
 
 struct _ENameSelectorDialogPrivate {
+	ESourceRegistry *registry;
 	ENameSelectorModel *name_selector_model;
 	GtkTreeModelSort *contact_sort;
 	GCancellable *cancellable;
@@ -88,6 +89,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);
@@ -119,7 +125,7 @@ G_DEFINE_TYPE_WITH_CODE (
 		E_TYPE_EXTENSIBLE, NULL))
 
 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;
@@ -148,12 +154,96 @@ 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;
 	GtkTreeSelection  *selection;
+	ESource *source;
 	gchar *tmp_str;
 	GtkWidget *name_selector_box;
 	GtkWidget *show_contacts_label;
@@ -181,10 +271,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;
 
-	name_selector_dialog->priv =
-		E_NAME_SELECTOR_DIALOG_GET_PRIVATE (name_selector_dialog);
+	priv = E_NAME_SELECTOR_DIALOG_GET_PRIVATE (object);
+
+	/* 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);
@@ -267,7 +359,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);
@@ -328,24 +420,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 */
@@ -353,111 +445,79 @@ 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));
 
-	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);
 
 	gtk_label_set_mnemonic_widget (GTK_LABEL (AddressBookLabel), source_combo);
 	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 */
 
-	/* TODO: Remember last used source */
+	source = e_source_registry_ref_default_address_book (priv->registry);
+	e_source_combo_box_set_active (
+		E_SOURCE_COMBO_BOX (source_combo), source);
+	g_object_unref (source);
 
 	/* 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
-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
-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)
-{
-	/* Chain up to parent's constructed() method. */
-	G_OBJECT_CLASS (e_name_selector_dialog_parent_class)->
-		constructed (object);
-
-	e_extensible_load_extensions (E_EXTENSIBLE (object));
-}
-
-static void
 e_name_selector_dialog_class_init (ENameSelectorDialogClass *class)
 {
 	GObjectClass *object_class;
@@ -465,22 +525,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->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)
 {
-	  return g_object_new (E_TYPE_NAME_SELECTOR_DIALOG, NULL);
+	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)
+{
+	g_return_val_if_fail (
+		E_IS_NAME_SELECTOR_DIALOG (name_selector_dialog), NULL);
+
+	return name_selector_dialog->priv->registry;
 }
 
 /* --------- *
@@ -997,7 +1092,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 3138eeb..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,7 +65,10 @@ 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);
diff --git a/libedataserverui/e-source-selector-dialog.c b/libedataserverui/e-source-selector-dialog.c
index dab186f..e642704 100644
--- a/libedataserverui/e-source-selector-dialog.c
+++ b/libedataserverui/e-source-selector-dialog.c
@@ -34,9 +34,17 @@
 	((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;
+};
+
+enum {
+	PROP_0,
+	PROP_EXTENSION_NAME,
+	PROP_REGISTRY,
+	PROP_SELECTOR
 };
 
 G_DEFINE_TYPE (
@@ -45,230 +53,328 @@ G_DEFINE_TYPE (
 	GTK_TYPE_DIALOG)
 
 static void
-source_selector_dialog_dispose (GObject *object)
+source_selector_dialog_row_activated_cb (GtkTreeView *tree_view,
+                                         GtkTreePath *path,
+                                         GtkTreeViewColumn *column,
+                                         GtkWidget *dialog)
 {
-	ESourceSelectorDialogPrivate *priv;
+	gtk_dialog_response (GTK_DIALOG (dialog), GTK_RESPONSE_OK);
+}
 
-	priv = E_SOURCE_SELECTOR_DIALOG_GET_PRIVATE (object);
+static void
+primary_selection_changed_cb (ESourceSelector *selector,
+                              ESourceSelectorDialog *dialog)
+{
+	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;
 	}
 
-	/* Chain up to parent's dispose() method. */
-	G_OBJECT_CLASS (e_source_selector_dialog_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_class_init (ESourceSelectorDialogClass *class)
+source_selector_dialog_set_extension_name (ESourceSelectorDialog *dialog,
+                                           const gchar *extension_name)
 {
-	GObjectClass *object_class;
+	g_return_if_fail (extension_name != NULL);
+	g_return_if_fail (dialog->priv->extension_name == NULL);
 
-	g_type_class_add_private (class, sizeof (ESourceSelectorDialogPrivate));
-
-	object_class = G_OBJECT_CLASS (class);
-	object_class->dispose = source_selector_dialog_dispose;
+	dialog->priv->extension_name = g_strdup (extension_name);
 }
 
 static void
-e_source_selector_dialog_init (ESourceSelectorDialog *dialog)
+source_selector_dialog_set_registry (ESourceSelectorDialog *dialog,
+                                     ESourceRegistry *registry)
 {
-	GtkWidget *action_area;
-	GtkWidget *content_area;
+	g_return_if_fail (E_IS_SOURCE_REGISTRY (registry));
+	g_return_if_fail (dialog->priv->registry == NULL);
 
-	dialog->priv = E_SOURCE_SELECTOR_DIALOG_GET_PRIVATE (dialog);
+	dialog->priv->registry = g_object_ref (registry);
+}
 
-	action_area = gtk_dialog_get_action_area (GTK_DIALOG (dialog));
-	content_area = gtk_dialog_get_content_area (GTK_DIALOG (dialog));
+static void
+source_selector_dialog_set_property (GObject *object,
+                                     guint property_id,
+                                     const GValue *value,
+                                     GParamSpec *pspec)
+{
+	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;
+
+	priv = E_SOURCE_SELECTOR_DIALOG_GET_PRIVATE (object);
 
-	if (priv->selected_source)
+	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));
+
+	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);
 
-	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);
+	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);
-
-	dialog = g_object_new (E_TYPE_SOURCE_SELECTOR_DIALOG, NULL);
-
-	return setup_dialog (parent, dialog, source_list);
+	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);
 }
 
 /**
- * e_source_selector_dialog_select_default_source:
+ * e_source_selector_dialog_get_selector:
  * @dialog: an #ESourceSelectorDialog
  *
- * Selects the default source in the dialog.
+ * Returns the #ESourceSelector widget embedded in @dialog.
  *
- * Returns: %TRUE if a default source was selected
+ * Returns: the #ESourceSelector widget
  *
- * Since: 2.28
+ * Since: 3.4
  **/
-gboolean
-e_source_selector_dialog_select_default_source (ESourceSelectorDialog *dialog)
+ESourceSelector *
+e_source_selector_dialog_get_selector (ESourceSelectorDialog *dialog)
 {
-	ESourceSelectorDialogPrivate *priv;
-
-	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;
-
-		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;
-
-			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;
-	}
+	g_return_val_if_fail (E_IS_SOURCE_SELECTOR_DIALOG (dialog), NULL);
 
-	return FALSE;
+	return E_SOURCE_SELECTOR (dialog->priv->selector);
 }
 
 /**
diff --git a/libedataserverui/e-source-selector-dialog.h b/libedataserverui/e-source-selector-dialog.h
index 66b8cf1..dc1c8b1 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,8 +63,10 @@ struct _ESourceSelectorDialogClass {
 
 GType		e_source_selector_dialog_get_type (void);
 GtkWidget *	e_source_selector_dialog_new	(GtkWindow *parent,
-						 ESourceList *source_list);
-gboolean	e_source_selector_dialog_select_default_source
+						 ESourceRegistry *registry,
+						 const gchar *extension_name);
+ESourceSelector *
+		e_source_selector_dialog_get_selector
 						(ESourceSelectorDialog *dialog);
 ESource *	e_source_selector_dialog_peek_primary_selection
 						(ESourceSelectorDialog *dialog);



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