0.9.6claws release
[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 gboolean prefs_filtering_action_key_pressed(GtkWidget *widget,
60     GdkEventKey *event, gpointer data);
61 static void prefs_filtering_action_cancel(void);
62 static void prefs_filtering_action_ok(void);
63 static gint prefs_filtering_action_deleted(GtkWidget *widget,
64     GdkEventAny *event, gpointer data);
65 static void prefs_filtering_action_type_selection_changed(GtkList *list,
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_DIALOG);
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         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(action_id == ACTION_EXECUTE 
733                                                  ? _("Command line not set")
734                                                  : _("Destination is not set."));
735                         return NULL;
736                 }
737                 break;
738         case ACTION_FORWARD:
739         case ACTION_FORWARD_AS_ATTACHMENT:
740         case ACTION_REDIRECT:
741                 destination = gtk_entry_get_text(GTK_ENTRY(filtering_action.dest_entry));
742                 if (*destination == '\0') {
743                         if (alert)
744                                 alertpanel_error(_("Recipient is not set."));
745                         return NULL;
746                 }
747                 break;
748         case ACTION_COLOR:
749                 labelcolor = colorlabel_get_color_menu_active_item(
750                         gtk_option_menu_get_menu(GTK_OPTION_MENU(filtering_action.color_optmenu)));
751                 destination = NULL;     
752                 break;
753         default:
754                 destination = NULL;
755                 break;
756         }
757         
758         action = filteringaction_new(action_type, account_id, destination, labelcolor);
759
760         return action;
761 }
762
763 /*!
764  *\brief        Signal handler for register button
765  */
766 static void prefs_filtering_action_register_cb(void)
767 {
768         FilteringAction *action;
769         
770         action = prefs_filtering_action_dialog_to_action(TRUE);
771         if (action == NULL)
772                 return;
773
774         prefs_filtering_action_clist_set_row(-1, action);
775
776         filteringaction_free(action);
777         /* presumably gtk_list_select_item(), called by 
778          * prefs_filtering_action_reset_dialog() activates 
779          * what seems to be a bug. this causes any other 
780          * list items to be unselectable */
781         /* prefs_filtering_action_reset_dialog(); */
782         gtk_list_select_item(GTK_LIST(filtering_action.account_list), 0);
783         gtk_entry_set_text(GTK_ENTRY(filtering_action.dest_entry), "");
784         prefs_filtering_action_update_hscrollbar();
785 }
786
787 /*!
788  *\brief        Signal handler for substitute button
789  */
790 static void prefs_filtering_action_substitute_cb(void)
791 {
792         GtkCList *clist = GTK_CLIST(filtering_action.action_clist);
793         gint row;
794         FilteringAction *action;
795
796         if (!clist->selection) return;
797         row = GPOINTER_TO_INT(clist->selection->data);
798         if (row == 0)
799                 return;
800         
801         action = prefs_filtering_action_dialog_to_action(TRUE);
802         if (action == NULL)
803                 return;
804
805         prefs_filtering_action_clist_set_row(row, action);
806
807         filteringaction_free(action);
808
809         prefs_filtering_action_reset_dialog();
810         
811         prefs_filtering_action_update_hscrollbar();
812 }
813
814 /*!
815  *\brief        Signal handler for delete button
816  */
817 static void prefs_filtering_action_delete_cb(void)
818 {
819         GtkCList *clist = GTK_CLIST(filtering_action.action_clist);
820         gint row;
821
822         if (!clist->selection) return;
823         row = GPOINTER_TO_INT(clist->selection->data);
824         if (row == 0)
825                 return;
826
827         gtk_clist_remove(clist, row);
828
829         prefs_filtering_action_reset_dialog();
830
831         prefs_filtering_action_update_hscrollbar();
832 }
833
834 /*!
835  *\brief        Signal handler for 'move up' button
836  */
837 static void prefs_filtering_action_up(void)
838 {
839         GtkCList *clist = GTK_CLIST(filtering_action.action_clist);
840         gint row;
841
842         if (!clist->selection) return;
843
844         row = GPOINTER_TO_INT(clist->selection->data);
845         if (row > 1) {
846                 gtk_clist_row_move(clist, row, row - 1);
847                 if (gtk_clist_row_is_visible(clist, row - 1) != GTK_VISIBILITY_FULL)
848                         gtk_clist_moveto(clist, row - 1, 0, 0, 0);
849         }
850 }
851
852 /*!
853  *\brief        Signal handler for 'move down' button
854  */
855 static void prefs_filtering_action_down(void)
856 {
857         GtkCList *clist = GTK_CLIST(filtering_action.action_clist);
858         gint row;
859
860         if (!clist->selection) return;
861
862         row = GPOINTER_TO_INT(clist->selection->data);
863         if (row >= 1 && row < clist->rows - 1) {
864                 gtk_clist_row_move(clist, row, row + 1);
865                 if (gtk_clist_row_is_visible(clist, row + 1) != GTK_VISIBILITY_FULL)
866                         gtk_clist_moveto(clist, row + 1, 0, 1, 0);
867         }
868 }
869
870 /*!
871  *\brief        Signal handler for select row.
872  *
873  *\param        clist List widget
874  *\param        row Selected row
875  *\param        column Selected column
876  *\param        event Event information
877  */
878 static void prefs_filtering_action_select(GtkCList *clist,
879     gint row, gint column, GdkEvent *event)
880 {
881         gchar *action_str;
882         FilteringAction *action;
883         GSList * action_list;
884         gint list_id;
885
886         if (!gtk_clist_get_text(GTK_CLIST(filtering_action.action_clist),
887                                 row, 0, &action_str))
888                 return;
889
890         if (row == 0) {
891                 prefs_filtering_action_reset_dialog();
892                 return;
893         }
894
895         action_list = matcher_parser_get_action_list(action_str);
896         if (action_list == NULL)
897                 return;
898
899         action = action_list->data;
900         g_slist_free(action_list);
901
902         if (action->destination)
903                 gtk_entry_set_text(GTK_ENTRY(filtering_action.dest_entry), action->destination);
904         else
905                 gtk_entry_set_text(GTK_ENTRY(filtering_action.dest_entry), "");
906
907         switch(action->type) {
908         case MATCHACTION_MOVE:
909                 gtk_list_select_item(GTK_LIST(filtering_action.action_type_list),
910                                      ACTION_MOVE);
911                 break;
912         case MATCHACTION_COPY:
913                 gtk_list_select_item(GTK_LIST(filtering_action.action_type_list),
914                                      ACTION_COPY);
915                 break;
916         case MATCHACTION_DELETE:
917                 gtk_list_select_item(GTK_LIST(filtering_action.action_type_list),
918                                      ACTION_DELETE);
919                 break;
920         case MATCHACTION_MARK:
921                 gtk_list_select_item(GTK_LIST(filtering_action.action_type_list),
922                                      ACTION_MARK);
923                 break;
924         case MATCHACTION_UNMARK:
925                 gtk_list_select_item(GTK_LIST(filtering_action.action_type_list),
926                                      ACTION_UNMARK);
927                 break;
928         case MATCHACTION_LOCK:
929                 gtk_list_select_item(GTK_LIST(filtering_action.action_type_list),
930                                      ACTION_LOCK);
931                 break;
932         case MATCHACTION_UNLOCK:
933                 gtk_list_select_item(GTK_LIST(filtering_action.action_type_list),
934                                      ACTION_UNLOCK);
935                 break;
936         case MATCHACTION_MARK_AS_READ:
937                 gtk_list_select_item(GTK_LIST(filtering_action.action_type_list),
938                                      ACTION_MARK_AS_READ);
939                 break;
940         case MATCHACTION_MARK_AS_UNREAD:
941                 gtk_list_select_item(GTK_LIST(filtering_action.action_type_list),
942                                      ACTION_MARK_AS_UNREAD);
943                 break;
944         case MATCHACTION_FORWARD:
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);
948                 gtk_list_select_item(GTK_LIST(filtering_action.account_list),
949                                      list_id);
950                 break;
951         case MATCHACTION_FORWARD_AS_ATTACHMENT:
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_FORWARD_AS_ATTACHMENT);
955                 gtk_list_select_item(GTK_LIST(filtering_action.account_list),
956                                      list_id);
957                 break;
958         case MATCHACTION_REDIRECT:
959                 list_id = get_list_id_from_account_id(action->account_id);
960                 gtk_list_select_item(GTK_LIST(filtering_action.action_type_list),
961                                      ACTION_REDIRECT);
962                 gtk_list_select_item(GTK_LIST(filtering_action.account_list),
963                                      list_id);
964                 break;
965         case MATCHACTION_EXECUTE:
966                 gtk_list_select_item(GTK_LIST(filtering_action.action_type_list),
967                                      ACTION_EXECUTE);
968                 break;
969         case MATCHACTION_COLOR:
970                 gtk_list_select_item(GTK_LIST(filtering_action.action_type_list),
971                                      ACTION_COLOR);
972                 gtk_option_menu_set_history(GTK_OPTION_MENU(filtering_action.color_optmenu), action->labelcolor);     
973                 break;
974         }
975 }
976
977 /*!
978  *\brief        Handle key press
979  *
980  *\param        widget Widget receiving key press
981  *\param        event Key event
982  *\param        data User data
983  */
984 static gboolean prefs_filtering_action_key_pressed(GtkWidget *widget,
985     GdkEventKey *event, gpointer data)
986 {
987         if (event && event->keyval == GDK_Escape)
988                 prefs_filtering_action_cancel();
989         return TRUE;            
990 }
991
992 /*!
993  *\brief        Cancel matcher dialog
994  */
995 static void prefs_filtering_action_cancel(void)
996 {
997         gtk_widget_hide(filtering_action.window);
998         inc_unlock();
999 }
1000
1001 /*!
1002  *\brief        Accept current matchers
1003  */
1004 static void prefs_filtering_action_ok(void)
1005 {
1006         GSList * action_list;
1007         GSList * cur;
1008
1009         action_list = prefs_filtering_action_get_list();
1010
1011         if (action_list == NULL) {
1012                 alertpanel_error(_("No action was defined."));
1013                 return;
1014         }
1015
1016         if (filtering_action_callback != NULL)
1017                 filtering_action_callback(action_list);
1018         for(cur = action_list ; cur != NULL ; cur = cur->next) {
1019                 filteringaction_free(cur->data);
1020         }
1021         g_slist_free(action_list);
1022
1023         gtk_widget_hide(filtering_action.window);
1024         inc_unlock();
1025 }
1026
1027 /*!
1028  *\brief        Called when closing dialog box
1029  *
1030  *\param        widget Dialog widget
1031  *\param        event Event info
1032  *\param        data User data
1033  *
1034  *\return       gint TRUE
1035  */
1036 static gint prefs_filtering_action_deleted(GtkWidget *widget,
1037     GdkEventAny *event, gpointer data)
1038 {
1039         prefs_filtering_action_cancel();
1040         return TRUE;
1041 }
1042
1043 /*
1044  * Strings describing exec format strings
1045  * 
1046  * When adding new lines, remember to put 2 strings for each line
1047  */
1048 static gchar *exec_desc_strings[] = {
1049         "%%",   "%",
1050         "%s",   N_("Subject"),
1051         "%f",   N_("From"),
1052         "%t",   N_("To"),
1053         "%c",   N_("Cc"),
1054         "%d",   N_("Date"),
1055         "%i",   N_("Message-ID"),
1056         "%n",   N_("Newsgroups"),
1057         "%r",   N_("References"),
1058         "%F",   N_("Filename - should not be modified"),
1059         "\\n",  N_("new line"),
1060         "\\",   N_("escape character for quotes"),
1061         "\\\"",N_("quote character"),
1062         NULL, NULL
1063 };
1064
1065 static DescriptionWindow exec_desc_win = { 
1066         NULL, 
1067         2,
1068         N_("Description of symbols"),
1069         exec_desc_strings
1070 };
1071
1072
1073
1074 /*!
1075  *\brief        Show Execute action's info
1076  */
1077 void prefs_filtering_action_exec_info(void)
1078 {
1079         description_window_create(&exec_desc_win);
1080 }
1081
1082 static void prefs_filtering_action_select_dest(void)
1083 {
1084         FolderItem *dest;
1085         gchar * path;
1086
1087         dest = foldersel_folder_sel(NULL, FOLDER_SEL_COPY, NULL);
1088         if (!dest) return;
1089
1090         path = folder_item_get_identifier(dest);
1091
1092         gtk_entry_set_text(GTK_ENTRY(filtering_action.dest_entry), path);
1093         g_free(path);
1094 }
1095
1096 static void prefs_filtering_action_type_selection_changed(GtkList *list,
1097     gpointer user_data)
1098 {
1099         gint value;
1100
1101         value = get_sel_from_list(GTK_LIST(filtering_action.action_type_list));
1102
1103         if (filtering_action.current_action != value) {
1104                 if (filtering_action.current_action == ACTION_FORWARD 
1105                 ||  filtering_action.current_action == ACTION_FORWARD_AS_ATTACHMENT
1106                 ||  filtering_action.current_action == ACTION_REDIRECT) {
1107                         debug_print("unregistering address completion entry\n");
1108                         address_completion_unregister_entry(GTK_ENTRY(filtering_action.dest_entry));
1109                 }
1110                 if (value == ACTION_FORWARD || value == ACTION_FORWARD_AS_ATTACHMENT
1111                 ||  value == ACTION_REDIRECT) {
1112                         debug_print("registering address completion entry\n");
1113                         address_completion_register_entry(GTK_ENTRY(filtering_action.dest_entry));
1114                 }
1115                 filtering_action.current_action = value;
1116         }
1117 }
1118
1119 static void prefs_filtering_action_type_select(GtkList *list,
1120     GtkWidget *widget, gpointer user_data)
1121 {
1122         Action value;
1123
1124         value = (Action) get_sel_from_list(GTK_LIST(filtering_action.action_type_list));
1125
1126         switch (value) {
1127         case ACTION_MOVE:
1128                 gtk_widget_show(filtering_action.account_label);
1129                 gtk_widget_set_sensitive(filtering_action.account_label, FALSE);
1130                 gtk_widget_set_sensitive(filtering_action.account_combo, FALSE);
1131                 gtk_widget_show(filtering_action.dest_entry);
1132                 gtk_widget_set_sensitive(filtering_action.dest_entry, TRUE);
1133                 gtk_widget_show(filtering_action.dest_btn);
1134                 gtk_widget_set_sensitive(filtering_action.dest_btn, TRUE);
1135                 gtk_widget_show(filtering_action.dest_label);
1136                 gtk_widget_set_sensitive(filtering_action.dest_label, TRUE);
1137                 gtk_widget_hide(filtering_action.recip_label);
1138                 gtk_widget_hide(filtering_action.exec_label);
1139                 gtk_widget_hide(filtering_action.exec_btn);
1140                 gtk_widget_hide(filtering_action.color_optmenu);
1141                 gtk_widget_hide(filtering_action.color_label);
1142                 break;
1143         case ACTION_COPY:
1144                 gtk_widget_show(filtering_action.account_label);
1145                 gtk_widget_set_sensitive(filtering_action.account_label, FALSE);
1146                 gtk_widget_set_sensitive(filtering_action.account_combo, FALSE);
1147                 gtk_widget_show(filtering_action.dest_entry);
1148                 gtk_widget_set_sensitive(filtering_action.dest_entry, TRUE);
1149                 gtk_widget_show(filtering_action.dest_btn);
1150                 gtk_widget_set_sensitive(filtering_action.dest_btn, TRUE);
1151                 gtk_widget_show(filtering_action.dest_label);
1152                 gtk_widget_set_sensitive(filtering_action.dest_label, TRUE);
1153                 gtk_widget_hide(filtering_action.recip_label);
1154                 gtk_widget_hide(filtering_action.exec_label);
1155                 gtk_widget_hide(filtering_action.exec_btn);
1156                 gtk_widget_hide(filtering_action.color_optmenu);
1157                 gtk_widget_hide(filtering_action.color_label);
1158                 break;
1159         case ACTION_DELETE:
1160                 gtk_widget_show(filtering_action.account_label);
1161                 gtk_widget_set_sensitive(filtering_action.account_label, FALSE);
1162                 gtk_widget_set_sensitive(filtering_action.account_combo, FALSE);
1163                 gtk_widget_show(filtering_action.dest_entry);
1164                 gtk_widget_set_sensitive(filtering_action.dest_entry, FALSE);
1165                 gtk_widget_show(filtering_action.dest_btn);
1166                 gtk_widget_set_sensitive(filtering_action.dest_btn, FALSE);
1167                 gtk_widget_show(filtering_action.dest_label);
1168                 gtk_widget_set_sensitive(filtering_action.dest_label, FALSE);
1169                 gtk_widget_hide(filtering_action.recip_label);
1170                 gtk_widget_hide(filtering_action.exec_label);
1171                 gtk_widget_hide(filtering_action.exec_btn);
1172                 gtk_widget_hide(filtering_action.color_optmenu);
1173                 gtk_widget_hide(filtering_action.color_label);
1174                 break;
1175         case ACTION_MARK:
1176         case ACTION_UNMARK:
1177         case ACTION_LOCK:
1178         case ACTION_UNLOCK:
1179         case ACTION_MARK_AS_READ:
1180         case ACTION_MARK_AS_UNREAD:
1181                 gtk_widget_show(filtering_action.account_label);
1182                 gtk_widget_set_sensitive(filtering_action.account_label, FALSE);
1183                 gtk_widget_set_sensitive(filtering_action.account_combo, FALSE);
1184                 gtk_widget_show(filtering_action.dest_entry);
1185                 gtk_widget_set_sensitive(filtering_action.dest_entry, FALSE);
1186                 gtk_widget_show(filtering_action.dest_btn);
1187                 gtk_widget_set_sensitive(filtering_action.dest_btn, FALSE);
1188                 gtk_widget_show(filtering_action.dest_label);
1189                 gtk_widget_set_sensitive(filtering_action.dest_label, FALSE);
1190                 gtk_widget_hide(filtering_action.recip_label);
1191                 gtk_widget_hide(filtering_action.exec_label);
1192                 gtk_widget_hide(filtering_action.exec_btn);
1193                 gtk_widget_hide(filtering_action.color_optmenu);
1194                 gtk_widget_hide(filtering_action.color_label);
1195                 break;
1196         case ACTION_FORWARD:
1197                 gtk_widget_show(filtering_action.account_label);
1198                 gtk_widget_set_sensitive(filtering_action.account_label, TRUE);
1199                 gtk_widget_set_sensitive(filtering_action.account_combo, TRUE);
1200                 gtk_widget_show(filtering_action.dest_entry);
1201                 gtk_widget_set_sensitive(filtering_action.dest_entry, TRUE);
1202                 gtk_widget_show(filtering_action.dest_btn);
1203                 gtk_widget_set_sensitive(filtering_action.dest_btn, FALSE);
1204                 gtk_widget_hide(filtering_action.dest_label);
1205                 gtk_widget_show(filtering_action.recip_label);
1206                 gtk_widget_set_sensitive(filtering_action.recip_label, TRUE);
1207                 gtk_widget_hide(filtering_action.exec_label);
1208                 gtk_widget_hide(filtering_action.exec_btn);
1209                 gtk_widget_hide(filtering_action.color_optmenu);
1210                 gtk_widget_hide(filtering_action.color_label);
1211                 break;
1212         case ACTION_FORWARD_AS_ATTACHMENT:
1213                 gtk_widget_show(filtering_action.account_label);
1214                 gtk_widget_set_sensitive(filtering_action.account_label, TRUE);
1215                 gtk_widget_set_sensitive(filtering_action.account_combo, TRUE);
1216                 gtk_widget_show(filtering_action.dest_entry);
1217                 gtk_widget_set_sensitive(filtering_action.dest_entry, TRUE);
1218                 gtk_widget_show(filtering_action.dest_btn);
1219                 gtk_widget_set_sensitive(filtering_action.dest_btn, FALSE);
1220                 gtk_widget_hide(filtering_action.dest_label);
1221                 gtk_widget_show(filtering_action.recip_label);
1222                 gtk_widget_set_sensitive(filtering_action.recip_label, TRUE);
1223                 gtk_widget_hide(filtering_action.exec_label);
1224                 gtk_widget_hide(filtering_action.exec_btn);
1225                 gtk_widget_hide(filtering_action.color_optmenu);
1226                 gtk_widget_hide(filtering_action.color_label);
1227                 break;
1228         case ACTION_REDIRECT:
1229                 gtk_widget_show(filtering_action.account_label);
1230                 gtk_widget_set_sensitive(filtering_action.account_label, TRUE);
1231                 gtk_widget_set_sensitive(filtering_action.account_combo, TRUE);
1232                 gtk_widget_show(filtering_action.dest_entry);
1233                 gtk_widget_set_sensitive(filtering_action.dest_entry, TRUE);
1234                 gtk_widget_show(filtering_action.dest_btn);
1235                 gtk_widget_set_sensitive(filtering_action.dest_btn, FALSE);
1236                 gtk_widget_hide(filtering_action.dest_label);
1237                 gtk_widget_show(filtering_action.recip_label);
1238                 gtk_widget_set_sensitive(filtering_action.recip_label, TRUE);
1239                 gtk_widget_hide(filtering_action.exec_label);
1240                 gtk_widget_hide(filtering_action.exec_btn);
1241                 gtk_widget_hide(filtering_action.color_optmenu);
1242                 gtk_widget_hide(filtering_action.color_label);
1243                 break;
1244         case ACTION_EXECUTE:
1245                 gtk_widget_show(filtering_action.account_label);
1246                 gtk_widget_set_sensitive(filtering_action.account_label, FALSE);
1247                 gtk_widget_set_sensitive(filtering_action.account_combo, FALSE);
1248                 gtk_widget_show(filtering_action.dest_entry);
1249                 gtk_widget_set_sensitive(filtering_action.dest_entry, TRUE);
1250                 gtk_widget_hide(filtering_action.dest_btn);
1251                 gtk_widget_hide(filtering_action.dest_label);
1252                 gtk_widget_hide(filtering_action.recip_label);
1253                 gtk_widget_show(filtering_action.exec_label);
1254                 gtk_widget_set_sensitive(filtering_action.exec_btn, TRUE);
1255                 gtk_widget_show(filtering_action.exec_btn);
1256                 gtk_widget_hide(filtering_action.color_optmenu);
1257                 gtk_widget_hide(filtering_action.color_label);
1258                 break;
1259         case ACTION_COLOR:
1260                 gtk_widget_show(filtering_action.account_label);
1261                 gtk_widget_set_sensitive(filtering_action.account_label, FALSE);
1262                 gtk_widget_set_sensitive(filtering_action.account_combo, FALSE);
1263                 gtk_widget_hide(filtering_action.dest_entry);
1264                 gtk_widget_hide(filtering_action.dest_btn);
1265                 gtk_widget_hide(filtering_action.dest_label);
1266                 gtk_widget_hide(filtering_action.recip_label);
1267                 gtk_widget_hide(filtering_action.exec_label);
1268                 gtk_widget_show(filtering_action.exec_btn);
1269                 gtk_widget_set_sensitive(filtering_action.exec_btn, FALSE);
1270                 gtk_widget_show(filtering_action.color_optmenu);
1271                 gtk_widget_show(filtering_action.color_label);
1272                 break;
1273         }
1274 }
1275
1276 static void prefs_filtering_action_reset_dialog(void)
1277 {
1278         gtk_list_select_item(GTK_LIST(filtering_action.action_type_list), 0);
1279         gtk_list_select_item(GTK_LIST(filtering_action.account_list), 0);
1280         gtk_entry_set_text(GTK_ENTRY(filtering_action.dest_entry), "");
1281 }