Fix memory leaks from results of gtk_tree_model_get().
[claws.git] / src / prefs_filtering.c
index bf95b4ce3586e202c2a3e99e926b1dd33549067c..8424ff8932bc49d023169b745935636b1bc2f4e9 100644 (file)
@@ -1,6 +1,6 @@
 /*
  * Sylpheed -- a GTK+ based, lightweight, and fast e-mail client
- * Copyright (C) 1999-2007 Hiroyuki Yamamoto and the Claws Mail team
+ * Copyright (C) 1999-2013 Hiroyuki Yamamoto and the Claws Mail team
  *
  * This program is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
@@ -19,6 +19,7 @@
 
 #ifdef HAVE_CONFIG_H
 #  include "config.h"
+#include "claws-features.h"
 #endif
 
 #include "defs.h"
@@ -26,7 +27,6 @@
 #include <glib.h>
 #include <glib/gi18n.h>
 #include <gtk/gtk.h>
-#include <gtk/gtkoptionmenu.h>
 #include <gdk/gdkkeysyms.h>
 #include <stdio.h>
 #include <stdlib.h>
 #include "gtkutils.h"
 #include "alertpanel.h"
 #include "folder.h"
+#include "folder_item_prefs.h"
 #include "filtering.h"
 #include "addr_compl.h"
 #include "manual.h"
 #include "combobox.h"
 #include "menu.h"
+#include "account.h"
 
 #include "matcher_parser.h"
 #include "matcher.h"
@@ -115,6 +117,8 @@ static void prefs_filtering_bottom  (gpointer action, gpointer data);
 static gint prefs_filtering_deleted    (GtkWidget      *widget,
                                         GdkEventAny    *event,
                                         gpointer        data);
+static void prefs_filtering_row_selected(GtkTreeSelection *selection,
+                                        GtkTreeView *list_view);
 static gboolean prefs_filtering_key_pressed(GtkWidget  *widget,
                                         GdkEventKey    *event,
                                         gpointer        data);
@@ -221,6 +225,7 @@ void prefs_filtering_open(GSList ** p_processing,
        }
 
        gtk_widget_show(filtering.window);
+       gtk_window_set_modal(GTK_WINDOW(filtering.window), TRUE);
 
        start_address_completion(NULL);
 }
@@ -228,7 +233,7 @@ void prefs_filtering_open(GSList ** p_processing,
 static void prefs_filtering_size_allocate_cb(GtkWidget *widget,
                                         GtkAllocation *allocation)
 {
-       g_return_if_fail(allocation != NULL);
+       cm_return_if_fail(allocation != NULL);
 
        prefs_common.filteringwin_width = allocation->width;
        prefs_common.filteringwin_height = allocation->height;
@@ -245,6 +250,7 @@ static void prefs_filtering_close(void)
                                (filtering.cond_list_view)));
        gtk_list_store_clear(store);
        gtk_widget_hide(filtering.window);
+       gtk_window_set_modal(GTK_WINDOW(filtering.window), FALSE);
        inc_unlock();
 }
 
@@ -255,14 +261,14 @@ static void prefs_filtering_account_option_menu_populate(void)
 
        accounts = account_get_list();
 
-       g_return_if_fail(accounts != NULL);
+       cm_return_if_fail(accounts != NULL);
 
-       COMBOBOX_ADD(filtering.account_combobox_list, Q_("Filtering Account Menu|All"), 0);
+       COMBOBOX_ADD(filtering.account_combobox_list, C_("Filtering Account Menu", "All"), 0);
+       COMBOBOX_ADD(filtering.account_combobox_list, NULL, 0);
        for (; accounts != NULL; accounts = accounts->next) {
                PrefsAccount *ac = (PrefsAccount *)accounts->data;
 
-               if (ac->protocol != A_NONE)
-                       COMBOBOX_ADD_ESCAPED(filtering.account_combobox_list, ac->account_name, ac->account_id);
+               COMBOBOX_ADD_ESCAPED(filtering.account_combobox_list, ac->account_name, ac->account_id);
        }
 }
 
@@ -329,14 +335,12 @@ static void prefs_filtering_create(void)
        GtkWidget *bottom_btn;
        GtkWidget *table;
        static GdkGeometry geometry;
-       CLAWS_TIP_DECL();
 
        debug_print("Creating filtering configuration window...\n");
 
        window = gtkut_window_new(GTK_WINDOW_TOPLEVEL, "prefs_filtering");
        gtk_container_set_border_width (GTK_CONTAINER (window), 8);
        gtk_window_set_position (GTK_WINDOW (window), GTK_WIN_POS_CENTER);
-       gtk_window_set_modal (GTK_WINDOW (window), TRUE);
        gtk_window_set_resizable(GTK_WINDOW (window), TRUE);
 
        vbox = gtk_vbox_new (FALSE, 6);
@@ -417,7 +421,7 @@ static void prefs_filtering_create(void)
                          (GtkAttachOptions) (GTK_FILL|GTK_EXPAND),
                          (GtkAttachOptions) (0), 0, 0);
 
-       cond_btn = gtk_button_new_with_label (_(" Define... "));
+       cond_btn =  gtk_button_new_with_mnemonic (_(" Def_ine... "));
        gtk_widget_show (cond_btn);
        gtk_table_attach (GTK_TABLE (table), cond_btn, 2, 3, 2, 3,
                          (GtkAttachOptions) (GTK_FILL),
@@ -439,7 +443,7 @@ static void prefs_filtering_create(void)
                          (GtkAttachOptions) (GTK_FILL|GTK_EXPAND),
                          (GtkAttachOptions) (0), 0, 0);
 
-       action_btn = gtk_button_new_with_label (_(" Define... "));
+       action_btn =  gtk_button_new_with_mnemonic (_(" De_fine... "));
        gtk_widget_show (action_btn);
        gtk_table_attach (GTK_TABLE (table), action_btn, 2, 3, 3, 4,
                          (GtkAttachOptions) (GTK_FILL),
@@ -470,7 +474,7 @@ static void prefs_filtering_create(void)
        CLAWS_SET_TIP(reg_btn,
                        _("Append the new rule above to the list"));
 
-       subst_btn = gtkut_get_replace_btn (_("Replace"));
+       subst_btn = gtkut_get_replace_btn (_("_Replace"));
        gtk_widget_show (subst_btn);
        gtk_box_pack_start (GTK_BOX (btn_hbox), subst_btn, FALSE, TRUE, 0);
        g_signal_connect(G_OBJECT (subst_btn), "clicked",
@@ -479,15 +483,18 @@ static void prefs_filtering_create(void)
        CLAWS_SET_TIP(subst_btn,
                        _("Replace the selected rule in list with the rule above"));
 
-       del_btn = gtk_button_new_from_stock (GTK_STOCK_DELETE);
-       gtk_widget_show (del_btn);
+       del_btn = gtk_button_new_with_mnemonic (_("D_elete"));
+       gtk_button_set_image(GTK_BUTTON(del_btn),
+                       gtk_image_new_from_stock(GTK_STOCK_REMOVE,GTK_ICON_SIZE_BUTTON));
        gtk_box_pack_start (GTK_BOX (btn_hbox), del_btn, FALSE, TRUE, 0);
        g_signal_connect(G_OBJECT (del_btn), "clicked",
                        G_CALLBACK(prefs_filtering_delete_cb), NULL);
        CLAWS_SET_TIP(del_btn,
                        _("Delete the selected rule from the list"));
 
-       clear_btn = gtk_button_new_from_stock (GTK_STOCK_CLEAR);
+       clear_btn = gtk_button_new_with_mnemonic (_("C_lear"));
+       gtk_button_set_image(GTK_BUTTON(clear_btn),
+                       gtk_image_new_from_stock(GTK_STOCK_CLEAR,GTK_ICON_SIZE_BUTTON));
        gtk_widget_show (clear_btn);
        gtk_box_pack_start (GTK_BOX (btn_hbox), clear_btn, FALSE, TRUE, 0);
        g_signal_connect(G_OBJECT (clear_btn), "clicked",
@@ -501,6 +508,8 @@ static void prefs_filtering_create(void)
 
        cond_scrolledwin = gtk_scrolled_window_new (NULL, NULL);
        gtk_widget_show (cond_scrolledwin);
+       gtk_scrolled_window_set_shadow_type(GTK_SCROLLED_WINDOW(cond_scrolledwin),
+                                           GTK_SHADOW_ETCHED_IN);
        gtk_widget_set_size_request (cond_scrolledwin, -1, 150);
        gtk_box_pack_start (GTK_BOX (cond_hbox), cond_scrolledwin,
                            TRUE, TRUE, 0);
@@ -525,7 +534,7 @@ static void prefs_filtering_create(void)
                        _("Move the selected rule to the top"));
 
 #ifndef GENERIC_UMPC
-       page_up_btn = gtk_button_new_with_mnemonic (_("Page up"));
+       page_up_btn = gtk_button_new_with_mnemonic (_("Page u_p"));
        gtk_button_set_image(GTK_BUTTON(page_up_btn),
                        gtk_image_new_from_stock(GTK_STOCK_GO_UP,GTK_ICON_SIZE_BUTTON));
        gtk_widget_show (page_up_btn);
@@ -553,7 +562,7 @@ static void prefs_filtering_create(void)
                        _("Move the selected rule down"));
 
 #ifndef GENERIC_UMPC
-       page_down_btn = gtk_button_new_with_mnemonic (_("Page down"));
+       page_down_btn = gtk_button_new_with_mnemonic (_("Page dow_n"));
        gtk_button_set_image(GTK_BUTTON(page_down_btn),
                        gtk_image_new_from_stock(GTK_STOCK_GO_DOWN,GTK_ICON_SIZE_BUTTON));
        gtk_widget_show (page_down_btn);
@@ -645,81 +654,12 @@ void prefs_filtering_rename_path(const gchar *old_path, const gchar *new_path)
 static void rename_path(GSList * filters,
                        const gchar * old_path, const gchar * new_path)
 {
-       gchar *base;
-       gchar *prefix;
-       gchar *suffix;
-       gchar *dest_path;
-       gchar *old_path_with_sep;
-       gint destlen;
-       gint prefixlen;
-       gint oldpathlen;
-        GSList * action_cur;
         GSList * cur;
 
-       oldpathlen = strlen(old_path);
-       old_path_with_sep = g_strconcat(old_path,G_DIR_SEPARATOR_S,NULL);
-
        for (cur = filters; cur != NULL; cur = cur->next) {
                FilteringProp   *filtering = (FilteringProp *)cur->data;
-                
-                for(action_cur = filtering->action_list ; action_cur != NULL ;
-                    action_cur = action_cur->next) {
-
-                        FilteringAction *action = action_cur->data;
-                        
-                        if (action->type == MATCHACTION_SET_TAG ||
-                           action->type == MATCHACTION_UNSET_TAG)
-                               continue;
-                        if (!action->destination) 
-                               continue;
-                        
-                        destlen = strlen(action->destination);
-                        
-                        if (destlen > oldpathlen) {
-                                prefixlen = destlen - oldpathlen;
-                                suffix = action->destination + prefixlen;
-                                
-                                if (!strncmp(old_path, suffix, oldpathlen)) {
-                                        prefix = g_malloc0(prefixlen + 1);
-                                        strncpy2(prefix, action->destination, prefixlen);
-                                        
-                                        base = suffix + oldpathlen;
-                                        while (*base == G_DIR_SEPARATOR) base++;
-                                        if (*base == '\0')
-                                                dest_path = g_strconcat(prefix,
-                                                    G_DIR_SEPARATOR_S,
-                                                    new_path, NULL);
-                                        else
-                                                dest_path = g_strconcat(prefix,
-                                                    G_DIR_SEPARATOR_S,
-                                                    new_path,
-                                                    G_DIR_SEPARATOR_S,
-                                                    base, NULL);
-                                        
-                                        g_free(prefix);
-                                        g_free(action->destination);
-                                        action->destination = dest_path;
-                                } else { /* for non-leaf folders */
-                                        /* compare with trailing slash */
-                                        if (!strncmp(old_path_with_sep, action->destination, oldpathlen+1)) {
-                                                
-                                                suffix = action->destination + oldpathlen + 1;
-                                                dest_path = g_strconcat(new_path,
-                                                    G_DIR_SEPARATOR_S,
-                                                    suffix, NULL);
-                                                g_free(action->destination);
-                                                action->destination = dest_path;
-                                        }
-                                }
-                        } else {
-                                /* folder-moving a leaf */
-                                if (!strcmp(old_path, action->destination)) {
-                                        dest_path = g_strdup(new_path);
-                                        g_free(action->destination);
-                                        action->destination = dest_path;
-                                }
-                        }
-                }
+               filtering_action_list_rename_path(filtering->action_list,
+                                                 old_path, new_path);
         }
 }
 
@@ -735,9 +675,9 @@ static gboolean prefs_filtering_rename_path_func(GNode *node, gpointer data)
        old_path = paths[0];
        new_path = paths[1];
 
-       g_return_val_if_fail(old_path != NULL, FALSE);
-       g_return_val_if_fail(new_path != NULL, FALSE);
-       g_return_val_if_fail(node != NULL, FALSE);
+       cm_return_val_if_fail(old_path != NULL, FALSE);
+       cm_return_val_if_fail(new_path != NULL, FALSE);
+       cm_return_val_if_fail(node != NULL, FALSE);
 
         item = node->data;
         if (!item || !item->prefs)
@@ -788,9 +728,9 @@ static gboolean prefs_filtering_rename_tag_func(GNode *node, gpointer data)
        old_tag = tags[0];
        new_tag = tags[1];
 
-       g_return_val_if_fail(old_tag != NULL, FALSE);
-       g_return_val_if_fail(new_tag != NULL, FALSE);
-       g_return_val_if_fail(node != NULL, FALSE);
+       cm_return_val_if_fail(old_tag != NULL, FALSE);
+       cm_return_val_if_fail(new_tag != NULL, FALSE);
+       cm_return_val_if_fail(node != NULL, FALSE);
 
         item = node->data;
         if (!item || !item->prefs)
@@ -875,8 +815,8 @@ static gboolean prefs_filtering_delete_path_func(GNode *node, gpointer data)
        FolderItem *item;
         GSList ** p_filters;
        
-       g_return_val_if_fail(path != NULL, FALSE);
-       g_return_val_if_fail(node != NULL, FALSE);
+       cm_return_val_if_fail(path != NULL, FALSE);
+       cm_return_val_if_fail(node != NULL, FALSE);
 
         item = node->data;
         if (!item || !item->prefs)
@@ -926,7 +866,7 @@ static void prefs_filtering_set_dialog(const gchar *header, const gchar *key)
                                account_name = ac_prefs->account_name;
                }
                if (account_name == NULL)
-                       account_name = (gchar *)Q_("Filtering Account Menu|All");
+                       account_name = (gchar *)C_("Filtering Account Menu", "All");
 
                cond_str = filteringprop_to_string(prop);
                subst_char(cond_str, '\t', ':');
@@ -978,7 +918,7 @@ static gboolean prefs_filtering_search_func_cb (GtkTreeModel *model, gint column
        if (!store_string || !key) return FALSE;
 
 
-       retval = (strncmp (key, store_string, strlen(key)) != 0);
+       retval = (g_ascii_strncasecmp (key, store_string, strlen(key)) != 0);
 
        g_free(store_string);
        debug_print("selecting row\n");
@@ -1017,16 +957,18 @@ static void prefs_filtering_set_list(void)
                                        filtering.cond_list_view, row,
                                        &enabled, &name, &account_id);
                        prop = matcher_parser_get_filtering(filtering_str);
-                       g_free(filtering_str);
                        if (prop) {
                                prop->enabled = enabled;
+                               if (prop->name != NULL)
+                                       g_free(prop->name);
                                prop->name = name;
                                prop->account_id = account_id;
                                prefs_filtering = 
                                        g_slist_append(prefs_filtering, prop);
                        }
                }
-               
+
+               g_free(filtering_str);
                row++;
        }                               
        
@@ -1036,14 +978,15 @@ static void prefs_filtering_set_list(void)
 static gint prefs_filtering_list_view_set_row(gint row, FilteringProp * prop)
 {
        GtkTreeView *list_view = GTK_TREE_VIEW(filtering.cond_list_view);
-       gchar *str;
+       gchar *str = NULL;
        GtkListStore *list_store;
        gchar *name = NULL;
        gint account_id = 0;
-       gchar *account_name = (gchar *)Q_("Filtering Account Menu|All");
+       gchar *account_name = (gchar *)C_("Filtering Account Menu", "All");
        gboolean enabled = TRUE;
 
-       str = filteringprop_to_string(prop);
+       if (prop)
+               str = filteringprop_to_string(prop);
        if (str == NULL)
                return -1;
 
@@ -1240,13 +1183,16 @@ static void prefs_filtering_substitute_cb(gpointer action, gpointer data)
        prefs_filtering_list_view_get_rule_info(
                        filtering.cond_list_view, selected_row,
                        &enabled, &name, &account_id);
+       g_free(name); /* We're not using this. */
        prop->enabled = enabled;
 
        prefs_filtering_list_view_set_row(selected_row, prop);
 
        filteringprop_free(prop);
 
-       prefs_filtering_reset_dialog();
+       prefs_filtering_row_selected(gtk_tree_view_get_selection(
+                               GTK_TREE_VIEW(filtering.cond_list_view)),
+                               GTK_TREE_VIEW(filtering.cond_list_view));
        modified = TRUE;
 }
 
@@ -1263,7 +1209,7 @@ static void prefs_filtering_delete_cb(gpointer action, gpointer data)
 
        if (alertpanel(_("Delete rule"),
                       _("Do you really want to delete this rule?"),
-                      GTK_STOCK_CANCEL, "+"GTK_STOCK_DELETE, NULL) == G_ALERTDEFAULT)
+                      GTK_STOCK_CANCEL, GTK_STOCK_DELETE, NULL, ALERTFOCUS_SECOND) == G_ALERTDEFAULT)
                return;
 
        model = gtk_tree_view_get_model(list_view);     
@@ -1282,7 +1228,7 @@ static void prefs_filtering_delete_all_cb(gpointer action, gpointer data)
        
        if (alertpanel(_("Delete all rules"),
                       _("Do you really want to delete all the rules?"),
-                      GTK_STOCK_CANCEL, "+"GTK_STOCK_DELETE, NULL) == G_ALERTDEFAULT)
+                      GTK_STOCK_CANCEL, GTK_STOCK_DELETE, NULL, ALERTFOCUS_SECOND) == G_ALERTDEFAULT)
                return;
 
        list_store = GTK_LIST_STORE(gtk_tree_view_get_model(GTK_TREE_VIEW(filtering.cond_list_view)));
@@ -1318,6 +1264,7 @@ static void prefs_filtering_duplicate_cb(gpointer action, gpointer data)
        prefs_filtering_list_view_get_rule_info(
                        filtering.cond_list_view, selected_row,
                        &enabled, &name, &account_id);
+       g_free(name); /* We're not using this. */
        prop->enabled = enabled;
 
        prefs_filtering_list_view_set_row(-selected_row-2, prop);
@@ -1351,14 +1298,13 @@ static void prefs_filtering_top(gpointer action, gpointer data)
 
 static void prefs_filtering_page_up(gpointer action, gpointer data)
 {
-       gint row, target_row, n_rows;
+       gint row, target_row;
        GtkTreeIter selected, target;
        GtkTreeModel *model;
        GtkTreePath *path;
        GdkRectangle cell_rect, view_rect;
 
        model = gtk_tree_view_get_model(GTK_TREE_VIEW(filtering.cond_list_view));       
-       n_rows = gtk_tree_model_iter_n_children(model, NULL);
        row = gtkut_list_view_get_selected_row(filtering.cond_list_view);
        if (row <= 1)
                return;
@@ -1497,10 +1443,8 @@ static void prefs_filtering_select_set(FilteringProp *prop)
        gtk_entry_set_text(GTK_ENTRY(filtering.cond_entry), matcher_str);
 
         action_str = filteringaction_list_to_string(prop->action_list);
-       if (matcher_str == NULL) {
-               return;
-       }
-       gtk_entry_set_text(GTK_ENTRY(filtering.action_entry), action_str);
+       if (action_str != NULL)
+               gtk_entry_set_text(GTK_ENTRY(filtering.action_entry), action_str);
 
        g_free(action_str);
        g_free(matcher_str);
@@ -1516,7 +1460,7 @@ static gint prefs_filtering_deleted(GtkWidget *widget, GdkEventAny *event,
 static gboolean prefs_filtering_key_pressed(GtkWidget *widget, GdkEventKey *event,
                                     gpointer data)
 {
-       if (event && event->keyval == GDK_Escape) {
+       if (event && event->keyval == GDK_KEY_Escape) {
                prefs_filtering_cancel(NULL, NULL);
                return TRUE;                    
        }
@@ -1536,8 +1480,8 @@ static gboolean prefs_filtering_check_mod(gboolean check_changed_list)
        if (check_changed_list) {
                if (modified && alertpanel(_("Filtering rules not saved"),
                                         _("The list of filtering rules have been modified. Close anyway?"),
-                                        GTK_STOCK_CLOSE, _("+_Continue editing"), 
-                                        NULL) != G_ALERTDEFAULT) {
+                                        GTK_STOCK_CLOSE, _("_Continue editing"), NULL,
+                                        ALERTFOCUS_SECOND) != G_ALERTDEFAULT) {
                        return TRUE;
                }
        }
@@ -1558,7 +1502,7 @@ static gboolean prefs_filtering_check_mod(gboolean check_changed_list)
                if (!filtering_str) {
                        val = alertpanel(_("Entry not saved"),
                                 _("The entry was not saved. Close anyway?"),
-                                GTK_STOCK_CLOSE, _("+_Continue editing"), NULL);
+                                GTK_STOCK_CLOSE, _("_Continue editing"), NULL, ALERTFOCUS_SECOND);
                        if (G_ALERTDEFAULT != val) {
                                g_free(filtering_str);
                                g_free(str); /* fixed two leaks: huzzah! */
@@ -1580,7 +1524,7 @@ static gboolean prefs_filtering_check_mod(gboolean check_changed_list)
                    strlen(action)) {
                        val = alertpanel(_("Entry not saved"),
                                 _("The entry was not saved. Close anyway?"),
-                                GTK_STOCK_CLOSE, _("+_Continue editing"), NULL);
+                                GTK_STOCK_CLOSE, _("_Continue editing"), NULL, ALERTFOCUS_SECOND);
                        if (G_ALERTDEFAULT != val) {
                                g_free(name);
                                g_free(condition);
@@ -1762,6 +1706,21 @@ static GtkActionEntry prefs_filtering_popup_entries[] =
 #endif
 };
 
+static void prefs_filtering_row_selected(GtkTreeSelection *selection,
+                                        GtkTreeView *list_view)
+{
+       GtkTreePath *path;
+       GtkTreeIter iter;
+       GtkTreeModel *model;
+       
+       if (!gtk_tree_selection_get_selected(selection, &model, &iter))
+               return;
+       
+       path = gtk_tree_model_get_path(model, &iter);
+       prefs_filtering_select_row(list_view, path);
+       gtk_tree_path_free(path);
+}
+
 static gint prefs_filtering_list_btn_pressed(GtkWidget *widget, GdkEventButton *event,
                                    GtkTreeView *list_view)
 {
@@ -1841,22 +1800,17 @@ static GtkWidget *prefs_filtering_list_view_create(void)
 {
        GtkTreeView *list_view;
        GtkTreeSelection *selector;
+       GtkListStore *store = prefs_filtering_create_data_store();
 
-       list_view = GTK_TREE_VIEW(gtk_tree_view_new_with_model(GTK_TREE_MODEL
-               (prefs_filtering_create_data_store())));
+       list_view = GTK_TREE_VIEW(gtk_tree_view_new_with_model(
+                               GTK_TREE_MODEL(store)));
+       g_object_unref(store);
 #ifdef GENERIC_UMPC
        g_object_set(list_view, "allow-checkbox-mode", FALSE, NULL);
 #endif
 
-#ifndef MAEMO
        g_signal_connect(G_OBJECT(list_view), "popup-menu",
                         G_CALLBACK(prefs_filtering_list_popup_menu), list_view);
-#else
-       gtk_widget_tap_and_hold_setup(GTK_WIDGET(list_view), NULL, NULL,
-                       GTK_TAP_AND_HOLD_NONE | GTK_TAP_AND_HOLD_NO_INTERNALS);
-       g_signal_connect(G_OBJECT(list_view), "tap-and-hold",
-                        G_CALLBACK(prefs_filtering_list_popup_menu), list_view);
-#endif
        g_signal_connect(G_OBJECT(list_view), "button-press-event",
                        G_CALLBACK(prefs_filtering_list_btn_pressed), list_view);
        
@@ -1865,6 +1819,8 @@ static GtkWidget *prefs_filtering_list_view_create(void)
        
        selector = gtk_tree_view_get_selection(list_view);
        gtk_tree_selection_set_mode(selector, GTK_SELECTION_BROWSE);
+       g_signal_connect(G_OBJECT(selector), "changed",
+                        G_CALLBACK(prefs_filtering_row_selected), list_view);
 
        /* create the columns */
        prefs_filtering_create_list_view_columns(GTK_WIDGET(list_view));
@@ -1986,6 +1942,8 @@ static void prefs_filtering_select_row(GtkTreeView *list_view, GtkTreePath *path
 
                        prop = matcher_parser_get_filtering(filtering_str);
                        if (prop) {
+                               if (prop->name != NULL)
+                                       g_free(prop->name);
                                prop->name = g_strdup(name);
                                prop->account_id = account_id;
                                prefs_filtering_select_set(prop);