aboutsummaryrefslogtreecommitdiffstats
path: root/calendar/cal-client
diff options
context:
space:
mode:
Diffstat (limited to 'calendar/cal-client')
-rw-r--r--calendar/cal-client/cal-client-types.c5
-rw-r--r--calendar/cal-client/cal-client-types.h5
-rw-r--r--calendar/cal-client/cal-client.c223
-rw-r--r--calendar/cal-client/cal-client.h32
-rw-r--r--calendar/cal-client/cal-listener.c193
-rw-r--r--calendar/cal-client/cal-listener.h34
-rw-r--r--calendar/cal-client/client-test.c38
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;