Fix truncated input widgets in preferences window
[claws.git] / src / prefs_filtering.c
blob2376cb1704a5ade45fba3447ba0a93fceda46b63
1 /*
2 * Sylpheed -- a GTK+ based, lightweight, and fast e-mail client
3 * Copyright (C) 1999-2013 Hiroyuki Yamamoto and the Claws Mail team
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 3 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
20 #ifdef HAVE_CONFIG_H
21 # include "config.h"
22 #include "claws-features.h"
23 #endif
25 #include "defs.h"
27 #include <glib.h>
28 #include <glib/gi18n.h>
29 #include <gtk/gtk.h>
30 #include <gdk/gdkkeysyms.h>
31 #include <stdio.h>
32 #include <stdlib.h>
33 #include <string.h>
34 #include <errno.h>
36 #include "main.h"
37 #include "prefs_gtk.h"
38 #include "prefs_matcher.h"
39 #include "prefs_filtering.h"
40 #include "prefs_common.h"
41 #include "mainwindow.h"
42 #include "foldersel.h"
43 #include "manage_window.h"
44 #include "inc.h"
45 #include "utils.h"
46 #include "gtkutils.h"
47 #include "alertpanel.h"
48 #include "folder.h"
49 #include "folder_item_prefs.h"
50 #include "filtering.h"
51 #include "addr_compl.h"
52 #include "manual.h"
53 #include "combobox.h"
54 #include "menu.h"
55 #include "account.h"
57 #include "matcher_parser.h"
58 #include "matcher.h"
59 #include "prefs_filtering_action.h"
61 enum {
62 PREFS_FILTERING_ENABLED,
63 PREFS_FILTERING_NAME,
64 PREFS_FILTERING_ACCOUNT_ID,
65 PREFS_FILTERING_ACCOUNT_NAME,
66 PREFS_FILTERING_RULE,
67 PREFS_FILTERING_PROP,
68 N_PREFS_FILTERING_COLUMNS
71 struct _Filtering {
72 GtkWidget *window;
74 GtkWidget *help_btn;
75 GtkWidget *ok_btn;
76 GtkWidget *name_entry;
77 GtkWidget *account_label;
78 GtkWidget *account_combobox;
79 GtkListStore *account_combobox_list;
80 GtkWidget *cond_entry;
81 GtkWidget *action_entry;
83 GtkWidget *cond_list_view;
85 GtkTreeViewColumn *account_name_column;
88 typedef struct _Filtering Filtering;
90 static Filtering filtering;
92 static GSList ** p_processing_list = NULL;
94 /* widget creating functions */
95 static void prefs_filtering_create (void);
97 static void prefs_filtering_set_dialog (const gchar *header,
98 const gchar *key);
99 static void prefs_filtering_set_list (void);
101 /* callback functions */
102 static gboolean prefs_filtering_search_func_cb (GtkTreeModel *model, gint column,
103 const gchar *key, GtkTreeIter *iter,
104 gpointer search_data);
105 static void prefs_filtering_register_cb (gpointer action, gpointer data);
106 static void prefs_filtering_substitute_cb (gpointer action, gpointer data);
107 static void prefs_filtering_delete_cb (gpointer action, gpointer data);
108 static void prefs_filtering_delete_all_cb(gpointer action, gpointer data);
109 static void prefs_filtering_clear_cb(gpointer action, gpointer data);
110 static void prefs_filtering_duplicate_cb(gpointer action, gpointer data);
111 static void prefs_filtering_top (gpointer action, gpointer data);
112 static void prefs_filtering_page_up (gpointer action, gpointer data);
113 static void prefs_filtering_up (gpointer action, gpointer data);
114 static void prefs_filtering_down (gpointer action, gpointer data);
115 static void prefs_filtering_page_down (gpointer action, gpointer data);
116 static void prefs_filtering_bottom (gpointer action, gpointer data);
117 static gint prefs_filtering_deleted (GtkWidget *widget,
118 GdkEventAny *event,
119 gpointer data);
120 static void prefs_filtering_row_selected(GtkTreeSelection *selection,
121 GtkTreeView *list_view);
122 static gboolean prefs_filtering_key_pressed(GtkWidget *widget,
123 GdkEventKey *event,
124 gpointer data);
125 static void prefs_filtering_cancel (gpointer action, gpointer data);
126 static void prefs_filtering_ok (gpointer action, gpointer data);
128 static void prefs_filtering_condition_define (gpointer action, gpointer data);
129 static void prefs_filtering_action_define (gpointer action, gpointer data);
130 static gint prefs_filtering_list_view_set_row (gint row, FilteringProp * prop);
132 static void prefs_filtering_reset_dialog (void);
133 static gboolean prefs_filtering_rename_tag_func(GNode *node, gpointer data);
134 static gboolean prefs_filtering_rename_path_func(GNode *node, gpointer data);
135 static gboolean prefs_filtering_delete_path_func(GNode *node, gpointer data);
137 static void delete_path(GSList ** p_filters, const gchar * path);
140 static GtkListStore* prefs_filtering_create_data_store (void);
141 static gint prefs_filtering_list_view_insert_rule (GtkListStore *list_store,
142 gint row,
143 gboolean enabled,
144 const gchar *name,
145 gint account_id,
146 const gchar *account_name,
147 const gchar *rule,
148 gboolean prop);
149 static gchar *prefs_filtering_list_view_get_rule (GtkWidget *list,
150 gint row);
151 static void prefs_filtering_list_view_get_rule_info (GtkWidget *list,
152 gint row,
153 gboolean *enabled,
154 gchar **name,
155 gint *account_id);
157 static GtkWidget *prefs_filtering_list_view_create (void);
158 static void prefs_filtering_create_list_view_columns (GtkWidget *list_view);
160 static void prefs_filtering_select_row(GtkTreeView *list_view, GtkTreePath *path);
162 static void prefs_filtering_account_option_menu_populate(void);
164 static gulong signal_id = 0; /* filtering.help_btn clicked signal */
166 static int modified = FALSE;
168 void prefs_filtering_open(GSList ** p_processing,
169 const gchar *title,
170 const gchar *help_url_anchor,
171 const gchar *header,
172 const gchar *key,
173 gboolean per_account_filtering)
175 if (prefs_rc_is_readonly(FILTERING_RC))
176 return;
178 inc_lock();
180 if (!filtering.window) {
181 prefs_filtering_create();
182 } else {
183 gtk_list_store_clear(filtering.account_combobox_list);
184 prefs_filtering_account_option_menu_populate();
187 gtk_tree_view_column_set_visible(filtering.account_name_column,
188 per_account_filtering);
190 manage_window_set_transient(GTK_WINDOW(filtering.window));
191 gtk_widget_grab_focus(filtering.ok_btn);
193 if (title != NULL)
194 gtk_window_set_title(GTK_WINDOW(filtering.window), title);
195 else
196 gtk_window_set_title (GTK_WINDOW(filtering.window),
197 _("Filtering/Processing configuration"));
199 if (help_url_anchor != NULL) {
200 if (signal_id != 0) {
201 g_signal_handler_disconnect(
202 G_OBJECT(filtering.help_btn),
203 signal_id);
206 signal_id = g_signal_connect(G_OBJECT(filtering.help_btn),
207 "clicked",
208 G_CALLBACK(manual_open_with_anchor_cb),
209 (gchar*)help_url_anchor);
211 else {
212 gtk_widget_set_sensitive(filtering.help_btn, FALSE);
215 p_processing_list = p_processing;
217 prefs_filtering_set_dialog(header, key);
218 if (per_account_filtering) {
219 gtk_widget_show(filtering.account_label);
220 gtk_widget_show(filtering.account_combobox);
221 } else {
222 gtk_widget_hide(filtering.account_label);
223 gtk_widget_hide(filtering.account_combobox);
224 combobox_select_by_data(GTK_COMBO_BOX(filtering.account_combobox), 0);
227 gtk_widget_show(filtering.window);
228 gtk_window_set_modal(GTK_WINDOW(filtering.window), TRUE);
230 start_address_completion(NULL);
233 static void prefs_filtering_size_allocate_cb(GtkWidget *widget,
234 GtkAllocation *allocation)
236 cm_return_if_fail(allocation != NULL);
238 prefs_common.filteringwin_width = allocation->width;
239 prefs_common.filteringwin_height = allocation->height;
242 /* prefs_filtering_close() - just to have one common exit point */
243 static void prefs_filtering_close(void)
245 GtkListStore *store;
247 end_address_completion();
249 store = GTK_LIST_STORE(gtk_tree_view_get_model(GTK_TREE_VIEW
250 (filtering.cond_list_view)));
251 gtk_list_store_clear(store);
252 gtk_widget_hide(filtering.window);
253 gtk_window_set_modal(GTK_WINDOW(filtering.window), FALSE);
254 inc_unlock();
257 static void prefs_filtering_account_option_menu_populate(void)
259 GList *accounts = NULL;
260 GtkTreeIter iter;
262 accounts = account_get_list();
264 cm_return_if_fail(accounts != NULL);
266 COMBOBOX_ADD(filtering.account_combobox_list, C_("Filtering Account Menu", "All"), 0);
267 COMBOBOX_ADD(filtering.account_combobox_list, NULL, 0);
268 for (; accounts != NULL; accounts = accounts->next) {
269 PrefsAccount *ac = (PrefsAccount *)accounts->data;
271 COMBOBOX_ADD_ESCAPED(filtering.account_combobox_list, ac->account_name, ac->account_id);
275 static GtkWidget *prefs_filtering_account_option_menu(Filtering *filtering)
277 GtkWidget *optmenu = NULL;
278 GtkWidget *optmenubox = NULL;
279 GtkListStore *menu = NULL;
281 optmenubox = gtk_event_box_new();
282 optmenu = gtkut_sc_combobox_create(optmenubox, FALSE);
283 menu = GTK_LIST_STORE(gtk_combo_box_get_model(GTK_COMBO_BOX(optmenu)));
285 filtering->account_combobox = optmenu;
286 filtering->account_combobox_list = menu;
288 prefs_filtering_account_option_menu_populate();
290 return optmenubox;
293 static void prefs_filtering_create(void)
295 GtkWidget *window;
296 GtkWidget *vbox;
297 GtkWidget *help_btn;
298 GtkWidget *cancel_btn;
299 GtkWidget *ok_btn;
300 GtkWidget *confirm_area;
302 GtkWidget *vbox1;
303 GtkWidget *reg_hbox;
304 GtkWidget *arrow;
305 GtkWidget *btn_hbox;
307 GtkWidget *name_label;
308 GtkWidget *name_entry;
309 GtkWidget *account_label;
310 GtkWidget *account_opt_menu;
311 GtkWidget *cond_label;
312 GtkWidget *cond_entry;
313 GtkWidget *cond_btn;
314 GtkWidget *action_label;
315 GtkWidget *action_entry;
316 GtkWidget *action_btn;
318 GtkWidget *reg_btn;
319 GtkWidget *subst_btn;
320 GtkWidget *del_btn;
321 GtkWidget *clear_btn;
323 GtkWidget *cond_hbox;
324 GtkWidget *cond_scrolledwin;
325 GtkWidget *cond_list_view;
327 GtkWidget *btn_vbox;
328 GtkWidget *top_btn;
329 GtkWidget *up_btn;
330 GtkWidget *down_btn;
331 #ifndef GENERIC_UMPC
332 GtkWidget *page_up_btn;
333 GtkWidget *page_down_btn;
334 #endif
335 GtkWidget *bottom_btn;
336 GtkWidget *table;
337 static GdkGeometry geometry;
339 debug_print("Creating filtering configuration window...\n");
341 window = gtkut_window_new(GTK_WINDOW_TOPLEVEL, "prefs_filtering");
342 gtk_container_set_border_width (GTK_CONTAINER (window), 8);
343 gtk_window_set_position (GTK_WINDOW (window), GTK_WIN_POS_CENTER);
344 gtk_window_set_resizable(GTK_WINDOW (window), TRUE);
346 vbox = gtk_vbox_new (FALSE, 6);
347 gtk_widget_show (vbox);
348 gtk_container_add (GTK_CONTAINER (window), vbox);
350 gtkut_stock_button_set_create_with_help(&confirm_area, &help_btn,
351 &cancel_btn, GTK_STOCK_CANCEL,
352 &ok_btn, GTK_STOCK_OK,
353 NULL, NULL);
354 gtk_widget_show (confirm_area);
355 gtk_box_pack_end (GTK_BOX(vbox), confirm_area, FALSE, FALSE, 0);
356 gtk_widget_grab_default (ok_btn);
358 gtk_window_set_title (GTK_WINDOW(window),
359 _("Filtering/Processing configuration"));
361 g_signal_connect(G_OBJECT(window), "delete_event",
362 G_CALLBACK(prefs_filtering_deleted), NULL);
363 g_signal_connect(G_OBJECT(window), "size_allocate",
364 G_CALLBACK(prefs_filtering_size_allocate_cb), NULL);
365 g_signal_connect(G_OBJECT(window), "key_press_event",
366 G_CALLBACK(prefs_filtering_key_pressed), NULL);
367 MANAGE_WINDOW_SIGNALS_CONNECT (window);
368 g_signal_connect(G_OBJECT(ok_btn), "clicked",
369 G_CALLBACK(prefs_filtering_ok), NULL);
370 g_signal_connect(G_OBJECT(cancel_btn), "clicked",
371 G_CALLBACK(prefs_filtering_cancel), NULL);
373 vbox1 = gtk_vbox_new (FALSE, VSPACING);
374 gtk_widget_show (vbox1);
375 gtk_box_pack_start (GTK_BOX (vbox), vbox1, FALSE, TRUE, 0);
376 gtk_container_set_border_width (GTK_CONTAINER (vbox1), 2);
378 table = gtk_table_new(4, 3, FALSE);
379 gtk_table_set_row_spacings (GTK_TABLE (table), VSPACING_NARROW_2);
380 gtk_table_set_col_spacings (GTK_TABLE (table), 4);
381 gtk_widget_show(table);
382 gtk_box_pack_start (GTK_BOX (vbox1), table, TRUE, TRUE, 0);
384 name_label = gtk_label_new (_("Name"));
385 gtk_widget_show (name_label);
386 gtk_misc_set_alignment (GTK_MISC (name_label), 1, 0.5);
387 gtk_table_attach (GTK_TABLE (table), name_label, 0, 1, 0, 1,
388 (GtkAttachOptions) (GTK_FILL),
389 (GtkAttachOptions) (0), 0, 0);
391 name_entry = gtk_entry_new ();
392 gtk_widget_show (name_entry);
393 gtk_table_attach (GTK_TABLE (table), name_entry, 1, 2, 0, 1,
394 (GtkAttachOptions) (GTK_FILL|GTK_EXPAND),
395 (GtkAttachOptions) (0), 0, 0);
397 account_label = gtk_label_new (_("Account"));
398 gtk_widget_show (account_label);
399 gtk_misc_set_alignment (GTK_MISC (account_label), 1, 0.5);
400 gtk_table_attach (GTK_TABLE (table), account_label, 0, 1, 1, 2,
401 (GtkAttachOptions) (GTK_FILL),
402 (GtkAttachOptions) (0), 0, 0);
404 account_opt_menu = prefs_filtering_account_option_menu(&filtering);
405 gtk_widget_show (account_opt_menu);
406 gtk_table_attach (GTK_TABLE (table), account_opt_menu, 1, 2, 1, 2,
407 (GtkAttachOptions) (GTK_FILL|GTK_EXPAND),
408 (GtkAttachOptions) (0), 0, 0);
409 combobox_select_by_data(GTK_COMBO_BOX(filtering.account_combobox), 0);
411 cond_label = gtk_label_new (_("Condition"));
412 gtk_widget_show (cond_label);
413 gtk_misc_set_alignment (GTK_MISC (cond_label), 1, 0.5);
414 gtk_table_attach (GTK_TABLE (table), cond_label, 0, 1, 2, 3,
415 (GtkAttachOptions) (GTK_FILL),
416 (GtkAttachOptions) (0), 0, 0);
418 cond_entry = gtk_entry_new ();
419 gtk_widget_show (cond_entry);
420 gtk_table_attach (GTK_TABLE (table), cond_entry, 1, 2, 2, 3,
421 (GtkAttachOptions) (GTK_FILL|GTK_EXPAND),
422 (GtkAttachOptions) (0), 0, 0);
424 cond_btn = gtk_button_new_with_mnemonic (_(" Def_ine... "));
425 gtk_widget_show (cond_btn);
426 gtk_table_attach (GTK_TABLE (table), cond_btn, 2, 3, 2, 3,
427 (GtkAttachOptions) (GTK_FILL),
428 (GtkAttachOptions) (0), 2, 2);
429 g_signal_connect(G_OBJECT (cond_btn), "clicked",
430 G_CALLBACK(prefs_filtering_condition_define),
431 NULL);
433 action_label = gtk_label_new (_("Action"));
434 gtk_widget_show (action_label);
435 gtk_misc_set_alignment (GTK_MISC (action_label), 1, 0.5);
436 gtk_table_attach (GTK_TABLE (table), action_label, 0, 1, 3, 4,
437 (GtkAttachOptions) (GTK_FILL),
438 (GtkAttachOptions) (0), 0, 0);
440 action_entry = gtk_entry_new ();
441 gtk_widget_show (action_entry);
442 gtk_table_attach (GTK_TABLE (table), action_entry, 1, 2, 3, 4,
443 (GtkAttachOptions) (GTK_FILL|GTK_EXPAND),
444 (GtkAttachOptions) (0), 0, 0);
446 action_btn = gtk_button_new_with_mnemonic (_(" De_fine... "));
447 gtk_widget_show (action_btn);
448 gtk_table_attach (GTK_TABLE (table), action_btn, 2, 3, 3, 4,
449 (GtkAttachOptions) (GTK_FILL),
450 (GtkAttachOptions) (0), 2, 2);
451 g_signal_connect(G_OBJECT (action_btn), "clicked",
452 G_CALLBACK(prefs_filtering_action_define),
453 NULL);
455 /* register / substitute / delete */
456 reg_hbox = gtk_hbox_new (FALSE, 4);
457 gtk_widget_show (reg_hbox);
458 gtk_box_pack_start (GTK_BOX (vbox1), reg_hbox, FALSE, FALSE, 0);
460 arrow = gtk_arrow_new (GTK_ARROW_DOWN, GTK_SHADOW_OUT);
461 gtk_widget_show (arrow);
462 gtk_box_pack_start (GTK_BOX (reg_hbox), arrow, FALSE, FALSE, 0);
463 gtk_widget_set_size_request (arrow, -1, 16);
465 btn_hbox = gtk_hbox_new (TRUE, 4);
466 gtk_widget_show (btn_hbox);
467 gtk_box_pack_start (GTK_BOX (reg_hbox), btn_hbox, FALSE, FALSE, 0);
469 reg_btn = gtk_button_new_from_stock (GTK_STOCK_ADD);
470 gtk_widget_show (reg_btn);
471 gtk_box_pack_start (GTK_BOX (btn_hbox), reg_btn, FALSE, TRUE, 0);
472 g_signal_connect(G_OBJECT (reg_btn), "clicked",
473 G_CALLBACK(prefs_filtering_register_cb), NULL);
474 CLAWS_SET_TIP(reg_btn,
475 _("Append the new rule above to the list"));
477 subst_btn = gtkut_get_replace_btn (_("_Replace"));
478 gtk_widget_show (subst_btn);
479 gtk_box_pack_start (GTK_BOX (btn_hbox), subst_btn, FALSE, TRUE, 0);
480 g_signal_connect(G_OBJECT (subst_btn), "clicked",
481 G_CALLBACK(prefs_filtering_substitute_cb),
482 NULL);
483 CLAWS_SET_TIP(subst_btn,
484 _("Replace the selected rule in list with the rule above"));
486 del_btn = gtk_button_new_with_mnemonic (_("D_elete"));
487 gtk_button_set_image(GTK_BUTTON(del_btn),
488 gtk_image_new_from_stock(GTK_STOCK_REMOVE,GTK_ICON_SIZE_BUTTON));
489 gtk_box_pack_start (GTK_BOX (btn_hbox), del_btn, FALSE, TRUE, 0);
490 g_signal_connect(G_OBJECT (del_btn), "clicked",
491 G_CALLBACK(prefs_filtering_delete_cb), NULL);
492 CLAWS_SET_TIP(del_btn,
493 _("Delete the selected rule from the list"));
495 clear_btn = gtk_button_new_with_mnemonic (_("C_lear"));
496 gtk_button_set_image(GTK_BUTTON(clear_btn),
497 gtk_image_new_from_stock(GTK_STOCK_CLEAR,GTK_ICON_SIZE_BUTTON));
498 gtk_widget_show (clear_btn);
499 gtk_box_pack_start (GTK_BOX (btn_hbox), clear_btn, FALSE, TRUE, 0);
500 g_signal_connect(G_OBJECT (clear_btn), "clicked",
501 G_CALLBACK(prefs_filtering_clear_cb), NULL);
502 CLAWS_SET_TIP(clear_btn,
503 _("Clear all the input fields in the dialog"));
505 cond_hbox = gtk_hbox_new (FALSE, 8);
506 gtk_widget_show (cond_hbox);
507 gtk_box_pack_start (GTK_BOX (vbox), cond_hbox, TRUE, TRUE, 0);
509 cond_scrolledwin = gtk_scrolled_window_new (NULL, NULL);
510 gtk_widget_show (cond_scrolledwin);
511 gtk_scrolled_window_set_shadow_type(GTK_SCROLLED_WINDOW(cond_scrolledwin),
512 GTK_SHADOW_ETCHED_IN);
513 gtk_widget_set_size_request (cond_scrolledwin, -1, 150);
514 gtk_box_pack_start (GTK_BOX (cond_hbox), cond_scrolledwin,
515 TRUE, TRUE, 0);
516 gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (cond_scrolledwin),
517 GTK_POLICY_AUTOMATIC,
518 GTK_POLICY_AUTOMATIC);
520 cond_list_view = prefs_filtering_list_view_create();
521 gtk_widget_show (cond_list_view);
522 gtk_container_add (GTK_CONTAINER (cond_scrolledwin), cond_list_view);
524 btn_vbox = gtk_vbox_new (FALSE, 8);
525 gtk_widget_show (btn_vbox);
526 gtk_box_pack_start (GTK_BOX (cond_hbox), btn_vbox, FALSE, FALSE, 0);
528 top_btn = gtk_button_new_from_stock (GTK_STOCK_GOTO_TOP);
529 gtk_widget_show (top_btn);
530 gtk_box_pack_start (GTK_BOX (btn_vbox), top_btn, FALSE, FALSE, 0);
531 g_signal_connect(G_OBJECT (top_btn), "clicked",
532 G_CALLBACK(prefs_filtering_top), NULL);
533 CLAWS_SET_TIP(top_btn,
534 _("Move the selected rule to the top"));
536 #ifndef GENERIC_UMPC
537 page_up_btn = gtk_button_new_with_mnemonic (_("Page u_p"));
538 gtk_button_set_image(GTK_BUTTON(page_up_btn),
539 gtk_image_new_from_stock(GTK_STOCK_GO_UP,GTK_ICON_SIZE_BUTTON));
540 gtk_widget_show (page_up_btn);
541 gtk_box_pack_start (GTK_BOX (btn_vbox), page_up_btn, FALSE, FALSE, 0);
542 g_signal_connect(G_OBJECT (page_up_btn), "clicked",
543 G_CALLBACK(prefs_filtering_page_up), NULL);
544 CLAWS_SET_TIP(page_up_btn,
545 _("Move the selected rule one page up"));
546 #endif
548 up_btn = gtk_button_new_from_stock (GTK_STOCK_GO_UP);
549 gtk_widget_show (up_btn);
550 gtk_box_pack_start (GTK_BOX (btn_vbox), up_btn, FALSE, FALSE, 0);
551 g_signal_connect(G_OBJECT (up_btn), "clicked",
552 G_CALLBACK(prefs_filtering_up), NULL);
553 CLAWS_SET_TIP(up_btn,
554 _("Move the selected rule up"));
556 down_btn = gtk_button_new_from_stock (GTK_STOCK_GO_DOWN);
557 gtk_widget_show (down_btn);
558 gtk_box_pack_start (GTK_BOX (btn_vbox), down_btn, FALSE, FALSE, 0);
559 g_signal_connect(G_OBJECT (down_btn), "clicked",
560 G_CALLBACK(prefs_filtering_down), NULL);
561 CLAWS_SET_TIP(down_btn,
562 _("Move the selected rule down"));
564 #ifndef GENERIC_UMPC
565 page_down_btn = gtk_button_new_with_mnemonic (_("Page dow_n"));
566 gtk_button_set_image(GTK_BUTTON(page_down_btn),
567 gtk_image_new_from_stock(GTK_STOCK_GO_DOWN,GTK_ICON_SIZE_BUTTON));
568 gtk_widget_show (page_down_btn);
569 gtk_box_pack_start (GTK_BOX (btn_vbox), page_down_btn, FALSE, FALSE, 0);
570 g_signal_connect(G_OBJECT (page_down_btn), "clicked",
571 G_CALLBACK(prefs_filtering_page_down), NULL);
572 CLAWS_SET_TIP(page_down_btn,
573 _("Move the selected rule one page down"));
574 #endif
576 bottom_btn = gtk_button_new_from_stock (GTK_STOCK_GOTO_BOTTOM);
577 gtk_widget_show (bottom_btn);
578 gtk_box_pack_start (GTK_BOX (btn_vbox), bottom_btn, FALSE, FALSE, 0);
579 g_signal_connect(G_OBJECT (bottom_btn), "clicked",
580 G_CALLBACK(prefs_filtering_bottom), NULL);
581 CLAWS_SET_TIP(bottom_btn,
582 _("Move the selected rule to the bottom"));
584 if (!geometry.min_height) {
585 geometry.min_width = 500;
586 geometry.min_height = 460;
589 gtk_window_set_geometry_hints(GTK_WINDOW(window), NULL, &geometry,
590 GDK_HINT_MIN_SIZE);
591 gtk_widget_set_size_request(window, prefs_common.filteringwin_width,
592 prefs_common.filteringwin_height);
594 gtk_widget_show_all(window);
596 filtering.window = window;
597 filtering.help_btn = help_btn;
598 filtering.ok_btn = ok_btn;
600 filtering.name_entry = name_entry;
601 filtering.cond_entry = cond_entry;
602 filtering.action_entry = action_entry;
603 filtering.cond_list_view = cond_list_view;
604 filtering.account_label = account_label;
607 static void rename_tag(GSList * filters,
608 const gchar * old_tag, const gchar * new_tag);
610 void prefs_filtering_rename_tag(const gchar *old_tag, const gchar *new_tag)
612 GList * cur;
613 const gchar *tags[2] = {NULL, NULL};
614 tags[0] = old_tag;
615 tags[1] = new_tag;
616 for (cur = folder_get_list() ; cur != NULL ; cur = g_list_next(cur)) {
617 Folder *folder;
618 folder = (Folder *) cur->data;
619 g_node_traverse(folder->node, G_PRE_ORDER, G_TRAVERSE_ALL, -1,
620 prefs_filtering_rename_tag_func, tags);
623 rename_tag(pre_global_processing, old_tag, new_tag);
624 rename_tag(post_global_processing, old_tag, new_tag);
625 rename_tag(filtering_rules, old_tag, new_tag);
627 prefs_matcher_write_config();
631 static void rename_path(GSList * filters,
632 const gchar * old_path, const gchar * new_path);
634 void prefs_filtering_rename_path(const gchar *old_path, const gchar *new_path)
636 GList * cur;
637 const gchar *paths[2] = {NULL, NULL};
638 paths[0] = old_path;
639 paths[1] = new_path;
640 for (cur = folder_get_list() ; cur != NULL ; cur = g_list_next(cur)) {
641 Folder *folder;
642 folder = (Folder *) cur->data;
643 g_node_traverse(folder->node, G_PRE_ORDER, G_TRAVERSE_ALL, -1,
644 prefs_filtering_rename_path_func, paths);
647 rename_path(pre_global_processing, old_path, new_path);
648 rename_path(post_global_processing, old_path, new_path);
649 rename_path(filtering_rules, old_path, new_path);
651 prefs_matcher_write_config();
654 static void rename_path(GSList * filters,
655 const gchar * old_path, const gchar * new_path)
657 GSList * cur;
659 for (cur = filters; cur != NULL; cur = cur->next) {
660 FilteringProp *filtering = (FilteringProp *)cur->data;
661 filtering_action_list_rename_path(filtering->action_list,
662 old_path, new_path);
666 static gboolean prefs_filtering_rename_path_func(GNode *node, gpointer data)
668 GSList *filters;
669 const gchar * old_path;
670 const gchar * new_path;
671 const gchar ** paths;
672 FolderItem *item;
674 paths = data;
675 old_path = paths[0];
676 new_path = paths[1];
678 cm_return_val_if_fail(old_path != NULL, FALSE);
679 cm_return_val_if_fail(new_path != NULL, FALSE);
680 cm_return_val_if_fail(node != NULL, FALSE);
682 item = node->data;
683 if (!item || !item->prefs)
684 return FALSE;
685 filters = item->prefs->processing;
687 rename_path(filters, old_path, new_path);
689 return FALSE;
692 static void rename_tag(GSList * filters,
693 const gchar * old_tag, const gchar * new_tag)
695 GSList * action_cur;
696 GSList * cur;
698 for (cur = filters; cur != NULL; cur = cur->next) {
699 FilteringProp *filtering = (FilteringProp *)cur->data;
701 for(action_cur = filtering->action_list ; action_cur != NULL ;
702 action_cur = action_cur->next) {
704 FilteringAction *action = action_cur->data;
706 if (action->type != MATCHACTION_SET_TAG &&
707 action->type != MATCHACTION_UNSET_TAG)
708 continue;
709 if (!action->destination)
710 continue;
711 if (!strcmp(action->destination, old_tag)) {
712 g_free(action->destination);
713 action->destination = g_strdup(new_tag);
719 static gboolean prefs_filtering_rename_tag_func(GNode *node, gpointer data)
721 GSList *filters;
722 const gchar * old_tag;
723 const gchar * new_tag;
724 const gchar ** tags;
725 FolderItem *item;
727 tags = data;
728 old_tag = tags[0];
729 new_tag = tags[1];
731 cm_return_val_if_fail(old_tag != NULL, FALSE);
732 cm_return_val_if_fail(new_tag != NULL, FALSE);
733 cm_return_val_if_fail(node != NULL, FALSE);
735 item = node->data;
736 if (!item || !item->prefs)
737 return FALSE;
738 filters = item->prefs->processing;
740 rename_tag(filters, old_tag, new_tag);
742 return FALSE;
745 void prefs_filtering_delete_path(const gchar *path)
747 GList * cur;
748 for (cur = folder_get_list() ; cur != NULL ; cur = g_list_next(cur)) {
749 Folder *folder;
750 folder = (Folder *) cur->data;
751 g_node_traverse(folder->node, G_PRE_ORDER, G_TRAVERSE_ALL, -1,
752 prefs_filtering_delete_path_func, (gchar *)path);
754 delete_path(&pre_global_processing, path);
755 delete_path(&post_global_processing, path);
756 delete_path(&filtering_rules, path);
758 prefs_matcher_write_config();
761 static void delete_path(GSList ** p_filters, const gchar * path)
763 GSList * filters;
764 GSList * duplist;
765 gchar *suffix;
766 gint destlen;
767 gint prefixlen;
768 gint pathlen;
769 GSList * action_cur;
770 GSList * cur;
772 filters = *p_filters;
773 pathlen = strlen(path);
774 duplist = g_slist_copy(filters);
775 for (cur = duplist ; cur != NULL; cur = g_slist_next(cur)) {
776 FilteringProp *filtering = (FilteringProp *) cur->data;
778 for(action_cur = filtering->action_list ; action_cur != NULL ;
779 action_cur = action_cur->next) {
781 FilteringAction *action;
783 action = action_cur->data;
785 if (action->type == MATCHACTION_SET_TAG ||
786 action->type == MATCHACTION_UNSET_TAG)
787 continue;
788 if (!action->destination)
789 continue;
791 destlen = strlen(action->destination);
793 if (destlen > pathlen) {
794 prefixlen = destlen - pathlen;
795 suffix = action->destination + prefixlen;
797 if (suffix && !strncmp(path, suffix, pathlen)) {
798 filteringprop_free(filtering);
799 filters = g_slist_remove(filters, filtering);
801 } else if (strcmp(action->destination, path) == 0) {
802 filteringprop_free(filtering);
803 filters = g_slist_remove(filters, filtering);
807 g_slist_free(duplist);
809 * p_filters = filters;
812 static gboolean prefs_filtering_delete_path_func(GNode *node, gpointer data)
814 const gchar *path = data;
815 FolderItem *item;
816 GSList ** p_filters;
818 cm_return_val_if_fail(path != NULL, FALSE);
819 cm_return_val_if_fail(node != NULL, FALSE);
821 item = node->data;
822 if (!item || !item->prefs)
823 return FALSE;
824 p_filters = &item->prefs->processing;
826 delete_path(p_filters, path);
828 return FALSE;
831 static void prefs_filtering_clear_list(GtkListStore *list_store)
833 gtk_list_store_clear(list_store);
835 /* add the place holder (New) at row 0 */
836 prefs_filtering_list_view_insert_rule(list_store, -1,
837 FALSE,
838 _("(New)"),
840 _("(New)"),
841 _("(New)"),
842 FALSE);
845 static void prefs_filtering_set_dialog(const gchar *header, const gchar *key)
847 GtkTreeView *list_view = GTK_TREE_VIEW(filtering.cond_list_view);
848 GSList *cur;
849 GSList * prefs_filtering;
850 gchar *cond_str;
851 GtkListStore *list_store;
853 list_store = GTK_LIST_STORE(gtk_tree_view_get_model(list_view));
854 prefs_filtering_clear_list(list_store);
856 prefs_filtering = *p_processing_list;
858 for(cur = prefs_filtering ; cur != NULL ; cur = g_slist_next(cur)) {
859 FilteringProp * prop = (FilteringProp *) cur->data;
860 gchar *account_name = NULL;
862 if (prop->account_id > 0) {
863 PrefsAccount *ac_prefs = account_find_from_id(prop->account_id);
865 if (ac_prefs)
866 account_name = ac_prefs->account_name;
868 if (account_name == NULL)
869 account_name = (gchar *)C_("Filtering Account Menu", "All");
871 cond_str = filteringprop_to_string(prop);
872 subst_char(cond_str, '\t', ':');
874 prefs_filtering_list_view_insert_rule(list_store, -1,
875 prop->enabled,
876 prop->name,
877 prop->account_id,
878 account_name,
879 cond_str, TRUE);
881 g_free(cond_str);
884 prefs_filtering_reset_dialog();
886 if (header && key) {
887 gchar * quoted_key;
888 gchar *match_str;
890 quoted_key = matcher_quote_str(key);
892 match_str = g_strconcat(header, " ", get_matchparser_tab_str(MATCHTYPE_MATCHCASE),
893 " \"", quoted_key, "\"", NULL);
894 g_free(quoted_key);
896 gtk_entry_set_text(GTK_ENTRY(filtering.cond_entry), match_str);
897 g_free(match_str);
901 static void prefs_filtering_reset_dialog(void)
903 gtk_entry_set_text(GTK_ENTRY(filtering.name_entry), "");
904 combobox_select_by_data(GTK_COMBO_BOX(filtering.account_combobox), 0);
905 gtk_entry_set_text(GTK_ENTRY(filtering.cond_entry), "");
906 gtk_entry_set_text(GTK_ENTRY(filtering.action_entry), "");
909 static gboolean prefs_filtering_search_func_cb (GtkTreeModel *model, gint column, const gchar *key,
910 GtkTreeIter *iter, gpointer search_data)
912 gchar *store_string;
913 gboolean retval;
914 GtkTreePath *path;
916 gtk_tree_model_get (model, iter, column, &store_string, -1);
918 if (!store_string || !key) return FALSE;
921 retval = (g_ascii_strncasecmp (key, store_string, strlen(key)) != 0);
923 g_free(store_string);
924 debug_print("selecting row\n");
925 path = gtk_tree_model_get_path(model, iter);
926 prefs_filtering_select_row(GTK_TREE_VIEW(filtering.cond_list_view), path);
927 gtk_tree_path_free(path);
929 return retval;
932 static void prefs_filtering_set_list(void)
934 gint row = 1;
935 FilteringProp *prop;
936 GSList * cur;
937 gchar * filtering_str;
938 GSList * prefs_filtering;
940 prefs_filtering = *p_processing_list;
941 for (cur = prefs_filtering ; cur != NULL ; cur = g_slist_next(cur))
942 filteringprop_free((FilteringProp *) cur->data);
943 g_slist_free(prefs_filtering);
944 prefs_filtering = NULL;
947 while (NULL != (filtering_str = prefs_filtering_list_view_get_rule
948 (filtering.cond_list_view, row))) {
949 /* FIXME: this strcmp() is bogus: "(New)" should never
950 * be inserted in the storage */
951 if (strcmp(filtering_str, _("(New)")) != 0) {
952 gboolean enabled;
953 gchar *name;
954 gint account_id = 0;
956 prefs_filtering_list_view_get_rule_info(
957 filtering.cond_list_view, row,
958 &enabled, &name, &account_id);
959 prop = matcher_parser_get_filtering(filtering_str);
960 g_free(filtering_str);
961 if (prop) {
962 prop->enabled = enabled;
963 if (prop->name != NULL)
964 g_free(prop->name);
965 prop->name = name;
966 prop->account_id = account_id;
967 prefs_filtering =
968 g_slist_append(prefs_filtering, prop);
972 row++;
975 *p_processing_list = prefs_filtering;
978 static gint prefs_filtering_list_view_set_row(gint row, FilteringProp * prop)
980 GtkTreeView *list_view = GTK_TREE_VIEW(filtering.cond_list_view);
981 gchar *str = NULL;
982 GtkListStore *list_store;
983 gchar *name = NULL;
984 gint account_id = 0;
985 gchar *account_name = (gchar *)C_("Filtering Account Menu", "All");
986 gboolean enabled = TRUE;
988 if (prop)
989 str = filteringprop_to_string(prop);
990 if (str == NULL)
991 return -1;
993 if (prop) {
994 if (prop->name)
995 name = prop->name;
996 account_id = prop->account_id;
997 if (account_id > 0)
998 account_name = account_find_from_id(account_id)->account_name;
999 enabled = prop->enabled;
1002 list_store = GTK_LIST_STORE(gtk_tree_view_get_model(list_view));
1004 row = prefs_filtering_list_view_insert_rule(list_store, row,
1005 enabled,
1006 name,
1007 account_id,
1008 account_name,
1009 str,
1010 prop != NULL);
1012 g_free(str);
1014 return row;
1017 static void prefs_filtering_condition_define_done(MatcherList * matchers)
1019 gchar * str;
1021 if (matchers == NULL)
1022 return;
1024 str = matcherlist_to_string(matchers);
1026 if (str != NULL) {
1027 gtk_entry_set_text(GTK_ENTRY(filtering.cond_entry), str);
1028 g_free(str);
1032 static void prefs_filtering_condition_define(gpointer action, gpointer data)
1034 gchar * cond_str;
1035 MatcherList * matchers = NULL;
1037 cond_str = gtk_editable_get_chars(GTK_EDITABLE(filtering.cond_entry), 0, -1);
1039 if (*cond_str != '\0') {
1040 matchers = matcher_parser_get_cond(cond_str, NULL);
1041 if (matchers == NULL)
1042 alertpanel_error(_("Condition string is not valid."));
1045 g_free(cond_str);
1047 prefs_matcher_open(matchers, prefs_filtering_condition_define_done);
1049 if (matchers != NULL)
1050 matcherlist_free(matchers);
1053 static void prefs_filtering_action_define_done(GSList * action_list)
1055 gchar * str;
1057 if (action_list == NULL)
1058 return;
1060 str = filteringaction_list_to_string(action_list);
1062 if (str != NULL) {
1063 gtk_entry_set_text(GTK_ENTRY(filtering.action_entry), str);
1064 g_free(str);
1068 static void prefs_filtering_action_define(gpointer action, gpointer data)
1070 gchar * action_str;
1071 GSList * action_list = NULL;
1073 action_str = gtk_editable_get_chars(GTK_EDITABLE(filtering.action_entry), 0, -1);
1075 if (*action_str != '\0') {
1076 action_list = matcher_parser_get_action_list(action_str);
1077 if (action_list == NULL)
1078 alertpanel_error(_("Action string is not valid."));
1081 g_free(action_str);
1083 prefs_filtering_action_open(action_list,
1084 prefs_filtering_action_define_done);
1086 if (action_list != NULL) {
1087 GSList * cur;
1088 for(cur = action_list ; cur != NULL ; cur = cur->next) {
1089 filteringaction_free(cur->data);
1095 /* register / substitute delete buttons */
1098 static FilteringProp * prefs_filtering_dialog_to_filtering(gboolean alert)
1100 MatcherList * cond;
1101 gboolean enabled = TRUE;
1102 gchar * name = NULL;
1103 gint account_id = 0;
1104 gchar * cond_str = NULL;
1105 gchar * action_str = NULL;
1106 FilteringProp * prop = NULL;
1107 GSList * action_list;
1109 name = gtk_editable_get_chars(GTK_EDITABLE(filtering.name_entry), 0, -1);
1111 account_id = combobox_get_active_data(GTK_COMBO_BOX(filtering.account_combobox));
1113 cond_str = gtk_editable_get_chars(GTK_EDITABLE(filtering.cond_entry), 0, -1);
1114 if (*cond_str == '\0') {
1115 if(alert == TRUE) alertpanel_error(_("Condition string is empty."));
1116 goto fail;
1119 action_str = gtk_editable_get_chars(GTK_EDITABLE(filtering.action_entry), 0, -1);
1120 if (*action_str == '\0') {
1121 if(alert == TRUE) alertpanel_error(_("Action string is empty."));
1122 goto fail;
1125 cond = matcher_parser_get_cond(cond_str, NULL);
1127 if (cond == NULL) {
1128 if(alert == TRUE) alertpanel_error(_("Condition string is not valid."));
1129 goto fail;
1132 action_list = matcher_parser_get_action_list(action_str);
1135 if (action_list == NULL) {
1136 if(alert == TRUE) alertpanel_error(_("Action string is not valid."));
1137 goto fail;
1140 prop = filteringprop_new(enabled, name, account_id, cond, action_list);
1142 fail:
1143 g_free(name);
1144 g_free(cond_str);
1145 g_free(action_str);
1146 return prop;
1149 static void prefs_filtering_register_cb(gpointer action, gpointer data)
1151 FilteringProp *prop;
1153 prop = prefs_filtering_dialog_to_filtering(TRUE);
1154 if (prop == NULL)
1155 return;
1156 prefs_filtering_list_view_set_row(-1, prop);
1158 filteringprop_free(prop);
1160 prefs_filtering_reset_dialog();
1161 modified = TRUE;
1164 static void prefs_filtering_substitute_cb(gpointer action, gpointer data)
1166 gint selected_row = gtkut_list_view_get_selected_row
1167 (filtering.cond_list_view);
1168 FilteringProp *prop;
1169 gboolean enabled;
1170 gchar *name;
1171 gint account_id;
1173 if (selected_row <= 0)
1174 return;
1176 prop = prefs_filtering_dialog_to_filtering(TRUE);
1178 if (prop == NULL)
1179 return;
1181 /* prop->emabled is always TRUE here, re-use the value from the selected row
1182 as we don't substitute this value from dialog */
1183 prefs_filtering_list_view_get_rule_info(
1184 filtering.cond_list_view, selected_row,
1185 &enabled, &name, &account_id);
1186 prop->enabled = enabled;
1188 prefs_filtering_list_view_set_row(selected_row, prop);
1190 filteringprop_free(prop);
1192 prefs_filtering_row_selected(gtk_tree_view_get_selection(
1193 GTK_TREE_VIEW(filtering.cond_list_view)),
1194 GTK_TREE_VIEW(filtering.cond_list_view));
1195 modified = TRUE;
1198 static void prefs_filtering_delete_cb(gpointer action, gpointer data)
1200 GtkTreeView *list_view = GTK_TREE_VIEW(filtering.cond_list_view);
1201 GtkTreeModel *model;
1202 GtkTreeIter iter;
1203 gint selected_row;
1205 selected_row = gtkut_list_view_get_selected_row(filtering.cond_list_view);
1206 if (selected_row <= 0)
1207 return;
1209 if (alertpanel(_("Delete rule"),
1210 _("Do you really want to delete this rule?"),
1211 GTK_STOCK_CANCEL, "+"GTK_STOCK_DELETE, NULL) == G_ALERTDEFAULT)
1212 return;
1214 model = gtk_tree_view_get_model(list_view);
1215 if (!gtk_tree_model_iter_nth_child(model, &iter, NULL, selected_row))
1216 return;
1218 gtk_list_store_remove(GTK_LIST_STORE(model), &iter);
1220 prefs_filtering_reset_dialog();
1221 modified = TRUE;
1224 static void prefs_filtering_delete_all_cb(gpointer action, gpointer data)
1226 GtkListStore *list_store;
1228 if (alertpanel(_("Delete all rules"),
1229 _("Do you really want to delete all the rules?"),
1230 GTK_STOCK_CANCEL, "+"GTK_STOCK_DELETE, NULL) == G_ALERTDEFAULT)
1231 return;
1233 list_store = GTK_LIST_STORE(gtk_tree_view_get_model(GTK_TREE_VIEW(filtering.cond_list_view)));
1234 prefs_filtering_clear_list(list_store);
1236 prefs_filtering_reset_dialog();
1237 modified = TRUE;
1240 static void prefs_filtering_clear_cb(gpointer action, gpointer data)
1242 prefs_filtering_reset_dialog();
1245 static void prefs_filtering_duplicate_cb(gpointer action, gpointer data)
1247 gint selected_row = gtkut_list_view_get_selected_row
1248 (filtering.cond_list_view);
1249 FilteringProp *prop;
1250 gboolean enabled;
1251 gchar *name;
1252 gint account_id;
1254 if (selected_row <= 0)
1255 return;
1257 prop = prefs_filtering_dialog_to_filtering(TRUE);
1258 if (prop == NULL)
1259 return;
1261 /* prop->emabled is always TRUE here, re-use the value from the selected row
1262 as we don't substitute this value from dialog */
1263 prefs_filtering_list_view_get_rule_info(
1264 filtering.cond_list_view, selected_row,
1265 &enabled, &name, &account_id);
1266 prop->enabled = enabled;
1268 prefs_filtering_list_view_set_row(-selected_row-2, prop);
1270 filteringprop_free(prop);
1272 prefs_filtering_reset_dialog();
1273 modified = TRUE;
1276 static void prefs_filtering_top(gpointer action, gpointer data)
1278 gint row;
1279 GtkTreeIter top, sel;
1280 GtkTreeModel *model;
1282 row = gtkut_list_view_get_selected_row(filtering.cond_list_view);
1283 if (row <= 1)
1284 return;
1286 model = gtk_tree_view_get_model(GTK_TREE_VIEW(filtering.cond_list_view));
1288 if (!gtk_tree_model_iter_nth_child(model, &top, NULL, 0)
1289 || !gtk_tree_model_iter_nth_child(model, &sel, NULL, row))
1290 return;
1292 gtk_list_store_move_after(GTK_LIST_STORE(model), &sel, &top);
1293 gtkut_list_view_select_row(filtering.cond_list_view, 1);
1294 modified = TRUE;
1297 static void prefs_filtering_page_up(gpointer action, gpointer data)
1299 gint row, target_row;
1300 GtkTreeIter selected, target;
1301 GtkTreeModel *model;
1302 GtkTreePath *path;
1303 GdkRectangle cell_rect, view_rect;
1305 model = gtk_tree_view_get_model(GTK_TREE_VIEW(filtering.cond_list_view));
1306 row = gtkut_list_view_get_selected_row(filtering.cond_list_view);
1307 if (row <= 1)
1308 return;
1310 if (!gtk_tree_model_iter_nth_child(model, &selected, NULL, row))
1311 return;
1313 /* compute number of rows per page (approximation) */
1314 path = gtk_tree_model_get_path(model, &selected);
1315 gtk_tree_view_get_cell_area(GTK_TREE_VIEW(filtering.cond_list_view), path, NULL, &cell_rect);
1316 gtk_tree_view_get_visible_rect(GTK_TREE_VIEW(filtering.cond_list_view), &view_rect);
1317 gtk_tree_path_free(path);
1318 target_row = row - (view_rect.height/cell_rect.height);
1319 if (target_row < 1)
1320 target_row = 1;
1322 if (!gtk_tree_model_iter_nth_child(model, &target, NULL, target_row))
1323 return;
1324 gtk_list_store_move_before(GTK_LIST_STORE(model), &selected, &target);
1325 gtkut_list_view_select_row(filtering.cond_list_view, target_row);
1326 modified = TRUE;
1328 static void prefs_filtering_up(gpointer action, gpointer data)
1330 gint row;
1331 GtkTreeIter top, sel;
1332 GtkTreeModel *model;
1334 row = gtkut_list_view_get_selected_row(filtering.cond_list_view);
1335 if (row <= 1)
1336 return;
1338 model = gtk_tree_view_get_model(GTK_TREE_VIEW(filtering.cond_list_view));
1340 if (!gtk_tree_model_iter_nth_child(model, &top, NULL, row - 1)
1341 || !gtk_tree_model_iter_nth_child(model, &sel, NULL, row))
1342 return;
1344 gtk_list_store_swap(GTK_LIST_STORE(model), &top, &sel);
1345 gtkut_list_view_select_row(filtering.cond_list_view, row - 1);
1346 modified = TRUE;
1349 static void prefs_filtering_down(gpointer action, gpointer data)
1351 gint row, n_rows;
1352 GtkTreeIter top, sel;
1353 GtkTreeModel *model;
1355 model = gtk_tree_view_get_model(GTK_TREE_VIEW(filtering.cond_list_view));
1356 n_rows = gtk_tree_model_iter_n_children(model, NULL);
1357 row = gtkut_list_view_get_selected_row(filtering.cond_list_view);
1358 if (row < 1 || row >= n_rows - 1)
1359 return;
1361 if (!gtk_tree_model_iter_nth_child(model, &top, NULL, row)
1362 || !gtk_tree_model_iter_nth_child(model, &sel, NULL, row + 1))
1363 return;
1365 gtk_list_store_swap(GTK_LIST_STORE(model), &top, &sel);
1366 gtkut_list_view_select_row(filtering.cond_list_view, row + 1);
1367 modified = TRUE;
1370 static void prefs_filtering_page_down(gpointer action, gpointer data)
1372 gint row, target_row, n_rows;
1373 GtkTreeIter selected, target;
1374 GtkTreeModel *model;
1375 GtkTreePath *path;
1376 GdkRectangle cell_rect, view_rect;
1378 model = gtk_tree_view_get_model(GTK_TREE_VIEW(filtering.cond_list_view));
1379 n_rows = gtk_tree_model_iter_n_children(model, NULL);
1380 row = gtkut_list_view_get_selected_row(filtering.cond_list_view);
1381 if (row < 1 || row >= n_rows -1)
1382 return;
1384 if (!gtk_tree_model_iter_nth_child(model, &selected, NULL, row))
1385 return;
1387 /* compute number of rows per page (approximation) */
1388 path = gtk_tree_model_get_path(model, &selected);
1389 gtk_tree_view_get_cell_area(GTK_TREE_VIEW(filtering.cond_list_view), path, NULL, &cell_rect);
1390 gtk_tree_view_get_visible_rect(GTK_TREE_VIEW(filtering.cond_list_view), &view_rect);
1391 gtk_tree_path_free(path);
1392 target_row = row + (view_rect.height/cell_rect.height);
1393 if (target_row > n_rows-1)
1394 target_row = n_rows-1;
1396 if (!gtk_tree_model_iter_nth_child(model, &target, NULL, target_row))
1397 return;
1398 gtk_list_store_move_after(GTK_LIST_STORE(model), &selected, &target);
1399 gtkut_list_view_select_row(filtering.cond_list_view, target_row);
1400 modified = TRUE;
1403 static void prefs_filtering_bottom(gpointer action, gpointer data)
1405 gint row, n_rows;
1406 GtkTreeIter top, sel;
1407 GtkTreeModel *model;
1409 model = gtk_tree_view_get_model(GTK_TREE_VIEW(filtering.cond_list_view));
1410 n_rows = gtk_tree_model_iter_n_children(model, NULL);
1411 row = gtkut_list_view_get_selected_row(filtering.cond_list_view);
1412 if (row < 1 || row >= n_rows - 1)
1413 return;
1415 if (!gtk_tree_model_iter_nth_child(model, &top, NULL, row)
1416 || !gtk_tree_model_iter_nth_child(model, &sel, NULL, n_rows - 1))
1417 return;
1419 gtk_list_store_move_after(GTK_LIST_STORE(model), &top, &sel);
1420 gtkut_list_view_select_row(filtering.cond_list_view, n_rows - 1);
1421 modified = TRUE;
1424 static void prefs_filtering_select_set(FilteringProp *prop)
1426 gchar *matcher_str;
1427 gchar *action_str;
1429 prefs_filtering_reset_dialog();
1431 matcher_str = matcherlist_to_string(prop->matchers);
1432 if (matcher_str == NULL) {
1433 return;
1436 if (prop->name != NULL)
1437 gtk_entry_set_text(GTK_ENTRY(filtering.name_entry), prop->name);
1439 combobox_select_by_data(GTK_COMBO_BOX(filtering.account_combobox), prop->account_id);
1441 gtk_entry_set_text(GTK_ENTRY(filtering.cond_entry), matcher_str);
1443 action_str = filteringaction_list_to_string(prop->action_list);
1444 if (action_str != NULL)
1445 gtk_entry_set_text(GTK_ENTRY(filtering.action_entry), action_str);
1447 g_free(action_str);
1448 g_free(matcher_str);
1451 static gint prefs_filtering_deleted(GtkWidget *widget, GdkEventAny *event,
1452 gpointer data)
1454 prefs_filtering_cancel(NULL, NULL);
1455 return TRUE;
1458 static gboolean prefs_filtering_key_pressed(GtkWidget *widget, GdkEventKey *event,
1459 gpointer data)
1461 if (event && event->keyval == GDK_KEY_Escape) {
1462 prefs_filtering_cancel(NULL, NULL);
1463 return TRUE;
1465 return FALSE;
1468 static gboolean prefs_filtering_check_mod(gboolean check_changed_list)
1470 FilteringProp * prop;
1471 gchar * str;
1472 gchar * filtering_str;
1473 gint row = 1;
1474 AlertValue val;
1476 prop = prefs_filtering_dialog_to_filtering(FALSE);
1478 if (check_changed_list) {
1479 if (modified && alertpanel(_("Filtering rules not saved"),
1480 _("The list of filtering rules have been modified. Close anyway?"),
1481 GTK_STOCK_CLOSE, g_strconcat("+", _("_Continue editing"), NULL),
1482 NULL) != G_ALERTDEFAULT) {
1483 return TRUE;
1487 /* check if a rule is being edited */
1488 if (prop != NULL) {
1489 str = filteringprop_to_string(prop);
1491 while (NULL != (filtering_str = (prefs_filtering_list_view_get_rule
1492 (filtering.cond_list_view,
1493 row)))) {
1494 if (strcmp(filtering_str, str) == 0)
1495 break;
1496 row++;
1497 g_free(filtering_str);
1500 if (!filtering_str) {
1501 val = alertpanel(_("Entry not saved"),
1502 _("The entry was not saved. Close anyway?"),
1503 GTK_STOCK_CLOSE, g_strconcat("+", _("_Continue editing"),NULL), NULL);
1504 if (G_ALERTDEFAULT != val) {
1505 g_free(filtering_str);
1506 g_free(str); /* fixed two leaks: huzzah! */
1507 filteringprop_free(prop);
1508 return TRUE;
1512 g_free(filtering_str);
1513 g_free(str);
1514 filteringprop_free(prop); /* fixed a leak: huzzah! */
1515 } else {
1516 gchar *name, *condition, *action;
1517 name = gtk_editable_get_chars(GTK_EDITABLE(filtering.name_entry), 0, -1);
1518 condition = gtk_editable_get_chars(GTK_EDITABLE(filtering.cond_entry), 0, -1);
1519 action = gtk_editable_get_chars(GTK_EDITABLE(filtering.action_entry), 0, -1);
1520 if (strlen(name) ||
1521 strlen(condition) ||
1522 strlen(action)) {
1523 val = alertpanel(_("Entry not saved"),
1524 _("The entry was not saved. Close anyway?"),
1525 GTK_STOCK_CLOSE, g_strconcat("+", _("_Continue editing"), NULL), NULL);
1526 if (G_ALERTDEFAULT != val) {
1527 g_free(name);
1528 g_free(condition);
1529 g_free(action);
1530 return TRUE;
1533 g_free(name);
1534 g_free(condition);
1535 g_free(action);
1537 return FALSE;
1540 static void prefs_filtering_ok(gpointer action, gpointer data)
1542 if (prefs_filtering_check_mod(FALSE))
1543 return;
1544 modified = FALSE;
1545 prefs_filtering_set_list();
1546 prefs_matcher_write_config();
1547 prefs_filtering_close();
1550 static void prefs_filtering_cancel(gpointer action, gpointer data)
1552 if (prefs_filtering_check_mod(TRUE))
1553 return;
1554 modified = FALSE;
1555 prefs_matcher_read_config();
1556 prefs_filtering_close();
1559 static GtkListStore* prefs_filtering_create_data_store(void)
1561 return gtk_list_store_new(N_PREFS_FILTERING_COLUMNS,
1562 G_TYPE_BOOLEAN,
1563 G_TYPE_STRING,
1564 G_TYPE_INT,
1565 G_TYPE_STRING,
1566 G_TYPE_STRING,
1567 G_TYPE_BOOLEAN,
1568 -1);
1572 *\brief Insert filtering rule into store. Note that we access the
1573 * tree view / store by index, which is a bit suboptimal, but
1574 * at least it made GTK 2 porting easier.
1576 *\param list_store Store to operate on
1577 *\param row -1 to add a new rule to store,
1578 row >=0 to change an existing row
1579 row <-1 insert a new row after (-row-2)
1580 *\param enabled TRUE if rule is enabled
1581 *\param name The Name of rule
1582 *\param account_id The account ID
1583 *\param account_name The account name or All or (New)
1584 *\param rule String representation of rule
1585 *\param prop TRUE if valid filtering rule; if FALSE it's the first
1586 * entry in the store ("(New)").
1588 *\return int Row of inserted / changed rule.
1590 static gint prefs_filtering_list_view_insert_rule(GtkListStore *list_store,
1591 gint row,
1592 gboolean enabled,
1593 const gchar *name,
1594 gint account_id,
1595 const gchar *account_name,
1596 const gchar *rule,
1597 gboolean prop)
1599 GtkTreeIter iter;
1600 GtkTreeIter sibling;
1602 /* check if valid row at all */
1603 if (row >= 0) {
1604 if (!gtk_tree_model_iter_nth_child(GTK_TREE_MODEL(list_store),
1605 &iter, NULL, row))
1606 row = -1;
1607 } else if (row < -1) {
1608 if (!gtk_tree_model_iter_nth_child(GTK_TREE_MODEL(list_store),
1609 &sibling, NULL, -row-2))
1610 row = -1;
1613 if (row == -1 ) {
1614 /* append new */
1615 gtk_list_store_append(list_store, &iter);
1616 gtk_list_store_set(list_store, &iter,
1617 PREFS_FILTERING_ENABLED, enabled,
1618 PREFS_FILTERING_NAME, name,
1619 PREFS_FILTERING_ACCOUNT_ID, account_id,
1620 PREFS_FILTERING_ACCOUNT_NAME, account_name,
1621 PREFS_FILTERING_RULE, rule,
1622 PREFS_FILTERING_PROP, prop,
1623 -1);
1624 return gtk_tree_model_iter_n_children(GTK_TREE_MODEL(list_store),
1625 NULL) - 1;
1626 } else if (row < -1) {
1627 /* duplicate */
1628 gtk_list_store_insert_after(list_store, &iter, &sibling);
1629 gtk_list_store_set(list_store, &iter,
1630 PREFS_FILTERING_ENABLED, enabled,
1631 PREFS_FILTERING_NAME, name,
1632 PREFS_FILTERING_ACCOUNT_ID, account_id,
1633 PREFS_FILTERING_ACCOUNT_NAME, account_name,
1634 PREFS_FILTERING_RULE, rule,
1635 PREFS_FILTERING_PROP, prop,
1636 -1);
1637 return gtk_tree_model_iter_n_children(GTK_TREE_MODEL(list_store),
1638 NULL) - 1;
1639 } else {
1640 /* change existing */
1641 gtk_list_store_set(list_store, &iter,
1642 PREFS_FILTERING_ENABLED, enabled,
1643 PREFS_FILTERING_NAME, name,
1644 PREFS_FILTERING_ACCOUNT_ID, account_id,
1645 PREFS_FILTERING_ACCOUNT_NAME, account_name,
1646 PREFS_FILTERING_RULE, rule,
1647 -1);
1648 return row;
1653 *\return gchar * Rule at specified row - should be freed.
1655 static gchar *prefs_filtering_list_view_get_rule(GtkWidget *list, gint row)
1657 GtkTreeView *list_view = GTK_TREE_VIEW(list);
1658 GtkTreeModel *model = gtk_tree_view_get_model(list_view);
1659 GtkTreeIter iter;
1660 gchar *result;
1662 if (!gtk_tree_model_iter_nth_child(model, &iter, NULL, row))
1663 return NULL;
1665 gtk_tree_model_get(model, &iter,
1666 PREFS_FILTERING_RULE, &result,
1667 -1);
1669 return result;
1672 static void prefs_filtering_list_view_get_rule_info(GtkWidget *list, gint row,
1673 gboolean *enabled, gchar **name, gint *account_id)
1675 GtkTreeView *list_view = GTK_TREE_VIEW(list);
1676 GtkTreeModel *model = gtk_tree_view_get_model(list_view);
1677 GtkTreeIter iter;
1679 *enabled = TRUE;
1680 *name = NULL;
1682 if (gtk_tree_model_iter_nth_child(model, &iter, NULL, row)) {
1683 gtk_tree_model_get(model, &iter,
1684 PREFS_FILTERING_ENABLED, enabled,
1685 PREFS_FILTERING_NAME, name,
1686 PREFS_FILTERING_ACCOUNT_ID, account_id,
1687 -1);
1691 static GtkActionGroup *prefs_filtering_popup_action = NULL;
1692 static GtkWidget *prefs_filtering_popup_menu = NULL;
1694 static GtkActionEntry prefs_filtering_popup_entries[] =
1696 {"PrefsFilteringPopup", NULL, "PrefsFilteringPopup" },
1697 {"PrefsFilteringPopup/Delete", NULL, N_("_Delete"), NULL, NULL, G_CALLBACK(prefs_filtering_delete_cb) },
1698 {"PrefsFilteringPopup/DeleteAll", NULL, N_("Delete _all"), NULL, NULL, G_CALLBACK(prefs_filtering_delete_all_cb) },
1699 {"PrefsFilteringPopup/Duplicate", NULL, N_("D_uplicate"), NULL, NULL, G_CALLBACK(prefs_filtering_duplicate_cb) },
1700 #ifdef GENERIC_UMPC
1701 {"PrefsFilteringPopup/---", NULL, "---", NULL, NULL, NULL },
1702 {"PrefsFilteringPopup/PageUp", NULL, N_("Move one page up"), NULL, NULL, G_CALLBACK(prefs_filtering_page_up) },
1703 {"PrefsFilteringPopup/PageDown", NULL, N_("Move one page down"), NULL, NULL, G_CALLBACK(prefs_filtering_page_down) },
1704 #endif
1707 static void prefs_filtering_row_selected(GtkTreeSelection *selection,
1708 GtkTreeView *list_view)
1710 GtkTreePath *path;
1711 GtkTreeIter iter;
1712 GtkTreeModel *model;
1714 if (!gtk_tree_selection_get_selected(selection, &model, &iter))
1715 return;
1717 path = gtk_tree_model_get_path(model, &iter);
1718 prefs_filtering_select_row(list_view, path);
1719 gtk_tree_path_free(path);
1722 static gint prefs_filtering_list_btn_pressed(GtkWidget *widget, GdkEventButton *event,
1723 GtkTreeView *list_view)
1725 if (event) {
1726 /* left- or right-button click */
1727 if (event->button == 1 || event->button == 3) {
1728 GtkTreePath *path = NULL;
1730 if (gtk_tree_view_get_path_at_pos( list_view, event->x, event->y,
1731 &path, NULL, NULL, NULL)) {
1732 prefs_filtering_select_row(list_view, path);
1734 if (path)
1735 gtk_tree_path_free(path);
1738 /* right-button click */
1739 if (event->button == 3) {
1740 GtkTreeModel *model = gtk_tree_view_get_model(list_view);
1741 GtkTreeIter iter;
1742 gboolean non_empty;
1743 gint row;
1745 if (!prefs_filtering_popup_menu) {
1746 prefs_filtering_popup_action = cm_menu_create_action_group("PrefsFilteringPopup", prefs_filtering_popup_entries,
1747 G_N_ELEMENTS(prefs_filtering_popup_entries), (gpointer)list_view);
1748 MENUITEM_ADDUI("/Menus", "PrefsFilteringPopup", "PrefsFilteringPopup", GTK_UI_MANAGER_MENU)
1749 MENUITEM_ADDUI("/Menus/PrefsFilteringPopup", "Delete", "PrefsFilteringPopup/Delete", GTK_UI_MANAGER_MENUITEM)
1750 MENUITEM_ADDUI("/Menus/PrefsFilteringPopup", "DeleteAll", "PrefsFilteringPopup/DeleteAll", GTK_UI_MANAGER_MENUITEM)
1751 MENUITEM_ADDUI("/Menus/PrefsFilteringPopup", "Duplicate", "PrefsFilteringPopup/Duplicate", GTK_UI_MANAGER_MENUITEM)
1752 #ifdef GENERIC_UMPC
1753 MENUITEM_ADDUI("/Menus/PrefsFilteringPopup", "Separator1", "PrefsFilteringPopup/---", GTK_UI_MANAGER_SEPARATOR)
1754 MENUITEM_ADDUI("/Menus/PrefsFilteringPopup", "PageUp", "PrefsFilteringPopup/PageUp", GTK_UI_MANAGER_MENUITEM)
1755 MENUITEM_ADDUI("/Menus/PrefsFilteringPopup", "PageDown", "PrefsFilteringPopup/PageDown", GTK_UI_MANAGER_MENUITEM)
1756 #endif
1757 prefs_filtering_popup_menu = gtk_menu_item_get_submenu(GTK_MENU_ITEM(
1758 gtk_ui_manager_get_widget(gtkut_ui_manager(), "/Menus/PrefsFilteringPopup")) );
1761 /* grey out some popup menu items if there is no selected row */
1762 row = gtkut_list_view_get_selected_row(GTK_WIDGET(list_view));
1763 cm_menu_set_sensitive("PrefsFilteringPopup/Delete", (row > 0));
1764 cm_menu_set_sensitive("PrefsFilteringPopup/Duplicate", (row > 0));
1766 /* grey out seom popup menu items if there is no row
1767 (not counting the (New) one at row 0) */
1768 non_empty = gtk_tree_model_get_iter_first(model, &iter);
1769 if (non_empty)
1770 non_empty = gtk_tree_model_iter_next(model, &iter);
1771 cm_menu_set_sensitive("PrefsFilteringPopup/DeleteAll", non_empty);
1773 gtk_menu_popup(GTK_MENU(prefs_filtering_popup_menu),
1774 NULL, NULL, NULL, NULL,
1775 event->button, event->time);
1778 return FALSE;
1781 static gboolean prefs_filtering_list_popup_menu(GtkWidget *widget, gpointer data)
1783 GtkTreeView *list_view = (GtkTreeView *)data;
1784 GdkEventButton event;
1786 event.button = 3;
1787 event.time = gtk_get_current_event_time();
1789 prefs_filtering_list_btn_pressed(NULL, &event, list_view);
1791 return TRUE;
1795 *\brief Create list view for filtering
1797 static GtkWidget *prefs_filtering_list_view_create(void)
1799 GtkTreeView *list_view;
1800 GtkTreeSelection *selector;
1802 list_view = GTK_TREE_VIEW(gtk_tree_view_new_with_model(GTK_TREE_MODEL
1803 (prefs_filtering_create_data_store())));
1804 #ifdef GENERIC_UMPC
1805 g_object_set(list_view, "allow-checkbox-mode", FALSE, NULL);
1806 #endif
1808 g_signal_connect(G_OBJECT(list_view), "popup-menu",
1809 G_CALLBACK(prefs_filtering_list_popup_menu), list_view);
1810 g_signal_connect(G_OBJECT(list_view), "button-press-event",
1811 G_CALLBACK(prefs_filtering_list_btn_pressed), list_view);
1813 gtk_tree_view_set_rules_hint(list_view, prefs_common.use_stripes_everywhere);
1814 gtk_tree_view_set_reorderable(list_view, TRUE);
1816 selector = gtk_tree_view_get_selection(list_view);
1817 gtk_tree_selection_set_mode(selector, GTK_SELECTION_BROWSE);
1818 g_signal_connect(G_OBJECT(selector), "changed",
1819 G_CALLBACK(prefs_filtering_row_selected), list_view);
1821 /* create the columns */
1822 prefs_filtering_create_list_view_columns(GTK_WIDGET(list_view));
1824 return GTK_WIDGET(list_view);
1827 static void prefs_filtering_enable_toggled(GtkCellRendererToggle *widget,
1828 gchar *path,
1829 GtkWidget *list_view)
1831 GtkTreeIter iter;
1832 GtkTreeModel *model = gtk_tree_view_get_model(GTK_TREE_VIEW(list_view));
1833 gboolean enabled = TRUE;
1835 if (!gtk_tree_model_get_iter_from_string(model, &iter, path))
1836 return;
1838 gtk_tree_model_get(model, &iter,
1839 PREFS_FILTERING_ENABLED, &enabled,
1840 -1);
1842 gtk_list_store_set(GTK_LIST_STORE(model), &iter,
1843 PREFS_FILTERING_ENABLED, !enabled,
1844 -1);
1847 static void prefs_filtering_create_list_view_columns(GtkWidget *list_view)
1849 GtkTreeViewColumn *column;
1850 GtkCellRenderer *renderer;
1852 renderer = gtk_cell_renderer_toggle_new();
1853 g_object_set(renderer,
1854 "radio", FALSE,
1855 "activatable", TRUE,
1856 NULL);
1857 column = gtk_tree_view_column_new_with_attributes
1858 (_("Enable"), /* FIXME : Enable, Enabled, or 'E' ? */
1859 renderer,
1860 "active", PREFS_FILTERING_ENABLED,
1861 NULL);
1862 gtk_tree_view_column_set_alignment (column, 0.5);
1863 gtk_tree_view_append_column(GTK_TREE_VIEW(list_view), column);
1864 g_signal_connect(G_OBJECT(renderer), "toggled",
1865 G_CALLBACK(prefs_filtering_enable_toggled),
1866 list_view);
1868 renderer = gtk_cell_renderer_text_new();
1869 column = gtk_tree_view_column_new_with_attributes
1870 (_("Name"),
1871 renderer,
1872 "text", PREFS_FILTERING_NAME,
1873 NULL);
1874 gtk_tree_view_append_column(GTK_TREE_VIEW(list_view), column);
1875 gtk_tree_view_column_set_resizable(column, TRUE);
1877 renderer = gtk_cell_renderer_text_new();
1878 column = gtk_tree_view_column_new_with_attributes
1879 (_("Account"),
1880 renderer,
1881 "text", PREFS_FILTERING_ACCOUNT_NAME,
1882 NULL);
1883 gtk_tree_view_append_column(GTK_TREE_VIEW(list_view), column);
1884 gtk_tree_view_column_set_resizable(column, TRUE);
1886 filtering.account_name_column = column;
1888 renderer = gtk_cell_renderer_text_new();
1889 column = gtk_tree_view_column_new_with_attributes
1890 (_("Rule"),
1891 renderer,
1892 "text", PREFS_FILTERING_RULE,
1893 NULL);
1895 gtk_tree_view_set_search_column(GTK_TREE_VIEW(list_view), PREFS_FILTERING_NAME);
1896 gtk_tree_view_set_search_equal_func(GTK_TREE_VIEW(list_view), prefs_filtering_search_func_cb , NULL, NULL);
1898 gtk_tree_view_append_column(GTK_TREE_VIEW(list_view), column);
1902 *\brief Triggered when a row has to be selected
1904 static void prefs_filtering_select_row(GtkTreeView *list_view, GtkTreePath *path)
1906 GtkTreeModel *model = gtk_tree_view_get_model(list_view);
1908 if (path && model) {
1909 GtkTreeSelection *selection;
1910 gboolean has_prop = FALSE;
1911 GtkTreeIter iter;
1913 /* select row */
1914 selection = gtk_tree_view_get_selection(list_view);
1915 gtk_tree_selection_select_path(selection, path);
1917 /* update dialog from selection */
1918 gtk_tree_model_get_iter(model, &iter, path);
1919 gtk_tree_model_get(model, &iter,
1920 PREFS_FILTERING_PROP, &has_prop,
1921 -1);
1923 if (has_prop) {
1924 FilteringProp *prop;
1925 gchar *filtering_str = NULL;
1926 gchar *name = NULL;
1927 gint account_id = 0;
1929 gtk_tree_model_get(model, &iter,
1930 PREFS_FILTERING_RULE, &filtering_str,
1931 -1);
1932 gtk_tree_model_get(model, &iter,
1933 PREFS_FILTERING_NAME, &name,
1934 -1);
1935 gtk_tree_model_get(model, &iter,
1936 PREFS_FILTERING_ACCOUNT_ID, &account_id,
1937 -1);
1939 prop = matcher_parser_get_filtering(filtering_str);
1940 if (prop) {
1941 if (prop->name != NULL)
1942 g_free(prop->name);
1943 prop->name = g_strdup(name);
1944 prop->account_id = account_id;
1945 prefs_filtering_select_set(prop);
1946 filteringprop_free(prop);
1948 g_free(name);
1949 g_free(filtering_str);
1950 } else
1951 prefs_filtering_reset_dialog();