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/cal-backend.c | |
parent | 123f506198c535dcb073c1998fed37c25ad131f9 (diff) | |
download | gsoc2013-evolution-d2fe58c56857e9e4b2e37f87174da6956b0d985c.tar gsoc2013-evolution-d2fe58c56857e9e4b2e37f87174da6956b0d985c.tar.gz gsoc2013-evolution-d2fe58c56857e9e4b2e37f87174da6956b0d985c.tar.bz2 gsoc2013-evolution-d2fe58c56857e9e4b2e37f87174da6956b0d985c.tar.lz gsoc2013-evolution-d2fe58c56857e9e4b2e37f87174da6956b0d985c.tar.xz 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/cal-backend.c')
-rw-r--r-- | calendar/cal-backend.c | 139 |
1 files changed, 138 insertions, 1 deletions
diff --git a/calendar/cal-backend.c b/calendar/cal-backend.c index 18ed6a6c86..1ce4b615c3 100644 --- a/calendar/cal-backend.c +++ b/calendar/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 */ +} |