[evolution-kolab/ek-wip-porting: 8/8] calendar: get the cal loading again, various fixups



commit 866780a024f663e0c2e0955846a92c0d353b5c07
Author: Christian Hilberg <hilberg kernelconcepts de>
Date:   Thu Mar 15 23:57:34 2012 +0100

    calendar: get the cal loading again, various fixups
    
    * calendar types can be open()ed again
    * properly create their backend databases
      under the new directory scheme (and use
      ESource UIDs for that)
    * completed initialization of KolabSettingsHandler
      and KolabMailAccess
    * error handling fixes

 src/calendar/e-cal-backend-kolab-factory.c |   19 +-
 src/calendar/e-cal-backend-kolab.c         |  623 ++++++++++++++++------------
 src/calendar/kolab-util-calendar.c         |   66 +++
 src/calendar/kolab-util-calendar.h         |    6 +
 4 files changed, 434 insertions(+), 280 deletions(-)
---
diff --git a/src/calendar/e-cal-backend-kolab-factory.c b/src/calendar/e-cal-backend-kolab-factory.c
index f5d63b4..2fd1d0a 100644
--- a/src/calendar/e-cal-backend-kolab-factory.c
+++ b/src/calendar/e-cal-backend-kolab-factory.c
@@ -26,15 +26,23 @@
 
 /*----------------------------------------------------------------------------*/
 
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
 #include <glib.h>
 #include <glib-object.h>
+
 #include <libedata-cal/e-cal-backend-factory.h>
+#include <libekolabutil/kolab-util-camel.h>
 
 #include "e-cal-backend-kolab.h"
 
 /*----------------------------------------------------------------------------*/
 
-#define FACTORY_NAME "kolab2"
+#define FACTORY_NAME KOLAB_CAMEL_PROVIDER_PROTOCOL
+
+/*----------------------------------------------------------------------------*/
 
 typedef ECalBackendFactory ECalBackendKolabEventsFactory;
 typedef ECalBackendFactoryClass ECalBackendKolabEventsFactoryClass;
@@ -54,18 +62,15 @@ GType e_cal_backend_kolab_events_factory_get_type (void);
 GType e_cal_backend_kolab_journal_factory_get_type (void);
 GType e_cal_backend_kolab_todos_factory_get_type (void);
 
-G_DEFINE_DYNAMIC_TYPE (
-                       ECalBackendKolabEventsFactory,
+G_DEFINE_DYNAMIC_TYPE (ECalBackendKolabEventsFactory,
                        e_cal_backend_kolab_events_factory,
                        E_TYPE_CAL_BACKEND_FACTORY)
 
-G_DEFINE_DYNAMIC_TYPE (
-                       ECalBackendKolabJournalFactory,
+G_DEFINE_DYNAMIC_TYPE (ECalBackendKolabJournalFactory,
                        e_cal_backend_kolab_journal_factory,
                        E_TYPE_CAL_BACKEND_FACTORY)
 
-G_DEFINE_DYNAMIC_TYPE (
-                       ECalBackendKolabTodosFactory,
+G_DEFINE_DYNAMIC_TYPE (ECalBackendKolabTodosFactory,
                        e_cal_backend_kolab_todos_factory,
                        E_TYPE_CAL_BACKEND_FACTORY)
 
diff --git a/src/calendar/e-cal-backend-kolab.c b/src/calendar/e-cal-backend-kolab.c
index 052c2ae..bf194c9 100644
--- a/src/calendar/e-cal-backend-kolab.c
+++ b/src/calendar/e-cal-backend-kolab.c
@@ -30,6 +30,7 @@
 #include <gio/gio.h>
 
 #include <libedata-cal/e-cal-backend-cache.h>
+#include <libedata-cal/e-data-cal-types.h>
 #include <libecal/e-cal.h>
 
 #include <libical/ical.h>
@@ -49,7 +50,7 @@
 /*----------------------------------------------------------------------------*/
 /* table of KolabMailAccess objects */
 
-/* static GHashTable *koma_objects = NULL; */
+static GHashTable *koma_objects = NULL;
 
 /*----------------------------------------------------------------------------*/
 
@@ -100,33 +101,45 @@ e_cal_backend_kolab_open (ECalBackendSync *backend,
                           EDataCal *cal,
                           GCancellable *cancellable,
                           gboolean only_if_exists,
-                          GError **err)
+                          GError **error)
 {
-	ECalBackendKolab *self = E_CAL_BACKEND_KOLAB (backend);
-	ECalBackendKolabPrivate *priv = E_CAL_BACKEND_KOLAB_PRIVATE (self);
-
-	g_assert (E_IS_DATA_CAL (cal));
-	(void)cancellable; /* FIXME */ /* cancellable may be NULL */
+	ECalBackendKolab *self = NULL;
+	ECalBackendKolabPrivate *priv = NULL;
+	ESource *esource = NULL;
+        CamelURL *c_url = NULL;
+        KolabSettingsHandler *ksettings = NULL;
+        KolabMailAccess *tmp_koma = NULL;
+        KolabSyncStrategyID sync_value = KOLAB_SYNC_STRATEGY_DEFAULT;
+        KolabMailAccessOpmodeID tmp_mode = KOLAB_MAIL_ACCESS_OPMODE_INVAL;
+        icalcomponent_kind icalkind = ICAL_VEVENT_COMPONENT;
+        gchar *sourcename = NULL;
+        gchar *servername = NULL;
+        gchar *username = NULL;
+        gchar *user_at_server = NULL;
+        gchar *tmp_key = NULL;
+        const gchar *prop_str = NULL;
+	GError *tmp_err = NULL;
+	gboolean ok = FALSE;
+
+	g_return_if_fail (error == NULL || *error == NULL);
+	e_return_data_cal_error_if_fail (E_IS_CAL_BACKEND_KOLAB (backend), InvalidArg);
+	e_return_data_cal_error_if_fail (E_IS_DATA_CAL (cal), InvalidArg);
+	/* cancellable may be NULL */
 	(void)only_if_exists; /* FIXME */
-	g_return_if_fail (err == NULL || *err == NULL);
 
-	(void)self;
-	(void)priv;
-	g_error ("%s: FIXME implement me", __func__);
+	self = E_CAL_BACKEND_KOLAB (backend);
+	priv = E_CAL_BACKEND_KOLAB_PRIVATE (self);
 
-#if 0 /* FIXME old */
 	/* to trigger eds to pass along username and password, set the property
 	 * "auth" to "true" in the source setting:
 	 * <property name="auth" value="true"/>
 	 * <property name="username" value="..."/>
 	 */
 
-	if (priv->already_opened == TRUE) return status;
-
-	esource = e_cal_backend_get_source (E_CAL_BACKEND (backend));
-	/* Getting the esource from the cal-Object did not work as expected? */
+	if (priv->already_opened == TRUE)
+		return;
 
-	icalkind = e_cal_backend_get_kind (E_CAL_BACKEND (kolab));
+	icalkind = e_cal_backend_get_kind (E_CAL_BACKEND (backend));
 	/* TODO: this has to be set according to the get_kind() method */
 	switch (icalkind) {
 	case ICAL_VEVENT_COMPONENT:
@@ -139,6 +152,7 @@ e_cal_backend_kolab_open (ECalBackendSync *backend,
 		priv->source_type = E_CAL_SOURCE_TYPE_JOURNAL;
 		break;
 	default:
+		/* FIXME */
 		g_error ("%s()[%u]: Unknown Type used in e-cal-backend-kolab initialization!",
 		         __func__, __LINE__);
 	}
@@ -150,44 +164,53 @@ e_cal_backend_kolab_open (ECalBackendSync *backend,
 	 * but as far as SSL goes, we want Camel to rule here
 	 * TODO check whether Camel session needs to be initialized before or after libcurl.
 	 */
-	ok = kolab_util_camel_init (&error);
+	ok = kolab_util_camel_init (&tmp_err);
 	if (! ok) {
-		status = kolab_util_calendar_map_error (error);
-		g_warning ("%s()[%u]: %s",
-		           __func__, __LINE__, error->message);
-		g_error_free (error);
-		error = NULL;
+		kolab_util_calendar_err_to_edb_err (error, tmp_err, __func__, __LINE__);
+		g_error_free (tmp_err);
+		return;
 	}
 
-	priv->cal_uri = e_source_get_uri(esource);
+	esource = e_backend_get_source (E_BACKEND (backend));
+	if (! E_IS_SOURCE (esource)) {
+		/* FIXME mark this as a translatable string */
+		tmp_err = e_data_cal_create_error (OtherError,
+		                                   "Could not get ESource for backend");
+		g_propagate_error (error, tmp_err);
+		return;
+	}
 
-	cex = camel_exception_new ();
-	c_url = camel_url_new (priv->cal_uri, cex);
+	priv->cal_uri = e_source_get_uri (esource);
+
+	c_url = camel_url_new (priv->cal_uri, &tmp_err);
 	if (c_url == NULL) {
-		g_warning ("%s()[%u]: %s",
-		           __func__, __LINE__,
-		           camel_exception_get_description (cex));
-		camel_exception_free (cex);
-		status = GNOME_Evolution_Calendar_OtherError;
+		kolab_util_calendar_err_to_edb_err (error, tmp_err, __func__, __LINE__);
+		g_error_free (tmp_err);
+		return;
 	}
 	servername = g_strdup (c_url->host);
+	username = g_strdup (c_url->user);
 	camel_url_free (c_url);
+	g_debug ("%s()[%u] servername = %s",
+	         __func__, __LINE__, servername);
+	g_debug ("%s()[%u]   username = %s",
+	         __func__, __LINE__, username);
 
 	/* Initialize backend cache */
 	if (priv->cal_cache != NULL) {
 		g_object_unref (priv->cal_cache);
 	}
-	priv->cal_cache = e_cal_backend_cache_new (priv->cal_uri,
-	                                           priv->source_type);
+	priv->cal_cache = e_cal_backend_cache_new (priv->cal_uri);
 	ok = e_file_cache_clean (E_FILE_CACHE (priv->cal_cache));
+	g_debug (" + Cal cache cleaning %s.", ok ? "was successful" : "FAILED");
 
 	/* Prepare data from sync strategy property */
 	prop_str = e_source_get_property (esource, KOLAB_SYNC_STRATEGY_PROP);
 	sync_value = kolab_util_misc_sync_value_from_property (prop_str);
 	sourcename = kolab_util_backend_get_relative_path_from_uri (priv->cal_uri);
 
-	/* This was the easy part. Now try to get the KoMA objects figured out */
-	user_at_server = g_strdup_printf ("%s %s", username, servername);
+	user_at_server = g_strdup_printf ("%s %s",
+	                                  username, servername);
 
 	ok = g_hash_table_lookup_extended (priv->koma_table,
 	                                   user_at_server,
@@ -197,6 +220,8 @@ e_cal_backend_kolab_open (ECalBackendSync *backend,
 		/* There is already a KoMA instance for $servername. Use it and return */
 		g_object_ref (tmp_koma);
 		priv->cal_koma = tmp_koma;
+		g_free (servername);
+		g_free (username);
 		g_free (user_at_server);
 		ksettings = kolab_mail_access_get_settings_handler (priv->cal_koma);
 		kolab_util_backend_prepare_settings (ksettings,
@@ -208,34 +233,47 @@ e_cal_backend_kolab_open (ECalBackendSync *backend,
 		                                     &sync_value);
 		goto notifications;
 	}
-	/* Otherwise we need to setup a new KoMA instance and a settings handler */
 
+	/* Nope, we need to setup a new KoMA instance and a settings handler */
+
+	/* Configure settings handler */
 	ksettings = KOLAB_SETTINGS_HANDLER (g_object_new (KOLAB_TYPE_SETTINGS_HANDLER, NULL));
-	(void) kolab_settings_handler_configure (ksettings,
-	                                         KOLAB_FOLDER_CONTEXT_CALENDAR,
-	                                         &error);
-	if (error != NULL) {
-		g_warning ("%s()[%u]: %s",
-		           __func__, __LINE__, error->message);
-		g_error_free (error);
-		error = NULL;
+	ok = kolab_settings_handler_configure (ksettings,
+	                                       KOLAB_FOLDER_CONTEXT_CALENDAR,
+	                                       &tmp_err);
+	if (! ok) {
+		g_free (servername);
+		g_free (username);
+		g_free (user_at_server);
+		g_object_unref (ksettings);
+		kolab_util_calendar_err_to_edb_err (error, tmp_err, __func__, __LINE__);
+		g_error_free (tmp_err);
+		return;
 	}
-	(void) kolab_settings_handler_bringup (ksettings,
-	                                       &error);
-	if (error != NULL) {
-		g_warning ("%s()[%u]: %s",
-		           __func__, __LINE__, error->message);
-		g_error_free (error);
-		error = NULL;
+
+	ok = kolab_settings_handler_bringup (ksettings, &tmp_err);
+	if (! ok) {
+		g_free (servername);
+		g_free (username);
+		g_free (user_at_server);
+		g_object_unref (ksettings);
+		kolab_util_calendar_err_to_edb_err (error, tmp_err, __func__, __LINE__);
+		g_error_free (tmp_err);
+		return;
 	}
+
 	kolab_util_backend_prepare_settings (ksettings,
 	                                     esource,
 	                                     servername,
 	                                     username,
-	                                     password,
+	                                     NULL,
 	                                     sourcename,
 	                                     &sync_value);
 
+	g_free (servername);
+	g_free (username);
+	g_free (sourcename);
+
 	priv->cal_koma = KOLAB_MAIL_ACCESS (g_object_new (KOLAB_TYPE_MAIL_ACCESS, NULL));
 	g_object_add_toggle_ref (G_OBJECT (priv->cal_koma),
 	                         kolab_util_backend_koma_table_cleanup_cb,
@@ -244,36 +282,30 @@ e_cal_backend_kolab_open (ECalBackendSync *backend,
 	                     user_at_server,
 	                     priv->cal_koma);
 
-	kolab_mail_access_configure (priv->cal_koma,
-	                             ksettings,
-	                             &error);
+	ok = kolab_mail_access_configure (priv->cal_koma,
+	                                  ksettings,
+	                                  &tmp_err);
 	g_object_unref (ksettings);
-	if (error != NULL) {
-		status = kolab_util_calendar_map_error (error);
-		g_warning ("%s()[%u]: %s",
-		           __func__, __LINE__, error->message);
-		g_error_free (error);
-		return status;
+	if (! ok) {
+		kolab_util_calendar_err_to_edb_err (error, tmp_err, __func__, __LINE__);
+		g_error_free (tmp_err);
+		return;
 	}
-	kolab_mail_access_bringup (priv->cal_koma,
-	                           &error);
-	if (error != NULL) {
-		status = kolab_util_calendar_map_error (error);
-		g_warning ("%s()[%u]: %s",
-		           __func__, __LINE__, error->message);
-		g_error_free (error);
-		return status;
+
+	ok = kolab_mail_access_bringup (priv->cal_koma,
+	                                cancellable,
+	                                &tmp_err);
+	if (! ok) {
+		kolab_util_calendar_err_to_edb_err (error, tmp_err, __func__, __LINE__);
+		g_error_free (tmp_err);
+		return;
 	}
 
  notifications:
 	priv->already_opened = TRUE;
+#if 0 /* FIXME */
 	e_cal_backend_kolab_set_mode (E_CAL_BACKEND (backend),
 	                              priv->cal_mode);
-
-	g_free (sourcename);
-	g_free (servername);
-
-	return status;
 #endif
 }
 
@@ -281,17 +313,19 @@ static void
 e_cal_backend_kolab_remove (ECalBackendSync *backend,
                             EDataCal *cal,
                             GCancellable *cancellable,
-                            GError **err)
+                            GError **error)
 {
-	ECalBackendKolab *self = E_CAL_BACKEND_KOLAB (backend);
-	ECalBackendKolabPrivate *priv = E_CAL_BACKEND_KOLAB_PRIVATE (self);
+	ECalBackendKolab *self = NULL;
+	ECalBackendKolabPrivate *priv = NULL;
+
+	g_return_if_fail (error == NULL || *error == NULL);
+	e_return_data_cal_error_if_fail (E_IS_CAL_BACKEND_KOLAB (backend), InvalidArg);
+	e_return_data_cal_error_if_fail (E_IS_DATA_CAL (cal), InvalidArg);
+	/* cancellable may be NULL */
 
-	g_assert (E_IS_DATA_CAL (cal));
-	(void)cancellable; /* FIXME */ /* cancellable may be NULL */
-	g_return_if_fail (err == NULL || *err == NULL);
+	self = E_CAL_BACKEND_KOLAB (backend);
+	priv = E_CAL_BACKEND_KOLAB_PRIVATE (self);
 
-	(void)self;
-	(void)priv;
 	g_error ("%s: FIXME implement me", __func__);
 
 #if 0 /* FIXME old */
@@ -316,17 +350,19 @@ static void
 e_cal_backend_kolab_refresh (ECalBackendSync *backend,
                              EDataCal *cal,
                              GCancellable *cancellable,
-                             GError **err)
+                             GError **error)
 {
-	ECalBackendKolab *self = E_CAL_BACKEND_KOLAB (backend);
-	ECalBackendKolabPrivate *priv = E_CAL_BACKEND_KOLAB_PRIVATE (self);
+	ECalBackendKolab *self = NULL;
+	ECalBackendKolabPrivate *priv = NULL;
 
-	g_assert (E_IS_DATA_CAL (cal));
-	(void)cancellable; /* FIXME */ /* cancellable may be NULL */
-	g_return_if_fail (err == NULL || *err == NULL);
+	g_return_if_fail (error == NULL || *error == NULL);
+	e_return_data_cal_error_if_fail (E_IS_CAL_BACKEND_KOLAB (backend), InvalidArg);
+	e_return_data_cal_error_if_fail (E_IS_DATA_CAL (cal), InvalidArg);
+	/* cancellable may be NULL */
+
+	self = E_CAL_BACKEND_KOLAB (backend);
+	priv = E_CAL_BACKEND_KOLAB_PRIVATE (self);
 
-	(void)self;
-	(void)priv;
 	g_error ("%s: FIXME implement me", __func__);
 }
 
@@ -336,19 +372,21 @@ e_cal_backend_kolab_get_backend_property (ECalBackendSync *backend,
                                           GCancellable *cancellable,
                                           const gchar *prop_name,
                                           gchar **prop_value,
-                                          GError **err)
+                                          GError **error)
 {
-	ECalBackendKolab *self = E_CAL_BACKEND_KOLAB (backend);
-	ECalBackendKolabPrivate *priv = E_CAL_BACKEND_KOLAB_PRIVATE (self);
+	ECalBackendKolab *self = NULL;
+	ECalBackendKolabPrivate *priv = NULL;
+
+	g_return_val_if_fail (error == NULL || *error == NULL, FALSE);
+	e_return_data_cal_error_val_if_fail (E_IS_CAL_BACKEND_KOLAB (backend), InvalidArg);
+	e_return_data_cal_error_val_if_fail (E_IS_DATA_CAL (cal), InvalidArg);
+	/* cancellable may be NULL */
+	e_return_data_cal_error_val_if_fail (prop_name != NULL, InvalidArg);
+	e_return_data_cal_error_val_if_fail (prop_value != NULL && *prop_value == NULL, InvalidArg);
 
-	g_assert (E_IS_DATA_CAL (cal));
-	(void)cancellable; /* FIXME */ /* cancellable may be NULL */
-	g_assert (prop_name != NULL);
-	(void)prop_value; /* FIXME */ /* must be NULL? */
-	g_return_val_if_fail (err == NULL || *err == NULL, FALSE);
+	self = E_CAL_BACKEND_KOLAB (backend);
+	priv = E_CAL_BACKEND_KOLAB_PRIVATE (self);
 
-	(void)self;
-	(void)priv;
 	g_error ("%s: FIXME implement me", __func__);
 
 	return FALSE;
@@ -360,19 +398,21 @@ e_cal_backend_kolab_set_backend_property (ECalBackendSync *backend,
                                           GCancellable *cancellable,
                                           const gchar *prop_name,
                                           const gchar *prop_value,
-                                          GError **err)
+                                          GError **error)
 {
-	ECalBackendKolab *self = E_CAL_BACKEND_KOLAB (backend);
-	ECalBackendKolabPrivate *priv = E_CAL_BACKEND_KOLAB_PRIVATE (self);
+	ECalBackendKolab *self = NULL;
+	ECalBackendKolabPrivate *priv = NULL;
+
+	g_return_val_if_fail (error == NULL || *error == NULL, FALSE);
+	e_return_data_cal_error_val_if_fail (E_IS_CAL_BACKEND_KOLAB (backend), InvalidArg);
+	e_return_data_cal_error_val_if_fail (E_IS_DATA_CAL (cal), InvalidArg);
+	/* cancellable may be NULL */
+	e_return_data_cal_error_val_if_fail (prop_name != NULL, InvalidArg);
+	e_return_data_cal_error_val_if_fail (prop_value != NULL, InvalidArg);
 
-	g_assert (E_IS_DATA_CAL (cal));
-	(void)cancellable; /* FIXME */ /* cancellable may be NULL */
-	g_assert (prop_name != NULL);
-	(void)prop_value; /* FIXME */ /* may be NULL? */
-	g_return_val_if_fail (err == NULL || *err == NULL, FALSE);
+	self = E_CAL_BACKEND_KOLAB (backend);
+	priv = E_CAL_BACKEND_KOLAB_PRIVATE (self);
 
-	(void)self;
-	(void)priv;
 	g_error ("%s: FIXME implement me", __func__);
 
 	return FALSE;
@@ -399,20 +439,22 @@ e_cal_backend_kolab_get_object (ECalBackendSync *backend,
                                 const gchar *uid,
                                 const gchar *rid,
                                 gchar **calobj,
-                                GError **err)
+                                GError **error)
 {
-	ECalBackendKolab *self = E_CAL_BACKEND_KOLAB (backend);
-	ECalBackendKolabPrivate *priv = E_CAL_BACKEND_KOLAB_PRIVATE (self);
+	ECalBackendKolab *self = NULL;
+	ECalBackendKolabPrivate *priv = NULL;
 
-	g_assert (E_IS_DATA_CAL (cal));
-	(void)cancellable; /* FIXME */ /* cancellable may be NULL */
-	g_assert (uid != NULL);
-	(void)rid; /* FIXME */ /* may be NULL? */
-	(void)calobj; /* FIXME */ /* must be NULL? */
-	g_return_if_fail (err == NULL || *err == NULL);
+	g_return_if_fail (error == NULL || *error == NULL);
+	e_return_data_cal_error_if_fail (E_IS_CAL_BACKEND_KOLAB (backend), InvalidArg);
+	e_return_data_cal_error_if_fail (E_IS_DATA_CAL (cal), InvalidArg);
+	/* cancellable may be NULL */
+	e_return_data_cal_error_if_fail (uid != NULL, InvalidArg);
+	/* rid may be NULL */
+	e_return_data_cal_error_if_fail (calobj != NULL && *calobj == NULL, InvalidArg);
+
+	self = E_CAL_BACKEND_KOLAB (backend);
+	priv = E_CAL_BACKEND_KOLAB_PRIVATE (self);
 
-	(void)self;
-	(void)priv;
 	g_error ("%s: FIXME implement me", __func__);
 
 #if 0 /* FIXME old */
@@ -449,19 +491,21 @@ e_cal_backend_kolab_get_object_list (ECalBackendSync *backend,
                                      GCancellable *cancellable,
                                      const gchar *sexp,
                                      GSList **calobjs,
-                                     GError **err)
+                                     GError **error)
 {
-	ECalBackendKolab *self = E_CAL_BACKEND_KOLAB (backend);
-	ECalBackendKolabPrivate *priv = E_CAL_BACKEND_KOLAB_PRIVATE (self);
+	ECalBackendKolab *self = NULL;
+	ECalBackendKolabPrivate *priv = NULL;
 
-	g_assert (E_IS_DATA_CAL (cal));
-	(void)cancellable; /* FIXME */ /* cancellable may be NULL */
-	(void)sexp; /* FIXME */ /* sexp may be NULL */
-	(void)calobjs; /* FIXME */ /* must be NULL? */
-	g_return_if_fail (err == NULL || *err == NULL);
+	g_return_if_fail (error == NULL || *error == NULL);
+	e_return_data_cal_error_if_fail (E_IS_CAL_BACKEND_KOLAB (backend), InvalidArg);
+	e_return_data_cal_error_if_fail (E_IS_DATA_CAL (cal), InvalidArg);
+	/* cancellable may be NULL */
+	/* sexp may be NULL */
+	e_return_data_cal_error_if_fail (calobjs != NULL && *calobjs == NULL, InvalidArg);
+
+	self = E_CAL_BACKEND_KOLAB (backend);
+	priv = E_CAL_BACKEND_KOLAB_PRIVATE (self);
 
-	(void)self;
-	(void)priv;
 	g_error ("%s: FIXME implement me", __func__);
 
 #if 0 /* FIXME old */
@@ -521,21 +565,21 @@ e_cal_backend_kolab_get_free_busy (ECalBackendSync *backend,
                                    time_t start,
                                    time_t end,
                                    GSList **freebusyobjs,
-                                   GError **err)
+                                   GError **error)
 {
-	ECalBackendKolab *self = E_CAL_BACKEND_KOLAB (backend);
-	ECalBackendKolabPrivate *priv = E_CAL_BACKEND_KOLAB_PRIVATE (self);
+	ECalBackendKolab *self = NULL;
+	ECalBackendKolabPrivate *priv = NULL;
+
+	g_return_if_fail (error == NULL || *error == NULL);
+	e_return_data_cal_error_if_fail (E_IS_CAL_BACKEND_KOLAB (backend), InvalidArg);
+	e_return_data_cal_error_if_fail (E_IS_DATA_CAL (cal), InvalidArg);
+	/* cancellable may be NULL */
+	e_return_data_cal_error_if_fail (users != NULL, InvalidArg);
+	e_return_data_cal_error_if_fail (freebusyobjs != NULL && *freebusyobjs == NULL, InvalidArg);
 
-	g_assert (E_IS_DATA_CAL (cal));
-	(void)cancellable; /* FIXME */ /* cancellable may be NULL */
-	(void)users; /* FIXME */
-	(void)start; /* FIXME */
-	(void)end; /* FIXME */
-	(void)freebusyobjs; /* FIXME */ /* must be NULL? */
-	g_return_if_fail (err == NULL || *err == NULL);
+	self = E_CAL_BACKEND_KOLAB (backend);
+	priv = E_CAL_BACKEND_KOLAB_PRIVATE (self);
 
-	(void)self;
-	(void)priv;
 	g_error ("%s: FIXME implement me", __func__);
 
 #if 0 /* FIXME old */
@@ -606,20 +650,22 @@ e_cal_backend_kolab_create_object (ECalBackendSync *backend,
                                    const gchar *calobj,
                                    gchar **uid,
                                    ECalComponent **new_component,
-                                   GError **err)
+                                   GError **error)
 {
-	ECalBackendKolab *self = E_CAL_BACKEND_KOLAB (backend);
-	ECalBackendKolabPrivate *priv = E_CAL_BACKEND_KOLAB_PRIVATE (self);
+	ECalBackendKolab *self = NULL;
+	ECalBackendKolabPrivate *priv = NULL;
+
+	g_return_if_fail (error == NULL || *error == NULL);
+	e_return_data_cal_error_if_fail (E_IS_CAL_BACKEND_KOLAB (backend), InvalidArg);
+	e_return_data_cal_error_if_fail (E_IS_DATA_CAL (cal), InvalidArg);
+	/* cancellable may be NULL */
+	e_return_data_cal_error_if_fail (calobj != NULL, InvalidArg);
+	e_return_data_cal_error_if_fail (uid != NULL && *uid == NULL, InvalidArg);
+	e_return_data_cal_error_if_fail (new_component != NULL && *new_component == NULL, InvalidArg);
 
-	g_assert (E_IS_DATA_CAL (cal));
-	(void)cancellable; /* FIXME */ /* cancellable may be NULL */
-	(void)calobj; /* FIXME */
-	(void)uid; /* FIXME */
-	g_return_if_fail (new_component == NULL || *new_component == NULL);
-	g_return_if_fail (err == NULL || *err == NULL);
+	self = E_CAL_BACKEND_KOLAB (backend);
+	priv = E_CAL_BACKEND_KOLAB_PRIVATE (self);
 
-	(void)self;
-	(void)priv;
 	g_error ("%s: FIXME implement me", __func__);
 
 #if 0 /* FIXME old */
@@ -728,21 +774,22 @@ e_cal_backend_kolab_modify_object (ECalBackendSync *backend,
                                    CalObjModType mod,
                                    ECalComponent **old_component,
                                    ECalComponent **new_component,
-                                   GError **err)
+                                   GError **error)
 {
-	ECalBackendKolab *self = E_CAL_BACKEND_KOLAB (backend);
-	ECalBackendKolabPrivate *priv = E_CAL_BACKEND_KOLAB_PRIVATE (self);
+	ECalBackendKolab *self = NULL;
+	ECalBackendKolabPrivate *priv = NULL;
 
-	g_assert (E_IS_DATA_CAL (cal));
-	(void)cancellable; /* FIXME */ /* cancellable may be NULL */
-	(void)calobj; /* FIXME */
-	(void)mod; /* FIXME */
-	g_return_if_fail (old_component == NULL || *old_component == NULL); /* FIXME */
-	g_return_if_fail (new_component == NULL || *new_component == NULL); /* FIXME */
-	g_return_if_fail (err == NULL || *err == NULL);
+	g_return_if_fail (error == NULL || *error == NULL);
+	e_return_data_cal_error_if_fail (E_IS_CAL_BACKEND_KOLAB (backend), InvalidArg);
+	e_return_data_cal_error_if_fail (E_IS_DATA_CAL (cal), InvalidArg);
+	/* cancellable may be NULL */
+	e_return_data_cal_error_if_fail (calobj != NULL, InvalidArg);
+	e_return_data_cal_error_if_fail (old_component != NULL && *old_component == NULL, InvalidArg);
+	e_return_data_cal_error_if_fail (new_component != NULL && *new_component == NULL, InvalidArg);
+
+	self = E_CAL_BACKEND_KOLAB (backend);
+	priv = E_CAL_BACKEND_KOLAB_PRIVATE (self);
 
-	(void)self;
-	(void)priv;
 	g_error ("%s: FIXME implement me", __func__);
 
 # if 0 /* FIXME old */
@@ -920,22 +967,23 @@ e_cal_backend_kolab_remove_object (ECalBackendSync *backend,
                                    CalObjModType mod,
                                    ECalComponent **old_component,
                                    ECalComponent **new_component,
-                                   GError **err)
+                                   GError **error)
 {
-	ECalBackendKolab *self = E_CAL_BACKEND_KOLAB (backend);
-	ECalBackendKolabPrivate *priv = E_CAL_BACKEND_KOLAB_PRIVATE (self);
+	ECalBackendKolab *self = NULL;
+	ECalBackendKolabPrivate *priv = NULL;
+
+	g_return_if_fail (error == NULL || *error == NULL);
+	e_return_data_cal_error_if_fail (E_IS_CAL_BACKEND_KOLAB (backend), InvalidArg);
+	e_return_data_cal_error_if_fail (E_IS_DATA_CAL (cal), InvalidArg);
+	/* cancellable may be NULL */
+	e_return_data_cal_error_if_fail (uid != NULL, InvalidArg);
+	/* rid may be NULL */
+	e_return_data_cal_error_if_fail (old_component != NULL && *old_component == NULL, InvalidArg);
+	e_return_data_cal_error_if_fail (new_component != NULL && *new_component == NULL, InvalidArg);
+
+	self = E_CAL_BACKEND_KOLAB (backend);
+	priv = E_CAL_BACKEND_KOLAB_PRIVATE (self);
 
-	g_assert (E_IS_DATA_CAL (cal));
-	(void)cancellable; /* FIXME */ /* cancellable may be NULL */
-	(void)uid; /* FIXME */
-	(void)rid; /* FIXME */ /* may be NULL? */
-	(void)mod; /* FIXME */
-	g_return_if_fail (old_component == NULL || *old_component == NULL); /* FIXME */
-	g_return_if_fail (new_component == NULL || *new_component == NULL); /* FIXME */
-	g_return_if_fail (err == NULL || *err == NULL);
-
-	(void)self;
-	(void)priv;
 	g_error ("%s: FIXME implement me", __func__);
 
 #if 0 /* FIXME old */
@@ -1093,18 +1141,20 @@ e_cal_backend_kolab_receive_objects (ECalBackendSync *backend,
                                      EDataCal *cal,
                                      GCancellable *cancellable,
                                      const gchar *calobj,
-                                     GError **err)
+                                     GError **error)
 {
-	ECalBackendKolab *self = E_CAL_BACKEND_KOLAB (backend);
-	ECalBackendKolabPrivate *priv = E_CAL_BACKEND_KOLAB_PRIVATE (self);
+	ECalBackendKolab *self = NULL;
+	ECalBackendKolabPrivate *priv = NULL;
 
-	g_assert (E_IS_DATA_CAL (cal));
-	(void)cancellable; /* FIXME */ /* cancellable may be NULL */
-	(void)calobj; /* FIXME */
-	g_return_if_fail (err == NULL || *err == NULL);
+	g_return_if_fail (error == NULL || *error == NULL);
+	e_return_data_cal_error_if_fail (E_IS_CAL_BACKEND_KOLAB (backend), InvalidArg);
+	e_return_data_cal_error_if_fail (E_IS_DATA_CAL (cal), InvalidArg);
+	/* cancellable may be NULL */
+	e_return_data_cal_error_if_fail (calobj != NULL, InvalidArg);
+
+	self = E_CAL_BACKEND_KOLAB (backend);
+	priv = E_CAL_BACKEND_KOLAB_PRIVATE (self);
 
-	(void)self;
-	(void)priv;
 	g_error ("%s: FIXME implement me", __func__);
 
 #if 0 /* FIXME old */
@@ -1187,20 +1237,22 @@ e_cal_backend_kolab_send_objects (ECalBackendSync *backend,
                                   const gchar *calobj,
                                   GSList **users,
                                   gchar **modified_calobj,
-                                  GError **err)
+                                  GError **error)
 {
-	ECalBackendKolab *self = E_CAL_BACKEND_KOLAB (backend);
-	ECalBackendKolabPrivate *priv = E_CAL_BACKEND_KOLAB_PRIVATE (self);
+	ECalBackendKolab *self = NULL;
+	ECalBackendKolabPrivate *priv = NULL;
+
+	g_return_if_fail (error == NULL || *error == NULL);
+	e_return_data_cal_error_if_fail (E_IS_CAL_BACKEND_KOLAB (backend), InvalidArg);
+	e_return_data_cal_error_if_fail (E_IS_DATA_CAL (cal), InvalidArg);
+	/* cancellable may be NULL */
+	e_return_data_cal_error_if_fail (calobj != NULL, InvalidArg);
+	e_return_data_cal_error_if_fail (users != NULL && *users == NULL, InvalidArg);
+	e_return_data_cal_error_if_fail (modified_calobj != NULL && *modified_calobj == NULL, InvalidArg);
 
-	g_assert (E_IS_DATA_CAL (cal));
-	(void)cancellable; /* FIXME */ /* cancellable may be NULL */
-	(void)calobj; /* FIXME */
-	(void)users; /* FIXME */ /* may be NULL? */
-	(void)modified_calobj; /* FIXME */ /* must be NULL? */
-	g_return_if_fail (err == NULL || *err == NULL);
+	self = E_CAL_BACKEND_KOLAB (backend);
+	priv = E_CAL_BACKEND_KOLAB_PRIVATE (self);
 
-	(void)self;
-	(void)priv;
 	g_error ("%s: FIXME implement me", __func__);
 
 #if 0 /* FIXME old */
@@ -1221,20 +1273,22 @@ e_cal_backend_kolab_get_attachment_uris (ECalBackendSync *backend,
                                          const gchar *uid,
                                          const gchar *rid,
                                          GSList **attachments,
-                                         GError **err)
+                                         GError **error)
 {
-	ECalBackendKolab *self = E_CAL_BACKEND_KOLAB (backend);
-	ECalBackendKolabPrivate *priv = E_CAL_BACKEND_KOLAB_PRIVATE (self);
+	ECalBackendKolab *self = NULL;
+	ECalBackendKolabPrivate *priv = NULL;
+
+	g_return_if_fail (error == NULL || *error == NULL);
+	e_return_data_cal_error_if_fail (E_IS_CAL_BACKEND_KOLAB (backend), InvalidArg);
+	e_return_data_cal_error_if_fail (E_IS_DATA_CAL (cal), InvalidArg);
+	/* cancellable may be NULL */
+	e_return_data_cal_error_if_fail (uid != NULL, InvalidArg);
+	e_return_data_cal_error_if_fail (rid != NULL, InvalidArg);
+	e_return_data_cal_error_if_fail (attachments != NULL && *attachments == NULL, InvalidArg);
 
-	g_assert (E_IS_DATA_CAL (cal));
-	(void)cancellable; /* FIXME */ /* cancellable may be NULL */
-	g_assert (uid != NULL);
-	(void)rid; /* FIXME */ /* may be NULL? */
-	(void)attachments; /* FIXME */ /* must be NULL? */
-	g_return_if_fail (err == NULL || *err == NULL);
+	self = E_CAL_BACKEND_KOLAB (backend);
+	priv = E_CAL_BACKEND_KOLAB_PRIVATE (self);
 
-	(void)self;
-	(void)priv;
 	g_error ("%s: FIXME implement me", __func__);
 }
 
@@ -1245,20 +1299,22 @@ e_cal_backend_kolab_discard_alarm (ECalBackendSync *backend,
                                    const gchar *uid,
                                    const gchar *rid,
                                    const gchar *auid,
-                                   GError **err)
+                                   GError **error)
 {
-	ECalBackendKolab *self = E_CAL_BACKEND_KOLAB (backend);
-	ECalBackendKolabPrivate *priv = E_CAL_BACKEND_KOLAB_PRIVATE (self);
+	ECalBackendKolab *self = NULL;
+	ECalBackendKolabPrivate *priv = NULL;
 
-	g_assert (E_IS_DATA_CAL (cal));
-	(void)cancellable; /* FIXME */ /* cancellable may be NULL */
-	g_assert (uid != NULL);
-	(void)rid; /* FIXME */ /* may be NULL? */
-	(void)auid; /* FIXME */ /* may be NULL? */
-	g_return_if_fail (err == NULL || *err == NULL);
+	g_return_if_fail (error == NULL || *error == NULL);
+	e_return_data_cal_error_if_fail (E_IS_CAL_BACKEND_KOLAB (backend), InvalidArg);
+	e_return_data_cal_error_if_fail (E_IS_DATA_CAL (cal), InvalidArg);
+	/* cancellable may be NULL */
+	e_return_data_cal_error_if_fail (uid != NULL, InvalidArg);
+	e_return_data_cal_error_if_fail (rid != NULL, InvalidArg);
+	e_return_data_cal_error_if_fail (auid != NULL, InvalidArg);
+
+	self = E_CAL_BACKEND_KOLAB (backend);
+	priv = E_CAL_BACKEND_KOLAB_PRIVATE (self);
 
-	(void)self;
-	(void)priv;
 	g_error ("%s: FIXME implement me", __func__);
 }
 
@@ -1268,19 +1324,21 @@ e_cal_backend_kolab_get_timezone (ECalBackendSync *backend,
                                   GCancellable *cancellable,
                                   const gchar *tzid,
                                   gchar **tzobject,
-                                  GError **err)
+                                  GError **error)
 {
-	ECalBackendKolab *self = E_CAL_BACKEND_KOLAB (backend);
-	ECalBackendKolabPrivate *priv = E_CAL_BACKEND_KOLAB_PRIVATE (self);
+	ECalBackendKolab *self = NULL;
+	ECalBackendKolabPrivate *priv = NULL;
+
+	g_return_if_fail (error == NULL || *error == NULL);
+	e_return_data_cal_error_if_fail (E_IS_CAL_BACKEND_KOLAB (backend), InvalidArg);
+	e_return_data_cal_error_if_fail (E_IS_DATA_CAL (cal), InvalidArg);
+	/* cancellable may be NULL */
+	e_return_data_cal_error_if_fail (tzid != NULL, InvalidArg);
+	e_return_data_cal_error_if_fail (tzobject != NULL && *tzobject == NULL, InvalidArg);
 
-	g_assert (E_IS_DATA_CAL (cal));
-	(void)cancellable; /* FIXME */ /* cancellable may be NULL */
-	g_assert (tzid != NULL);
-	(void)tzobject; /* FIXME */ /* must be NULL? */
-	g_return_if_fail (err == NULL || *err == NULL);
+	self = E_CAL_BACKEND_KOLAB (backend);
+	priv = E_CAL_BACKEND_KOLAB_PRIVATE (self);
 
-	(void)self;
-	(void)priv;
 	g_error ("%s: FIXME implement me", __func__);
 }
 
@@ -1299,18 +1357,20 @@ e_cal_backend_kolab_add_timezone (ECalBackendSync *backend,
                                   EDataCal *cal,
                                   GCancellable *cancellable,
                                   const gchar *tzobject,
-                                  GError **err)
+                                  GError **error)
 {
-	ECalBackendKolab *self = E_CAL_BACKEND_KOLAB (backend);
-	ECalBackendKolabPrivate *priv = E_CAL_BACKEND_KOLAB_PRIVATE (self);
+	ECalBackendKolab *self = NULL;
+	ECalBackendKolabPrivate *priv = NULL;
+
+	g_return_if_fail (error == NULL || *error == NULL);
+	e_return_data_cal_error_if_fail (E_IS_CAL_BACKEND_KOLAB (backend), InvalidArg);
+	e_return_data_cal_error_if_fail (E_IS_DATA_CAL (cal), InvalidArg);
+	/* cancellable may be NULL */
+	e_return_data_cal_error_if_fail (tzobject != NULL, InvalidArg);
 
-	g_assert (E_IS_DATA_CAL (cal));
-	(void)cancellable; /* FIXME */ /* cancellable may be NULL */
-	g_assert (tzobject != NULL);
-	g_return_if_fail (err == NULL || *err == NULL);
+	self = E_CAL_BACKEND_KOLAB (backend);
+	priv = E_CAL_BACKEND_KOLAB_PRIVATE (self);
 
-	(void)self;
-	(void)priv;
 	g_error ("%s: FIXME implement me", __func__);
 
 #if 0 /* FIXME old */
@@ -1342,17 +1402,19 @@ static void
 e_cal_backend_kolab_authenticate_user (ECalBackendSync *backend,
                                        GCancellable *cancellable,
                                        ECredentials *credentials,
-                                       GError **err)
+                                       GError **error)
 {
-	ECalBackendKolab *self = E_CAL_BACKEND_KOLAB (backend);
-	ECalBackendKolabPrivate *priv = E_CAL_BACKEND_KOLAB_PRIVATE (self);
+	ECalBackendKolab *self = NULL;
+	ECalBackendKolabPrivate *priv = NULL;
 
-	(void)cancellable; /* FIXME */ /* cancellable may be NULL */
-	g_assert (credentials != NULL);
-	g_return_if_fail (err == NULL || *err == NULL);
+	g_return_if_fail (error == NULL || *error == NULL);
+	e_return_data_cal_error_if_fail (E_IS_CAL_BACKEND_KOLAB (backend), InvalidArg);
+	/* cancellable may be NULL */
+	e_return_data_cal_error_if_fail (credentials != NULL, InvalidArg);
+
+	self = E_CAL_BACKEND_KOLAB (backend);
+	priv = E_CAL_BACKEND_KOLAB_PRIVATE (self);
 
-	(void)self;
-	(void)priv;
 	g_error ("%s: FIXME implement me", __func__);
 }
 
@@ -1367,13 +1429,15 @@ static void
 e_cal_backend_kolab_start_view (ECalBackend *backend,
                                 EDataCalView *view)
 {
-	ECalBackendKolab *self = E_CAL_BACKEND_KOLAB (backend);
-	ECalBackendKolabPrivate *priv = E_CAL_BACKEND_KOLAB_PRIVATE (self);
+	ECalBackendKolab *self = NULL;
+	ECalBackendKolabPrivate *priv = NULL;
 
-	g_assert (E_IS_DATA_CAL_VIEW (view));
+	g_return_if_fail (E_IS_CAL_BACKEND_KOLAB (backend));
+	g_return_if_fail (E_IS_DATA_CAL_VIEW (view));
+
+	self = E_CAL_BACKEND_KOLAB (backend);
+	priv = E_CAL_BACKEND_KOLAB_PRIVATE (self);
 
-	(void)self;
-	(void)priv;
 	g_error ("%s: FIXME implement me", __func__);
 
 #if 0 /* FIXME old */
@@ -1437,24 +1501,29 @@ static void
 e_cal_backend_kolab_stop_view (ECalBackend *backend,
                                EDataCalView *view)
 {
-	ECalBackendKolab *self = E_CAL_BACKEND_KOLAB (backend);
-	ECalBackendKolabPrivate *priv = E_CAL_BACKEND_KOLAB_PRIVATE (self);
+	ECalBackendKolab *self = NULL;
+	ECalBackendKolabPrivate *priv = NULL;
+
+	g_return_if_fail (E_IS_CAL_BACKEND_KOLAB (backend));
+	g_return_if_fail (E_IS_DATA_CAL_VIEW (view));
 
-	g_assert (E_IS_DATA_CAL_VIEW (view));
+	self = E_CAL_BACKEND_KOLAB (backend);
+	priv = E_CAL_BACKEND_KOLAB_PRIVATE (self);
 
-	(void)self;
-	(void)priv;
 	g_error ("%s: FIXME implement me", __func__);
 }
 
 static void
 e_cal_backend_kolab_last_client_gone (ECalBackend *backend)
 {
-	ECalBackendKolab *self = E_CAL_BACKEND_KOLAB (backend);
-	ECalBackendKolabPrivate *priv = E_CAL_BACKEND_KOLAB_PRIVATE (self);
+	ECalBackendKolab *self = NULL;
+	ECalBackendKolabPrivate *priv = NULL;
+
+	g_return_if_fail (E_IS_CAL_BACKEND_KOLAB (backend));
+
+	self = E_CAL_BACKEND_KOLAB (backend);
+	priv = E_CAL_BACKEND_KOLAB_PRIVATE (self);
 
-	(void)self;
-	(void)priv;
 	g_error ("%s: FIXME implement me", __func__);
 }
 
@@ -1469,7 +1538,13 @@ e_cal_backend_kolab_init (ECalBackendKolab *backend)
 
 	g_debug ("%s()[%u] called.", __func__, __LINE__);
 
-	priv->koma_table = NULL;
+	if (koma_objects == NULL)
+		koma_objects = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, NULL);
+	else
+		g_hash_table_ref (koma_objects);
+
+	priv->koma_table = koma_objects;
+
 	priv->cal_mode = 0;
 	priv->cal_koma = NULL;
 	priv->cal_cache = NULL;
@@ -1488,10 +1563,12 @@ e_cal_backend_kolab_dispose (GObject *object)
 
 	g_debug ("%s()[%u] called.", __func__, __LINE__);
 
-	if (priv->already_opened != FALSE) {
+	if (priv->already_opened) {
 		priv->already_opened = FALSE;
 		g_object_unref (priv->cal_koma);
 		priv->cal_koma = NULL;
+		g_hash_table_unref (koma_objects);
+		priv->koma_table = NULL;
 	}
 	if (priv->default_zone != NULL) {
 		g_object_unref (priv->default_zone);
@@ -1536,6 +1613,14 @@ e_cal_backend_kolab_class_init (ECalBackendKolabClass *klass)
 
 	g_type_class_add_private (klass, sizeof (ECalBackendKolabPrivate));
 
+	object_class->dispose = e_cal_backend_kolab_dispose;
+	object_class->finalize = e_cal_backend_kolab_finalize;
+
+	/* Backend parent class methods methods not covered in the sync backend part */
+	backend_class->start_view = e_cal_backend_kolab_start_view;
+	backend_class->stop_view = e_cal_backend_kolab_stop_view;
+	backend_class->last_client_gone = e_cal_backend_kolab_last_client_gone;
+
 	/* Sync backend class functions */
 	sync_class->open_sync = e_cal_backend_kolab_open;
 	sync_class->remove_sync = e_cal_backend_kolab_remove;
@@ -1556,14 +1641,6 @@ e_cal_backend_kolab_class_init (ECalBackendKolabClass *klass)
 	sync_class->add_timezone_sync = e_cal_backend_kolab_add_timezone;
 	sync_class->authenticate_user_sync = e_cal_backend_kolab_authenticate_user;
 
-	/* Backend parent class methods methods not covered in the sync backend part */
-	backend_class->start_view = e_cal_backend_kolab_start_view;
-	backend_class->stop_view = e_cal_backend_kolab_stop_view;
-	backend_class->last_client_gone = e_cal_backend_kolab_last_client_gone;
-
-	object_class->dispose = e_cal_backend_kolab_dispose;
-	object_class->finalize = e_cal_backend_kolab_finalize;
-
 } /* e_cal_backend_kolab_class_init () */
 
 
diff --git a/src/calendar/kolab-util-calendar.c b/src/calendar/kolab-util-calendar.c
index fb92946..54679b7 100644
--- a/src/calendar/kolab-util-calendar.c
+++ b/src/calendar/kolab-util-calendar.c
@@ -26,6 +26,7 @@
 /*----------------------------------------------------------------------------*/
 
 #include <libecal/e-cal.h>
+#include <libedata-cal/e-data-cal-types.h>
 
 #include <libekolabutil/camel-system-headers.h>
 #include <libekolab/kolab-settings-handler.h>
@@ -481,3 +482,68 @@ kolab_util_calendar_extract (icalcomponent *icalcomp,
 	return GNOME_Evolution_Calendar_Success;
 } /* kolab_util_calendar_extract () */
 #endif
+
+void
+kolab_util_calendar_err_to_edb_err (GError **e_err,
+                                    const GError *k_err,
+                                    const gchar *func,
+                                    guint line)
+{
+	EDataCalCallStatus status = OtherError;
+	GError *tmp_err = NULL;
+
+	g_return_if_fail (e_err == NULL || *e_err == NULL);
+	g_return_if_fail (k_err != NULL);
+
+	g_warning ("%s()[%u]: '%s', Code %i, Domain '%s'",
+	           func, line, k_err->message, k_err->code,
+	           g_quark_to_string (k_err->domain));
+
+	if (!e_err)
+		return;
+
+	if (g_error_matches (k_err, G_IO_ERROR, G_IO_ERROR_CANCELLED)) {
+		g_propagate_error (e_err, g_error_copy (k_err));
+		return;
+	}
+
+	/* TODO
+	 *
+	 * Need to implement a more elaborated error mapping here.
+	 * This function maps Kolab engine errors only. Errors can
+	 * originate from the camel/ as well as from the libekolab/
+	 * libs. These yield errors in various domains. The following
+	 * EDataCalCallStatus (other than OTHER_ERROR) are candidates
+	 * for being populated from certain k_err's:
+	 *
+	 * RepositoryOffline
+	 * PermissionDenied
+	 * InvalidRange
+	 * ObjectNotFound
+	 * InvalidObject
+	 * ObjectIdAlreadyExists
+	 * AuthenticationFailed
+	 * AuthenticationRequired
+	 * UnsupportedField
+	 * UnsupportedMethod
+	 * TLSNotAvailable
+	 * NoSuchCal
+	 * UnknownUser
+	 * SearchSizeLimitExceeded
+	 * InvalidQuery
+	 * QueryRefused
+	 * CouldNotCancel
+	 * InvalidServerVersion
+	 * NotSupported
+	 * NotOpened
+	 *
+	 * Depending on k_err->domain and k_err->code, we can map
+	 * to a fitting EDataCalCallStatus. More than one combination
+	 * of k_err->domain and k_err->code may map to one specific
+	 * EDataCalCallStatus.
+	 */
+
+	tmp_err = e_data_cal_create_error (status,
+	                                   k_err->message);
+	g_propagate_error (e_err, tmp_err);
+}
diff --git a/src/calendar/kolab-util-calendar.h b/src/calendar/kolab-util-calendar.h
index 803610e..fd7ec99 100644
--- a/src/calendar/kolab-util-calendar.h
+++ b/src/calendar/kolab-util-calendar.h
@@ -85,6 +85,12 @@ kolab_util_calendar_extract (icalcomponent *icalcomp,
 ECalBackendSyncStatus kolab_util_calendar_map_error (GError *error);
 #endif
 
+void
+kolab_util_calendar_err_to_edb_err (GError **e_err,
+                                    const GError *k_err,
+                                    const gchar *func,
+                                    guint line);
+
 /*----------------------------------------------------------------------------*/
 
 #endif /* _KOLAB_UTIL_CALENDAR_H_ */



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