[evolution-patches] patch for adding 'has-alarms-in-range' function to the SEXP language (calendar)



This adds the 'has-alarms-in-range' function, which will be used by the
alarm daemon
-- 
Rodrigo Moya <rodrigo novell com>
Index: ChangeLog
===================================================================
RCS file: /cvs/gnome/evolution-data-server/calendar/ChangeLog,v
retrieving revision 1.316
diff -u -p -r1.316 ChangeLog
--- ChangeLog	17 Aug 2004 14:32:39 -0000	1.316
+++ ChangeLog	18 Aug 2004 11:45:08 -0000
@@ -1,3 +1,58 @@
+2004-08-18  Rodrigo Moya <rodrigo novell com>
+
+	* libedata-cal/e-cal-backend-sexp.c (func_has_alarms_in_range): new
+	function for the regular expression language.
+	(e_cal_backend_sexp_new): added new function to the list of symbols.
+
+	* libecal/e-cal.c (e_cal_get_alarms_in_range): use the new
+	'has-alarms-in-range' function.
+
 2004-08-17  Rodrigo Moya <rodrigo novell com>
 
 	Fixes #61782
Index: libecal/e-cal.c
===================================================================
RCS file: /cvs/gnome/evolution-data-server/calendar/libecal/e-cal.c,v
retrieving revision 1.73
diff -u -p -r1.73 e-cal.c
--- libecal/e-cal.c	17 Aug 2004 13:36:35 -0000	1.73
+++ libecal/e-cal.c	18 Aug 2004 11:45:09 -0000
@@ -3131,7 +3131,7 @@ e_cal_get_alarms_in_range (ECal *ecal, t
 {
 	ECalPrivate *priv;
 	GSList *alarms;
-	char *sexp;
+	char *sexp, *iso_start, *iso_end;;
 	GList *object_list = NULL;
 
 	g_return_val_if_fail (ecal != NULL, NULL);
@@ -3143,8 +3143,21 @@ e_cal_get_alarms_in_range (ECal *ecal, t
 	g_return_val_if_fail (start >= 0 && end >= 0, NULL);
 	g_return_val_if_fail (start <= end, NULL);
 
+	iso_start = isodate_from_time_t (start);
+	if (!iso_start)
+		return;
+
+	iso_end = isodate_from_time_t (end);
+	if (!iso_end) {
+		g_free (iso_start);
+		return;
+	}
+
 	/* build the query string */
-	sexp = g_strdup ("(has-alarms?)");
+	sexp = g_strdup_printf ("(has-alarms-in-range? (make-time \"%s\") (make-time \"%s\"))",
+				iso_start, iso_end);
+	g_free (iso_start);
+	g_free (iso_end);
 
 	/* execute the query on the server */
 	if (!e_cal_get_object_list (ecal, sexp, &object_list, NULL)) {
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.16
diff -u -p -r1.16 e-cal-backend-sexp.c
--- libedata-cal/e-cal-backend-sexp.c	1 Jun 2004 23:09:41 -0000	1.16
+++ libedata-cal/e-cal-backend-sexp.c	18 Aug 2004 11:45:10 -0000
@@ -537,6 +537,67 @@ func_has_alarms (ESExp *esexp, int argc,
 	return result;
 }
 
+/* (has-alarms-in-range? START END)
+ *
+ * START - time_t, start of the time range
+ * END - time_t, end of the time range
+ *
+ * Returns: a boolean indicating whether the component has alarms in the given
+ * time range or not.
+ */
+static ESExpResult *
+func_has_alarms_in_range (ESExp *esexp, int argc, ESExpResult **argv, void *data)
+{
+	time_t start, end;
+	ESExpResult *result;
+	icaltimezone *default_zone;
+	ECalComponentAlarms *alarms;
+	ECalComponentAlarmAction omit[] = {-1};
+	SearchContext *ctx = data;
+
+	/* Check argument types */
+
+	if (argc != 2) {
+		e_sexp_fatal_error (esexp, _("\"%s\" expects two arguments"),
+				    "has-alarms-in-range");
+		return NULL;
+	}
+
+	if (argv[0]->type != ESEXP_RES_TIME) {
+		e_sexp_fatal_error (esexp, _("\"%s\" expects the first "
+					     "argument to be a time_t"),
+				    "has-alarms-in-range");
+		return NULL;
+	}
+	start = argv[0]->value.time;
+
+	if (argv[1]->type != ESEXP_RES_TIME) {
+		e_sexp_fatal_error (esexp, _("\"%s\" expects the second "
+					     "argument to be a time_t"),
+				    "has-alarms-in-range");
+		return NULL;
+	}
+	end = argv[1]->value.time;
+
+	/* See if the object has alarms in the given time range */
+	default_zone = e_cal_backend_internal_get_default_timezone (ctx->backend);
+	if (!default_zone)
+		default_zone = icaltimezone_get_utc_timezone ();
+
+	alarms = e_cal_util_generate_alarms_for_comp (ctx->comp, start, end,
+						      omit, resolve_tzid_cb,
+						      ctx, default_zone);
+
+	result = e_sexp_result_new (esexp, ESEXP_RES_BOOL);
+	if (alarms) {
+		result->value.bool = TRUE;
+		e_cal_component_alarms_free (alarms);
+	} else
+		result->value.bool = FALSE;
+
+	return result;
+}
+
 /* (has-categories? STR+)
  * (has-categories? #f)
  *
@@ -899,6 +960,7 @@ static struct {
 	{ "occur-in-time-range?", func_occur_in_time_range, 0 },
 	{ "contains?", func_contains, 0 },
 	{ "has-alarms?", func_has_alarms, 0 },
+	{ "has-alarms-in-range?", func_has_alarms_in_range, 0 },
 	{ "has-recurrences?", func_has_recurrences, 0 },
 	{ "has-categories?", func_has_categories, 0 },
 	{ "is-completed?", func_is_completed, 0 },


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