diff options
author | Federico Mena Quintero <federico@helixcode.com> | 2000-02-12 10:03:58 +0800 |
---|---|---|
committer | Arturo Espinosa <unammx@src.gnome.org> | 2000-02-12 10:03:58 +0800 |
commit | d2fe58c56857e9e4b2e37f87174da6956b0d985c (patch) | |
tree | e71df413e8a7862616755f64700b1dbbc513f9be /calendar/pcs | |
parent | 123f506198c535dcb073c1998fed37c25ad131f9 (diff) | |
download | gsoc2013-evolution-d2fe58c56857e9e4b2e37f87174da6956b0d985c.tar.gz gsoc2013-evolution-d2fe58c56857e9e4b2e37f87174da6956b0d985c.tar.zst gsoc2013-evolution-d2fe58c56857e9e4b2e37f87174da6956b0d985c.zip |
Implemented.
2000-02-11 Federico Mena Quintero <federico@helixcode.com>
* cal-client.c (cal_client_update_object): Implemented.
* cal.c (cal_notify_update): New function to notify the listener
about an updated object.
(Cal_update_object): Implemented.
(Cal_get_uids): set_release() the sequence to TRUE.
(Cal_get_events_in_range): Likewise.
* cal-backend.c (remove_object): New function to remove objects
from a calendar backend.
(cal_backend_update_object): New public function to update an
object and notify clients about it.
* evolution-calendar.idl (Cal): Added update_object() and
delete_object() methods.
(Listener): Removed the obj_changed method and renamed obj_added
to obj_updated. We now only have updated and removed notifiers.
* cal-listener.[ch]: Removed the "changed" notification code.
Changed the "added" notification code to the "updated"
notification.
* cal-client.c: Likewise.
* tlacuache.c (create_cal_factory): Connect to "destroy" on the
factory and exit the main loop when the factory is destroyed.
* cal-factory.c (backend_destroy_cb): New callback used when a
backend is destroyed. Removes the backend from the factory's hash
table and unrefs the factory if all backends go away.
(add_calendar_client): Free the environment.
* cal.c (cal_new): Use bonobo_object_unref() if we fail to
initialize.
* cal-listener.c (cal_listener_new): Likewise.
* layout.c (layout_events): Plug li.partition memory leak.
svn path=/trunk/; revision=1742
Diffstat (limited to 'calendar/pcs')
-rw-r--r-- | calendar/pcs/cal-backend.c | 139 | ||||
-rw-r--r-- | calendar/pcs/cal-backend.h | 4 | ||||
-rw-r--r-- | calendar/pcs/cal-factory.c | 49 | ||||
-rw-r--r-- | calendar/pcs/cal.c | 57 | ||||
-rw-r--r-- | calendar/pcs/cal.h | 2 | ||||
-rw-r--r-- | calendar/pcs/tlacuache.c | 19 |
6 files changed, 258 insertions, 12 deletions
diff --git a/calendar/pcs/cal-backend.c b/calendar/pcs/cal-backend.c index 18ed6a6c86..1ce4b615c3 100644 --- a/calendar/pcs/cal-backend.c +++ b/calendar/pcs/cal-backend.c @@ -197,6 +197,19 @@ cal_backend_destroy (GtkObject *object) /* iCalObject manipulation functions */ +/* Looks up an object by its UID in the backend's object hash table */ +static iCalObject * +lookup_object (CalBackend *backend, const char *uid) +{ + CalBackendPrivate *priv; + iCalObject *ico; + + priv = backend->priv; + ico = g_hash_table_lookup (priv->object_hash, uid); + + return ico; +} + /* Ensures that an iCalObject has a unique identifier. If it doesn't have one, * it will create one for it. Returns whether an UID was created or not. */ @@ -275,6 +288,49 @@ add_object (CalBackend *backend, iCalObject *ico) #endif } +/* Removes an object from the backend's hash and lists. Does not perform + * notification on the clients. + */ +static void +remove_object (CalBackend *backend, iCalObject *ico) +{ + CalBackendPrivate *priv; + GList **list, *l; + + priv = backend->priv; + + g_assert (ico->uid != NULL); + g_hash_table_remove (priv->object_hash, ico->uid); + + switch (ico->type) { + case ICAL_EVENT: + list = &priv->events; + break; + + case ICAL_TODO: + list = &priv->todos; + break; + + case ICAL_JOURNAL: + list = &priv->journals; + break; + + default: + list = NULL; + } + + if (!list) + return; + + l = g_list_find (*list, ico); + g_assert (l != NULL); + + *list = g_list_remove_link (*list, l); + g_list_free_1 (l); + + ical_object_destroy (ico); +} + /* Load a calendar from a VObject */ static void load_from_vobject (CalBackend *backend, VObject *vobject) @@ -609,7 +665,7 @@ cal_backend_get_object (CalBackend *backend, const char *uid) g_assert (priv->object_hash != NULL); - ico = g_hash_table_lookup (priv->object_hash, uid); + ico = lookup_object (backend, uid); if (!ico) return NULL; @@ -782,3 +838,84 @@ cal_backend_get_events_in_range (CalBackend *backend, time_t start, time_t end) c.event_list = g_list_sort (c.event_list, compare_instance_func); return c.event_list; } + +/* Notifies a backend's clients that an object was updated */ +static void +notify_update (CalBackend *backend, const char *uid) +{ + CalBackendPrivate *priv; + GList *l; + + priv = backend->priv; + + for (l = priv->clients; l; l = l->next) { + Cal *cal; + + cal = CAL (l->data); + cal_notify_update (cal, uid); + } +} + +/** + * cal_backend_update_object: + * @backend: A calendar backend. + * @uid: Unique identifier of the object to update. + * @calobj: String representation of the new calendar object. + * + * Updates an object in a calendar backend. It will replace any existing object + * that has the same UID as the specified one. The backend will in turn notify + * all of its clients about the change. + * + * Return value: TRUE on success, FALSE on being passed an invalid object. + **/ +gboolean +cal_backend_update_object (CalBackend *backend, const char *uid, const char *calobj) +{ + CalBackendPrivate *priv; + iCalObject *ico, *new_ico; + CalObjFindStatus status; + + g_return_val_if_fail (backend != NULL, FALSE); + g_return_val_if_fail (IS_CAL_BACKEND (backend), FALSE); + + priv = backend->priv; + g_return_val_if_fail (priv->loaded, FALSE); + + g_return_val_if_fail (uid != NULL, FALSE); + g_return_val_if_fail (calobj != NULL, FALSE); + + /* Pull the object from the string */ + + status = ical_object_find_in_string (uid, calobj, &new_ico); + + if (status != CAL_OBJ_FIND_SUCCESS) + return FALSE; + + /* Update the object */ + + ico = lookup_object (backend, uid); + + if (ico) + remove_object (backend, ico); + + add_object (backend, new_ico); + + notify_update (backend, new_ico->uid); + return TRUE; +} + +void +cal_backend_remove_object (CalBackend *backend, const char *uid) +{ + CalBackendPrivate *priv; + + g_return_if_fail (backend != NULL); + g_return_if_fail (IS_CAL_BACKEND (backend)); + + priv = backend->priv; + g_return_if_fail (priv->loaded); + + g_return_if_fail (uid != NULL); + + /* FIXME */ +} diff --git a/calendar/pcs/cal-backend.h b/calendar/pcs/cal-backend.h index 41b2b9186d..fab83e4b82 100644 --- a/calendar/pcs/cal-backend.h +++ b/calendar/pcs/cal-backend.h @@ -76,6 +76,10 @@ GList *cal_backend_get_uids (CalBackend *backend, CalObjType type); GList *cal_backend_get_events_in_range (CalBackend *backend, time_t start, time_t end); +gboolean cal_backend_update_object (CalBackend *backend, const char *uid, const char *calobj); + +void cal_backend_remove_object (CalBackend *backend, const char *uid); + END_GNOME_DECLS diff --git a/calendar/pcs/cal-factory.c b/calendar/pcs/cal-factory.c index 14b7ac9cb6..a170718678 100644 --- a/calendar/pcs/cal-factory.c +++ b/calendar/pcs/cal-factory.c @@ -20,6 +20,7 @@ */ #include <config.h> +#include <gtk/gtksignal.h> #include "cal.h" #include "cal-backend.h" #include "cal-factory.h" @@ -139,6 +140,8 @@ cal_factory_destroy (GtkObject *object) factory = CAL_FACTORY (object); priv = factory->priv; + /* Should we assert that there are no more backends? */ + g_hash_table_foreach (priv->backends, free_backend, NULL); g_hash_table_destroy (priv->backends); priv->backends = NULL; @@ -244,6 +247,41 @@ lookup_backend (CalFactory *factory, GnomeVFSURI *uri) return backend; } +/* Callback used when a backend is destroyed */ +static void +backend_destroy_cb (GtkObject *object, gpointer data) +{ + CalFactory *factory; + CalFactoryPrivate *priv; + CalBackend *backend; + GnomeVFSURI *uri; + gpointer orig_key; + gboolean result; + GnomeVFSURI *orig_uri; + + factory = CAL_FACTORY (data); + priv = factory->priv; + + /* Remove the backend from the hash table */ + + backend = CAL_BACKEND (object); + uri = cal_backend_get_uri (backend); + g_assert (uri != NULL); + + result = g_hash_table_lookup_extended (priv->backends, uri, &orig_key, NULL); + g_assert (result != FALSE); + + orig_uri = orig_key; + + g_hash_table_remove (priv->backends, orig_uri); + gnome_vfs_uri_unref (orig_uri); + + /* If there are no more backends, then the factory can go away */ + + if (g_hash_table_size (priv->backends) == 0) + bonobo_object_unref (BONOBO_OBJECT (factory)); +} + /* Adds a backend to the calendar factory's hash table */ static void add_backend (CalFactory *factory, GnomeVFSURI *uri, CalBackend *backend) @@ -254,9 +292,10 @@ add_backend (CalFactory *factory, GnomeVFSURI *uri, CalBackend *backend) gnome_vfs_uri_ref (uri); g_hash_table_insert (priv->backends, uri, backend); - /* FIXME: connect to destroy on the backend and remove it from - * the hash table when it dies. - */ + + gtk_signal_connect (GTK_OBJECT (backend), "destroy", + GTK_SIGNAL_FUNC (backend_destroy_cb), + factory); } /* Loads a calendar backend and puts it in the factory's backend hash table */ @@ -350,6 +389,8 @@ add_calendar_client (CalFactory *factory, CalBackend *backend, Evolution_Calenda g_message ("add_calendar_client(): could not notify the listener"); bonobo_object_unref (BONOBO_OBJECT (cal)); } + + CORBA_exception_free (&ev); } /* Job handler for the load calendar command */ @@ -566,7 +607,7 @@ cal_factory_new (void) if (ev._major != CORBA_NO_EXCEPTION || retval) { g_message ("cal_factory_new(): could not create the CORBA factory"); - gtk_object_unref (GTK_OBJECT (factory)); + bonobo_object_unref (BONOBO_OBJECT (factory)); CORBA_exception_free (&ev); return NULL; } diff --git a/calendar/pcs/cal.c b/calendar/pcs/cal.c index 358f08167d..158e4c493c 100644 --- a/calendar/pcs/cal.c +++ b/calendar/pcs/cal.c @@ -226,6 +226,7 @@ Cal_get_uids (PortableServer_Servant servant, n = g_list_length (uids); seq = Evolution_Calendar_CalObjUIDSeq__alloc (); + CORBA_sequence_set_release (seq, TRUE); seq->_length = n; seq->_buffer = CORBA_sequence_Evolution_Calendar_CalObjUID_allocbuf (n); @@ -279,6 +280,7 @@ Cal_get_events_in_range (PortableServer_Servant servant, n = g_list_length (elist); seq = Evolution_Calendar_CalObjInstanceSeq__alloc (); + CORBA_sequence_set_release (seq, TRUE); seq->_length = n; seq->_buffer = CORBA_sequence_Evolution_Calendar_CalObjInstance_allocbuf (n); @@ -304,6 +306,25 @@ Cal_get_events_in_range (PortableServer_Servant servant, return seq; } +/* Cal::update_object method */ +static void +Cal_update_object (PortableServer_Servant servant, + const Evolution_Calendar_CalObjUID uid, + const Evolution_Calendar_CalObj calobj, + CORBA_Environment *ev) +{ + Cal *cal; + CalPrivate *priv; + + cal = CAL (bonobo_object_from_servant (servant)); + priv = cal->priv; + + if (!cal_backend_update_object (priv->backend, uid, calobj)) + CORBA_exception_set (ev, CORBA_USER_EXCEPTION, + ex_Evolution_Calendar_Cal_InvalidObject, + NULL); +} + /** * cal_get_epv: * @void: @@ -322,6 +343,7 @@ cal_get_epv (void) epv->get_object = Cal_get_object; epv->get_uids = Cal_get_uids; epv->get_events_in_range = Cal_get_events_in_range; + epv->update_object = Cal_update_object; return epv; } @@ -438,7 +460,7 @@ cal_new (CalBackend *backend, Evolution_Calendar_Listener listener) ret = CORBA_Object_is_nil ((CORBA_Object) corba_cal, &ev); if (ev._major != CORBA_NO_EXCEPTION || ret) { g_message ("cal_new(): could not create the CORBA object"); - gtk_object_unref (GTK_OBJECT (cal)); + bonobo_object_unref (BONOBO_OBJECT (cal)); CORBA_exception_free (&ev); return NULL; } @@ -448,9 +470,40 @@ cal_new (CalBackend *backend, Evolution_Calendar_Listener listener) retval = cal_construct (cal, corba_cal, backend, listener); if (!retval) { g_message ("cal_new(): could not construct the calendar client interface"); - gtk_object_unref (GTK_OBJECT (cal)); + bonobo_object_unref (BONOBO_OBJECT (cal)); return NULL; } return retval; } + +/** + * cal_notify_update: + * @cal: A calendar client interface. + * @uid: UID of object that was updated. + * + * Notifies a listener attached to a calendar client interface object about an + * update to a calendar object. + **/ +void +cal_notify_update (Cal *cal, const char *uid) +{ + CalPrivate *priv; + CORBA_Environment ev; + + g_return_if_fail (cal != NULL); + g_return_if_fail (IS_CAL (cal)); + g_return_if_fail (uid != NULL); + + priv = cal->priv; + g_return_if_fail (priv->listener != CORBA_OBJECT_NIL); + + CORBA_exception_init (&ev); + Evolution_Calendar_Listener_obj_updated (priv->listener, uid, &ev); + + if (ev._major != CORBA_NO_EXCEPTION) + g_message ("cal_notify_update(): could not notify the listener " + "about an updated object"); + + CORBA_exception_free (&ev); +} diff --git a/calendar/pcs/cal.h b/calendar/pcs/cal.h index b866470437..18f38f5655 100644 --- a/calendar/pcs/cal.h +++ b/calendar/pcs/cal.h @@ -58,6 +58,8 @@ Evolution_Calendar_Cal cal_corba_object_create (BonoboObject *object); Cal *cal_new (CalBackend *backend, Evolution_Calendar_Listener listener); +void cal_notify_update (Cal *cal, const char *uid); + POA_Evolution_Calendar_Cal__epv *cal_get_epv (void); diff --git a/calendar/pcs/tlacuache.c b/calendar/pcs/tlacuache.c index 602cbfbe27..35bb585862 100644 --- a/calendar/pcs/tlacuache.c +++ b/calendar/pcs/tlacuache.c @@ -28,11 +28,6 @@ -/* The calendar factory */ -static CalFactory *factory; - - - /* Stuff that the un-converted alarm code needs to build */ int debug_alarms = FALSE; @@ -54,10 +49,18 @@ calendar_notify (time_t time, CalendarAlarm *which, void *data) +/* Callback used when the calendar factory is destroyed */ +static void +factory_destroy_cb (GtkObject *object, gpointer data) +{ + gtk_main_quit (); +} + /* Creates and registers the calendar factory */ static gboolean create_cal_factory (void) { + CalFactory *factory; CORBA_Object object; CORBA_Environment ev; int result; @@ -79,14 +82,20 @@ create_cal_factory (void) if (ev._major != CORBA_NO_EXCEPTION || result == -1) { g_message ("create_cal_factory(): could not register the calendar factory"); + bonobo_object_unref (BONOBO_OBJECT (factory)); CORBA_exception_free (&ev); return FALSE; } else if (result == -2) { g_message ("create_cal_factory(): a calendar factory is already registered"); + bonobo_object_unref (BONOBO_OBJECT (factory)); CORBA_exception_free (&ev); return FALSE; } + gtk_signal_connect (GTK_OBJECT (factory), "destroy", + GTK_SIGNAL_FUNC (factory_destroy_cb), + NULL); + CORBA_exception_free (&ev); return TRUE; } |