From a0afdf4f53224a55425a8826c0563faa510fa6c5 Mon Sep 17 00:00:00 2001 From: Federico Mena Quintero Date: Sun, 1 Jul 2001 04:59:24 +0000 Subject: Fixes bug #1406. 2001-06-30 Federico Mena Quintero Fixes bug #1406. * gui/calendar-config.c (config_read): Handle the options for the task list colors. (calendar_config_write): Ditto. (calendar_config_get_tasks_due_today_color): New function. (calendar_config_set_tasks_due_today_color): New function. (calendar_config_get_tasks_overdue_color): New function. (calendar_config_set_tasks_overdue_color): New function. (calendar_config_configure_e_calendar_table): Use e_table_model_changed() for the colors. * gui/dialogs/cal-prefs-dialog.glade: Updated the options for the task list and alarms. * gui/dialogs/cal-prefs-dialog.c (cal_prefs_dialog_show_config): Update the task list settings. (cal_prefs_dialog_update_config): Ditto. * gui/calendar-model.c (get_color): Deal with tasks for today as well as overdue tasks. Make it cleaner, even though we have to duplicate a chunk of is_overdue(). * gui/calendar-commands.c (preferences_cmd): Renamed from properties_cmd(). svn path=/trunk/; revision=10648 --- calendar/gui/calendar-model.c | 87 +++++++++++++++++++++++++++++++++---------- 1 file changed, 68 insertions(+), 19 deletions(-) (limited to 'calendar/gui/calendar-model.c') diff --git a/calendar/gui/calendar-model.c b/calendar/gui/calendar-model.c index 1e64b940c4..bcd4d69843 100644 --- a/calendar/gui/calendar-model.c +++ b/calendar/gui/calendar-model.c @@ -43,8 +43,9 @@ #include #include #include -#include "calendar-model.h" #include "calendar-commands.h" +#include "calendar-config.h" +#include "calendar-model.h" /* Private part of the ECalendarModel structure */ @@ -561,7 +562,7 @@ get_url (CalComponent *comp) /* Returns whether the completion date has been set on a component */ static gboolean -get_is_complete (CalComponent *comp) +is_complete (CalComponent *comp) { struct icaltimetype *t; gboolean retval; @@ -575,14 +576,11 @@ get_is_complete (CalComponent *comp) return retval; } -/* Returns whether a calendar component is overdue. - * - * FIXME: This will only get called when the component is scrolled into the - * ETable. There should be some sort of dynamic update thingy for if a component - * becomes overdue while it is being viewed. +/* Returns whether a component is overdue. Sigh, this is very similar to + * get_color() below. */ static gboolean -get_is_overdue (CalComponent *comp) +is_overdue (CalComponent *comp) { CalComponentDateTime dt; gboolean retval; @@ -598,15 +596,12 @@ get_is_overdue (CalComponent *comp) /* Second, is it already completed? */ - if (get_is_complete (comp)) { + if (is_complete (comp)) { retval = FALSE; goto out; } - /* Third, are we overdue as of right now? We use <= in the - * comparison below so that the table entries change color - * immediately. - */ + /* Third, are we overdue as of right now? */ t = icaltime_as_timet (*dt.value); @@ -623,6 +618,63 @@ get_is_overdue (CalComponent *comp) return retval; } +/* Computes the color to be used to display a component */ +static const char * +get_color (CalComponent *comp) +{ + CalComponentDateTime dt; + const char *retval; + + cal_component_get_due (comp, &dt); + + /* First, do we have a due date? */ + + if (!dt.value) + retval = NULL; + else { + time_t t, t_now; + struct tm tm, tm_now; + + /* Second, is it already completed? */ + + if (is_complete (comp)) { + retval = NULL; + goto out; + } + + /* Third, is it due today? */ + + t = icaltime_as_timet (*dt.value); + tm = *localtime (&t); + + t_now = time (NULL); + tm_now = *localtime (&t_now); + + if (tm.tm_year == tm_now.tm_year + && tm.tm_mon == tm_now.tm_mon + && tm.tm_mday == tm_now.tm_mday) { + retval = calendar_config_get_tasks_due_today_color (); + goto out; + } + + /* Fourth, are we overdue as of right now? We use <= in the + * comparison below so that the table entries change color + * immediately. + */ + + if (t <= t_now) + retval = calendar_config_get_tasks_overdue_color (); + else + retval = NULL; + } + + out: + + cal_component_free_datetime (&dt); + + return retval; +} + static void * get_status (CalComponent *comp) { @@ -732,19 +784,16 @@ calendar_model_value_at (ETableModel *etm, int col, int row) } } case CAL_COMPONENT_FIELD_COMPLETE: - return GINT_TO_POINTER (get_is_complete (comp)); + return GINT_TO_POINTER (is_complete (comp)); case CAL_COMPONENT_FIELD_RECURRING: return GINT_TO_POINTER (cal_component_has_recurrences (comp)); case CAL_COMPONENT_FIELD_OVERDUE: - return GINT_TO_POINTER (get_is_overdue (comp)); + return GINT_TO_POINTER (is_overdue (comp)); case CAL_COMPONENT_FIELD_COLOR: - if (get_is_overdue (comp)) - return "red"; - else - return NULL; + return (void *) get_color (comp); case CAL_COMPONENT_FIELD_STATUS: return get_status (comp); -- cgit v1.2.3