[evolution-data-server] ECalBackendSExp: Take an ETimezoneCache instead of ECalBackend.



commit e09820b1c4c92903ab091c9413a4ef266872aea0
Author: Matthew Barnes <mbarnes redhat com>
Date:   Thu Jan 3 11:35:15 2013 -0500

    ECalBackendSExp: Take an ETimezoneCache instead of ECalBackend.
    
    Here's the real reason for the ETimezoneCache interface.
    
    By changing ECalBackend parameters to ETimezoneCache (an interface which
    ECalBackend implements), we abstract away the requirement for a calendar
    backend when performing S-expression evaluation.
    
    Since ECalClient also implements the ETimezoneCache interface, this opens
    the possibility of allowing client-side S-expression evaluation.  (Would
    first require moving ECalBackendSExp to libecal, plus of course a rename
    to omit the "Backend" part.)
    
    Affected functions:
    
        e_cal_backend_sexp_match_object()
        e_cal_backend_sexp_match_comp()
    
    This is another API break.  3rd party backends will have to be adjusted.

 calendar/backends/caldav/e-cal-backend-caldav.c    |   14 ++++----
 .../backends/contacts/e-cal-backend-contacts.c     |    7 +++-
 calendar/backends/file/e-cal-backend-file.c        |   19 +++++++++--
 calendar/backends/http/e-cal-backend-http.c        |   14 ++++++--
 calendar/backends/weather/e-cal-backend-weather.c  |   15 ++++++--
 calendar/libedata-cal/e-cal-backend-sexp.c         |   34 +++++++------------
 calendar/libedata-cal/e-cal-backend-sexp.h         |    8 +---
 calendar/libedata-cal/e-data-cal-view.c            |   17 +++++++++-
 8 files changed, 79 insertions(+), 49 deletions(-)
---
diff --git a/calendar/backends/caldav/e-cal-backend-caldav.c b/calendar/backends/caldav/e-cal-backend-caldav.c
index 6193109..9f425b3 100644
--- a/calendar/backends/caldav/e-cal-backend-caldav.c
+++ b/calendar/backends/caldav/e-cal-backend-caldav.c
@@ -4498,7 +4498,7 @@ caldav_get_object_list (ECalBackendSync *backend,
 {
 	ECalBackendCalDAV        *cbdav;
 	ECalBackendSExp	 *sexp;
-	ECalBackend *bkend;
+	ETimezoneCache *cache;
 	gboolean                  do_search;
 	GSList			 *list, *iter;
 	time_t occur_start = -1, occur_end = -1;
@@ -4523,17 +4523,17 @@ caldav_get_object_list (ECalBackendSync *backend,
 
 	prunning_by_time = e_cal_backend_sexp_evaluate_occur_times (sexp, &occur_start, &occur_end);
 
+	cache = E_TIMEZONE_CACHE (backend);
+
 	list = prunning_by_time ?
 		e_cal_backend_store_get_components_occuring_in_range (cbdav->priv->store, occur_start, occur_end)
 		: e_cal_backend_store_get_components (cbdav->priv->store);
 
-	bkend = E_CAL_BACKEND (backend);
-
 	for (iter = list; iter; iter = g_slist_next (iter)) {
 		ECalComponent *comp = E_CAL_COMPONENT (iter->data);
 
 		if (!do_search ||
-		    e_cal_backend_sexp_match_comp (sexp, comp, bkend)) {
+		    e_cal_backend_sexp_match_comp (sexp, comp, cache)) {
 			*objects = g_slist_prepend (*objects, e_cal_component_get_as_string (comp));
 		}
 
@@ -4550,7 +4550,7 @@ caldav_start_view (ECalBackend *backend,
 {
 	ECalBackendCalDAV        *cbdav;
 	ECalBackendSExp	 *sexp;
-	ECalBackend              *bkend;
+	ETimezoneCache *cache;
 	gboolean                  do_search;
 	GSList			 *list, *iter;
 	const gchar               *sexp_string;
@@ -4571,7 +4571,7 @@ caldav_start_view (ECalBackend *backend,
 		&occur_start,
 		&occur_end);
 
-	bkend = E_CAL_BACKEND (backend);
+	cache = E_TIMEZONE_CACHE (backend);
 
 	list = prunning_by_time ?
 		e_cal_backend_store_get_components_occuring_in_range (cbdav->priv->store, occur_start, occur_end)
@@ -4581,7 +4581,7 @@ caldav_start_view (ECalBackend *backend,
 		ECalComponent *comp = E_CAL_COMPONENT (iter->data);
 
 		if (!do_search ||
-		    e_cal_backend_sexp_match_comp (sexp, comp, bkend)) {
+		    e_cal_backend_sexp_match_comp (sexp, comp, cache)) {
 			e_data_cal_view_notify_components_added_1 (query, comp);
 		}
 
diff --git a/calendar/backends/contacts/e-cal-backend-contacts.c b/calendar/backends/contacts/e-cal-backend-contacts.c
index 1a53655..1cc8739 100644
--- a/calendar/backends/contacts/e-cal-backend-contacts.c
+++ b/calendar/backends/contacts/e-cal-backend-contacts.c
@@ -526,11 +526,14 @@ contact_record_cb (gpointer key,
                    gpointer value,
                    gpointer user_data)
 {
+	ETimezoneCache *timezone_cache;
 	ContactRecordCB *cb_data = user_data;
 	ContactRecord   *record = value;
 	gpointer data;
 
-	if (record->comp_birthday && e_cal_backend_sexp_match_comp (cb_data->sexp, record->comp_birthday, E_CAL_BACKEND (cb_data->cbc))) {
+	timezone_cache = E_TIMEZONE_CACHE (cb_data->cbc);
+
+	if (record->comp_birthday && e_cal_backend_sexp_match_comp (cb_data->sexp, record->comp_birthday, timezone_cache)) {
 		if (cb_data->as_string)
 			data = e_cal_component_get_as_string (record->comp_birthday);
 		else
@@ -539,7 +542,7 @@ contact_record_cb (gpointer key,
 		cb_data->result = g_slist_prepend (cb_data->result, data);
 	}
 
-	if (record->comp_anniversary && e_cal_backend_sexp_match_comp (cb_data->sexp, record->comp_anniversary, E_CAL_BACKEND (cb_data->cbc))) {
+	if (record->comp_anniversary && e_cal_backend_sexp_match_comp (cb_data->sexp, record->comp_anniversary, timezone_cache)) {
 		if (cb_data->as_string)
 			data = e_cal_component_get_as_string (record->comp_anniversary);
 		else
diff --git a/calendar/backends/file/e-cal-backend-file.c b/calendar/backends/file/e-cal-backend-file.c
index 00fa8d0..0395f92 100644
--- a/calendar/backends/file/e-cal-backend-file.c
+++ b/calendar/backends/file/e-cal-backend-file.c
@@ -1556,6 +1556,7 @@ match_object_sexp_to_component (gpointer value,
 {
 	ECalComponent * comp = value;
 	MatchObjectData *match_data = data;
+	ETimezoneCache *timezone_cache;
 	const gchar *uid;
 
 	e_cal_component_get_uid (comp, &uid);
@@ -1564,8 +1565,10 @@ match_object_sexp_to_component (gpointer value,
 
 	g_return_if_fail (match_data->backend != NULL);
 
+	timezone_cache = E_TIMEZONE_CACHE (match_data->backend);
+
 	if ((!match_data->search_needed) ||
-	    (e_cal_backend_sexp_match_comp (match_data->obj_sexp, comp, match_data->backend))) {
+	    (e_cal_backend_sexp_match_comp (match_data->obj_sexp, comp, timezone_cache))) {
 		if (match_data->as_string)
 			match_data->comps_list = g_slist_prepend (match_data->comps_list, e_cal_component_get_as_string (comp));
 		else
@@ -1580,9 +1583,12 @@ match_recurrence_sexp (gpointer key,
 {
 	ECalComponent *comp = value;
 	MatchObjectData *match_data = data;
+	ETimezoneCache *timezone_cache;
+
+	timezone_cache = E_TIMEZONE_CACHE (match_data->backend);
 
 	if ((!match_data->search_needed) ||
-	    (e_cal_backend_sexp_match_comp (match_data->obj_sexp, comp, match_data->backend))) {
+	    (e_cal_backend_sexp_match_comp (match_data->obj_sexp, comp, timezone_cache))) {
 		if (match_data->as_string)
 			match_data->comps_list = g_slist_prepend (match_data->comps_list, e_cal_component_get_as_string (comp));
 		else
@@ -1597,12 +1603,15 @@ match_object_sexp (gpointer key,
 {
 	ECalBackendFileObject *obj_data = value;
 	MatchObjectData *match_data = data;
+	ETimezoneCache *timezone_cache;
+
+	timezone_cache = E_TIMEZONE_CACHE (match_data->backend);
 
 	if (obj_data->full_object) {
 		if ((!match_data->search_needed) ||
 		    (e_cal_backend_sexp_match_comp (match_data->obj_sexp,
 						    obj_data->full_object,
-						    match_data->backend))) {
+						    timezone_cache))) {
 			if (match_data->as_string)
 				match_data->comps_list = g_slist_prepend (match_data->comps_list, e_cal_component_get_as_string (obj_data->full_object));
 			else
@@ -1995,7 +2004,9 @@ create_user_free_busy (ECalBackendFile *cbfile,
 				continue;
 		}
 
-		if (!e_cal_backend_sexp_match_comp (obj_sexp, l->data, E_CAL_BACKEND (cbfile)))
+		if (!e_cal_backend_sexp_match_comp (
+			obj_sexp, l->data,
+			E_TIMEZONE_CACHE (cbfile)))
 			continue;
 
 		vcalendar_comp = icalcomponent_get_parent (icalcomp);
diff --git a/calendar/backends/http/e-cal-backend-http.c b/calendar/backends/http/e-cal-backend-http.c
index f5accf2..eacc3a5 100644
--- a/calendar/backends/http/e-cal-backend-http.c
+++ b/calendar/backends/http/e-cal-backend-http.c
@@ -1064,12 +1064,15 @@ e_cal_backend_http_get_object_list (ECalBackendSync *backend,
 	ECalBackendHttpPrivate *priv;
 	GSList *components, *l;
 	ECalBackendSExp *cbsexp;
+	ETimezoneCache *timezone_cache;
 	time_t occur_start = -1, occur_end = -1;
 	gboolean prunning_by_time;
 
 	cbhttp = E_CAL_BACKEND_HTTP (backend);
 	priv = cbhttp->priv;
 
+	timezone_cache = E_TIMEZONE_CACHE (backend);
+
 	if (!priv->store) {
 		g_propagate_error (perror, EDC_ERROR (NoSuchCal));
 		return;
@@ -1089,7 +1092,7 @@ e_cal_backend_http_get_object_list (ECalBackendSync *backend,
 		: e_cal_backend_store_get_components (priv->store);
 
 	for (l = components; l != NULL; l = g_slist_next (l)) {
-		if (e_cal_backend_sexp_match_comp (cbsexp, E_CAL_COMPONENT (l->data), E_CAL_BACKEND (backend))) {
+		if (e_cal_backend_sexp_match_comp (cbsexp, E_CAL_COMPONENT (l->data), timezone_cache)) {
 			*objects = g_slist_append (*objects, e_cal_component_get_as_string (l->data));
 		}
 	}
@@ -1108,12 +1111,15 @@ e_cal_backend_http_start_view (ECalBackend *backend,
 	GSList *components, *l;
 	GSList *objects = NULL;
 	ECalBackendSExp *cbsexp;
+	ETimezoneCache *timezone_cache;
 	time_t occur_start = -1, occur_end = -1;
 	gboolean prunning_by_time;
 
 	cbhttp = E_CAL_BACKEND_HTTP (backend);
 	priv = cbhttp->priv;
 
+	timezone_cache = E_TIMEZONE_CACHE (backend);
+
 	cbsexp = e_data_cal_view_get_sexp (query);
 
 	d (g_message (G_STRLOC ": Starting query (%s)", e_cal_backend_sexp_text (cbsexp)));
@@ -1139,7 +1145,7 @@ e_cal_backend_http_start_view (ECalBackend *backend,
 	for (l = components; l != NULL; l = g_slist_next (l)) {
 		ECalComponent *comp = l->data;
 
-		if (e_cal_backend_sexp_match_comp (cbsexp, comp, E_CAL_BACKEND (backend))) {
+		if (e_cal_backend_sexp_match_comp (cbsexp, comp, timezone_cache)) {
 			objects = g_slist_append (objects, comp);
 		}
 	}
@@ -1268,7 +1274,9 @@ create_user_free_busy (ECalBackendHttp *cbhttp,
 				continue;
 		}
 
-		if (!e_cal_backend_sexp_match_comp (obj_sexp, l->data, E_CAL_BACKEND (cbhttp)))
+		if (!e_cal_backend_sexp_match_comp (
+			obj_sexp, l->data,
+			E_TIMEZONE_CACHE (cbhttp)))
 			continue;
 
 		vcalendar_comp = icalcomponent_get_parent (icalcomp);
diff --git a/calendar/backends/weather/e-cal-backend-weather.c b/calendar/backends/weather/e-cal-backend-weather.c
index 6229a0c..13f0d0c 100644
--- a/calendar/backends/weather/e-cal-backend-weather.c
+++ b/calendar/backends/weather/e-cal-backend-weather.c
@@ -597,16 +597,20 @@ e_cal_backend_weather_get_object_list (ECalBackendSync *backend,
 {
 	ECalBackendWeather *cbw = E_CAL_BACKEND_WEATHER (backend);
 	ECalBackendWeatherPrivate *priv = cbw->priv;
-	ECalBackendSExp *sexp = e_cal_backend_sexp_new (sexp_string);
+	ECalBackendSExp *sexp;
+	ETimezoneCache *timezone_cache;
 	GSList *components, *l;
 	time_t occur_start = -1, occur_end = -1;
 	gboolean prunning_by_time;
 
-	if (!sexp) {
+	sexp = e_cal_backend_sexp_new (sexp_string);
+	if (sexp == NULL) {
 		g_propagate_error (perror, EDC_ERROR (InvalidQuery));
 		return;
 	}
 
+	timezone_cache = E_TIMEZONE_CACHE (backend);
+
 	*objects = NULL;
 	prunning_by_time = e_cal_backend_sexp_evaluate_occur_times (
 		sexp,
@@ -618,7 +622,7 @@ e_cal_backend_weather_get_object_list (ECalBackendSync *backend,
 		: e_cal_backend_store_get_components (priv->store);
 
 	for (l = components; l != NULL; l = g_slist_next (l)) {
-		if (e_cal_backend_sexp_match_comp (sexp, E_CAL_COMPONENT (l->data), E_CAL_BACKEND (backend)))
+		if (e_cal_backend_sexp_match_comp (sexp, E_CAL_COMPONENT (l->data), timezone_cache))
 			*objects = g_slist_append (*objects, e_cal_component_get_as_string (l->data));
 	}
 
@@ -696,6 +700,7 @@ e_cal_backend_weather_start_view (ECalBackend *backend,
 	ECalBackendWeather *cbw;
 	ECalBackendWeatherPrivate *priv;
 	ECalBackendSExp *sexp;
+	ETimezoneCache *timezone_cache;
 	GSList *components, *l;
 	GSList *objects;
 	GError *error;
@@ -720,6 +725,8 @@ e_cal_backend_weather_start_view (ECalBackend *backend,
 		return;
 	}
 
+	timezone_cache = E_TIMEZONE_CACHE (backend);
+
 	objects = NULL;
 	prunning_by_time = e_cal_backend_sexp_evaluate_occur_times (sexp, &occur_start, &occur_end);
 	components = prunning_by_time ?
@@ -727,7 +734,7 @@ e_cal_backend_weather_start_view (ECalBackend *backend,
 		: e_cal_backend_store_get_components (priv->store);
 
 	for (l = components; l != NULL; l = g_slist_next (l)) {
-		if (e_cal_backend_sexp_match_comp (sexp, E_CAL_COMPONENT (l->data), backend))
+		if (e_cal_backend_sexp_match_comp (sexp, E_CAL_COMPONENT (l->data), timezone_cache))
 			objects = g_slist_prepend (objects, l->data);
 	}
 
diff --git a/calendar/libedata-cal/e-cal-backend-sexp.c b/calendar/libedata-cal/e-cal-backend-sexp.c
index db9c9e4..a8afa80 100644
--- a/calendar/libedata-cal/e-cal-backend-sexp.c
+++ b/calendar/libedata-cal/e-cal-backend-sexp.c
@@ -43,7 +43,7 @@ struct _ECalBackendSExpPrivate {
 
 struct _SearchContext {
 	ECalComponent *comp;
-	ECalBackend *backend;
+	ETimezoneCache *cache;
 	gboolean occurs;
 	gint occurrences_count;
 
@@ -374,12 +374,10 @@ resolve_tzid (const gchar *tzid,
 {
 	SearchContext *ctx = user_data;
 
-	if (!tzid || !tzid[0])
+	if (tzid == NULL || *tzid == '\0')
 		return NULL;
-	else if (!strcmp (tzid, "UTC"))
-		return icaltimezone_get_utc_timezone ();
 
-	return e_cal_backend_internal_get_timezone (ctx->backend, tzid);
+	return e_timezone_cache_get_timezone (ctx->cache, tzid);
 }
 
 /* (occur-in-time-range? START END TZLOC)
@@ -531,9 +529,8 @@ func_occurrences_count (ESExp *esexp,
 	ctx->occurrences_count = 0;
 	e_cal_recur_generate_instances (
 		ctx->comp, start, end,
-					count_instances_time_range_cb, ctx,
-					resolve_tzid, ctx,
-					default_zone);
+		count_instances_time_range_cb, ctx,
+		resolve_tzid, ctx, default_zone);
 
 	result = e_sexp_result_new (esexp, ESEXP_RES_INT);
 	result->value.number = ctx->occurrences_count;
@@ -1520,7 +1517,7 @@ e_cal_backend_sexp_evaluate_occur_times (ECalBackendSExp *sexp,
  * e_cal_backend_sexp_match_comp:
  * @sexp: An #ESExp object.
  * @comp: Component to match against the expression.
- * @backend: Backend.
+ * @cache: an #ETimezoneCache
  *
  * Matches the given ECalComponent against the expression.
  *
@@ -1529,29 +1526,24 @@ e_cal_backend_sexp_evaluate_occur_times (ECalBackendSExp *sexp,
 gboolean
 e_cal_backend_sexp_match_comp (ECalBackendSExp *sexp,
                                ECalComponent *comp,
-                               ECalBackend *backend)
+                               ETimezoneCache *cache)
 {
 	ESExpResult *r;
 	gboolean retval;
 
 	g_return_val_if_fail (E_IS_CAL_BACKEND_SEXP (sexp), FALSE);
 	g_return_val_if_fail (E_IS_CAL_COMPONENT (comp), FALSE);
-	g_return_val_if_fail (E_IS_CAL_BACKEND (backend), FALSE);
+	g_return_val_if_fail (E_IS_TIMEZONE_CACHE (cache), FALSE);
 
 	sexp->priv->search_context->comp = g_object_ref (comp);
-	sexp->priv->search_context->backend = g_object_ref (backend);
+	sexp->priv->search_context->cache = g_object_ref (cache);
 
-	/* if it's not a valid vcard why is it in our db? :) */
-	if (!sexp->priv->search_context->comp)  {
-		g_object_unref (sexp->priv->search_context->backend);
-		return FALSE;
-	}
 	r = e_sexp_eval (sexp->priv->search_sexp);
 
 	retval = (r && r->type == ESEXP_RES_BOOL && r->value.boolean);
 
 	g_object_unref (sexp->priv->search_context->comp);
-	g_object_unref (sexp->priv->search_context->backend);
+	g_object_unref (sexp->priv->search_context->cache);
 
 	e_sexp_result_free (sexp->priv->search_sexp, r);
 
@@ -1562,7 +1554,7 @@ e_cal_backend_sexp_match_comp (ECalBackendSExp *sexp,
  * e_cal_backend_sexp_match_object:
  * @sexp: An #ESExp object.
  * @object: An iCalendar string.
- * @backend: A backend.
+ * @cache: an #ETimezoneCache
  *
  * Match an iCalendar expression against the expression.
  *
@@ -1571,7 +1563,7 @@ e_cal_backend_sexp_match_comp (ECalBackendSExp *sexp,
 gboolean
 e_cal_backend_sexp_match_object (ECalBackendSExp *sexp,
                                  const gchar *object,
-                                 ECalBackend *backend)
+                                 ETimezoneCache *cache)
 {
 	ECalComponent *comp;
 	icalcomponent *icalcomp;
@@ -1584,7 +1576,7 @@ e_cal_backend_sexp_match_object (ECalBackendSExp *sexp,
 	comp = e_cal_component_new ();
 	e_cal_component_set_icalcomponent (comp, icalcomp);
 
-	retval = e_cal_backend_sexp_match_comp (sexp, comp, backend);
+	retval = e_cal_backend_sexp_match_comp (sexp, comp, cache);
 
 	g_object_unref (comp);
 
diff --git a/calendar/libedata-cal/e-cal-backend-sexp.h b/calendar/libedata-cal/e-cal-backend-sexp.h
index d9c1ccc..2eb3910 100644
--- a/calendar/libedata-cal/e-cal-backend-sexp.h
+++ b/calendar/libedata-cal/e-cal-backend-sexp.h
@@ -30,8 +30,6 @@
 
 #include <libecal/libecal.h>
 
-#include <libedata-cal/e-cal-backend.h>
-
 /* Standard GObject macros */
 #define E_TYPE_CAL_BACKEND_SEXP \
 	(e_cal_backend_sexp_get_type ())
@@ -53,8 +51,6 @@
 
 G_BEGIN_DECLS
 
-struct _ECalBackend;
-
 typedef struct _ECalBackendSExp ECalBackendSExp;
 typedef struct _ECalBackendSExpClass ECalBackendSExpClass;
 typedef struct _ECalBackendSExpPrivate ECalBackendSExpPrivate;
@@ -75,10 +71,10 @@ const gchar *	e_cal_backend_sexp_text		(ECalBackendSExp *sexp);
 
 gboolean	e_cal_backend_sexp_match_object	(ECalBackendSExp *sexp,
 						 const gchar *object,
-						 struct _ECalBackend *backend);
+						 ETimezoneCache *cache);
 gboolean	e_cal_backend_sexp_match_comp	(ECalBackendSExp *sexp,
 						 ECalComponent *comp,
-						 struct _ECalBackend *backend);
+						 ETimezoneCache *cache);
 
 /* Default implementations of time functions for use by subclasses */
 
diff --git a/calendar/libedata-cal/e-data-cal-view.c b/calendar/libedata-cal/e-data-cal-view.c
index c162962..daa8c4d 100644
--- a/calendar/libedata-cal/e-data-cal-view.c
+++ b/calendar/libedata-cal/e-data-cal-view.c
@@ -27,6 +27,7 @@
 
 #include <string.h>
 
+#include "e-cal-backend.h"
 #include "e-cal-backend-sexp.h"
 #include "e-data-cal-view.h"
 #include "e-gdbus-cal-view.h"
@@ -924,11 +925,17 @@ gboolean
 e_data_cal_view_object_matches (EDataCalView *view,
                                 const gchar *object)
 {
+	ECalBackend *backend;
+	ECalBackendSExp *sexp;
+
 	g_return_val_if_fail (E_IS_DATA_CAL_VIEW (view), FALSE);
 	g_return_val_if_fail (object != NULL, FALSE);
 
+	sexp = e_data_cal_view_get_sexp (view);
+	backend = e_data_cal_view_get_backend (view);
+
 	return e_cal_backend_sexp_match_object (
-		view->priv->sexp, object, view->priv->backend);
+		sexp, object, E_TIMEZONE_CACHE (backend));
 }
 
 /**
@@ -947,11 +954,17 @@ gboolean
 e_data_cal_view_component_matches (EDataCalView *view,
                                    ECalComponent *component)
 {
+	ECalBackend *backend;
+	ECalBackendSExp *sexp;
+
 	g_return_val_if_fail (E_IS_DATA_CAL_VIEW (view), FALSE);
 	g_return_val_if_fail (E_IS_CAL_COMPONENT (component), FALSE);
 
+	sexp = e_data_cal_view_get_sexp (view);
+	backend = e_data_cal_view_get_backend (view);
+
 	return e_cal_backend_sexp_match_comp (
-		view->priv->sexp, component, view->priv->backend);
+		sexp, component, E_TIMEZONE_CACHE (backend));
 }
 
 /**



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