diff options
Diffstat (limited to 'calendar/pcs')
-rw-r--r-- | calendar/pcs/cal-backend-file.c | 65 | ||||
-rw-r--r-- | calendar/pcs/cal-backend.c | 10 | ||||
-rw-r--r-- | calendar/pcs/cal-backend.h | 9 | ||||
-rw-r--r-- | calendar/pcs/cal-factory.c | 90 | ||||
-rw-r--r-- | calendar/pcs/cal.c | 7 |
5 files changed, 97 insertions, 84 deletions
diff --git a/calendar/pcs/cal-backend-file.c b/calendar/pcs/cal-backend-file.c index 3f0c73dc99..bb70686ce2 100644 --- a/calendar/pcs/cal-backend-file.c +++ b/calendar/pcs/cal-backend-file.c @@ -3,7 +3,8 @@ * Copyright (C) 2000 Ximian, Inc. * Copyright (C) 2000 Ximian, Inc. * - * Author: Federico Mena-Quintero <federico@ximian.com> + * Authors: Federico Mena-Quintero <federico@ximian.com> + * Rodrigo Moya <rodrigo@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 @@ -25,6 +26,7 @@ #include <bonobo/bonobo-exception.h> #include <bonobo/bonobo-moniker-util.h> #include <bonobo-conf/bonobo-config-database.h> +#include <libgnomevfs/gnome-vfs.h> #include "e-util/e-dbhash.h" #include "cal-util/cal-recur.h" #include "cal-util/cal-util.h" @@ -45,7 +47,7 @@ typedef struct { /* Private part of the CalBackendFile structure */ struct _CalBackendFilePrivate { /* URI where the calendar data is stored */ - GnomeVFSURI *uri; + char *uri; /* List of Cal objects with their listeners */ GList *clients; @@ -86,8 +88,9 @@ static void cal_backend_file_class_init (CalBackendFileClass *class); static void cal_backend_file_init (CalBackendFile *cbfile); static void cal_backend_file_destroy (GtkObject *object); -static GnomeVFSURI *cal_backend_file_get_uri (CalBackend *backend); -static CalBackendOpenStatus cal_backend_file_open (CalBackend *backend, GnomeVFSURI *uri, +static const char *cal_backend_file_get_uri (CalBackend *backend); +static CalBackendOpenStatus cal_backend_file_open (CalBackend *backend, + const char *uristr, gboolean only_if_exists); static gboolean cal_backend_file_is_loaded (CalBackend *backend); @@ -254,6 +257,7 @@ static void save (CalBackendFile *cbfile) { CalBackendFilePrivate *priv; + GnomeVFSURI *uri; GnomeVFSHandle *handle = NULL; GnomeVFSResult result; GnomeVFSFileSize out; @@ -264,8 +268,10 @@ save (CalBackendFile *cbfile) g_assert (priv->uri != NULL); g_assert (priv->icalcomp != NULL); + uri = gnome_vfs_uri_new (priv->uri); + /* Make a backup copy of the file if it exists */ - tmp = gnome_vfs_uri_to_string (priv->uri, GNOME_VFS_URI_HIDE_NONE); + tmp = gnome_vfs_uri_to_string (uri, GNOME_VFS_URI_HIDE_NONE); if (tmp) { GnomeVFSURI *backup_uri; gchar *backup_uristr; @@ -273,7 +279,7 @@ save (CalBackendFile *cbfile) backup_uristr = g_strconcat (tmp, "~", NULL); backup_uri = gnome_vfs_uri_new (backup_uristr); - result = gnome_vfs_move_uri (priv->uri, backup_uri, TRUE); + result = gnome_vfs_move_uri (uri, backup_uri, TRUE); gnome_vfs_uri_unref (backup_uri); g_free (tmp); @@ -281,7 +287,7 @@ save (CalBackendFile *cbfile) } /* Now write the new file out */ - result = gnome_vfs_create_uri (&handle, priv->uri, + result = gnome_vfs_create_uri (&handle, uri, GNOME_VFS_OPEN_WRITE, FALSE, 0666); @@ -295,6 +301,7 @@ save (CalBackendFile *cbfile) goto error; gnome_vfs_close (handle); + gnome_vfs_uri_unref (uri); return; @@ -342,7 +349,7 @@ cal_backend_file_destroy (GtkObject *object) /* Clean up */ if (priv->uri) { - gnome_vfs_uri_unref (priv->uri); + g_free (priv->uri); priv->uri = NULL; } @@ -404,7 +411,7 @@ lookup_component (CalBackendFile *cbfile, const char *uid) /* Calendar backend methods */ /* Get_uri handler for the file backend */ -static GnomeVFSURI * +static const char * cal_backend_file_get_uri (CalBackend *backend) { CalBackendFile *cbfile; @@ -416,7 +423,7 @@ cal_backend_file_get_uri (CalBackend *backend) g_return_val_if_fail (priv->icalcomp != NULL, NULL); g_assert (priv->uri != NULL); - return priv->uri; + return (const char *) priv->uri; } /* Used from g_hash_table_foreach(), adds a category name to the sequence */ @@ -768,7 +775,7 @@ parse_file (FILE *file) /* Parses an open iCalendar file and loads it into the backend */ static CalBackendOpenStatus -open_cal (CalBackendFile *cbfile, GnomeVFSURI *uri, FILE *file) +open_cal (CalBackendFile *cbfile, const char *uristr, FILE *file) { CalBackendFilePrivate *priv; icalcomponent *icalcomp; @@ -801,14 +808,13 @@ open_cal (CalBackendFile *cbfile, GnomeVFSURI *uri, FILE *file) priv->comp_uid_hash = g_hash_table_new (g_str_hash, g_str_equal); scan_vcalendar (cbfile); - gnome_vfs_uri_ref (uri); - priv->uri = uri; + priv->uri = g_strdup (uristr); return CAL_BACKEND_OPEN_SUCCESS; } static CalBackendOpenStatus -create_cal (CalBackendFile *cbfile, GnomeVFSURI *uri) +create_cal (CalBackendFile *cbfile, const char *uristr) { CalBackendFilePrivate *priv; @@ -820,8 +826,7 @@ create_cal (CalBackendFile *cbfile, GnomeVFSURI *uri) /* Create our internal data */ priv->comp_uid_hash = g_hash_table_new (g_str_hash, g_str_equal); - gnome_vfs_uri_ref (uri); - priv->uri = uri; + priv->uri = g_strdup (uristr); mark_dirty (cbfile); @@ -830,12 +835,14 @@ create_cal (CalBackendFile *cbfile, GnomeVFSURI *uri) /* Open handler for the file backend */ static CalBackendOpenStatus -cal_backend_file_open (CalBackend *backend, GnomeVFSURI *uri, gboolean only_if_exists) +cal_backend_file_open (CalBackend *backend, const char *uristr, gboolean only_if_exists) { CalBackendFile *cbfile; CalBackendFilePrivate *priv; - char *str_uri; FILE *file; + char *str_uri; + GnomeVFSURI *uri; + CalBackendOpenStatus status; cbfile = CAL_BACKEND_FILE (backend); priv = cbfile->priv; @@ -846,9 +853,15 @@ cal_backend_file_open (CalBackend *backend, GnomeVFSURI *uri, gboolean only_if_e g_assert (priv->uri == NULL); g_assert (priv->comp_uid_hash == NULL); - if (!gnome_vfs_uri_is_local (uri)) + uri = gnome_vfs_uri_new (uristr); + if (!uri) return CAL_BACKEND_OPEN_ERROR; + if (!gnome_vfs_uri_is_local (uri)) { + gnome_vfs_uri_unref (uri); + return CAL_BACKEND_OPEN_ERROR; + } + str_uri = gnome_vfs_uri_to_string (uri, (GNOME_VFS_URI_HIDE_USER_NAME | GNOME_VFS_URI_HIDE_PASSWORD @@ -858,16 +871,20 @@ cal_backend_file_open (CalBackend *backend, GnomeVFSURI *uri, gboolean only_if_e /* Load! */ file = fopen (str_uri, "r"); - g_free (str_uri); if (file) - return open_cal (cbfile, uri, file); + status = open_cal (cbfile, str_uri, file); else { if (only_if_exists) - return CAL_BACKEND_OPEN_NOT_FOUND; - - return create_cal (cbfile, uri); + status = CAL_BACKEND_OPEN_NOT_FOUND; + else + status = create_cal (cbfile, str_uri); } + + g_free (str_uri); + gnome_vfs_uri_unref (uri); + + return status; } /* is_loaded handler for the file backend */ diff --git a/calendar/pcs/cal-backend.c b/calendar/pcs/cal-backend.c index ae2bd328eb..d123f17ec6 100644 --- a/calendar/pcs/cal-backend.c +++ b/calendar/pcs/cal-backend.c @@ -171,7 +171,7 @@ cal_backend_class_init (CalBackendClass *class) * * Return value: The URI where the calendar is stored. **/ -GnomeVFSURI * +const char * cal_backend_get_uri (CalBackend *backend) { g_return_val_if_fail (backend != NULL, NULL); @@ -249,7 +249,7 @@ cal_backend_add_cal (CalBackend *backend, Cal *cal) /** * cal_backend_open: * @backend: A calendar backend. - * @uri: URI that contains the calendar data. + * @uristr: URI that contains the calendar data. * @only_if_exists: Whether the calendar should be opened only if it already * exists. If FALSE, a new calendar will be created when the specified @uri * does not exist. @@ -260,16 +260,16 @@ cal_backend_add_cal (CalBackend *backend, Cal *cal) * Return value: An operation status code. **/ CalBackendOpenStatus -cal_backend_open (CalBackend *backend, GnomeVFSURI *uri, gboolean only_if_exists) +cal_backend_open (CalBackend *backend, const char *uristr, gboolean only_if_exists) { CalBackendOpenStatus result; g_return_val_if_fail (backend != NULL, CAL_BACKEND_OPEN_ERROR); g_return_val_if_fail (IS_CAL_BACKEND (backend), CAL_BACKEND_OPEN_ERROR); - g_return_val_if_fail (uri != NULL, CAL_BACKEND_OPEN_ERROR); + g_return_val_if_fail (uristr != NULL, CAL_BACKEND_OPEN_ERROR); g_assert (CLASS (backend)->open != NULL); - result = (* CLASS (backend)->open) (backend, uri, only_if_exists); + result = (* CLASS (backend)->open) (backend, uristr, only_if_exists); return result; } diff --git a/calendar/pcs/cal-backend.h b/calendar/pcs/cal-backend.h index ff5d31d0dd..669de43f8e 100644 --- a/calendar/pcs/cal-backend.h +++ b/calendar/pcs/cal-backend.h @@ -26,7 +26,6 @@ #define CAL_BACKEND_H #include <libgnome/gnome-defs.h> -#include <libgnomevfs/gnome-vfs.h> #include <cal-util/cal-util.h> #include <cal-util/cal-component.h> #include "evolution-calendar.h" @@ -75,9 +74,9 @@ struct _CalBackendClass { void (* obj_removed) (CalBackend *backend, const char *uid); /* Virtual methods */ - GnomeVFSURI *(* get_uri) (CalBackend *backend); + const char *(* get_uri) (CalBackend *backend); - CalBackendOpenStatus (* open) (CalBackend *backend, GnomeVFSURI *uri, + CalBackendOpenStatus (* open) (CalBackend *backend, const char *uristr, gboolean only_if_exists); gboolean (* is_loaded) (CalBackend *backend); @@ -118,11 +117,11 @@ struct _CalBackendClass { GtkType cal_backend_get_type (void); -GnomeVFSURI *cal_backend_get_uri (CalBackend *backend); +const char *cal_backend_get_uri (CalBackend *backend); void cal_backend_add_cal (CalBackend *backend, Cal *cal); -CalBackendOpenStatus cal_backend_open (CalBackend *backend, GnomeVFSURI *uri, +CalBackendOpenStatus cal_backend_open (CalBackend *backend, const char *uristr, gboolean only_if_exists); gboolean cal_backend_is_loaded (CalBackend *backend); diff --git a/calendar/pcs/cal-factory.c b/calendar/pcs/cal-factory.c index 32786861bd..9b4bc2fc67 100644 --- a/calendar/pcs/cal-factory.c +++ b/calendar/pcs/cal-factory.c @@ -25,6 +25,7 @@ #include <stdio.h> #include <gtk/gtksignal.h> #include <liboaf/liboaf.h> +#include "e-util/e-url.h" #include "evolution-calendar.h" #include "cal.h" #include "cal-backend.h" @@ -84,13 +85,13 @@ free_method (gpointer key, gpointer value, gpointer data) static void free_backend (gpointer key, gpointer value, gpointer data) { - GnomeVFSURI *uri; + char *uri; CalBackend *backend; uri = key; backend = value; - gnome_vfs_uri_unref (uri); + g_free (uri); gtk_object_unref (GTK_OBJECT (backend)); } @@ -98,14 +99,14 @@ free_backend (gpointer key, gpointer value, gpointer data) /* Looks up a calendar backend in a factory's hash table of uri->cal */ static CalBackend * -lookup_backend (CalFactory *factory, GnomeVFSURI *uri) +lookup_backend (CalFactory *factory, const char *uristr) { CalFactoryPrivate *priv; CalBackend *backend; priv = factory->priv; - backend = g_hash_table_lookup (priv->backends, uri); + backend = g_hash_table_lookup (priv->backends, uristr); return backend; } @@ -115,10 +116,10 @@ backend_last_client_gone_cb (CalBackend *backend, gpointer data) { CalFactory *factory; CalFactoryPrivate *priv; - GnomeVFSURI *uri; + const char *uristr; gpointer orig_key; gboolean result; - GnomeVFSURI *orig_uri; + const char *orig_uristr; fprintf (stderr, "backend_last_client_gone_cb() called!\n"); @@ -127,16 +128,16 @@ backend_last_client_gone_cb (CalBackend *backend, gpointer data) /* Remove the backend from the hash table */ - uri = cal_backend_get_uri (backend); - g_assert (uri != NULL); + uristr = cal_backend_get_uri (backend); + g_assert (uristr != NULL); - result = g_hash_table_lookup_extended (priv->backends, uri, &orig_key, NULL); + result = g_hash_table_lookup_extended (priv->backends, uristr, &orig_key, NULL); g_assert (result != FALSE); - orig_uri = orig_key; + orig_uristr = orig_key; - g_hash_table_remove (priv->backends, orig_uri); - gnome_vfs_uri_unref (orig_uri); + g_hash_table_remove (priv->backends, orig_uristr); + g_free ((gpointer) orig_uristr); gtk_object_unref (GTK_OBJECT (backend)); @@ -148,14 +149,13 @@ backend_last_client_gone_cb (CalBackend *backend, gpointer data) /* Adds a backend to the calendar factory's hash table */ static void -add_backend (CalFactory *factory, GnomeVFSURI *uri, CalBackend *backend) +add_backend (CalFactory *factory, const char *uristr, CalBackend *backend) { CalFactoryPrivate *priv; priv = factory->priv; - gnome_vfs_uri_ref (uri); - g_hash_table_insert (priv->backends, uri, backend); + g_hash_table_insert (priv->backends, g_strdup (uristr), backend); gtk_signal_connect (GTK_OBJECT (backend), "last_client_gone", GTK_SIGNAL_FUNC (backend_last_client_gone_cb), @@ -167,17 +167,25 @@ add_backend (CalFactory *factory, GnomeVFSURI *uri, CalBackend *backend) * MethodNotSupported error code. */ static CalBackend * -launch_backend_for_uri (CalFactory *factory, GnomeVFSURI *uri, GNOME_Evolution_Calendar_Listener listener) +launch_backend_for_uri (CalFactory *factory, + const char *uristr, + GNOME_Evolution_Calendar_Listener listener) { CalFactoryPrivate *priv; const char *method; GtkType *type; CalBackend *backend; + EUri *uri; priv = factory->priv; - method = gnome_vfs_uri_get_scheme (uri); + uri = e_uri_new (uristr); + if (!uri) + return NULL; + + method = uri->protocol; type = g_hash_table_lookup (priv->methods, method); + e_uri_free (uri); if (!type) { CORBA_Environment ev; @@ -205,7 +213,7 @@ launch_backend_for_uri (CalFactory *factory, GnomeVFSURI *uri, GNOME_Evolution_C /* Opens a calendar backend and puts it in the factory's backend hash table */ static CalBackend * -open_backend (CalFactory *factory, GnomeVFSURI *uri, gboolean only_if_exists, +open_backend (CalFactory *factory, const char *uristr, gboolean only_if_exists, GNOME_Evolution_Calendar_Listener listener) { CalFactoryPrivate *priv; @@ -215,15 +223,15 @@ open_backend (CalFactory *factory, GnomeVFSURI *uri, gboolean only_if_exists, priv = factory->priv; - backend = launch_backend_for_uri (factory, uri, listener); + backend = launch_backend_for_uri (factory, uristr, listener); if (!backend) return NULL; - status = cal_backend_open (backend, uri, only_if_exists); + status = cal_backend_open (backend, uristr, only_if_exists); switch (status) { case CAL_BACKEND_OPEN_SUCCESS: - add_backend (factory, uri, backend); + add_backend (factory, uristr, backend); return backend; case CAL_BACKEND_OPEN_ERROR: @@ -268,7 +276,9 @@ open_backend (CalFactory *factory, GnomeVFSURI *uri, gboolean only_if_exists, * object. */ static void -add_calendar_client (CalFactory *factory, CalBackend *backend, GNOME_Evolution_Calendar_Listener listener) +add_calendar_client (CalFactory *factory, + CalBackend *backend, + GNOME_Evolution_Calendar_Listener listener) { Cal *cal; CORBA_Environment ev; @@ -316,21 +326,16 @@ add_uri (gpointer key, gpointer value, gpointer data) GNOME_Evolution_Calendar_StringSeq *list = cfud->list; GNOME_Evolution_Calendar_CalMode mode = cfud->mode; char *uri_string = key; - CalBackend *backend; - GnomeVFSURI *uri; + CalBackend *backend; switch (mode) { case GNOME_Evolution_Calendar_MODE_LOCAL: - uri = gnome_vfs_uri_new_private (uri_string, TRUE, TRUE, TRUE); - backend = lookup_backend (factory, uri); - gnome_vfs_uri_unref (uri); + backend = lookup_backend (factory, uri_string); if (backend == NULL && cal_backend_get_mode (backend) == CAL_MODE_LOCAL) return; break; case GNOME_Evolution_Calendar_MODE_REMOTE: - uri = gnome_vfs_uri_new_private (uri_string, TRUE, TRUE, TRUE); - backend = lookup_backend (factory, uri); - gnome_vfs_uri_unref (uri); + backend = lookup_backend (factory, uri_string); if (backend == NULL && cal_backend_get_mode (backend) == CAL_MODE_REMOTE) return; break; @@ -356,18 +361,17 @@ open_fn (gpointer data) { OpenJobData *jd; CalFactory *factory; - GnomeVFSURI *uri; gboolean only_if_exists; GNOME_Evolution_Calendar_Listener listener; CalBackend *backend; CORBA_Environment ev; + char *uri_string; jd = data; g_assert (jd->uri != NULL); /* Check the URI */ - - uri = gnome_vfs_uri_new_private (jd->uri, TRUE, TRUE, TRUE); + uri_string = g_strdup (jd->uri); g_free (jd->uri); only_if_exists = jd->only_if_exists; @@ -375,7 +379,7 @@ open_fn (gpointer data) listener = jd->listener; g_free (jd); - if (!uri) { + if (!uri_string) { CORBA_exception_init (&ev); GNOME_Evolution_Calendar_Listener_notifyCalOpened ( listener, @@ -392,12 +396,10 @@ open_fn (gpointer data) /* Look up the backend and create it if needed */ - backend = lookup_backend (factory, uri); + backend = lookup_backend (factory, uri_string); if (!backend) - backend = open_backend (factory, uri, only_if_exists, listener); - - gnome_vfs_uri_unref (uri); + backend = open_backend (factory, uri_string, only_if_exists, listener); if (backend) add_calendar_client (factory, backend, listener); @@ -428,16 +430,15 @@ impl_CalFactory_open (PortableServer_Servant servant, gboolean result; OpenJobData *jd; GNOME_Evolution_Calendar_Listener listener_copy; - GnomeVFSURI *uri; - const char *method_str; GtkType type; + EUri *uri; factory = CAL_FACTORY (bonobo_object_from_servant (servant)); priv = factory->priv; /* check URI to see if we support it */ - uri = gnome_vfs_uri_new_private (str_uri, TRUE, TRUE, TRUE); + uri = e_uri_new (str_uri); if (!uri) { CORBA_exception_set (ev, CORBA_USER_EXCEPTION, ex_GNOME_Evolution_Calendar_CalFactory_InvalidURI, @@ -445,10 +446,9 @@ impl_CalFactory_open (PortableServer_Servant servant, return; } - method_str = gnome_vfs_uri_get_scheme (uri); - type = g_hash_table_lookup (priv->methods, method_str); + type = g_hash_table_lookup (priv->methods, uri->protocol); - gnome_vfs_uri_unref (uri); + e_uri_free (uri); if (!type) { CORBA_exception_set (ev, CORBA_USER_EXCEPTION, ex_GNOME_Evolution_Calendar_CalFactory_UnsupportedMethod, @@ -615,7 +615,7 @@ cal_factory_init (CalFactory *factory) factory->priv = priv; priv->methods = g_hash_table_new (g_str_hash, g_str_equal); - priv->backends = g_hash_table_new (gnome_vfs_uri_hash, gnome_vfs_uri_hequal); + priv->backends = g_hash_table_new (g_str_hash, g_str_equal); priv->registered = FALSE; } diff --git a/calendar/pcs/cal.c b/calendar/pcs/cal.c index 7a21aed95e..973b6aa980 100644 --- a/calendar/pcs/cal.c +++ b/calendar/pcs/cal.c @@ -40,7 +40,7 @@ struct _CalPrivate { /* Listener on the client we notify */ GNOME_Evolution_Calendar_Listener listener; - /* and a reference to the WombatClient interface */ + /* A reference to the WombatClient interface */ GNOME_Evolution_WombatClient wombat_client; }; @@ -52,17 +52,14 @@ impl_Cal_get_uri (PortableServer_Servant servant, { Cal *cal; CalPrivate *priv; - GnomeVFSURI *uri; char *str_uri; CORBA_char *str_uri_copy; cal = CAL (bonobo_object_from_servant (servant)); priv = cal->priv; - uri = cal_backend_get_uri (priv->backend); - str_uri = gnome_vfs_uri_to_string (uri, GNOME_VFS_URI_HIDE_NONE); + str_uri = cal_backend_get_uri (priv->backend); str_uri_copy = CORBA_string_dup (str_uri); - g_free (str_uri); return str_uri_copy; } |