Re: [evolution-patches] patch for dealing with recurrences in ECalBackendSexp



On Mon, 2004-03-15 at 19:36 +0100, Rodrigo Moya wrote:

> This patch makes ECalBackendSexp deal with recurrences, so all the
> events happening in the given time range (including their recurrences)
> are returned on queries started by clients.

updated patch cuts down the lines of code
Index: ChangeLog
===================================================================
RCS file: /cvs/gnome/evolution-data-server/calendar/ChangeLog,v
retrieving revision 1.205
diff -u -p -r1.205 ChangeLog
--- ChangeLog	15 Mar 2004 17:33:18 -0000	1.205
+++ ChangeLog	15 Mar 2004 18:55:43 -0000
@@ -1,3 +1,22 @@
+2004-03-15  Rodrigo Moya <rodrigo ximian com>
+
+	* libedata-cal/e-cal-backend-sexp.c (func_occur_in_time_range): expand
+	recurrences for the given time range to be sure that we return the
+	correct events.
+	(check_instance_time_range_cb): callback to check the expanded recurrences.
+
 2004-03-15  Rodney Dawes  <dobey ximian com>
 
 	* libecal/libecal-1.0.pc.in:
Index: libedata-cal/e-cal-backend-sexp.c
===================================================================
RCS file: /cvs/gnome/evolution-data-server/calendar/libedata-cal/e-cal-backend-sexp.c,v
retrieving revision 1.12
diff -u -p -r1.12 e-cal-backend-sexp.c
--- libedata-cal/e-cal-backend-sexp.c	2 Mar 2004 22:48:55 -0000	1.12
+++ libedata-cal/e-cal-backend-sexp.c	15 Mar 2004 18:55:44 -0000
@@ -38,6 +38,7 @@ struct _ECalBackendSExpPrivate {
 struct _SearchContext {
 	ECalComponent *comp;
 	ECalBackend *backend;
+	gboolean occurs;
 };
 
 ESExpResult *
@@ -259,6 +260,30 @@ func_uid (ESExp *esexp, int argc, ESExpR
 	return result;
 }
 
+static gboolean
+check_instance_time_range_cb (ECalComponent *comp, time_t instance_start, time_t instance_end, gpointer data)
+{
+	SearchContext *ctx = data;
+
+	/* if we get called, the event has an occurrence in the given time range */
+	ctx->occurs = TRUE;
+
+	return TRUE;
+}
+
+static icaltimezone *
+resolve_tzid_cb (const char *tzid, gpointer user_data)
+{
+	SearchContext *ctx = user_data;
+                                                                                
+        if (!tzid || !tzid[0])
+                return NULL;
+        else if (!strcmp (tzid, "UTC"))
+                return icaltimezone_get_utc_timezone ();
+                                                                                
+        return e_cal_backend_internal_get_timezone (ctx->backend, tzid);
+}
+
 /* (occur-in-time-range? START END)
  *
  * START - time_t, start of the time range
@@ -272,9 +297,8 @@ func_occur_in_time_range (ESExp *esexp, 
 {
 	SearchContext *ctx = data;
 	time_t start, end, tt;
-	gboolean occurs;
-	ESExpResult *result;
 	ECalComponentDateTime dt;
+	ESExpResult *result;
 
 	/* Check argument types */
 
@@ -301,39 +325,14 @@ func_occur_in_time_range (ESExp *esexp, 
 	end = argv[1]->value.time;
 
 	/* See if the object occurs in the specified time range */
-	occurs = FALSE;
-	
-	e_cal_component_get_dtstart (ctx->comp, &dt);
-	if (dt.value) {
-		icaltimezone *zone;
-
-		if (dt.tzid)
-			zone = e_cal_backend_internal_get_timezone (ctx->backend, dt.tzid);
-		else
-			zone = e_cal_backend_internal_get_default_timezone (ctx->backend);
-		
-		tt = icaltime_as_timet_with_zone (*dt.value, zone);
-		e_cal_component_free_datetime (&dt);
-		if (tt >= start && tt <= end)
-			occurs = TRUE;
-		else {
-			e_cal_component_get_dtend (ctx->comp, &dt);
-			if (dt.value) {
-				if (dt.tzid)
-					zone = e_cal_backend_internal_get_timezone (ctx->backend, dt.tzid);
-				else
-					zone = e_cal_backend_internal_get_default_timezone (ctx->backend);
-
-				tt = icaltime_as_timet_with_zone (*dt.value, zone);
-				if (tt >= start && tt <= end)
-					occurs = TRUE;
-				e_cal_component_free_datetime (&dt);
-			}
-		}
-	}
+	ctx->occurs = FALSE;
+	e_cal_recur_generate_instances (ctx->comp, start, end,
+					(ECalRecurInstanceFn) check_instance_time_range_cb,
+					ctx, resolve_tzid_cb, ctx,
+					e_cal_backend_internal_get_default_timezone (ctx->backend));
 
 	result = e_sexp_result_new (esexp, ESEXP_RES_BOOL);
-	result->value.bool = occurs;
+	result->value.bool = ctx->occurs;
 
 	return result;
 }


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