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 #ifndef USE_NEW_ADDRBOOK
126 GtkWidget *addressbook_btn;
128 GtkWidget *score_entry;
129 GtkWidget *tags_combo;
135 typedef enum Action_ {
144 ACTION_MARK_AS_UNREAD,
148 ACTION_FORWARD_AS_ATTACHMENT,
160 ACTION_ADD_TO_ADDRESSBOOK,
162 /* add other action constants */
170 { NULL, N_("Move"), ACTION_MOVE },
171 { NULL, N_("Copy"), ACTION_COPY },
172 { NULL, N_("Delete"), ACTION_DELETE },
173 { NULL, N_("Hide"), ACTION_HIDE },
174 { N_("Message flags"), N_("Mark"), ACTION_MARK },
175 { N_("Message flags"), N_("Unmark"), ACTION_UNMARK },
176 { N_("Message flags"), N_("Lock"), ACTION_LOCK },
177 { N_("Message flags"), N_("Unlock"), ACTION_UNLOCK },
178 { N_("Message flags"), N_("Mark as read"), ACTION_MARK_AS_READ },
179 { N_("Message flags"), N_("Mark as unread"), ACTION_MARK_AS_UNREAD },
180 { N_("Message flags"), N_("Mark as spam"), ACTION_MARK_AS_SPAM },
181 { N_("Message flags"), N_("Mark as ham"), ACTION_MARK_AS_HAM },
182 { NULL, N_("Execute"), ACTION_EXECUTE },
183 #if !GTK_CHECK_VERSION(3, 0, 0)
184 { NULL, N_("Color label"), ACTION_COLOR },
186 { N_("Resend"), N_("Forward"), ACTION_FORWARD },
187 { N_("Resend"), N_("Forward as attachment"), ACTION_FORWARD_AS_ATTACHMENT },
188 { N_("Resend"), N_("Redirect"), ACTION_REDIRECT },
189 { N_("Score"), N_("Change score"), ACTION_CHANGE_SCORE },
190 { N_("Score"), N_("Set score"), ACTION_SET_SCORE },
191 { N_("Tags"), N_("Apply tag"), ACTION_SET_TAG },
192 { N_("Tags"), N_("Unset tag"), ACTION_UNSET_TAG },
193 { N_("Tags"), N_("Clear tags"), ACTION_CLEAR_TAGS },
194 { N_("Threads"), N_("Ignore thread"), ACTION_IGNORE },
195 { N_("Threads"), N_("Watch thread"), ACTION_WATCH },
196 { NULL, N_("Add to address book"), ACTION_ADD_TO_ADDRESSBOOK },
197 { NULL, N_("Stop filter"), ACTION_STOP },
211 static PrefsFilteringActionSignal *filtering_action_callback;
213 static GtkTreeModel *prefs_filtering_action_create_model(void)
215 GtkTreeIter iter, iter2;
217 gchar *curr_menu = NULL;
220 store = gtk_tree_store_new(N_ACTION_COMBO, G_TYPE_STRING, G_TYPE_INT,
223 for (i = 0; action_menu[i].menu || action_menu[i].text; i++)
225 if (action_menu[i].menu) {
226 if (!curr_menu || strcmp(action_menu[i].menu, curr_menu)) {
227 gtk_tree_store_append(store, &iter, NULL);
228 gtk_tree_store_set(store, &iter,
230 gettext(action_menu[i].menu),
231 ACTION_COMBO_SENS, TRUE,
233 curr_menu = action_menu[i].menu;
236 gtk_tree_store_append(store, &iter2, &iter);
237 gtk_tree_store_set(store, &iter2,
238 ACTION_COMBO_TEXT, gettext(action_menu[i].text),
239 ACTION_COMBO_DATA, action_menu[i].action,
240 ACTION_COMBO_SENS, TRUE,
245 gtk_tree_store_append(store, &iter, NULL);
246 gtk_tree_store_set(store, &iter,
247 ACTION_COMBO_TEXT, gettext(action_menu[i].text),
248 ACTION_COMBO_DATA, action_menu[i].action,
249 ACTION_COMBO_SENS, TRUE,
254 return GTK_TREE_MODEL(store);
257 static void cell_is_sensitive(GtkCellLayout *cell_layout,
258 GtkCellRenderer *cell,
259 GtkTreeModel *tree_model,
263 if(gtk_tree_model_iter_has_child (tree_model, iter)) {
264 g_object_set (cell, "sensitive", FALSE, NULL);
269 *\brief Opens the filtering action dialog with a list of actions
271 *\param matchers List of conditions
275 void prefs_filtering_action_open(GSList *action_list,
276 PrefsFilteringActionSignal *cb)
280 if (!filtering_action.window) {
281 prefs_filtering_action_create();
283 #if !GTK_CHECK_VERSION(3, 0, 0)
284 /* update color label menu */
285 gtk_cmoption_menu_set_menu(GTK_CMOPTION_MENU(filtering_action.color_optmenu),
286 colorlabel_create_color_menu());
290 manage_window_set_transient(GTK_WINDOW(filtering_action.window));
291 gtk_widget_grab_focus(filtering_action.ok_btn);
293 filtering_action_callback = cb;
295 prefs_filtering_action_set_dialog(action_list);
297 gtk_widget_show(filtering_action.window);
301 *\brief Save Gtk object size to prefs dataset
303 static void prefs_filtering_action_size_allocate_cb(GtkWidget *widget,
304 GtkAllocation *allocation)
306 cm_return_if_fail(allocation != NULL);
308 prefs_common.filteringactionwin_width = allocation->width;
309 prefs_common.filteringactionwin_height = allocation->height;
312 #define LABELS_WIDTH 80
313 #define SECOND_ROW_WIDTH 250
315 static void prefs_filtering_action_check_widget_width(GtkWidget *widget)
319 gtk_widget_size_request(widget, &req);
320 if(req.width > SECOND_ROW_WIDTH)
321 gtk_widget_set_size_request(widget, SECOND_ROW_WIDTH, -1);
325 *\brief Create the matcher dialog
327 static void prefs_filtering_action_create(void)
332 GtkWidget *cancel_btn;
333 GtkWidget *confirm_area;
343 GtkWidget *action_combo;
344 GtkWidget *account_combo;
345 GtkWidget *header_combo;
346 GtkWidget *header_entry;
347 #ifndef USE_NEW_ADDRBOOK
348 GtkWidget *addressbook_btn;
350 GtkWidget *dest_entry;
352 GtkWidget *score_entry;
353 GtkWidget *tags_combo;
359 GtkWidget *subst_btn;
362 GtkWidget *action_hbox;
363 GtkWidget *action_scrolledwin;
364 GtkWidget *action_list_view;
372 #if !GTK_CHECK_VERSION(3, 0, 0)
373 GtkWidget *color_optmenu;
376 static GdkGeometry geometry;
381 GtkSizeGroup *size_group = gtk_size_group_new(GTK_SIZE_GROUP_HORIZONTAL);
382 GtkSizeGroup *size_action = gtk_size_group_new(GTK_SIZE_GROUP_HORIZONTAL);
384 GtkCellRenderer *renderer;
386 debug_print("Creating matcher configuration window...\n");
388 window = gtkut_window_new(GTK_WINDOW_TOPLEVEL, "prefs_filtering_action");
389 gtk_container_set_border_width(GTK_CONTAINER(window), VBOX_BORDER);
390 gtk_window_set_position(GTK_WINDOW(window), GTK_WIN_POS_CENTER);
391 gtk_window_set_modal(GTK_WINDOW(window), TRUE);
392 gtk_window_set_resizable(GTK_WINDOW(window), TRUE);
394 vbox = gtk_vbox_new(FALSE, 6);
395 gtk_container_add(GTK_CONTAINER(window), vbox);
397 gtkut_stock_button_set_create(&confirm_area,
398 &cancel_btn, GTK_STOCK_CANCEL,
399 &ok_btn, GTK_STOCK_OK,
401 gtk_box_pack_end(GTK_BOX(vbox), confirm_area, FALSE, FALSE, 0);
402 gtk_widget_grab_default(ok_btn);
404 gtk_window_set_title(GTK_WINDOW(window),
405 _("Action configuration"));
406 g_signal_connect(G_OBJECT(window), "delete_event",
407 G_CALLBACK(prefs_filtering_action_deleted), NULL);
408 g_signal_connect(G_OBJECT(window), "size_allocate",
409 G_CALLBACK(prefs_filtering_action_size_allocate_cb), NULL);
410 g_signal_connect(G_OBJECT(window), "key_press_event",
411 G_CALLBACK(prefs_filtering_action_key_pressed), NULL);
412 MANAGE_WINDOW_SIGNALS_CONNECT(window);
413 g_signal_connect(G_OBJECT(ok_btn), "clicked",
414 G_CALLBACK(prefs_filtering_action_ok), NULL);
415 g_signal_connect(G_OBJECT(cancel_btn), "clicked",
416 G_CALLBACK(prefs_filtering_action_cancel), NULL);
418 vbox1 = gtk_vbox_new(FALSE, VSPACING);
419 gtk_box_pack_start(GTK_BOX(vbox), vbox1, TRUE, TRUE, 0);
420 gtk_container_set_border_width(GTK_CONTAINER (vbox1), 2);
422 frame = gtk_frame_new(_("Rule"));
423 gtk_frame_set_label_align(GTK_FRAME(frame), 0.01, 0.5);
424 gtk_box_pack_start (GTK_BOX (vbox1), frame, FALSE, FALSE, 0);
425 gtk_widget_set_size_request(frame, -1, 110);
427 table = gtk_table_new(3, 3, FALSE);
428 gtk_container_set_border_width(GTK_CONTAINER(table), 2);
429 gtk_table_set_row_spacings (GTK_TABLE (table), VSPACING_NARROW_2);
430 gtk_table_set_col_spacings (GTK_TABLE (table), HSPACING_NARROW);
431 gtk_container_add(GTK_CONTAINER(frame), table);
433 /* first row labels */
435 label1 = gtk_label_new (_("Action"));
436 gtk_widget_set_size_request(label1, LABELS_WIDTH, -1);
437 gtk_size_group_add_widget(size_group, label1);
438 gtk_misc_set_alignment (GTK_MISC (label1), 1, 0.5);
439 gtk_table_attach(GTK_TABLE(table), label1, 0, 1, 0, 1,
440 GTK_FILL, GTK_SHRINK, 0, 0);
442 label2 = gtk_label_new ("");
443 gtk_size_group_add_widget(size_group, label2);
444 gtk_misc_set_alignment (GTK_MISC (label2), 1, 0.5);
445 gtk_table_attach(GTK_TABLE(table), label2, 0, 1, 1, 2,
446 GTK_FILL, GTK_SHRINK, 0, 0);
448 label3 = gtk_label_new ("");
449 gtk_size_group_add_widget(size_group, label3);
450 gtk_misc_set_alignment (GTK_MISC (label3), 1, 0.5);
451 gtk_table_attach(GTK_TABLE(table), label3, 0, 1, 2, 3,
452 GTK_FILL, GTK_SHRINK, 0, 0);
456 hbox1 = gtk_hbox_new(FALSE, 0);
457 gtk_table_attach(GTK_TABLE(table), hbox1, 1, 2, 0, 1,
458 GTK_FILL, GTK_SHRINK, 0, 0);
460 model = prefs_filtering_action_create_model();
461 action_combo = gtk_combo_box_new_with_model(model);
462 gtk_size_group_add_widget(size_action, action_combo);
464 renderer = gtk_cell_renderer_text_new();
465 gtk_cell_layout_pack_start(GTK_CELL_LAYOUT(action_combo), renderer, TRUE);
466 gtk_cell_layout_set_attributes(GTK_CELL_LAYOUT(action_combo), renderer,
467 "text", ACTION_COMBO_TEXT,
468 "sensitive", ACTION_COMBO_SENS,
470 gtk_cell_layout_set_cell_data_func(GTK_CELL_LAYOUT(action_combo), renderer,
471 cell_is_sensitive, NULL, NULL);
473 combobox_select_by_data(GTK_COMBO_BOX(action_combo), ACTION_MOVE);
474 g_signal_connect(G_OBJECT(action_combo), "changed",
475 G_CALLBACK(prefs_filtering_action_type_selection_changed),
477 gtk_box_pack_start(GTK_BOX(hbox1), action_combo, FALSE, FALSE, 0);
478 gtk_box_pack_start(GTK_BOX(hbox1), gtk_label_new(""), TRUE, TRUE, 0);
482 hbox1 = gtk_hbox_new (FALSE, 0);
483 gtk_table_attach(GTK_TABLE(table), hbox1, 1, 2, 1, 2,
484 GTK_FILL | GTK_EXPAND, GTK_SHRINK, 0, 0);
486 account_combo = gtk_combo_box_new_text ();
487 gtk_size_group_add_widget(size_action, account_combo);
489 for (accounts = account_get_list() ; accounts != NULL;
490 accounts = accounts->next) {
491 PrefsAccount *ac = (PrefsAccount *)accounts->data;
492 gchar *name = g_strdup(ac->account_name);
493 gtk_combo_box_append_text(GTK_COMBO_BOX(account_combo), (gpointer) name);
497 prefs_filtering_action_check_widget_width(account_combo);
498 gtk_combo_box_set_active(GTK_COMBO_BOX(account_combo), 0);
499 gtk_box_pack_start (GTK_BOX (hbox1), account_combo,
504 header_combo = combobox_text_new(TRUE, "From", "To", "Cc", "Reply-To", "Sender", NULL);
505 gtk_size_group_add_widget(size_action, header_combo);
506 gtk_box_pack_start (GTK_BOX (hbox1), header_combo,
508 header_entry = gtk_bin_get_child(GTK_BIN((header_combo)));
512 hbox1 = gtk_hbox_new (FALSE, 0);
513 gtk_table_attach(GTK_TABLE(table), hbox1, 1, 2, 2, 3,
514 GTK_FILL | GTK_EXPAND, GTK_SHRINK, 0, 0);
516 dest_entry = gtk_entry_new ();
517 gtk_box_pack_start (GTK_BOX (hbox1), dest_entry, TRUE, TRUE, 0);
519 score_entry = gtk_spin_button_new_with_range(-1000, 1000, 1);
520 gtk_box_pack_start(GTK_BOX(hbox1), score_entry, FALSE, FALSE, 0);
522 #if !GTK_CHECK_VERSION(3, 0, 0)
523 color_optmenu = gtk_cmoption_menu_new();
524 gtk_size_group_add_widget(size_action, color_optmenu);
525 gtk_cmoption_menu_set_menu(GTK_CMOPTION_MENU(color_optmenu),
526 colorlabel_create_color_menu());
527 prefs_filtering_action_check_widget_width(color_optmenu);
528 gtk_box_pack_start(GTK_BOX(hbox1), color_optmenu, FALSE, FALSE, 0);
531 tags_combo = gtk_combo_box_new_text ();
532 gtk_size_group_add_widget(size_action, tags_combo);
534 for (tmp = tags = tags_get_list() ; tmp != NULL;
536 gchar *name = g_strdup(tags_get_tag(GPOINTER_TO_INT(tmp->data)));
538 gtk_combo_box_append_text(GTK_COMBO_BOX(tags_combo), (gpointer) name);
542 prefs_filtering_action_check_widget_width(tags_combo);
543 gtk_combo_box_set_active(GTK_COMBO_BOX(tags_combo), 0);
544 gtk_box_pack_start (GTK_BOX (hbox1), tags_combo,
547 hbox1 = gtk_hbox_new (FALSE, 0);
548 gtk_table_attach(GTK_TABLE(table), hbox1, 2, 3, 2, 3,
549 GTK_FILL, GTK_SHRINK, 0, 0);
551 dest_btn = gtk_button_new_with_label (_("Select ..."));
552 gtk_box_pack_start (GTK_BOX (hbox1), dest_btn, FALSE, FALSE, 0);
553 g_signal_connect (G_OBJECT (dest_btn), "clicked",
554 G_CALLBACK(prefs_filtering_action_select_dest),
557 #ifndef USE_NEW_ADDRBOOK
558 addressbook_btn = gtk_button_new_with_label (_("Select ..."));
559 gtk_box_pack_start (GTK_BOX (hbox1), addressbook_btn, FALSE, FALSE, 0);
560 g_signal_connect (G_OBJECT (addressbook_btn), "clicked",
561 G_CALLBACK(prefs_filtering_action_select_addressbook),
565 exec_btn = gtk_button_new_from_stock(GTK_STOCK_INFO);
566 gtk_box_pack_start (GTK_BOX (hbox1), exec_btn, FALSE, FALSE, 0);
567 g_signal_connect (G_OBJECT (exec_btn), "clicked",
568 G_CALLBACK(prefs_filtering_action_exec_info),
571 /* register / substitute / delete */
573 reg_hbox = gtk_hbox_new(FALSE, 4);
574 gtk_box_pack_start(GTK_BOX(vbox1), reg_hbox, FALSE, FALSE, 0);
576 arrow = gtk_arrow_new(GTK_ARROW_DOWN, GTK_SHADOW_OUT);
577 gtk_box_pack_start(GTK_BOX(reg_hbox), arrow, FALSE, FALSE, 0);
578 gtk_widget_set_size_request(arrow, -1, 16);
580 btn_hbox = gtk_hbox_new(TRUE, 4);
581 gtk_box_pack_start(GTK_BOX(reg_hbox), btn_hbox, FALSE, FALSE, 0);
583 reg_btn = gtk_button_new_from_stock(GTK_STOCK_ADD);
584 gtk_box_pack_start(GTK_BOX(btn_hbox), reg_btn, FALSE, TRUE, 0);
585 g_signal_connect(G_OBJECT(reg_btn), "clicked",
586 G_CALLBACK(prefs_filtering_action_register_cb), NULL);
588 subst_btn = gtkut_get_replace_btn(_("Replace"));
589 gtk_box_pack_start(GTK_BOX(btn_hbox), subst_btn, FALSE, TRUE, 0);
590 g_signal_connect(G_OBJECT(subst_btn), "clicked",
591 G_CALLBACK(prefs_filtering_action_substitute_cb),
594 del_btn = gtk_button_new_from_stock(GTK_STOCK_DELETE);
595 gtk_box_pack_start(GTK_BOX(btn_hbox), del_btn, FALSE, TRUE, 0);
596 g_signal_connect(G_OBJECT(del_btn), "clicked",
597 G_CALLBACK(prefs_filtering_action_delete_cb), NULL);
599 action_hbox = gtk_hbox_new(FALSE, 8);
600 gtk_box_pack_start(GTK_BOX(vbox1), action_hbox, TRUE, TRUE, 0);
602 action_scrolledwin = gtk_scrolled_window_new(NULL, NULL);
603 gtk_widget_set_size_request(action_scrolledwin, -1, 150);
604 gtk_box_pack_start(GTK_BOX(action_hbox), action_scrolledwin,
606 gtk_scrolled_window_set_shadow_type(GTK_SCROLLED_WINDOW(action_scrolledwin),
607 GTK_SHADOW_ETCHED_IN);
608 gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(action_scrolledwin),
609 GTK_POLICY_AUTOMATIC,
610 GTK_POLICY_AUTOMATIC);
612 action_list_view = prefs_filtering_action_list_view_create();
613 gtk_container_add(GTK_CONTAINER(action_scrolledwin), action_list_view);
615 btn_vbox = gtk_vbox_new(FALSE, 8);
616 gtk_box_pack_start(GTK_BOX(action_hbox), btn_vbox, FALSE, FALSE, 0);
618 up_btn = gtk_button_new_from_stock(GTK_STOCK_GO_UP);
619 gtk_box_pack_start(GTK_BOX(btn_vbox), up_btn, FALSE, FALSE, 0);
620 g_signal_connect(G_OBJECT(up_btn), "clicked",
621 G_CALLBACK(prefs_filtering_action_up), NULL);
623 down_btn = gtk_button_new_from_stock(GTK_STOCK_GO_DOWN);
624 gtk_box_pack_start(GTK_BOX(btn_vbox), down_btn, FALSE, FALSE, 0);
625 g_signal_connect(G_OBJECT(down_btn), "clicked",
626 G_CALLBACK(prefs_filtering_action_down), NULL);
628 if (!geometry.min_height) {
629 geometry.min_width = 490;
630 geometry.min_height = 348;
633 gtk_window_set_geometry_hints(GTK_WINDOW(window), NULL, &geometry,
635 gtk_widget_set_size_request(window, prefs_common.filteringactionwin_width,
636 prefs_common.filteringactionwin_height);
638 gtk_widget_show_all(window);
640 filtering_action.window = window;
641 filtering_action.label1 = label1;
642 filtering_action.label2 = label2;
643 filtering_action.label3 = label3;
644 filtering_action.action_combo = action_combo;
645 filtering_action.account_combo = account_combo;
646 filtering_action.tags_combo = tags_combo;
647 filtering_action.dest_entry = dest_entry;
648 filtering_action.dest_btn = dest_btn;
649 filtering_action.exec_btn = exec_btn;
650 #if !GTK_CHECK_VERSION(3, 0, 0)
651 filtering_action.color_optmenu = color_optmenu;
653 filtering_action.score_entry = score_entry;
654 filtering_action.header_combo = header_combo;
655 filtering_action.header_entry = header_entry;
656 #ifndef USE_NEW_ADDRBOOK
657 filtering_action.addressbook_btn = addressbook_btn;
659 filtering_action.ok_btn = ok_btn;
660 filtering_action.action_list_view = action_list_view;
662 prefs_filtering_action_type_selection_changed(NULL, NULL);
666 *\brief Set the contents of a row
668 *\param row Index of row to set
669 *\param prop Condition to set
672 static void prefs_filtering_action_list_view_set_row(GtkTreeIter *row,
673 FilteringAction *action)
677 if (row == NULL && action == NULL) {
678 prefs_filtering_action_list_view_insert_action
679 (filtering_action.action_list_view,
680 NULL, _("(New)"), FALSE);
684 buf = filteringaction_to_string(action);
686 prefs_filtering_action_list_view_insert_action
687 (filtering_action.action_list_view,
693 *\brief Initializes dialog with a set of conditions
695 *\param matchers List of conditions
697 static void prefs_filtering_action_set_dialog(GSList *action_list)
701 gtk_list_store_clear(GTK_LIST_STORE(gtk_tree_view_get_model
702 (GTK_TREE_VIEW(filtering_action.action_list_view))));
704 prefs_filtering_action_list_view_set_row(NULL, NULL);
705 if (action_list != NULL) {
706 for (cur = action_list; cur != NULL;
707 cur = g_slist_next(cur)) {
708 FilteringAction *action;
709 action = (FilteringAction *) cur->data;
710 prefs_filtering_action_list_view_set_row(NULL, action);
714 prefs_filtering_action_reset_dialog();
716 combobox_set_sensitive(GTK_COMBO_BOX(filtering_action.action_combo), 9,
717 (tags_get_size() > 0) ? TRUE : FALSE);
721 *\brief Converts current actions in list box in
722 * an action list used by the filtering system.
724 *\return GSList * List of actions.
726 static GSList *prefs_filtering_action_get_list(void)
732 GtkTreeView *list_view = GTK_TREE_VIEW(filtering_action.action_list_view);
733 GtkTreeModel *model = gtk_tree_view_get_model(list_view);
738 while (gtk_tree_model_iter_nth_child(model, &iter, NULL, row)) {
740 gtk_tree_model_get(model, &iter,
741 PFA_ACTION, &action_str,
742 PFA_VALID_ACTION, &is_valid,
746 GSList * tmp_action_list;
747 tmp_action_list = matcher_parser_get_action_list(action_str);
749 if (tmp_action_list == NULL) {
754 action_list = g_slist_concat(action_list,
768 *\brief Returns account ID from the given list index
770 *\return gint account ID
772 static gint get_account_id_from_list_id(gint list_id)
776 for (accounts = account_get_list() ; accounts != NULL;
777 accounts = accounts->next) {
778 PrefsAccount *ac = (PrefsAccount *)accounts->data;
781 return ac->account_id;
788 *\brief Returns list index from the given account ID
790 *\return gint list index
792 static gint get_list_id_from_account_id(gint account_id)
797 for (accounts = account_get_list() ; accounts != NULL;
798 accounts = accounts->next) {
799 PrefsAccount *ac = (PrefsAccount *)accounts->data;
801 if (account_id == ac->account_id)
810 *\brief Returns parser action ID from internal action ID
812 *\return gint parser action ID
814 static gint prefs_filtering_action_get_matching_from_action(Action action_id)
818 return MATCHACTION_MOVE;
820 return MATCHACTION_SET_TAG;
821 case ACTION_UNSET_TAG:
822 return MATCHACTION_UNSET_TAG;
823 case ACTION_CLEAR_TAGS:
824 return MATCHACTION_CLEAR_TAGS;
826 return MATCHACTION_COPY;
828 return MATCHACTION_DELETE;
830 return MATCHACTION_MARK;
832 return MATCHACTION_UNMARK;
834 return MATCHACTION_LOCK;
836 return MATCHACTION_UNLOCK;
837 case ACTION_MARK_AS_READ:
838 return MATCHACTION_MARK_AS_READ;
839 case ACTION_MARK_AS_UNREAD:
840 return MATCHACTION_MARK_AS_UNREAD;
841 case ACTION_MARK_AS_SPAM:
842 return MATCHACTION_MARK_AS_SPAM;
843 case ACTION_MARK_AS_HAM:
844 return MATCHACTION_MARK_AS_HAM;
846 return MATCHACTION_FORWARD;
847 case ACTION_FORWARD_AS_ATTACHMENT:
848 return MATCHACTION_FORWARD_AS_ATTACHMENT;
849 case ACTION_REDIRECT:
850 return MATCHACTION_REDIRECT;
852 return MATCHACTION_EXECUTE;
853 #if !GTK_CHECK_VERSION(3, 0, 0)
855 return MATCHACTION_COLOR;
858 return MATCHACTION_HIDE;
860 return MATCHACTION_IGNORE;
862 return MATCHACTION_WATCH;
864 return MATCHACTION_STOP;
865 case ACTION_CHANGE_SCORE:
866 return MATCHACTION_CHANGE_SCORE;
867 case ACTION_SET_SCORE:
868 return MATCHACTION_SET_SCORE;
869 case ACTION_ADD_TO_ADDRESSBOOK:
870 return MATCHACTION_ADD_TO_ADDRESSBOOK;
877 *\brief Returns action from the content of the dialog
879 *\param alert specifies whether alert dialog boxes should be shown
882 *\return FilteringAction * action entered in the dialog box.
884 static FilteringAction * prefs_filtering_action_dialog_to_action(gboolean alert)
890 gchar * destination = NULL;
892 FilteringAction * action;
894 gchar * header = NULL;
896 action_id = combobox_get_active_data(GTK_COMBO_BOX(filtering_action.action_combo));
897 action_type = prefs_filtering_action_get_matching_from_action(action_id);
898 list_id = gtk_combo_box_get_active(GTK_COMBO_BOX(filtering_action.account_combo));
899 account_id = get_account_id_from_list_id(list_id);
907 destination = gtk_editable_get_chars(GTK_EDITABLE(filtering_action.dest_entry), 0, -1);
908 if (*destination == '\0') {
910 alertpanel_error(action_id == ACTION_EXECUTE
911 ? _("Command-line not set")
912 : _("Destination is not set."));
918 case ACTION_FORWARD_AS_ATTACHMENT:
919 case ACTION_REDIRECT:
920 destination = gtk_editable_get_chars(GTK_EDITABLE(filtering_action.dest_entry), 0, -1);
921 if (*destination == '\0') {
923 alertpanel_error(_("Recipient is not set."));
928 #if !GTK_CHECK_VERSION(3, 0, 0)
930 labelcolor = colorlabel_get_color_menu_active_item(
931 gtk_cmoption_menu_get_menu(GTK_CMOPTION_MENU(filtering_action.color_optmenu)));
935 case ACTION_CHANGE_SCORE:
936 case ACTION_SET_SCORE:
937 score = gtk_spin_button_get_value_as_int(GTK_SPIN_BUTTON(
938 filtering_action.score_entry));
939 if (!score && action_id == ACTION_CHANGE_SCORE) {
941 alertpanel_error(_("Score is not set"));
945 case ACTION_ADD_TO_ADDRESSBOOK:
946 header = gtk_editable_get_chars(GTK_EDITABLE(filtering_action.header_entry), 0, -1);
947 if (*header == '\0') {
949 alertpanel_error(_("Header is not set."));
953 destination = gtk_editable_get_chars(GTK_EDITABLE(filtering_action.dest_entry), 0, -1);
954 if (*destination == '\0') {
956 alertpanel_error(_("Target addressbook/folder is not set."));
962 case ACTION_UNSET_TAG:
963 destination = gtk_combo_box_get_active_text(GTK_COMBO_BOX(filtering_action.tags_combo));
964 if (!destination || *destination == '\0') {
966 alertpanel_error(_("Tag name is empty."));
980 case ACTION_MARK_AS_READ:
981 case ACTION_MARK_AS_UNREAD:
982 case ACTION_MARK_AS_SPAM:
983 case ACTION_MARK_AS_HAM:
984 case ACTION_CLEAR_TAGS:
988 action = filteringaction_new(action_type, account_id,
989 destination, labelcolor, score, header);
996 *\brief Signal handler for register button
998 static void prefs_filtering_action_register_cb(void)
1000 FilteringAction *action;
1002 action = prefs_filtering_action_dialog_to_action(TRUE);
1006 prefs_filtering_action_list_view_set_row(NULL, action);
1008 filteringaction_free(action);
1010 * (presumably gtk_list_select_item(), called by
1011 * prefs_filtering_action_reset_dialog() activates
1012 * what seems to be a bug. this causes any other
1013 * list items to be unselectable)
1014 * prefs_filtering_action_reset_dialog(); */
1015 gtk_combo_box_set_active(GTK_COMBO_BOX(filtering_action.account_combo), 0);
1016 gtk_combo_box_set_active(GTK_COMBO_BOX(filtering_action.tags_combo), 0);
1017 gtk_entry_set_text(GTK_ENTRY(filtering_action.dest_entry), "");
1021 *\brief Signal handler for substitute button
1023 static void prefs_filtering_action_substitute_cb(void)
1025 GtkTreeView *list_view = GTK_TREE_VIEW
1026 (filtering_action.action_list_view);
1027 GtkTreeSelection *selection = gtk_tree_view_get_selection(list_view);
1028 GtkTreeModel *model;
1031 FilteringAction *action;
1033 if (!gtk_tree_selection_get_selected(selection, &model, &row))
1036 gtk_tree_model_get(model, &row, PFA_VALID_ACTION, &is_valid, -1);
1040 action = prefs_filtering_action_dialog_to_action(TRUE);
1044 prefs_filtering_action_list_view_set_row(&row, action);
1046 filteringaction_free(action);
1048 prefs_filtering_action_reset_dialog();
1052 *\brief Signal handler for delete button
1054 static void prefs_filtering_action_delete_cb(void)
1056 GtkTreeView *list_view = GTK_TREE_VIEW
1057 (filtering_action.action_list_view);
1058 GtkTreeSelection *selection = gtk_tree_view_get_selection(list_view);
1059 GtkTreeModel *model;
1063 if (!gtk_tree_selection_get_selected(selection, &model, &row))
1066 gtk_tree_model_get(model, &row, PFA_VALID_ACTION, &is_valid, -1);
1070 gtk_list_store_remove(GTK_LIST_STORE(model), &row);
1072 prefs_filtering_action_reset_dialog();
1076 *\brief Signal handler for 'move up' button
1078 static void prefs_filtering_action_up(void)
1080 GtkTreePath *prev, *sel, *try;
1082 GtkListStore *store = NULL;
1083 GtkTreeModel *model = NULL;
1086 if (!gtk_tree_selection_get_selected
1087 (gtk_tree_view_get_selection
1088 (GTK_TREE_VIEW(filtering_action.action_list_view)),
1092 store = (GtkListStore *)model;
1093 sel = gtk_tree_model_get_path(GTK_TREE_MODEL(store), &isel);
1097 /* no move if we're at row 0 or 1, looks phony, but other
1098 * solutions are more convoluted... */
1099 try = gtk_tree_path_copy(sel);
1100 if (!gtk_tree_path_prev(try) || !gtk_tree_path_prev(try)) {
1101 gtk_tree_path_free(try);
1102 gtk_tree_path_free(sel);
1105 gtk_tree_path_free(try);
1107 prev = gtk_tree_path_copy(sel);
1108 if (gtk_tree_path_prev(prev)) {
1109 gtk_tree_model_get_iter(GTK_TREE_MODEL(store),
1111 gtk_list_store_swap(store, &iprev, &isel);
1112 /* XXX: GTK2 select row?? */
1115 gtk_tree_path_free(sel);
1116 gtk_tree_path_free(prev);
1120 *\brief Signal handler for 'move down' button
1122 static void prefs_filtering_action_down(void)
1124 GtkListStore *store = NULL;
1125 GtkTreeModel *model = NULL;
1126 GtkTreeIter next, sel;
1129 if (!gtk_tree_selection_get_selected
1130 (gtk_tree_view_get_selection
1131 (GTK_TREE_VIEW(filtering_action.action_list_view)),
1135 store = (GtkListStore *)model;
1136 try = gtk_tree_model_get_path(GTK_TREE_MODEL(store), &sel);
1140 /* move when not at row 0 ... */
1141 if (gtk_tree_path_prev(try)) {
1143 if (gtk_tree_model_iter_next(GTK_TREE_MODEL(store), &next))
1144 gtk_list_store_swap(store, &next, &sel);
1147 gtk_tree_path_free(try);
1151 *\brief Handle key press
1153 *\param widget Widget receiving key press
1154 *\param event Key event
1155 *\param data User data
1157 static gboolean prefs_filtering_action_key_pressed(GtkWidget *widget,
1158 GdkEventKey *event, gpointer data)
1160 if (event && event->keyval == GDK_KEY_Escape) {
1161 prefs_filtering_action_cancel();
1168 *\brief Cancel matcher dialog
1170 static void prefs_filtering_action_cancel(void)
1172 gtk_widget_destroy(filtering_action.window);
1173 filtering_action.window = NULL;
1178 *\brief Accept current matchers
1180 static void prefs_filtering_action_ok(void)
1182 GSList * action_list;
1185 action_list = prefs_filtering_action_get_list();
1187 if (action_list == NULL) {
1188 alertpanel_error(_("No action was defined."));
1192 if (filtering_action_callback != NULL)
1193 filtering_action_callback(action_list);
1194 for(cur = action_list ; cur != NULL ; cur = cur->next) {
1195 filteringaction_free(cur->data);
1197 g_slist_free(action_list);
1199 gtk_widget_destroy(filtering_action.window);
1200 filtering_action.window = NULL;
1205 *\brief Called when closing dialog box
1207 *\param widget Dialog widget
1208 *\param event Event info
1209 *\param data User data
1213 static gint prefs_filtering_action_deleted(GtkWidget *widget,
1214 GdkEventAny *event, gpointer data)
1216 prefs_filtering_action_cancel();
1221 * Strings describing exec format strings
1223 * When adding new lines, remember to put 2 strings for each line
1225 static gchar *exec_desc_strings[] = {
1226 "%%", N_("literal %"),
1227 "%s", N_("Subject"),
1232 "%i", N_("Message-ID"),
1233 "%n", N_("Newsgroups"),
1234 "%r", N_("References"),
1235 "%F", N_("filename (should not be modified)"),
1236 "\\n", N_("new line"),
1237 "\\", N_("escape character for quotes"),
1238 "\\\"", N_("quote character"),
1242 static DescriptionWindow exec_desc_win = {
1246 N_("Filtering Action: 'Execute'"),
1247 N_("'Execute' allows you to send a message or message element "
1248 "to an external program or script.\n"
1249 "The following symbols can be used:"),
1254 *\brief Show Execute action's info
1256 static void prefs_filtering_action_exec_info(GtkWidget *widget, GtkWidget *parent)
1258 exec_desc_win.parent = parent;
1259 description_window_create(&exec_desc_win);
1262 static void prefs_filtering_action_select_dest(void)
1267 dest = foldersel_folder_sel(NULL, FOLDER_SEL_COPY, NULL, FALSE);
1270 path = folder_item_get_identifier(dest);
1272 gtk_entry_set_text(GTK_ENTRY(filtering_action.dest_entry), path);
1276 #ifndef USE_NEW_ADDRBOOK
1277 static void prefs_filtering_action_select_addressbook(void)
1279 const gchar *folderpath = NULL;
1280 gchar *new_path = NULL;
1282 folderpath = gtk_entry_get_text(GTK_ENTRY(filtering_action.dest_entry));
1283 new_path = addressbook_folder_selection(folderpath);
1285 gtk_entry_set_text(GTK_ENTRY(filtering_action.dest_entry), new_path);
1291 static void prefs_filtering_action_enable_widget(GtkWidget* widget, const gboolean enable)
1293 cm_return_if_fail(widget != NULL);
1297 #if !GTK_CHECK_VERSION(2,24,0)
1298 if(GTK_IS_COMBO_BOX(widget) || GTK_IS_COMBO_BOX_ENTRY(widget))
1300 if(GTK_IS_COMBO_BOX(widget))
1302 gtk_combo_box_set_active(GTK_COMBO_BOX(widget), 0);
1303 else if(GTK_IS_SPIN_BUTTON(widget))
1304 gtk_spin_button_set_value(GTK_SPIN_BUTTON(widget), 0);
1305 else if(GTK_IS_ENTRY(widget)) {
1306 gtk_entry_set_text(GTK_ENTRY(widget), "");
1307 } else if(GTK_IS_CMOPTION_MENU(widget))
1308 gtk_cmoption_menu_set_history(GTK_CMOPTION_MENU(widget), 0);
1310 gtk_widget_set_sensitive(widget, TRUE);
1311 gtk_widget_show(widget);
1313 gtk_widget_set_sensitive(widget, FALSE);
1314 gtk_widget_hide(widget);
1318 #define ACTION_SEND(x) (x == ACTION_FORWARD || x == ACTION_REDIRECT || \
1319 x == ACTION_FORWARD_AS_ATTACHMENT)
1320 #define ACTION_SCORE(x) (x == ACTION_CHANGE_SCORE || x == ACTION_SET_SCORE)
1321 #define ACTION_TAG(x) (x == ACTION_SET_TAG || x == ACTION_UNSET_TAG)
1322 #define ACTION_FILEOP(x) (x == ACTION_MOVE || x == ACTION_COPY)
1324 static void prefs_filtering_action_type_selection_changed(GtkWidget *combo,
1329 value = combobox_get_active_data(GTK_COMBO_BOX(filtering_action.action_combo));
1331 if (filtering_action.current_action != value) {
1332 if (ACTION_SEND(filtering_action.current_action)) {
1333 debug_print("unregistering address completion entry\n");
1334 address_completion_unregister_entry(GTK_ENTRY(filtering_action.dest_entry));
1335 address_completion_end(filtering_action.window);
1337 if (ACTION_SEND(value)) {
1338 debug_print("registering address completion entry\n");
1339 address_completion_start(filtering_action.window);
1340 address_completion_register_entry(
1341 GTK_ENTRY(filtering_action.dest_entry),
1344 filtering_action.current_action = value;
1347 prefs_filtering_action_enable_widget(filtering_action.label2,
1348 (ACTION_SEND(value) || value == ACTION_ADD_TO_ADDRESSBOOK));
1350 prefs_filtering_action_enable_widget(filtering_action.label3,
1351 (ACTION_SEND(value) || ACTION_TAG(value) ||
1352 ACTION_SCORE(value) || ACTION_FILEOP(value) ||
1353 value == ACTION_COLOR || value == ACTION_EXECUTE ||
1354 value == ACTION_ADD_TO_ADDRESSBOOK));
1356 prefs_filtering_action_enable_widget(filtering_action.account_combo,
1357 ACTION_SEND(value));
1359 prefs_filtering_action_enable_widget(filtering_action.tags_combo,
1362 prefs_filtering_action_enable_widget(filtering_action.dest_entry,
1363 (ACTION_FILEOP(value) || value == ACTION_EXECUTE ||
1364 ACTION_SEND(value) || value == ACTION_ADD_TO_ADDRESSBOOK));
1366 prefs_filtering_action_enable_widget(filtering_action.dest_btn,
1367 ACTION_FILEOP(value));
1369 prefs_filtering_action_enable_widget(filtering_action.exec_btn,
1370 (value == ACTION_EXECUTE));
1372 #if !GTK_CHECK_VERSION(3, 0, 0)
1373 prefs_filtering_action_enable_widget(filtering_action.color_optmenu,
1374 (value == ACTION_COLOR));
1377 prefs_filtering_action_enable_widget(filtering_action.header_combo,
1378 (value == ACTION_ADD_TO_ADDRESSBOOK));
1379 #ifndef USE_NEW_ADDRBOOK
1380 prefs_filtering_action_enable_widget(filtering_action.addressbook_btn,
1381 (value == ACTION_ADD_TO_ADDRESSBOOK));
1383 prefs_filtering_action_enable_widget(filtering_action.score_entry,
1384 ACTION_SCORE(value));
1387 case ACTION_FORWARD:
1388 case ACTION_FORWARD_AS_ATTACHMENT:
1389 case ACTION_REDIRECT:
1390 gtk_label_set_text(GTK_LABEL(filtering_action.label2), _("Account"));
1391 gtk_label_set_text(GTK_LABEL(filtering_action.label3), _("Recipient"));
1393 case ACTION_ADD_TO_ADDRESSBOOK:
1394 gtk_label_set_text(GTK_LABEL(filtering_action.label2), _("Header Name"));
1395 gtk_label_set_text(GTK_LABEL(filtering_action.label3), _("Book/Folder"));
1399 gtk_label_set_text(GTK_LABEL(filtering_action.label3), _("Destination"));
1401 #if !GTK_CHECK_VERSION(3, 0, 0)
1403 gtk_label_set_text(GTK_LABEL(filtering_action.label3), _("Color"));
1406 case ACTION_EXECUTE:
1407 gtk_label_set_text(GTK_LABEL(filtering_action.label3), _("Execute"));
1409 case ACTION_SET_SCORE:
1410 case ACTION_CHANGE_SCORE:
1411 gtk_label_set_text(GTK_LABEL(filtering_action.label3), _("Score"));
1413 case ACTION_SET_TAG:
1414 case ACTION_UNSET_TAG:
1415 gtk_label_set_text(GTK_LABEL(filtering_action.label3), _("Tag"));
1420 static void prefs_filtering_action_reset_dialog(void)
1422 combobox_select_by_data(GTK_COMBO_BOX(filtering_action.action_combo), ACTION_MOVE);
1423 gtk_combo_box_set_active(GTK_COMBO_BOX(filtering_action.account_combo), 0);
1424 gtk_entry_set_text(GTK_ENTRY(filtering_action.dest_entry), "");
1425 gtk_spin_button_set_value(GTK_SPIN_BUTTON(filtering_action.score_entry), 0);
1428 static GtkListStore* prefs_filtering_action_create_data_store(void)
1430 return gtk_list_store_new(N_PFA_COLUMNS,
1436 static void prefs_filtering_action_list_view_insert_action(GtkWidget *list_view,
1438 const gchar *action,
1441 GtkListStore *store = GTK_LIST_STORE(gtk_tree_view_get_model
1442 (GTK_TREE_VIEW(list_view)));
1446 /* see if row exists, if not append */
1448 gtk_list_store_append(store, &iter);
1452 gtk_list_store_set(store, &iter,
1454 PFA_VALID_ACTION, is_valid,
1458 static GtkWidget *prefs_filtering_action_list_view_create(void)
1460 GtkTreeView *list_view;
1461 GtkTreeModel *model;
1462 GtkTreeSelection *selector;
1464 model = GTK_TREE_MODEL(prefs_filtering_action_create_data_store());
1465 list_view = GTK_TREE_VIEW(gtk_tree_view_new_with_model(model));
1466 g_object_unref(model);
1468 gtk_tree_view_set_rules_hint(list_view, prefs_common.use_stripes_everywhere);
1469 gtk_tree_view_set_reorderable(list_view, TRUE);
1471 selector = gtk_tree_view_get_selection(list_view);
1472 gtk_tree_selection_set_mode(selector, GTK_SELECTION_BROWSE);
1473 gtk_tree_selection_set_select_function
1474 (selector, prefs_filtering_actions_selected, NULL, NULL);
1476 /* create the columns */
1477 prefs_filtering_action_create_list_view_columns(list_view);
1479 return GTK_WIDGET(list_view);
1482 static void prefs_filtering_action_create_list_view_columns(GtkTreeView *list_view)
1484 GtkTreeViewColumn *column;
1485 GtkCellRenderer *renderer;
1487 renderer = gtk_cell_renderer_text_new();
1488 column = gtk_tree_view_column_new_with_attributes
1489 (_("Current action list"),
1493 gtk_tree_view_append_column(list_view, column);
1496 static gboolean prefs_filtering_actions_selected
1497 (GtkTreeSelection *selector,
1498 GtkTreeModel *model,
1500 gboolean currently_selected,
1504 FilteringAction *action;
1505 GSList * action_list;
1511 if (currently_selected)
1514 if (!gtk_tree_model_get_iter(model, &iter, path))
1517 gtk_tree_model_get(model, &iter,
1518 PFA_VALID_ACTION, &is_valid,
1522 prefs_filtering_action_reset_dialog();
1526 gtk_tree_model_get(model, &iter,
1527 PFA_ACTION, &action_str,
1530 action_list = matcher_parser_get_action_list(action_str);
1533 if (action_list == NULL)
1536 action = action_list->data;
1537 g_slist_free(action_list);
1539 switch(action->type) {
1540 case MATCHACTION_MOVE:
1541 combobox_select_by_data(GTK_COMBO_BOX(filtering_action.action_combo),
1544 case MATCHACTION_COPY:
1545 combobox_select_by_data(GTK_COMBO_BOX(filtering_action.action_combo),
1548 case MATCHACTION_DELETE:
1549 combobox_select_by_data(GTK_COMBO_BOX(filtering_action.action_combo),
1552 case MATCHACTION_MARK:
1553 combobox_select_by_data(GTK_COMBO_BOX(filtering_action.action_combo),
1556 case MATCHACTION_UNMARK:
1557 combobox_select_by_data(GTK_COMBO_BOX(filtering_action.action_combo),
1560 case MATCHACTION_LOCK:
1561 combobox_select_by_data(GTK_COMBO_BOX(filtering_action.action_combo),
1564 case MATCHACTION_UNLOCK:
1565 combobox_select_by_data(GTK_COMBO_BOX(filtering_action.action_combo),
1568 case MATCHACTION_MARK_AS_READ:
1569 combobox_select_by_data(GTK_COMBO_BOX(filtering_action.action_combo),
1570 ACTION_MARK_AS_READ);
1572 case MATCHACTION_MARK_AS_UNREAD:
1573 combobox_select_by_data(GTK_COMBO_BOX(filtering_action.action_combo),
1574 ACTION_MARK_AS_UNREAD);
1576 case MATCHACTION_MARK_AS_SPAM:
1577 combobox_select_by_data(GTK_COMBO_BOX(filtering_action.action_combo),
1578 ACTION_MARK_AS_SPAM);
1580 case MATCHACTION_MARK_AS_HAM:
1581 combobox_select_by_data(GTK_COMBO_BOX(filtering_action.action_combo),
1582 ACTION_MARK_AS_HAM);
1584 case MATCHACTION_FORWARD:
1585 list_id = get_list_id_from_account_id(action->account_id);
1586 combobox_select_by_data(GTK_COMBO_BOX(filtering_action.action_combo),
1588 gtk_combo_box_set_active(GTK_COMBO_BOX(filtering_action.account_combo),
1591 case MATCHACTION_FORWARD_AS_ATTACHMENT:
1592 list_id = get_list_id_from_account_id(action->account_id);
1593 combobox_select_by_data(GTK_COMBO_BOX(filtering_action.action_combo),
1594 ACTION_FORWARD_AS_ATTACHMENT);
1595 gtk_combo_box_set_active(GTK_COMBO_BOX(filtering_action.account_combo),
1598 case MATCHACTION_REDIRECT:
1599 list_id = get_list_id_from_account_id(action->account_id);
1600 combobox_select_by_data(GTK_COMBO_BOX(filtering_action.action_combo),
1602 gtk_combo_box_set_active(GTK_COMBO_BOX(filtering_action.account_combo),
1605 case MATCHACTION_EXECUTE:
1606 combobox_select_by_data(GTK_COMBO_BOX(filtering_action.action_combo),
1609 #if !GTK_CHECK_VERSION(3, 0, 0)
1610 case MATCHACTION_COLOR:
1611 combobox_select_by_data(GTK_COMBO_BOX(filtering_action.action_combo),
1613 gtk_cmoption_menu_set_history(GTK_CMOPTION_MENU(filtering_action.color_optmenu),
1614 action->labelcolor + 1);
1615 menu = gtk_cmoption_menu_get_menu(GTK_CMOPTION_MENU(
1616 filtering_action.color_optmenu));
1617 g_signal_emit_by_name(G_OBJECT(menu), "selection-done", menu);
1620 case MATCHACTION_CHANGE_SCORE:
1621 combobox_select_by_data(GTK_COMBO_BOX(filtering_action.action_combo),
1622 ACTION_CHANGE_SCORE);
1623 gtk_spin_button_set_value(GTK_SPIN_BUTTON(filtering_action.score_entry),
1626 case MATCHACTION_SET_SCORE:
1627 combobox_select_by_data(GTK_COMBO_BOX(filtering_action.action_combo),
1629 gtk_spin_button_set_value(GTK_SPIN_BUTTON(filtering_action.score_entry),
1632 case MATCHACTION_STOP:
1633 combobox_select_by_data(GTK_COMBO_BOX(filtering_action.action_combo),
1636 case MATCHACTION_HIDE:
1637 combobox_select_by_data(GTK_COMBO_BOX(filtering_action.action_combo),
1640 case MATCHACTION_IGNORE:
1641 combobox_select_by_data(GTK_COMBO_BOX(filtering_action.action_combo),
1644 case MATCHACTION_WATCH:
1645 combobox_select_by_data(GTK_COMBO_BOX(filtering_action.action_combo),
1648 case MATCHACTION_ADD_TO_ADDRESSBOOK:
1650 gtk_entry_set_text(GTK_ENTRY(filtering_action.header_entry), action->header);
1652 gtk_entry_set_text(GTK_ENTRY(filtering_action.header_entry), "");
1653 combobox_select_by_data(GTK_COMBO_BOX(filtering_action.action_combo),
1654 ACTION_ADD_TO_ADDRESSBOOK);
1656 case MATCHACTION_SET_TAG:
1657 combobox_select_by_data(GTK_COMBO_BOX(filtering_action.action_combo),
1659 combobox_select_by_text(GTK_COMBO_BOX(filtering_action.tags_combo),
1660 action->destination);
1662 case MATCHACTION_UNSET_TAG:
1663 combobox_select_by_data(GTK_COMBO_BOX(filtering_action.action_combo),
1665 combobox_select_by_text(GTK_COMBO_BOX(filtering_action.tags_combo),
1666 action->destination);
1668 case MATCHACTION_CLEAR_TAGS:
1669 combobox_select_by_data(GTK_COMBO_BOX(filtering_action.action_combo),
1673 g_warning("unhandled case !\n");
1675 if (action->destination)
1676 gtk_entry_set_text(GTK_ENTRY(filtering_action.dest_entry), action->destination);
1678 gtk_entry_set_text(GTK_ENTRY(filtering_action.dest_entry), "");
1680 filteringaction_free(action); /* XXX: memleak */