[evolution/new-importer: 2/3] Begin porting calendar importers to the new framework.



commit cc5b39688be43c0f3036231a79e64f7c70777ca8
Author: Matthew Barnes <mbarnes redhat com>
Date:   Sun Sep 27 13:24:33 2009 -0400

    Begin porting calendar importers to the new framework.

 e-util/e-import-handler.c                    |    2 +-
 modules/calendar/Makefile.am                 |    4 +
 modules/calendar/e-cal-import-handler.c      |  274 ++++++++++++++++
 modules/calendar/e-cal-import-handler.h      |   66 ++++
 modules/calendar/e-ical-import-handler.c     |  430 ++++++++++++++++++++++++++
 modules/calendar/e-ical-import-handler.h     |   66 ++++
 modules/calendar/evolution-module-calendar.c |    6 +
 7 files changed, 847 insertions(+), 1 deletions(-)
---
diff --git a/e-util/e-import-handler.c b/e-util/e-import-handler.c
index c5d6c48..7d7eeb4 100644
--- a/e-util/e-import-handler.c
+++ b/e-util/e-import-handler.c
@@ -79,7 +79,7 @@ e_import_handler_get_type (void)
 		type = g_type_register_static (
 			G_TYPE_OBJECT, "EImportHandler",
 			&type_info, G_TYPE_FLAG_ABSTRACT);
-	};
+	}
 
 	return type;
 }
diff --git a/modules/calendar/Makefile.am b/modules/calendar/Makefile.am
index fee7c68..71f84c8 100644
--- a/modules/calendar/Makefile.am
+++ b/modules/calendar/Makefile.am
@@ -18,6 +18,8 @@ libevolution_module_calendar_la_SOURCES =		\
 	e-cal-config-hook.h				\
 	e-cal-event-hook.c				\
 	e-cal-event-hook.h				\
+	e-cal-import-handler.c				\
+	e-cal-import-handler.h				\
 	e-cal-shell-backend.c				\
 	e-cal-shell-backend.h				\
 	e-cal-shell-content.c				\
@@ -36,6 +38,8 @@ libevolution_module_calendar_la_SOURCES =		\
 	e-cal-shell-view-private.c			\
 	e-cal-shell-view-private.h			\
 	e-cal-shell-view-taskpad.c			\
+	e-ical-import-handler.c				\
+	e-ical-import-handler.h				\
 	e-memo-shell-backend.c				\
 	e-memo-shell-backend.h				\
 	e-memo-shell-content.c				\
diff --git a/modules/calendar/e-cal-import-handler.c b/modules/calendar/e-cal-import-handler.c
new file mode 100644
index 0000000..2a847bc
--- /dev/null
+++ b/modules/calendar/e-cal-import-handler.c
@@ -0,0 +1,274 @@
+/*
+ * e-cal-import-handler.c
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) version 3.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with the program; if not, see <http://www.gnu.org/licenses/>
+ *
+ *
+ * Copyright (C) 1999-2008 Novell, Inc. (www.novell.com)
+ *
+ */
+
+#include "e-cal-import-handler.h"
+
+#define E_CAL_IMPORT_HANDLER_GET_PRIVATE(obj) \
+	(G_TYPE_INSTANCE_GET_PRIVATE \
+	((obj), E_TYPE_CAL_IMPORT_HANDLER, ECalImportHandlerPrivate))
+
+struct _ECalImportHandlerPrivate {
+	ESource *destination_source;
+	ECalSourceType destination_type;
+};
+
+enum {
+	PROP_0,
+	PROP_DESTINATION_TYPE,
+	PROP_DESTINATION_SOURCE
+};
+
+static gpointer parent_class;
+static GType cal_import_handler_type;
+
+static void
+cal_import_handler_event_toggled_cb (ECalImportHandler *handler)
+{
+	ECalSourceType type = E_CAL_SOURCE_TYPE_EVENT;
+	e_cal_import_handler_set_destination_type (handler, type);
+}
+
+static void
+cal_import_handler_journal_toggled_cb (ECalImportHandler *handler)
+{
+	ECalSourceType type = E_CAL_SOURCE_TYPE_JOURNAL;
+	e_cal_import_handler_set_destination_type (handler, type);
+}
+
+static void
+cal_import_handler_todo_toggled_cb (ECalImportHandler *handler)
+{
+	ECalSourceType type = E_CAL_SOURCE_TYPE_TODO;
+	e_cal_import_handler_set_destination_type (handler, type);
+}
+
+static void
+cal_import_handler_set_property (GObject *object,
+                                 guint property_id,
+                                 const GValue *value,
+                                 GParamSpec *pspec)
+{
+	switch (property_id) {
+		case PROP_DESTINATION_TYPE:
+			e_cal_import_handler_set_destination_type (
+				E_CAL_IMPORT_HANDLER (object),
+				g_value_get_int (value));
+			return;
+	}
+
+	G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
+}
+
+static void
+cal_import_handler_get_property (GObject *object,
+                                 guint property_id,
+                                 GValue *value,
+                                 GParamSpec *pspec)
+{
+	switch (property_id) {
+		case PROP_DESTINATION_TYPE:
+			g_value_set_int (
+				value,
+				e_cal_import_handler_get_destination_type (
+				E_CAL_IMPORT_HANDLER (object)));
+			return;
+	}
+
+	G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
+}
+
+static GtkWidget *
+cal_import_handler_get_destination_widget (EImportHandler *handler)
+{
+	ECalImportHandlerPrivate *priv;
+	GtkWidget *vbox;
+	GtkWidget *widget;
+	GtkWidget *container;
+	GtkWidget *notebook;
+	GSList *group = NULL;
+	const gchar *text;
+	gint ii;
+
+	priv = E_CAL_IMPORT_HANDLER_GET_PRIVATE (handler);
+
+	widget = gtk_vbox_new (FALSE, 12);
+	gtk_widget_show (widget);
+
+	vbox = container = widget;
+
+	widget = gtk_hbox_new (FALSE, 12);
+	gtk_box_pack_start (GTK_BOX (container), widget, FALSE, TRUE, 0);
+	gtk_widget_show (widget);
+
+	container = widget;
+
+	text = _("Appointments and Meetings");
+	widget = gtk_radio_button_new_with_label (group, text);
+	gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (widget), TRUE);
+	gtk_box_pack_start (GTK_BOX (container), widget, FALSE, FALSE, 0);
+	gtk_widget_show (widget);
+
+	g_signal_connect_swapped (
+		widget, "toggled",
+		G_CALLBACK (import_handler_event_toggled_cb), handler);
+
+	group = gtk_radio_button_get_group (GTK_RADIO_BUTTON (widget));
+
+	text = _("Tasks");
+	widget = gtk_radio_button_new_with_label (group, text);
+	gtk_box_pack_start (GTK_BOX (container), widget, FALSE, FALSE, 0);
+	gtk_widget_show (widget);
+
+	g_signal_connect_swapped (
+		widget, "toggled",
+		G_CALLBACK (import_handler_todo_toggled_cb), handler);
+
+	group = gtk_radio_button_get_group (GTK_RADIO_BUTTON (widget));
+
+	text = _("Memos");
+	widget = gtk_radio_button_new_with_label (group, text);
+	gtk_box_pack_start (GTK_BOX (container), widget, FALSE, FALSE, 0);
+	gtk_widget_show (widget);
+
+	g_signal_connect_swapped (
+		widget, "toggled",
+		G_CALLBACK (import_handler_journal_toggled_cb), handler);
+
+	container = vbox;
+
+	widget = gtk_notebook_new ();
+	gtk_notebook_set_show_tabs (GTK_NOTEBOOK (widget), FALSE);
+	gtk_box_pack_start (GTK_BOX (container), widget, TRUE, TRUE, 0);
+	gtk_widget_show (widget);
+
+	notebook = widget;
+
+	for (ii = 0; ii < E_CAL_SOURCE_TYPE_LAST; ii++) {
+		ESourceList *source_list;
+		ESource *source;
+
+		/* FIXME Improve error handling. */
+		if (!e_cal_get_sources (&source_list, ii, NULL))
+			continue;
+
+		container = notebook;
+
+		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_notebook_append_page (
+			GTK_NOTEBOOK (container), widget, NULL);
+		gtk_widget_show (widget);
+
+		container = widget;
+
+		widget = e_source_selector_new (source_list);
+		e_source_selector_show_selection (
+			E_SOURCE_SELECTOR (widget), FALSE);
+		gtk_container_add (GTK_CONTAINER (container), widget);
+		gtk_widget_show (widget);
+
+		source = e_source_list_peek_source_any (source_list);
+		e_source_selector_set_primary_selection (
+			E_SOURCE_SELECTOR (widget), source);
+
+		/* This corresponds with the initial radio selection. */
+		if (ii == E_CAL_SOURCE_TYPE_EVENT)
+			priv->destination_source = g_object_ref (source);
+	}
+
+	return vbox;
+}
+
+static void
+cal_import_handler_class_init (ECalImportHandlerClass *class)
+{
+	GObjectClass *object_class;
+	EImportHandlerClass *import_handler_class;
+
+	parent_class = g_type_class_peek_parent (class);
+	g_type_class_add_private (class, sizeof (ECalImportHandlerPrivate));
+
+	object_class = G_OBJECT_CLASS (class);
+	object_class->set_property = cal_import_handler_set_property;
+	object_class->get_property = cal_import_handler_get_property;
+
+	import_handler_class = E_IMPORT_HANDLER (class);
+	import_handler_class->get_destination_widget =
+		import_handler_get_destination_widget;
+}
+
+static void
+cal_import_handler_init (ECalImportHandler *handler)
+{
+	handler->priv = E_CAL_IMPORT_HANDLER_GET_PRIVATE (handler);
+
+	handler->priv->destination_type = E_CAL_SOURCE_TYPE_EVENT;
+}
+
+GType
+e_cal_import_handler_get_type (void)
+{
+	return cal_import_handler_type;
+}
+
+void
+e_cal_import_handler_register_type (GTypeModule *type_module)
+{
+	static const GTypeInfo type_info = {
+		sizeof (ECalImportHandlerClass),
+		(GBaseInitFunc) NULL,
+		(GBaseFinalizeFunc) NULL,
+		(GClassInitFunc) cal_import_handler_class_init,
+		(GClassFinalizeFunc) NULL,
+		NULL,  /* class_data */
+		sizeof (ECalImportHandler),
+		0,     /* n_preallocs */
+		(GInstanceInitFunc) cal_import_handler_init,
+		NULL   /* value_table */
+	};
+
+	cal_import_handler_type = g_type_module_register_type (
+		type_module, E_TYPE_IMPORT_HANDLER,
+		"ECalImportHandler", &type_info, G_TYPE_FLAG_ABSTRACT);
+}
+
+ECalSourceType
+e_cal_import_handler_get_destination_type (ECalImportHandler *handler)
+{
+	g_return_val_if_fail (E_IS_CAL_IMPORT_HANDLER (handler), 0);
+
+	return handler->priv->destination_type;
+}
+
+void
+e_cal_import_handler_set_destination_type (ECalImportHandler *handler,
+                                           ECalSourceType destination_type)
+{
+	g_return_if_fail (E_IS_CAL_IMPORT_HANDLER (handler));
+
+	handler->priv->destination_type = destination_type;
+
+	g_object_notify (G_OBJECT (handler), "destination-type");
+}
diff --git a/modules/calendar/e-cal-import-handler.h b/modules/calendar/e-cal-import-handler.h
new file mode 100644
index 0000000..27b4ace
--- /dev/null
+++ b/modules/calendar/e-cal-import-handler.h
@@ -0,0 +1,66 @@
+/*
+ * e-cal-import-handler.h
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) version 3.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with the program; if not, see <http://www.gnu.org/licenses/>
+ *
+ *
+ * Copyright (C) 1999-2008 Novell, Inc. (www.novell.com)
+ *
+ */
+
+#ifndef E_CAL_IMPORT_HANDLER_H
+#define E_CAL_IMPORT_HANDLER_H
+
+#include <e-util/e-import-handler.h>
+
+/* Standard GObject macros */
+#define E_TYPE_CAL_IMPORT_HANDLER \
+	(e_cal_import_handler_get_type ())
+#define E_CAL_IMPORT_HANDLER(obj) \
+	(G_TYPE_CHECK_INSTANCE_CAST \
+	((obj), E_TYPE_CAL_IMPORT_HANDLER, ECalImportHandler))
+#define E_CAL_IMPORT_HANDLER_CLASS(cls) \
+	(G_TYPE_CHECK_CLASS_CAST \
+	((cls), E_TYPE_CAL_IMPORT_HANDLER, ECalImportHandlerClass))
+#define E_IS_CAL_IMPORT_HANDLER(obj) \
+	(G_TYPE_CHECK_INSTANCE_TYPE \
+	((obj), E_TYPE_CAL_IMPORT_HANDLER))
+#define E_IS_CAL_IMPORT_HANDLER_CLASS(cls) \
+	(G_TYPE_CHECK_CLASS_TYPE \
+	((cls), E_TYPE_CAL_IMPORT_HANDLER))
+#define E_CAL_IMPORT_HANDLER_GET_CLASS(obj) \
+	(G_TYPE_INSTANCE_GET_CLASS \
+	((obj), E_TYPE_CAL_IMPORT_HANDLER, ECalImportHandlerClass))
+
+G_BEGIN_DECLS
+
+typedef struct _ECalImportHandler ECalImportHandler;
+typedef struct _ECalImportHandlerClass ECalImportHandlerClass;
+typedef struct _ECalImportHandlerPrivate ECalImportHandlerPrivate;
+
+struct _ECalImportHandler {
+	EImportHandler parent;
+	ECalImportHandlerPrivate *priv;
+};
+
+struct _ECalImportHandlerClass {
+	EImportHandlerClass parent_class;
+};
+
+GType	e_cal_import_handler_get_type		(void);
+void	e_cal_import_handler_register_type	(GTypeModule *type_module);
+
+G_END_DECLS
+
+#endif /* E_CAL_IMPORT_HANDLER_H */
diff --git a/modules/calendar/e-ical-import-handler.c b/modules/calendar/e-ical-import-handler.c
new file mode 100644
index 0000000..5a222d4
--- /dev/null
+++ b/modules/calendar/e-ical-import-handler.c
@@ -0,0 +1,430 @@
+/*
+ * e-ical-import-handler.c
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) version 3.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with the program; if not, see <http://www.gnu.org/licenses/>
+ *
+ *
+ * Copyright (C) 1999-2008 Novell, Inc. (www.novell.com)
+ *
+ */
+
+#include "e-ical-import-handler.h"
+
+#define E_ICAL_IMPORT_HANDLER_GET_PRIVATE(obj) \
+	(G_TYPE_INSTANCE_GET_PRIVATE \
+	((obj), E_TYPE_ICAL_IMPORT_HANDLER, EIcalImportHandlerPrivate))
+
+struct _EIcalImportHandlerPrivate {
+	gint placeholder;
+};
+
+static gpointer parent_class;
+static GType ical_import_handler_type;
+
+/********************** e_import_handler_import_async() **********************/
+
+typedef struct _ImportContext;
+
+struct _ImportContext {
+	EImportHandler *handler;
+	GCancellable *cancellable;
+	GSimpleAsyncResult *simple;
+};
+
+static ImportContext *
+import_context_new (EImportHandler *handler,
+                    GCancellable *cancellable,
+                    GAsyncReadyCallback callback,
+                    gpointer user_data)
+{
+	ImportContext *import_context;
+	GSimpleAsyncResult *simple;
+
+	if (cancellable != NULL)
+		g_object_ref (cancellable);
+
+	simple = g_simple_async_result_new (
+		G_OBJECT (handler), callback,
+		user_data, e_import_handler_import_async);
+
+	import_context = g_slice_new0 (ImportContext);
+	import_context->handler = g_object_ref (handler);
+	import_context->cancellable = cancellable;
+	import_context->simple = simple;
+
+	return import_context;
+}
+
+static void
+import_context_free (ImportContext *import_context)
+{
+	/* Do not free the GSimpleAsyncResult. */
+	g_object_unref (import_context->handler);
+
+	if (import_context->cancellable != NULL)
+		g_object_unref (import_context->cancellable);
+
+	g_slice_free (ImportContext, import_context);
+}
+
+static gboolean
+import_check_for_error (ImportContext *import_context,
+                        GError *error)
+{
+	GSimpleAsyncResult *simple;
+
+	if (error == NULL)
+		return FALSE;
+
+	/* Steal the result. */
+	simple = import_context->simple;
+	import_context->simple = NULL;
+
+	g_simple_async_result_set_op_res_gboolean (simple, FALSE);
+	g_simple_async_result_set_from_error (simple, error);
+	g_simple_async_result_complete (simple);
+	g_error_free (error);
+
+	import_context_free (import_context);
+
+	return TRUE;
+}
+
+static void
+import_splice_ready_cb (GOutputStream *output_stream,
+                        GAsyncResult *result,
+                        ImportContext *import_context)
+{
+	GSimpleAsyncResult *simple;
+	icalcomponent *icalcomp;
+	const gchar *content;
+	gboolean can_import = FALSE;
+	GError *error = NULL;
+
+	g_output_stream_splice_finish (output_stream, result, &error);
+
+	if (inspect_check_for_error (inspect_context, error))
+		return;
+
+	content = g_memory_output_stream_get_data (
+		G_MEMORY_OUTPUT_STREAM (output_stream));
+
+	icalcomp = e_cal_util_parse_ics_string (contents);
+
+	if (icalcomp != NULL) {
+		can_import = icalcomponent_is_valid (icalcomp);
+		icalcomponent_free (icalcomp);
+	}
+
+	/* Steal the result. */
+	simple = import_context->simple;
+	import_context->simple = NULL;
+
+	g_simple_async_result_set_op_res_gboolean (simple, can_import);
+	g_simple_async_result_complete (simple);
+
+	inspect_context_free (inspect_context);
+}
+
+static void
+import_read_ready_cb (GFile *file,
+                      GAsyncResult *result,
+                      ImportContext *import_context)
+{
+	GCancellable *cancellable;
+	GFileInputStream *input_stream;
+	GOutputStream *output_stream;
+	GError *error = NULL;
+
+	input_stream = g_read_finish (file, result, &error);
+
+	if (import_check_for_error (import_context, error))
+		return;
+
+	/* Load the contents into a GMemoryOutputStream. */
+	output_stream = g_memory_output_stream_new (
+		NULL, 0, g_realloc, g_free);
+
+	cancellable = import_context->cancellable;
+
+	g_output_stream_splice_async (
+		output_stream,
+		G_INPUT_STREAM (input_stream),
+		G_OUTPUT_STREAM_SPLICE_CLOSE_SOURCE |
+		G_OUTPUT_STREAM_SPLICE_CLOSE_TARGET,
+		G_PRIORITY_DEFAULT, cancellable,
+		(GAsyncReadyCallback) import_splice_ready_cb,
+		import_context);
+
+	g_object_unref (input_stream);
+	g_object_unref (output_stream);
+}
+
+/********************* e_import_handler_inspect_async() **********************/
+
+typedef struct _InspectContext;
+
+struct _InspectContext {
+	EImportHandler *handler;
+	GCancellable *cancellable;
+	GSimpleAsyncResult *simple;
+};
+
+static InspectContext *
+inspect_context_new (EImportHandler *handler,
+                     GCancellable *cancellable,
+                     GAsyncReadyCallback callback,
+                     gpointer user_data)
+{
+	InspectContext *inspect_context;
+	GSimpleAsyncResult *simple;
+
+	if (cancellable != NULL)
+		g_object_ref (cancellable);
+
+	simple = g_simple_async_result_new (
+		G_OBJECT (handler), callback,
+		user_data, e_import_handler_inspect_async);
+
+	inspect_context = g_slice_new0 (InspectContext);
+	inspect_context->handler = g_object_ref (handler);
+	inspect_context->cancellable = cancellable;
+	inspect_context->simple = simple;
+
+	return inspect_context;
+}
+
+static void
+inspect_context_free (InspectContext *inspect_context)
+{
+	/* Do not free the GSimpleAsyncResult. */
+	g_object_unref (inspect_context->handler);
+
+	if (inspect_context->cancellable != NULL)
+		g_object_unref (inspect_context->cancellable);
+
+	g_slice_free (InspectContext, inspect_context);
+}
+
+static gboolean
+inspect_check_for_error (InspectContext *inspect_context,
+                         GError *error)
+{
+	GSimpleAsyncResult *simple;
+
+	if (error == NULL)
+		return FALSE;
+
+	/* Steal the result. */
+	simple = inspect_context->simple;
+	inspect_context->simple = NULL;
+
+	g_simple_async_result_set_op_res_gboolean (simple, FALSE);
+	g_simple_async_result_set_from_error (simple, error);
+	g_simple_async_result_complete (simple);
+	g_error_free (error);
+
+	inspect_context_free (inspect_context);
+
+	return TRUE;
+}
+
+static void
+inspect_splice_ready_cb (GOutputStream *output_stream,
+                         GAsyncResult *result,
+                         InspectContext *inspect_context)
+{
+	GSimpleAsyncResult *simple;
+	icalcomponent *icalcomp;
+	const gchar *content;
+	gboolean can_import = FALSE;
+	GError *error = NULL;
+
+	g_output_stream_splice_finish (output_stream, result, &error);
+
+	if (inspect_check_for_error (inspect_context, error))
+		return;
+
+	content = g_memory_output_stream_get_data (
+		G_MEMORY_OUTPUT_STREAM (output_stream));
+
+	icalcomp = e_cal_util_parse_ics_string (contents);
+
+	if (icalcomp != NULL) {
+		can_import = icalcomponent_is_valid (icalcomp);
+		icalcomponent_free (icalcomp);
+	}
+
+	/* Steal the result. */
+	simple = inspect_context->simple;
+	inspect_context->simple = NULL;
+
+	g_simple_async_result_set_op_res_gboolean (simple, can_inport);
+	g_simple_async_result_complete (simple);
+
+	inspect_context_free (inspect_context);
+}
+
+static void
+inspect_read_ready_cb (GFile *file,
+                       GAsyncResult *result,
+                       InspectContext *inspect_context)
+{
+	GCancellable *cancellable;
+	GFileInputStream *input_stream;
+	GOutputStream *output_stream;
+	GError *error = NULL;
+
+	input_stream = g_read_finish (file, result, &error);
+
+	if (inspect_check_for_error (inspect_context, error))
+		return;
+
+	/* Load the contents into a GMemoryOutputStream. */
+	output_stream = g_memory_output_stream_new (
+		NULL, 0, g_realloc, g_free);
+
+	cancellable = inspect_context->cancellable;
+
+	g_ouput_stream_splice_async (
+		output_stream,
+		G_INPUT_STREAM (input_stream),
+		G_OUTPUT_STREAM_SPLICE_CLOSE_SOURCE |
+		G_OUTPUT_STREAM_SPLICE_CLOSE_TARGET,
+		G_PRIORITY_DEFAULT, cancellable,
+		(GAsyncReadyCallback) inspect_splice_ready_cb,
+		inspect_context);
+
+	g_object_unref (input_stream);
+	g_object_unref (output_stream);
+}
+
+/*********************** End of Asynchronous Callbacks ***********************/
+
+static void
+ical_import_handler_import_async (EImportHandler *handler,
+                                  GFile *source,
+                                  GCancellable *cancellable,
+                                  GFileProgressCallback progress_callback,
+                                  gpointer progress_callback_data,
+                                  GAsyncReadyCallback callback,
+                                  gpointer user_data)
+{
+}
+
+static gboolean
+ical_import_handler_import_finish (EImportHandler *handler,
+                                   AsyncResult *result,
+                                   GError **error)
+{
+	GSimpleAsyncResult *simple;
+	gboolean success;
+
+	simple = G_SIMPLE_ASYNC_RESULT (result);
+	success = g_simple_async_result_get_op_res_gboolean (simple);
+	g_simple_async_result_propagate_error (simple, error);
+	g_object_unref (simple);
+
+	return success;
+}
+
+static void
+ical_import_handler_inspect_async (EImportHandler *handler,
+                                   GFile *source,
+                                   GCancellable *cancellable,
+                                   GAsyncReadyCallback callback,
+                                   gpointer user_data)
+{
+	InspectContext *inspect_context;
+
+	inspect_context = inspect_context_new (
+		handler, cancellable, callback, user_data);
+
+	g_read_async (
+		source, G_PRIORITY_DEFAULT, cancellable,
+		(GAsyncReadyCallback) inspect_read_ready_cb,
+		inspect_context);
+}
+
+static gboolean
+ical_import_handler_inspect_finish (EImportHandler *handler,
+                                    GAsyncResult *result,
+                                    GError **error)
+{
+	GSimpleAsyncResult *simple;
+	gboolean can_import;
+
+	simple = G_SIMPLE_ASYNC_RESULT (result);
+	can_import = g_simple_async_result_get_op_res_gboolean (simple);
+	g_simple_async_result_propagate_error (simple, error);
+	g_object_unref (simple);
+
+	return can_import;
+}
+
+static void
+ical_import_handler_class_init (EIcalImportHandlerClass *class)
+{
+	EImportHandlerClass *import_handler_class;
+	const gchar *name;
+	const gchar *description;
+
+	parent_class = g_type_class_peek_parent (class);
+	g_type_class_add_private (class, sizeof (EIcalImportHandlerPrivate));
+
+	name = _("iCalendar files (.ics)");
+	description = _("Evolution iCalendar importer");
+
+	import_handler_class = E_IMPORT_HANDLER_CLASS (class);
+	import_handler_class->name = name;
+	import_handler_class->description = description;
+	import_handler_class->flags = E_IMPORT_SINGLE_FILE;
+	import_handler_class->import_async = ical_import_handler_import_async;
+	import_handler_class->import_finish = ical_import_handler_import_finish;
+	import_handler_class->inspect_async = ical_import_handler_inspect_async;
+	import_handler_class->inspect_finish = ical_import_handler_inspect_finish;
+}
+
+static void
+ical_import_handler_init (EIcalImportHandler *handler)
+{
+	handler->priv = E_ICAL_IMPORT_HANDLER_GET_PRIVATE (handler);
+}
+
+GType
+e_ical_import_handler_get_type (void)
+{
+	return ical_import_handler_type;
+}
+
+void
+e_ical_import_handler_register_type (GTypeModule *type_module)
+{
+	static const GTypeInfo type_info = {
+		sizeof (EIcalImportHandlerClass),
+		(GBaseInitFunc) NULL,
+		(GBaseFinalizeFunc) NULL,
+		(GClassInitFunc) ical_import_handler_class_init,
+		(GClassFinalizeFunc) NULL,
+		NULL,  /* class_data */
+		sizeof (EIcalImportHandler),
+		0,     /* n_preallocs */
+		(GInstanceInitFunc) ical_import_handler_init,
+		NULL   /* value_table */
+	};
+
+	ical_import_handler_type = g_type_module_register_type (
+		type_module, E_TYPE_CAL_IMPORT_HANDLER,
+		"EIcalImportHandler", &type_info, 0);
+}
diff --git a/modules/calendar/e-ical-import-handler.h b/modules/calendar/e-ical-import-handler.h
new file mode 100644
index 0000000..d26dfa6
--- /dev/null
+++ b/modules/calendar/e-ical-import-handler.h
@@ -0,0 +1,66 @@
+/*
+ * e-ical-import-handler.h
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) version 3.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with the program; if not, see <http://www.gnu.org/licenses/>
+ *
+ *
+ * Copyright (C) 1999-2008 Novell, Inc. (www.novell.com)
+ *
+ */
+
+#ifndef E_ICAL_IMPORT_HANDLER_H
+#define E_ICAL_IMPORT_HANDLER_H
+
+#include "e-cal-import-handler.h"
+
+/* Standard GObject macros */
+#define E_TYPE_ICAL_IMPORT_HANDLER \
+	(e_ical_import_handler_get_type ())
+#define E_ICAL_IMPORT_HANDLER(obj) \
+	(G_TYPE_CHECK_INSTANCE_CAST \
+	((obj), E_TYPE_ICAL_IMPORT_HANDLER, EIcalImportHandler))
+#define E_ICAL_IMPORT_HANDLER_CLASS(cls) \
+	(G_TYPE_CHECK_CLASS_CAST \
+	((cls), E_TYPE_ICAL_IMPORT_HANDLER, EIcalImportHandlerClass))
+#define E_IS_ICAL_IMPORT_HANDLER(obj) \
+	(G_TYPE_CHECK_INSTANCE_TYPE \
+	((obj), E_TYPE_ICAL_IMPORT_HANDLER))
+#define E_IS_ICAL_IMPORT_HANDLER_CLASS(cls) \
+	(G_TYPE_CHECK_CLASS_TYPE \
+	((cls), E_TYPE_ICAL_IMPORT_HANDLER))
+#define E_ICAL_IMPORT_HANDLER_GET_CLASS(obj) \
+	(G_TYPE_INSTANCE_GET_CLASS \
+	((obj), E_TYPE_ICAL_IMPORT_HANDLER, EIcalImportHandlerClass))
+
+G_BEGIN_DECLS
+
+typedef struct _EIcalImportHandler EIcalImportHandler;
+typedef struct _EIcalImportHandlerClass EIcalImportHandlerClass;
+typedef struct _EIcalImportHandlerPrivate EIcalImportHandlerPrivate;
+
+struct _EIcalImportHandler {
+	ECalImportHandler parent;
+	EIcalImportHandlerPrivate *priv;
+};
+
+struct _EIcalImportHandlerClass {
+	ECalImportHandlerClass parent_class;
+};
+
+GType	e_ical_import_handler_get_type		(void);
+void	e_ical_import_handler_register_type	(GTypeModule *type_module);
+
+G_END_DECLS
+
+#endif /* E_ICAL_IMPORT_HANDLER_H */
diff --git a/modules/calendar/evolution-module-calendar.c b/modules/calendar/evolution-module-calendar.c
index f72e8a9..263a6ab 100644
--- a/modules/calendar/evolution-module-calendar.c
+++ b/modules/calendar/evolution-module-calendar.c
@@ -24,6 +24,9 @@
 #include "e-cal-config-hook.h"
 #include "e-cal-event-hook.h"
 
+#include "e-cal-import-handler.h"
+#include "e-ical-import-handler.h"
+
 #include "e-cal-shell-backend.h"
 #include "e-cal-shell-content.h"
 #include "e-cal-shell-sidebar.h"
@@ -53,6 +56,9 @@ e_module_load (GTypeModule *type_module)
 	e_cal_config_hook_register_type (type_module);
 	e_cal_event_hook_register_type (type_module);
 
+	e_cal_import_handler_register_type (type_module);
+	e_ical_import_handler_register_type (type_module);
+
 	e_cal_shell_backend_register_type (type_module);
 	e_cal_shell_content_register_type (type_module);
 	e_cal_shell_sidebar_register_type (type_module);



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