[evolution-kolab/ek-wip-porting] ECalBackendKolab: improved handling of online state switching



commit 7795972512e9d32ba510888464dfbde205601991
Author: Christian Hilberg <hilberg kernelconcepts de>
Date:   Tue Mar 20 15:23:12 2012 +0100

    ECalBackendKolab: improved handling of online state switching
    
    * force authentication if password is missing
    * kolab_util_backend_deploy_mode_by_backend()
      may return FALSE with no GError set
    * removed local already_opened flag (we've got
      enough of these around already)

 src/calendar/e-cal-backend-kolab.c |   82 +++++++++++++++++++-----------------
 1 files changed, 43 insertions(+), 39 deletions(-)
---
diff --git a/src/calendar/e-cal-backend-kolab.c b/src/calendar/e-cal-backend-kolab.c
index 1ab0de9..85d5056 100644
--- a/src/calendar/e-cal-backend-kolab.c
+++ b/src/calendar/e-cal-backend-kolab.c
@@ -62,6 +62,13 @@ e_cal_backend_kolab_add_timezone (ECalBackendSync *backend,
                                   const gchar *tzobject,
                                   GError **error);
 
+static void
+e_cal_backend_kolab_open (ECalBackendSync *backend,
+                          EDataCal *cal,
+                          GCancellable *cancellable,
+                          gboolean only_if_exists,
+                          GError **error);
+
 /*----------------------------------------------------------------------------*/
 
 #define E_CAL_BACKEND_KOLAB_PRIVATE(o)  (G_TYPE_INSTANCE_GET_PRIVATE ((o), E_TYPE_CAL_BACKEND_KOLAB, ECalBackendKolabPrivate))
@@ -89,7 +96,6 @@ struct _ECalBackendKolabPrivate {
 	gchar *user_email;
 	ECalComponent *default_zone;
 	ECalSourceType source_type;
-	gboolean already_opened;
 	gchar *cal_uri;
 	GError *mode_switch_err;
 };
@@ -150,19 +156,18 @@ cal_backend_kolab_signal_online_cb (GObject *object)
 	 *
 	 */
 
-	if (priv->mode_switch_err != NULL) {
-		g_warning ("%s()[%u]: Online mode switching error pending (%s)",
-		           __func__, __LINE__, priv->mode_switch_err->message);
-		g_error_free (priv->mode_switch_err);
-		priv->mode_switch_err = NULL;
-	}
 	(void) kolab_util_backend_deploy_mode_by_backend (priv->cal_koma,
 	                                                  online,
-	                                                  NULL, /* GCancellable (see above )*/
+	                                                  NULL, /* GCancellable (see above ) */
 	                                                  &(priv->mode_switch_err));
 	if (priv->mode_switch_err) {
-		g_warning ("%s()[%u]: Online mode switching error pending (%s)",
-		           __func__, __LINE__, priv->mode_switch_err->message);
+		g_warning ("%s()[%u]: Online mode switching error pending, (%s), Domain %s Code %i",
+		           __func__, __LINE__,
+		           priv->mode_switch_err->message,
+		           g_quark_to_string (priv->mode_switch_err->domain),
+		           priv->mode_switch_err->code);
+		g_error_free (priv->mode_switch_err);
+		priv->mode_switch_err = NULL;
 	}
 }
 
@@ -187,7 +192,7 @@ cal_backend_kolab_notify_opened (ECalBackendKolab *self,
 		return FALSE;
 	}
 	e_cal_backend_notify_online (cbackend,
-	                             tmp_mode = KOLAB_MAIL_ACCESS_OPMODE_ONLINE ? TRUE : FALSE);
+	                             tmp_mode == KOLAB_MAIL_ACCESS_OPMODE_ONLINE ? TRUE : FALSE);
 	e_cal_backend_notify_readonly (cbackend, FALSE);
 	e_cal_backend_notify_opened (cbackend, NULL);
 
@@ -261,9 +266,6 @@ e_cal_backend_kolab_open (ECalBackendSync *backend,
 	 * <property name="username" value="..."/>
 	 */
 
-	if (priv->already_opened == TRUE)
-		return;
-
 	icalkind = e_cal_backend_get_kind (E_CAL_BACKEND (backend));
 	/* TODO: this has to be set according to the get_kind() method */
 	switch (icalkind) {
@@ -344,6 +346,8 @@ e_cal_backend_kolab_open (ECalBackendSync *backend,
 	                                   (gpointer *) &tmp_key,
 	                                   (gpointer *) &tmp_koma);
 	if (ok) {
+		gchar *passwd = NULL;
+
 		/* There already is a KoMA instance for user_at_server.
 		 * Use it and return
 		 */
@@ -360,19 +364,25 @@ e_cal_backend_kolab_open (ECalBackendSync *backend,
 		                                     NULL,
 		                                     sourcename,
 		                                     &sync_value);
-		g_object_unref (ksettings);
-		/* We should have received authentication data (password)
-		 * at this point, since it was requested and stored when
-		 * the KolabMailAccess object was initially created.
-		 * We can just skip the AuthenticationRequested part here
-		 * and move along...
+		/* We may find that we do not yet have a password set.
+		 * In case we're requested to go online, we will need
+		 * one, so we need to get authentication data first.
 		 */
-		online = e_backend_get_online (E_BACKEND (backend));
-		ok = kolab_util_backend_deploy_mode_by_backend (priv->cal_koma,
-		                                                online,
-		                                                cancellable,
-		                                                &tmp_err);
-		if (! ok) {
+		passwd = g_strdup (kolab_settings_handler_get_char_field (ksettings,
+		                                                          KOLAB_SETTINGS_HANDLER_CHAR_FIELD_KOLAB_USER_PASSWORD,
+		                                                          NULL));
+		g_object_unref (ksettings);
+		if (passwd == NULL) {
+			e_cal_backend_notify_auth_required (E_CAL_BACKEND (self), TRUE, NULL);
+			return;
+		}
+		g_free (passwd);
+
+		(void) kolab_util_backend_deploy_mode_by_backend (priv->cal_koma,
+		                                                  online,
+		                                                  cancellable,
+		                                                  &tmp_err);
+		if (tmp_err != NULL) {
 			kolab_util_calendar_err_to_edb_err (error, tmp_err, __func__, __LINE__);
 			g_error_free (tmp_err);
 			return;
@@ -466,7 +476,6 @@ e_cal_backend_kolab_open (ECalBackendSync *backend,
 	 * it once the book gets opened.
 	 */
 	e_cal_backend_notify_auth_required (E_CAL_BACKEND (self), TRUE, NULL);
-	priv->already_opened = TRUE;
 }
 
 static void
@@ -489,11 +498,10 @@ e_cal_backend_kolab_remove (ECalBackendSync *backend,
 	g_warning ("%s: FIXME implement me", __func__);
 
 #if 0 /* FIXME old */
-	if (priv->already_opened != FALSE) {
+	if (priv->cal_koma != NULL) {
 		g_object_unref (priv->cal_koma);
 		priv->cal_koma = NULL;
 	}
-	priv->already_opened = FALSE;
 
 	/* Remove backend cache */
 	if (priv->cal_cache != NULL) {
@@ -1699,11 +1707,11 @@ e_cal_backend_kolab_authenticate_user (ECalBackendSync *backend,
 	g_object_unref (ksettings);
 
 	online = e_backend_get_online (E_BACKEND (backend));
-	ok = kolab_util_backend_deploy_mode_by_backend (priv->cal_koma,
-	                                                online,
-	                                                cancellable,
-	                                                &tmp_err);
-	if (! ok) {
+	(void) kolab_util_backend_deploy_mode_by_backend (priv->cal_koma,
+	                                                  online,
+	                                                  cancellable,
+	                                                  &tmp_err);
+	if (tmp_err != NULL) {
 		kolab_util_calendar_err_to_edb_err (error, tmp_err, __func__, __LINE__);
 		g_error_free (tmp_err);
 		return;
@@ -1894,7 +1902,6 @@ e_cal_backend_kolab_init (ECalBackendKolab *backend)
 	priv->user_email = NULL;
 	priv->default_zone = NULL;
 	priv->source_type = 0;
-	priv->already_opened = FALSE;
 	priv->cal_uri = NULL;
 	priv->mode_switch_err = NULL;
 	priv->active_cal_views = g_hash_table_new_full (g_direct_hash,
@@ -1913,9 +1920,7 @@ e_cal_backend_kolab_dispose (GObject *object)
 
 	g_debug ("%s()[%u] called.", __func__, __LINE__);
 
-	if (priv->already_opened) {
-		priv->already_opened = FALSE;
-		g_warning ("%s()[%u] FIXME KolabMailAccess (table) disposal", __func__, __LINE__);
+	g_warning ("%s()[%u] FIXME KolabMailAccess (table) disposal", __func__, __LINE__);
 #if 0 /* FIXME (check g_object_toggle_ref cleanup callback) */
 		if (priv->cal_koma != NULL) {
 			g_object_unref (priv->cal_koma);
@@ -1926,7 +1931,6 @@ e_cal_backend_kolab_dispose (GObject *object)
 			priv->koma_table = NULL;
 		}
 #endif
-	}
 	if (priv->default_zone != NULL) {
 		g_object_unref (priv->default_zone);
 		priv->default_zone = NULL;



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