New; tell each query about a created/modified/removed object.

* 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.

svn path=/trunk/; revision=23102
This commit is contained in:
Dan Winship
2003-10-28 13:32:55 +00:00
parent 196efb7acc
commit 179cdf3686
8 changed files with 171 additions and 118 deletions

View File

@ -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 JP Rosevear <jpr@ximian.com>
* gui/gnome-cal.c (setup_widgets): store config objects as well

View File

@ -1579,8 +1579,7 @@ check_tzids (icalparameter *param, void *data)
/* 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 @@ cal_backend_file_receive_objects (CalBackendSync *backend, Cal *cal, const char
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 @@ cal_backend_file_receive_objects (CalBackendSync *backend, Cal *cal, const char
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;

View File

@ -149,15 +149,13 @@ cal_backend_sync_discard_alarm (CalBackendSync *backend, Cal *cal, const char *u
}
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 @@ static void
_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

View File

@ -48,7 +48,7 @@ struct _CalBackendSyncClass {
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_discard_alarm (CalBackendSync *backend, Ca
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);

View File

@ -896,6 +896,129 @@ cal_backend_internal_get_timezone (CalBackend *backend, const char *tzid)
return (* CLASS (backend)->internal_get_timezone) (backend, tzid);
}
/**
* 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.

View File

@ -160,6 +160,10 @@ icaltimezone* cal_backend_internal_get_timezone (CalBackend *backend, const char
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);

View File

@ -768,8 +768,6 @@ cal_notify_object_created (Cal *cal, GNOME_Evolution_Calendar_CallStatus status,
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 @@ cal_notify_object_created (Cal *cal, GNOME_Evolution_Calendar_CallStatus status,
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 @@ cal_notify_object_modified (Cal *cal, GNOME_Evolution_Calendar_CallStatus status
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 @@ cal_notify_object_modified (Cal *cal, GNOME_Evolution_Calendar_CallStatus status
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 @@ cal_notify_object_removed (Cal *cal, GNOME_Evolution_Calendar_CallStatus status,
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 @@ cal_notify_object_removed (Cal *cal, GNOME_Evolution_Calendar_CallStatus status,
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 @@ cal_notify_object_removed (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)
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);
@ -921,25 +850,6 @@ cal_notify_objects_received (Cal *cal, GNOME_Evolution_Calendar_CallStatus statu
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);

View File

@ -81,8 +81,7 @@ void cal_notify_object_removed (Cal *cal, GNOME_Evolution_Calendar_CallStatus st
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);