2 * Sylpheed -- a GTK+ based, lightweight, and fast e-mail client
3 * Copyright (C) 1999-2001 Hiroyuki Yamamoto
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 2 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, write to the Free Software
17 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
28 #include <gdk/gdkkeysyms.h>
36 #include "prefs_gtk.h"
37 #include "prefs_filtering_action.h"
38 #include "prefs_common.h"
39 #include "mainwindow.h"
40 #include "foldersel.h"
41 #include "manage_window.h"
46 #include "alertpanel.h"
48 #include "description_window.h"
49 #include "addr_compl.h"
51 #include "matcher_parser.h"
52 #include "colorlabel.h"
55 static void prefs_filtering_action_create(void);
56 static void prefs_filtering_action_delete_cb(void);
57 static void prefs_filtering_action_substitute_cb(void);
58 static void prefs_filtering_action_register_cb(void);
59 static void prefs_filtering_action_reset_dialog(void);
60 static gboolean prefs_filtering_action_key_pressed(GtkWidget *widget,
61 GdkEventKey *event, gpointer data);
62 static void prefs_filtering_action_cancel(void);
63 static void prefs_filtering_action_ok(void);
64 static gint prefs_filtering_action_deleted(GtkWidget *widget,
65 GdkEventAny *event, gpointer data);
66 static void prefs_filtering_action_type_selection_changed(GtkList *list,
68 static void prefs_filtering_action_type_select(GtkList *list,
69 GtkWidget *widget, gpointer user_data);
70 static void prefs_filtering_action_select_dest(void);
71 static void prefs_filtering_action_select(GtkCList *clist,
72 gint row, gint column, GdkEvent *event);
73 static void prefs_filtering_action_up(void);
74 static void prefs_filtering_action_down(void);
75 static void prefs_filtering_action_set_dialog(GSList *action_list);
76 static GSList *prefs_filtering_action_get_list(void);
80 *\brief UI data for matcher dialog
82 static struct FilteringAction {
87 GtkWidget *action_clist;
88 GtkWidget *action_type_list;
89 GtkWidget *action_combo;
90 GtkWidget *account_label;
91 GtkWidget *account_list;
92 GtkWidget *account_combo;
93 GtkWidget *dest_entry;
95 GtkWidget *dest_label;
96 GtkWidget *recip_label;
97 GtkWidget *exec_label;
99 GtkWidget *color_label;
100 GtkWidget *color_optmenu;
101 GtkWidget *score_label;
107 typedef enum Action_ {
116 ACTION_MARK_AS_UNREAD,
118 ACTION_FORWARD_AS_ATTACHMENT,
126 /* add other action constants */
133 { N_("Move"), ACTION_MOVE },
134 { N_("Copy"), ACTION_COPY },
135 { N_("Delete"), ACTION_DELETE },
136 { N_("Mark"), ACTION_MARK },
137 { N_("Unmark"), ACTION_UNMARK },
138 { N_("Lock"), ACTION_LOCK },
139 { N_("Unlock"), ACTION_UNLOCK },
140 { N_("Mark as read"), ACTION_MARK_AS_READ },
141 { N_("Mark as unread"), ACTION_MARK_AS_UNREAD },
142 { N_("Forward"), ACTION_FORWARD },
143 { N_("Forward as attachment"), ACTION_FORWARD_AS_ATTACHMENT },
144 { N_("Redirect"), ACTION_REDIRECT },
145 { N_("Execute"), ACTION_EXECUTE },
146 { N_("Color"), ACTION_COLOR },
147 { N_("Change score"), ACTION_CHANGE_SCORE},
148 { N_("Set score"), ACTION_SET_SCORE},
149 { N_("Hide"), ACTION_HIDE },
150 { N_("Stop filter"), ACTION_STOP },
157 static PrefsFilteringActionSignal *filtering_action_callback;
160 *\brief Find index of list selection
162 *\param list GTK list widget
164 *\return gint Selection index
166 static gint get_sel_from_list(GtkList *list)
172 if (list->selection == NULL)
175 sel = list->selection->data;
176 for (child = list->children; child != NULL; child = g_list_next(child)) {
177 if (child->data == sel)
186 *\brief Opens the filtering action dialog with a list of actions
188 *\param matchers List of conditions
192 void prefs_filtering_action_open(GSList *action_list,
193 PrefsFilteringActionSignal *cb)
197 if (!filtering_action.window) {
198 prefs_filtering_action_create();
201 manage_window_set_transient(GTK_WINDOW(filtering_action.window));
202 gtk_widget_grab_focus(filtering_action.ok_btn);
204 filtering_action_callback = cb;
206 prefs_filtering_action_set_dialog(action_list);
208 gtk_widget_show(filtering_action.window);
212 *\brief Create the matcher dialog
214 static void prefs_filtering_action_create(void)
219 GtkWidget *cancel_btn;
220 GtkWidget *confirm_area;
226 GtkWidget *action_label;
227 GtkWidget *recip_label;
228 GtkWidget *action_combo;
229 GtkWidget *action_type_list;
230 GtkWidget *account_list;
231 GtkWidget *dest_label;
232 GtkWidget *exec_label;
233 GtkWidget *score_label;
234 GtkWidget *color_label;
235 GtkWidget *account_label;
236 GtkWidget *account_combo;
237 GtkWidget *dest_entry;
245 GtkWidget *subst_btn;
248 GtkWidget *action_hbox;
249 GtkWidget *action_scrolledwin;
250 GtkWidget *action_clist;
258 GtkWidget *color_optmenu;
266 debug_print("Creating matcher configuration window...\n");
268 window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
269 gtk_container_set_border_width(GTK_CONTAINER(window), 8);
270 gtk_window_set_position(GTK_WINDOW(window), GTK_WIN_POS_CENTER);
271 gtk_window_set_modal(GTK_WINDOW(window), TRUE);
272 gtk_window_set_resizable(GTK_WINDOW(window), TRUE);
274 vbox = gtk_vbox_new(FALSE, 6);
275 gtk_widget_show(vbox);
276 gtk_container_add(GTK_CONTAINER(window), vbox);
278 gtkut_button_set_create(&confirm_area, &ok_btn, _("OK"),
279 &cancel_btn, _("Cancel"), NULL, NULL);
280 gtk_widget_show(confirm_area);
281 gtk_box_pack_end(GTK_BOX(vbox), confirm_area, FALSE, FALSE, 0);
282 gtk_widget_grab_default(ok_btn);
284 gtk_window_set_title(GTK_WINDOW(window),
285 _("Filtering action configuration"));
286 g_signal_connect(G_OBJECT(window), "delete_event",
287 G_CALLBACK(prefs_filtering_action_deleted), NULL);
288 g_signal_connect(G_OBJECT(window), "key_press_event",
289 G_CALLBACK(prefs_filtering_action_key_pressed), NULL);
290 MANAGE_WINDOW_SIGNALS_CONNECT(window);
291 g_signal_connect(G_OBJECT(ok_btn), "clicked",
292 G_CALLBACK(prefs_filtering_action_ok), NULL);
293 g_signal_connect(G_OBJECT(cancel_btn), "clicked",
294 G_CALLBACK(prefs_filtering_action_cancel), NULL);
296 vbox1 = gtk_vbox_new(FALSE, VSPACING);
297 gtk_widget_show(vbox1);
298 gtk_box_pack_start(GTK_BOX(vbox), vbox1, TRUE, TRUE, 0);
299 gtk_container_set_border_width(GTK_CONTAINER (vbox1), 2);
301 /* action to be defined */
303 hbox1 = gtk_hbox_new (FALSE, VSPACING);
304 gtk_widget_show (hbox1);
305 gtk_box_pack_start (GTK_BOX (vbox1), hbox1, FALSE, FALSE, 0);
306 gtk_container_set_border_width (GTK_CONTAINER (vbox1), 2);
308 action_label = gtk_label_new (_("Action"));
309 gtk_widget_show (action_label);
310 gtk_misc_set_alignment (GTK_MISC (action_label), 0, 0.5);
311 gtk_box_pack_start (GTK_BOX (hbox1), action_label, FALSE, FALSE, 0);
313 action_combo = gtk_combo_new ();
314 gtk_widget_show (action_combo);
315 gtk_entry_set_editable(GTK_ENTRY(GTK_COMBO(action_combo)->entry),
319 for (i = 0; i < sizeof action_text / sizeof action_text[0]; i++)
320 combo_items = g_list_append
321 (combo_items, (gpointer) _(action_text[i].text));
322 gtk_combo_set_popdown_strings(GTK_COMBO(action_combo), combo_items);
324 g_list_free(combo_items);
326 gtk_box_pack_start (GTK_BOX (hbox1), action_combo,
328 action_type_list = GTK_COMBO(action_combo)->list;
329 g_signal_connect (G_OBJECT(action_type_list), "select-child",
330 G_CALLBACK(prefs_filtering_action_type_select),
333 g_signal_connect(G_OBJECT(action_type_list), "selection-changed",
334 G_CALLBACK(prefs_filtering_action_type_selection_changed),
339 hbox1 = gtk_hbox_new (FALSE, VSPACING);
340 gtk_widget_show (vbox1);
341 gtk_box_pack_start (GTK_BOX (vbox1), hbox1, FALSE, FALSE, 0);
342 gtk_container_set_border_width (GTK_CONTAINER (vbox1), 2);
344 account_label = gtk_label_new (_("Account"));
345 gtk_widget_show (account_label);
346 gtk_misc_set_alignment (GTK_MISC (account_label), 0, 0.5);
347 gtk_box_pack_start (GTK_BOX (hbox1), account_label, FALSE, FALSE, 0);
349 account_combo = gtk_combo_new ();
350 gtk_widget_set_usize (account_combo, 150, -1);
351 gtk_widget_show (account_combo);
354 for (accounts = account_get_list() ; accounts != NULL;
355 accounts = accounts->next) {
356 PrefsAccount *ac = (PrefsAccount *)accounts->data;
359 name = g_strdup_printf("%s <%s> (%s)",
360 ac->name, ac->address,
362 combo_items = g_list_append(combo_items, (gpointer) name);
365 gtk_combo_set_popdown_strings(GTK_COMBO(account_combo), combo_items);
367 for(cur = g_list_first(combo_items) ; cur != NULL ;
368 cur = g_list_next(cur))
370 g_list_free(combo_items);
372 gtk_box_pack_start (GTK_BOX (hbox1), account_combo,
374 account_list = GTK_COMBO(account_combo)->list;
375 gtk_entry_set_editable(GTK_ENTRY(GTK_COMBO(account_combo)->entry),
380 hbox1 = gtk_hbox_new (FALSE, VSPACING);
381 gtk_widget_show (vbox1);
382 gtk_box_pack_start (GTK_BOX (vbox1), hbox1, FALSE, FALSE, 0);
383 gtk_container_set_border_width (GTK_CONTAINER (vbox1), 2);
385 dest_label = gtk_label_new (_("Destination"));
386 gtk_widget_show (dest_label);
387 gtk_misc_set_alignment (GTK_MISC (dest_label), 0, 0.5);
388 gtk_box_pack_start (GTK_BOX (hbox1), dest_label, FALSE, FALSE, 0);
390 recip_label = gtk_label_new (_("Recipient"));
391 gtk_widget_show (recip_label);
392 gtk_misc_set_alignment (GTK_MISC (recip_label), 0, 0.5);
393 gtk_box_pack_start (GTK_BOX (hbox1), recip_label, FALSE, FALSE, 0);
395 exec_label = gtk_label_new (_("Execute"));
396 gtk_widget_show (exec_label);
397 gtk_misc_set_alignment (GTK_MISC (exec_label), 0, 0.5);
398 gtk_box_pack_start (GTK_BOX (hbox1), exec_label, FALSE, FALSE, 0);
400 color_label = gtk_label_new (_("Color"));
401 gtk_widget_show(color_label);
402 gtk_misc_set_alignment(GTK_MISC(color_label), 0, 0.5);
403 gtk_box_pack_start(GTK_BOX(hbox1), color_label, FALSE, FALSE, 0);
405 score_label = gtk_label_new (_("Score"));
406 gtk_widget_show (score_label);
407 gtk_misc_set_alignment (GTK_MISC (score_label), 0, 0.5);
408 gtk_box_pack_start (GTK_BOX (hbox1), score_label, FALSE, FALSE, 0);
410 dest_entry = gtk_entry_new ();
411 gtk_widget_set_usize (dest_entry, 150, -1);
412 gtk_widget_show (dest_entry);
413 gtk_box_pack_start (GTK_BOX (hbox1), dest_entry, TRUE, TRUE, 0);
415 color_optmenu = gtk_option_menu_new();
416 gtk_option_menu_set_menu(GTK_OPTION_MENU(color_optmenu),
417 colorlabel_create_color_menu());
418 gtk_box_pack_start(GTK_BOX(hbox1), color_optmenu, TRUE, TRUE, 0);
420 dest_btn = gtk_button_new_with_label (_("Select ..."));
421 gtk_widget_show (dest_btn);
422 gtk_box_pack_start (GTK_BOX (hbox1), dest_btn, FALSE, FALSE, 0);
423 g_signal_connect (G_OBJECT (dest_btn), "clicked",
424 G_CALLBACK(prefs_filtering_action_select_dest),
427 exec_btn = gtk_button_new_with_label (_("Info ..."));
428 gtk_widget_show (exec_btn);
429 gtk_box_pack_start (GTK_BOX (hbox1), exec_btn, FALSE, FALSE, 0);
430 g_signal_connect (G_OBJECT (exec_btn), "clicked",
431 G_CALLBACK(prefs_filtering_action_exec_info),
434 /* register / substitute / delete */
436 reg_hbox = gtk_hbox_new(FALSE, 4);
437 gtk_widget_show(reg_hbox);
438 gtk_box_pack_start(GTK_BOX(vbox1), reg_hbox, FALSE, FALSE, 0);
440 arrow = gtk_arrow_new(GTK_ARROW_DOWN, GTK_SHADOW_OUT);
441 gtk_widget_show(arrow);
442 gtk_box_pack_start(GTK_BOX(reg_hbox), arrow, FALSE, FALSE, 0);
443 gtk_widget_set_usize(arrow, -1, 16);
445 btn_hbox = gtk_hbox_new(TRUE, 4);
446 gtk_widget_show(btn_hbox);
447 gtk_box_pack_start(GTK_BOX(reg_hbox), btn_hbox, FALSE, FALSE, 0);
449 reg_btn = gtk_button_new_with_label(_("Add"));
450 gtk_widget_show(reg_btn);
451 gtk_box_pack_start(GTK_BOX(btn_hbox), reg_btn, FALSE, TRUE, 0);
452 g_signal_connect(G_OBJECT(reg_btn), "clicked",
453 G_CALLBACK(prefs_filtering_action_register_cb), NULL);
455 subst_btn = gtk_button_new_with_label(_(" Replace "));
456 gtk_widget_show(subst_btn);
457 gtk_box_pack_start(GTK_BOX(btn_hbox), subst_btn, FALSE, TRUE, 0);
458 g_signal_connect(G_OBJECT(subst_btn), "clicked",
459 G_CALLBACK(prefs_filtering_action_substitute_cb),
462 del_btn = gtk_button_new_with_label(_("Delete"));
463 gtk_widget_show(del_btn);
464 gtk_box_pack_start(GTK_BOX(btn_hbox), del_btn, FALSE, TRUE, 0);
465 g_signal_connect(G_OBJECT(del_btn), "clicked",
466 G_CALLBACK(prefs_filtering_action_delete_cb), NULL);
468 action_hbox = gtk_hbox_new(FALSE, 8);
469 gtk_widget_show(action_hbox);
470 gtk_box_pack_start(GTK_BOX(vbox1), action_hbox, TRUE, TRUE, 0);
472 action_scrolledwin = gtk_scrolled_window_new(NULL, NULL);
473 gtk_widget_show(action_scrolledwin);
474 gtk_widget_set_usize(action_scrolledwin, -1, 150);
475 gtk_box_pack_start(GTK_BOX(action_hbox), action_scrolledwin,
477 gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(action_scrolledwin),
478 GTK_POLICY_AUTOMATIC,
479 GTK_POLICY_AUTOMATIC);
481 title[0] = _("Current action list");
482 action_clist = gtk_clist_new_with_titles(1, title);
483 gtk_widget_show(action_clist);
484 gtk_container_add(GTK_CONTAINER(action_scrolledwin), action_clist);
485 gtk_clist_set_column_width(GTK_CLIST(action_clist), 0, 80);
486 gtk_clist_set_selection_mode(GTK_CLIST(action_clist),
487 GTK_SELECTION_BROWSE);
488 GTK_WIDGET_UNSET_FLAGS(GTK_CLIST(action_clist)->column[0].button,
490 g_signal_connect(G_OBJECT(action_clist), "select_row",
491 G_CALLBACK(prefs_filtering_action_select), NULL);
493 btn_vbox = gtk_vbox_new(FALSE, 8);
494 gtk_widget_show(btn_vbox);
495 gtk_box_pack_start(GTK_BOX(action_hbox), btn_vbox, FALSE, FALSE, 0);
497 up_btn = gtk_button_new_with_label(_("Up"));
498 gtk_widget_show(up_btn);
499 gtk_box_pack_start(GTK_BOX(btn_vbox), up_btn, FALSE, FALSE, 0);
500 g_signal_connect(G_OBJECT(up_btn), "clicked",
501 G_CALLBACK(prefs_filtering_action_up), NULL);
503 down_btn = gtk_button_new_with_label(_("Down"));
504 gtk_widget_show(down_btn);
505 gtk_box_pack_start(GTK_BOX(btn_vbox), down_btn, FALSE, FALSE, 0);
506 g_signal_connect(G_OBJECT(down_btn), "clicked",
507 G_CALLBACK(prefs_filtering_action_down), NULL);
509 gtk_widget_show_all(window);
511 filtering_action.window = window;
512 filtering_action.action_type_list = action_type_list;
513 filtering_action.action_combo = action_combo;
514 filtering_action.account_label = account_label;
515 filtering_action.account_list = account_list;
516 filtering_action.account_combo = account_combo;
517 filtering_action.dest_entry = dest_entry;
518 filtering_action.dest_btn = dest_btn;
519 filtering_action.dest_label = dest_label;
520 filtering_action.recip_label = recip_label;
521 filtering_action.exec_label = exec_label;
522 filtering_action.exec_btn = exec_btn;
523 filtering_action.color_label = color_label;
524 filtering_action.color_optmenu = color_optmenu;
525 filtering_action.score_label = score_label;
526 filtering_action.ok_btn = ok_btn;
527 filtering_action.action_clist = action_clist;
531 *\brief Set the contents of a row
533 *\param row Index of row to set
534 *\param prop Condition to set
536 *\return gint Row index \a prop has been added
538 static gint prefs_filtering_action_clist_set_row(gint row, FilteringAction *action)
540 GtkCList *clist = GTK_CLIST(filtering_action.action_clist);
541 gchar *action_tab_str[1];
545 if (action == NULL) {
546 action_tab_str[0] = _("(New)");
547 return gtk_clist_append(clist, action_tab_str);
550 filteringaction_to_string(buf, sizeof buf, action);
551 action_str = g_strdup(buf);
553 action_tab_str[0] = action_str;
555 row = gtk_clist_append(clist, action_tab_str);
557 gtk_clist_set_text(clist, row, 0, action_tab_str[0]);
564 *\brief Update scrollbar
566 static void prefs_filtering_action_update_hscrollbar(void)
568 gint optwidth = gtk_clist_optimal_column_width(GTK_CLIST(filtering_action.action_clist), 0);
569 gtk_clist_set_column_width(GTK_CLIST(filtering_action.action_clist), 0, optwidth);
573 *\brief Initializes dialog with a set of conditions
575 *\param matchers List of conditions
577 static void prefs_filtering_action_set_dialog(GSList *action_list)
579 GtkCList *clist = GTK_CLIST(filtering_action.action_clist);
582 gtk_clist_freeze(clist);
583 gtk_clist_clear(clist);
585 prefs_filtering_action_clist_set_row(-1, NULL);
586 if (action_list != NULL) {
587 for (cur = action_list; cur != NULL;
588 cur = g_slist_next(cur)) {
589 FilteringAction *action;
590 action = (FilteringAction *) cur->data;
591 prefs_filtering_action_clist_set_row(-1, action);
595 prefs_filtering_action_update_hscrollbar();
597 gtk_clist_thaw(clist);
599 prefs_filtering_action_reset_dialog();
603 *\brief Converts current actions in list box in
604 * an action list used by the filtering system.
606 *\return GSList * List of actions.
608 static GSList *prefs_filtering_action_get_list(void)
616 while (gtk_clist_get_text(GTK_CLIST(filtering_action.action_clist),
617 row, 0, &action_str)) {
619 if (strcmp(action_str, _("(New)")) != 0) {
620 GSList * tmp_action_list;
621 tmp_action_list = matcher_parser_get_action_list(action_str);
623 if (tmp_action_list == NULL)
626 action_list = g_slist_concat(action_list,
636 *\brief Returns account ID from the given list index
638 *\return gint account ID
640 static gint get_account_id_from_list_id(gint list_id)
644 for (accounts = account_get_list() ; accounts != NULL;
645 accounts = accounts->next) {
646 PrefsAccount *ac = (PrefsAccount *)accounts->data;
649 return ac->account_id;
656 *\brief Returns list index from the given account ID
658 *\return gint list index
660 static gint get_list_id_from_account_id(gint account_id)
665 for (accounts = account_get_list() ; accounts != NULL;
666 accounts = accounts->next) {
667 PrefsAccount *ac = (PrefsAccount *)accounts->data;
669 if (account_id == ac->account_id)
678 *\brief Returns parser action ID from internal action ID
680 *\return gint parser action ID
682 static gint prefs_filtering_action_get_matching_from_action(Action action_id)
686 return MATCHACTION_MOVE;
688 return MATCHACTION_COPY;
690 return MATCHACTION_DELETE;
692 return MATCHACTION_MARK;
694 return MATCHACTION_UNMARK;
696 return MATCHACTION_LOCK;
698 return MATCHACTION_UNLOCK;
699 case ACTION_MARK_AS_READ:
700 return MATCHACTION_MARK_AS_READ;
701 case ACTION_MARK_AS_UNREAD:
702 return MATCHACTION_MARK_AS_UNREAD;
704 return MATCHACTION_FORWARD;
705 case ACTION_FORWARD_AS_ATTACHMENT:
706 return MATCHACTION_FORWARD_AS_ATTACHMENT;
707 case ACTION_REDIRECT:
708 return MATCHACTION_REDIRECT;
710 return MATCHACTION_EXECUTE;
712 return MATCHACTION_COLOR;
714 return MATCHACTION_HIDE;
716 return MATCHACTION_STOP;
717 case ACTION_CHANGE_SCORE:
718 return MATCHACTION_CHANGE_SCORE;
719 case ACTION_SET_SCORE:
720 return MATCHACTION_SET_SCORE;
727 *\brief Returns action from the content of the dialog
729 *\param alert specifies whether alert dialog boxes should be shown
732 *\return FilteringAction * action entered in the dialog box.
734 static FilteringAction * prefs_filtering_action_dialog_to_action(gboolean alert)
740 gchar * destination = NULL;
742 FilteringAction * action;
743 gchar * score_str = NULL;
746 action_id = get_sel_from_list(GTK_LIST(filtering_action.action_type_list));
747 action_type = prefs_filtering_action_get_matching_from_action(action_id);
748 list_id = get_sel_from_list(GTK_LIST(filtering_action.account_list));
749 account_id = get_account_id_from_list_id(list_id);
757 destination = gtk_editable_get_chars(GTK_EDITABLE(filtering_action.dest_entry), 0, -1);
758 if (*destination == '\0') {
760 alertpanel_error(action_id == ACTION_EXECUTE
761 ? _("Command line not set")
762 : _("Destination is not set."));
768 case ACTION_FORWARD_AS_ATTACHMENT:
769 case ACTION_REDIRECT:
770 destination = gtk_editable_get_chars(GTK_EDITABLE(filtering_action.dest_entry), 0, -1);
771 if (*destination == '\0') {
773 alertpanel_error(_("Recipient is not set."));
779 labelcolor = colorlabel_get_color_menu_active_item(
780 gtk_option_menu_get_menu(GTK_OPTION_MENU(filtering_action.color_optmenu)));
783 case ACTION_CHANGE_SCORE:
784 case ACTION_SET_SCORE:
785 score_str = gtk_editable_get_chars(GTK_EDITABLE(filtering_action.dest_entry), 0, -1);
786 if (*score_str == '\0') {
788 alertpanel_error(_("Score is not set"));
792 score = strtol(score_str, NULL, 10);
801 case ACTION_MARK_AS_READ:
802 case ACTION_MARK_AS_UNREAD:
807 action = filteringaction_new(action_type, account_id,
808 destination, labelcolor, score);
816 *\brief Signal handler for register button
818 static void prefs_filtering_action_register_cb(void)
820 FilteringAction *action;
822 action = prefs_filtering_action_dialog_to_action(TRUE);
826 prefs_filtering_action_clist_set_row(-1, action);
828 filteringaction_free(action);
829 /* presumably gtk_list_select_item(), called by
830 * prefs_filtering_action_reset_dialog() activates
831 * what seems to be a bug. this causes any other
832 * list items to be unselectable */
833 /* prefs_filtering_action_reset_dialog(); */
834 gtk_list_select_item(GTK_LIST(filtering_action.account_list), 0);
835 gtk_entry_set_text(GTK_ENTRY(filtering_action.dest_entry), "");
836 prefs_filtering_action_update_hscrollbar();
840 *\brief Signal handler for substitute button
842 static void prefs_filtering_action_substitute_cb(void)
844 GtkCList *clist = GTK_CLIST(filtering_action.action_clist);
846 FilteringAction *action;
848 if (!clist->selection) return;
849 row = GPOINTER_TO_INT(clist->selection->data);
853 action = prefs_filtering_action_dialog_to_action(TRUE);
857 prefs_filtering_action_clist_set_row(row, action);
859 filteringaction_free(action);
861 prefs_filtering_action_reset_dialog();
863 prefs_filtering_action_update_hscrollbar();
867 *\brief Signal handler for delete button
869 static void prefs_filtering_action_delete_cb(void)
871 GtkCList *clist = GTK_CLIST(filtering_action.action_clist);
874 if (!clist->selection) return;
875 row = GPOINTER_TO_INT(clist->selection->data);
879 gtk_clist_remove(clist, row);
881 prefs_filtering_action_reset_dialog();
883 prefs_filtering_action_update_hscrollbar();
887 *\brief Signal handler for 'move up' button
889 static void prefs_filtering_action_up(void)
891 GtkCList *clist = GTK_CLIST(filtering_action.action_clist);
894 if (!clist->selection) return;
896 row = GPOINTER_TO_INT(clist->selection->data);
898 gtk_clist_row_move(clist, row, row - 1);
899 if (gtk_clist_row_is_visible(clist, row - 1) != GTK_VISIBILITY_FULL)
900 gtk_clist_moveto(clist, row - 1, 0, 0, 0);
905 *\brief Signal handler for 'move down' button
907 static void prefs_filtering_action_down(void)
909 GtkCList *clist = GTK_CLIST(filtering_action.action_clist);
912 if (!clist->selection) return;
914 row = GPOINTER_TO_INT(clist->selection->data);
915 if (row >= 1 && row < clist->rows - 1) {
916 gtk_clist_row_move(clist, row, row + 1);
917 if (gtk_clist_row_is_visible(clist, row + 1) != GTK_VISIBILITY_FULL)
918 gtk_clist_moveto(clist, row + 1, 0, 1, 0);
923 *\brief Signal handler for select row.
925 *\param clist List widget
926 *\param row Selected row
927 *\param column Selected column
928 *\param event Event information
930 static void prefs_filtering_action_select(GtkCList *clist,
931 gint row, gint column, GdkEvent *event)
934 FilteringAction *action;
935 GSList * action_list;
938 if (!gtk_clist_get_text(GTK_CLIST(filtering_action.action_clist),
939 row, 0, &action_str))
943 prefs_filtering_action_reset_dialog();
947 action_list = matcher_parser_get_action_list(action_str);
948 if (action_list == NULL)
951 action = action_list->data;
952 g_slist_free(action_list);
954 if (action->destination)
955 gtk_entry_set_text(GTK_ENTRY(filtering_action.dest_entry), action->destination);
957 gtk_entry_set_text(GTK_ENTRY(filtering_action.dest_entry), "");
959 switch(action->type) {
960 case MATCHACTION_MOVE:
961 gtk_list_select_item(GTK_LIST(filtering_action.action_type_list),
964 case MATCHACTION_COPY:
965 gtk_list_select_item(GTK_LIST(filtering_action.action_type_list),
968 case MATCHACTION_DELETE:
969 gtk_list_select_item(GTK_LIST(filtering_action.action_type_list),
972 case MATCHACTION_MARK:
973 gtk_list_select_item(GTK_LIST(filtering_action.action_type_list),
976 case MATCHACTION_UNMARK:
977 gtk_list_select_item(GTK_LIST(filtering_action.action_type_list),
980 case MATCHACTION_LOCK:
981 gtk_list_select_item(GTK_LIST(filtering_action.action_type_list),
984 case MATCHACTION_UNLOCK:
985 gtk_list_select_item(GTK_LIST(filtering_action.action_type_list),
988 case MATCHACTION_MARK_AS_READ:
989 gtk_list_select_item(GTK_LIST(filtering_action.action_type_list),
990 ACTION_MARK_AS_READ);
992 case MATCHACTION_MARK_AS_UNREAD:
993 gtk_list_select_item(GTK_LIST(filtering_action.action_type_list),
994 ACTION_MARK_AS_UNREAD);
996 case MATCHACTION_FORWARD:
997 list_id = get_list_id_from_account_id(action->account_id);
998 gtk_list_select_item(GTK_LIST(filtering_action.action_type_list),
1000 gtk_list_select_item(GTK_LIST(filtering_action.account_list),
1003 case MATCHACTION_FORWARD_AS_ATTACHMENT:
1004 list_id = get_list_id_from_account_id(action->account_id);
1005 gtk_list_select_item(GTK_LIST(filtering_action.action_type_list),
1006 ACTION_FORWARD_AS_ATTACHMENT);
1007 gtk_list_select_item(GTK_LIST(filtering_action.account_list),
1010 case MATCHACTION_REDIRECT:
1011 list_id = get_list_id_from_account_id(action->account_id);
1012 gtk_list_select_item(GTK_LIST(filtering_action.action_type_list),
1014 gtk_list_select_item(GTK_LIST(filtering_action.account_list),
1017 case MATCHACTION_EXECUTE:
1018 gtk_list_select_item(GTK_LIST(filtering_action.action_type_list),
1021 case MATCHACTION_COLOR:
1022 gtk_list_select_item(GTK_LIST(filtering_action.action_type_list),
1024 gtk_option_menu_set_history(GTK_OPTION_MENU(filtering_action.color_optmenu), action->labelcolor);
1026 case MATCHACTION_CHANGE_SCORE:
1027 gtk_list_select_item(GTK_LIST(filtering_action.action_type_list),
1028 ACTION_CHANGE_SCORE);
1030 case MATCHACTION_SET_SCORE:
1031 gtk_list_select_item(GTK_LIST(filtering_action.action_type_list),
1034 case MATCHACTION_STOP:
1035 gtk_list_select_item(GTK_LIST(filtering_action.action_type_list),
1038 case MATCHACTION_HIDE:
1039 gtk_list_select_item(GTK_LIST(filtering_action.action_type_list),
1046 *\brief Handle key press
1048 *\param widget Widget receiving key press
1049 *\param event Key event
1050 *\param data User data
1052 static gboolean prefs_filtering_action_key_pressed(GtkWidget *widget,
1053 GdkEventKey *event, gpointer data)
1055 if (event && event->keyval == GDK_Escape) {
1056 prefs_filtering_action_cancel();
1063 *\brief Cancel matcher dialog
1065 static void prefs_filtering_action_cancel(void)
1067 gtk_widget_hide(filtering_action.window);
1072 *\brief Accept current matchers
1074 static void prefs_filtering_action_ok(void)
1076 GSList * action_list;
1079 action_list = prefs_filtering_action_get_list();
1081 if (action_list == NULL) {
1082 alertpanel_error(_("No action was defined."));
1086 if (filtering_action_callback != NULL)
1087 filtering_action_callback(action_list);
1088 for(cur = action_list ; cur != NULL ; cur = cur->next) {
1089 filteringaction_free(cur->data);
1091 g_slist_free(action_list);
1093 gtk_widget_hide(filtering_action.window);
1098 *\brief Called when closing dialog box
1100 *\param widget Dialog widget
1101 *\param event Event info
1102 *\param data User data
1106 static gint prefs_filtering_action_deleted(GtkWidget *widget,
1107 GdkEventAny *event, gpointer data)
1109 prefs_filtering_action_cancel();
1114 * Strings describing exec format strings
1116 * When adding new lines, remember to put 2 strings for each line
1118 static gchar *exec_desc_strings[] = {
1120 "%s", N_("Subject"),
1125 "%i", N_("Message-ID"),
1126 "%n", N_("Newsgroups"),
1127 "%r", N_("References"),
1128 "%F", N_("Filename - should not be modified"),
1129 "\\n", N_("new line"),
1130 "\\", N_("escape character for quotes"),
1131 "\\\"",N_("quote character"),
1135 static DescriptionWindow exec_desc_win = {
1138 N_("Description of symbols"),
1145 *\brief Show Execute action's info
1147 void prefs_filtering_action_exec_info(void)
1149 description_window_create(&exec_desc_win);
1152 static void prefs_filtering_action_select_dest(void)
1157 dest = foldersel_folder_sel(NULL, FOLDER_SEL_COPY, NULL);
1160 path = folder_item_get_identifier(dest);
1162 gtk_entry_set_text(GTK_ENTRY(filtering_action.dest_entry), path);
1166 static void prefs_filtering_action_type_selection_changed(GtkList *list,
1171 value = get_sel_from_list(GTK_LIST(filtering_action.action_type_list));
1173 if (filtering_action.current_action != value) {
1174 if (filtering_action.current_action == ACTION_FORWARD
1175 || filtering_action.current_action == ACTION_FORWARD_AS_ATTACHMENT
1176 || filtering_action.current_action == ACTION_REDIRECT) {
1177 debug_print("unregistering address completion entry\n");
1178 address_completion_unregister_entry(GTK_ENTRY(filtering_action.dest_entry));
1180 if (value == ACTION_FORWARD || value == ACTION_FORWARD_AS_ATTACHMENT
1181 || value == ACTION_REDIRECT) {
1182 debug_print("registering address completion entry\n");
1183 address_completion_register_entry(GTK_ENTRY(filtering_action.dest_entry));
1185 filtering_action.current_action = value;
1189 static void prefs_filtering_action_type_select(GtkList *list,
1190 GtkWidget *widget, gpointer user_data)
1194 value = (Action) get_sel_from_list(GTK_LIST(filtering_action.action_type_list));
1198 gtk_widget_show(filtering_action.account_label);
1199 gtk_widget_set_sensitive(filtering_action.account_label, FALSE);
1200 gtk_widget_set_sensitive(filtering_action.account_combo, FALSE);
1201 gtk_widget_show(filtering_action.dest_entry);
1202 gtk_widget_set_sensitive(filtering_action.dest_entry, TRUE);
1203 gtk_widget_show(filtering_action.dest_btn);
1204 gtk_widget_set_sensitive(filtering_action.dest_btn, TRUE);
1205 gtk_widget_show(filtering_action.dest_label);
1206 gtk_widget_set_sensitive(filtering_action.dest_label, TRUE);
1207 gtk_widget_hide(filtering_action.recip_label);
1208 gtk_widget_hide(filtering_action.exec_label);
1209 gtk_widget_hide(filtering_action.exec_btn);
1210 gtk_widget_hide(filtering_action.color_optmenu);
1211 gtk_widget_hide(filtering_action.color_label);
1212 gtk_widget_hide(filtering_action.score_label);
1215 gtk_widget_show(filtering_action.account_label);
1216 gtk_widget_set_sensitive(filtering_action.account_label, FALSE);
1217 gtk_widget_set_sensitive(filtering_action.account_combo, FALSE);
1218 gtk_widget_show(filtering_action.dest_entry);
1219 gtk_widget_set_sensitive(filtering_action.dest_entry, TRUE);
1220 gtk_widget_show(filtering_action.dest_btn);
1221 gtk_widget_set_sensitive(filtering_action.dest_btn, TRUE);
1222 gtk_widget_show(filtering_action.dest_label);
1223 gtk_widget_set_sensitive(filtering_action.dest_label, TRUE);
1224 gtk_widget_hide(filtering_action.recip_label);
1225 gtk_widget_hide(filtering_action.exec_label);
1226 gtk_widget_hide(filtering_action.exec_btn);
1227 gtk_widget_hide(filtering_action.color_optmenu);
1228 gtk_widget_hide(filtering_action.color_label);
1229 gtk_widget_hide(filtering_action.score_label);
1232 gtk_widget_show(filtering_action.account_label);
1233 gtk_widget_set_sensitive(filtering_action.account_label, FALSE);
1234 gtk_widget_set_sensitive(filtering_action.account_combo, FALSE);
1235 gtk_widget_show(filtering_action.dest_entry);
1236 gtk_widget_set_sensitive(filtering_action.dest_entry, FALSE);
1237 gtk_widget_show(filtering_action.dest_btn);
1238 gtk_widget_set_sensitive(filtering_action.dest_btn, FALSE);
1239 gtk_widget_show(filtering_action.dest_label);
1240 gtk_widget_set_sensitive(filtering_action.dest_label, FALSE);
1241 gtk_widget_hide(filtering_action.recip_label);
1242 gtk_widget_hide(filtering_action.exec_label);
1243 gtk_widget_hide(filtering_action.exec_btn);
1244 gtk_widget_hide(filtering_action.color_optmenu);
1245 gtk_widget_hide(filtering_action.color_label);
1246 gtk_widget_hide(filtering_action.score_label);
1252 case ACTION_MARK_AS_READ:
1253 case ACTION_MARK_AS_UNREAD:
1256 gtk_widget_show(filtering_action.account_label);
1257 gtk_widget_set_sensitive(filtering_action.account_label, FALSE);
1258 gtk_widget_set_sensitive(filtering_action.account_combo, FALSE);
1259 gtk_widget_show(filtering_action.dest_entry);
1260 gtk_widget_set_sensitive(filtering_action.dest_entry, FALSE);
1261 gtk_widget_show(filtering_action.dest_btn);
1262 gtk_widget_set_sensitive(filtering_action.dest_btn, FALSE);
1263 gtk_widget_show(filtering_action.dest_label);
1264 gtk_widget_set_sensitive(filtering_action.dest_label, FALSE);
1265 gtk_widget_hide(filtering_action.recip_label);
1266 gtk_widget_hide(filtering_action.exec_label);
1267 gtk_widget_hide(filtering_action.exec_btn);
1268 gtk_widget_hide(filtering_action.color_optmenu);
1269 gtk_widget_hide(filtering_action.color_label);
1270 gtk_widget_hide(filtering_action.score_label);
1272 case ACTION_FORWARD:
1273 gtk_widget_show(filtering_action.account_label);
1274 gtk_widget_set_sensitive(filtering_action.account_label, TRUE);
1275 gtk_widget_set_sensitive(filtering_action.account_combo, TRUE);
1276 gtk_widget_show(filtering_action.dest_entry);
1277 gtk_widget_set_sensitive(filtering_action.dest_entry, TRUE);
1278 gtk_widget_show(filtering_action.dest_btn);
1279 gtk_widget_set_sensitive(filtering_action.dest_btn, FALSE);
1280 gtk_widget_hide(filtering_action.dest_label);
1281 gtk_widget_show(filtering_action.recip_label);
1282 gtk_widget_set_sensitive(filtering_action.recip_label, TRUE);
1283 gtk_widget_hide(filtering_action.exec_label);
1284 gtk_widget_hide(filtering_action.exec_btn);
1285 gtk_widget_hide(filtering_action.color_optmenu);
1286 gtk_widget_hide(filtering_action.color_label);
1287 gtk_widget_hide(filtering_action.score_label);
1289 case ACTION_FORWARD_AS_ATTACHMENT:
1290 gtk_widget_show(filtering_action.account_label);
1291 gtk_widget_set_sensitive(filtering_action.account_label, TRUE);
1292 gtk_widget_set_sensitive(filtering_action.account_combo, TRUE);
1293 gtk_widget_show(filtering_action.dest_entry);
1294 gtk_widget_set_sensitive(filtering_action.dest_entry, TRUE);
1295 gtk_widget_show(filtering_action.dest_btn);
1296 gtk_widget_set_sensitive(filtering_action.dest_btn, FALSE);
1297 gtk_widget_hide(filtering_action.dest_label);
1298 gtk_widget_show(filtering_action.recip_label);
1299 gtk_widget_set_sensitive(filtering_action.recip_label, TRUE);
1300 gtk_widget_hide(filtering_action.exec_label);
1301 gtk_widget_hide(filtering_action.exec_btn);
1302 gtk_widget_hide(filtering_action.color_optmenu);
1303 gtk_widget_hide(filtering_action.color_label);
1304 gtk_widget_hide(filtering_action.score_label);
1306 case ACTION_REDIRECT:
1307 gtk_widget_show(filtering_action.account_label);
1308 gtk_widget_set_sensitive(filtering_action.account_label, TRUE);
1309 gtk_widget_set_sensitive(filtering_action.account_combo, TRUE);
1310 gtk_widget_show(filtering_action.dest_entry);
1311 gtk_widget_set_sensitive(filtering_action.dest_entry, TRUE);
1312 gtk_widget_show(filtering_action.dest_btn);
1313 gtk_widget_set_sensitive(filtering_action.dest_btn, FALSE);
1314 gtk_widget_hide(filtering_action.dest_label);
1315 gtk_widget_show(filtering_action.recip_label);
1316 gtk_widget_set_sensitive(filtering_action.recip_label, TRUE);
1317 gtk_widget_hide(filtering_action.exec_label);
1318 gtk_widget_hide(filtering_action.exec_btn);
1319 gtk_widget_hide(filtering_action.color_optmenu);
1320 gtk_widget_hide(filtering_action.color_label);
1321 gtk_widget_hide(filtering_action.score_label);
1323 case ACTION_EXECUTE:
1324 gtk_widget_show(filtering_action.account_label);
1325 gtk_widget_set_sensitive(filtering_action.account_label, FALSE);
1326 gtk_widget_set_sensitive(filtering_action.account_combo, FALSE);
1327 gtk_widget_show(filtering_action.dest_entry);
1328 gtk_widget_set_sensitive(filtering_action.dest_entry, TRUE);
1329 gtk_widget_hide(filtering_action.dest_btn);
1330 gtk_widget_hide(filtering_action.dest_label);
1331 gtk_widget_hide(filtering_action.recip_label);
1332 gtk_widget_show(filtering_action.exec_label);
1333 gtk_widget_set_sensitive(filtering_action.exec_btn, TRUE);
1334 gtk_widget_show(filtering_action.exec_btn);
1335 gtk_widget_hide(filtering_action.color_optmenu);
1336 gtk_widget_hide(filtering_action.color_label);
1337 gtk_widget_hide(filtering_action.score_label);
1340 gtk_widget_show(filtering_action.account_label);
1341 gtk_widget_set_sensitive(filtering_action.account_label, FALSE);
1342 gtk_widget_set_sensitive(filtering_action.account_combo, FALSE);
1343 gtk_widget_hide(filtering_action.dest_entry);
1344 gtk_widget_hide(filtering_action.dest_btn);
1345 gtk_widget_hide(filtering_action.dest_label);
1346 gtk_widget_hide(filtering_action.recip_label);
1347 gtk_widget_hide(filtering_action.exec_label);
1348 gtk_widget_show(filtering_action.exec_btn);
1349 gtk_widget_set_sensitive(filtering_action.exec_btn, FALSE);
1350 gtk_widget_show(filtering_action.color_optmenu);
1351 gtk_widget_show(filtering_action.color_label);
1352 gtk_widget_hide(filtering_action.score_label);
1354 case ACTION_CHANGE_SCORE:
1355 case ACTION_SET_SCORE:
1356 gtk_widget_show(filtering_action.account_label);
1357 gtk_widget_set_sensitive(filtering_action.account_label, FALSE);
1358 gtk_widget_set_sensitive(filtering_action.account_combo, FALSE);
1359 gtk_widget_show(filtering_action.dest_entry);
1360 gtk_widget_set_sensitive(filtering_action.dest_entry, TRUE);
1361 gtk_widget_hide(filtering_action.dest_btn);
1362 gtk_widget_hide(filtering_action.dest_label);
1363 gtk_widget_hide(filtering_action.recip_label);
1364 gtk_widget_hide(filtering_action.exec_label);
1365 gtk_widget_show(filtering_action.exec_btn);
1366 gtk_widget_set_sensitive(filtering_action.exec_btn, FALSE);
1367 gtk_widget_hide(filtering_action.color_optmenu);
1368 gtk_widget_hide(filtering_action.color_label);
1369 gtk_widget_show(filtering_action.score_label);
1374 static void prefs_filtering_action_reset_dialog(void)
1376 gtk_list_select_item(GTK_LIST(filtering_action.action_type_list), 0);
1377 gtk_list_select_item(GTK_LIST(filtering_action.account_list), 0);
1378 gtk_entry_set_text(GTK_ENTRY(filtering_action.dest_entry), "");