[evolution-data-server/gnome-3-0] calendar file backend: support remove with CALOBJ_MOD_ONLY_THIS



commit 6ca796ef46900d5403c9a1bc0b26aa39c0ff6e35
Author: Patrick Ohly <patrick ohly intel com>
Date:   Thu May 12 14:04:37 2011 +0200

    calendar file backend: support remove with CALOBJ_MOD_ONLY_THIS
    
    Support for this capability is easy:
    - report removal of the detached recurrence
    - report error when not found
    - avoid modifying the parent (= full_object)
    
    (Adapted from commit 17a86ec294883db631fee24285c2585dcb0b2098)

 calendar/backends/file/e-cal-backend-file.c |   34 ++++++++++++++++++++++----
 1 files changed, 28 insertions(+), 6 deletions(-)
---
diff --git a/calendar/backends/file/e-cal-backend-file.c b/calendar/backends/file/e-cal-backend-file.c
index 34a48af..4b54f57 100644
--- a/calendar/backends/file/e-cal-backend-file.c
+++ b/calendar/backends/file/e-cal-backend-file.c
@@ -446,6 +446,7 @@ e_cal_backend_file_get_static_capabilities (ECalBackendSync *backend, EDataCal *
 	*capabilities = g_strdup (CAL_STATIC_CAPABILITY_NO_EMAIL_ALARMS ","
 				  CAL_STATIC_CAPABILITY_NO_THISANDFUTURE ","
 				  CAL_STATIC_CAPABILITY_DELEGATE_SUPPORTED ","
+				  CAL_STATIC_CAPABILITY_REMOVE_ONLY_THIS ","
 				  CAL_STATIC_CAPABILITY_NO_THISANDPRIOR);
 }
 
@@ -2669,12 +2670,16 @@ remove_instance (ECalBackendFile *cbfile, ECalBackendFileObject *obj_data,
 		/* remove recurrence */
 		if (g_hash_table_lookup_extended (obj_data->recurrences, rid,
 		                                  (gpointer *)&hash_rid, (gpointer *)&comp)) {
-			/* Removing without parent? Report as removal. */
-			if (old_object && !obj_data->full_object)
+			/* Removing without parent or not modifying parent?
+			   Report removal to caller. */
+			if (old_object &&
+			    (!obj_data->full_object || mod == CALOBJ_MOD_ONLY_THIS))
 				*old_object = e_cal_component_get_as_string (comp);
 
-			/* Removing with parent? Report directly instead of going via caller. */
-			if (obj_data->full_object) {
+			/* Reporting parent modification to caller?
+			   Report directly instead of going via caller. */
+			if (obj_data->full_object &&
+			    mod != CALOBJ_MOD_ONLY_THIS) {
 				/* old object string not provided,
 				   instead rely on the view detecting
 				   whether it contains the id */
@@ -2690,6 +2695,10 @@ remove_instance (ECalBackendFile *cbfile, ECalBackendFileObject *obj_data,
 			cbfile->priv->comp = g_list_remove (cbfile->priv->comp, comp);
 			obj_data->recurrences_list = g_list_remove (obj_data->recurrences_list, comp);
 			g_hash_table_remove (obj_data->recurrences, rid);
+		} else if (mod == CALOBJ_MOD_ONLY_THIS) {
+			if (error)
+				g_propagate_error (error, EDC_ERROR (ObjectNotFound));
+			return obj_data;
 		} else {
 			/* not an error, only add EXDATE */
 		}
@@ -2703,6 +2712,11 @@ remove_instance (ECalBackendFile *cbfile, ECalBackendFileObject *obj_data,
 				return obj_data;
 			}
 		}
+
+		/* avoid modifying parent? */
+		if (mod == CALOBJ_MOD_ONLY_THIS)
+			return obj_data;
+
 		/* remove the main component from our data before modifying it */
 		icalcomponent_remove_component (cbfile->priv->icalcomp,
 						e_cal_component_get_icalcomponent (obj_data->full_object));
@@ -2730,6 +2744,15 @@ remove_instance (ECalBackendFile *cbfile, ECalBackendFileObject *obj_data,
 					     e_cal_component_get_icalcomponent (obj_data->full_object));
 		cbfile->priv->comp = g_list_prepend (cbfile->priv->comp, obj_data->full_object);
 	} else {
+		if (!obj_data->full_object) {
+			/* Nothing to do, parent doesn't exist. Tell
+			   caller about this? Not an error with
+			   CALOBJ_MOD_THIS. */
+			if (mod == CALOBJ_MOD_ONLY_THIS && error)
+				g_propagate_error (error, EDC_ERROR (ObjectNotFound));
+			return obj_data;
+		}
+
 		/* remove the main component from our data before deleting it */
 		if (!remove_component_from_intervaltree (cbfile, obj_data->full_object)) {
 			/* return without changing anything */
@@ -2804,6 +2827,7 @@ e_cal_backend_file_remove_object (ECalBackendSync *backend, EDataCal *cal,
 	case CALOBJ_MOD_THIS:
 	case CALOBJ_MOD_THISANDPRIOR:
 	case CALOBJ_MOD_THISANDFUTURE:
+	case CALOBJ_MOD_ONLY_THIS:
 	case CALOBJ_MOD_ALL:
 		break;
 	default:
@@ -2833,8 +2857,6 @@ e_cal_backend_file_remove_object (ECalBackendSync *backend, EDataCal *cal,
 		*object = NULL;
 		break;
 	case CALOBJ_MOD_ONLY_THIS:
-		/* not reached, keep compiler happy */
-		break;
 	case CALOBJ_MOD_THIS :
 		obj_data = remove_instance (cbfile, obj_data, uid, recur_id, mod, old_object, object, error);
 		break;



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