From f865d886f5aae9279d44f726a0b8093316a40e09 Mon Sep 17 00:00:00 2001 From: Miguel de Icaza Date: Thu, 2 Apr 1998 07:57:58 +0000 Subject: New main program that uses our new datatypes and objects. 1998-04-02 Miguel de Icaza * main.c: New main program that uses our new datatypes and objects. * calendar.c (calendar_load_from_vobject, calendar_load): Implement loading of vCalendar objects and vCalendar files. * calobj.c (ical_object_create_from_vobject): Implement loading of vCalendar event and todo objects. * timeutil.c (isodate_from_time_t): New function. * gnome-cal.c, gnome-cal.h: Implement a toplevel widget, derived from GnomeApp. It holds all of the day views and arbitrates the display. svn path=/trunk/; revision=93 --- calendar/.cvsignore | 1 + calendar/ChangeLog | 17 +++++ calendar/Makefile.am | 18 +++-- calendar/cal-util/calobj.c | 168 +++++++++++++++++++++++++++++++++++++++++++++ calendar/cal-util/calobj.h | 7 +- calendar/calendar.c | 55 +++++++++++++++ calendar/calendar.h | 1 + calendar/calobj.c | 168 +++++++++++++++++++++++++++++++++++++++++++++ calendar/calobj.h | 7 +- calendar/gnome-cal.c | 11 +-- calendar/gnome-cal.h | 2 +- calendar/gui/Makefile.am | 18 +++-- calendar/gui/calendar.c | 55 +++++++++++++++ calendar/gui/calendar.h | 1 + calendar/gui/gnome-cal.c | 11 +-- calendar/gui/gnome-cal.h | 2 +- calendar/gui/main.c | 24 ++++++- calendar/main.c | 24 ++++++- calendar/pcs/calobj.c | 168 +++++++++++++++++++++++++++++++++++++++++++++ calendar/pcs/calobj.h | 7 +- calendar/timeutil.c | 11 +++ calendar/timeutil.h | 1 + 22 files changed, 747 insertions(+), 30 deletions(-) diff --git a/calendar/.cvsignore b/calendar/.cvsignore index 9d3b9d1349..71e5400a29 100644 --- a/calendar/.cvsignore +++ b/calendar/.cvsignore @@ -4,3 +4,4 @@ Makefile _libs .libs gncal +gnomecal diff --git a/calendar/ChangeLog b/calendar/ChangeLog index 59bc2b5328..396f5d2a83 100644 --- a/calendar/ChangeLog +++ b/calendar/ChangeLog @@ -1,3 +1,20 @@ +1998-04-02 Miguel de Icaza + + * main.c: New main program that uses our new datatypes and + objects. + + * calendar.c (calendar_load_from_vobject, calendar_load): + Implement loading of vCalendar objects and vCalendar files. + + * calobj.c (ical_object_create_from_vobject): Implement loading of + vCalendar event and todo objects. + + * timeutil.c (isodate_from_time_t): New function. + + * gnome-cal.c, gnome-cal.h: Implement a toplevel widget, derived + from GnomeApp. It holds all of the day views and arbitrates the + display. + 1998-04-02 Federico Mena Quintero * gncal-week-view.[ch]: New week view composite widget. This diff --git a/calendar/Makefile.am b/calendar/Makefile.am index 5ab3511b11..6ab68ffb7d 100644 --- a/calendar/Makefile.am +++ b/calendar/Makefile.am @@ -9,15 +9,23 @@ INCLUDES = \ bin_PROGRAMS = gnomecal gnomecal_SOURCES = \ - main.c \ - gnome-cal.c \ - gnome-cal.h \ - views.c \ calendar.c \ calendar.h \ calobj.c \ calobj.h \ - views.h + gncal-week-view.c \ + gncal-week-view.h \ + gncal-day-view.c \ + gncal-day-view.h \ + gnome-cal.c \ + gnome-cal.h \ + main.c \ + timeutil.c \ + timeutil.h \ + view-utils.h \ + view-utils.c \ + views.h \ + views.c #gncal_SOURCES = \ diff --git a/calendar/cal-util/calobj.c b/calendar/cal-util/calobj.c index fcdfb7e59d..2f4647548f 100644 --- a/calendar/cal-util/calobj.c +++ b/calendar/cal-util/calobj.c @@ -6,7 +6,10 @@ * Miguel de Icaza (miguel@gnu.org) * Federico Mena (federico@gimp.org) */ +#include +#include #include "calobj.h" +#include "versit/vcc.h" iCalObject * ical_object_new (void) @@ -46,3 +49,168 @@ ical_object_destroy (iCalObject *ico) g_free (ico); } + +GList * +set_list (char *str, char *sc) +{ + GList *list = 0; + char *s; + + for (s = strtok (str, sc); s; s = strtok (NULL, sc)) + list = g_list_prepend (list, g_strdup (s)); + + return list; +} + +#define is_a_prop_of(obj,prop) isAPropertyOf (obj,prop) +#define str_val(obj) (char *) vObjectUStringZValue (obj) +#define has(obj,prop) (vo = isAPropertyOf (obj, prop)) + +/* FIXME: we need to load the recurrence properties */ +iCalObject * +ical_object_create_from_vobject (VObject *o, const char *object_name) +{ + time_t now = time (NULL); + iCalObject *ical; + VObject *vo; + VObjectIterator i; + + ical = g_new0 (iCalObject, 1); + + if (strcmp (object_name, VCEventProp) == 0) + ical->type = ICAL_EVENT; + else if (strcmp (object_name, VCTodoProp) == 0) + ical->type = ICAL_TODO; + else + return 0; + /* uid */ + if (has (o, VCUniqueStringProp)) + ical->uid = g_strdup (str_val (vo)); + + /* seq */ + if (has (o, VCSequenceProp)) + ical->seq = atoi (str_val (vo)); + else + ical->seq = 0; + + /* dtstart */ + if (has (o, VCDTstartProp)) + ical->dtstart = time_from_isodate (str_val (vo)); + else + ical->dtstart = 0; + + /* dtend */ + if (has (o, VCDTendProp)) + ical->dtend = time_from_isodate (str_val (vo)); + else + ical->dtend = 0; + + /* dcreated */ + if (has (o, VCDCreatedProp)) + ical->created = time_from_isodate (str_val (vo)); + + /* completed */ + if (has (o, VCCompletedProp)) + ical->completed = time_from_isodate (str_val (vo)); + + /* last_mod */ + if (has (o, VCLastModifiedProp)) + ical->last_mod = time_from_isodate (str_val (vo)); + else + ical->last_mod = now; + + /* exdate */ + if (has (o, VCExpDateProp)) + ical->exdate = set_list (str_val (vo), ","); + + /* description */ + if (has (o, VCDescriptionProp)) + ical->description = g_strdup (str_val (vo)); + + /* summary */ + if (has (o, VCSummaryProp)) + ical->summary = g_strdup (str_val (vo)); + else + ical->summary = g_strdup (""); + + /* status */ + if (has (o, VCStatusProp)) + ical->status = g_strdup (str_val (vo)); + else + ical->status = g_strdup ("NEEDS ACTION"); + + if (has (o, VCClassProp)) + ical->class = g_strdup (str_val (vo)); + else + ical->status = g_strdup ("PUBLIC"); + + /* categories */ + if (has (o, VCCategoriesProp)) + ical->categories = set_list (str_val (vo), ","); + + /* resources */ + if (has (o, VCResourcesProp)) + ical->resources = set_list (str_val (vo), ";"); + + /* priority */ + if (has (o, VCPriorityProp)) + ical->priority = atoi (str_val (vo)); + + /* tranparency */ + if (has (o, VCTranspProp)) + ical->transp = atoi (str_val (vo)) ? ICAL_TRANSPARENT : ICAL_OPAQUE; + + /* related */ + if (has (o, VCRelatedToProp)) + ical->related = set_list (str_val (vo), ";"); + + /* attach */ + initPropIterator (&i, o); + while (moreIteration (&i)){ + vo = nextVObject (&i); + if (strcmp (vObjectName (vo), VCAttachProp) == 0) + ical->attach = g_list_prepend (ical->attach, g_strdup (str_val (vo))); + } + + /* url */ + if (has (o, VCURLProp)) + ical->url = g_strdup (str_val (vo)); + + /* FIXME: dalarm */ + if (has (o, VCDAlarmProp)) + ; + + /* FIXME: aalarm */ + if (has (o, VCAAlarmProp)) + ; + + /* FIXME: palarm */ + if (has (o, VCPAlarmProp)) + ; + + /* FIXME: malarm */ + if (has (o, VCMAlarmProp)) + ; + + /* FIXME: rdate */ + if (has (o, VCRDateProp)) + ; + + /* FIXME: rrule */ + if (has (o, VCRRuleProp)) + ; + + return ical; +} + +void +ical_object_save (iCalObject *ical) +{ + VObject *o; + + if (ical->type == ICAL_EVENT) + o = newVObject (VCEventProp); + else + o = newVObject (VCTodoProp); +} + diff --git a/calendar/cal-util/calobj.h b/calendar/cal-util/calobj.h index d5f6db0ae0..85f88dccd9 100644 --- a/calendar/cal-util/calobj.h +++ b/calendar/cal-util/calobj.h @@ -8,6 +8,7 @@ #define CALOBJ_H #include +#include "versit/vcc.h" BEGIN_GNOME_DECLS @@ -89,14 +90,16 @@ typedef struct { char *url; time_t recurid; - /* VALARM objects are always inside another object, never alone */ - CalendarAlarm *alarm; + CalendarAlarm *dalarm; + CalendarAlarm *aalarm; } iCalObject; iCalObject *ical_new (char *comment, char *organizer, char *summary); iCalObject *ical_object_new (void); void ical_object_destroy (iCalObject *ico); +iCalObject *ical_object_create_from_vobject (VObject *obj, const char *object_name); END_GNOME_DECLS #endif + diff --git a/calendar/calendar.c b/calendar/calendar.c index e077279461..5d7cb1dd8a 100644 --- a/calendar/calendar.c +++ b/calendar/calendar.c @@ -13,6 +13,7 @@ */ #include "calendar.h" +#include "versit/vcc.h" Calendar * calendar_new (char *title) @@ -28,6 +29,7 @@ calendar_new (char *title) void calendar_add_object (Calendar *cal, iCalObject *obj) { + printf ("Adding object\n"); switch (obj->type){ case ICAL_EVENT: cal->events = g_list_prepend (cal->events, obj); @@ -133,3 +135,56 @@ calendar_compare_by_dtstart (gpointer a, gpointer b) return (diff < 0) ? -1 : (diff > 0) ? 1 : 0; } + +#define str_val(obj) (char *) vObjectUStringZValue (obj) + +/* Loads our calendar contents from a vObject */ +void +calendar_load_from_vobject (Calendar *cal, VObject *vcal) +{ + VObjectIterator i;; + + initPropIterator (&i, vcal); + + while (moreIteration (&i)){ + VObject *this = nextVObject (&i); + iCalObject *ical; + const char *object_name = vObjectName (this); + + if (strcmp (object_name, VCDCreatedProp) == 0){ + cal->created = time_from_isodate (str_val (this)); + continue; + } + + if (strcmp (object_name, VCLocationProp) == 0) + continue; /* FIXME: imlement */ + + if (strcmp (object_name, VCProdIdProp) == 0) + continue; /* FIXME: implement */ + + if (strcmp (object_name, VCVersionProp) == 0) + continue; /* FIXME: implement */ + + ical = ical_object_create_from_vobject (this, object_name); + + if (ical) + calendar_add_object (cal, ical); + } +} + +/* Loads a calendar from a file */ +void +calendar_load (Calendar *cal, char *fname) +{ + VObject *vcal; + + if (cal->filename){ + g_warning ("Calendar load called again\n"); + return; + } + + cal->filename = g_strdup (fname); + vcal = Parse_MIME_FromFileName (fname); + calendar_load_from_vobject (cal, vcal); + cleanVObject (vcal); +} diff --git a/calendar/calendar.h b/calendar/calendar.h index 09242d9b76..805076d949 100644 --- a/calendar/calendar.h +++ b/calendar/calendar.h @@ -12,6 +12,7 @@ typedef struct { GList *todo; GList *journal; + time_t created; int modified; } Calendar; diff --git a/calendar/calobj.c b/calendar/calobj.c index fcdfb7e59d..2f4647548f 100644 --- a/calendar/calobj.c +++ b/calendar/calobj.c @@ -6,7 +6,10 @@ * Miguel de Icaza (miguel@gnu.org) * Federico Mena (federico@gimp.org) */ +#include +#include #include "calobj.h" +#include "versit/vcc.h" iCalObject * ical_object_new (void) @@ -46,3 +49,168 @@ ical_object_destroy (iCalObject *ico) g_free (ico); } + +GList * +set_list (char *str, char *sc) +{ + GList *list = 0; + char *s; + + for (s = strtok (str, sc); s; s = strtok (NULL, sc)) + list = g_list_prepend (list, g_strdup (s)); + + return list; +} + +#define is_a_prop_of(obj,prop) isAPropertyOf (obj,prop) +#define str_val(obj) (char *) vObjectUStringZValue (obj) +#define has(obj,prop) (vo = isAPropertyOf (obj, prop)) + +/* FIXME: we need to load the recurrence properties */ +iCalObject * +ical_object_create_from_vobject (VObject *o, const char *object_name) +{ + time_t now = time (NULL); + iCalObject *ical; + VObject *vo; + VObjectIterator i; + + ical = g_new0 (iCalObject, 1); + + if (strcmp (object_name, VCEventProp) == 0) + ical->type = ICAL_EVENT; + else if (strcmp (object_name, VCTodoProp) == 0) + ical->type = ICAL_TODO; + else + return 0; + /* uid */ + if (has (o, VCUniqueStringProp)) + ical->uid = g_strdup (str_val (vo)); + + /* seq */ + if (has (o, VCSequenceProp)) + ical->seq = atoi (str_val (vo)); + else + ical->seq = 0; + + /* dtstart */ + if (has (o, VCDTstartProp)) + ical->dtstart = time_from_isodate (str_val (vo)); + else + ical->dtstart = 0; + + /* dtend */ + if (has (o, VCDTendProp)) + ical->dtend = time_from_isodate (str_val (vo)); + else + ical->dtend = 0; + + /* dcreated */ + if (has (o, VCDCreatedProp)) + ical->created = time_from_isodate (str_val (vo)); + + /* completed */ + if (has (o, VCCompletedProp)) + ical->completed = time_from_isodate (str_val (vo)); + + /* last_mod */ + if (has (o, VCLastModifiedProp)) + ical->last_mod = time_from_isodate (str_val (vo)); + else + ical->last_mod = now; + + /* exdate */ + if (has (o, VCExpDateProp)) + ical->exdate = set_list (str_val (vo), ","); + + /* description */ + if (has (o, VCDescriptionProp)) + ical->description = g_strdup (str_val (vo)); + + /* summary */ + if (has (o, VCSummaryProp)) + ical->summary = g_strdup (str_val (vo)); + else + ical->summary = g_strdup (""); + + /* status */ + if (has (o, VCStatusProp)) + ical->status = g_strdup (str_val (vo)); + else + ical->status = g_strdup ("NEEDS ACTION"); + + if (has (o, VCClassProp)) + ical->class = g_strdup (str_val (vo)); + else + ical->status = g_strdup ("PUBLIC"); + + /* categories */ + if (has (o, VCCategoriesProp)) + ical->categories = set_list (str_val (vo), ","); + + /* resources */ + if (has (o, VCResourcesProp)) + ical->resources = set_list (str_val (vo), ";"); + + /* priority */ + if (has (o, VCPriorityProp)) + ical->priority = atoi (str_val (vo)); + + /* tranparency */ + if (has (o, VCTranspProp)) + ical->transp = atoi (str_val (vo)) ? ICAL_TRANSPARENT : ICAL_OPAQUE; + + /* related */ + if (has (o, VCRelatedToProp)) + ical->related = set_list (str_val (vo), ";"); + + /* attach */ + initPropIterator (&i, o); + while (moreIteration (&i)){ + vo = nextVObject (&i); + if (strcmp (vObjectName (vo), VCAttachProp) == 0) + ical->attach = g_list_prepend (ical->attach, g_strdup (str_val (vo))); + } + + /* url */ + if (has (o, VCURLProp)) + ical->url = g_strdup (str_val (vo)); + + /* FIXME: dalarm */ + if (has (o, VCDAlarmProp)) + ; + + /* FIXME: aalarm */ + if (has (o, VCAAlarmProp)) + ; + + /* FIXME: palarm */ + if (has (o, VCPAlarmProp)) + ; + + /* FIXME: malarm */ + if (has (o, VCMAlarmProp)) + ; + + /* FIXME: rdate */ + if (has (o, VCRDateProp)) + ; + + /* FIXME: rrule */ + if (has (o, VCRRuleProp)) + ; + + return ical; +} + +void +ical_object_save (iCalObject *ical) +{ + VObject *o; + + if (ical->type == ICAL_EVENT) + o = newVObject (VCEventProp); + else + o = newVObject (VCTodoProp); +} + diff --git a/calendar/calobj.h b/calendar/calobj.h index d5f6db0ae0..85f88dccd9 100644 --- a/calendar/calobj.h +++ b/calendar/calobj.h @@ -8,6 +8,7 @@ #define CALOBJ_H #include +#include "versit/vcc.h" BEGIN_GNOME_DECLS @@ -89,14 +90,16 @@ typedef struct { char *url; time_t recurid; - /* VALARM objects are always inside another object, never alone */ - CalendarAlarm *alarm; + CalendarAlarm *dalarm; + CalendarAlarm *aalarm; } iCalObject; iCalObject *ical_new (char *comment, char *organizer, char *summary); iCalObject *ical_object_new (void); void ical_object_destroy (iCalObject *ico); +iCalObject *ical_object_create_from_vobject (VObject *obj, const char *object_name); END_GNOME_DECLS #endif + diff --git a/calendar/gnome-cal.c b/calendar/gnome-cal.c index 333931a5a2..0b22a1a684 100644 --- a/calendar/gnome-cal.c +++ b/calendar/gnome-cal.c @@ -39,10 +39,13 @@ setup_widgets (GnomeCalendar *gcal) { GtkWidget *notebook; GtkWidget *day_view, *week_view, *year_view, *task_view; - + time_t now; + + now = time (NULL); + notebook = gtk_notebook_new (); day_view = day_view_create (gcal); - week_view = week_view_create (gcal); + week_view = gncal_week_view_new (gcal->cal, now); year_view = year_view_create (gcal); task_view = tasks_create (gcal); @@ -86,7 +89,7 @@ gnome_calendar_new (char *title) } void -gnome_calendar_load (char *file) +gnome_calendar_load (GnomeCalendar *gcal, char *file) { - + calendar_load (gcal->cal, file); } diff --git a/calendar/gnome-cal.h b/calendar/gnome-cal.h index 840ccf5122..2b30bf1f7c 100644 --- a/calendar/gnome-cal.h +++ b/calendar/gnome-cal.h @@ -28,7 +28,7 @@ typedef struct { guint gnome_calendar_get_type (void); GtkWidget *gnome_calendar_new (char *title); -void gnome_calendar_load (char *file); +void gnome_calendar_load (GnomeCalendar *gcal, char *file); END_GNOME_DECLS diff --git a/calendar/gui/Makefile.am b/calendar/gui/Makefile.am index 5ab3511b11..6ab68ffb7d 100644 --- a/calendar/gui/Makefile.am +++ b/calendar/gui/Makefile.am @@ -9,15 +9,23 @@ INCLUDES = \ bin_PROGRAMS = gnomecal gnomecal_SOURCES = \ - main.c \ - gnome-cal.c \ - gnome-cal.h \ - views.c \ calendar.c \ calendar.h \ calobj.c \ calobj.h \ - views.h + gncal-week-view.c \ + gncal-week-view.h \ + gncal-day-view.c \ + gncal-day-view.h \ + gnome-cal.c \ + gnome-cal.h \ + main.c \ + timeutil.c \ + timeutil.h \ + view-utils.h \ + view-utils.c \ + views.h \ + views.c #gncal_SOURCES = \ diff --git a/calendar/gui/calendar.c b/calendar/gui/calendar.c index e077279461..5d7cb1dd8a 100644 --- a/calendar/gui/calendar.c +++ b/calendar/gui/calendar.c @@ -13,6 +13,7 @@ */ #include "calendar.h" +#include "versit/vcc.h" Calendar * calendar_new (char *title) @@ -28,6 +29,7 @@ calendar_new (char *title) void calendar_add_object (Calendar *cal, iCalObject *obj) { + printf ("Adding object\n"); switch (obj->type){ case ICAL_EVENT: cal->events = g_list_prepend (cal->events, obj); @@ -133,3 +135,56 @@ calendar_compare_by_dtstart (gpointer a, gpointer b) return (diff < 0) ? -1 : (diff > 0) ? 1 : 0; } + +#define str_val(obj) (char *) vObjectUStringZValue (obj) + +/* Loads our calendar contents from a vObject */ +void +calendar_load_from_vobject (Calendar *cal, VObject *vcal) +{ + VObjectIterator i;; + + initPropIterator (&i, vcal); + + while (moreIteration (&i)){ + VObject *this = nextVObject (&i); + iCalObject *ical; + const char *object_name = vObjectName (this); + + if (strcmp (object_name, VCDCreatedProp) == 0){ + cal->created = time_from_isodate (str_val (this)); + continue; + } + + if (strcmp (object_name, VCLocationProp) == 0) + continue; /* FIXME: imlement */ + + if (strcmp (object_name, VCProdIdProp) == 0) + continue; /* FIXME: implement */ + + if (strcmp (object_name, VCVersionProp) == 0) + continue; /* FIXME: implement */ + + ical = ical_object_create_from_vobject (this, object_name); + + if (ical) + calendar_add_object (cal, ical); + } +} + +/* Loads a calendar from a file */ +void +calendar_load (Calendar *cal, char *fname) +{ + VObject *vcal; + + if (cal->filename){ + g_warning ("Calendar load called again\n"); + return; + } + + cal->filename = g_strdup (fname); + vcal = Parse_MIME_FromFileName (fname); + calendar_load_from_vobject (cal, vcal); + cleanVObject (vcal); +} diff --git a/calendar/gui/calendar.h b/calendar/gui/calendar.h index 09242d9b76..805076d949 100644 --- a/calendar/gui/calendar.h +++ b/calendar/gui/calendar.h @@ -12,6 +12,7 @@ typedef struct { GList *todo; GList *journal; + time_t created; int modified; } Calendar; diff --git a/calendar/gui/gnome-cal.c b/calendar/gui/gnome-cal.c index 333931a5a2..0b22a1a684 100644 --- a/calendar/gui/gnome-cal.c +++ b/calendar/gui/gnome-cal.c @@ -39,10 +39,13 @@ setup_widgets (GnomeCalendar *gcal) { GtkWidget *notebook; GtkWidget *day_view, *week_view, *year_view, *task_view; - + time_t now; + + now = time (NULL); + notebook = gtk_notebook_new (); day_view = day_view_create (gcal); - week_view = week_view_create (gcal); + week_view = gncal_week_view_new (gcal->cal, now); year_view = year_view_create (gcal); task_view = tasks_create (gcal); @@ -86,7 +89,7 @@ gnome_calendar_new (char *title) } void -gnome_calendar_load (char *file) +gnome_calendar_load (GnomeCalendar *gcal, char *file) { - + calendar_load (gcal->cal, file); } diff --git a/calendar/gui/gnome-cal.h b/calendar/gui/gnome-cal.h index 840ccf5122..2b30bf1f7c 100644 --- a/calendar/gui/gnome-cal.h +++ b/calendar/gui/gnome-cal.h @@ -28,7 +28,7 @@ typedef struct { guint gnome_calendar_get_type (void); GtkWidget *gnome_calendar_new (char *title); -void gnome_calendar_load (char *file); +void gnome_calendar_load (GnomeCalendar *gcal, char *file); END_GNOME_DECLS diff --git a/calendar/gui/main.c b/calendar/gui/main.c index 941efe1c2b..be54ba2d81 100644 --- a/calendar/gui/main.c +++ b/calendar/gui/main.c @@ -173,10 +173,25 @@ GnomeUIInfo gnome_cal_menu [] = { GNOMEUIINFO_END }; +GnomeUIInfo gnome_toolbar [] = { + { GNOME_APP_UI_ITEM, N_("Prev"), N_("Previous"), /*previous_clicked*/0, 0, 0, + GNOME_APP_PIXMAP_STOCK, GNOME_STOCK_MENU_BACK }, + + { GNOME_APP_UI_ITEM, N_("Today"), N_("Today"), /*previous_clicked*/0, 0, 0, + GNOME_APP_PIXMAP_STOCK, GNOME_STOCK_MENU_BACK }, + + { GNOME_APP_UI_ITEM, N_("Next"), N_("Next"), /*previous_clicked*/0, 0, 0, + GNOME_APP_PIXMAP_STOCK, GNOME_STOCK_MENU_FORWARD }, + + GNOMEUIINFO_END +}; + static void setup_menu (GtkWidget *gcal) { gnome_app_create_menus_with_data (GNOME_APP (gcal), gnome_cal_menu, gcal); + gnome_app_create_toolbar_with_data (GNOME_APP (gcal), gnome_toolbar, gcal); + } static void @@ -191,8 +206,13 @@ new_calendar (char *full_name, char *calendar_file) setup_menu (toplevel); gtk_widget_show (toplevel); - if (g_file_exists (calendar_file)) - gnome_calendar_load (calendar_file); + if (g_file_exists (calendar_file)){ + printf ("Trying to load %s\n", calendar_file); + gnome_calendar_load (GNOME_CALENDAR (toplevel), calendar_file); + } else { + printf ("tring: ./test.vcf\n"); + gnome_calendar_load (GNOME_CALENDAR (toplevel), "./test.vcf"); + } active_calendars++; } diff --git a/calendar/main.c b/calendar/main.c index 941efe1c2b..be54ba2d81 100644 --- a/calendar/main.c +++ b/calendar/main.c @@ -173,10 +173,25 @@ GnomeUIInfo gnome_cal_menu [] = { GNOMEUIINFO_END }; +GnomeUIInfo gnome_toolbar [] = { + { GNOME_APP_UI_ITEM, N_("Prev"), N_("Previous"), /*previous_clicked*/0, 0, 0, + GNOME_APP_PIXMAP_STOCK, GNOME_STOCK_MENU_BACK }, + + { GNOME_APP_UI_ITEM, N_("Today"), N_("Today"), /*previous_clicked*/0, 0, 0, + GNOME_APP_PIXMAP_STOCK, GNOME_STOCK_MENU_BACK }, + + { GNOME_APP_UI_ITEM, N_("Next"), N_("Next"), /*previous_clicked*/0, 0, 0, + GNOME_APP_PIXMAP_STOCK, GNOME_STOCK_MENU_FORWARD }, + + GNOMEUIINFO_END +}; + static void setup_menu (GtkWidget *gcal) { gnome_app_create_menus_with_data (GNOME_APP (gcal), gnome_cal_menu, gcal); + gnome_app_create_toolbar_with_data (GNOME_APP (gcal), gnome_toolbar, gcal); + } static void @@ -191,8 +206,13 @@ new_calendar (char *full_name, char *calendar_file) setup_menu (toplevel); gtk_widget_show (toplevel); - if (g_file_exists (calendar_file)) - gnome_calendar_load (calendar_file); + if (g_file_exists (calendar_file)){ + printf ("Trying to load %s\n", calendar_file); + gnome_calendar_load (GNOME_CALENDAR (toplevel), calendar_file); + } else { + printf ("tring: ./test.vcf\n"); + gnome_calendar_load (GNOME_CALENDAR (toplevel), "./test.vcf"); + } active_calendars++; } diff --git a/calendar/pcs/calobj.c b/calendar/pcs/calobj.c index fcdfb7e59d..2f4647548f 100644 --- a/calendar/pcs/calobj.c +++ b/calendar/pcs/calobj.c @@ -6,7 +6,10 @@ * Miguel de Icaza (miguel@gnu.org) * Federico Mena (federico@gimp.org) */ +#include +#include #include "calobj.h" +#include "versit/vcc.h" iCalObject * ical_object_new (void) @@ -46,3 +49,168 @@ ical_object_destroy (iCalObject *ico) g_free (ico); } + +GList * +set_list (char *str, char *sc) +{ + GList *list = 0; + char *s; + + for (s = strtok (str, sc); s; s = strtok (NULL, sc)) + list = g_list_prepend (list, g_strdup (s)); + + return list; +} + +#define is_a_prop_of(obj,prop) isAPropertyOf (obj,prop) +#define str_val(obj) (char *) vObjectUStringZValue (obj) +#define has(obj,prop) (vo = isAPropertyOf (obj, prop)) + +/* FIXME: we need to load the recurrence properties */ +iCalObject * +ical_object_create_from_vobject (VObject *o, const char *object_name) +{ + time_t now = time (NULL); + iCalObject *ical; + VObject *vo; + VObjectIterator i; + + ical = g_new0 (iCalObject, 1); + + if (strcmp (object_name, VCEventProp) == 0) + ical->type = ICAL_EVENT; + else if (strcmp (object_name, VCTodoProp) == 0) + ical->type = ICAL_TODO; + else + return 0; + /* uid */ + if (has (o, VCUniqueStringProp)) + ical->uid = g_strdup (str_val (vo)); + + /* seq */ + if (has (o, VCSequenceProp)) + ical->seq = atoi (str_val (vo)); + else + ical->seq = 0; + + /* dtstart */ + if (has (o, VCDTstartProp)) + ical->dtstart = time_from_isodate (str_val (vo)); + else + ical->dtstart = 0; + + /* dtend */ + if (has (o, VCDTendProp)) + ical->dtend = time_from_isodate (str_val (vo)); + else + ical->dtend = 0; + + /* dcreated */ + if (has (o, VCDCreatedProp)) + ical->created = time_from_isodate (str_val (vo)); + + /* completed */ + if (has (o, VCCompletedProp)) + ical->completed = time_from_isodate (str_val (vo)); + + /* last_mod */ + if (has (o, VCLastModifiedProp)) + ical->last_mod = time_from_isodate (str_val (vo)); + else + ical->last_mod = now; + + /* exdate */ + if (has (o, VCExpDateProp)) + ical->exdate = set_list (str_val (vo), ","); + + /* description */ + if (has (o, VCDescriptionProp)) + ical->description = g_strdup (str_val (vo)); + + /* summary */ + if (has (o, VCSummaryProp)) + ical->summary = g_strdup (str_val (vo)); + else + ical->summary = g_strdup (""); + + /* status */ + if (has (o, VCStatusProp)) + ical->status = g_strdup (str_val (vo)); + else + ical->status = g_strdup ("NEEDS ACTION"); + + if (has (o, VCClassProp)) + ical->class = g_strdup (str_val (vo)); + else + ical->status = g_strdup ("PUBLIC"); + + /* categories */ + if (has (o, VCCategoriesProp)) + ical->categories = set_list (str_val (vo), ","); + + /* resources */ + if (has (o, VCResourcesProp)) + ical->resources = set_list (str_val (vo), ";"); + + /* priority */ + if (has (o, VCPriorityProp)) + ical->priority = atoi (str_val (vo)); + + /* tranparency */ + if (has (o, VCTranspProp)) + ical->transp = atoi (str_val (vo)) ? ICAL_TRANSPARENT : ICAL_OPAQUE; + + /* related */ + if (has (o, VCRelatedToProp)) + ical->related = set_list (str_val (vo), ";"); + + /* attach */ + initPropIterator (&i, o); + while (moreIteration (&i)){ + vo = nextVObject (&i); + if (strcmp (vObjectName (vo), VCAttachProp) == 0) + ical->attach = g_list_prepend (ical->attach, g_strdup (str_val (vo))); + } + + /* url */ + if (has (o, VCURLProp)) + ical->url = g_strdup (str_val (vo)); + + /* FIXME: dalarm */ + if (has (o, VCDAlarmProp)) + ; + + /* FIXME: aalarm */ + if (has (o, VCAAlarmProp)) + ; + + /* FIXME: palarm */ + if (has (o, VCPAlarmProp)) + ; + + /* FIXME: malarm */ + if (has (o, VCMAlarmProp)) + ; + + /* FIXME: rdate */ + if (has (o, VCRDateProp)) + ; + + /* FIXME: rrule */ + if (has (o, VCRRuleProp)) + ; + + return ical; +} + +void +ical_object_save (iCalObject *ical) +{ + VObject *o; + + if (ical->type == ICAL_EVENT) + o = newVObject (VCEventProp); + else + o = newVObject (VCTodoProp); +} + diff --git a/calendar/pcs/calobj.h b/calendar/pcs/calobj.h index d5f6db0ae0..85f88dccd9 100644 --- a/calendar/pcs/calobj.h +++ b/calendar/pcs/calobj.h @@ -8,6 +8,7 @@ #define CALOBJ_H #include +#include "versit/vcc.h" BEGIN_GNOME_DECLS @@ -89,14 +90,16 @@ typedef struct { char *url; time_t recurid; - /* VALARM objects are always inside another object, never alone */ - CalendarAlarm *alarm; + CalendarAlarm *dalarm; + CalendarAlarm *aalarm; } iCalObject; iCalObject *ical_new (char *comment, char *organizer, char *summary); iCalObject *ical_object_new (void); void ical_object_destroy (iCalObject *ico); +iCalObject *ical_object_create_from_vobject (VObject *obj, const char *object_name); END_GNOME_DECLS #endif + diff --git a/calendar/timeutil.c b/calendar/timeutil.c index c9e574fbfd..7957751049 100644 --- a/calendar/timeutil.c +++ b/calendar/timeutil.c @@ -29,6 +29,17 @@ time_from_isodate (char *str) return mktime (&my_tm); } +char * +isodate_from_time_t (time_t t) +{ + struct tm *tm; + static char isotime [40]; + + tm = localtime (&t); + strftime (isotime, sizeof (isotime)-1, "%Y%m%dT%H%M%sZ", tm); + return &isotime; +} + time_t time_from_start_duration (time_t start, char *duration) { diff --git a/calendar/timeutil.h b/calendar/timeutil.h index 4f062b8923..d33b65470b 100644 --- a/calendar/timeutil.h +++ b/calendar/timeutil.h @@ -15,6 +15,7 @@ time_t time_from_isodate (char *str); time_t time_from_start_duration (time_t start, char *duration); +char *isodate_from_time_t (time_t t); /* Returns pointer to a statically-allocated buffer with a string of the form * 3am, 4am, 12pm, 08h, 17h, etc. -- cgit v1.2.3