[PATCH] CVS Filters



	Hi all,
here is a small patch against current CVS : it corrects a FIXME of 
filter-file.c.
I'm trying to avoid big patches now (they seem to be buggy in general, and 
more difficult to manage anyway).
Please review it because I'm waiting woody release to update my system, 
and in the meantime I have no way to compile the cvs sources (I test all 
the changes with the balsa-1.2.3 sources, but still, bugs can escape me 
;-).
Thanks
Bye
Manu
diff -u ./filter-file.c /home/manu/prog/test/balsa-cvs/balsa/libbalsa/filter-file.c
--- ./filter-file.c	Mon Nov 26 10:07:00 2001
+++ /home/manu/prog/test/balsa-cvs/balsa/libbalsa/filter-file.c	Thu Nov 22 13:23:13 2001
@@ -122,6 +122,27 @@
  * Position filter_errno
  */
 
+/* Temporary struct used to ensure that we keep the same order for conditions
+   as specified by the user */
+
+typedef struct {
+    LibBalsaCondition * cnd;
+    gint order;
+} LibBalsaTempCondition;
+
+/* You'll note that this comparison function is inversed
+   That's for a purpose ;-)
+   I use it to avoid a g_list_reverse call (because the order
+   will already be reversed because of the choice of the reversed
+   comparison func) */
+
+static gint compare_conditions_order(gconstpointer  a,gconstpointer  b)
+{
+    const LibBalsaTempCondition * t1=a;
+    const LibBalsaTempCondition * t2=b;
+    return t2->order-t1->order;
+}
+
 void
 libbalsa_conditions_new_from_config(gchar * prefix,
                                     gchar * filter_section_name,
@@ -132,6 +153,7 @@
     gchar *tmp,* condprefix,*key;
     gint pref_len=strlen(CONDITION_SECTION_PREFIX)+strlen(filter_section_name);
     gint err=FILTER_NOERR;
+    GList * tmp_list=NULL;
 
     FILTER_SETFLAG(fil,FILTER_VALID);
     FILTER_SETFLAG(fil,FILTER_COMPILED);
@@ -158,15 +180,13 @@
 		    filter_errno=FILTER_NOERR;
 		    libbalsa_condition_free(cond);
 		}
-		/* FIXME: Ugly hack to preserve condition order in a
-		   filter. It seems that gnome section iterator always
-		   retrieve section in reverse order so I prepend the
-		   conditions to have good order at the end for now
-		   this hack works, but we'll have to fix that in the
-		   future (gnome_config could change and break our
-		   assumption) and use order of condition section key
-		   to insure order of condition */
-		else libbalsa_filter_prepend_condition(fil,cond);
+		else {
+		    LibBalsaTempCondition * tmp=g_new(LibBalsaTempCondition,1);
+		    
+		    tmp->cnd=cond;
+		    tmp->order=atoi(strrchr(key,':')+1);
+		    tmp_list=g_list_prepend(tmp_list,tmp);
+		}
 	    }
 	    else FILTER_CLRFLAG(fil,FILTER_VALID);
 	    gnome_config_pop_prefix();
@@ -175,8 +195,23 @@
     }
     g_free(tmp);
     /* We position filter_errno to the last non-critical error */
-    if (filter_errno==FILTER_NOERR)
+    if (filter_errno==FILTER_NOERR) {
+	LibBalsaTempCondition * tmp;
+
 	filter_errno=err;
+	/* We sort the list of temp conditions, then
+	   we populate the conditions list of the filter */
+	tmp_list=g_list_sort(tmp_list,compare_conditions_order);
+	for (;tmp_list;) {
+	    tmp=(LibBalsaTempCondition *)(tmp_list->data);
+	    libbalsa_filter_prepend_condition(fil,tmp->cnd);
+	    g_free(tmp);
+	    tmp_list=g_list_remove_link(tmp_list,tmp_list);
+	}
+	/* We don't do a g_list_reverse because the comparison func
+	   which dictate the order of the list after the sort is already
+	   reversed */
+    }
 }
 
 /* End of helper functions */
@@ -228,11 +263,13 @@
     gnome_config_set_int("Match-fields",cond->match_fields);
 
     /* We clean all other keys, to have a clean config file */
-    gnome_config_clean_key("Match-string");
-    gnome_config_clean_key("Reg-exps");
-    gnome_config_clean_key("Low-date");
-    gnome_config_clean_key("High-date");
-    gnome_config_clean_key("Flags");
+    if (cond->type!=CONDITION_SIMPLE) gnome_config_clean_key("Match-string");
+    if (cond->type!=CONDITION_REGEX) gnome_config_clean_key("Reg-exps");
+    if (cond->type!=CONDITION_DATE) {
+	gnome_config_clean_key("Low-date");
+	gnome_config_clean_key("High-date");
+    }
+    if (cond->type!=CONDITION_FLAG) gnome_config_clean_key("Flags");
 
     switch(cond->type) {
     case CONDITION_SIMPLE:


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]