diff options
Diffstat (limited to 'calendar')
-rw-r--r-- | calendar/ChangeLog | 12 | ||||
-rw-r--r-- | calendar/Makefile.am | 17 | ||||
-rw-r--r-- | calendar/cal-backend.c | 136 | ||||
-rw-r--r-- | calendar/cal-backend.h | 5 | ||||
-rw-r--r-- | calendar/calendar.c | 6 | ||||
-rw-r--r-- | calendar/calendar.h | 6 | ||||
-rw-r--r-- | calendar/gui/Makefile.am | 17 | ||||
-rw-r--r-- | calendar/gui/calendar.c | 6 | ||||
-rw-r--r-- | calendar/gui/calendar.h | 6 | ||||
-rw-r--r-- | calendar/icalendar.c | 70 | ||||
-rw-r--r-- | calendar/pcs/cal-backend.c | 136 | ||||
-rw-r--r-- | calendar/pcs/cal-backend.h | 5 |
12 files changed, 307 insertions, 115 deletions
diff --git a/calendar/ChangeLog b/calendar/ChangeLog index 679107d985..d952624d20 100644 --- a/calendar/ChangeLog +++ b/calendar/ChangeLog @@ -1,3 +1,15 @@ +2000-02-17 Seth Alves <alves@hungry.com> + + * cal-backend.h: moved CalendarFormat type def here + + * cal-backend.c (cal_backend_load): if extension suggests + an ical file, attempt to load an iCal file. + (cal_get_type_from_filename): returns CAL_ICAL if file + extension is 'ics' or 'ifb', else returns CAL_VCAL + (icalendar_calendar_load): moved this here from + icalendar.c because it needs to call the static function + add_object. + 2000-02-17 Federico Mena Quintero <federico@helixcode.com> * cal-client.c (cal_client_remove_object): Implemented. diff --git a/calendar/Makefile.am b/calendar/Makefile.am index 1762bc0bf7..575344e651 100644 --- a/calendar/Makefile.am +++ b/calendar/Makefile.am @@ -20,19 +20,14 @@ endif bin_PROGRAMS = gnomecal tlacuache $(extra_pilot_bins) -#if HAVE_LIBICAL -ICAL_INCLUDEDIR = -I../libical/src/libical -ICAL_SOURCES = icalendar.c ICAL_LINK_FLAGS = ../libical/src/libical/libical.a -#endif - INCLUDES = \ -I$(includedir) \ $(GNOME_INCLUDEDIR) \ $(GNOME_CONDUIT_INCLUDEDIR) \ $(PISOCK_INCLUDEDIR) \ - $(ICAL_INCLUDEDIR) \ + -I../libical/src/libical \ -DGNOMELOCALEDIR=\""$(datadir)/locale"\" GNOMECAL_CORBA_GENERATED = \ @@ -99,6 +94,8 @@ gnomecal_SOURCES = \ gnome-cal.c \ gnome-cal.h \ goto.c \ + icalendar.c \ + icalendar.h \ layout.c \ layout.h \ main.c \ @@ -118,8 +115,7 @@ gnomecal_SOURCES = \ view-utils.h \ view-utils.c \ year-view.c \ - year-view.h \ - $(ICAL_SOURCES) + year-view.h calendar_pilot_sync_SOURCES = \ GnomeCal-common.c \ @@ -148,6 +144,8 @@ tlacuache_SOURCES = \ cal-util.h \ calobj.c \ calobj.h \ + icalendar.c \ + icalendar.h \ job.c \ job.h \ timeutil.c \ @@ -166,7 +164,8 @@ tlacuache_INCLUDES = \ tlacuache_LDADD = \ $(BONOBO_VFS_GNOME_LIBS) \ - ../libversit/libversit.la + ../libversit/libversit.la \ + $(ICAL_LINK_FLAGS) calendar_pilot_sync_LDADD = \ $(PISOCK_LIBDIR) $(PISOCK_LIBS) \ diff --git a/calendar/cal-backend.c b/calendar/cal-backend.c index 6b9894e098..570c4dccdc 100644 --- a/calendar/cal-backend.c +++ b/calendar/cal-backend.c @@ -24,6 +24,7 @@ #include "cal-backend.h" #include "calobj.h" #include "../libversit/vcc.h" +#include "icalendar.h" @@ -37,6 +38,9 @@ typedef struct { /* URI where the calendar data is stored */ GnomeVFSURI *uri; + /* format of this calendar (ical or vcal) */ + CalendarFormat format; + /* List of Cal objects with their listeners */ GList *clients; @@ -118,6 +122,9 @@ cal_backend_init (CalBackend *backend) priv = g_new0 (CalBackendPrivate, 1); backend->priv = priv; + + /* FIXME can be CAL_VCAL or CAL_ICAL */ + priv->format = CAL_VCAL; } /* Saves a calendar */ @@ -550,6 +557,103 @@ cal_backend_add_cal (CalBackend *backend, Cal *cal) priv->clients = g_list_prepend (priv->clients, cal); } + +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 void +icalendar_calendar_load (CalBackend * cal, 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 + add_object (cal, ical); + subcomp = icalcomponent_get_next_component (comp, + ICAL_ANY_COMPONENT); + } +} + + +/* +ics is to be used to designate a file containing (an arbitrary set of) +calendaring and scheduling information. + +ifb is to be used to designate a file containing free or busy time +information. + +anything else is assumed to be a vcal file. +*/ + +static CalendarFormat +cal_get_type_from_filename (char *str_uri) +{ + int len; + + if (str_uri == NULL) + return CAL_VCAL; + + len = strlen (str_uri); + if (len < 5) + return CAL_VCAL; + + if (str_uri[ len-4 ] == '.' && + str_uri[ len-3 ] == 'i' && + str_uri[ len-2 ] == 'c' && + str_uri[ len-1 ] == 's') + return CAL_ICAL; + + if (str_uri[ len-4 ] == '.' && + str_uri[ len-3 ] == 'i' && + str_uri[ len-2 ] == 'f' && + str_uri[ len-1 ] == 'b') + return CAL_ICAL; + + return CAL_VCAL; +} + + /** * cal_backend_load: * @backend: A calendar backend. @@ -586,15 +690,33 @@ cal_backend_load (CalBackend *backend, GnomeVFSURI *uri) | GNOME_VFS_URI_HIDE_HOST_PORT | GNOME_VFS_URI_HIDE_TOPLEVEL_METHOD)); - vobject = Parse_MIME_FromFileName (str_uri); - g_free (str_uri); - if (!vobject) - return CAL_BACKEND_LOAD_ERROR; + /* look at the extension on the filename and decide + if this is a ical or vcal file */ - load_from_vobject (backend, vobject); - cleanVObject (vobject); - cleanStrTbl (); + priv->format = cal_get_type_from_filename (str_uri); + + /* load */ + + switch (priv->format) { + case CAL_VCAL: + vobject = Parse_MIME_FromFileName (str_uri); + + if (!vobject) + return CAL_BACKEND_LOAD_ERROR; + + load_from_vobject (backend, vobject); + cleanVObject (vobject); + cleanStrTbl (); + break; + case CAL_ICAL: + icalendar_calendar_load (backend, str_uri); + break; + default: + return CAL_BACKEND_LOAD_ERROR; + } + + g_free (str_uri); gnome_vfs_uri_ref (uri); diff --git a/calendar/cal-backend.h b/calendar/cal-backend.h index 66b1b8f5e3..21c516126d 100644 --- a/calendar/cal-backend.h +++ b/calendar/cal-backend.h @@ -57,6 +57,11 @@ struct _CalBackendClass { GtkObjectClass parent_class; }; +typedef enum { + CAL_VCAL, + CAL_ICAL +} CalendarFormat; + GtkType cal_backend_get_type (void); CalBackend *cal_backend_new (void); diff --git a/calendar/calendar.c b/calendar/calendar.c index 0a690f344b..172ef3390e 100644 --- a/calendar/calendar.c +++ b/calendar/calendar.c @@ -21,6 +21,7 @@ #include "alarm.h" #include "timeutil.h" #include "../libversit/vcc.h" +#include "icalendar.h" #ifdef HAVE_TZNAME extern char *tzname[2]; @@ -334,12 +335,11 @@ calendar_load (Calendar *cal, char *fname) cleanVObject (vcal); cleanStrTbl (); break; -#ifdef HAVE_LIBICAL - hi; + /* case CAL_ICAL: icalendar_calendar_load (cal, fname); break; -#endif + */ default: return "Unknown calendar format"; } diff --git a/calendar/calendar.h b/calendar/calendar.h index 452281ebd1..4e077ddd58 100644 --- a/calendar/calendar.h +++ b/calendar/calendar.h @@ -2,14 +2,10 @@ #define CALENDAR_H #include "calobj.h" +#include "cal-backend.h" BEGIN_GNOME_DECLS -typedef enum { - CAL_VCAL, - CAL_ICAL -} CalendarFormat; - typedef struct { /* This calendar's title */ char *title; diff --git a/calendar/gui/Makefile.am b/calendar/gui/Makefile.am index 1762bc0bf7..575344e651 100644 --- a/calendar/gui/Makefile.am +++ b/calendar/gui/Makefile.am @@ -20,19 +20,14 @@ endif bin_PROGRAMS = gnomecal tlacuache $(extra_pilot_bins) -#if HAVE_LIBICAL -ICAL_INCLUDEDIR = -I../libical/src/libical -ICAL_SOURCES = icalendar.c ICAL_LINK_FLAGS = ../libical/src/libical/libical.a -#endif - INCLUDES = \ -I$(includedir) \ $(GNOME_INCLUDEDIR) \ $(GNOME_CONDUIT_INCLUDEDIR) \ $(PISOCK_INCLUDEDIR) \ - $(ICAL_INCLUDEDIR) \ + -I../libical/src/libical \ -DGNOMELOCALEDIR=\""$(datadir)/locale"\" GNOMECAL_CORBA_GENERATED = \ @@ -99,6 +94,8 @@ gnomecal_SOURCES = \ gnome-cal.c \ gnome-cal.h \ goto.c \ + icalendar.c \ + icalendar.h \ layout.c \ layout.h \ main.c \ @@ -118,8 +115,7 @@ gnomecal_SOURCES = \ view-utils.h \ view-utils.c \ year-view.c \ - year-view.h \ - $(ICAL_SOURCES) + year-view.h calendar_pilot_sync_SOURCES = \ GnomeCal-common.c \ @@ -148,6 +144,8 @@ tlacuache_SOURCES = \ cal-util.h \ calobj.c \ calobj.h \ + icalendar.c \ + icalendar.h \ job.c \ job.h \ timeutil.c \ @@ -166,7 +164,8 @@ tlacuache_INCLUDES = \ tlacuache_LDADD = \ $(BONOBO_VFS_GNOME_LIBS) \ - ../libversit/libversit.la + ../libversit/libversit.la \ + $(ICAL_LINK_FLAGS) calendar_pilot_sync_LDADD = \ $(PISOCK_LIBDIR) $(PISOCK_LIBS) \ diff --git a/calendar/gui/calendar.c b/calendar/gui/calendar.c index 0a690f344b..172ef3390e 100644 --- a/calendar/gui/calendar.c +++ b/calendar/gui/calendar.c @@ -21,6 +21,7 @@ #include "alarm.h" #include "timeutil.h" #include "../libversit/vcc.h" +#include "icalendar.h" #ifdef HAVE_TZNAME extern char *tzname[2]; @@ -334,12 +335,11 @@ calendar_load (Calendar *cal, char *fname) cleanVObject (vcal); cleanStrTbl (); break; -#ifdef HAVE_LIBICAL - hi; + /* case CAL_ICAL: icalendar_calendar_load (cal, fname); break; -#endif + */ default: return "Unknown calendar format"; } diff --git a/calendar/gui/calendar.h b/calendar/gui/calendar.h index 452281ebd1..4e077ddd58 100644 --- a/calendar/gui/calendar.h +++ b/calendar/gui/calendar.h @@ -2,14 +2,10 @@ #define CALENDAR_H #include "calobj.h" +#include "cal-backend.h" BEGIN_GNOME_DECLS -typedef enum { - CAL_VCAL, - CAL_ICAL -} CalendarFormat; - typedef struct { /* This calendar's title */ char *title; diff --git a/calendar/icalendar.c b/calendar/icalendar.c index 43c1b46016..30d91f6858 100644 --- a/calendar/icalendar.c +++ b/calendar/icalendar.c @@ -13,12 +13,9 @@ #include <gnome.h> #include <unistd.h> #include <sys/stat.h> -#include "ical.h" -#include "calobj.h" -#include "calendar.h" +#include "icalendar.h" +#include "cal-backend.h" -void icalendar_calendar_load (Calendar* cal, char* fname); -static icalcomponent* icalendar_parse_file (char* fname); static time_t icaltime_to_timet (struct icaltimetype* i); static CalendarAlarm* parse_alarm (icalproperty *prop); static iCalPerson* parse_person (icalproperty *prop, gchar *value); @@ -39,14 +36,8 @@ copy_to_list (GList** store, gchar* src) return *store; } -/* eh? - static icalcomponent* - ical_object_to_icalcomponent (iCalObject* ical) - { - icalcomponent *comp; -*/ -static iCalObject * +iCalObject * ical_object_create_from_icalcomponent (icalcomponent* comp) { iCalObject *ical = NULL; @@ -372,61 +363,6 @@ this may not be correct */ return ical; } -void -icalendar_calendar_load (Calendar* cal, 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 - calendar_add_object (cal, ical); - subcomp = icalcomponent_get_next_component (comp, - ICAL_ANY_COMPONENT); - } -} - -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 time_t icaltime_to_timet (struct icaltimetype* i) { diff --git a/calendar/pcs/cal-backend.c b/calendar/pcs/cal-backend.c index 6b9894e098..570c4dccdc 100644 --- a/calendar/pcs/cal-backend.c +++ b/calendar/pcs/cal-backend.c @@ -24,6 +24,7 @@ #include "cal-backend.h" #include "calobj.h" #include "../libversit/vcc.h" +#include "icalendar.h" @@ -37,6 +38,9 @@ typedef struct { /* URI where the calendar data is stored */ GnomeVFSURI *uri; + /* format of this calendar (ical or vcal) */ + CalendarFormat format; + /* List of Cal objects with their listeners */ GList *clients; @@ -118,6 +122,9 @@ cal_backend_init (CalBackend *backend) priv = g_new0 (CalBackendPrivate, 1); backend->priv = priv; + + /* FIXME can be CAL_VCAL or CAL_ICAL */ + priv->format = CAL_VCAL; } /* Saves a calendar */ @@ -550,6 +557,103 @@ cal_backend_add_cal (CalBackend *backend, Cal *cal) priv->clients = g_list_prepend (priv->clients, cal); } + +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 void +icalendar_calendar_load (CalBackend * cal, 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 + add_object (cal, ical); + subcomp = icalcomponent_get_next_component (comp, + ICAL_ANY_COMPONENT); + } +} + + +/* +ics is to be used to designate a file containing (an arbitrary set of) +calendaring and scheduling information. + +ifb is to be used to designate a file containing free or busy time +information. + +anything else is assumed to be a vcal file. +*/ + +static CalendarFormat +cal_get_type_from_filename (char *str_uri) +{ + int len; + + if (str_uri == NULL) + return CAL_VCAL; + + len = strlen (str_uri); + if (len < 5) + return CAL_VCAL; + + if (str_uri[ len-4 ] == '.' && + str_uri[ len-3 ] == 'i' && + str_uri[ len-2 ] == 'c' && + str_uri[ len-1 ] == 's') + return CAL_ICAL; + + if (str_uri[ len-4 ] == '.' && + str_uri[ len-3 ] == 'i' && + str_uri[ len-2 ] == 'f' && + str_uri[ len-1 ] == 'b') + return CAL_ICAL; + + return CAL_VCAL; +} + + /** * cal_backend_load: * @backend: A calendar backend. @@ -586,15 +690,33 @@ cal_backend_load (CalBackend *backend, GnomeVFSURI *uri) | GNOME_VFS_URI_HIDE_HOST_PORT | GNOME_VFS_URI_HIDE_TOPLEVEL_METHOD)); - vobject = Parse_MIME_FromFileName (str_uri); - g_free (str_uri); - if (!vobject) - return CAL_BACKEND_LOAD_ERROR; + /* look at the extension on the filename and decide + if this is a ical or vcal file */ - load_from_vobject (backend, vobject); - cleanVObject (vobject); - cleanStrTbl (); + priv->format = cal_get_type_from_filename (str_uri); + + /* load */ + + switch (priv->format) { + case CAL_VCAL: + vobject = Parse_MIME_FromFileName (str_uri); + + if (!vobject) + return CAL_BACKEND_LOAD_ERROR; + + load_from_vobject (backend, vobject); + cleanVObject (vobject); + cleanStrTbl (); + break; + case CAL_ICAL: + icalendar_calendar_load (backend, str_uri); + break; + default: + return CAL_BACKEND_LOAD_ERROR; + } + + g_free (str_uri); gnome_vfs_uri_ref (uri); diff --git a/calendar/pcs/cal-backend.h b/calendar/pcs/cal-backend.h index 66b1b8f5e3..21c516126d 100644 --- a/calendar/pcs/cal-backend.h +++ b/calendar/pcs/cal-backend.h @@ -57,6 +57,11 @@ struct _CalBackendClass { GtkObjectClass parent_class; }; +typedef enum { + CAL_VCAL, + CAL_ICAL +} CalendarFormat; + GtkType cal_backend_get_type (void); CalBackend *cal_backend_new (void); |