[evolution-exchange] Bug #664572 - Change e_cal_backend_notify_component* to use ECalComponent



commit 3224821db207240422ccaec4aa58449213186842
Author: Milan Crha <mcrha redhat com>
Date:   Thu Nov 24 12:08:27 2011 +0100

    Bug #664572 - Change e_cal_backend_notify_component* to use ECalComponent

 calendar/e-cal-backend-exchange-calendar.c |  149 +++++++++++++++-------------
 calendar/e-cal-backend-exchange-tasks.c    |   58 ++++++-----
 calendar/e-cal-backend-exchange.c          |   99 ++++++++++--------
 3 files changed, 163 insertions(+), 143 deletions(-)
---
diff --git a/calendar/e-cal-backend-exchange-calendar.c b/calendar/e-cal-backend-exchange-calendar.c
index 22b80c7..6792172 100644
--- a/calendar/e-cal-backend-exchange-calendar.c
+++ b/calendar/e-cal-backend-exchange-calendar.c
@@ -54,7 +54,7 @@ enum {
 
 #define d(x)
 
-static gboolean modify_object_with_href (ECalBackendSync *backend, EDataCal *cal, GCancellable *cancellable, const gchar *calobj, CalObjModType mod, icalcomponent **old_icalcomp, icalcomponent **new_icalcomp, const gchar *href, const gchar *rid_to_remove, GError **error);
+static gboolean modify_object_with_href (ECalBackendSync *backend, EDataCal *cal, GCancellable *cancellable, const gchar *calobj, CalObjModType mod, ECalComponent **old_ecalcomp, ECalComponent **new_ecalcomp, const gchar *href, const gchar *rid_to_remove, GError **error);
 
 static icalproperty *find_attendee_prop (icalcomponent *ical_comp, const gchar *address);
 static gboolean check_owner_partstatus_for_declined (ECalBackendSync *backend,
@@ -253,10 +253,16 @@ add_ical (ECalBackendExchange *cbex,
 		status = add_vevent (cbex, href, lastmod, icalcomp);
 
 		if (status) {
-			e_cal_backend_notify_component_created (backend, icalcomp);
+			ecomp = e_cal_component_new_from_icalcomponent (icalcomp);
+			icalcomp = NULL;
+			if (ecomp) {
+				e_cal_backend_notify_component_created (backend, ecomp);
+				g_object_unref (ecomp);
+			}
 		}
 
-		icalcomponent_free (icalcomp);
+		if (icalcomp)
+			icalcomponent_free (icalcomp);
 		return status;
 	} else if (kind != ICAL_VCALENDAR_COMPONENT) {
 		retval = FALSE;
@@ -294,10 +300,16 @@ add_ical (ECalBackendExchange *cbex,
 			status = add_vevent (cbex, href, lastmod, new_comp);
 
 			if (status) {
-				e_cal_backend_notify_component_created (backend, new_comp);
+				ecomp = e_cal_component_new_from_icalcomponent (new_comp);
+				new_comp = NULL;
+				if (ecomp) {
+					e_cal_backend_notify_component_created (backend, ecomp);
+					g_object_unref (ecomp);
+				}
 			}
 
-			icalcomponent_free (new_comp);
+			if (new_comp)
+				icalcomponent_free (new_comp);
 		}
 		subcomp = icalcomponent_get_next_component (
 				icalcomp, ICAL_VEVENT_COMPONENT);
@@ -766,7 +778,7 @@ create_object (ECalBackendSync *backend,
                GCancellable *cancellable,
                const gchar *calobj,
                gchar **uid,
-               icalcomponent **new_icalcomp,
+               ECalComponent **new_ecalcomp,
                GError **error)
 {
 	/* FIXME : Return some value in uid */
@@ -908,15 +920,15 @@ create_object (ECalBackendSync *backend,
 	/* add the timezones information and the component itself
 	 * to the VCALENDAR object */
 	e_cal_component_commit_sequence (comp);
-	*new_icalcomp = icalcomponent_new_clone (e_cal_component_get_icalcomponent (comp));
-	if (!*new_icalcomp) {
+	*new_ecalcomp = e_cal_component_clone (comp);
+	if (!*new_ecalcomp) {
 		g_object_unref (comp);
 		icalcomponent_free (cbdata->vcal_comp);
 		g_free (cbdata);
 		g_propagate_error (error, EDC_ERROR_EX (OtherError, "Cannot get comp as string"));
 		return;
 	}
-	real_icalcomp = icalcomponent_new_clone (*new_icalcomp);
+	real_icalcomp = icalcomponent_new_clone (e_cal_component_get_icalcomponent (*new_ecalcomp));
 
 	icalcomponent_foreach_tzid (real_icalcomp, add_timezone_cb, cbdata);
 	icalcomponent_add_component (cbdata->vcal_comp, real_icalcomp);
@@ -1123,13 +1135,13 @@ modify_object (ECalBackendSync *backend,
                GCancellable *cancellable,
                const gchar *calobj,
                CalObjModType mod,
-               icalcomponent **old_icalcomp,
-               icalcomponent **new_icalcomp,
+               ECalComponent **old_ecalcomp,
+               ECalComponent **new_ecalcomp,
                GError **perror)
 {
 	d(printf ("ecbexc_modify_object(%p, %p, %d, %s)", backend, cal, mod, calobj));
 
-	modify_object_with_href (backend, cal, cancellable, calobj, mod, old_icalcomp, new_icalcomp, NULL, NULL, perror);
+	modify_object_with_href (backend, cal, cancellable, calobj, mod, old_ecalcomp, new_ecalcomp, NULL, NULL, perror);
 }
 
 #define e_return_data_cal_error_and_val_if_fail(expr, _code, _val)		\
@@ -1153,8 +1165,8 @@ modify_object_with_href (ECalBackendSync *backend,
                          GCancellable *cancellable,
                          const gchar *calobj,
                          CalObjModType mod,
-                         icalcomponent **old_icalcomp,
-                         icalcomponent **new_icalcomp,
+                         ECalComponent **old_ecalcomp,
+                         ECalComponent **new_ecalcomp,
                          const gchar *href,
                          const gchar *rid_to_remove,
                          GError **error)
@@ -1470,8 +1482,9 @@ modify_object_with_href (ECalBackendSync *backend,
 
 	e_cal_backend_exchange_cache_unlock (cbex);
 
-	if (!cached_ecomp && remove)
-		*new_icalcomp = icalcomponent_new_clone (icalcomp);
+	if (!cached_ecomp && remove) {
+		*new_ecalcomp = e_cal_component_new_from_icalcomponent (icalcomponent_new_clone (icalcomp));
+	}
 
 	body_crlf = icalcomponent_as_ical_string_r (cbdata->vcal_comp);
 
@@ -1526,7 +1539,7 @@ modify_object_with_href (ECalBackendSync *backend,
 
 	if (cached_ecomp) {
 		e_cal_component_commit_sequence (cached_ecomp);
-		*old_icalcomp = icalcomponent_new_clone (e_cal_component_get_icalcomponent (cached_ecomp));
+		*old_ecalcomp = e_cal_component_clone (cached_ecomp);
 	}
 
 	ctx = exchange_account_get_context (E_CAL_BACKEND_EXCHANGE (cbexc)->account);
@@ -1550,7 +1563,7 @@ modify_object_with_href (ECalBackendSync *backend,
 		e_cal_backend_exchange_cache_unlock (cbex);
 
 		if (!remove)
-			*new_icalcomp = icalcomponent_new_clone (e_cal_component_get_icalcomponent (real_ecomp));
+			*new_ecalcomp = e_cal_component_clone (real_ecomp);
 	} else {
 		g_propagate_error (error, EDC_ERROR_HTTP_STATUS (http_status));
 	}
@@ -1576,8 +1589,8 @@ remove_object (ECalBackendSync *backend,
                const gchar *uid,
                const gchar *rid,
                CalObjModType mod,
-               icalcomponent **old_icalcomp,
-               icalcomponent **new_icalcomp,
+               ECalComponent **old_ecalcomp,
+               ECalComponent **new_ecalcomp,
                GError **error)
 {
 	ECalBackendExchangeCalendar *cbexc;
@@ -1587,7 +1600,7 @@ remove_object (ECalBackendSync *backend,
 	E2kContext *ctx;
 	ECalComponent *comp;
 	gchar *calobj;
-	icalcomponent *obj_icalcomp = NULL;
+	ECalComponent *obj_ecalcomp = NULL;
 	struct icaltimetype time_rid;
 
 	/* Will handle only CALOBJ_MOD_THIS and CALOBJ_MOD_ALL for mod.
@@ -1615,14 +1628,14 @@ remove_object (ECalBackendSync *backend,
 
 	comp = e_cal_component_new ();
 	e_cal_component_set_icalcomponent (comp, icalcomponent_new_clone (ecomp->icomp));
-	if (old_icalcomp) {
+	if (old_ecalcomp) {
 		e_cal_component_commit_sequence (comp);
-		*old_icalcomp = icalcomponent_new_clone (e_cal_component_get_icalcomponent (comp));
+		*old_ecalcomp = e_cal_component_clone (comp);
 	}
 
 	/*TODO How handle multiple detached intances with no master object ?*/
 	if (mod == CALOBJ_MOD_THIS && rid && *rid && ecomp->icomp) {
-		icalcomponent *tmp_new_icalcomp = NULL;
+		ECalComponent *tmp_new_ecalcomp = NULL;
 		gboolean res;
 
 		/*remove a single instance of a recurring event and modify */
@@ -1631,20 +1644,20 @@ remove_object (ECalBackendSync *backend,
 		calobj  = (gchar *) icalcomponent_as_ical_string_r (ecomp->icomp);
 
 		e_cal_backend_exchange_cache_unlock (cbex);
-		res = modify_object_with_href (backend, cal, cancellable, calobj, mod, &obj_icalcomp, &tmp_new_icalcomp, NULL, rid, error);
-		if (tmp_new_icalcomp)
-			icalcomponent_free (tmp_new_icalcomp);
+		res = modify_object_with_href (backend, cal, cancellable, calobj, mod, &obj_ecalcomp, &tmp_new_ecalcomp, NULL, rid, error);
+		if (tmp_new_ecalcomp)
+			g_object_unref (tmp_new_ecalcomp);
 
 		g_object_unref (comp);
 		g_free (calobj);
 		if (!res)
 			return;
-		if (obj_icalcomp) {
-			if (old_icalcomp) {
-				icalcomponent_free (*old_icalcomp);
-				*old_icalcomp = obj_icalcomp;
+		if (obj_ecalcomp) {
+			if (old_ecalcomp) {
+				g_object_unref (*old_ecalcomp);
+				*old_ecalcomp = obj_ecalcomp;
 			} else {
-				icalcomponent_free (obj_icalcomp);
+				g_object_unref (obj_ecalcomp);
 			}
 		}
 
@@ -1665,7 +1678,7 @@ remove_object (ECalBackendSync *backend,
 		}
 		e_cal_backend_exchange_cache_unlock (cbex);
 	}
-	*new_icalcomp = NULL;
+	*new_ecalcomp = NULL;
 
 	g_propagate_error (error, EDC_ERROR_HTTP_STATUS (status));
 }
@@ -1724,7 +1737,7 @@ receive_objects (ECalBackendSync *backend,
 	for (l = comps; l; l= l->next) {
 		const gchar *uid;
 		gchar *icalobj, *rid = NULL;
-		icalcomponent *old_icalcomp = NULL, *new_icalcomp = NULL;
+		ECalComponent *old_ecalcomp = NULL, *new_ecalcomp = NULL;
 
 		subcomp = l->data;
 
@@ -1745,15 +1758,13 @@ receive_objects (ECalBackendSync *backend,
 		case ICAL_METHOD_REPLY:
 			e_cal_backend_exchange_cache_lock (cbex);
 			if ((ecomp = get_exchange_comp (E_CAL_BACKEND_EXCHANGE (cbexc), uid)) != NULL ) {
-				icalcomponent *old_icalcomp = NULL;
-
 				d(printf ("uid : %s : found in the cache\n", uid));
 
 				e_cal_backend_exchange_cache_unlock (cbex);
 				if (check_owner_partstatus_for_declined (backend, subcomp)) {
 					ECalComponentId *id = NULL;
 					remove_object (backend, cal, cancellable, uid, NULL,
-								CALOBJ_MOD_ALL, &old_icalcomp,
+								CALOBJ_MOD_ALL, &old_ecalcomp,
 								NULL, &err);
 					if (err) {
 						g_free (rid);
@@ -1762,10 +1773,9 @@ receive_objects (ECalBackendSync *backend,
 					}
 					id = e_cal_component_get_id (comp);
 					e_cal_backend_notify_component_removed (E_CAL_BACKEND (backend), id,
-									     old_icalcomp, NULL);
+									     old_ecalcomp, NULL);
 					e_cal_component_free_id (id);
 				} else {
-					icalcomponent *new_icalcomp = NULL;
 					CalObjModType mod = CALOBJ_MOD_ALL;
 					GSList *attachment_list;
 
@@ -1782,22 +1792,21 @@ receive_objects (ECalBackendSync *backend,
 					icalobj = e_cal_component_get_as_string (comp);
 					if (!modify_object_with_href (backend, cal, cancellable, icalobj,
 									  mod,
-									  &old_icalcomp, &new_icalcomp, NULL, NULL, error)) {
+									  &old_ecalcomp, &new_ecalcomp, NULL, NULL, error)) {
 						g_free (rid);
 						goto error;
 					}
-					e_cal_backend_notify_component_modified (E_CAL_BACKEND (backend), old_icalcomp, new_icalcomp);
-					if (new_icalcomp)
-						icalcomponent_free (new_icalcomp);
+					e_cal_backend_notify_component_modified (E_CAL_BACKEND (backend), old_ecalcomp, new_ecalcomp);
+					if (new_ecalcomp)
+						g_object_unref (new_ecalcomp);
 					d(printf ("Notify that the new object after modication is : %s\n", icalobj));
 					g_free (icalobj);
 				}
 
-				if (old_icalcomp)
-					icalcomponent_free (old_icalcomp);
+				if (old_ecalcomp)
+					g_object_unref (old_ecalcomp);
 			} else if (!check_owner_partstatus_for_declined (backend, subcomp)) {
 				gchar *returned_uid;
-				icalcomponent *new_icalcomp = NULL;
 				GSList *attachment_list;
 
 				attachment_list = receive_attachments (cbex, comp);
@@ -1812,7 +1821,7 @@ receive_objects (ECalBackendSync *backend,
 				d(printf ("Create a new object : %s\n", icalobj));
 
 				e_cal_backend_exchange_cache_unlock (cbex);
-				create_object (backend, cal, cancellable, icalobj, &returned_uid, &new_icalcomp, &err);
+				create_object (backend, cal, cancellable, icalobj, &returned_uid, &new_ecalcomp, &err);
 				if (err) {
 					g_free (icalobj);
 					g_propagate_error (error, err);
@@ -1820,11 +1829,11 @@ receive_objects (ECalBackendSync *backend,
 					goto error;
 				}
 
-				e_cal_backend_notify_component_created (E_CAL_BACKEND (backend), new_icalcomp);
+				e_cal_backend_notify_component_created (E_CAL_BACKEND (backend), new_ecalcomp);
 				d(printf ("Notify that the new object is created : %s\n", icalobj));
 				g_free (icalobj);
-				if (new_icalcomp)
-					icalcomponent_free (new_icalcomp);
+				if (new_ecalcomp)
+					g_object_unref (new_ecalcomp);
 			} else {
 				e_cal_backend_exchange_cache_unlock (cbex);
 			}
@@ -1836,23 +1845,21 @@ receive_objects (ECalBackendSync *backend,
 
 		case ICAL_METHOD_CANCEL:
 			if (rid)
-				remove_object (backend, cal, cancellable, uid, rid, CALOBJ_MOD_THIS, &old_icalcomp, &new_icalcomp, &err);
+				remove_object (backend, cal, cancellable, uid, rid, CALOBJ_MOD_THIS, &old_ecalcomp, &new_ecalcomp, &err);
 			else
-				remove_object (backend, cal, cancellable, uid, NULL, CALOBJ_MOD_ALL, &old_icalcomp, &new_icalcomp, &err);
+				remove_object (backend, cal, cancellable, uid, NULL, CALOBJ_MOD_ALL, &old_ecalcomp, &new_ecalcomp, &err);
 			if (!err) {
 				ECalComponentId *id = e_cal_component_get_id (comp);
-				e_cal_backend_notify_component_removed (E_CAL_BACKEND (backend), id, old_icalcomp, NULL);
+				e_cal_backend_notify_component_removed (E_CAL_BACKEND (backend), id, old_ecalcomp, NULL);
 				e_cal_component_free_id (id);
 
 			} else {
 				g_propagate_error (error, err);
 			}
-			if (old_icalcomp) {
-				icalcomponent_free (old_icalcomp);
-				old_icalcomp = NULL;
-			}
-			if (new_icalcomp)
-				icalcomponent_free (new_icalcomp);
+			if (old_ecalcomp)
+				g_object_unref (old_ecalcomp);
+			if (new_ecalcomp)
+				g_object_unref (new_ecalcomp);
 			break;
 		default:
 			g_propagate_error (error, EDC_ERROR (UnsupportedMethod));
@@ -1906,7 +1913,7 @@ book_resource (ECalBackendExchange *cbex,
 	gboolean bookable = TRUE;
 	gchar *top_uri = NULL, *cal_uri = NULL, *returned_uid = NULL, *sanitized_uid;
 	gchar *startz, *endz, *href = NULL, *calobj = NULL;
-	icalcomponent *old_icalcomp = NULL, *new_icalcomp = NULL;
+	ECalComponent *old_ecalcomp = NULL, *new_ecalcomp = NULL;
 	E2kRestriction *rn;
 	gint nresult;
 	ECalBackendExchangeBookingResult retval = E_CAL_BACKEND_EXCHANGE_BOOKING_ERROR;
@@ -2105,35 +2112,35 @@ book_resource (ECalBackendExchange *cbex,
 	if (ecomp) {
 		gboolean modify_ok = FALSE;
 		/* Use the PUT method to create the meeting item in the resource's calendar. */
-		if (modify_object_with_href (E_CAL_BACKEND_SYNC (cbex), cal, NULL, calobj, book_all ? CALOBJ_MOD_ALL : CALOBJ_MOD_THIS, &old_icalcomp, &new_icalcomp, href, NULL, NULL)) {
+		if (modify_object_with_href (E_CAL_BACKEND_SYNC (cbex), cal, NULL, calobj, book_all ? CALOBJ_MOD_ALL : CALOBJ_MOD_THIS, &old_ecalcomp, &new_ecalcomp, href, NULL, NULL)) {
 			/* Need this to update the participation status of the resource
 			 * in the organizer's calendar. */
-			modify_ok = modify_object_with_href (E_CAL_BACKEND_SYNC (cbex), cal, NULL, calobj, book_all ? CALOBJ_MOD_ALL : CALOBJ_MOD_THIS, &old_icalcomp, &new_icalcomp, NULL, NULL, NULL);
+			modify_ok = modify_object_with_href (E_CAL_BACKEND_SYNC (cbex), cal, NULL, calobj, book_all ? CALOBJ_MOD_ALL : CALOBJ_MOD_THIS, &old_ecalcomp, &new_ecalcomp, NULL, NULL, NULL);
 		} else {
 			retval = E_CAL_BACKEND_EXCHANGE_BOOKING_ERROR;
 			goto cleanup;
 		}
 		if (modify_ok) {
-			e_cal_backend_notify_component_modified (E_CAL_BACKEND (cbex), old_icalcomp, new_icalcomp);
+			e_cal_backend_notify_component_modified (E_CAL_BACKEND (cbex), old_ecalcomp, new_ecalcomp);
 			retval = E_CAL_BACKEND_EXCHANGE_BOOKING_OK;
 		}
-		if (old_icalcomp)
-			icalcomponent_free (old_icalcomp);
-		if (new_icalcomp)
-			icalcomponent_free (new_icalcomp);
+		if (old_ecalcomp)
+			g_object_unref (old_ecalcomp);
+		if (new_ecalcomp)
+			g_object_unref (new_ecalcomp);
 	} else {
 		GError *err = NULL;
 
-		create_object (E_CAL_BACKEND_SYNC (cbex), cal, NULL, calobj, &returned_uid, &new_icalcomp, &err);
+		create_object (E_CAL_BACKEND_SYNC (cbex), cal, NULL, calobj, &returned_uid, &new_ecalcomp, &err);
 		if (!err) {
-			e_cal_backend_notify_component_created (E_CAL_BACKEND (cbex), new_icalcomp);
+			e_cal_backend_notify_component_created (E_CAL_BACKEND (cbex), new_ecalcomp);
 			retval = E_CAL_BACKEND_EXCHANGE_BOOKING_OK;
 		} else {
 			g_error_free (err);
 		}
 
-		if (new_icalcomp)
-			icalcomponent_free (new_icalcomp);
+		if (new_ecalcomp)
+			g_object_unref (new_ecalcomp);
 	}
 
  cleanup:
diff --git a/calendar/e-cal-backend-exchange-tasks.c b/calendar/e-cal-backend-exchange-tasks.c
index c76be1f..74fc48c 100644
--- a/calendar/e-cal-backend-exchange-tasks.c
+++ b/calendar/e-cal-backend-exchange-tasks.c
@@ -857,9 +857,12 @@ get_changed_tasks (ECalBackendExchange *cbex)
 			e_cal_backend_exchange_cache_unlock (cbex);
 
 			if (status && kind == ICAL_VTODO_COMPONENT) {
-				gchar *str = icalcomponent_as_ical_string_r (icalcomp);
-				e_cal_backend_notify_object_created (E_CAL_BACKEND (cbex), str);
-				g_free (str);
+				ECalComponent *comp = e_cal_component_new_from_icalcomponent (icalcomponent_new_clone (icalcomp));
+
+				if (comp) {
+					e_cal_backend_notify_component_created (E_CAL_BACKEND (cbex), comp);
+					g_object_unref (comp);
+				}
 			}
 
 		}
@@ -1082,7 +1085,7 @@ create_task_object (ECalBackendSync *backend,
                     GCancellable *cancellable,
                     const gchar *calobj,
                     gchar **return_uid,
-                    icalcomponent **new_icalcomp,
+                    ECalComponent **new_ecalcomp,
                     GError **error)
 {
 	ECalBackendExchange *ecalbex;
@@ -1212,8 +1215,8 @@ create_task_object (ECalBackendSync *backend,
 
 	update_props (comp, &props);
 	e_cal_component_commit_sequence (comp);
-	*new_icalcomp = icalcomponent_new_clone (e_cal_component_get_icalcomponent (comp));
-	if (!*new_icalcomp) {
+	*new_ecalcomp = e_cal_component_clone (comp);
+	if (!*new_ecalcomp) {
 		g_object_unref (comp);
 		g_free (from_name);
 		g_free (from_addr);
@@ -1221,7 +1224,7 @@ create_task_object (ECalBackendSync *backend,
 		return;
 	}
 
-	real_icalcomp = icalcomponent_new_clone (*new_icalcomp);
+	real_icalcomp = icalcomponent_new_clone (e_cal_component_get_icalcomponent (*new_ecalcomp));
 
 	e2kctx = exchange_account_get_context (ecalbex->account);
 	status = e_folder_exchange_proppatch_new (ecalbex->folder, NULL,
@@ -1256,8 +1259,8 @@ modify_task_object (ECalBackendSync *backend,
                     GCancellable *cancellable,
                     const gchar *calobj,
                     CalObjModType mod,
-                    icalcomponent **old_icalcomp,
-                    icalcomponent **new_icalcomp,
+                    ECalComponent **old_ecalcomp,
+                    ECalComponent **new_ecalcomp,
                     GError **error)
 {
 	ECalBackendExchangeTasks *ecalbextask;
@@ -1318,7 +1321,7 @@ modify_task_object (ECalBackendSync *backend,
 		return;
 	}
 
-	*old_icalcomp = icalcomponent_new_clone (ecalbexcomp->icomp);
+	*old_ecalcomp = e_cal_component_new_from_icalcomponent (icalcomponent_new_clone (ecalbexcomp->icomp));
 
 	e_cal_backend_exchange_cache_unlock (ecalbex);
 
@@ -1433,40 +1436,40 @@ receive_task_objects (ECalBackendSync *backend,
 
 		e_cal_backend_exchange_cache_lock (cbex);
 		if (get_exchange_comp (E_CAL_BACKEND_EXCHANGE (ecalbextask), uid)) {
-			icalcomponent *old_icalcomp = NULL, *new_icalcomp = NULL;
+			ECalComponent *old_ecalcomp = NULL, *new_ecalcomp = NULL;
 
 			e_cal_backend_exchange_cache_unlock (cbex);
-			modify_task_object (backend, cal, cancellable, calobj, CALOBJ_MOD_THIS, &old_icalcomp, &new_icalcomp, &err);
+			modify_task_object (backend, cal, cancellable, calobj, CALOBJ_MOD_THIS, &old_ecalcomp, &new_ecalcomp, &err);
 			if (err) {
 				g_free (rid);
 				g_propagate_error (error, err);
 				return;
 			}
 
-			e_cal_backend_notify_component_modified (E_CAL_BACKEND (backend), old_icalcomp, new_icalcomp);
-			if (old_icalcomp)
-				icalcomponent_free (old_icalcomp);
-			if (new_icalcomp)
-				icalcomponent_free (new_icalcomp);
+			e_cal_backend_notify_component_modified (E_CAL_BACKEND (backend), old_ecalcomp, new_ecalcomp);
+			if (old_ecalcomp)
+				g_object_unref (old_ecalcomp);
+			if (new_ecalcomp)
+				g_object_unref (new_ecalcomp);
 		} else {
 			gchar *returned_uid;
-			icalcomponent *new_icalcomp = NULL;
+			ECalComponent *new_ecalcomp = NULL;
 
 			e_cal_backend_exchange_cache_unlock (cbex);
 			calobj = icalcomponent_as_ical_string_r (subcomp);
-			create_task_object (backend, cal, cancellable, calobj, &returned_uid, &new_icalcomp, &err);
+			create_task_object (backend, cal, cancellable, calobj, &returned_uid, &new_ecalcomp, &err);
 			g_free (calobj);
 			if (err) {
-				if (new_icalcomp)
-					icalcomponent_free (new_icalcomp);
+				if (new_ecalcomp)
+					g_object_unref (new_ecalcomp);
 				g_free (rid);
 				g_propagate_error (error, err);
 				return;
 			}
 
-			e_cal_backend_notify_component_created (E_CAL_BACKEND (backend), new_icalcomp);
-			if (new_icalcomp)
-				icalcomponent_free (new_icalcomp);
+			e_cal_backend_notify_component_created (E_CAL_BACKEND (backend), new_ecalcomp);
+			if (new_ecalcomp)
+				g_object_unref (new_ecalcomp);
 		}
 		g_free (rid);
 	}
@@ -1481,8 +1484,8 @@ remove_task_object (ECalBackendSync *backend,
                     const gchar *uid,
                     const gchar *rid,
                     CalObjModType mod,
-                    icalcomponent **old_icalcomp,
-                    icalcomponent **new_icalcomp,
+                    ECalComponent **old_ecalcomp,
+                    ECalComponent **new_ecalcomp,
                     GError **error)
 {
 	ECalBackendExchange *ecalbex = E_CAL_BACKEND_EXCHANGE (backend);
@@ -1507,8 +1510,7 @@ remove_task_object (ECalBackendSync *backend,
 		return;
 	}
 
-	*old_icalcomp = icalcomponent_new_clone (icalcomponent_new_clone (ecalbexcomp->icomp));
-
+	*old_ecalcomp = e_cal_component_new_from_icalcomponent (icalcomponent_new_clone (ecalbexcomp->icomp));
 	e_cal_backend_exchange_cache_unlock (ecalbex);
 
 	ctx = exchange_account_get_context (ecalbex->account);
diff --git a/calendar/e-cal-backend-exchange.c b/calendar/e-cal-backend-exchange.c
index f6610f0..f3c0fd2 100644
--- a/calendar/e-cal-backend-exchange.c
+++ b/calendar/e-cal-backend-exchange.c
@@ -733,32 +733,31 @@ e_cal_backend_exchange_in_cache (ECalBackendExchange *cbex,
 	return TRUE;
 }
 
-static void
+static gboolean
 uncache (gpointer key,
          gpointer value,
          gpointer data)
 {
 	ECalBackendExchange *cbex = data;
 	ECalBackend *backend = E_CAL_BACKEND (cbex);
-	ECalComponentId *id = g_new0 (ECalComponentId, 1);
 	ECalBackendExchangeComponent *ecomp;
 
 	ecomp = (ECalBackendExchangeComponent *) value;
 
-	/* FIXME Need get the recurrence id here */
-	id->uid = g_strdup (key);
-	id->rid = NULL;
 	if (ecomp->icomp) {
-		gchar *str = NULL;
-		/* FIXME somehow the query does not match with the component in some cases, so user needs to press a
-		 * clear to get rid of the component from the view in that case*/
-		str = icalcomponent_as_ical_string_r (ecomp->icomp);
-		e_cal_backend_notify_object_removed (backend, id, icalcomponent_as_ical_string_r (ecomp->icomp)
-				, NULL);
-		g_free (str);
-	}
-	g_hash_table_remove (cbex->priv->objects, key);
-	e_cal_component_free_id (id);
+		ECalComponent *comp = e_cal_component_new_from_icalcomponent (icalcomponent_new_clone (ecomp->icomp));
+
+		if (comp) {
+			ECalComponentId *id;
+
+			id = e_cal_component_get_id (comp);
+			e_cal_backend_notify_component_removed (backend, id, comp, NULL);
+			e_cal_component_free_id (id);
+			g_object_unref (comp);
+		}
+	}
+
+	return TRUE;
 }
 
 void
@@ -766,7 +765,7 @@ e_cal_backend_exchange_cache_sync_end (ECalBackendExchange *cbex)
 {
 	g_return_if_fail (cbex->priv->cache_unseen != NULL);
 
-	g_hash_table_foreach (cbex->priv->cache_unseen, uncache, cbex);
+	g_hash_table_foreach_remove (cbex->priv->cache_unseen, uncache, cbex);
 
 	g_hash_table_destroy (cbex->priv->cache_unseen);
 	cbex->priv->cache_unseen = NULL;
@@ -974,7 +973,7 @@ create_object (ECalBackendSync *backend,
                GCancellable *cancellable,
                const gchar *calobj,
                gchar **uid,
-               icalcomponent **new_object,
+               ECalComponent **new_component,
                GError **perror)
 {
 	g_propagate_error (perror, EDC_ERROR (NotSupported));
@@ -987,8 +986,8 @@ modify_object (ECalBackendSync *backend,
                GCancellable *cancellable,
                const gchar *calobj,
                CalObjModType mod,
-               icalcomponent **old_object,
-               icalcomponent **new_object,
+               ECalComponent **old_component,
+               ECalComponent **new_component,
                GError **perror)
 {
 	g_propagate_error (perror, EDC_ERROR (NotSupported));
@@ -1214,9 +1213,9 @@ send_objects (ECalBackendSync *backend,
 }
 
 typedef struct {
-	GSList *obj_list;
+	GSList *comps_list;
+	gboolean as_string;
 	gboolean search_needed;
-	const gchar *query;
 	ECalBackendSExp *obj_sexp;
 	ECalBackend *backend;
 } MatchObjectData;
@@ -1228,7 +1227,6 @@ match_recurrence_sexp (gpointer data,
 	icalcomponent *icomp = data;
 	MatchObjectData *match_data = user_data;
 	ECalComponent *comp = NULL;
-	gchar * comp_as_string = NULL;
 
 	d(printf("ecbe_match_recurrence_sexp(%p, %p)\n", icomp, match_data));
 
@@ -1240,9 +1238,10 @@ match_recurrence_sexp (gpointer data,
 
 	if ((!match_data->search_needed) ||
 	    (e_cal_backend_sexp_match_comp (match_data->obj_sexp, comp, match_data->backend))) {
-		comp_as_string = e_cal_component_get_as_string (comp);
-		match_data->obj_list = g_slist_append (match_data->obj_list, comp_as_string);
-		d(printf ("ecbe_match_recurrence_sexp: match found, adding \n%s\n", comp_as_string));
+		if (match_data->as_string)
+			match_data->comps_list = g_slist_prepend (match_data->comps_list, e_cal_component_get_as_string (comp));
+		else
+			match_data->comps_list = g_slist_prepend (match_data->comps_list, g_object_ref (comp));
 	}
 	g_object_unref (comp);
 }
@@ -1270,8 +1269,10 @@ match_object_sexp (gpointer key,
 
 		if ((!match_data->search_needed) ||
 		    (e_cal_backend_sexp_match_comp (match_data->obj_sexp, comp, match_data->backend))) {
-			match_data->obj_list = g_slist_append (match_data->obj_list,
-						      e_cal_component_get_as_string (comp));
+			if (match_data->as_string)
+				match_data->comps_list = g_slist_append (match_data->comps_list, e_cal_component_get_as_string (comp));
+			else
+				match_data->comps_list = g_slist_append (match_data->comps_list, g_object_ref (comp));
 		}
 		g_object_unref (comp);
 	}
@@ -1290,17 +1291,16 @@ get_object_list (ECalBackendSync *backend,
                  GSList **objects,
                  GError **perror)
 {
-
 	ECalBackendExchange *cbex;
 	ECalBackendExchangePrivate *priv;
-	MatchObjectData match_data;
+	MatchObjectData match_data = { 0 };
 
 	cbex = E_CAL_BACKEND_EXCHANGE (backend);
 	priv = cbex->priv;
 
 	match_data.search_needed = TRUE;
-	match_data.query = sexp;
-	match_data.obj_list = NULL;
+	match_data.as_string = TRUE;
+	match_data.comps_list = NULL;
 	match_data.backend = E_CAL_BACKEND (backend);
 
 	if (!strcmp (sexp, "#t"))
@@ -1316,7 +1316,7 @@ get_object_list (ECalBackendSync *backend,
 	g_hash_table_foreach (cbex->priv->objects, (GHFunc) match_object_sexp, &match_data);
 	g_mutex_unlock (priv->cache_lock);
 
-	*objects = match_data.obj_list;
+	*objects = match_data.comps_list;
 
 	g_object_unref (match_data.obj_sexp);
 }
@@ -1394,31 +1394,42 @@ static void
 start_view (ECalBackend *backend,
             EDataCalView *view)
 {
-	const gchar *sexp = NULL;
-	GSList *objects = NULL;
+	ECalBackendExchange *cbex;
+	ECalBackendExchangePrivate *priv;
+	MatchObjectData match_data = { 0 };
+	const gchar *sexp;
 	GError *error = NULL;
 
 	d(printf("ecbe_start_view(%p, %p)\n", backend, view));
 
+	cbex = E_CAL_BACKEND_EXCHANGE (backend);
+	priv = cbex->priv;
+
+	match_data.search_needed = TRUE;
+	match_data.as_string = FALSE;
+	match_data.obj_sexp = e_data_cal_view_get_object_sexp (view);
+	match_data.comps_list = NULL;
+	match_data.backend = E_CAL_BACKEND (backend);
+
 	sexp = e_data_cal_view_get_text (view);
-	if (!sexp) {
+	if (!sexp || !match_data.obj_sexp) {
 		error = EDC_ERROR (InvalidQuery);
 		e_data_cal_view_notify_complete (view, error);
 		g_error_free (error);
 		return;
 	}
-	get_object_list (E_CAL_BACKEND_SYNC (backend), NULL, NULL, sexp, &objects, &error);
-	if (error) {
-		e_data_cal_view_notify_complete (view, error);
-		g_error_free (error);
-		return;
-	}
 
-	if (objects) {
-		e_data_cal_view_notify_objects_added (view, objects);
+	if (!strcmp (sexp, "#t"))
+		match_data.search_needed = FALSE;
+
+	g_mutex_lock (priv->cache_lock);
+	g_hash_table_foreach (cbex->priv->objects, (GHFunc) match_object_sexp, &match_data);
+	g_mutex_unlock (priv->cache_lock);
+
+	if (match_data.comps_list) {
+		e_data_cal_view_notify_components_added (view, match_data.comps_list);
 
-		g_slist_foreach (objects, (GFunc) g_free, NULL);
-		g_slist_free (objects);
+		g_slist_free_full (match_data.comps_list, g_object_unref);
 	}
 
 	e_data_cal_view_notify_complete (view, NULL /* Success */);



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