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



commit ea303c182abe1516f2a859b2ab2cffef7cecfedd
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/Makefile.am                |    1 +
 addressbook/importers/evolution-csv-importer.c   |   39 +++++++++++++--------
 addressbook/importers/evolution-ldif-importer.c  |   39 +++++++++++++--------
 addressbook/importers/evolution-vcard-importer.c |   39 +++++++++++++--------
 4 files changed, 73 insertions(+), 45 deletions(-)
---
diff --git a/addressbook/importers/Makefile.am b/addressbook/importers/Makefile.am
index 3f2f1db..515370d 100644
--- a/addressbook/importers/Makefile.am
+++ b/addressbook/importers/Makefile.am
@@ -22,6 +22,7 @@ libevolution_addressbook_importers_la_LDFLAGS = -avoid-version $(NO_UNDEFINED)
 
 libevolution_addressbook_importers_la_LIBADD = \
 	$(top_builddir)/e-util/libeutil.la 				\
+	$(top_builddir)/shell/libeshell.la				\
 	$(top_builddir)/addressbook/util/libeabutil.la			\
 	$(top_builddir)/widgets/misc/libemiscwidgets.la			\
 	$(EVOLUTION_DATA_SERVER_LIBS)					\
diff --git a/addressbook/importers/evolution-csv-importer.c b/addressbook/importers/evolution-csv-importer.c
index 66cc0a7..a0ee5b1 100644
--- a/addressbook/importers/evolution-csv-importer.c
+++ b/addressbook/importers/evolution-csv-importer.c
@@ -37,9 +37,11 @@
 #include <libebook/e-book-client.h>
 #include <libedataserverui/e-client-utils.h>
 #include <libedataserverui/e-source-selector.h>
+#include <libedataserver/e-source-address-book.h>
 
 #include <libebook/e-destination.h>
 
+#include <shell/e-shell.h>
 #include <e-util/e-import.h>
 
 #include "evolution-addressbook-importers.h"
@@ -766,31 +768,38 @@ csv_getwidget (EImport *ei,
                EImportTarget *target,
                EImportImporter *im)
 {
+	EShell *shell;
 	GtkWidget *vbox, *selector;
+	ESourceRegistry *registry;
 	ESource *primary;
-	ESourceList *source_list;
-
-	/* FIXME Better error handling */
-	if (!e_book_client_get_sources (&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);
+	shell = e_shell_get_default ();
+	registry = e_shell_get_registry (shell);
+	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,
-			(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, "csv-source", primary,
+				(GDestroyNotify) g_object_unref);
+		}
+
+		g_list_free_full (list, (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",
@@ -921,8 +930,8 @@ csv_import (EImport *ei,
 
 	source = g_datalist_get_data (&target->data, "csv-source");
 
-	e_client_utils_open_new (source, E_CLIENT_SOURCE_TYPE_CONTACTS, FALSE, NULL,
-		e_client_utils_authenticate_handler, NULL,
+	e_client_utils_open_new (
+		source, E_CLIENT_SOURCE_TYPE_CONTACTS, FALSE, NULL,
 		book_loaded_cb, gci);
 }
 
diff --git a/addressbook/importers/evolution-ldif-importer.c b/addressbook/importers/evolution-ldif-importer.c
index 989bb80..9909c52 100644
--- a/addressbook/importers/evolution-ldif-importer.c
+++ b/addressbook/importers/evolution-ldif-importer.c
@@ -44,9 +44,11 @@
 #include <libebook/e-book-client.h>
 #include <libedataserverui/e-client-utils.h>
 #include <libedataserverui/e-source-selector.h>
+#include <libedataserver/e-source-address-book.h>
 
 #include <libebook/e-destination.h>
 
+#include <shell/e-shell.h>
 #include <e-util/e-import.h>
 
 #include "evolution-addressbook-importers.h"
@@ -564,31 +566,38 @@ ldif_getwidget (EImport *ei,
                 EImportTarget *target,
                 EImportImporter *im)
 {
+	EShell *shell;
 	GtkWidget *vbox, *selector;
+	ESourceRegistry *registry;
 	ESource *primary;
-	ESourceList *source_list;
-
-	/* FIXME Better error handling */
-	if (!e_book_client_get_sources (&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);
+	shell = e_shell_get_default ();
+	registry = e_shell_get_registry (shell);
+	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_full (list, (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",
@@ -711,8 +720,8 @@ ldif_import (EImport *ei,
 
 	source = g_datalist_get_data (&target->data, "ldif-source");
 
-	e_client_utils_open_new (source, E_CLIENT_SOURCE_TYPE_CONTACTS, FALSE, NULL,
-		e_client_utils_authenticate_handler, NULL,
+	e_client_utils_open_new (
+		source, E_CLIENT_SOURCE_TYPE_CONTACTS, FALSE, NULL,
 		book_loaded_cb, gci);
 }
 
diff --git a/addressbook/importers/evolution-vcard-importer.c b/addressbook/importers/evolution-vcard-importer.c
index b355539..7170acf 100644
--- a/addressbook/importers/evolution-vcard-importer.c
+++ b/addressbook/importers/evolution-vcard-importer.c
@@ -38,10 +38,12 @@
 #include <libebook/e-book-client.h>
 #include <libedataserverui/e-client-utils.h>
 #include <libedataserverui/e-source-selector.h>
+#include <libedataserver/e-source-address-book.h>
 
 #include <util/eab-book-util.h>
 #include <libebook/e-destination.h>
 
+#include <shell/e-shell.h>
 #include <e-util/e-import.h>
 #include <e-util/e-datetime-format.h>
 #include <misc/e-web-view-preview.h>
@@ -402,31 +404,38 @@ vcard_getwidget (EImport *ei,
                  EImportTarget *target,
                  EImportImporter *im)
 {
+	EShell *shell;
 	GtkWidget *vbox, *selector;
+	ESourceRegistry *registry;
 	ESource *primary;
-	ESourceList *source_list;
-
-	/* FIXME Better error handling */
-	if (!e_book_client_get_sources (&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);
+	shell = e_shell_get_default ();
+	registry = e_shell_get_registry (shell);
+	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);
+		}
+
+		g_list_free_full (list, (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",
@@ -569,8 +578,8 @@ vcard_import (EImport *ei,
 
 	source = g_datalist_get_data (&target->data, "vcard-source");
 
-	e_client_utils_open_new (source, E_CLIENT_SOURCE_TYPE_CONTACTS, FALSE, NULL,
-		e_client_utils_authenticate_handler, NULL,
+	e_client_utils_open_new (
+		source, E_CLIENT_SOURCE_TYPE_CONTACTS, FALSE, NULL,
 		book_loaded_cb, gci);
 }
 



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