aboutsummaryrefslogtreecommitdiffstats
path: root/calendar/pcs
diff options
context:
space:
mode:
Diffstat (limited to 'calendar/pcs')
-rw-r--r--calendar/pcs/cal-backend-file.c147
-rw-r--r--calendar/pcs/cal-backend-file.h3
-rw-r--r--calendar/pcs/cal-backend.c99
-rw-r--r--calendar/pcs/cal-backend.h22
-rw-r--r--calendar/pcs/cal-common.h3
-rw-r--r--calendar/pcs/cal-factory.c298
-rw-r--r--calendar/pcs/cal-factory.h3
-rw-r--r--calendar/pcs/cal.c3
-rw-r--r--calendar/pcs/cal.h3
-rw-r--r--calendar/pcs/job.c3
-rw-r--r--calendar/pcs/job.h3
11 files changed, 214 insertions, 373 deletions
diff --git a/calendar/pcs/cal-backend-file.c b/calendar/pcs/cal-backend-file.c
index 10d0a35746..623031fa69 100644
--- a/calendar/pcs/cal-backend-file.c
+++ b/calendar/pcs/cal-backend-file.c
@@ -1,8 +1,9 @@
/* Evolution calendar - iCalendar file backend
*
* 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
@@ -65,8 +66,8 @@ static void cal_backend_file_destroy (GtkObject *object);
static GnomeVFSURI *cal_backend_file_get_uri (CalBackend *backend);
static void cal_backend_file_add_cal (CalBackend *backend, Cal *cal);
-static CalBackendLoadStatus cal_backend_file_load (CalBackend *backend, GnomeVFSURI *uri);
-static void cal_backend_file_create (CalBackend *backend, GnomeVFSURI *uri);
+static CalBackendOpenStatus cal_backend_file_open (CalBackend *backend, GnomeVFSURI *uri,
+ gboolean only_if_exists);
static int cal_backend_file_get_n_objects (CalBackend *backend, CalObjType type);
static char *cal_backend_file_get_object (CalBackend *backend, const char *uid);
@@ -138,8 +139,7 @@ cal_backend_file_class_init (CalBackendFileClass *class)
backend_class->get_uri = cal_backend_file_get_uri;
backend_class->add_cal = cal_backend_file_add_cal;
- backend_class->load = cal_backend_file_load;
- backend_class->create = cal_backend_file_create;
+ backend_class->open = cal_backend_file_open;
backend_class->get_n_objects = cal_backend_file_get_n_objects;
backend_class->get_object = cal_backend_file_get_object;
backend_class->get_type_by_uid = cal_backend_file_get_type_by_uid;
@@ -587,7 +587,7 @@ scan_vcalendar (CalBackendFile *cbfile)
/* Callback used from icalparser_parse() */
static char *
-get_line (char *s, size_t size, void *data)
+get_line_fn (char *s, size_t size, void *data)
{
FILE *file;
@@ -595,91 +595,71 @@ get_line (char *s, size_t size, void *data)
return fgets (s, size, file);
}
-/* Load handler for the file backend */
-static CalBackendLoadStatus
-cal_backend_file_load (CalBackend *backend, GnomeVFSURI *uri)
+/* Parses an open iCalendar file and returns a toplevel component with the contents */
+static icalcomponent *
+parse_file (FILE *file)
{
- CalBackendFile *cbfile;
- CalBackendFilePrivate *priv;
- char *str_uri;
- FILE *file;
icalparser *parser;
icalcomponent *icalcomp;
- cbfile = CAL_BACKEND_FILE (backend);
- priv = cbfile->priv;
-
- g_return_val_if_fail (priv->icalcomp == NULL, CAL_BACKEND_LOAD_ERROR);
- g_return_val_if_fail (uri != NULL, CAL_BACKEND_LOAD_ERROR);
+ parser = icalparser_new ();
+ icalparser_set_gen_data (parser, file);
- if (!gnome_vfs_uri_is_local (uri))
- return CAL_BACKEND_LOAD_ERROR;
+ icalcomp = icalparser_parse (parser, get_line_fn);
+ icalparser_free (parser);
- str_uri = gnome_vfs_uri_to_string (uri,
- (GNOME_VFS_URI_HIDE_USER_NAME
- | GNOME_VFS_URI_HIDE_PASSWORD
- | GNOME_VFS_URI_HIDE_HOST_NAME
- | GNOME_VFS_URI_HIDE_HOST_PORT
- | GNOME_VFS_URI_HIDE_TOPLEVEL_METHOD));
+ return icalcomp;
+}
- /* Load! */
- file = fopen (str_uri, "r");
- g_free (str_uri);
+/* Parses an open iCalendar file and loads it into the backend */
+static CalBackendOpenStatus
+open_cal (CalBackendFile *cbfile, GnomeVFSURI *uri, FILE *file)
+{
+ CalBackendFilePrivate *priv;
+ icalcomponent *icalcomp;
- if (!file)
- return CAL_BACKEND_LOAD_ERROR;
+ priv = cbfile->priv;
- parser = icalparser_new ();
- icalparser_set_gen_data (parser, file);
+ icalcomp = parse_file (file);
- icalcomp = icalparser_parse (parser, get_line);
- icalparser_free (parser);
+ if (fclose (file) != 0) {
+ if (icalcomp)
+ icalcomponent_free (icalcomp);
- if (fclose (file) != 0)
- return CAL_BACKEND_LOAD_ERROR;
+ return CAL_BACKEND_OPEN_ERROR;
+ }
if (!icalcomp)
- return CAL_BACKEND_LOAD_ERROR;
-
- /* FIXME: should we try to demangle XROOT components and individual
- * components as well?
+ return CAL_BACKEND_OPEN_ERROR;
+
+ /* FIXME: should we try to demangle XROOT components and
+ * individual components as well?
*/
if (icalcomponent_isa (icalcomp) != ICAL_VCALENDAR_COMPONENT)
- return CAL_BACKEND_LOAD_ERROR;
+ return CAL_BACKEND_OPEN_ERROR;
priv->icalcomp = icalcomp;
priv->comp_uid_hash = g_hash_table_new (g_str_hash, g_str_equal);
scan_vcalendar (cbfile);
- /* Clean up */
- if (priv->uri)
- gnome_vfs_uri_unref (priv->uri);
-
gnome_vfs_uri_ref (uri);
priv->uri = uri;
- return CAL_BACKEND_LOAD_SUCCESS;
+ return CAL_BACKEND_OPEN_SUCCESS;
}
-/* Create handler for the file backend */
-static void
-cal_backend_file_create (CalBackend *backend, GnomeVFSURI *uri)
+static CalBackendOpenStatus
+create_cal (CalBackendFile *cbfile, GnomeVFSURI *uri)
{
- CalBackendFile *cbfile;
CalBackendFilePrivate *priv;
icalproperty *prop;
- cbfile = CAL_BACKEND_FILE (backend);
priv = cbfile->priv;
- g_return_if_fail (priv->icalcomp == NULL);
- g_return_if_fail (uri != NULL);
-
/* Create the new calendar information */
- g_assert (priv->icalcomp == NULL);
priv->icalcomp = icalcomponent_new (ICAL_VCALENDAR_COMPONENT);
/* RFC 2445, section 4.7.1 */
@@ -687,26 +667,67 @@ cal_backend_file_create (CalBackend *backend, GnomeVFSURI *uri)
icalcomponent_add_property (priv->icalcomp, prop);
/* RFC 2445, section 4.7.3 */
- prop = icalproperty_new_prodid ("-//Helix Code//NONSGML Evolution Calendar//EN");
+ prop = icalproperty_new_prodid ("-//Ximian//NONSGML Evolution Calendar//EN");
icalcomponent_add_property (priv->icalcomp, prop);
- /* RFC 2445, section 4.7.4 */
+ /* RFC 2445, section 4.7.4. This is the iCalendar spec version, *NOT*
+ * the product version! Do not change this!
+ */
prop = icalproperty_new_version ("2.0");
icalcomponent_add_property (priv->icalcomp, prop);
/* Create our internal data */
- g_assert (priv->comp_uid_hash == NULL);
priv->comp_uid_hash = g_hash_table_new (g_str_hash, g_str_equal);
- /* Clean up */
- if (priv->uri)
- gnome_vfs_uri_unref (priv->uri);
-
gnome_vfs_uri_ref (uri);
priv->uri = uri;
mark_dirty (cbfile);
+
+ return CAL_BACKEND_OPEN_SUCCESS;
+}
+
+/* Open handler for the file backend */
+static CalBackendOpenStatus
+cal_backend_file_open (CalBackend *backend, GnomeVFSURI *uri, gboolean only_if_exists)
+{
+ CalBackendFile *cbfile;
+ CalBackendFilePrivate *priv;
+ char *str_uri;
+ FILE *file;
+
+ cbfile = CAL_BACKEND_FILE (backend);
+ priv = cbfile->priv;
+
+ g_return_val_if_fail (priv->icalcomp == NULL, CAL_BACKEND_OPEN_ERROR);
+ g_return_val_if_fail (uri != NULL, CAL_BACKEND_OPEN_ERROR);
+
+ g_assert (priv->uri == NULL);
+ g_assert (priv->comp_uid_hash == NULL);
+
+ if (!gnome_vfs_uri_is_local (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
+ | GNOME_VFS_URI_HIDE_HOST_NAME
+ | GNOME_VFS_URI_HIDE_HOST_PORT
+ | GNOME_VFS_URI_HIDE_TOPLEVEL_METHOD));
+
+ /* Load! */
+ file = fopen (str_uri, "r");
+ g_free (str_uri);
+
+ if (file)
+ return open_cal (cbfile, uri, file);
+ else {
+ if (only_if_exists)
+ return CAL_BACKEND_OPEN_NOT_FOUND;
+
+ return create_cal (cbfile, uri);
+ }
}
/* Get_n_objects handler for the file backend */
diff --git a/calendar/pcs/cal-backend-file.h b/calendar/pcs/cal-backend-file.h
index 376790751c..a85c6d20fd 100644
--- a/calendar/pcs/cal-backend-file.h
+++ b/calendar/pcs/cal-backend-file.h
@@ -1,8 +1,9 @@
/* Evolution calendar - iCalendar file backend
*
* 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
diff --git a/calendar/pcs/cal-backend.c b/calendar/pcs/cal-backend.c
index 0dc5d45883..6353fbbcd7 100644
--- a/calendar/pcs/cal-backend.c
+++ b/calendar/pcs/cal-backend.c
@@ -2,9 +2,10 @@
/* Evolution calendar - generic backend class
*
* 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
@@ -40,10 +41,6 @@ enum {
};
static void cal_backend_class_init (CalBackendClass *class);
-static void cal_backend_init (CalBackend *backend);
-static void cal_backend_destroy (GtkObject *object);
-
-static GtkObjectClass *parent_class;
static guint cal_backend_signals[LAST_SIGNAL];
@@ -71,7 +68,7 @@ cal_backend_get_type (void)
sizeof (CalBackend),
sizeof (CalBackendClass),
(GtkClassInitFunc) cal_backend_class_init,
- (GtkObjectInitFunc) cal_backend_init,
+ (GtkObjectInitFunc) NULL,
NULL, /* reserved_1 */
NULL, /* reserved_2 */
(GtkClassInitFunc) NULL
@@ -92,10 +89,6 @@ cal_backend_class_init (CalBackendClass *class)
object_class = (GtkObjectClass *) class;
- parent_class = gtk_type_class (GTK_TYPE_OBJECT);
-
- object_class->destroy = cal_backend_destroy;
-
cal_backend_signals[LAST_CLIENT_GONE] =
gtk_signal_new ("last_client_gone",
GTK_RUN_FIRST,
@@ -107,37 +100,13 @@ cal_backend_class_init (CalBackendClass *class)
gtk_object_class_add_signals (object_class, cal_backend_signals, LAST_SIGNAL);
}
-/* Per instance initialization function */
-static void
-cal_backend_init (CalBackend *backend)
-{
- backend->uri = NULL;
-}
-
-static void
-cal_backend_destroy (GtkObject *object)
-{
- CalBackend *backend;
-
- g_return_if_fail (object != NULL);
- g_return_if_fail (IS_CAL_BACKEND (object));
-
- backend = CAL_BACKEND (object);
-
- if (backend->uri)
- gnome_vfs_uri_unref (backend->uri);
-
- if (GTK_OBJECT_CLASS (parent_class)->destroy)
- (* GTK_OBJECT_CLASS (parent_class)->destroy) (object);
-}
-
/**
* cal_backend_get_uri:
* @backend: A calendar backend.
*
- * Queries the URI of a calendar backend, which must already have a loaded
+ * Queries the URI of a calendar backend, which must already have an open
* calendar.
*
* Return value: The URI where the calendar is stored.
@@ -152,23 +121,13 @@ cal_backend_get_uri (CalBackend *backend)
return (* CLASS (backend)->get_uri) (backend);
}
-static void
-cal_backend_set_uri (CalBackend *backend, GnomeVFSURI *uri)
-{
- if (backend->uri)
- gnome_vfs_uri_unref (backend->uri);
-
- gnome_vfs_uri_ref (uri);
- backend->uri = 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.
+ * The calendar backend must already have an open calendar.
**/
void
cal_backend_add_cal (CalBackend *backend, Cal *cal)
@@ -181,54 +140,34 @@ cal_backend_add_cal (CalBackend *backend, Cal *cal)
}
/**
- * cal_backend_load:
+ * cal_backend_open:
* @backend: A calendar backend.
* @uri: 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.
*
- * Loads a calendar backend with data from a calendar stored at the specified
+ * Opens a calendar backend with data from a calendar stored at the specified
* URI.
*
* Return value: An operation status code.
**/
-CalBackendLoadStatus
-cal_backend_load (CalBackend *backend, GnomeVFSURI *uri)
+CalBackendOpenStatus
+cal_backend_open (CalBackend *backend, GnomeVFSURI *uri, gboolean only_if_exists)
{
- CalBackendLoadStatus result;
+ CalBackendOpenStatus result;
- 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);
+ 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_assert (CLASS (backend)->load != NULL);
- result = (* CLASS (backend)->load) (backend, uri);
+ g_assert (CLASS (backend)->open != NULL);
+ result = (* CLASS (backend)->open) (backend, uri, only_if_exists);
- if (result == CAL_BACKEND_LOAD_SUCCESS)
- cal_backend_set_uri (backend, uri);
-
return result;
}
/**
- * 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)
-{
- g_return_if_fail (backend != NULL);
- g_return_if_fail (IS_CAL_BACKEND (backend));
- g_return_if_fail (uri != NULL);
-
- g_assert (CLASS (backend)->create != NULL);
- (* CLASS (backend)->create) (backend, uri);
-
- cal_backend_set_uri (backend, uri);
-}
-
-/**
* cal_backend_get_n_objects:
* @backend: A calendar backend.
* @type: Types of objects that will be included in the count.
diff --git a/calendar/pcs/cal-backend.h b/calendar/pcs/cal-backend.h
index 6194630b43..efb7068165 100644
--- a/calendar/pcs/cal-backend.h
+++ b/calendar/pcs/cal-backend.h
@@ -2,8 +2,9 @@
/* Evolution calendar - generic backend class
*
* 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
@@ -44,9 +45,10 @@ BEGIN_GNOME_DECLS
/* Load status values */
typedef enum {
- CAL_BACKEND_LOAD_SUCCESS, /* Loading OK */
- CAL_BACKEND_LOAD_ERROR /* We need better error reporting in libversit */
-} CalBackendLoadStatus;
+ CAL_BACKEND_OPEN_SUCCESS, /* Loading OK */
+ CAL_BACKEND_OPEN_ERROR, /* We need better error reporting in libversit */
+ CAL_BACKEND_OPEN_NOT_FOUND
+} CalBackendOpenStatus;
/* Result codes for ::get_alarms_in_range() */
typedef enum {
@@ -57,8 +59,6 @@ typedef enum {
struct _CalBackend {
GtkObject object;
-
- GnomeVFSURI *uri;
};
struct _CalBackendClass {
@@ -70,8 +70,9 @@ struct _CalBackendClass {
/* Virtual methods */
GnomeVFSURI *(* get_uri) (CalBackend *backend);
void (* add_cal) (CalBackend *backend, Cal *cal);
- CalBackendLoadStatus (* load) (CalBackend *backend, GnomeVFSURI *uri);
- void (* create) (CalBackend *backend, GnomeVFSURI *uri);
+
+ CalBackendOpenStatus (* open) (CalBackend *backend, GnomeVFSURI *uri,
+ gboolean only_if_exists);
int (* get_n_objects) (CalBackend *backend, CalObjType type);
char *(* get_object) (CalBackend *backend, const char *uid);
@@ -97,9 +98,8 @@ GnomeVFSURI *cal_backend_get_uri (CalBackend *backend);
void cal_backend_add_cal (CalBackend *backend, Cal *cal);
-CalBackendLoadStatus cal_backend_load (CalBackend *backend, GnomeVFSURI *uri);
-
-void cal_backend_create (CalBackend *backend, GnomeVFSURI *uri);
+CalBackendOpenStatus cal_backend_open (CalBackend *backend, GnomeVFSURI *uri,
+ gboolean only_if_exists);
int cal_backend_get_n_objects (CalBackend *backend, CalObjType type);
diff --git a/calendar/pcs/cal-common.h b/calendar/pcs/cal-common.h
index e51ddf1bdd..3454742ce8 100644
--- a/calendar/pcs/cal-common.h
+++ b/calendar/pcs/cal-common.h
@@ -1,8 +1,9 @@
/* Evolution calendar server - common declarations
*
* 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
diff --git a/calendar/pcs/cal-factory.c b/calendar/pcs/cal-factory.c
index 3834c34e62..40ffd2b735 100644
--- a/calendar/pcs/cal-factory.c
+++ b/calendar/pcs/cal-factory.c
@@ -1,8 +1,9 @@
/* Evolution calendar factory
*
* 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
@@ -197,58 +198,7 @@ cal_factory_destroy (GtkObject *object)
-/* Loading and creating calendars */
-
-/* Job data */
-typedef struct {
- CalFactory *factory;
- char *uri;
- GNOME_Evolution_Calendar_Listener listener;
-} LoadCreateJobData;
-
-/* Queues a load or create request */
-static void
-queue_load_create_job (CalFactory *factory, const char *uri, GNOME_Evolution_Calendar_Listener listener,
- JobFunc func)
-{
- LoadCreateJobData *jd;
- CORBA_Environment ev;
- GNOME_Evolution_Calendar_Listener listener_copy;
- gboolean result;
-
- g_assert (uri != NULL);
-
- CORBA_exception_init (&ev);
- result = CORBA_Object_is_nil (listener, &ev);
- if (ev._major != CORBA_NO_EXCEPTION) {
- g_message ("queue_load_create_job(): could not see if the listener was NIL");
- CORBA_exception_free (&ev);
- return;
- }
- CORBA_exception_free (&ev);
-
- if (result) {
- g_message ("queue_load_create_job(): cannot operate on a NIL listener!");
- return;
- }
-
- listener_copy = CORBA_Object_duplicate (listener, &ev);
-
- if (ev._major != CORBA_NO_EXCEPTION) {
- g_message ("queue_load_create_job(): could not duplicate the listener");
- CORBA_exception_free (&ev);
- return;
- }
-
- CORBA_exception_free (&ev);
-
- jd = g_new (LoadCreateJobData, 1);
- jd->factory = factory;
- jd->uri = g_strdup (uri);
- jd->listener = listener_copy;
-
- job_add (func, jd);
-}
+/* Opening calendars */
/* Looks up a calendar backend in a factory's hash table of uri->cal */
static CalBackend *
@@ -339,7 +289,7 @@ launch_backend_for_uri (CalFactory *factory, GnomeVFSURI *uri, GNOME_Evolution_C
CORBA_Environment ev;
CORBA_exception_init (&ev);
- GNOME_Evolution_Calendar_Listener_notifyCalLoaded (
+ GNOME_Evolution_Calendar_Listener_notifyCalOpened (
listener,
GNOME_Evolution_Calendar_Listener_METHOD_NOT_SUPPORTED,
CORBA_OBJECT_NIL,
@@ -359,13 +309,14 @@ launch_backend_for_uri (CalFactory *factory, GnomeVFSURI *uri, GNOME_Evolution_C
return backend;
}
-/* Loads a calendar backend and puts it in the factory's backend hash table */
+/* Opens a calendar backend and puts it in the factory's backend hash table */
static CalBackend *
-load_backend (CalFactory *factory, GnomeVFSURI *uri, GNOME_Evolution_Calendar_Listener listener)
+open_backend (CalFactory *factory, GnomeVFSURI *uri, gboolean only_if_exists,
+ GNOME_Evolution_Calendar_Listener listener)
{
CalFactoryPrivate *priv;
CalBackend *backend;
- CalBackendLoadStatus status;
+ CalBackendOpenStatus status;
CORBA_Environment ev;
priv = factory->priv;
@@ -374,70 +325,49 @@ load_backend (CalFactory *factory, GnomeVFSURI *uri, GNOME_Evolution_Calendar_Li
if (!backend)
return NULL;
- status = cal_backend_load (backend, uri);
+ status = cal_backend_open (backend, uri, only_if_exists);
switch (status) {
- case CAL_BACKEND_LOAD_SUCCESS:
+ case CAL_BACKEND_OPEN_SUCCESS:
add_backend (factory, uri, backend);
return backend;
- case CAL_BACKEND_LOAD_ERROR:
+ case CAL_BACKEND_OPEN_ERROR:
gtk_object_unref (GTK_OBJECT (backend));
CORBA_exception_init (&ev);
- GNOME_Evolution_Calendar_Listener_notifyCalLoaded (listener,
- GNOME_Evolution_Calendar_Listener_ERROR,
- CORBA_OBJECT_NIL,
- &ev);
+ GNOME_Evolution_Calendar_Listener_notifyCalOpened (
+ listener,
+ GNOME_Evolution_Calendar_Listener_ERROR,
+ CORBA_OBJECT_NIL,
+ &ev);
if (ev._major != CORBA_NO_EXCEPTION)
- g_message ("load_backend(): could not notify the listener");
+ g_message ("open_backend(): could not notify the listener");
CORBA_exception_free (&ev);
return NULL;
- default:
- g_assert_not_reached ();
- return NULL;
- }
-}
-
-/* Creates a calendar backend and puts it in the factory's backend hash table */
-static CalBackend *
-create_backend (CalFactory *factory, GnomeVFSURI *uri, GNOME_Evolution_Calendar_Listener listener)
-{
- CalFactoryPrivate *priv;
- CalBackend *backend;
-
- priv = factory->priv;
-
- backend = launch_backend_for_uri (factory, uri, listener);
- if (!backend)
- return NULL;
-
- cal_backend_create (backend, uri);
-
- /* FIXME: add error reporting to cal_backend_create() */
-#if 0
- {
- CORBA_Environment ev;
+ case CAL_BACKEND_OPEN_NOT_FOUND:
+ gtk_object_unref (GTK_OBJECT (backend));
CORBA_exception_init (&ev);
- GNOME_Evolution_Calendar_Listener_notifyCalLoaded (listener,
- GNOME_Evolution_Calendar_Listener_ERROR,
- CORBA_OBJECT_NIL,
- &ev);
+ GNOME_Evolution_Calendar_Listener_notifyCalOpened (
+ listener,
+ GNOME_Evolution_Calendar_Listener_NOT_FOUND,
+ CORBA_OBJECT_NIL,
+ &ev);
if (ev._major != CORBA_NO_EXCEPTION)
- g_message ("create_fn(): could not notify the listener");
+ g_message ("open_backend(): could not notify the listener");
CORBA_exception_free (&ev);
- }
-#endif
-
- add_backend (factory, uri, backend);
+ return NULL;
- return backend;
+ default:
+ g_assert_not_reached ();
+ return NULL;
+ }
}
/* Adds a listener to a calendar backend by creating a calendar client interface
@@ -454,10 +384,11 @@ add_calendar_client (CalFactory *factory, CalBackend *backend, GNOME_Evolution_C
g_message ("add_calendar_client(): could not create the calendar client interface");
CORBA_exception_init (&ev);
- GNOME_Evolution_Calendar_Listener_notifyCalLoaded (listener,
- GNOME_Evolution_Calendar_Listener_ERROR,
- CORBA_OBJECT_NIL,
- &ev);
+ GNOME_Evolution_Calendar_Listener_notifyCalOpened (
+ listener,
+ GNOME_Evolution_Calendar_Listener_ERROR,
+ CORBA_OBJECT_NIL,
+ &ev);
if (ev._major != CORBA_NO_EXCEPTION)
g_message ("add_calendar_client(): could not notify the listener");
@@ -468,10 +399,11 @@ add_calendar_client (CalFactory *factory, CalBackend *backend, GNOME_Evolution_C
cal_backend_add_cal (backend, cal);
CORBA_exception_init (&ev);
- GNOME_Evolution_Calendar_Listener_notifyCalLoaded (listener,
- GNOME_Evolution_Calendar_Listener_SUCCESS,
- bonobo_object_corba_objref (BONOBO_OBJECT (cal)),
- &ev);
+ GNOME_Evolution_Calendar_Listener_notifyCalOpened (
+ listener,
+ GNOME_Evolution_Calendar_Listener_SUCCESS,
+ bonobo_object_corba_objref (BONOBO_OBJECT (cal)),
+ &ev);
if (ev._major != CORBA_NO_EXCEPTION) {
g_message ("add_calendar_client(): could not notify the listener");
@@ -481,73 +413,22 @@ add_calendar_client (CalFactory *factory, CalBackend *backend, GNOME_Evolution_C
CORBA_exception_free (&ev);
}
-/* Job handler for the load calendar command */
-static void
-load_fn (gpointer data)
-{
- LoadCreateJobData *jd;
+/* Job data */
+typedef struct {
CalFactory *factory;
- GnomeVFSURI *uri;
+ char *uri;
+ gboolean only_if_exists;
GNOME_Evolution_Calendar_Listener listener;
- CalBackend *backend;
- CORBA_Environment ev;
-
- jd = data;
- g_assert (jd->uri != NULL);
-
- /* Check the URI */
-
- uri = gnome_vfs_uri_new (jd->uri);
- g_free (jd->uri);
-
- factory = jd->factory;
- listener = jd->listener;
- g_free (jd);
-
- if (!uri) {
- CORBA_exception_init (&ev);
- GNOME_Evolution_Calendar_Listener_notifyCalLoaded (listener,
- GNOME_Evolution_Calendar_Listener_ERROR,
- CORBA_OBJECT_NIL,
- &ev);
-
- if (ev._major != CORBA_NO_EXCEPTION)
- g_message ("load_fn(): Could not notify the listener!");
-
- CORBA_exception_free (&ev);
- goto out;
- }
-
- /* Look up the backend and create it if needed */
-
- backend = lookup_backend (factory, uri);
-
- if (!backend)
- backend = load_backend (factory, uri, listener);
-
- gnome_vfs_uri_unref (uri);
-
- if (backend)
- add_calendar_client (factory, backend, listener);
-
- out:
-
- CORBA_exception_init (&ev);
- CORBA_Object_release (listener, &ev);
-
- if (ev._major != CORBA_NO_EXCEPTION)
- g_message ("load_fn(): could not release the listener");
+} OpenJobData;
- CORBA_exception_free (&ev);
-}
-
-/* Job handler for the create calendar command */
+/* Job handler for the open calendar command */
static void
-create_fn (gpointer data)
+open_fn (gpointer data)
{
- LoadCreateJobData *jd;
+ OpenJobData *jd;
CalFactory *factory;
GnomeVFSURI *uri;
+ gboolean only_if_exists;
GNOME_Evolution_Calendar_Listener listener;
CalBackend *backend;
CORBA_Environment ev;
@@ -560,58 +441,45 @@ create_fn (gpointer data)
uri = gnome_vfs_uri_new (jd->uri);
g_free (jd->uri);
+ only_if_exists = jd->only_if_exists;
factory = jd->factory;
listener = jd->listener;
g_free (jd);
if (!uri) {
CORBA_exception_init (&ev);
- GNOME_Evolution_Calendar_Listener_notifyCalLoaded (listener,
- GNOME_Evolution_Calendar_Listener_ERROR,
- CORBA_OBJECT_NIL,
- &ev);
+ GNOME_Evolution_Calendar_Listener_notifyCalOpened (
+ listener,
+ GNOME_Evolution_Calendar_Listener_ERROR,
+ CORBA_OBJECT_NIL,
+ &ev);
if (ev._major != CORBA_NO_EXCEPTION)
- g_message ("create_fn(): Could not notify the listener!");
+ g_message ("open_fn(): Could not notify the listener!");
CORBA_exception_free (&ev);
goto out;
}
- /* Check that the backend is not in use */
+ /* Look up the backend and create it if needed */
backend = lookup_backend (factory, uri);
- if (backend) {
- CORBA_exception_init (&ev);
- GNOME_Evolution_Calendar_Listener_notifyCalLoaded (listener,
- GNOME_Evolution_Calendar_Listener_IN_USE,
- CORBA_OBJECT_NIL,
- &ev);
-
- if (ev._major != CORBA_NO_EXCEPTION)
- g_message ("create_fn(): could not notify the listener");
-
- CORBA_exception_free (&ev);
- goto out;
- }
-
- /* Create the backend */
+ if (!backend)
+ backend = open_backend (factory, uri, only_if_exists, listener);
- backend = create_backend (factory, uri, listener);
+ gnome_vfs_uri_unref (uri);
if (backend)
add_calendar_client (factory, backend, listener);
- gnome_vfs_uri_unref (uri);
-
out:
CORBA_exception_init (&ev);
CORBA_Object_release (listener, &ev);
if (ev._major != CORBA_NO_EXCEPTION)
- g_message ("create_fn(): could not release the listener");
+ g_message ("open_fn(): could not release the listener");
CORBA_exception_free (&ev);
}
@@ -620,10 +488,11 @@ create_fn (gpointer data)
/* CORBA servant implementation */
-/* CalFactory::load method */
+/* CalFactory::open method */
static void
-CalFactory_load (PortableServer_Servant servant,
+CalFactory_open (PortableServer_Servant servant,
const CORBA_char *uri,
+ CORBA_boolean only_if_exists,
GNOME_Evolution_Calendar_Listener listener,
CORBA_Environment *ev)
{
@@ -631,6 +500,8 @@ CalFactory_load (PortableServer_Servant servant,
CalFactoryPrivate *priv;
CORBA_Environment ev2;
gboolean result;
+ OpenJobData *jd;
+ GNOME_Evolution_Calendar_Listener listener_copy;
factory = CAL_FACTORY (bonobo_object_from_servant (servant));
priv = factory->priv;
@@ -648,23 +519,27 @@ CalFactory_load (PortableServer_Servant servant,
}
CORBA_exception_free (&ev2);
- queue_load_create_job (factory, uri, listener, load_fn);
-}
+ CORBA_exception_init (&ev2);
+ listener_copy = CORBA_Object_duplicate (listener, &ev2);
-/* CalFactory::create method */
-static void
-CalFactory_create (PortableServer_Servant servant,
- const CORBA_char *uri,
- GNOME_Evolution_Calendar_Listener listener,
- CORBA_Environment *ev)
-{
- CalFactory *factory;
- CalFactoryPrivate *priv;
+ if (ev2._major != CORBA_NO_EXCEPTION) {
+ g_message ("CalFactory_open(): could not duplicate the listener");
+ CORBA_exception_free (&ev2);
+ CORBA_exception_set (ev, CORBA_USER_EXCEPTION,
+ ex_GNOME_Evolution_Calendar_CalFactory_NilListener,
+ NULL);
+ return;
+ }
- factory = CAL_FACTORY (bonobo_object_from_servant (servant));
- priv = factory->priv;
+ CORBA_exception_free (&ev2);
+
+ jd = g_new (OpenJobData, 1);
+ jd->factory = factory;
+ jd->uri = g_strdup (uri);
+ jd->only_if_exists = only_if_exists;
+ jd->listener = listener_copy;
- queue_load_create_job (factory, uri, listener, create_fn);
+ job_add (open_fn, jd);
}
/**
@@ -681,8 +556,7 @@ cal_factory_get_epv (void)
POA_GNOME_Evolution_Calendar_CalFactory__epv *epv;
epv = g_new0 (POA_GNOME_Evolution_Calendar_CalFactory__epv, 1);
- epv->load = CalFactory_load;
- epv->create = CalFactory_create;
+ epv->open = CalFactory_open;
return epv;
}
@@ -802,7 +676,7 @@ str_tolower (const char *s)
* @backend_type: Class type of the backend to create for this @method.
*
* Registers the type of a #CalBackend subclass that will be used to handle URIs
- * with a particular method. When the factory is asked to load a particular
+ * with a particular method. When the factory is asked to open a particular
* URI, it will look in its list of registered methods and create a backend of
* the appropriate type.
**/
diff --git a/calendar/pcs/cal-factory.h b/calendar/pcs/cal-factory.h
index 5e61d26ab5..4bdf9bf52f 100644
--- a/calendar/pcs/cal-factory.h
+++ b/calendar/pcs/cal-factory.h
@@ -1,8 +1,9 @@
/* Evolution calendar factory
*
* 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
diff --git a/calendar/pcs/cal.c b/calendar/pcs/cal.c
index 77f18806d9..69eccd7f55 100644
--- a/calendar/pcs/cal.c
+++ b/calendar/pcs/cal.c
@@ -1,8 +1,9 @@
/* Evolution calendar client interface object
*
* 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
diff --git a/calendar/pcs/cal.h b/calendar/pcs/cal.h
index d4c9f02650..844640cd8d 100644
--- a/calendar/pcs/cal.h
+++ b/calendar/pcs/cal.h
@@ -1,8 +1,9 @@
/* Evolution calendar client interface object
*
* 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
diff --git a/calendar/pcs/job.c b/calendar/pcs/job.c
index d97df6d883..f8223f0bab 100644
--- a/calendar/pcs/job.c
+++ b/calendar/pcs/job.c
@@ -1,8 +1,9 @@
/* GNOME personal calendar server - job manager
*
* 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
diff --git a/calendar/pcs/job.h b/calendar/pcs/job.h
index c9bce24dd4..f9a0d86923 100644
--- a/calendar/pcs/job.h
+++ b/calendar/pcs/job.h
@@ -1,8 +1,9 @@
/* GNOME personal calendar server - job manager
*
* 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