[evolution-patches] calendar head patch



(This is for head, I just want to give rodrigo/hpj a chance to comment
on it.)

The first part of this is to add convenience functions to notify each
Query about new/changed/removed objects (eg, when the exchange backend
notices that someone else has made a change to the folder). While doing
that, I noticed that the calendar code had the same problem the
addressbook code had before, which is that in some cases, when a contact
was modified, it would be passed as "modified" to all Queries, rather
than being checked against each Query's sexp to see if the change
resulted in the object being added to or removed from the view. I fixed
that by making cal_notify_objects_received not take lists of changes any
more.


Index: ChangeLog
===================================================================
RCS file: /cvs/gnome/evolution/calendar/ChangeLog,v
retrieving revision 1.1905
diff -u -r1.1905 ChangeLog
--- ChangeLog	27 Oct 2003 13:11:49 -0000	1.1905
+++ ChangeLog	27 Oct 2003 20:09:33 -0000
@@ -1,3 +1,28 @@
+2003-10-27  Dan Winship  <danw ximian com>
+
+	* pcs/cal-backend.c (cal_backend_notify_object_created,
+	cal_backend_notify_object_modified,
+	cal_backend_notify_object_removed): New; tell each query about a
+	created/modified/removed object.
+
+	* pcs/cal.c (cal_notify_object_created): Use
+	cal_backend_notify_object_created.
+	(cal_notify_object_modified, cal_notify_object_removed): Likewise
+	for modified/removed
+	(cal_notify_objects_received): we need both the before and after
+	forms for the modified objects so they can be resolved as
+	adds/modifies/removes per-query. But the caller can just call the
+	cal_backend_* routines for each object anyway, so just remove the
+	created/modified/removed lists.
+
+	* pcs/cal-backend-sync.c (cal_backend_sync_receive_objects):
+	Remove created/modified/removed list arguments.
+	(_cal_backend_receive_objects): Likewise.
+
+	* pcs/cal-backend-file.c (cal_backend_file_receive_objects):
+	Remove created/modified/removed list arguments. Replace the one
+	use of *removed with a call to cal_backend_notify_object_removed.
+
 2003-10-27  Rodrigo Moya <rodrigo ximian com>
 
 	* gui/e-cal-model.h: changed fill_component_from_model virtual
Index: pcs/cal-backend-file.c
===================================================================
RCS file: /cvs/gnome/evolution/calendar/pcs/cal-backend-file.c,v
retrieving revision 1.85
diff -u -r1.85 cal-backend-file.c
--- pcs/cal-backend-file.c	24 Oct 2003 15:00:10 -0000	1.85
+++ pcs/cal-backend-file.c	27 Oct 2003 20:09:34 -0000
@@ -1579,8 +1579,7 @@
 
 /* Update_objects handler for the file backend. */
 static CalBackendSyncStatus
-cal_backend_file_receive_objects (CalBackendSync *backend, Cal *cal, const char *calobj,
-				  GList **created, GList **modified, GList **removed)
+cal_backend_file_receive_objects (CalBackendSync *backend, Cal *cal, const char *calobj)
 {
 	CalBackendFile *cbfile;
 	CalBackendFilePrivate *priv;
@@ -1613,8 +1612,6 @@
 
 	method = icalcomponent_get_method (toplevel_comp);
 
-	*created = *modified = *removed = NULL;
-
 	/* Build a list of timezones so we can make sure all the objects have valid info */
 	tzdata.zones = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, NULL);
 
@@ -1689,8 +1686,10 @@
 			break;
 		case ICAL_METHOD_CANCEL:
 			/* FIXME Do we need to remove the subcomp so it isn't merged? */
-			if (cancel_received_object (cbfile, subcomp))
-				*removed = g_list_prepend (*removed, g_strdup (icalcomponent_get_uid (subcomp)));
+			if (cancel_received_object (cbfile, subcomp)) {
+				const char *calobj = icalcomponent_as_ical_string (subcomp);
+				cal_backend_notify_object_removed (CAL_BACKEND (backend), icalcomponent_get_uid (subcomp), calobj);
+			}
 			break;
 		default:
 			status = GNOME_Evolution_Calendar_UnsupportedMethod;
Index: pcs/cal-backend-sync.c
===================================================================
RCS file: /cvs/gnome/evolution/calendar/pcs/cal-backend-sync.c,v
retrieving revision 1.4
diff -u -r1.4 cal-backend-sync.c
--- pcs/cal-backend-sync.c	24 Oct 2003 15:00:10 -0000	1.4
+++ pcs/cal-backend-sync.c	27 Oct 2003 20:09:34 -0000
@@ -149,15 +149,13 @@
 }
 
 CalBackendSyncStatus
-cal_backend_sync_receive_objects (CalBackendSync *backend, Cal *cal, const char *calobj,
-				  GList **created, GList **modified, GList **removed)
+cal_backend_sync_receive_objects (CalBackendSync *backend, Cal *cal, const char *calobj)
 {
 	g_return_val_if_fail (backend && CAL_IS_BACKEND_SYNC (backend), GNOME_Evolution_Calendar_OtherError);
 
 	g_assert (CAL_BACKEND_SYNC_GET_CLASS (backend)->receive_objects_sync);
 
-	return (* CAL_BACKEND_SYNC_GET_CLASS (backend)->receive_objects_sync) (backend, cal, calobj, 
-									       created, modified, removed);
+	return (* CAL_BACKEND_SYNC_GET_CLASS (backend)->receive_objects_sync) (backend, cal, calobj);
 }
 
 CalBackendSyncStatus
@@ -393,12 +391,10 @@
 _cal_backend_receive_objects (CalBackend *backend, Cal *cal, const char *calobj)
 {
 	CalBackendSyncStatus status;
-	GList *created = NULL, *modified = NULL, *removed = NULL;
 	
-	status = cal_backend_sync_receive_objects (CAL_BACKEND_SYNC (backend), cal, calobj, 
-						   &created, &modified, &removed);
+	status = cal_backend_sync_receive_objects (CAL_BACKEND_SYNC (backend), cal, calobj);
 
-	cal_notify_objects_received (cal, status, created, modified, removed);
+	cal_notify_objects_received (cal, status);
 }
 
 static void
Index: pcs/cal-backend-sync.h
===================================================================
RCS file: /cvs/gnome/evolution/calendar/pcs/cal-backend-sync.h,v
retrieving revision 1.3
diff -u -r1.3 cal-backend-sync.h
--- pcs/cal-backend-sync.h	24 Oct 2003 15:00:10 -0000	1.3
+++ pcs/cal-backend-sync.h	27 Oct 2003 20:09:34 -0000
@@ -48,7 +48,7 @@
 
 	CalBackendSyncStatus (*discard_alarm_sync)  (CalBackendSync *backend, Cal *cal, const char *uid, const char *auid);
 
-	CalBackendSyncStatus (*receive_objects_sync)  (CalBackendSync *backend, Cal *cal, const char *calobj, GList **created, GList **modified, GList **removed);
+	CalBackendSyncStatus (*receive_objects_sync)  (CalBackendSync *backend, Cal *cal, const char *calobj);
 	CalBackendSyncStatus (*send_objects_sync)  (CalBackendSync *backend, Cal *cal, const char *calobj);
 
 	CalBackendSyncStatus (*get_default_object_sync)  (CalBackendSync *backend, Cal *cal, char **object);
@@ -112,10 +112,7 @@
 
 CalBackendSyncStatus cal_backend_sync_receive_objects         (CalBackendSync  *backend,
 							       Cal             *cal,
-							       const char      *calobj,
-							       GList          **created,
-							       GList          **modified,
-							       GList          **removed);
+							       const char      *calobj);
 CalBackendSyncStatus cal_backend_sync_send_objects            (CalBackendSync  *backend,
 							       Cal             *cal,
 							       const char      *calobj);
Index: pcs/cal-backend.c
===================================================================
RCS file: /cvs/gnome/evolution/calendar/pcs/cal-backend.c,v
retrieving revision 1.98
diff -u -r1.98 cal-backend.c
--- pcs/cal-backend.c	24 Oct 2003 15:00:10 -0000	1.98
+++ pcs/cal-backend.c	27 Oct 2003 20:09:34 -0000
@@ -897,6 +897,129 @@
 }
 
 /**
+ * cal_backend_notify_object_created:
+ * @backend: A calendar backend.
+ * @calobj: iCalendar representation of new object
+ *
+ * Notifies each of the backend's listeners about a new object.
+ *
+ * cal_notify_object_created() calls this for you. You only need to
+ * call cal_backend_notify_object_created() yourself to report objects
+ * created by non-PCS clients.
+ **/
+void
+cal_backend_notify_object_created (CalBackend *backend, const char *calobj)
+{
+	EList *queries;
+	EIterator *iter;
+	Query *query;
+
+	queries = cal_backend_get_queries (backend);
+	iter = e_list_get_iterator (queries);
+
+	while (e_iterator_is_valid (iter)) {
+		query = QUERY (e_iterator_get (iter));
+
+		bonobo_object_ref (query);
+		if (query_object_matches (query, calobj))		
+			query_notify_objects_added_1 (query, calobj);
+		bonobo_object_unref (query);
+
+		e_iterator_next (iter);
+	}
+	g_object_unref (iter);
+	g_object_unref (queries);
+}
+
+/**
+ * cal_backend_notify_object_modified:
+ * @backend: A calendar backend.
+ * @old_object: iCalendar representation of the original form of the object
+ * @object: iCalendar representation of the new form of the object
+ *
+ * Notifies each of the backend's listeners about a modified object.
+ *
+ * cal_notify_object_modified() calls this for you. You only need to
+ * call cal_backend_notify_object_modified() yourself to report objects
+ * modified by non-PCS clients.
+ **/
+void
+cal_backend_notify_object_modified (CalBackend *backend, 
+				    const char *old_object, const char *object)
+{
+	EList *queries;
+	EIterator *iter;
+	Query *query;
+	gboolean old_match, new_match;
+
+	queries = cal_backend_get_queries (backend);
+	iter = e_list_get_iterator (queries);
+
+	while (e_iterator_is_valid (iter)) {
+		query = QUERY (e_iterator_get (iter));
+		
+		bonobo_object_ref (query);
+
+		old_match = query_object_matches (query, old_object);
+		new_match = query_object_matches (query, object);
+		if (old_match && new_match)
+			query_notify_objects_modified_1 (query, object);
+		else if (new_match)
+			query_notify_objects_added_1 (query, object);
+		else /* if (old_match) */ {
+			icalcomponent *comp;
+
+			comp = icalcomponent_new_from_string ((char *)old_object);
+			query_notify_objects_removed_1 (query, icalcomponent_get_uid (comp));
+			icalcomponent_free (comp);
+		}
+
+		bonobo_object_unref (query);
+
+		e_iterator_next (iter);
+	}
+	g_object_unref (iter);
+	g_object_unref (queries);
+}
+
+/**
+ * cal_backend_notify_object_removed:
+ * @backend: A calendar backend.
+ * @uid: the UID of the removed object
+ * @old_object: iCalendar representation of the removed object
+ *
+ * Notifies each of the backend's listeners about a removed object.
+ *
+ * cal_notify_object_removed() calls this for you. You only need to
+ * call cal_backend_notify_object_removed() yourself to report objects
+ * removed by non-PCS clients.
+ **/
+void
+cal_backend_notify_object_removed (CalBackend *backend, const char *uid,
+				   const char *old_object)
+{
+	EList *queries;
+	EIterator *iter;
+	Query *query;
+
+	queries = cal_backend_get_queries (backend);
+	iter = e_list_get_iterator (queries);
+
+	while (e_iterator_is_valid (iter)) {
+		query = QUERY (e_iterator_get (iter));
+
+		bonobo_object_ref (query);
+		if (query_object_matches (query, old_object))
+			query_notify_objects_removed_1 (query, uid);
+		bonobo_object_unref (query);
+
+		e_iterator_next (iter);
+	}
+	g_object_unref (iter);
+	g_object_unref (queries);
+}
+
+/**
  * cal_backend_notify_mode:
  * @backend: A calendar backend.
  * @status: Status of the mode set
Index: pcs/cal-backend.h
===================================================================
RCS file: /cvs/gnome/evolution/calendar/pcs/cal-backend.h,v
retrieving revision 1.62
diff -u -r1.62 cal-backend.h
--- pcs/cal-backend.h	24 Oct 2003 15:00:11 -0000	1.62
+++ pcs/cal-backend.h	27 Oct 2003 20:09:34 -0000
@@ -160,6 +160,10 @@
 
 void cal_backend_last_client_gone (CalBackend *backend);
 
+void cal_backend_notify_object_created  (CalBackend *backend, const char *calobj);
+void cal_backend_notify_object_modified (CalBackend *backend, const char *old_object, const char *object);
+void cal_backend_notify_object_removed  (CalBackend *backend, const char *uid, const char *old_object);
+
 void cal_backend_notify_mode      (CalBackend *backend,
 				   GNOME_Evolution_Calendar_Listener_SetModeStatus status, 
 				   GNOME_Evolution_Calendar_CalMode mode);
Index: pcs/cal.c
===================================================================
RCS file: /cvs/gnome/evolution/calendar/pcs/cal.c,v
retrieving revision 1.77
diff -u -r1.77 cal.c
--- pcs/cal.c	24 Oct 2003 15:00:11 -0000	1.77
+++ pcs/cal.c	27 Oct 2003 20:09:34 -0000
@@ -768,8 +768,6 @@
 			   const char *uid, const char *object)
 {
 	CalPrivate *priv;
-	EList *queries;
-	EIterator *iter;
 	CORBA_Environment ev;
 
 	g_return_if_fail (cal != NULL);
@@ -778,25 +776,8 @@
 	priv = cal->priv;
 	g_return_if_fail (priv->listener != CORBA_OBJECT_NIL);
 
-	queries = cal_backend_get_queries (priv->backend);
-	iter = e_list_get_iterator (queries);
-
-	while (e_iterator_is_valid (iter)) {
-		Query *query = QUERY (e_iterator_get (iter));
-		
-		bonobo_object_dup_ref (BONOBO_OBJREF (query), NULL);
-		
-		if (!query_object_matches (query, object))
-			continue;
-		
-		query_notify_objects_added_1 (query, object);
-
-		bonobo_object_release_unref (BONOBO_OBJREF (query), NULL);
-
-		e_iterator_next (iter);
-	}
-	g_object_unref (iter);
-	g_object_unref (queries);
+	if (status == GNOME_Evolution_Calendar_Success)
+		cal_backend_notify_object_created (priv->backend, object);
 
 	CORBA_exception_init (&ev);
 	GNOME_Evolution_Calendar_Listener_notifyObjectCreated (priv->listener, status, uid ? uid : "", &ev);
@@ -812,8 +793,6 @@
 			    const char *old_object, const char *object)
 {
 	CalPrivate *priv;
-	EList *queries;
-	EIterator *iter;
 	CORBA_Environment ev;
 
 	g_return_if_fail (cal != NULL);
@@ -822,36 +801,8 @@
 	priv = cal->priv;
 	g_return_if_fail (priv->listener != CORBA_OBJECT_NIL);
 
-	queries = cal_backend_get_queries (priv->backend);
-	iter = e_list_get_iterator (queries);
-
-	while (object && old_object && e_iterator_is_valid (iter)) {
-		Query *query = QUERY (e_iterator_get (iter));
-		gboolean old_match, new_match;
-		
-		bonobo_object_dup_ref (BONOBO_OBJREF (query), NULL);
-
-		old_match = query_object_matches (query, old_object);
-		new_match = query_object_matches (query, object);
-		if (old_match && new_match)
-			query_notify_objects_modified_1 (query, object);
-		else if (new_match)
-			query_notify_objects_added_1 (query, object);
-		else /* if (old_match) */ {
-			icalcomponent *comp;
-
-			comp = icalcomponent_new_from_string ((char *)old_object);
-			query_notify_objects_removed_1 (query, icalcomponent_get_uid (comp));
-			icalcomponent_free (comp);
-		}
-		query_notify_query_done (query, GNOME_Evolution_Calendar_Success);
-
-		bonobo_object_release_unref (BONOBO_OBJREF (query), NULL);
-
-		e_iterator_next (iter);
-	}
-	g_object_unref (iter);
-	g_object_unref (queries);
+	if (status == GNOME_Evolution_Calendar_Success)
+		cal_backend_notify_object_modified (priv->backend, old_object, object);
 
 	CORBA_exception_init (&ev);
 	GNOME_Evolution_Calendar_Listener_notifyObjectModified (priv->listener, status, &ev);
@@ -867,8 +818,6 @@
 			   const char *uid, const char *object)
 {
 	CalPrivate *priv;
-	EList *queries;
-	EIterator *iter;
 	CORBA_Environment ev;
 
 	g_return_if_fail (cal != NULL);
@@ -877,25 +826,8 @@
 	priv = cal->priv;
 	g_return_if_fail (priv->listener != CORBA_OBJECT_NIL);
 
-	queries = cal_backend_get_queries (priv->backend);
-	iter = e_list_get_iterator (queries);
-
-	while (uid && object && e_iterator_is_valid (iter)) {
-		Query *query = QUERY (e_iterator_get (iter));
-
-		bonobo_object_dup_ref (BONOBO_OBJREF (query), NULL);
-
-		if (!query_object_matches (query, object))
-			continue;
-
-		query_notify_objects_removed_1 (query, uid);
-
-		bonobo_object_release_unref (BONOBO_OBJREF (query), NULL);
-
-		e_iterator_next (iter);
-	}
-	g_object_unref (iter);
-	g_object_unref (queries);
+	if (status == GNOME_Evolution_Calendar_Success)
+		cal_backend_notify_object_removed (priv->backend, uid, object);
 
 	CORBA_exception_init (&ev);
 	GNOME_Evolution_Calendar_Listener_notifyObjectRemoved (priv->listener, status, &ev);
@@ -907,12 +839,9 @@
 }
 
 void
-cal_notify_objects_received (Cal *cal, GNOME_Evolution_Calendar_CallStatus status, 
-			     GList *created, GList *modified, GList *removed)
+cal_notify_objects_received (Cal *cal, GNOME_Evolution_Calendar_CallStatus status)
 {
 	CalPrivate *priv;
-	EList *queries;
-	EIterator *iter;
 	CORBA_Environment ev;
 
 	g_return_if_fail (cal != NULL);
@@ -920,25 +849,6 @@
 
 	priv = cal->priv;
 	g_return_if_fail (priv->listener != CORBA_OBJECT_NIL);
-
-	queries = cal_backend_get_queries (priv->backend);
-	iter = e_list_get_iterator (queries);
-
-	while (e_iterator_is_valid (iter)) {
-		Query *query = QUERY (e_iterator_get (iter));
-
-		bonobo_object_dup_ref (BONOBO_OBJREF (query), NULL);
-
-		query_notify_objects_added (query, created);
-		query_notify_objects_modified (query, modified);
-		query_notify_objects_removed (query, removed);
-
-		bonobo_object_release_unref (BONOBO_OBJREF (query), NULL);
-
-		e_iterator_next (iter);
-	}
-	g_object_unref (iter);
-	g_object_unref (queries);
 
 	CORBA_exception_init (&ev);
 	GNOME_Evolution_Calendar_Listener_notifyObjectsReceived (priv->listener, status, &ev);
Index: pcs/cal.h
===================================================================
RCS file: /cvs/gnome/evolution/calendar/pcs/cal.h,v
retrieving revision 1.23
diff -u -r1.23 cal.h
--- pcs/cal.h	21 Oct 2003 18:51:04 -0000	1.23
+++ pcs/cal.h	27 Oct 2003 20:09:34 -0000
@@ -81,8 +81,7 @@
 				const char *uid, const char *object);
 void cal_notify_alarm_discarded (Cal *cal, GNOME_Evolution_Calendar_CallStatus status);
 
-void cal_notify_objects_received (Cal *cal, GNOME_Evolution_Calendar_CallStatus status, 
-				  GList *created, GList *modified, GList *removed);
+void cal_notify_objects_received (Cal *cal, GNOME_Evolution_Calendar_CallStatus status);
 void cal_notify_objects_sent (Cal *cal, GNOME_Evolution_Calendar_CallStatus status);
 
 void cal_notify_default_object (Cal *cal, GNOME_Evolution_Calendar_CallStatus status, char *object);


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