Allow filtering based on future dates not just past dates

"Trever L. Adams" <[email protected]>
Newsgroups gmane.comp.gnome.evolution.patches
Message-ID <[email protected]>
I have tested this patch with version 2.7.3-5 of evolution as seen in
FC/RedHat rawhide. It works. It is attached to bug 211085 in gnome
bugzilla and bug 190359 in RedHat bugzilla.

It has one hack in set_values function due to the hack to provide a
history. It is much better than my other methods that required abs or
other ways of doing abs. This one is safe for all platforms as written,
I believe, and only requires one hack, versus several if done another
way.

Additionally, sorry for some of the diff spam, this is due to me using
glade-2 to do a few necessary changes.

This does not include any translation updates - they are needed!

Is there anyway this can be included in the main distribution of
evolution? What are the rules/guidelines for placing a copyright notice
or authorship notice?

Thank you,
Trever L. Adams

_______________________________________________
Evolution-patches mailing list
[email protected]
http://mail.gnome.org/mailman/listinfo/evolution-patches
filter-date-evolution.patch (text/x-patch, 16 KB)
diff -ur evolution-2.7.3/filter/filter-datespec.c my-evolution-2.7.3/filter/filter-datespec.c
--- evolution-2.7.3/filter/filter-datespec.c	2005-08-09 17:29:27.000000000 -0600
+++ my-evolution-2.7.3/filter/filter-datespec.c	2006-06-28 20:51:01.000000000 -0600
@@ -61,8 +61,10 @@
 
 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 @@
 #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 @@
 
 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 @@
 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 @@
 			
 			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 @@
 		fds->value = mktime(&tm);
 		/* what about timezone? */
 		break; }
+	case FDST_X_FUTURE:
 	case FDST_X_AGO: {
 		int val;
 		
@@ -349,6 +362,8 @@
 	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 @@
 		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);
 }
 
 
@@ -397,6 +419,18 @@
 }
 
 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)
 {
 	struct _FilterDatespecPrivate *p = PRIV(fds);
@@ -424,6 +458,7 @@
 	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 @@
 			  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 @@
 	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 -ur evolution-2.7.3/filter/filter-datespec.h my-evolution-2.7.3/filter/filter-datespec.h
--- evolution-2.7.3/filter/filter-datespec.h	2002-11-01 16:22:57.000000000 -0700
+++ my-evolution-2.7.3/filter/filter-datespec.h	2006-06-28 17:25:55.000000000 -0600
@@ -42,6 +42,7 @@
 	FDST_NOW,
 	FDST_SPECIFIED,
 	FDST_X_AGO,
+	FDST_X_FUTURE,
 } FilterDatespec_type;
 
 struct _FilterDatespec {
@@ -52,7 +53,7 @@
 	
 	/* 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 -ur evolution-2.7.3/filter/filter.glade my-evolution-2.7.3/filter/filter.glade
--- evolution-2.7.3/filter/filter.glade	2005-12-20 11:21:51.000000000 -0700
+++ my-evolution-2.7.3/filter/filter.glade	2006-06-28 17:26:00.000000000 -0600
@@ -12,6 +12,13 @@
   <property name="modal">False</property>
   <property name="resizable">True</property>
   <property name="destroy_with_parent">False</property>
+  <property name="decorated">True</property>
+  <property name="skip_taskbar_hint">False</property>
+  <property name="skip_pager_hint">False</property>
+  <property name="type_hint">GDK_WINDOW_TYPE_HINT_NORMAL</property>
+  <property name="gravity">GDK_GRAVITY_NORTH_WEST</property>
+  <property name="focus_on_map">True</property>
+  <property name="urgency_hint">False</property>
 
   <child>
     <widget class="GtkVBox" id="rule_editor">
@@ -21,7 +28,7 @@
       <property name="spacing">6</property>
 
       <child>
-        <widget class="GtkLabel" id="label17">
+	<widget class="GtkLabel" id="label17">
 	  <property name="visible">True</property>
 	  <property name="label" translatable="yes">Show filters for mail:</property>
 	  <property name="use_underline">False</property>
@@ -33,6 +40,10 @@
 	  <property name="yalign">0.5</property>
 	  <property name="xpad">0</property>
 	  <property name="ypad">0</property>
+	  <property name="ellipsize">PANGO_ELLIPSIZE_NONE</property>
+	  <property name="width_chars">-1</property>
+	  <property name="single_line_mode">False</property>
+	  <property name="angle">0</property>
 	</widget>
 	<packing>
 	  <property name="padding">0</property>
@@ -86,6 +97,10 @@
 	      <property name="yalign">0.5</property>
 	      <property name="xpad">0</property>
 	      <property name="ypad">0</property>
+	      <property name="ellipsize">PANGO_ELLIPSIZE_NONE</property>
+	      <property name="width_chars">-1</property>
+	      <property name="single_line_mode">False</property>
+	      <property name="angle">0</property>
 	    </widget>
 	    <packing>
 	      <property name="padding">0</property>
@@ -113,6 +128,10 @@
 		  <property name="yalign">0.5</property>
 		  <property name="xpad">0</property>
 		  <property name="ypad">0</property>
+		  <property name="ellipsize">PANGO_ELLIPSIZE_NONE</property>
+		  <property name="width_chars">-1</property>
+		  <property name="single_line_mode">False</property>
+		  <property name="angle">0</property>
 		</widget>
 		<packing>
 		  <property name="padding">0</property>
@@ -162,6 +181,7 @@
 			      <property name="label">gtk-add</property>
 			      <property name="use_stock">True</property>
 			      <property name="relief">GTK_RELIEF_NORMAL</property>
+			      <property name="focus_on_click">True</property>
 			    </widget>
 			  </child>
 
@@ -173,6 +193,7 @@
 			      <property name="label" translatable="yes">_Edit</property>
 			      <property name="use_underline">True</property>
 			      <property name="relief">GTK_RELIEF_NORMAL</property>
+			      <property name="focus_on_click">True</property>
 			    </widget>
 			  </child>
 
@@ -184,6 +205,7 @@
 			      <property name="label">gtk-remove</property>
 			      <property name="use_stock">True</property>
 			      <property name="relief">GTK_RELIEF_NORMAL</property>
+			      <property name="focus_on_click">True</property>
 			    </widget>
 			  </child>
 
@@ -195,6 +217,7 @@
 			      <property name="label">gtk-goto-top</property>
 			      <property name="use_stock">True</property>
 			      <property name="relief">GTK_RELIEF_NORMAL</property>
+			      <property name="focus_on_click">True</property>
 			    </widget>
 			  </child>
 
@@ -206,6 +229,7 @@
 			      <property name="label">gtk-go-up</property>
 			      <property name="use_stock">True</property>
 			      <property name="relief">GTK_RELIEF_NORMAL</property>
+			      <property name="focus_on_click">True</property>
 			    </widget>
 			  </child>
 
@@ -217,6 +241,7 @@
 			      <property name="label">gtk-go-down</property>
 			      <property name="use_stock">True</property>
 			      <property name="relief">GTK_RELIEF_NORMAL</property>
+			      <property name="focus_on_click">True</property>
 			    </widget>
 			  </child>
 
@@ -228,6 +253,7 @@
 			      <property name="label">gtk-goto-bottom</property>
 			      <property name="use_stock">True</property>
 			      <property name="relief">GTK_RELIEF_NORMAL</property>
+			      <property name="focus_on_click">True</property>
 			    </widget>
 			  </child>
 			</widget>
@@ -278,6 +304,13 @@
   <property name="modal">False</property>
   <property name="resizable">True</property>
   <property name="destroy_with_parent">False</property>
+  <property name="decorated">True</property>
+  <property name="skip_taskbar_hint">False</property>
+  <property name="skip_pager_hint">False</property>
+  <property name="type_hint">GDK_WINDOW_TYPE_HINT_NORMAL</property>
+  <property name="gravity">GDK_GRAVITY_NORTH_WEST</property>
+  <property name="focus_on_map">True</property>
+  <property name="urgency_hint">False</property>
 
   <child>
     <widget class="GtkVBox" id="filter_datespec">
@@ -305,6 +338,10 @@
 	      <property name="yalign">0.5</property>
 	      <property name="xpad">0</property>
 	      <property name="ypad">0</property>
+	      <property name="ellipsize">PANGO_ELLIPSIZE_NONE</property>
+	      <property name="width_chars">-1</property>
+	      <property name="single_line_mode">False</property>
+	      <property name="angle">0</property>
 	    </widget>
 	    <packing>
 	      <property name="padding">0</property>
@@ -403,6 +440,10 @@
 		  <property name="yalign">0.5</property>
 		  <property name="xpad">0</property>
 		  <property name="ypad">0</property>
+		  <property name="ellipsize">PANGO_ELLIPSIZE_NONE</property>
+		  <property name="width_chars">-1</property>
+		  <property name="single_line_mode">False</property>
+		  <property name="angle">0</property>
 		</widget>
 		<packing>
 		  <property name="padding">0</property>
@@ -430,6 +471,10 @@
 	      <property name="yalign">0.5</property>
 	      <property name="xpad">0</property>
 	      <property name="ypad">0</property>
+	      <property name="ellipsize">PANGO_ELLIPSIZE_NONE</property>
+	      <property name="width_chars">-1</property>
+	      <property name="single_line_mode">False</property>
+	      <property name="angle">0</property>
 	    </widget>
 	    <packing>
 	      <property name="type">tab</property>
@@ -456,6 +501,10 @@
 		  <property name="yalign">0.5</property>
 		  <property name="xpad">0</property>
 		  <property name="ypad">0</property>
+		  <property name="ellipsize">PANGO_ELLIPSIZE_NONE</property>
+		  <property name="width_chars">-1</property>
+		  <property name="single_line_mode">False</property>
+		  <property name="angle">0</property>
 		</widget>
 		<packing>
 		  <property name="padding">0</property>
@@ -496,6 +545,10 @@
 	      <property name="yalign">0.5</property>
 	      <property name="xpad">0</property>
 	      <property name="ypad">0</property>
+	      <property name="ellipsize">PANGO_ELLIPSIZE_NONE</property>
+	      <property name="width_chars">-1</property>
+	      <property name="single_line_mode">False</property>
+	      <property name="angle">0</property>
 	    </widget>
 	    <packing>
 	      <property name="type">tab</property>
@@ -522,6 +575,10 @@
 		  <property name="yalign">0.5</property>
 		  <property name="xpad">0</property>
 		  <property name="ypad">0</property>
+		  <property name="ellipsize">PANGO_ELLIPSIZE_NONE</property>
+		  <property name="width_chars">-1</property>
+		  <property name="single_line_mode">False</property>
+		  <property name="angle">0</property>
 		</widget>
 		<packing>
 		  <property name="padding">0</property>
@@ -631,18 +688,32 @@
 		  </child>
 
 		  <child>
-		    <widget class="GtkLabel" id="label8">
+		    <widget class="GtkOptionMenu" id="option_past_future">
 		      <property name="visible">True</property>
-		      <property name="label" translatable="yes">ago</property>
-		      <property name="use_underline">False</property>
-		      <property name="use_markup">False</property>
-		      <property name="justify">GTK_JUSTIFY_CENTER</property>
-		      <property name="wrap">False</property>
-		      <property name="selectable">False</property>
-		      <property name="xalign">7.45058e-09</property>
-		      <property name="yalign">0.5</property>
-		      <property name="xpad">0</property>
-		      <property name="ypad">0</property>
+		      <property name="can_focus">True</property>
+		      <property name="history">0</property>
+
+		      <child internal-child="menu">
+			<widget class="GtkMenu" id="convertwidget31">
+			  <property name="visible">True</property>
+
+			  <child>
+			    <widget class="GtkMenuItem" id="convertwidget32">
+			      <property name="visible">True</property>
+			      <property name="label" translatable="yes">ago</property>
+			      <property name="use_underline">True</property>
+			    </widget>
+			  </child>
+
+			  <child>
+			    <widget class="GtkMenuItem" id="convertwidget33">
+			      <property name="visible">True</property>
+			      <property name="label" translatable="yes">in the future</property>
+			      <property name="use_underline">True</property>
+			    </widget>
+			  </child>
+			</widget>
+		      </child>
 		    </widget>
 		    <packing>
 		      <property name="padding">0</property>
@@ -677,6 +748,10 @@
 	      <property name="yalign">0.5</property>
 	      <property name="xpad">0</property>
 	      <property name="ypad">0</property>
+	      <property name="ellipsize">PANGO_ELLIPSIZE_NONE</property>
+	      <property name="width_chars">-1</property>
+	      <property name="single_line_mode">False</property>
+	      <property name="angle">0</property>
 	    </widget>
 	    <packing>
 	      <property name="type">tab</property>
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.