[evolution/account-mgmt: 10/33] Adapt addressbook/importers to the new ESource API.



commit 5d627e08fdbd7347d28a2c43675bdcd1e09daf6f
Author: Matthew Barnes <mbarnes redhat com>
Date:   Wed Dec 8 00:17:17 2010 -0500

    Adapt addressbook/importers to the new ESource API.

 addressbook/importers/evolution-csv-importer.c   |   32 +++++++++++++--------
 addressbook/importers/evolution-ldif-importer.c  |   31 ++++++++++++---------
 addressbook/importers/evolution-vcard-importer.c |   30 +++++++++++---------
 3 files changed, 55 insertions(+), 38 deletions(-)
---
diff --git a/addressbook/importers/evolution-csv-importer.c b/addressbook/importers/evolution-csv-importer.c
index 69e8295..bf20b4a 100644
--- a/addressbook/importers/evolution-csv-importer.c
+++ b/addressbook/importers/evolution-csv-importer.c
@@ -32,6 +32,7 @@
 #include <glib/gstdio.h>
 
 #include <libebook/e-book.h>
+#include <libebook/e-source-address-book.h>
 #include <libedataserverui/e-book-auth-util.h>
 #include <libedataserverui/e-source-selector.h>
 
@@ -736,27 +737,34 @@ static GtkWidget *
 csv_getwidget (EImport *ei, EImportTarget *target, EImportImporter *im)
 {
 	GtkWidget *vbox, *selector;
+	ESourceRegistry *registry;
 	ESource *primary;
-	ESourceList *source_list;
-
-	/* FIXME Better error handling */
-	if (!e_book_get_addressbooks (&source_list, NULL))
-		return NULL;
+	const gchar *extension_name;
 
 	vbox = gtk_vbox_new (FALSE, FALSE);
 
-	selector = e_source_selector_new (source_list);
-	e_source_selector_show_selection (E_SOURCE_SELECTOR (selector), FALSE);
+	registry = e_source_registry_get_default ();
+	extension_name = E_SOURCE_EXTENSION_ADDRESS_BOOK;
+	selector = e_source_selector_new (registry, extension_name);
+	e_source_selector_set_show_toggles (
+		E_SOURCE_SELECTOR (selector), FALSE);
 	gtk_box_pack_start (GTK_BOX (vbox), selector, FALSE, TRUE, 6);
 
 	primary = g_datalist_get_data(&target->data, "csv-source");
 	if (primary == NULL) {
-		primary = e_source_list_peek_source_any (source_list);
-		g_object_ref (primary);
-		g_datalist_set_data_full(&target->data, "csv-source", primary, g_object_unref);
+		GList *list;
+
+		list = e_source_registry_list_sources (registry, extension_name);
+		if (list != NULL) {
+			primary = g_object_ref (list->data);
+			g_datalist_set_data_full (
+				&target->data, "csv-source", primary,
+				(GDestroyNotify) g_object_unref);
+			g_list_free (list);
+		}
 	}
-	e_source_selector_set_primary_selection (E_SOURCE_SELECTOR (selector), primary);
-	g_object_unref (source_list);
+	e_source_selector_set_primary_selection (
+		E_SOURCE_SELECTOR (selector), primary);
 
 	g_signal_connect (
 		selector, "primary_selection_changed",
diff --git a/addressbook/importers/evolution-ldif-importer.c b/addressbook/importers/evolution-ldif-importer.c
index d8d5e6e..4ec2aea 100644
--- a/addressbook/importers/evolution-ldif-importer.c
+++ b/addressbook/importers/evolution-ldif-importer.c
@@ -42,6 +42,7 @@
 #include <glib/gstdio.h>
 
 #include <libebook/e-book.h>
+#include <libebook/e-source-address-book.h>
 #include <libedataserverui/e-book-auth-util.h>
 #include <libedataserverui/e-source-selector.h>
 
@@ -534,30 +535,34 @@ static GtkWidget *
 ldif_getwidget (EImport *ei, EImportTarget *target, EImportImporter *im)
 {
 	GtkWidget *vbox, *selector;
+	ESourceRegistry *registry;
 	ESource *primary;
-	ESourceList *source_list;
-
-	/* FIXME Better error handling */
-	if (!e_book_get_addressbooks (&source_list, NULL))
-		return NULL;
+	const gchar *extension_name;
 
 	vbox = gtk_vbox_new (FALSE, FALSE);
 
-	selector = e_source_selector_new (source_list);
-	e_source_selector_show_selection (E_SOURCE_SELECTOR (selector), FALSE);
+	registry = e_source_registry_get_default ();
+	extension_name = E_SOURCE_EXTENSION_ADDRESS_BOOK;
+	selector = e_source_selector_new (registry, extension_name);
+	e_source_selector_set_show_toggles (
+		E_SOURCE_SELECTOR (selector), FALSE);
 	gtk_box_pack_start (GTK_BOX (vbox), selector, FALSE, TRUE, 6);
 
 	primary = g_datalist_get_data(&target->data, "ldif-source");
 	if (primary == NULL) {
-		primary = e_source_list_peek_source_any (source_list);
-		g_object_ref (primary);
-		g_datalist_set_data_full (
-			&target->data, "ldif-source", primary,
-			(GDestroyNotify) g_object_unref);
+		GList *list;
+
+		list = e_source_registry_list_sources (registry, extension_name);
+		if (list != NULL) {
+			primary = g_object_ref (list->data);
+			g_datalist_set_data_full (
+				&target->data, "ldif-source", primary,
+				(GDestroyNotify) g_object_unref);
+			g_list_free (list);
+		}
 	}
 	e_source_selector_set_primary_selection (
 		E_SOURCE_SELECTOR (selector), primary);
-	g_object_unref (source_list);
 
 	g_signal_connect (
 		selector, "primary_selection_changed",
diff --git a/addressbook/importers/evolution-vcard-importer.c b/addressbook/importers/evolution-vcard-importer.c
index c9cc489..a67c4b8 100644
--- a/addressbook/importers/evolution-vcard-importer.c
+++ b/addressbook/importers/evolution-vcard-importer.c
@@ -36,6 +36,7 @@
 #include <glib/gstdio.h>
 
 #include <libebook/e-book.h>
+#include <libebook/e-source-address-book.h>
 #include <libedataserverui/e-book-auth-util.h>
 #include <libedataserverui/e-source-selector.h>
 
@@ -398,30 +399,33 @@ static GtkWidget *
 vcard_getwidget (EImport *ei, EImportTarget *target, EImportImporter *im)
 {
 	GtkWidget *vbox, *selector;
+	ESourceRegistry *registry;
 	ESource *primary;
-	ESourceList *source_list;
-
-	/* FIXME Better error handling */
-	if (!e_book_get_addressbooks (&source_list, NULL))
-		return NULL;
+	const gchar *extension_name;
 
 	vbox = gtk_vbox_new (FALSE, FALSE);
 
-	selector = e_source_selector_new (source_list);
-	e_source_selector_show_selection (E_SOURCE_SELECTOR (selector), FALSE);
+	registry = e_source_registry_get_default ();
+	extension_name = E_SOURCE_EXTENSION_ADDRESS_BOOK;
+	selector = e_source_selector_new (registry, extension_name);
+	e_source_selector_set_show_toggles (
+		E_SOURCE_SELECTOR (selector), FALSE);
 	gtk_box_pack_start (GTK_BOX (vbox), selector, FALSE, TRUE, 6);
 
 	primary = g_datalist_get_data(&target->data, "vcard-source");
 	if (primary == NULL) {
-		primary = e_source_list_peek_source_any (source_list);
-		g_object_ref (primary);
-		g_datalist_set_data_full (
-			&target->data, "vcard-source", primary,
-			(GDestroyNotify) g_object_unref);
+		GList *list;
+
+		list = e_source_registry_list_sources (registry, extension_name);
+		if (list != NULL) {
+			primary = g_object_ref (list->data);
+			g_datalist_set_data_full (
+				&target->data, "vcard-source", primary,
+				(GDestroyNotify) g_object_unref);
+		}
 	}
 	e_source_selector_set_primary_selection (
 		E_SOURCE_SELECTOR (selector), primary);
-	g_object_unref (source_list);
 
 	g_signal_connect (
 		selector, "primary_selection_changed",



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