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"
50 #include "matcher_parser.h"
51 #include "colorlabel.h"
54 static void prefs_filtering_action_create(void);
55 static void prefs_filtering_action_delete_cb(void);
56 static void prefs_filtering_action_substitute_cb(void);
57 static void prefs_filtering_action_register_cb(void);
58 static void prefs_filtering_action_reset_dialog(void);
59 static gboolean prefs_filtering_action_key_pressed(GtkWidget *widget,
60 GdkEventKey *event, gpointer data);
61 static void prefs_filtering_action_cancel(void);
62 static void prefs_filtering_action_ok(void);
63 static gint prefs_filtering_action_deleted(GtkWidget *widget,
64 GdkEventAny *event, gpointer data);
65 static void prefs_filtering_action_type_selection_changed(GtkList *list,
67 static void prefs_filtering_action_type_select(GtkList *list,
68 GtkWidget *widget, gpointer user_data);
69 static void prefs_filtering_action_select_dest(void);
70 static void prefs_filtering_action_select(GtkCList *clist,
71 gint row, gint column, GdkEvent *event);
72 static void prefs_filtering_action_up(void);
73 static void prefs_filtering_action_down(void);
74 static void prefs_filtering_action_set_dialog(GSList *action_list);
75 static GSList *prefs_filtering_action_get_list(void);
79 *\brief UI data for matcher dialog
81 static struct FilteringAction {
86 GtkWidget *action_clist;
87 GtkWidget *action_type_list;
88 GtkWidget *action_combo;
89 GtkWidget *account_label;
90 GtkWidget *account_list;
91 GtkWidget *account_combo;
92 GtkWidget *dest_entry;
94 GtkWidget *dest_label;
95 GtkWidget *recip_label;
96 GtkWidget *exec_label;
98 GtkWidget *color_label;
99 GtkWidget *color_optmenu;
100 GtkWidget *score_label;
106 typedef enum Action_ {
115 ACTION_MARK_AS_UNREAD,
117 ACTION_FORWARD_AS_ATTACHMENT,
124 /* add other action constants */
131 { N_("Move"), ACTION_MOVE },
132 { N_("Copy"), ACTION_COPY },
133 { N_("Delete"), ACTION_DELETE },
134 { N_("Mark"), ACTION_MARK },
135 { N_("Unmark"), ACTION_UNMARK },
136 { N_("Lock"), ACTION_LOCK },
137 { N_("Unlock"), ACTION_UNLOCK },
138 { N_("Mark as read"), ACTION_MARK_AS_READ },
139 { N_("Mark as unread"), ACTION_MARK_AS_UNREAD },
140 { N_("Forward"), ACTION_FORWARD },
141 { N_("Forward as attachment"), ACTION_FORWARD_AS_ATTACHMENT },
142 { N_("Redirect"), ACTION_REDIRECT },
143 { N_("Execute"), ACTION_EXECUTE },
144 { N_("Color"), ACTION_COLOR },
145 { N_("(In/de)crease score"), ACTION_ADD_SCORE},
146 { N_("Set score"), ACTION_SET_SCORE},
147 { N_("Stop filter"), ACTION_STOP },
154 static PrefsFilteringActionSignal *filtering_action_callback;
157 *\brief Find index of list selection
159 *\param list GTK list widget
161 *\return gint Selection index
163 static gint get_sel_from_list(GtkList *list)
169 if (list->selection == NULL)
172 sel = list->selection->data;
173 for (child = list->children; child != NULL; child = g_list_next(child)) {
174 if (child->data == sel)
183 *\brief Opens the filtering action dialog with a list of actions
185 *\param matchers List of conditions
189 void prefs_filtering_action_open(GSList *action_list,
190 PrefsFilteringActionSignal *cb)
194 if (!filtering_action.window) {
195 prefs_filtering_action_create();
198 manage_window_set_transient(GTK_WINDOW(filtering_action.window));
199 gtk_widget_grab_focus(filtering_action.ok_btn);
201 filtering_action_callback = cb;
203 prefs_filtering_action_set_dialog(action_list);
205 gtk_widget_show(filtering_action.window);
209 *\brief Create the matcher dialog
211 static void prefs_filtering_action_create(void)
216 GtkWidget *cancel_btn;
217 GtkWidget *confirm_area;
223 GtkWidget *action_label;
224 GtkWidget *recip_label;
225 GtkWidget *action_combo;
226 GtkWidget *action_type_list;
227 GtkWidget *account_list;
228 GtkWidget *dest_label;
229 GtkWidget *exec_label;
230 GtkWidget *score_label;
231 GtkWidget *color_label;
232 GtkWidget *account_label;
233 GtkWidget *account_combo;
234 GtkWidget *dest_entry;
242 GtkWidget *subst_btn;
245 GtkWidget *action_hbox;
246 GtkWidget *action_scrolledwin;
247 GtkWidget *action_clist;
255 GtkWidget *color_optmenu;
263 debug_print("Creating matcher configuration window...\n");
265 window = gtk_window_new(GTK_WINDOW_DIALOG);
266 gtk_container_set_border_width(GTK_CONTAINER(window), 8);
267 gtk_window_position(GTK_WINDOW(window), GTK_WIN_POS_CENTER);
268 gtk_window_set_modal(GTK_WINDOW(window), TRUE);
269 gtk_window_set_policy(GTK_WINDOW(window), FALSE, TRUE, FALSE);
271 vbox = gtk_vbox_new(FALSE, 6);
272 gtk_widget_show(vbox);
273 gtk_container_add(GTK_CONTAINER(window), vbox);
275 gtkut_button_set_create(&confirm_area, &ok_btn, _("OK"),
276 &cancel_btn, _("Cancel"), NULL, NULL);
277 gtk_widget_show(confirm_area);
278 gtk_box_pack_end(GTK_BOX(vbox), confirm_area, FALSE, FALSE, 0);
279 gtk_widget_grab_default(ok_btn);
281 gtk_window_set_title(GTK_WINDOW(window),
282 _("Filtering action configuration"));
283 gtk_signal_connect(GTK_OBJECT(window), "delete_event",
284 GTK_SIGNAL_FUNC(prefs_filtering_action_deleted), NULL);
285 gtk_signal_connect(GTK_OBJECT(window), "key_press_event",
286 GTK_SIGNAL_FUNC(prefs_filtering_action_key_pressed), NULL);
287 MANAGE_WINDOW_SIGNALS_CONNECT(window);
288 gtk_signal_connect(GTK_OBJECT(ok_btn), "clicked",
289 GTK_SIGNAL_FUNC(prefs_filtering_action_ok), NULL);
290 gtk_signal_connect(GTK_OBJECT(cancel_btn), "clicked",
291 GTK_SIGNAL_FUNC(prefs_filtering_action_cancel), NULL);
293 vbox1 = gtk_vbox_new(FALSE, VSPACING);
294 gtk_widget_show(vbox1);
295 gtk_box_pack_start(GTK_BOX(vbox), vbox1, TRUE, TRUE, 0);
296 gtk_container_set_border_width(GTK_CONTAINER (vbox1), 2);
298 /* action to be defined */
300 hbox1 = gtk_hbox_new (FALSE, VSPACING);
301 gtk_widget_show (hbox1);
302 gtk_box_pack_start (GTK_BOX (vbox1), hbox1, FALSE, FALSE, 0);
303 gtk_container_set_border_width (GTK_CONTAINER (vbox1), 2);
305 action_label = gtk_label_new (_("Action"));
306 gtk_widget_show (action_label);
307 gtk_misc_set_alignment (GTK_MISC (action_label), 0, 0.5);
308 gtk_box_pack_start (GTK_BOX (hbox1), action_label, FALSE, FALSE, 0);
310 action_combo = gtk_combo_new ();
311 gtk_widget_show (action_combo);
312 gtk_entry_set_editable(GTK_ENTRY(GTK_COMBO(action_combo)->entry),
316 for (i = 0; i < sizeof action_text / sizeof action_text[0]; i++)
317 combo_items = g_list_append
318 (combo_items, (gpointer) _(action_text[i].text));
319 gtk_combo_set_popdown_strings(GTK_COMBO(action_combo), combo_items);
321 g_list_free(combo_items);
323 gtk_box_pack_start (GTK_BOX (hbox1), action_combo,
325 action_type_list = GTK_COMBO(action_combo)->list;
326 gtk_signal_connect (GTK_OBJECT (action_type_list), "select-child",
327 GTK_SIGNAL_FUNC (prefs_filtering_action_type_select),
330 gtk_signal_connect(GTK_OBJECT(action_type_list), "selection-changed",
331 GTK_SIGNAL_FUNC(prefs_filtering_action_type_selection_changed),
336 hbox1 = gtk_hbox_new (FALSE, VSPACING);
337 gtk_widget_show (vbox1);
338 gtk_box_pack_start (GTK_BOX (vbox1), hbox1, FALSE, FALSE, 0);
339 gtk_container_set_border_width (GTK_CONTAINER (vbox1), 2);
341 account_label = gtk_label_new (_("Account"));
342 gtk_widget_show (account_label);
343 gtk_misc_set_alignment (GTK_MISC (account_label), 0, 0.5);
344 gtk_box_pack_start (GTK_BOX (hbox1), account_label, FALSE, FALSE, 0);
346 account_combo = gtk_combo_new ();
347 gtk_widget_set_usize (account_combo, 150, -1);
348 gtk_widget_show (account_combo);
351 for (accounts = account_get_list() ; accounts != NULL;
352 accounts = accounts->next) {
353 PrefsAccount *ac = (PrefsAccount *)accounts->data;
356 name = g_strdup_printf("%s <%s> (%s)",
357 ac->name, ac->address,
359 combo_items = g_list_append(combo_items, (gpointer) name);
362 gtk_combo_set_popdown_strings(GTK_COMBO(account_combo), combo_items);
364 for(cur = g_list_first(combo_items) ; cur != NULL ;
365 cur = g_list_next(cur))
367 g_list_free(combo_items);
369 gtk_box_pack_start (GTK_BOX (hbox1), account_combo,
371 account_list = GTK_COMBO(account_combo)->list;
372 gtk_entry_set_editable(GTK_ENTRY(GTK_COMBO(account_combo)->entry),
377 hbox1 = gtk_hbox_new (FALSE, VSPACING);
378 gtk_widget_show (vbox1);
379 gtk_box_pack_start (GTK_BOX (vbox1), hbox1, FALSE, FALSE, 0);
380 gtk_container_set_border_width (GTK_CONTAINER (vbox1), 2);
382 dest_label = gtk_label_new (_("Destination"));
383 gtk_widget_show (dest_label);
384 gtk_misc_set_alignment (GTK_MISC (dest_label), 0, 0.5);
385 gtk_box_pack_start (GTK_BOX (hbox1), dest_label, FALSE, FALSE, 0);
387 recip_label = gtk_label_new (_("Recipient"));
388 gtk_widget_show (recip_label);
389 gtk_misc_set_alignment (GTK_MISC (recip_label), 0, 0.5);
390 gtk_box_pack_start (GTK_BOX (hbox1), recip_label, FALSE, FALSE, 0);
392 exec_label = gtk_label_new (_("Execute"));
393 gtk_widget_show (exec_label);
394 gtk_misc_set_alignment (GTK_MISC (exec_label), 0, 0.5);
395 gtk_box_pack_start (GTK_BOX (hbox1), exec_label, FALSE, FALSE, 0);
397 color_label = gtk_label_new (_("Color"));
398 gtk_widget_show(color_label);
399 gtk_misc_set_alignment(GTK_MISC(color_label), 0, 0.5);
400 gtk_box_pack_start(GTK_BOX(hbox1), color_label, FALSE, FALSE, 0);
402 score_label = gtk_label_new (_("Score"));
403 gtk_widget_show (score_label);
404 gtk_misc_set_alignment (GTK_MISC (score_label), 0, 0.5);
405 gtk_box_pack_start (GTK_BOX (hbox1), score_label, FALSE, FALSE, 0);
407 dest_entry = gtk_entry_new ();
408 gtk_widget_set_usize (dest_entry, 150, -1);
409 gtk_widget_show (dest_entry);
410 gtk_box_pack_start (GTK_BOX (hbox1), dest_entry, TRUE, TRUE, 0);
412 color_optmenu = gtk_option_menu_new();
413 gtk_option_menu_set_menu(GTK_OPTION_MENU(color_optmenu),
414 colorlabel_create_color_menu());
415 gtk_box_pack_start(GTK_BOX(hbox1), color_optmenu, TRUE, TRUE, 0);
417 dest_btn = gtk_button_new_with_label (_("Select ..."));
418 gtk_widget_show (dest_btn);
419 gtk_box_pack_start (GTK_BOX (hbox1), dest_btn, FALSE, FALSE, 0);
420 gtk_signal_connect (GTK_OBJECT (dest_btn), "clicked",
421 GTK_SIGNAL_FUNC (prefs_filtering_action_select_dest),
424 exec_btn = gtk_button_new_with_label (_("Info ..."));
425 gtk_widget_show (exec_btn);
426 gtk_box_pack_start (GTK_BOX (hbox1), exec_btn, FALSE, FALSE, 0);
427 gtk_signal_connect (GTK_OBJECT (exec_btn), "clicked",
428 GTK_SIGNAL_FUNC (prefs_filtering_action_exec_info),
431 /* register / substitute / delete */
433 reg_hbox = gtk_hbox_new(FALSE, 4);
434 gtk_widget_show(reg_hbox);
435 gtk_box_pack_start(GTK_BOX(vbox1), reg_hbox, FALSE, FALSE, 0);
437 arrow = gtk_arrow_new(GTK_ARROW_DOWN, GTK_SHADOW_OUT);
438 gtk_widget_show(arrow);
439 gtk_box_pack_start(GTK_BOX(reg_hbox), arrow, FALSE, FALSE, 0);
440 gtk_widget_set_usize(arrow, -1, 16);
442 btn_hbox = gtk_hbox_new(TRUE, 4);
443 gtk_widget_show(btn_hbox);
444 gtk_box_pack_start(GTK_BOX(reg_hbox), btn_hbox, FALSE, FALSE, 0);
446 reg_btn = gtk_button_new_with_label(_("Add"));
447 gtk_widget_show(reg_btn);
448 gtk_box_pack_start(GTK_BOX(btn_hbox), reg_btn, FALSE, TRUE, 0);
449 gtk_signal_connect(GTK_OBJECT(reg_btn), "clicked",
450 GTK_SIGNAL_FUNC(prefs_filtering_action_register_cb), NULL);
452 subst_btn = gtk_button_new_with_label(_(" Replace "));
453 gtk_widget_show(subst_btn);
454 gtk_box_pack_start(GTK_BOX(btn_hbox), subst_btn, FALSE, TRUE, 0);
455 gtk_signal_connect(GTK_OBJECT(subst_btn), "clicked",
456 GTK_SIGNAL_FUNC(prefs_filtering_action_substitute_cb),
459 del_btn = gtk_button_new_with_label(_("Delete"));
460 gtk_widget_show(del_btn);
461 gtk_box_pack_start(GTK_BOX(btn_hbox), del_btn, FALSE, TRUE, 0);
462 gtk_signal_connect(GTK_OBJECT(del_btn), "clicked",
463 GTK_SIGNAL_FUNC(prefs_filtering_action_delete_cb), NULL);
465 action_hbox = gtk_hbox_new(FALSE, 8);
466 gtk_widget_show(action_hbox);
467 gtk_box_pack_start(GTK_BOX(vbox1), action_hbox, TRUE, TRUE, 0);
469 action_scrolledwin = gtk_scrolled_window_new(NULL, NULL);
470 gtk_widget_show(action_scrolledwin);
471 gtk_widget_set_usize(action_scrolledwin, -1, 150);
472 gtk_box_pack_start(GTK_BOX(action_hbox), action_scrolledwin,
474 gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(action_scrolledwin),
475 GTK_POLICY_AUTOMATIC,
476 GTK_POLICY_AUTOMATIC);
478 title[0] = _("Current action list");
479 action_clist = gtk_clist_new_with_titles(1, title);
480 gtk_widget_show(action_clist);
481 gtk_container_add(GTK_CONTAINER(action_scrolledwin), action_clist);
482 gtk_clist_set_column_width(GTK_CLIST(action_clist), 0, 80);
483 gtk_clist_set_selection_mode(GTK_CLIST(action_clist),
484 GTK_SELECTION_BROWSE);
485 GTK_WIDGET_UNSET_FLAGS(GTK_CLIST(action_clist)->column[0].button,
487 gtk_signal_connect(GTK_OBJECT(action_clist), "select_row",
488 GTK_SIGNAL_FUNC(prefs_filtering_action_select), NULL);
490 btn_vbox = gtk_vbox_new(FALSE, 8);
491 gtk_widget_show(btn_vbox);
492 gtk_box_pack_start(GTK_BOX(action_hbox), btn_vbox, FALSE, FALSE, 0);
494 up_btn = gtk_button_new_with_label(_("Up"));
495 gtk_widget_show(up_btn);
496 gtk_box_pack_start(GTK_BOX(btn_vbox), up_btn, FALSE, FALSE, 0);
497 gtk_signal_connect(GTK_OBJECT(up_btn), "clicked",
498 GTK_SIGNAL_FUNC(prefs_filtering_action_up), NULL);
500 down_btn = gtk_button_new_with_label(_("Down"));
501 gtk_widget_show(down_btn);
502 gtk_box_pack_start(GTK_BOX(btn_vbox), down_btn, FALSE, FALSE, 0);
503 gtk_signal_connect(GTK_OBJECT(down_btn), "clicked",
504 GTK_SIGNAL_FUNC(prefs_filtering_action_down), NULL);
506 gtk_widget_show_all(window);
508 filtering_action.window = window;
509 filtering_action.action_type_list = action_type_list;
510 filtering_action.action_combo = action_combo;
511 filtering_action.account_label = account_label;
512 filtering_action.account_list = account_list;
513 filtering_action.account_combo = account_combo;
514 filtering_action.dest_entry = dest_entry;
515 filtering_action.dest_btn = dest_btn;
516 filtering_action.dest_label = dest_label;
517 filtering_action.recip_label = recip_label;
518 filtering_action.exec_label = exec_label;
519 filtering_action.exec_btn = exec_btn;
520 filtering_action.color_label = color_label;
521 filtering_action.color_optmenu = color_optmenu;
522 filtering_action.score_label = score_label;
523 filtering_action.ok_btn = ok_btn;
524 filtering_action.action_clist = action_clist;
528 *\brief Set the contents of a row
530 *\param row Index of row to set
531 *\param prop Condition to set
533 *\return gint Row index \a prop has been added
535 static gint prefs_filtering_action_clist_set_row(gint row, FilteringAction *action)
537 GtkCList *clist = GTK_CLIST(filtering_action.action_clist);
538 gchar *action_tab_str[1];
542 if (action == NULL) {
543 action_tab_str[0] = _("(New)");
544 return gtk_clist_append(clist, action_tab_str);
547 filteringaction_to_string(buf, sizeof buf, action);
548 action_str = g_strdup(buf);
550 action_tab_str[0] = action_str;
552 row = gtk_clist_append(clist, action_tab_str);
554 gtk_clist_set_text(clist, row, 0, action_tab_str[0]);
561 *\brief Update scrollbar
563 static void prefs_filtering_action_update_hscrollbar(void)
565 gint optwidth = gtk_clist_optimal_column_width(GTK_CLIST(filtering_action.action_clist), 0);
566 gtk_clist_set_column_width(GTK_CLIST(filtering_action.action_clist), 0, optwidth);
570 *\brief Initializes dialog with a set of conditions
572 *\param matchers List of conditions
574 static void prefs_filtering_action_set_dialog(GSList *action_list)
576 GtkCList *clist = GTK_CLIST(filtering_action.action_clist);
579 gtk_clist_freeze(clist);
580 gtk_clist_clear(clist);
582 prefs_filtering_action_clist_set_row(-1, NULL);
583 if (action_list != NULL) {
584 for (cur = action_list; cur != NULL;
585 cur = g_slist_next(cur)) {
586 FilteringAction *action;
587 action = (FilteringAction *) cur->data;
588 prefs_filtering_action_clist_set_row(-1, action);
592 prefs_filtering_action_update_hscrollbar();
594 gtk_clist_thaw(clist);
596 prefs_filtering_action_reset_dialog();
600 *\brief Converts current actions in list box in
601 * an action list used by the filtering system.
603 *\return GSList * List of actions.
605 static GSList *prefs_filtering_action_get_list(void)
608 FilteringAction *action;
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), "");