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



commit 2ea9a4ca9dc08e2d0ecf140717609c1461470e2c
Author: Matthew Barnes <mbarnes redhat com>
Date:   Wed Dec 8 10:09:14 2010 -0500

    Adapt calendars/importers to the new ESource API.

 calendar/importers/icalendar-importer.c |   43 +++++++++++++++++++++---------
 1 files changed, 30 insertions(+), 13 deletions(-)
---
diff --git a/calendar/importers/icalendar-importer.c b/calendar/importers/icalendar-importer.c
index ea7f7d5..7cea85a 100644
--- a/calendar/importers/icalendar-importer.c
+++ b/calendar/importers/icalendar-importer.c
@@ -37,6 +37,7 @@
 
 #include <libecal/e-cal.h>
 #include <libecal/e-cal-time-util.h>
+#include <libecal/e-source-calendar.h>
 #include <libedataserverui/e-source-selector.h>
 #include <libical/icalvcal.h>
 #include "evolution-calendar-importer.h"
@@ -239,26 +240,43 @@ ivcal_getwidget (EImport *ei, EImportTarget *target, EImportImporter *im)
 
 	/* Type of icalendar items */
 	for (i = 0; import_type_map[i] != -1; i++) {
+		ESourceRegistry *registry;
 		GtkWidget *selector, *rb;
-		ESourceList *source_list;
-		ESource *primary;
+		ESource *source = NULL;
 		GtkWidget *scrolled;
 		struct _selector_data *sd;
+		const gchar *extension_name;
+		GList *list;
+
+		registry = e_source_registry_get_default ();
+
+		switch (import_type_map[i]) {
+			case E_CAL_SOURCE_TYPE_EVENT:
+				extension_name = E_SOURCE_EXTENSION_CALENDAR;
+				break;
+			case E_CAL_SOURCE_TYPE_TODO:
+				extension_name = E_SOURCE_EXTENSION_TASK_LIST;
+				break;
+			default:
+				g_warn_if_reached ();
+				continue;
+		}
 
-		/* FIXME Better error handling */
-		if (!e_cal_get_sources (&source_list, import_type_map[i], NULL))
-			continue;
-
-		selector = e_source_selector_new (source_list);
-		e_source_selector_show_selection (E_SOURCE_SELECTOR (selector), FALSE);
+		selector = e_source_selector_new (registry, extension_name);
+		e_source_selector_set_show_toggles (
+			E_SOURCE_SELECTOR (selector), FALSE);
 		scrolled = gtk_scrolled_window_new (NULL, NULL);
 		gtk_scrolled_window_set_policy ((GtkScrolledWindow *)scrolled, GTK_POLICY_AUTOMATIC, GTK_POLICY_ALWAYS);
 		gtk_container_add ((GtkContainer *)scrolled, selector);
 		gtk_notebook_append_page (GTK_NOTEBOOK (nb), scrolled, NULL);
 
-		/* FIXME What if no sources? */
-		primary = e_source_list_peek_source_any (source_list);
-		e_source_selector_set_primary_selection (E_SOURCE_SELECTOR (selector), primary);
+		list = e_source_registry_list_sources (registry, extension_name);
+		if (list != NULL) {
+			source = E_SOURCE (list->data);
+			e_source_selector_set_primary_selection (
+				E_SOURCE_SELECTOR (selector), source);
+			g_list_free (list);
+		}
 
 		g_signal_connect (selector, "primary_selection_changed", G_CALLBACK (primary_selection_changed_cb), target);
 
@@ -276,11 +294,10 @@ ivcal_getwidget (EImport *ei, EImportTarget *target, EImportImporter *im)
 		if (!group)
 			group = gtk_radio_button_get_group (GTK_RADIO_BUTTON (rb));
 		if (first == NULL) {
-			g_datalist_set_data_full(&target->data, "primary-source", g_object_ref(primary), g_object_unref);
+			g_datalist_set_data_full(&target->data, "primary-source", g_object_ref (source), g_object_unref);
 			g_datalist_set_data(&target->data, "primary-type", GINT_TO_POINTER(import_type_map[i]));
 			first = rb;
 		}
-		g_object_unref (source_list);
 	}
 	if (first)
 		gtk_toggle_button_set_active ((GtkToggleButton *)first, TRUE);



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