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_ALT_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_ALT_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_ALT_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);
303 gtk_window_set_modal(GTK_WINDOW(filtering_action.window), TRUE);
307 *\brief Save Gtk object size to prefs dataset
309 static void prefs_filtering_action_size_allocate_cb(GtkWidget *widget,
310 GtkAllocation *allocation)
312 cm_return_if_fail(allocation != NULL);
314 prefs_common.filteringactionwin_width = allocation->width;
315 prefs_common.filteringactionwin_height = allocation->height;
318 #define LABELS_WIDTH 80
319 #define SECOND_ROW_WIDTH 250
321 static void prefs_filtering_action_check_widget_width(GtkWidget *widget)
325 gtk_widget_size_request(widget, &req);
326 if(req.width > SECOND_ROW_WIDTH)
327 gtk_widget_set_size_request(widget, SECOND_ROW_WIDTH, -1);
331 *\brief Create the matcher dialog
333 static void prefs_filtering_action_create(void)
338 GtkWidget *cancel_btn;
339 GtkWidget *confirm_area;
349 GtkWidget *action_combo;
350 GtkWidget *account_combo;
351 GtkWidget *header_combo;
352 GtkWidget *header_entry;
353 #ifndef USE_ALT_ADDRBOOK
354 GtkWidget *addressbook_btn;
356 GtkWidget *dest_entry;
358 GtkWidget *score_entry;
359 GtkWidget *tags_combo;
365 GtkWidget *subst_btn;
368 GtkWidget *action_hbox;
369 GtkWidget *action_scrolledwin;
370 GtkWidget *action_list_view;
378 #if !GTK_CHECK_VERSION(3, 0, 0)
379 GtkWidget *color_optmenu;
382 static GdkGeometry geometry;
387 GtkSizeGroup *size_group = gtk_size_group_new(GTK_SIZE_GROUP_HORIZONTAL);
388 GtkSizeGroup *size_action = gtk_size_group_new(GTK_SIZE_GROUP_HORIZONTAL);
390 GtkCellRenderer *renderer;
392 debug_print("Creating matcher configuration window...\n");
394 window = gtkut_window_new(GTK_WINDOW_TOPLEVEL, "prefs_filtering_action");
395 gtk_container_set_border_width(GTK_CONTAINER(window), VBOX_BORDER);
396 gtk_window_set_position(GTK_WINDOW(window), GTK_WIN_POS_CENTER);
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 account_combo = gtk_combo_box_text_new ();
492 gtk_size_group_add_widget(size_action, account_combo);
494 for (accounts = account_get_list() ; accounts != NULL;
495 accounts = accounts->next) {
496 PrefsAccount *ac = (PrefsAccount *)accounts->data;
497 gchar *name = g_strdup(ac->account_name);
498 gtk_combo_box_text_append_text(GTK_COMBO_BOX_TEXT(account_combo), (gpointer) name);
502 prefs_filtering_action_check_widget_width(account_combo);
503 gtk_combo_box_set_active(GTK_COMBO_BOX(account_combo), 0);
504 gtk_box_pack_start (GTK_BOX (hbox1), account_combo,
509 header_combo = combobox_text_new(TRUE, "From", "To", "Cc", "Reply-To", "Sender", NULL);
510 gtk_size_group_add_widget(size_action, header_combo);
511 gtk_box_pack_start (GTK_BOX (hbox1), header_combo,
513 header_entry = gtk_bin_get_child(GTK_BIN((header_combo)));
517 hbox1 = gtk_hbox_new (FALSE, 0);
518 gtk_table_attach(GTK_TABLE(table), hbox1, 1, 2, 2, 3,
519 GTK_FILL | GTK_EXPAND, GTK_SHRINK, 0, 0);
521 dest_entry = gtk_entry_new ();
522 gtk_box_pack_start (GTK_BOX (hbox1), dest_entry, TRUE, TRUE, 0);
524 score_entry = gtk_spin_button_new_with_range(-1000, 1000, 1);
525 gtk_box_pack_start(GTK_BOX(hbox1), score_entry, FALSE, FALSE, 0);
527 #if !GTK_CHECK_VERSION(3, 0, 0)
528 color_optmenu = gtk_cmoption_menu_new();
529 gtk_size_group_add_widget(size_action, color_optmenu);
530 gtk_cmoption_menu_set_menu(GTK_CMOPTION_MENU(color_optmenu),
531 colorlabel_create_color_menu());
532 prefs_filtering_action_check_widget_width(color_optmenu);
533 gtk_box_pack_start(GTK_BOX(hbox1), color_optmenu, FALSE, FALSE, 0);
536 tags_combo = gtk_combo_box_text_new ();
537 gtk_size_group_add_widget(size_action, tags_combo);
539 for (tmp = tags = tags_get_list() ; tmp != NULL;
541 gchar *name = g_strdup(tags_get_tag(GPOINTER_TO_INT(tmp->data)));
543 gtk_combo_box_text_append_text(GTK_COMBO_BOX_TEXT(tags_combo), (gpointer) name);
548 prefs_filtering_action_check_widget_width(tags_combo);
549 gtk_combo_box_set_active(GTK_COMBO_BOX(tags_combo), 0);
550 gtk_box_pack_start (GTK_BOX (hbox1), tags_combo,
553 hbox1 = gtk_hbox_new (FALSE, 0);
554 gtk_table_attach(GTK_TABLE(table), hbox1, 2, 3, 2, 3,
555 GTK_FILL, GTK_SHRINK, 0, 0);
557 dest_btn = gtk_button_new_with_label (_("Select..."));
558 gtk_box_pack_start (GTK_BOX (hbox1), dest_btn, FALSE, FALSE, 0);
559 g_signal_connect (G_OBJECT (dest_btn), "clicked",
560 G_CALLBACK(prefs_filtering_action_select_dest),
563 #ifndef USE_ALT_ADDRBOOK
564 addressbook_btn = gtk_button_new_with_label (_("Select..."));
565 gtk_box_pack_start (GTK_BOX (hbox1), addressbook_btn, FALSE, FALSE, 0);
566 g_signal_connect (G_OBJECT (addressbook_btn), "clicked",
567 G_CALLBACK(prefs_filtering_action_select_addressbook),
571 exec_btn = gtk_button_new_from_stock(GTK_STOCK_INFO);
572 gtk_box_pack_start (GTK_BOX (hbox1), exec_btn, FALSE, FALSE, 0);
573 g_signal_connect (G_OBJECT (exec_btn), "clicked",
574 G_CALLBACK(prefs_filtering_action_exec_info),
577 /* register / substitute / delete */
579 reg_hbox = gtk_hbox_new(FALSE, 4);
580 gtk_box_pack_start(GTK_BOX(vbox1), reg_hbox, FALSE, FALSE, 0);
582 arrow = gtk_arrow_new(GTK_ARROW_DOWN, GTK_SHADOW_OUT);
583 gtk_box_pack_start(GTK_BOX(reg_hbox), arrow, FALSE, FALSE, 0);
584 gtk_widget_set_size_request(arrow, -1, 16);
586 btn_hbox = gtk_hbox_new(TRUE, 4);
587 gtk_box_pack_start(GTK_BOX(reg_hbox), btn_hbox, FALSE, FALSE, 0);
589 reg_btn = gtk_button_new_from_stock(GTK_STOCK_ADD);
590 gtk_box_pack_start(GTK_BOX(btn_hbox), reg_btn, FALSE, TRUE, 0);
591 g_signal_connect(G_OBJECT(reg_btn), "clicked",
592 G_CALLBACK(prefs_filtering_action_register_cb), NULL);
594 subst_btn = gtkut_get_replace_btn(_("_Replace"));
595 gtk_box_pack_start(GTK_BOX(btn_hbox), subst_btn, FALSE, TRUE, 0);
596 g_signal_connect(G_OBJECT(subst_btn), "clicked",
597 G_CALLBACK(prefs_filtering_action_substitute_cb),
600 del_btn = gtk_button_new_with_mnemonic (_("D_elete"));
601 gtk_button_set_image(GTK_BUTTON(del_btn),
602 gtk_image_new_from_stock(GTK_STOCK_REMOVE,GTK_ICON_SIZE_BUTTON));
603 gtk_box_pack_start(GTK_BOX(btn_hbox), del_btn, FALSE, TRUE, 0);
604 g_signal_connect(G_OBJECT(del_btn), "clicked",
605 G_CALLBACK(prefs_filtering_action_delete_cb), NULL);
607 action_hbox = gtk_hbox_new(FALSE, 8);
608 gtk_box_pack_start(GTK_BOX(vbox1), action_hbox, TRUE, TRUE, 0);
610 action_scrolledwin = gtk_scrolled_window_new(NULL, NULL);
611 gtk_widget_set_size_request(action_scrolledwin, -1, 150);
612 gtk_box_pack_start(GTK_BOX(action_hbox), action_scrolledwin,
614 gtk_scrolled_window_set_shadow_type(GTK_SCROLLED_WINDOW(action_scrolledwin),
615 GTK_SHADOW_ETCHED_IN);
616 gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(action_scrolledwin),
617 GTK_POLICY_AUTOMATIC,
618 GTK_POLICY_AUTOMATIC);
620 action_list_view = prefs_filtering_action_list_view_create();
621 gtk_container_add(GTK_CONTAINER(action_scrolledwin), action_list_view);
623 btn_vbox = gtk_vbox_new(FALSE, 8);
624 gtk_box_pack_start(GTK_BOX(action_hbox), btn_vbox, FALSE, FALSE, 0);
626 up_btn = gtk_button_new_from_stock(GTK_STOCK_GO_UP);
627 gtk_box_pack_start(GTK_BOX(btn_vbox), up_btn, FALSE, FALSE, 0);
628 g_signal_connect(G_OBJECT(up_btn), "clicked",
629 G_CALLBACK(prefs_filtering_action_up), NULL);
631 down_btn = gtk_button_new_from_stock(GTK_STOCK_GO_DOWN);
632 gtk_box_pack_start(GTK_BOX(btn_vbox), down_btn, FALSE, FALSE, 0);
633 g_signal_connect(G_OBJECT(down_btn), "clicked",
634 G_CALLBACK(prefs_filtering_action_down), NULL);
636 if (!geometry.min_height) {
637 geometry.min_width = 490;
638 geometry.min_height = 348;
641 gtk_window_set_geometry_hints(GTK_WINDOW(window), NULL, &geometry,
643 gtk_widget_set_size_request(window, prefs_common.filteringactionwin_width,
644 prefs_common.filteringactionwin_height);
646 g_object_unref(G_OBJECT(size_group));
647 g_object_unref(G_OBJECT(size_action));
649 gtk_widget_show_all(window);
651 filtering_action.window = window;
652 filtering_action.label1 = label1;
653 filtering_action.label2 = label2;
654 filtering_action.label3 = label3;
655 filtering_action.action_combo = action_combo;
656 filtering_action.account_combo = account_combo;
657 filtering_action.tags_combo = tags_combo;
658 filtering_action.dest_entry = dest_entry;
659 filtering_action.dest_btn = dest_btn;
660 filtering_action.exec_btn = exec_btn;
661 #if !GTK_CHECK_VERSION(3, 0, 0)
662 filtering_action.color_optmenu = color_optmenu;
664 filtering_action.score_entry = score_entry;
665 filtering_action.header_combo = header_combo;
666 filtering_action.header_entry = header_entry;
667 #ifndef USE_ALT_ADDRBOOK
668 filtering_action.addressbook_btn = addressbook_btn;
670 filtering_action.ok_btn = ok_btn;
671 filtering_action.action_list_view = action_list_view;
673 prefs_filtering_action_type_selection_changed(NULL, NULL);
677 *\brief Set the contents of a row
679 *\param row Index of row to set
680 *\param prop Condition to set
683 static void prefs_filtering_action_list_view_set_row(GtkTreeIter *row,
684 FilteringAction *action)
688 if (row == NULL && action == NULL) {
689 prefs_filtering_action_list_view_insert_action
690 (filtering_action.action_list_view,
691 NULL, _("(New)"), FALSE);
695 buf = filteringaction_to_string(action);
697 prefs_filtering_action_list_view_insert_action
698 (filtering_action.action_list_view,
704 *\brief Initializes dialog with a set of conditions
706 *\param matchers List of conditions
708 static void prefs_filtering_action_set_dialog(GSList *action_list)
712 gtk_list_store_clear(GTK_LIST_STORE(gtk_tree_view_get_model
713 (GTK_TREE_VIEW(filtering_action.action_list_view))));
715 prefs_filtering_action_list_view_set_row(NULL, NULL);
716 if (action_list != NULL) {
717 for (cur = action_list; cur != NULL;
718 cur = g_slist_next(cur)) {
719 FilteringAction *action;
720 action = (FilteringAction *) cur->data;
721 prefs_filtering_action_list_view_set_row(NULL, action);
725 prefs_filtering_action_reset_dialog();
727 combobox_set_sensitive(GTK_COMBO_BOX(filtering_action.action_combo), 9,
728 (tags_get_size() > 0) ? TRUE : FALSE);
732 *\brief Converts current actions in list box in
733 * an action list used by the filtering system.
735 *\return GSList * List of actions.
737 static GSList *prefs_filtering_action_get_list(void)
743 GtkTreeView *list_view = GTK_TREE_VIEW(filtering_action.action_list_view);
744 GtkTreeModel *model = gtk_tree_view_get_model(list_view);
749 while (gtk_tree_model_iter_nth_child(model, &iter, NULL, row)) {
751 gtk_tree_model_get(model, &iter,
752 PFA_ACTION, &action_str,
753 PFA_VALID_ACTION, &is_valid,
757 GSList * tmp_action_list;
758 tmp_action_list = matcher_parser_get_action_list(action_str);
760 if (tmp_action_list == NULL) {
765 action_list = g_slist_concat(action_list,
779 *\brief Returns account ID from the given list index
781 *\return gint account ID
783 static gint get_account_id_from_list_id(gint list_id)
787 for (accounts = account_get_list() ; accounts != NULL;
788 accounts = accounts->next) {
789 PrefsAccount *ac = (PrefsAccount *)accounts->data;
792 return ac->account_id;
799 *\brief Returns list index from the given account ID
801 *\return gint list index
803 static gint get_list_id_from_account_id(gint account_id)
808 for (accounts = account_get_list() ; accounts != NULL;
809 accounts = accounts->next) {
810 PrefsAccount *ac = (PrefsAccount *)accounts->data;
812 if (account_id == ac->account_id)
821 *\brief Returns parser action ID from internal action ID
823 *\return gint parser action ID
825 static gint prefs_filtering_action_get_matching_from_action(Action action_id)
829 return MATCHACTION_MOVE;
831 return MATCHACTION_SET_TAG;
832 case ACTION_UNSET_TAG:
833 return MATCHACTION_UNSET_TAG;
834 case ACTION_CLEAR_TAGS:
835 return MATCHACTION_CLEAR_TAGS;
837 return MATCHACTION_COPY;
839 return MATCHACTION_DELETE;
841 return MATCHACTION_MARK;
843 return MATCHACTION_UNMARK;
845 return MATCHACTION_LOCK;
847 return MATCHACTION_UNLOCK;
848 case ACTION_MARK_AS_READ:
849 return MATCHACTION_MARK_AS_READ;
850 case ACTION_MARK_AS_UNREAD:
851 return MATCHACTION_MARK_AS_UNREAD;
852 case ACTION_MARK_AS_SPAM:
853 return MATCHACTION_MARK_AS_SPAM;
854 case ACTION_MARK_AS_HAM:
855 return MATCHACTION_MARK_AS_HAM;
857 return MATCHACTION_FORWARD;
858 case ACTION_FORWARD_AS_ATTACHMENT:
859 return MATCHACTION_FORWARD_AS_ATTACHMENT;
860 case ACTION_REDIRECT:
861 return MATCHACTION_REDIRECT;
863 return MATCHACTION_EXECUTE;
864 #if !GTK_CHECK_VERSION(3, 0, 0)
866 return MATCHACTION_COLOR;
869 return MATCHACTION_HIDE;
871 return MATCHACTION_IGNORE;
873 return MATCHACTION_WATCH;
875 return MATCHACTION_STOP;
876 case ACTION_CHANGE_SCORE:
877 return MATCHACTION_CHANGE_SCORE;
878 case ACTION_SET_SCORE:
879 return MATCHACTION_SET_SCORE;
880 case ACTION_ADD_TO_ADDRESSBOOK:
881 return MATCHACTION_ADD_TO_ADDRESSBOOK;
888 *\brief Returns action from the content of the dialog
890 *\param alert specifies whether alert dialog boxes should be shown
893 *\return FilteringAction * action entered in the dialog box.
895 static FilteringAction * prefs_filtering_action_dialog_to_action(gboolean alert)
901 gchar * destination = NULL;
903 FilteringAction * action;
905 gchar * header = NULL;
907 action_id = combobox_get_active_data(GTK_COMBO_BOX(filtering_action.action_combo));
908 action_type = prefs_filtering_action_get_matching_from_action(action_id);
909 list_id = gtk_combo_box_get_active(GTK_COMBO_BOX(filtering_action.account_combo));
910 account_id = get_account_id_from_list_id(list_id);
918 destination = gtk_editable_get_chars(GTK_EDITABLE(filtering_action.dest_entry), 0, -1);
919 if (*destination == '\0') {
921 alertpanel_error(action_id == ACTION_EXECUTE
922 ? _("Command-line not set")
923 : _("Destination is not set."));
929 case ACTION_FORWARD_AS_ATTACHMENT:
930 case ACTION_REDIRECT:
931 destination = gtk_editable_get_chars(GTK_EDITABLE(filtering_action.dest_entry), 0, -1);
932 if (*destination == '\0') {
934 alertpanel_error(_("Recipient is not set."));
939 #if !GTK_CHECK_VERSION(3, 0, 0)
941 labelcolor = colorlabel_get_color_menu_active_item(
942 gtk_cmoption_menu_get_menu(GTK_CMOPTION_MENU(filtering_action.color_optmenu)));
946 case ACTION_CHANGE_SCORE:
947 case ACTION_SET_SCORE:
948 score = gtk_spin_button_get_value_as_int(GTK_SPIN_BUTTON(
949 filtering_action.score_entry));
950 if (!score && action_id == ACTION_CHANGE_SCORE) {
952 alertpanel_error(_("Score is not set"));
956 case ACTION_ADD_TO_ADDRESSBOOK:
957 header = gtk_editable_get_chars(GTK_EDITABLE(filtering_action.header_entry), 0, -1);
958 if (*header == '\0') {
960 alertpanel_error(_("Header is not set."));
964 destination = gtk_editable_get_chars(GTK_EDITABLE(filtering_action.dest_entry), 0, -1);
965 if (*destination == '\0') {
967 alertpanel_error(_("Target addressbook/folder is not set."));
973 case ACTION_UNSET_TAG:
974 destination = gtk_combo_box_text_get_active_text(GTK_COMBO_BOX_TEXT(filtering_action.tags_combo));
975 if (!destination || *destination == '\0') {
977 alertpanel_error(_("Tag name is empty."));
991 case ACTION_MARK_AS_READ:
992 case ACTION_MARK_AS_UNREAD:
993 case ACTION_MARK_AS_SPAM:
994 case ACTION_MARK_AS_HAM:
995 case ACTION_CLEAR_TAGS:
999 action = filteringaction_new(action_type, account_id,
1000 destination, labelcolor, score, header);
1002 g_free(destination);
1007 *\brief Signal handler for register button
1009 static void prefs_filtering_action_register_cb(void)
1011 FilteringAction *action;
1013 action = prefs_filtering_action_dialog_to_action(TRUE);
1017 prefs_filtering_action_list_view_set_row(NULL, action);
1019 filteringaction_free(action);
1021 * (presumably gtk_list_select_item(), called by
1022 * prefs_filtering_action_reset_dialog() activates
1023 * what seems to be a bug. this causes any other
1024 * list items to be unselectable)
1025 * prefs_filtering_action_reset_dialog(); */
1026 gtk_combo_box_set_active(GTK_COMBO_BOX(filtering_action.account_combo), 0);
1027 gtk_combo_box_set_active(GTK_COMBO_BOX(filtering_action.tags_combo), 0);
1028 gtk_entry_set_text(GTK_ENTRY(filtering_action.dest_entry), "");
1032 *\brief Signal handler for substitute button
1034 static void prefs_filtering_action_substitute_cb(void)
1036 GtkTreeView *list_view = GTK_TREE_VIEW
1037 (filtering_action.action_list_view);
1038 GtkTreeSelection *selection = gtk_tree_view_get_selection(list_view);
1039 GtkTreeModel *model;
1042 FilteringAction *action;
1044 if (!gtk_tree_selection_get_selected(selection, &model, &row))
1047 gtk_tree_model_get(model, &row, PFA_VALID_ACTION, &is_valid, -1);
1051 action = prefs_filtering_action_dialog_to_action(TRUE);
1055 prefs_filtering_action_list_view_set_row(&row, action);
1057 filteringaction_free(action);
1059 prefs_filtering_action_reset_dialog();
1063 *\brief Signal handler for delete button
1065 static void prefs_filtering_action_delete_cb(void)
1067 GtkTreeView *list_view = GTK_TREE_VIEW
1068 (filtering_action.action_list_view);
1069 GtkTreeSelection *selection = gtk_tree_view_get_selection(list_view);
1070 GtkTreeModel *model;
1074 if (!gtk_tree_selection_get_selected(selection, &model, &row))
1077 gtk_tree_model_get(model, &row, PFA_VALID_ACTION, &is_valid, -1);
1081 gtk_list_store_remove(GTK_LIST_STORE(model), &row);
1083 prefs_filtering_action_reset_dialog();
1087 *\brief Signal handler for 'move up' button
1089 static void prefs_filtering_action_up(void)
1091 GtkTreePath *prev, *sel, *try;
1093 GtkListStore *store = NULL;
1094 GtkTreeModel *model = NULL;
1097 if (!gtk_tree_selection_get_selected
1098 (gtk_tree_view_get_selection
1099 (GTK_TREE_VIEW(filtering_action.action_list_view)),
1103 store = (GtkListStore *)model;
1104 sel = gtk_tree_model_get_path(GTK_TREE_MODEL(store), &isel);
1108 /* no move if we're at row 0 or 1, looks phony, but other
1109 * solutions are more convoluted... */
1110 try = gtk_tree_path_copy(sel);
1111 if (!gtk_tree_path_prev(try) || !gtk_tree_path_prev(try)) {
1112 gtk_tree_path_free(try);
1113 gtk_tree_path_free(sel);
1116 gtk_tree_path_free(try);
1118 prev = gtk_tree_path_copy(sel);
1119 if (gtk_tree_path_prev(prev)) {
1120 gtk_tree_model_get_iter(GTK_TREE_MODEL(store),
1122 gtk_list_store_swap(store, &iprev, &isel);
1123 /* XXX: GTK2 select row?? */
1126 gtk_tree_path_free(sel);
1127 gtk_tree_path_free(prev);
1131 *\brief Signal handler for 'move down' button
1133 static void prefs_filtering_action_down(void)
1135 GtkListStore *store = NULL;
1136 GtkTreeModel *model = NULL;
1137 GtkTreeIter next, sel;
1140 if (!gtk_tree_selection_get_selected
1141 (gtk_tree_view_get_selection
1142 (GTK_TREE_VIEW(filtering_action.action_list_view)),
1146 store = (GtkListStore *)model;
1147 try = gtk_tree_model_get_path(GTK_TREE_MODEL(store), &sel);
1151 /* move when not at row 0 ... */
1152 if (gtk_tree_path_prev(try)) {
1154 if (gtk_tree_model_iter_next(GTK_TREE_MODEL(store), &next))
1155 gtk_list_store_swap(store, &next, &sel);
1158 gtk_tree_path_free(try);
1162 *\brief Handle key press
1164 *\param widget Widget receiving key press
1165 *\param event Key event
1166 *\param data User data
1168 static gboolean prefs_filtering_action_key_pressed(GtkWidget *widget,
1169 GdkEventKey *event, gpointer data)
1171 if (event && event->keyval == GDK_KEY_Escape) {
1172 prefs_filtering_action_cancel();
1179 *\brief Cancel matcher dialog
1181 static void prefs_filtering_action_cancel(void)
1183 gtk_widget_destroy(filtering_action.window);
1184 filtering_action.window = NULL;
1189 *\brief Accept current matchers
1191 static void prefs_filtering_action_ok(void)
1193 GSList * action_list;
1196 action_list = prefs_filtering_action_get_list();
1198 if (action_list == NULL) {
1199 alertpanel_error(_("No action was defined."));
1203 if (filtering_action_callback != NULL)
1204 filtering_action_callback(action_list);
1205 for(cur = action_list ; cur != NULL ; cur = cur->next) {
1206 filteringaction_free(cur->data);
1208 g_slist_free(action_list);
1210 gtk_widget_destroy(filtering_action.window);
1211 filtering_action.window = NULL;
1216 *\brief Called when closing dialog box
1218 *\param widget Dialog widget
1219 *\param event Event info
1220 *\param data User data
1224 static gint prefs_filtering_action_deleted(GtkWidget *widget,
1225 GdkEventAny *event, gpointer data)
1227 prefs_filtering_action_cancel();
1232 * Strings describing exec format strings
1234 * When adding new lines, remember to put 2 strings for each line
1236 static gchar *exec_desc_strings[] = {
1237 "%%", N_("literal %"),
1238 "%s", N_("Subject"),
1243 "%i", N_("Message-ID"),
1244 "%n", N_("Newsgroups"),
1245 "%r", N_("References"),
1246 "%F", N_("filename (should not be modified)"),
1247 "\\n", N_("new line"),
1248 "\\", N_("escape character for quotes"),
1249 "\\\"", N_("quote character"),
1253 static DescriptionWindow exec_desc_win = {
1258 N_("Filtering Action: 'Execute'"),
1259 N_("'Execute' allows you to send a message or message element "
1260 "to an external program or script.\n"
1261 "The following symbols can be used:"),
1266 *\brief Show Execute action's info
1268 static void prefs_filtering_action_exec_info(GtkWidget *widget, GtkWidget *parent)
1270 exec_desc_win.parent = parent;
1271 description_window_create(&exec_desc_win);
1274 static void prefs_filtering_action_select_dest(void)
1279 dest = foldersel_folder_sel(NULL, FOLDER_SEL_COPY, NULL, FALSE,
1280 _("Select destination folder"));
1283 path = folder_item_get_identifier(dest);
1285 gtk_entry_set_text(GTK_ENTRY(filtering_action.dest_entry), path);
1289 #ifndef USE_ALT_ADDRBOOK
1290 static void prefs_filtering_action_select_addressbook(void)
1292 const gchar *folderpath = NULL;
1293 gchar *new_path = NULL;
1295 folderpath = gtk_entry_get_text(GTK_ENTRY(filtering_action.dest_entry));
1296 new_path = addressbook_folder_selection(folderpath);
1298 gtk_entry_set_text(GTK_ENTRY(filtering_action.dest_entry), new_path);
1304 static void prefs_filtering_action_enable_widget(GtkWidget* widget, const gboolean enable)
1306 cm_return_if_fail(widget != NULL);
1310 if(GTK_IS_COMBO_BOX(widget))
1311 gtk_combo_box_set_active(GTK_COMBO_BOX(widget), 0);
1312 else if(GTK_IS_SPIN_BUTTON(widget))
1313 gtk_spin_button_set_value(GTK_SPIN_BUTTON(widget), 0);
1314 else if(GTK_IS_ENTRY(widget))
1315 gtk_entry_set_text(GTK_ENTRY(widget), "");
1316 #if !GTK_CHECK_VERSION(3, 0, 0)
1317 else if(GTK_IS_CMOPTION_MENU(widget))
1318 gtk_cmoption_menu_set_history(GTK_CMOPTION_MENU(widget), 0);
1321 gtk_widget_set_sensitive(widget, TRUE);
1322 gtk_widget_show(widget);
1324 gtk_widget_set_sensitive(widget, FALSE);
1325 gtk_widget_hide(widget);
1329 #define ACTION_SEND(x) (x == ACTION_FORWARD || x == ACTION_REDIRECT || \
1330 x == ACTION_FORWARD_AS_ATTACHMENT)
1331 #define ACTION_SCORE(x) (x == ACTION_CHANGE_SCORE || x == ACTION_SET_SCORE)
1332 #define ACTION_TAG(x) (x == ACTION_SET_TAG || x == ACTION_UNSET_TAG)
1333 #define ACTION_FILEOP(x) (x == ACTION_MOVE || x == ACTION_COPY)
1335 static void prefs_filtering_action_type_selection_changed(GtkWidget *combo,
1340 value = combobox_get_active_data(GTK_COMBO_BOX(filtering_action.action_combo));
1342 if (filtering_action.current_action != value) {
1343 if (ACTION_SEND(filtering_action.current_action)) {
1344 debug_print("unregistering address completion entry\n");
1345 address_completion_unregister_entry(GTK_ENTRY(filtering_action.dest_entry));
1346 address_completion_end(filtering_action.window);
1348 if (ACTION_SEND(value)) {
1349 debug_print("registering address completion entry\n");
1350 address_completion_start(filtering_action.window);
1351 address_completion_register_entry(
1352 GTK_ENTRY(filtering_action.dest_entry),
1355 filtering_action.current_action = value;
1358 prefs_filtering_action_enable_widget(filtering_action.label2,
1359 (ACTION_SEND(value) || value == ACTION_ADD_TO_ADDRESSBOOK));
1361 prefs_filtering_action_enable_widget(filtering_action.label3,
1362 (ACTION_SEND(value) || ACTION_TAG(value) ||
1363 ACTION_SCORE(value) || ACTION_FILEOP(value) ||
1364 value == ACTION_COLOR || value == ACTION_EXECUTE ||
1365 value == ACTION_ADD_TO_ADDRESSBOOK));
1367 prefs_filtering_action_enable_widget(filtering_action.account_combo,
1368 ACTION_SEND(value));
1370 prefs_filtering_action_enable_widget(filtering_action.tags_combo,
1373 prefs_filtering_action_enable_widget(filtering_action.dest_entry,
1374 (ACTION_FILEOP(value) || value == ACTION_EXECUTE ||
1375 ACTION_SEND(value) || value == ACTION_ADD_TO_ADDRESSBOOK));
1377 prefs_filtering_action_enable_widget(filtering_action.dest_btn,
1378 ACTION_FILEOP(value));
1380 prefs_filtering_action_enable_widget(filtering_action.exec_btn,
1381 (value == ACTION_EXECUTE));
1383 #if !GTK_CHECK_VERSION(3, 0, 0)
1384 prefs_filtering_action_enable_widget(filtering_action.color_optmenu,
1385 (value == ACTION_COLOR));
1388 prefs_filtering_action_enable_widget(filtering_action.header_combo,
1389 (value == ACTION_ADD_TO_ADDRESSBOOK));
1390 #ifndef USE_ALT_ADDRBOOK
1391 prefs_filtering_action_enable_widget(filtering_action.addressbook_btn,
1392 (value == ACTION_ADD_TO_ADDRESSBOOK));
1394 prefs_filtering_action_enable_widget(filtering_action.score_entry,
1395 ACTION_SCORE(value));
1398 case ACTION_FORWARD:
1399 case ACTION_FORWARD_AS_ATTACHMENT:
1400 case ACTION_REDIRECT:
1401 gtk_label_set_text(GTK_LABEL(filtering_action.label2), _("Account"));
1402 gtk_label_set_text(GTK_LABEL(filtering_action.label3), _("Recipient"));
1404 case ACTION_ADD_TO_ADDRESSBOOK:
1405 gtk_label_set_text(GTK_LABEL(filtering_action.label2), _("Header Name"));
1406 gtk_label_set_text(GTK_LABEL(filtering_action.label3), _("Book/Folder"));
1410 gtk_label_set_text(GTK_LABEL(filtering_action.label3), _("Destination"));
1412 #if !GTK_CHECK_VERSION(3, 0, 0)
1414 gtk_label_set_text(GTK_LABEL(filtering_action.label3), _("Color"));
1417 case ACTION_EXECUTE:
1418 gtk_label_set_text(GTK_LABEL(filtering_action.label3), _("Execute"));
1420 case ACTION_SET_SCORE:
1421 case ACTION_CHANGE_SCORE:
1422 gtk_label_set_text(GTK_LABEL(filtering_action.label3), _("Score"));
1424 case ACTION_SET_TAG:
1425 case ACTION_UNSET_TAG:
1426 gtk_label_set_text(GTK_LABEL(filtering_action.label3), _("Tag"));
1431 static void prefs_filtering_action_reset_dialog(void)
1433 combobox_select_by_data(GTK_COMBO_BOX(filtering_action.action_combo), ACTION_MOVE);
1434 gtk_combo_box_set_active(GTK_COMBO_BOX(filtering_action.account_combo), 0);
1435 gtk_entry_set_text(GTK_ENTRY(filtering_action.dest_entry), "");
1436 gtk_spin_button_set_value(GTK_SPIN_BUTTON(filtering_action.score_entry), 0);
1439 static GtkListStore* prefs_filtering_action_create_data_store(void)
1441 return gtk_list_store_new(N_PFA_COLUMNS,
1447 static void prefs_filtering_action_list_view_insert_action(GtkWidget *list_view,
1449 const gchar *action,
1452 GtkListStore *store = GTK_LIST_STORE(gtk_tree_view_get_model
1453 (GTK_TREE_VIEW(list_view)));
1457 /* see if row exists, if not append */
1459 gtk_list_store_append(store, &iter);
1463 gtk_list_store_set(store, &iter,
1465 PFA_VALID_ACTION, is_valid,
1469 static GtkWidget *prefs_filtering_action_list_view_create(void)
1471 GtkTreeView *list_view;
1472 GtkTreeModel *model;
1473 GtkTreeSelection *selector;
1475 model = GTK_TREE_MODEL(prefs_filtering_action_create_data_store());
1476 list_view = GTK_TREE_VIEW(gtk_tree_view_new_with_model(model));
1477 g_object_unref(model);
1479 gtk_tree_view_set_rules_hint(list_view, prefs_common.use_stripes_everywhere);
1480 gtk_tree_view_set_reorderable(list_view, TRUE);
1482 selector = gtk_tree_view_get_selection(list_view);
1483 gtk_tree_selection_set_mode(selector, GTK_SELECTION_BROWSE);
1484 gtk_tree_selection_set_select_function
1485 (selector, prefs_filtering_actions_selected, NULL, NULL);
1487 /* create the columns */
1488 prefs_filtering_action_create_list_view_columns(list_view);
1490 return GTK_WIDGET(list_view);
1493 static void prefs_filtering_action_create_list_view_columns(GtkTreeView *list_view)
1495 GtkTreeViewColumn *column;
1496 GtkCellRenderer *renderer;
1498 renderer = gtk_cell_renderer_text_new();
1499 column = gtk_tree_view_column_new_with_attributes
1500 (_("Current action list"),
1504 gtk_tree_view_append_column(list_view, column);
1507 static gboolean prefs_filtering_actions_selected
1508 (GtkTreeSelection *selector,
1509 GtkTreeModel *model,
1511 gboolean currently_selected,
1515 FilteringAction *action;
1516 GSList * action_list;
1522 if (currently_selected)
1525 if (!gtk_tree_model_get_iter(model, &iter, path))
1528 gtk_tree_model_get(model, &iter,
1529 PFA_VALID_ACTION, &is_valid,
1533 prefs_filtering_action_reset_dialog();
1537 gtk_tree_model_get(model, &iter,
1538 PFA_ACTION, &action_str,
1541 action_list = matcher_parser_get_action_list(action_str);
1544 if (action_list == NULL)
1547 action = action_list->data;
1548 g_slist_free(action_list);
1550 switch(action->type) {
1551 case MATCHACTION_MOVE:
1552 combobox_select_by_data(GTK_COMBO_BOX(filtering_action.action_combo),
1555 case MATCHACTION_COPY:
1556 combobox_select_by_data(GTK_COMBO_BOX(filtering_action.action_combo),
1559 case MATCHACTION_DELETE:
1560 combobox_select_by_data(GTK_COMBO_BOX(filtering_action.action_combo),
1563 case MATCHACTION_MARK:
1564 combobox_select_by_data(GTK_COMBO_BOX(filtering_action.action_combo),
1567 case MATCHACTION_UNMARK:
1568 combobox_select_by_data(GTK_COMBO_BOX(filtering_action.action_combo),
1571 case MATCHACTION_LOCK:
1572 combobox_select_by_data(GTK_COMBO_BOX(filtering_action.action_combo),
1575 case MATCHACTION_UNLOCK:
1576 combobox_select_by_data(GTK_COMBO_BOX(filtering_action.action_combo),
1579 case MATCHACTION_MARK_AS_READ:
1580 combobox_select_by_data(GTK_COMBO_BOX(filtering_action.action_combo),
1581 ACTION_MARK_AS_READ);
1583 case MATCHACTION_MARK_AS_UNREAD:
1584 combobox_select_by_data(GTK_COMBO_BOX(filtering_action.action_combo),
1585 ACTION_MARK_AS_UNREAD);
1587 case MATCHACTION_MARK_AS_SPAM:
1588 combobox_select_by_data(GTK_COMBO_BOX(filtering_action.action_combo),
1589 ACTION_MARK_AS_SPAM);
1591 case MATCHACTION_MARK_AS_HAM:
1592 combobox_select_by_data(GTK_COMBO_BOX(filtering_action.action_combo),
1593 ACTION_MARK_AS_HAM);
1595 case MATCHACTION_FORWARD:
1596 list_id = get_list_id_from_account_id(action->account_id);
1597 combobox_select_by_data(GTK_COMBO_BOX(filtering_action.action_combo),
1599 gtk_combo_box_set_active(GTK_COMBO_BOX(filtering_action.account_combo),
1602 case MATCHACTION_FORWARD_AS_ATTACHMENT:
1603 list_id = get_list_id_from_account_id(action->account_id);
1604 combobox_select_by_data(GTK_COMBO_BOX(filtering_action.action_combo),
1605 ACTION_FORWARD_AS_ATTACHMENT);
1606 gtk_combo_box_set_active(GTK_COMBO_BOX(filtering_action.account_combo),
1609 case MATCHACTION_REDIRECT:
1610 list_id = get_list_id_from_account_id(action->account_id);
1611 combobox_select_by_data(GTK_COMBO_BOX(filtering_action.action_combo),
1613 gtk_combo_box_set_active(GTK_COMBO_BOX(filtering_action.account_combo),
1616 case MATCHACTION_EXECUTE:
1617 combobox_select_by_data(GTK_COMBO_BOX(filtering_action.action_combo),
1620 #if !GTK_CHECK_VERSION(3, 0, 0)
1621 case MATCHACTION_COLOR:
1622 combobox_select_by_data(GTK_COMBO_BOX(filtering_action.action_combo),
1624 gtk_cmoption_menu_set_history(GTK_CMOPTION_MENU(filtering_action.color_optmenu),
1625 action->labelcolor + 1);
1626 menu = gtk_cmoption_menu_get_menu(GTK_CMOPTION_MENU(
1627 filtering_action.color_optmenu));
1628 g_signal_emit_by_name(G_OBJECT(menu), "selection-done", menu);
1631 case MATCHACTION_CHANGE_SCORE:
1632 combobox_select_by_data(GTK_COMBO_BOX(filtering_action.action_combo),
1633 ACTION_CHANGE_SCORE);
1634 gtk_spin_button_set_value(GTK_SPIN_BUTTON(filtering_action.score_entry),
1637 case MATCHACTION_SET_SCORE:
1638 combobox_select_by_data(GTK_COMBO_BOX(filtering_action.action_combo),
1640 gtk_spin_button_set_value(GTK_SPIN_BUTTON(filtering_action.score_entry),
1643 case MATCHACTION_STOP:
1644 combobox_select_by_data(GTK_COMBO_BOX(filtering_action.action_combo),
1647 case MATCHACTION_HIDE:
1648 combobox_select_by_data(GTK_COMBO_BOX(filtering_action.action_combo),
1651 case MATCHACTION_IGNORE:
1652 combobox_select_by_data(GTK_COMBO_BOX(filtering_action.action_combo),
1655 case MATCHACTION_WATCH:
1656 combobox_select_by_data(GTK_COMBO_BOX(filtering_action.action_combo),
1659 case MATCHACTION_ADD_TO_ADDRESSBOOK:
1661 gtk_entry_set_text(GTK_ENTRY(filtering_action.header_entry), action->header);
1663 gtk_entry_set_text(GTK_ENTRY(filtering_action.header_entry), "");
1664 combobox_select_by_data(GTK_COMBO_BOX(filtering_action.action_combo),
1665 ACTION_ADD_TO_ADDRESSBOOK);
1667 case MATCHACTION_SET_TAG:
1668 combobox_select_by_data(GTK_COMBO_BOX(filtering_action.action_combo),
1670 combobox_select_by_text(GTK_COMBO_BOX(filtering_action.tags_combo),
1671 action->destination);
1673 case MATCHACTION_UNSET_TAG:
1674 combobox_select_by_data(GTK_COMBO_BOX(filtering_action.action_combo),
1676 combobox_select_by_text(GTK_COMBO_BOX(filtering_action.tags_combo),
1677 action->destination);
1679 case MATCHACTION_CLEAR_TAGS:
1680 combobox_select_by_data(GTK_COMBO_BOX(filtering_action.action_combo),
1684 g_warning("unhandled action type");
1686 if (action->destination)
1687 gtk_entry_set_text(GTK_ENTRY(filtering_action.dest_entry), action->destination);
1689 gtk_entry_set_text(GTK_ENTRY(filtering_action.dest_entry), "");
1691 filteringaction_free(action); /* XXX: memleak */