Re: [evolution-patches] Fix for reloading/unloading calendars when source list changes



On Fri, 2004-08-27 at 09:19 -0400, JP Rosevear wrote:
> Rodrigo's alarm daemon patch will conflict with this now, in
> load_calendars_cb.  list_changed_cb would blow away the sources for the
> source types it wasn't processing.
> 
your patch and mines attached to this message fix the problems we were
trying to fix, so approved.
-- 
Rodrigo Moya <rodrigo novell com>
Index: ChangeLog
===================================================================
RCS file: /cvs/gnome/evolution/calendar/ChangeLog,v
retrieving revision 1.2496
diff -u -p -r1.2496 ChangeLog
--- ChangeLog	26 Aug 2004 16:16:53 -0000	1.2496
+++ ChangeLog	27 Aug 2004 14:59:43 -0000
@@ -1,3 +1,9 @@
+2004-08-26  Rodrigo Moya <rodrigo novell com>
+
+	* gui/alarm-notify/alarm-queue.c (load_alarms): use the
+	new 'has-alarms-in-range' query.
+	(alarm_queu_add_client): make sure we don't add twice the same alarm.
+
 2004-08-26  Christian Neumair  <chris gnome-de org>
 
 	* gui/GNOME_Evolution_Calendar.server.in.in:
@@ -9,7 +15,7 @@
 	record correctly, should fix copy to/from problems when syncing
 
 	* conduits/calendar/calendar-conduit.c (for_each): ditto
-	
+
 2004-08-25  Frederic Crozat  <fcrozat mandrakesoft com>
 
 	* gui/dialogs/recur-comp.c: (recur_component_dialog):
Index: gui/alarm-notify/alarm-queue.c
===================================================================
RCS file: /cvs/gnome/evolution/calendar/gui/alarm-notify/alarm-queue.c,v
retrieving revision 1.69
diff -u -p -r1.69 alarm-queue.c
--- gui/alarm-notify/alarm-queue.c	10 Aug 2004 14:14:43 -0000	1.69
+++ gui/alarm-notify/alarm-queue.c	27 Aug 2004 14:59:44 -0000
@@ -390,20 +390,38 @@ load_alarms (ClientAlarms *ca, time_t st
 {
 	/* create the live query */
 	if (!ca->query) {
-		/* FIXME: handle errors */
-		if (!e_cal_get_query (ca->client, "(has-alarms?)", &ca->query, NULL)) {
-			g_warning (G_STRLOC ": Could not get query for client");
+		char *str_query, *iso_start, *iso_end;
+
+		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;
 		}
 
-		g_signal_connect (G_OBJECT (ca->query), "objects_added",
-				  G_CALLBACK (query_objects_changed_cb), ca);
-		g_signal_connect (G_OBJECT (ca->query), "objects_modified",
-				  G_CALLBACK (query_objects_changed_cb), ca);
-		g_signal_connect (G_OBJECT (ca->query), "objects_removed",
-				  G_CALLBACK (query_objects_removed_cb), ca);
+		str_query = 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);
+
+		/* FIXME: handle errors */
+		if (!e_cal_get_query (ca->client, str_query, &ca->query, NULL)) {
+			g_warning (G_STRLOC ": Could not get query for client");
+		} else {
+			g_signal_connect (G_OBJECT (ca->query), "objects_added",
+					  G_CALLBACK (query_objects_changed_cb), ca);
+			g_signal_connect (G_OBJECT (ca->query), "objects_modified",
+					  G_CALLBACK (query_objects_changed_cb), ca);
+			g_signal_connect (G_OBJECT (ca->query), "objects_removed",
+					  G_CALLBACK (query_objects_removed_cb), ca);
+
+			e_cal_view_start (ca->query);
+		}
 
-		e_cal_view_start (ca->query);
+		g_free (str_query);
 	}
 }
 
@@ -1292,14 +1310,13 @@ alarm_queue_add_client (ECal *client)
 
 	ca->uid_alarms_hash = g_hash_table_new (g_str_hash, g_str_equal);
 
-	if (e_cal_get_load_state (client) != E_CAL_LOAD_LOADED)
-		g_signal_connect (client, "cal_opened",
-				  G_CALLBACK (cal_opened_cb),
-				  ca);
-
 	if (e_cal_get_load_state (client) == E_CAL_LOAD_LOADED) {
 		load_alarms_for_today (ca);
 		load_missed_alarms (ca);
+	else {
+		g_signal_connect (client, "cal_opened",
+				  G_CALLBACK (cal_opened_cb),
+				  ca);
 	}
 }
 
Index: ChangeLog
===================================================================
RCS file: /cvs/gnome/evolution-data-server/calendar/ChangeLog,v
retrieving revision 1.323
diff -u -p -r1.323 ChangeLog
--- ChangeLog	27 Aug 2004 05:39:52 -0000	1.323
+++ ChangeLog	27 Aug 2004 15:04:38 -0000
@@ -1,3 +1,12 @@
+2004-08-27  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-27  Chenthill Palanisamy <pchenthill novell com>
 
 	* backends/groupwise/e-cal-backend-groupwise-utils.c
Index: libecal/e-cal.c
===================================================================
RCS file: /cvs/gnome/evolution-data-server/calendar/libecal/e-cal.c,v
retrieving revision 1.74
diff -u -p -r1.74 e-cal.c
--- libecal/e-cal.c	25 Aug 2004 14:38:14 -0000	1.74
+++ libecal/e-cal.c	27 Aug 2004 15:04:40 -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	27 Aug 2004 15:04:40 -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]