2 * Claws Mail -- a GTK+ based, lightweight, and fast e-mail client
3 * Copyright (C) 2003-2011 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>
35 #if !GTK_CHECK_VERSION(3, 0, 0)
36 #include "gtkcmoptionmenu.h"
39 #include "prefs_gtk.h"
40 #include "prefs_filtering_action.h"
41 #include "prefs_common.h"
42 #include "mainwindow.h"
43 #include "foldersel.h"
44 #include "manage_window.h"
49 #include "alertpanel.h"
51 #include "description_window.h"
52 #include "addr_compl.h"
54 #include "matcher_parser.h"
55 #include "colorlabel.h"
65 static void prefs_filtering_action_create(void);
66 static void prefs_filtering_action_delete_cb(void);
67 static void prefs_filtering_action_substitute_cb(void);
68 static void prefs_filtering_action_register_cb(void);
69 static void prefs_filtering_action_reset_dialog(void);
70 static gboolean prefs_filtering_action_key_pressed(GtkWidget *widget,
71 GdkEventKey *event, gpointer data);
72 static void prefs_filtering_action_cancel(void);
73 static void prefs_filtering_action_ok(void);
74 static gint prefs_filtering_action_deleted(GtkWidget *widget,
75 GdkEventAny *event, gpointer data);
76 static void prefs_filtering_action_type_selection_changed(GtkWidget *widget,
78 static void prefs_filtering_action_select_dest(void);
79 #ifndef USE_NEW_ADDRBOOK
80 static void prefs_filtering_action_select_addressbook(void);
82 static void prefs_filtering_action_up(void);
83 static void prefs_filtering_action_down(void);
84 static void prefs_filtering_action_set_dialog(GSList *action_list);
85 static GSList *prefs_filtering_action_get_list(void);
87 static GtkListStore* prefs_filtering_action_create_data_store (void);
88 static void prefs_filtering_action_list_view_insert_action (GtkWidget *list_view,
92 static GtkWidget *prefs_filtering_action_list_view_create (void);
93 static void prefs_filtering_action_create_list_view_columns (GtkTreeView *list_view);
94 static gboolean prefs_filtering_actions_selected (GtkTreeSelection *selector,
97 gboolean currently_selected,
100 static void prefs_filtering_action_exec_info (GtkWidget *widget,
104 *\brief UI data for matcher dialog
106 static struct FilteringAction_ {
111 GtkWidget *action_list_view;
115 GtkWidget *action_combo;
116 GtkWidget *account_combo;
117 GtkWidget *dest_entry;
120 #if !GTK_CHECK_VERSION(3, 0, 0)
121 GtkWidget *color_optmenu;
123 GtkWidget *header_combo;
124 GtkWidget *header_entry;
125 GtkWidget *addressbook_btn;
126 GtkWidget *score_entry;
127 GtkWidget *tags_combo;
133 typedef enum Action_ {
142 ACTION_MARK_AS_UNREAD,
146 ACTION_FORWARD_AS_ATTACHMENT,
158 ACTION_ADD_TO_ADDRESSBOOK,
160 /* add other action constants */
168 { NULL, N_("Move"), ACTION_MOVE },
169 { NULL, N_("Copy"), ACTION_COPY },
170 { NULL, N_("Delete"), ACTION_DELETE },
171 { NULL, N_("Hide"), ACTION_HIDE },
172 { N_("Message flags"), N_("Mark"), ACTION_MARK },
173 { N_("Message flags"), N_("Unmark"), ACTION_UNMARK },
174 { N_("Message flags"), N_("Lock"), ACTION_LOCK },
175 { N_("Message flags"), N_("Unlock"), ACTION_UNLOCK },
176 { N_("Message flags"), N_("Mark as read"), ACTION_MARK_AS_READ },
177 { N_("Message flags"), N_("Mark as unread"), ACTION_MARK_AS_UNREAD },
178 { N_("Message flags"), N_("Mark as spam"), ACTION_MARK_AS_SPAM },
179 { N_("Message flags"), N_("Mark as ham"), ACTION_MARK_AS_HAM },
180 { NULL, N_("Execute"), ACTION_EXECUTE },
181 #if !GTK_CHECK_VERSION(3, 0, 0)
182 { NULL, N_("Color label"), ACTION_COLOR },
184 { N_("Resend"), N_("Forward"), ACTION_FORWARD },
185 { N_("Resend"), N_("Forward as attachment"), ACTION_FORWARD_AS_ATTACHMENT },
186 { N_("Resend"), N_("Redirect"), ACTION_REDIRECT },
187 { N_("Score"), N_("Change score"), ACTION_CHANGE_SCORE },
188 { N_("Score"), N_("Set score"), ACTION_SET_SCORE },
189 { N_("Tags"), N_("Apply tag"), ACTION_SET_TAG },
190 { N_("Tags"), N_("Unset tag"), ACTION_UNSET_TAG },
191 { N_("Tags"), N_("Clear tags"), ACTION_CLEAR_TAGS },
192 { N_("Threads"), N_("Ignore thread"), ACTION_IGNORE },
193 { N_("Threads"), N_("Watch thread"), ACTION_WATCH },
194 { NULL, N_("Add to address book"), ACTION_ADD_TO_ADDRESSBOOK },
195 { NULL, N_("Stop filter"), ACTION_STOP },
209 static PrefsFilteringActionSignal *filtering_action_callback;
211 static GtkTreeModel *prefs_filtering_action_create_model(void)
213 GtkTreeIter iter, iter2;
215 gchar *curr_menu = NULL;
218 store = gtk_tree_store_new(N_ACTION_COMBO, G_TYPE_STRING, G_TYPE_INT,
221 for (i = 0; action_menu[i].menu || action_menu[i].text; i++)
223 if (action_menu[i].menu) {
224 if (!curr_menu || strcmp(action_menu[i].menu, curr_menu)) {
225 gtk_tree_store_append(store, &iter, NULL);
226 gtk_tree_store_set(store, &iter,
228 gettext(action_menu[i].menu),
229 ACTION_COMBO_SENS, TRUE,
231 curr_menu = action_menu[i].menu;
234 gtk_tree_store_append(store, &iter2, &iter);
235 gtk_tree_store_set(store, &iter2,
236 ACTION_COMBO_TEXT, gettext(action_menu[i].text),
237 ACTION_COMBO_DATA, action_menu[i].action,
238 ACTION_COMBO_SENS, TRUE,
243 gtk_tree_store_append(store, &iter, NULL);
244 gtk_tree_store_set(store, &iter,
245 ACTION_COMBO_TEXT, gettext(action_menu[i].text),
246 ACTION_COMBO_DATA, action_menu[i].action,
247 ACTION_COMBO_SENS, TRUE,
252 return GTK_TREE_MODEL(store);
255 static void cell_is_sensitive(GtkCellLayout *cell_layout,
256 GtkCellRenderer *cell,
257 GtkTreeModel *tree_model,
261 if(gtk_tree_model_iter_has_child (tree_model, iter)) {
262 g_object_set (cell, "sensitive", FALSE, NULL);
267 *\brief Opens the filtering action dialog with a list of actions
269 *\param matchers List of conditions
273 void prefs_filtering_action_open(GSList *action_list,
274 PrefsFilteringActionSignal *cb)
278 if (!filtering_action.window) {
279 prefs_filtering_action_create();
281 #if !GTK_CHECK_VERSION(3, 0, 0)
282 /* update color label menu */
283 gtk_cmoption_menu_set_menu(GTK_CMOPTION_MENU(filtering_action.color_optmenu),
284 colorlabel_create_color_menu());
288 manage_window_set_transient(GTK_WINDOW(filtering_action.window));
289 gtk_widget_grab_focus(filtering_action.ok_btn);
291 filtering_action_callback = cb;
293 prefs_filtering_action_set_dialog(action_list);
295 gtk_widget_show(filtering_action.window);
299 *\brief Save Gtk object size to prefs dataset
301 static void prefs_filtering_action_size_allocate_cb(GtkWidget *widget,
302 GtkAllocation *allocation)
304 cm_return_if_fail(allocation != NULL);
306 prefs_common.filteringactionwin_width = allocation->width;
307 prefs_common.filteringactionwin_height = allocation->height;
310 #define LABELS_WIDTH 80
311 #define SECOND_ROW_WIDTH 250
313 static void prefs_filtering_action_check_widget_width(GtkWidget *widget)
317 gtk_widget_size_request(widget, &req);
318 if(req.width > SECOND_ROW_WIDTH)
319 gtk_widget_set_size_request(widget, SECOND_ROW_WIDTH, -1);
323 *\brief Create the matcher dialog
325 static void prefs_filtering_action_create(void)
330 GtkWidget *cancel_btn;
331 GtkWidget *confirm_area;
341 GtkWidget *action_combo;
342 GtkWidget *account_combo;
343 GtkWidget *header_combo;
344 GtkWidget *header_entry;
345 GtkWidget *addressbook_btn;
346 GtkWidget *dest_entry;
348 GtkWidget *score_entry;
349 GtkWidget *tags_combo;
355 GtkWidget *subst_btn;
358 GtkWidget *action_hbox;
359 GtkWidget *action_scrolledwin;
360 GtkWidget *action_list_view;
368 #if !GTK_CHECK_VERSION(3, 0, 0)
369 GtkWidget *color_optmenu;
372 static GdkGeometry geometry;
377 GtkSizeGroup *size_group = gtk_size_group_new(GTK_SIZE_GROUP_HORIZONTAL);
378 GtkSizeGroup *size_action = gtk_size_group_new(GTK_SIZE_GROUP_HORIZONTAL);
380 GtkCellRenderer *renderer;
382 debug_print("Creating matcher configuration window...\n");
384 window = gtkut_window_new(GTK_WINDOW_TOPLEVEL, "prefs_filtering_action");
385 gtk_container_set_border_width(GTK_CONTAINER(window), VBOX_BORDER);
386 gtk_window_set_position(GTK_WINDOW(window), GTK_WIN_POS_CENTER);
387 gtk_window_set_modal(GTK_WINDOW(window), TRUE);
388 gtk_window_set_resizable(GTK_WINDOW(window), TRUE);
390 vbox = gtk_vbox_new(FALSE, 6);
391 gtk_container_add(GTK_CONTAINER(window), vbox);
393 gtkut_stock_button_set_create(&confirm_area,
394 &cancel_btn, GTK_STOCK_CANCEL,
395 &ok_btn, GTK_STOCK_OK,
397 gtk_box_pack_end(GTK_BOX(vbox), confirm_area, FALSE, FALSE, 0);
398 gtk_widget_grab_default(ok_btn);
400 gtk_window_set_title(GTK_WINDOW(window),
401 _("Action configuration"));
402 g_signal_connect(G_OBJECT(window), "delete_event",
403 G_CALLBACK(prefs_filtering_action_deleted), NULL);
404 g_signal_connect(G_OBJECT(window), "size_allocate",
405 G_CALLBACK(prefs_filtering_action_size_allocate_cb), NULL);
406 g_signal_connect(G_OBJECT(window), "key_press_event",
407 G_CALLBACK(prefs_filtering_action_key_pressed), NULL);
408 MANAGE_WINDOW_SIGNALS_CONNECT(window);
409 g_signal_connect(G_OBJECT(ok_btn), "clicked",
410 G_CALLBACK(prefs_filtering_action_ok), NULL);
411 g_signal_connect(G_OBJECT(cancel_btn), "clicked",
412 G_CALLBACK(prefs_filtering_action_cancel), NULL);
414 vbox1 = gtk_vbox_new(FALSE, VSPACING);
415 gtk_box_pack_start(GTK_BOX(vbox), vbox1, TRUE, TRUE, 0);
416 gtk_container_set_border_width(GTK_CONTAINER (vbox1), 2);
418 frame = gtk_frame_new(_("Rule"));
419 gtk_frame_set_label_align(GTK_FRAME(frame), 0.01, 0.5);
420 gtk_box_pack_start (GTK_BOX (vbox1), frame, FALSE, FALSE, 0);
421 gtk_widget_set_size_request(frame, -1, 110);
423 table = gtk_table_new(3, 3, FALSE);
424 gtk_container_set_border_width(GTK_CONTAINER(table), 2);
425 gtk_table_set_row_spacings (GTK_TABLE (table), VSPACING_NARROW_2);
426 gtk_table_set_col_spacings (GTK_TABLE (table), HSPACING_NARROW);
427 gtk_container_add(GTK_CONTAINER(frame), table);
429 /* first row labels */
431 label1 = gtk_label_new (_("Action"));
432 gtk_widget_set_size_request(label1, LABELS_WIDTH, -1);
433 gtk_size_group_add_widget(size_group, label1);
434 gtk_misc_set_alignment (GTK_MISC (label1), 1, 0.5);
435 gtk_table_attach(GTK_TABLE(table), label1, 0, 1, 0, 1,
436 GTK_FILL, GTK_SHRINK, 0, 0);
438 label2 = gtk_label_new ("");
439 gtk_size_group_add_widget(size_group, label2);
440 gtk_misc_set_alignment (GTK_MISC (label2), 1, 0.5);
441 gtk_table_attach(GTK_TABLE(table), label2, 0, 1, 1, 2,
442 GTK_FILL, GTK_SHRINK, 0, 0);
444 label3 = gtk_label_new ("");
445 gtk_size_group_add_widget(size_group, label3);
446 gtk_misc_set_alignment (GTK_MISC (label3), 1, 0.5);
447 gtk_table_attach(GTK_TABLE(table), label3, 0, 1, 2, 3,
448 GTK_FILL, GTK_SHRINK, 0, 0);
452 hbox1 = gtk_hbox_new(FALSE, 0);
453 gtk_table_attach(GTK_TABLE(table), hbox1, 1, 2, 0, 1,
454 GTK_FILL, GTK_SHRINK, 0, 0);
456 model = prefs_filtering_action_create_model();
457 action_combo = gtk_combo_box_new_with_model(model);
458 gtk_size_group_add_widget(size_action, action_combo);
460 renderer = gtk_cell_renderer_text_new();
461 gtk_cell_layout_pack_start(GTK_CELL_LAYOUT(action_combo), renderer, TRUE);
462 gtk_cell_layout_set_attributes(GTK_CELL_LAYOUT(action_combo), renderer,
463 "text", ACTION_COMBO_TEXT,
464 "sensitive", ACTION_COMBO_SENS,
466 gtk_cell_layout_set_cell_data_func(GTK_CELL_LAYOUT(action_combo), renderer,
467 cell_is_sensitive, NULL, NULL);
469 combobox_select_by_data(GTK_COMBO_BOX(action_combo), ACTION_MOVE);
470 g_signal_connect(G_OBJECT(action_combo), "changed",
471 G_CALLBACK(prefs_filtering_action_type_selection_changed),
473 gtk_box_pack_start(GTK_BOX(hbox1), action_combo, FALSE, FALSE, 0);
474 gtk_box_pack_start(GTK_BOX(hbox1), gtk_label_new(""), TRUE, TRUE, 0);
478 hbox1 = gtk_hbox_new (FALSE, 0);
479 gtk_table_attach(GTK_TABLE(table), hbox1, 1, 2, 1, 2,
480 GTK_FILL | GTK_EXPAND, GTK_SHRINK, 0, 0);
482 account_combo = gtk_combo_box_new_text ();
483 gtk_size_group_add_widget(size_action, account_combo);
485 for (accounts = account_get_list() ; accounts != NULL;
486 accounts = accounts->next) {
487 PrefsAccount *ac = (PrefsAccount *)accounts->data;
488 gchar *name = g_strdup(ac->account_name);
489 gtk_combo_box_append_text(GTK_COMBO_BOX(account_combo), (gpointer) name);
493 prefs_filtering_action_check_widget_width(account_combo);
494 gtk_combo_box_set_active(GTK_COMBO_BOX(account_combo), 0);
495 gtk_box_pack_start (GTK_BOX (hbox1), account_combo,
500 header_combo = combobox_text_new(TRUE, "From", "To", "Cc", "Reply-To", "Sender", NULL);
501 gtk_size_group_add_widget(size_action, header_combo);
502 gtk_box_pack_start (GTK_BOX (hbox1), header_combo,
504 header_entry = gtk_bin_get_child(GTK_BIN((header_combo)));
508 hbox1 = gtk_hbox_new (FALSE, 0);
509 gtk_table_attach(GTK_TABLE(table), hbox1, 1, 2, 2, 3,
510 GTK_FILL | GTK_EXPAND, GTK_SHRINK, 0, 0);
512 dest_entry = gtk_entry_new ();
513 gtk_box_pack_start (GTK_BOX (hbox1), dest_entry, TRUE, TRUE, 0);
515 score_entry = gtk_spin_button_new_with_range(-1000, 1000, 1);
516 gtk_box_pack_start(GTK_BOX(hbox1), score_entry, FALSE, FALSE, 0);
518 #if !GTK_CHECK_VERSION(3, 0, 0)
519 color_optmenu = gtk_cmoption_menu_new();
520 gtk_size_group_add_widget(size_action, color_optmenu);
521 gtk_cmoption_menu_set_menu(GTK_CMOPTION_MENU(color_optmenu),
522 colorlabel_create_color_menu());
523 prefs_filtering_action_check_widget_width(color_optmenu);
524 gtk_box_pack_start(GTK_BOX(hbox1), color_optmenu, FALSE, FALSE, 0);
527 tags_combo = gtk_combo_box_new_text ();
528 gtk_size_group_add_widget(size_action, tags_combo);
530 for (tmp = tags = tags_get_list() ; tmp != NULL;
532 gchar *name = g_strdup(tags_get_tag(GPOINTER_TO_INT(tmp->data)));
534 gtk_combo_box_append_text(GTK_COMBO_BOX(tags_combo), (gpointer) name);
538 prefs_filtering_action_check_widget_width(tags_combo);
539 gtk_combo_box_set_active(GTK_COMBO_BOX(tags_combo), 0);
540 gtk_box_pack_start (GTK_BOX (hbox1), tags_combo,
543 hbox1 = gtk_hbox_new (FALSE, 0);
544 gtk_table_attach(GTK_TABLE(table), hbox1, 2, 3, 2, 3,
545 GTK_FILL, GTK_SHRINK, 0, 0);
547 dest_btn = gtk_button_new_with_label (_("Select ..."));
548 gtk_box_pack_start (GTK_BOX (hbox1), dest_btn, FALSE, FALSE, 0);
549 g_signal_connect (G_OBJECT (dest_btn), "clicked",
550 G_CALLBACK(prefs_filtering_action_select_dest),
553 addressbook_btn = gtk_button_new_with_label (_("Select ..."));
554 gtk_box_pack_start (GTK_BOX (hbox1), addressbook_btn, FALSE, FALSE, 0);
555 #ifndef USE_NEW_ADDRBOOK
556 g_signal_connect (G_OBJECT (addressbook_btn), "clicked",
557 G_CALLBACK(prefs_filtering_action_select_addressbook),
560 gtk_widget_set_sensitive(GTK_WIDGET(addressbook_btn), FALSE);
562 exec_btn = gtk_button_new_from_stock(GTK_STOCK_INFO);
563 gtk_box_pack_start (GTK_BOX (hbox1), exec_btn, FALSE, FALSE, 0);
564 g_signal_connect (G_OBJECT (exec_btn), "clicked",
565 G_CALLBACK(prefs_filtering_action_exec_info),
568 /* register / substitute / delete */
570 reg_hbox = gtk_hbox_new(FALSE, 4);
571 gtk_box_pack_start(GTK_BOX(vbox1), reg_hbox, FALSE, FALSE, 0);
573 arrow = gtk_arrow_new(GTK_ARROW_DOWN, GTK_SHADOW_OUT);
574 gtk_box_pack_start(GTK_BOX(reg_hbox), arrow, FALSE, FALSE, 0);
575 gtk_widget_set_size_request(arrow, -1, 16);
577 btn_hbox = gtk_hbox_new(TRUE, 4);
578 gtk_box_pack_start(GTK_BOX(reg_hbox), btn_hbox, FALSE, FALSE, 0);
580 reg_btn = gtk_button_new_from_stock(GTK_STOCK_ADD);
581 gtk_box_pack_start(GTK_BOX(btn_hbox), reg_btn, FALSE, TRUE, 0);
582 g_signal_connect(G_OBJECT(reg_btn), "clicked",
583 G_CALLBACK(prefs_filtering_action_register_cb), NULL);
585 subst_btn = gtkut_get_replace_btn(_("Replace"));
586 gtk_box_pack_start(GTK_BOX(btn_hbox), subst_btn, FALSE, TRUE, 0);
587 g_signal_connect(G_OBJECT(subst_btn), "clicked",
588 G_CALLBACK(prefs_filtering_action_substitute_cb),
591 del_btn = gtk_button_new_from_stock(GTK_STOCK_DELETE);
592 gtk_box_pack_start(GTK_BOX(btn_hbox), del_btn, FALSE, TRUE, 0);
593 g_signal_connect(G_OBJECT(del_btn), "clicked",
594 G_CALLBACK(prefs_filtering_action_delete_cb), NULL);
596 action_hbox = gtk_hbox_new(FALSE, 8);
597 gtk_box_pack_start(GTK_BOX(vbox1), action_hbox, TRUE, TRUE, 0);
599 action_scrolledwin = gtk_scrolled_window_new(NULL, NULL);
600 gtk_widget_set_size_request(action_scrolledwin, -1, 150);
601 gtk_box_pack_start(GTK_BOX(action_hbox), action_scrolledwin,
603 gtk_scrolled_window_set_shadow_type(GTK_SCROLLED_WINDOW(action_scrolledwin),
604 GTK_SHADOW_ETCHED_IN);
605 gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(action_scrolledwin),
606 GTK_POLICY_AUTOMATIC,
607 GTK_POLICY_AUTOMATIC);
609 action_list_view = prefs_filtering_action_list_view_create();
610 gtk_container_add(GTK_CONTAINER(action_scrolledwin), action_list_view);
612 btn_vbox = gtk_vbox_new(FALSE, 8);
613 gtk_box_pack_start(GTK_BOX(action_hbox), btn_vbox, FALSE, FALSE, 0);
615 up_btn = gtk_button_new_from_stock(GTK_STOCK_GO_UP);
616 gtk_box_pack_start(GTK_BOX(btn_vbox), up_btn, FALSE, FALSE, 0);
617 g_signal_connect(G_OBJECT(up_btn), "clicked",
618 G_CALLBACK(prefs_filtering_action_up), NULL);
620 down_btn = gtk_button_new_from_stock(GTK_STOCK_GO_DOWN);
621 gtk_box_pack_start(GTK_BOX(btn_vbox), down_btn, FALSE, FALSE, 0);
622 g_signal_connect(G_OBJECT(down_btn), "clicked",
623 G_CALLBACK(prefs_filtering_action_down), NULL);
625 if (!geometry.min_height) {
626 geometry.min_width = 490;
627 geometry.min_height = 348;
630 gtk_window_set_geometry_hints(GTK_WINDOW(window), NULL, &geometry,
632 gtk_widget_set_size_request(window, prefs_common.filteringactionwin_width,
633 prefs_common.filteringactionwin_height);
635 gtk_widget_show_all(window);
637 filtering_action.window = window;
638 filtering_action.label1 = label1;
639 filtering_action.label2 = label2;
640 filtering_action.label3 = label3;
641 filtering_action.action_combo = action_combo;
642 filtering_action.account_combo = account_combo;
643 filtering_action.tags_combo = tags_combo;
644 filtering_action.dest_entry = dest_entry;
645 filtering_action.dest_btn = dest_btn;
646 filtering_action.exec_btn = exec_btn;
647 #if !GTK_CHECK_VERSION(3, 0, 0)
648 filtering_action.color_optmenu = color_optmenu;
650 filtering_action.score_entry = score_entry;
651 filtering_action.header_combo = header_combo;
652 filtering_action.header_entry = header_entry;
653 #ifndef USE_NEW_ADDRBOOK
654 filtering_action.addressbook_btn = addressbook_btn;
656 filtering_action.ok_btn = ok_btn;
657 filtering_action.action_list_view = action_list_view;
659 prefs_filtering_action_type_selection_changed(NULL, NULL);
663 *\brief Set the contents of a row
665 *\param row Index of row to set
666 *\param prop Condition to set
669 static void prefs_filtering_action_list_view_set_row(GtkTreeIter *row,
670 FilteringAction *action)
674 if (row == NULL && action == NULL) {
675 prefs_filtering_action_list_view_insert_action
676 (filtering_action.action_list_view,
677 NULL, _("(New)"), FALSE);
681 buf = filteringaction_to_string(action);
683 prefs_filtering_action_list_view_insert_action
684 (filtering_action.action_list_view,
690 *\brief Initializes dialog with a set of conditions
692 *\param matchers List of conditions
694 static void prefs_filtering_action_set_dialog(GSList *action_list)
698 gtk_list_store_clear(GTK_LIST_STORE(gtk_tree_view_get_model
699 (GTK_TREE_VIEW(filtering_action.action_list_view))));
701 prefs_filtering_action_list_view_set_row(NULL, NULL);
702 if (action_list != NULL) {
703 for (cur = action_list; cur != NULL;
704 cur = g_slist_next(cur)) {
705 FilteringAction *action;
706 action = (FilteringAction *) cur->data;
707 prefs_filtering_action_list_view_set_row(NULL, action);
711 prefs_filtering_action_reset_dialog();
713 combobox_set_sensitive(GTK_COMBO_BOX(filtering_action.action_combo), 9,
714 (tags_get_size() > 0) ? TRUE : FALSE);
718 *\brief Converts current actions in list box in
719 * an action list used by the filtering system.
721 *\return GSList * List of actions.
723 static GSList *prefs_filtering_action_get_list(void)
729 GtkTreeView *list_view = GTK_TREE_VIEW(filtering_action.action_list_view);
730 GtkTreeModel *model = gtk_tree_view_get_model(list_view);
735 while (gtk_tree_model_iter_nth_child(model, &iter, NULL, row)) {
737 gtk_tree_model_get(model, &iter,
738 PFA_ACTION, &action_str,
739 PFA_VALID_ACTION, &is_valid,
743 GSList * tmp_action_list;
744 tmp_action_list = matcher_parser_get_action_list(action_str);
746 if (tmp_action_list == NULL) {
751 action_list = g_slist_concat(action_list,
765 *\brief Returns account ID from the given list index
767 *\return gint account ID
769 static gint get_account_id_from_list_id(gint list_id)
773 for (accounts = account_get_list() ; accounts != NULL;
774 accounts = accounts->next) {
775 PrefsAccount *ac = (PrefsAccount *)accounts->data;
778 return ac->account_id;
785 *\brief Returns list index from the given account ID
787 *\return gint list index
789 static gint get_list_id_from_account_id(gint account_id)
794 for (accounts = account_get_list() ; accounts != NULL;
795 accounts = accounts->next) {
796 PrefsAccount *ac = (PrefsAccount *)accounts->data;
798 if (account_id == ac->account_id)
807 *\brief Returns parser action ID from internal action ID
809 *\return gint parser action ID
811 static gint prefs_filtering_action_get_matching_from_action(Action action_id)
815 return MATCHACTION_MOVE;
817 return MATCHACTION_SET_TAG;
818 case ACTION_UNSET_TAG:
819 return MATCHACTION_UNSET_TAG;
820 case ACTION_CLEAR_TAGS:
821 return MATCHACTION_CLEAR_TAGS;
823 return MATCHACTION_COPY;
825 return MATCHACTION_DELETE;
827 return MATCHACTION_MARK;
829 return MATCHACTION_UNMARK;
831 return MATCHACTION_LOCK;
833 return MATCHACTION_UNLOCK;
834 case ACTION_MARK_AS_READ:
835 return MATCHACTION_MARK_AS_READ;
836 case ACTION_MARK_AS_UNREAD:
837 return MATCHACTION_MARK_AS_UNREAD;
838 case ACTION_MARK_AS_SPAM:
839 return MATCHACTION_MARK_AS_SPAM;
840 case ACTION_MARK_AS_HAM:
841 return MATCHACTION_MARK_AS_HAM;
843 return MATCHACTION_FORWARD;
844 case ACTION_FORWARD_AS_ATTACHMENT:
845 return MATCHACTION_FORWARD_AS_ATTACHMENT;
846 case ACTION_REDIRECT:
847 return MATCHACTION_REDIRECT;
849 return MATCHACTION_EXECUTE;
850 #if !GTK_CHECK_VERSION(3, 0, 0)
852 return MATCHACTION_COLOR;
855 return MATCHACTION_HIDE;
857 return MATCHACTION_IGNORE;
859 return MATCHACTION_WATCH;
861 return MATCHACTION_STOP;
862 case ACTION_CHANGE_SCORE:
863 return MATCHACTION_CHANGE_SCORE;
864 case ACTION_SET_SCORE:
865 return MATCHACTION_SET_SCORE;
866 case ACTION_ADD_TO_ADDRESSBOOK:
867 return MATCHACTION_ADD_TO_ADDRESSBOOK;
874 *\brief Returns action from the content of the dialog
876 *\param alert specifies whether alert dialog boxes should be shown
879 *\return FilteringAction * action entered in the dialog box.
881 static FilteringAction * prefs_filtering_action_dialog_to_action(gboolean alert)
887 gchar * destination = NULL;
889 FilteringAction * action;
891 gchar * header = NULL;
893 action_id = combobox_get_active_data(GTK_COMBO_BOX(filtering_action.action_combo));
894 action_type = prefs_filtering_action_get_matching_from_action(action_id);
895 list_id = gtk_combo_box_get_active(GTK_COMBO_BOX(filtering_action.account_combo));
896 account_id = get_account_id_from_list_id(list_id);
904 destination = gtk_editable_get_chars(GTK_EDITABLE(filtering_action.dest_entry), 0, -1);
905 if (*destination == '\0') {
907 alertpanel_error(action_id == ACTION_EXECUTE
908 ? _("Command-line not set")
909 : _("Destination is not set."));
915 case ACTION_FORWARD_AS_ATTACHMENT:
916 case ACTION_REDIRECT:
917 destination = gtk_editable_get_chars(GTK_EDITABLE(filtering_action.dest_entry), 0, -1);
918 if (*destination == '\0') {
920 alertpanel_error(_("Recipient is not set."));
925 #if !GTK_CHECK_VERSION(3, 0, 0)
927 labelcolor = colorlabel_get_color_menu_active_item(
928 gtk_cmoption_menu_get_menu(GTK_CMOPTION_MENU(filtering_action.color_optmenu)));
932 case ACTION_CHANGE_SCORE:
933 case ACTION_SET_SCORE:
934 score = gtk_spin_button_get_value_as_int(GTK_SPIN_BUTTON(
935 filtering_action.score_entry));
936 if (!score && action_id == ACTION_CHANGE_SCORE) {
938 alertpanel_error(_("Score is not set"));
942 case ACTION_ADD_TO_ADDRESSBOOK:
943 header = gtk_editable_get_chars(GTK_EDITABLE(filtering_action.header_entry), 0, -1);
944 if (*header == '\0') {
946 alertpanel_error(_("Header is not set."));
950 destination = gtk_editable_get_chars(GTK_EDITABLE(filtering_action.dest_entry), 0, -1);
951 if (*destination == '\0') {
953 alertpanel_error(_("Target addressbook/folder is not set."));
959 case ACTION_UNSET_TAG:
960 destination = gtk_combo_box_get_active_text(GTK_COMBO_BOX(filtering_action.tags_combo));
961 if (!destination || *destination == '\0') {
963 alertpanel_error(_("Tag name is empty."));
977 case ACTION_MARK_AS_READ:
978 case ACTION_MARK_AS_UNREAD:
979 case ACTION_MARK_AS_SPAM:
980 case ACTION_MARK_AS_HAM:
981 case ACTION_CLEAR_TAGS:
985 action = filteringaction_new(action_type, account_id,
986 destination, labelcolor, score, header);
993 *\brief Signal handler for register button
995 static void prefs_filtering_action_register_cb(void)
997 FilteringAction *action;
999 action = prefs_filtering_action_dialog_to_action(TRUE);
1003 prefs_filtering_action_list_view_set_row(NULL, action);
1005 filteringaction_free(action);
1007 * (presumably gtk_list_select_item(), called by
1008 * prefs_filtering_action_reset_dialog() activates
1009 * what seems to be a bug. this causes any other
1010 * list items to be unselectable)
1011 * prefs_filtering_action_reset_dialog(); */
1012 gtk_combo_box_set_active(GTK_COMBO_BOX(filtering_action.account_combo), 0);
1013 gtk_combo_box_set_active(GTK_COMBO_BOX(filtering_action.tags_combo), 0);
1014 gtk_entry_set_text(GTK_ENTRY(filtering_action.dest_entry), "");
1018 *\brief Signal handler for substitute button
1020 static void prefs_filtering_action_substitute_cb(void)
1022 GtkTreeView *list_view = GTK_TREE_VIEW
1023 (filtering_action.action_list_view);
1024 GtkTreeSelection *selection = gtk_tree_view_get_selection(list_view);
1025 GtkTreeModel *model;
1028 FilteringAction *action;
1030 if (!gtk_tree_selection_get_selected(selection, &model, &row))
1033 gtk_tree_model_get(model, &row, PFA_VALID_ACTION, &is_valid, -1);
1037 action = prefs_filtering_action_dialog_to_action(TRUE);
1041 prefs_filtering_action_list_view_set_row(&row, action);
1043 filteringaction_free(action);
1045 prefs_filtering_action_reset_dialog();
1049 *\brief Signal handler for delete button
1051 static void prefs_filtering_action_delete_cb(void)
1053 GtkTreeView *list_view = GTK_TREE_VIEW
1054 (filtering_action.action_list_view);
1055 GtkTreeSelection *selection = gtk_tree_view_get_selection(list_view);
1056 GtkTreeModel *model;
1060 if (!gtk_tree_selection_get_selected(selection, &model, &row))
1063 gtk_tree_model_get(model, &row, PFA_VALID_ACTION, &is_valid, -1);
1067 gtk_list_store_remove(GTK_LIST_STORE(model), &row);
1069 prefs_filtering_action_reset_dialog();
1073 *\brief Signal handler for 'move up' button
1075 static void prefs_filtering_action_up(void)
1077 GtkTreePath *prev, *sel, *try;
1079 GtkListStore *store = NULL;
1080 GtkTreeModel *model = NULL;
1083 if (!gtk_tree_selection_get_selected
1084 (gtk_tree_view_get_selection
1085 (GTK_TREE_VIEW(filtering_action.action_list_view)),
1089 store = (GtkListStore *)model;
1090 sel = gtk_tree_model_get_path(GTK_TREE_MODEL(store), &isel);
1094 /* no move if we're at row 0 or 1, looks phony, but other
1095 * solutions are more convoluted... */
1096 try = gtk_tree_path_copy(sel);
1097 if (!gtk_tree_path_prev(try) || !gtk_tree_path_prev(try)) {
1098 gtk_tree_path_free(try);
1099 gtk_tree_path_free(sel);
1102 gtk_tree_path_free(try);
1104 prev = gtk_tree_path_copy(sel);
1105 if (gtk_tree_path_prev(prev)) {
1106 gtk_tree_model_get_iter(GTK_TREE_MODEL(store),
1108 gtk_list_store_swap(store, &iprev, &isel);
1109 /* XXX: GTK2 select row?? */
1112 gtk_tree_path_free(sel);
1113 gtk_tree_path_free(prev);
1117 *\brief Signal handler for 'move down' button
1119 static void prefs_filtering_action_down(void)
1121 GtkListStore *store = NULL;
1122 GtkTreeModel *model = NULL;
1123 GtkTreeIter next, sel;
1126 if (!gtk_tree_selection_get_selected
1127 (gtk_tree_view_get_selection
1128 (GTK_TREE_VIEW(filtering_action.action_list_view)),
1132 store = (GtkListStore *)model;
1133 try = gtk_tree_model_get_path(GTK_TREE_MODEL(store), &sel);
1137 /* move when not at row 0 ... */
1138 if (gtk_tree_path_prev(try)) {
1140 if (gtk_tree_model_iter_next(GTK_TREE_MODEL(store), &next))
1141 gtk_list_store_swap(store, &next, &sel);
1144 gtk_tree_path_free(try);
1148 *\brief Handle key press
1150 *\param widget Widget receiving key press
1151 *\param event Key event
1152 *\param data User data
1154 static gboolean prefs_filtering_action_key_pressed(GtkWidget *widget,
1155 GdkEventKey *event, gpointer data)
1157 if (event && event->keyval == GDK_KEY_Escape) {
1158 prefs_filtering_action_cancel();
1165 *\brief Cancel matcher dialog
1167 static void prefs_filtering_action_cancel(void)
1169 gtk_widget_destroy(filtering_action.window);
1170 filtering_action.window = NULL;
1175 *\brief Accept current matchers
1177 static void prefs_filtering_action_ok(void)
1179 GSList * action_list;
1182 action_list = prefs_filtering_action_get_list();
1184 if (action_list == NULL) {
1185 alertpanel_error(_("No action was defined."));
1189 if (filtering_action_callback != NULL)
1190 filtering_action_callback(action_list);
1191 for(cur = action_list ; cur != NULL ; cur = cur->next) {
1192 filteringaction_free(cur->data);
1194 g_slist_free(action_list);
1196 gtk_widget_destroy(filtering_action.window);
1197 filtering_action.window = NULL;
1202 *\brief Called when closing dialog box
1204 *\param widget Dialog widget
1205 *\param event Event info
1206 *\param data User data
1210 static gint prefs_filtering_action_deleted(GtkWidget *widget,
1211 GdkEventAny *event, gpointer data)
1213 prefs_filtering_action_cancel();
1218 * Strings describing exec format strings
1220 * When adding new lines, remember to put 2 strings for each line
1222 static gchar *exec_desc_strings[] = {
1223 "%%", N_("literal %"),
1224 "%s", N_("Subject"),
1229 "%i", N_("Message-ID"),
1230 "%n", N_("Newsgroups"),
1231 "%r", N_("References"),
1232 "%F", N_("filename (should not be modified)"),
1233 "\\n", N_("new line"),
1234 "\\", N_("escape character for quotes"),
1235 "\\\"", N_("quote character"),
1239 static DescriptionWindow exec_desc_win = {
1243 N_("Filtering Action: 'Execute'"),
1244 N_("'Execute' allows you to send a message or message element "
1245 "to an external program or script.\n"
1246 "The following symbols can be used:"),
1251 *\brief Show Execute action's info
1253 static void prefs_filtering_action_exec_info(GtkWidget *widget, GtkWidget *parent)
1255 exec_desc_win.parent = parent;
1256 description_window_create(&exec_desc_win);
1259 static void prefs_filtering_action_select_dest(void)
1264 dest = foldersel_folder_sel(NULL, FOLDER_SEL_COPY, NULL, FALSE);
1267 path = folder_item_get_identifier(dest);
1269 gtk_entry_set_text(GTK_ENTRY(filtering_action.dest_entry), path);
1273 #ifndef USE_NEW_ADDRBOOK
1274 static void prefs_filtering_action_select_addressbook(void)
1276 const gchar *folderpath = NULL;
1277 gchar *new_path = NULL;
1279 folderpath = gtk_entry_get_text(GTK_ENTRY(filtering_action.dest_entry));
1280 new_path = addressbook_folder_selection(folderpath);
1282 gtk_entry_set_text(GTK_ENTRY(filtering_action.dest_entry), new_path);
1288 static void prefs_filtering_action_enable_widget(GtkWidget* widget, const gboolean enable)
1290 cm_return_if_fail(widget != NULL);
1294 #if !GTK_CHECK_VERSION(2,24,0)
1295 if(GTK_IS_COMBO_BOX(widget) || GTK_IS_COMBO_BOX_ENTRY(widget))
1297 if(GTK_IS_COMBO_BOX(widget))
1299 gtk_combo_box_set_active(GTK_COMBO_BOX(widget), 0);
1300 else if(GTK_IS_SPIN_BUTTON(widget))
1301 gtk_spin_button_set_value(GTK_SPIN_BUTTON(widget), 0);
1302 else if(GTK_IS_ENTRY(widget)) {
1303 gtk_entry_set_text(GTK_ENTRY(widget), "");
1304 } else if(GTK_IS_CMOPTION_MENU(widget))
1305 gtk_cmoption_menu_set_history(GTK_CMOPTION_MENU(widget), 0);
1307 gtk_widget_set_sensitive(widget, TRUE);
1308 gtk_widget_show(widget);
1310 gtk_widget_set_sensitive(widget, FALSE);
1311 gtk_widget_hide(widget);
1315 #define ACTION_SEND(x) (x == ACTION_FORWARD || x == ACTION_REDIRECT || \
1316 x == ACTION_FORWARD_AS_ATTACHMENT)
1317 #define ACTION_SCORE(x) (x == ACTION_CHANGE_SCORE || x == ACTION_SET_SCORE)
1318 #define ACTION_TAG(x) (x == ACTION_SET_TAG || x == ACTION_UNSET_TAG)
1319 #define ACTION_FILEOP(x) (x == ACTION_MOVE || x == ACTION_COPY)
1321 static void prefs_filtering_action_type_selection_changed(GtkWidget *combo,
1326 value = combobox_get_active_data(GTK_COMBO_BOX(filtering_action.action_combo));
1328 if (filtering_action.current_action != value) {
1329 if (ACTION_SEND(filtering_action.current_action)) {
1330 debug_print("unregistering address completion entry\n");
1331 address_completion_unregister_entry(GTK_ENTRY(filtering_action.dest_entry));
1332 address_completion_end(filtering_action.window);
1334 if (ACTION_SEND(value)) {
1335 debug_print("registering address completion entry\n");
1336 address_completion_start(filtering_action.window);
1337 address_completion_register_entry(
1338 GTK_ENTRY(filtering_action.dest_entry),
1341 filtering_action.current_action = value;
1344 prefs_filtering_action_enable_widget(filtering_action.label2,
1345 (ACTION_SEND(value) || value == ACTION_ADD_TO_ADDRESSBOOK));
1347 prefs_filtering_action_enable_widget(filtering_action.label3,
1348 (ACTION_SEND(value) || ACTION_TAG(value) ||
1349 ACTION_SCORE(value) || ACTION_FILEOP(value) ||
1350 value == ACTION_COLOR || value == ACTION_EXECUTE ||
1351 value == ACTION_ADD_TO_ADDRESSBOOK));
1353 prefs_filtering_action_enable_widget(filtering_action.account_combo,
1354 ACTION_SEND(value));
1356 prefs_filtering_action_enable_widget(filtering_action.tags_combo,
1359 prefs_filtering_action_enable_widget(filtering_action.dest_entry,
1360 (ACTION_FILEOP(value) || value == ACTION_EXECUTE ||
1361 ACTION_SEND(value) || value == ACTION_ADD_TO_ADDRESSBOOK));
1363 prefs_filtering_action_enable_widget(filtering_action.dest_btn,
1364 ACTION_FILEOP(value));
1366 prefs_filtering_action_enable_widget(filtering_action.exec_btn,
1367 (value == ACTION_EXECUTE));
1369 #if !GTK_CHECK_VERSION(3, 0, 0)
1370 prefs_filtering_action_enable_widget(filtering_action.color_optmenu,
1371 (value == ACTION_COLOR));
1374 prefs_filtering_action_enable_widget(filtering_action.header_combo,
1375 (value == ACTION_ADD_TO_ADDRESSBOOK));
1377 prefs_filtering_action_enable_widget(filtering_action.addressbook_btn,
1378 (value == ACTION_ADD_TO_ADDRESSBOOK));
1380 prefs_filtering_action_enable_widget(filtering_action.score_entry,
1381 ACTION_SCORE(value));
1384 case ACTION_FORWARD:
1385 case ACTION_FORWARD_AS_ATTACHMENT:
1386 case ACTION_REDIRECT:
1387 gtk_label_set_text(GTK_LABEL(filtering_action.label2), _("Account"));
1388 gtk_label_set_text(GTK_LABEL(filtering_action.label3), _("Recipient"));
1390 case ACTION_ADD_TO_ADDRESSBOOK:
1391 gtk_label_set_text(GTK_LABEL(filtering_action.label2), _("Header Name"));
1392 gtk_label_set_text(GTK_LABEL(filtering_action.label3), _("Book/Folder"));
1396 gtk_label_set_text(GTK_LABEL(filtering_action.label3), _("Destination"));
1398 #if !GTK_CHECK_VERSION(3, 0, 0)
1400 gtk_label_set_text(GTK_LABEL(filtering_action.label3), _("Color"));
1403 case ACTION_EXECUTE:
1404 gtk_label_set_text(GTK_LABEL(filtering_action.label3), _("Execute"));
1406 case ACTION_SET_SCORE:
1407 case ACTION_CHANGE_SCORE:
1408 gtk_label_set_text(GTK_LABEL(filtering_action.label3), _("Score"));
1410 case ACTION_SET_TAG:
1411 case ACTION_UNSET_TAG:
1412 gtk_label_set_text(GTK_LABEL(filtering_action.label3), _("Tag"));
1417 static void prefs_filtering_action_reset_dialog(void)
1419 combobox_select_by_data(GTK_COMBO_BOX(filtering_action.action_combo), ACTION_MOVE);
1420 gtk_combo_box_set_active(GTK_COMBO_BOX(filtering_action.account_combo), 0);
1421 gtk_entry_set_text(GTK_ENTRY(filtering_action.dest_entry), "");
1422 gtk_spin_button_set_value(GTK_SPIN_BUTTON(filtering_action.score_entry), 0);
1425 static GtkListStore* prefs_filtering_action_create_data_store(void)
1427 return gtk_list_store_new(N_PFA_COLUMNS,
1433 static void prefs_filtering_action_list_view_insert_action(GtkWidget *list_view,
1435 const gchar *action,
1438 GtkListStore *store = GTK_LIST_STORE(gtk_tree_view_get_model
1439 (GTK_TREE_VIEW(list_view)));
1443 /* see if row exists, if not append */
1445 gtk_list_store_append(store, &iter);
1449 gtk_list_store_set(store, &iter,
1451 PFA_VALID_ACTION, is_valid,
1455 static GtkWidget *prefs_filtering_action_list_view_create(void)
1457 GtkTreeView *list_view;
1458 GtkTreeModel *model;
1459 GtkTreeSelection *selector;
1461 model = GTK_TREE_MODEL(prefs_filtering_action_create_data_store());
1462 list_view = GTK_TREE_VIEW(gtk_tree_view_new_with_model(model));
1463 g_object_unref(model);
1465 gtk_tree_view_set_rules_hint(list_view, prefs_common.use_stripes_everywhere);
1466 gtk_tree_view_set_reorderable(list_view, TRUE);
1468 selector = gtk_tree_view_get_selection(list_view);
1469 gtk_tree_selection_set_mode(selector, GTK_SELECTION_BROWSE);
1470 gtk_tree_selection_set_select_function
1471 (selector, prefs_filtering_actions_selected, NULL, NULL);
1473 /* create the columns */
1474 prefs_filtering_action_create_list_view_columns(list_view);
1476 return GTK_WIDGET(list_view);
1479 static void prefs_filtering_action_create_list_view_columns(GtkTreeView *list_view)
1481 GtkTreeViewColumn *column;
1482 GtkCellRenderer *renderer;
1484 renderer = gtk_cell_renderer_text_new();
1485 column = gtk_tree_view_column_new_with_attributes
1486 (_("Current action list"),
1490 gtk_tree_view_append_column(list_view, column);
1493 static gboolean prefs_filtering_actions_selected
1494 (GtkTreeSelection *selector,
1495 GtkTreeModel *model,
1497 gboolean currently_selected,
1501 FilteringAction *action;
1502 GSList * action_list;
1508 if (currently_selected)
1511 if (!gtk_tree_model_get_iter(model, &iter, path))
1514 gtk_tree_model_get(model, &iter,
1515 PFA_VALID_ACTION, &is_valid,
1519 prefs_filtering_action_reset_dialog();
1523 gtk_tree_model_get(model, &iter,
1524 PFA_ACTION, &action_str,
1527 action_list = matcher_parser_get_action_list(action_str);
1530 if (action_list == NULL)
1533 action = action_list->data;
1534 g_slist_free(action_list);
1536 switch(action->type) {
1537 case MATCHACTION_MOVE:
1538 combobox_select_by_data(GTK_COMBO_BOX(filtering_action.action_combo),
1541 case MATCHACTION_COPY:
1542 combobox_select_by_data(GTK_COMBO_BOX(filtering_action.action_combo),
1545 case MATCHACTION_DELETE:
1546 combobox_select_by_data(GTK_COMBO_BOX(filtering_action.action_combo),
1549 case MATCHACTION_MARK:
1550 combobox_select_by_data(GTK_COMBO_BOX(filtering_action.action_combo),
1553 case MATCHACTION_UNMARK:
1554 combobox_select_by_data(GTK_COMBO_BOX(filtering_action.action_combo),
1557 case MATCHACTION_LOCK:
1558 combobox_select_by_data(GTK_COMBO_BOX(filtering_action.action_combo),
1561 case MATCHACTION_UNLOCK:
1562 combobox_select_by_data(GTK_COMBO_BOX(filtering_action.action_combo),
1565 case MATCHACTION_MARK_AS_READ:
1566 combobox_select_by_data(GTK_COMBO_BOX(filtering_action.action_combo),
1567 ACTION_MARK_AS_READ);
1569 case MATCHACTION_MARK_AS_UNREAD:
1570 combobox_select_by_data(GTK_COMBO_BOX(filtering_action.action_combo),
1571 ACTION_MARK_AS_UNREAD);
1573 case MATCHACTION_MARK_AS_SPAM:
1574 combobox_select_by_data(GTK_COMBO_BOX(filtering_action.action_combo),
1575 ACTION_MARK_AS_SPAM);
1577 case MATCHACTION_MARK_AS_HAM:
1578 combobox_select_by_data(GTK_COMBO_BOX(filtering_action.action_combo),
1579 ACTION_MARK_AS_HAM);
1581 case MATCHACTION_FORWARD:
1582 list_id = get_list_id_from_account_id(action->account_id);
1583 combobox_select_by_data(GTK_COMBO_BOX(filtering_action.action_combo),
1585 gtk_combo_box_set_active(GTK_COMBO_BOX(filtering_action.account_combo),
1588 case MATCHACTION_FORWARD_AS_ATTACHMENT:
1589 list_id = get_list_id_from_account_id(action->account_id);
1590 combobox_select_by_data(GTK_COMBO_BOX(filtering_action.action_combo),
1591 ACTION_FORWARD_AS_ATTACHMENT);
1592 gtk_combo_box_set_active(GTK_COMBO_BOX(filtering_action.account_combo),
1595 case MATCHACTION_REDIRECT:
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_EXECUTE:
1603 combobox_select_by_data(GTK_COMBO_BOX(filtering_action.action_combo),
1606 #if !GTK_CHECK_VERSION(3, 0, 0)
1607 case MATCHACTION_COLOR:
1608 combobox_select_by_data(GTK_COMBO_BOX(filtering_action.action_combo),
1610 gtk_cmoption_menu_set_history(GTK_CMOPTION_MENU(filtering_action.color_optmenu),
1611 action->labelcolor + 1);
1612 menu = gtk_cmoption_menu_get_menu(GTK_CMOPTION_MENU(
1613 filtering_action.color_optmenu));
1614 g_signal_emit_by_name(G_OBJECT(menu), "selection-done", menu);
1617 case MATCHACTION_CHANGE_SCORE:
1618 combobox_select_by_data(GTK_COMBO_BOX(filtering_action.action_combo),
1619 ACTION_CHANGE_SCORE);
1620 gtk_spin_button_set_value(GTK_SPIN_BUTTON(filtering_action.score_entry),
1623 case MATCHACTION_SET_SCORE:
1624 combobox_select_by_data(GTK_COMBO_BOX(filtering_action.action_combo),
1626 gtk_spin_button_set_value(GTK_SPIN_BUTTON(filtering_action.score_entry),
1629 case MATCHACTION_STOP:
1630 combobox_select_by_data(GTK_COMBO_BOX(filtering_action.action_combo),
1633 case MATCHACTION_HIDE:
1634 combobox_select_by_data(GTK_COMBO_BOX(filtering_action.action_combo),
1637 case MATCHACTION_IGNORE:
1638 combobox_select_by_data(GTK_COMBO_BOX(filtering_action.action_combo),
1641 case MATCHACTION_WATCH:
1642 combobox_select_by_data(GTK_COMBO_BOX(filtering_action.action_combo),
1645 case MATCHACTION_ADD_TO_ADDRESSBOOK:
1647 gtk_entry_set_text(GTK_ENTRY(filtering_action.header_entry), action->header);
1649 gtk_entry_set_text(GTK_ENTRY(filtering_action.header_entry), "");
1650 combobox_select_by_data(GTK_COMBO_BOX(filtering_action.action_combo),
1651 ACTION_ADD_TO_ADDRESSBOOK);
1653 case MATCHACTION_SET_TAG:
1654 combobox_select_by_data(GTK_COMBO_BOX(filtering_action.action_combo),
1656 combobox_select_by_text(GTK_COMBO_BOX(filtering_action.tags_combo),
1657 action->destination);
1659 case MATCHACTION_UNSET_TAG:
1660 combobox_select_by_data(GTK_COMBO_BOX(filtering_action.action_combo),
1662 combobox_select_by_text(GTK_COMBO_BOX(filtering_action.tags_combo),
1663 action->destination);
1665 case MATCHACTION_CLEAR_TAGS:
1666 combobox_select_by_data(GTK_COMBO_BOX(filtering_action.action_combo),
1670 g_warning("unhandled case !\n");
1672 if (action->destination)
1673 gtk_entry_set_text(GTK_ENTRY(filtering_action.dest_entry), action->destination);
1675 gtk_entry_set_text(GTK_ENTRY(filtering_action.dest_entry), "");
1677 filteringaction_free(action); /* XXX: memleak */