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



commit 33bce2c526f6b3d53df7d4368ab0de420585e31b
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 |    1 +
 .../tmpl/e-source-selector-dialog.sgml             |   27 ++-
 libedataserverui/e-name-selector-dialog.c          |    5 +-
 libedataserverui/e-source-selector-dialog.c        |  452 +++++++++++++-------
 libedataserverui/e-source-selector-dialog.h        |    8 +-
 5 files changed, 326 insertions(+), 167 deletions(-)
---
diff --git a/docs/reference/libedataserverui/libedataserverui-sections.txt b/docs/reference/libedataserverui/libedataserverui-sections.txt
index 25ee523..ab35e11 100644
--- a/docs/reference/libedataserverui/libedataserverui-sections.txt
+++ b/docs/reference/libedataserverui/libedataserverui-sections.txt
@@ -346,6 +346,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/docs/reference/libedataserverui/tmpl/e-source-selector-dialog.sgml b/docs/reference/libedataserverui/tmpl/e-source-selector-dialog.sgml
index f83b041..70ff95a 100644
--- a/docs/reference/libedataserverui/tmpl/e-source-selector-dialog.sgml
+++ b/docs/reference/libedataserverui/tmpl/e-source-selector-dialog.sgml
@@ -26,13 +26,38 @@ ESourceSelectorDialog
 </para>
 
 
+<!-- ##### ARG ESourceSelectorDialog:extension-name ##### -->
+<para>
+
+</para>
+
+<!-- ##### ARG ESourceSelectorDialog:registry ##### -->
+<para>
+
+</para>
+
+<!-- ##### ARG ESourceSelectorDialog:selector ##### -->
+<para>
+
+</para>
+
 <!-- ##### FUNCTION e_source_selector_dialog_new ##### -->
 <para>
 
 </para>
 
 @parent: 
- source_list: 
+ registry: 
+ extension_name: 
+ Returns: 
+
+
+<!-- ##### FUNCTION e_source_selector_dialog_get_selector ##### -->
+<para>
+
+</para>
+
+ dialog: 
 @Returns: 
 
 
diff --git a/libedataserverui/e-name-selector-dialog.c b/libedataserverui/e-name-selector-dialog.c
index eb6ea50..362b828 100644
--- a/libedataserverui/e-name-selector-dialog.c
+++ b/libedataserverui/e-name-selector-dialog.c
@@ -26,6 +26,7 @@
 #include <gdk/gdkkeysyms.h>
 #include <glib/gi18n-lib.h>
 #include <gconf/gconf-client.h>
+#include <libebook/e-source-address-book.h>
 #include <libedataserverui/e-source-combo-box.h>
 #include <libedataserverui/e-destination-store.h>
 #include <libedataserverui/e-contact-store.h>
@@ -166,6 +167,7 @@ e_name_selector_dialog_init (ENameSelectorDialog *name_selector_dialog)
 	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);
@@ -367,7 +369,8 @@ e_name_selector_dialog_init (ENameSelectorDialog *name_selector_dialog)
 	/* 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 (registry, extension_name);
 	g_signal_connect_swapped (
 		source_combo, "changed",
 		G_CALLBACK (source_changed), name_selector_dialog);
diff --git a/libedataserverui/e-source-selector-dialog.c b/libedataserverui/e-source-selector-dialog.c
index 5082170..fba18d9 100644
--- a/libedataserverui/e-source-selector-dialog.c
+++ b/libedataserverui/e-source-selector-dialog.c
@@ -30,269 +30,395 @@
 #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_free (priv);
-	E_SOURCE_SELECTOR_DIALOG (object)->priv = NULL;
+	g_return_if_fail (extension_name != NULL);
+	g_return_if_fail (dialog->priv->extension_name == 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);
+	g_return_if_fail (E_IS_SOURCE_REGISTRY (registry));
+	g_return_if_fail (dialog->priv->registry == NULL);
 
-	object_class->dispose = e_source_selector_dialog_dispose;
-	object_class->finalize = e_source_selector_dialog_finalize;
-
-	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);
-#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);
+	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->registry != NULL) {
+		g_object_unref (priv->registry);
+		priv->registry = NULL;
+	}
 
-	if (priv->selected_source)
+	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_container_add (GTK_CONTAINER (content_area), vbox);
-	gtk_widget_show (vbox);
+	widget = gtk_vbox_new (FALSE, 12);
+	gtk_container_set_border_width (GTK_CONTAINER (widget), 12);
+	gtk_container_add (GTK_CONTAINER (container), widget);
+	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: Parent window.
- * @source_list: A source list.
+ * @parent: a parent window
+ * @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: The newly created widget.
- */
+ * Returns: a new #ESourceSelectorDialog
+ **/
 GtkWidget *
-e_source_selector_dialog_new (GtkWindow *parent, ESourceList *source_list)
+e_source_selector_dialog_new (GtkWindow *parent,
+                              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: 2.92
+ **/
+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);
 }
 
 /**
  * e_source_selector_dialog_select_default_source:
- * @dialog: An #ESourceSelectorDialog widget.
+ * @dialog: an #ESourceSelectorDialog
  *
- * Selects default source in the dialog.
+ * Selects the default source in the dialog.
  *
- * Returns: Whether found any default source.
+ * Returns: %TRUE if a default source was selected
  *
  * Since: 2.28
  **/
 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;
-
-		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);
+	selector = e_source_selector_dialog_get_selector (dialog);
+	default_source = e_source_selector_get_default_source (selector);
 
-			for (s = sources; s != NULL && !default_source; s = s->next) {
-				ESource *source = E_SOURCE (s->data);
+	if (!E_IS_SOURCE (default_source))
+		return FALSE;
 
-				if (source && e_source_get_property (source, "default"))
-					default_source = source;
-			}
+	/* FIXME This assumes the source is valid for selector. */
+	e_source_selector_set_primary_selection (selector, default_source);
 
-		}
-
-		if (default_source)
-			e_source_selector_set_primary_selection (E_SOURCE_SELECTOR (priv->source_selector), default_source);
-
-		return default_source != NULL;
-	}
-
-	return FALSE;
+	return TRUE;
 }
 
 /**
  * e_source_selector_dialog_peek_primary_selection:
- * @dialog: An #ESourceSelectorDialog widget.
+ * @dialog: an #ESourceSelectorDialog
  *
  * Peek the currently selected source in the given @dialog.
  *
- * Returns: the selected ESource.
+ * Returns: the selected #ESource
  */
 ESource *
 e_source_selector_dialog_peek_primary_selection (ESourceSelectorDialog *dialog)
 {
-	ESourceSelectorDialogPrivate *priv;
-
 	g_return_val_if_fail (E_IS_SOURCE_SELECTOR_DIALOG (dialog), NULL);
 
-	priv = dialog->priv;
-	return priv->selected_source;
+	return dialog->priv->selected_source;
 }
diff --git a/libedataserverui/e-source-selector-dialog.h b/libedataserverui/e-source-selector-dialog.h
index b7455a7..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]