inital gtk2 patch
[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
50 #include "matcher_parser.h"
51 #include "colorlabel.h"
52
53
54 static void prefs_filtering_action_create(void);
55 static void prefs_filtering_action_delete_cb(void);
56 static void prefs_filtering_action_substitute_cb(void);
57 static void prefs_filtering_action_register_cb(void);
58 static void prefs_filtering_action_reset_dialog(void);
59 static void prefs_filtering_action_key_pressed(GtkWidget *widget,
60     GdkEventKey *event, gpointer data);
61 static void prefs_filtering_action_cancel(void);
62 static void prefs_filtering_action_ok(void);
63 static gint prefs_filtering_action_deleted(GtkWidget *widget,
64     GdkEventAny *event, gpointer data);
65 static void prefs_filtering_action_type_selection_changed(GtkList *list,
66     gpointer user_data);
67 static void prefs_filtering_action_type_select(GtkList *list,
68     GtkWidget *widget, gpointer user_data);
69 static void prefs_filtering_action_select_dest(void);
70 static void prefs_filtering_action_select(GtkCList *clist,
71     gint row, gint column, GdkEvent *event);
72 static void prefs_filtering_action_up(void);
73 static void prefs_filtering_action_down(void);
74 static void prefs_filtering_action_set_dialog(GSList *action_list);
75 static GSList *prefs_filtering_action_get_list(void);
76
77
78 /*!
79  *\brief        UI data for matcher dialog
80  */
81 static struct FilteringAction {
82         GtkWidget *window;
83
84         GtkWidget *ok_btn;
85
86         GtkWidget *action_clist;
87         GtkWidget *action_type_list;
88         GtkWidget *action_combo;
89         GtkWidget *account_label;
90         GtkWidget *account_list;
91         GtkWidget *account_combo;
92         GtkWidget *dest_entry;
93         GtkWidget *dest_btn;
94         GtkWidget *dest_label;
95         GtkWidget *recip_label;
96         GtkWidget *exec_label;
97         GtkWidget *exec_btn;
98         GtkWidget *color_label;
99         GtkWidget *color_optmenu;
100
101         gint current_action;
102 } filtering_action;
103
104
105 typedef enum Action_ {
106         ACTION_MOVE,
107         ACTION_COPY,
108         ACTION_DELETE,
109         ACTION_MARK,
110         ACTION_UNMARK,
111         ACTION_LOCK,
112         ACTION_UNLOCK,
113         ACTION_MARK_AS_READ,
114         ACTION_MARK_AS_UNREAD,
115         ACTION_FORWARD,
116         ACTION_FORWARD_AS_ATTACHMENT,
117         ACTION_REDIRECT,
118         ACTION_EXECUTE,
119         ACTION_COLOR,
120         /* add other action constants */
121 } Action;
122
123 static struct {
124         gchar *text;
125         Action action;
126 } action_text [] = {
127         { N_("Move"),                   ACTION_MOVE     },      
128         { N_("Copy"),                   ACTION_COPY     },
129         { N_("Delete"),                 ACTION_DELETE   },
130         { N_("Mark"),                   ACTION_MARK     },
131         { N_("Unmark"),                 ACTION_UNMARK   },
132         { N_("Lock"),                   ACTION_LOCK     },
133         { N_("Unlock"),                 ACTION_UNLOCK   },
134         { N_("Mark as read"),           ACTION_MARK_AS_READ },
135         { N_("Mark as unread"),         ACTION_MARK_AS_UNREAD },
136         { N_("Forward"),                ACTION_FORWARD  },
137         { N_("Forward as attachment"),  ACTION_FORWARD_AS_ATTACHMENT },
138         { N_("Redirect"),               ACTION_REDIRECT },
139         { N_("Execute"),                ACTION_EXECUTE  },
140         { N_("Color"),                  ACTION_COLOR    }
141 };
142
143
144 /*!
145  *\brief        Hooks
146  */
147 static PrefsFilteringActionSignal *filtering_action_callback;
148
149 /*!
150  *\brief        Find index of list selection 
151  *
152  *\param        list GTK list widget
153  *
154  *\return       gint Selection index
155  */
156 static gint get_sel_from_list(GtkList *list)
157 {
158         gint row = 0;
159         void * sel;
160         GList * child;
161
162         if (list->selection == NULL)
163                 return -1;
164
165         sel = list->selection->data;
166         for (child = list->children; child != NULL; child = g_list_next(child)) {
167                 if (child->data == sel)
168                         return row;
169                 row ++;
170         }
171         
172         return row;
173 }
174
175 /*!
176  *\brief        Opens the filtering action dialog with a list of actions
177  *
178  *\param        matchers List of conditions
179  *\param        cb Callback
180  *
181  */
182 void prefs_filtering_action_open(GSList *action_list,
183     PrefsFilteringActionSignal *cb)
184 {
185         inc_lock();
186
187         if (!filtering_action.window) {
188                 prefs_filtering_action_create();
189         }
190
191         manage_window_set_transient(GTK_WINDOW(filtering_action.window));
192         gtk_widget_grab_focus(filtering_action.ok_btn);
193
194         filtering_action_callback = cb;
195
196         prefs_filtering_action_set_dialog(action_list);
197
198         gtk_widget_show(filtering_action.window);
199 }
200
201 /*!
202  *\brief        Create the matcher dialog
203  */
204 static void prefs_filtering_action_create(void)
205 {
206         GtkWidget *window;
207         GtkWidget *vbox;
208         GtkWidget *ok_btn;
209         GtkWidget *cancel_btn;
210         GtkWidget *confirm_area;
211
212         GtkWidget *vbox1;
213
214         GtkWidget *hbox1;
215
216         GtkWidget *action_label;
217         GtkWidget *recip_label;
218         GtkWidget *action_combo;
219         GtkWidget *action_type_list;
220         GtkWidget *account_list;
221         GtkWidget *dest_label;
222         GtkWidget *exec_label;
223         GtkWidget *color_label;
224         GtkWidget *account_label;
225         GtkWidget *account_combo;
226         GtkWidget *dest_entry;
227         GtkWidget *dest_btn;
228         GList * cur;
229
230         GtkWidget *reg_hbox;
231         GtkWidget *btn_hbox;
232         GtkWidget *arrow;
233         GtkWidget *reg_btn;
234         GtkWidget *subst_btn;
235         GtkWidget *del_btn;
236
237         GtkWidget *action_hbox;
238         GtkWidget *action_scrolledwin;
239         GtkWidget *action_clist;
240
241         GtkWidget *btn_vbox;
242         GtkWidget *up_btn;
243         GtkWidget *down_btn;
244
245         GtkWidget *exec_btn;
246
247         GtkWidget *color_optmenu;
248
249         GList *combo_items;
250         gint i;
251
252         gchar *title[1];
253         GList * accounts;
254
255         debug_print("Creating matcher configuration window...\n");
256
257         window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
258         gtk_container_set_border_width(GTK_CONTAINER(window), 8);
259         gtk_window_position(GTK_WINDOW(window), GTK_WIN_POS_CENTER);
260         gtk_window_set_modal(GTK_WINDOW(window), TRUE);
261         gtk_window_set_policy(GTK_WINDOW(window), FALSE, TRUE, FALSE);
262
263         vbox = gtk_vbox_new(FALSE, 6);
264         gtk_widget_show(vbox);
265         gtk_container_add(GTK_CONTAINER(window), vbox);
266
267         gtkut_button_set_create(&confirm_area, &ok_btn, _("OK"),
268                                 &cancel_btn, _("Cancel"), NULL, NULL);
269         gtk_widget_show(confirm_area);
270         gtk_box_pack_end(GTK_BOX(vbox), confirm_area, FALSE, FALSE, 0);
271         gtk_widget_grab_default(ok_btn);
272
273         gtk_window_set_title(GTK_WINDOW(window),
274                              _("Filtering action configuration"));
275         gtk_signal_connect(GTK_OBJECT(window), "delete_event",
276                            GTK_SIGNAL_FUNC(prefs_filtering_action_deleted), NULL);
277         gtk_signal_connect(GTK_OBJECT(window), "key_press_event",
278                            GTK_SIGNAL_FUNC(prefs_filtering_action_key_pressed), NULL);
279         MANAGE_WINDOW_SIGNALS_CONNECT(window);
280         gtk_signal_connect(GTK_OBJECT(ok_btn), "clicked",
281                            GTK_SIGNAL_FUNC(prefs_filtering_action_ok), NULL);
282         gtk_signal_connect(GTK_OBJECT(cancel_btn), "clicked",
283                            GTK_SIGNAL_FUNC(prefs_filtering_action_cancel), NULL);
284
285         vbox1 = gtk_vbox_new(FALSE, VSPACING);
286         gtk_widget_show(vbox1);
287         gtk_box_pack_start(GTK_BOX(vbox), vbox1, TRUE, TRUE, 0);
288         gtk_container_set_border_width(GTK_CONTAINER (vbox1), 2);
289
290         /* action to be defined */
291
292         hbox1 = gtk_hbox_new (FALSE, VSPACING);
293         gtk_widget_show (hbox1);
294         gtk_box_pack_start (GTK_BOX (vbox1), hbox1, FALSE, FALSE, 0);
295         gtk_container_set_border_width (GTK_CONTAINER (vbox1), 2);
296
297         action_label = gtk_label_new (_("Action"));
298         gtk_widget_show (action_label);
299         gtk_misc_set_alignment (GTK_MISC (action_label), 0, 0.5);
300         gtk_box_pack_start (GTK_BOX (hbox1), action_label, FALSE, FALSE, 0);
301
302         action_combo = gtk_combo_new ();
303         gtk_widget_show (action_combo);
304         gtk_entry_set_editable(GTK_ENTRY(GTK_COMBO(action_combo)->entry),
305                                FALSE);
306
307         combo_items = NULL;
308         for (i = 0; i < sizeof action_text / sizeof action_text[0]; i++)
309                 combo_items = g_list_append
310                         (combo_items, (gpointer) _(action_text[i].text));
311         gtk_combo_set_popdown_strings(GTK_COMBO(action_combo), combo_items);
312
313         g_list_free(combo_items);
314
315         gtk_box_pack_start (GTK_BOX (hbox1), action_combo,
316                             TRUE, TRUE, 0);
317         action_type_list = GTK_COMBO(action_combo)->list;
318         gtk_signal_connect (GTK_OBJECT (action_type_list), "select-child",
319                             GTK_SIGNAL_FUNC (prefs_filtering_action_type_select),
320                             NULL);
321
322         gtk_signal_connect(GTK_OBJECT(action_type_list), "selection-changed",
323                            GTK_SIGNAL_FUNC(prefs_filtering_action_type_selection_changed),
324                            NULL);
325
326         /* accounts */
327
328         hbox1 = gtk_hbox_new (FALSE, VSPACING);
329         gtk_widget_show (vbox1);
330         gtk_box_pack_start (GTK_BOX (vbox1), hbox1, FALSE, FALSE, 0);
331         gtk_container_set_border_width (GTK_CONTAINER (vbox1), 2);
332
333         account_label = gtk_label_new (_("Account"));
334         gtk_widget_show (account_label);
335         gtk_misc_set_alignment (GTK_MISC (account_label), 0, 0.5);
336         gtk_box_pack_start (GTK_BOX (hbox1), account_label, FALSE, FALSE, 0);
337
338         account_combo = gtk_combo_new ();
339         gtk_widget_set_usize (account_combo, 150, -1);
340         gtk_widget_show (account_combo);
341
342         combo_items = NULL;
343         for (accounts = account_get_list() ; accounts != NULL;
344              accounts = accounts->next) {
345                 PrefsAccount *ac = (PrefsAccount *)accounts->data;
346                 gchar *name;
347
348                 name = g_strdup_printf("%s <%s> (%s)",
349                                        ac->name, ac->address,
350                                        ac->account_name);
351                 combo_items = g_list_append(combo_items, (gpointer) name);
352         }
353
354         gtk_combo_set_popdown_strings(GTK_COMBO(account_combo), combo_items);
355
356         for(cur = g_list_first(combo_items) ; cur != NULL ;
357             cur = g_list_next(cur))
358                 g_free(cur->data);
359         g_list_free(combo_items);
360
361         gtk_box_pack_start (GTK_BOX (hbox1), account_combo,
362                             TRUE, TRUE, 0);
363         account_list = GTK_COMBO(account_combo)->list;
364         gtk_entry_set_editable(GTK_ENTRY(GTK_COMBO(account_combo)->entry),
365                                FALSE);
366
367         /* destination */
368
369         hbox1 = gtk_hbox_new (FALSE, VSPACING);
370         gtk_widget_show (vbox1);
371         gtk_box_pack_start (GTK_BOX (vbox1), hbox1, FALSE, FALSE, 0);
372         gtk_container_set_border_width (GTK_CONTAINER (vbox1), 2);
373
374         dest_label = gtk_label_new (_("Destination"));
375         gtk_widget_show (dest_label);
376         gtk_misc_set_alignment (GTK_MISC (dest_label), 0, 0.5);
377         gtk_box_pack_start (GTK_BOX (hbox1), dest_label, FALSE, FALSE, 0);
378
379         recip_label = gtk_label_new (_("Recipient"));
380         gtk_widget_show (recip_label);
381         gtk_misc_set_alignment (GTK_MISC (recip_label), 0, 0.5);
382         gtk_box_pack_start (GTK_BOX (hbox1), recip_label, FALSE, FALSE, 0);
383
384         exec_label = gtk_label_new (_("Execute"));
385         gtk_widget_show (exec_label);
386         gtk_misc_set_alignment (GTK_MISC (exec_label), 0, 0.5);
387         gtk_box_pack_start (GTK_BOX (hbox1), exec_label, FALSE, FALSE, 0);
388         
389         color_label = gtk_label_new (_("Color"));
390         gtk_widget_show(color_label);
391         gtk_misc_set_alignment(GTK_MISC(color_label), 0, 0.5);
392         gtk_box_pack_start(GTK_BOX(hbox1), color_label, FALSE, FALSE, 0);
393
394         dest_entry = gtk_entry_new ();
395         gtk_widget_set_usize (dest_entry, 150, -1);
396         gtk_widget_show (dest_entry);
397         gtk_box_pack_start (GTK_BOX (hbox1), dest_entry, TRUE, TRUE, 0);
398         
399         color_optmenu = gtk_option_menu_new();
400         gtk_option_menu_set_menu(GTK_OPTION_MENU(color_optmenu),
401                                  colorlabel_create_color_menu());
402         gtk_box_pack_start(GTK_BOX(hbox1), color_optmenu, TRUE, TRUE, 0);
403
404         dest_btn = gtk_button_new_with_label (_("Select ..."));
405         gtk_widget_show (dest_btn);
406         gtk_box_pack_start (GTK_BOX (hbox1), dest_btn, FALSE, FALSE, 0);
407         gtk_signal_connect (GTK_OBJECT (dest_btn), "clicked",
408                             GTK_SIGNAL_FUNC (prefs_filtering_action_select_dest),
409                             NULL);
410
411         exec_btn = gtk_button_new_with_label (_("Info ..."));
412         gtk_widget_show (exec_btn);
413         gtk_box_pack_start (GTK_BOX (hbox1), exec_btn, FALSE, FALSE, 0);
414         gtk_signal_connect (GTK_OBJECT (exec_btn), "clicked",
415                             GTK_SIGNAL_FUNC (prefs_filtering_action_exec_info),
416                             NULL);
417
418         /* register / substitute / delete */
419
420         reg_hbox = gtk_hbox_new(FALSE, 4);
421         gtk_widget_show(reg_hbox);
422         gtk_box_pack_start(GTK_BOX(vbox1), reg_hbox, FALSE, FALSE, 0);
423
424         arrow = gtk_arrow_new(GTK_ARROW_DOWN, GTK_SHADOW_OUT);
425         gtk_widget_show(arrow);
426         gtk_box_pack_start(GTK_BOX(reg_hbox), arrow, FALSE, FALSE, 0);
427         gtk_widget_set_usize(arrow, -1, 16);
428
429         btn_hbox = gtk_hbox_new(TRUE, 4);
430         gtk_widget_show(btn_hbox);
431         gtk_box_pack_start(GTK_BOX(reg_hbox), btn_hbox, FALSE, FALSE, 0);
432
433         reg_btn = gtk_button_new_with_label(_("Add"));
434         gtk_widget_show(reg_btn);
435         gtk_box_pack_start(GTK_BOX(btn_hbox), reg_btn, FALSE, TRUE, 0);
436         gtk_signal_connect(GTK_OBJECT(reg_btn), "clicked",
437                            GTK_SIGNAL_FUNC(prefs_filtering_action_register_cb), NULL);
438
439         subst_btn = gtk_button_new_with_label(_("  Replace  "));
440         gtk_widget_show(subst_btn);
441         gtk_box_pack_start(GTK_BOX(btn_hbox), subst_btn, FALSE, TRUE, 0);
442         gtk_signal_connect(GTK_OBJECT(subst_btn), "clicked",
443                            GTK_SIGNAL_FUNC(prefs_filtering_action_substitute_cb),
444                            NULL);
445
446         del_btn = gtk_button_new_with_label(_("Delete"));
447         gtk_widget_show(del_btn);
448         gtk_box_pack_start(GTK_BOX(btn_hbox), del_btn, FALSE, TRUE, 0);
449         gtk_signal_connect(GTK_OBJECT(del_btn), "clicked",
450                            GTK_SIGNAL_FUNC(prefs_filtering_action_delete_cb), NULL);
451
452         action_hbox = gtk_hbox_new(FALSE, 8);
453         gtk_widget_show(action_hbox);
454         gtk_box_pack_start(GTK_BOX(vbox1), action_hbox, TRUE, TRUE, 0);
455
456         action_scrolledwin = gtk_scrolled_window_new(NULL, NULL);
457         gtk_widget_show(action_scrolledwin);
458         gtk_widget_set_usize(action_scrolledwin, -1, 150);
459         gtk_box_pack_start(GTK_BOX(action_hbox), action_scrolledwin,
460                            TRUE, TRUE, 0);
461         gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(action_scrolledwin),
462                                        GTK_POLICY_AUTOMATIC,
463                                        GTK_POLICY_AUTOMATIC);
464
465         title[0] = _("Current action list");
466         action_clist = gtk_clist_new_with_titles(1, title);
467         gtk_widget_show(action_clist);
468         gtk_container_add(GTK_CONTAINER(action_scrolledwin), action_clist);
469         gtk_clist_set_column_width(GTK_CLIST(action_clist), 0, 80);
470         gtk_clist_set_selection_mode(GTK_CLIST(action_clist),
471                                      GTK_SELECTION_BROWSE);
472         GTK_WIDGET_UNSET_FLAGS(GTK_CLIST(action_clist)->column[0].button,
473                                GTK_CAN_FOCUS);
474         gtk_signal_connect(GTK_OBJECT(action_clist), "select_row",
475                            GTK_SIGNAL_FUNC(prefs_filtering_action_select), NULL);
476
477         btn_vbox = gtk_vbox_new(FALSE, 8);
478         gtk_widget_show(btn_vbox);
479         gtk_box_pack_start(GTK_BOX(action_hbox), btn_vbox, FALSE, FALSE, 0);
480
481         up_btn = gtk_button_new_with_label(_("Up"));
482         gtk_widget_show(up_btn);
483         gtk_box_pack_start(GTK_BOX(btn_vbox), up_btn, FALSE, FALSE, 0);
484         gtk_signal_connect(GTK_OBJECT(up_btn), "clicked",
485                            GTK_SIGNAL_FUNC(prefs_filtering_action_up), NULL);
486
487         down_btn = gtk_button_new_with_label(_("Down"));
488         gtk_widget_show(down_btn);
489         gtk_box_pack_start(GTK_BOX(btn_vbox), down_btn, FALSE, FALSE, 0);
490         gtk_signal_connect(GTK_OBJECT(down_btn), "clicked",
491                            GTK_SIGNAL_FUNC(prefs_filtering_action_down), NULL);
492
493         gtk_widget_show_all(window);
494
495         filtering_action.window    = window;
496         filtering_action.action_type_list = action_type_list;
497         filtering_action.action_combo = action_combo;
498         filtering_action.account_label = account_label;
499         filtering_action.account_list = account_list;
500         filtering_action.account_combo = account_combo;
501         filtering_action.dest_entry = dest_entry;
502         filtering_action.dest_btn = dest_btn;
503         filtering_action.dest_label = dest_label;
504         filtering_action.recip_label = recip_label;
505         filtering_action.exec_label = exec_label;
506         filtering_action.exec_btn = exec_btn;
507         filtering_action.color_label   = color_label;
508         filtering_action.color_optmenu = color_optmenu;
509         filtering_action.ok_btn = ok_btn;
510         filtering_action.action_clist = action_clist;
511 }
512
513 /*!
514  *\brief        Set the contents of a row
515  *
516  *\param        row Index of row to set
517  *\param        prop Condition to set
518  *
519  *\return       gint Row index \a prop has been added
520  */
521 static gint prefs_filtering_action_clist_set_row(gint row, FilteringAction *action)
522 {
523         GtkCList *clist = GTK_CLIST(filtering_action.action_clist);
524         gchar *action_tab_str[1];
525         gchar *action_str;
526         gchar buf[256];
527
528         if (action == NULL) {
529                 action_tab_str[0] = _("(New)");
530                 return gtk_clist_append(clist, action_tab_str);
531         }
532
533         filteringaction_to_string(buf, sizeof buf, action);
534         action_str = g_strdup(buf);
535         
536         action_tab_str[0] = action_str;
537         if (row < 0)
538                 row = gtk_clist_append(clist, action_tab_str);
539         else
540                 gtk_clist_set_text(clist, row, 0, action_tab_str[0]);
541         g_free(action_str);
542
543         return row;
544 }
545
546 /*!
547  *\brief        Update scrollbar
548  */
549 static void prefs_filtering_action_update_hscrollbar(void)
550 {
551         gint optwidth = gtk_clist_optimal_column_width(GTK_CLIST(filtering_action.action_clist), 0);
552         gtk_clist_set_column_width(GTK_CLIST(filtering_action.action_clist), 0, optwidth);
553 }
554
555 /*!
556  *\brief        Initializes dialog with a set of conditions
557  *
558  *\param        matchers List of conditions
559  */
560 static void prefs_filtering_action_set_dialog(GSList *action_list)
561 {
562         GtkCList *clist = GTK_CLIST(filtering_action.action_clist);
563         GSList *cur;
564
565         gtk_clist_freeze(clist);
566         gtk_clist_clear(clist);
567
568         prefs_filtering_action_clist_set_row(-1, NULL);
569         if (action_list != NULL) {
570                 for (cur = action_list; cur != NULL;
571                      cur = g_slist_next(cur)) {
572                         FilteringAction *action;
573                         action = (FilteringAction *) cur->data;
574                         prefs_filtering_action_clist_set_row(-1, action);
575                 }
576         }
577         
578         prefs_filtering_action_update_hscrollbar();
579
580         gtk_clist_thaw(clist);
581
582         prefs_filtering_action_reset_dialog();
583 }
584
585 /*!
586  *\brief        Converts current actions in list box in
587  *              an action list used by the filtering system.
588  *
589  *\return       GSList * List of actions.
590  */
591 static GSList *prefs_filtering_action_get_list(void)
592 {
593         gchar *action_str;
594         FilteringAction *action;
595         gint row = 1;
596         GSList *action_list;
597
598         action_list = NULL;
599
600         while (gtk_clist_get_text(GTK_CLIST(filtering_action.action_clist),
601                                   row, 0, &action_str)) {
602
603                 if (strcmp(action_str, _("(New)")) != 0) {
604                         GSList * tmp_action_list;
605                         tmp_action_list = matcher_parser_get_action_list(action_str);
606                         
607                         if (tmp_action_list == NULL)
608                                 break;
609
610                         action_list = g_slist_concat(action_list,
611                             tmp_action_list);
612                 }
613                 row ++;
614         }
615
616         return action_list;
617 }
618
619 /*!
620  *\brief        Returns account ID from the given list index
621  *
622  *\return       gint account ID
623  */
624 static gint get_account_id_from_list_id(gint list_id)
625 {
626         GList * accounts;
627
628         for (accounts = account_get_list() ; accounts != NULL;
629              accounts = accounts->next) {
630                 PrefsAccount *ac = (PrefsAccount *)accounts->data;
631
632                 if (list_id == 0)
633                         return ac->account_id;
634                 list_id--;
635         }
636         return 0;
637 }
638
639 /*!
640  *\brief        Returns list index from the given account ID
641  *
642  *\return       gint list index
643  */
644 static gint get_list_id_from_account_id(gint account_id)
645 {
646         GList * accounts;
647         gint list_id = 0;
648
649         for (accounts = account_get_list() ; accounts != NULL;
650              accounts = accounts->next) {
651                 PrefsAccount *ac = (PrefsAccount *)accounts->data;
652
653                 if (account_id == ac->account_id)
654                         return list_id;
655                 list_id++;
656         }
657         return 0;
658 }
659
660
661 /*!
662  *\brief        Returns parser action ID from internal action ID
663  *
664  *\return       gint parser action ID
665  */
666 static gint prefs_filtering_action_get_matching_from_action(Action action_id)
667 {
668         switch (action_id) {
669         case ACTION_MOVE:
670                 return MATCHACTION_MOVE;
671         case ACTION_COPY:
672                 return MATCHACTION_COPY;
673         case ACTION_DELETE:
674                 return MATCHACTION_DELETE;
675         case ACTION_MARK:
676                 return MATCHACTION_MARK;
677         case ACTION_UNMARK:
678                 return MATCHACTION_UNMARK;
679         case ACTION_LOCK:
680                 return MATCHACTION_LOCK;
681         case ACTION_UNLOCK:
682                 return MATCHACTION_UNLOCK;
683         case ACTION_MARK_AS_READ:
684                 return MATCHACTION_MARK_AS_READ;
685         case ACTION_MARK_AS_UNREAD:
686                 return MATCHACTION_MARK_AS_UNREAD;
687         case ACTION_FORWARD:
688                 return MATCHACTION_FORWARD;
689         case ACTION_FORWARD_AS_ATTACHMENT:
690                 return MATCHACTION_FORWARD_AS_ATTACHMENT;
691         case ACTION_REDIRECT:
692                 return MATCHACTION_REDIRECT;
693         case ACTION_EXECUTE:
694                 return MATCHACTION_EXECUTE;
695         case ACTION_COLOR:
696                 return MATCHACTION_COLOR;
697         default:
698                 return -1;
699         }
700 }
701
702 /*!
703  *\brief        Returns action from the content of the dialog
704  *
705  *\param        alert specifies whether alert dialog boxes should be shown
706  *                or not.
707  *
708  *\return       FilteringAction * action entered in the dialog box.
709  */
710 static FilteringAction * prefs_filtering_action_dialog_to_action(gboolean alert)
711 {
712         Action action_id;
713         gint action_type;
714         gint list_id;
715         gint account_id;
716         const gchar * destination;
717         gint labelcolor = 0;
718         FilteringAction * action;
719
720         action_id = get_sel_from_list(GTK_LIST(filtering_action.action_type_list));
721         action_type = prefs_filtering_action_get_matching_from_action(action_id);
722         list_id = get_sel_from_list(GTK_LIST(filtering_action.account_list));
723         account_id = get_account_id_from_list_id(list_id);
724
725         switch (action_id) {
726         case ACTION_MOVE:
727         case ACTION_COPY:
728         case ACTION_EXECUTE:
729                 destination = gtk_entry_get_text(GTK_ENTRY(filtering_action.dest_entry));
730                 if (*destination == '\0') {
731                         if (alert)
732                                 alertpanel_error(_("Destination is not set."));
733                         return NULL;
734                 }
735                 break;
736         case ACTION_FORWARD:
737         case ACTION_FORWARD_AS_ATTACHMENT:
738         case ACTION_REDIRECT:
739                 destination = gtk_entry_get_text(GTK_ENTRY(filtering_action.dest_entry));
740                 if (*destination == '\0') {
741                         if (alert)
742                                 alertpanel_error(_("Recipient is not set."));
743                         return NULL;
744                 }
745                 break;
746         case ACTION_COLOR:
747                 labelcolor = colorlabel_get_color_menu_active_item(
748                         gtk_option_menu_get_menu(GTK_OPTION_MENU(filtering_action.color_optmenu)));
749                 destination = NULL;     
750                 break;
751         default:
752                 destination = NULL;
753                 break;
754         }
755         
756         action = filteringaction_new(action_type, account_id, destination, labelcolor);
757
758         return action;
759 }
760
761 /*!
762  *\brief        Signal handler for register button
763  */
764 static void prefs_filtering_action_register_cb(void)
765 {
766         FilteringAction *action;
767         
768         action = prefs_filtering_action_dialog_to_action(TRUE);
769         if (action == NULL)
770                 return;
771
772         prefs_filtering_action_clist_set_row(-1, action);
773
774         filteringaction_free(action);
775
776         prefs_filtering_action_reset_dialog();
777         prefs_filtering_action_update_hscrollbar();
778 }
779
780 /*!
781  *\brief        Signal handler for substitute button
782  */
783 static void prefs_filtering_action_substitute_cb(void)
784 {
785         GtkCList *clist = GTK_CLIST(filtering_action.action_clist);
786         gint row;
787         FilteringAction *action;
788
789         if (!clist->selection) return;
790         row = GPOINTER_TO_INT(clist->selection->data);
791         if (row == 0)
792                 return;
793         
794         action = prefs_filtering_action_dialog_to_action(TRUE);
795         if (action == NULL)
796                 return;
797
798         prefs_filtering_action_clist_set_row(row, action);
799
800         filteringaction_free(action);
801
802         prefs_filtering_action_reset_dialog();
803         
804         prefs_filtering_action_update_hscrollbar();
805 }
806
807 /*!
808  *\brief        Signal handler for delete button
809  */
810 static void prefs_filtering_action_delete_cb(void)
811 {
812         GtkCList *clist = GTK_CLIST(filtering_action.action_clist);
813         gint row;
814
815         if (!clist->selection) return;
816         row = GPOINTER_TO_INT(clist->selection->data);
817         if (row == 0)
818                 return;
819
820         gtk_clist_remove(clist, row);
821
822         prefs_filtering_action_reset_dialog();
823
824         prefs_filtering_action_update_hscrollbar();
825 }
826
827 /*!
828  *\brief        Signal handler for 'move up' button
829  */
830 static void prefs_filtering_action_up(void)
831 {
832         GtkCList *clist = GTK_CLIST(filtering_action.action_clist);
833         gint row;
834
835         if (!clist->selection) return;
836
837         row = GPOINTER_TO_INT(clist->selection->data);
838         if (row > 1) {
839                 gtk_clist_row_move(clist, row, row - 1);
840                 if (gtk_clist_row_is_visible(clist, row - 1) != GTK_VISIBILITY_FULL)
841                         gtk_clist_moveto(clist, row - 1, 0, 0, 0);
842         }
843 }
844
845 /*!
846  *\brief        Signal handler for 'move down' button
847  */
848 static void prefs_filtering_action_down(void)
849 {
850         GtkCList *clist = GTK_CLIST(filtering_action.action_clist);
851         gint row;
852
853         if (!clist->selection) return;
854
855         row = GPOINTER_TO_INT(clist->selection->data);
856         if (row >= 1 && row < clist->rows - 1) {
857                 gtk_clist_row_move(clist, row, row + 1);
858                 if (gtk_clist_row_is_visible(clist, row + 1) != GTK_VISIBILITY_FULL)
859                         gtk_clist_moveto(clist, row + 1, 0, 1, 0);
860         }
861 }
862
863 /*!
864  *\brief        Signal handler for select row.
865  *
866  *\param        clist List widget
867  *\param        row Selected row
868  *\param        column Selected column
869  *\param        event Event information
870  */
871 static void prefs_filtering_action_select(GtkCList *clist,
872     gint row, gint column, GdkEvent *event)
873 {
874         gchar *action_str;
875         FilteringAction *action;
876         GSList * action_list;
877         gint list_id;
878
879         if (!gtk_clist_get_text(GTK_CLIST(filtering_action.action_clist),
880                                 row, 0, &action_str))
881                 return;
882
883         if (row == 0) {
884                 prefs_filtering_action_reset_dialog();
885                 return;
886         }
887
888         action_list = matcher_parser_get_action_list(action_str);
889         if (action_list == NULL)
890                 return;
891
892         action = action_list->data;
893         g_slist_free(action_list);
894
895         if (action->destination)
896                 gtk_entry_set_text(GTK_ENTRY(filtering_action.dest_entry), action->destination);
897         else
898                 gtk_entry_set_text(GTK_ENTRY(filtering_action.dest_entry), "");
899
900         switch(action->type) {
901         case MATCHACTION_MOVE:
902                 gtk_list_select_item(GTK_LIST(filtering_action.action_type_list),
903                                      ACTION_MOVE);
904                 break;
905         case MATCHACTION_COPY:
906                 gtk_list_select_item(GTK_LIST(filtering_action.action_type_list),
907                                      ACTION_COPY);
908                 break;
909         case MATCHACTION_DELETE:
910                 gtk_list_select_item(GTK_LIST(filtering_action.action_type_list),
911                                      ACTION_DELETE);
912                 break;
913         case MATCHACTION_MARK:
914                 gtk_list_select_item(GTK_LIST(filtering_action.action_type_list),
915                                      ACTION_MARK);
916                 break;
917         case MATCHACTION_UNMARK:
918                 gtk_list_select_item(GTK_LIST(filtering_action.action_type_list),
919                                      ACTION_UNMARK);
920                 break;
921         case MATCHACTION_LOCK:
922                 gtk_list_select_item(GTK_LIST(filtering_action.action_type_list),
923                                      ACTION_LOCK);
924                 break;
925         case MATCHACTION_UNLOCK:
926                 gtk_list_select_item(GTK_LIST(filtering_action.action_type_list),
927                                      ACTION_UNLOCK);
928                 break;
929         case MATCHACTION_MARK_AS_READ:
930                 gtk_list_select_item(GTK_LIST(filtering_action.action_type_list),
931                                      ACTION_MARK_AS_READ);
932                 break;
933         case MATCHACTION_MARK_AS_UNREAD:
934                 gtk_list_select_item(GTK_LIST(filtering_action.action_type_list),
935                                      ACTION_MARK_AS_UNREAD);
936                 break;
937         case MATCHACTION_FORWARD:
938                 list_id = get_list_id_from_account_id(action->account_id);
939                 gtk_list_select_item(GTK_LIST(filtering_action.action_type_list),
940                                      ACTION_FORWARD);
941                 gtk_list_select_item(GTK_LIST(filtering_action.account_list),
942                                      list_id);
943                 break;
944         case MATCHACTION_FORWARD_AS_ATTACHMENT:
945                 list_id = get_list_id_from_account_id(action->account_id);
946                 gtk_list_select_item(GTK_LIST(filtering_action.action_type_list),
947                                      ACTION_FORWARD_AS_ATTACHMENT);
948                 gtk_list_select_item(GTK_LIST(filtering_action.account_list),
949                                      list_id);
950                 break;
951         case MATCHACTION_REDIRECT:
952                 list_id = get_list_id_from_account_id(action->account_id);
953                 gtk_list_select_item(GTK_LIST(filtering_action.action_type_list),
954                                      ACTION_REDIRECT);
955                 gtk_list_select_item(GTK_LIST(filtering_action.account_list),
956                                      list_id);
957                 break;
958         case MATCHACTION_EXECUTE:
959                 gtk_list_select_item(GTK_LIST(filtering_action.action_type_list),
960                                      ACTION_EXECUTE);
961                 break;
962         case MATCHACTION_COLOR:
963                 gtk_list_select_item(GTK_LIST(filtering_action.action_type_list),
964                                      ACTION_COLOR);
965                 gtk_option_menu_set_history(GTK_OPTION_MENU(filtering_action.color_optmenu), action->labelcolor);     
966                 break;
967         }
968 }
969
970 /*!
971  *\brief        Handle key press
972  *
973  *\param        widget Widget receiving key press
974  *\param        event Key event
975  *\param        data User data
976  */
977 static void prefs_filtering_action_key_pressed(GtkWidget *widget,
978     GdkEventKey *event, gpointer data)
979 {
980         if (event && event->keyval == GDK_Escape)
981                 prefs_filtering_action_cancel();
982 }
983
984 /*!
985  *\brief        Cancel matcher dialog
986  */
987 static void prefs_filtering_action_cancel(void)
988 {
989         gtk_widget_hide(filtering_action.window);
990         inc_unlock();
991 }
992
993 /*!
994  *\brief        Accept current matchers
995  */
996 static void prefs_filtering_action_ok(void)
997 {
998         GSList * action_list;
999         GSList * cur;
1000
1001         action_list = prefs_filtering_action_get_list();
1002
1003         if (action_list == NULL) {
1004                 alertpanel_error(_("No action was defined."));
1005                 return;
1006         }
1007
1008         if (filtering_action_callback != NULL)
1009                 filtering_action_callback(action_list);
1010         for(cur = action_list ; cur != NULL ; cur = cur->next) {
1011                 filteringaction_free(cur->data);
1012         }
1013         g_slist_free(action_list);
1014
1015         gtk_widget_hide(filtering_action.window);
1016         inc_unlock();
1017 }
1018
1019 /*!
1020  *\brief        Called when closing dialog box
1021  *
1022  *\param        widget Dialog widget
1023  *\param        event Event info
1024  *\param        data User data
1025  *
1026  *\return       gint TRUE
1027  */
1028 static gint prefs_filtering_action_deleted(GtkWidget *widget,
1029     GdkEventAny *event, gpointer data)
1030 {
1031         prefs_filtering_action_cancel();
1032         return TRUE;
1033 }
1034
1035 /*
1036  * Strings describing exec format strings
1037  * 
1038  * When adding new lines, remember to put 2 strings for each line
1039  */
1040 static gchar *exec_desc_strings[] = {
1041         "%%",   "%",
1042         "%s",   N_("Subject"),
1043         "%f",   N_("From"),
1044         "%t",   N_("To"),
1045         "%c",   N_("Cc"),
1046         "%d",   N_("Date"),
1047         "%i",   N_("Message-ID"),
1048         "%n",   N_("Newsgroups"),
1049         "%r",   N_("References"),
1050         "%F",   N_("Filename - should not be modified"),
1051         "\\n",  N_("new line"),
1052         "\\",   N_("escape character for quotes"),
1053         "\\\"",N_("quote character"),
1054         NULL, NULL
1055 };
1056
1057 static DescriptionWindow exec_desc_win = { 
1058         NULL, 
1059         2,
1060         N_("Description of symbols"),
1061         exec_desc_strings
1062 };
1063
1064
1065
1066 /*!
1067  *\brief        Show Execute action's info
1068  */
1069 void prefs_filtering_action_exec_info(void)
1070 {
1071         description_window_create(&exec_desc_win);
1072 }
1073
1074 static void prefs_filtering_action_select_dest(void)
1075 {
1076         FolderItem *dest;
1077         gchar * path;
1078
1079         dest = foldersel_folder_sel(NULL, FOLDER_SEL_COPY, NULL);
1080         if (!dest) return;
1081
1082         path = folder_item_get_identifier(dest);
1083
1084         gtk_entry_set_text(GTK_ENTRY(filtering_action.dest_entry), path);
1085         g_free(path);
1086 }
1087
1088 static void prefs_filtering_action_type_selection_changed(GtkList *list,
1089     gpointer user_data)
1090 {
1091         gint value;
1092
1093         value = get_sel_from_list(GTK_LIST(filtering_action.action_type_list));
1094
1095         if (filtering_action.current_action != value) {
1096                 if (filtering_action.current_action == ACTION_FORWARD 
1097                 ||  filtering_action.current_action == ACTION_FORWARD_AS_ATTACHMENT
1098                 ||  filtering_action.current_action == ACTION_REDIRECT) {
1099                         debug_print("unregistering address completion entry\n");
1100                         address_completion_unregister_entry(GTK_ENTRY(filtering_action.dest_entry));
1101                 }
1102                 if (value == ACTION_FORWARD || value == ACTION_FORWARD_AS_ATTACHMENT
1103                 ||  value == ACTION_REDIRECT) {
1104                         debug_print("registering address completion entry\n");
1105                         address_completion_register_entry(GTK_ENTRY(filtering_action.dest_entry));
1106                 }
1107                 filtering_action.current_action = value;
1108         }
1109 }
1110
1111 static void prefs_filtering_action_type_select(GtkList *list,
1112     GtkWidget *widget, gpointer user_data)
1113 {
1114         Action value;
1115
1116         value = (Action) get_sel_from_list(GTK_LIST(filtering_action.action_type_list));
1117
1118         switch (value) {
1119         case ACTION_MOVE:
1120                 gtk_widget_show(filtering_action.account_label);
1121                 gtk_widget_set_sensitive(filtering_action.account_label, FALSE);
1122                 gtk_widget_set_sensitive(filtering_action.account_combo, FALSE);
1123                 gtk_widget_show(filtering_action.dest_entry);
1124                 gtk_widget_set_sensitive(filtering_action.dest_entry, TRUE);
1125                 gtk_widget_show(filtering_action.dest_btn);
1126                 gtk_widget_set_sensitive(filtering_action.dest_btn, TRUE);
1127                 gtk_widget_show(filtering_action.dest_label);
1128                 gtk_widget_set_sensitive(filtering_action.dest_label, TRUE);
1129                 gtk_widget_hide(filtering_action.recip_label);
1130                 gtk_widget_hide(filtering_action.exec_label);
1131                 gtk_widget_hide(filtering_action.exec_btn);
1132                 gtk_widget_hide(filtering_action.color_optmenu);
1133                 gtk_widget_hide(filtering_action.color_label);
1134                 break;
1135         case ACTION_COPY:
1136                 gtk_widget_show(filtering_action.account_label);
1137                 gtk_widget_set_sensitive(filtering_action.account_label, FALSE);
1138                 gtk_widget_set_sensitive(filtering_action.account_combo, FALSE);
1139                 gtk_widget_show(filtering_action.dest_entry);
1140                 gtk_widget_set_sensitive(filtering_action.dest_entry, TRUE);
1141                 gtk_widget_show(filtering_action.dest_btn);
1142                 gtk_widget_set_sensitive(filtering_action.dest_btn, TRUE);
1143                 gtk_widget_show(filtering_action.dest_label);
1144                 gtk_widget_set_sensitive(filtering_action.dest_label, TRUE);
1145                 gtk_widget_hide(filtering_action.recip_label);
1146                 gtk_widget_hide(filtering_action.exec_label);
1147                 gtk_widget_hide(filtering_action.exec_btn);
1148                 gtk_widget_hide(filtering_action.color_optmenu);
1149                 gtk_widget_hide(filtering_action.color_label);
1150                 break;
1151         case ACTION_DELETE:
1152                 gtk_widget_show(filtering_action.account_label);
1153                 gtk_widget_set_sensitive(filtering_action.account_label, FALSE);
1154                 gtk_widget_set_sensitive(filtering_action.account_combo, FALSE);
1155                 gtk_widget_show(filtering_action.dest_entry);
1156                 gtk_widget_set_sensitive(filtering_action.dest_entry, FALSE);
1157                 gtk_widget_show(filtering_action.dest_btn);
1158                 gtk_widget_set_sensitive(filtering_action.dest_btn, FALSE);
1159                 gtk_widget_show(filtering_action.dest_label);
1160                 gtk_widget_set_sensitive(filtering_action.dest_label, FALSE);
1161                 gtk_widget_hide(filtering_action.recip_label);
1162                 gtk_widget_hide(filtering_action.exec_label);
1163                 gtk_widget_hide(filtering_action.exec_btn);
1164                 gtk_widget_hide(filtering_action.color_optmenu);
1165                 gtk_widget_hide(filtering_action.color_label);
1166                 break;
1167         case ACTION_MARK:
1168         case ACTION_UNMARK:
1169         case ACTION_LOCK:
1170         case ACTION_UNLOCK:
1171         case ACTION_MARK_AS_READ:
1172         case ACTION_MARK_AS_UNREAD:
1173                 gtk_widget_show(filtering_action.account_label);
1174                 gtk_widget_set_sensitive(filtering_action.account_label, FALSE);
1175                 gtk_widget_set_sensitive(filtering_action.account_combo, FALSE);
1176                 gtk_widget_show(filtering_action.dest_entry);
1177                 gtk_widget_set_sensitive(filtering_action.dest_entry, FALSE);
1178                 gtk_widget_show(filtering_action.dest_btn);
1179                 gtk_widget_set_sensitive(filtering_action.dest_btn, FALSE);
1180                 gtk_widget_show(filtering_action.dest_label);
1181                 gtk_widget_set_sensitive(filtering_action.dest_label, FALSE);
1182                 gtk_widget_hide(filtering_action.recip_label);
1183                 gtk_widget_hide(filtering_action.exec_label);
1184                 gtk_widget_hide(filtering_action.exec_btn);
1185                 gtk_widget_hide(filtering_action.color_optmenu);
1186                 gtk_widget_hide(filtering_action.color_label);
1187                 break;
1188         case ACTION_FORWARD:
1189                 gtk_widget_show(filtering_action.account_label);
1190                 gtk_widget_set_sensitive(filtering_action.account_label, TRUE);
1191                 gtk_widget_set_sensitive(filtering_action.account_combo, TRUE);
1192                 gtk_widget_show(filtering_action.dest_entry);
1193                 gtk_widget_set_sensitive(filtering_action.dest_entry, TRUE);
1194                 gtk_widget_show(filtering_action.dest_btn);
1195                 gtk_widget_set_sensitive(filtering_action.dest_btn, FALSE);
1196                 gtk_widget_hide(filtering_action.dest_label);
1197                 gtk_widget_show(filtering_action.recip_label);
1198                 gtk_widget_set_sensitive(filtering_action.recip_label, TRUE);
1199                 gtk_widget_hide(filtering_action.exec_label);
1200                 gtk_widget_hide(filtering_action.exec_btn);
1201                 gtk_widget_hide(filtering_action.color_optmenu);
1202                 gtk_widget_hide(filtering_action.color_label);
1203                 break;
1204         case ACTION_FORWARD_AS_ATTACHMENT:
1205                 gtk_widget_show(filtering_action.account_label);
1206                 gtk_widget_set_sensitive(filtering_action.account_label, TRUE);
1207                 gtk_widget_set_sensitive(filtering_action.account_combo, TRUE);
1208                 gtk_widget_show(filtering_action.dest_entry);
1209                 gtk_widget_set_sensitive(filtering_action.dest_entry, TRUE);
1210                 gtk_widget_show(filtering_action.dest_btn);
1211                 gtk_widget_set_sensitive(filtering_action.dest_btn, FALSE);
1212                 gtk_widget_hide(filtering_action.dest_label);
1213                 gtk_widget_show(filtering_action.recip_label);
1214                 gtk_widget_set_sensitive(filtering_action.recip_label, TRUE);
1215                 gtk_widget_hide(filtering_action.exec_label);
1216                 gtk_widget_hide(filtering_action.exec_btn);
1217                 gtk_widget_hide(filtering_action.color_optmenu);
1218                 gtk_widget_hide(filtering_action.color_label);
1219                 break;
1220         case ACTION_REDIRECT:
1221                 gtk_widget_show(filtering_action.account_label);
1222                 gtk_widget_set_sensitive(filtering_action.account_label, TRUE);
1223                 gtk_widget_set_sensitive(filtering_action.account_combo, TRUE);
1224                 gtk_widget_show(filtering_action.dest_entry);
1225                 gtk_widget_set_sensitive(filtering_action.dest_entry, TRUE);
1226                 gtk_widget_show(filtering_action.dest_btn);
1227                 gtk_widget_set_sensitive(filtering_action.dest_btn, FALSE);
1228                 gtk_widget_hide(filtering_action.dest_label);
1229                 gtk_widget_show(filtering_action.recip_label);
1230                 gtk_widget_set_sensitive(filtering_action.recip_label, TRUE);
1231                 gtk_widget_hide(filtering_action.exec_label);
1232                 gtk_widget_hide(filtering_action.exec_btn);
1233                 gtk_widget_hide(filtering_action.color_optmenu);
1234                 gtk_widget_hide(filtering_action.color_label);
1235                 break;
1236         case ACTION_EXECUTE:
1237                 gtk_widget_show(filtering_action.account_label);
1238                 gtk_widget_set_sensitive(filtering_action.account_label, FALSE);
1239                 gtk_widget_set_sensitive(filtering_action.account_combo, FALSE);
1240                 gtk_widget_show(filtering_action.dest_entry);
1241                 gtk_widget_set_sensitive(filtering_action.dest_entry, TRUE);
1242                 gtk_widget_hide(filtering_action.dest_btn);
1243                 gtk_widget_hide(filtering_action.dest_label);
1244                 gtk_widget_hide(filtering_action.recip_label);
1245                 gtk_widget_show(filtering_action.exec_label);
1246                 gtk_widget_set_sensitive(filtering_action.exec_btn, TRUE);
1247                 gtk_widget_show(filtering_action.exec_btn);
1248                 gtk_widget_hide(filtering_action.color_optmenu);
1249                 gtk_widget_hide(filtering_action.color_label);
1250                 break;
1251         case ACTION_COLOR:
1252                 gtk_widget_show(filtering_action.account_label);
1253                 gtk_widget_set_sensitive(filtering_action.account_label, FALSE);
1254                 gtk_widget_set_sensitive(filtering_action.account_combo, FALSE);
1255                 gtk_widget_hide(filtering_action.dest_entry);
1256                 gtk_widget_hide(filtering_action.dest_btn);
1257                 gtk_widget_hide(filtering_action.dest_label);
1258                 gtk_widget_hide(filtering_action.recip_label);
1259                 gtk_widget_hide(filtering_action.exec_label);
1260                 gtk_widget_show(filtering_action.exec_btn);
1261                 gtk_widget_set_sensitive(filtering_action.exec_btn, FALSE);
1262                 gtk_widget_show(filtering_action.color_optmenu);
1263                 gtk_widget_show(filtering_action.color_label);
1264                 break;
1265         }
1266 }
1267
1268 static void prefs_filtering_action_reset_dialog(void)
1269 {
1270         gtk_list_select_item(GTK_LIST(filtering_action.action_type_list), 0);
1271         gtk_list_select_item(GTK_LIST(filtering_action.account_list), 0);
1272         gtk_entry_set_text(GTK_ENTRY(filtering_action.dest_entry), "");
1273 }