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,
125 /* add other action constants */
132 { N_("Move"), ACTION_MOVE },
133 { N_("Copy"), ACTION_COPY },
134 { N_("Delete"), ACTION_DELETE },
135 { N_("Mark"), ACTION_MARK },
136 { N_("Unmark"), ACTION_UNMARK },
137 { N_("Lock"), ACTION_LOCK },
138 { N_("Unlock"), ACTION_UNLOCK },
139 { N_("Mark as read"), ACTION_MARK_AS_READ },
140 { N_("Mark as unread"), ACTION_MARK_AS_UNREAD },
141 { N_("Forward"), ACTION_FORWARD },
142 { N_("Forward as attachment"), ACTION_FORWARD_AS_ATTACHMENT },
143 { N_("Redirect"), ACTION_REDIRECT },
144 { N_("Execute"), ACTION_EXECUTE },
145 { N_("Color"), ACTION_COLOR },
146 { N_("(In/de)crease score"), ACTION_ADD_SCORE},
147 { N_("Set score"), ACTION_SET_SCORE},
148 { N_("Stop filter"), ACTION_STOP },
155 static PrefsFilteringActionSignal *filtering_action_callback;
158 *\brief Find index of list selection
160 *\param list GTK list widget
162 *\return gint Selection index
164 static gint get_sel_from_list(GtkList *list)
170 if (list->selection == NULL)
173 sel = list->selection->data;
174 for (child = list->children; child != NULL; child = g_list_next(child)) {
175 if (child->data == sel)
184 *\brief Opens the filtering action dialog with a list of actions
186 *\param matchers List of conditions
190 void prefs_filtering_action_open(GSList *action_list,
191 PrefsFilteringActionSignal *cb)
195 if (!filtering_action.window) {
196 prefs_filtering_action_create();
199 manage_window_set_transient(GTK_WINDOW(filtering_action.window));
200 gtk_widget_grab_focus(filtering_action.ok_btn);
202 filtering_action_callback = cb;
204 prefs_filtering_action_set_dialog(action_list);
206 gtk_widget_show(filtering_action.window);
210 *\brief Create the matcher dialog
212 static void prefs_filtering_action_create(void)
217 GtkWidget *cancel_btn;
218 GtkWidget *confirm_area;
224 GtkWidget *action_label;
225 GtkWidget *recip_label;
226 GtkWidget *action_combo;
227 GtkWidget *action_type_list;
228 GtkWidget *account_list;
229 GtkWidget *dest_label;
230 GtkWidget *exec_label;
231 GtkWidget *score_label;
232 GtkWidget *color_label;
233 GtkWidget *account_label;
234 GtkWidget *account_combo;
235 GtkWidget *dest_entry;
243 GtkWidget *subst_btn;
246 GtkWidget *action_hbox;
247 GtkWidget *action_scrolledwin;
248 GtkWidget *action_clist;
256 GtkWidget *color_optmenu;
264 debug_print("Creating matcher configuration window...\n");
266 window = gtk_window_new(GTK_WINDOW_DIALOG);
267 gtk_container_set_border_width(GTK_CONTAINER(window), 8);
268 gtk_window_position(GTK_WINDOW(window), GTK_WIN_POS_CENTER);
269 gtk_window_set_modal(GTK_WINDOW(window), TRUE);
270 gtk_window_set_policy(GTK_WINDOW(window), FALSE, TRUE, FALSE);
272 vbox = gtk_vbox_new(FALSE, 6);
273 gtk_widget_show(vbox);
274 gtk_container_add(GTK_CONTAINER(window), vbox);
276 gtkut_button_set_create(&confirm_area, &ok_btn, _("OK"),
277 &cancel_btn, _("Cancel"), NULL, NULL);
278 gtk_widget_show(confirm_area);
279 gtk_box_pack_end(GTK_BOX(vbox), confirm_area, FALSE, FALSE, 0);
280 gtk_widget_grab_default(ok_btn);
282 gtk_window_set_title(GTK_WINDOW(window),
283 _("Filtering action configuration"));
284 gtk_signal_connect(GTK_OBJECT(window), "delete_event",
285 GTK_SIGNAL_FUNC(prefs_filtering_action_deleted), NULL);
286 gtk_signal_connect(GTK_OBJECT(window), "key_press_event",
287 GTK_SIGNAL_FUNC(prefs_filtering_action_key_pressed), NULL);
288 MANAGE_WINDOW_SIGNALS_CONNECT(window);
289 gtk_signal_connect(GTK_OBJECT(ok_btn), "clicked",
290 GTK_SIGNAL_FUNC(prefs_filtering_action_ok), NULL);
291 gtk_signal_connect(GTK_OBJECT(cancel_btn), "clicked",
292 GTK_SIGNAL_FUNC(prefs_filtering_action_cancel), NULL);
294 vbox1 = gtk_vbox_new(FALSE, VSPACING);
295 gtk_widget_show(vbox1);
296 gtk_box_pack_start(GTK_BOX(vbox), vbox1, TRUE, TRUE, 0);
297 gtk_container_set_border_width(GTK_CONTAINER (vbox1), 2);
299 /* action to be defined */
301 hbox1 = gtk_hbox_new (FALSE, VSPACING);
302 gtk_widget_show (hbox1);
303 gtk_box_pack_start (GTK_BOX (vbox1), hbox1, FALSE, FALSE, 0);
304 gtk_container_set_border_width (GTK_CONTAINER (vbox1), 2);
306 action_label = gtk_label_new (_("Action"));
307 gtk_widget_show (action_label);
308 gtk_misc_set_alignment (GTK_MISC (action_label), 0, 0.5);
309 gtk_box_pack_start (GTK_BOX (hbox1), action_label, FALSE, FALSE, 0);
311 action_combo = gtk_combo_new ();
312 gtk_widget_show (action_combo);
313 gtk_entry_set_editable(GTK_ENTRY(GTK_COMBO(action_combo)->entry),
317 for (i = 0; i < sizeof action_text / sizeof action_text[0]; i++)
318 combo_items = g_list_append
319 (combo_items, (gpointer) _(action_text[i].text));
320 gtk_combo_set_popdown_strings(GTK_COMBO(action_combo), combo_items);
322 g_list_free(combo_items);
324 gtk_box_pack_start (GTK_BOX (hbox1), action_combo,
326 action_type_list = GTK_COMBO(action_combo)->list;
327 gtk_signal_connect (GTK_OBJECT (action_type_list), "select-child",
328 GTK_SIGNAL_FUNC (prefs_filtering_action_type_select),
331 gtk_signal_connect(GTK_OBJECT(action_type_list), "selection-changed",
332 GTK_SIGNAL_FUNC(prefs_filtering_action_type_selection_changed),
337 hbox1 = gtk_hbox_new (FALSE, VSPACING);
338 gtk_widget_show (vbox1);
339 gtk_box_pack_start (GTK_BOX (vbox1), hbox1, FALSE, FALSE, 0);
340 gtk_container_set_border_width (GTK_CONTAINER (vbox1), 2);
342 account_label = gtk_label_new (_("Account"));
343 gtk_widget_show (account_label);
344 gtk_misc_set_alignment (GTK_MISC (account_label), 0, 0.5);
345 gtk_box_pack_start (GTK_BOX (hbox1), account_label, FALSE, FALSE, 0);
347 account_combo = gtk_combo_new ();
348 gtk_widget_set_usize (account_combo, 150, -1);
349 gtk_widget_show (account_combo);
352 for (accounts = account_get_list() ; accounts != NULL;
353 accounts = accounts->next) {
354 PrefsAccount *ac = (PrefsAccount *)accounts->data;
357 name = g_strdup_printf("%s <%s> (%s)",
358 ac->name, ac->address,
360 combo_items = g_list_append(combo_items, (gpointer) name);
363 gtk_combo_set_popdown_strings(GTK_COMBO(account_combo), combo_items);
365 for(cur = g_list_first(combo_items) ; cur != NULL ;
366 cur = g_list_next(cur))
368 g_list_free(combo_items);
370 gtk_box_pack_start (GTK_BOX (hbox1), account_combo,
372 account_list = GTK_COMBO(account_combo)->list;
373 gtk_entry_set_editable(GTK_ENTRY(GTK_COMBO(account_combo)->entry),
378 hbox1 = gtk_hbox_new (FALSE, VSPACING);
379 gtk_widget_show (vbox1);
380 gtk_box_pack_start (GTK_BOX (vbox1), hbox1, FALSE, FALSE, 0);
381 gtk_container_set_border_width (GTK_CONTAINER (vbox1), 2);
383 dest_label = gtk_label_new (_("Destination"));
384 gtk_widget_show (dest_label);
385 gtk_misc_set_alignment (GTK_MISC (dest_label), 0, 0.5);
386 gtk_box_pack_start (GTK_BOX (hbox1), dest_label, FALSE, FALSE, 0);
388 recip_label = gtk_label_new (_("Recipient"));
389 gtk_widget_show (recip_label);
390 gtk_misc_set_alignment (GTK_MISC (recip_label), 0, 0.5);
391 gtk_box_pack_start (GTK_BOX (hbox1), recip_label, FALSE, FALSE, 0);
393 exec_label = gtk_label_new (_("Execute"));
394 gtk_widget_show (exec_label);
395 gtk_misc_set_alignment (GTK_MISC (exec_label), 0, 0.5);
396 gtk_box_pack_start (GTK_BOX (hbox1), exec_label, FALSE, FALSE, 0);
398 color_label = gtk_label_new (_("Color"));
399 gtk_widget_show(color_label);
400 gtk_misc_set_alignment(GTK_MISC(color_label), 0, 0.5);
401 gtk_box_pack_start(GTK_BOX(hbox1), color_label, FALSE, FALSE, 0);
403 score_label = gtk_label_new (_("Score"));
404 gtk_widget_show (score_label);
405 gtk_misc_set_alignment (GTK_MISC (score_label), 0, 0.5);
406 gtk_box_pack_start (GTK_BOX (hbox1), score_label, FALSE, FALSE, 0);
408 dest_entry = gtk_entry_new ();
409 gtk_widget_set_usize (dest_entry, 150, -1);
410 gtk_widget_show (dest_entry);
411 gtk_box_pack_start (GTK_BOX (hbox1), dest_entry, TRUE, TRUE, 0);
413 color_optmenu = gtk_option_menu_new();
414 gtk_option_menu_set_menu(GTK_OPTION_MENU(color_optmenu),
415 colorlabel_create_color_menu());
416 gtk_box_pack_start(GTK_BOX(hbox1), color_optmenu, TRUE, TRUE, 0);
418 dest_btn = gtk_button_new_with_label (_("Select ..."));
419 gtk_widget_show (dest_btn);
420 gtk_box_pack_start (GTK_BOX (hbox1), dest_btn, FALSE, FALSE, 0);
421 gtk_signal_connect (GTK_OBJECT (dest_btn), "clicked",
422 GTK_SIGNAL_FUNC (prefs_filtering_action_select_dest),
425 exec_btn = gtk_button_new_with_label (_("Info ..."));
426 gtk_widget_show (exec_btn);
427 gtk_box_pack_start (GTK_BOX (hbox1), exec_btn, FALSE, FALSE, 0);
428 gtk_signal_connect (GTK_OBJECT (exec_btn), "clicked",
429 GTK_SIGNAL_FUNC (prefs_filtering_action_exec_info),
432 /* register / substitute / delete */
434 reg_hbox = gtk_hbox_new(FALSE, 4);
435 gtk_widget_show(reg_hbox);
436 gtk_box_pack_start(GTK_BOX(vbox1), reg_hbox, FALSE, FALSE, 0);
438 arrow = gtk_arrow_new(GTK_ARROW_DOWN, GTK_SHADOW_OUT);
439 gtk_widget_show(arrow);
440 gtk_box_pack_start(GTK_BOX(reg_hbox), arrow, FALSE, FALSE, 0);
441 gtk_widget_set_usize(arrow, -1, 16);
443 btn_hbox = gtk_hbox_new(TRUE, 4);
444 gtk_widget_show(btn_hbox);
445 gtk_box_pack_start(GTK_BOX(reg_hbox), btn_hbox, FALSE, FALSE, 0);
447 reg_btn = gtk_button_new_with_label(_("Add"));
448 gtk_widget_show(reg_btn);
449 gtk_box_pack_start(GTK_BOX(btn_hbox), reg_btn, FALSE, TRUE, 0);
450 gtk_signal_connect(GTK_OBJECT(reg_btn), "clicked",
451 GTK_SIGNAL_FUNC(prefs_filtering_action_register_cb), NULL);
453 subst_btn = gtk_button_new_with_label(_(" Replace "));
454 gtk_widget_show(subst_btn);
455 gtk_box_pack_start(GTK_BOX(btn_hbox), subst_btn, FALSE, TRUE, 0);
456 gtk_signal_connect(GTK_OBJECT(subst_btn), "clicked",
457 GTK_SIGNAL_FUNC(prefs_filtering_action_substitute_cb),
460 del_btn = gtk_button_new_with_label(_("Delete"));
461 gtk_widget_show(del_btn);
462 gtk_box_pack_start(GTK_BOX(btn_hbox), del_btn, FALSE, TRUE, 0);
463 gtk_signal_connect(GTK_OBJECT(del_btn), "clicked",
464 GTK_SIGNAL_FUNC(prefs_filtering_action_delete_cb), NULL);
466 action_hbox = gtk_hbox_new(FALSE, 8);
467 gtk_widget_show(action_hbox);
468 gtk_box_pack_start(GTK_BOX(vbox1), action_hbox, TRUE, TRUE, 0);
470 action_scrolledwin = gtk_scrolled_window_new(NULL, NULL);
471 gtk_widget_show(action_scrolledwin);
472 gtk_widget_set_usize(action_scrolledwin, -1, 150);
473 gtk_box_pack_start(GTK_BOX(action_hbox), action_scrolledwin,
475 gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(action_scrolledwin),
476 GTK_POLICY_AUTOMATIC,
477 GTK_POLICY_AUTOMATIC);
479 title[0] = _("Current action list");
480 action_clist = gtk_clist_new_with_titles(1, title);
481 gtk_widget_show(action_clist);
482 gtk_container_add(GTK_CONTAINER(action_scrolledwin), action_clist);
483 gtk_clist_set_column_width(GTK_CLIST(action_clist), 0, 80);
484 gtk_clist_set_selection_mode(GTK_CLIST(action_clist),
485 GTK_SELECTION_BROWSE);
486 GTK_WIDGET_UNSET_FLAGS(GTK_CLIST(action_clist)->column[0].button,
488 gtk_signal_connect(GTK_OBJECT(action_clist), "select_row",
489 GTK_SIGNAL_FUNC(prefs_filtering_action_select), NULL);
491 btn_vbox = gtk_vbox_new(FALSE, 8);
492 gtk_widget_show(btn_vbox);
493 gtk_box_pack_start(GTK_BOX(action_hbox), btn_vbox, FALSE, FALSE, 0);
495 up_btn = gtk_button_new_with_label(_("Up"));
496 gtk_widget_show(up_btn);
497 gtk_box_pack_start(GTK_BOX(btn_vbox), up_btn, FALSE, FALSE, 0);
498 gtk_signal_connect(GTK_OBJECT(up_btn), "clicked",
499 GTK_SIGNAL_FUNC(prefs_filtering_action_up), NULL);
501 down_btn = gtk_button_new_with_label(_("Down"));
502 gtk_widget_show(down_btn);
503 gtk_box_pack_start(GTK_BOX(btn_vbox), down_btn, FALSE, FALSE, 0);
504 gtk_signal_connect(GTK_OBJECT(down_btn), "clicked",
505 GTK_SIGNAL_FUNC(prefs_filtering_action_down), NULL);
507 gtk_widget_show_all(window);
509 filtering_action.window = window;
510 filtering_action.action_type_list = action_type_list;
511 filtering_action.action_combo = action_combo;
512 filtering_action.account_label = account_label;
513 filtering_action.account_list = account_list;
514 filtering_action.account_combo = account_combo;
515 filtering_action.dest_entry = dest_entry;
516 filtering_action.dest_btn = dest_btn;
517 filtering_action.dest_label = dest_label;
518 filtering_action.recip_label = recip_label;
519 filtering_action.exec_label = exec_label;
520 filtering_action.exec_btn = exec_btn;
521 filtering_action.color_label = color_label;
522 filtering_action.color_optmenu = color_optmenu;
523 filtering_action.score_label = score_label;
524 filtering_action.ok_btn = ok_btn;
525 filtering_action.action_clist = action_clist;
529 *\brief Set the contents of a row
531 *\param row Index of row to set
532 *\param prop Condition to set
534 *\return gint Row index \a prop has been added
536 static gint prefs_filtering_action_clist_set_row(gint row, FilteringAction *action)
538 GtkCList *clist = GTK_CLIST(filtering_action.action_clist);
539 gchar *action_tab_str[1];
543 if (action == NULL) {
544 action_tab_str[0] = _("(New)");
545 return gtk_clist_append(clist, action_tab_str);
548 filteringaction_to_string(buf, sizeof buf, action);
549 action_str = g_strdup(buf);
551 action_tab_str[0] = action_str;
553 row = gtk_clist_append(clist, action_tab_str);
555 gtk_clist_set_text(clist, row, 0, action_tab_str[0]);
562 *\brief Update scrollbar
564 static void prefs_filtering_action_update_hscrollbar(void)
566 gint optwidth = gtk_clist_optimal_column_width(GTK_CLIST(filtering_action.action_clist), 0);
567 gtk_clist_set_column_width(GTK_CLIST(filtering_action.action_clist), 0, optwidth);
571 *\brief Initializes dialog with a set of conditions
573 *\param matchers List of conditions
575 static void prefs_filtering_action_set_dialog(GSList *action_list)
577 GtkCList *clist = GTK_CLIST(filtering_action.action_clist);
580 gtk_clist_freeze(clist);
581 gtk_clist_clear(clist);
583 prefs_filtering_action_clist_set_row(-1, NULL);
584 if (action_list != NULL) {
585 for (cur = action_list; cur != NULL;
586 cur = g_slist_next(cur)) {
587 FilteringAction *action;
588 action = (FilteringAction *) cur->data;
589 prefs_filtering_action_clist_set_row(-1, action);
593 prefs_filtering_action_update_hscrollbar();
595 gtk_clist_thaw(clist);
597 prefs_filtering_action_reset_dialog();
601 *\brief Converts current actions in list box in
602 * an action list used by the filtering system.
604 *\return GSList * List of actions.
606 static GSList *prefs_filtering_action_get_list(void)
614 while (gtk_clist_get_text(GTK_CLIST(filtering_action.action_clist),
615 row, 0, &action_str)) {
617 if (strcmp(action_str, _("(New)")) != 0) {
618 GSList * tmp_action_list;
619 tmp_action_list = matcher_parser_get_action_list(action_str);
621 if (tmp_action_list == NULL)
624 action_list = g_slist_concat(action_list,
634 *\brief Returns account ID from the given list index
636 *\return gint account ID
638 static gint get_account_id_from_list_id(gint list_id)
642 for (accounts = account_get_list() ; accounts != NULL;
643 accounts = accounts->next) {
644 PrefsAccount *ac = (PrefsAccount *)accounts->data;
647 return ac->account_id;
654 *\brief Returns list index from the given account ID
656 *\return gint list index
658 static gint get_list_id_from_account_id(gint account_id)
663 for (accounts = account_get_list() ; accounts != NULL;
664 accounts = accounts->next) {
665 PrefsAccount *ac = (PrefsAccount *)accounts->data;
667 if (account_id == ac->account_id)
676 *\brief Returns parser action ID from internal action ID
678 *\return gint parser action ID
680 static gint prefs_filtering_action_get_matching_from_action(Action action_id)
684 return MATCHACTION_MOVE;
686 return MATCHACTION_COPY;
688 return MATCHACTION_DELETE;
690 return MATCHACTION_MARK;
692 return MATCHACTION_UNMARK;
694 return MATCHACTION_LOCK;
696 return MATCHACTION_UNLOCK;
697 case ACTION_MARK_AS_READ:
698 return MATCHACTION_MARK_AS_READ;
699 case ACTION_MARK_AS_UNREAD:
700 return MATCHACTION_MARK_AS_UNREAD;
702 return MATCHACTION_FORWARD;
703 case ACTION_FORWARD_AS_ATTACHMENT:
704 return MATCHACTION_FORWARD_AS_ATTACHMENT;
705 case ACTION_REDIRECT:
706 return MATCHACTION_REDIRECT;
708 return MATCHACTION_EXECUTE;
710 return MATCHACTION_COLOR;
712 return MATCHACTION_STOP;
713 case ACTION_ADD_SCORE:
714 return MATCHACTION_ADD_SCORE;
715 case ACTION_SET_SCORE:
716 return MATCHACTION_SET_SCORE;
723 *\brief Returns action from the content of the dialog
725 *\param alert specifies whether alert dialog boxes should be shown
728 *\return FilteringAction * action entered in the dialog box.
730 static FilteringAction * prefs_filtering_action_dialog_to_action(gboolean alert)
738 FilteringAction * action;
742 action_id = get_sel_from_list(GTK_LIST(filtering_action.action_type_list));
743 action_type = prefs_filtering_action_get_matching_from_action(action_id);
744 list_id = get_sel_from_list(GTK_LIST(filtering_action.account_list));
745 account_id = get_account_id_from_list_id(list_id);
753 destination = gtk_entry_get_text(GTK_ENTRY(filtering_action.dest_entry));
754 if (*destination == '\0') {
756 alertpanel_error(action_id == ACTION_EXECUTE
757 ? _("Command line not set")
758 : _("Destination is not set."));
763 case ACTION_FORWARD_AS_ATTACHMENT:
764 case ACTION_REDIRECT:
765 destination = gtk_entry_get_text(GTK_ENTRY(filtering_action.dest_entry));
766 if (*destination == '\0') {
768 alertpanel_error(_("Recipient is not set."));
773 labelcolor = colorlabel_get_color_menu_active_item(
774 gtk_option_menu_get_menu(GTK_OPTION_MENU(filtering_action.color_optmenu)));
777 case ACTION_ADD_SCORE:
778 case ACTION_SET_SCORE:
779 score_str = gtk_entry_get_text(GTK_ENTRY(filtering_action.dest_entry));
780 if (*score_str == '\0') {
782 alertpanel_error(_("Score is not set"));
785 score = strtol(score_str, NULL, 10);
793 case ACTION_MARK_AS_READ:
794 case ACTION_MARK_AS_UNREAD:
799 action = filteringaction_new(action_type, account_id,
800 destination, labelcolor, score);
806 *\brief Signal handler for register button
808 static void prefs_filtering_action_register_cb(void)
810 FilteringAction *action;
812 action = prefs_filtering_action_dialog_to_action(TRUE);
816 prefs_filtering_action_clist_set_row(-1, action);
818 filteringaction_free(action);
819 /* presumably gtk_list_select_item(), called by
820 * prefs_filtering_action_reset_dialog() activates
821 * what seems to be a bug. this causes any other
822 * list items to be unselectable */
823 /* prefs_filtering_action_reset_dialog(); */
824 gtk_list_select_item(GTK_LIST(filtering_action.account_list), 0);
825 gtk_entry_set_text(GTK_ENTRY(filtering_action.dest_entry), "");
826 prefs_filtering_action_update_hscrollbar();
830 *\brief Signal handler for substitute button
832 static void prefs_filtering_action_substitute_cb(void)
834 GtkCList *clist = GTK_CLIST(filtering_action.action_clist);
836 FilteringAction *action;
838 if (!clist->selection) return;
839 row = GPOINTER_TO_INT(clist->selection->data);
843 action = prefs_filtering_action_dialog_to_action(TRUE);
847 prefs_filtering_action_clist_set_row(row, action);
849 filteringaction_free(action);
851 prefs_filtering_action_reset_dialog();
853 prefs_filtering_action_update_hscrollbar();
857 *\brief Signal handler for delete button
859 static void prefs_filtering_action_delete_cb(void)
861 GtkCList *clist = GTK_CLIST(filtering_action.action_clist);
864 if (!clist->selection) return;
865 row = GPOINTER_TO_INT(clist->selection->data);
869 gtk_clist_remove(clist, row);
871 prefs_filtering_action_reset_dialog();
873 prefs_filtering_action_update_hscrollbar();
877 *\brief Signal handler for 'move up' button
879 static void prefs_filtering_action_up(void)
881 GtkCList *clist = GTK_CLIST(filtering_action.action_clist);
884 if (!clist->selection) return;
886 row = GPOINTER_TO_INT(clist->selection->data);
888 gtk_clist_row_move(clist, row, row - 1);
889 if (gtk_clist_row_is_visible(clist, row - 1) != GTK_VISIBILITY_FULL)
890 gtk_clist_moveto(clist, row - 1, 0, 0, 0);
895 *\brief Signal handler for 'move down' button
897 static void prefs_filtering_action_down(void)
899 GtkCList *clist = GTK_CLIST(filtering_action.action_clist);
902 if (!clist->selection) return;
904 row = GPOINTER_TO_INT(clist->selection->data);
905 if (row >= 1 && row < clist->rows - 1) {
906 gtk_clist_row_move(clist, row, row + 1);
907 if (gtk_clist_row_is_visible(clist, row + 1) != GTK_VISIBILITY_FULL)
908 gtk_clist_moveto(clist, row + 1, 0, 1, 0);
913 *\brief Signal handler for select row.
915 *\param clist List widget
916 *\param row Selected row
917 *\param column Selected column
918 *\param event Event information
920 static void prefs_filtering_action_select(GtkCList *clist,
921 gint row, gint column, GdkEvent *event)
924 FilteringAction *action;
925 GSList * action_list;
928 if (!gtk_clist_get_text(GTK_CLIST(filtering_action.action_clist),
929 row, 0, &action_str))
933 prefs_filtering_action_reset_dialog();
937 action_list = matcher_parser_get_action_list(action_str);
938 if (action_list == NULL)
941 action = action_list->data;
942 g_slist_free(action_list);
944 if (action->destination)
945 gtk_entry_set_text(GTK_ENTRY(filtering_action.dest_entry), action->destination);
947 gtk_entry_set_text(GTK_ENTRY(filtering_action.dest_entry), "");
949 switch(action->type) {
950 case MATCHACTION_MOVE:
951 gtk_list_select_item(GTK_LIST(filtering_action.action_type_list),
954 case MATCHACTION_COPY:
955 gtk_list_select_item(GTK_LIST(filtering_action.action_type_list),
958 case MATCHACTION_DELETE:
959 gtk_list_select_item(GTK_LIST(filtering_action.action_type_list),
962 case MATCHACTION_MARK:
963 gtk_list_select_item(GTK_LIST(filtering_action.action_type_list),
966 case MATCHACTION_UNMARK:
967 gtk_list_select_item(GTK_LIST(filtering_action.action_type_list),
970 case MATCHACTION_LOCK:
971 gtk_list_select_item(GTK_LIST(filtering_action.action_type_list),
974 case MATCHACTION_UNLOCK:
975 gtk_list_select_item(GTK_LIST(filtering_action.action_type_list),
978 case MATCHACTION_MARK_AS_READ:
979 gtk_list_select_item(GTK_LIST(filtering_action.action_type_list),
980 ACTION_MARK_AS_READ);
982 case MATCHACTION_MARK_AS_UNREAD:
983 gtk_list_select_item(GTK_LIST(filtering_action.action_type_list),
984 ACTION_MARK_AS_UNREAD);
986 case MATCHACTION_FORWARD:
987 list_id = get_list_id_from_account_id(action->account_id);
988 gtk_list_select_item(GTK_LIST(filtering_action.action_type_list),
990 gtk_list_select_item(GTK_LIST(filtering_action.account_list),
993 case MATCHACTION_FORWARD_AS_ATTACHMENT:
994 list_id = get_list_id_from_account_id(action->account_id);
995 gtk_list_select_item(GTK_LIST(filtering_action.action_type_list),
996 ACTION_FORWARD_AS_ATTACHMENT);
997 gtk_list_select_item(GTK_LIST(filtering_action.account_list),
1000 case MATCHACTION_REDIRECT:
1001 list_id = get_list_id_from_account_id(action->account_id);
1002 gtk_list_select_item(GTK_LIST(filtering_action.action_type_list),
1004 gtk_list_select_item(GTK_LIST(filtering_action.account_list),
1007 case MATCHACTION_EXECUTE:
1008 gtk_list_select_item(GTK_LIST(filtering_action.action_type_list),
1011 case MATCHACTION_COLOR:
1012 gtk_list_select_item(GTK_LIST(filtering_action.action_type_list),
1014 gtk_option_menu_set_history(GTK_OPTION_MENU(filtering_action.color_optmenu), action->labelcolor);
1016 case MATCHACTION_ADD_SCORE:
1017 gtk_list_select_item(GTK_LIST(filtering_action.action_type_list),
1020 case MATCHACTION_SET_SCORE:
1021 gtk_list_select_item(GTK_LIST(filtering_action.action_type_list),
1024 case MATCHACTION_STOP:
1025 gtk_list_select_item(GTK_LIST(filtering_action.action_type_list),
1032 *\brief Handle key press
1034 *\param widget Widget receiving key press
1035 *\param event Key event
1036 *\param data User data
1038 static gboolean prefs_filtering_action_key_pressed(GtkWidget *widget,
1039 GdkEventKey *event, gpointer data)
1041 if (event && event->keyval == GDK_Escape)
1042 prefs_filtering_action_cancel();
1047 *\brief Cancel matcher dialog
1049 static void prefs_filtering_action_cancel(void)
1051 gtk_widget_hide(filtering_action.window);
1056 *\brief Accept current matchers
1058 static void prefs_filtering_action_ok(void)
1060 GSList * action_list;
1063 action_list = prefs_filtering_action_get_list();
1065 if (action_list == NULL) {
1066 alertpanel_error(_("No action was defined."));
1070 if (filtering_action_callback != NULL)
1071 filtering_action_callback(action_list);
1072 for(cur = action_list ; cur != NULL ; cur = cur->next) {
1073 filteringaction_free(cur->data);
1075 g_slist_free(action_list);
1077 gtk_widget_hide(filtering_action.window);
1082 *\brief Called when closing dialog box
1084 *\param widget Dialog widget
1085 *\param event Event info
1086 *\param data User data
1090 static gint prefs_filtering_action_deleted(GtkWidget *widget,
1091 GdkEventAny *event, gpointer data)
1093 prefs_filtering_action_cancel();
1098 * Strings describing exec format strings
1100 * When adding new lines, remember to put 2 strings for each line
1102 static gchar *exec_desc_strings[] = {
1104 "%s", N_("Subject"),
1109 "%i", N_("Message-ID"),
1110 "%n", N_("Newsgroups"),
1111 "%r", N_("References"),
1112 "%F", N_("Filename - should not be modified"),
1113 "\\n", N_("new line"),
1114 "\\", N_("escape character for quotes"),
1115 "\\\"",N_("quote character"),
1119 static DescriptionWindow exec_desc_win = {
1122 N_("Description of symbols"),
1129 *\brief Show Execute action's info
1131 void prefs_filtering_action_exec_info(void)
1133 description_window_create(&exec_desc_win);
1136 static void prefs_filtering_action_select_dest(void)
1141 dest = foldersel_folder_sel(NULL, FOLDER_SEL_COPY, NULL);
1144 path = folder_item_get_identifier(dest);
1146 gtk_entry_set_text(GTK_ENTRY(filtering_action.dest_entry), path);
1150 static void prefs_filtering_action_type_selection_changed(GtkList *list,
1155 value = get_sel_from_list(GTK_LIST(filtering_action.action_type_list));
1157 if (filtering_action.current_action != value) {
1158 if (filtering_action.current_action == ACTION_FORWARD
1159 || filtering_action.current_action == ACTION_FORWARD_AS_ATTACHMENT
1160 || filtering_action.current_action == ACTION_REDIRECT) {
1161 debug_print("unregistering address completion entry\n");
1162 address_completion_unregister_entry(GTK_ENTRY(filtering_action.dest_entry));
1164 if (value == ACTION_FORWARD || value == ACTION_FORWARD_AS_ATTACHMENT
1165 || value == ACTION_REDIRECT) {
1166 debug_print("registering address completion entry\n");
1167 address_completion_register_entry(GTK_ENTRY(filtering_action.dest_entry));
1169 filtering_action.current_action = value;
1173 static void prefs_filtering_action_type_select(GtkList *list,
1174 GtkWidget *widget, gpointer user_data)
1178 value = (Action) get_sel_from_list(GTK_LIST(filtering_action.action_type_list));
1182 gtk_widget_show(filtering_action.account_label);
1183 gtk_widget_set_sensitive(filtering_action.account_label, FALSE);
1184 gtk_widget_set_sensitive(filtering_action.account_combo, FALSE);
1185 gtk_widget_show(filtering_action.dest_entry);
1186 gtk_widget_set_sensitive(filtering_action.dest_entry, TRUE);
1187 gtk_widget_show(filtering_action.dest_btn);
1188 gtk_widget_set_sensitive(filtering_action.dest_btn, TRUE);
1189 gtk_widget_show(filtering_action.dest_label);
1190 gtk_widget_set_sensitive(filtering_action.dest_label, TRUE);
1191 gtk_widget_hide(filtering_action.recip_label);
1192 gtk_widget_hide(filtering_action.exec_label);
1193 gtk_widget_hide(filtering_action.exec_btn);
1194 gtk_widget_hide(filtering_action.color_optmenu);
1195 gtk_widget_hide(filtering_action.color_label);
1196 gtk_widget_hide(filtering_action.score_label);
1199 gtk_widget_show(filtering_action.account_label);
1200 gtk_widget_set_sensitive(filtering_action.account_label, FALSE);
1201 gtk_widget_set_sensitive(filtering_action.account_combo, FALSE);
1202 gtk_widget_show(filtering_action.dest_entry);
1203 gtk_widget_set_sensitive(filtering_action.dest_entry, TRUE);
1204 gtk_widget_show(filtering_action.dest_btn);
1205 gtk_widget_set_sensitive(filtering_action.dest_btn, TRUE);
1206 gtk_widget_show(filtering_action.dest_label);
1207 gtk_widget_set_sensitive(filtering_action.dest_label, TRUE);
1208 gtk_widget_hide(filtering_action.recip_label);
1209 gtk_widget_hide(filtering_action.exec_label);
1210 gtk_widget_hide(filtering_action.exec_btn);
1211 gtk_widget_hide(filtering_action.color_optmenu);
1212 gtk_widget_hide(filtering_action.color_label);
1213 gtk_widget_hide(filtering_action.score_label);
1216 gtk_widget_show(filtering_action.account_label);
1217 gtk_widget_set_sensitive(filtering_action.account_label, FALSE);
1218 gtk_widget_set_sensitive(filtering_action.account_combo, FALSE);
1219 gtk_widget_show(filtering_action.dest_entry);
1220 gtk_widget_set_sensitive(filtering_action.dest_entry, FALSE);
1221 gtk_widget_show(filtering_action.dest_btn);
1222 gtk_widget_set_sensitive(filtering_action.dest_btn, FALSE);
1223 gtk_widget_show(filtering_action.dest_label);
1224 gtk_widget_set_sensitive(filtering_action.dest_label, FALSE);
1225 gtk_widget_hide(filtering_action.recip_label);
1226 gtk_widget_hide(filtering_action.exec_label);
1227 gtk_widget_hide(filtering_action.exec_btn);
1228 gtk_widget_hide(filtering_action.color_optmenu);
1229 gtk_widget_hide(filtering_action.color_label);
1230 gtk_widget_hide(filtering_action.score_label);
1236 case ACTION_MARK_AS_READ:
1237 case ACTION_MARK_AS_UNREAD:
1239 gtk_widget_show(filtering_action.account_label);
1240 gtk_widget_set_sensitive(filtering_action.account_label, FALSE);
1241 gtk_widget_set_sensitive(filtering_action.account_combo, FALSE);
1242 gtk_widget_show(filtering_action.dest_entry);
1243 gtk_widget_set_sensitive(filtering_action.dest_entry, FALSE);
1244 gtk_widget_show(filtering_action.dest_btn);
1245 gtk_widget_set_sensitive(filtering_action.dest_btn, FALSE);
1246 gtk_widget_show(filtering_action.dest_label);
1247 gtk_widget_set_sensitive(filtering_action.dest_label, FALSE);
1248 gtk_widget_hide(filtering_action.recip_label);
1249 gtk_widget_hide(filtering_action.exec_label);
1250 gtk_widget_hide(filtering_action.exec_btn);
1251 gtk_widget_hide(filtering_action.color_optmenu);
1252 gtk_widget_hide(filtering_action.color_label);
1253 gtk_widget_hide(filtering_action.score_label);
1255 case ACTION_FORWARD:
1256 gtk_widget_show(filtering_action.account_label);
1257 gtk_widget_set_sensitive(filtering_action.account_label, TRUE);
1258 gtk_widget_set_sensitive(filtering_action.account_combo, TRUE);
1259 gtk_widget_show(filtering_action.dest_entry);
1260 gtk_widget_set_sensitive(filtering_action.dest_entry, TRUE);
1261 gtk_widget_show(filtering_action.dest_btn);
1262 gtk_widget_set_sensitive(filtering_action.dest_btn, FALSE);
1263 gtk_widget_hide(filtering_action.dest_label);
1264 gtk_widget_show(filtering_action.recip_label);
1265 gtk_widget_set_sensitive(filtering_action.recip_label, TRUE);
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_AS_ATTACHMENT:
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_REDIRECT:
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_EXECUTE:
1307 gtk_widget_show(filtering_action.account_label);
1308 gtk_widget_set_sensitive(filtering_action.account_label, FALSE);
1309 gtk_widget_set_sensitive(filtering_action.account_combo, FALSE);
1310 gtk_widget_show(filtering_action.dest_entry);
1311 gtk_widget_set_sensitive(filtering_action.dest_entry, TRUE);
1312 gtk_widget_hide(filtering_action.dest_btn);
1313 gtk_widget_hide(filtering_action.dest_label);
1314 gtk_widget_hide(filtering_action.recip_label);
1315 gtk_widget_show(filtering_action.exec_label);
1316 gtk_widget_set_sensitive(filtering_action.exec_btn, TRUE);
1317 gtk_widget_show(filtering_action.exec_btn);
1318 gtk_widget_hide(filtering_action.color_optmenu);
1319 gtk_widget_hide(filtering_action.color_label);
1320 gtk_widget_hide(filtering_action.score_label);
1323 gtk_widget_show(filtering_action.account_label);
1324 gtk_widget_set_sensitive(filtering_action.account_label, FALSE);
1325 gtk_widget_set_sensitive(filtering_action.account_combo, FALSE);
1326 gtk_widget_hide(filtering_action.dest_entry);
1327 gtk_widget_hide(filtering_action.dest_btn);
1328 gtk_widget_hide(filtering_action.dest_label);
1329 gtk_widget_hide(filtering_action.recip_label);
1330 gtk_widget_hide(filtering_action.exec_label);
1331 gtk_widget_show(filtering_action.exec_btn);
1332 gtk_widget_set_sensitive(filtering_action.exec_btn, FALSE);
1333 gtk_widget_show(filtering_action.color_optmenu);
1334 gtk_widget_show(filtering_action.color_label);
1335 gtk_widget_hide(filtering_action.score_label);
1337 case ACTION_ADD_SCORE:
1338 case ACTION_SET_SCORE:
1339 gtk_widget_show(filtering_action.account_label);
1340 gtk_widget_set_sensitive(filtering_action.account_label, FALSE);
1341 gtk_widget_set_sensitive(filtering_action.account_combo, FALSE);
1342 gtk_widget_show(filtering_action.dest_entry);
1343 gtk_widget_set_sensitive(filtering_action.dest_entry, TRUE);
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_hide(filtering_action.color_optmenu);
1351 gtk_widget_hide(filtering_action.color_label);
1352 gtk_widget_show(filtering_action.score_label);
1357 static void prefs_filtering_action_reset_dialog(void)
1359 gtk_list_select_item(GTK_LIST(filtering_action.action_type_list), 0);
1360 gtk_list_select_item(GTK_LIST(filtering_action.account_list), 0);
1361 gtk_entry_set_text(GTK_ENTRY(filtering_action.dest_entry), "");