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.c61
-rw-r--r--calendar/cal-client/cal-client.h11
-rw-r--r--calendar/cal-client/client-test.c24
3 files changed, 73 insertions, 23 deletions
diff --git a/calendar/cal-client/cal-client.c b/calendar/cal-client/cal-client.c
index 97dda85acb..23ab9bc003 100644
--- a/calendar/cal-client/cal-client.c
+++ b/calendar/cal-client/cal-client.c
@@ -32,6 +32,9 @@
#include "cal-client.h"
#include "cal-listener.h"
+#include "cal-util/icalendar-save.h"
+#include "cal-util/icalendar.h"
+
/* Loading state for the calendar client */
@@ -559,41 +562,73 @@ cal_client_create_calendar (CalClient *client, const char *str_uri)
* sought object, or NULL if no object had the specified UID. A complete
* calendar is returned because you also need the timezone data.
**/
-char *
-cal_client_get_object (CalClient *client, const char *uid)
+CalClientGetStatus cal_client_get_object (CalClient *client,
+ const char *uid,
+ iCalObject **ico)
{
CalClientPrivate *priv;
CORBA_Environment ev;
Evolution_Calendar_CalObj calobj;
- char *retval;
+ char *obj_str = NULL;
- g_return_val_if_fail (client != NULL, NULL);
- g_return_val_if_fail (IS_CAL_CLIENT (client), NULL);
+ icalcomponent* comp = NULL;
+ icalcomponent *subcomp;
+ iCalObject *ical;
+
+ g_return_val_if_fail (client != NULL, CAL_CLIENT_GET_SYNTAX_ERROR);
+ g_return_val_if_fail (IS_CAL_CLIENT (client), CAL_CLIENT_GET_SYNTAX_ERROR);
priv = client->priv;
- g_return_val_if_fail (priv->load_state == LOAD_STATE_LOADED, NULL);
+ g_return_val_if_fail (priv->load_state == LOAD_STATE_LOADED, CAL_CLIENT_GET_SYNTAX_ERROR);
- g_return_val_if_fail (uid != NULL, NULL);
+ g_return_val_if_fail (uid != NULL, CAL_CLIENT_GET_SYNTAX_ERROR);
- retval = NULL;
+ obj_str = NULL;
CORBA_exception_init (&ev);
calobj = Evolution_Calendar_Cal_get_object (priv->cal, uid, &ev);
if (ev._major == CORBA_USER_EXCEPTION
&& strcmp (CORBA_exception_id (&ev), ex_Evolution_Calendar_Cal_NotFound) == 0)
- goto out;
+ goto decode;
else if (ev._major != CORBA_NO_EXCEPTION) {
g_message ("cal_client_get_object(): could not get the object");
- goto out;
+ goto decode;
}
- retval = g_strdup (calobj);
+ obj_str = g_strdup (calobj);
CORBA_free (calobj);
- out:
+ decode:
CORBA_exception_free (&ev);
- return retval;
+
+ /* convert the string into an iCalObject */
+ (*ico) = NULL;
+ if (obj_str == NULL) return CAL_CLIENT_GET_SYNTAX_ERROR;
+ comp = icalparser_parse_string (obj_str);
+ free (obj_str);
+ if (!comp) return CAL_CLIENT_GET_SYNTAX_ERROR;
+ subcomp = icalcomponent_get_first_component (comp, ICAL_ANY_COMPONENT);
+ if (!subcomp) return CAL_CLIENT_GET_SYNTAX_ERROR;
+
+ while (subcomp) {
+ ical = ical_object_create_from_icalcomponent (subcomp);
+ if (ical->type != ICAL_EVENT &&
+ ical->type != ICAL_TODO &&
+ ical->type != ICAL_JOURNAL) {
+ g_warning ("Skipping unsupported iCalendar component");
+ } else {
+ if (strcasecmp (ical->uid, uid) == 0) {
+ (*ico) = ical;
+ (*ico)->ref_count = 1;
+ return CAL_CLIENT_GET_SUCCESS;
+ }
+ }
+ subcomp = icalcomponent_get_next_component (comp,
+ ICAL_ANY_COMPONENT);
+ }
+
+ return CAL_CLIENT_GET_NOT_FOUND;
}
/**
diff --git a/calendar/cal-client/cal-client.h b/calendar/cal-client/cal-client.h
index 12cbcc7c87..755b005f74 100644
--- a/calendar/cal-client/cal-client.h
+++ b/calendar/cal-client/cal-client.h
@@ -47,6 +47,13 @@ typedef enum {
CAL_CLIENT_LOAD_METHOD_NOT_SUPPORTED
} CalClientLoadStatus;
+typedef enum {
+ CAL_CLIENT_GET_SUCCESS,
+ CAL_CLIENT_GET_NOT_FOUND,
+ CAL_CLIENT_GET_SYNTAX_ERROR
+} CalClientGetStatus;
+
+
struct _CalClient {
GtkObject object;
@@ -74,7 +81,9 @@ 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);
-char *cal_client_get_object (CalClient *client, const char *uid);
+CalClientGetStatus cal_client_get_object (CalClient *client,
+ const char *uid,
+ iCalObject **ico);
GList *cal_client_get_uids (CalClient *client, CalObjType type);
diff --git a/calendar/cal-client/client-test.c b/calendar/cal-client/client-test.c
index f4b847eb65..f8741f4539 100644
--- a/calendar/cal-client/client-test.c
+++ b/calendar/cal-client/client-test.c
@@ -1,3 +1,4 @@
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
#include <config.h>
#include <bonobo.h>
#include <gnome.h>
@@ -48,17 +49,22 @@ list_uids (gpointer data)
for (l = uids; l; l = l->next) {
char *uid;
- char *calobj;
+ iCalObject *ico;
+ CalClientGetStatus status;
uid = l->data;
- calobj = cal_client_get_object (client, uid);
-
- printf ("------------------------------\n%s", calobj);
- printf ("------------------------------\n");
-
- cal_client_update_object (client, uid, calobj);
-
- g_free (calobj);
+ status = cal_client_get_object (client, uid, &ico);
+
+ if (status == CAL_CLIENT_GET_SUCCESS) {
+ printf ("------------------------------\n");
+ dump_icalobject (ico);
+ printf ("------------------------------\n");
+ } else {
+ printf ("FAILED: %d\n", status);
+ }
+
+ // cal_client_update_object (client, uid, calobj);
+ // g_free (calobj);
}
}