diff options
author | Federico Mena Quintero <federico@ximian.com> | 2001-01-17 18:44:33 +0800 |
---|---|---|
committer | Federico Mena Quintero <federico@src.gnome.org> | 2001-01-17 18:44:33 +0800 |
commit | 0932fd7ec9d21e763371a043283384af8bc987fb (patch) | |
tree | dbfd7dcaf49fd667712a6408eae165bd201c3219 /calendar/cal-client | |
parent | ff6098b51168decc542245a215056dc6219ebd69 (diff) | |
download | gsoc2013-evolution-0932fd7ec9d21e763371a043283384af8bc987fb.tar.gz gsoc2013-evolution-0932fd7ec9d21e763371a043283384af8bc987fb.tar.zst gsoc2013-evolution-0932fd7ec9d21e763371a043283384af8bc987fb.zip |
Ximianified email addresses and copyrights.
2001-01-17 Federico Mena Quintero <federico@ximian.com>
* */*: Ximianified email addresses and copyrights.
* idl/evolution-calendar.idl (CalFactory::open): Renamed from
::load(), and added an only_if_exists argument.
(CalFactory::create): Removed method.
(Listener::OpenStatus): Removed the IN_USE error and replaced it
with a NOT_FOUND one; renamed the enum from LoadStatus.
(Listener::notifyCalOpened): Renamed from notifyCalLoaded().
* pcs/cal-backend.h (CalBackend): Removed the uri field.
(CalBackendOpenStatus): Renamed from CalBackendLoadStatus and
added a NOT_FOUND value.
(CalBackendClass::open): Put in a slot for the open method.
* pcs/cal-backend.c (cal_backend_create): Removed function.
* pcs/cal-backend-file.c (cal_backend_file_open): Return the
appropriate value when only_if_exists is TRUE.
(create_cal): We are Ximian now, so set the PRODID property to
the appropriate foo.
* pcs/cal-factory.c (CalFactory_open): implemented, replacing
CalFactory_load() and CalFactory_create().
(CalFactory_open): Moved the queue_load_create_job() stuff to
here, since we now only need to contemplate the open case instead
of load/create ones.
(open_backend): Do everything here; replaces load_backend() and
create_backend().
* cal-client/cal-listener.h (CalListenerClass::cal_opened):
Renamed from cal_loaded.
(CalListenerClass): Replaced the silly signals, which are
gratuitous abstraction, by a set of function pointers in the
instance structure.
* cal-client/cal-listener.c (cal_listener_get_calendar): Removed
unused function.
(cal_listener_construct): Added the listener notification functions.
(cal_listener_new): Ditto.
(Listener_notifyCalOpened): Renamed to our new naming convention
for servant implementations.
(Listener_notifyObjUpdated): Ditto.
(Listener_notifyObjRemoved): Ditto.
* cal-client/cal-client.h (CalClientOpenStatus): Renamed from
CalClientLoadStatus.
(CalClientClass::cal_opened): Renamed from ::cal_loaded().
(CalClientLoadState): New enum; basically make LoadState public so
that users of this code do not have to maintain their own states.
* cal-client/cal-client.c (cal_client_create_calendar): Removed
function.
(cal_client_open_calendar): Moved the functionality over from
load_or_create(); now we do everything here.
(*): Use the CalClientLoadState enum values instead of the old
LoadState values.
(cal_client_get_load_state): Renamed from cal_client_is_loaded(),
and return the appropriate value.
(CalClientPrivate): Added an uri field.
(cal_client_init): Initialize priv->uri.
(cal_client_destroy): Free the priv->uri.
(cal_opened_cb): Maintain the priv->uri.
(cal_client_open_calendar): Fill in the priv->uri.
(cal_client_get_uri): New function.
* gui/calendar-model.c (calendar_model_set_new_comp_vtype): New
function to configure the type of calendar components to create
when doing click-to-add. This makes the model usable for
something other than task lists.
(calendar_model_get_new_comp_vtype): New function.
* gui/e-calendar-table.c (e_calendar_table_get_model): New function.
(e_calendar_table_destroy): Unref the subset_model.
* gui/gnome-cal.h (GnomeCalendarOpenMode): Removed enum.
* gui/gnome-cal.c (LoadState): Removed enum; we now use the
CalClientLoadState from the client objects.
(GnomeCalendarPrivate): Removed the loading_uri and
task_pad_loading_uri fields as well as the load_state and
task_pad_load_state fields, as we can now query them directly from
the CalClient.
(open_error): Renamed from load_error().
(create_error): Removed function.
(gnome_calendar_open): Do not take in the mode parameter.
(cal_opened_cb): Get rid of our beautifully-crafted state machine
and replace it with simple code; all the loading smarts are in the
Wombat now.
(setup_widgets): Set the new component vtype of the table model to
CAL_COMPONENT_TODO.
* gui/Makefile.am (evolution_calendar_SOURCES): Removed
gnome-month-item.[ch] from the list of sources.
* gui/calendar-summary.c (CalSummary): Removed unused cal_loaded
field.
(create_summary_view): Do not check if the file exists; this is
the job of the Wombat.
(generate_html_summary): Fixed prototype.
(alarm_fn): Fixed prototype.
(property_dialog): Fixed prototype. Wonder if/how this ever
worked.
(create_summary_view): Cast the component and view as
appropriate. Removed unused html variable.
[Iain dude, are you compiling with -Wall?]
* gui/e-itip-control.c (cal_opened_cb): Sigh, this function
signature was *very* wrong. It was using CalClientGetStatus
instead of CalClientOpenStatus.
* gui/e-tasks.h (ETasksOpenMode): Removed enum.
* gui/e-tasks.c (setup_widgets): Set the new component vtype of
the table model to CAL_COMPONENT_TODO.
(LoadState): Removed the state machine foo.
(e_tasks_open): Removed the mode parameter.
(initial_load): Removed function.
(create_error): Removed function.
(ETasksPrivate): Removed folder_uri field.
(cal_opened_cb): Remove the state machine.
* gui/component-factory.c: #include "tasks-control.h"
* conduits/calendar/calendar-conduit.h (ECalConduitContext):
Removed calendar_load_tried field.
* conduits/calendar/calendar-conduit.c (start_calendar_server_cb):
Sigh, fixed function prototype.
* conduits/todo/todo-conduit.h (EToDoConduitContext): Removed
calendar_load_tried field.
* conduits/todo/todo-conduit.c (start_calendar_server_cb): Fixed
function prototype.
svn path=/trunk/; revision=7571
Diffstat (limited to 'calendar/cal-client')
-rw-r--r-- | calendar/cal-client/cal-client-types.c | 5 | ||||
-rw-r--r-- | calendar/cal-client/cal-client-types.h | 5 | ||||
-rw-r--r-- | calendar/cal-client/cal-client.c | 223 | ||||
-rw-r--r-- | calendar/cal-client/cal-client.h | 32 | ||||
-rw-r--r-- | calendar/cal-client/cal-listener.c | 193 | ||||
-rw-r--r-- | calendar/cal-client/cal-listener.h | 34 | ||||
-rw-r--r-- | calendar/cal-client/client-test.c | 38 |
7 files changed, 280 insertions, 250 deletions
diff --git a/calendar/cal-client/cal-client-types.c b/calendar/cal-client/cal-client-types.c index 98da8b8a6f..23aa14475f 100644 --- a/calendar/cal-client/cal-client-types.c +++ b/calendar/cal-client/cal-client-types.c @@ -1,9 +1,10 @@ /* Evolution calendar utilities and types * * Copyright (C) 2000 Helix Code, Inc. + * Copyright (C) 2000 Ximian, Inc. * - * Authors: Federico Mena-Quintero <federico@helixcode.com> - * JP Rosevear <jpr@helixcode.com> + * Authors: Federico Mena-Quintero <federico@ximian.com> + * JP Rosevear <jpr@ximian.com> * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by diff --git a/calendar/cal-client/cal-client-types.h b/calendar/cal-client/cal-client-types.h index 5c017458ad..c356f2378e 100644 --- a/calendar/cal-client/cal-client-types.h +++ b/calendar/cal-client/cal-client-types.h @@ -1,9 +1,10 @@ /* Evolution calendar utilities and types * * Copyright (C) 2000 Helix Code, Inc. + * Copyright (C) 2000 Ximian, Inc. * - * Authors: Federico Mena-Quintero <federico@helixcode.com> - * JP Rosevear <jpr@helixcode.com> + * Authors: Federico Mena-Quintero <federico@ximian.com> + * JP Rosevear <jpr@ximian.com> * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by diff --git a/calendar/cal-client/cal-client.c b/calendar/cal-client/cal-client.c index 344dd91545..a89cfae40c 100644 --- a/calendar/cal-client/cal-client.c +++ b/calendar/cal-client/cal-client.c @@ -1,10 +1,10 @@ - /* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ /* Evolution calendar client * * Copyright (C) 2000 Helix Code, Inc. + * Copyright (C) 2000 Ximian, Inc. * - * Author: Federico Mena-Quintero <federico@helixcode.com> + * Author: Federico Mena-Quintero <federico@ximian.com> * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -31,17 +31,15 @@ -/* Loading state for the calendar client */ -typedef enum { - LOAD_STATE_NOT_LOADED, - LOAD_STATE_LOADING, - LOAD_STATE_LOADED -} LoadState; - /* Private part of the CalClient structure */ struct _CalClientPrivate { /* Load state to avoid multiple loads */ - LoadState load_state; + CalClientLoadState load_state; + + /* URI of the calendar that is being loaded or is already loaded, or + * NULL if we are not loaded. + */ + char *uri; /* The calendar factory we are contacting */ GNOME_Evolution_Calendar_CalFactory factory; @@ -57,7 +55,7 @@ struct _CalClientPrivate { /* Signal IDs */ enum { - CAL_LOADED, + CAL_OPENED, OBJ_UPDATED, OBJ_REMOVED, LAST_SIGNAL @@ -115,11 +113,11 @@ cal_client_class_init (CalClientClass *class) parent_class = gtk_type_class (GTK_TYPE_OBJECT); - cal_client_signals[CAL_LOADED] = - gtk_signal_new ("cal_loaded", + cal_client_signals[CAL_OPENED] = + gtk_signal_new ("cal_opened", GTK_RUN_FIRST, object_class->type, - GTK_SIGNAL_OFFSET (CalClientClass, cal_loaded), + GTK_SIGNAL_OFFSET (CalClientClass, cal_opened), gtk_marshal_NONE__ENUM, GTK_TYPE_NONE, 1, GTK_TYPE_ENUM); @@ -154,8 +152,9 @@ cal_client_init (CalClient *client) priv = g_new0 (CalClientPrivate, 1); client->priv = priv; + priv->load_state = CAL_CLIENT_LOAD_NOT_LOADED; + priv->uri = NULL; priv->factory = CORBA_OBJECT_NIL; - priv->load_state = LOAD_STATE_NOT_LOADED; } /* Gets rid of the factory that a client knows about */ @@ -263,7 +262,12 @@ cal_client_destroy (GtkObject *object) destroy_listener (client); destroy_cal (client); - priv->load_state = LOAD_STATE_NOT_LOADED; + priv->load_state = CAL_CLIENT_LOAD_NOT_LOADED; + + if (priv->uri) { + g_free (priv->uri); + priv->uri = NULL; + } g_free (priv); client->priv = NULL; @@ -276,10 +280,10 @@ cal_client_destroy (GtkObject *object) /* Signal handlers for the listener's signals */ -/* Handle the cal_loaded signal from the listener */ +/* Handle the cal_opened notification from the listener */ static void -cal_loaded_cb (CalListener *listener, - GNOME_Evolution_Calendar_Listener_LoadStatus status, +cal_opened_cb (CalListener *listener, + GNOME_Evolution_Calendar_Listener_OpenStatus status, GNOME_Evolution_Calendar_Cal cal, gpointer data) { @@ -287,42 +291,44 @@ cal_loaded_cb (CalListener *listener, CalClientPrivate *priv; CORBA_Environment ev; GNOME_Evolution_Calendar_Cal cal_copy; - CalClientLoadStatus client_status; + CalClientOpenStatus client_status; client = CAL_CLIENT (data); priv = client->priv; - g_assert (priv->load_state == LOAD_STATE_LOADING); + g_assert (priv->load_state == CAL_CLIENT_LOAD_LOADING); + g_assert (priv->uri != NULL); - client_status = CAL_CLIENT_LOAD_ERROR; + client_status = CAL_CLIENT_OPEN_ERROR; switch (status) { case GNOME_Evolution_Calendar_Listener_SUCCESS: CORBA_exception_init (&ev); cal_copy = CORBA_Object_duplicate (cal, &ev); if (ev._major != CORBA_NO_EXCEPTION) { - g_message ("cal_loaded(): could not duplicate the calendar client interface"); + g_message ("cal_opened_cb(): could not duplicate the " + "calendar client interface"); CORBA_exception_free (&ev); goto error; } CORBA_exception_free (&ev); priv->cal = cal_copy; - priv->load_state = LOAD_STATE_LOADED; + priv->load_state = CAL_CLIENT_LOAD_LOADED; - client_status = CAL_CLIENT_LOAD_SUCCESS; + client_status = CAL_CLIENT_OPEN_SUCCESS; goto out; case GNOME_Evolution_Calendar_Listener_ERROR: - client_status = CAL_CLIENT_LOAD_ERROR; + client_status = CAL_CLIENT_OPEN_ERROR; goto error; - case GNOME_Evolution_Calendar_Listener_IN_USE: - client_status = CAL_CLIENT_LOAD_IN_USE; + case GNOME_Evolution_Calendar_Listener_NOT_FOUND: + client_status = CAL_CLIENT_OPEN_NOT_FOUND; goto error; case GNOME_Evolution_Calendar_Listener_METHOD_NOT_SUPPORTED: - client_status = CAL_CLIENT_LOAD_METHOD_NOT_SUPPORTED; + client_status = CAL_CLIENT_OPEN_METHOD_NOT_SUPPORTED; goto error; default: @@ -333,14 +339,24 @@ cal_loaded_cb (CalListener *listener, bonobo_object_unref (BONOBO_OBJECT (priv->listener)); priv->listener = NULL; - priv->load_state = LOAD_STATE_NOT_LOADED; + + /* We free the priv->uri and set the priv->load_state until after the + * "cal_opened" signal has been emitted so that handlers will be able to + * access this information. + */ out: - g_assert (priv->load_state != LOAD_STATE_LOADING); + g_assert (priv->load_state != CAL_CLIENT_LOAD_LOADING); - gtk_signal_emit (GTK_OBJECT (client), cal_client_signals[CAL_LOADED], + gtk_signal_emit (GTK_OBJECT (client), cal_client_signals[CAL_OPENED], client_status); + + if (client_status != CAL_CLIENT_OPEN_SUCCESS) { + priv->load_state = CAL_CLIENT_LOAD_NOT_LOADED; + g_free (priv->uri); + priv->uri = NULL; + } } /* Handle the obj_updated signal from the listener */ @@ -425,7 +441,7 @@ cal_client_construct (CalClient *client) * cal_client_new: * * Creates a new calendar client. It should be initialized by calling - * cal_client_load_calendar() or cal_client_create_calendar(). + * cal_client_open_calendar(). * * Return value: A newly-created calendar client, or NULL if the client could * not be constructed because it could not contact the calendar server. @@ -446,9 +462,23 @@ cal_client_new (void) return client; } -/* Issues a load or create request */ -static gboolean -load_or_create (CalClient *client, const char *str_uri, gboolean load) +/** + * cal_client_open_calendar: + * @client: A calendar client. + * @str_uri: URI of calendar to open. + * @only_if_exists: FALSE if the calendar should be opened even if there + * was no storage for it, i.e. to create a new calendar or load an existing + * one if it already exists. TRUE if it should only try to load calendars + * that already exist. + * + * Makes a calendar client initiate a request to open a calendar. The calendar + * client will emit the "cal_opened" signal when the response from the server is + * received. + * + * Return value: TRUE on success, FALSE on failure to issue the open request. + **/ +gboolean +cal_client_open_calendar (CalClient *client, const char *str_uri, gboolean only_if_exists) { CalClientPrivate *priv; GNOME_Evolution_Calendar_Listener corba_listener; @@ -458,44 +488,41 @@ load_or_create (CalClient *client, const char *str_uri, gboolean load) g_return_val_if_fail (IS_CAL_CLIENT (client), FALSE); priv = client->priv; - g_return_val_if_fail (priv->load_state == LOAD_STATE_NOT_LOADED, FALSE); + g_return_val_if_fail (priv->load_state == CAL_CLIENT_LOAD_NOT_LOADED, FALSE); + g_assert (priv->uri == NULL); g_return_val_if_fail (str_uri != NULL, FALSE); - priv->listener = cal_listener_new (); + priv->listener = cal_listener_new (cal_opened_cb, + obj_updated_cb, + obj_removed_cb, + client); if (!priv->listener) { - g_message ("load_or_create(): could not create the listener"); + g_message ("cal_client_open_calendar(): could not create the listener"); return FALSE; } - gtk_signal_connect (GTK_OBJECT (priv->listener), "cal_loaded", - GTK_SIGNAL_FUNC (cal_loaded_cb), - client); - gtk_signal_connect (GTK_OBJECT (priv->listener), "obj_updated", - GTK_SIGNAL_FUNC (obj_updated_cb), - client); - gtk_signal_connect (GTK_OBJECT (priv->listener), "obj_removed", - GTK_SIGNAL_FUNC (obj_removed_cb), - client); - corba_listener = (GNOME_Evolution_Calendar_Listener) bonobo_object_corba_objref ( BONOBO_OBJECT (priv->listener)); - + CORBA_exception_init (&ev); - priv->load_state = LOAD_STATE_LOADING; + priv->load_state = CAL_CLIENT_LOAD_LOADING; + priv->uri = g_strdup (str_uri); - if (load) - GNOME_Evolution_Calendar_CalFactory_load (priv->factory, str_uri, corba_listener, &ev); - else - GNOME_Evolution_Calendar_CalFactory_create (priv->factory, str_uri, corba_listener, &ev); + GNOME_Evolution_Calendar_CalFactory_open (priv->factory, str_uri, only_if_exists, + corba_listener, &ev); if (ev._major != CORBA_NO_EXCEPTION) { - g_message ("load_or_create(): load/create request failed"); + CORBA_exception_free (&ev); + + g_message ("cal_client_open_calendar(): open request failed"); bonobo_object_unref (BONOBO_OBJECT (priv->listener)); priv->listener = NULL; - priv->load_state = LOAD_STATE_NOT_LOADED; - CORBA_exception_free (&ev); + priv->load_state = CAL_CLIENT_LOAD_NOT_LOADED; + g_free (priv->uri); + priv->uri = NULL; + return FALSE; } CORBA_exception_free (&ev); @@ -504,58 +531,46 @@ load_or_create (CalClient *client, const char *str_uri, gboolean load) } /** - * cal_client_load_calendar: + * cal_client_get_load_state: * @client: A calendar client. - * @str_uri: URI of calendar to load. - * - * Makes a calendar client initiate a request to load a calendar. The calendar - * client will emit the "cal_loaded" signal when the response from the server is - * received. - * - * Return value: TRUE on success, FALSE on failure to issue the load request. + * + * Queries the state of loading of a calendar client. + * + * Return value: A #CalClientLoadState value indicating whether the client has + * not been loaded with cal_client_open_calendar() yet, whether it is being + * loaded, or whether it is already loaded. **/ -gboolean -cal_client_load_calendar (CalClient *client, const char *str_uri) +CalClientLoadState +cal_client_get_load_state (CalClient *client) { - return load_or_create (client, str_uri, TRUE); -} + CalClientPrivate *priv; -/** - * cal_client_create_calendar: - * @client: A calendar client. - * @str_uri: URI that will contain the calendar data. - * - * Makes a calendar client initiate a request to create a new calendar. The - * calendar client will emit the "cal_loaded" signal when the response from the - * server is received. - * - * Return value: TRUE on success, FALSE on failure to issue the create request. - **/ -gboolean -cal_client_create_calendar (CalClient *client, const char *str_uri) -{ - return load_or_create (client, str_uri, FALSE); + g_return_val_if_fail (client != NULL, FALSE); + g_return_val_if_fail (IS_CAL_CLIENT (client), FALSE); + + priv = client->priv; + return priv->load_state; } /** - * cal_client_is_loaded: + * cal_client_get_uri: * @client: A calendar client. * - * Queries whether a calendar client has been loaded successfully. + * Queries the URI that is open in a calendar client. * - * Return value: TRUE if the client has been loaded, FALSE if it has not or if - * the loading process is not finished yet. + * Return value: The URI of the calendar that is already loaded or is being + * loaded, or NULL if the client has not started a load request yet. **/ -gboolean -cal_client_is_loaded (CalClient *client) +const char * +cal_client_get_uri (CalClient *client) { CalClientPrivate *priv; - g_return_val_if_fail (client != NULL, FALSE); - g_return_val_if_fail (IS_CAL_CLIENT (client), FALSE); + g_return_val_if_fail (client != NULL, NULL); + g_return_val_if_fail (IS_CAL_CLIENT (client), NULL); priv = client->priv; - return (priv->load_state == LOAD_STATE_LOADED); + return priv->uri; } /* Converts our representation of a calendar component type into its CORBA representation */ @@ -589,7 +604,7 @@ cal_client_get_n_objects (CalClient *client, CalObjType type) g_return_val_if_fail (IS_CAL_CLIENT (client), -1); priv = client->priv; - g_return_val_if_fail (priv->load_state == LOAD_STATE_LOADED, -1); + g_return_val_if_fail (priv->load_state == CAL_CLIENT_LOAD_LOADED, -1); t = corba_obj_type (type); @@ -630,7 +645,7 @@ cal_client_get_object (CalClient *client, const char *uid, CalComponent **comp) g_return_val_if_fail (IS_CAL_CLIENT (client), CAL_CLIENT_GET_NOT_FOUND); priv = client->priv; - g_return_val_if_fail (priv->load_state == LOAD_STATE_LOADED, CAL_CLIENT_GET_NOT_FOUND); + g_return_val_if_fail (priv->load_state == CAL_CLIENT_LOAD_LOADED, CAL_CLIENT_GET_NOT_FOUND); g_return_val_if_fail (uid != NULL, CAL_CLIENT_GET_NOT_FOUND); g_return_val_if_fail (comp != NULL, CAL_CLIENT_GET_NOT_FOUND); @@ -713,7 +728,7 @@ cal_client_get_uids (CalClient *client, CalObjType type) g_return_val_if_fail (IS_CAL_CLIENT (client), NULL); priv = client->priv; - g_return_val_if_fail (priv->load_state == LOAD_STATE_LOADED, NULL); + g_return_val_if_fail (priv->load_state == CAL_CLIENT_LOAD_LOADED, NULL); t = corba_obj_type (type); @@ -783,7 +798,7 @@ cal_client_get_changes (CalClient *client, CalObjType type, const char *change_i g_return_val_if_fail (IS_CAL_CLIENT (client), NULL); priv = client->priv; - g_return_val_if_fail (priv->load_state == LOAD_STATE_LOADED, NULL); + g_return_val_if_fail (priv->load_state == CAL_CLIENT_LOAD_LOADED, NULL); t = corba_obj_type (type); CORBA_exception_init (&ev); @@ -860,7 +875,7 @@ cal_client_get_objects_in_range (CalClient *client, CalObjType type, time_t star g_return_val_if_fail (IS_CAL_CLIENT (client), NULL); priv = client->priv; - g_return_val_if_fail (priv->load_state == LOAD_STATE_LOADED, NULL); + g_return_val_if_fail (priv->load_state == CAL_CLIENT_LOAD_LOADED, NULL); g_return_val_if_fail (start != -1 && end != -1, NULL); g_return_val_if_fail (start <= end, NULL); @@ -1110,7 +1125,7 @@ cal_client_generate_instances (CalClient *client, CalObjType type, g_return_if_fail (IS_CAL_CLIENT (client)); priv = client->priv; - g_return_if_fail (priv->load_state == LOAD_STATE_LOADED); + g_return_if_fail (priv->load_state == CAL_CLIENT_LOAD_LOADED); g_return_if_fail (start != -1 && end != -1); g_return_if_fail (start <= end); @@ -1263,7 +1278,7 @@ cal_client_get_alarms_in_range (CalClient *client, time_t start, time_t end) g_return_val_if_fail (IS_CAL_CLIENT (client), NULL); priv = client->priv; - g_return_val_if_fail (priv->load_state == LOAD_STATE_LOADED, NULL); + g_return_val_if_fail (priv->load_state == CAL_CLIENT_LOAD_LOADED, NULL); g_return_val_if_fail (start != -1 && end != -1, NULL); g_return_val_if_fail (start <= end, NULL); @@ -1339,7 +1354,7 @@ cal_client_get_alarms_for_object (CalClient *client, const char *uid, g_return_val_if_fail (IS_CAL_CLIENT (client), FALSE); priv = client->priv; - g_return_val_if_fail (priv->load_state == LOAD_STATE_LOADED, FALSE); + g_return_val_if_fail (priv->load_state == CAL_CLIENT_LOAD_LOADED, FALSE); g_return_val_if_fail (uid != NULL, FALSE); g_return_val_if_fail (start != -1 && end != -1, FALSE); @@ -1409,7 +1424,7 @@ cal_client_update_object (CalClient *client, CalComponent *comp) g_return_val_if_fail (IS_CAL_CLIENT (client), FALSE); priv = client->priv; - g_return_val_if_fail (priv->load_state == LOAD_STATE_LOADED, FALSE); + g_return_val_if_fail (priv->load_state == CAL_CLIENT_LOAD_LOADED, FALSE); g_return_val_if_fail (comp != NULL, FALSE); @@ -1464,7 +1479,7 @@ cal_client_remove_object (CalClient *client, const char *uid) g_return_val_if_fail (IS_CAL_CLIENT (client), FALSE); priv = client->priv; - g_return_val_if_fail (priv->load_state == LOAD_STATE_LOADED, FALSE); + g_return_val_if_fail (priv->load_state == CAL_CLIENT_LOAD_LOADED, FALSE); g_return_val_if_fail (uid != NULL, FALSE); diff --git a/calendar/cal-client/cal-client.h b/calendar/cal-client/cal-client.h index bbd0d1871e..9e17b22b2b 100644 --- a/calendar/cal-client/cal-client.h +++ b/calendar/cal-client/cal-client.h @@ -1,8 +1,9 @@ /* Evolution calendar client * * Copyright (C) 2000 Helix Code, Inc. + * Copyright (C) 2000 Ximian, Inc. * - * Author: Federico Mena-Quintero <federico@helixcode.com> + * Author: Federico Mena-Quintero <federico@ximian.com> * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -42,20 +43,28 @@ typedef struct _CalClientClass CalClientClass; typedef struct _CalClientPrivate CalClientPrivate; -/* Load status for the cal_loaded signal */ +/* Open status for the cal_opened signal */ typedef enum { - CAL_CLIENT_LOAD_SUCCESS, - CAL_CLIENT_LOAD_ERROR, - CAL_CLIENT_LOAD_IN_USE, - CAL_CLIENT_LOAD_METHOD_NOT_SUPPORTED -} CalClientLoadStatus; + CAL_CLIENT_OPEN_SUCCESS, + CAL_CLIENT_OPEN_ERROR, + CAL_CLIENT_OPEN_NOT_FOUND, + CAL_CLIENT_OPEN_METHOD_NOT_SUPPORTED +} CalClientOpenStatus; +/* Get status for the cal_client_get_object() function */ typedef enum { CAL_CLIENT_GET_SUCCESS, CAL_CLIENT_GET_NOT_FOUND, CAL_CLIENT_GET_SYNTAX_ERROR } CalClientGetStatus; +/* Whether the client is not loaded, is being loaded, or is already loaded */ +typedef enum { + CAL_CLIENT_LOAD_NOT_LOADED, + CAL_CLIENT_LOAD_LOADING, + CAL_CLIENT_LOAD_LOADED +} CalClientLoadState; + struct _CalClient { GtkObject object; @@ -69,7 +78,7 @@ struct _CalClientClass { /* Notification signals */ - void (* cal_loaded) (CalClient *client, CalClientLoadStatus status); + void (* cal_opened) (CalClient *client, CalClientOpenStatus status); void (* obj_updated) (CalClient *client, const char *uid); void (* obj_removed) (CalClient *client, const char *uid); @@ -81,10 +90,11 @@ CalClient *cal_client_construct (CalClient *client); CalClient *cal_client_new (void); -gboolean cal_client_load_calendar (CalClient *client, const char *str_uri); -gboolean cal_client_create_calendar (CalClient *client, const char *str_uri); +gboolean cal_client_open_calendar (CalClient *client, const char *str_uri, gboolean only_if_exists); + +CalClientLoadState cal_client_get_load_state (CalClient *client); -gboolean cal_client_is_loaded (CalClient *client); +const char *cal_client_get_uri (CalClient *client); int cal_client_get_n_objects (CalClient *client, CalObjType type); diff --git a/calendar/cal-client/cal-listener.c b/calendar/cal-client/cal-listener.c index cf7442b0e9..b5c3bdbd6b 100644 --- a/calendar/cal-client/cal-listener.c +++ b/calendar/cal-client/cal-listener.c @@ -1,8 +1,9 @@ /* Evolution calendar listener * * Copyright (C) 2000 Helix Code, Inc. + * Copyright (C) 2000 Ximian, Inc. * - * Author: Federico Mena-Quintero <federico@helixcode.com> + * Author: Federico Mena-Quintero <federico@ximian.com> * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -29,28 +30,22 @@ struct _CalListenerPrivate { /* The calendar this listener refers to */ GNOME_Evolution_Calendar_Cal cal; + + /* Notification functions and their closure data */ + CalListenerCalOpenedFn cal_opened_fn; + CalListenerObjUpdatedFn obj_updated_fn; + CalListenerObjRemovedFn obj_removed_fn; + gpointer fn_data; }; -/* Signal IDs */ -enum { - CAL_LOADED, - OBJ_UPDATED, - OBJ_REMOVED, - LAST_SIGNAL -}; - static void cal_listener_class_init (CalListenerClass *class); static void cal_listener_init (CalListener *listener); static void cal_listener_destroy (GtkObject *object); -static void marshal_cal_loaded (GtkObject *object, GtkSignalFunc func, gpointer data, GtkArg *args); - static POA_GNOME_Evolution_Calendar_Listener__vepv cal_listener_vepv; -static guint cal_listener_signals[LAST_SIGNAL]; - static BonoboObjectClass *parent_class; @@ -105,34 +100,6 @@ cal_listener_class_init (CalListenerClass *class) parent_class = gtk_type_class (bonobo_object_get_type ()); - cal_listener_signals[CAL_LOADED] = - gtk_signal_new ("cal_loaded", - GTK_RUN_FIRST, - object_class->type, - GTK_SIGNAL_OFFSET (CalListenerClass, cal_loaded), - marshal_cal_loaded, - GTK_TYPE_NONE, 2, - GTK_TYPE_ENUM, - GTK_TYPE_POINTER); - cal_listener_signals[OBJ_UPDATED] = - gtk_signal_new ("obj_updated", - GTK_RUN_FIRST, - object_class->type, - GTK_SIGNAL_OFFSET (CalListenerClass, obj_updated), - gtk_marshal_NONE__POINTER, - GTK_TYPE_NONE, 1, - GTK_TYPE_POINTER); - cal_listener_signals[OBJ_REMOVED] = - gtk_signal_new ("obj_removed", - GTK_RUN_FIRST, - object_class->type, - GTK_SIGNAL_OFFSET (CalListenerClass, obj_removed), - gtk_marshal_NONE__POINTER, - GTK_TYPE_NONE, 1, - GTK_TYPE_POINTER); - - gtk_object_class_add_signals (object_class, cal_listener_signals, LAST_SIGNAL); - object_class->destroy = cal_listener_destroy; init_cal_listener_corba_class (); @@ -148,6 +115,9 @@ cal_listener_init (CalListener *listener) listener->priv = priv; priv->cal = CORBA_OBJECT_NIL; + priv->cal_opened_fn = NULL; + priv->obj_updated_fn = NULL; + priv->obj_removed_fn = NULL; } /* Destroy handler for the calendar listener */ @@ -192,29 +162,14 @@ cal_listener_destroy (GtkObject *object) -/* Marshalers */ - -typedef void (* CalLoadedFunc) (GtkObject *object, gint status, gpointer cal, gpointer data); - -static void -marshal_cal_loaded (GtkObject *object, GtkSignalFunc func, gpointer data, GtkArg *args) -{ - CalLoadedFunc rfunc; - - rfunc = (CalLoadedFunc) func; - (* rfunc) (object, GTK_VALUE_ENUM (args[0]), GTK_VALUE_POINTER (args[1]), data); -} - - - /* CORBA servant implementation */ -/* Listener::cal_loaded method */ +/* Listener::notifyCalOpened method */ static void -Listener_cal_loaded (PortableServer_Servant servant, - GNOME_Evolution_Calendar_Listener_LoadStatus status, - GNOME_Evolution_Calendar_Cal cal, - CORBA_Environment *ev) +Listener_notifyCalOpened (PortableServer_Servant servant, + GNOME_Evolution_Calendar_Listener_OpenStatus status, + GNOME_Evolution_Calendar_Cal cal, + CORBA_Environment *ev) { CalListener *listener; CalListenerPrivate *priv; @@ -225,7 +180,7 @@ Listener_cal_loaded (PortableServer_Servant servant, priv = listener->priv; if (priv->cal != CORBA_OBJECT_NIL) { - g_message ("Listener_cal_loaded(): calendar was already loaded!"); + g_message ("Listener_notifyCalOpened(): calendar was already open!"); return; } @@ -233,7 +188,7 @@ Listener_cal_loaded (PortableServer_Servant servant, cal_copy = CORBA_Object_duplicate (cal, &aev); if (aev._major != CORBA_NO_EXCEPTION) { - g_message ("Listener_cal_loaded(): could not duplicate the calendar"); + g_message ("Listener_notifyCalOpened(): could not duplicate the calendar"); CORBA_exception_free (&aev); return; } @@ -241,34 +196,40 @@ Listener_cal_loaded (PortableServer_Servant servant, priv->cal = cal_copy; - gtk_signal_emit (GTK_OBJECT (listener), cal_listener_signals[CAL_LOADED], - status, cal); + g_assert (priv->cal_opened_fn != NULL); + (* priv->cal_opened_fn) (listener, status, cal, priv->fn_data); } -/* Listener::obj_updated method */ +/* Listener::notifyObjUpdated method */ static void -Listener_obj_updated (PortableServer_Servant servant, - GNOME_Evolution_Calendar_CalObjUID uid, - CORBA_Environment *ev) +Listener_notifyObjUpdated (PortableServer_Servant servant, + GNOME_Evolution_Calendar_CalObjUID uid, + CORBA_Environment *ev) { CalListener *listener; + CalListenerPrivate *priv; listener = CAL_LISTENER (bonobo_object_from_servant (servant)); - gtk_signal_emit (GTK_OBJECT (listener), cal_listener_signals[OBJ_UPDATED], - uid); + priv = listener->priv; + + g_assert (priv->obj_updated_fn != NULL); + (* priv->obj_updated_fn) (listener, uid, priv->fn_data); } -/* Listener::obj_removed method */ +/* Listener::notifyObjRemoved method */ static void -Listener_obj_removed (PortableServer_Servant servant, - GNOME_Evolution_Calendar_CalObjUID uid, - CORBA_Environment *ev) +Listener_notifyObjRemoved (PortableServer_Servant servant, + GNOME_Evolution_Calendar_CalObjUID uid, + CORBA_Environment *ev) { CalListener *listener; + CalListenerPrivate *priv; listener = CAL_LISTENER (bonobo_object_from_servant (servant)); - gtk_signal_emit (GTK_OBJECT (listener), cal_listener_signals[OBJ_REMOVED], - uid); + priv = listener->priv; + + g_assert (priv->obj_removed_fn != NULL); + (* priv->obj_removed_fn) (listener, uid, priv->fn_data); } /** @@ -285,9 +246,9 @@ cal_listener_get_epv (void) POA_GNOME_Evolution_Calendar_Listener__epv *epv; epv = g_new0 (POA_GNOME_Evolution_Calendar_Listener__epv, 1); - epv->notifyCalLoaded = Listener_cal_loaded; - epv->notifyObjUpdated = Listener_obj_updated; - epv->notifyObjRemoved = Listener_obj_removed; + epv->notifyCalOpened = Listener_notifyCalOpened; + epv->notifyObjUpdated = Listener_notifyObjUpdated; + epv->notifyObjRemoved = Listener_notifyObjRemoved; return epv; } @@ -297,6 +258,14 @@ cal_listener_get_epv (void) * cal_listener_construct: * @listener: A calendar listener. * @corba_listener: CORBA object for the calendar listener. + * @cal_opened_fn: Function that will be called to notify that a calendar was + * opened. + * @obj_updated_fn: Function that will be called to notify that an object in the + * calendar was updated. + * @obj_removed_fn: Function that will be called to notify that an object in the + * calendar was removed. + * @fn_data: Closure data pointer that will be passed to the notification + * functions. * * Constructs a calendar listener by binding the corresponding CORBA object to * it. @@ -304,10 +273,27 @@ cal_listener_get_epv (void) * Return value: the same object as the @listener argument. **/ CalListener * -cal_listener_construct (CalListener *listener, GNOME_Evolution_Calendar_Listener corba_listener) +cal_listener_construct (CalListener *listener, + GNOME_Evolution_Calendar_Listener corba_listener, + CalListenerCalOpenedFn cal_opened_fn, + CalListenerObjUpdatedFn obj_updated_fn, + CalListenerObjRemovedFn obj_removed_fn, + gpointer fn_data) { + CalListenerPrivate *priv; + g_return_val_if_fail (listener != NULL, NULL); g_return_val_if_fail (IS_CAL_LISTENER (listener), NULL); + g_return_val_if_fail (cal_opened_fn != NULL, NULL); + g_return_val_if_fail (obj_updated_fn != NULL, NULL); + g_return_val_if_fail (obj_removed_fn != NULL, NULL); + + priv = listener->priv; + + priv->cal_opened_fn = cal_opened_fn; + priv->obj_updated_fn = obj_updated_fn; + priv->obj_removed_fn = obj_removed_fn; + priv->fn_data = fn_data; bonobo_object_construct (BONOBO_OBJECT (listener), corba_listener); return listener; @@ -349,7 +335,14 @@ cal_listener_corba_object_create (BonoboObject *object) /** * cal_listener_new: - * @void: + * @cal_opened_fn: Function that will be called to notify that a calendar was + * opened. + * @obj_updated_fn: Function that will be called to notify that an object in the + * calendar was updated. + * @obj_removed_fn: Function that will be called to notify that an object in the + * calendar was removed. + * @fn_data: Closure data pointer that will be passed to the notification + * functions. * * Creates a new #CalListener object. * @@ -357,13 +350,20 @@ cal_listener_corba_object_create (BonoboObject *object) * CORBA object could not be created. **/ CalListener * -cal_listener_new (void) +cal_listener_new (CalListenerCalOpenedFn cal_opened_fn, + CalListenerObjUpdatedFn obj_updated_fn, + CalListenerObjRemovedFn obj_removed_fn, + gpointer fn_data) { CalListener *listener; CORBA_Environment ev; GNOME_Evolution_Calendar_Listener corba_listener; gboolean result; + g_return_val_if_fail (cal_opened_fn != NULL, NULL); + g_return_val_if_fail (obj_updated_fn != NULL, NULL); + g_return_val_if_fail (obj_removed_fn != NULL, NULL); + listener = gtk_type_new (CAL_LISTENER_TYPE); corba_listener = cal_listener_corba_object_create (BONOBO_OBJECT (listener)); @@ -379,25 +379,10 @@ cal_listener_new (void) } CORBA_exception_free (&ev); - return cal_listener_construct (listener, corba_listener); -} - -/** - * cal_listener_get_calendar: - * @listener: A calendar listener. - * - * Queries the calendar that a listener is watching. - * - * Return value: The calendar that the listener is watching. - **/ -GNOME_Evolution_Calendar_Cal -cal_listener_get_calendar (CalListener *listener) -{ - CalListenerPrivate *priv; - - g_return_val_if_fail (listener != NULL, CORBA_OBJECT_NIL); - g_return_val_if_fail (IS_CAL_LISTENER (listener), CORBA_OBJECT_NIL); - - priv = listener->priv; - return priv->cal; + return cal_listener_construct (listener, + corba_listener, + cal_opened_fn, + obj_updated_fn, + obj_removed_fn, + fn_data); } diff --git a/calendar/cal-client/cal-listener.h b/calendar/cal-client/cal-listener.h index 1a12f07ca2..612d1d889f 100644 --- a/calendar/cal-client/cal-listener.h +++ b/calendar/cal-client/cal-listener.h @@ -1,8 +1,9 @@ /* Evolution calendar listener * * Copyright (C) 2000 Helix Code, Inc. + * Copyright (C) 2000 Ximian, Inc. * - * Author: Federico Mena-Quintero <federico@helixcode.com> + * Author: Federico Mena-Quintero <federico@ximian.com> * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -54,23 +55,42 @@ struct _CalListenerClass { /* Notification signals */ - void (* cal_loaded) (CalListener *listener, - GNOME_Evolution_Calendar_Listener_LoadStatus status, + void (* cal_opened) (CalListener *listener, + GNOME_Evolution_Calendar_Listener_OpenStatus status, GNOME_Evolution_Calendar_Cal cal); void (* obj_updated) (CalListener *listener, const GNOME_Evolution_Calendar_CalObjUID uid); void (* obj_removed) (CalListener *listener, const GNOME_Evolution_Calendar_CalObjUID uid); }; +/* Notification functions */ +typedef void (* CalListenerCalOpenedFn) (CalListener *listener, + GNOME_Evolution_Calendar_Listener_OpenStatus status, + GNOME_Evolution_Calendar_Cal cal, + gpointer data); + +typedef void (* CalListenerObjUpdatedFn) (CalListener *listener, + const GNOME_Evolution_Calendar_CalObjUID uid, + gpointer data); +typedef void (* CalListenerObjRemovedFn) (CalListener *listener, + const GNOME_Evolution_Calendar_CalObjUID uid, + gpointer data); + + GtkType cal_listener_get_type (void); CalListener *cal_listener_construct (CalListener *listener, - GNOME_Evolution_Calendar_Listener corba_listener); + GNOME_Evolution_Calendar_Listener corba_listener, + CalListenerCalOpenedFn cal_opened_fn, + CalListenerObjUpdatedFn obj_updated_fn, + CalListenerObjRemovedFn obj_removed_fn, + gpointer fn_data); GNOME_Evolution_Calendar_Listener cal_listener_corba_object_create (BonoboObject *object); -CalListener *cal_listener_new (void); - -GNOME_Evolution_Calendar_Cal cal_listener_get_calendar (CalListener *listener); +CalListener *cal_listener_new (CalListenerCalOpenedFn cal_opened_fn, + CalListenerObjUpdatedFn obj_updated_fn, + CalListenerObjRemovedFn obj_removed_fn, + gpointer fn_data); POA_GNOME_Evolution_Calendar_Listener__epv *cal_listener_get_epv (void); diff --git a/calendar/cal-client/client-test.c b/calendar/cal-client/client-test.c index c28e3f5696..7ff8aab8fc 100644 --- a/calendar/cal-client/client-test.c +++ b/calendar/cal-client/client-test.c @@ -1,8 +1,9 @@ /* Evolution calendar client - test program * * Copyright (C) 2000 Helix Code, Inc. + * Copyright (C) 2000 Ximian, Inc. * - * Author: Federico Mena-Quintero <federico@helixcode.com> + * Author: Federico Mena-Quintero <federico@ximian.com> * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -115,17 +116,18 @@ list_uids (gpointer data) return FALSE; } -/* Callback used when a calendar is loaded */ +/* Callback used when a calendar is opened */ static void -cal_loaded (CalClient *client, CalClientLoadStatus status, gpointer data) +cal_opened_cb (CalClient *client, CalClientOpenStatus status, gpointer data) { cl_printf (client, "Load/create %s\n", - ((status == CAL_CLIENT_LOAD_SUCCESS) ? "success" : - (status == CAL_CLIENT_LOAD_ERROR) ? "error" : - (status == CAL_CLIENT_LOAD_IN_USE) ? "in use" : + ((status == CAL_CLIENT_OPEN_SUCCESS) ? "success" : + (status == CAL_CLIENT_OPEN_ERROR) ? "error" : + (status == CAL_CLIENT_OPEN_NOT_FOUND) ? "not found" : + (status == CAL_CLIENT_OPEN_METHOD_NOT_SUPPORTED) ? "method not supported" : "unknown status value")); - if (status == CAL_CLIENT_LOAD_SUCCESS) + if (status == CAL_CLIENT_OPEN_SUCCESS) g_idle_add (list_uids, client); else gtk_object_unref (GTK_OBJECT (client)); @@ -133,7 +135,7 @@ cal_loaded (CalClient *client, CalClientLoadStatus status, gpointer data) /* Callback used when an object is updated */ static void -obj_updated (CalClient *client, const char *uid, gpointer data) +obj_updated_cb (CalClient *client, const char *uid, gpointer data) { cl_printf (client, "Object updated: %s\n", uid); } @@ -155,7 +157,7 @@ client_destroy_cb (GtkObject *object, gpointer data) /* Creates a calendar client and tries to load the specified URI into it */ static void -create_client (CalClient **client, const char *uri, gboolean load) +create_client (CalClient **client, const char *uri, gboolean only_if_exists) { gboolean result; @@ -169,23 +171,19 @@ create_client (CalClient **client, const char *uri, gboolean load) client_destroy_cb, NULL); - gtk_signal_connect (GTK_OBJECT (*client), "cal_loaded", - GTK_SIGNAL_FUNC (cal_loaded), + gtk_signal_connect (GTK_OBJECT (*client), "cal_opened", + GTK_SIGNAL_FUNC (cal_opened_cb), NULL); gtk_signal_connect (GTK_OBJECT (*client), "obj_updated", - GTK_SIGNAL_FUNC (obj_updated), + GTK_SIGNAL_FUNC (obj_updated_cb), NULL); printf ("Calendar loading `%s'...\n", uri); - if (load) - result = cal_client_load_calendar (*client, uri); - else - result = cal_client_create_calendar (*client, uri); + result = cal_client_open_calendar (*client, uri, only_if_exists); if (!result) { - g_message ("create_client(): failure when issuing calendar %s request `%s'", - load ? "load" : "create", + g_message ("create_client(): failure when issuing calendar open request `%s'", uri); exit (1); } @@ -205,8 +203,8 @@ main (int argc, char **argv) exit (1); } - create_client (&client1, "/cvs/evolution/calendar/cal-client/test.ics", TRUE); - create_client (&client2, "/cvs/evolution/calendar/cal-client/test.ics", FALSE); + create_client (&client1, "/cvs/evolution/calendar/cal-client/test.ics", FALSE); + create_client (&client2, "/cvs/evolution/calendar/cal-client/test.ics", TRUE); bonobo_main (); return 0; |