remove gtk_window_set_wmclass()
[claws.git] / src / prefs_filtering_action.c
1 /*
2  * Sylpheed -- a GTK+ based, lightweight, and fast e-mail client
3  * Copyright (C) 1999-2001 Hiroyuki Yamamoto
4  *
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.
9  *
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.
14  *
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.
18  */
19
20 #ifdef HAVE_CONFIG_H
21 #  include "config.h"
22 #endif
23
24 #include "defs.h"
25
26 #include <glib.h>
27 #include <gtk/gtk.h>
28 #include <gdk/gdkkeysyms.h>
29 #include <stdio.h>
30 #include <stdlib.h>
31 #include <string.h>
32 #include <errno.h>
33
34 #include "intl.h"
35 #include "main.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"
42 #include "inc.h"
43 #include "matcher.h"
44 #include "utils.h"
45 #include "gtkutils.h"
46 #include "alertpanel.h"
47 #include "folder.h"
48 #include "description_window.h"
49 #include "addr_compl.h"
50
51 #include "matcher_parser.h"
52 #include "colorlabel.h"
53
54
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,
67     gpointer user_data);
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);
77
78
79 /*!
80  *\brief        UI data for matcher dialog
81  */
82 static struct FilteringAction {
83         GtkWidget *window;
84
85         GtkWidget *ok_btn;
86
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;
94         GtkWidget *dest_btn;
95         GtkWidget *dest_label;
96         GtkWidget *recip_label;
97         GtkWidget *exec_label;
98         GtkWidget *exec_btn;
99         GtkWidget *color_label;
100         GtkWidget *color_optmenu;
101         GtkWidget *score_label;
102
103         gint current_action;
104 } filtering_action;
105
106
107 typedef enum Action_ {
108         ACTION_MOVE,
109         ACTION_COPY,
110         ACTION_DELETE,
111         ACTION_MARK,
112         ACTION_UNMARK,
113         ACTION_LOCK,
114         ACTION_UNLOCK,
115         ACTION_MARK_AS_READ,
116         ACTION_MARK_AS_UNREAD,
117         ACTION_FORWARD,
118         ACTION_FORWARD_AS_ATTACHMENT,
119         ACTION_REDIRECT,
120         ACTION_EXECUTE,
121         ACTION_COLOR,
122         ACTION_CHANGE_SCORE,
123         ACTION_SET_SCORE,
124         ACTION_HIDE,
125         ACTION_STOP,
126         /* add other action constants */
127 } Action;
128
129 static struct {
130         gchar *text;
131         Action action;
132 } action_text [] = {
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     },
151 };
152
153
154 /*!
155  *\brief        Hooks
156  */
157 static PrefsFilteringActionSignal *filtering_action_callback;
158
159 /*!
160  *\brief        Find index of list selection 
161  *
162  *\param        list GTK list widget
163  *
164  *\return       gint Selection index
165  */
166 static gint get_sel_from_list(GtkList *list)
167 {
168         gint row = 0;
169         void * sel;
170         GList * child;
171
172         if (list->selection == NULL) 
173                 return -1;
174
175         sel = list->selection->data;
176         for (child = list->children; child != NULL; child = g_list_next(child)) {
177                 if (child->data == sel)
178                         return row;
179                 row ++;
180         }
181         
182         return row;
183 }
184
185 /*!
186  *\brief        Opens the filtering action dialog with a list of actions
187  *
188  *\param        matchers List of conditions
189  *\param        cb Callback
190  *
191  */
192 void prefs_filtering_action_open(GSList *action_list,
193     PrefsFilteringActionSignal *cb)
194 {
195         inc_lock();
196
197         if (!filtering_action.window) {
198                 prefs_filtering_action_create();
199         }
200
201         manage_window_set_transient(GTK_WINDOW(filtering_action.window));
202         gtk_widget_grab_focus(filtering_action.ok_btn);
203
204         filtering_action_callback = cb;
205
206         prefs_filtering_action_set_dialog(action_list);
207
208         gtk_widget_show(filtering_action.window);
209 }
210
211 /*!
212  *\brief        Create the matcher dialog
213  */
214 static void prefs_filtering_action_create(void)
215 {
216         GtkWidget *window;
217         GtkWidget *vbox;
218         GtkWidget *ok_btn;
219         GtkWidget *cancel_btn;
220         GtkWidget *confirm_area;
221
222         GtkWidget *vbox1;
223
224         GtkWidget *hbox1;
225
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;
238         GtkWidget *dest_btn;
239         GList * cur;
240
241         GtkWidget *reg_hbox;
242         GtkWidget *btn_hbox;
243         GtkWidget *arrow;
244         GtkWidget *reg_btn;
245         GtkWidget *subst_btn;
246         GtkWidget *del_btn;
247
248         GtkWidget *action_hbox;
249         GtkWidget *action_scrolledwin;
250         GtkWidget *action_clist;
251
252         GtkWidget *btn_vbox;
253         GtkWidget *up_btn;
254         GtkWidget *down_btn;
255
256         GtkWidget *exec_btn;
257
258         GtkWidget *color_optmenu;
259
260         GList *combo_items;
261         gint i;
262
263         gchar *title[1];
264         GList * accounts;
265
266         debug_print("Creating matcher configuration window...\n");
267
268         window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
269         gtk_container_set_border_width(GTK_CONTAINER(window), 8);
270         gtk_window_set_position(GTK_WINDOW(window), GTK_WIN_POS_CENTER);
271         gtk_window_set_modal(GTK_WINDOW(window), TRUE);
272         gtk_window_set_resizable(GTK_WINDOW(window), TRUE);
273
274         vbox = gtk_vbox_new(FALSE, 6);
275         gtk_widget_show(vbox);
276         gtk_container_add(GTK_CONTAINER(window), vbox);
277
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);
283
284         gtk_window_set_title(GTK_WINDOW(window),
285                              _("Filtering action configuration"));
286         g_signal_connect(G_OBJECT(window), "delete_event",
287                          G_CALLBACK(prefs_filtering_action_deleted), NULL);
288         g_signal_connect(G_OBJECT(window), "key_press_event",
289                          G_CALLBACK(prefs_filtering_action_key_pressed), NULL);
290         MANAGE_WINDOW_SIGNALS_CONNECT(window);
291         g_signal_connect(G_OBJECT(ok_btn), "clicked",
292                          G_CALLBACK(prefs_filtering_action_ok), NULL);
293         g_signal_connect(G_OBJECT(cancel_btn), "clicked",
294                          G_CALLBACK(prefs_filtering_action_cancel), NULL);
295
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);
300
301         /* action to be defined */
302
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);
307
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);
312
313         action_combo = gtk_combo_new ();
314         gtk_widget_show (action_combo);
315         gtk_entry_set_editable(GTK_ENTRY(GTK_COMBO(action_combo)->entry),
316                                FALSE);
317
318         combo_items = NULL;
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);
323
324         g_list_free(combo_items);
325
326         gtk_box_pack_start (GTK_BOX (hbox1), action_combo,
327                             TRUE, TRUE, 0);
328         action_type_list = GTK_COMBO(action_combo)->list;
329         g_signal_connect (G_OBJECT(action_type_list), "select-child",
330                           G_CALLBACK(prefs_filtering_action_type_select),
331                           NULL);
332
333         g_signal_connect(G_OBJECT(action_type_list), "selection-changed",
334                          G_CALLBACK(prefs_filtering_action_type_selection_changed),
335                          NULL);
336
337         /* accounts */
338
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);
343
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);
348
349         account_combo = gtk_combo_new ();
350         gtk_widget_set_usize (account_combo, 150, -1);
351         gtk_widget_show (account_combo);
352
353         combo_items = NULL;
354         for (accounts = account_get_list() ; accounts != NULL;
355              accounts = accounts->next) {
356                 PrefsAccount *ac = (PrefsAccount *)accounts->data;
357                 gchar *name;
358
359                 name = g_strdup_printf("%s <%s> (%s)",
360                                        ac->name, ac->address,
361                                        ac->account_name);
362                 combo_items = g_list_append(combo_items, (gpointer) name);
363         }
364
365         gtk_combo_set_popdown_strings(GTK_COMBO(account_combo), combo_items);
366
367         for(cur = g_list_first(combo_items) ; cur != NULL ;
368             cur = g_list_next(cur))
369                 g_free(cur->data);
370         g_list_free(combo_items);
371
372         gtk_box_pack_start (GTK_BOX (hbox1), account_combo,
373                             TRUE, TRUE, 0);
374         account_list = GTK_COMBO(account_combo)->list;
375         gtk_entry_set_editable(GTK_ENTRY(GTK_COMBO(account_combo)->entry),
376                                FALSE);
377
378         /* destination */
379
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);
384
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);
389
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);
394
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);
399         
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);
404
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);
409
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);
414         
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);
419
420         dest_btn = gtk_button_new_with_label (_("Select ..."));
421         gtk_widget_show (dest_btn);
422         gtk_box_pack_start (GTK_BOX (hbox1), dest_btn, FALSE, FALSE, 0);
423         g_signal_connect (G_OBJECT (dest_btn), "clicked",
424                           G_CALLBACK(prefs_filtering_action_select_dest),
425                           NULL);
426
427         exec_btn = gtk_button_new_with_label (_("Info ..."));
428         gtk_widget_show (exec_btn);
429         gtk_box_pack_start (GTK_BOX (hbox1), exec_btn, FALSE, FALSE, 0);
430         g_signal_connect (G_OBJECT (exec_btn), "clicked",
431                           G_CALLBACK(prefs_filtering_action_exec_info),
432                           NULL);
433
434         /* register / substitute / delete */
435
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);
439
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);
444
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);
448
449         reg_btn = gtk_button_new_with_label(_("Add"));
450         gtk_widget_show(reg_btn);
451         gtk_box_pack_start(GTK_BOX(btn_hbox), reg_btn, FALSE, TRUE, 0);
452         g_signal_connect(G_OBJECT(reg_btn), "clicked",
453                          G_CALLBACK(prefs_filtering_action_register_cb), NULL);
454
455         subst_btn = gtk_button_new_with_label(_("  Replace  "));
456         gtk_widget_show(subst_btn);
457         gtk_box_pack_start(GTK_BOX(btn_hbox), subst_btn, FALSE, TRUE, 0);
458         g_signal_connect(G_OBJECT(subst_btn), "clicked",
459                          G_CALLBACK(prefs_filtering_action_substitute_cb),
460                          NULL);
461
462         del_btn = gtk_button_new_with_label(_("Delete"));
463         gtk_widget_show(del_btn);
464         gtk_box_pack_start(GTK_BOX(btn_hbox), del_btn, FALSE, TRUE, 0);
465         g_signal_connect(G_OBJECT(del_btn), "clicked",
466                          G_CALLBACK(prefs_filtering_action_delete_cb), NULL);
467
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);
471
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,
476                            TRUE, TRUE, 0);
477         gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(action_scrolledwin),
478                                        GTK_POLICY_AUTOMATIC,
479                                        GTK_POLICY_AUTOMATIC);
480
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,
489                                GTK_CAN_FOCUS);
490         g_signal_connect(G_OBJECT(action_clist), "select_row",
491                          G_CALLBACK(prefs_filtering_action_select), NULL);
492
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);
496
497         up_btn = gtk_button_new_with_label(_("Up"));
498         gtk_widget_show(up_btn);
499         gtk_box_pack_start(GTK_BOX(btn_vbox), up_btn, FALSE, FALSE, 0);
500         g_signal_connect(G_OBJECT(up_btn), "clicked",
501                          G_CALLBACK(prefs_filtering_action_up), NULL);
502
503         down_btn = gtk_button_new_with_label(_("Down"));
504         gtk_widget_show(down_btn);
505         gtk_box_pack_start(GTK_BOX(btn_vbox), down_btn, FALSE, FALSE, 0);
506         g_signal_connect(G_OBJECT(down_btn), "clicked",
507                          G_CALLBACK(prefs_filtering_action_down), NULL);
508
509         gtk_widget_show_all(window);
510
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;
528 }
529
530 /*!
531  *\brief        Set the contents of a row
532  *
533  *\param        row Index of row to set
534  *\param        prop Condition to set
535  *
536  *\return       gint Row index \a prop has been added
537  */
538 static gint prefs_filtering_action_clist_set_row(gint row, FilteringAction *action)
539 {
540         GtkCList *clist = GTK_CLIST(filtering_action.action_clist);
541         gchar *action_tab_str[1];
542         gchar *action_str;
543         gchar buf[256];
544
545         if (action == NULL) {
546                 action_tab_str[0] = _("(New)");
547                 return gtk_clist_append(clist, action_tab_str);
548         }
549
550         filteringaction_to_string(buf, sizeof buf, action);
551         action_str = g_strdup(buf);
552         
553         action_tab_str[0] = action_str;
554         if (row < 0)
555                 row = gtk_clist_append(clist, action_tab_str);
556         else
557                 gtk_clist_set_text(clist, row, 0, action_tab_str[0]);
558         g_free(action_str);
559
560         return row;
561 }
562
563 /*!
564  *\brief        Update scrollbar
565  */
566 static void prefs_filtering_action_update_hscrollbar(void)
567 {
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);
570 }
571
572 /*!
573  *\brief        Initializes dialog with a set of conditions
574  *
575  *\param        matchers List of conditions
576  */
577 static void prefs_filtering_action_set_dialog(GSList *action_list)
578 {
579         GtkCList *clist = GTK_CLIST(filtering_action.action_clist);
580         GSList *cur;
581
582         gtk_clist_freeze(clist);
583         gtk_clist_clear(clist);
584
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);
592                 }
593         }
594         
595         prefs_filtering_action_update_hscrollbar();
596
597         gtk_clist_thaw(clist);
598
599         prefs_filtering_action_reset_dialog();
600 }
601
602 /*!
603  *\brief        Converts current actions in list box in
604  *              an action list used by the filtering system.
605  *
606  *\return       GSList * List of actions.
607  */
608 static GSList *prefs_filtering_action_get_list(void)
609 {
610         gchar *action_str;
611         gint row = 1;
612         GSList *action_list;
613
614         action_list = NULL;
615
616         while (gtk_clist_get_text(GTK_CLIST(filtering_action.action_clist),
617                                   row, 0, &action_str)) {
618
619                 if (strcmp(action_str, _("(New)")) != 0) {
620                         GSList * tmp_action_list;
621                         tmp_action_list = matcher_parser_get_action_list(action_str);
622                         
623                         if (tmp_action_list == NULL)
624                                 break;
625
626                         action_list = g_slist_concat(action_list,
627                             tmp_action_list);
628                 }
629                 row ++;
630         }
631
632         return action_list;
633 }
634
635 /*!
636  *\brief        Returns account ID from the given list index
637  *
638  *\return       gint account ID
639  */
640 static gint get_account_id_from_list_id(gint list_id)
641 {
642         GList * accounts;
643
644         for (accounts = account_get_list() ; accounts != NULL;
645              accounts = accounts->next) {
646                 PrefsAccount *ac = (PrefsAccount *)accounts->data;
647
648                 if (list_id == 0)
649                         return ac->account_id;
650                 list_id--;
651         }
652         return 0;
653 }
654
655 /*!
656  *\brief        Returns list index from the given account ID
657  *
658  *\return       gint list index
659  */
660 static gint get_list_id_from_account_id(gint account_id)
661 {
662         GList * accounts;
663         gint list_id = 0;
664
665         for (accounts = account_get_list() ; accounts != NULL;
666              accounts = accounts->next) {
667                 PrefsAccount *ac = (PrefsAccount *)accounts->data;
668
669                 if (account_id == ac->account_id)
670                         return list_id;
671                 list_id++;
672         }
673         return 0;
674 }
675
676
677 /*!
678  *\brief        Returns parser action ID from internal action ID
679  *
680  *\return       gint parser action ID
681  */
682 static gint prefs_filtering_action_get_matching_from_action(Action action_id)
683 {
684         switch (action_id) {
685         case ACTION_MOVE:
686                 return MATCHACTION_MOVE;
687         case ACTION_COPY:
688                 return MATCHACTION_COPY;
689         case ACTION_DELETE:
690                 return MATCHACTION_DELETE;
691         case ACTION_MARK:
692                 return MATCHACTION_MARK;
693         case ACTION_UNMARK:
694                 return MATCHACTION_UNMARK;
695         case ACTION_LOCK:
696                 return MATCHACTION_LOCK;
697         case ACTION_UNLOCK:
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;
703         case ACTION_FORWARD:
704                 return MATCHACTION_FORWARD;
705         case ACTION_FORWARD_AS_ATTACHMENT:
706                 return MATCHACTION_FORWARD_AS_ATTACHMENT;
707         case ACTION_REDIRECT:
708                 return MATCHACTION_REDIRECT;
709         case ACTION_EXECUTE:
710                 return MATCHACTION_EXECUTE;
711         case ACTION_COLOR:
712                 return MATCHACTION_COLOR;
713         case ACTION_HIDE:
714                 return MATCHACTION_HIDE;
715         case ACTION_STOP:
716                 return MATCHACTION_STOP;
717         case ACTION_CHANGE_SCORE:
718                 return MATCHACTION_CHANGE_SCORE;
719         case ACTION_SET_SCORE:
720                 return MATCHACTION_SET_SCORE;
721         default:
722                 return -1;
723         }
724 }
725
726 /*!
727  *\brief        Returns action from the content of the dialog
728  *
729  *\param        alert specifies whether alert dialog boxes should be shown
730  *                or not.
731  *
732  *\return       FilteringAction * action entered in the dialog box.
733  */
734 static FilteringAction * prefs_filtering_action_dialog_to_action(gboolean alert)
735 {
736         Action action_id;
737         gint action_type;
738         gint list_id;
739         gint account_id;
740         const gchar * destination;
741         gint labelcolor = 0;
742         FilteringAction * action;
743         gchar * score_str;
744         gint score;
745         
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);
750         score = 0;
751         destination = NULL;
752         
753         switch (action_id) {
754         case ACTION_MOVE:
755         case ACTION_COPY:
756         case ACTION_EXECUTE:
757                 destination = gtk_entry_get_text(GTK_ENTRY(filtering_action.dest_entry));
758                 if (*destination == '\0') {
759                         if (alert)
760                                 alertpanel_error(action_id == ACTION_EXECUTE 
761                                                  ? _("Command line not set")
762                                                  : _("Destination is not set."));
763                         return NULL;
764                 }
765                 break;
766         case ACTION_FORWARD:
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') {
771                         if (alert)
772                                 alertpanel_error(_("Recipient is not set."));
773                         return NULL;
774                 }
775                 break;
776         case ACTION_COLOR:
777                 labelcolor = colorlabel_get_color_menu_active_item(
778                         gtk_option_menu_get_menu(GTK_OPTION_MENU(filtering_action.color_optmenu)));
779                 destination = NULL;     
780                 break;
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') {
785                         if (alert)
786                                 alertpanel_error(_("Score is not set"));
787                         return NULL;
788                 }
789                 score = strtol(score_str, NULL, 10);
790                 break;
791         case ACTION_STOP:
792         case ACTION_HIDE:
793         case ACTION_DELETE:
794         case ACTION_MARK:
795         case ACTION_UNMARK:
796         case ACTION_LOCK:
797         case ACTION_UNLOCK:
798         case ACTION_MARK_AS_READ:
799         case ACTION_MARK_AS_UNREAD:
800         default:
801                 break;
802         }
803         
804         action = filteringaction_new(action_type, account_id,
805             destination, labelcolor, score);
806
807         return action;
808 }
809
810 /*!
811  *\brief        Signal handler for register button
812  */
813 static void prefs_filtering_action_register_cb(void)
814 {
815         FilteringAction *action;
816         
817         action = prefs_filtering_action_dialog_to_action(TRUE);
818         if (action == NULL)
819                 return;
820
821         prefs_filtering_action_clist_set_row(-1, action);
822
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();
832 }
833
834 /*!
835  *\brief        Signal handler for substitute button
836  */
837 static void prefs_filtering_action_substitute_cb(void)
838 {
839         GtkCList *clist = GTK_CLIST(filtering_action.action_clist);
840         gint row;
841         FilteringAction *action;
842
843         if (!clist->selection) return;
844         row = GPOINTER_TO_INT(clist->selection->data);
845         if (row == 0)
846                 return;
847         
848         action = prefs_filtering_action_dialog_to_action(TRUE);
849         if (action == NULL)
850                 return;
851
852         prefs_filtering_action_clist_set_row(row, action);
853
854         filteringaction_free(action);
855
856         prefs_filtering_action_reset_dialog();
857         
858         prefs_filtering_action_update_hscrollbar();
859 }
860
861 /*!
862  *\brief        Signal handler for delete button
863  */
864 static void prefs_filtering_action_delete_cb(void)
865 {
866         GtkCList *clist = GTK_CLIST(filtering_action.action_clist);
867         gint row;
868
869         if (!clist->selection) return;
870         row = GPOINTER_TO_INT(clist->selection->data);
871         if (row == 0)
872                 return;
873
874         gtk_clist_remove(clist, row);
875
876         prefs_filtering_action_reset_dialog();
877
878         prefs_filtering_action_update_hscrollbar();
879 }
880
881 /*!
882  *\brief        Signal handler for 'move up' button
883  */
884 static void prefs_filtering_action_up(void)
885 {
886         GtkCList *clist = GTK_CLIST(filtering_action.action_clist);
887         gint row;
888
889         if (!clist->selection) return;
890
891         row = GPOINTER_TO_INT(clist->selection->data);
892         if (row > 1) {
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);
896         }
897 }
898
899 /*!
900  *\brief        Signal handler for 'move down' button
901  */
902 static void prefs_filtering_action_down(void)
903 {
904         GtkCList *clist = GTK_CLIST(filtering_action.action_clist);
905         gint row;
906
907         if (!clist->selection) return;
908
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);
914         }
915 }
916
917 /*!
918  *\brief        Signal handler for select row.
919  *
920  *\param        clist List widget
921  *\param        row Selected row
922  *\param        column Selected column
923  *\param        event Event information
924  */
925 static void prefs_filtering_action_select(GtkCList *clist,
926     gint row, gint column, GdkEvent *event)
927 {
928         gchar *action_str;
929         FilteringAction *action;
930         GSList * action_list;
931         gint list_id;
932
933         if (!gtk_clist_get_text(GTK_CLIST(filtering_action.action_clist),
934                                 row, 0, &action_str))
935                 return;
936
937         if (row == 0) {
938                 prefs_filtering_action_reset_dialog();
939                 return;
940         }
941
942         action_list = matcher_parser_get_action_list(action_str);
943         if (action_list == NULL)
944                 return;
945
946         action = action_list->data;
947         g_slist_free(action_list);
948
949         if (action->destination)
950                 gtk_entry_set_text(GTK_ENTRY(filtering_action.dest_entry), action->destination);
951         else
952                 gtk_entry_set_text(GTK_ENTRY(filtering_action.dest_entry), "");
953
954         switch(action->type) {
955         case MATCHACTION_MOVE:
956                 gtk_list_select_item(GTK_LIST(filtering_action.action_type_list),
957                                      ACTION_MOVE);
958                 break;
959         case MATCHACTION_COPY:
960                 gtk_list_select_item(GTK_LIST(filtering_action.action_type_list),
961                                      ACTION_COPY);
962                 break;
963         case MATCHACTION_DELETE:
964                 gtk_list_select_item(GTK_LIST(filtering_action.action_type_list),
965                                      ACTION_DELETE);
966                 break;
967         case MATCHACTION_MARK:
968                 gtk_list_select_item(GTK_LIST(filtering_action.action_type_list),
969                                      ACTION_MARK);
970                 break;
971         case MATCHACTION_UNMARK:
972                 gtk_list_select_item(GTK_LIST(filtering_action.action_type_list),
973                                      ACTION_UNMARK);
974                 break;
975         case MATCHACTION_LOCK:
976                 gtk_list_select_item(GTK_LIST(filtering_action.action_type_list),
977                                      ACTION_LOCK);
978                 break;
979         case MATCHACTION_UNLOCK:
980                 gtk_list_select_item(GTK_LIST(filtering_action.action_type_list),
981                                      ACTION_UNLOCK);
982                 break;
983         case MATCHACTION_MARK_AS_READ:
984                 gtk_list_select_item(GTK_LIST(filtering_action.action_type_list),
985                                      ACTION_MARK_AS_READ);
986                 break;
987         case MATCHACTION_MARK_AS_UNREAD:
988                 gtk_list_select_item(GTK_LIST(filtering_action.action_type_list),
989                                      ACTION_MARK_AS_UNREAD);
990                 break;
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),
994                                      ACTION_FORWARD);
995                 gtk_list_select_item(GTK_LIST(filtering_action.account_list),
996                                      list_id);
997                 break;
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),
1003                                      list_id);
1004                 break;
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),
1008                                      ACTION_REDIRECT);
1009                 gtk_list_select_item(GTK_LIST(filtering_action.account_list),
1010                                      list_id);
1011                 break;
1012         case MATCHACTION_EXECUTE:
1013                 gtk_list_select_item(GTK_LIST(filtering_action.action_type_list),
1014                                      ACTION_EXECUTE);
1015                 break;
1016         case MATCHACTION_COLOR:
1017                 gtk_list_select_item(GTK_LIST(filtering_action.action_type_list),
1018                                      ACTION_COLOR);
1019                 gtk_option_menu_set_history(GTK_OPTION_MENU(filtering_action.color_optmenu), action->labelcolor);     
1020                 break;
1021         case MATCHACTION_CHANGE_SCORE:
1022                 gtk_list_select_item(GTK_LIST(filtering_action.action_type_list),
1023                                      ACTION_CHANGE_SCORE);
1024                 break;
1025         case MATCHACTION_SET_SCORE:
1026                 gtk_list_select_item(GTK_LIST(filtering_action.action_type_list),
1027                                      ACTION_SET_SCORE);
1028                 break;
1029         case MATCHACTION_STOP:
1030                 gtk_list_select_item(GTK_LIST(filtering_action.action_type_list),
1031                                      ACTION_STOP);
1032                 break;
1033         case MATCHACTION_HIDE:
1034                 gtk_list_select_item(GTK_LIST(filtering_action.action_type_list),
1035                                      ACTION_HIDE);
1036                 break;
1037         }
1038 }
1039
1040 /*!
1041  *\brief        Handle key press
1042  *
1043  *\param        widget Widget receiving key press
1044  *\param        event Key event
1045  *\param        data User data
1046  */
1047 static gboolean prefs_filtering_action_key_pressed(GtkWidget *widget,
1048     GdkEventKey *event, gpointer data)
1049 {
1050         if (event && event->keyval == GDK_Escape) {
1051                 prefs_filtering_action_cancel();
1052                 return TRUE;            
1053         }
1054         return FALSE;
1055 }
1056
1057 /*!
1058  *\brief        Cancel matcher dialog
1059  */
1060 static void prefs_filtering_action_cancel(void)
1061 {
1062         gtk_widget_hide(filtering_action.window);
1063         inc_unlock();
1064 }
1065
1066 /*!
1067  *\brief        Accept current matchers
1068  */
1069 static void prefs_filtering_action_ok(void)
1070 {
1071         GSList * action_list;
1072         GSList * cur;
1073
1074         action_list = prefs_filtering_action_get_list();
1075
1076         if (action_list == NULL) {
1077                 alertpanel_error(_("No action was defined."));
1078                 return;
1079         }
1080
1081         if (filtering_action_callback != NULL)
1082                 filtering_action_callback(action_list);
1083         for(cur = action_list ; cur != NULL ; cur = cur->next) {
1084                 filteringaction_free(cur->data);
1085         }
1086         g_slist_free(action_list);
1087
1088         gtk_widget_hide(filtering_action.window);
1089         inc_unlock();
1090 }
1091
1092 /*!
1093  *\brief        Called when closing dialog box
1094  *
1095  *\param        widget Dialog widget
1096  *\param        event Event info
1097  *\param        data User data
1098  *
1099  *\return       gint TRUE
1100  */
1101 static gint prefs_filtering_action_deleted(GtkWidget *widget,
1102     GdkEventAny *event, gpointer data)
1103 {
1104         prefs_filtering_action_cancel();
1105         return TRUE;
1106 }
1107
1108 /*
1109  * Strings describing exec format strings
1110  * 
1111  * When adding new lines, remember to put 2 strings for each line
1112  */
1113 static gchar *exec_desc_strings[] = {
1114         "%%",   "%",
1115         "%s",   N_("Subject"),
1116         "%f",   N_("From"),
1117         "%t",   N_("To"),
1118         "%c",   N_("Cc"),
1119         "%d",   N_("Date"),
1120         "%i",   N_("Message-ID"),
1121         "%n",   N_("Newsgroups"),
1122         "%r",   N_("References"),
1123         "%F",   N_("Filename - should not be modified"),
1124         "\\n",  N_("new line"),
1125         "\\",   N_("escape character for quotes"),
1126         "\\\"",N_("quote character"),
1127         NULL, NULL
1128 };
1129
1130 static DescriptionWindow exec_desc_win = { 
1131         NULL, 
1132         2,
1133         N_("Description of symbols"),
1134         exec_desc_strings
1135 };
1136
1137
1138
1139 /*!
1140  *\brief        Show Execute action's info
1141  */
1142 void prefs_filtering_action_exec_info(void)
1143 {
1144         description_window_create(&exec_desc_win);
1145 }
1146
1147 static void prefs_filtering_action_select_dest(void)
1148 {
1149         FolderItem *dest;
1150         gchar * path;
1151
1152         dest = foldersel_folder_sel(NULL, FOLDER_SEL_COPY, NULL);
1153         if (!dest) return;
1154
1155         path = folder_item_get_identifier(dest);
1156
1157         gtk_entry_set_text(GTK_ENTRY(filtering_action.dest_entry), path);
1158         g_free(path);
1159 }
1160
1161 static void prefs_filtering_action_type_selection_changed(GtkList *list,
1162     gpointer user_data)
1163 {
1164         gint value;
1165
1166         value = get_sel_from_list(GTK_LIST(filtering_action.action_type_list));
1167
1168         if (filtering_action.current_action != value) {
1169                 if (filtering_action.current_action == ACTION_FORWARD 
1170                 ||  filtering_action.current_action == ACTION_FORWARD_AS_ATTACHMENT
1171                 ||  filtering_action.current_action == ACTION_REDIRECT) {
1172                         debug_print("unregistering address completion entry\n");
1173                         address_completion_unregister_entry(GTK_ENTRY(filtering_action.dest_entry));
1174                 }
1175                 if (value == ACTION_FORWARD || value == ACTION_FORWARD_AS_ATTACHMENT
1176                 ||  value == ACTION_REDIRECT) {
1177                         debug_print("registering address completion entry\n");
1178                         address_completion_register_entry(GTK_ENTRY(filtering_action.dest_entry));
1179                 }
1180                 filtering_action.current_action = value;
1181         }
1182 }
1183
1184 static void prefs_filtering_action_type_select(GtkList *list,
1185     GtkWidget *widget, gpointer user_data)
1186 {
1187         Action value;
1188
1189         value = (Action) get_sel_from_list(GTK_LIST(filtering_action.action_type_list));
1190
1191         switch (value) {
1192         case ACTION_MOVE:
1193                 gtk_widget_show(filtering_action.account_label);
1194                 gtk_widget_set_sensitive(filtering_action.account_label, FALSE);
1195                 gtk_widget_set_sensitive(filtering_action.account_combo, FALSE);
1196                 gtk_widget_show(filtering_action.dest_entry);
1197                 gtk_widget_set_sensitive(filtering_action.dest_entry, TRUE);
1198                 gtk_widget_show(filtering_action.dest_btn);
1199                 gtk_widget_set_sensitive(filtering_action.dest_btn, TRUE);
1200                 gtk_widget_show(filtering_action.dest_label);
1201                 gtk_widget_set_sensitive(filtering_action.dest_label, TRUE);
1202                 gtk_widget_hide(filtering_action.recip_label);
1203                 gtk_widget_hide(filtering_action.exec_label);
1204                 gtk_widget_hide(filtering_action.exec_btn);
1205                 gtk_widget_hide(filtering_action.color_optmenu);
1206                 gtk_widget_hide(filtering_action.color_label);
1207                 gtk_widget_hide(filtering_action.score_label);
1208                 break;
1209         case ACTION_COPY:
1210                 gtk_widget_show(filtering_action.account_label);
1211                 gtk_widget_set_sensitive(filtering_action.account_label, FALSE);
1212                 gtk_widget_set_sensitive(filtering_action.account_combo, FALSE);
1213                 gtk_widget_show(filtering_action.dest_entry);
1214                 gtk_widget_set_sensitive(filtering_action.dest_entry, TRUE);
1215                 gtk_widget_show(filtering_action.dest_btn);
1216                 gtk_widget_set_sensitive(filtering_action.dest_btn, TRUE);
1217                 gtk_widget_show(filtering_action.dest_label);
1218                 gtk_widget_set_sensitive(filtering_action.dest_label, TRUE);
1219                 gtk_widget_hide(filtering_action.recip_label);
1220                 gtk_widget_hide(filtering_action.exec_label);
1221                 gtk_widget_hide(filtering_action.exec_btn);
1222                 gtk_widget_hide(filtering_action.color_optmenu);
1223                 gtk_widget_hide(filtering_action.color_label);
1224                 gtk_widget_hide(filtering_action.score_label);
1225                 break;
1226         case ACTION_DELETE:
1227                 gtk_widget_show(filtering_action.account_label);
1228                 gtk_widget_set_sensitive(filtering_action.account_label, FALSE);
1229                 gtk_widget_set_sensitive(filtering_action.account_combo, FALSE);
1230                 gtk_widget_show(filtering_action.dest_entry);
1231                 gtk_widget_set_sensitive(filtering_action.dest_entry, FALSE);
1232                 gtk_widget_show(filtering_action.dest_btn);
1233                 gtk_widget_set_sensitive(filtering_action.dest_btn, FALSE);
1234                 gtk_widget_show(filtering_action.dest_label);
1235                 gtk_widget_set_sensitive(filtering_action.dest_label, FALSE);
1236                 gtk_widget_hide(filtering_action.recip_label);
1237                 gtk_widget_hide(filtering_action.exec_label);
1238                 gtk_widget_hide(filtering_action.exec_btn);
1239                 gtk_widget_hide(filtering_action.color_optmenu);
1240                 gtk_widget_hide(filtering_action.color_label);
1241                 gtk_widget_hide(filtering_action.score_label);
1242                 break;
1243         case ACTION_MARK:
1244         case ACTION_UNMARK:
1245         case ACTION_LOCK:
1246         case ACTION_UNLOCK:
1247         case ACTION_MARK_AS_READ:
1248         case ACTION_MARK_AS_UNREAD:
1249         case ACTION_STOP:
1250         case ACTION_HIDE:
1251                 gtk_widget_show(filtering_action.account_label);
1252                 gtk_widget_set_sensitive(filtering_action.account_label, FALSE);
1253                 gtk_widget_set_sensitive(filtering_action.account_combo, FALSE);
1254                 gtk_widget_show(filtering_action.dest_entry);
1255                 gtk_widget_set_sensitive(filtering_action.dest_entry, FALSE);
1256                 gtk_widget_show(filtering_action.dest_btn);
1257                 gtk_widget_set_sensitive(filtering_action.dest_btn, FALSE);
1258                 gtk_widget_show(filtering_action.dest_label);
1259                 gtk_widget_set_sensitive(filtering_action.dest_label, FALSE);
1260                 gtk_widget_hide(filtering_action.recip_label);
1261                 gtk_widget_hide(filtering_action.exec_label);
1262                 gtk_widget_hide(filtering_action.exec_btn);
1263                 gtk_widget_hide(filtering_action.color_optmenu);
1264                 gtk_widget_hide(filtering_action.color_label);
1265                 gtk_widget_hide(filtering_action.score_label);
1266                 break;
1267         case ACTION_FORWARD:
1268                 gtk_widget_show(filtering_action.account_label);
1269                 gtk_widget_set_sensitive(filtering_action.account_label, TRUE);
1270                 gtk_widget_set_sensitive(filtering_action.account_combo, TRUE);
1271                 gtk_widget_show(filtering_action.dest_entry);
1272                 gtk_widget_set_sensitive(filtering_action.dest_entry, TRUE);
1273                 gtk_widget_show(filtering_action.dest_btn);
1274                 gtk_widget_set_sensitive(filtering_action.dest_btn, FALSE);
1275                 gtk_widget_hide(filtering_action.dest_label);
1276                 gtk_widget_show(filtering_action.recip_label);
1277                 gtk_widget_set_sensitive(filtering_action.recip_label, TRUE);
1278                 gtk_widget_hide(filtering_action.exec_label);
1279                 gtk_widget_hide(filtering_action.exec_btn);
1280                 gtk_widget_hide(filtering_action.color_optmenu);
1281                 gtk_widget_hide(filtering_action.color_label);
1282                 gtk_widget_hide(filtering_action.score_label);
1283                 break;
1284         case ACTION_FORWARD_AS_ATTACHMENT:
1285                 gtk_widget_show(filtering_action.account_label);
1286                 gtk_widget_set_sensitive(filtering_action.account_label, TRUE);
1287                 gtk_widget_set_sensitive(filtering_action.account_combo, TRUE);
1288                 gtk_widget_show(filtering_action.dest_entry);
1289                 gtk_widget_set_sensitive(filtering_action.dest_entry, TRUE);
1290                 gtk_widget_show(filtering_action.dest_btn);
1291                 gtk_widget_set_sensitive(filtering_action.dest_btn, FALSE);
1292                 gtk_widget_hide(filtering_action.dest_label);
1293                 gtk_widget_show(filtering_action.recip_label);
1294                 gtk_widget_set_sensitive(filtering_action.recip_label, TRUE);
1295                 gtk_widget_hide(filtering_action.exec_label);
1296                 gtk_widget_hide(filtering_action.exec_btn);
1297                 gtk_widget_hide(filtering_action.color_optmenu);
1298                 gtk_widget_hide(filtering_action.color_label);
1299                 gtk_widget_hide(filtering_action.score_label);
1300                 break;
1301         case ACTION_REDIRECT:
1302                 gtk_widget_show(filtering_action.account_label);
1303                 gtk_widget_set_sensitive(filtering_action.account_label, TRUE);
1304                 gtk_widget_set_sensitive(filtering_action.account_combo, TRUE);
1305                 gtk_widget_show(filtering_action.dest_entry);
1306                 gtk_widget_set_sensitive(filtering_action.dest_entry, TRUE);
1307                 gtk_widget_show(filtering_action.dest_btn);
1308                 gtk_widget_set_sensitive(filtering_action.dest_btn, FALSE);
1309                 gtk_widget_hide(filtering_action.dest_label);
1310                 gtk_widget_show(filtering_action.recip_label);
1311                 gtk_widget_set_sensitive(filtering_action.recip_label, TRUE);
1312                 gtk_widget_hide(filtering_action.exec_label);
1313                 gtk_widget_hide(filtering_action.exec_btn);
1314                 gtk_widget_hide(filtering_action.color_optmenu);
1315                 gtk_widget_hide(filtering_action.color_label);
1316                 gtk_widget_hide(filtering_action.score_label);
1317                 break;
1318         case ACTION_EXECUTE:
1319                 gtk_widget_show(filtering_action.account_label);
1320                 gtk_widget_set_sensitive(filtering_action.account_label, FALSE);
1321                 gtk_widget_set_sensitive(filtering_action.account_combo, FALSE);
1322                 gtk_widget_show(filtering_action.dest_entry);
1323                 gtk_widget_set_sensitive(filtering_action.dest_entry, TRUE);
1324                 gtk_widget_hide(filtering_action.dest_btn);
1325                 gtk_widget_hide(filtering_action.dest_label);
1326                 gtk_widget_hide(filtering_action.recip_label);
1327                 gtk_widget_show(filtering_action.exec_label);
1328                 gtk_widget_set_sensitive(filtering_action.exec_btn, TRUE);
1329                 gtk_widget_show(filtering_action.exec_btn);
1330                 gtk_widget_hide(filtering_action.color_optmenu);
1331                 gtk_widget_hide(filtering_action.color_label);
1332                 gtk_widget_hide(filtering_action.score_label);
1333                 break;
1334         case ACTION_COLOR:
1335                 gtk_widget_show(filtering_action.account_label);
1336                 gtk_widget_set_sensitive(filtering_action.account_label, FALSE);
1337                 gtk_widget_set_sensitive(filtering_action.account_combo, FALSE);
1338                 gtk_widget_hide(filtering_action.dest_entry);
1339                 gtk_widget_hide(filtering_action.dest_btn);
1340                 gtk_widget_hide(filtering_action.dest_label);
1341                 gtk_widget_hide(filtering_action.recip_label);
1342                 gtk_widget_hide(filtering_action.exec_label);
1343                 gtk_widget_show(filtering_action.exec_btn);
1344                 gtk_widget_set_sensitive(filtering_action.exec_btn, FALSE);
1345                 gtk_widget_show(filtering_action.color_optmenu);
1346                 gtk_widget_show(filtering_action.color_label);
1347                 gtk_widget_hide(filtering_action.score_label);
1348                 break;
1349         case ACTION_CHANGE_SCORE:
1350         case ACTION_SET_SCORE:
1351                 gtk_widget_show(filtering_action.account_label);
1352                 gtk_widget_set_sensitive(filtering_action.account_label, FALSE);
1353                 gtk_widget_set_sensitive(filtering_action.account_combo, FALSE);
1354                 gtk_widget_show(filtering_action.dest_entry);
1355                 gtk_widget_set_sensitive(filtering_action.dest_entry, TRUE);
1356                 gtk_widget_hide(filtering_action.dest_btn);
1357                 gtk_widget_hide(filtering_action.dest_label);
1358                 gtk_widget_hide(filtering_action.recip_label);
1359                 gtk_widget_hide(filtering_action.exec_label);
1360                 gtk_widget_show(filtering_action.exec_btn);
1361                 gtk_widget_set_sensitive(filtering_action.exec_btn, FALSE);
1362                 gtk_widget_hide(filtering_action.color_optmenu);
1363                 gtk_widget_hide(filtering_action.color_label);
1364                 gtk_widget_show(filtering_action.score_label);
1365                 break;
1366         }
1367 }
1368
1369 static void prefs_filtering_action_reset_dialog(void)
1370 {
1371         gtk_list_select_item(GTK_LIST(filtering_action.action_type_list), 0);
1372         gtk_list_select_item(GTK_LIST(filtering_action.account_list), 0);
1373         gtk_entry_set_text(GTK_ENTRY(filtering_action.dest_entry), "");
1374 }