diff options
author | Federico Mena Quintero <federico@helixcode.com> | 2000-02-11 19:08:08 +0800 |
---|---|---|
committer | Arturo Espinosa <unammx@src.gnome.org> | 2000-02-11 19:08:08 +0800 |
commit | d8fbc4fc0c01d174f04e8f2370131a5240764f4b (patch) | |
tree | d530001f5c312790457e2cd55585dd46eac32085 /calendar/pcs/cal-backend.c | |
parent | db6312e2549c63372546af84fce3ce41b7c3f48d (diff) | |
download | gsoc2013-evolution-d8fbc4fc0c01d174f04e8f2370131a5240764f4b.tar.gz gsoc2013-evolution-d8fbc4fc0c01d174f04e8f2370131a5240764f4b.tar.zst gsoc2013-evolution-d8fbc4fc0c01d174f04e8f2370131a5240764f4b.zip |
Connect to the Cal's destroy signal. (cal_backend_remove_cal): Killed
2000-02-10 Federico Mena Quintero <federico@helixcode.com>
* cal-backend.c (cal_backend_add_cal): Connect to the Cal's
destroy signal.
(cal_backend_remove_cal): Killed function now that removal of Cal
objects is done in their destroy callback.
(cal_destroy_cb): New callback to remove a Cal from the backend's
list of clients. Also, the backend destroys itself when there are
no more clients connected to it.
(save): New placeholder function to save a backend.
(destroy): New function to destroy a backend's data.
(cal_backend_destroy): Save the calendar and destroy it.
* cal.c (cal_destroy): Reset the priv->backend to NULL.
* cal-factory.c (add_calendar_client): There is no need to call
cal_backend_remove_cal(); we can now just destroy the Cal object.
(create_fn): Make sure we always unref the URI.
(load_fn): Move the URI unref to the end of the function for
safety.
* cal-factory.c (add_calendar_client): Unref the Cal only if
notification of the listener was unsuccessful. Otherwise, the
calendar user agent (Listener side) keeps the reference.
* tl-test.c (list_uids): Free the calobj.
* cal-client.c (cal_loaded_cb): Use bonobo_object_unref() to get
rid of the listener.
(load_or_create): Likewise.
(destroy_factory): New function to get rid of the factory.
(destroy_listener): New function to get rid of the listener.
(destroy_cal): New function to get rid of the calendar client
interface object.
(cal_client_destroy): Free all resources.
(cal_client_get_object): CORBA_free() the calobj string. Boy, I
love memprof.
* cal-listener.c (cal_listener_destroy): Reset the priv->cal to
CORBA_OBJECT_NIL.
* cal-backend.c (cal_backend_remove_cal): Do not unref the Cal,
since the calendar user agent owns it.
(cal_backend_add_cal): Do not ref the Cal, since the calendar user
agent owns it.
* cal-factory.c (add_calendar_client): Use bonobo_object_unref()
to get rid of the calendar client interface object.
* calobj.c (ical_object_create_from_vobject): Duplicate the
default "PUBLIC" string.
2000-02-09 Federico Mena Quintero <federico@helixcode.com>
* cal-factory.c (cal_factory_load): Added documentation comment.
(load_fn): Do not print a message if the backend could not be
loaded due to a non-fatal error.
(queue_load_create_job): Moved the stuff from cal_factory_load()
to here. Now this function serves to queue load or create
requests.
(cal_factory_load): Use queue_load_create_job().
(cal_factory_create): Implemented; use queue_load_create_job().
(create_fn): New job handler for creating new calendars.
(create_backend): New function to create a new backend with a new
calendar.
(add_backend): New helper function to add backends to the
factory's hash table.
(load_backend): Use add_backend() instead of adding the backend by
ourselves.
* cal-client.c (load_or_create): Moved the functionality from
cal_client_load_calendar() to here, and added an option to create
a new calendar instead of loading an existing one.
(cal_client_load_calendar): Use load_or_create().
(cal_client_create_calendar): Implemented.
* cal-backend.c (cal_backend_create): Implemented.
* evolution-calendar.idl (LoadStatus): Added an IN_USE error for
create requests.
* cal-listener.h (CalListenerLoadStatus): Added CAL_LISTENER_LOAD_IN_USE.
* cal-listener.c (Listener_cal_loaded): Convert the IN_USE error.
* cal-client.h (CalClientLoadStatus): Added CAL_CLIENT_LOAD_IN_USE.
* cal-client.c (cal_loaded_cb): Handle CAL_LISTENER_LOAD_IN_USE.
* tl-test.c: New test program for the calendar client side; it
also exercises the server side by sending commands to it.
* Makefile.am: Added the tl-test program.
* tlacuache.gnorba: Updated.
* tlacuache.c (create_cal_factory): Use the right GOAD id.
* cal-client.c (cal_client_construct): Use the right GOAD id.
svn path=/trunk/; revision=1732
Diffstat (limited to 'calendar/pcs/cal-backend.c')
-rw-r--r-- | calendar/pcs/cal-backend.c | 182 |
1 files changed, 144 insertions, 38 deletions
diff --git a/calendar/pcs/cal-backend.c b/calendar/pcs/cal-backend.c index 17148cb048..18ed6a6c86 100644 --- a/calendar/pcs/cal-backend.c +++ b/calendar/pcs/cal-backend.c @@ -20,6 +20,7 @@ */ #include <config.h> +#include <gtk/gtksignal.h> #include "cal-backend.h" #include "calobj.h" #include "../libversit/vcc.h" @@ -36,7 +37,7 @@ typedef struct { /* URI where the calendar data is stored */ GnomeVFSURI *uri; - /* List of Cal client interface objects, each with its listener */ + /* List of Cal objects with their listeners */ GList *clients; /* All the iCalObject structures in the calendar, hashed by UID. The @@ -119,6 +120,55 @@ cal_backend_init (CalBackend *backend) backend->priv = priv; } +/* Saves a calendar */ +static void +save (CalBackend *backend) +{ + /* FIXME */ +} + +/* g_hash_table_foreach() callback to destroy an iCalObject */ +static void +free_ical_object (gpointer key, gpointer value, gpointer data) +{ + iCalObject *ico; + + ico = value; + ical_object_destroy (ico); +} + +/* Destroys a backend's data */ +static void +destroy (CalBackend *backend) +{ + CalBackendPrivate *priv; + + priv = backend->priv; + + if (priv->uri) { + gnome_vfs_uri_unref (priv->uri); + priv->uri = NULL; + } + + g_assert (priv->clients == NULL); + + if (priv->object_hash) { + g_hash_table_foreach (priv->object_hash, free_ical_object, NULL); + g_hash_table_destroy (priv->object_hash); + priv->object_hash = NULL; + } + + g_list_free (priv->events); + g_list_free (priv->todos); + g_list_free (priv->journals); + + priv->events = NULL; + priv->todos = NULL; + priv->journals = NULL; + + priv->loaded = FALSE; +} + /* Destroy handler for the calendar backend */ static void cal_backend_destroy (GtkObject *object) @@ -132,7 +182,10 @@ cal_backend_destroy (GtkObject *object) backend = CAL_BACKEND (object); priv = backend->priv; - /* FIXME: free stuff */ + if (priv->loaded) + save (backend); + + destroy (backend); g_free (priv); @@ -265,6 +318,11 @@ load_from_vobject (CalBackend *backend, VObject *vobject) ical = ical_object_create_from_vobject (this, object_name); + /* FIXME: some broken files may have duplicated UIDs. This is + * Bad(tm). Deal with it by creating new UIDs for them and + * spitting some messages to the console. + */ + if (ical) add_object (backend, ical); } @@ -364,45 +422,57 @@ cal_backend_get_uri (CalBackend *backend) return priv->uri; } -/** - * cal_backend_add_cal: - * @backend: A calendar backend. - * @cal: A calendar client interface object. - * - * Adds a calendar client interface object to a calendar @backend. The calendar - * backend must already have a loaded calendar. - **/ -void -cal_backend_add_cal (CalBackend *backend, Cal *cal) +/* Callback used when a Cal is destroyed */ +static void +cal_destroy_cb (GtkObject *object, gpointer data) { + Cal *cal; + Cal *lcal; + CalBackend *backend; CalBackendPrivate *priv; + GList *l; - g_return_if_fail (backend != NULL); - g_return_if_fail (IS_CAL_BACKEND (backend)); + cal = CAL (object); + backend = CAL_BACKEND (data); priv = backend->priv; - g_return_if_fail (priv->loaded); - g_return_if_fail (cal != NULL); - g_return_if_fail (IS_CAL (cal)); + /* Find the cal in the list of clients */ - gtk_object_ref (GTK_OBJECT (cal)); - priv->clients = g_list_prepend (priv->clients, cal); + for (l = priv->clients; l; l = l->next) { + lcal = CAL (l->data); + + if (lcal == cal) + break; + } + + g_assert (l != NULL); + + /* Disconnect */ + + priv->clients = g_list_remove_link (priv->clients, l); + g_list_free_1 (l); + + /* When all clients go away, the backend can go away, too. Commit + * suicide here. + */ + + if (!priv->clients) + gtk_object_unref (GTK_OBJECT (backend)); } /** - * cal_backend_remove_cal: + * cal_backend_add_cal: * @backend: A calendar backend. * @cal: A calendar client interface object. - * - * Removes a calendar client interface object from a calendar backend. The - * calendar backend must already have a loaded calendar. + * + * Adds a calendar client interface object to a calendar @backend. The calendar + * backend must already have a loaded calendar. **/ void -cal_backend_remove_cal (CalBackend *backend, Cal *cal) +cal_backend_add_cal (CalBackend *backend, Cal *cal) { CalBackendPrivate *priv; - GList *l; g_return_if_fail (backend != NULL); g_return_if_fail (IS_CAL_BACKEND (backend)); @@ -413,13 +483,15 @@ cal_backend_remove_cal (CalBackend *backend, Cal *cal) g_return_if_fail (cal != NULL); g_return_if_fail (IS_CAL (cal)); - l = g_list_find (priv->clients, cal); - if (!l) - return; + /* We do not keep a reference to the Cal since the calendar user agent + * owns it. + */ + + gtk_signal_connect (GTK_OBJECT (cal), "destroy", + GTK_SIGNAL_FUNC (cal_destroy_cb), + backend); - gtk_object_unref (GTK_OBJECT (cal)); - priv->clients = g_list_remove_link (priv->clients, l); - g_list_free_1 (l); + priv->clients = g_list_prepend (priv->clients, cal); } /** @@ -441,11 +513,12 @@ cal_backend_load (CalBackend *backend, GnomeVFSURI *uri) g_return_val_if_fail (backend != NULL, CAL_BACKEND_LOAD_ERROR); g_return_val_if_fail (IS_CAL_BACKEND (backend), CAL_BACKEND_LOAD_ERROR); - g_return_val_if_fail (uri != NULL, CAL_BACKEND_LOAD_ERROR); priv = backend->priv; g_return_val_if_fail (!priv->loaded, CAL_BACKEND_LOAD_ERROR); + g_return_val_if_fail (uri != NULL, CAL_BACKEND_LOAD_ERROR); + /* FIXME: this looks rather bad; maybe we should check for local files * and fail if they are remote. */ @@ -475,13 +548,46 @@ cal_backend_load (CalBackend *backend, GnomeVFSURI *uri) } /** + * cal_backend_create: + * @backend: A calendar backend. + * @uri: URI that will contain the calendar data. + * + * Creates a new empty calendar in a calendar backend. + **/ +void +cal_backend_create (CalBackend *backend, GnomeVFSURI *uri) +{ + 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 (uri != NULL); + + /* Create the new calendar information */ + + g_assert (priv->object_hash == NULL); + priv->object_hash = g_hash_table_new (g_str_hash, g_str_equal); + + /* Done */ + + gnome_vfs_uri_ref (uri); + + priv->uri = uri; + priv->loaded = TRUE; +} + +/** * cal_backend_get_object: * @backend: A calendar backend. * @uid: Unique identifier for a calendar object. - * + * * Queries a calendar backend for a calendar object based on its unique * identifier. - * + * * Return value: The string representation of a complete calendar wrapping the * the sought object, or NULL if no object had the specified UID. A complete * calendar is returned because you also need the timezone data. @@ -560,10 +666,10 @@ build_uids_list (gpointer key, gpointer value, gpointer data) * cal_backend_get_uids: * @backend: A calendar backend. * @type: Bitmask with types of objects to return. - * + * * Builds a list of unique identifiers corresponding to calendar objects whose * type matches one of the types specified in the @type flags. - * + * * Return value: A list of strings that are the sought UIDs. **/ GList * @@ -639,11 +745,11 @@ compare_instance_func (gconstpointer a, gconstpointer b) * @backend: A calendar backend. * @start: Start time for query. * @end: End time for query. - * + * * Builds a sorted list of calendar event object instances that occur or recur * within the specified time range. Each object instance contains the object * itself and the start/end times at which it occurs or recurs. - * + * * Return value: A list of calendar event object instances, sorted by their * start times. **/ |