From ce71400f35232aa9122fceb3436dfc56b8b206e8 Mon Sep 17 00:00:00 2001 From: JP Rosevear Date: Tue, 25 Sep 2001 16:35:40 +0000 Subject: use bonobo-exception stuff to clean code 2001-09-25 JP Rosevear * pcs/cal.c: use bonobo-exception stuff to clean code * pcs/cal-factory.c (add_uri): add uri to the list if the type matches (impl_CalFactory_uriList): implement uriList method * pcs/cal-backend.h: new virtual function member * pcs/cal-backend.c (cal_backend_is_remote): call virtual function * pcs/cal-backend-file.c (cal_backend_file_class_init): override virtual function (cal_backend_file_is_remote): new virtual function, always return FALSE * idl/evolution-calendar.idl: uriList factory call, with flags for types to get * gui/dialogs/comp-editor.c (comp_editor_destroy): cast to remove warning * gui/e-itip-control.c (write_label_piece): kill warnings by take const char * * gui/component-factory.c (create_object): aggregate offline interface * gui/Makefile.am: compile new files * calobj.[hc]: Remove obsolete files * cal-util/cal-util.h: enum URI types for uriList call * cal-client/cal-client.c (build_uri_list): build list from string sequence (cal_client_uri_list): factory call to get uri list * cal-client/cal-client.h: new proto * cal-client/cal-client.c: use bonobo exception stuff to clean code * gui/calendar-offline-handler.[hc]: Start some skeleton routines for online/offline handling * pcs/cal-factory.c (launch_backend_for_uri): use accessor and remove FIXME svn path=/trunk/; revision=13110 --- calendar/pcs/cal-backend-file.c | 15 ++++++++ calendar/pcs/cal-backend.c | 27 ++++++++++++++- calendar/pcs/cal-backend.h | 2 ++ calendar/pcs/cal-factory.c | 77 ++++++++++++++++++++++++++++++++++++++--- calendar/pcs/cal.c | 68 ++++++++++++------------------------ 5 files changed, 139 insertions(+), 50 deletions(-) (limited to 'calendar/pcs') diff --git a/calendar/pcs/cal-backend-file.c b/calendar/pcs/cal-backend-file.c index 7407b6b7c0..a1e679b1c0 100644 --- a/calendar/pcs/cal-backend-file.c +++ b/calendar/pcs/cal-backend-file.c @@ -90,6 +90,7 @@ static GnomeVFSURI *cal_backend_file_get_uri (CalBackend *backend); static CalBackendOpenStatus cal_backend_file_open (CalBackend *backend, GnomeVFSURI *uri, gboolean only_if_exists); static gboolean cal_backend_file_is_loaded (CalBackend *backend); +static gboolean cal_backend_file_is_remote (CalBackend *backend); static int cal_backend_file_get_n_objects (CalBackend *backend, CalObjType type); static char *cal_backend_file_get_object (CalBackend *backend, const char *uid); @@ -169,6 +170,7 @@ cal_backend_file_class_init (CalBackendFileClass *class) backend_class->get_uri = cal_backend_file_get_uri; backend_class->open = cal_backend_file_open; backend_class->is_loaded = cal_backend_file_is_loaded; + backend_class->is_remote = cal_backend_file_is_remote; backend_class->get_n_objects = cal_backend_file_get_n_objects; backend_class->get_object = cal_backend_file_get_object; backend_class->get_object_component = cal_backend_file_get_object_component; @@ -878,6 +880,19 @@ cal_backend_file_is_loaded (CalBackend *backend) return (priv->icalcomp != NULL); } +/* is_remote handler for the file backend */ +static gboolean +cal_backend_file_is_remote (CalBackend *backend) +{ + CalBackendFile *cbfile; + CalBackendFilePrivate *priv; + + cbfile = CAL_BACKEND_FILE (backend); + priv = cbfile->priv; + + return FALSE; +} + /* Get_n_objects handler for the file backend */ static int cal_backend_file_get_n_objects (CalBackend *backend, CalObjType type) diff --git a/calendar/pcs/cal-backend.c b/calendar/pcs/cal-backend.c index 20f3a74ee1..296af0e8a3 100644 --- a/calendar/pcs/cal-backend.c +++ b/calendar/pcs/cal-backend.c @@ -144,6 +144,7 @@ cal_backend_class_init (CalBackendClass *class) class->get_uri = NULL; class->open = NULL; class->is_loaded = NULL; + class->is_remote = NULL; class->get_n_objects = NULL; class->get_object = NULL; class->get_object_component = NULL; @@ -278,7 +279,8 @@ cal_backend_open (CalBackend *backend, GnomeVFSURI *uri, gboolean only_if_exists * * Queries whether a calendar backend has been loaded yet. * - * Return value: TRUE if the backend has been loaded with data, FALSE otherwise. + * Return value: TRUE if the backend has been loaded with data, FALSE + * otherwise. **/ gboolean cal_backend_is_loaded (CalBackend *backend) @@ -294,6 +296,29 @@ cal_backend_is_loaded (CalBackend *backend) return result; } +/** + * cal_backend_is_remote: + * @backend: A calendar backend. + * + * Queries whether a calendar backend is connected remotely. + * + * Return value: TRUE if the backend is connected remotely, FALSE + * otherwise. + **/ +gboolean +cal_backend_is_remote (CalBackend *backend) +{ + gboolean result; + + g_return_val_if_fail (backend != NULL, FALSE); + g_return_val_if_fail (IS_CAL_BACKEND (backend), FALSE); + + g_assert (CLASS (backend)->is_remote != NULL); + result = (* CLASS (backend)->is_remote) (backend); + + return result; +} + /** * cal_backend_get_n_objects: * @backend: A calendar backend. diff --git a/calendar/pcs/cal-backend.h b/calendar/pcs/cal-backend.h index 1864a08f73..32617f94ae 100644 --- a/calendar/pcs/cal-backend.h +++ b/calendar/pcs/cal-backend.h @@ -81,6 +81,7 @@ struct _CalBackendClass { gboolean only_if_exists); gboolean (* is_loaded) (CalBackend *backend); + gboolean (* is_remote) (CalBackend *backend); /* General object acquirement and information related virtual methods */ int (* get_n_objects) (CalBackend *backend, CalObjType type); @@ -122,6 +123,7 @@ CalBackendOpenStatus cal_backend_open (CalBackend *backend, GnomeVFSURI *uri, gboolean only_if_exists); gboolean cal_backend_is_loaded (CalBackend *backend); +gboolean cal_backend_is_remote (CalBackend *backend); int cal_backend_get_n_objects (CalBackend *backend, CalObjType type); diff --git a/calendar/pcs/cal-factory.c b/calendar/pcs/cal-factory.c index 00f6d8b6da..458279b65f 100644 --- a/calendar/pcs/cal-factory.c +++ b/calendar/pcs/cal-factory.c @@ -25,6 +25,7 @@ #include #include #include +#include "evolution-calendar.h" #include "cal.h" #include "cal-backend.h" #include "cal-factory.h" @@ -50,6 +51,13 @@ struct _CalFactoryPrivate { guint registered : 1; }; +typedef struct +{ + CalFactory *factory; + GNOME_Evolution_Calendar_UriType type; + GNOME_Evolution_Calendar_StringSeq *list; +} CalFactoryUriData; + /* Signal IDs */ enum SIGNALS { LAST_CALENDAR_GONE, @@ -162,15 +170,13 @@ static CalBackend * launch_backend_for_uri (CalFactory *factory, GnomeVFSURI *uri, GNOME_Evolution_Calendar_Listener listener) { CalFactoryPrivate *priv; - char *method; + const char *method; GtkType *type; CalBackend *backend; priv = factory->priv; - /* FIXME: add an accessor function to gnome-vfs */ - method = uri->method_string; - + method = gnome_vfs_uri_get_scheme (uri); type = g_hash_table_lookup (priv->methods, method); if (!type) { @@ -301,6 +307,41 @@ add_calendar_client (CalFactory *factory, CalBackend *backend, GNOME_Evolution_C CORBA_exception_free (&ev); } +/* Add a uri to a string list */ +static void +add_uri (gpointer key, gpointer value, gpointer data) +{ + CalFactoryUriData *cfud = data; + CalFactory *factory = cfud->factory; + GNOME_Evolution_Calendar_StringSeq *list = cfud->list; + GNOME_Evolution_Calendar_UriType type = cfud->type; + char *uri_string = key; + CalBackend *backend; + GnomeVFSURI *uri; + + switch (type) { + case GNOME_Evolution_Calendar_URI_LOCAL: + uri = gnome_vfs_uri_new_private (uri_string, TRUE, TRUE, TRUE); + backend = lookup_backend (factory, uri); + gnome_vfs_uri_unref (uri); + if (backend == NULL && cal_backend_is_remote (backend)) + return; + break; + case GNOME_Evolution_Calendar_URI_REMOTE: + uri = gnome_vfs_uri_new_private (uri_string, TRUE, TRUE, TRUE); + backend = lookup_backend (factory, uri); + gnome_vfs_uri_unref (uri); + if (backend == NULL && !cal_backend_is_remote (backend)) + return; + break; + case GNOME_Evolution_Calendar_URI_ANY: + break; + } + + list->_buffer[list->_length] = CORBA_string_dup (uri_string); + list->_length++; +} + /* Job data */ typedef struct { CalFactory *factory; @@ -427,6 +468,33 @@ impl_CalFactory_open (PortableServer_Servant servant, job_add (open_fn, jd); } +static GNOME_Evolution_Calendar_StringSeq * +impl_CalFactory_uriList (PortableServer_Servant servant, + GNOME_Evolution_Calendar_UriType type, + CORBA_Environment *ev) +{ + CalFactory *factory; + CalFactoryPrivate *priv; + CalFactoryUriData cfud; + GNOME_Evolution_Calendar_StringSeq *list; + + factory = CAL_FACTORY (bonobo_object_from_servant (servant)); + priv = factory->priv; + + list = GNOME_Evolution_Calendar_StringSeq__alloc (); + list->_length = 0; + list->_maximum = g_hash_table_size (priv->backends); + list->_buffer = CORBA_sequence_CORBA_string_allocbuf (list->_maximum); + + cfud.factory = factory; + cfud.type = type; + cfud.list = list; + g_hash_table_foreach (priv->backends, add_uri, &cfud); + + return list; + +} + /** @@ -508,6 +576,7 @@ cal_factory_class_init (CalFactoryClass *klass) /* Epv methods */ epv->open = impl_CalFactory_open; + epv->uriList = impl_CalFactory_uriList; } /* Object initialization function for the calendar factory */ diff --git a/calendar/pcs/cal.c b/calendar/pcs/cal.c index 9532e8265a..481019bcb8 100644 --- a/calendar/pcs/cal.c +++ b/calendar/pcs/cal.c @@ -23,6 +23,7 @@ #include #include +#include #include "cal.h" #include "query.h" #include "wombat.h" @@ -118,9 +119,8 @@ impl_Cal_get_object (PortableServer_Servant servant, g_free (calobj); return calobj_copy; } else { - CORBA_exception_set (ev, CORBA_USER_EXCEPTION, - ex_GNOME_Evolution_Calendar_Cal_NotFound, - NULL); + bonobo_exception_set (ev, ex_GNOME_Evolution_Calendar_Cal_NotFound); + return NULL; } } @@ -218,9 +218,7 @@ impl_Cal_get_objects_in_range (PortableServer_Servant servant, t_end = (time_t) end; if (t_start > t_end || t_start == -1 || t_end == -1) { - CORBA_exception_set (ev, CORBA_USER_EXCEPTION, - ex_GNOME_Evolution_Calendar_Cal_InvalidRange, - NULL); + bonobo_exception_set (ev, ex_GNOME_Evolution_Calendar_Cal_InvalidRange); return NULL; } @@ -254,9 +252,7 @@ impl_Cal_get_free_busy (PortableServer_Servant servant, t_end = (time_t) end; if (t_start > t_end || t_start == -1 || t_end == -1) { - CORBA_exception_set (ev, CORBA_USER_EXCEPTION, - ex_GNOME_Evolution_Calendar_Cal_InvalidRange, - NULL); + bonobo_exception_set (ev, ex_GNOME_Evolution_Calendar_Cal_InvalidRange); return NULL; } @@ -295,9 +291,7 @@ impl_Cal_get_free_busy (PortableServer_Servant servant, return seq; } - CORBA_exception_set (ev, CORBA_USER_EXCEPTION, - ex_GNOME_Evolution_Calendar_Cal_NotFound, - NULL); + bonobo_exception_set (ev, ex_GNOME_Evolution_Calendar_Cal_NotFound); return NULL; } @@ -323,9 +317,7 @@ impl_Cal_get_alarms_in_range (PortableServer_Servant servant, seq = cal_backend_get_alarms_in_range (priv->backend, t_start, t_end, &valid_range); if (!valid_range) { - CORBA_exception_set (ev, CORBA_USER_EXCEPTION, - ex_GNOME_Evolution_Calendar_Cal_InvalidRange, - NULL); + bonobo_exception_set (ev, ex_GNOME_Evolution_Calendar_Cal_InvalidRange); return NULL; } @@ -359,15 +351,11 @@ impl_Cal_get_alarms_for_object (PortableServer_Servant servant, return alarms; case CAL_BACKEND_GET_ALARMS_NOT_FOUND: - CORBA_exception_set (ev, CORBA_USER_EXCEPTION, - ex_GNOME_Evolution_Calendar_Cal_NotFound, - NULL); + bonobo_exception_set (ev, ex_GNOME_Evolution_Calendar_Cal_NotFound); return NULL; case CAL_BACKEND_GET_ALARMS_INVALID_RANGE: - CORBA_exception_set (ev, CORBA_USER_EXCEPTION, - ex_GNOME_Evolution_Calendar_Cal_InvalidRange, - NULL); + bonobo_exception_set (ev, ex_GNOME_Evolution_Calendar_Cal_InvalidRange); return NULL; default: @@ -389,9 +377,7 @@ impl_Cal_update_objects (PortableServer_Servant servant, priv = cal->priv; if (!cal_backend_update_objects (priv->backend, calobj)) - CORBA_exception_set (ev, CORBA_USER_EXCEPTION, - ex_GNOME_Evolution_Calendar_Cal_InvalidObject, - NULL); + bonobo_exception_set (ev, ex_GNOME_Evolution_Calendar_Cal_InvalidObject); } /* Cal::remove_object method */ @@ -407,9 +393,7 @@ impl_Cal_remove_object (PortableServer_Servant servant, priv = cal->priv; if (!cal_backend_remove_object (priv->backend, uid)) - CORBA_exception_set (ev, CORBA_USER_EXCEPTION, - ex_GNOME_Evolution_Calendar_Cal_NotFound, - NULL); + bonobo_exception_set (ev, ex_GNOME_Evolution_Calendar_Cal_NotFound); } /* Cal::getQuery implementation */ @@ -430,20 +414,16 @@ impl_Cal_get_query (PortableServer_Servant servant, query = query_new (priv->backend, ql, sexp); if (!query) { - CORBA_exception_set (ev, CORBA_USER_EXCEPTION, - ex_GNOME_Evolution_Calendar_Cal_CouldNotCreate, - NULL); + bonobo_exception_set (ev, ex_GNOME_Evolution_Calendar_Cal_CouldNotCreate); return CORBA_OBJECT_NIL; } CORBA_exception_init (&ev2); query_copy = CORBA_Object_duplicate (BONOBO_OBJREF (query), &ev2); - if (ev2._major != CORBA_NO_EXCEPTION) { + if (BONOBO_EX (&ev2)) { CORBA_exception_free (&ev2); g_message ("Cal_get_query(): Could not duplicate the query reference"); - CORBA_exception_set (ev, CORBA_USER_EXCEPTION, - ex_GNOME_Evolution_Calendar_Cal_CouldNotCreate, - NULL); + bonobo_exception_set (ev, ex_GNOME_Evolution_Calendar_Cal_CouldNotCreate); return CORBA_OBJECT_NIL; } @@ -474,9 +454,7 @@ impl_Cal_get_timezone_object (PortableServer_Servant servant, g_free (calobj); return calobj_copy; } else { - CORBA_exception_set (ev, CORBA_USER_EXCEPTION, - ex_GNOME_Evolution_Calendar_Cal_NotFound, - NULL); + bonobo_exception_set (ev, ex_GNOME_Evolution_Calendar_Cal_NotFound); return NULL; } } @@ -511,7 +489,7 @@ cal_construct (Cal *cal, CORBA_exception_init (&ev); priv->listener = CORBA_Object_duplicate (listener, &ev); - if (ev._major != CORBA_NO_EXCEPTION) { + if (BONOBO_EX (&ev)) { g_message ("cal_construct: could not duplicate the listener"); priv->listener = CORBA_OBJECT_NIL; CORBA_exception_free (&ev); @@ -523,7 +501,7 @@ cal_construct (Cal *cal, priv->listener, "IDL:GNOME/Evolution/WombatClient:1.0", &ev); - if (ev._major != CORBA_NO_EXCEPTION) { + if (BONOBO_EX (&ev)) { g_message ("cal_construct: could not get the WombatClient interface"); priv->wombat_client = CORBA_OBJECT_NIL; } @@ -584,7 +562,7 @@ cal_destroy (GtkObject *object) CORBA_exception_init (&ev); bonobo_object_release_unref (priv->listener, &ev); - if (ev._major != CORBA_NO_EXCEPTION) + if (BONOBO_EX (&ev)) g_message ("cal_destroy(): could not release the listener"); priv->listener = NULL; @@ -665,7 +643,7 @@ cal_notify_update (Cal *cal, const char *uid) CORBA_exception_init (&ev); GNOME_Evolution_Calendar_Listener_notifyObjUpdated (priv->listener, (char *) uid, &ev); - if (ev._major != CORBA_NO_EXCEPTION) + if (BONOBO_EX (&ev)) g_message ("cal_notify_update(): could not notify the listener " "about an updated object"); @@ -696,7 +674,7 @@ cal_notify_remove (Cal *cal, const char *uid) CORBA_exception_init (&ev); GNOME_Evolution_Calendar_Listener_notifyObjRemoved (priv->listener, (char *) uid, &ev); - if (ev._major != CORBA_NO_EXCEPTION) + if (BONOBO_EX (&ev)) g_message ("cal_notify_remove(): could not notify the listener " "about a removed object"); @@ -727,7 +705,7 @@ cal_notify_categories_changed (Cal *cal, GNOME_Evolution_Calendar_StringSeq *cat CORBA_exception_init (&ev); GNOME_Evolution_Calendar_Listener_notifyCategoriesChanged (priv->listener, categories, &ev); - if (ev._major != CORBA_NO_EXCEPTION) + if (BONOBO_EX (&ev)) g_message ("cal_notify_categories_changed(): Could not notify the listener " "about the current set of categories"); @@ -765,7 +743,7 @@ cal_get_password (Cal *cal, const char *prompt, const char *key) (const CORBA_char *) prompt, (const CORBA_char *) key, &ev); - if (ev._major != CORBA_NO_EXCEPTION) { + if (BONOBO_EX (&ev)) { g_message ("cal_get_password: could not get password from associated WombatClient"); CORBA_exception_free (&ev); return NULL; @@ -804,7 +782,7 @@ cal_forget_password (Cal *cal, const char *key) (const CORBA_char *) key, &ev); - if (ev._major != CORBA_NO_EXCEPTION) { + if (BONOBO_EX (&ev)) { g_message ("cal_forget_password: could not notify WombatClient about " "password to be forgotten"); } -- cgit v1.2.3