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.c93
-rw-r--r--calendar/cal-client/cal-client.h5
-rw-r--r--calendar/cal-client/cal-listener.c46
-rw-r--r--calendar/cal-client/cal-listener.h3
-rw-r--r--calendar/cal-client/client-test.c16
5 files changed, 89 insertions, 74 deletions
diff --git a/calendar/cal-client/cal-client.c b/calendar/cal-client/cal-client.c
index aa8cdcf50c..9b25740318 100644
--- a/calendar/cal-client/cal-client.c
+++ b/calendar/cal-client/cal-client.c
@@ -54,9 +54,8 @@ typedef struct {
/* Signal IDs */
enum {
CAL_LOADED,
- OBJ_ADDED,
+ OBJ_UPDATED,
OBJ_REMOVED,
- OBJ_CHANGED,
LAST_SIGNAL
};
@@ -120,11 +119,11 @@ cal_client_class_init (CalClientClass *class)
gtk_marshal_NONE__ENUM,
GTK_TYPE_NONE, 1,
GTK_TYPE_ENUM);
- cal_client_signals[OBJ_ADDED] =
- gtk_signal_new ("obj_added",
+ cal_client_signals[OBJ_UPDATED] =
+ gtk_signal_new ("obj_updated",
GTK_RUN_FIRST,
object_class->type,
- GTK_SIGNAL_OFFSET (CalClientClass, obj_added),
+ GTK_SIGNAL_OFFSET (CalClientClass, obj_updated),
gtk_marshal_NONE__STRING,
GTK_TYPE_NONE, 1,
GTK_TYPE_STRING);
@@ -136,14 +135,6 @@ cal_client_class_init (CalClientClass *class)
gtk_marshal_NONE__STRING,
GTK_TYPE_NONE, 1,
GTK_TYPE_STRING);
- cal_client_signals[OBJ_CHANGED] =
- gtk_signal_new ("obj_changed",
- GTK_RUN_FIRST,
- object_class->type,
- GTK_SIGNAL_OFFSET (CalClientClass, obj_changed),
- gtk_marshal_NONE__STRING,
- GTK_TYPE_NONE, 1,
- GTK_TYPE_STRING);
gtk_object_class_add_signals (object_class, cal_client_signals, LAST_SIGNAL);
@@ -215,7 +206,7 @@ static void
destroy_cal (CalClient *client)
{
CalClientPrivate *priv;
- CORBA_Environment ev;
+ CORBA_Environment ev;
int result;
priv = client->priv;
@@ -233,7 +224,7 @@ destroy_cal (CalClient *client)
if (result)
return;
-
+
CORBA_exception_init (&ev);
Evolution_Calendar_Cal_unref (priv->cal, &ev);
if (ev._major != CORBA_NO_EXCEPTION)
@@ -343,14 +334,14 @@ cal_loaded_cb (CalListener *listener,
client_status);
}
-/* Handle the obj_added signal from the listener */
+/* Handle the obj_updated signal from the listener */
static void
-obj_added_cb (CalListener *listener, const Evolution_Calendar_CalObjUID uid, gpointer data)
+obj_updated_cb (CalListener *listener, const Evolution_Calendar_CalObjUID uid, gpointer data)
{
CalClient *client;
client = CAL_CLIENT (data);
- gtk_signal_emit (GTK_OBJECT (client), cal_client_signals[OBJ_ADDED], uid);
+ gtk_signal_emit (GTK_OBJECT (client), cal_client_signals[OBJ_UPDATED], uid);
}
/* Handle the obj_removed signal from the listener */
@@ -363,16 +354,6 @@ obj_removed_cb (CalListener *listener, const Evolution_Calendar_CalObjUID uid, g
gtk_signal_emit (GTK_OBJECT (client), cal_client_signals[OBJ_REMOVED], uid);
}
-/* Handle the obj_changed signal from the listener */
-static void
-obj_changed_cb (CalListener *listener, const Evolution_Calendar_CalObjUID uid, gpointer data)
-{
- CalClient *client;
-
- client = CAL_CLIENT (data);
- gtk_signal_emit (GTK_OBJECT (client), cal_client_signals[OBJ_CHANGED], uid);
-}
-
/**
@@ -484,15 +465,12 @@ load_or_create (CalClient *client, const char *str_uri, gboolean load)
gtk_signal_connect (GTK_OBJECT (priv->listener), "cal_loaded",
GTK_SIGNAL_FUNC (cal_loaded_cb),
client);
- gtk_signal_connect (GTK_OBJECT (priv->listener), "obj_added",
- GTK_SIGNAL_FUNC (obj_added_cb),
+ 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);
- gtk_signal_connect (GTK_OBJECT (priv->listener), "obj_changed",
- GTK_SIGNAL_FUNC (obj_changed_cb),
- client);
corba_listener = (Evolution_Calendar_Listener) bonobo_object_corba_objref (
BONOBO_OBJECT (priv->listener));
@@ -719,3 +697,52 @@ cal_client_get_events_in_range (CalClient *client, time_t start, time_t end)
return elist;
}
+
+/**
+ * cal_client_update_object:
+ * @client: A calendar client.
+ * @uid: Unique identifier of object to update.
+ * @calobj: String representation of the new calendar object.
+ *
+ * Asks a calendar to update an object based on its UID. Any existing object
+ * with the specified UID will be replaced. The client program should not
+ * assume that the object is actually in the server's storage until it has
+ * received the "obj_updated" notification signal.
+ *
+ * Return value: TRUE on success, FALSE on specifying an invalid object.
+ **/
+gboolean
+cal_client_update_object (CalClient *client, const char *uid, const char *calobj)
+{
+ CalClientPrivate *priv;
+ CORBA_Environment ev;
+ gboolean retval;
+
+ g_return_val_if_fail (client != NULL, FALSE);
+ 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 (uid != NULL, FALSE);
+ g_return_val_if_fail (calobj != NULL, FALSE);
+
+ retval = FALSE;
+
+ CORBA_exception_init (&ev);
+ Evolution_Calendar_Cal_update_object (priv->cal, uid, calobj, &ev);
+
+ if (ev._major == CORBA_USER_EXCEPTION &&
+ strcmp (CORBA_exception_id (&ev), ex_Evolution_Calendar_Cal_InvalidObject) == 0)
+ goto out;
+ else if (ev._major != CORBA_NO_EXCEPTION) {
+ g_message ("cal_client_update_object(): could not update the object");
+ goto out;
+ }
+
+ retval = TRUE;
+
+ out:
+ CORBA_exception_free (&ev);
+ return retval;
+}
diff --git a/calendar/cal-client/cal-client.h b/calendar/cal-client/cal-client.h
index 0c4c3e4406..7baad2c733 100644
--- a/calendar/cal-client/cal-client.h
+++ b/calendar/cal-client/cal-client.h
@@ -60,9 +60,8 @@ struct _CalClientClass {
void (* cal_loaded) (CalClient *client, CalClientLoadStatus status);
- void (* obj_added) (CalClient *client, const char *uid);
+ void (* obj_updated) (CalClient *client, const char *uid);
void (* obj_removed) (CalClient *client, const char *uid);
- void (* obj_changed) (CalClient *client, const char *uid);
};
GtkType cal_client_get_type (void);
@@ -80,6 +79,8 @@ GList *cal_client_get_uids (CalClient *client, CalObjType type);
GList *cal_client_get_events_in_range (CalClient *client, time_t start, time_t end);
+gboolean cal_client_update_object (CalClient *client, const char *uid, const char *calobj);
+
END_GNOME_DECLS
diff --git a/calendar/cal-client/cal-listener.c b/calendar/cal-client/cal-listener.c
index 32024d04f5..2c875c4c38 100644
--- a/calendar/cal-client/cal-listener.c
+++ b/calendar/cal-client/cal-listener.c
@@ -36,9 +36,8 @@ typedef struct {
/* Signal IDs */
enum {
CAL_LOADED,
- OBJ_ADDED,
+ OBJ_UPDATED,
OBJ_REMOVED,
- OBJ_CHANGED,
LAST_SIGNAL
};
@@ -115,11 +114,11 @@ cal_listener_class_init (CalListenerClass *class)
GTK_TYPE_NONE, 2,
GTK_TYPE_ENUM,
GTK_TYPE_POINTER);
- cal_listener_signals[OBJ_ADDED] =
- gtk_signal_new ("obj_added",
+ cal_listener_signals[OBJ_UPDATED] =
+ gtk_signal_new ("obj_updated",
GTK_RUN_FIRST,
object_class->type,
- GTK_SIGNAL_OFFSET (CalListenerClass, obj_added),
+ GTK_SIGNAL_OFFSET (CalListenerClass, obj_updated),
gtk_marshal_NONE__POINTER,
GTK_TYPE_NONE, 1,
GTK_TYPE_POINTER);
@@ -131,14 +130,6 @@ cal_listener_class_init (CalListenerClass *class)
gtk_marshal_NONE__POINTER,
GTK_TYPE_NONE, 1,
GTK_TYPE_POINTER);
- cal_listener_signals[OBJ_CHANGED] =
- gtk_signal_new ("obj_changed",
- GTK_RUN_FIRST,
- object_class->type,
- GTK_SIGNAL_OFFSET (CalListenerClass, obj_changed),
- gtk_marshal_NONE__POINTER,
- GTK_TYPE_NONE, 1,
- GTK_TYPE_POINTER);
gtk_object_class_add_signals (object_class, cal_listener_signals, LAST_SIGNAL);
@@ -272,16 +263,16 @@ Listener_cal_loaded (PortableServer_Servant servant,
load_status, cal);
}
-/* Listener::obj_added method */
+/* Listener::obj_updated method */
static void
-Listener_obj_added (PortableServer_Servant servant,
- Evolution_Calendar_CalObjUID uid,
- CORBA_Environment *ev)
+Listener_obj_updated (PortableServer_Servant servant,
+ Evolution_Calendar_CalObjUID uid,
+ CORBA_Environment *ev)
{
CalListener *listener;
listener = CAL_LISTENER (bonobo_object_from_servant (servant));
- gtk_signal_emit (GTK_OBJECT (listener), cal_listener_signals[OBJ_ADDED],
+ gtk_signal_emit (GTK_OBJECT (listener), cal_listener_signals[OBJ_UPDATED],
uid);
}
@@ -298,19 +289,6 @@ Listener_obj_removed (PortableServer_Servant servant,
uid);
}
-/* Listener::obj_changed method */
-static void
-Listener_obj_changed (PortableServer_Servant servant,
- Evolution_Calendar_CalObjUID uid,
- CORBA_Environment *ev)
-{
- CalListener *listener;
-
- listener = CAL_LISTENER (bonobo_object_from_servant (servant));
- gtk_signal_emit (GTK_OBJECT (listener), cal_listener_signals[OBJ_CHANGED],
- uid);
-}
-
/**
* cal_listener_get_epv:
* @void:
@@ -326,10 +304,8 @@ cal_listener_get_epv (void)
epv = g_new0 (POA_Evolution_Calendar_Listener__epv, 1);
epv->cal_loaded = Listener_cal_loaded;
- epv->obj_added = Listener_obj_added;
+ epv->obj_updated = Listener_obj_updated;
epv->obj_removed = Listener_obj_removed;
- epv->obj_changed = Listener_obj_changed;
-
return epv;
}
@@ -415,7 +391,7 @@ cal_listener_new (void)
if (ev._major != CORBA_NO_EXCEPTION || result) {
g_message ("cal_listener_new(): could not create the CORBA listener");
- gtk_object_unref (GTK_OBJECT (listener));
+ bonobo_object_unref (BONOBO_OBJECT (listener));
CORBA_exception_free (&ev);
return NULL;
}
diff --git a/calendar/cal-client/cal-listener.h b/calendar/cal-client/cal-listener.h
index 52b934e774..23590e6ff8 100644
--- a/calendar/cal-client/cal-listener.h
+++ b/calendar/cal-client/cal-listener.h
@@ -62,9 +62,8 @@ struct _CalListenerClass {
void (* cal_loaded) (CalListener *listener,
CalListenerLoadStatus status,
Evolution_Calendar_Cal cal);
- void (* obj_added) (CalListener *listener, const Evolution_Calendar_CalObjUID uid);
+ void (* obj_updated) (CalListener *listener, const Evolution_Calendar_CalObjUID uid);
void (* obj_removed) (CalListener *listener, const Evolution_Calendar_CalObjUID uid);
- void (* obj_changed) (CalListener *listener, const Evolution_Calendar_CalObjUID uid);
};
GtkType cal_listener_get_type (void);
diff --git a/calendar/cal-client/client-test.c b/calendar/cal-client/client-test.c
index bebaa42d87..d2374db275 100644
--- a/calendar/cal-client/client-test.c
+++ b/calendar/cal-client/client-test.c
@@ -57,13 +57,15 @@ list_uids (gpointer data)
printf ("------------------------------\n%s", calobj);
printf ("------------------------------\n");
+ cal_client_update_object (client, uid, calobj);
+
g_free (calobj);
}
}
cal_obj_uid_list_free (uids);
- gtk_object_unref (GTK_OBJECT (client));
+/* gtk_object_unref (GTK_OBJECT (client)); */
return FALSE;
}
@@ -84,6 +86,13 @@ cal_loaded (CalClient *client, CalClientLoadStatus status, gpointer data)
gtk_object_unref (GTK_OBJECT (client));
}
+/* Callback used when an object is updated */
+static void
+obj_updated (CalClient *client, const char *uid, gpointer data)
+{
+ cl_printf (client, "Object updated: %s\n", uid);
+}
+
/* Creates a calendar client and tries to load the specified URI into it */
static CalClient *
create_client (const char *uri, gboolean load)
@@ -100,13 +109,16 @@ create_client (const char *uri, gboolean load)
gtk_signal_connect (GTK_OBJECT (client), "cal_loaded",
GTK_SIGNAL_FUNC (cal_loaded),
NULL);
+ gtk_signal_connect (GTK_OBJECT (client), "obj_updated",
+ GTK_SIGNAL_FUNC (obj_updated),
+ 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_load_calendar (client, uri);
if (!result) {
g_message ("create_client(): failure when issuing calendar load/create request `%s'",