2 * Claws Mail -- a GTK+ based, lightweight, and fast e-mail client
3 * Copyright (C) 2003-2012 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/>.
22 #include "claws-features.h"
28 #include <glib/gi18n.h>
30 #include <gdk/gdkkeysyms.h>
36 #if !GTK_CHECK_VERSION(3, 0, 0)
37 #include "gtkcmoptionmenu.h"
40 #include "prefs_gtk.h"
41 #include "prefs_filtering_action.h"
42 #include "prefs_common.h"
43 #include "mainwindow.h"
44 #include "foldersel.h"
45 #include "manage_window.h"
50 #include "alertpanel.h"
52 #include "description_window.h"
53 #include "addr_compl.h"
55 #include "matcher_parser.h"
56 #include "colorlabel.h"
59 #ifndef USE_NEW_ADDRBOOK
60 #include "addressbook.h"
70 static void prefs_filtering_action_create(void);
71 static void prefs_filtering_action_delete_cb(void);
72 static void prefs_filtering_action_substitute_cb(void);
73 static void prefs_filtering_action_register_cb(void);
74 static void prefs_filtering_action_reset_dialog(void);
75 static gboolean prefs_filtering_action_key_pressed(GtkWidget *widget,
76 GdkEventKey *event, gpointer data);
77 static void prefs_filtering_action_cancel(void);
78 static void prefs_filtering_action_ok(void);
79 static gint prefs_filtering_action_deleted(GtkWidget *widget,
80 GdkEventAny *event, gpointer data);
81 static void prefs_filtering_action_type_selection_changed(GtkWidget *widget,
83 static void prefs_filtering_action_select_dest(void);
84 #ifndef USE_NEW_ADDRBOOK
85 static void prefs_filtering_action_select_addressbook(void);
87 static void prefs_filtering_action_up(void);
88 static void prefs_filtering_action_down(void);
89 static void prefs_filtering_action_set_dialog(GSList *action_list);
90 static GSList *prefs_filtering_action_get_list(void);
92 static GtkListStore* prefs_filtering_action_create_data_store (void);
93 static void prefs_filtering_action_list_view_insert_action (GtkWidget *list_view,
97 static GtkWidget *prefs_filtering_action_list_view_create (void);
98 static void prefs_filtering_action_create_list_view_columns (GtkTreeView *list_view);
99 static gboolean prefs_filtering_actions_selected (GtkTreeSelection *selector,
102 gboolean currently_selected,
105 static void prefs_filtering_action_exec_info (GtkWidget *widget,
109 *\brief UI data for matcher dialog
111 static struct FilteringAction_ {
116 GtkWidget *action_list_view;
120 GtkWidget *action_combo;
121 GtkWidget *account_combo;
122 GtkWidget *dest_entry;
125 #if !GTK_CHECK_VERSION(3, 0, 0)
126 GtkWidget *color_optmenu;
128 GtkWidget *header_combo;
129 GtkWidget *header_entry;
130 #ifndef USE_NEW_ADDRBOOK
131 GtkWidget *addressbook_btn;
133 GtkWidget *score_entry;
134 GtkWidget *tags_combo;
140 typedef enum Action_ {
149 ACTION_MARK_AS_UNREAD,
153 ACTION_FORWARD_AS_ATTACHMENT,
165 ACTION_ADD_TO_ADDRESSBOOK,
167 /* add other action constants */
175 { NULL, N_("Move"), ACTION_MOVE },
176 { NULL, N_("Copy"), ACTION_COPY },
177 { NULL, N_("Delete"), ACTION_DELETE },
178 { NULL, N_("Hide"), ACTION_HIDE },
179 { N_("Message flags"), N_("Mark"), ACTION_MARK },
180 { N_("Message flags"), N_("Unmark"), ACTION_UNMARK },
181 { N_("Message flags"), N_("Lock"), ACTION_LOCK },
182 { N_("Message flags"), N_("Unlock"), ACTION_UNLOCK },
183 { N_("Message flags"), N_("Mark as read"), ACTION_MARK_AS_READ },
184 { N_("Message flags"), N_("Mark as unread"), ACTION_MARK_AS_UNREAD },
185 { N_("Message flags"), N_("Mark as spam"), ACTION_MARK_AS_SPAM },
186 { N_("Message flags"), N_("Mark as ham"), ACTION_MARK_AS_HAM },
187 { NULL, N_("Execute"), ACTION_EXECUTE },
188 #if !GTK_CHECK_VERSION(3, 0, 0)
189 { NULL, N_("Color label"), ACTION_COLOR },
191 { N_("Resend"), N_("Forward"), ACTION_FORWARD },
192 { N_("Resend"), N_("Forward as attachment"), ACTION_FORWARD_AS_ATTACHMENT },
193 { N_("Resend"), N_("Redirect"), ACTION_REDIRECT },
194 { N_("Score"), N_("Change score"), ACTION_CHANGE_SCORE },
195 { N_("Score"), N_("Set score"), ACTION_SET_SCORE },
196 { N_("Tags"), N_("Apply tag"), ACTION_SET_TAG },
197 { N_("Tags"), N_("Unset tag"), ACTION_UNSET_TAG },
198 { N_("Tags"), N_("Clear tags"), ACTION_CLEAR_TAGS },
199 { N_("Threads"), N_("Ignore thread"), ACTION_IGNORE },
200 { N_("Threads"), N_("Watch thread"), ACTION_WATCH },
201 { NULL, N_("Add to address book"), ACTION_ADD_TO_ADDRESSBOOK },
202 { NULL, N_("Stop filter"), ACTION_STOP },
216 static PrefsFilteringActionSignal *filtering_action_callback;
218 static GtkTreeModel *prefs_filtering_action_create_model(void)
220 GtkTreeIter iter, iter2;
222 gchar *curr_menu = NULL;
225 store = gtk_tree_store_new(N_ACTION_COMBO, G_TYPE_STRING, G_TYPE_INT,
228 for (i = 0; action_menu[i].menu || action_menu[i].text; i++)
230 if (action_menu[i].menu) {
231 if (!curr_menu || strcmp(action_menu[i].menu, curr_menu)) {
232 gtk_tree_store_append(store, &iter, NULL);
233 gtk_tree_store_set(store, &iter,
235 gettext(action_menu[i].menu),
236 ACTION_COMBO_SENS, TRUE,
238 curr_menu = action_menu[i].menu;
241 gtk_tree_store_append(store, &iter2, &iter);
242 gtk_tree_store_set(store, &iter2,
243 ACTION_COMBO_TEXT, gettext(action_menu[i].text),
244 ACTION_COMBO_DATA, action_menu[i].action,
245 ACTION_COMBO_SENS, TRUE,
250 gtk_tree_store_append(store, &iter, NULL);
251 gtk_tree_store_set(store, &iter,
252 ACTION_COMBO_TEXT, gettext(action_menu[i].text),
253 ACTION_COMBO_DATA, action_menu[i].action,
254 ACTION_COMBO_SENS, TRUE,
259 return GTK_TREE_MODEL(store);
262 static void cell_is_sensitive(GtkCellLayout *cell_layout,
263 GtkCellRenderer *cell,
264 GtkTreeModel *tree_model,
268 if(gtk_tree_model_iter_has_child (tree_model, iter)) {
269 g_object_set (cell, "sensitive", FALSE, NULL);
274 *\brief Opens the filtering action dialog with a list of actions
276 *\param matchers List of conditions
280 void prefs_filtering_action_open(GSList *action_list,
281 PrefsFilteringActionSignal *cb)
285 if (!filtering_action.window) {
286 prefs_filtering_action_create();
288 #if !GTK_CHECK_VERSION(3, 0, 0)
289 /* update color label menu */
290 gtk_cmoption_menu_set_menu(GTK_CMOPTION_MENU(filtering_action.color_optmenu),
291 colorlabel_create_color_menu());
295 manage_window_set_transient(GTK_WINDOW(filtering_action.window));
296 gtk_widget_grab_focus(filtering_action.ok_btn);
298 filtering_action_callback = cb;
300 prefs_filtering_action_set_dialog(action_list);
302 gtk_widget_show(filtering_action.window);
306 *\brief Save Gtk object size to prefs dataset
308 static void prefs_filtering_action_size_allocate_cb(GtkWidget *widget,
309 GtkAllocation *allocation)
311 cm_return_if_fail(allocation != NULL);
313 prefs_common.filteringactionwin_width = allocation->width;
314 prefs_common.filteringactionwin_height = allocation->height;
317 #define LABELS_WIDTH 80
318 #define SECOND_ROW_WIDTH 250
320 static void prefs_filtering_action_check_widget_width(GtkWidget *widget)
324 gtk_widget_size_request(widget, &req);
325 if(req.width > SECOND_ROW_WIDTH)
326 gtk_widget_set_size_request(widget, SECOND_ROW_WIDTH, -1);
330 *\brief Create the matcher dialog
332 static void prefs_filtering_action_create(void)
337 GtkWidget *cancel_btn;
338 GtkWidget *confirm_area;
348 GtkWidget *action_combo;
349 GtkWidget *account_combo;
350 GtkWidget *header_combo;
351 GtkWidget *header_entry;
352 #ifndef USE_NEW_ADDRBOOK
353 GtkWidget *addressbook_btn;
355 GtkWidget *dest_entry;
357 GtkWidget *score_entry;
358 GtkWidget *tags_combo;
364 GtkWidget *subst_btn;
367 GtkWidget *action_hbox;
368 GtkWidget *action_scrolledwin;
369 GtkWidget *action_list_view;
377 #if !GTK_CHECK_VERSION(3, 0, 0)
378 GtkWidget *color_optmenu;
381 static GdkGeometry geometry;
386 GtkSizeGroup *size_group = gtk_size_group_new(GTK_SIZE_GROUP_HORIZONTAL);
387 GtkSizeGroup *size_action = gtk_size_group_new(GTK_SIZE_GROUP_HORIZONTAL);
389 GtkCellRenderer *renderer;
391 debug_print("Creating matcher configuration window...\n");
393 window = gtkut_window_new(GTK_WINDOW_TOPLEVEL, "prefs_filtering_action");
394 gtk_container_set_border_width(GTK_CONTAINER(window), VBOX_BORDER);
395 gtk_window_set_position(GTK_WINDOW(window), GTK_WIN_POS_CENTER);
396 gtk_window_set_modal(GTK_WINDOW(window), TRUE);
397 gtk_window_set_resizable(GTK_WINDOW(window), TRUE);
399 vbox = gtk_vbox_new(FALSE, 6);
400 gtk_container_add(GTK_CONTAINER(window), vbox);
402 gtkut_stock_button_set_create(&confirm_area,
403 &cancel_btn, GTK_STOCK_CANCEL,
404 &ok_btn, GTK_STOCK_OK,
406 gtk_box_pack_end(GTK_BOX(vbox), confirm_area, FALSE, FALSE, 0);
407 gtk_widget_grab_default(ok_btn);
409 gtk_window_set_title(GTK_WINDOW(window),
410 _("Action configuration"));
411 g_signal_connect(G_OBJECT(window), "delete_event",
412 G_CALLBACK(prefs_filtering_action_deleted), NULL);
413 g_signal_connect(G_OBJECT(window), "size_allocate",
414 G_CALLBACK(prefs_filtering_action_size_allocate_cb), NULL);
415 g_signal_connect(G_OBJECT(window), "key_press_event",
416 G_CALLBACK(prefs_filtering_action_key_pressed), NULL);
417 MANAGE_WINDOW_SIGNALS_CONNECT(window);
418 g_signal_connect(G_OBJECT(ok_btn), "clicked",
419 G_CALLBACK(prefs_filtering_action_ok), NULL);
420 g_signal_connect(G_OBJECT(cancel_btn), "clicked",
421 G_CALLBACK(prefs_filtering_action_cancel), NULL);
423 vbox1 = gtk_vbox_new(FALSE, VSPACING);
424 gtk_box_pack_start(GTK_BOX(vbox), vbox1, TRUE, TRUE, 0);
425 gtk_container_set_border_width(GTK_CONTAINER (vbox1), 2);
427 frame = gtk_frame_new(_("Rule"));
428 gtk_frame_set_label_align(GTK_FRAME(frame), 0.01, 0.5);
429 gtk_box_pack_start (GTK_BOX (vbox1), frame, FALSE, FALSE, 0);
430 gtk_widget_set_size_request(frame, -1, 110);
432 table = gtk_table_new(3, 3, FALSE);
433 gtk_container_set_border_width(GTK_CONTAINER(table), 2);
434 gtk_table_set_row_spacings (GTK_TABLE (table), VSPACING_NARROW_2);
435 gtk_table_set_col_spacings (GTK_TABLE (table), HSPACING_NARROW);
436 gtk_container_add(GTK_CONTAINER(frame), table);
438 /* first row labels */
440 label1 = gtk_label_new (_("Action"));
441 gtk_widget_set_size_request(label1, LABELS_WIDTH, -1);
442 gtk_size_group_add_widget(size_group, label1);
443 gtk_misc_set_alignment (GTK_MISC (label1), 1, 0.5);
444 gtk_table_attach(GTK_TABLE(table), label1, 0, 1, 0, 1,
445 GTK_FILL, GTK_SHRINK, 0, 0);
447 label2 = gtk_label_new ("");
448 gtk_size_group_add_widget(size_group, label2);
449 gtk_misc_set_alignment (GTK_MISC (label2), 1, 0.5);
450 gtk_table_attach(GTK_TABLE(table), label2, 0, 1, 1, 2,
451 GTK_FILL, GTK_SHRINK, 0, 0);
453 label3 = gtk_label_new ("");
454 gtk_size_group_add_widget(size_group, label3);
455 gtk_misc_set_alignment (GTK_MISC (label3), 1, 0.5);
456 gtk_table_attach(GTK_TABLE(table), label3, 0, 1, 2, 3,
457 GTK_FILL, GTK_SHRINK, 0, 0);
461 hbox1 = gtk_hbox_new(FALSE, 0);
462 gtk_table_attach(GTK_TABLE(table), hbox1, 1, 2, 0, 1,
463 GTK_FILL, GTK_SHRINK, 0, 0);
465 model = prefs_filtering_action_create_model();
466 action_combo = gtk_combo_box_new_with_model(model);
467 gtk_size_group_add_widget(size_action, action_combo);
469 renderer = gtk_cell_renderer_text_new();
470 gtk_cell_layout_pack_start(GTK_CELL_LAYOUT(action_combo), renderer, TRUE);
471 gtk_cell_layout_set_attributes(GTK_CELL_LAYOUT(action_combo), renderer,
472 "text", ACTION_COMBO_TEXT,
473 "sensitive", ACTION_COMBO_SENS,
475 gtk_cell_layout_set_cell_data_func(GTK_CELL_LAYOUT(action_combo), renderer,
476 cell_is_sensitive, NULL, NULL);
478 combobox_select_by_data(GTK_COMBO_BOX(action_combo), ACTION_MOVE);
479 g_signal_connect(G_OBJECT(action_combo), "changed",
480 G_CALLBACK(prefs_filtering_action_type_selection_changed),
482 gtk_box_pack_start(GTK_BOX(hbox1), action_combo, FALSE, FALSE, 0);
483 gtk_box_pack_start(GTK_BOX(hbox1), gtk_label_new(""), TRUE, TRUE, 0);
487 hbox1 = gtk_hbox_new (FALSE, 0);
488 gtk_table_attach(GTK_TABLE(table), hbox1, 1, 2, 1, 2,
489 GTK_FILL | GTK_EXPAND, GTK_SHRINK, 0, 0);
491 #if !GTK_CHECK_VERSION(2, 24, 0)
492 account_combo = gtk_combo_box_new_text ();
494 account_combo = gtk_combo_box_text_new ();
496 gtk_size_group_add_widget(size_action, account_combo);
498 for (accounts = account_get_list() ; accounts != NULL;
499 accounts = accounts->next) {
500 PrefsAccount *ac = (PrefsAccount *)accounts->data;
501 gchar *name = g_strdup(ac->account_name);
502 #if !GTK_CHECK_VERSION(2, 24, 0)
503 gtk_combo_box_append_text(GTK_COMBO_BOX(account_combo), (gpointer) name);
505 gtk_combo_box_text_append_text(GTK_COMBO_BOX_TEXT(account_combo), (gpointer) name);
510 prefs_filtering_action_check_widget_width(account_combo);
511 gtk_combo_box_set_active(GTK_COMBO_BOX(account_combo), 0);
512 gtk_box_pack_start (GTK_BOX (hbox1), account_combo,
517 header_combo = combobox_text_new(TRUE, "From", "To", "Cc", "Reply-To", "Sender", NULL);
518 gtk_size_group_add_widget(size_action, header_combo);
519 gtk_box_pack_start (GTK_BOX (hbox1), header_combo,
521 header_entry = gtk_bin_get_child(GTK_BIN((header_combo)));
525 hbox1 = gtk_hbox_new (FALSE, 0);
526 gtk_table_attach(GTK_TABLE(table), hbox1, 1, 2, 2, 3,
527 GTK_FILL | GTK_EXPAND, GTK_SHRINK, 0, 0);
529 dest_entry = gtk_entry_new ();
530 gtk_box_pack_start (GTK_BOX (hbox1), dest_entry, TRUE, TRUE, 0);
532 score_entry = gtk_spin_button_new_with_range(-1000, 1000, 1);
533 gtk_box_pack_start(GTK_BOX(hbox1), score_entry, FALSE, FALSE, 0);
535 #if !GTK_CHECK_VERSION(3, 0, 0)
536 color_optmenu = gtk_cmoption_menu_new();
537 gtk_size_group_add_widget(size_action, color_optmenu);
538 gtk_cmoption_menu_set_menu(GTK_CMOPTION_MENU(color_optmenu),
539 colorlabel_create_color_menu());
540 prefs_filtering_action_check_widget_width(color_optmenu);
541 gtk_box_pack_start(GTK_BOX(hbox1), color_optmenu, FALSE, FALSE, 0);
544 #if !GTK_CHECK_VERSION(2, 24, 0)
545 tags_combo = gtk_combo_box_new_text ();
547 tags_combo = gtk_combo_box_text_new ();
549 gtk_size_group_add_widget(size_action, tags_combo);
551 for (tmp = tags = tags_get_list() ; tmp != NULL;
553 gchar *name = g_strdup(tags_get_tag(GPOINTER_TO_INT(tmp->data)));
555 #if !GTK_CHECK_VERSION(2, 24, 0)
556 gtk_combo_box_append_text(GTK_COMBO_BOX(tags_combo), (gpointer) name);
558 gtk_combo_box_text_append_text(GTK_COMBO_BOX_TEXT(tags_combo), (gpointer) name);
564 prefs_filtering_action_check_widget_width(tags_combo);
565 gtk_combo_box_set_active(GTK_COMBO_BOX(tags_combo), 0);
566 gtk_box_pack_start (GTK_BOX (hbox1), tags_combo,
569 hbox1 = gtk_hbox_new (FALSE, 0);
570 gtk_table_attach(GTK_TABLE(table), hbox1, 2, 3, 2, 3,
571 GTK_FILL, GTK_SHRINK, 0, 0);
573 dest_btn = gtk_button_new_with_label (_("Select ..."));
574 gtk_box_pack_start (GTK_BOX (hbox1), dest_btn, FALSE, FALSE, 0);
575 g_signal_connect (G_OBJECT (dest_btn), "clicked",
576 G_CALLBACK(prefs_filtering_action_select_dest),
579 #ifndef USE_NEW_ADDRBOOK
580 addressbook_btn = gtk_button_new_with_label (_("Select ..."));
581 gtk_box_pack_start (GTK_BOX (hbox1), addressbook_btn, FALSE, FALSE, 0);
582 g_signal_connect (G_OBJECT (addressbook_btn), "clicked",
583 G_CALLBACK(prefs_filtering_action_select_addressbook),
587 exec_btn = gtk_button_new_from_stock(GTK_STOCK_INFO);
588 gtk_box_pack_start (GTK_BOX (hbox1), exec_btn, FALSE, FALSE, 0);
589 g_signal_connect (G_OBJECT (exec_btn), "clicked",
590 G_CALLBACK(prefs_filtering_action_exec_info),
593 /* register / substitute / delete */
595 reg_hbox = gtk_hbox_new(FALSE, 4);
596 gtk_box_pack_start(GTK_BOX(vbox1), reg_hbox, FALSE, FALSE, 0);
598 arrow = gtk_arrow_new(GTK_ARROW_DOWN, GTK_SHADOW_OUT);
599 gtk_box_pack_start(GTK_BOX(reg_hbox), arrow, FALSE, FALSE, 0);
600 gtk_widget_set_size_request(arrow, -1, 16);
602 btn_hbox = gtk_hbox_new(TRUE, 4);
603 gtk_box_pack_start(GTK_BOX(reg_hbox), btn_hbox, FALSE, FALSE, 0);
605 reg_btn = gtk_button_new_from_stock(GTK_STOCK_ADD);
606 gtk_box_pack_start(GTK_BOX(btn_hbox), reg_btn, FALSE, TRUE, 0);
607 g_signal_connect(G_OBJECT(reg_btn), "clicked",
608 G_CALLBACK(prefs_filtering_action_register_cb), NULL);
610 subst_btn = gtkut_get_replace_btn(_("Replace"));
611 gtk_box_pack_start(GTK_BOX(btn_hbox), subst_btn, FALSE, TRUE, 0);
612 g_signal_connect(G_OBJECT(subst_btn), "clicked",
613 G_CALLBACK(prefs_filtering_action_substitute_cb),
616 del_btn = gtk_button_new_from_stock(GTK_STOCK_DELETE);
617 gtk_box_pack_start(GTK_BOX(btn_hbox), del_btn, FALSE, TRUE, 0);
618 g_signal_connect(G_OBJECT(del_btn), "clicked",
619 G_CALLBACK(prefs_filtering_action_delete_cb), NULL);
621 action_hbox = gtk_hbox_new(FALSE, 8);
622 gtk_box_pack_start(GTK_BOX(vbox1), action_hbox, TRUE, TRUE, 0);
624 action_scrolledwin = gtk_scrolled_window_new(NULL, NULL);
625 gtk_widget_set_size_request(action_scrolledwin, -1, 150);
626 gtk_box_pack_start(GTK_BOX(action_hbox), action_scrolledwin,
628 gtk_scrolled_window_set_shadow_type(GTK_SCROLLED_WINDOW(action_scrolledwin),
629 GTK_SHADOW_ETCHED_IN);
630 gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(action_scrolledwin),
631 GTK_POLICY_AUTOMATIC,
632 GTK_POLICY_AUTOMATIC);
634 action_list_view = prefs_filtering_action_list_view_create();
635 gtk_container_add(GTK_CONTAINER(action_scrolledwin), action_list_view);
637 btn_vbox = gtk_vbox_new(FALSE, 8);
638 gtk_box_pack_start(GTK_BOX(action_hbox), btn_vbox, FALSE, FALSE, 0);
640 up_btn = gtk_button_new_from_stock(GTK_STOCK_GO_UP);
641 gtk_box_pack_start(GTK_BOX(btn_vbox), up_btn, FALSE, FALSE, 0);
642 g_signal_connect(G_OBJECT(up_btn), "clicked",
643 G_CALLBACK(prefs_filtering_action_up), NULL);
645 down_btn = gtk_button_new_from_stock(GTK_STOCK_GO_DOWN);
646 gtk_box_pack_start(GTK_BOX(btn_vbox), down_btn, FALSE, FALSE, 0);
647 g_signal_connect(G_OBJECT(down_btn), "clicked",
648 G_CALLBACK(prefs_filtering_action_down), NULL);
650 if (!geometry.min_height) {
651 geometry.min_width = 490;
652 geometry.min_height = 348;
655 gtk_window_set_geometry_hints(GTK_WINDOW(window), NULL, &geometry,
657 gtk_widget_set_size_request(window, prefs_common.filteringactionwin_width,
658 prefs_common.filteringactionwin_height);
660 gtk_widget_show_all(window);
662 filtering_action.window = window;
663 filtering_action.label1 = label1;
664 filtering_action.label2 = label2;
665 filtering_action.label3 = label3;
666 filtering_action.action_combo = action_combo;
667 filtering_action.account_combo = account_combo;
668 filtering_action.tags_combo = tags_combo;
669 filtering_action.dest_entry = dest_entry;
670 filtering_action.dest_btn = dest_btn;
671 filtering_action.exec_btn = exec_btn;
672 #if !GTK_CHECK_VERSION(3, 0, 0)
673 filtering_action.color_optmenu = color_optmenu;
675 filtering_action.score_entry = score_entry;
676 filtering_action.header_combo = header_combo;
677 filtering_action.header_entry = header_entry;
678 #ifndef USE_NEW_ADDRBOOK
679 filtering_action.addressbook_btn = addressbook_btn;
681 filtering_action.ok_btn = ok_btn;
682 filtering_action.action_list_view = action_list_view;
684 prefs_filtering_action_type_selection_changed(NULL, NULL);
688 *\brief Set the contents of a row
690 *\param row Index of row to set
691 *\param prop Condition to set
694 static void prefs_filtering_action_list_view_set_row(GtkTreeIter *row,
695 FilteringAction *action)
699 if (row == NULL && action == NULL) {
700 prefs_filtering_action_list_view_insert_action
701 (filtering_action.action_list_view,
702 NULL, _("(New)"), FALSE);
706 buf = filteringaction_to_string(action);
708 prefs_filtering_action_list_view_insert_action
709 (filtering_action.action_list_view,
715 *\brief Initializes dialog with a set of conditions
717 *\param matchers List of conditions
719 static void prefs_filtering_action_set_dialog(GSList *action_list)
723 gtk_list_store_clear(GTK_LIST_STORE(gtk_tree_view_get_model
724 (GTK_TREE_VIEW(filtering_action.action_list_view))));
726 prefs_filtering_action_list_view_set_row(NULL, NULL);
727 if (action_list != NULL) {
728 for (cur = action_list; cur != NULL;
729 cur = g_slist_next(cur)) {
730 FilteringAction *action;
731 action = (FilteringAction *) cur->data;
732 prefs_filtering_action_list_view_set_row(NULL, action);
736 prefs_filtering_action_reset_dialog();
738 combobox_set_sensitive(GTK_COMBO_BOX(filtering_action.action_combo), 9,
739 (tags_get_size() > 0) ? TRUE : FALSE);
743 *\brief Converts current actions in list box in
744 * an action list used by the filtering system.
746 *\return GSList * List of actions.
748 static GSList *prefs_filtering_action_get_list(void)
754 GtkTreeView *list_view = GTK_TREE_VIEW(filtering_action.action_list_view);
755 GtkTreeModel *model = gtk_tree_view_get_model(list_view);
760 while (gtk_tree_model_iter_nth_child(model, &iter, NULL, row)) {
762 gtk_tree_model_get(model, &iter,
763 PFA_ACTION, &action_str,
764 PFA_VALID_ACTION, &is_valid,
768 GSList * tmp_action_list;
769 tmp_action_list = matcher_parser_get_action_list(action_str);
771 if (tmp_action_list == NULL) {
776 action_list = g_slist_concat(action_list,
790 *\brief Returns account ID from the given list index
792 *\return gint account ID
794 static gint get_account_id_from_list_id(gint list_id)
798 for (accounts = account_get_list() ; accounts != NULL;
799 accounts = accounts->next) {
800 PrefsAccount *ac = (PrefsAccount *)accounts->data;
803 return ac->account_id;
810 *\brief Returns list index from the given account ID
812 *\return gint list index
814 static gint get_list_id_from_account_id(gint account_id)
819 for (accounts = account_get_list() ; accounts != NULL;
820 accounts = accounts->next) {
821 PrefsAccount *ac = (PrefsAccount *)accounts->data;
823 if (account_id == ac->account_id)
832 *\brief Returns parser action ID from internal action ID
834 *\return gint parser action ID
836 static gint prefs_filtering_action_get_matching_from_action(Action action_id)
840 return MATCHACTION_MOVE;
842 return MATCHACTION_SET_TAG;
843 case ACTION_UNSET_TAG:
844 return MATCHACTION_UNSET_TAG;
845 case ACTION_CLEAR_TAGS:
846 return MATCHACTION_CLEAR_TAGS;
848 return MATCHACTION_COPY;
850 return MATCHACTION_DELETE;
852 return MATCHACTION_MARK;
854 return MATCHACTION_UNMARK;
856 return MATCHACTION_LOCK;
858 return MATCHACTION_UNLOCK;
859 case ACTION_MARK_AS_READ:
860 return MATCHACTION_MARK_AS_READ;
861 case ACTION_MARK_AS_UNREAD:
862 return MATCHACTION_MARK_AS_UNREAD;
863 case ACTION_MARK_AS_SPAM:
864 return MATCHACTION_MARK_AS_SPAM;
865 case ACTION_MARK_AS_HAM:
866 return MATCHACTION_MARK_AS_HAM;
868 return MATCHACTION_FORWARD;
869 case ACTION_FORWARD_AS_ATTACHMENT:
870 return MATCHACTION_FORWARD_AS_ATTACHMENT;
871 case ACTION_REDIRECT:
872 return MATCHACTION_REDIRECT;
874 return MATCHACTION_EXECUTE;
875 #if !GTK_CHECK_VERSION(3, 0, 0)
877 return MATCHACTION_COLOR;
880 return MATCHACTION_HIDE;
882 return MATCHACTION_IGNORE;
884 return MATCHACTION_WATCH;
886 return MATCHACTION_STOP;
887 case ACTION_CHANGE_SCORE:
888 return MATCHACTION_CHANGE_SCORE;
889 case ACTION_SET_SCORE:
890 return MATCHACTION_SET_SCORE;
891 case ACTION_ADD_TO_ADDRESSBOOK:
892 return MATCHACTION_ADD_TO_ADDRESSBOOK;
899 *\brief Returns action from the content of the dialog
901 *\param alert specifies whether alert dialog boxes should be shown
904 *\return FilteringAction * action entered in the dialog box.
906 static FilteringAction * prefs_filtering_action_dialog_to_action(gboolean alert)
912 gchar * destination = NULL;
914 FilteringAction * action;
916 gchar * header = NULL;
918 action_id = combobox_get_active_data(GTK_COMBO_BOX(filtering_action.action_combo));
919 action_type = prefs_filtering_action_get_matching_from_action(action_id);
920 list_id = gtk_combo_box_get_active(GTK_COMBO_BOX(filtering_action.account_combo));
921 account_id = get_account_id_from_list_id(list_id);
929 destination = gtk_editable_get_chars(GTK_EDITABLE(filtering_action.dest_entry), 0, -1);
930 if (*destination == '\0') {
932 alertpanel_error(action_id == ACTION_EXECUTE
933 ? _("Command-line not set")
934 : _("Destination is not set."));
940 case ACTION_FORWARD_AS_ATTACHMENT:
941 case ACTION_REDIRECT:
942 destination = gtk_editable_get_chars(GTK_EDITABLE(filtering_action.dest_entry), 0, -1);
943 if (*destination == '\0') {
945 alertpanel_error(_("Recipient is not set."));
950 #if !GTK_CHECK_VERSION(3, 0, 0)
952 labelcolor = colorlabel_get_color_menu_active_item(
953 gtk_cmoption_menu_get_menu(GTK_CMOPTION_MENU(filtering_action.color_optmenu)));
957 case ACTION_CHANGE_SCORE:
958 case ACTION_SET_SCORE:
959 score = gtk_spin_button_get_value_as_int(GTK_SPIN_BUTTON(
960 filtering_action.score_entry));
961 if (!score && action_id == ACTION_CHANGE_SCORE) {
963 alertpanel_error(_("Score is not set"));
967 case ACTION_ADD_TO_ADDRESSBOOK:
968 header = gtk_editable_get_chars(GTK_EDITABLE(filtering_action.header_entry), 0, -1);
969 if (*header == '\0') {
971 alertpanel_error(_("Header is not set."));
975 destination = gtk_editable_get_chars(GTK_EDITABLE(filtering_action.dest_entry), 0, -1);
976 if (*destination == '\0') {
978 alertpanel_error(_("Target addressbook/folder is not set."));
984 case ACTION_UNSET_TAG:
985 #if !GTK_CHECK_VERSION(2, 24, 0)
986 destination = gtk_combo_box_get_active_text(GTK_COMBO_BOX(filtering_action.tags_combo));
988 destination = gtk_combo_box_text_get_active_text(GTK_COMBO_BOX_TEXT(filtering_action.tags_combo));
990 if (!destination || *destination == '\0') {
992 alertpanel_error(_("Tag name is empty."));
1006 case ACTION_MARK_AS_READ:
1007 case ACTION_MARK_AS_UNREAD:
1008 case ACTION_MARK_AS_SPAM:
1009 case ACTION_MARK_AS_HAM:
1010 case ACTION_CLEAR_TAGS:
1014 action = filteringaction_new(action_type, account_id,
1015 destination, labelcolor, score, header);
1017 g_free(destination);
1022 *\brief Signal handler for register button
1024 static void prefs_filtering_action_register_cb(void)
1026 FilteringAction *action;
1028 action = prefs_filtering_action_dialog_to_action(TRUE);
1032 prefs_filtering_action_list_view_set_row(NULL, action);
1034 filteringaction_free(action);
1036 * (presumably gtk_list_select_item(), called by
1037 * prefs_filtering_action_reset_dialog() activates
1038 * what seems to be a bug. this causes any other
1039 * list items to be unselectable)
1040 * prefs_filtering_action_reset_dialog(); */
1041 gtk_combo_box_set_active(GTK_COMBO_BOX(filtering_action.account_combo), 0);
1042 gtk_combo_box_set_active(GTK_COMBO_BOX(filtering_action.tags_combo), 0);
1043 gtk_entry_set_text(GTK_ENTRY(filtering_action.dest_entry), "");
1047 *\brief Signal handler for substitute button
1049 static void prefs_filtering_action_substitute_cb(void)
1051 GtkTreeView *list_view = GTK_TREE_VIEW
1052 (filtering_action.action_list_view);
1053 GtkTreeSelection *selection = gtk_tree_view_get_selection(list_view);
1054 GtkTreeModel *model;
1057 FilteringAction *action;
1059 if (!gtk_tree_selection_get_selected(selection, &model, &row))
1062 gtk_tree_model_get(model, &row, PFA_VALID_ACTION, &is_valid, -1);
1066 action = prefs_filtering_action_dialog_to_action(TRUE);
1070 prefs_filtering_action_list_view_set_row(&row, action);
1072 filteringaction_free(action);
1074 prefs_filtering_action_reset_dialog();
1078 *\brief Signal handler for delete button
1080 static void prefs_filtering_action_delete_cb(void)
1082 GtkTreeView *list_view = GTK_TREE_VIEW
1083 (filtering_action.action_list_view);
1084 GtkTreeSelection *selection = gtk_tree_view_get_selection(list_view);
1085 GtkTreeModel *model;
1089 if (!gtk_tree_selection_get_selected(selection, &model, &row))
1092 gtk_tree_model_get(model, &row, PFA_VALID_ACTION, &is_valid, -1);
1096 gtk_list_store_remove(GTK_LIST_STORE(model), &row);
1098 prefs_filtering_action_reset_dialog();
1102 *\brief Signal handler for 'move up' button
1104 static void prefs_filtering_action_up(void)
1106 GtkTreePath *prev, *sel, *try;
1108 GtkListStore *store = NULL;
1109 GtkTreeModel *model = NULL;
1112 if (!gtk_tree_selection_get_selected
1113 (gtk_tree_view_get_selection
1114 (GTK_TREE_VIEW(filtering_action.action_list_view)),
1118 store = (GtkListStore *)model;
1119 sel = gtk_tree_model_get_path(GTK_TREE_MODEL(store), &isel);
1123 /* no move if we're at row 0 or 1, looks phony, but other
1124 * solutions are more convoluted... */
1125 try = gtk_tree_path_copy(sel);
1126 if (!gtk_tree_path_prev(try) || !gtk_tree_path_prev(try)) {
1127 gtk_tree_path_free(try);
1128 gtk_tree_path_free(sel);
1131 gtk_tree_path_free(try);
1133 prev = gtk_tree_path_copy(sel);
1134 if (gtk_tree_path_prev(prev)) {
1135 gtk_tree_model_get_iter(GTK_TREE_MODEL(store),
1137 gtk_list_store_swap(store, &iprev, &isel);
1138 /* XXX: GTK2 select row?? */
1141 gtk_tree_path_free(sel);
1142 gtk_tree_path_free(prev);
1146 *\brief Signal handler for 'move down' button
1148 static void prefs_filtering_action_down(void)
1150 GtkListStore *store = NULL;
1151 GtkTreeModel *model = NULL;
1152 GtkTreeIter next, sel;
1155 if (!gtk_tree_selection_get_selected
1156 (gtk_tree_view_get_selection
1157 (GTK_TREE_VIEW(filtering_action.action_list_view)),
1161 store = (GtkListStore *)model;
1162 try = gtk_tree_model_get_path(GTK_TREE_MODEL(store), &sel);
1166 /* move when not at row 0 ... */
1167 if (gtk_tree_path_prev(try)) {
1169 if (gtk_tree_model_iter_next(GTK_TREE_MODEL(store), &next))
1170 gtk_list_store_swap(store, &next, &sel);
1173 gtk_tree_path_free(try);
1177 *\brief Handle key press
1179 *\param widget Widget receiving key press
1180 *\param event Key event
1181 *\param data User data
1183 static gboolean prefs_filtering_action_key_pressed(GtkWidget *widget,
1184 GdkEventKey *event, gpointer data)
1186 if (event && event->keyval == GDK_KEY_Escape) {
1187 prefs_filtering_action_cancel();
1194 *\brief Cancel matcher dialog
1196 static void prefs_filtering_action_cancel(void)
1198 gtk_widget_destroy(filtering_action.window);
1199 filtering_action.window = NULL;
1204 *\brief Accept current matchers
1206 static void prefs_filtering_action_ok(void)
1208 GSList * action_list;
1211 action_list = prefs_filtering_action_get_list();
1213 if (action_list == NULL) {
1214 alertpanel_error(_("No action was defined."));
1218 if (filtering_action_callback != NULL)
1219 filtering_action_callback(action_list);
1220 for(cur = action_list ; cur != NULL ; cur = cur->next) {
1221 filteringaction_free(cur->data);
1223 g_slist_free(action_list);
1225 gtk_widget_destroy(filtering_action.window);
1226 filtering_action.window = NULL;
1231 *\brief Called when closing dialog box
1233 *\param widget Dialog widget
1234 *\param event Event info
1235 *\param data User data
1239 static gint prefs_filtering_action_deleted(GtkWidget *widget,
1240 GdkEventAny *event, gpointer data)
1242 prefs_filtering_action_cancel();
1247 * Strings describing exec format strings
1249 * When adding new lines, remember to put 2 strings for each line
1251 static gchar *exec_desc_strings[] = {
1252 "%%", N_("literal %"),
1253 "%s", N_("Subject"),
1258 "%i", N_("Message-ID"),
1259 "%n", N_("Newsgroups"),
1260 "%r", N_("References"),
1261 "%F", N_("filename (should not be modified)"),
1262 "\\n", N_("new line"),
1263 "\\", N_("escape character for quotes"),
1264 "\\\"", N_("quote character"),
1268 static DescriptionWindow exec_desc_win = {
1273 N_("Filtering Action: 'Execute'"),
1274 N_("'Execute' allows you to send a message or message element "
1275 "to an external program or script.\n"
1276 "The following symbols can be used:"),
1281 *\brief Show Execute action's info
1283 static void prefs_filtering_action_exec_info(GtkWidget *widget, GtkWidget *parent)
1285 exec_desc_win.parent = parent;
1286 description_window_create(&exec_desc_win);
1289 static void prefs_filtering_action_select_dest(void)
1294 dest = foldersel_folder_sel(NULL, FOLDER_SEL_COPY, NULL, FALSE);
1297 path = folder_item_get_identifier(dest);
1299 gtk_entry_set_text(GTK_ENTRY(filtering_action.dest_entry), path);
1303 #ifndef USE_NEW_ADDRBOOK
1304 static void prefs_filtering_action_select_addressbook(void)
1306 const gchar *folderpath = NULL;
1307 gchar *new_path = NULL;
1309 folderpath = gtk_entry_get_text(GTK_ENTRY(filtering_action.dest_entry));
1310 new_path = addressbook_folder_selection(folderpath);
1312 gtk_entry_set_text(GTK_ENTRY(filtering_action.dest_entry), new_path);
1318 static void prefs_filtering_action_enable_widget(GtkWidget* widget, const gboolean enable)
1320 cm_return_if_fail(widget != NULL);
1324 #if !GTK_CHECK_VERSION(2,24,0)
1325 if(GTK_IS_COMBO_BOX(widget) || GTK_IS_COMBO_BOX_ENTRY(widget))
1327 if(GTK_IS_COMBO_BOX(widget))
1329 gtk_combo_box_set_active(GTK_COMBO_BOX(widget), 0);
1330 else if(GTK_IS_SPIN_BUTTON(widget))
1331 gtk_spin_button_set_value(GTK_SPIN_BUTTON(widget), 0);
1332 else if(GTK_IS_ENTRY(widget))
1333 gtk_entry_set_text(GTK_ENTRY(widget), "");
1334 #if !GTK_CHECK_VERSION(3, 0, 0)
1335 else if(GTK_IS_CMOPTION_MENU(widget))
1336 gtk_cmoption_menu_set_history(GTK_CMOPTION_MENU(widget), 0);
1339 gtk_widget_set_sensitive(widget, TRUE);
1340 gtk_widget_show(widget);
1342 gtk_widget_set_sensitive(widget, FALSE);
1343 gtk_widget_hide(widget);
1347 #define ACTION_SEND(x) (x == ACTION_FORWARD || x == ACTION_REDIRECT || \
1348 x == ACTION_FORWARD_AS_ATTACHMENT)
1349 #define ACTION_SCORE(x) (x == ACTION_CHANGE_SCORE || x == ACTION_SET_SCORE)
1350 #define ACTION_TAG(x) (x == ACTION_SET_TAG || x == ACTION_UNSET_TAG)
1351 #define ACTION_FILEOP(x) (x == ACTION_MOVE || x == ACTION_COPY)
1353 static void prefs_filtering_action_type_selection_changed(GtkWidget *combo,
1358 value = combobox_get_active_data(GTK_COMBO_BOX(filtering_action.action_combo));
1360 if (filtering_action.current_action != value) {
1361 if (ACTION_SEND(filtering_action.current_action)) {
1362 debug_print("unregistering address completion entry\n");
1363 address_completion_unregister_entry(GTK_ENTRY(filtering_action.dest_entry));
1364 address_completion_end(filtering_action.window);
1366 if (ACTION_SEND(value)) {
1367 debug_print("registering address completion entry\n");
1368 address_completion_start(filtering_action.window);
1369 address_completion_register_entry(
1370 GTK_ENTRY(filtering_action.dest_entry),
1373 filtering_action.current_action = value;
1376 prefs_filtering_action_enable_widget(filtering_action.label2,
1377 (ACTION_SEND(value) || value == ACTION_ADD_TO_ADDRESSBOOK));
1379 prefs_filtering_action_enable_widget(filtering_action.label3,
1380 (ACTION_SEND(value) || ACTION_TAG(value) ||
1381 ACTION_SCORE(value) || ACTION_FILEOP(value) ||
1382 value == ACTION_COLOR || value == ACTION_EXECUTE ||
1383 value == ACTION_ADD_TO_ADDRESSBOOK));
1385 prefs_filtering_action_enable_widget(filtering_action.account_combo,
1386 ACTION_SEND(value));
1388 prefs_filtering_action_enable_widget(filtering_action.tags_combo,
1391 prefs_filtering_action_enable_widget(filtering_action.dest_entry,
1392 (ACTION_FILEOP(value) || value == ACTION_EXECUTE ||
1393 ACTION_SEND(value) || value == ACTION_ADD_TO_ADDRESSBOOK));
1395 prefs_filtering_action_enable_widget(filtering_action.dest_btn,
1396 ACTION_FILEOP(value));
1398 prefs_filtering_action_enable_widget(filtering_action.exec_btn,
1399 (value == ACTION_EXECUTE));
1401 #if !GTK_CHECK_VERSION(3, 0, 0)
1402 prefs_filtering_action_enable_widget(filtering_action.color_optmenu,
1403 (value == ACTION_COLOR));
1406 prefs_filtering_action_enable_widget(filtering_action.header_combo,
1407 (value == ACTION_ADD_TO_ADDRESSBOOK));
1408 #ifndef USE_NEW_ADDRBOOK
1409 prefs_filtering_action_enable_widget(filtering_action.addressbook_btn,
1410 (value == ACTION_ADD_TO_ADDRESSBOOK));
1412 prefs_filtering_action_enable_widget(filtering_action.score_entry,
1413 ACTION_SCORE(value));
1416 case ACTION_FORWARD:
1417 case ACTION_FORWARD_AS_ATTACHMENT:
1418 case ACTION_REDIRECT:
1419 gtk_label_set_text(GTK_LABEL(filtering_action.label2), _("Account"));
1420 gtk_label_set_text(GTK_LABEL(filtering_action.label3), _("Recipient"));
1422 case ACTION_ADD_TO_ADDRESSBOOK:
1423 gtk_label_set_text(GTK_LABEL(filtering_action.label2), _("Header Name"));
1424 gtk_label_set_text(GTK_LABEL(filtering_action.label3), _("Book/Folder"));
1428 gtk_label_set_text(GTK_LABEL(filtering_action.label3), _("Destination"));
1430 #if !GTK_CHECK_VERSION(3, 0, 0)
1432 gtk_label_set_text(GTK_LABEL(filtering_action.label3), _("Color"));
1435 case ACTION_EXECUTE:
1436 gtk_label_set_text(GTK_LABEL(filtering_action.label3), _("Execute"));
1438 case ACTION_SET_SCORE:
1439 case ACTION_CHANGE_SCORE:
1440 gtk_label_set_text(GTK_LABEL(filtering_action.label3), _("Score"));
1442 case ACTION_SET_TAG:
1443 case ACTION_UNSET_TAG:
1444 gtk_label_set_text(GTK_LABEL(filtering_action.label3), _("Tag"));
1449 static void prefs_filtering_action_reset_dialog(void)
1451 combobox_select_by_data(GTK_COMBO_BOX(filtering_action.action_combo), ACTION_MOVE);
1452 gtk_combo_box_set_active(GTK_COMBO_BOX(filtering_action.account_combo), 0);
1453 gtk_entry_set_text(GTK_ENTRY(filtering_action.dest_entry), "");
1454 gtk_spin_button_set_value(GTK_SPIN_BUTTON(filtering_action.score_entry), 0);
1457 static GtkListStore* prefs_filtering_action_create_data_store(void)
1459 return gtk_list_store_new(N_PFA_COLUMNS,
1465 static void prefs_filtering_action_list_view_insert_action(GtkWidget *list_view,
1467 const gchar *action,
1470 GtkListStore *store = GTK_LIST_STORE(gtk_tree_view_get_model
1471 (GTK_TREE_VIEW(list_view)));
1475 /* see if row exists, if not append */
1477 gtk_list_store_append(store, &iter);
1481 gtk_list_store_set(store, &iter,
1483 PFA_VALID_ACTION, is_valid,
1487 static GtkWidget *prefs_filtering_action_list_view_create(void)
1489 GtkTreeView *list_view;
1490 GtkTreeModel *model;
1491 GtkTreeSelection *selector;
1493 model = GTK_TREE_MODEL(prefs_filtering_action_create_data_store());
1494 list_view = GTK_TREE_VIEW(gtk_tree_view_new_with_model(model));
1495 g_object_unref(model);
1497 gtk_tree_view_set_rules_hint(list_view, prefs_common.use_stripes_everywhere);
1498 gtk_tree_view_set_reorderable(list_view, TRUE);
1500 selector = gtk_tree_view_get_selection(list_view);
1501 gtk_tree_selection_set_mode(selector, GTK_SELECTION_BROWSE);
1502 gtk_tree_selection_set_select_function
1503 (selector, prefs_filtering_actions_selected, NULL, NULL);
1505 /* create the columns */
1506 prefs_filtering_action_create_list_view_columns(list_view);
1508 return GTK_WIDGET(list_view);
1511 static void prefs_filtering_action_create_list_view_columns(GtkTreeView *list_view)
1513 GtkTreeViewColumn *column;
1514 GtkCellRenderer *renderer;
1516 renderer = gtk_cell_renderer_text_new();
1517 column = gtk_tree_view_column_new_with_attributes
1518 (_("Current action list"),
1522 gtk_tree_view_append_column(list_view, column);
1525 static gboolean prefs_filtering_actions_selected
1526 (GtkTreeSelection *selector,
1527 GtkTreeModel *model,
1529 gboolean currently_selected,
1533 FilteringAction *action;
1534 GSList * action_list;
1540 if (currently_selected)
1543 if (!gtk_tree_model_get_iter(model, &iter, path))
1546 gtk_tree_model_get(model, &iter,
1547 PFA_VALID_ACTION, &is_valid,
1551 prefs_filtering_action_reset_dialog();
1555 gtk_tree_model_get(model, &iter,
1556 PFA_ACTION, &action_str,
1559 action_list = matcher_parser_get_action_list(action_str);
1562 if (action_list == NULL)
1565 action = action_list->data;
1566 g_slist_free(action_list);
1568 switch(action->type) {
1569 case MATCHACTION_MOVE:
1570 combobox_select_by_data(GTK_COMBO_BOX(filtering_action.action_combo),
1573 case MATCHACTION_COPY:
1574 combobox_select_by_data(GTK_COMBO_BOX(filtering_action.action_combo),
1577 case MATCHACTION_DELETE:
1578 combobox_select_by_data(GTK_COMBO_BOX(filtering_action.action_combo),
1581 case MATCHACTION_MARK:
1582 combobox_select_by_data(GTK_COMBO_BOX(filtering_action.action_combo),
1585 case MATCHACTION_UNMARK:
1586 combobox_select_by_data(GTK_COMBO_BOX(filtering_action.action_combo),
1589 case MATCHACTION_LOCK:
1590 combobox_select_by_data(GTK_COMBO_BOX(filtering_action.action_combo),
1593 case MATCHACTION_UNLOCK:
1594 combobox_select_by_data(GTK_COMBO_BOX(filtering_action.action_combo),
1597 case MATCHACTION_MARK_AS_READ:
1598 combobox_select_by_data(GTK_COMBO_BOX(filtering_action.action_combo),
1599 ACTION_MARK_AS_READ);
1601 case MATCHACTION_MARK_AS_UNREAD:
1602 combobox_select_by_data(GTK_COMBO_BOX(filtering_action.action_combo),
1603 ACTION_MARK_AS_UNREAD);
1605 case MATCHACTION_MARK_AS_SPAM:
1606 combobox_select_by_data(GTK_COMBO_BOX(filtering_action.action_combo),
1607 ACTION_MARK_AS_SPAM);
1609 case MATCHACTION_MARK_AS_HAM:
1610 combobox_select_by_data(GTK_COMBO_BOX(filtering_action.action_combo),
1611 ACTION_MARK_AS_HAM);
1613 case MATCHACTION_FORWARD:
1614 list_id = get_list_id_from_account_id(action->account_id);
1615 combobox_select_by_data(GTK_COMBO_BOX(filtering_action.action_combo),
1617 gtk_combo_box_set_active(GTK_COMBO_BOX(filtering_action.account_combo),
1620 case MATCHACTION_FORWARD_AS_ATTACHMENT:
1621 list_id = get_list_id_from_account_id(action->account_id);
1622 combobox_select_by_data(GTK_COMBO_BOX(filtering_action.action_combo),
1623 ACTION_FORWARD_AS_ATTACHMENT);
1624 gtk_combo_box_set_active(GTK_COMBO_BOX(filtering_action.account_combo),
1627 case MATCHACTION_REDIRECT:
1628 list_id = get_list_id_from_account_id(action->account_id);
1629 combobox_select_by_data(GTK_COMBO_BOX(filtering_action.action_combo),
1631 gtk_combo_box_set_active(GTK_COMBO_BOX(filtering_action.account_combo),
1634 case MATCHACTION_EXECUTE:
1635 combobox_select_by_data(GTK_COMBO_BOX(filtering_action.action_combo),
1638 #if !GTK_CHECK_VERSION(3, 0, 0)
1639 case MATCHACTION_COLOR:
1640 combobox_select_by_data(GTK_COMBO_BOX(filtering_action.action_combo),
1642 gtk_cmoption_menu_set_history(GTK_CMOPTION_MENU(filtering_action.color_optmenu),
1643 action->labelcolor + 1);
1644 menu = gtk_cmoption_menu_get_menu(GTK_CMOPTION_MENU(
1645 filtering_action.color_optmenu));
1646 g_signal_emit_by_name(G_OBJECT(menu), "selection-done", menu);
1649 case MATCHACTION_CHANGE_SCORE:
1650 combobox_select_by_data(GTK_COMBO_BOX(filtering_action.action_combo),
1651 ACTION_CHANGE_SCORE);
1652 gtk_spin_button_set_value(GTK_SPIN_BUTTON(filtering_action.score_entry),
1655 case MATCHACTION_SET_SCORE:
1656 combobox_select_by_data(GTK_COMBO_BOX(filtering_action.action_combo),
1658 gtk_spin_button_set_value(GTK_SPIN_BUTTON(filtering_action.score_entry),
1661 case MATCHACTION_STOP:
1662 combobox_select_by_data(GTK_COMBO_BOX(filtering_action.action_combo),
1665 case MATCHACTION_HIDE:
1666 combobox_select_by_data(GTK_COMBO_BOX(filtering_action.action_combo),
1669 case MATCHACTION_IGNORE:
1670 combobox_select_by_data(GTK_COMBO_BOX(filtering_action.action_combo),
1673 case MATCHACTION_WATCH:
1674 combobox_select_by_data(GTK_COMBO_BOX(filtering_action.action_combo),
1677 case MATCHACTION_ADD_TO_ADDRESSBOOK:
1679 gtk_entry_set_text(GTK_ENTRY(filtering_action.header_entry), action->header);
1681 gtk_entry_set_text(GTK_ENTRY(filtering_action.header_entry), "");
1682 combobox_select_by_data(GTK_COMBO_BOX(filtering_action.action_combo),
1683 ACTION_ADD_TO_ADDRESSBOOK);
1685 case MATCHACTION_SET_TAG:
1686 combobox_select_by_data(GTK_COMBO_BOX(filtering_action.action_combo),
1688 combobox_select_by_text(GTK_COMBO_BOX(filtering_action.tags_combo),
1689 action->destination);
1691 case MATCHACTION_UNSET_TAG:
1692 combobox_select_by_data(GTK_COMBO_BOX(filtering_action.action_combo),
1694 combobox_select_by_text(GTK_COMBO_BOX(filtering_action.tags_combo),
1695 action->destination);
1697 case MATCHACTION_CLEAR_TAGS:
1698 combobox_select_by_data(GTK_COMBO_BOX(filtering_action.action_combo),
1702 g_warning("unhandled case !\n");
1704 if (action->destination)
1705 gtk_entry_set_text(GTK_ENTRY(filtering_action.dest_entry), action->destination);
1707 gtk_entry_set_text(GTK_ENTRY(filtering_action.dest_entry), "");
1709 filteringaction_free(action); /* XXX: memleak */