2 * Claws Mail -- a GTK+ based, lightweight, and fast e-mail client
3 * Copyright (C) 2003-2009 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 #include "gtkcmoptionmenu.h"
37 #include "prefs_gtk.h"
38 #include "prefs_filtering_action.h"
39 #include "prefs_common.h"
40 #include "mainwindow.h"
41 #include "foldersel.h"
42 #include "manage_window.h"
47 #include "alertpanel.h"
49 #include "description_window.h"
50 #include "addr_compl.h"
52 #include "matcher_parser.h"
53 #include "colorlabel.h"
63 static void prefs_filtering_action_create(void);
64 static void prefs_filtering_action_delete_cb(void);
65 static void prefs_filtering_action_substitute_cb(void);
66 static void prefs_filtering_action_register_cb(void);
67 static void prefs_filtering_action_reset_dialog(void);
68 static gboolean prefs_filtering_action_key_pressed(GtkWidget *widget,
69 GdkEventKey *event, gpointer data);
70 static void prefs_filtering_action_cancel(void);
71 static void prefs_filtering_action_ok(void);
72 static gint prefs_filtering_action_deleted(GtkWidget *widget,
73 GdkEventAny *event, gpointer data);
74 static void prefs_filtering_action_type_selection_changed(GtkWidget *widget,
76 static void prefs_filtering_action_select_dest(void);
77 static void prefs_filtering_action_select_addressbook(void);
78 static void prefs_filtering_action_up(void);
79 static void prefs_filtering_action_down(void);
80 static void prefs_filtering_action_set_dialog(GSList *action_list);
81 static GSList *prefs_filtering_action_get_list(void);
83 static GtkListStore* prefs_filtering_action_create_data_store (void);
84 static void prefs_filtering_action_list_view_insert_action (GtkWidget *list_view,
88 static GtkWidget *prefs_filtering_action_list_view_create (void);
89 static void prefs_filtering_action_create_list_view_columns (GtkTreeView *list_view);
90 static gboolean prefs_filtering_actions_selected (GtkTreeSelection *selector,
93 gboolean currently_selected,
96 static void prefs_filtering_action_exec_info (GtkWidget *widget,
100 *\brief UI data for matcher dialog
102 static struct FilteringAction_ {
107 GtkWidget *action_list_view;
111 GtkWidget *action_combo;
112 GtkWidget *account_combo;
113 GtkWidget *dest_entry;
116 GtkWidget *color_optmenu;
117 GtkWidget *header_combo;
118 GtkWidget *header_entry;
119 GtkWidget *addressbook_btn;
120 GtkWidget *score_entry;
121 GtkWidget *tags_combo;
127 typedef enum Action_ {
136 ACTION_MARK_AS_UNREAD,
140 ACTION_FORWARD_AS_ATTACHMENT,
152 ACTION_ADD_TO_ADDRESSBOOK,
154 /* add other action constants */
162 { NULL, N_("Move"), ACTION_MOVE },
163 { NULL, N_("Copy"), ACTION_COPY },
164 { NULL, N_("Delete"), ACTION_DELETE },
165 { NULL, N_("Hide"), ACTION_HIDE },
166 { N_("Message flags"), N_("Mark"), ACTION_MARK },
167 { N_("Message flags"), N_("Unmark"), ACTION_UNMARK },
168 { N_("Message flags"), N_("Lock"), ACTION_LOCK },
169 { N_("Message flags"), N_("Unlock"), ACTION_UNLOCK },
170 { N_("Message flags"), N_("Mark as read"), ACTION_MARK_AS_READ },
171 { N_("Message flags"), N_("Mark as unread"), ACTION_MARK_AS_UNREAD },
172 { N_("Message flags"), N_("Mark as spam"), ACTION_MARK_AS_SPAM },
173 { N_("Message flags"), N_("Mark as ham"), ACTION_MARK_AS_HAM },
174 { NULL, N_("Execute"), ACTION_EXECUTE },
175 { NULL, N_("Color label"), ACTION_COLOR },
176 { N_("Resend"), N_("Forward"), ACTION_FORWARD },
177 { N_("Resend"), N_("Forward as attachment"), ACTION_FORWARD_AS_ATTACHMENT },
178 { N_("Resend"), N_("Redirect"), ACTION_REDIRECT },
179 { N_("Score"), N_("Change score"), ACTION_CHANGE_SCORE },
180 { N_("Score"), N_("Set score"), ACTION_SET_SCORE },
181 { N_("Tags"), N_("Apply tag"), ACTION_SET_TAG },
182 { N_("Tags"), N_("Unset tag"), ACTION_UNSET_TAG },
183 { N_("Tags"), N_("Clear tags"), ACTION_CLEAR_TAGS },
184 { N_("Threads"), N_("Ignore thread"), ACTION_IGNORE },
185 { N_("Threads"), N_("Watch thread"), ACTION_WATCH },
186 { NULL, N_("Add to address book"), ACTION_ADD_TO_ADDRESSBOOK },
187 { NULL, N_("Stop filter"), ACTION_STOP },
201 static PrefsFilteringActionSignal *filtering_action_callback;
203 static GtkTreeModel *prefs_filtering_action_create_model(void)
205 GtkTreeIter iter, iter2;
207 gchar *curr_menu = NULL;
210 store = gtk_tree_store_new(N_ACTION_COMBO, G_TYPE_STRING, G_TYPE_INT,
213 for (i = 0; action_menu[i].menu || action_menu[i].text; i++)
215 if (action_menu[i].menu) {
216 if (!curr_menu || strcmp(action_menu[i].menu, curr_menu)) {
217 gtk_tree_store_append(store, &iter, NULL);
218 gtk_tree_store_set(store, &iter,
220 gettext(action_menu[i].menu),
221 ACTION_COMBO_SENS, TRUE,
223 curr_menu = action_menu[i].menu;
226 gtk_tree_store_append(store, &iter2, &iter);
227 gtk_tree_store_set(store, &iter2,
228 ACTION_COMBO_TEXT, gettext(action_menu[i].text),
229 ACTION_COMBO_DATA, action_menu[i].action,
230 ACTION_COMBO_SENS, TRUE,
235 gtk_tree_store_append(store, &iter, NULL);
236 gtk_tree_store_set(store, &iter,
237 ACTION_COMBO_TEXT, gettext(action_menu[i].text),
238 ACTION_COMBO_DATA, action_menu[i].action,
239 ACTION_COMBO_SENS, TRUE,
244 return GTK_TREE_MODEL(store);
247 static void cell_is_sensitive(GtkCellLayout *cell_layout,
248 GtkCellRenderer *cell,
249 GtkTreeModel *tree_model,
253 if(gtk_tree_model_iter_has_child (tree_model, iter)) {
254 g_object_set (cell, "sensitive", FALSE, NULL);
259 *\brief Opens the filtering action dialog with a list of actions
261 *\param matchers List of conditions
265 void prefs_filtering_action_open(GSList *action_list,
266 PrefsFilteringActionSignal *cb)
270 if (!filtering_action.window) {
271 prefs_filtering_action_create();
273 /* update color label menu */
274 gtk_cmoption_menu_set_menu(GTK_CMOPTION_MENU(filtering_action.color_optmenu),
275 colorlabel_create_color_menu());
278 manage_window_set_transient(GTK_WINDOW(filtering_action.window));
279 gtk_widget_grab_focus(filtering_action.ok_btn);
281 filtering_action_callback = cb;
283 prefs_filtering_action_set_dialog(action_list);
285 gtk_widget_show(filtering_action.window);
289 *\brief Save Gtk object size to prefs dataset
291 static void prefs_filtering_action_size_allocate_cb(GtkWidget *widget,
292 GtkAllocation *allocation)
294 cm_return_if_fail(allocation != NULL);
296 prefs_common.filteringactionwin_width = allocation->width;
297 prefs_common.filteringactionwin_height = allocation->height;
300 #define LABELS_WIDTH 80
301 #define SECOND_ROW_WIDTH 250
303 static void prefs_filtering_action_check_widget_width(GtkWidget *widget)
307 gtk_widget_size_request(widget, &req);
308 if(req.width > SECOND_ROW_WIDTH)
309 gtk_widget_set_size_request(widget, SECOND_ROW_WIDTH, -1);
313 *\brief Create the matcher dialog
315 static void prefs_filtering_action_create(void)
320 GtkWidget *cancel_btn;
321 GtkWidget *confirm_area;
331 GtkWidget *action_combo;
332 GtkWidget *account_combo;
333 GtkWidget *header_combo;
334 GtkWidget *header_entry;
335 GtkWidget *addressbook_btn;
336 GtkWidget *dest_entry;
338 GtkWidget *score_entry;
339 GtkWidget *tags_combo;
345 GtkWidget *subst_btn;
348 GtkWidget *action_hbox;
349 GtkWidget *action_scrolledwin;
350 GtkWidget *action_list_view;
358 GtkWidget *color_optmenu;
360 static GdkGeometry geometry;
365 GtkSizeGroup *size_group = gtk_size_group_new(GTK_SIZE_GROUP_HORIZONTAL);
366 GtkSizeGroup *size_action = gtk_size_group_new(GTK_SIZE_GROUP_HORIZONTAL);
368 GtkCellRenderer *renderer;
370 debug_print("Creating matcher configuration window...\n");
372 window = gtkut_window_new(GTK_WINDOW_TOPLEVEL, "prefs_filtering_action");
373 gtk_container_set_border_width(GTK_CONTAINER(window), VBOX_BORDER);
374 gtk_window_set_position(GTK_WINDOW(window), GTK_WIN_POS_CENTER);
375 gtk_window_set_modal(GTK_WINDOW(window), TRUE);
376 gtk_window_set_resizable(GTK_WINDOW(window), TRUE);
378 vbox = gtk_vbox_new(FALSE, 6);
379 gtk_container_add(GTK_CONTAINER(window), vbox);
381 gtkut_stock_button_set_create(&confirm_area,
382 &cancel_btn, GTK_STOCK_CANCEL,
383 &ok_btn, GTK_STOCK_OK,
385 gtk_box_pack_end(GTK_BOX(vbox), confirm_area, FALSE, FALSE, 0);
386 gtk_widget_grab_default(ok_btn);
388 gtk_window_set_title(GTK_WINDOW(window),
389 _("Action configuration"));
390 g_signal_connect(G_OBJECT(window), "delete_event",
391 G_CALLBACK(prefs_filtering_action_deleted), NULL);
392 g_signal_connect(G_OBJECT(window), "size_allocate",
393 G_CALLBACK(prefs_filtering_action_size_allocate_cb), NULL);
394 g_signal_connect(G_OBJECT(window), "key_press_event",
395 G_CALLBACK(prefs_filtering_action_key_pressed), NULL);
396 MANAGE_WINDOW_SIGNALS_CONNECT(window);
397 g_signal_connect(G_OBJECT(ok_btn), "clicked",
398 G_CALLBACK(prefs_filtering_action_ok), NULL);
399 g_signal_connect(G_OBJECT(cancel_btn), "clicked",
400 G_CALLBACK(prefs_filtering_action_cancel), NULL);
402 vbox1 = gtk_vbox_new(FALSE, VSPACING);
403 gtk_box_pack_start(GTK_BOX(vbox), vbox1, TRUE, TRUE, 0);
404 gtk_container_set_border_width(GTK_CONTAINER (vbox1), 2);
406 frame = gtk_frame_new(_("Rule"));
407 gtk_frame_set_label_align(GTK_FRAME(frame), 0.01, 0.5);
408 gtk_box_pack_start (GTK_BOX (vbox1), frame, FALSE, FALSE, 0);
409 gtk_widget_set_size_request(frame, -1, 110);
411 table = gtk_table_new(3, 3, FALSE);
412 gtk_container_set_border_width(GTK_CONTAINER(table), 2);
413 gtk_table_set_row_spacings (GTK_TABLE (table), VSPACING_NARROW_2);
414 gtk_table_set_col_spacings (GTK_TABLE (table), HSPACING_NARROW);
415 gtk_container_add(GTK_CONTAINER(frame), table);
417 /* first row labels */
419 label1 = gtk_label_new (_("Action"));
420 gtk_widget_set_size_request(label1, LABELS_WIDTH, -1);
421 gtk_size_group_add_widget(size_group, label1);
422 gtk_misc_set_alignment (GTK_MISC (label1), 1, 0.5);
423 gtk_table_attach(GTK_TABLE(table), label1, 0, 1, 0, 1,
424 GTK_FILL, GTK_SHRINK, 0, 0);
426 label2 = gtk_label_new ("");
427 gtk_size_group_add_widget(size_group, label2);
428 gtk_misc_set_alignment (GTK_MISC (label2), 1, 0.5);
429 gtk_table_attach(GTK_TABLE(table), label2, 0, 1, 1, 2,
430 GTK_FILL, GTK_SHRINK, 0, 0);
432 label3 = gtk_label_new ("");
433 gtk_size_group_add_widget(size_group, label3);
434 gtk_misc_set_alignment (GTK_MISC (label3), 1, 0.5);
435 gtk_table_attach(GTK_TABLE(table), label3, 0, 1, 2, 3,
436 GTK_FILL, GTK_SHRINK, 0, 0);
440 hbox1 = gtk_hbox_new(FALSE, 0);
441 gtk_table_attach(GTK_TABLE(table), hbox1, 1, 2, 0, 1,
442 GTK_FILL, GTK_SHRINK, 0, 0);
444 model = prefs_filtering_action_create_model();
445 action_combo = gtk_combo_box_new_with_model(model);
446 gtk_size_group_add_widget(size_action, action_combo);
448 renderer = gtk_cell_renderer_text_new();
449 gtk_cell_layout_pack_start(GTK_CELL_LAYOUT(action_combo), renderer, TRUE);
450 gtk_cell_layout_set_attributes(GTK_CELL_LAYOUT(action_combo), renderer,
451 "text", ACTION_COMBO_TEXT,
452 "sensitive", ACTION_COMBO_SENS,
454 gtk_cell_layout_set_cell_data_func(GTK_CELL_LAYOUT(action_combo), renderer,
455 cell_is_sensitive, NULL, NULL);
457 combobox_select_by_data(GTK_COMBO_BOX(action_combo), ACTION_MOVE);
458 g_signal_connect(G_OBJECT(action_combo), "changed",
459 G_CALLBACK(prefs_filtering_action_type_selection_changed),
461 gtk_box_pack_start(GTK_BOX(hbox1), action_combo, FALSE, FALSE, 0);
462 gtk_box_pack_start(GTK_BOX(hbox1), gtk_label_new(""), TRUE, TRUE, 0);
466 hbox1 = gtk_hbox_new (FALSE, 0);
467 gtk_table_attach(GTK_TABLE(table), hbox1, 1, 2, 1, 2,
468 GTK_FILL | GTK_EXPAND, GTK_SHRINK, 0, 0);
470 account_combo = gtk_combo_box_new_text ();
471 gtk_size_group_add_widget(size_action, account_combo);
473 for (accounts = account_get_list() ; accounts != NULL;
474 accounts = accounts->next) {
475 PrefsAccount *ac = (PrefsAccount *)accounts->data;
476 gchar *name = g_strdup(ac->account_name);
477 gtk_combo_box_append_text(GTK_COMBO_BOX(account_combo), (gpointer) name);
481 prefs_filtering_action_check_widget_width(account_combo);
482 gtk_combo_box_set_active(GTK_COMBO_BOX(account_combo), 0);
483 gtk_box_pack_start (GTK_BOX (hbox1), account_combo,
488 header_combo = combobox_text_new(TRUE, "From", "To", "Cc", "Reply-To", "Sender", NULL);
489 gtk_size_group_add_widget(size_action, header_combo);
490 gtk_box_pack_start (GTK_BOX (hbox1), header_combo,
492 header_entry = gtk_bin_get_child(GTK_BIN((header_combo)));
496 hbox1 = gtk_hbox_new (FALSE, 0);
497 gtk_table_attach(GTK_TABLE(table), hbox1, 1, 2, 2, 3,
498 GTK_FILL | GTK_EXPAND, GTK_SHRINK, 0, 0);
500 dest_entry = gtk_entry_new ();
501 gtk_box_pack_start (GTK_BOX (hbox1), dest_entry, TRUE, TRUE, 0);
503 score_entry = gtk_spin_button_new_with_range(-1000, 1000, 1);
504 gtk_box_pack_start(GTK_BOX(hbox1), score_entry, FALSE, FALSE, 0);
506 color_optmenu = gtk_cmoption_menu_new();
507 gtk_size_group_add_widget(size_action, color_optmenu);
508 gtk_cmoption_menu_set_menu(GTK_CMOPTION_MENU(color_optmenu),
509 colorlabel_create_color_menu());
510 prefs_filtering_action_check_widget_width(color_optmenu);
511 gtk_box_pack_start(GTK_BOX(hbox1), color_optmenu, FALSE, FALSE, 0);
513 tags_combo = gtk_combo_box_new_text ();
514 gtk_size_group_add_widget(size_action, tags_combo);
516 for (tmp = tags = tags_get_list() ; tmp != NULL;
518 gchar *name = g_strdup(tags_get_tag(GPOINTER_TO_INT(tmp->data)));
520 gtk_combo_box_append_text(GTK_COMBO_BOX(tags_combo), (gpointer) name);
524 prefs_filtering_action_check_widget_width(tags_combo);
525 gtk_combo_box_set_active(GTK_COMBO_BOX(tags_combo), 0);
526 gtk_box_pack_start (GTK_BOX (hbox1), tags_combo,
529 hbox1 = gtk_hbox_new (FALSE, 0);
530 gtk_table_attach(GTK_TABLE(table), hbox1, 2, 3, 2, 3,
531 GTK_FILL, GTK_SHRINK, 0, 0);
533 dest_btn = gtk_button_new_with_label (_("Select ..."));
534 gtk_box_pack_start (GTK_BOX (hbox1), dest_btn, FALSE, FALSE, 0);
535 g_signal_connect (G_OBJECT (dest_btn), "clicked",
536 G_CALLBACK(prefs_filtering_action_select_dest),
539 addressbook_btn = gtk_button_new_with_label (_("Select ..."));
540 gtk_box_pack_start (GTK_BOX (hbox1), addressbook_btn, FALSE, FALSE, 0);
541 g_signal_connect (G_OBJECT (addressbook_btn), "clicked",
542 G_CALLBACK(prefs_filtering_action_select_addressbook),
545 #if GTK_CHECK_VERSION(2, 8, 0)
546 exec_btn = gtk_button_new_from_stock(GTK_STOCK_INFO);
548 exec_btn = gtk_button_new_with_label (_("Info..."));
550 gtk_box_pack_start (GTK_BOX (hbox1), exec_btn, FALSE, FALSE, 0);
551 g_signal_connect (G_OBJECT (exec_btn), "clicked",
552 G_CALLBACK(prefs_filtering_action_exec_info),
555 /* register / substitute / delete */
557 reg_hbox = gtk_hbox_new(FALSE, 4);
558 gtk_box_pack_start(GTK_BOX(vbox1), reg_hbox, FALSE, FALSE, 0);
560 arrow = gtk_arrow_new(GTK_ARROW_DOWN, GTK_SHADOW_OUT);
561 gtk_box_pack_start(GTK_BOX(reg_hbox), arrow, FALSE, FALSE, 0);
562 gtk_widget_set_size_request(arrow, -1, 16);
564 btn_hbox = gtk_hbox_new(TRUE, 4);
565 gtk_box_pack_start(GTK_BOX(reg_hbox), btn_hbox, FALSE, FALSE, 0);
567 reg_btn = gtk_button_new_from_stock(GTK_STOCK_ADD);
568 gtk_box_pack_start(GTK_BOX(btn_hbox), reg_btn, FALSE, TRUE, 0);
569 g_signal_connect(G_OBJECT(reg_btn), "clicked",
570 G_CALLBACK(prefs_filtering_action_register_cb), NULL);
572 subst_btn = gtkut_get_replace_btn(_("Replace"));
573 gtk_box_pack_start(GTK_BOX(btn_hbox), subst_btn, FALSE, TRUE, 0);
574 g_signal_connect(G_OBJECT(subst_btn), "clicked",
575 G_CALLBACK(prefs_filtering_action_substitute_cb),
578 del_btn = gtk_button_new_from_stock(GTK_STOCK_DELETE);
579 gtk_box_pack_start(GTK_BOX(btn_hbox), del_btn, FALSE, TRUE, 0);
580 g_signal_connect(G_OBJECT(del_btn), "clicked",
581 G_CALLBACK(prefs_filtering_action_delete_cb), NULL);
583 action_hbox = gtk_hbox_new(FALSE, 8);
584 gtk_box_pack_start(GTK_BOX(vbox1), action_hbox, TRUE, TRUE, 0);
586 action_scrolledwin = gtk_scrolled_window_new(NULL, NULL);
587 gtk_widget_set_size_request(action_scrolledwin, -1, 150);
588 gtk_box_pack_start(GTK_BOX(action_hbox), action_scrolledwin,
590 gtk_scrolled_window_set_shadow_type(GTK_SCROLLED_WINDOW(action_scrolledwin),
591 GTK_SHADOW_ETCHED_IN);
592 gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(action_scrolledwin),
593 GTK_POLICY_AUTOMATIC,
594 GTK_POLICY_AUTOMATIC);
596 action_list_view = prefs_filtering_action_list_view_create();
597 gtk_container_add(GTK_CONTAINER(action_scrolledwin), action_list_view);
599 btn_vbox = gtk_vbox_new(FALSE, 8);
600 gtk_box_pack_start(GTK_BOX(action_hbox), btn_vbox, FALSE, FALSE, 0);
602 up_btn = gtk_button_new_from_stock(GTK_STOCK_GO_UP);
603 gtk_box_pack_start(GTK_BOX(btn_vbox), up_btn, FALSE, FALSE, 0);
604 g_signal_connect(G_OBJECT(up_btn), "clicked",
605 G_CALLBACK(prefs_filtering_action_up), NULL);
607 down_btn = gtk_button_new_from_stock(GTK_STOCK_GO_DOWN);
608 gtk_box_pack_start(GTK_BOX(btn_vbox), down_btn, FALSE, FALSE, 0);
609 g_signal_connect(G_OBJECT(down_btn), "clicked",
610 G_CALLBACK(prefs_filtering_action_down), NULL);
612 if (!geometry.min_height) {
613 geometry.min_width = 490;
614 geometry.min_height = 348;
617 gtk_window_set_geometry_hints(GTK_WINDOW(window), NULL, &geometry,
619 gtk_widget_set_size_request(window, prefs_common.filteringactionwin_width,
620 prefs_common.filteringactionwin_height);
622 gtk_widget_show_all(window);
624 filtering_action.window = window;
625 filtering_action.label1 = label1;
626 filtering_action.label2 = label2;
627 filtering_action.label3 = label3;
628 filtering_action.action_combo = action_combo;
629 filtering_action.account_combo = account_combo;
630 filtering_action.tags_combo = tags_combo;
631 filtering_action.dest_entry = dest_entry;
632 filtering_action.dest_btn = dest_btn;
633 filtering_action.exec_btn = exec_btn;
634 filtering_action.color_optmenu = color_optmenu;
635 filtering_action.score_entry = score_entry;
636 filtering_action.header_combo = header_combo;
637 filtering_action.header_entry = header_entry;
638 filtering_action.addressbook_btn = addressbook_btn;
639 filtering_action.ok_btn = ok_btn;
640 filtering_action.action_list_view = action_list_view;
642 prefs_filtering_action_type_selection_changed(NULL, NULL);
646 *\brief Set the contents of a row
648 *\param row Index of row to set
649 *\param prop Condition to set
652 static void prefs_filtering_action_list_view_set_row(GtkTreeIter *row,
653 FilteringAction *action)
657 if (row == NULL && action == NULL) {
658 prefs_filtering_action_list_view_insert_action
659 (filtering_action.action_list_view,
660 NULL, _("(New)"), FALSE);
664 buf = filteringaction_to_string(action);
666 prefs_filtering_action_list_view_insert_action
667 (filtering_action.action_list_view,
673 *\brief Initializes dialog with a set of conditions
675 *\param matchers List of conditions
677 static void prefs_filtering_action_set_dialog(GSList *action_list)
681 gtk_list_store_clear(GTK_LIST_STORE(gtk_tree_view_get_model
682 (GTK_TREE_VIEW(filtering_action.action_list_view))));
684 prefs_filtering_action_list_view_set_row(NULL, NULL);
685 if (action_list != NULL) {
686 for (cur = action_list; cur != NULL;
687 cur = g_slist_next(cur)) {
688 FilteringAction *action;
689 action = (FilteringAction *) cur->data;
690 prefs_filtering_action_list_view_set_row(NULL, action);
694 prefs_filtering_action_reset_dialog();
696 combobox_set_sensitive(GTK_COMBO_BOX(filtering_action.action_combo), 9,
697 (tags_get_size() > 0) ? TRUE : FALSE);
701 *\brief Converts current actions in list box in
702 * an action list used by the filtering system.
704 *\return GSList * List of actions.
706 static GSList *prefs_filtering_action_get_list(void)
712 GtkTreeView *list_view = GTK_TREE_VIEW(filtering_action.action_list_view);
713 GtkTreeModel *model = gtk_tree_view_get_model(list_view);
718 while (gtk_tree_model_iter_nth_child(model, &iter, NULL, row)) {
720 gtk_tree_model_get(model, &iter,
721 PFA_ACTION, &action_str,
722 PFA_VALID_ACTION, &is_valid,
726 GSList * tmp_action_list;
727 tmp_action_list = matcher_parser_get_action_list(action_str);
729 if (tmp_action_list == NULL) {
734 action_list = g_slist_concat(action_list,
748 *\brief Returns account ID from the given list index
750 *\return gint account ID
752 static gint get_account_id_from_list_id(gint list_id)
756 for (accounts = account_get_list() ; accounts != NULL;
757 accounts = accounts->next) {
758 PrefsAccount *ac = (PrefsAccount *)accounts->data;
761 return ac->account_id;
768 *\brief Returns list index from the given account ID
770 *\return gint list index
772 static gint get_list_id_from_account_id(gint account_id)
777 for (accounts = account_get_list() ; accounts != NULL;
778 accounts = accounts->next) {
779 PrefsAccount *ac = (PrefsAccount *)accounts->data;
781 if (account_id == ac->account_id)
790 *\brief Returns parser action ID from internal action ID
792 *\return gint parser action ID
794 static gint prefs_filtering_action_get_matching_from_action(Action action_id)
798 return MATCHACTION_MOVE;
800 return MATCHACTION_SET_TAG;
801 case ACTION_UNSET_TAG:
802 return MATCHACTION_UNSET_TAG;
803 case ACTION_CLEAR_TAGS:
804 return MATCHACTION_CLEAR_TAGS;
806 return MATCHACTION_COPY;
808 return MATCHACTION_DELETE;
810 return MATCHACTION_MARK;
812 return MATCHACTION_UNMARK;
814 return MATCHACTION_LOCK;
816 return MATCHACTION_UNLOCK;
817 case ACTION_MARK_AS_READ:
818 return MATCHACTION_MARK_AS_READ;
819 case ACTION_MARK_AS_UNREAD:
820 return MATCHACTION_MARK_AS_UNREAD;
821 case ACTION_MARK_AS_SPAM:
822 return MATCHACTION_MARK_AS_SPAM;
823 case ACTION_MARK_AS_HAM:
824 return MATCHACTION_MARK_AS_HAM;
826 return MATCHACTION_FORWARD;
827 case ACTION_FORWARD_AS_ATTACHMENT:
828 return MATCHACTION_FORWARD_AS_ATTACHMENT;
829 case ACTION_REDIRECT:
830 return MATCHACTION_REDIRECT;
832 return MATCHACTION_EXECUTE;
834 return MATCHACTION_COLOR;
836 return MATCHACTION_HIDE;
838 return MATCHACTION_IGNORE;
840 return MATCHACTION_WATCH;
842 return MATCHACTION_STOP;
843 case ACTION_CHANGE_SCORE:
844 return MATCHACTION_CHANGE_SCORE;
845 case ACTION_SET_SCORE:
846 return MATCHACTION_SET_SCORE;
847 case ACTION_ADD_TO_ADDRESSBOOK:
848 return MATCHACTION_ADD_TO_ADDRESSBOOK;
855 *\brief Returns action from the content of the dialog
857 *\param alert specifies whether alert dialog boxes should be shown
860 *\return FilteringAction * action entered in the dialog box.
862 static FilteringAction * prefs_filtering_action_dialog_to_action(gboolean alert)
868 gchar * destination = NULL;
870 FilteringAction * action;
872 gchar * header = NULL;
874 action_id = combobox_get_active_data(GTK_COMBO_BOX(filtering_action.action_combo));
875 action_type = prefs_filtering_action_get_matching_from_action(action_id);
876 list_id = gtk_combo_box_get_active(GTK_COMBO_BOX(filtering_action.account_combo));
877 account_id = get_account_id_from_list_id(list_id);
885 destination = gtk_editable_get_chars(GTK_EDITABLE(filtering_action.dest_entry), 0, -1);
886 if (*destination == '\0') {
888 alertpanel_error(action_id == ACTION_EXECUTE
889 ? _("Command-line not set")
890 : _("Destination is not set."));
896 case ACTION_FORWARD_AS_ATTACHMENT:
897 case ACTION_REDIRECT:
898 destination = gtk_editable_get_chars(GTK_EDITABLE(filtering_action.dest_entry), 0, -1);
899 if (*destination == '\0') {
901 alertpanel_error(_("Recipient is not set."));
907 labelcolor = colorlabel_get_color_menu_active_item(
908 gtk_cmoption_menu_get_menu(GTK_CMOPTION_MENU(filtering_action.color_optmenu)));
911 case ACTION_CHANGE_SCORE:
912 case ACTION_SET_SCORE:
913 score = gtk_spin_button_get_value_as_int(GTK_SPIN_BUTTON(
914 filtering_action.score_entry));
915 if (!score && action_id == ACTION_CHANGE_SCORE) {
917 alertpanel_error(_("Score is not set"));
921 case ACTION_ADD_TO_ADDRESSBOOK:
922 header = gtk_editable_get_chars(GTK_EDITABLE(filtering_action.header_entry), 0, -1);
923 if (*header == '\0') {
925 alertpanel_error(_("Header is not set."));
929 destination = gtk_editable_get_chars(GTK_EDITABLE(filtering_action.dest_entry), 0, -1);
930 if (*destination == '\0') {
932 alertpanel_error(_("Target addressbook/folder is not set."));
938 case ACTION_UNSET_TAG:
939 destination = gtk_combo_box_get_active_text(GTK_COMBO_BOX(filtering_action.tags_combo));
940 if (!destination || *destination == '\0') {
942 alertpanel_error(_("Tag name is empty."));
956 case ACTION_MARK_AS_READ:
957 case ACTION_MARK_AS_UNREAD:
958 case ACTION_MARK_AS_SPAM:
959 case ACTION_MARK_AS_HAM:
960 case ACTION_CLEAR_TAGS:
964 action = filteringaction_new(action_type, account_id,
965 destination, labelcolor, score, header);
972 *\brief Signal handler for register button
974 static void prefs_filtering_action_register_cb(void)
976 FilteringAction *action;
978 action = prefs_filtering_action_dialog_to_action(TRUE);
982 prefs_filtering_action_list_view_set_row(NULL, action);
984 filteringaction_free(action);
986 * (presumably gtk_list_select_item(), called by
987 * prefs_filtering_action_reset_dialog() activates
988 * what seems to be a bug. this causes any other
989 * list items to be unselectable)
990 * prefs_filtering_action_reset_dialog(); */
991 gtk_combo_box_set_active(GTK_COMBO_BOX(filtering_action.account_combo), 0);
992 gtk_combo_box_set_active(GTK_COMBO_BOX(filtering_action.tags_combo), 0);
993 gtk_entry_set_text(GTK_ENTRY(filtering_action.dest_entry), "");
997 *\brief Signal handler for substitute button
999 static void prefs_filtering_action_substitute_cb(void)
1001 GtkTreeView *list_view = GTK_TREE_VIEW
1002 (filtering_action.action_list_view);
1003 GtkTreeSelection *selection = gtk_tree_view_get_selection(list_view);
1004 GtkTreeModel *model;
1007 FilteringAction *action;
1009 if (!gtk_tree_selection_get_selected(selection, &model, &row))
1012 gtk_tree_model_get(model, &row, PFA_VALID_ACTION, &is_valid, -1);
1016 action = prefs_filtering_action_dialog_to_action(TRUE);
1020 prefs_filtering_action_list_view_set_row(&row, action);
1022 filteringaction_free(action);
1024 prefs_filtering_action_reset_dialog();
1028 *\brief Signal handler for delete button
1030 static void prefs_filtering_action_delete_cb(void)
1032 GtkTreeView *list_view = GTK_TREE_VIEW
1033 (filtering_action.action_list_view);
1034 GtkTreeSelection *selection = gtk_tree_view_get_selection(list_view);
1035 GtkTreeModel *model;
1039 if (!gtk_tree_selection_get_selected(selection, &model, &row))
1042 gtk_tree_model_get(model, &row, PFA_VALID_ACTION, &is_valid, -1);
1046 gtk_list_store_remove(GTK_LIST_STORE(model), &row);
1048 prefs_filtering_action_reset_dialog();
1052 *\brief Signal handler for 'move up' button
1054 static void prefs_filtering_action_up(void)
1056 GtkTreePath *prev, *sel, *try;
1058 GtkListStore *store = NULL;
1059 GtkTreeModel *model = NULL;
1062 if (!gtk_tree_selection_get_selected
1063 (gtk_tree_view_get_selection
1064 (GTK_TREE_VIEW(filtering_action.action_list_view)),
1068 store = (GtkListStore *)model;
1069 sel = gtk_tree_model_get_path(GTK_TREE_MODEL(store), &isel);
1073 /* no move if we're at row 0 or 1, looks phony, but other
1074 * solutions are more convoluted... */
1075 try = gtk_tree_path_copy(sel);
1076 if (!gtk_tree_path_prev(try) || !gtk_tree_path_prev(try)) {
1077 gtk_tree_path_free(try);
1078 gtk_tree_path_free(sel);
1081 gtk_tree_path_free(try);
1083 prev = gtk_tree_path_copy(sel);
1084 if (gtk_tree_path_prev(prev)) {
1085 gtk_tree_model_get_iter(GTK_TREE_MODEL(store),
1087 gtk_list_store_swap(store, &iprev, &isel);
1088 /* XXX: GTK2 select row?? */
1091 gtk_tree_path_free(sel);
1092 gtk_tree_path_free(prev);
1096 *\brief Signal handler for 'move down' button
1098 static void prefs_filtering_action_down(void)
1100 GtkListStore *store = NULL;
1101 GtkTreeModel *model = NULL;
1102 GtkTreeIter next, sel;
1105 if (!gtk_tree_selection_get_selected
1106 (gtk_tree_view_get_selection
1107 (GTK_TREE_VIEW(filtering_action.action_list_view)),
1111 store = (GtkListStore *)model;
1112 try = gtk_tree_model_get_path(GTK_TREE_MODEL(store), &sel);
1116 /* move when not at row 0 ... */
1117 if (gtk_tree_path_prev(try)) {
1119 if (gtk_tree_model_iter_next(GTK_TREE_MODEL(store), &next))
1120 gtk_list_store_swap(store, &next, &sel);
1123 gtk_tree_path_free(try);
1127 *\brief Handle key press
1129 *\param widget Widget receiving key press
1130 *\param event Key event
1131 *\param data User data
1133 static gboolean prefs_filtering_action_key_pressed(GtkWidget *widget,
1134 GdkEventKey *event, gpointer data)
1136 if (event && event->keyval == GDK_Escape) {
1137 prefs_filtering_action_cancel();
1144 *\brief Cancel matcher dialog
1146 static void prefs_filtering_action_cancel(void)
1148 gtk_widget_destroy(filtering_action.window);
1149 filtering_action.window = NULL;
1154 *\brief Accept current matchers
1156 static void prefs_filtering_action_ok(void)
1158 GSList * action_list;
1161 action_list = prefs_filtering_action_get_list();
1163 if (action_list == NULL) {
1164 alertpanel_error(_("No action was defined."));
1168 if (filtering_action_callback != NULL)
1169 filtering_action_callback(action_list);
1170 for(cur = action_list ; cur != NULL ; cur = cur->next) {
1171 filteringaction_free(cur->data);
1173 g_slist_free(action_list);
1175 gtk_widget_destroy(filtering_action.window);
1176 filtering_action.window = NULL;
1181 *\brief Called when closing dialog box
1183 *\param widget Dialog widget
1184 *\param event Event info
1185 *\param data User data
1189 static gint prefs_filtering_action_deleted(GtkWidget *widget,
1190 GdkEventAny *event, gpointer data)
1192 prefs_filtering_action_cancel();
1197 * Strings describing exec format strings
1199 * When adding new lines, remember to put 2 strings for each line
1201 static gchar *exec_desc_strings[] = {
1202 "%%", N_("literal %"),
1203 "%s", N_("Subject"),
1208 "%i", N_("Message-ID"),
1209 "%n", N_("Newsgroups"),
1210 "%r", N_("References"),
1211 "%F", N_("filename (should not be modified)"),
1212 "\\n", N_("new line"),
1213 "\\", N_("escape character for quotes"),
1214 "\\\"", N_("quote character"),
1218 static DescriptionWindow exec_desc_win = {
1222 N_("Filtering Action: 'Execute'"),
1223 N_("'Execute' allows you to send a message or message element "
1224 "to an external program or script.\n"
1225 "The following symbols can be used:"),
1230 *\brief Show Execute action's info
1232 static void prefs_filtering_action_exec_info(GtkWidget *widget, GtkWidget *parent)
1234 exec_desc_win.parent = parent;
1235 description_window_create(&exec_desc_win);
1238 static void prefs_filtering_action_select_dest(void)
1243 dest = foldersel_folder_sel(NULL, FOLDER_SEL_COPY, NULL, FALSE);
1246 path = folder_item_get_identifier(dest);
1248 gtk_entry_set_text(GTK_ENTRY(filtering_action.dest_entry), path);
1252 static void prefs_filtering_action_select_addressbook(void)
1254 const gchar *folderpath = NULL;
1255 gchar *new_path = NULL;
1257 folderpath = gtk_entry_get_text(GTK_ENTRY(filtering_action.dest_entry));
1258 new_path = addressbook_folder_selection(folderpath);
1260 gtk_entry_set_text(GTK_ENTRY(filtering_action.dest_entry), new_path);
1265 static void prefs_filtering_action_enable_widget(GtkWidget* widget, const gboolean enable)
1267 cm_return_if_fail(widget != NULL);
1271 if(GTK_IS_COMBO_BOX(widget) || GTK_IS_COMBO_BOX_ENTRY(widget))
1272 gtk_combo_box_set_active(GTK_COMBO_BOX(widget), 0);
1273 else if(GTK_IS_SPIN_BUTTON(widget))
1274 gtk_spin_button_set_value(GTK_SPIN_BUTTON(widget), 0);
1275 else if(GTK_IS_ENTRY(widget)) {
1276 gtk_entry_set_text(GTK_ENTRY(widget), "");
1277 } else if(GTK_IS_CMOPTION_MENU(widget))
1278 gtk_cmoption_menu_set_history(GTK_CMOPTION_MENU(widget), 0);
1280 gtk_widget_set_sensitive(widget, TRUE);
1281 gtk_widget_show(widget);
1283 gtk_widget_set_sensitive(widget, FALSE);
1284 gtk_widget_hide(widget);
1288 #define ACTION_SEND(x) (x == ACTION_FORWARD || x == ACTION_REDIRECT || \
1289 x == ACTION_FORWARD_AS_ATTACHMENT)
1290 #define ACTION_SCORE(x) (x == ACTION_CHANGE_SCORE || x == ACTION_SET_SCORE)
1291 #define ACTION_TAG(x) (x == ACTION_SET_TAG || x == ACTION_UNSET_TAG)
1292 #define ACTION_FILEOP(x) (x == ACTION_MOVE || x == ACTION_COPY)
1294 static void prefs_filtering_action_type_selection_changed(GtkWidget *combo,
1299 value = combobox_get_active_data(GTK_COMBO_BOX(filtering_action.action_combo));
1301 if (filtering_action.current_action != value) {
1302 if (ACTION_SEND(filtering_action.current_action)) {
1303 debug_print("unregistering address completion entry\n");
1304 address_completion_unregister_entry(GTK_ENTRY(filtering_action.dest_entry));
1305 address_completion_end(filtering_action.window);
1307 if (ACTION_SEND(value)) {
1308 debug_print("registering address completion entry\n");
1309 address_completion_start(filtering_action.window);
1310 address_completion_register_entry(
1311 GTK_ENTRY(filtering_action.dest_entry),
1314 filtering_action.current_action = value;
1317 prefs_filtering_action_enable_widget(filtering_action.label2,
1318 (ACTION_SEND(value) || value == ACTION_ADD_TO_ADDRESSBOOK));
1320 prefs_filtering_action_enable_widget(filtering_action.label3,
1321 (ACTION_SEND(value) || ACTION_TAG(value) ||
1322 ACTION_SCORE(value) || ACTION_FILEOP(value) ||
1323 value == ACTION_COLOR || value == ACTION_EXECUTE ||
1324 value == ACTION_ADD_TO_ADDRESSBOOK));
1326 prefs_filtering_action_enable_widget(filtering_action.account_combo,
1327 ACTION_SEND(value));
1329 prefs_filtering_action_enable_widget(filtering_action.tags_combo,
1332 prefs_filtering_action_enable_widget(filtering_action.dest_entry,
1333 (ACTION_FILEOP(value) || value == ACTION_EXECUTE ||
1334 ACTION_SEND(value) || value == ACTION_ADD_TO_ADDRESSBOOK));
1336 prefs_filtering_action_enable_widget(filtering_action.dest_btn,
1337 ACTION_FILEOP(value));
1339 prefs_filtering_action_enable_widget(filtering_action.exec_btn,
1340 (value == ACTION_EXECUTE));
1342 prefs_filtering_action_enable_widget(filtering_action.color_optmenu,
1343 (value == ACTION_COLOR));
1345 prefs_filtering_action_enable_widget(filtering_action.header_combo,
1346 (value == ACTION_ADD_TO_ADDRESSBOOK));
1348 prefs_filtering_action_enable_widget(filtering_action.addressbook_btn,
1349 (value == ACTION_ADD_TO_ADDRESSBOOK));
1351 prefs_filtering_action_enable_widget(filtering_action.score_entry,
1352 ACTION_SCORE(value));
1355 case ACTION_FORWARD:
1356 case ACTION_FORWARD_AS_ATTACHMENT:
1357 case ACTION_REDIRECT:
1358 gtk_label_set_text(GTK_LABEL(filtering_action.label2), _("Account"));
1359 gtk_label_set_text(GTK_LABEL(filtering_action.label3), _("Recipient"));
1361 case ACTION_ADD_TO_ADDRESSBOOK:
1362 gtk_label_set_text(GTK_LABEL(filtering_action.label2), _("Header Name"));
1363 gtk_label_set_text(GTK_LABEL(filtering_action.label3), _("Book/Folder"));
1367 gtk_label_set_text(GTK_LABEL(filtering_action.label3), _("Destination"));
1370 gtk_label_set_text(GTK_LABEL(filtering_action.label3), _("Color"));
1372 case ACTION_EXECUTE:
1373 gtk_label_set_text(GTK_LABEL(filtering_action.label3), _("Execute"));
1375 case ACTION_SET_SCORE:
1376 case ACTION_CHANGE_SCORE:
1377 gtk_label_set_text(GTK_LABEL(filtering_action.label3), _("Score"));
1379 case ACTION_SET_TAG:
1380 case ACTION_UNSET_TAG:
1381 gtk_label_set_text(GTK_LABEL(filtering_action.label3), _("Tag"));
1386 static void prefs_filtering_action_reset_dialog(void)
1388 combobox_select_by_data(GTK_COMBO_BOX(filtering_action.action_combo), ACTION_MOVE);
1389 gtk_combo_box_set_active(GTK_COMBO_BOX(filtering_action.account_combo), 0);
1390 gtk_entry_set_text(GTK_ENTRY(filtering_action.dest_entry), "");
1391 gtk_spin_button_set_value(GTK_SPIN_BUTTON(filtering_action.score_entry), 0);
1394 static GtkListStore* prefs_filtering_action_create_data_store(void)
1396 return gtk_list_store_new(N_PFA_COLUMNS,
1402 static void prefs_filtering_action_list_view_insert_action(GtkWidget *list_view,
1404 const gchar *action,
1407 GtkListStore *store = GTK_LIST_STORE(gtk_tree_view_get_model
1408 (GTK_TREE_VIEW(list_view)));
1412 /* see if row exists, if not append */
1414 gtk_list_store_append(store, &iter);
1418 gtk_list_store_set(store, &iter,
1420 PFA_VALID_ACTION, is_valid,
1424 static GtkWidget *prefs_filtering_action_list_view_create(void)
1426 GtkTreeView *list_view;
1427 GtkTreeModel *model;
1428 GtkTreeSelection *selector;
1430 model = GTK_TREE_MODEL(prefs_filtering_action_create_data_store());
1431 list_view = GTK_TREE_VIEW(gtk_tree_view_new_with_model(model));
1432 g_object_unref(model);
1434 gtk_tree_view_set_rules_hint(list_view, prefs_common.use_stripes_everywhere);
1435 gtk_tree_view_set_reorderable(list_view, TRUE);
1437 selector = gtk_tree_view_get_selection(list_view);
1438 gtk_tree_selection_set_mode(selector, GTK_SELECTION_BROWSE);
1439 gtk_tree_selection_set_select_function
1440 (selector, prefs_filtering_actions_selected, NULL, NULL);
1442 /* create the columns */
1443 prefs_filtering_action_create_list_view_columns(list_view);
1445 return GTK_WIDGET(list_view);
1448 static void prefs_filtering_action_create_list_view_columns(GtkTreeView *list_view)
1450 GtkTreeViewColumn *column;
1451 GtkCellRenderer *renderer;
1453 renderer = gtk_cell_renderer_text_new();
1454 column = gtk_tree_view_column_new_with_attributes
1455 (_("Current action list"),
1459 gtk_tree_view_append_column(list_view, column);
1462 static gboolean prefs_filtering_actions_selected
1463 (GtkTreeSelection *selector,
1464 GtkTreeModel *model,
1466 gboolean currently_selected,
1470 FilteringAction *action;
1471 GSList * action_list;
1477 if (currently_selected)
1480 if (!gtk_tree_model_get_iter(model, &iter, path))
1483 gtk_tree_model_get(model, &iter,
1484 PFA_VALID_ACTION, &is_valid,
1488 prefs_filtering_action_reset_dialog();
1492 gtk_tree_model_get(model, &iter,
1493 PFA_ACTION, &action_str,
1496 action_list = matcher_parser_get_action_list(action_str);
1499 if (action_list == NULL)
1502 action = action_list->data;
1503 g_slist_free(action_list);
1505 switch(action->type) {
1506 case MATCHACTION_MOVE:
1507 combobox_select_by_data(GTK_COMBO_BOX(filtering_action.action_combo),
1510 case MATCHACTION_COPY:
1511 combobox_select_by_data(GTK_COMBO_BOX(filtering_action.action_combo),
1514 case MATCHACTION_DELETE:
1515 combobox_select_by_data(GTK_COMBO_BOX(filtering_action.action_combo),
1518 case MATCHACTION_MARK:
1519 combobox_select_by_data(GTK_COMBO_BOX(filtering_action.action_combo),
1522 case MATCHACTION_UNMARK:
1523 combobox_select_by_data(GTK_COMBO_BOX(filtering_action.action_combo),
1526 case MATCHACTION_LOCK:
1527 combobox_select_by_data(GTK_COMBO_BOX(filtering_action.action_combo),
1530 case MATCHACTION_UNLOCK:
1531 combobox_select_by_data(GTK_COMBO_BOX(filtering_action.action_combo),
1534 case MATCHACTION_MARK_AS_READ:
1535 combobox_select_by_data(GTK_COMBO_BOX(filtering_action.action_combo),
1536 ACTION_MARK_AS_READ);
1538 case MATCHACTION_MARK_AS_UNREAD:
1539 combobox_select_by_data(GTK_COMBO_BOX(filtering_action.action_combo),
1540 ACTION_MARK_AS_UNREAD);
1542 case MATCHACTION_MARK_AS_SPAM:
1543 combobox_select_by_data(GTK_COMBO_BOX(filtering_action.action_combo),
1544 ACTION_MARK_AS_SPAM);
1546 case MATCHACTION_MARK_AS_HAM:
1547 combobox_select_by_data(GTK_COMBO_BOX(filtering_action.action_combo),
1548 ACTION_MARK_AS_HAM);
1550 case MATCHACTION_FORWARD:
1551 list_id = get_list_id_from_account_id(action->account_id);
1552 combobox_select_by_data(GTK_COMBO_BOX(filtering_action.action_combo),
1554 gtk_combo_box_set_active(GTK_COMBO_BOX(filtering_action.account_combo),
1557 case MATCHACTION_FORWARD_AS_ATTACHMENT:
1558 list_id = get_list_id_from_account_id(action->account_id);
1559 combobox_select_by_data(GTK_COMBO_BOX(filtering_action.action_combo),
1560 ACTION_FORWARD_AS_ATTACHMENT);
1561 gtk_combo_box_set_active(GTK_COMBO_BOX(filtering_action.account_combo),
1564 case MATCHACTION_REDIRECT:
1565 list_id = get_list_id_from_account_id(action->account_id);
1566 combobox_select_by_data(GTK_COMBO_BOX(filtering_action.action_combo),
1568 gtk_combo_box_set_active(GTK_COMBO_BOX(filtering_action.account_combo),
1571 case MATCHACTION_EXECUTE:
1572 combobox_select_by_data(GTK_COMBO_BOX(filtering_action.action_combo),
1575 case MATCHACTION_COLOR:
1576 combobox_select_by_data(GTK_COMBO_BOX(filtering_action.action_combo),
1578 gtk_cmoption_menu_set_history(GTK_CMOPTION_MENU(filtering_action.color_optmenu),
1579 action->labelcolor);
1580 menu = gtk_cmoption_menu_get_menu(GTK_CMOPTION_MENU(
1581 filtering_action.color_optmenu));
1582 g_signal_emit_by_name(G_OBJECT(menu), "selection-done", menu);
1584 case MATCHACTION_CHANGE_SCORE:
1585 combobox_select_by_data(GTK_COMBO_BOX(filtering_action.action_combo),
1586 ACTION_CHANGE_SCORE);
1587 gtk_spin_button_set_value(GTK_SPIN_BUTTON(filtering_action.score_entry),
1590 case MATCHACTION_SET_SCORE:
1591 combobox_select_by_data(GTK_COMBO_BOX(filtering_action.action_combo),
1593 gtk_spin_button_set_value(GTK_SPIN_BUTTON(filtering_action.score_entry),
1596 case MATCHACTION_STOP:
1597 combobox_select_by_data(GTK_COMBO_BOX(filtering_action.action_combo),
1600 case MATCHACTION_HIDE:
1601 combobox_select_by_data(GTK_COMBO_BOX(filtering_action.action_combo),
1604 case MATCHACTION_IGNORE:
1605 combobox_select_by_data(GTK_COMBO_BOX(filtering_action.action_combo),
1608 case MATCHACTION_WATCH:
1609 combobox_select_by_data(GTK_COMBO_BOX(filtering_action.action_combo),
1612 case MATCHACTION_ADD_TO_ADDRESSBOOK:
1614 gtk_entry_set_text(GTK_ENTRY(filtering_action.header_entry), action->header);
1616 gtk_entry_set_text(GTK_ENTRY(filtering_action.header_entry), "");
1617 combobox_select_by_data(GTK_COMBO_BOX(filtering_action.action_combo),
1618 ACTION_ADD_TO_ADDRESSBOOK);
1620 case MATCHACTION_SET_TAG:
1621 combobox_select_by_data(GTK_COMBO_BOX(filtering_action.action_combo),
1623 combobox_select_by_text(GTK_COMBO_BOX(filtering_action.tags_combo),
1624 action->destination);
1626 case MATCHACTION_UNSET_TAG:
1627 combobox_select_by_data(GTK_COMBO_BOX(filtering_action.action_combo),
1629 combobox_select_by_text(GTK_COMBO_BOX(filtering_action.tags_combo),
1630 action->destination);
1632 case MATCHACTION_CLEAR_TAGS:
1633 combobox_select_by_data(GTK_COMBO_BOX(filtering_action.action_combo),
1637 g_warning("unhandled case !\n");
1639 if (action->destination)
1640 gtk_entry_set_text(GTK_ENTRY(filtering_action.dest_entry), action->destination);
1642 gtk_entry_set_text(GTK_ENTRY(filtering_action.dest_entry), "");
1644 filteringaction_free(action); /* XXX: memleak */