[evolution-kolab/ek-wip-xfb: 2/8] ECalBackendKolab: XFB getter password/error fixup



commit 62010c4b1d6237be5acb758ade376e8433325468
Author: Christian Hilberg <hilberg kernelconcepts de>
Date:   Mon Oct 22 19:40:59 2012 +0200

    ECalBackendKolab: XFB getter password/error fixup
    
    * fixed password handling for the XFB getter
      (we temporarily make the account password visible
      via KolabSettingsHandler)
    * fixed error handling within the getter function

 src/calendar/e-cal-backend-kolab.c |   88 +++++++++++++++++++++---------------
 1 files changed, 52 insertions(+), 36 deletions(-)
---
diff --git a/src/calendar/e-cal-backend-kolab.c b/src/calendar/e-cal-backend-kolab.c
index 9aa28c7..c4bc041 100644
--- a/src/calendar/e-cal-backend-kolab.c
+++ b/src/calendar/e-cal-backend-kolab.c
@@ -714,7 +714,7 @@ cal_backend_kolab_get_free_busy (ECalBackendSync *backend,
 	ECalBackendKolabPrivate *priv = NULL;
 	KolabSettingsHandler *ksettings = NULL;
 	GSList *it = NULL;
-	gboolean internal_state = TRUE;
+	gboolean have_objects = FALSE;
 	GError *tmp_err = NULL;
 
 	g_return_if_fail (error == NULL || *error == NULL);
@@ -733,54 +733,70 @@ cal_backend_kolab_get_free_busy (ECalBackendSync *backend,
 	if (ksettings == NULL) {
 		/* TODO add a translatable string as custom message */
 		tmp_err = e_data_cal_create_error (OtherError, NULL);
+		goto exit;
 	}
 
+	/* If we went through authentication already, we can make the
+	 * password visible via ksettings so it can be used in
+	 * KolabUtilHttpJob. If we're not authenticated, we're most
+	 * probably offline, in which case we cannot fetch XFB anyway
+	 */
+	kolab_mail_access_password_set_visible (priv->cal_koma, TRUE);
+
 	/* receive the xfb information */
 	for (it = (GSList *) users; it != NULL; it = g_slist_next (it)) {
 		KolabUtilHttpJob *job = NULL;
 		ECalComponent *ecalcomp = NULL;
 
+		/* TODO Can we sensibly propagate an error
+		 *      here? Failure for one does not
+		 *      necessarily imply failure for all
+		 */
+
 		job = kolab_util_calendar_retrieve_xfb (ksettings, (gchar *) it->data, &tmp_err);
-		if (job != NULL) {
-			ecalcomp = kolabconv_cal_util_freebusy_ecalcomp_new_from_ics ((gchar *) (job->buffer->data),
-			                                                              job->nbytes,
-			                                                              &tmp_err);
-			kolab_util_http_job_free (job);
-		}
-		if (tmp_err != NULL) {
-			/* TODO Can we sensibly propagate an error
-			 *      here? Failure for one does not
-			 *      necessarily imply failure for all
-			 */
-			g_warning ("%s()[%u] %s", __func__, __LINE__, tmp_err->message);
-			g_error_free (tmp_err);
-			tmp_err = NULL;
-			internal_state = FALSE;
-		}
+		if (tmp_err != NULL)
+			goto skip_warn;
+
+		ecalcomp = kolabconv_cal_util_freebusy_ecalcomp_new_from_ics ((gchar *) (job->buffer->data),
+		                                                              job->nbytes,
+		                                                              &tmp_err);
+		kolab_util_http_job_free (job);
+
+		if (tmp_err != NULL)
+			goto skip_warn;
 
-		if (ecalcomp == NULL) {
+		if (ecalcomp == NULL)
 			/* this is not an error, but there's no F/B
 			 * information available.
 			 */
-			g_object_unref (ksettings);
-			tmp_err = e_data_cal_create_error (ObjectNotFound, NULL);
-			g_propagate_error (error, tmp_err);
-			return;
-		}
-		else {
-			*freebusyobjs = g_slist_append (*freebusyobjs,
-			                                g_strdup (e_cal_component_get_as_string (ecalcomp)));
-			g_object_unref (ecalcomp);
-		}
+			continue;
+
+		*freebusyobjs = g_slist_append (*freebusyobjs,
+		                                g_strdup (e_cal_component_get_as_string (ecalcomp)));
+		g_object_unref (ecalcomp);
+		have_objects = TRUE;
+
+		continue;
+
+	skip_warn:
+		g_warning ("%s()[%u] %s", __func__, __LINE__, tmp_err->message);
+		g_error_free (tmp_err);
+		tmp_err = NULL;
 	}
-	g_object_unref (ksettings);
-	if (! internal_state) {
-		/* TODO add a translatable string as custom message here,
-		 *      could use a saved tmp_err->message (e.g. latest)
-		 */
-		tmp_err = e_data_cal_create_error (OtherError, NULL);
+
+ exit:
+
+	/* hide the password again */
+	kolab_mail_access_password_set_visible (priv->cal_koma, FALSE);
+
+	if (ksettings != NULL)
+		g_object_unref (ksettings);
+
+	if (! have_objects)
+		tmp_err = e_data_cal_create_error (ObjectNotFound, NULL);
+
+	if (tmp_err != NULL)
 		g_propagate_error (error, tmp_err);
-	}
 }
 
 /**
@@ -1308,7 +1324,7 @@ cal_backend_kolab_remove_objects (ECalBackendSync *backend,
 		oc_data = (*old_components)->data;
 	if (*new_components != NULL)
 		nc_data = (*new_components)->data;
-	
+
 	e_cal_backend_notify_component_removed (E_CAL_BACKEND (backend),
 	                                        id,
 	                                        oc_data,



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