2006-05-13 [wwp] 2.2.0cvs13
authorTristan Chabredier <wwp@claws-mail.org>
Sat, 13 May 2006 13:04:55 +0000 (13:04 +0000)
committerTristan Chabredier <wwp@claws-mail.org>
Sat, 13 May 2006 13:04:55 +0000 (13:04 +0000)
* src/filtering.c
* src/filtering.h
* src/matcher.c
* src/matcher_parser_lex.l
* src/matcher_parser_parse.y
* src/prefs_filtering.c
new feature: provide the ability to disable filtering and processing
rules. Patch by Fabien Vantard <fzzzzz@gmail.com>, w/ some minor
adaptations.

ChangeLog
PATCHSETS
configure.ac
src/filtering.c
src/filtering.h
src/matcher.c
src/matcher_parser_lex.l
src/matcher_parser_parse.y
src/prefs_filtering.c

index f95ddba..f718055 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,15 @@
+2006-05-13 [wwp]       2.2.0cvs13
+
+       * src/filtering.c
+       * src/filtering.h
+       * src/matcher.c
+       * src/matcher_parser_lex.l
+       * src/matcher_parser_parse.y
+       * src/prefs_filtering.c
+               new feature: provide the ability to disable filtering and processing
+               rules. Patch by Fabien Vantard <fzzzzz@gmail.com>, w/ some minor
+               adaptations.
+
 2006-05-13 [colin]     2.2.0cvs12
 
        * src/compose.c
index 5f13366..c483a85 100644 (file)
--- a/PATCHSETS
+++ b/PATCHSETS
 ( cvs diff -u -r 1.1.2.4 -r 1.1.2.5 RELEASE_NOTES;  ) > 2.2.0cvs10.patchset
 ( cvs diff -u -r 1.8.2.17 -r 1.8.2.18 src/export.c;  cvs diff -u -r 1.13.2.16 -r 1.13.2.17 src/import.c;  cvs diff -u -r 1.274.2.109 -r 1.274.2.110 src/mainwindow.c;  cvs diff -u -r 1.28.2.13 -r 1.28.2.14 src/mbox.c;  cvs diff -u -r 1.395.2.197 -r 1.395.2.198 src/summaryview.c;  cvs diff -u -r 1.68.2.23 -r 1.68.2.24 src/summaryview.h;  ) > 2.2.0cvs11.patchset
 ( cvs diff -u -r 1.382.2.270 -r 1.382.2.271 src/compose.c;  ) > 2.2.0cvs12.patchset
+( cvs diff -u -r 1.60.2.15 -r 1.60.2.16 src/filtering.c;  cvs diff -u -r 1.21.2.6 -r 1.21.2.7 src/filtering.h;  cvs diff -u -r 1.75.2.21 -r 1.75.2.22 src/matcher.c;  cvs diff -u -r 1.16.2.5 -r 1.16.2.6 src/matcher_parser_lex.l;  cvs diff -u -r 1.25.2.13 -r 1.25.2.14 src/matcher_parser_parse.y;  cvs diff -u -r 1.59.2.33 -r 1.59.2.34 src/prefs_filtering.c;  ) > 2.2.0cvs13.patchset
index 482bed8..9f01ab0 100644 (file)
@@ -11,7 +11,7 @@ MINOR_VERSION=2
 MICRO_VERSION=0
 INTERFACE_AGE=0
 BINARY_AGE=0
-EXTRA_VERSION=12
+EXTRA_VERSION=13
 EXTRA_RELEASE=
 EXTRA_GTK2_VERSION=
 
index 6437f86..3408aeb 100644 (file)
@@ -82,13 +82,15 @@ void filteringaction_free(FilteringAction * action)
        g_free(action);
 }
 
-FilteringProp * filteringprop_new(const gchar *name,
+FilteringProp * filteringprop_new(gboolean enabled,
+                                 const gchar *name,
                                  MatcherList * matchers,
                                  GSList * action_list)
 {
        FilteringProp * filtering;
 
        filtering = g_new0(FilteringProp, 1);
+       filtering->enabled = enabled;
        filtering->name = name ? g_strdup(name): NULL;
        filtering->matchers = matchers;
        filtering->action_list = action_list;
@@ -143,6 +145,7 @@ FilteringProp * filteringprop_copy(FilteringProp *src)
                     filteringaction_copy(filtering_action));
         }
 
+       new->enabled = src->enabled;
        new->name = g_strdup(src->name);
 
        return new;
@@ -469,7 +472,7 @@ static gboolean filter_msginfo(GSList * filtering_list, MsgInfo * info)
        for (l = filtering_list, final = FALSE, apply_next = FALSE; l != NULL; l = g_slist_next(l)) {
                FilteringProp * filtering = (FilteringProp *) l->data;
 
-               if (filtering_match_condition(filtering, info)) {
+               if (filtering->enabled && filtering_match_condition(filtering, info)) {
                        apply_next = filtering_apply_rule(filtering, info, &final);
                         if (final)
                                 break;
index bc30442..09e8e4e 100644 (file)
@@ -36,6 +36,7 @@ struct _FilteringAction {
 typedef struct _FilteringAction FilteringAction;
 
 struct _FilteringProp {
+       gboolean enabled;
        gchar *name;
        MatcherList * matchers;
        GSList * action_list;
@@ -53,7 +54,8 @@ void filteringaction_free(FilteringAction *action);
 FilteringAction * filteringaction_parse(gchar **str);
 gboolean filteringaction_apply_action_list (GSList *action_list, MsgInfo *info);
 
-FilteringProp * filteringprop_new(const gchar *name,
+FilteringProp * filteringprop_new(gboolean enabled,
+                                 const gchar *name,
                                  MatcherList *matchers,
                                  GSList *action_list);
 void filteringprop_free(FilteringProp *prop);
index ad9eced..e63009c 100644 (file)
@@ -1438,7 +1438,19 @@ static void prefs_filtering_write(FILE *fp, GSList *prefs_filtering)
                
                if (NULL == (filtering_str = filteringprop_to_string(prop)))
                        continue;
-                               
+
+               if (prop->enabled) {
+                       if (fputs("enabled ", fp) == EOF) {
+                               FILE_OP_ERROR("filtering config", "fputs || fputc");
+                               return;
+                       }
+               } else {
+                       if (fputs("disabled ", fp) == EOF) {
+                               FILE_OP_ERROR("filtering config", "fputs || fputc");
+                               return;
+                       }
+               }
+
                if (fputs("rulename \"", fp) == EOF) {
                        FILE_OP_ERROR("filtering config", "fputs || fputc");
                        g_free(filtering_str);
index 6dd3b11..46ed018 100644 (file)
@@ -113,5 +113,11 @@ void matcher_parser_init(void)
 rulename       {
                return MATCHER_RULENAME;
                }
+disabled       {
+               return MATCHER_DISABLED;
+               }
+enabled        {
+               return MATCHER_ENABLED;
+               }
 
 %%
index e29ffff..a17f266 100644 (file)
@@ -43,6 +43,7 @@ static MatcherProp *prop;
 
 static GSList *matchers_list = NULL;
 
+static gboolean enabled = TRUE;
 static gchar *name = NULL;
 static MatcherList *cond;
 static GSList *action_list = NULL;
@@ -56,6 +57,7 @@ static int enable_compatibility = 0;
 enum {
         MATCHER_PARSE_FILE,
         MATCHER_PARSE_NO_EOL,
+       MATCHER_PARSE_ENABLED,
        MATCHER_PARSE_NAME,
         MATCHER_PARSE_CONDITION,
         MATCHER_PARSE_FILTERING_ACTION,
@@ -279,6 +281,7 @@ int matcher_parserwrap(void)
 
 %start file
 
+%token MATCHER_ENABLED MATCHER_DISABLED
 %token MATCHER_RULENAME
 %token <str> MATCHER_STRING
 %token <str> MATCHER_SECTION
@@ -344,7 +347,9 @@ MATCHER_SECTION MATCHER_EOL
 ;
 
 instruction:
-name condition filtering MATCHER_EOL
+enabled name condition filtering MATCHER_EOL
+| enabled name condition filtering
+| name condition filtering MATCHER_EOL
 | name condition filtering
 {
        if (matcher_parse_op == MATCHER_PARSE_NO_EOL)
@@ -354,6 +359,15 @@ name condition filtering MATCHER_EOL
                YYERROR;
        }
 }
+| enabled
+{
+       if (matcher_parse_op == MATCHER_PARSE_ENABLED)
+               YYACCEPT;
+       else {
+               matcher_parsererror("parse error enabled");
+               YYERROR;
+       }
+}
 | name
 {
        if (matcher_parse_op == MATCHER_PARSE_NAME)
@@ -384,6 +398,17 @@ name condition filtering MATCHER_EOL
 | MATCHER_EOL
 ;
 
+enabled:
+MATCHER_ENABLED
+{
+       enabled = TRUE;
+}
+| MATCHER_DISABLED
+{
+       enabled = FALSE;
+}
+;
+
 name:
 MATCHER_RULENAME MATCHER_STRING
 {
@@ -394,8 +419,9 @@ MATCHER_RULENAME MATCHER_STRING
 filtering:
 filtering_action_list
 {
-       filtering = filteringprop_new(name, cond, action_list);
-        g_free(name);
+       filtering = filteringprop_new(enabled, name, cond, action_list);
+       enabled = TRUE;
+       g_free(name);
        name = NULL;
         if (enable_compatibility) {
                 prefs_filtering = &filtering_rules;
index 406ba3b..478f280 100644 (file)
@@ -55,6 +55,7 @@
 #include "prefs_filtering_action.h"
 
 enum {
+       PREFS_FILTERING_ENABLED,
        PREFS_FILTERING_NAME,
        PREFS_FILTERING_RULE,
        PREFS_FILTERING_PROP,
@@ -112,13 +113,16 @@ static void delete_path(GSList ** p_filters, const gchar * path);
 static GtkListStore* prefs_filtering_create_data_store (void);
 static gint prefs_filtering_list_view_insert_rule      (GtkListStore *list_store,
                                                         gint row,
+                                                        gboolean enabled,
                                                         const gchar *name, 
                                                         const gchar *rule, 
                                                         gboolean prop);
 static gchar *prefs_filtering_list_view_get_rule       (GtkWidget *list, 
                                                         gint row);
-static gchar *prefs_filtering_list_view_get_rule_name  (GtkWidget *list, 
-                                                        gint row);
+static void prefs_filtering_list_view_get_rule_name    (GtkWidget *list, 
+                                                        gint row,
+                                                        gboolean *enabled,
+                                                        gchar **name);
 
 static GtkWidget *prefs_filtering_list_view_create     (void);
 static void prefs_filtering_create_list_view_columns   (GtkWidget *list_view);
@@ -644,6 +648,7 @@ static void prefs_filtering_set_dialog(const gchar *header, const gchar *key)
 
        /* add the place holder (New) at row 0 */
        prefs_filtering_list_view_insert_rule(list_store, -1, 
+                                             FALSE,
                                              _("(New)"),
                                              _("(New)"),
                                              FALSE);
@@ -657,6 +662,7 @@ static void prefs_filtering_set_dialog(const gchar *header, const gchar *key)
                subst_char(cond_str, '\t', ':');
 
                prefs_filtering_list_view_insert_rule(list_store, -1, 
+                                                     prop->enabled,
                                                      prop->name,
                                                      cond_str, TRUE);
                
@@ -707,10 +713,16 @@ static void prefs_filtering_set_list(void)
                /* FIXME: this strcmp() is bogus: "(New)" should never
                 * be inserted in the storage */
                if (strcmp(filtering_str, _("(New)")) != 0) {
-                       gchar *name = prefs_filtering_list_view_get_rule_name(filtering.cond_list_view, row);
+                       gboolean enabled;
+                       gchar *name;
+
+                       prefs_filtering_list_view_get_rule_name(
+                                       filtering.cond_list_view, row,
+                                       &enabled, &name);
                        prop = matcher_parser_get_filtering(filtering_str);
                        g_free(filtering_str);
                        if (prop) {
+                               prop->enabled = enabled;
                                prop->name = name;
                                prefs_filtering = 
                                        g_slist_append(prefs_filtering, prop);
@@ -729,17 +741,25 @@ static gint prefs_filtering_list_view_set_row(gint row, FilteringProp * prop)
        gchar *str;
        GtkListStore *list_store;
        gchar *name = NULL;
-       
+       gboolean enabled = TRUE;
+
        str = filteringprop_to_string(prop);
        if (str == NULL)
                return -1;
-       
-       if (prop && prop->name)
-               name = prop->name;
+
+       if (prop) {
+               if (prop->name)
+                       name = prop->name;
+               enabled = prop->enabled;
+       }
 
        list_store = GTK_LIST_STORE(gtk_tree_view_get_model(list_view));
 
-       row = prefs_filtering_list_view_insert_rule(list_store, row, name, str, prop != NULL);
+       row = prefs_filtering_list_view_insert_rule(list_store, row,
+                                                   enabled,
+                                                   name,
+                                                   str,
+                                                   prop != NULL);
 
        g_free(str);
 
@@ -830,6 +850,7 @@ static void prefs_filtering_action_define(void)
 static FilteringProp * prefs_filtering_dialog_to_filtering(gboolean alert)
 {
        MatcherList * cond;
+       gboolean enabled = TRUE;
        gchar * name = NULL;
        gchar * cond_str = NULL;
        gchar * action_str = NULL;
@@ -865,7 +886,7 @@ static FilteringProp * prefs_filtering_dialog_to_filtering(gboolean alert)
                goto fail;
        }
 
-       prop = filteringprop_new(name, cond, action_list);
+       prop = filteringprop_new(enabled, name, cond, action_list);
 
 fail:
        g_free(name);
@@ -1128,6 +1149,7 @@ static void prefs_filtering_cancel(void)
 static GtkListStore* prefs_filtering_create_data_store(void)
 {
        return gtk_list_store_new(N_PREFS_FILTERING_COLUMNS,
+                                 G_TYPE_BOOLEAN,
                                  G_TYPE_STRING,
                                  G_TYPE_STRING,
                                  G_TYPE_BOOLEAN,
@@ -1142,6 +1164,8 @@ static GtkListStore* prefs_filtering_create_data_store(void)
  *\param       list_store Store to operate on
  *\param       row -1 to add a new rule to store, else change an existing
  *             row
+ *\param       enabled TRUE if rule is enabled
+ *\param       name The Name of rule
  *\param       rule String representation of rule
  *\param       prop TRUE if valid filtering rule; if FALSE it's the first
  *             entry in the store ("(New)").
@@ -1150,6 +1174,7 @@ static GtkListStore* prefs_filtering_create_data_store(void)
  */
 static gint prefs_filtering_list_view_insert_rule(GtkListStore *list_store,
                                                  gint row,
+                                                 gboolean enabled,
                                                  const gchar *name,
                                                  const gchar *rule,
                                                  gboolean prop) 
@@ -1167,6 +1192,7 @@ static gint prefs_filtering_list_view_insert_rule(GtkListStore *list_store,
                /* append new */
                gtk_list_store_append(list_store, &iter);
                gtk_list_store_set(list_store, &iter, 
+                                  PREFS_FILTERING_ENABLED, enabled,
                                   PREFS_FILTERING_NAME, name,
                                   PREFS_FILTERING_RULE, rule,
                                   PREFS_FILTERING_PROP, prop,
@@ -1176,6 +1202,7 @@ static gint prefs_filtering_list_view_insert_rule(GtkListStore *list_store,
        } else {
                /* change existing */
                gtk_list_store_set(list_store, &iter, 
+                                  PREFS_FILTERING_ENABLED, enabled,
                                   PREFS_FILTERING_NAME, name,
                                   PREFS_FILTERING_RULE, rule,
                                   -1);
@@ -1203,21 +1230,21 @@ static gchar *prefs_filtering_list_view_get_rule(GtkWidget *list, gint row)
        return result;
 }
 
-static gchar *prefs_filtering_list_view_get_rule_name(GtkWidget *list, gint row)
+static void prefs_filtering_list_view_get_rule_name(GtkWidget *list, gint row, gboolean *enabled, gchar **name)
 {      
        GtkTreeView *list_view = GTK_TREE_VIEW(list);
        GtkTreeModel *model = gtk_tree_view_get_model(list_view);
        GtkTreeIter iter;
-       gchar *result = NULL;
 
-       if (!gtk_tree_model_iter_nth_child(model, &iter, NULL, row))
-               return NULL;
-       
-       gtk_tree_model_get(model, &iter, 
-                          PREFS_FILTERING_NAME, &result,
-                          -1);
-       
-       return result;
+       *enabled = TRUE;
+       *name = NULL;
+
+       if (gtk_tree_model_iter_nth_child(model, &iter, NULL, row)) {
+               gtk_tree_model_get(model, &iter, 
+                                  PREFS_FILTERING_ENABLED, enabled,
+                                  PREFS_FILTERING_NAME, name,
+                                  -1);
+       }
 }
 
 /*!
@@ -1245,11 +1272,46 @@ static GtkWidget *prefs_filtering_list_view_create(void)
        return GTK_WIDGET(list_view);
 }
 
+static void prefs_filtering_enable_toggled(GtkCellRendererToggle *widget,
+               gchar *path,
+               GtkWidget *list_view)
+{
+       GtkTreeIter iter;
+       GtkTreeModel *model = gtk_tree_view_get_model(GTK_TREE_VIEW(list_view));
+       gboolean enabled = TRUE;
+
+       if (!gtk_tree_model_get_iter_from_string(model, &iter, path))
+               return;
+
+       gtk_tree_model_get(model, &iter,
+                          PREFS_FILTERING_ENABLED, &enabled,
+                          -1);
+
+       gtk_list_store_set(GTK_LIST_STORE(model), &iter,
+                          PREFS_FILTERING_ENABLED, !enabled,
+                          -1);
+}
+
 static void prefs_filtering_create_list_view_columns(GtkWidget *list_view)
 {
        GtkTreeViewColumn *column;
        GtkCellRenderer *renderer;
 
+       renderer = gtk_cell_renderer_toggle_new();
+       g_object_set(renderer,
+                    "radio", FALSE,
+                    "activatable", TRUE,
+                    NULL);
+       column = gtk_tree_view_column_new_with_attributes
+               (_("Enable"), /* FIXME : Enable, Enabled, or 'E' ? */
+                renderer,
+                "active", PREFS_FILTERING_ENABLED,
+                NULL);
+       gtk_tree_view_append_column(GTK_TREE_VIEW(list_view), column);
+       g_signal_connect(G_OBJECT(renderer), "toggled",
+                        G_CALLBACK(prefs_filtering_enable_toggled),
+                        list_view);
+
        renderer = gtk_cell_renderer_text_new();
        column = gtk_tree_view_column_new_with_attributes
                (_("Name"),