aboutsummaryrefslogtreecommitdiffstats
path: root/calendar
diff options
context:
space:
mode:
Diffstat (limited to 'calendar')
-rw-r--r--calendar/ChangeLog10
-rw-r--r--calendar/cal-util/icalendar-save.c15
-rw-r--r--calendar/cal-util/icalendar-test.c146
-rw-r--r--calendar/cal-util/icalendar.c24
-rw-r--r--calendar/pcs/.cvsignore2
-rw-r--r--calendar/pcs/Makefile.am19
-rw-r--r--calendar/pcs/icalendar-save.c15
-rw-r--r--calendar/pcs/icalendar-test.c146
-rw-r--r--calendar/pcs/icalendar.c24
9 files changed, 373 insertions, 28 deletions
diff --git a/calendar/ChangeLog b/calendar/ChangeLog
index da615fd8f2..0073bbd209 100644
--- a/calendar/ChangeLog
+++ b/calendar/ChangeLog
@@ -1,3 +1,13 @@
+2000-04-24 Seth Alves <alves@hungry.com>
+
+ * pcs/icalendar.c (parse_person): allow for null CN
+ (parse_person): allow for null sent_by
+
+ * pcs/Makefile.am: build icalendar-test
+
+ * pcs/icalendar-test.c: a test which loads an ical file and
+ converts it to our internal format, and then saves it back out.
+
2000-04-24 Damon Chaplin <damon@helixcode.com>
* gui/Makefile.am: added new source files and pixmaps, and removed
diff --git a/calendar/cal-util/icalendar-save.c b/calendar/cal-util/icalendar-save.c
index a3b2505778..1b35d2dadf 100644
--- a/calendar/cal-util/icalendar-save.c
+++ b/calendar/cal-util/icalendar-save.c
@@ -164,9 +164,9 @@ icalcomponent_create_from_ical_object (iCalObject *ical)
/*** transp ***/
{
if (ical->transp == ICAL_TRANSP_PROPERTY)
- icalproperty_set_transp (prop, "TRANSPARENT");
+ prop = icalproperty_new_transp ("TRANSPARENT");
else
- icalproperty_set_transp (prop, "OPAQUE");
+ prop = icalproperty_new_transp ("OPAQUE");
icalcomponent_add_property (comp, prop);
}
@@ -347,8 +347,10 @@ void unparse_person (iCalPerson *person, icalproperty *person_prop)
/* convert iCalPerson to an icalproperty */
- param = icalparameter_new_cn (person->name);
- icalproperty_add_parameter (person_prop, param);
+ if (person->name) {
+ param = icalparameter_new_cn (person->name);
+ icalproperty_add_parameter (person_prop, param);
+ }
if (g_strcasecmp (person->role, "CHAIR") == 0)
param = icalparameter_new_role (ICAL_ROLE_CHAIR);
@@ -418,7 +420,10 @@ void unparse_person (iCalPerson *person, icalproperty *person_prop)
icalproperty_add_parameter (person_prop, param);
}
- param = icalparameter_new_sentby (person->sent_by);
+ if (person->sent_by) {
+ param = icalparameter_new_sentby (person->sent_by);
+ icalproperty_add_parameter (person_prop, param);
+ }
/* ret->deleg_to is a list of ICAL_DIR_PARAMETER */
/* FIX ME ... */
diff --git a/calendar/cal-util/icalendar-test.c b/calendar/cal-util/icalendar-test.c
new file mode 100644
index 0000000000..921e109a2c
--- /dev/null
+++ b/calendar/cal-util/icalendar-test.c
@@ -0,0 +1,146 @@
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
+
+#include <sys/stat.h>
+#include <stdlib.h>
+#include <unistd.h>
+
+#include <config.h>
+#include <gtk/gtksignal.h>
+#include <cal-util/calobj.h>
+#include "libversit/vcc.h"
+
+#include "icalendar-save.h"
+#include "icalendar.h"
+
+
+static icalcomponent*
+icalendar_parse_file (char* fname)
+{
+ FILE* fp;
+ icalcomponent* comp = NULL;
+ gchar* str;
+ struct stat st;
+ int n;
+
+ fp = fopen (fname, "r");
+ if (!fp) {
+ g_warning ("Cannot open open calendar file.");
+ return NULL;
+ }
+
+ stat (fname, &st);
+
+ str = g_malloc (st.st_size + 2);
+
+ n = fread ((gchar*) str, 1, st.st_size, fp);
+ if (n != st.st_size) {
+ g_warning ("Read error.");
+ }
+ str[n] = '\0';
+
+ fclose (fp);
+
+ comp = icalparser_parse_string (str);
+ g_free (str);
+
+ return comp;
+}
+
+
+static GList *
+icalendar_calendar_load (GList *icals, char *fname)
+{
+ icalcomponent *comp;
+ icalcomponent *subcomp;
+ iCalObject *ical;
+
+ comp = icalendar_parse_file (fname);
+ subcomp = icalcomponent_get_first_component (comp,
+ ICAL_ANY_COMPONENT);
+ 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 {
+ printf ("prepending %p\n", ical);
+ icals = g_list_prepend (icals, ical);
+ }
+ subcomp = icalcomponent_get_next_component (comp,
+ ICAL_ANY_COMPONENT);
+ }
+
+ return icals;
+}
+
+
+
+
+static void
+icalendar_calendar_save (GList *icals, char *fname)
+{
+ GList *cur;
+ icalcomponent *top = icalcomponent_new (ICAL_VCALENDAR_COMPONENT);
+ char *out_cal_string;
+
+ for (cur=icals; cur; cur=cur->next) {
+ iCalObject *ical = (iCalObject *) cur->data;
+ icalcomponent *comp;
+ comp = icalcomponent_create_from_ical_object (ical);
+ icalcomponent_add_component (top, comp);
+ }
+
+ out_cal_string = icalcomponent_as_ical_string (top);
+
+ printf ("---------------------------------------------------------\n");
+ printf ("%s", out_cal_string);
+}
+
+
+
+int main (int argc, char *argv[])
+{
+ GList *icals = NULL;
+ int i;
+ long int n0, n1;
+ struct icaldurationtype dt;
+
+
+ /* test icaldurationtype_from_timet */
+ srandom (time (0));
+
+ for (i=0; i<10; i++) {
+ n0 = random () % ((60 * 60 * 24 * 7) * 4);
+ dt = icaldurationtype_from_timet (n0);
+ n1 = icaldurationtype_as_timet (dt);
+
+ printf ("%ld -> (%d %d %d %d %d) -> %ld\n",
+ n0,
+ dt.weeks, dt.days, dt.hours, dt.minutes, dt.seconds,
+ n1);
+ if (n0 != n1) abort ();
+ }
+
+ /*****************/
+ /* test conversion of icalcomponents to and from iCalObjects */
+ /*****************/
+
+ /* load an ical file */
+
+ if (argc < 2) {
+ printf ("give ical file as argument.\n");
+ return 1;
+ }
+
+ icals = icalendar_calendar_load (icals, argv[ 1 ]);
+
+ printf ("loaded %d ical components\n", g_list_length (icals));
+
+
+ /* save it back out */
+
+ icalendar_calendar_save (icals, "out.ical");
+
+ return 0;
+}
diff --git a/calendar/cal-util/icalendar.c b/calendar/cal-util/icalendar.c
index 8a15bb3cb4..eedb732617 100644
--- a/calendar/cal-util/icalendar.c
+++ b/calendar/cal-util/icalendar.c
@@ -1,3 +1,4 @@
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
/*
* icalendar server for gnomecal
*
@@ -195,8 +196,8 @@ ical_object_create_from_icalcomponent (icalcomponent* comp)
ical->dtend = icaltime_to_timet (&ictime);
param = icalproperty_get_first_parameter (prop,
ICAL_VALUE_PARAMETER);
- ical->date_only = (icalparameter_get_value (param) ==
- ICAL_VALUE_DATE);
+ if (param)
+ ical->date_only = (icalparameter_get_value (param) == ICAL_VALUE_DATE);
/* FIXME: We should handle timezone specifiers */
break;
case ICAL_DUE_PROPERTY:
@@ -213,8 +214,8 @@ ical_object_create_from_icalcomponent (icalcomponent* comp)
ical->dtstart = icaltime_to_timet (&ictime);
param = icalproperty_get_first_parameter (prop,
ICAL_VALUE_PARAMETER);
- ical->date_only = (icalparameter_get_value (param) ==
- ICAL_VALUE_DATE);
+ if (param)
+ ical->date_only = (icalparameter_get_value (param) == ICAL_VALUE_DATE);
/* FIXME: We should handle timezone specifiers */
break;
case ICAL_DURATION_PROPERTY:
@@ -414,7 +415,11 @@ parse_person (icalproperty* prop, gchar* value)
param = icalproperty_get_first_parameter (prop,
ICAL_CN_PARAMETER);
- ret->name = g_strdup (icalparameter_get_cn (param));
+ if (param)
+ ret->name = g_strdup (icalparameter_get_cn (param));
+ else
+ ret->name = NULL;
+
param = icalproperty_get_first_parameter (prop,
ICAL_ROLE_PARAMETER);
@@ -532,10 +537,11 @@ parse_person (icalproperty* prop, gchar* value)
ICAL_DELEGATEDFROM_PARAMETER);
}
- param = icalproperty_get_first_parameter (prop, ICAL_SENTBY_PARAMETER
-);
- copy_str (&ret->sent_by,
- icalparameter_get_sentby (param));
+ param = icalproperty_get_first_parameter (prop, ICAL_SENTBY_PARAMETER);
+ if (param)
+ copy_str (&ret->sent_by, icalparameter_get_sentby (param));
+ else
+ ret->sent_by = NULL;
param = icalproperty_get_first_parameter (prop, ICAL_DIR_PARAMETER);
while (param) {
diff --git a/calendar/pcs/.cvsignore b/calendar/pcs/.cvsignore
index f4bf65a918..564ce29f83 100644
--- a/calendar/pcs/.cvsignore
+++ b/calendar/pcs/.cvsignore
@@ -1,7 +1,9 @@
Makefile
Makefile.in
.deps
+.libs
evolution-calendar-stubs.c
evolution-calendar-skels.c
evolution-calendar-common.c
evolution-calendar.h
+icalendar-test
diff --git a/calendar/pcs/Makefile.am b/calendar/pcs/Makefile.am
index 545e403201..11aba079cb 100644
--- a/calendar/pcs/Makefile.am
+++ b/calendar/pcs/Makefile.am
@@ -38,5 +38,24 @@ libpcs_a_SOURCES = \
job.c \
job.h
+
+
+noinst_PROGRAMS = icalendar-test
+
+icalendar_test_SOURCES = \
+ icalendar-test.c \
+ icalendar.c \
+ icalendar-save.c
+
+icalendar_test_LDADD = \
+ $(EXTRA_GNOME_LIBS) \
+ $(top_builddir)/libversit/libversit.la \
+ $(top_builddir)/libical/src/libical/libical.la
+
+# $(top_builddir)/calendar/cal-util/libcal-util.la \
+
+
+
+
BUILT_SOURCES = $(CORBA_GENERATED)
CLEANFILES += $(BUILT_SOURCES)
diff --git a/calendar/pcs/icalendar-save.c b/calendar/pcs/icalendar-save.c
index a3b2505778..1b35d2dadf 100644
--- a/calendar/pcs/icalendar-save.c
+++ b/calendar/pcs/icalendar-save.c
@@ -164,9 +164,9 @@ icalcomponent_create_from_ical_object (iCalObject *ical)
/*** transp ***/
{
if (ical->transp == ICAL_TRANSP_PROPERTY)
- icalproperty_set_transp (prop, "TRANSPARENT");
+ prop = icalproperty_new_transp ("TRANSPARENT");
else
- icalproperty_set_transp (prop, "OPAQUE");
+ prop = icalproperty_new_transp ("OPAQUE");
icalcomponent_add_property (comp, prop);
}
@@ -347,8 +347,10 @@ void unparse_person (iCalPerson *person, icalproperty *person_prop)
/* convert iCalPerson to an icalproperty */
- param = icalparameter_new_cn (person->name);
- icalproperty_add_parameter (person_prop, param);
+ if (person->name) {
+ param = icalparameter_new_cn (person->name);
+ icalproperty_add_parameter (person_prop, param);
+ }
if (g_strcasecmp (person->role, "CHAIR") == 0)
param = icalparameter_new_role (ICAL_ROLE_CHAIR);
@@ -418,7 +420,10 @@ void unparse_person (iCalPerson *person, icalproperty *person_prop)
icalproperty_add_parameter (person_prop, param);
}
- param = icalparameter_new_sentby (person->sent_by);
+ if (person->sent_by) {
+ param = icalparameter_new_sentby (person->sent_by);
+ icalproperty_add_parameter (person_prop, param);
+ }
/* ret->deleg_to is a list of ICAL_DIR_PARAMETER */
/* FIX ME ... */
diff --git a/calendar/pcs/icalendar-test.c b/calendar/pcs/icalendar-test.c
new file mode 100644
index 0000000000..921e109a2c
--- /dev/null
+++ b/calendar/pcs/icalendar-test.c
@@ -0,0 +1,146 @@
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
+
+#include <sys/stat.h>
+#include <stdlib.h>
+#include <unistd.h>
+
+#include <config.h>
+#include <gtk/gtksignal.h>
+#include <cal-util/calobj.h>
+#include "libversit/vcc.h"
+
+#include "icalendar-save.h"
+#include "icalendar.h"
+
+
+static icalcomponent*
+icalendar_parse_file (char* fname)
+{
+ FILE* fp;
+ icalcomponent* comp = NULL;
+ gchar* str;
+ struct stat st;
+ int n;
+
+ fp = fopen (fname, "r");
+ if (!fp) {
+ g_warning ("Cannot open open calendar file.");
+ return NULL;
+ }
+
+ stat (fname, &st);
+
+ str = g_malloc (st.st_size + 2);
+
+ n = fread ((gchar*) str, 1, st.st_size, fp);
+ if (n != st.st_size) {
+ g_warning ("Read error.");
+ }
+ str[n] = '\0';
+
+ fclose (fp);
+
+ comp = icalparser_parse_string (str);
+ g_free (str);
+
+ return comp;
+}
+
+
+static GList *
+icalendar_calendar_load (GList *icals, char *fname)
+{
+ icalcomponent *comp;
+ icalcomponent *subcomp;
+ iCalObject *ical;
+
+ comp = icalendar_parse_file (fname);
+ subcomp = icalcomponent_get_first_component (comp,
+ ICAL_ANY_COMPONENT);
+ 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 {
+ printf ("prepending %p\n", ical);
+ icals = g_list_prepend (icals, ical);
+ }
+ subcomp = icalcomponent_get_next_component (comp,
+ ICAL_ANY_COMPONENT);
+ }
+
+ return icals;
+}
+
+
+
+
+static void
+icalendar_calendar_save (GList *icals, char *fname)
+{
+ GList *cur;
+ icalcomponent *top = icalcomponent_new (ICAL_VCALENDAR_COMPONENT);
+ char *out_cal_string;
+
+ for (cur=icals; cur; cur=cur->next) {
+ iCalObject *ical = (iCalObject *) cur->data;
+ icalcomponent *comp;
+ comp = icalcomponent_create_from_ical_object (ical);
+ icalcomponent_add_component (top, comp);
+ }
+
+ out_cal_string = icalcomponent_as_ical_string (top);
+
+ printf ("---------------------------------------------------------\n");
+ printf ("%s", out_cal_string);
+}
+
+
+
+int main (int argc, char *argv[])
+{
+ GList *icals = NULL;
+ int i;
+ long int n0, n1;
+ struct icaldurationtype dt;
+
+
+ /* test icaldurationtype_from_timet */
+ srandom (time (0));
+
+ for (i=0; i<10; i++) {
+ n0 = random () % ((60 * 60 * 24 * 7) * 4);
+ dt = icaldurationtype_from_timet (n0);
+ n1 = icaldurationtype_as_timet (dt);
+
+ printf ("%ld -> (%d %d %d %d %d) -> %ld\n",
+ n0,
+ dt.weeks, dt.days, dt.hours, dt.minutes, dt.seconds,
+ n1);
+ if (n0 != n1) abort ();
+ }
+
+ /*****************/
+ /* test conversion of icalcomponents to and from iCalObjects */
+ /*****************/
+
+ /* load an ical file */
+
+ if (argc < 2) {
+ printf ("give ical file as argument.\n");
+ return 1;
+ }
+
+ icals = icalendar_calendar_load (icals, argv[ 1 ]);
+
+ printf ("loaded %d ical components\n", g_list_length (icals));
+
+
+ /* save it back out */
+
+ icalendar_calendar_save (icals, "out.ical");
+
+ return 0;
+}
diff --git a/calendar/pcs/icalendar.c b/calendar/pcs/icalendar.c
index 8a15bb3cb4..eedb732617 100644
--- a/calendar/pcs/icalendar.c
+++ b/calendar/pcs/icalendar.c
@@ -1,3 +1,4 @@
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
/*
* icalendar server for gnomecal
*
@@ -195,8 +196,8 @@ ical_object_create_from_icalcomponent (icalcomponent* comp)
ical->dtend = icaltime_to_timet (&ictime);
param = icalproperty_get_first_parameter (prop,
ICAL_VALUE_PARAMETER);
- ical->date_only = (icalparameter_get_value (param) ==
- ICAL_VALUE_DATE);
+ if (param)
+ ical->date_only = (icalparameter_get_value (param) == ICAL_VALUE_DATE);
/* FIXME: We should handle timezone specifiers */
break;
case ICAL_DUE_PROPERTY:
@@ -213,8 +214,8 @@ ical_object_create_from_icalcomponent (icalcomponent* comp)
ical->dtstart = icaltime_to_timet (&ictime);
param = icalproperty_get_first_parameter (prop,
ICAL_VALUE_PARAMETER);
- ical->date_only = (icalparameter_get_value (param) ==
- ICAL_VALUE_DATE);
+ if (param)
+ ical->date_only = (icalparameter_get_value (param) == ICAL_VALUE_DATE);
/* FIXME: We should handle timezone specifiers */
break;
case ICAL_DURATION_PROPERTY:
@@ -414,7 +415,11 @@ parse_person (icalproperty* prop, gchar* value)
param = icalproperty_get_first_parameter (prop,
ICAL_CN_PARAMETER);
- ret->name = g_strdup (icalparameter_get_cn (param));
+ if (param)
+ ret->name = g_strdup (icalparameter_get_cn (param));
+ else
+ ret->name = NULL;
+
param = icalproperty_get_first_parameter (prop,
ICAL_ROLE_PARAMETER);
@@ -532,10 +537,11 @@ parse_person (icalproperty* prop, gchar* value)
ICAL_DELEGATEDFROM_PARAMETER);
}
- param = icalproperty_get_first_parameter (prop, ICAL_SENTBY_PARAMETER
-);
- copy_str (&ret->sent_by,
- icalparameter_get_sentby (param));
+ param = icalproperty_get_first_parameter (prop, ICAL_SENTBY_PARAMETER);
+ if (param)
+ copy_str (&ret->sent_by, icalparameter_get_sentby (param));
+ else
+ ret->sent_by = NULL;
param = icalproperty_get_first_parameter (prop, ICAL_DIR_PARAMETER);
while (param) {