2 * Sylpheed -- a GTK+ based, lightweight, and fast e-mail client
3 * Copyright (C) 1999-2006 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 2 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, write to the Free Software
17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
27 #include <glib/gi18n.h>
29 #include <gtk/gtkoptionmenu.h>
30 #include <gdk/gdkkeysyms.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"
47 #include "alertpanel.h"
49 #include "filtering.h"
50 #include "addr_compl.h"
51 #include "colorlabel.h"
55 #include "matcher_parser.h"
57 #include "prefs_filtering_action.h"
60 PREFS_FILTERING_ENABLED
,
62 PREFS_FILTERING_ACCOUNT_ID
,
63 PREFS_FILTERING_ACCOUNT_NAME
,
66 N_PREFS_FILTERING_COLUMNS
74 GtkWidget
*name_entry
;
75 GtkWidget
*account_label
;
76 GtkWidget
*account_combobox
;
77 GtkListStore
*account_combobox_list
;
78 GtkWidget
*cond_entry
;
79 GtkWidget
*action_entry
;
81 GtkWidget
*cond_list_view
;
83 GtkTreeViewColumn
*account_name_column
;
86 typedef struct _Filtering Filtering
;
88 static Filtering filtering
;
90 static GSList
** p_processing_list
= NULL
;
92 /* widget creating functions */
93 static void prefs_filtering_create (void);
95 static void prefs_filtering_set_dialog (const gchar
*header
,
97 static void prefs_filtering_set_list (void);
99 /* callback functions */
100 static void prefs_filtering_register_cb (void);
101 static void prefs_filtering_substitute_cb (void);
102 static void prefs_filtering_delete_cb (void);
103 static void prefs_filtering_top (void);
104 static void prefs_filtering_up (void);
105 static void prefs_filtering_down (void);
106 static void prefs_filtering_bottom (void);
107 static gint
prefs_filtering_deleted (GtkWidget
*widget
,
110 static gboolean
prefs_filtering_key_pressed(GtkWidget
*widget
,
113 static void prefs_filtering_cancel (void);
114 static void prefs_filtering_ok (void);
116 static void prefs_filtering_condition_define (void);
117 static void prefs_filtering_action_define(void);
118 static gint
prefs_filtering_list_view_set_row (gint row
, FilteringProp
* prop
);
120 static void prefs_filtering_reset_dialog (void);
121 static gboolean
prefs_filtering_rename_path_func(GNode
*node
, gpointer data
);
122 static gboolean
prefs_filtering_delete_path_func(GNode
*node
, gpointer data
);
124 static void delete_path(GSList
** p_filters
, const gchar
* path
);
127 static GtkListStore
* prefs_filtering_create_data_store (void);
128 static gint
prefs_filtering_list_view_insert_rule (GtkListStore
*list_store
,
133 const gchar
*account_name
,
136 static gchar
*prefs_filtering_list_view_get_rule (GtkWidget
*list
,
138 static void prefs_filtering_list_view_get_rule_info (GtkWidget
*list
,
144 static GtkWidget
*prefs_filtering_list_view_create (void);
145 static void prefs_filtering_create_list_view_columns (GtkWidget
*list_view
);
146 static gint
prefs_filtering_get_selected_row (GtkWidget
*list_view
);
147 static gboolean
prefs_filtering_list_view_select_row (GtkWidget
*list
, gint row
);
149 static gboolean
prefs_filtering_selected (GtkTreeSelection
*selector
,
152 gboolean currently_selected
,
155 static void prefs_filtering_account_option_menu_populate(void);
157 static gulong signal_id
= 0; /* filtering.help_btn clicked signal */
159 void prefs_filtering_open(GSList
** p_processing
,
161 const gchar
*help_url_anchor
,
164 gboolean per_account_filtering
)
166 if (prefs_rc_is_readonly(FILTERING_RC
))
171 if (!filtering
.window
) {
172 prefs_filtering_create();
174 gtk_list_store_clear(filtering
.account_combobox_list
);
175 prefs_filtering_account_option_menu_populate();
178 gtk_tree_view_column_set_visible(filtering
.account_name_column
,
179 per_account_filtering
);
181 manage_window_set_transient(GTK_WINDOW(filtering
.window
));
182 gtk_widget_grab_focus(filtering
.ok_btn
);
185 gtk_window_set_title(GTK_WINDOW(filtering
.window
), title
);
187 gtk_window_set_title (GTK_WINDOW(filtering
.window
),
188 _("Filtering/Processing configuration"));
190 if (help_url_anchor
!= NULL
) {
191 if (signal_id
!= 0) {
192 g_signal_handler_disconnect(
193 G_OBJECT(filtering
.help_btn
),
197 signal_id
= g_signal_connect(G_OBJECT(filtering
.help_btn
),
199 G_CALLBACK(manual_open_with_anchor_cb
),
200 (gchar
*)help_url_anchor
);
203 gtk_widget_set_sensitive(filtering
.help_btn
, FALSE
);
206 p_processing_list
= p_processing
;
208 prefs_filtering_set_dialog(header
, key
);
209 if (per_account_filtering
) {
210 gtk_widget_show(filtering
.account_label
);
211 gtk_widget_show(filtering
.account_combobox
);
213 gtk_widget_hide(filtering
.account_label
);
214 gtk_widget_hide(filtering
.account_combobox
);
215 combobox_select_by_data(GTK_COMBO_BOX(filtering
.account_combobox
), 0);
218 gtk_widget_show(filtering
.window
);
220 start_address_completion(NULL
);
223 static void prefs_filtering_size_allocate_cb(GtkWidget
*widget
,
224 GtkAllocation
*allocation
)
226 g_return_if_fail(allocation
!= NULL
);
228 prefs_common
.filteringwin_width
= allocation
->width
;
229 prefs_common
.filteringwin_height
= allocation
->height
;
232 /* prefs_filtering_close() - just to have one common exit point */
233 static void prefs_filtering_close(void)
235 end_address_completion();
237 gtk_widget_hide(filtering
.window
);
241 static void prefs_filtering_account_option_menu_populate(void)
243 GList
*accounts
= NULL
;
246 accounts
= account_get_list();
248 g_return_if_fail(accounts
!= NULL
);
250 COMBOBOX_ADD(filtering
.account_combobox_list
, Q_("Filtering Account Menu|All"), 0);
251 for (; accounts
!= NULL
; accounts
= accounts
->next
) {
252 PrefsAccount
*ac
= (PrefsAccount
*)accounts
->data
;
254 COMBOBOX_ADD(filtering
.account_combobox_list
, ac
->account_name
, ac
->account_id
);
258 static GtkWidget
*prefs_filtering_account_option_menu(Filtering
*filtering
)
260 GtkWidget
*optmenu
= NULL
;
261 GtkWidget
*optmenubox
= NULL
;
262 GtkListStore
*menu
= NULL
;
264 optmenubox
= gtk_event_box_new();
265 optmenu
= gtkut_sc_combobox_create(optmenubox
, FALSE
);
266 menu
= GTK_LIST_STORE(gtk_combo_box_get_model(GTK_COMBO_BOX(optmenu
)));
268 filtering
->account_combobox
= optmenu
;
269 filtering
->account_combobox_list
= menu
;
271 prefs_filtering_account_option_menu_populate();
276 static void prefs_filtering_create(void)
281 GtkWidget
*cancel_btn
;
283 GtkWidget
*confirm_area
;
290 GtkWidget
*name_label
;
291 GtkWidget
*name_entry
;
292 GtkWidget
*account_label
;
293 GtkWidget
*account_opt_menu
;
294 GtkWidget
*cond_label
;
295 GtkWidget
*cond_entry
;
297 GtkWidget
*action_label
;
298 GtkWidget
*action_entry
;
299 GtkWidget
*action_btn
;
302 GtkWidget
*subst_btn
;
305 GtkWidget
*cond_hbox
;
306 GtkWidget
*cond_scrolledwin
;
307 GtkWidget
*cond_list_view
;
314 GtkWidget
*bottom_btn
;
316 static GdkGeometry geometry
;
318 debug_print("Creating filtering configuration window...\n");
320 window
= gtk_window_new (GTK_WINDOW_TOPLEVEL
);
321 gtk_container_set_border_width (GTK_CONTAINER (window
), 8);
322 gtk_window_set_position (GTK_WINDOW (window
), GTK_WIN_POS_CENTER
);
323 gtk_window_set_modal (GTK_WINDOW (window
), TRUE
);
324 gtk_window_set_resizable(GTK_WINDOW (window
), TRUE
);
326 vbox
= gtk_vbox_new (FALSE
, 6);
327 gtk_widget_show (vbox
);
328 gtk_container_add (GTK_CONTAINER (window
), vbox
);
330 gtkut_stock_button_set_create_with_help(&confirm_area
, &help_btn
,
331 &cancel_btn
, GTK_STOCK_CANCEL
,
332 &ok_btn
, GTK_STOCK_OK
,
334 gtk_widget_show (confirm_area
);
335 gtk_box_pack_end (GTK_BOX(vbox
), confirm_area
, FALSE
, FALSE
, 0);
336 gtk_widget_grab_default (ok_btn
);
338 gtk_window_set_title (GTK_WINDOW(window
),
339 _("Filtering/Processing configuration"));
341 g_signal_connect(G_OBJECT(window
), "delete_event",
342 G_CALLBACK(prefs_filtering_deleted
), NULL
);
343 g_signal_connect(G_OBJECT(window
), "size_allocate",
344 G_CALLBACK(prefs_filtering_size_allocate_cb
), NULL
);
345 g_signal_connect(G_OBJECT(window
), "key_press_event",
346 G_CALLBACK(prefs_filtering_key_pressed
), NULL
);
347 MANAGE_WINDOW_SIGNALS_CONNECT (window
);
348 g_signal_connect(G_OBJECT(ok_btn
), "clicked",
349 G_CALLBACK(prefs_filtering_ok
), NULL
);
350 g_signal_connect(G_OBJECT(cancel_btn
), "clicked",
351 G_CALLBACK(prefs_filtering_cancel
), NULL
);
353 vbox1
= gtk_vbox_new (FALSE
, VSPACING
);
354 gtk_widget_show (vbox1
);
355 gtk_box_pack_start (GTK_BOX (vbox
), vbox1
, FALSE
, TRUE
, 0);
356 gtk_container_set_border_width (GTK_CONTAINER (vbox1
), 2);
358 table
= gtk_table_new(4, 3, FALSE
);
359 gtk_table_set_row_spacings (GTK_TABLE (table
), VSPACING_NARROW_2
);
360 gtk_table_set_col_spacings (GTK_TABLE (table
), 4);
361 gtk_widget_show(table
);
362 gtk_box_pack_start (GTK_BOX (vbox1
), table
, TRUE
, TRUE
, 0);
364 name_label
= gtk_label_new (_("Name"));
365 gtk_widget_show (name_label
);
366 gtk_misc_set_alignment (GTK_MISC (name_label
), 1, 0.5);
367 gtk_table_attach (GTK_TABLE (table
), name_label
, 0, 1, 0, 1,
368 (GtkAttachOptions
) (GTK_FILL
),
369 (GtkAttachOptions
) (0), 0, 0);
371 name_entry
= gtk_entry_new ();
372 gtk_widget_show (name_entry
);
373 gtk_table_attach (GTK_TABLE (table
), name_entry
, 1, 2, 0, 1,
374 (GtkAttachOptions
) (GTK_FILL
|GTK_EXPAND
),
375 (GtkAttachOptions
) (0), 0, 0);
377 account_label
= gtk_label_new (_("Account"));
378 gtk_widget_show (account_label
);
379 gtk_misc_set_alignment (GTK_MISC (account_label
), 1, 0.5);
380 gtk_table_attach (GTK_TABLE (table
), account_label
, 0, 1, 1, 2,
381 (GtkAttachOptions
) (GTK_FILL
),
382 (GtkAttachOptions
) (0), 0, 0);
384 account_opt_menu
= prefs_filtering_account_option_menu(&filtering
);
385 gtk_widget_show (account_opt_menu
);
386 gtk_table_attach (GTK_TABLE (table
), account_opt_menu
, 1, 2, 1, 2,
387 (GtkAttachOptions
) (GTK_FILL
|GTK_EXPAND
),
388 (GtkAttachOptions
) (0), 0, 0);
389 combobox_select_by_data(GTK_COMBO_BOX(filtering
.account_combobox
), 0);
391 cond_label
= gtk_label_new (_("Condition"));
392 gtk_widget_show (cond_label
);
393 gtk_misc_set_alignment (GTK_MISC (cond_label
), 1, 0.5);
394 gtk_table_attach (GTK_TABLE (table
), cond_label
, 0, 1, 2, 3,
395 (GtkAttachOptions
) (GTK_FILL
),
396 (GtkAttachOptions
) (0), 0, 0);
398 cond_entry
= gtk_entry_new ();
399 gtk_widget_show (cond_entry
);
400 gtk_table_attach (GTK_TABLE (table
), cond_entry
, 1, 2, 2, 3,
401 (GtkAttachOptions
) (GTK_FILL
|GTK_EXPAND
),
402 (GtkAttachOptions
) (0), 0, 0);
404 cond_btn
= gtk_button_new_with_label (_(" Define... "));
405 gtk_widget_show (cond_btn
);
406 gtk_table_attach (GTK_TABLE (table
), cond_btn
, 2, 3, 2, 3,
407 (GtkAttachOptions
) (GTK_FILL
),
408 (GtkAttachOptions
) (0), 2, 2);
409 g_signal_connect(G_OBJECT (cond_btn
), "clicked",
410 G_CALLBACK(prefs_filtering_condition_define
),
413 action_label
= gtk_label_new (_("Action"));
414 gtk_widget_show (action_label
);
415 gtk_misc_set_alignment (GTK_MISC (action_label
), 1, 0.5);
416 gtk_table_attach (GTK_TABLE (table
), action_label
, 0, 1, 3, 4,
417 (GtkAttachOptions
) (GTK_FILL
),
418 (GtkAttachOptions
) (0), 0, 0);
420 action_entry
= gtk_entry_new ();
421 gtk_widget_show (action_entry
);
422 gtk_table_attach (GTK_TABLE (table
), action_entry
, 1, 2, 3, 4,
423 (GtkAttachOptions
) (GTK_FILL
|GTK_EXPAND
),
424 (GtkAttachOptions
) (0), 0, 0);
426 action_btn
= gtk_button_new_with_label (_(" Define... "));
427 gtk_widget_show (action_btn
);
428 gtk_table_attach (GTK_TABLE (table
), action_btn
, 2, 3, 3, 4,
429 (GtkAttachOptions
) (GTK_FILL
),
430 (GtkAttachOptions
) (0), 2, 2);
431 g_signal_connect(G_OBJECT (action_btn
), "clicked",
432 G_CALLBACK(prefs_filtering_action_define
),
435 /* register / substitute / delete */
436 reg_hbox
= gtk_hbox_new (FALSE
, 4);
437 gtk_widget_show (reg_hbox
);
438 gtk_box_pack_start (GTK_BOX (vbox1
), reg_hbox
, FALSE
, FALSE
, 0);
440 arrow
= gtk_arrow_new (GTK_ARROW_DOWN
, GTK_SHADOW_OUT
);
441 gtk_widget_show (arrow
);
442 gtk_box_pack_start (GTK_BOX (reg_hbox
), arrow
, FALSE
, FALSE
, 0);
443 gtk_widget_set_size_request (arrow
, -1, 16);
445 btn_hbox
= gtk_hbox_new (TRUE
, 4);
446 gtk_widget_show (btn_hbox
);
447 gtk_box_pack_start (GTK_BOX (reg_hbox
), btn_hbox
, FALSE
, FALSE
, 0);
449 reg_btn
= gtk_button_new_from_stock (GTK_STOCK_ADD
);
450 gtk_widget_show (reg_btn
);
451 gtk_box_pack_start (GTK_BOX (btn_hbox
), reg_btn
, FALSE
, TRUE
, 0);
452 g_signal_connect(G_OBJECT (reg_btn
), "clicked",
453 G_CALLBACK(prefs_filtering_register_cb
), NULL
);
455 subst_btn
= gtkut_get_replace_btn (_("Replace"));
456 gtk_widget_show (subst_btn
);
457 gtk_box_pack_start (GTK_BOX (btn_hbox
), subst_btn
, FALSE
, TRUE
, 0);
458 g_signal_connect(G_OBJECT (subst_btn
), "clicked",
459 G_CALLBACK(prefs_filtering_substitute_cb
),
462 del_btn
= gtk_button_new_from_stock (GTK_STOCK_DELETE
);
463 gtk_widget_show (del_btn
);
464 gtk_box_pack_start (GTK_BOX (btn_hbox
), del_btn
, FALSE
, TRUE
, 0);
465 g_signal_connect(G_OBJECT (del_btn
), "clicked",
466 G_CALLBACK(prefs_filtering_delete_cb
), NULL
);
468 cond_hbox
= gtk_hbox_new (FALSE
, 8);
469 gtk_widget_show (cond_hbox
);
470 gtk_box_pack_start (GTK_BOX (vbox
), cond_hbox
, TRUE
, TRUE
, 0);
472 cond_scrolledwin
= gtk_scrolled_window_new (NULL
, NULL
);
473 gtk_widget_show (cond_scrolledwin
);
474 gtk_widget_set_size_request (cond_scrolledwin
, -1, 150);
475 gtk_box_pack_start (GTK_BOX (cond_hbox
), cond_scrolledwin
,
477 gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (cond_scrolledwin
),
478 GTK_POLICY_AUTOMATIC
,
479 GTK_POLICY_AUTOMATIC
);
481 cond_list_view
= prefs_filtering_list_view_create();
482 gtk_widget_show (cond_list_view
);
483 gtk_container_add (GTK_CONTAINER (cond_scrolledwin
), cond_list_view
);
485 btn_vbox
= gtk_vbox_new (FALSE
, 8);
486 gtk_widget_show (btn_vbox
);
487 gtk_box_pack_start (GTK_BOX (cond_hbox
), btn_vbox
, FALSE
, FALSE
, 0);
489 top_btn
= gtk_button_new_from_stock (GTK_STOCK_GOTO_TOP
);
490 gtk_widget_show (top_btn
);
491 gtk_box_pack_start (GTK_BOX (btn_vbox
), top_btn
, FALSE
, FALSE
, 0);
492 g_signal_connect(G_OBJECT (top_btn
), "clicked",
493 G_CALLBACK(prefs_filtering_top
), NULL
);
495 PACK_VSPACER (btn_vbox
, spc_vbox
, VSPACING_NARROW_2
);
497 up_btn
= gtk_button_new_from_stock (GTK_STOCK_GO_UP
);
498 gtk_widget_show (up_btn
);
499 gtk_box_pack_start (GTK_BOX (btn_vbox
), up_btn
, FALSE
, FALSE
, 0);
500 g_signal_connect(G_OBJECT (up_btn
), "clicked",
501 G_CALLBACK(prefs_filtering_up
), NULL
);
503 down_btn
= gtk_button_new_from_stock (GTK_STOCK_GO_DOWN
);
504 gtk_widget_show (down_btn
);
505 gtk_box_pack_start (GTK_BOX (btn_vbox
), down_btn
, FALSE
, FALSE
, 0);
506 g_signal_connect(G_OBJECT (down_btn
), "clicked",
507 G_CALLBACK(prefs_filtering_down
), NULL
);
509 PACK_VSPACER (btn_vbox
, spc_vbox
, VSPACING_NARROW_2
);
511 bottom_btn
= gtk_button_new_from_stock (GTK_STOCK_GOTO_BOTTOM
);
512 gtk_widget_show (bottom_btn
);
513 gtk_box_pack_start (GTK_BOX (btn_vbox
), bottom_btn
, FALSE
, FALSE
, 0);
514 g_signal_connect(G_OBJECT (bottom_btn
), "clicked",
515 G_CALLBACK(prefs_filtering_bottom
), NULL
);
517 if (!geometry
.min_height
) {
518 geometry
.min_width
= 500;
519 geometry
.min_height
= 400;
522 gtk_window_set_geometry_hints(GTK_WINDOW(window
), NULL
, &geometry
,
524 gtk_widget_set_size_request(window
, prefs_common
.filteringwin_width
,
525 prefs_common
.filteringwin_height
);
527 gtk_widget_show_all(window
);
529 filtering
.window
= window
;
530 filtering
.help_btn
= help_btn
;
531 filtering
.ok_btn
= ok_btn
;
533 filtering
.name_entry
= name_entry
;
534 filtering
.cond_entry
= cond_entry
;
535 filtering
.action_entry
= action_entry
;
536 filtering
.cond_list_view
= cond_list_view
;
537 filtering
.account_label
= account_label
;
540 static void rename_path(GSList
* filters
,
541 const gchar
* old_path
, const gchar
* new_path
);
543 void prefs_filtering_rename_path(const gchar
*old_path
, const gchar
*new_path
)
546 const gchar
*paths
[2] = {NULL
, NULL
};
549 for (cur
= folder_get_list() ; cur
!= NULL
; cur
= g_list_next(cur
)) {
551 folder
= (Folder
*) cur
->data
;
552 g_node_traverse(folder
->node
, G_PRE_ORDER
, G_TRAVERSE_ALL
, -1,
553 prefs_filtering_rename_path_func
, paths
);
556 rename_path(pre_global_processing
, old_path
, new_path
);
557 rename_path(post_global_processing
, old_path
, new_path
);
558 rename_path(filtering_rules
, old_path
, new_path
);
560 prefs_matcher_write_config();
563 static void rename_path(GSList
* filters
,
564 const gchar
* old_path
, const gchar
* new_path
)
570 gchar
*old_path_with_sep
;
577 oldpathlen
= strlen(old_path
);
578 old_path_with_sep
= g_strconcat(old_path
,G_DIR_SEPARATOR_S
,NULL
);
580 for (cur
= filters
; cur
!= NULL
; cur
= cur
->next
) {
581 FilteringProp
*filtering
= (FilteringProp
*)cur
->data
;
583 for(action_cur
= filtering
->action_list
; action_cur
!= NULL
;
584 action_cur
= action_cur
->next
) {
586 FilteringAction
*action
= action_cur
->data
;
588 if (!action
->destination
) continue;
590 destlen
= strlen(action
->destination
);
592 if (destlen
> oldpathlen
) {
593 prefixlen
= destlen
- oldpathlen
;
594 suffix
= action
->destination
+ prefixlen
;
596 if (!strncmp(old_path
, suffix
, oldpathlen
)) {
597 prefix
= g_malloc0(prefixlen
+ 1);
598 strncpy2(prefix
, action
->destination
, prefixlen
);
600 base
= suffix
+ oldpathlen
;
601 while (*base
== G_DIR_SEPARATOR
) base
++;
603 dest_path
= g_strconcat(prefix
,
607 dest_path
= g_strconcat(prefix
,
614 g_free(action
->destination
);
615 action
->destination
= dest_path
;
616 } else { /* for non-leaf folders */
617 /* compare with trailing slash */
618 if (!strncmp(old_path_with_sep
, action
->destination
, oldpathlen
+1)) {
620 suffix
= action
->destination
+ oldpathlen
+ 1;
621 dest_path
= g_strconcat(new_path
,
624 g_free(action
->destination
);
625 action
->destination
= dest_path
;
629 /* folder-moving a leaf */
630 if (!strcmp(old_path
, action
->destination
)) {
631 dest_path
= g_strdup(new_path
);
632 g_free(action
->destination
);
633 action
->destination
= dest_path
;
640 static gboolean
prefs_filtering_rename_path_func(GNode
*node
, gpointer data
)
643 const gchar
* old_path
;
644 const gchar
* new_path
;
645 const gchar
** paths
;
652 g_return_val_if_fail(old_path
!= NULL
, FALSE
);
653 g_return_val_if_fail(new_path
!= NULL
, FALSE
);
654 g_return_val_if_fail(node
!= NULL
, FALSE
);
657 if (!item
|| !item
->prefs
)
659 filters
= item
->prefs
->processing
;
661 rename_path(filters
, old_path
, new_path
);
666 void prefs_filtering_delete_path(const gchar
*path
)
669 for (cur
= folder_get_list() ; cur
!= NULL
; cur
= g_list_next(cur
)) {
671 folder
= (Folder
*) cur
->data
;
672 g_node_traverse(folder
->node
, G_PRE_ORDER
, G_TRAVERSE_ALL
, -1,
673 prefs_filtering_delete_path_func
, (gchar
*)path
);
675 delete_path(&pre_global_processing
, path
);
676 delete_path(&post_global_processing
, path
);
677 delete_path(&filtering_rules
, path
);
679 prefs_matcher_write_config();
682 static void delete_path(GSList
** p_filters
, const gchar
* path
)
693 filters
= *p_filters
;
694 pathlen
= strlen(path
);
695 duplist
= g_slist_copy(filters
);
696 for (cur
= duplist
; cur
!= NULL
; cur
= g_slist_next(cur
)) {
697 FilteringProp
*filtering
= (FilteringProp
*) cur
->data
;
699 for(action_cur
= filtering
->action_list
; action_cur
!= NULL
;
700 action_cur
= action_cur
->next
) {
702 FilteringAction
*action
;
704 action
= action_cur
->data
;
706 if (!action
->destination
) continue;
708 destlen
= strlen(action
->destination
);
710 if (destlen
> pathlen
) {
711 prefixlen
= destlen
- pathlen
;
712 suffix
= action
->destination
+ prefixlen
;
714 if (suffix
&& !strncmp(path
, suffix
, pathlen
)) {
715 filteringprop_free(filtering
);
716 filters
= g_slist_remove(filters
, filtering
);
718 } else if (strcmp(action
->destination
, path
) == 0) {
719 filteringprop_free(filtering
);
720 filters
= g_slist_remove(filters
, filtering
);
724 g_slist_free(duplist
);
726 * p_filters
= filters
;
729 static gboolean
prefs_filtering_delete_path_func(GNode
*node
, gpointer data
)
731 const gchar
*path
= data
;
735 g_return_val_if_fail(path
!= NULL
, FALSE
);
736 g_return_val_if_fail(node
!= NULL
, FALSE
);
739 if (!item
|| !item
->prefs
)
741 p_filters
= &item
->prefs
->processing
;
743 delete_path(p_filters
, path
);
748 static void prefs_filtering_set_dialog(const gchar
*header
, const gchar
*key
)
750 GtkTreeView
*list_view
= GTK_TREE_VIEW(filtering
.cond_list_view
);
752 GSList
* prefs_filtering
;
754 GtkListStore
*list_store
;
756 list_store
= GTK_LIST_STORE(gtk_tree_view_get_model(list_view
));
757 gtk_list_store_clear(list_store
);
759 /* add the place holder (New) at row 0 */
760 prefs_filtering_list_view_insert_rule(list_store
, -1,
768 prefs_filtering
= *p_processing_list
;
770 for(cur
= prefs_filtering
; cur
!= NULL
; cur
= g_slist_next(cur
)) {
771 FilteringProp
* prop
= (FilteringProp
*) cur
->data
;
772 gchar
*account_name
= NULL
;
774 if (prop
->account_id
> 0) {
775 PrefsAccount
*ac_prefs
= account_find_from_id(prop
->account_id
);
778 account_name
= ac_prefs
->account_name
;
780 if (account_name
== NULL
)
781 account_name
= (gchar
*)Q_("Filtering Account Menu|All");
783 cond_str
= filteringprop_to_string(prop
);
784 subst_char(cond_str
, '\t', ':');
786 prefs_filtering_list_view_insert_rule(list_store
, -1,
796 prefs_filtering_reset_dialog();
802 quoted_key
= matcher_quote_str(key
);
804 match_str
= g_strconcat(header
, " ", get_matchparser_tab_str(MATCHTYPE_MATCHCASE
),
805 " \"", quoted_key
, "\"", NULL
);
808 gtk_entry_set_text(GTK_ENTRY(filtering
.cond_entry
), match_str
);
813 static void prefs_filtering_reset_dialog(void)
815 gtk_entry_set_text(GTK_ENTRY(filtering
.name_entry
), "");
816 combobox_select_by_data(GTK_COMBO_BOX(filtering
.account_combobox
), 0);
817 gtk_entry_set_text(GTK_ENTRY(filtering
.cond_entry
), "");
818 gtk_entry_set_text(GTK_ENTRY(filtering
.action_entry
), "");
821 static void prefs_filtering_set_list(void)
826 gchar
* filtering_str
;
827 GSList
* prefs_filtering
;
829 prefs_filtering
= *p_processing_list
;
830 for (cur
= prefs_filtering
; cur
!= NULL
; cur
= g_slist_next(cur
))
831 filteringprop_free((FilteringProp
*) cur
->data
);
832 g_slist_free(prefs_filtering
);
833 prefs_filtering
= NULL
;
836 while (NULL
!= (filtering_str
= prefs_filtering_list_view_get_rule
837 (filtering
.cond_list_view
, row
))) {
838 /* FIXME: this strcmp() is bogus: "(New)" should never
839 * be inserted in the storage */
840 if (strcmp(filtering_str
, _("(New)")) != 0) {
845 prefs_filtering_list_view_get_rule_info(
846 filtering
.cond_list_view
, row
,
847 &enabled
, &name
, &account_id
);
848 prop
= matcher_parser_get_filtering(filtering_str
);
849 g_free(filtering_str
);
851 prop
->enabled
= enabled
;
853 prop
->account_id
= account_id
;
855 g_slist_append(prefs_filtering
, prop
);
862 *p_processing_list
= prefs_filtering
;
865 static gint
prefs_filtering_list_view_set_row(gint row
, FilteringProp
* prop
)
867 GtkTreeView
*list_view
= GTK_TREE_VIEW(filtering
.cond_list_view
);
869 GtkListStore
*list_store
;
872 gchar
*account_name
= (gchar
*)Q_("Filtering Account Menu|All");
873 gboolean enabled
= TRUE
;
875 str
= filteringprop_to_string(prop
);
882 account_id
= prop
->account_id
;
884 account_name
= account_find_from_id(account_id
)->account_name
;
885 enabled
= prop
->enabled
;
888 list_store
= GTK_LIST_STORE(gtk_tree_view_get_model(list_view
));
890 row
= prefs_filtering_list_view_insert_rule(list_store
, row
,
903 static void prefs_filtering_condition_define_done(MatcherList
* matchers
)
907 if (matchers
== NULL
)
910 str
= matcherlist_to_string(matchers
);
913 gtk_entry_set_text(GTK_ENTRY(filtering
.cond_entry
), str
);
918 static void prefs_filtering_condition_define(void)
921 MatcherList
* matchers
= NULL
;
923 cond_str
= gtk_editable_get_chars(GTK_EDITABLE(filtering
.cond_entry
), 0, -1);
925 if (*cond_str
!= '\0') {
926 matchers
= matcher_parser_get_cond(cond_str
, NULL
);
927 if (matchers
== NULL
)
928 alertpanel_error(_("Condition string is not valid."));
933 prefs_matcher_open(matchers
, prefs_filtering_condition_define_done
);
935 if (matchers
!= NULL
)
936 matcherlist_free(matchers
);
939 static void prefs_filtering_action_define_done(GSList
* action_list
)
943 if (action_list
== NULL
)
946 str
= filteringaction_list_to_string(action_list
);
949 gtk_entry_set_text(GTK_ENTRY(filtering
.action_entry
), str
);
954 static void prefs_filtering_action_define(void)
957 GSList
* action_list
= NULL
;
959 action_str
= gtk_editable_get_chars(GTK_EDITABLE(filtering
.action_entry
), 0, -1);
961 if (*action_str
!= '\0') {
962 action_list
= matcher_parser_get_action_list(action_str
);
963 if (action_list
== NULL
)
964 alertpanel_error(_("Action string is not valid."));
969 prefs_filtering_action_open(action_list
,
970 prefs_filtering_action_define_done
);
972 if (action_list
!= NULL
) {
974 for(cur
= action_list
; cur
!= NULL
; cur
= cur
->next
) {
975 filteringaction_free(cur
->data
);
981 /* register / substitute delete buttons */
984 static FilteringProp
* prefs_filtering_dialog_to_filtering(gboolean alert
)
987 gboolean enabled
= TRUE
;
990 gchar
* cond_str
= NULL
;
991 gchar
* action_str
= NULL
;
992 FilteringProp
* prop
= NULL
;
993 GSList
* action_list
;
995 name
= gtk_editable_get_chars(GTK_EDITABLE(filtering
.name_entry
), 0, -1);
997 account_id
= combobox_get_active_data(GTK_COMBO_BOX(filtering
.account_combobox
));
999 cond_str
= gtk_editable_get_chars(GTK_EDITABLE(filtering
.cond_entry
), 0, -1);
1000 if (*cond_str
== '\0') {
1001 if(alert
== TRUE
) alertpanel_error(_("Condition string is empty."));
1005 action_str
= gtk_editable_get_chars(GTK_EDITABLE(filtering
.action_entry
), 0, -1);
1006 if (*action_str
== '\0') {
1007 if(alert
== TRUE
) alertpanel_error(_("Action string is empty."));
1011 cond
= matcher_parser_get_cond(cond_str
, NULL
);
1014 if(alert
== TRUE
) alertpanel_error(_("Condition string is not valid."));
1018 action_list
= matcher_parser_get_action_list(action_str
);
1021 if (action_list
== NULL
) {
1022 if(alert
== TRUE
) alertpanel_error(_("Action string is not valid."));
1026 prop
= filteringprop_new(enabled
, name
, account_id
, cond
, action_list
);
1035 static void prefs_filtering_register_cb(void)
1037 FilteringProp
* prop
;
1039 prop
= prefs_filtering_dialog_to_filtering(TRUE
);
1042 prefs_filtering_list_view_set_row(-1, prop
);
1044 filteringprop_free(prop
);
1046 prefs_filtering_reset_dialog();
1049 static void prefs_filtering_substitute_cb(void)
1051 gint selected_row
= prefs_filtering_get_selected_row
1052 (filtering
.cond_list_view
);
1053 FilteringProp
*prop
;
1058 if (selected_row
<= 0)
1061 prop
= prefs_filtering_dialog_to_filtering(TRUE
);
1066 /* prop->emabled is always TRUE here, re-use the value from the selected row
1067 as we don't substitute this value from dialog */
1068 prefs_filtering_list_view_get_rule_info(
1069 filtering
.cond_list_view
, selected_row
,
1070 &enabled
, &name
, &account_id
);
1071 prop
->enabled
= enabled
;
1073 prefs_filtering_list_view_set_row(selected_row
, prop
);
1075 filteringprop_free(prop
);
1077 prefs_filtering_reset_dialog();
1080 static void prefs_filtering_delete_cb(void)
1082 GtkTreeView
*list_view
= GTK_TREE_VIEW(filtering
.cond_list_view
);
1083 GtkTreeModel
*model
;
1087 row
= prefs_filtering_get_selected_row(filtering
.cond_list_view
);
1091 if (alertpanel(_("Delete rule"),
1092 _("Do you really want to delete this rule?"),
1093 GTK_STOCK_CANCEL
, "+"GTK_STOCK_DELETE
, NULL
) == G_ALERTDEFAULT
)
1096 model
= gtk_tree_view_get_model(list_view
);
1097 if (!gtk_tree_model_iter_nth_child(model
, &iter
, NULL
, row
))
1100 gtk_list_store_remove(GTK_LIST_STORE(model
), &iter
);
1102 prefs_filtering_reset_dialog();
1105 static void prefs_filtering_top(void)
1108 GtkTreeIter top
, sel
;
1109 GtkTreeModel
*model
;
1111 row
= prefs_filtering_get_selected_row(filtering
.cond_list_view
);
1115 model
= gtk_tree_view_get_model(GTK_TREE_VIEW(filtering
.cond_list_view
));
1117 if (!gtk_tree_model_iter_nth_child(model
, &top
, NULL
, 0)
1118 || !gtk_tree_model_iter_nth_child(model
, &sel
, NULL
, row
))
1121 gtk_list_store_move_after(GTK_LIST_STORE(model
), &sel
, &top
);
1122 prefs_filtering_list_view_select_row(filtering
.cond_list_view
, 1);
1125 static void prefs_filtering_up(void)
1128 GtkTreeIter top
, sel
;
1129 GtkTreeModel
*model
;
1131 row
= prefs_filtering_get_selected_row(filtering
.cond_list_view
);
1135 model
= gtk_tree_view_get_model(GTK_TREE_VIEW(filtering
.cond_list_view
));
1137 if (!gtk_tree_model_iter_nth_child(model
, &top
, NULL
, row
- 1)
1138 || !gtk_tree_model_iter_nth_child(model
, &sel
, NULL
, row
))
1141 gtk_list_store_swap(GTK_LIST_STORE(model
), &top
, &sel
);
1142 prefs_filtering_list_view_select_row(filtering
.cond_list_view
, row
- 1);
1145 static void prefs_filtering_down(void)
1148 GtkTreeIter top
, sel
;
1149 GtkTreeModel
*model
;
1151 model
= gtk_tree_view_get_model(GTK_TREE_VIEW(filtering
.cond_list_view
));
1152 n_rows
= gtk_tree_model_iter_n_children(model
, NULL
);
1153 row
= prefs_filtering_get_selected_row(filtering
.cond_list_view
);
1154 if (row
< 1 || row
>= n_rows
- 1)
1157 if (!gtk_tree_model_iter_nth_child(model
, &top
, NULL
, row
)
1158 || !gtk_tree_model_iter_nth_child(model
, &sel
, NULL
, row
+ 1))
1161 gtk_list_store_swap(GTK_LIST_STORE(model
), &top
, &sel
);
1162 prefs_filtering_list_view_select_row(filtering
.cond_list_view
, row
+ 1);
1165 static void prefs_filtering_bottom(void)
1168 GtkTreeIter top
, sel
;
1169 GtkTreeModel
*model
;
1171 model
= gtk_tree_view_get_model(GTK_TREE_VIEW(filtering
.cond_list_view
));
1172 n_rows
= gtk_tree_model_iter_n_children(model
, NULL
);
1173 row
= prefs_filtering_get_selected_row(filtering
.cond_list_view
);
1174 if (row
< 1 || row
>= n_rows
- 1)
1177 if (!gtk_tree_model_iter_nth_child(model
, &top
, NULL
, row
)
1178 || !gtk_tree_model_iter_nth_child(model
, &sel
, NULL
, n_rows
- 1))
1181 gtk_list_store_move_after(GTK_LIST_STORE(model
), &top
, &sel
);
1182 prefs_filtering_list_view_select_row(filtering
.cond_list_view
, n_rows
- 1);
1185 static void prefs_filtering_select_set(FilteringProp
*prop
)
1190 prefs_filtering_reset_dialog();
1192 matcher_str
= matcherlist_to_string(prop
->matchers
);
1193 if (matcher_str
== NULL
) {
1197 if (prop
->name
!= NULL
)
1198 gtk_entry_set_text(GTK_ENTRY(filtering
.name_entry
), prop
->name
);
1200 combobox_select_by_data(GTK_COMBO_BOX(filtering
.account_combobox
), prop
->account_id
);
1202 gtk_entry_set_text(GTK_ENTRY(filtering
.cond_entry
), matcher_str
);
1204 action_str
= filteringaction_list_to_string(prop
->action_list
);
1205 if (matcher_str
== NULL
) {
1208 gtk_entry_set_text(GTK_ENTRY(filtering
.action_entry
), action_str
);
1211 g_free(matcher_str
);
1214 static gint
prefs_filtering_deleted(GtkWidget
*widget
, GdkEventAny
*event
,
1217 prefs_filtering_cancel();
1221 static gboolean
prefs_filtering_key_pressed(GtkWidget
*widget
, GdkEventKey
*event
,
1224 if (event
&& event
->keyval
== GDK_Escape
) {
1225 prefs_filtering_cancel();
1231 static void prefs_filtering_ok(void)
1233 FilteringProp
* prop
;
1235 gchar
* filtering_str
;
1239 prop
= prefs_filtering_dialog_to_filtering(FALSE
);
1241 str
= filteringprop_to_string(prop
);
1243 while (NULL
!= (filtering_str
= (prefs_filtering_list_view_get_rule
1244 (filtering
.cond_list_view
,
1246 if (strcmp(filtering_str
, str
) == 0)
1249 g_free(filtering_str
);
1252 if (!filtering_str
) {
1253 val
= alertpanel(_("Entry not saved"),
1254 _("The entry was not saved. Close anyway?"),
1255 GTK_STOCK_CLOSE
, _("+_Continue editing"), NULL
);
1256 if (G_ALERTDEFAULT
!= val
) {
1257 g_free(filtering_str
);
1258 g_free(str
); /* fixed two leaks: huzzah! */
1259 filteringprop_free(prop
);
1264 g_free(filtering_str
);
1266 filteringprop_free(prop
); /* fixed a leak: huzzah! */
1268 gchar
*name
, *condition
, *action
;
1269 name
= gtk_editable_get_chars(GTK_EDITABLE(filtering
.name_entry
), 0, -1);
1270 condition
= gtk_editable_get_chars(GTK_EDITABLE(filtering
.cond_entry
), 0, -1);
1271 action
= gtk_editable_get_chars(GTK_EDITABLE(filtering
.action_entry
), 0, -1);
1273 strlen(condition
) ||
1275 val
= alertpanel(_("Entry not saved"),
1276 _("The entry was not saved. Close anyway?"),
1277 GTK_STOCK_CLOSE
, _("+_Continue editing"), NULL
);
1278 if (G_ALERTDEFAULT
!= val
) {
1289 prefs_filtering_set_list();
1290 prefs_matcher_write_config();
1291 prefs_filtering_close();
1294 static void prefs_filtering_cancel(void)
1296 prefs_matcher_read_config();
1297 prefs_filtering_close();
1300 static GtkListStore
* prefs_filtering_create_data_store(void)
1302 return gtk_list_store_new(N_PREFS_FILTERING_COLUMNS
,
1313 *\brief Insert filtering rule into store. Note that we access the
1314 * tree view / store by index, which is a bit suboptimal, but
1315 * at least it made GTK 2 porting easier.
1317 *\param list_store Store to operate on
1318 *\param row -1 to add a new rule to store, else change an existing
1320 *\param enabled TRUE if rule is enabled
1321 *\param name The Name of rule
1322 *\param account_id The account ID
1323 *\param account_name The account name or All or (New)
1324 *\param rule String representation of rule
1325 *\param prop TRUE if valid filtering rule; if FALSE it's the first
1326 * entry in the store ("(New)").
1328 *\return int Row of inserted / changed rule.
1330 static gint
prefs_filtering_list_view_insert_rule(GtkListStore
*list_store
,
1335 const gchar
*account_name
,
1341 /* check if valid row at all */
1343 if (!gtk_tree_model_iter_nth_child(GTK_TREE_MODEL(list_store
),
1350 gtk_list_store_append(list_store
, &iter
);
1351 gtk_list_store_set(list_store
, &iter
,
1352 PREFS_FILTERING_ENABLED
, enabled
,
1353 PREFS_FILTERING_NAME
, name
,
1354 PREFS_FILTERING_ACCOUNT_ID
, account_id
,
1355 PREFS_FILTERING_ACCOUNT_NAME
, account_name
,
1356 PREFS_FILTERING_RULE
, rule
,
1357 PREFS_FILTERING_PROP
, prop
,
1359 return gtk_tree_model_iter_n_children(GTK_TREE_MODEL(list_store
),
1362 /* change existing */
1363 gtk_list_store_set(list_store
, &iter
,
1364 PREFS_FILTERING_ENABLED
, enabled
,
1365 PREFS_FILTERING_NAME
, name
,
1366 PREFS_FILTERING_ACCOUNT_ID
, account_id
,
1367 PREFS_FILTERING_ACCOUNT_NAME
, account_name
,
1368 PREFS_FILTERING_RULE
, rule
,
1375 *\return gchar * Rule at specified row - should be freed.
1377 static gchar
*prefs_filtering_list_view_get_rule(GtkWidget
*list
, gint row
)
1379 GtkTreeView
*list_view
= GTK_TREE_VIEW(list
);
1380 GtkTreeModel
*model
= gtk_tree_view_get_model(list_view
);
1384 if (!gtk_tree_model_iter_nth_child(model
, &iter
, NULL
, row
))
1387 gtk_tree_model_get(model
, &iter
,
1388 PREFS_FILTERING_RULE
, &result
,
1394 static void prefs_filtering_list_view_get_rule_info(GtkWidget
*list
, gint row
,
1395 gboolean
*enabled
, gchar
**name
, gint
*account_id
)
1397 GtkTreeView
*list_view
= GTK_TREE_VIEW(list
);
1398 GtkTreeModel
*model
= gtk_tree_view_get_model(list_view
);
1404 if (gtk_tree_model_iter_nth_child(model
, &iter
, NULL
, row
)) {
1405 gtk_tree_model_get(model
, &iter
,
1406 PREFS_FILTERING_ENABLED
, enabled
,
1407 PREFS_FILTERING_NAME
, name
,
1408 PREFS_FILTERING_ACCOUNT_ID
, account_id
,
1414 *\brief Create list view for filtering
1416 static GtkWidget
*prefs_filtering_list_view_create(void)
1418 GtkTreeView
*list_view
;
1419 GtkTreeSelection
*selector
;
1421 list_view
= GTK_TREE_VIEW(gtk_tree_view_new_with_model(GTK_TREE_MODEL
1422 (prefs_filtering_create_data_store())));
1424 gtk_tree_view_set_rules_hint(list_view
, prefs_common
.use_stripes_everywhere
);
1425 gtk_tree_view_set_reorderable(list_view
, TRUE
);
1427 selector
= gtk_tree_view_get_selection(list_view
);
1428 gtk_tree_selection_set_mode(selector
, GTK_SELECTION_BROWSE
);
1429 gtk_tree_selection_set_select_function(selector
, prefs_filtering_selected
,
1432 /* create the columns */
1433 prefs_filtering_create_list_view_columns(GTK_WIDGET(list_view
));
1435 return GTK_WIDGET(list_view
);
1438 static void prefs_filtering_enable_toggled(GtkCellRendererToggle
*widget
,
1440 GtkWidget
*list_view
)
1443 GtkTreeModel
*model
= gtk_tree_view_get_model(GTK_TREE_VIEW(list_view
));
1444 gboolean enabled
= TRUE
;
1446 if (!gtk_tree_model_get_iter_from_string(model
, &iter
, path
))
1449 gtk_tree_model_get(model
, &iter
,
1450 PREFS_FILTERING_ENABLED
, &enabled
,
1453 gtk_list_store_set(GTK_LIST_STORE(model
), &iter
,
1454 PREFS_FILTERING_ENABLED
, !enabled
,
1458 static void prefs_filtering_create_list_view_columns(GtkWidget
*list_view
)
1460 GtkTreeViewColumn
*column
;
1461 GtkCellRenderer
*renderer
;
1463 renderer
= gtk_cell_renderer_toggle_new();
1464 g_object_set(renderer
,
1466 "activatable", TRUE
,
1468 column
= gtk_tree_view_column_new_with_attributes
1469 (_("Enable"), /* FIXME : Enable, Enabled, or 'E' ? */
1471 "active", PREFS_FILTERING_ENABLED
,
1473 gtk_tree_view_column_set_alignment (column
, 0.5);
1474 gtk_tree_view_append_column(GTK_TREE_VIEW(list_view
), column
);
1475 g_signal_connect(G_OBJECT(renderer
), "toggled",
1476 G_CALLBACK(prefs_filtering_enable_toggled
),
1479 renderer
= gtk_cell_renderer_text_new();
1480 column
= gtk_tree_view_column_new_with_attributes
1483 "text", PREFS_FILTERING_NAME
,
1485 gtk_tree_view_append_column(GTK_TREE_VIEW(list_view
), column
);
1486 gtk_tree_view_column_set_resizable(column
, TRUE
);
1488 renderer
= gtk_cell_renderer_text_new();
1489 column
= gtk_tree_view_column_new_with_attributes
1492 "text", PREFS_FILTERING_ACCOUNT_NAME
,
1494 gtk_tree_view_append_column(GTK_TREE_VIEW(list_view
), column
);
1495 gtk_tree_view_column_set_resizable(column
, TRUE
);
1497 filtering
.account_name_column
= column
;
1499 renderer
= gtk_cell_renderer_text_new();
1500 column
= gtk_tree_view_column_new_with_attributes
1503 "text", PREFS_FILTERING_RULE
,
1505 gtk_tree_view_append_column(GTK_TREE_VIEW(list_view
), column
);
1508 static gboolean
gtkut_tree_iter_comp(GtkTreeModel
*model
,
1512 GtkTreePath
*path1
= gtk_tree_model_get_path(model
, iter1
);
1513 GtkTreePath
*path2
= gtk_tree_model_get_path(model
, iter2
);
1516 result
= gtk_tree_path_compare(path1
, path2
) == 0;
1518 gtk_tree_path_free(path1
);
1519 gtk_tree_path_free(path2
);
1525 *\brief Get selected row number.
1527 static gint
prefs_filtering_get_selected_row(GtkWidget
*list_view
)
1529 GtkTreeView
*view
= GTK_TREE_VIEW(list_view
);
1530 GtkTreeModel
*model
= gtk_tree_view_get_model(view
);
1531 int n_rows
= gtk_tree_model_iter_n_children(model
, NULL
);
1532 GtkTreeSelection
*selection
;
1539 selection
= gtk_tree_view_get_selection(view
);
1540 if (!gtk_tree_selection_get_selected(selection
, &model
, &iter
))
1543 /* get all iterators and compare them... */
1544 for (row
= 0; row
< n_rows
; row
++) {
1547 gtk_tree_model_iter_nth_child(model
, &itern
, NULL
, row
);
1548 if (gtkut_tree_iter_comp(model
, &iter
, &itern
))
1555 static gboolean
prefs_filtering_list_view_select_row(GtkWidget
*list
, gint row
)
1557 GtkTreeView
*list_view
= GTK_TREE_VIEW(list
);
1558 GtkTreeSelection
*selection
= gtk_tree_view_get_selection(list_view
);
1559 GtkTreeModel
*model
= gtk_tree_view_get_model(list_view
);
1563 if (!gtk_tree_model_iter_nth_child(model
, &iter
, NULL
, row
))
1566 gtk_tree_selection_select_iter(selection
, &iter
);
1568 path
= gtk_tree_model_get_path(model
, &iter
);
1569 gtk_tree_view_set_cursor(list_view
, path
, NULL
, FALSE
);
1570 gtk_tree_path_free(path
);
1576 *\brief Triggered when a row is selected
1578 static gboolean
prefs_filtering_selected(GtkTreeSelection
*selector
,
1579 GtkTreeModel
*model
,
1581 gboolean currently_selected
,
1584 if (currently_selected
)
1587 gboolean has_prop
= FALSE
;
1590 gtk_tree_model_get_iter(model
, &iter
, path
);
1591 gtk_tree_model_get(model
, &iter
,
1592 PREFS_FILTERING_PROP
, &has_prop
,
1596 FilteringProp
*prop
;
1597 gchar
*filtering_str
= NULL
;
1599 gint account_id
= 0;
1601 gtk_tree_model_get(model
, &iter
,
1602 PREFS_FILTERING_RULE
, &filtering_str
,
1604 gtk_tree_model_get(model
, &iter
,
1605 PREFS_FILTERING_NAME
, &name
,
1607 gtk_tree_model_get(model
, &iter
,
1608 PREFS_FILTERING_ACCOUNT_ID
, &account_id
,
1611 prop
= matcher_parser_get_filtering(filtering_str
);
1613 prop
->name
= g_strdup(name
);
1614 prop
->account_id
= account_id
;
1615 prefs_filtering_select_set(prop
);
1616 filteringprop_free(prop
);
1619 g_free(filtering_str
);
1621 prefs_filtering_reset_dialog();