diff options
author | Milan Crha <mcrha@redhat.com> | 2008-06-09 18:50:54 +0800 |
---|---|---|
committer | Milan Crha <mcrha@src.gnome.org> | 2008-06-09 18:50:54 +0800 |
commit | f1cfc8c031380ebd6f4c5fcd681ba1cc4e77f967 (patch) | |
tree | efb82364d33cceaa2a990582de1b1c3b4b652fc7 /filter | |
parent | 7d4f83689a512f3af1a4002a1567ffbb2762ebb9 (diff) | |
download | gsoc2013-evolution-f1cfc8c031380ebd6f4c5fcd681ba1cc4e77f967.tar.gz gsoc2013-evolution-f1cfc8c031380ebd6f4c5fcd681ba1cc4e77f967.tar.zst gsoc2013-evolution-f1cfc8c031380ebd6f4c5fcd681ba1cc4e77f967.zip |
** Fix for bug #201011
2008-06-09 Milan Crha <mcrha@redhat.com>
** Fix for bug #201011
* filter/filter-rule.h: (struct _FilterRule): New property 'enabled'
to be able to disable filter rules.
* filter/filter-rule.c: (filter_rule_init), (rule_eq), (xml_encode),
(xml_decode), (rule_copy): Store/restore/use 'enabled' value.
* filter/rule-editor.c: (add_editor_response), (rule_move), (set_source):
Set the 'enabled' column properly.
* filter/rule-editor.c: (rule_able_toggled), (rule_editor_treeview_new):
Add column "Enabled" to the tree, but have it hidden by default, only
those whom supports it can show it.
* mail/em-filter-editor.c: (em_filter_editor_construct):
Show Enabled column in the editor, because we support it here.
* mail/mail-session.c: (main_get_filter_driver): Skip disabled rules.
svn path=/trunk/; revision=35620
Diffstat (limited to 'filter')
-rw-r--r-- | filter/ChangeLog | 14 | ||||
-rw-r--r-- | filter/filter-rule.c | 17 | ||||
-rw-r--r-- | filter/filter-rule.h | 2 | ||||
-rw-r--r-- | filter/rule-editor.c | 47 |
4 files changed, 75 insertions, 5 deletions
diff --git a/filter/ChangeLog b/filter/ChangeLog index 32e27840e1..269362e0d3 100644 --- a/filter/ChangeLog +++ b/filter/ChangeLog @@ -1,3 +1,17 @@ +2008-06-09 Milan Crha <mcrha@redhat.com> + + ** Fix for bug #201011 + + * filter-rule.h: (struct _FilterRule): New property 'enabled' + to be able to disable filter rules. + * filter-rule.c: (filter_rule_init), (rule_eq), (xml_encode), + (xml_decode), (rule_copy): Store/restore/use 'enabled' value. + * rule-editor.c: (add_editor_response), (rule_move), (set_source): + Set the 'enabled' column properly. + * rule-editor.c: (rule_able_toggled), (rule_editor_treeview_new): + Add column "Enabled" to the tree, but have it hidden by default, only + those whom supports it can show it. + 2008-06-03 Kjartan Maraas <kmaraas@gnome.org> * filter-part.c: (main): gtk_window_set_policy -> diff --git a/filter/filter-rule.c b/filter/filter-rule.c index 2dfb0b7fd6..4d5d76505c 100644 --- a/filter/filter-rule.c +++ b/filter/filter-rule.c @@ -121,6 +121,7 @@ static void filter_rule_init (FilterRule *fr) { fr->priv = g_malloc0 (sizeof (*fr->priv)); + fr->enabled = TRUE; } static void @@ -258,7 +259,8 @@ list_eq(GList *al, GList *bl) static int rule_eq (FilterRule *fr, FilterRule *cm) { - return fr->grouping == cm->grouping + return fr->enabled == cm->enabled + && fr->grouping == cm->grouping && fr->threading == fr->threading && ((fr->name && cm->name && strcmp (fr->name, cm->name) == 0) || (fr->name == NULL && cm->name == NULL)) @@ -282,6 +284,9 @@ xml_encode (FilterRule *fr) GList *l; node = xmlNewNode (NULL, (const unsigned char *)"rule"); + + xmlSetProp (node, (const unsigned char *)"enabled", (const unsigned char *)(fr->enabled ? "true" : "false")); + switch (fr->grouping) { case FILTER_GROUP_ALL: xmlSetProp (node, (const unsigned char *)"grouping", (const unsigned char *)"all"); @@ -390,6 +395,14 @@ xml_decode (FilterRule *fr, xmlNodePtr node, RuleContext *f) fr->name = NULL; } + grouping = (char *)xmlGetProp (node, (const unsigned char *)"enabled"); + if (!grouping) + fr->enabled = TRUE; + else { + fr->enabled = strcmp (grouping, "false") != 0; + xmlFree (grouping); + } + grouping = (char *)xmlGetProp (node, (const unsigned char *)"grouping"); if (!strcmp (grouping, "any")) fr->grouping = FILTER_GROUP_ANY; @@ -447,6 +460,8 @@ rule_copy (FilterRule *dest, FilterRule *src) { GList *node; + dest->enabled = src->enabled; + g_free (dest->name); dest->name = g_strdup (src->name); diff --git a/filter/filter-rule.h b/filter/filter-rule.h index 19c3f0941a..924bf44459 100644 --- a/filter/filter-rule.h +++ b/filter/filter-rule.h @@ -72,6 +72,8 @@ struct _FilterRule { unsigned int system:1; /* this is a system rule, cannot be edited/deleted */ GList *parts; + + gboolean enabled; }; struct _FilterRuleClass { diff --git a/filter/rule-editor.c b/filter/rule-editor.c index cc60d4fa8a..40f045dbf9 100644 --- a/filter/rule-editor.c +++ b/filter/rule-editor.c @@ -338,7 +338,7 @@ add_editor_response (GtkWidget *dialog, int button, RuleEditor *re) g_object_ref (re->edit); gtk_list_store_append (re->model, &iter); - gtk_list_store_set (re->model, &iter, 0, re->edit->name, 1, re->edit, -1); + gtk_list_store_set (re->model, &iter, 0, re->edit->name, 1, re->edit, 2, re->edit->enabled, -1); selection = gtk_tree_view_get_selection (re->list); gtk_tree_selection_select_iter (selection, &iter); @@ -557,7 +557,7 @@ rule_move (RuleEditor *re, int from, int to) gtk_list_store_insert (re->model, &iter, to); /* set the data on the row */ - gtk_list_store_set (re->model, &iter, 0, rule->name, 1, rule, -1); + gtk_list_store_set (re->model, &iter, 0, rule->name, 1, rule, 2, rule->enabled, -1); /* select the row */ selection = gtk_tree_view_get_selection (re->list); @@ -713,7 +713,7 @@ set_source (RuleEditor *re, const char *source) while ((rule = rule_context_next_rule (re->context, rule, source)) != NULL) { d(printf("Adding row '%s'\n", rule->name)); gtk_list_store_append (re->model, &iter); - gtk_list_store_set (re->model, &iter, 0, rule->name, 1, rule, -1); + gtk_list_store_set (re->model, &iter, 0, rule->name, 1, rule, 2, rule->enabled, -1); } g_free (re->source); @@ -722,6 +722,33 @@ set_source (RuleEditor *re, const char *source) rule_editor_set_sensitive (re); } +static void +rule_able_toggled (GtkCellRendererToggle *renderer, char *arg1, gpointer user_data) +{ + GtkWidget *table = user_data; + GtkTreeSelection *selection; + GtkTreeModel *model; + GtkTreePath *path; + GtkTreeIter iter; + + path = gtk_tree_path_new_from_string (arg1); + model = gtk_tree_view_get_model (GTK_TREE_VIEW (table)); + selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (table)); + + if (gtk_tree_model_get_iter (model, &iter, path)) { + FilterRule *rule = NULL; + + gtk_tree_model_get (model, &iter, 1, &rule, -1); + + if (rule) { + rule->enabled = !rule->enabled; + gtk_list_store_set (GTK_LIST_STORE (model), &iter, 2, rule->enabled, -1); + } + } + + gtk_tree_path_free (path); +} + GtkWidget *rule_editor_treeview_new (char *widget_name, char *string1, char *string2, int int1, int int2); @@ -732,16 +759,28 @@ rule_editor_treeview_new (char *widget_name, char *string1, char *string2, int i GtkTreeSelection *selection; GtkCellRenderer *renderer; GtkListStore *model; + GtkTreeViewColumn *column; scrolled = gtk_scrolled_window_new (NULL, NULL); gtk_scrolled_window_set_shadow_type (GTK_SCROLLED_WINDOW (scrolled), GTK_SHADOW_IN); gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scrolled), GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC); - model = gtk_list_store_new (2, G_TYPE_STRING, G_TYPE_POINTER); + model = gtk_list_store_new (3, G_TYPE_STRING, G_TYPE_POINTER, G_TYPE_BOOLEAN); table = gtk_tree_view_new_with_model ((GtkTreeModel *) model); gtk_tree_view_set_headers_visible ((GtkTreeView *) table, FALSE); + renderer = gtk_cell_renderer_toggle_new (); + g_object_set (G_OBJECT (renderer), "activatable", TRUE, NULL); + gtk_tree_view_insert_column_with_attributes ((GtkTreeView *) table, -1, + _("Enabled"), renderer, + "active", 2, NULL); + g_signal_connect (renderer, "toggled", G_CALLBACK (rule_able_toggled), table); + + /* hide enable column by default */ + column = gtk_tree_view_get_column (GTK_TREE_VIEW (table), 0); + gtk_tree_view_column_set_visible (column, FALSE); + renderer = gtk_cell_renderer_text_new (); gtk_tree_view_insert_column_with_attributes ((GtkTreeView *) table, -1, _("Rule name"), renderer, |