diff options
Diffstat (limited to 'calendar/gui')
-rw-r--r-- | calendar/gui/gncal-todo.c | 279 | ||||
-rw-r--r-- | calendar/gui/main.c | 11 | ||||
-rw-r--r-- | calendar/gui/main.h | 12 | ||||
-rw-r--r-- | calendar/gui/prop.c | 78 |
4 files changed, 318 insertions, 62 deletions
diff --git a/calendar/gui/gncal-todo.c b/calendar/gui/gncal-todo.c index 941eddf453..3be3ac4517 100644 --- a/calendar/gui/gncal-todo.c +++ b/calendar/gui/gncal-todo.c @@ -15,7 +15,13 @@ int todo_show_due_date = 0; int todo_show_priority = 0; -int todo_due_date_overdue_highlight = 0; +int todo_show_time_remaining = 0; + +int todo_item_dstatus_highlight_overdue = 0; +int todo_item_dstatus_highlight_due_today = 0; +int todo_item_dstatus_highlight_not_due_yet = 0; + + char *todo_overdue_font_text; gint todo_current_sort_column = 0; gint todo_current_sort_type = GTK_SORT_ASCENDING; @@ -177,7 +183,7 @@ simple_todo_editor (GncalTodo *todo, iCalObject *ico) gtk_widget_show (due_label); due_entry = gtk_entry_new (); - due_entry = date_edit_new (ico->dtend, FALSE); + due_entry = date_edit_new (ico->dtend, TRUE); gtk_box_pack_start (GTK_BOX (due_box), due_entry, TRUE, TRUE, 0); gtk_widget_show (due_entry); @@ -412,15 +418,17 @@ gncal_todo_init (GncalTodo *todo) GtkWidget *w; GtkWidget *sw; GtkWidget *hbox; - gchar *titles[3] = { + gchar *titles[4] = { N_("Summary"), N_("Due Date"), - N_("Priority") + N_("Priority"), + N_("Time Left") }; - char *tmp[3]; + char *tmp[4]; tmp[0] = _(titles[0]); tmp[1] = _(titles[1]); tmp[2] = _(titles[2]); + tmp[3] = _(titles[3]); gtk_box_set_spacing (GTK_BOX (todo), 4); @@ -439,7 +447,7 @@ gncal_todo_init (GncalTodo *todo) gtk_widget_show (sw); - w = gtk_clist_new_with_titles(3, tmp); + w = gtk_clist_new_with_titles(4, tmp); todo->clist = GTK_CLIST (w); gtk_clist_set_selection_mode (todo->clist, GTK_SELECTION_BROWSE); @@ -523,53 +531,224 @@ convert_time_t_to_char (time_t t) return g_strdup (buf); } +enum todo_styles { + TODO_STYLE_OVERDUE, + TODO_STYLE_DUE_TODAY, + TODO_STYLE_NOT_DUE +}; + + +enum todo_status { + TODO_ITEM_DSTATUS_NOT_DUE_YET, + TODO_ITEM_DSTATUS_DUE_TODAY, + TODO_ITEM_DSTATUS_OVERDUE, + TODO_ITEM_DSTATUS_LAST_DUE_STATUS +}; +typedef enum todo_status todo_status; + static GtkStyle * -make_overdue_todo_style(GncalTodo *todo) +make_todo_style(GncalTodo *todo, todo_status style_type) { - GtkStyle *overdue_style = NULL; - GdkColor overdue_color; + GtkStyle *style = NULL; + GdkColor style_color; + int color_prop = 0; + switch(style_type) { + case TODO_ITEM_DSTATUS_NOT_DUE_YET: + color_prop = COLOR_PROP_TODO_NOT_DUE_YET; + break; + case TODO_ITEM_DSTATUS_DUE_TODAY: + color_prop = COLOR_PROP_TODO_DUE_TODAY; + break; + case TODO_ITEM_DSTATUS_OVERDUE: + color_prop = COLOR_PROP_TODO_OVERDUE; + break; + case TODO_ITEM_DSTATUS_LAST_DUE_STATUS: + } - /*make the overdue color configurable */ - overdue_color.red = color_props[COLOR_PROP_OVERDUE_TODO].r; - overdue_color.green = color_props[COLOR_PROP_OVERDUE_TODO].g; - overdue_color.blue = color_props[COLOR_PROP_OVERDUE_TODO].b; + style_color.red = color_props[color_prop].r; + style_color.green = color_props[color_prop].g; + style_color.blue = color_props[color_prop].b; - overdue_style = gtk_style_copy (GTK_WIDGET (todo->clist)->style); - overdue_style->base[GTK_STATE_NORMAL] = overdue_color; + style = gtk_style_copy (GTK_WIDGET (todo->clist)->style); + style->base[GTK_STATE_NORMAL] = style_color; + return style; +} + + + + +static +todo_status todo_item_due_status(time_t *todo_due_time) { + struct tm due_tm_time; + struct tm current_time; + struct tm *temp_tm; + time_t current_time_val = time(NULL); + temp_tm = localtime(todo_due_time); + /* make a copy so it dosen't get over written */ + memcpy(&due_tm_time, temp_tm, sizeof(struct tm)); - return overdue_style; + + temp_tm = localtime(¤t_time_val); + memcpy(¤t_time, temp_tm, sizeof(struct tm)); + + if(due_tm_time.tm_mon == current_time.tm_mon && + due_tm_time.tm_mday == current_time.tm_mday && + due_tm_time.tm_year == current_time.tm_year) { + return TODO_ITEM_DSTATUS_DUE_TODAY; + } + + if((*todo_due_time) < current_time_val) { + return TODO_ITEM_DSTATUS_OVERDUE; + } + + return TODO_ITEM_DSTATUS_NOT_DUE_YET; } + +enum todo_remaining_time_form { + TODO_ITEM_REMAINING_WEEKS, + TODO_ITEM_REMAINING_DAYS, + TODO_ITEM_REMAINING_HOURS, + TODO_ITEM_REMAINING_MINUTES, + TODO_ITEM_REMAINING_SECONDS +}; +typedef enum todo_remaining_time_form todo_remaining_time_form; + static void insert_in_clist (GncalTodo *todo, iCalObject *ico) { int i; - char *text[3]; - static GtkStyle *overdue_style = NULL; + char *text[4]; + char time_remaining_buffer[100]; + time_t time_remain; + todo_remaining_time_form time_remaining_form; + int sec_in_week = 3600*7*24; + int sec_in_day = 3600*24; + int sec_in_hour = 3600; + int sec_in_minute = 60; + int weeks = 0; + int days = 0; + int hours = 0; + int minutes = 0; + int seconds = 0; + - - /* setup the over due style if we haven't already, or it changed.*/ - if (todo_style_changed || !overdue_style) { - /* free the old style cause its not needed anymore */ - if(!overdue_style) g_free(overdue_style); - overdue_style = make_overdue_todo_style(todo); + /* an array for the styles of items */ + static GtkStyle *dstatus_styles[TODO_ITEM_DSTATUS_LAST_DUE_STATUS]; + /* we want to remake the styles when the status is changed, + also we need to check for the null value in the pointer so we init them + at startup */ + if (todo_style_changed || !dstatus_styles[TODO_ITEM_DSTATUS_NOT_DUE_YET]) { + g_free(dstatus_styles[TODO_ITEM_DSTATUS_NOT_DUE_YET]); + g_free(dstatus_styles[TODO_ITEM_DSTATUS_OVERDUE]); + g_free(dstatus_styles[TODO_ITEM_DSTATUS_DUE_TODAY]); + + dstatus_styles[TODO_ITEM_DSTATUS_NOT_DUE_YET] = make_todo_style(todo, TODO_ITEM_DSTATUS_NOT_DUE_YET); + dstatus_styles[TODO_ITEM_DSTATUS_OVERDUE] = make_todo_style(todo, TODO_ITEM_DSTATUS_OVERDUE); + dstatus_styles[TODO_ITEM_DSTATUS_DUE_TODAY] = make_todo_style(todo, TODO_ITEM_DSTATUS_DUE_TODAY); + todo_style_changed = 0; } + + + text[0] = ico->summary; + if(todo_show_time_remaining) { + memset(time_remaining_buffer, 0, 100); + /* we need to make a string that represents the amount of time remaining + before this task is due */ + + /* for right now all I'll do is up to the hours. */ + time_remain = (ico->dtend - time(NULL)); + if(time_remain < 0) { + text[3] = "Overdue!"; + } + else { + + /* lets determine a decent denomination to display */ + if(time_remain / (sec_in_week)) + { + /* we have weeks available */ + time_remaining_form = TODO_ITEM_REMAINING_WEEKS; + weeks = time_remain / sec_in_week; + days = (time_remain % (sec_in_week))/sec_in_day; + } + else if(time_remain / (sec_in_day)) + { + /* we have days available */ + time_remaining_form = TODO_ITEM_REMAINING_DAYS; + days = time_remain / sec_in_day; + hours = (time_remain % sec_in_day)/sec_in_hour; + } + else if(time_remain / (sec_in_hour)) + { + /* we have hours available */ + time_remaining_form = TODO_ITEM_REMAINING_HOURS; + hours = time_remain /sec_in_hour; + minutes = (time_remain % sec_in_hour) / sec_in_minute; + } + else if(time_remain / sec_in_minute) + { + time_remaining_form = TODO_ITEM_REMAINING_MINUTES; + minutes = time_remain / sec_in_minute; + seconds = time_remain % sec_in_minute; + } + else + { + time_remaining_form = TODO_ITEM_REMAINING_SECONDS; + seconds = time_remain; + } + + switch(time_remaining_form) + { + case TODO_ITEM_REMAINING_WEEKS: + snprintf(time_remaining_buffer, 100, "%d %s %d %s", weeks, + (weeks > 1) ? _("Weeks") : _("Week"), + days, (days > 1) ? _("Days") : _("Day")); + break; + case TODO_ITEM_REMAINING_DAYS: + snprintf(time_remaining_buffer, 100, "%d %s %d %s", days, + (days > 1) ? _("Days") : _("Day"), + hours, (hours > 1) ? _("Hours") : _("Hour")); + break; + case TODO_ITEM_REMAINING_HOURS: + snprintf(time_remaining_buffer, 100, "%d %s %d %s", hours, + (hours > 1) ? _("Hours") : _("Hour"), + minutes, (minutes > 1) ? _("Minutes") : _("Minute")); + break; + case TODO_ITEM_REMAINING_MINUTES: + snprintf(time_remaining_buffer, 100, "%d %s %d %s", minutes, + (minutes > 1) ? _("Minutes") : _("Minute"), + seconds, (seconds > 1) ? _("Seconds") : _("Second")); + break; + case TODO_ITEM_REMAINING_SECONDS: + snprintf(time_remaining_buffer, 100, "%d %s", seconds, + (seconds > 1) ? _("Seconds") : _("Second")); + break; + } + text[3] = g_strdup(time_remaining_buffer); + todo->data_ptrs = g_slist_append(todo->data_ptrs, text[3]); + } + + } + else { + text[3] = "Loose penguini!"; + } /* * right now column 0 will be the summary * and column 1 will be the due date. * WISH: this should be able to be changed on the fly */ - if(ico->dtend && todo_show_due_date) { - text[1] = convert_time_t_to_char (ico->dtend); - /* Append the data's pointer so later it can be properly freed */ - todo->data_ptrs = g_slist_append (todo->data_ptrs, text[1]); - } + if(ico->dtend && todo_show_due_date) + { + text[1] = convert_time_t_to_char (ico->dtend); + /* Append the data's pointer so later it can be properly freed */ + todo->data_ptrs = g_slist_append (todo->data_ptrs, text[1]); + } else text[1] = NULL; @@ -589,9 +768,27 @@ insert_in_clist (GncalTodo *todo, iCalObject *ico) * determine if the task is overdue.. * if so mark with the apropriate style */ - if(todo_due_date_overdue_highlight) { - if(ico->dtend < time(NULL)) - gtk_clist_set_row_style(todo->clist, i, overdue_style); + + switch(todo_item_due_status(&ico->dtend)) { + case TODO_ITEM_DSTATUS_NOT_DUE_YET: + if(todo_item_dstatus_highlight_not_due_yet) + { + gtk_clist_set_row_style(todo->clist, i, dstatus_styles[TODO_ITEM_DSTATUS_NOT_DUE_YET]); + } + break; + case TODO_ITEM_DSTATUS_DUE_TODAY: + if(todo_item_dstatus_highlight_due_today) + { + gtk_clist_set_row_style(todo->clist, i, dstatus_styles[TODO_ITEM_DSTATUS_DUE_TODAY]); + } + break; + case TODO_ITEM_DSTATUS_OVERDUE: + if(todo_item_dstatus_highlight_overdue) + { + gtk_clist_set_row_style(todo->clist, i, dstatus_styles[TODO_ITEM_DSTATUS_OVERDUE]); + } + break; + case TODO_ITEM_DSTATUS_LAST_DUE_STATUS: } /* keep the list in order */ @@ -626,10 +823,20 @@ gncal_todo_update (GncalTodo *todo, iCalObject *ico, int flags) /* check on the columns that we should display */ /* check for due date */ - if(todo_show_due_date) - gtk_clist_set_column_visibility (todo->clist, 1, 1); - else - gtk_clist_set_column_visibility (todo->clist, 1, 0); + if(todo_show_due_date) { + gtk_clist_set_column_visibility (todo->clist, 1, 1); + } + else { + gtk_clist_set_column_visibility (todo->clist, 1, 0); + } + + if(todo_show_time_remaining) { + gtk_clist_set_column_visibility (todo->clist, 3, 1); + } + else { + gtk_clist_set_column_visibility (todo->clist, 3, 0); + } + if(todo_show_priority) gtk_clist_set_column_visibility (todo->clist, 2, 1); diff --git a/calendar/gui/main.c b/calendar/gui/main.c index b41b9a6d63..acd732e1ad 100644 --- a/calendar/gui/main.c +++ b/calendar/gui/main.c @@ -62,7 +62,9 @@ struct color_prop color_props[] = { { 0xd364, 0xc6b7, 0x7969, N_("Highlighted day:"), "/calendar/Colors/prelight_bg" }, { 0x01f0, 0x01f0, 0x01f0, N_("Day numbers:"), "/calendar/Colors/day_fg" }, { 0x0000, 0x0000, 0xffff, N_("Current day's number:"), "/calendar/Colors/current_fg" }, - { 0x0000, 0xaaaa, 0xaaaa, N_("Overdue To Do item"), "/calendar/Coloirs/todo_overdue" } + { 0xbbbb, 0xbbbb, 0x0000, N_("To-Do item that is not yet due:"), "/calendar/Colors/todo_not_yet" }, + { 0xdddd, 0xbbbb, 0x0000, N_("To-Do item that is due today:"), "/calendar/Colors/todo_today" }, + { 0xbbbb, 0xdddd, 0x0000, N_("To-Do item that is overdue:"), "/calendar/Colors/todo_overdue" } }; /* Number of active calendars */ @@ -206,9 +208,14 @@ init_calendar (void) /* read todolist settings */ + todo_show_time_remaining = gnome_config_get_bool("/calendar/Todo/show_time_remain"); todo_show_due_date = gnome_config_get_bool("/calendar/Todo/show_due_date"); - todo_due_date_overdue_highlight = gnome_config_get_bool("/calendar/Todo/highlight_overdue_tasks"); + todo_item_dstatus_highlight_overdue = gnome_config_get_bool("/calendar/Todo/highlight_overdue"); + + todo_item_dstatus_highlight_due_today = gnome_config_get_bool("/calendar/Todo/highlight_due_today"); + + todo_item_dstatus_highlight_not_due_yet = gnome_config_get_bool("/calendar/Todo/highlight_not_due_yet"); todo_current_sort_column = gnome_config_get_int("/calendar/Todo/sort_column"); diff --git a/calendar/gui/main.h b/calendar/gui/main.h index bc80e37be4..77a5e12217 100644 --- a/calendar/gui/main.h +++ b/calendar/gui/main.h @@ -19,7 +19,9 @@ typedef enum { COLOR_PROP_PRELIGHT_DAY_BG, /* Background color for prelighted day */ COLOR_PROP_DAY_FG, /* Color for day numbers */ COLOR_PROP_CURRENT_DAY_FG, /* Color for current day's number */ - COLOR_PROP_OVERDUE_TODO, + COLOR_PROP_TODO_NOT_DUE_YET, /* Color for Todo items not yet due */ + COLOR_PROP_TODO_DUE_TODAY, /* Color for Todo items due today */ + COLOR_PROP_TODO_OVERDUE, /* Color for Todo items that are overdue */ COLOR_PROP_LAST /* Number of color properties */ } ColorProp; @@ -36,10 +38,14 @@ extern struct color_prop color_props[]; /* todo preferences */ extern int todo_show_due_date; -extern int todo_due_date_overdue_highlight; + +extern int todo_item_dstatus_highlight_overdue; +extern int todo_item_dstatus_highlight_due_today; +extern int todo_item_dstatus_highlight_not_due_yet; + +extern int todo_show_time_remaining; extern int todo_show_priority; extern char *todo_overdue_font_text; -extern struct color_prop todo_overdue_highlight_color; extern gboolean todo_style_changed; extern gint todo_current_sort_column; extern gint todo_current_sort_type; diff --git a/calendar/gui/prop.c b/calendar/gui/prop.c index b1fa468010..29b4f527f6 100644 --- a/calendar/gui/prop.c +++ b/calendar/gui/prop.c @@ -45,7 +45,13 @@ static GnomeCanvasItem *month_item; /* Widgets for the todo page */ static GtkWidget *due_date_show_button; -static GtkWidget *due_date_overdue_highlight; + +static GtkWidget *todo_item_time_remaining_show_button; + +static GtkWidget *todo_item_highlight_overdue; +static GtkWidget *todo_item_highlight_not_due_yet; +static GtkWidget *todo_item_highlight_due_today; + static GtkWidget *priority_show_button; /* Widgets for the alarm page */ @@ -133,13 +139,24 @@ static void prop_apply_todo(void) { todo_show_due_date = GTK_TOGGLE_BUTTON (due_date_show_button)->active; - todo_due_date_overdue_highlight = GTK_TOGGLE_BUTTON (due_date_overdue_highlight)->active; + + todo_item_dstatus_highlight_overdue = GTK_TOGGLE_BUTTON(todo_item_highlight_overdue)->active; + todo_item_dstatus_highlight_not_due_yet = GTK_TOGGLE_BUTTON(todo_item_highlight_not_due_yet)->active; + todo_item_dstatus_highlight_due_today = GTK_TOGGLE_BUTTON(todo_item_highlight_due_today)->active; todo_show_priority = GTK_TOGGLE_BUTTON (priority_show_button)->active; + todo_show_time_remaining = GTK_TOGGLE_BUTTON (todo_item_time_remaining_show_button)->active; + /* storing the values */ + + gnome_config_set_bool("/calendar/Todo/show_time_remain", todo_show_time_remaining); + gnome_config_set_bool("/calendar/Todo/highlight_overdue", todo_item_dstatus_highlight_overdue); + + gnome_config_set_bool("/calendar/Todo/highlight_due_today", todo_item_dstatus_highlight_due_today); + + gnome_config_set_bool("/calendar/Todo/highlight_not_due_yet", todo_item_dstatus_highlight_not_due_yet); gnome_config_set_bool("/calendar/Todo/show_due_date", todo_show_due_date); - gnome_config_set_bool("/calendar/Todo/highlight_overdue_tasks", todo_due_date_overdue_highlight); gnome_config_set_bool("/calendar/Todo/show_priority", todo_show_priority); /* need to sync our config changes. */ gnome_config_sync (); @@ -496,7 +513,7 @@ create_colors_page (void) GtkWidget *w; int i; - frame = gtk_frame_new (_("Colors for months")); + frame = gtk_frame_new (_("Colors for display")); gtk_container_set_border_width (GTK_CONTAINER (frame), GNOME_PAD_SMALL); gnome_property_box_append_page (GNOME_PROPERTY_BOX (prop_win), frame, gtk_label_new (_("Colors"))); @@ -557,15 +574,8 @@ create_colors_page (void) static void set_todo_page_options(void) { - if(!GTK_TOGGLE_BUTTON (due_date_show_button)->active) { - /* disable everything */ - gtk_widget_set_sensitive(due_date_overdue_highlight,0); - } - else - { - gtk_widget_set_sensitive(due_date_overdue_highlight,1); - } - + + while (gtk_events_pending ()) gtk_main_iteration (); } @@ -588,17 +598,25 @@ build_list_options_frame(void) vbox = gtk_vbox_new (FALSE, 0); gtk_container_add (GTK_CONTAINER (frame), vbox); - due_date_show_button = gtk_check_button_new_with_label (_("Summary")); due_date_show_button = gtk_check_button_new_with_label (_("Due Date")); priority_show_button = gtk_check_button_new_with_label (_("Priority")); - + todo_item_time_remaining_show_button = gtk_check_button_new_with_label (_("Time Until Due")); + gtk_toggle_button_set_state (GTK_TOGGLE_BUTTON(due_date_show_button), todo_show_due_date); gtk_signal_connect (GTK_OBJECT(due_date_show_button), "clicked", (GtkSignalFunc) todo_option_set, NULL); gtk_box_pack_start (GTK_BOX (vbox), due_date_show_button, FALSE, FALSE, 0); - + + gtk_toggle_button_set_state (GTK_TOGGLE_BUTTON(todo_item_time_remaining_show_button), todo_show_time_remaining); + gtk_signal_connect (GTK_OBJECT(todo_item_time_remaining_show_button), + "clicked", + (GtkSignalFunc) todo_option_set, + NULL); + gtk_box_pack_start (GTK_BOX (vbox), todo_item_time_remaining_show_button, FALSE, FALSE, 0); + + gtk_toggle_button_set_state (GTK_TOGGLE_BUTTON(priority_show_button), todo_show_priority); gtk_signal_connect (GTK_OBJECT(priority_show_button), "clicked", @@ -618,14 +636,32 @@ build_style_list_options_frame(void) vbox = gtk_vbox_new (FALSE, 0); gtk_container_add (GTK_CONTAINER (frame), vbox); - due_date_overdue_highlight = gtk_check_button_new_with_label (_("Highlight overdue items")); - - gtk_toggle_button_set_state (GTK_TOGGLE_BUTTON(due_date_overdue_highlight), todo_due_date_overdue_highlight); - gtk_signal_connect (GTK_OBJECT(due_date_overdue_highlight), + todo_item_highlight_overdue = gtk_check_button_new_with_label (_("Highlight overdue items")); + gtk_toggle_button_set_state (GTK_TOGGLE_BUTTON(todo_item_highlight_overdue), + todo_item_dstatus_highlight_overdue); + todo_item_highlight_not_due_yet = gtk_check_button_new_with_label (_("Highlight not yet due items")); + gtk_toggle_button_set_state (GTK_TOGGLE_BUTTON(todo_item_highlight_not_due_yet), + todo_item_dstatus_highlight_overdue); + todo_item_highlight_due_today = gtk_check_button_new_with_label (_("Highlight items due today")); + gtk_toggle_button_set_state (GTK_TOGGLE_BUTTON(todo_item_highlight_due_today), + todo_item_dstatus_highlight_overdue); + + gtk_signal_connect (GTK_OBJECT(todo_item_highlight_overdue), "clicked", (GtkSignalFunc) todo_option_set, NULL); - gtk_box_pack_start (GTK_BOX (vbox), due_date_overdue_highlight, FALSE, FALSE, 0); + gtk_signal_connect (GTK_OBJECT(todo_item_highlight_not_due_yet), + "clicked", + (GtkSignalFunc) todo_option_set, + NULL); + gtk_signal_connect (GTK_OBJECT(todo_item_highlight_due_today), + "clicked", + (GtkSignalFunc) todo_option_set, + NULL); + + gtk_box_pack_start (GTK_BOX (vbox), todo_item_highlight_overdue, FALSE, FALSE, 0); + gtk_box_pack_start (GTK_BOX (vbox), todo_item_highlight_due_today, FALSE, FALSE, 0); + gtk_box_pack_start (GTK_BOX (vbox), todo_item_highlight_not_due_yet, FALSE, FALSE, 0); return frame; } static void |