Fix memory leaks from results of gtk_tree_model_get().
[claws.git] / src / prefs_filtering.c
index 407732431a8290332925b1eb10548edf210013e8..8424ff8932bc49d023169b745935636b1bc2f4e9 100644 (file)
@@ -421,7 +421,7 @@ static void prefs_filtering_create(void)
                          (GtkAttachOptions) (GTK_FILL|GTK_EXPAND),
                          (GtkAttachOptions) (0), 0, 0);
 
-       cond_btn =  gtk_button_new_with_mnemonic (_(" D_efine... "));
+       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),
@@ -483,7 +483,7 @@ 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_with_mnemonic (_("Re_move"));
+       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);
@@ -508,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);
@@ -955,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++;
        }                               
        
@@ -1179,6 +1183,7 @@ 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);
@@ -1204,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);     
@@ -1223,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)));
@@ -1259,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);
@@ -1437,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);
@@ -1476,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;
                }
        }
@@ -1498,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! */
@@ -1520,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);
@@ -1796,9 +1800,11 @@ 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
@@ -1936,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);