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_DIALOG);
269 gtk_container_set_border_width(GTK_CONTAINER(window), 8);
270 gtk_window_position(GTK_WINDOW(window), GTK_WIN_POS_CENTER);
271 gtk_window_set_modal(GTK_WINDOW(window), TRUE);
272 gtk_window_set_policy(GTK_WINDOW(window), FALSE, TRUE, FALSE);
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 gtk_signal_connect(GTK_OBJECT(window), "delete_event",
287 GTK_SIGNAL_FUNC(prefs_filtering_action_deleted), NULL);
288 gtk_signal_connect(GTK_OBJECT(window), "key_press_event",
289 GTK_SIGNAL_FUNC(prefs_filtering_action_key_pressed), NULL);
290 MANAGE_WINDOW_SIGNALS_CONNECT(window);
291 gtk_signal_connect(GTK_OBJECT(ok_btn), "clicked",
292 GTK_SIGNAL_FUNC(prefs_filtering_action_ok), NULL);
293 gtk_signal_connect(GTK_OBJECT(cancel_btn), "clicked",
294 GTK_SIGNAL_FUNC(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 gtk_signal_connect (GTK_OBJECT (action_type_list), "select-child",
330 GTK_SIGNAL_FUNC (prefs_filtering_action_type_select),
333 gtk_signal_connect(GTK_OBJECT(action_type_list), "selection-changed",
334 GTK_SIGNAL_FUNC(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 gtk_signal_connect (GTK_OBJECT (dest_btn), "clicked",
424 GTK_SIGNAL_FUNC (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 gtk_signal_connect (GTK_OBJECT (exec_btn), "clicked",
431 GTK_SIGNAL_FUNC (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 gtk_signal_connect(GTK_OBJECT(reg_btn), "clicked",
453 GTK_SIGNAL_FUNC(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 gtk_signal_connect(GTK_OBJECT(subst_btn), "clicked",
459 GTK_SIGNAL_FUNC(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 gtk_signal_connect(GTK_OBJECT(del_btn), "clicked",
466 GTK_SIGNAL_FUNC(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 gtk_signal_connect(GTK_OBJECT(action_clist), "select_row",
491 GTK_SIGNAL_FUNC(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 gtk_signal_connect(GTK_OBJECT(up_btn), "clicked",
501 GTK_SIGNAL_FUNC(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 gtk_signal_connect(GTK_OBJECT(down_btn), "clicked",
507 GTK_SIGNAL_FUNC(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)
742 FilteringAction * action;
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_entry_get_text(GTK_ENTRY(filtering_action.dest_entry));
758 if (*destination == '\0') {
760 alertpanel_error(action_id == ACTION_EXECUTE
761 ? _("Command line not set")
762 : _("Destination is not set."));
767 case ACTION_FORWARD_AS_ATTACHMENT:
768 case ACTION_REDIRECT:
769 destination = gtk_entry_get_text(GTK_ENTRY(filtering_action.dest_entry));
770 if (*destination == '\0') {
772 alertpanel_error(_("Recipient is not set."));
777 labelcolor = colorlabel_get_color_menu_active_item(
778 gtk_option_menu_get_menu(GTK_OPTION_MENU(filtering_action.color_optmenu)));
781 case ACTION_CHANGE_SCORE:
782 case ACTION_SET_SCORE:
783 score_str = gtk_entry_get_text(GTK_ENTRY(filtering_action.dest_entry));
784 if (*score_str == '\0') {
786 alertpanel_error(_("Score is not set"));
789 score = strtol(score_str, NULL, 10);
798 case ACTION_MARK_AS_READ:
799 case ACTION_MARK_AS_UNREAD:
804 action = filteringaction_new(action_type, account_id,
805 destination, labelcolor, score);
811 *\brief Signal handler for register button
813 static void prefs_filtering_action_register_cb(void)
815 FilteringAction *action;
817 action = prefs_filtering_action_dialog_to_action(TRUE);
821 prefs_filtering_action_clist_set_row(-1, action);
823 filteringaction_free(action);
824 /* presumably gtk_list_select_item(), called by
825 * prefs_filtering_action_reset_dialog() activates
826 * what seems to be a bug. this causes any other
827 * list items to be unselectable */
828 /* prefs_filtering_action_reset_dialog(); */
829 gtk_list_select_item(GTK_LIST(filtering_action.account_list), 0);
830 gtk_entry_set_text(GTK_ENTRY(filtering_action.dest_entry), "");
831 prefs_filtering_action_update_hscrollbar();
835 *\brief Signal handler for substitute button
837 static void prefs_filtering_action_substitute_cb(void)
839 GtkCList *clist = GTK_CLIST(filtering_action.action_clist);
841 FilteringAction *action;
843 if (!clist->selection) return;
844 row = GPOINTER_TO_INT(clist->selection->data);
848 action = prefs_filtering_action_dialog_to_action(TRUE);
852 prefs_filtering_action_clist_set_row(row, action);
854 filteringaction_free(action);
856 prefs_filtering_action_reset_dialog();
858 prefs_filtering_action_update_hscrollbar();
862 *\brief Signal handler for delete button
864 static void prefs_filtering_action_delete_cb(void)
866 GtkCList *clist = GTK_CLIST(filtering_action.action_clist);
869 if (!clist->selection) return;
870 row = GPOINTER_TO_INT(clist->selection->data);
874 gtk_clist_remove(clist, row);
876 prefs_filtering_action_reset_dialog();
878 prefs_filtering_action_update_hscrollbar();
882 *\brief Signal handler for 'move up' button
884 static void prefs_filtering_action_up(void)
886 GtkCList *clist = GTK_CLIST(filtering_action.action_clist);
889 if (!clist->selection) return;
891 row = GPOINTER_TO_INT(clist->selection->data);
893 gtk_clist_row_move(clist, row, row - 1);
894 if (gtk_clist_row_is_visible(clist, row - 1) != GTK_VISIBILITY_FULL)
895 gtk_clist_moveto(clist, row - 1, 0, 0, 0);
900 *\brief Signal handler for 'move down' button
902 static void prefs_filtering_action_down(void)
904 GtkCList *clist = GTK_CLIST(filtering_action.action_clist);
907 if (!clist->selection) return;
909 row = GPOINTER_TO_INT(clist->selection->data);
910 if (row >= 1 && row < clist->rows - 1) {
911 gtk_clist_row_move(clist, row, row + 1);
912 if (gtk_clist_row_is_visible(clist, row + 1) != GTK_VISIBILITY_FULL)
913 gtk_clist_moveto(clist, row + 1, 0, 1, 0);
918 *\brief Signal handler for select row.
920 *\param clist List widget
921 *\param row Selected row
922 *\param column Selected column
923 *\param event Event information
925 static void prefs_filtering_action_select(GtkCList *clist,
926 gint row, gint column, GdkEvent *event)
929 FilteringAction *action;
930 GSList * action_list;
933 if (!gtk_clist_get_text(GTK_CLIST(filtering_action.action_clist),
934 row, 0, &action_str))
938 prefs_filtering_action_reset_dialog();
942 action_list = matcher_parser_get_action_list(action_str);
943 if (action_list == NULL)
946 action = action_list->data;
947 g_slist_free(action_list);
949 if (action->destination)
950 gtk_entry_set_text(GTK_ENTRY(filtering_action.dest_entry), action->destination);
952 gtk_entry_set_text(GTK_ENTRY(filtering_action.dest_entry), "");
954 switch(action->type) {
955 case MATCHACTION_MOVE:
956 gtk_list_select_item(GTK_LIST(filtering_action.action_type_list),
959 case MATCHACTION_COPY:
960 gtk_list_select_item(GTK_LIST(filtering_action.action_type_list),
963 case MATCHACTION_DELETE:
964 gtk_list_select_item(GTK_LIST(filtering_action.action_type_list),
967 case MATCHACTION_MARK:
968 gtk_list_select_item(GTK_LIST(filtering_action.action_type_list),
971 case MATCHACTION_UNMARK:
972 gtk_list_select_item(GTK_LIST(filtering_action.action_type_list),
975 case MATCHACTION_LOCK:
976 gtk_list_select_item(GTK_LIST(filtering_action.action_type_list),
979 case MATCHACTION_UNLOCK:
980 gtk_list_select_item(GTK_LIST(filtering_action.action_type_list),
983 case MATCHACTION_MARK_AS_READ:
984 gtk_list_select_item(GTK_LIST(filtering_action.action_type_list),
985 ACTION_MARK_AS_READ);
987 case MATCHACTION_MARK_AS_UNREAD:
988 gtk_list_select_item(GTK_LIST(filtering_action.action_type_list),
989 ACTION_MARK_AS_UNREAD);
991 case MATCHACTION_FORWARD:
992 list_id = get_list_id_from_account_id(action->account_id);
993 gtk_list_select_item(GTK_LIST(filtering_action.action_type_list),
995 gtk_list_select_item(GTK_LIST(filtering_action.account_list),
998 case MATCHACTION_FORWARD_AS_ATTACHMENT:
999 list_id = get_list_id_from_account_id(action->account_id);
1000 gtk_list_select_item(GTK_LIST(filtering_action.action_type_list),
1001 ACTION_FORWARD_AS_ATTACHMENT);
1002 gtk_list_select_item(GTK_LIST(filtering_action.account_list),
1005 case MATCHACTION_REDIRECT:
1006 list_id = get_list_id_from_account_id(action->account_id);
1007 gtk_list_select_item(GTK_LIST(filtering_action.action_type_list),
1009 gtk_list_select_item(GTK_LIST(filtering_action.account_list),
1012 case MATCHACTION_EXECUTE:
1013 gtk_list_select_item(GTK_LIST(filtering_action.action_type_list),
1016 case MATCHACTION_COLOR:
1017 gtk_list_select_item(GTK_LIST(filtering_action.action_type_list),
1019 gtk_option_menu_set_history(GTK_OPTION_MENU(filtering_action.color_optmenu), action->labelcolor);
1021 case MATCHACTION_CHANGE_SCORE:
1022 gtk_list_select_item(GTK_LIST(filtering_action.action_type_list),
1023 ACTION_CHANGE_SCORE);
1025 case MATCHACTION_SET_SCORE:
1026 gtk_list_select_item(GTK_LIST(filtering_action.action_type_list),
1029 case MATCHACTION_STOP:
1030 gtk_list_select_item(GTK_LIST(filtering_action.action_type_list),
1033 case MATCHACTION_HIDE:
1034 gtk_list_select_item(GTK_LIST(filtering_action.action_type_list),
1041 *\brief Handle key press
1043 *\param widget Widget receiving key press
1044 *\param event Key event
1045 *\param data User data
1047 static gboolean prefs_filtering_action_key_pressed(GtkWidget *widget,
1048 GdkEventKey *event, gpointer data)
1050 if (event && event->keyval == GDK_Escape)
1051 prefs_filtering_action_cancel();
1056 *\brief Cancel matcher dialog
1058 static void prefs_filtering_action_cancel(void)
1060 gtk_widget_hide(filtering_action.window);
1065 *\brief Accept current matchers
1067 static void prefs_filtering_action_ok(void)
1069 GSList * action_list;
1072 action_list = prefs_filtering_action_get_list();
1074 if (action_list == NULL) {
1075 alertpanel_error(_("No action was defined."));
1079 if (filtering_action_callback != NULL)
1080 filtering_action_callback(action_list);
1081 for(cur = action_list ; cur != NULL ; cur = cur->next) {
1082 filteringaction_free(cur->data);
1084 g_slist_free(action_list);
1086 gtk_widget_hide(filtering_action.window);
1091 *\brief Called when closing dialog box
1093 *\param widget Dialog widget
1094 *\param event Event info
1095 *\param data User data
1099 static gint prefs_filtering_action_deleted(GtkWidget *widget,
1100 GdkEventAny *event, gpointer data)
1102 prefs_filtering_action_cancel();
1107 * Strings describing exec format strings
1109 * When adding new lines, remember to put 2 strings for each line
1111 static gchar *exec_desc_strings[] = {
1113 "%s", N_("Subject"),
1118 "%i", N_("Message-ID"),
1119 "%n", N_("Newsgroups"),
1120 "%r", N_("References"),
1121 "%F", N_("Filename - should not be modified"),
1122 "\\n", N_("new line"),
1123 "\\", N_("escape character for quotes"),
1124 "\\\"",N_("quote character"),
1128 static DescriptionWindow exec_desc_win = {
1131 N_("Description of symbols"),
1138 *\brief Show Execute action's info
1140 void prefs_filtering_action_exec_info(void)
1142 description_window_create(&exec_desc_win);
1145 static void prefs_filtering_action_select_dest(void)
1150 dest = foldersel_folder_sel(NULL, FOLDER_SEL_COPY, NULL);
1153 path = folder_item_get_identifier(dest);
1155 gtk_entry_set_text(GTK_ENTRY(filtering_action.dest_entry), path);
1159 static void prefs_filtering_action_type_selection_changed(GtkList *list,
1164 value = get_sel_from_list(GTK_LIST(filtering_action.action_type_list));
1166 if (filtering_action.current_action != value) {
1167 if (filtering_action.current_action == ACTION_FORWARD
1168 || filtering_action.current_action == ACTION_FORWARD_AS_ATTACHMENT
1169 || filtering_action.current_action == ACTION_REDIRECT) {
1170 debug_print("unregistering address completion entry\n");
1171 address_completion_unregister_entry(GTK_ENTRY(filtering_action.dest_entry));
1173 if (value == ACTION_FORWARD || value == ACTION_FORWARD_AS_ATTACHMENT
1174 || value == ACTION_REDIRECT) {
1175 debug_print("registering address completion entry\n");
1176 address_completion_register_entry(GTK_ENTRY(filtering_action.dest_entry));
1178 filtering_action.current_action = value;
1182 static void prefs_filtering_action_type_select(GtkList *list,
1183 GtkWidget *widget, gpointer user_data)
1187 value = (Action) get_sel_from_list(GTK_LIST(filtering_action.action_type_list));
1191 gtk_widget_show(filtering_action.account_label);
1192 gtk_widget_set_sensitive(filtering_action.account_label, FALSE);
1193 gtk_widget_set_sensitive(filtering_action.account_combo, FALSE);
1194 gtk_widget_show(filtering_action.dest_entry);
1195 gtk_widget_set_sensitive(filtering_action.dest_entry, TRUE);
1196 gtk_widget_show(filtering_action.dest_btn);
1197 gtk_widget_set_sensitive(filtering_action.dest_btn, TRUE);
1198 gtk_widget_show(filtering_action.dest_label);
1199 gtk_widget_set_sensitive(filtering_action.dest_label, TRUE);
1200 gtk_widget_hide(filtering_action.recip_label);
1201 gtk_widget_hide(filtering_action.exec_label);
1202 gtk_widget_hide(filtering_action.exec_btn);
1203 gtk_widget_hide(filtering_action.color_optmenu);
1204 gtk_widget_hide(filtering_action.color_label);
1205 gtk_widget_hide(filtering_action.score_label);
1208 gtk_widget_show(filtering_action.account_label);
1209 gtk_widget_set_sensitive(filtering_action.account_label, FALSE);
1210 gtk_widget_set_sensitive(filtering_action.account_combo, FALSE);
1211 gtk_widget_show(filtering_action.dest_entry);
1212 gtk_widget_set_sensitive(filtering_action.dest_entry, TRUE);
1213 gtk_widget_show(filtering_action.dest_btn);
1214 gtk_widget_set_sensitive(filtering_action.dest_btn, TRUE);
1215 gtk_widget_show(filtering_action.dest_label);
1216 gtk_widget_set_sensitive(filtering_action.dest_label, TRUE);
1217 gtk_widget_hide(filtering_action.recip_label);
1218 gtk_widget_hide(filtering_action.exec_label);
1219 gtk_widget_hide(filtering_action.exec_btn);
1220 gtk_widget_hide(filtering_action.color_optmenu);
1221 gtk_widget_hide(filtering_action.color_label);
1222 gtk_widget_hide(filtering_action.score_label);
1225 gtk_widget_show(filtering_action.account_label);
1226 gtk_widget_set_sensitive(filtering_action.account_label, FALSE);
1227 gtk_widget_set_sensitive(filtering_action.account_combo, FALSE);
1228 gtk_widget_show(filtering_action.dest_entry);
1229 gtk_widget_set_sensitive(filtering_action.dest_entry, FALSE);
1230 gtk_widget_show(filtering_action.dest_btn);
1231 gtk_widget_set_sensitive(filtering_action.dest_btn, FALSE);
1232 gtk_widget_show(filtering_action.dest_label);
1233 gtk_widget_set_sensitive(filtering_action.dest_label, FALSE);
1234 gtk_widget_hide(filtering_action.recip_label);
1235 gtk_widget_hide(filtering_action.exec_label);
1236 gtk_widget_hide(filtering_action.exec_btn);
1237 gtk_widget_hide(filtering_action.color_optmenu);
1238 gtk_widget_hide(filtering_action.color_label);
1239 gtk_widget_hide(filtering_action.score_label);
1245 case ACTION_MARK_AS_READ:
1246 case ACTION_MARK_AS_UNREAD:
1249 gtk_widget_show(filtering_action.account_label);
1250 gtk_widget_set_sensitive(filtering_action.account_label, FALSE);
1251 gtk_widget_set_sensitive(filtering_action.account_combo, FALSE);
1252 gtk_widget_show(filtering_action.dest_entry);
1253 gtk_widget_set_sensitive(filtering_action.dest_entry, FALSE);
1254 gtk_widget_show(filtering_action.dest_btn);
1255 gtk_widget_set_sensitive(filtering_action.dest_btn, FALSE);
1256 gtk_widget_show(filtering_action.dest_label);
1257 gtk_widget_set_sensitive(filtering_action.dest_label, FALSE);
1258 gtk_widget_hide(filtering_action.recip_label);
1259 gtk_widget_hide(filtering_action.exec_label);
1260 gtk_widget_hide(filtering_action.exec_btn);
1261 gtk_widget_hide(filtering_action.color_optmenu);
1262 gtk_widget_hide(filtering_action.color_label);
1263 gtk_widget_hide(filtering_action.score_label);
1265 case ACTION_FORWARD:
1266 gtk_widget_show(filtering_action.account_label);
1267 gtk_widget_set_sensitive(filtering_action.account_label, TRUE);
1268 gtk_widget_set_sensitive(filtering_action.account_combo, TRUE);
1269 gtk_widget_show(filtering_action.dest_entry);
1270 gtk_widget_set_sensitive(filtering_action.dest_entry, TRUE);
1271 gtk_widget_show(filtering_action.dest_btn);
1272 gtk_widget_set_sensitive(filtering_action.dest_btn, FALSE);
1273 gtk_widget_hide(filtering_action.dest_label);
1274 gtk_widget_show(filtering_action.recip_label);
1275 gtk_widget_set_sensitive(filtering_action.recip_label, TRUE);
1276 gtk_widget_hide(filtering_action.exec_label);
1277 gtk_widget_hide(filtering_action.exec_btn);
1278 gtk_widget_hide(filtering_action.color_optmenu);
1279 gtk_widget_hide(filtering_action.color_label);
1280 gtk_widget_hide(filtering_action.score_label);
1282 case ACTION_FORWARD_AS_ATTACHMENT:
1283 gtk_widget_show(filtering_action.account_label);
1284 gtk_widget_set_sensitive(filtering_action.account_label, TRUE);
1285 gtk_widget_set_sensitive(filtering_action.account_combo, TRUE);
1286 gtk_widget_show(filtering_action.dest_entry);
1287 gtk_widget_set_sensitive(filtering_action.dest_entry, TRUE);
1288 gtk_widget_show(filtering_action.dest_btn);
1289 gtk_widget_set_sensitive(filtering_action.dest_btn, FALSE);
1290 gtk_widget_hide(filtering_action.dest_label);
1291 gtk_widget_show(filtering_action.recip_label);
1292 gtk_widget_set_sensitive(filtering_action.recip_label, TRUE);
1293 gtk_widget_hide(filtering_action.exec_label);
1294 gtk_widget_hide(filtering_action.exec_btn);
1295 gtk_widget_hide(filtering_action.color_optmenu);
1296 gtk_widget_hide(filtering_action.color_label);
1297 gtk_widget_hide(filtering_action.score_label);
1299 case ACTION_REDIRECT:
1300 gtk_widget_show(filtering_action.account_label);
1301 gtk_widget_set_sensitive(filtering_action.account_label, TRUE);
1302 gtk_widget_set_sensitive(filtering_action.account_combo, TRUE);
1303 gtk_widget_show(filtering_action.dest_entry);
1304 gtk_widget_set_sensitive(filtering_action.dest_entry, TRUE);
1305 gtk_widget_show(filtering_action.dest_btn);
1306 gtk_widget_set_sensitive(filtering_action.dest_btn, FALSE);
1307 gtk_widget_hide(filtering_action.dest_label);
1308 gtk_widget_show(filtering_action.recip_label);
1309 gtk_widget_set_sensitive(filtering_action.recip_label, TRUE);
1310 gtk_widget_hide(filtering_action.exec_label);
1311 gtk_widget_hide(filtering_action.exec_btn);
1312 gtk_widget_hide(filtering_action.color_optmenu);
1313 gtk_widget_hide(filtering_action.color_label);
1314 gtk_widget_hide(filtering_action.score_label);
1316 case ACTION_EXECUTE:
1317 gtk_widget_show(filtering_action.account_label);
1318 gtk_widget_set_sensitive(filtering_action.account_label, FALSE);
1319 gtk_widget_set_sensitive(filtering_action.account_combo, FALSE);
1320 gtk_widget_show(filtering_action.dest_entry);
1321 gtk_widget_set_sensitive(filtering_action.dest_entry, TRUE);
1322 gtk_widget_hide(filtering_action.dest_btn);
1323 gtk_widget_hide(filtering_action.dest_label);
1324 gtk_widget_hide(filtering_action.recip_label);
1325 gtk_widget_show(filtering_action.exec_label);
1326 gtk_widget_set_sensitive(filtering_action.exec_btn, TRUE);
1327 gtk_widget_show(filtering_action.exec_btn);
1328 gtk_widget_hide(filtering_action.color_optmenu);
1329 gtk_widget_hide(filtering_action.color_label);
1330 gtk_widget_hide(filtering_action.score_label);
1333 gtk_widget_show(filtering_action.account_label);
1334 gtk_widget_set_sensitive(filtering_action.account_label, FALSE);
1335 gtk_widget_set_sensitive(filtering_action.account_combo, FALSE);
1336 gtk_widget_hide(filtering_action.dest_entry);
1337 gtk_widget_hide(filtering_action.dest_btn);
1338 gtk_widget_hide(filtering_action.dest_label);
1339 gtk_widget_hide(filtering_action.recip_label);
1340 gtk_widget_hide(filtering_action.exec_label);
1341 gtk_widget_show(filtering_action.exec_btn);
1342 gtk_widget_set_sensitive(filtering_action.exec_btn, FALSE);
1343 gtk_widget_show(filtering_action.color_optmenu);
1344 gtk_widget_show(filtering_action.color_label);
1345 gtk_widget_hide(filtering_action.score_label);
1347 case ACTION_CHANGE_SCORE:
1348 case ACTION_SET_SCORE:
1349 gtk_widget_show(filtering_action.account_label);
1350 gtk_widget_set_sensitive(filtering_action.account_label, FALSE);
1351 gtk_widget_set_sensitive(filtering_action.account_combo, FALSE);
1352 gtk_widget_show(filtering_action.dest_entry);
1353 gtk_widget_set_sensitive(filtering_action.dest_entry, TRUE);
1354 gtk_widget_hide(filtering_action.dest_btn);
1355 gtk_widget_hide(filtering_action.dest_label);
1356 gtk_widget_hide(filtering_action.recip_label);
1357 gtk_widget_hide(filtering_action.exec_label);
1358 gtk_widget_show(filtering_action.exec_btn);
1359 gtk_widget_set_sensitive(filtering_action.exec_btn, FALSE);
1360 gtk_widget_hide(filtering_action.color_optmenu);
1361 gtk_widget_hide(filtering_action.color_label);
1362 gtk_widget_show(filtering_action.score_label);
1367 static void prefs_filtering_action_reset_dialog(void)
1369 gtk_list_select_item(GTK_LIST(filtering_action.action_type_list), 0);
1370 gtk_list_select_item(GTK_LIST(filtering_action.account_list), 0);
1371 gtk_entry_set_text(GTK_ENTRY(filtering_action.dest_entry), "");