aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorFederico Mena Quintero <federico@nuclecu.unam.mx>1998-08-30 09:29:19 +0800
committerArturo Espinosa <unammx@src.gnome.org>1998-08-30 09:29:19 +0800
commite0d99122ab17d9bf356cf793b41aec6b6d6016b1 (patch)
treeb2f202ce6ea0b927a8fa4929034c84af223ef782
parent9b6991077bd564348e9dd229ca523bdaa8239ed1 (diff)
downloadgsoc2013-evolution-e0d99122ab17d9bf356cf793b41aec6b6d6016b1.tar.gz
gsoc2013-evolution-e0d99122ab17d9bf356cf793b41aec6b6d6016b1.tar.zst
gsoc2013-evolution-e0d99122ab17d9bf356cf793b41aec6b6d6016b1.zip
Centralized marking of month items. We now have a little utility function
Centralized marking of month items. We now have a little utility function to colorify the days in a month item that have events scheduled for them. This is currently used by the year view and the go-to dialog. Fixed buglets here and there. 1998-08-29 Federico Mena Quintero <federico@nuclecu.unam.mx> * mark.[ch]: New files with utility functions to mark calendars with their events. * mark.c (mark_month_item): New public function to mark a month item with events. (unmark_month_item): New public function to unmark all the days in a month item to their default appearance. * year-view.c (year_view_set): Use the new unmark_month_item() and mark_month_item() to mark the months with events. * goto.c (update): New function that updates the calendar in the Go-to dialog by marking the days. * timeutil.c (time_year_begin): Modified to take a time_t value. (time_year_end): Likewise. (time_month_begin): Actually implemented this function, which was in the header file but not here. (time_days_in_month): New public function that returns the number of days in a month. * Makefile.am (gnomecal_SOURCES): Added mark.[ch] to the sources. * year-view.c (unmark_days): Use unmark_month_item(). * gncal-full-day.c (gncal_full_day_destroy): Fixed crash when destroying the full day view. The full day's destroy method is unusual in that it destroys the list of child widgets itself, as it does not have a remove method, so it needs to reset the list to NULL. svn path=/trunk/; revision=351
-rw-r--r--calendar/ChangeLog33
-rw-r--r--calendar/Makefile.am2
-rw-r--r--calendar/TODO3
-rw-r--r--calendar/gncal-full-day.c2
-rw-r--r--calendar/gnome-month-item.c4
-rw-r--r--calendar/goto.c39
-rw-r--r--calendar/gui/Makefile.am2
-rw-r--r--calendar/gui/gncal-full-day.c2
-rw-r--r--calendar/gui/gnome-month-item.c4
-rw-r--r--calendar/gui/goto.c39
-rw-r--r--calendar/gui/year-view.c113
-rw-r--r--calendar/timeutil.c74
-rw-r--r--calendar/timeutil.h37
-rw-r--r--calendar/year-view.c113
14 files changed, 178 insertions, 289 deletions
diff --git a/calendar/ChangeLog b/calendar/ChangeLog
index 174de9483f..e818feb341 100644
--- a/calendar/ChangeLog
+++ b/calendar/ChangeLog
@@ -1,3 +1,36 @@
+1998-08-29 Federico Mena Quintero <federico@nuclecu.unam.mx>
+
+ * mark.[ch]: New files with utility functions to mark calendars
+ with their events.
+
+ * mark.c (mark_month_item): New public function to mark a month
+ item with events.
+ (unmark_month_item): New public function to unmark all the days in
+ a month item to their default appearance.
+
+ * year-view.c (year_view_set): Use the new unmark_month_item() and
+ mark_month_item() to mark the months with events.
+
+ * goto.c (update): New function that updates the calendar in the
+ Go-to dialog by marking the days.
+
+ * timeutil.c (time_year_begin): Modified to take a time_t value.
+ (time_year_end): Likewise.
+ (time_month_begin): Actually implemented this function, which was
+ in the header file but not here.
+ (time_days_in_month): New public function that returns the number
+ of days in a month.
+
+ * Makefile.am (gnomecal_SOURCES): Added mark.[ch] to the sources.
+
+ * year-view.c (unmark_days): Use unmark_month_item().
+
+ * gncal-full-day.c (gncal_full_day_destroy): Fixed crash when
+ destroying the full day view. The full day's destroy method is
+ unusual in that it destroys the list of child widgets itself, as
+ it does not have a remove method, so it needs to reset the list to
+ NULL.
+
1998-08-27 Federico Mena Quintero <federico@nuclecu.unam.mx>
* gnome-month-item.c (build_month): Now does the correct thing
diff --git a/calendar/Makefile.am b/calendar/Makefile.am
index dfd034e433..9e4163c932 100644
--- a/calendar/Makefile.am
+++ b/calendar/Makefile.am
@@ -38,6 +38,8 @@ gnomecal_SOURCES = \
goto.c \
main.c \
main.h \
+ mark.c \
+ mark.h \
month-view.c \
month-view.h \
popup-menu.c \
diff --git a/calendar/TODO b/calendar/TODO
index 11ce1d577a..7ea072b486 100644
--- a/calendar/TODO
+++ b/calendar/TODO
@@ -1,5 +1,8 @@
BUGS:
+- Goto dialog: fix recoloring of marked days when a LeaveNotify event
+ is gotten for an item.
+
- Recurrence end date is wrong. An event that repeats daily will not
be included in the ending date of the recurrence (off-by-one error?).
diff --git a/calendar/gncal-full-day.c b/calendar/gncal-full-day.c
index 64e5ec6ef4..ecc2a0d0cb 100644
--- a/calendar/gncal-full-day.c
+++ b/calendar/gncal-full-day.c
@@ -1028,6 +1028,8 @@ gncal_full_day_destroy (GtkObject *object)
}
g_list_free (fullday->children);
+ fullday->children = NULL;
+
g_free (fullday->drag_info);
if (GTK_OBJECT_CLASS (parent_class)->destroy)
diff --git a/calendar/gnome-month-item.c b/calendar/gnome-month-item.c
index eb0c5eb469..289664e535 100644
--- a/calendar/gnome-month-item.c
+++ b/calendar/gnome-month-item.c
@@ -15,7 +15,7 @@
/* Number of days in a month, for normal and leap years */
-static int days_in_month[2][12] = {
+static const int days_in_month[2][12] = {
{ 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 },
{ 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 }
};
@@ -23,7 +23,7 @@ static int days_in_month[2][12] = {
/* The weird month of September 1752, where 3 Sep through 13 Sep were eliminated due to the
* Gregorian reformation.
*/
-static int sept_1752[42] = {
+static const int sept_1752[42] = {
0, 0, 1, 2, 14, 15, 16,
17, 18, 19, 20, 21, 22, 23,
24, 25, 26, 27, 28, 29, 30,
diff --git a/calendar/goto.c b/calendar/goto.c
index c3ac3a157e..c312189ce7 100644
--- a/calendar/goto.c
+++ b/calendar/goto.c
@@ -10,38 +10,21 @@
#include "gnome-cal.h"
#include "gnome-month-item.h"
#include "main.h"
+#include "mark.h"
#include "timeutil.h"
+/* Updates the specified month item by marking it appropriately from the calendar the dialog refers
+ * to. */
static void
-highlight_current_day (GnomeMonthItem *mitem)
+update (GnomeMonthItem *mitem, GtkWidget *dialog)
{
- struct tm *tm;
- time_t t;
- GnomeCanvasItem *label;
- int i;
-
- t = time (NULL);
- tm = localtime (&t);
-
- /* First clear all the days to normal */
-
- for (i = 0; i < 42; i++) {
- label = gnome_month_item_num2child (mitem, i + GNOME_MONTH_ITEM_DAY_LABEL);
- gnome_canvas_item_set (label,
- "fill_color", "black",
- NULL);
- }
+ GnomeCalendar *gcal;
- /* Highlight the current day, if appropriate */
+ gcal = GNOME_CALENDAR (gtk_object_get_data (GTK_OBJECT (dialog), "gnome_calendar"));
- if ((mitem->year == (tm->tm_year + 1900)) && (mitem->month == tm->tm_mon)) {
- i = gnome_month_item_day2index (mitem, tm->tm_mday);
- label = gnome_month_item_num2child (mitem, i + GNOME_MONTH_ITEM_DAY_LABEL);
- gnome_canvas_item_set (label,
- "fill_color", "blue",
- NULL);
- }
+ unmark_month_item (mitem);
+ mark_month_item (mitem, gcal->cal);
}
/* Callback used when the year adjustment is changed */
@@ -54,7 +37,7 @@ year_changed (GtkAdjustment *adj, GtkWidget *dialog)
gnome_canvas_item_set (mitem,
"year", (int) adj->value,
NULL);
- highlight_current_day (GNOME_MONTH_ITEM (mitem));
+ update (GNOME_MONTH_ITEM (mitem), dialog);
}
/* Creates the year control with its adjustment */
@@ -99,7 +82,7 @@ month_toggled (GtkToggleButton *toggle, gpointer data)
gnome_canvas_item_set (mitem,
"month", GPOINTER_TO_INT (data),
NULL);
- highlight_current_day (GNOME_MONTH_ITEM (mitem));
+ update (GNOME_MONTH_ITEM (mitem), dialog);
}
/* Creates the months control */
@@ -236,7 +219,7 @@ create_days (GtkWidget *dialog, GnomeCalendar *gcal, int day, int month, int yea
"start_on_monday", week_starts_on_monday,
"heading_color", "white",
NULL);
- highlight_current_day (GNOME_MONTH_ITEM (mitem));
+ update (GNOME_MONTH_ITEM (mitem), dialog);
gtk_object_set_data (GTK_OBJECT (dialog), "month_item", mitem);
diff --git a/calendar/gui/Makefile.am b/calendar/gui/Makefile.am
index dfd034e433..9e4163c932 100644
--- a/calendar/gui/Makefile.am
+++ b/calendar/gui/Makefile.am
@@ -38,6 +38,8 @@ gnomecal_SOURCES = \
goto.c \
main.c \
main.h \
+ mark.c \
+ mark.h \
month-view.c \
month-view.h \
popup-menu.c \
diff --git a/calendar/gui/gncal-full-day.c b/calendar/gui/gncal-full-day.c
index 64e5ec6ef4..ecc2a0d0cb 100644
--- a/calendar/gui/gncal-full-day.c
+++ b/calendar/gui/gncal-full-day.c
@@ -1028,6 +1028,8 @@ gncal_full_day_destroy (GtkObject *object)
}
g_list_free (fullday->children);
+ fullday->children = NULL;
+
g_free (fullday->drag_info);
if (GTK_OBJECT_CLASS (parent_class)->destroy)
diff --git a/calendar/gui/gnome-month-item.c b/calendar/gui/gnome-month-item.c
index eb0c5eb469..289664e535 100644
--- a/calendar/gui/gnome-month-item.c
+++ b/calendar/gui/gnome-month-item.c
@@ -15,7 +15,7 @@
/* Number of days in a month, for normal and leap years */
-static int days_in_month[2][12] = {
+static const int days_in_month[2][12] = {
{ 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 },
{ 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 }
};
@@ -23,7 +23,7 @@ static int days_in_month[2][12] = {
/* The weird month of September 1752, where 3 Sep through 13 Sep were eliminated due to the
* Gregorian reformation.
*/
-static int sept_1752[42] = {
+static const int sept_1752[42] = {
0, 0, 1, 2, 14, 15, 16,
17, 18, 19, 20, 21, 22, 23,
24, 25, 26, 27, 28, 29, 30,
diff --git a/calendar/gui/goto.c b/calendar/gui/goto.c
index c3ac3a157e..c312189ce7 100644
--- a/calendar/gui/goto.c
+++ b/calendar/gui/goto.c
@@ -10,38 +10,21 @@
#include "gnome-cal.h"
#include "gnome-month-item.h"
#include "main.h"
+#include "mark.h"
#include "timeutil.h"
+/* Updates the specified month item by marking it appropriately from the calendar the dialog refers
+ * to. */
static void
-highlight_current_day (GnomeMonthItem *mitem)
+update (GnomeMonthItem *mitem, GtkWidget *dialog)
{
- struct tm *tm;
- time_t t;
- GnomeCanvasItem *label;
- int i;
-
- t = time (NULL);
- tm = localtime (&t);
-
- /* First clear all the days to normal */
-
- for (i = 0; i < 42; i++) {
- label = gnome_month_item_num2child (mitem, i + GNOME_MONTH_ITEM_DAY_LABEL);
- gnome_canvas_item_set (label,
- "fill_color", "black",
- NULL);
- }
+ GnomeCalendar *gcal;
- /* Highlight the current day, if appropriate */
+ gcal = GNOME_CALENDAR (gtk_object_get_data (GTK_OBJECT (dialog), "gnome_calendar"));
- if ((mitem->year == (tm->tm_year + 1900)) && (mitem->month == tm->tm_mon)) {
- i = gnome_month_item_day2index (mitem, tm->tm_mday);
- label = gnome_month_item_num2child (mitem, i + GNOME_MONTH_ITEM_DAY_LABEL);
- gnome_canvas_item_set (label,
- "fill_color", "blue",
- NULL);
- }
+ unmark_month_item (mitem);
+ mark_month_item (mitem, gcal->cal);
}
/* Callback used when the year adjustment is changed */
@@ -54,7 +37,7 @@ year_changed (GtkAdjustment *adj, GtkWidget *dialog)
gnome_canvas_item_set (mitem,
"year", (int) adj->value,
NULL);
- highlight_current_day (GNOME_MONTH_ITEM (mitem));
+ update (GNOME_MONTH_ITEM (mitem), dialog);
}
/* Creates the year control with its adjustment */
@@ -99,7 +82,7 @@ month_toggled (GtkToggleButton *toggle, gpointer data)
gnome_canvas_item_set (mitem,
"month", GPOINTER_TO_INT (data),
NULL);
- highlight_current_day (GNOME_MONTH_ITEM (mitem));
+ update (GNOME_MONTH_ITEM (mitem), dialog);
}
/* Creates the months control */
@@ -236,7 +219,7 @@ create_days (GtkWidget *dialog, GnomeCalendar *gcal, int day, int month, int yea
"start_on_monday", week_starts_on_monday,
"heading_color", "white",
NULL);
- highlight_current_day (GNOME_MONTH_ITEM (mitem));
+ update (GNOME_MONTH_ITEM (mitem), dialog);
gtk_object_set_data (GTK_OBJECT (dialog), "month_item", mitem);
diff --git a/calendar/gui/year-view.c b/calendar/gui/year-view.c
index bb3a38ecab..a09862f5f0 100644
--- a/calendar/gui/year-view.c
+++ b/calendar/gui/year-view.c
@@ -10,6 +10,7 @@
#include <libgnomeui/gnome-canvas-text.h>
#include "year-view.h"
#include "main.h"
+#include "mark.h"
#include "timeutil.h"
@@ -284,107 +285,7 @@ year_view_update (YearView *yv, iCalObject *object, int flags)
if (object && ((flags & CHANGE_SUMMARY) == flags))
return;
- year_view_set (yv, time_year_begin (yv->year));
-}
-
-/* Unmarks all the days in the year view by setting their boxes and labels to the default colors */
-static void
-unmark_days (YearView *yv)
-{
- GnomeCanvasItem *item;
- int i, j;
-
- for (i = 0; i < 12; i++)
- for (j = 0; j < 42; j++) {
- /* Box */
-
- item = gnome_month_item_num2child (GNOME_MONTH_ITEM (yv->mitems[i]),
- GNOME_MONTH_ITEM_DAY_BOX + j);
- gnome_canvas_item_set (item,
- "fill_color", "#d6d6d6d6d6d6",
- NULL);
-
- /* Label */
-
- item = gnome_month_item_num2child (GNOME_MONTH_ITEM (yv->mitems[i]),
- GNOME_MONTH_ITEM_DAY_LABEL + j);
- gnome_canvas_item_set (item,
- "fill_color", "black",
- NULL);
- }
-}
-
-/* Marks all the days that fall into the specified time span */
-static void
-mark_event (YearView *yv, time_t start, time_t end)
-{
- time_t t;
- struct tm tm;
- int day_index;
- GnomeCanvasItem *mitem, *item;
-
- tm = *localtime (&start);
- end = time_end_of_day (end);
-
- for (t = start; t < end; t += 60 * 60 * 24) {
- mktime (&tm); /* normalize the time */
-
- /* We need this comparison because an event may span more than one year (!).
- * Yes, this is not the most efficient way of doing this (we could just clip
- * the event to the current year), but it will do for now.
- */
-
- if ((tm.tm_year + 1900) == yv->year) {
- /* Figure out the month item and day index that correspond to this time */
-
- mitem = yv->mitems[tm.tm_mon];
- day_index = gnome_month_item_day2index (GNOME_MONTH_ITEM (mitem), tm.tm_mday);
- g_assert (day_index != -1);
-
- /* Mark the day box */
-
- item = gnome_month_item_num2child (GNOME_MONTH_ITEM (mitem),
- GNOME_MONTH_ITEM_DAY_BOX + day_index);
- gnome_canvas_item_set (item,
- "fill_color", "tan",
- NULL);
-
- /* Mark the day label */
-
- item = gnome_month_item_num2child (GNOME_MONTH_ITEM (mitem),
- GNOME_MONTH_ITEM_DAY_LABEL + day_index);
- gnome_canvas_item_set (item,
- "fill_color", "black",
- NULL);
- }
-
- /* Next day */
-
- tm.tm_mday++;
- }
-}
-
-/* Queries the calendar for all the events in the current year and marks the days that have at least
- * one event in them.
- */
-static void
-mark_days (YearView *yv)
-{
- time_t year_begin, year_end;
- GList *list, *l;
- CalendarObject *co;
-
- year_begin = time_year_begin (yv->year);
- year_end = time_year_end (yv->year);
-
- list = calendar_get_events_in_range (yv->calendar->cal, year_begin, year_end);
-
- for (l = list; l; l = l->next) {
- co = l->data;
- mark_event (yv, co->ev_start, co->ev_end);
- }
-
- calendar_destroy_event_list (list);
+ year_view_set (yv, time_year_begin (time_from_day (yv->year, 0, 1)));
}
void
@@ -415,8 +316,12 @@ year_view_set (YearView *yv, time_t year)
"month", i,
NULL);
- unmark_days (yv);
- mark_days (yv);
+ /* Unmark and re-mark all the months */
+
+ for (i = 0; i < 12; i++) {
+ unmark_month_item (GNOME_MONTH_ITEM (yv->mitems[i]));
+ mark_month_item (GNOME_MONTH_ITEM (yv->mitems[i]), yv->calendar->cal);
+ }
}
void
@@ -432,5 +337,5 @@ year_view_time_format_changed (YearView *yv)
"start_on_monday", week_starts_on_monday,
NULL);
- year_view_set (yv, time_year_begin (yv->year));
+ year_view_set (yv, time_year_begin (time_from_day (yv->year, 0, 1)));
}
diff --git a/calendar/timeutil.c b/calendar/timeutil.c
index 670a29609b..5d4008e75d 100644
--- a/calendar/timeutil.c
+++ b/calendar/timeutil.c
@@ -171,6 +171,30 @@ time_day_hour (time_t t, int hour)
return mktime (&tm);
}
+/* Number of days in a month, for normal and leap years */
+static const int days_in_month[2][12] = {
+ { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 },
+ { 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 }
+};
+
+/* Returns whether the specified year is a leap year */
+static int
+is_leap_year (int year)
+{
+ if (year <= 1752)
+ return !(year % 4);
+ else
+ return (!(year % 4) && (year % 100)) || !(year % 400);
+}
+
+int
+time_days_in_month (int year, int month)
+{
+ g_return_val_if_fail (year >= 1900, 0);
+ g_return_val_if_fail ((month >= 0) && (month < 12), 0);
+
+ return days_in_month [is_leap_year (year)][month];
+}
time_t
time_from_day (int year, int month, int day)
@@ -213,36 +237,60 @@ time_end_of_day (time_t t)
}
time_t
-time_year_begin (int year)
+time_year_begin (time_t t)
{
struct tm tm;
- time_t retval;
-
+
+ tm = *localtime (&t);
tm.tm_hour = 0;
tm.tm_min = 0;
tm.tm_sec = 0;
- tm.tm_year = year - 1900;
tm.tm_mon = 0;
tm.tm_mday = 1;
- tm.tm_isdst = -1;
-
- retval = mktime (&tm);
- return retval;
+
+ return mktime (&tm);
}
time_t
-time_year_end (int year)
+time_year_end (time_t t)
{
struct tm tm;
-
+
+ tm = *localtime (&t);
tm.tm_hour = 23;
tm.tm_min = 59;
tm.tm_sec = 59;
- tm.tm_year = year - 1900;
tm.tm_mon = 11;
tm.tm_mday = 31;
- tm.tm_isdst = -1;
-
+
+ return mktime (&tm);
+}
+
+time_t
+time_month_begin (time_t t)
+{
+ struct tm tm;
+
+ tm = *localtime (&t);
+ tm.tm_hour = 0;
+ tm.tm_min = 0;
+ tm.tm_sec = 0;
+ tm.tm_mday = 1;
+
+ return mktime (&tm);
+}
+
+time_t
+time_month_end (time_t t)
+{
+ struct tm tm;
+
+ tm = *localtime (&t);
+ tm.tm_hour = 23;
+ tm.tm_min = 59;
+ tm.tm_sec = 59;
+ tm.tm_mday = time_days_in_month (tm.tm_year + 1900, tm.tm_mon);
+
return mktime (&tm);
}
diff --git a/calendar/timeutil.h b/calendar/timeutil.h
index 73b521cc20..ac006012ac 100644
--- a/calendar/timeutil.h
+++ b/calendar/timeutil.h
@@ -20,7 +20,7 @@ int get_time_t_hour (time_t t);
int isodiff_to_secs (char *str);
char *isodiff_from_secs (int secs);
-time_t time_add_minutes (time_t time, int minutes);
+time_t time_add_minutes (time_t time, int minutes);
time_t time_add_day (time_t time, int days);
time_t time_add_week (time_t time, int weeks);
time_t time_add_month (time_t time, int months);
@@ -33,19 +33,40 @@ time_t time_add_year (time_t time, int years);
*/
char *format_simple_hour (int hour, int use_am_pm);
-/* Converts the specified date to a time_t at the start of the specified day */
+/* Returns the number of days in the specified month. Years are full years (starting from year 1).
+ * Months are in [0, 11].
+ */
+int time_days_in_month (int year, int month);
+
+/* Converts the specified date to a time_t at the start of the specified day. Years are full years
+ * (starting from year 1). Months are in [0, 11]. Days are 1-based.
+ */
time_t time_from_day (int year, int month, int day);
time_t time_start_of_day (time_t t);
time_t time_end_of_day (time_t t);
time_t time_day_hour (time_t t, int hour);
-time_t time_year_begin (int year);
-time_t time_year_end (int year);
-time_t time_week_begin (time_t t);
-time_t parse_date (char *str);
-time_t time_month_begin (time_t t);
-time_t time_month_end (time_t t);
+/* These two functions take a time value and return the beginning or end of the corresponding year,
+ * respectively.
+ */
+time_t time_year_begin (time_t t);
+time_t time_year_end (time_t t);
+
+/* These two functions take a time value and return the beginning or end of the corresponding month,
+ * respectively.
+ */
+time_t time_month_begin (time_t t);
+time_t time_month_end (time_t t);
+
+/* These functions take a time value and return the beginning or end of the corresponding week,
+ * respectively.
+ */
+time_t time_week_begin (time_t t);
+time_t time_week_end (time_t t);
+
+time_t parse_date (char *str);
void print_time_t (time_t t);
+
#endif
diff --git a/calendar/year-view.c b/calendar/year-view.c
index bb3a38ecab..a09862f5f0 100644
--- a/calendar/year-view.c
+++ b/calendar/year-view.c
@@ -10,6 +10,7 @@
#include <libgnomeui/gnome-canvas-text.h>
#include "year-view.h"
#include "main.h"
+#include "mark.h"
#include "timeutil.h"
@@ -284,107 +285,7 @@ year_view_update (YearView *yv, iCalObject *object, int flags)
if (object && ((flags & CHANGE_SUMMARY) == flags))
return;
- year_view_set (yv, time_year_begin (yv->year));
-}
-
-/* Unmarks all the days in the year view by setting their boxes and labels to the default colors */
-static void
-unmark_days (YearView *yv)
-{
- GnomeCanvasItem *item;
- int i, j;
-
- for (i = 0; i < 12; i++)
- for (j = 0; j < 42; j++) {
- /* Box */
-
- item = gnome_month_item_num2child (GNOME_MONTH_ITEM (yv->mitems[i]),
- GNOME_MONTH_ITEM_DAY_BOX + j);
- gnome_canvas_item_set (item,
- "fill_color", "#d6d6d6d6d6d6",
- NULL);
-
- /* Label */
-
- item = gnome_month_item_num2child (GNOME_MONTH_ITEM (yv->mitems[i]),
- GNOME_MONTH_ITEM_DAY_LABEL + j);
- gnome_canvas_item_set (item,
- "fill_color", "black",
- NULL);
- }
-}
-
-/* Marks all the days that fall into the specified time span */
-static void
-mark_event (YearView *yv, time_t start, time_t end)
-{
- time_t t;
- struct tm tm;
- int day_index;
- GnomeCanvasItem *mitem, *item;
-
- tm = *localtime (&start);
- end = time_end_of_day (end);
-
- for (t = start; t < end; t += 60 * 60 * 24) {
- mktime (&tm); /* normalize the time */
-
- /* We need this comparison because an event may span more than one year (!).
- * Yes, this is not the most efficient way of doing this (we could just clip
- * the event to the current year), but it will do for now.
- */
-
- if ((tm.tm_year + 1900) == yv->year) {
- /* Figure out the month item and day index that correspond to this time */
-
- mitem = yv->mitems[tm.tm_mon];
- day_index = gnome_month_item_day2index (GNOME_MONTH_ITEM (mitem), tm.tm_mday);
- g_assert (day_index != -1);
-
- /* Mark the day box */
-
- item = gnome_month_item_num2child (GNOME_MONTH_ITEM (mitem),
- GNOME_MONTH_ITEM_DAY_BOX + day_index);
- gnome_canvas_item_set (item,
- "fill_color", "tan",
- NULL);
-
- /* Mark the day label */
-
- item = gnome_month_item_num2child (GNOME_MONTH_ITEM (mitem),
- GNOME_MONTH_ITEM_DAY_LABEL + day_index);
- gnome_canvas_item_set (item,
- "fill_color", "black",
- NULL);
- }
-
- /* Next day */
-
- tm.tm_mday++;
- }
-}
-
-/* Queries the calendar for all the events in the current year and marks the days that have at least
- * one event in them.
- */
-static void
-mark_days (YearView *yv)
-{
- time_t year_begin, year_end;
- GList *list, *l;
- CalendarObject *co;
-
- year_begin = time_year_begin (yv->year);
- year_end = time_year_end (yv->year);
-
- list = calendar_get_events_in_range (yv->calendar->cal, year_begin, year_end);
-
- for (l = list; l; l = l->next) {
- co = l->data;
- mark_event (yv, co->ev_start, co->ev_end);
- }
-
- calendar_destroy_event_list (list);
+ year_view_set (yv, time_year_begin (time_from_day (yv->year, 0, 1)));
}
void
@@ -415,8 +316,12 @@ year_view_set (YearView *yv, time_t year)
"month", i,
NULL);
- unmark_days (yv);
- mark_days (yv);
+ /* Unmark and re-mark all the months */
+
+ for (i = 0; i < 12; i++) {
+ unmark_month_item (GNOME_MONTH_ITEM (yv->mitems[i]));
+ mark_month_item (GNOME_MONTH_ITEM (yv->mitems[i]), yv->calendar->cal);
+ }
}
void
@@ -432,5 +337,5 @@ year_view_time_format_changed (YearView *yv)
"start_on_monday", week_starts_on_monday,
NULL);
- year_view_set (yv, time_year_begin (yv->year));
+ year_view_set (yv, time_year_begin (time_from_day (yv->year, 0, 1)));
}