From b30a06b9e876fba26887e612ecac69d9d2aa5f76 Mon Sep 17 00:00:00 2001 From: Srinivasa Ragavan Date: Fri, 11 May 2007 05:57:50 +0000 Subject: Fix for bug #211058 svn path=/trunk/; revision=33502 --- filter/ChangeLog | 9 +++++++ filter/filter-datespec.c | 68 ++++++++++++++++++++++++++++++++++++++---------- filter/filter-datespec.h | 3 ++- filter/filter.glade | 41 ++++++++++++++++++----------- 4 files changed, 91 insertions(+), 30 deletions(-) (limited to 'filter') diff --git a/filter/ChangeLog b/filter/ChangeLog index c10dcfc3ad..93dc9c20cd 100644 --- a/filter/ChangeLog +++ b/filter/ChangeLog @@ -1,3 +1,12 @@ +2007-05-11 Srinivasa Ragavan + + ** Patch from Trever Adams for bug #211058 + + * filter-datespec.c: (set_button), (get_values), (set_values), + (set_option_past_future), (button_clicked), (format_sexp): + * filter-datespec.h: + * filter.glade: + 2007-04-20 Srinivasa Ragavan ** Fix for bug #430559 from Vinod. diff --git a/filter/filter-datespec.c b/filter/filter-datespec.c index 9ebbacfa65..f8bceb3e6a 100644 --- a/filter/filter-datespec.c +++ b/filter/filter-datespec.c @@ -61,8 +61,10 @@ static void filter_datespec_finalise (GObject *obj); typedef struct _timespan { guint32 seconds; - const char *singular; - const char *plural; + const char *past_singular; + const char *past_plural; + const char *future_singular; + const char *future_plural; float max; } timespan; @@ -75,13 +77,13 @@ typedef struct _timespan { #define ngettext(a, b) a, b static const timespan timespans[] = { - { 1, ngettext("1 second ago", "%d seconds ago"), 59.0 }, - { 60, ngettext("1 minute ago", "%d minutes ago"), 59.0 }, - { 3600, ngettext("1 hour ago", "%d hours ago"), 23.0 }, - { 86400, ngettext("1 day ago", "%d days ago"), 31.0 }, - { 604800, ngettext("1 week ago", "%d weeks ago"), 52.0 }, - { 2419200, ngettext("1 month ago", "%d months ago"), 12.0 }, - { 31557600, ngettext("1 year ago", "%d years ago"), 1000.0 }, + { 1, ngettext("1 second ago", "%d seconds ago"), ngettext("1 second in the future", "%d seconds in the future"), 59.0 }, + { 60, ngettext("1 minute ago", "%d minutes ago"), ngettext("1 minute in the future", "%d minutes in the future"), 59.0 }, + { 3600, ngettext("1 hour ago", "%d hours ago"), ngettext("1 hour in the future", "%d hours in the future"), 23.0 }, + { 86400, ngettext("1 day ago", "%d days ago"), ngettext("1 day in the future", "%d days in the future"), 31.0 }, + { 604800, ngettext("1 week ago", "%d weeks ago"), ngettext("1 week in the future", "%d weeks in the future"), 52.0 }, + { 2419200, ngettext("1 month ago", "%d months ago"), ngettext("1 month in the future", "%d months in the future"), 12.0 }, + { 31557600, ngettext("1 year ago", "%d years ago"), ngettext("1 year in the future", "%d years in the future"), 1000.0 }, }; /* now we let the compiler see the real function call */ @@ -92,7 +94,7 @@ static const timespan timespans[] = { struct _FilterDatespecPrivate { GtkWidget *label_button; - GtkWidget *notebook_type, *option_type, *calendar_specify, *spin_relative, *option_relative; + GtkWidget *notebook_type, *option_type, *calendar_specify, *spin_relative, *option_relative, *option_past_future; FilterDatespec_type type; int span; }; @@ -264,7 +266,7 @@ static int get_best_span (time_t val) { int i; - + for (i=N_TIMESPANS-1;i>=0;i--) { if (val % timespans[i].seconds == 0) return i; @@ -302,8 +304,18 @@ set_button (FilterDatespec *fds) span = get_best_span(fds->value); count = fds->value / timespans[span].seconds; + sprintf(buf, ngettext(timespans[span].past_singular, timespans[span].past_plural, count), count); + } + break; + case FDST_X_FUTURE: + if (fds->value == 0) + label = _("now"); + else { + int span, count; - sprintf(buf, ngettext(timespans[span].singular, timespans[span].plural, count), count); + span = get_best_span(fds->value); + count = fds->value / timespans[span].seconds; + sprintf(buf, ngettext(timespans[span].future_singular, timespans[span].future_plural, count), count); } break; } @@ -329,6 +341,7 @@ get_values (FilterDatespec *fds) fds->value = mktime(&tm); /* what about timezone? */ break; } + case FDST_X_FUTURE: case FDST_X_AGO: { int val; @@ -349,6 +362,8 @@ set_values (FilterDatespec *fds) struct _FilterDatespecPrivate *p = PRIV(fds); p->type = fds->type==FDST_UNKNOWN ? FDST_NOW : fds->type; + + int note_type = fds->type==FDST_X_FUTURE ? FDST_X_AGO : fds->type; // FUTURE and AGO use the same notebook pages/etc. switch (p->type) { case FDST_NOW: @@ -368,11 +383,18 @@ set_values (FilterDatespec *fds) p->span = get_best_span(fds->value); gtk_spin_button_set_value((GtkSpinButton*)p->spin_relative, fds->value/timespans[p->span].seconds); gtk_option_menu_set_history((GtkOptionMenu*)p->option_relative, p->span); + gtk_option_menu_set_history((GtkOptionMenu*)p->option_past_future, 0); + break; + case FDST_X_FUTURE: + p->span = get_best_span(fds->value); + gtk_spin_button_set_value((GtkSpinButton*)p->spin_relative, fds->value/timespans[p->span].seconds); + gtk_option_menu_set_history((GtkOptionMenu*)p->option_relative, p->span); + gtk_option_menu_set_history((GtkOptionMenu*)p->option_past_future, 1); break; } - gtk_notebook_set_current_page ((GtkNotebook*) p->notebook_type, p->type); - gtk_option_menu_set_history ((GtkOptionMenu*) p->option_type, p->type); + gtk_notebook_set_current_page ((GtkNotebook*) p->notebook_type, note_type); + gtk_option_menu_set_history ((GtkOptionMenu*) p->option_type, note_type); } @@ -396,6 +418,18 @@ set_option_relative (GtkMenu *menu, FilterDatespec *fds) fds->priv->span = g_list_index (GTK_MENU_SHELL (menu)->children, w); } +static void +set_option_past_future (GtkMenu *menu, FilterDatespec *fds) +{ + GtkWidget *w; + + w = gtk_menu_get_active (menu); + if(g_list_index (GTK_MENU_SHELL (menu)->children, w) == 0) + fds->type = fds->priv->type = FDST_X_AGO; + else + fds->type = fds->priv->type = FDST_X_FUTURE; +} + static void button_clicked (GtkButton *button, FilterDatespec *fds) { @@ -424,6 +458,7 @@ button_clicked (GtkButton *button, FilterDatespec *fds) p->calendar_specify = glade_xml_get_widget (gui, "calendar_specify"); p->spin_relative = glade_xml_get_widget (gui, "spin_relative"); p->option_relative = glade_xml_get_widget (gui, "option_relative"); + p->option_past_future = glade_xml_get_widget (gui, "option_past_future"); set_values (fds); @@ -431,6 +466,8 @@ button_clicked (GtkButton *button, FilterDatespec *fds) G_CALLBACK (set_option_type), fds); g_signal_connect (GTK_OPTION_MENU (p->option_relative)->menu, "deactivate", G_CALLBACK (set_option_relative), fds); + g_signal_connect (GTK_OPTION_MENU (p->option_past_future)->menu, "deactivate", + G_CALLBACK (set_option_past_future), fds); gtk_box_pack_start ((GtkBox *) dialog->vbox, toplevel, TRUE, TRUE, 3); @@ -486,5 +523,8 @@ format_sexp (FilterElement *fe, GString *out) case FDST_X_AGO: g_string_append_printf (out, "(- (get-current-date) %d)", (int) fds->value); break; + case FDST_X_FUTURE: + g_string_append_printf (out, "(+ (get-current-date) %d)", (int) fds->value); + break; } } diff --git a/filter/filter-datespec.h b/filter/filter-datespec.h index 6290ab34b5..75512ba6c0 100644 --- a/filter/filter-datespec.h +++ b/filter/filter-datespec.h @@ -42,6 +42,7 @@ typedef enum _FilterDatespec_type { FDST_NOW, FDST_SPECIFIED, FDST_X_AGO, + FDST_X_FUTURE, } FilterDatespec_type; struct _FilterDatespec { @@ -52,7 +53,7 @@ struct _FilterDatespec { /* either a timespan, an absolute time, or 0 * depending on type -- the above mapping to - * (X_AGO, SPECIFIED, NOW) + * (X_FUTURE, X_AGO, SPECIFIED, NOW) */ time_t value; diff --git a/filter/filter.glade b/filter/filter.glade index 234d41ae6f..084501c57c 100644 --- a/filter/filter.glade +++ b/filter/filter.glade @@ -700,22 +700,33 @@ a time relative to when filtering occurs. - + True - ago - False - False - GTK_JUSTIFY_CENTER - False - False - 7.45058015283e-09 - 0.5 - 0 - 0 - PANGO_ELLIPSIZE_NONE - -1 - False - 0 + True + 0 + + + + True + + + + True + ago + True + + + + + + True + in the future + True + + + + + 0 -- cgit