2 * Claws Mail -- a GTK+ based, lightweight, and fast e-mail client
3 * Copyright (C) 2003-2007 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/>.
27 #include <glib/gi18n.h>
29 #include <gdk/gdkkeysyms.h>
36 #include "prefs_gtk.h"
37 #include "prefs_filtering_action.h"
38 #include "prefs_common.h"
39 #include "mainwindow.h"
40 #include "foldersel.h"
41 #include "manage_window.h"
46 #include "alertpanel.h"
48 #include "description_window.h"
49 #include "addr_compl.h"
51 #include "matcher_parser.h"
52 #include "colorlabel.h"
62 static void prefs_filtering_action_create(void);
63 static void prefs_filtering_action_delete_cb(void);
64 static void prefs_filtering_action_substitute_cb(void);
65 static void prefs_filtering_action_register_cb(void);
66 static void prefs_filtering_action_reset_dialog(void);
67 static gboolean
prefs_filtering_action_key_pressed(GtkWidget
*widget
,
68 GdkEventKey
*event
, gpointer data
);
69 static void prefs_filtering_action_cancel(void);
70 static void prefs_filtering_action_ok(void);
71 static gint
prefs_filtering_action_deleted(GtkWidget
*widget
,
72 GdkEventAny
*event
, gpointer data
);
73 static void prefs_filtering_action_type_selection_changed(GtkWidget
*widget
,
75 static void prefs_filtering_action_select_dest(void);
76 static void prefs_filtering_action_select_addressbook(void);
77 static void prefs_filtering_action_up(void);
78 static void prefs_filtering_action_down(void);
79 static void prefs_filtering_action_set_dialog(GSList
*action_list
);
80 static GSList
*prefs_filtering_action_get_list(void);
82 static GtkListStore
* prefs_filtering_action_create_data_store (void);
83 static void prefs_filtering_action_list_view_insert_action (GtkWidget
*list_view
,
87 static GtkWidget
*prefs_filtering_action_list_view_create (void);
88 static void prefs_filtering_action_create_list_view_columns (GtkTreeView
*list_view
);
89 static gboolean
prefs_filtering_actions_selected (GtkTreeSelection
*selector
,
92 gboolean currently_selected
,
95 static void prefs_filtering_action_exec_info (GtkWidget
*widget
,
99 *\brief UI data for matcher dialog
101 static struct FilteringAction_
{
106 GtkWidget
*action_list_view
;
110 GtkWidget
*action_combo
;
111 GtkWidget
*account_combo
;
112 GtkWidget
*dest_entry
;
115 GtkWidget
*color_optmenu
;
116 GtkWidget
*header_combo
;
117 GtkWidget
*header_entry
;
118 GtkWidget
*addressbook_btn
;
119 GtkWidget
*score_entry
;
120 GtkWidget
*tags_combo
;
126 typedef enum Action_
{
135 ACTION_MARK_AS_UNREAD
,
139 ACTION_FORWARD_AS_ATTACHMENT
,
151 ACTION_ADD_TO_ADDRESSBOOK
,
153 /* add other action constants */
161 { NULL
, N_("Move"), ACTION_MOVE
},
162 { NULL
, N_("Copy"), ACTION_COPY
},
163 { NULL
, N_("Delete"), ACTION_DELETE
},
164 { NULL
, N_("Hide"), ACTION_HIDE
},
165 { N_("Message flags"), N_("Mark"), ACTION_MARK
},
166 { N_("Message flags"), N_("Unmark"), ACTION_UNMARK
},
167 { N_("Message flags"), N_("Lock"), ACTION_LOCK
},
168 { N_("Message flags"), N_("Unlock"), ACTION_UNLOCK
},
169 { N_("Message flags"), N_("Mark as read"), ACTION_MARK_AS_READ
},
170 { N_("Message flags"), N_("Mark as unread"), ACTION_MARK_AS_UNREAD
},
171 { N_("Message flags"), N_("Mark as spam"), ACTION_MARK_AS_SPAM
},
172 { N_("Message flags"), N_("Mark as ham"), ACTION_MARK_AS_HAM
},
173 { NULL
, N_("Execute"), ACTION_EXECUTE
},
174 { NULL
, N_("Color label"), ACTION_COLOR
},
175 { N_("Resend"), N_("Forward"), ACTION_FORWARD
},
176 { N_("Resend"), N_("Forward as attachment"), ACTION_FORWARD_AS_ATTACHMENT
},
177 { N_("Resend"), N_("Redirect"), ACTION_REDIRECT
},
178 { N_("Score"), N_("Change score"), ACTION_CHANGE_SCORE
},
179 { N_("Score"), N_("Set score"), ACTION_SET_SCORE
},
180 { N_("Tags"), N_("Apply tag"), ACTION_SET_TAG
},
181 { N_("Tags"), N_("Unset tag"), ACTION_UNSET_TAG
},
182 { N_("Tags"), N_("Clear tags"), ACTION_CLEAR_TAGS
},
183 { N_("Threads"), N_("Ignore thread"), ACTION_IGNORE
},
184 { N_("Threads"), N_("Watch thread"), ACTION_WATCH
},
185 { NULL
, N_("Add to address book"), ACTION_ADD_TO_ADDRESSBOOK
},
186 { NULL
, N_("Stop filter"), ACTION_STOP
},
200 static PrefsFilteringActionSignal
*filtering_action_callback
;
202 static GtkTreeModel
*prefs_filtering_action_create_model(void)
204 GtkTreeIter iter
, iter2
;
206 gchar
*curr_menu
= NULL
;
209 store
= gtk_tree_store_new(N_ACTION_COMBO
, G_TYPE_STRING
, G_TYPE_INT
,
212 for (i
= 0; action_menu
[i
].menu
|| action_menu
[i
].text
; i
++)
214 if (action_menu
[i
].menu
) {
215 if (!curr_menu
|| strcmp(action_menu
[i
].menu
, curr_menu
)) {
216 gtk_tree_store_append(store
, &iter
, NULL
);
217 gtk_tree_store_set(store
, &iter
,
219 gettext(action_menu
[i
].menu
),
220 ACTION_COMBO_SENS
, TRUE
,
222 curr_menu
= action_menu
[i
].menu
;
225 gtk_tree_store_append(store
, &iter2
, &iter
);
226 gtk_tree_store_set(store
, &iter2
,
227 ACTION_COMBO_TEXT
, gettext(action_menu
[i
].text
),
228 ACTION_COMBO_DATA
, action_menu
[i
].action
,
229 ACTION_COMBO_SENS
, TRUE
,
234 gtk_tree_store_append(store
, &iter
, NULL
);
235 gtk_tree_store_set(store
, &iter
,
236 ACTION_COMBO_TEXT
, gettext(action_menu
[i
].text
),
237 ACTION_COMBO_DATA
, action_menu
[i
].action
,
238 ACTION_COMBO_SENS
, TRUE
,
243 return GTK_TREE_MODEL(store
);
246 static void cell_is_sensitive(GtkCellLayout
*cell_layout
,
247 GtkCellRenderer
*cell
,
248 GtkTreeModel
*tree_model
,
252 if(gtk_tree_model_iter_has_child (tree_model
, iter
)) {
253 g_object_set (cell
, "sensitive", FALSE
, NULL
);
258 *\brief Opens the filtering action dialog with a list of actions
260 *\param matchers List of conditions
264 void prefs_filtering_action_open(GSList
*action_list
,
265 PrefsFilteringActionSignal
*cb
)
269 if (!filtering_action
.window
) {
270 prefs_filtering_action_create();
272 /* update color label menu */
273 gtk_option_menu_set_menu(GTK_OPTION_MENU(filtering_action
.color_optmenu
),
274 colorlabel_create_color_menu());
277 manage_window_set_transient(GTK_WINDOW(filtering_action
.window
));
278 gtk_widget_grab_focus(filtering_action
.ok_btn
);
280 filtering_action_callback
= cb
;
282 prefs_filtering_action_set_dialog(action_list
);
284 gtk_widget_show(filtering_action
.window
);
288 *\brief Save Gtk object size to prefs dataset
290 static void prefs_filtering_action_size_allocate_cb(GtkWidget
*widget
,
291 GtkAllocation
*allocation
)
293 g_return_if_fail(allocation
!= NULL
);
295 prefs_common
.filteringactionwin_width
= allocation
->width
;
296 prefs_common
.filteringactionwin_height
= allocation
->height
;
299 #define LABELS_WIDTH 80
300 #define SECOND_ROW_WIDTH 250
302 static void prefs_filtering_action_check_widget_width(GtkWidget
*widget
)
306 gtk_widget_size_request(widget
, &req
);
307 if(req
.width
> SECOND_ROW_WIDTH
)
308 gtk_widget_set_size_request(widget
, SECOND_ROW_WIDTH
, -1);
312 *\brief Create the matcher dialog
314 static void prefs_filtering_action_create(void)
319 GtkWidget
*cancel_btn
;
320 GtkWidget
*confirm_area
;
330 GtkWidget
*action_combo
;
331 GtkWidget
*account_combo
;
332 GtkWidget
*header_combo
;
333 GtkWidget
*header_entry
;
334 GtkWidget
*addressbook_btn
;
335 GtkWidget
*dest_entry
;
337 GtkWidget
*score_entry
;
338 GtkWidget
*tags_combo
;
344 GtkWidget
*subst_btn
;
347 GtkWidget
*action_hbox
;
348 GtkWidget
*action_scrolledwin
;
349 GtkWidget
*action_list_view
;
357 GtkWidget
*color_optmenu
;
359 static GdkGeometry geometry
;
364 GtkSizeGroup
*size_group
= gtk_size_group_new(GTK_SIZE_GROUP_HORIZONTAL
);
365 GtkSizeGroup
*size_action
= gtk_size_group_new(GTK_SIZE_GROUP_HORIZONTAL
);
367 GtkCellRenderer
*renderer
;
369 debug_print("Creating matcher configuration window...\n");
371 window
= gtkut_window_new(GTK_WINDOW_TOPLEVEL
, "prefs_filtering_action");
372 gtk_container_set_border_width(GTK_CONTAINER(window
), VBOX_BORDER
);
373 gtk_window_set_position(GTK_WINDOW(window
), GTK_WIN_POS_CENTER
);
374 gtk_window_set_modal(GTK_WINDOW(window
), TRUE
);
375 gtk_window_set_resizable(GTK_WINDOW(window
), TRUE
);
377 vbox
= gtk_vbox_new(FALSE
, 6);
378 gtk_container_add(GTK_CONTAINER(window
), vbox
);
380 gtkut_stock_button_set_create(&confirm_area
,
381 &cancel_btn
, GTK_STOCK_CANCEL
,
382 &ok_btn
, GTK_STOCK_OK
,
384 gtk_box_pack_end(GTK_BOX(vbox
), confirm_area
, FALSE
, FALSE
, 0);
385 gtk_widget_grab_default(ok_btn
);
387 gtk_window_set_title(GTK_WINDOW(window
),
388 _("Action configuration"));
389 g_signal_connect(G_OBJECT(window
), "delete_event",
390 G_CALLBACK(prefs_filtering_action_deleted
), NULL
);
391 g_signal_connect(G_OBJECT(window
), "size_allocate",
392 G_CALLBACK(prefs_filtering_action_size_allocate_cb
), NULL
);
393 g_signal_connect(G_OBJECT(window
), "key_press_event",
394 G_CALLBACK(prefs_filtering_action_key_pressed
), NULL
);
395 MANAGE_WINDOW_SIGNALS_CONNECT(window
);
396 g_signal_connect(G_OBJECT(ok_btn
), "clicked",
397 G_CALLBACK(prefs_filtering_action_ok
), NULL
);
398 g_signal_connect(G_OBJECT(cancel_btn
), "clicked",
399 G_CALLBACK(prefs_filtering_action_cancel
), NULL
);
401 vbox1
= gtk_vbox_new(FALSE
, VSPACING
);
402 gtk_box_pack_start(GTK_BOX(vbox
), vbox1
, TRUE
, TRUE
, 0);
403 gtk_container_set_border_width(GTK_CONTAINER (vbox1
), 2);
405 frame
= gtk_frame_new(_("Rule"));
406 gtk_frame_set_label_align(GTK_FRAME(frame
), 0.01, 0.5);
407 gtk_box_pack_start (GTK_BOX (vbox1
), frame
, FALSE
, FALSE
, 0);
408 gtk_widget_set_size_request(frame
, -1, 110);
410 table
= gtk_table_new(3, 3, FALSE
);
411 gtk_container_set_border_width(GTK_CONTAINER(table
), 2);
412 gtk_table_set_row_spacings (GTK_TABLE (table
), VSPACING_NARROW_2
);
413 gtk_table_set_col_spacings (GTK_TABLE (table
), HSPACING_NARROW
);
414 gtk_container_add(GTK_CONTAINER(frame
), table
);
416 /* first row labels */
418 label1
= gtk_label_new (_("Action"));
419 gtk_widget_set_size_request(label1
, LABELS_WIDTH
, -1);
420 gtk_size_group_add_widget(size_group
, label1
);
421 gtk_misc_set_alignment (GTK_MISC (label1
), 1, 0.5);
422 gtk_table_attach(GTK_TABLE(table
), label1
, 0, 1, 0, 1,
423 GTK_FILL
, GTK_SHRINK
, 0, 0);
425 label2
= gtk_label_new ("");
426 gtk_size_group_add_widget(size_group
, label2
);
427 gtk_misc_set_alignment (GTK_MISC (label2
), 1, 0.5);
428 gtk_table_attach(GTK_TABLE(table
), label2
, 0, 1, 1, 2,
429 GTK_FILL
, GTK_SHRINK
, 0, 0);
431 label3
= gtk_label_new ("");
432 gtk_size_group_add_widget(size_group
, label3
);
433 gtk_misc_set_alignment (GTK_MISC (label3
), 1, 0.5);
434 gtk_table_attach(GTK_TABLE(table
), label3
, 0, 1, 2, 3,
435 GTK_FILL
, GTK_SHRINK
, 0, 0);
439 hbox1
= gtk_hbox_new(FALSE
, 0);
440 gtk_table_attach(GTK_TABLE(table
), hbox1
, 1, 2, 0, 1,
441 GTK_FILL
, GTK_SHRINK
, 0, 0);
443 model
= prefs_filtering_action_create_model();
444 action_combo
= gtk_combo_box_new_with_model(model
);
445 gtk_size_group_add_widget(size_action
, action_combo
);
447 renderer
= gtk_cell_renderer_text_new();
448 gtk_cell_layout_pack_start(GTK_CELL_LAYOUT(action_combo
), renderer
, TRUE
);
449 gtk_cell_layout_set_attributes(GTK_CELL_LAYOUT(action_combo
), renderer
,
450 "text", ACTION_COMBO_TEXT
,
451 "sensitive", ACTION_COMBO_SENS
,
453 gtk_cell_layout_set_cell_data_func(GTK_CELL_LAYOUT(action_combo
), renderer
,
454 cell_is_sensitive
, NULL
, NULL
);
456 combobox_select_by_data(GTK_COMBO_BOX(action_combo
), ACTION_MOVE
);
457 g_signal_connect(G_OBJECT(action_combo
), "changed",
458 G_CALLBACK(prefs_filtering_action_type_selection_changed
),
460 gtk_box_pack_start(GTK_BOX(hbox1
), action_combo
, FALSE
, FALSE
, 0);
461 gtk_box_pack_start(GTK_BOX(hbox1
), gtk_label_new(""), TRUE
, TRUE
, 0);
465 hbox1
= gtk_hbox_new (FALSE
, 0);
466 gtk_table_attach(GTK_TABLE(table
), hbox1
, 1, 2, 1, 2,
467 GTK_FILL
| GTK_EXPAND
, GTK_SHRINK
, 0, 0);
469 account_combo
= gtk_combo_box_new_text ();
470 gtk_size_group_add_widget(size_action
, account_combo
);
472 for (accounts
= account_get_list() ; accounts
!= NULL
;
473 accounts
= accounts
->next
) {
474 PrefsAccount
*ac
= (PrefsAccount
*)accounts
->data
;
475 gchar
*name
= g_strdup(ac
->account_name
);
476 gtk_combo_box_append_text(GTK_COMBO_BOX(account_combo
), (gpointer
) name
);
480 prefs_filtering_action_check_widget_width(account_combo
);
481 gtk_combo_box_set_active(GTK_COMBO_BOX(account_combo
), 0);
482 gtk_box_pack_start (GTK_BOX (hbox1
), account_combo
,
487 header_combo
= combobox_text_new(TRUE
, "From", "To", "Cc", "Reply-To", "Sender", NULL
);
488 gtk_size_group_add_widget(size_action
, header_combo
);
489 gtk_box_pack_start (GTK_BOX (hbox1
), header_combo
,
491 header_entry
= GTK_BIN(header_combo
)->child
;
495 hbox1
= gtk_hbox_new (FALSE
, 0);
496 gtk_table_attach(GTK_TABLE(table
), hbox1
, 1, 2, 2, 3,
497 GTK_FILL
| GTK_EXPAND
, GTK_SHRINK
, 0, 0);
499 dest_entry
= gtk_entry_new ();
500 gtk_box_pack_start (GTK_BOX (hbox1
), dest_entry
, TRUE
, TRUE
, 0);
502 score_entry
= gtk_spin_button_new_with_range(-1000, 1000, 1);
503 gtk_box_pack_start(GTK_BOX(hbox1
), score_entry
, FALSE
, FALSE
, 0);
505 color_optmenu
= gtk_option_menu_new();
506 gtk_size_group_add_widget(size_action
, color_optmenu
);
507 gtk_option_menu_set_menu(GTK_OPTION_MENU(color_optmenu
),
508 colorlabel_create_color_menu());
509 prefs_filtering_action_check_widget_width(color_optmenu
);
510 gtk_box_pack_start(GTK_BOX(hbox1
), color_optmenu
, FALSE
, FALSE
, 0);
512 tags_combo
= gtk_combo_box_new_text ();
513 gtk_size_group_add_widget(size_action
, tags_combo
);
515 for (tmp
= tags
= tags_get_list() ; tmp
!= NULL
;
517 gchar
*name
= g_strdup(tags_get_tag(GPOINTER_TO_INT(tmp
->data
)));
519 gtk_combo_box_append_text(GTK_COMBO_BOX(tags_combo
), (gpointer
) name
);
523 prefs_filtering_action_check_widget_width(tags_combo
);
524 gtk_combo_box_set_active(GTK_COMBO_BOX(tags_combo
), 0);
525 gtk_box_pack_start (GTK_BOX (hbox1
), tags_combo
,
528 hbox1
= gtk_hbox_new (FALSE
, 0);
529 gtk_table_attach(GTK_TABLE(table
), hbox1
, 2, 3, 2, 3,
530 GTK_FILL
, GTK_SHRINK
, 0, 0);
532 dest_btn
= gtk_button_new_with_label (_("Select ..."));
533 gtk_box_pack_start (GTK_BOX (hbox1
), dest_btn
, FALSE
, FALSE
, 0);
534 g_signal_connect (G_OBJECT (dest_btn
), "clicked",
535 G_CALLBACK(prefs_filtering_action_select_dest
),
538 addressbook_btn
= gtk_button_new_with_label (_("Select ..."));
539 gtk_box_pack_start (GTK_BOX (hbox1
), addressbook_btn
, FALSE
, FALSE
, 0);
540 g_signal_connect (G_OBJECT (addressbook_btn
), "clicked",
541 G_CALLBACK(prefs_filtering_action_select_addressbook
),
544 #if GTK_CHECK_VERSION(2, 8, 0)
545 exec_btn
= gtk_button_new_from_stock(GTK_STOCK_INFO
);
547 exec_btn
= gtk_button_new_with_label (_("Info..."));
549 gtk_box_pack_start (GTK_BOX (hbox1
), exec_btn
, FALSE
, FALSE
, 0);
550 g_signal_connect (G_OBJECT (exec_btn
), "clicked",
551 G_CALLBACK(prefs_filtering_action_exec_info
),
554 /* register / substitute / delete */
556 reg_hbox
= gtk_hbox_new(FALSE
, 4);
557 gtk_box_pack_start(GTK_BOX(vbox1
), reg_hbox
, FALSE
, FALSE
, 0);
559 arrow
= gtk_arrow_new(GTK_ARROW_DOWN
, GTK_SHADOW_OUT
);
560 gtk_box_pack_start(GTK_BOX(reg_hbox
), arrow
, FALSE
, FALSE
, 0);
561 gtk_widget_set_size_request(arrow
, -1, 16);
563 btn_hbox
= gtk_hbox_new(TRUE
, 4);
564 gtk_box_pack_start(GTK_BOX(reg_hbox
), btn_hbox
, FALSE
, FALSE
, 0);
566 reg_btn
= gtk_button_new_from_stock(GTK_STOCK_ADD
);
567 gtk_box_pack_start(GTK_BOX(btn_hbox
), reg_btn
, FALSE
, TRUE
, 0);
568 g_signal_connect(G_OBJECT(reg_btn
), "clicked",
569 G_CALLBACK(prefs_filtering_action_register_cb
), NULL
);
571 subst_btn
= gtkut_get_replace_btn(_("Replace"));
572 gtk_box_pack_start(GTK_BOX(btn_hbox
), subst_btn
, FALSE
, TRUE
, 0);
573 g_signal_connect(G_OBJECT(subst_btn
), "clicked",
574 G_CALLBACK(prefs_filtering_action_substitute_cb
),
577 del_btn
= gtk_button_new_from_stock(GTK_STOCK_DELETE
);
578 gtk_box_pack_start(GTK_BOX(btn_hbox
), del_btn
, FALSE
, TRUE
, 0);
579 g_signal_connect(G_OBJECT(del_btn
), "clicked",
580 G_CALLBACK(prefs_filtering_action_delete_cb
), NULL
);
582 action_hbox
= gtk_hbox_new(FALSE
, 8);
583 gtk_box_pack_start(GTK_BOX(vbox1
), action_hbox
, TRUE
, TRUE
, 0);
585 action_scrolledwin
= gtk_scrolled_window_new(NULL
, NULL
);
586 gtk_widget_set_size_request(action_scrolledwin
, -1, 150);
587 gtk_box_pack_start(GTK_BOX(action_hbox
), action_scrolledwin
,
589 gtk_scrolled_window_set_shadow_type(GTK_SCROLLED_WINDOW(action_scrolledwin
),
590 GTK_SHADOW_ETCHED_IN
);
591 gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(action_scrolledwin
),
592 GTK_POLICY_AUTOMATIC
,
593 GTK_POLICY_AUTOMATIC
);
595 action_list_view
= prefs_filtering_action_list_view_create();
596 gtk_container_add(GTK_CONTAINER(action_scrolledwin
), action_list_view
);
598 btn_vbox
= gtk_vbox_new(FALSE
, 8);
599 gtk_box_pack_start(GTK_BOX(action_hbox
), btn_vbox
, FALSE
, FALSE
, 0);
601 up_btn
= gtk_button_new_from_stock(GTK_STOCK_GO_UP
);
602 gtk_box_pack_start(GTK_BOX(btn_vbox
), up_btn
, FALSE
, FALSE
, 0);
603 g_signal_connect(G_OBJECT(up_btn
), "clicked",
604 G_CALLBACK(prefs_filtering_action_up
), NULL
);
606 down_btn
= gtk_button_new_from_stock(GTK_STOCK_GO_DOWN
);
607 gtk_box_pack_start(GTK_BOX(btn_vbox
), down_btn
, FALSE
, FALSE
, 0);
608 g_signal_connect(G_OBJECT(down_btn
), "clicked",
609 G_CALLBACK(prefs_filtering_action_down
), NULL
);
611 if (!geometry
.min_height
) {
612 geometry
.min_width
= 490;
613 geometry
.min_height
= 348;
616 gtk_window_set_geometry_hints(GTK_WINDOW(window
), NULL
, &geometry
,
618 gtk_widget_set_size_request(window
, prefs_common
.filteringactionwin_width
,
619 prefs_common
.filteringactionwin_height
);
621 gtk_widget_show_all(window
);
623 filtering_action
.window
= window
;
624 filtering_action
.label1
= label1
;
625 filtering_action
.label2
= label2
;
626 filtering_action
.label3
= label3
;
627 filtering_action
.action_combo
= action_combo
;
628 filtering_action
.account_combo
= account_combo
;
629 filtering_action
.tags_combo
= tags_combo
;
630 filtering_action
.dest_entry
= dest_entry
;
631 filtering_action
.dest_btn
= dest_btn
;
632 filtering_action
.exec_btn
= exec_btn
;
633 filtering_action
.color_optmenu
= color_optmenu
;
634 filtering_action
.score_entry
= score_entry
;
635 filtering_action
.header_combo
= header_combo
;
636 filtering_action
.header_entry
= header_entry
;
637 filtering_action
.addressbook_btn
= addressbook_btn
;
638 filtering_action
.ok_btn
= ok_btn
;
639 filtering_action
.action_list_view
= action_list_view
;
641 prefs_filtering_action_type_selection_changed(NULL
, NULL
);
645 *\brief Set the contents of a row
647 *\param row Index of row to set
648 *\param prop Condition to set
651 static void prefs_filtering_action_list_view_set_row(GtkTreeIter
*row
,
652 FilteringAction
*action
)
656 if (row
== NULL
&& action
== NULL
) {
657 prefs_filtering_action_list_view_insert_action
658 (filtering_action
.action_list_view
,
659 NULL
, _("(New)"), FALSE
);
663 filteringaction_to_string(buf
, sizeof buf
, action
);
665 prefs_filtering_action_list_view_insert_action
666 (filtering_action
.action_list_view
,
671 *\brief Initializes dialog with a set of conditions
673 *\param matchers List of conditions
675 static void prefs_filtering_action_set_dialog(GSList
*action_list
)
679 gtk_list_store_clear(GTK_LIST_STORE(gtk_tree_view_get_model
680 (GTK_TREE_VIEW(filtering_action
.action_list_view
))));
682 prefs_filtering_action_list_view_set_row(NULL
, NULL
);
683 if (action_list
!= NULL
) {
684 for (cur
= action_list
; cur
!= NULL
;
685 cur
= g_slist_next(cur
)) {
686 FilteringAction
*action
;
687 action
= (FilteringAction
*) cur
->data
;
688 prefs_filtering_action_list_view_set_row(NULL
, action
);
692 prefs_filtering_action_reset_dialog();
694 combobox_set_sensitive(GTK_COMBO_BOX(filtering_action
.action_combo
), 9,
695 (tags_get_size() > 0) ? TRUE
: FALSE
);
699 *\brief Converts current actions in list box in
700 * an action list used by the filtering system.
702 *\return GSList * List of actions.
704 static GSList
*prefs_filtering_action_get_list(void)
710 GtkTreeView
*list_view
= GTK_TREE_VIEW(filtering_action
.action_list_view
);
711 GtkTreeModel
*model
= gtk_tree_view_get_model(list_view
);
716 while (gtk_tree_model_iter_nth_child(model
, &iter
, NULL
, row
)) {
718 gtk_tree_model_get(model
, &iter
,
719 PFA_ACTION
, &action_str
,
720 PFA_VALID_ACTION
, &is_valid
,
724 GSList
* tmp_action_list
;
725 tmp_action_list
= matcher_parser_get_action_list(action_str
);
727 if (tmp_action_list
== NULL
) {
732 action_list
= g_slist_concat(action_list
,
746 *\brief Returns account ID from the given list index
748 *\return gint account ID
750 static gint
get_account_id_from_list_id(gint list_id
)
754 for (accounts
= account_get_list() ; accounts
!= NULL
;
755 accounts
= accounts
->next
) {
756 PrefsAccount
*ac
= (PrefsAccount
*)accounts
->data
;
759 return ac
->account_id
;
766 *\brief Returns list index from the given account ID
768 *\return gint list index
770 static gint
get_list_id_from_account_id(gint account_id
)
775 for (accounts
= account_get_list() ; accounts
!= NULL
;
776 accounts
= accounts
->next
) {
777 PrefsAccount
*ac
= (PrefsAccount
*)accounts
->data
;
779 if (account_id
== ac
->account_id
)
788 *\brief Returns parser action ID from internal action ID
790 *\return gint parser action ID
792 static gint
prefs_filtering_action_get_matching_from_action(Action action_id
)
796 return MATCHACTION_MOVE
;
798 return MATCHACTION_SET_TAG
;
799 case ACTION_UNSET_TAG
:
800 return MATCHACTION_UNSET_TAG
;
801 case ACTION_CLEAR_TAGS
:
802 return MATCHACTION_CLEAR_TAGS
;
804 return MATCHACTION_COPY
;
806 return MATCHACTION_DELETE
;
808 return MATCHACTION_MARK
;
810 return MATCHACTION_UNMARK
;
812 return MATCHACTION_LOCK
;
814 return MATCHACTION_UNLOCK
;
815 case ACTION_MARK_AS_READ
:
816 return MATCHACTION_MARK_AS_READ
;
817 case ACTION_MARK_AS_UNREAD
:
818 return MATCHACTION_MARK_AS_UNREAD
;
819 case ACTION_MARK_AS_SPAM
:
820 return MATCHACTION_MARK_AS_SPAM
;
821 case ACTION_MARK_AS_HAM
:
822 return MATCHACTION_MARK_AS_HAM
;
824 return MATCHACTION_FORWARD
;
825 case ACTION_FORWARD_AS_ATTACHMENT
:
826 return MATCHACTION_FORWARD_AS_ATTACHMENT
;
827 case ACTION_REDIRECT
:
828 return MATCHACTION_REDIRECT
;
830 return MATCHACTION_EXECUTE
;
832 return MATCHACTION_COLOR
;
834 return MATCHACTION_HIDE
;
836 return MATCHACTION_IGNORE
;
838 return MATCHACTION_WATCH
;
840 return MATCHACTION_STOP
;
841 case ACTION_CHANGE_SCORE
:
842 return MATCHACTION_CHANGE_SCORE
;
843 case ACTION_SET_SCORE
:
844 return MATCHACTION_SET_SCORE
;
845 case ACTION_ADD_TO_ADDRESSBOOK
:
846 return MATCHACTION_ADD_TO_ADDRESSBOOK
;
853 *\brief Returns action from the content of the dialog
855 *\param alert specifies whether alert dialog boxes should be shown
858 *\return FilteringAction * action entered in the dialog box.
860 static FilteringAction
* prefs_filtering_action_dialog_to_action(gboolean alert
)
866 gchar
* destination
= NULL
;
868 FilteringAction
* action
;
870 gchar
* header
= NULL
;
872 action_id
= combobox_get_active_data(GTK_COMBO_BOX(filtering_action
.action_combo
));
873 action_type
= prefs_filtering_action_get_matching_from_action(action_id
);
874 list_id
= gtk_combo_box_get_active(GTK_COMBO_BOX(filtering_action
.account_combo
));
875 account_id
= get_account_id_from_list_id(list_id
);
883 destination
= gtk_editable_get_chars(GTK_EDITABLE(filtering_action
.dest_entry
), 0, -1);
884 if (*destination
== '\0') {
886 alertpanel_error(action_id
== ACTION_EXECUTE
887 ? _("Command line not set")
888 : _("Destination is not set."));
894 case ACTION_FORWARD_AS_ATTACHMENT
:
895 case ACTION_REDIRECT
:
896 destination
= gtk_editable_get_chars(GTK_EDITABLE(filtering_action
.dest_entry
), 0, -1);
897 if (*destination
== '\0') {
899 alertpanel_error(_("Recipient is not set."));
905 labelcolor
= colorlabel_get_color_menu_active_item(
906 gtk_option_menu_get_menu(GTK_OPTION_MENU(filtering_action
.color_optmenu
)));
909 case ACTION_CHANGE_SCORE
:
910 case ACTION_SET_SCORE
:
911 score
= gtk_spin_button_get_value_as_int(GTK_SPIN_BUTTON(
912 filtering_action
.score_entry
));
913 if (!score
&& action_id
== ACTION_CHANGE_SCORE
) {
915 alertpanel_error(_("Score is not set"));
919 case ACTION_ADD_TO_ADDRESSBOOK
:
920 header
= gtk_editable_get_chars(GTK_EDITABLE(filtering_action
.header_entry
), 0, -1);
921 if (*header
== '\0') {
923 alertpanel_error(_("Header is not set."));
927 destination
= gtk_editable_get_chars(GTK_EDITABLE(filtering_action
.dest_entry
), 0, -1);
928 if (*destination
== '\0') {
930 alertpanel_error(_("Target addressbook/folder is not set."));
936 case ACTION_UNSET_TAG
:
937 destination
= gtk_combo_box_get_active_text(GTK_COMBO_BOX(filtering_action
.tags_combo
));
938 if (!destination
|| *destination
== '\0') {
940 alertpanel_error(_("Tag name is empty."));
954 case ACTION_MARK_AS_READ
:
955 case ACTION_MARK_AS_UNREAD
:
956 case ACTION_MARK_AS_SPAM
:
957 case ACTION_MARK_AS_HAM
:
958 case ACTION_CLEAR_TAGS
:
962 action
= filteringaction_new(action_type
, account_id
,
963 destination
, labelcolor
, score
, header
);
970 *\brief Signal handler for register button
972 static void prefs_filtering_action_register_cb(void)
974 FilteringAction
*action
;
976 action
= prefs_filtering_action_dialog_to_action(TRUE
);
980 prefs_filtering_action_list_view_set_row(NULL
, action
);
982 filteringaction_free(action
);
984 * (presumably gtk_list_select_item(), called by
985 * prefs_filtering_action_reset_dialog() activates
986 * what seems to be a bug. this causes any other
987 * list items to be unselectable)
988 * prefs_filtering_action_reset_dialog(); */
989 gtk_combo_box_set_active(GTK_COMBO_BOX(filtering_action
.account_combo
), 0);
990 gtk_combo_box_set_active(GTK_COMBO_BOX(filtering_action
.tags_combo
), 0);
991 gtk_entry_set_text(GTK_ENTRY(filtering_action
.dest_entry
), "");
995 *\brief Signal handler for substitute button
997 static void prefs_filtering_action_substitute_cb(void)
999 GtkTreeView
*list_view
= GTK_TREE_VIEW
1000 (filtering_action
.action_list_view
);
1001 GtkTreeSelection
*selection
= gtk_tree_view_get_selection(list_view
);
1002 GtkTreeModel
*model
;
1005 FilteringAction
*action
;
1007 if (!gtk_tree_selection_get_selected(selection
, &model
, &row
))
1010 gtk_tree_model_get(model
, &row
, PFA_VALID_ACTION
, &is_valid
, -1);
1014 action
= prefs_filtering_action_dialog_to_action(TRUE
);
1018 prefs_filtering_action_list_view_set_row(&row
, action
);
1020 filteringaction_free(action
);
1022 prefs_filtering_action_reset_dialog();
1026 *\brief Signal handler for delete button
1028 static void prefs_filtering_action_delete_cb(void)
1030 GtkTreeView
*list_view
= GTK_TREE_VIEW
1031 (filtering_action
.action_list_view
);
1032 GtkTreeSelection
*selection
= gtk_tree_view_get_selection(list_view
);
1033 GtkTreeModel
*model
;
1037 if (!gtk_tree_selection_get_selected(selection
, &model
, &row
))
1040 gtk_tree_model_get(model
, &row
, PFA_VALID_ACTION
, &is_valid
, -1);
1044 gtk_list_store_remove(GTK_LIST_STORE(model
), &row
);
1046 prefs_filtering_action_reset_dialog();
1050 *\brief Signal handler for 'move up' button
1052 static void prefs_filtering_action_up(void)
1054 GtkTreePath
*prev
, *sel
, *try;
1056 GtkListStore
*store
= NULL
;
1057 GtkTreeModel
*model
= NULL
;
1060 if (!gtk_tree_selection_get_selected
1061 (gtk_tree_view_get_selection
1062 (GTK_TREE_VIEW(filtering_action
.action_list_view
)),
1066 store
= (GtkListStore
*)model
;
1067 sel
= gtk_tree_model_get_path(GTK_TREE_MODEL(store
), &isel
);
1071 /* no move if we're at row 0 or 1, looks phony, but other
1072 * solutions are more convoluted... */
1073 try = gtk_tree_path_copy(sel
);
1074 if (!gtk_tree_path_prev(try) || !gtk_tree_path_prev(try)) {
1075 gtk_tree_path_free(try);
1076 gtk_tree_path_free(sel
);
1079 gtk_tree_path_free(try);
1081 prev
= gtk_tree_path_copy(sel
);
1082 if (gtk_tree_path_prev(prev
)) {
1083 gtk_tree_model_get_iter(GTK_TREE_MODEL(store
),
1085 gtk_list_store_swap(store
, &iprev
, &isel
);
1086 /* XXX: GTK2 select row?? */
1089 gtk_tree_path_free(sel
);
1090 gtk_tree_path_free(prev
);
1094 *\brief Signal handler for 'move down' button
1096 static void prefs_filtering_action_down(void)
1098 GtkListStore
*store
= NULL
;
1099 GtkTreeModel
*model
= NULL
;
1100 GtkTreeIter next
, sel
;
1103 if (!gtk_tree_selection_get_selected
1104 (gtk_tree_view_get_selection
1105 (GTK_TREE_VIEW(filtering_action
.action_list_view
)),
1109 store
= (GtkListStore
*)model
;
1110 try = gtk_tree_model_get_path(GTK_TREE_MODEL(store
), &sel
);
1114 /* move when not at row 0 ... */
1115 if (gtk_tree_path_prev(try)) {
1117 if (gtk_tree_model_iter_next(GTK_TREE_MODEL(store
), &next
))
1118 gtk_list_store_swap(store
, &next
, &sel
);
1121 gtk_tree_path_free(try);
1125 *\brief Handle key press
1127 *\param widget Widget receiving key press
1128 *\param event Key event
1129 *\param data User data
1131 static gboolean
prefs_filtering_action_key_pressed(GtkWidget
*widget
,
1132 GdkEventKey
*event
, gpointer data
)
1134 if (event
&& event
->keyval
== GDK_Escape
) {
1135 prefs_filtering_action_cancel();
1142 *\brief Cancel matcher dialog
1144 static void prefs_filtering_action_cancel(void)
1146 gtk_widget_destroy(filtering_action
.window
);
1147 filtering_action
.window
= NULL
;
1152 *\brief Accept current matchers
1154 static void prefs_filtering_action_ok(void)
1156 GSList
* action_list
;
1159 action_list
= prefs_filtering_action_get_list();
1161 if (action_list
== NULL
) {
1162 alertpanel_error(_("No action was defined."));
1166 if (filtering_action_callback
!= NULL
)
1167 filtering_action_callback(action_list
);
1168 for(cur
= action_list
; cur
!= NULL
; cur
= cur
->next
) {
1169 filteringaction_free(cur
->data
);
1171 g_slist_free(action_list
);
1173 gtk_widget_destroy(filtering_action
.window
);
1174 filtering_action
.window
= NULL
;
1179 *\brief Called when closing dialog box
1181 *\param widget Dialog widget
1182 *\param event Event info
1183 *\param data User data
1187 static gint
prefs_filtering_action_deleted(GtkWidget
*widget
,
1188 GdkEventAny
*event
, gpointer data
)
1190 prefs_filtering_action_cancel();
1195 * Strings describing exec format strings
1197 * When adding new lines, remember to put 2 strings for each line
1199 static gchar
*exec_desc_strings
[] = {
1200 "%%", N_("literal %"),
1201 "%s", N_("Subject"),
1206 "%i", N_("Message-ID"),
1207 "%n", N_("Newsgroups"),
1208 "%r", N_("References"),
1209 "%F", N_("filename (should not be modified)"),
1210 "\\n", N_("new line"),
1211 "\\", N_("escape character for quotes"),
1212 "\\\"", N_("quote character"),
1216 static DescriptionWindow exec_desc_win
= {
1220 N_("Filtering Action: 'Execute'"),
1221 N_("'Execute' allows you to send a message or message element "
1222 "to an external program or script.\n"
1223 "The following symbols can be used:"),
1228 *\brief Show Execute action's info
1230 static void prefs_filtering_action_exec_info(GtkWidget
*widget
, GtkWidget
*parent
)
1232 exec_desc_win
.parent
= parent
;
1233 description_window_create(&exec_desc_win
);
1236 static void prefs_filtering_action_select_dest(void)
1241 dest
= foldersel_folder_sel(NULL
, FOLDER_SEL_COPY
, NULL
, FALSE
);
1244 path
= folder_item_get_identifier(dest
);
1246 gtk_entry_set_text(GTK_ENTRY(filtering_action
.dest_entry
), path
);
1250 static void prefs_filtering_action_select_addressbook(void)
1252 const gchar
*folderpath
= NULL
;
1253 gchar
*new_path
= NULL
;
1255 folderpath
= gtk_entry_get_text(GTK_ENTRY(filtering_action
.dest_entry
));
1256 new_path
= addressbook_folder_selection(folderpath
);
1258 gtk_entry_set_text(GTK_ENTRY(filtering_action
.dest_entry
), new_path
);
1263 static void prefs_filtering_action_enable_widget(GtkWidget
* widget
, const gboolean enable
)
1265 g_return_if_fail(widget
!= NULL
);
1269 if(GTK_IS_COMBO_BOX(widget
) || GTK_IS_COMBO_BOX_ENTRY(widget
))
1270 gtk_combo_box_set_active(GTK_COMBO_BOX(widget
), 0);
1271 else if(GTK_IS_SPIN_BUTTON(widget
))
1272 gtk_spin_button_set_value(GTK_SPIN_BUTTON(widget
), 0);
1273 else if(GTK_IS_ENTRY(widget
)) {
1274 gtk_entry_set_text(GTK_ENTRY(widget
), "");
1275 } else if(GTK_IS_OPTION_MENU(widget
))
1276 gtk_option_menu_set_history(GTK_OPTION_MENU(widget
), 0);
1278 gtk_widget_set_sensitive(widget
, TRUE
);
1279 gtk_widget_show(widget
);
1281 gtk_widget_set_sensitive(widget
, FALSE
);
1282 gtk_widget_hide(widget
);
1286 #define ACTION_SEND(x) (x == ACTION_FORWARD || x == ACTION_REDIRECT || \
1287 x == ACTION_FORWARD_AS_ATTACHMENT)
1288 #define ACTION_SCORE(x) (x == ACTION_CHANGE_SCORE || x == ACTION_SET_SCORE)
1289 #define ACTION_TAG(x) (x == ACTION_SET_TAG || x == ACTION_UNSET_TAG)
1290 #define ACTION_FILEOP(x) (x == ACTION_MOVE || x == ACTION_COPY)
1292 static void prefs_filtering_action_type_selection_changed(GtkWidget
*combo
,
1297 value
= combobox_get_active_data(GTK_COMBO_BOX(filtering_action
.action_combo
));
1299 if (filtering_action
.current_action
!= value
) {
1300 if (ACTION_SEND(filtering_action
.current_action
)) {
1301 debug_print("unregistering address completion entry\n");
1302 address_completion_unregister_entry(GTK_ENTRY(filtering_action
.dest_entry
));
1303 address_completion_end(filtering_action
.window
);
1305 if (ACTION_SEND(value
)) {
1306 debug_print("registering address completion entry\n");
1307 address_completion_start(filtering_action
.window
);
1308 address_completion_register_entry(
1309 GTK_ENTRY(filtering_action
.dest_entry
),
1312 filtering_action
.current_action
= value
;
1315 prefs_filtering_action_enable_widget(filtering_action
.label2
,
1316 (ACTION_SEND(value
) || value
== ACTION_ADD_TO_ADDRESSBOOK
));
1318 prefs_filtering_action_enable_widget(filtering_action
.label3
,
1319 (ACTION_SEND(value
) || ACTION_TAG(value
) ||
1320 ACTION_SCORE(value
) || ACTION_FILEOP(value
) ||
1321 value
== ACTION_COLOR
|| value
== ACTION_EXECUTE
||
1322 value
== ACTION_ADD_TO_ADDRESSBOOK
));
1324 prefs_filtering_action_enable_widget(filtering_action
.account_combo
,
1325 ACTION_SEND(value
));
1327 prefs_filtering_action_enable_widget(filtering_action
.tags_combo
,
1330 prefs_filtering_action_enable_widget(filtering_action
.dest_entry
,
1331 (ACTION_FILEOP(value
) || value
== ACTION_EXECUTE
||
1332 ACTION_SEND(value
) || value
== ACTION_ADD_TO_ADDRESSBOOK
));
1334 prefs_filtering_action_enable_widget(filtering_action
.dest_btn
,
1335 ACTION_FILEOP(value
));
1337 prefs_filtering_action_enable_widget(filtering_action
.exec_btn
,
1338 (value
== ACTION_EXECUTE
));
1340 prefs_filtering_action_enable_widget(filtering_action
.color_optmenu
,
1341 (value
== ACTION_COLOR
));
1343 prefs_filtering_action_enable_widget(filtering_action
.header_combo
,
1344 (value
== ACTION_ADD_TO_ADDRESSBOOK
));
1346 prefs_filtering_action_enable_widget(filtering_action
.addressbook_btn
,
1347 (value
== ACTION_ADD_TO_ADDRESSBOOK
));
1349 prefs_filtering_action_enable_widget(filtering_action
.score_entry
,
1350 ACTION_SCORE(value
));
1353 case ACTION_FORWARD
:
1354 case ACTION_FORWARD_AS_ATTACHMENT
:
1355 case ACTION_REDIRECT
:
1356 gtk_label_set_text(GTK_LABEL(filtering_action
.label2
), _("Account"));
1357 gtk_label_set_text(GTK_LABEL(filtering_action
.label3
), _("Recipient"));
1359 case ACTION_ADD_TO_ADDRESSBOOK
:
1360 gtk_label_set_text(GTK_LABEL(filtering_action
.label2
), _("Header Name"));
1361 gtk_label_set_text(GTK_LABEL(filtering_action
.label3
), _("Book/Folder"));
1365 gtk_label_set_text(GTK_LABEL(filtering_action
.label3
), _("Destination"));
1368 gtk_label_set_text(GTK_LABEL(filtering_action
.label3
), _("Color"));
1370 case ACTION_EXECUTE
:
1371 gtk_label_set_text(GTK_LABEL(filtering_action
.label3
), _("Execute"));
1373 case ACTION_SET_SCORE
:
1374 case ACTION_CHANGE_SCORE
:
1375 gtk_label_set_text(GTK_LABEL(filtering_action
.label3
), _("Score"));
1377 case ACTION_SET_TAG
:
1378 case ACTION_UNSET_TAG
:
1379 gtk_label_set_text(GTK_LABEL(filtering_action
.label3
), _("Tag"));
1384 static void prefs_filtering_action_reset_dialog(void)
1386 combobox_select_by_data(GTK_COMBO_BOX(filtering_action
.action_combo
), ACTION_MOVE
);
1387 gtk_combo_box_set_active(GTK_COMBO_BOX(filtering_action
.account_combo
), 0);
1388 gtk_entry_set_text(GTK_ENTRY(filtering_action
.dest_entry
), "");
1389 gtk_spin_button_set_value(GTK_SPIN_BUTTON(filtering_action
.score_entry
), 0);
1392 static GtkListStore
* prefs_filtering_action_create_data_store(void)
1394 return gtk_list_store_new(N_PFA_COLUMNS
,
1400 static void prefs_filtering_action_list_view_insert_action(GtkWidget
*list_view
,
1402 const gchar
*action
,
1405 GtkListStore
*store
= GTK_LIST_STORE(gtk_tree_view_get_model
1406 (GTK_TREE_VIEW(list_view
)));
1410 /* see if row exists, if not append */
1412 gtk_list_store_append(store
, &iter
);
1416 gtk_list_store_set(store
, &iter
,
1418 PFA_VALID_ACTION
, is_valid
,
1422 static GtkWidget
*prefs_filtering_action_list_view_create(void)
1424 GtkTreeView
*list_view
;
1425 GtkTreeModel
*model
;
1426 GtkTreeSelection
*selector
;
1428 model
= GTK_TREE_MODEL(prefs_filtering_action_create_data_store());
1429 list_view
= GTK_TREE_VIEW(gtk_tree_view_new_with_model(model
));
1430 g_object_unref(model
);
1432 gtk_tree_view_set_rules_hint(list_view
, prefs_common
.use_stripes_everywhere
);
1434 selector
= gtk_tree_view_get_selection(list_view
);
1435 gtk_tree_selection_set_mode(selector
, GTK_SELECTION_BROWSE
);
1436 gtk_tree_selection_set_select_function
1437 (selector
, prefs_filtering_actions_selected
, NULL
, NULL
);
1439 /* create the columns */
1440 prefs_filtering_action_create_list_view_columns(list_view
);
1442 return GTK_WIDGET(list_view
);
1445 static void prefs_filtering_action_create_list_view_columns(GtkTreeView
*list_view
)
1447 GtkTreeViewColumn
*column
;
1448 GtkCellRenderer
*renderer
;
1450 renderer
= gtk_cell_renderer_text_new();
1451 column
= gtk_tree_view_column_new_with_attributes
1452 (_("Current action list"),
1456 gtk_tree_view_append_column(list_view
, column
);
1459 static gboolean prefs_filtering_actions_selected
1460 (GtkTreeSelection
*selector
,
1461 GtkTreeModel
*model
,
1463 gboolean currently_selected
,
1467 FilteringAction
*action
;
1468 GSList
* action_list
;
1473 if (currently_selected
)
1476 if (!gtk_tree_model_get_iter(model
, &iter
, path
))
1479 gtk_tree_model_get(model
, &iter
,
1480 PFA_VALID_ACTION
, &is_valid
,
1484 prefs_filtering_action_reset_dialog();
1488 gtk_tree_model_get(model
, &iter
,
1489 PFA_ACTION
, &action_str
,
1492 action_list
= matcher_parser_get_action_list(action_str
);
1495 if (action_list
== NULL
)
1498 action
= action_list
->data
;
1499 g_slist_free(action_list
);
1501 switch(action
->type
) {
1502 case MATCHACTION_MOVE
:
1503 combobox_select_by_data(GTK_COMBO_BOX(filtering_action
.action_combo
),
1506 case MATCHACTION_COPY
:
1507 combobox_select_by_data(GTK_COMBO_BOX(filtering_action
.action_combo
),
1510 case MATCHACTION_DELETE
:
1511 combobox_select_by_data(GTK_COMBO_BOX(filtering_action
.action_combo
),
1514 case MATCHACTION_MARK
:
1515 combobox_select_by_data(GTK_COMBO_BOX(filtering_action
.action_combo
),
1518 case MATCHACTION_UNMARK
:
1519 combobox_select_by_data(GTK_COMBO_BOX(filtering_action
.action_combo
),
1522 case MATCHACTION_LOCK
:
1523 combobox_select_by_data(GTK_COMBO_BOX(filtering_action
.action_combo
),
1526 case MATCHACTION_UNLOCK
:
1527 combobox_select_by_data(GTK_COMBO_BOX(filtering_action
.action_combo
),
1530 case MATCHACTION_MARK_AS_READ
:
1531 combobox_select_by_data(GTK_COMBO_BOX(filtering_action
.action_combo
),
1532 ACTION_MARK_AS_READ
);
1534 case MATCHACTION_MARK_AS_UNREAD
:
1535 combobox_select_by_data(GTK_COMBO_BOX(filtering_action
.action_combo
),
1536 ACTION_MARK_AS_UNREAD
);
1538 case MATCHACTION_MARK_AS_SPAM
:
1539 combobox_select_by_data(GTK_COMBO_BOX(filtering_action
.action_combo
),
1540 ACTION_MARK_AS_SPAM
);
1542 case MATCHACTION_MARK_AS_HAM
:
1543 combobox_select_by_data(GTK_COMBO_BOX(filtering_action
.action_combo
),
1544 ACTION_MARK_AS_HAM
);
1546 case MATCHACTION_FORWARD
:
1547 list_id
= get_list_id_from_account_id(action
->account_id
);
1548 combobox_select_by_data(GTK_COMBO_BOX(filtering_action
.action_combo
),
1550 gtk_combo_box_set_active(GTK_COMBO_BOX(filtering_action
.account_combo
),
1553 case MATCHACTION_FORWARD_AS_ATTACHMENT
:
1554 list_id
= get_list_id_from_account_id(action
->account_id
);
1555 combobox_select_by_data(GTK_COMBO_BOX(filtering_action
.action_combo
),
1556 ACTION_FORWARD_AS_ATTACHMENT
);
1557 gtk_combo_box_set_active(GTK_COMBO_BOX(filtering_action
.account_combo
),
1560 case MATCHACTION_REDIRECT
:
1561 list_id
= get_list_id_from_account_id(action
->account_id
);
1562 combobox_select_by_data(GTK_COMBO_BOX(filtering_action
.action_combo
),
1564 gtk_combo_box_set_active(GTK_COMBO_BOX(filtering_action
.account_combo
),
1567 case MATCHACTION_EXECUTE
:
1568 combobox_select_by_data(GTK_COMBO_BOX(filtering_action
.action_combo
),
1571 case MATCHACTION_COLOR
:
1572 combobox_select_by_data(GTK_COMBO_BOX(filtering_action
.action_combo
),
1574 gtk_option_menu_set_history(GTK_OPTION_MENU(filtering_action
.color_optmenu
),
1575 action
->labelcolor
);
1577 case MATCHACTION_CHANGE_SCORE
:
1578 combobox_select_by_data(GTK_COMBO_BOX(filtering_action
.action_combo
),
1579 ACTION_CHANGE_SCORE
);
1580 gtk_spin_button_set_value(GTK_SPIN_BUTTON(filtering_action
.score_entry
),
1583 case MATCHACTION_SET_SCORE
:
1584 combobox_select_by_data(GTK_COMBO_BOX(filtering_action
.action_combo
),
1586 gtk_spin_button_set_value(GTK_SPIN_BUTTON(filtering_action
.score_entry
),
1589 case MATCHACTION_STOP
:
1590 combobox_select_by_data(GTK_COMBO_BOX(filtering_action
.action_combo
),
1593 case MATCHACTION_HIDE
:
1594 combobox_select_by_data(GTK_COMBO_BOX(filtering_action
.action_combo
),
1597 case MATCHACTION_IGNORE
:
1598 combobox_select_by_data(GTK_COMBO_BOX(filtering_action
.action_combo
),
1601 case MATCHACTION_WATCH
:
1602 combobox_select_by_data(GTK_COMBO_BOX(filtering_action
.action_combo
),
1605 case MATCHACTION_ADD_TO_ADDRESSBOOK
:
1607 gtk_entry_set_text(GTK_ENTRY(filtering_action
.header_entry
), action
->header
);
1609 gtk_entry_set_text(GTK_ENTRY(filtering_action
.header_entry
), "");
1610 combobox_select_by_data(GTK_COMBO_BOX(filtering_action
.action_combo
),
1611 ACTION_ADD_TO_ADDRESSBOOK
);
1613 case MATCHACTION_SET_TAG
:
1614 combobox_select_by_data(GTK_COMBO_BOX(filtering_action
.action_combo
),
1616 combobox_select_by_text(GTK_COMBO_BOX(filtering_action
.tags_combo
),
1617 action
->destination
);
1619 case MATCHACTION_UNSET_TAG
:
1620 combobox_select_by_data(GTK_COMBO_BOX(filtering_action
.action_combo
),
1622 combobox_select_by_text(GTK_COMBO_BOX(filtering_action
.tags_combo
),
1623 action
->destination
);
1625 case MATCHACTION_CLEAR_TAGS
:
1626 combobox_select_by_data(GTK_COMBO_BOX(filtering_action
.action_combo
),
1630 g_warning("unhandled case !\n");
1632 if (action
->destination
)
1633 gtk_entry_set_text(GTK_ENTRY(filtering_action
.dest_entry
), action
->destination
);
1635 gtk_entry_set_text(GTK_ENTRY(filtering_action
.dest_entry
), "");
1637 filteringaction_free(action
); /* XXX: memleak */