[evolution-patches] [calendar-alarm-notify] fix for bug#269685



hi

 After snoozing an alarm for a calendar item,
 change in summary or any other non-time related
 fields of the component do not reflect in the 
 the future alarms of the component.

 This patch updates the local structures maintained
 for alarms so that the changes are reflected.

regards

Index: ChangeLog
===================================================================
RCS file: /cvs/gnome/evolution/calendar/ChangeLog,v
retrieving revision 1.2804
diff -u -p -r1.2804 ChangeLog
--- ChangeLog	19 Sep 2005 08:10:51 -0000	1.2804
+++ ChangeLog	28 Sep 2005 04:49:18 -0000
@@ -1,3 +1,14 @@
+2005-09-28  P. S. Chakravarthi <pchakravarthi novell com>
+
+	Fixes #269685
+	* gui/alarm-notify/alarm-queue.c 
+	(update_cqa): added.
+	(update_qa): added.
+	(query_objects_changed_cb): Used the above two newly
+	added functions to update the local alarm structures
+	viz. CompQueuedAlarms and QueuedAlarm, whenever there
+	are non-time related changes in a calendar component. 
+	
 2005-09-08  P. S. Chakravarthi <pchakravarthi novell com>
 
 	Fix #261625
Index: gui/alarm-notify/alarm-queue.c
===================================================================
RCS file: /cvs/gnome/evolution/calendar/gui/alarm-notify/alarm-queue.c,v
retrieving revision 1.87
diff -u -p -r1.87 alarm-queue.c
--- gui/alarm-notify/alarm-queue.c	16 May 2005 06:12:59 -0000	1.87
+++ gui/alarm-notify/alarm-queue.c	28 Sep 2005 04:49:18 -0000
@@ -119,6 +119,9 @@ typedef struct {
 	/* Instance from our parent CompQueuedAlarms->alarms->alarms list */
 	ECalComponentAlarmInstance *instance;
 
+	/* original trigger of the instance from component */
+	time_t orig_trigger;
+
 	/* Whether this is a snoozed queued alarm or a normal one */
 	guint snooze : 1;
 } QueuedAlarm;
@@ -139,8 +142,8 @@ static void query_objects_changed_cb (EC
 static void query_objects_removed_cb (ECal *client, GList *objects, gpointer data);
 
 static void remove_client_alarms (ClientAlarms *ca);
-
-
+static void update_cqa (CompQueuedAlarms *cqa, ECalComponent *comp);
+static void update_qa (ECalComponentAlarms *alarms, QueuedAlarm *qa); 
 
 /* Alarm queue engine */
 
@@ -376,6 +379,7 @@ add_component_alarms (ClientAlarms *ca, 
 		qa = g_new (QueuedAlarm, 1);
 		qa->alarm_id = alarm_id;
 		qa->instance = instance;
+		qa->orig_trigger = instance->trigger;
 		qa->snooze = FALSE;
 
 		cqa->queued_alarms = g_slist_prepend (cqa->queued_alarms, qa);
@@ -536,6 +540,7 @@ remove_comp (ClientAlarms *ca, const cha
 /* Called when a calendar component changes; we must reload its corresponding
  * alarms.
  */
+
 static void
 query_objects_changed_cb (ECal *client, GList *objects, gpointer data)
 {
@@ -580,8 +585,17 @@ query_objects_changed_cb (ECal *client, 
 		}
 
 		g_message ("Already existing alarms");
-		/* if the alarms or the alarms list is empty, just remove it */
+
+		/* if the alarms or the alarms list is empty remove it after updating the cqa structure */
 		if (alarms == NULL || alarms->alarms == NULL) {
+		
+			/* update the cqa and its queued alarms for changes in summary and alarm_uid  */
+			ECalComponent *newcomp = e_cal_component_new ();
+			if (!e_cal_component_set_icalcomponent (newcomp, icalcomponent_new_clone (l->data)))
+				g_message ("couldn't update calendar component with modified data from backend\n");
+
+			update_cqa (cqa, newcomp);
+
 			if (alarms)
 				e_cal_component_alarms_free (alarms);
 			continue;
@@ -611,7 +625,7 @@ query_objects_changed_cb (ECal *client, 
 			qa->alarm_id = alarm_id;
 			qa->instance = instance;
 			qa->snooze = FALSE;
-			
+			qa->orig_trigger = instance->trigger;	
 			cqa->queued_alarms = g_slist_prepend (cqa->queued_alarms, qa);
 		}
 		
@@ -1525,3 +1539,75 @@ alarm_queue_remove_client (ECal *client)
 
 	g_hash_table_remove (client_alarms_hash, client);
 }
+
+/* Update non-time related variables for various structures on modification of an existing component 
+   to be called only from query_objects_changed_cb */
+static 
+void update_cqa (CompQueuedAlarms *cqa, ECalComponent *newcomp)
+{
+	ECalComponent *oldcomp;
+	ECalComponentAlarms *alarms;
+	GSList *qa_list;	/* List of current QueuedAlarms corresponding to cqa */
+	time_t from, to;
+	icaltimezone *zone;
+	char *uid;
+
+	g_return_if_fail (cqa != NULL);
+	g_return_if_fail (cqa->alarms != NULL);
+	g_return_if_fail (cqa->alarms->comp != NULL);
+
+	oldcomp = cqa->alarms->comp;
+	e_cal_component_get_uid (newcomp, (const char **)&uid); 
+
+	zone = config_data_get_timezone ();
+	from = time_day_begin_with_zone (time (NULL), zone);
+	to = time_day_end_with_zone (time (NULL), zone);
+
+	g_message ("Getting all alarms for modified component\n");
+	if (!e_cal_get_alarms_for_object (cqa->parent_client->client, uid, from, to, &alarms))
+		g_message ("No alarms found on the modified component\n");
+
+	g_return_if_fail (alarms != NULL);
+
+	/* Update auids in Queued Alarms*/
+	for (qa_list = cqa->queued_alarms; qa_list; qa_list = qa_list->next) {
+ 
+		QueuedAlarm *qa = qa_list->data;
+		char *check_auid = (char *) qa->instance->auid;
+
+		if (e_cal_component_get_alarm (newcomp, check_auid))
+			continue;
+		else {
+			if (e_cal_component_get_alarm (oldcomp, check_auid)) 
+				update_qa (alarms, qa);
+			else
+				g_message ("Failed in auid lookup for old component also\n");
+		}		
+	}
+
+	/* Update the actual component stored in CompQueuedAlarms structure */
+	g_object_unref (cqa->alarms->comp);
+	cqa->alarms->comp = newcomp;
+	e_cal_component_alarms_free (alarms);
+}
+
+static
+void update_qa (ECalComponentAlarms *alarms, QueuedAlarm *qa)
+{
+	char *auid;
+	ECalComponentAlarmInstance *al_inst;
+	GSList *instance_list;
+	time_t trigger;
+	
+	g_return_if_fail (qa != NULL);
+	g_return_if_fail (alarms != NULL);
+
+	for (instance_list = alarms->alarms; instance_list; instance_list = instance_list->next) {
+		al_inst = instance_list->data;
+		if (al_inst->trigger == qa->orig_trigger) {  /* FIXME if two or more alarm instances (audio, note) 									  for same component have same trigger */
+			g_free (qa->instance->auid);
+			qa->instance->auid = g_strdup (al_inst->auid);
+			break;
+		}
+	}
+}	


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