aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--calendar/ChangeLog4
-rw-r--r--calendar/cal-util/calobj.c18
-rw-r--r--calendar/cal-util/calobj.h12
-rw-r--r--calendar/calendar.c6
-rw-r--r--calendar/calendar.h12
-rw-r--r--calendar/calobj.c18
-rw-r--r--calendar/calobj.h12
-rw-r--r--calendar/gnome-cal.c5
-rw-r--r--calendar/gui/calendar.c6
-rw-r--r--calendar/gui/calendar.h12
-rw-r--r--calendar/gui/gnome-cal.c5
-rw-r--r--calendar/gui/year-view.c57
-rw-r--r--calendar/gui/year-view.h8
-rw-r--r--calendar/pcs/calobj.c18
-rw-r--r--calendar/pcs/calobj.h12
-rw-r--r--calendar/timeutil.c35
-rw-r--r--calendar/year-view.c57
-rw-r--r--calendar/year-view.h8
18 files changed, 260 insertions, 45 deletions
diff --git a/calendar/ChangeLog b/calendar/ChangeLog
index 28eaf35f8d..03e9cfc784 100644
--- a/calendar/ChangeLog
+++ b/calendar/ChangeLog
@@ -1,3 +1,7 @@
+1998-04-15 Miguel de Icaza <miguel@nuclecu.unam.mx>
+
+ * calobj.c (ical_foreach): Define iterator routine.
+
1998-04-15 Arturo Espinosa Aldama <arturo@nuclecu.unam.mx>
* gncal-year-view.[hc]: Now using time_t for new and set.
diff --git a/calendar/cal-util/calobj.c b/calendar/cal-util/calobj.c
index f02feaf7a1..7e5f535189 100644
--- a/calendar/cal-util/calobj.c
+++ b/calendar/cal-util/calobj.c
@@ -99,7 +99,13 @@ ical_object_destroy (iCalObject *ico)
lfree_if_defined (ico->resources);
lfree_if_defined (ico->related);
lfree_if_defined (ico->attach);
-
+
+ /* Alarms */
+ g_free (ico->dalarm.data);
+ g_free (ico->palarm.data);
+ g_free (ico->malarm.data);
+ g_free (ico->aalarm.data);
+
g_free (ico);
}
@@ -670,3 +676,13 @@ ical_object_to_vobject (iCalObject *ical)
/* FIXME: alarms */
return o;
}
+
+void
+ical_foreach (GList *events, iCalObjectFn fn, void *closure)
+{
+ for (; events; events = events->next){
+ iCalObject *ical = events->data;
+
+ (*fn) (ical, ical->dtstart, ical->dtend, closure);
+ }
+}
diff --git a/calendar/cal-util/calobj.h b/calendar/cal-util/calobj.h
index 9287332d40..8f7abf8871 100644
--- a/calendar/cal-util/calobj.h
+++ b/calendar/cal-util/calobj.h
@@ -153,11 +153,15 @@ typedef struct {
int new;
} iCalObject;
-iCalObject *ical_new (char *comment, char *organizer, char *summary);
-iCalObject *ical_object_new (void);
-void ical_object_destroy (iCalObject *ico);
+/* The callback for the recurrence generator */
+typedef void (*iCalObjectFn)(iCalObject *, time_t, time_t, void *);
+
+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);
-VObject *ical_object_to_vobject (iCalObject *ical);
+VObject *ical_object_to_vobject (iCalObject *ical);
+void ical_foreach (GList *events, iCalObjectFn fn, void *closure);
END_GNOME_DECLS
diff --git a/calendar/calendar.c b/calendar/calendar.c
index ebece3aadc..9f9ef4dc51 100644
--- a/calendar/calendar.c
+++ b/calendar/calendar.c
@@ -36,6 +36,8 @@ calendar_add_object (Calendar *cal, iCalObject *obj)
switch (obj->type){
case ICAL_EVENT:
cal->events = g_list_prepend (cal->events, obj);
+ if (obj->recur)
+ cal->recur = g_list_prepend (cal->recur, obj);
break;
case ICAL_TODO:
@@ -60,6 +62,8 @@ calendar_remove_object (Calendar *cal, iCalObject *obj)
switch (obj->type){
case ICAL_EVENT:
cal->events = g_list_remove (cal->events, obj);
+ if (obj->recur)
+ cal->recur = g_list_remove (cal->recur, obj);
break;
case ICAL_TODO:
@@ -107,7 +111,7 @@ ice (time_t t)
return buffer;
}
-static GList *
+GList *
calendar_get_objects_in_range (GList *objects, time_t start, time_t end, GCompareFunc sort_func)
{
GList *new_events = 0;
diff --git a/calendar/calendar.h b/calendar/calendar.h
index f93946315c..a59fec7544 100644
--- a/calendar/calendar.h
+++ b/calendar/calendar.h
@@ -6,13 +6,24 @@
BEGIN_GNOME_DECLS
typedef struct {
+ /* This calendar's title */
char *title;
+
+ /* backing store for this calendar object */
char *filename;
+
+ /* The list of events; todo's and journal entries */
GList *events;
GList *todo;
GList *journal;
+ /* Events that have a recurrence field are also present here */
+ GList *recur;
+
+ /* Time at which the calendar was created */
time_t created;
+
+ /* If the calendar was last modified */
int modified;
void *temp;
} Calendar;
@@ -23,6 +34,7 @@ void calendar_add_object (Calendar *cal, iCalObject *obj);
void calendar_remove_object (Calendar *cal, iCalObject *obj);
void calendar_destroy (Calendar *cal);
GList *calendar_get_events_in_range (Calendar *cal, time_t start, time_t end, GCompareFunc sort_func);
+GList *calendar_get_objects_in_range (GList *objects, time_t start, time_t end, GCompareFunc sort_func);
GList *calendar_get_todo_in_range (Calendar *cal, time_t start, time_t end, GCompareFunc sort_func);
GList *calendar_get_journal_in_range (Calendar *cal, time_t start, time_t end, GCompareFunc sort_func);
gint calendar_compare_by_dtstart (gpointer a, gpointer b);
diff --git a/calendar/calobj.c b/calendar/calobj.c
index f02feaf7a1..7e5f535189 100644
--- a/calendar/calobj.c
+++ b/calendar/calobj.c
@@ -99,7 +99,13 @@ ical_object_destroy (iCalObject *ico)
lfree_if_defined (ico->resources);
lfree_if_defined (ico->related);
lfree_if_defined (ico->attach);
-
+
+ /* Alarms */
+ g_free (ico->dalarm.data);
+ g_free (ico->palarm.data);
+ g_free (ico->malarm.data);
+ g_free (ico->aalarm.data);
+
g_free (ico);
}
@@ -670,3 +676,13 @@ ical_object_to_vobject (iCalObject *ical)
/* FIXME: alarms */
return o;
}
+
+void
+ical_foreach (GList *events, iCalObjectFn fn, void *closure)
+{
+ for (; events; events = events->next){
+ iCalObject *ical = events->data;
+
+ (*fn) (ical, ical->dtstart, ical->dtend, closure);
+ }
+}
diff --git a/calendar/calobj.h b/calendar/calobj.h
index 9287332d40..8f7abf8871 100644
--- a/calendar/calobj.h
+++ b/calendar/calobj.h
@@ -153,11 +153,15 @@ typedef struct {
int new;
} iCalObject;
-iCalObject *ical_new (char *comment, char *organizer, char *summary);
-iCalObject *ical_object_new (void);
-void ical_object_destroy (iCalObject *ico);
+/* The callback for the recurrence generator */
+typedef void (*iCalObjectFn)(iCalObject *, time_t, time_t, void *);
+
+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);
-VObject *ical_object_to_vobject (iCalObject *ical);
+VObject *ical_object_to_vobject (iCalObject *ical);
+void ical_foreach (GList *events, iCalObjectFn fn, void *closure);
END_GNOME_DECLS
diff --git a/calendar/gnome-cal.c b/calendar/gnome-cal.c
index 6be4eb3f1e..e38f818c49 100644
--- a/calendar/gnome-cal.c
+++ b/calendar/gnome-cal.c
@@ -83,7 +83,7 @@ setup_widgets (GnomeCalendar *gcal)
gcal->notebook = gtk_notebook_new ();
gcal->week_view = gncal_week_view_new (gcal, now);
- gcal->year_view = gncal_year_view_new (now);
+ gcal->year_view = gncal_year_view_new (gcal, now);
gcal->task_view = tasks_create (gcal);
setup_day_view (gcal);
@@ -190,8 +190,9 @@ gnome_calendar_new (char *title)
static void
gnome_calendar_update_all (GnomeCalendar *cal, iCalObject *object, int flags)
{
- gncal_full_day_update (GNCAL_FULL_DAY (cal->day_view), object, flags);
+ gncal_full_day_update (GNCAL_FULL_DAY (cal->day_view), object, flags);
gncal_week_view_update (GNCAL_WEEK_VIEW (cal->week_view), object, flags);
+ gncal_year_view_update (GNCAL_YEAR_VIEW (cal->year_view), object, flags);
}
void
diff --git a/calendar/gui/calendar.c b/calendar/gui/calendar.c
index ebece3aadc..9f9ef4dc51 100644
--- a/calendar/gui/calendar.c
+++ b/calendar/gui/calendar.c
@@ -36,6 +36,8 @@ calendar_add_object (Calendar *cal, iCalObject *obj)
switch (obj->type){
case ICAL_EVENT:
cal->events = g_list_prepend (cal->events, obj);
+ if (obj->recur)
+ cal->recur = g_list_prepend (cal->recur, obj);
break;
case ICAL_TODO:
@@ -60,6 +62,8 @@ calendar_remove_object (Calendar *cal, iCalObject *obj)
switch (obj->type){
case ICAL_EVENT:
cal->events = g_list_remove (cal->events, obj);
+ if (obj->recur)
+ cal->recur = g_list_remove (cal->recur, obj);
break;
case ICAL_TODO:
@@ -107,7 +111,7 @@ ice (time_t t)
return buffer;
}
-static GList *
+GList *
calendar_get_objects_in_range (GList *objects, time_t start, time_t end, GCompareFunc sort_func)
{
GList *new_events = 0;
diff --git a/calendar/gui/calendar.h b/calendar/gui/calendar.h
index f93946315c..a59fec7544 100644
--- a/calendar/gui/calendar.h
+++ b/calendar/gui/calendar.h
@@ -6,13 +6,24 @@
BEGIN_GNOME_DECLS
typedef struct {
+ /* This calendar's title */
char *title;
+
+ /* backing store for this calendar object */
char *filename;
+
+ /* The list of events; todo's and journal entries */
GList *events;
GList *todo;
GList *journal;
+ /* Events that have a recurrence field are also present here */
+ GList *recur;
+
+ /* Time at which the calendar was created */
time_t created;
+
+ /* If the calendar was last modified */
int modified;
void *temp;
} Calendar;
@@ -23,6 +34,7 @@ void calendar_add_object (Calendar *cal, iCalObject *obj);
void calendar_remove_object (Calendar *cal, iCalObject *obj);
void calendar_destroy (Calendar *cal);
GList *calendar_get_events_in_range (Calendar *cal, time_t start, time_t end, GCompareFunc sort_func);
+GList *calendar_get_objects_in_range (GList *objects, time_t start, time_t end, GCompareFunc sort_func);
GList *calendar_get_todo_in_range (Calendar *cal, time_t start, time_t end, GCompareFunc sort_func);
GList *calendar_get_journal_in_range (Calendar *cal, time_t start, time_t end, GCompareFunc sort_func);
gint calendar_compare_by_dtstart (gpointer a, gpointer b);
diff --git a/calendar/gui/gnome-cal.c b/calendar/gui/gnome-cal.c
index 6be4eb3f1e..e38f818c49 100644
--- a/calendar/gui/gnome-cal.c
+++ b/calendar/gui/gnome-cal.c
@@ -83,7 +83,7 @@ setup_widgets (GnomeCalendar *gcal)
gcal->notebook = gtk_notebook_new ();
gcal->week_view = gncal_week_view_new (gcal, now);
- gcal->year_view = gncal_year_view_new (now);
+ gcal->year_view = gncal_year_view_new (gcal, now);
gcal->task_view = tasks_create (gcal);
setup_day_view (gcal);
@@ -190,8 +190,9 @@ gnome_calendar_new (char *title)
static void
gnome_calendar_update_all (GnomeCalendar *cal, iCalObject *object, int flags)
{
- gncal_full_day_update (GNCAL_FULL_DAY (cal->day_view), object, flags);
+ gncal_full_day_update (GNCAL_FULL_DAY (cal->day_view), object, flags);
gncal_week_view_update (GNCAL_WEEK_VIEW (cal->week_view), object, flags);
+ gncal_year_view_update (GNCAL_YEAR_VIEW (cal->year_view), object, flags);
}
void
diff --git a/calendar/gui/year-view.c b/calendar/gui/year-view.c
index c3d6057086..c3db60f28b 100644
--- a/calendar/gui/year-view.c
+++ b/calendar/gui/year-view.c
@@ -72,7 +72,7 @@ gncal_year_view_init (GncalYearView *yview)
}
GtkWidget *
-gncal_year_view_new (time_t date)
+gncal_year_view_new (GnomeCalendar *calendar, time_t date)
{
struct tm my_tm = { 0, 0, 0, 0, 0, 0, 0, 0, 0 };
char monthbuff[40];
@@ -85,7 +85,8 @@ gncal_year_view_new (time_t date)
tmptm = localtime(&date);
yview->year = tmptm->tm_year;
- my_tm.tm_mon = tmptm->tm_year;
+ yview->gcal = calendar;
+ my_tm.tm_year = tmptm->tm_year;
yview->year_label = gtk_label_new("");
gtk_table_attach (GTK_TABLE (yview),
GTK_WIDGET (yview->year_label),
@@ -151,11 +152,51 @@ void gncal_year_view_set (GncalYearView *yview, time_t date)
}
}
-/*void
-gncal_week_view_update (GncalWeekView *wview, iCalObject *ico, int flags)
+static void
+year_view_mark_day (iCalObject *ical, time_t start, time_t end, void *closure)
+{
+ GncalYearView *yview = (GncalYearView *) closure;
+ struct tm *tm_s;
+ int days, day;
+
+ tm_s = localtime (&start);
+ days = difftime (end, start) / (60*60*24);
+
+ for (day = 0; day <= days; day++){
+ time_t new = mktime (tm_s);
+ struct tm *tm_day;
+
+ tm_day = localtime (&new);
+ gtk_calendar_mark_day (GTK_CALENDAR (yview->calendar [tm_day->tm_mon]),
+ tm_day->tm_mday);
+ tm_s->tm_mday++;
+ }
+}
+
+void
+gncal_year_view_update (GncalYearView *yview, iCalObject *ico, int flags)
{
- g_return_if_fail (wview != NULL);
- g_return_if_fail (GNCAL_IS_YEAR_VIEW (wview));
+ g_return_if_fail (yview != NULL);
+ g_return_if_fail (GNCAL_IS_YEAR_VIEW (yview));
+
+ /* If only the summary changed, we dont care */
+ if ((flags & CHANGE_SUMMARY) == flags)
+ return;
+
+ if (flags & CHANGE_NEW){
+ time_t year_begin, year_end;
+ GList *l, *nl;
+
+ year_begin = time_year_begin (yview->year);
+ year_end = time_year_end (yview->year);
+
+ l = g_list_append (NULL, ico);
+ nl = calendar_get_objects_in_range (l, year_begin, year_end, NULL);
+ if (nl){
+ ical_foreach (nl, year_view_mark_day, yview);
+ g_list_free (nl);
+ }
+ g_list_free (l);
+ }
+}
- update (wview, TRUE, ico, flags);
-}*/
diff --git a/calendar/gui/year-view.h b/calendar/gui/year-view.h
index bdd542abda..828678f56d 100644
--- a/calendar/gui/year-view.h
+++ b/calendar/gui/year-view.h
@@ -33,7 +33,8 @@ typedef struct _GncalYearViewClass GncalYearViewClass;
struct _GncalYearView {
GtkTable table;
- GtkWidget *calendar[12]; /* one calendar per month */
+ GnomeCalendar *gcal; /* The calendar we are associated to */
+ GtkWidget *calendar[12]; /* one calendar per month */
guint handler[12]; /* for (un)blocking the calendars */
GtkWidget *year_label;
@@ -46,9 +47,8 @@ struct _GncalYearViewClass {
guint gncal_year_view_get_type (void);
-GtkWidget *gncal_year_view_new (time_t date);
-
-void gncal_year_view_set (GncalYearView *yview, time_t date);
+GtkWidget *gncal_year_view_new (GnomeCalendar *calendar, time_t date);
+void gncal_year_view_set (GncalYearView *yview, time_t date);
END_GNOME_DECLS
diff --git a/calendar/pcs/calobj.c b/calendar/pcs/calobj.c
index f02feaf7a1..7e5f535189 100644
--- a/calendar/pcs/calobj.c
+++ b/calendar/pcs/calobj.c
@@ -99,7 +99,13 @@ ical_object_destroy (iCalObject *ico)
lfree_if_defined (ico->resources);
lfree_if_defined (ico->related);
lfree_if_defined (ico->attach);
-
+
+ /* Alarms */
+ g_free (ico->dalarm.data);
+ g_free (ico->palarm.data);
+ g_free (ico->malarm.data);
+ g_free (ico->aalarm.data);
+
g_free (ico);
}
@@ -670,3 +676,13 @@ ical_object_to_vobject (iCalObject *ical)
/* FIXME: alarms */
return o;
}
+
+void
+ical_foreach (GList *events, iCalObjectFn fn, void *closure)
+{
+ for (; events; events = events->next){
+ iCalObject *ical = events->data;
+
+ (*fn) (ical, ical->dtstart, ical->dtend, closure);
+ }
+}
diff --git a/calendar/pcs/calobj.h b/calendar/pcs/calobj.h
index 9287332d40..8f7abf8871 100644
--- a/calendar/pcs/calobj.h
+++ b/calendar/pcs/calobj.h
@@ -153,11 +153,15 @@ typedef struct {
int new;
} iCalObject;
-iCalObject *ical_new (char *comment, char *organizer, char *summary);
-iCalObject *ical_object_new (void);
-void ical_object_destroy (iCalObject *ico);
+/* The callback for the recurrence generator */
+typedef void (*iCalObjectFn)(iCalObject *, time_t, time_t, void *);
+
+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);
-VObject *ical_object_to_vobject (iCalObject *ical);
+VObject *ical_object_to_vobject (iCalObject *ical);
+void ical_foreach (GList *events, iCalObjectFn fn, void *closure);
END_GNOME_DECLS
diff --git a/calendar/timeutil.c b/calendar/timeutil.c
index c19b394be9..63b78a4152 100644
--- a/calendar/timeutil.c
+++ b/calendar/timeutil.c
@@ -165,3 +165,38 @@ time_end_of_day (time_t t)
return retval;
}
+time_t
+time_year_begin (int year)
+{
+ struct tm tm;
+ time_t retval;
+
+ tm.tm_hour = 0;
+ tm.tm_min = 0;
+ tm.tm_sec = 0;
+ tm.tm_year = year;
+ tm.tm_mon = 0;
+ tm.tm_mday = 1;
+ tm.tm_isdst = -1;
+
+ retval = mktime (&tm);
+ return retval;
+}
+
+time_t
+time_year_end (int year)
+{
+ struct tm tm;
+ time_t retval;
+
+ tm.tm_hour = 23;
+ tm.tm_min = 59;
+ tm.tm_sec = 59;
+ tm.tm_year = year;
+ tm.tm_mon = 11;
+ tm.tm_mday = 31;
+ tm.tm_isdst = -1;
+
+ retval = mktime (&tm);
+ return retval;
+}
diff --git a/calendar/year-view.c b/calendar/year-view.c
index c3d6057086..c3db60f28b 100644
--- a/calendar/year-view.c
+++ b/calendar/year-view.c
@@ -72,7 +72,7 @@ gncal_year_view_init (GncalYearView *yview)
}
GtkWidget *
-gncal_year_view_new (time_t date)
+gncal_year_view_new (GnomeCalendar *calendar, time_t date)
{
struct tm my_tm = { 0, 0, 0, 0, 0, 0, 0, 0, 0 };
char monthbuff[40];
@@ -85,7 +85,8 @@ gncal_year_view_new (time_t date)
tmptm = localtime(&date);
yview->year = tmptm->tm_year;
- my_tm.tm_mon = tmptm->tm_year;
+ yview->gcal = calendar;
+ my_tm.tm_year = tmptm->tm_year;
yview->year_label = gtk_label_new("");
gtk_table_attach (GTK_TABLE (yview),
GTK_WIDGET (yview->year_label),
@@ -151,11 +152,51 @@ void gncal_year_view_set (GncalYearView *yview, time_t date)
}
}
-/*void
-gncal_week_view_update (GncalWeekView *wview, iCalObject *ico, int flags)
+static void
+year_view_mark_day (iCalObject *ical, time_t start, time_t end, void *closure)
+{
+ GncalYearView *yview = (GncalYearView *) closure;
+ struct tm *tm_s;
+ int days, day;
+
+ tm_s = localtime (&start);
+ days = difftime (end, start) / (60*60*24);
+
+ for (day = 0; day <= days; day++){
+ time_t new = mktime (tm_s);
+ struct tm *tm_day;
+
+ tm_day = localtime (&new);
+ gtk_calendar_mark_day (GTK_CALENDAR (yview->calendar [tm_day->tm_mon]),
+ tm_day->tm_mday);
+ tm_s->tm_mday++;
+ }
+}
+
+void
+gncal_year_view_update (GncalYearView *yview, iCalObject *ico, int flags)
{
- g_return_if_fail (wview != NULL);
- g_return_if_fail (GNCAL_IS_YEAR_VIEW (wview));
+ g_return_if_fail (yview != NULL);
+ g_return_if_fail (GNCAL_IS_YEAR_VIEW (yview));
+
+ /* If only the summary changed, we dont care */
+ if ((flags & CHANGE_SUMMARY) == flags)
+ return;
+
+ if (flags & CHANGE_NEW){
+ time_t year_begin, year_end;
+ GList *l, *nl;
+
+ year_begin = time_year_begin (yview->year);
+ year_end = time_year_end (yview->year);
+
+ l = g_list_append (NULL, ico);
+ nl = calendar_get_objects_in_range (l, year_begin, year_end, NULL);
+ if (nl){
+ ical_foreach (nl, year_view_mark_day, yview);
+ g_list_free (nl);
+ }
+ g_list_free (l);
+ }
+}
- update (wview, TRUE, ico, flags);
-}*/
diff --git a/calendar/year-view.h b/calendar/year-view.h
index bdd542abda..828678f56d 100644
--- a/calendar/year-view.h
+++ b/calendar/year-view.h
@@ -33,7 +33,8 @@ typedef struct _GncalYearViewClass GncalYearViewClass;
struct _GncalYearView {
GtkTable table;
- GtkWidget *calendar[12]; /* one calendar per month */
+ GnomeCalendar *gcal; /* The calendar we are associated to */
+ GtkWidget *calendar[12]; /* one calendar per month */
guint handler[12]; /* for (un)blocking the calendars */
GtkWidget *year_label;
@@ -46,9 +47,8 @@ struct _GncalYearViewClass {
guint gncal_year_view_get_type (void);
-GtkWidget *gncal_year_view_new (time_t date);
-
-void gncal_year_view_set (GncalYearView *yview, time_t date);
+GtkWidget *gncal_year_view_new (GnomeCalendar *calendar, time_t date);
+void gncal_year_view_set (GncalYearView *yview, time_t date);
END_GNOME_DECLS