[evolution-data-server] calendar file backend: support remove with CALOBJ_MOD_ONLY_THIS



commit 17a86ec294883db631fee24285c2585dcb0b2098
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)

 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 0d85bf7..64b2fb0 100644
--- a/calendar/backends/file/e-cal-backend-file.c
+++ b/calendar/backends/file/e-cal-backend-file.c
@@ -404,6 +404,7 @@ e_cal_backend_file_get_backend_property (ECalBackendSync *backend, EDataCal *cal
 		*prop_value = 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);
 	} else if (g_str_equal (prop_name, CAL_BACKEND_PROPERTY_CAL_EMAIL_ADDRESS) ||
 		   g_str_equal (prop_name, CAL_BACKEND_PROPERTY_ALARM_EMAIL_ADDRESS)) {
@@ -2451,12 +2452,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 */
@@ -2472,6 +2477,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 */
 		}
@@ -2485,6 +2494,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));
@@ -2512,6 +2526,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 */
@@ -2586,6 +2609,7 @@ e_cal_backend_file_remove_object (ECalBackendSync *backend, EDataCal *cal, GCanc
 	case CALOBJ_MOD_THIS:
 	case CALOBJ_MOD_THISANDPRIOR:
 	case CALOBJ_MOD_THISANDFUTURE:
+	case CALOBJ_MOD_ONLY_THIS:
 	case CALOBJ_MOD_ALL:
 		break;
 	default:
@@ -2615,8 +2639,6 @@ e_cal_backend_file_remove_object (ECalBackendSync *backend, EDataCal *cal, GCanc
 		*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]