Statistics
| Revision:

root / src / prefs_filter_edit.c @ 2916

History | View | Annotate | Download (63.8 kB)

1 1 hiro
/*
2 1 hiro
 * Sylpheed -- a GTK+ based, lightweight, and fast e-mail client
3 2042 hiro
 * Copyright (C) 1999-2008 Hiroyuki Yamamoto
4 1 hiro
 *
5 1 hiro
 * This program is free software; you can redistribute it and/or modify
6 1 hiro
 * it under the terms of the GNU General Public License as published by
7 1 hiro
 * the Free Software Foundation; either version 2 of the License, or
8 1 hiro
 * (at your option) any later version.
9 1 hiro
 *
10 1 hiro
 * This program is distributed in the hope that it will be useful,
11 1 hiro
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 1 hiro
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13 1 hiro
 * GNU General Public License for more details.
14 1 hiro
 *
15 1 hiro
 * You should have received a copy of the GNU General Public License
16 1 hiro
 * along with this program; if not, write to the Free Software
17 1 hiro
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
18 1 hiro
 */
19 1 hiro
20 1 hiro
#ifdef HAVE_CONFIG_H
21 1 hiro
#  include "config.h"
22 1 hiro
#endif
23 1 hiro
24 1 hiro
#include "defs.h"
25 1 hiro
26 1 hiro
#include <glib.h>
27 92 hiro
#include <glib/gi18n.h>
28 1 hiro
#include <gtk/gtk.h>
29 1 hiro
#include <gdk/gdkkeysyms.h>
30 1 hiro
#include <stdio.h>
31 1 hiro
#include <stdlib.h>
32 1 hiro
#include <string.h>
33 1 hiro
#include <errno.h>
34 1 hiro
35 1 hiro
#include "main.h"
36 1 hiro
#include "prefs.h"
37 1 hiro
#include "prefs_filter.h"
38 1 hiro
#include "prefs_filter_edit.h"
39 1 hiro
#include "prefs_common.h"
40 1 hiro
#include "mainwindow.h"
41 1 hiro
#include "foldersel.h"
42 1 hiro
#include "colorlabel.h"
43 1 hiro
#include "manage_window.h"
44 1 hiro
#include "procheader.h"
45 1 hiro
#include "menu.h"
46 1 hiro
#include "filter.h"
47 1 hiro
#include "utils.h"
48 1 hiro
#include "gtkutils.h"
49 1 hiro
#include "stock_pixmap.h"
50 1 hiro
#include "alertpanel.h"
51 1 hiro
#include "folder.h"
52 1 hiro
53 1 hiro
static struct FilterRuleEditWindow {
54 1 hiro
        GtkWidget *window;
55 1 hiro
56 1 hiro
        GtkWidget *name_entry;
57 1 hiro
        GtkWidget *bool_op_optmenu;
58 1 hiro
59 1 hiro
        GtkWidget *cond_scrolled_win;
60 808 hiro
        FilterCondEdit cond_edit;
61 1 hiro
62 1 hiro
        GtkWidget *action_scrolled_win;
63 1 hiro
        GtkWidget *action_vbox;
64 1 hiro
        GSList *action_hbox_list;
65 1 hiro
66 1 hiro
        GtkWidget *ok_btn;
67 1 hiro
        GtkWidget *cancel_btn;
68 1 hiro
69 1 hiro
        FilterRule *new_rule;
70 1 hiro
        gboolean edit_finished;
71 1 hiro
} rule_edit_window;
72 1 hiro
73 1 hiro
static struct FilterEditHeaderListDialog {
74 1 hiro
        GtkWidget *window;
75 1 hiro
        GtkWidget *clist;
76 1 hiro
        GtkWidget *entry;
77 1 hiro
78 1 hiro
        gboolean finished;
79 1 hiro
        gboolean ok;
80 1 hiro
} edit_header_list_dialog;
81 1 hiro
82 1 hiro
static void prefs_filter_edit_create                (void);
83 1 hiro
static void prefs_filter_edit_clear                (void);
84 2042 hiro
static void prefs_filter_edit_rule_to_dialog        (FilterRule        *rule,
85 2042 hiro
                                                 const gchar        *default_name);
86 808 hiro
static void prefs_filter_edit_update_header_list(FilterCondEdit        *cond_list);
87 1 hiro
88 1 hiro
static void prefs_filter_edit_set_action_hbox_menu_sensitive
89 1 hiro
                                                (ActionHBox        *hbox,
90 1 hiro
                                                 ActionMenuType         type,
91 1 hiro
                                                 gboolean         sensitive);
92 1 hiro
static void prefs_filter_edit_set_action_hbox_menus_sensitive
93 1 hiro
                                                (void);
94 1 hiro
95 1 hiro
static void prefs_filter_edit_get_action_hbox_menus_selection
96 1 hiro
                                                (gboolean        *selection);
97 1 hiro
static ActionMenuType prefs_filter_edit_get_action_hbox_type
98 1 hiro
                                                (ActionHBox        *hbox);
99 1 hiro
100 1 hiro
static void prefs_filter_edit_insert_action_hbox(ActionHBox        *hbox,
101 1 hiro
                                                 gint                 pos);
102 808 hiro
static void prefs_filter_edit_remove_cond_hbox        (FilterCondEdit        *cond_edit,
103 808 hiro
                                                 CondHBox        *hbox);
104 1 hiro
static void prefs_filter_edit_remove_action_hbox(ActionHBox        *hbox);
105 1 hiro
106 1 hiro
static void prefs_filter_edit_add_rule_action        (FilterRule        *rule);
107 1 hiro
108 1 hiro
static void prefs_filter_edit_set_cond_header_menu
109 808 hiro
                                                (FilterCondEdit        *cond_edit,
110 808 hiro
                                                 CondHBox        *hbox);
111 1 hiro
112 1 hiro
static void prefs_filter_edit_activate_cond_header
113 808 hiro
                                                (FilterCondEdit        *cond_edit,
114 808 hiro
                                                 const gchar        *header);
115 1 hiro
116 808 hiro
static void prefs_filter_edit_edit_header_list        (FilterCondEdit        *cond_edit);
117 1 hiro
118 1 hiro
static FilterRule *prefs_filter_edit_dialog_to_rule        (void);
119 1 hiro
120 1 hiro
/* callback functions */
121 1 hiro
static gint prefs_filter_edit_deleted                (GtkWidget        *widget,
122 1 hiro
                                                 GdkEventAny        *event,
123 1 hiro
                                                 gpointer         data);
124 1 hiro
static gboolean prefs_filter_edit_key_pressed        (GtkWidget        *widget,
125 1 hiro
                                                 GdkEventKey        *event,
126 1 hiro
                                                 gpointer         data);
127 1 hiro
static void prefs_filter_edit_ok                (void);
128 1 hiro
static void prefs_filter_edit_cancel                (void);
129 1 hiro
130 1 hiro
static void prefs_filter_cond_activated_cb        (GtkWidget        *widget,
131 1 hiro
                                                 gpointer         data);
132 2461 hiro
static void prefs_filter_match_activated_cb        (GtkWidget        *widget,
133 2461 hiro
                                                 gpointer         data);
134 1 hiro
static void prefs_filter_action_activated_cb        (GtkWidget        *widget,
135 1 hiro
                                                 gpointer         data);
136 1 hiro
137 1 hiro
static void prefs_filter_action_select_dest_cb        (GtkWidget        *widget,
138 1 hiro
                                                 gpointer         data);
139 1 hiro
140 1 hiro
static void prefs_filter_cond_del_cb                (GtkWidget        *widget,
141 1 hiro
                                                 gpointer         data);
142 1 hiro
static void prefs_filter_cond_add_cb                (GtkWidget        *widget,
143 1 hiro
                                                 gpointer         data);
144 1 hiro
static void prefs_filter_action_del_cb                (GtkWidget        *widget,
145 1 hiro
                                                 gpointer         data);
146 1 hiro
static void prefs_filter_action_add_cb                (GtkWidget        *widget,
147 1 hiro
                                                 gpointer         data);
148 1 hiro
149 1 hiro
150 2042 hiro
FilterRule *prefs_filter_edit_open(FilterRule *rule, const gchar *header,
151 2042 hiro
                                   const gchar *key)
152 1 hiro
{
153 198 hiro
        static gboolean lock = FALSE;
154 1 hiro
        FilterRule *new_rule;
155 1 hiro
156 198 hiro
        if (lock)
157 198 hiro
                return NULL;
158 198 hiro
159 198 hiro
        lock = TRUE;
160 198 hiro
161 1 hiro
        if (!rule_edit_window.window)
162 1 hiro
                prefs_filter_edit_create();
163 1 hiro
164 1 hiro
        manage_window_set_transient(GTK_WINDOW(rule_edit_window.window));
165 1 hiro
166 808 hiro
        prefs_filter_edit_set_header_list(&rule_edit_window.cond_edit, rule);
167 2042 hiro
        prefs_filter_edit_rule_to_dialog(rule, key);
168 1 hiro
        if (header)
169 808 hiro
                prefs_filter_edit_activate_cond_header
170 808 hiro
                        (&rule_edit_window.cond_edit, header);
171 198 hiro
        GTK_EVENTS_FLUSH();
172 1 hiro
        gtk_widget_show(rule_edit_window.window);
173 1 hiro
174 1 hiro
        rule_edit_window.new_rule = NULL;
175 1 hiro
        rule_edit_window.edit_finished = FALSE;
176 1 hiro
        while (rule_edit_window.edit_finished == FALSE)
177 1 hiro
                gtk_main_iteration();
178 1 hiro
179 198 hiro
        gtk_widget_hide(rule_edit_window.window);
180 1 hiro
        prefs_filter_edit_clear();
181 1 hiro
        prefs_filter_set_msg_header_list(NULL);
182 1 hiro
183 1 hiro
        new_rule = rule_edit_window.new_rule;
184 1 hiro
        rule_edit_window.new_rule = NULL;
185 1 hiro
186 1 hiro
        if (new_rule)
187 1 hiro
                debug_print("new rule created: %s\n", new_rule->name);
188 1 hiro
189 198 hiro
        lock = FALSE;
190 198 hiro
191 1 hiro
        return new_rule;
192 1 hiro
}
193 1 hiro
194 1 hiro
static void prefs_filter_edit_create(void)
195 1 hiro
{
196 1 hiro
        GtkWidget *window;
197 1 hiro
198 1 hiro
        GtkWidget *vbox;
199 1 hiro
200 1 hiro
        GtkWidget *hbox;
201 1 hiro
        GtkWidget *label;
202 1 hiro
        GtkWidget *name_entry;
203 1 hiro
204 1 hiro
        GtkWidget *bool_op_optmenu;
205 1 hiro
        GtkWidget *menu;
206 1 hiro
        GtkWidget *menuitem;
207 1 hiro
208 1 hiro
        GtkWidget *cond_scrolled_win;
209 1 hiro
        GtkWidget *cond_vbox;
210 1 hiro
211 1 hiro
        GtkWidget *action_scrolled_win;
212 1 hiro
        GtkWidget *action_vbox;
213 1 hiro
214 1 hiro
        GtkWidget *ok_btn;
215 1 hiro
        GtkWidget *cancel_btn;
216 1 hiro
        GtkWidget *confirm_area;
217 1 hiro
218 1 hiro
        window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
219 1 hiro
        gtk_container_set_border_width(GTK_CONTAINER(window), 8);
220 1 hiro
        gtk_widget_set_size_request(window, 632, 405);
221 1 hiro
        gtk_window_position(GTK_WINDOW(window), GTK_WIN_POS_CENTER);
222 1 hiro
        gtk_window_set_modal(GTK_WINDOW(window), TRUE);
223 1 hiro
        gtk_window_set_policy(GTK_WINDOW(window), FALSE, TRUE, FALSE);
224 1 hiro
        gtk_widget_realize(window);
225 1 hiro
226 1 hiro
        vbox = gtk_vbox_new(FALSE, 6);
227 1 hiro
        gtk_widget_show(vbox);
228 1 hiro
        gtk_container_add(GTK_CONTAINER(window), vbox);
229 1 hiro
230 31 hiro
        gtkut_stock_button_set_create(&confirm_area, &ok_btn, GTK_STOCK_OK,
231 31 hiro
                                      &cancel_btn, GTK_STOCK_CANCEL,
232 31 hiro
                                      NULL, NULL);
233 1 hiro
        gtk_widget_show(confirm_area);
234 1 hiro
        gtk_box_pack_end(GTK_BOX(vbox), confirm_area, FALSE, FALSE, 0);
235 1 hiro
        gtk_widget_grab_default(ok_btn);
236 1 hiro
237 1 hiro
        gtk_window_set_title(GTK_WINDOW(window),
238 1 hiro
                             _("Filter rule"));
239 1 hiro
        g_signal_connect(G_OBJECT(window), "delete_event",
240 1 hiro
                         G_CALLBACK(prefs_filter_edit_deleted), NULL);
241 1 hiro
        g_signal_connect(G_OBJECT(window), "key_press_event",
242 1 hiro
                         G_CALLBACK(prefs_filter_edit_key_pressed), NULL);
243 1 hiro
        MANAGE_WINDOW_SIGNALS_CONNECT (window);
244 1 hiro
        g_signal_connect(G_OBJECT(ok_btn), "clicked",
245 1 hiro
                         G_CALLBACK(prefs_filter_edit_ok), NULL);
246 1 hiro
        g_signal_connect(G_OBJECT(cancel_btn), "clicked",
247 1 hiro
                         G_CALLBACK(prefs_filter_edit_cancel), NULL);
248 1 hiro
249 1 hiro
        hbox = gtk_hbox_new(FALSE, 4);
250 1 hiro
        gtk_widget_show(hbox);
251 1 hiro
        gtk_box_pack_start(GTK_BOX(vbox), hbox, FALSE, FALSE, 0);
252 1 hiro
253 1 hiro
        label = gtk_label_new(_("Name:"));
254 1 hiro
        gtk_widget_show(label);
255 1 hiro
        gtk_box_pack_start(GTK_BOX(hbox), label, FALSE, FALSE, 0);
256 1 hiro
257 1 hiro
        name_entry = gtk_entry_new();
258 1 hiro
        gtk_widget_show(name_entry);
259 1 hiro
        gtk_box_pack_start(GTK_BOX(hbox), name_entry, TRUE, TRUE, 0);
260 1 hiro
261 1 hiro
        hbox = gtk_hbox_new(FALSE, 4);
262 1 hiro
        gtk_widget_show(hbox);
263 1 hiro
        gtk_box_pack_start(GTK_BOX(vbox), hbox, FALSE, FALSE, 0);
264 1 hiro
265 1 hiro
        bool_op_optmenu = gtk_option_menu_new();
266 1 hiro
        gtk_widget_show(bool_op_optmenu);
267 1 hiro
        gtk_box_pack_start(GTK_BOX(hbox), bool_op_optmenu, FALSE, FALSE, 0);
268 1 hiro
269 1 hiro
        menu = gtk_menu_new();
270 198 hiro
        gtk_widget_show(menu);
271 1 hiro
        MENUITEM_ADD(menu, menuitem,
272 1 hiro
                     _("If any of the following condition matches"), FLT_OR);
273 1 hiro
        MENUITEM_ADD(menu, menuitem,
274 1 hiro
                     _("If all of the following conditions match"), FLT_AND);
275 1 hiro
        gtk_option_menu_set_menu(GTK_OPTION_MENU(bool_op_optmenu), menu);
276 2776 hiro
        gtk_option_menu_set_history(GTK_OPTION_MENU(bool_op_optmenu), FLT_AND);
277 1 hiro
278 1 hiro
        cond_scrolled_win = gtk_scrolled_window_new(NULL, NULL);
279 1 hiro
        gtk_widget_show(cond_scrolled_win);
280 1 hiro
        gtk_widget_set_size_request(cond_scrolled_win, -1, 125);
281 1 hiro
        gtk_box_pack_start(GTK_BOX(vbox), cond_scrolled_win, TRUE, TRUE, 0);
282 1 hiro
        gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(cond_scrolled_win),
283 1 hiro
                                       GTK_POLICY_AUTOMATIC,
284 1 hiro
                                       GTK_POLICY_AUTOMATIC);
285 1 hiro
286 1 hiro
        cond_vbox = gtk_vbox_new(FALSE, 2);
287 1 hiro
        gtk_widget_show(cond_vbox);
288 1 hiro
        gtk_container_set_border_width(GTK_CONTAINER(cond_vbox), 2);
289 1 hiro
        gtk_scrolled_window_add_with_viewport
290 1 hiro
                (GTK_SCROLLED_WINDOW(cond_scrolled_win), cond_vbox);
291 1 hiro
292 1 hiro
        hbox = gtk_hbox_new(FALSE, 4);
293 1 hiro
        gtk_widget_show(hbox);
294 1 hiro
        gtk_box_pack_start(GTK_BOX(vbox), hbox, FALSE, FALSE, 0);
295 1 hiro
296 1 hiro
        label = gtk_label_new(_("Perform the following actions:"));
297 1 hiro
        gtk_widget_show(label);
298 1 hiro
        gtk_box_pack_start(GTK_BOX(hbox), label, FALSE, FALSE, 0);
299 1 hiro
300 1 hiro
        action_scrolled_win = gtk_scrolled_window_new(NULL, NULL);
301 1 hiro
        gtk_widget_show(action_scrolled_win);
302 1 hiro
        gtk_box_pack_start(GTK_BOX(vbox), action_scrolled_win, TRUE, TRUE, 0);
303 1 hiro
        gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(action_scrolled_win),
304 1 hiro
                                       GTK_POLICY_AUTOMATIC,
305 1 hiro
                                       GTK_POLICY_AUTOMATIC);
306 1 hiro
307 1 hiro
        action_vbox = gtk_vbox_new(FALSE, 2);
308 1 hiro
        gtk_widget_show(action_vbox);
309 1 hiro
        gtk_container_set_border_width(GTK_CONTAINER(action_vbox), 2);
310 1 hiro
        gtk_scrolled_window_add_with_viewport
311 1 hiro
                (GTK_SCROLLED_WINDOW(action_scrolled_win), action_vbox);
312 1 hiro
313 1 hiro
        rule_edit_window.window = window;
314 1 hiro
        rule_edit_window.name_entry = name_entry;
315 1 hiro
316 1 hiro
        rule_edit_window.bool_op_optmenu = bool_op_optmenu;
317 1 hiro
        rule_edit_window.cond_scrolled_win = cond_scrolled_win;
318 808 hiro
        rule_edit_window.cond_edit.cond_vbox = cond_vbox;
319 1 hiro
        rule_edit_window.action_scrolled_win = action_scrolled_win;
320 1 hiro
        rule_edit_window.action_vbox = action_vbox;
321 1 hiro
322 1 hiro
        rule_edit_window.ok_btn = ok_btn;
323 1 hiro
        rule_edit_window.cancel_btn = cancel_btn;
324 1 hiro
}
325 1 hiro
326 808 hiro
FilterCondEdit *prefs_filter_edit_cond_edit_create(void)
327 808 hiro
{
328 808 hiro
        FilterCondEdit *cond_edit;
329 808 hiro
        GtkWidget *cond_vbox;
330 808 hiro
331 808 hiro
        cond_edit = g_new(FilterCondEdit, 1);
332 808 hiro
333 808 hiro
        cond_vbox = gtk_vbox_new(FALSE, 2);
334 808 hiro
        gtk_widget_show(cond_vbox);
335 808 hiro
        gtk_container_set_border_width(GTK_CONTAINER(cond_vbox), 2);
336 808 hiro
337 808 hiro
        cond_edit->cond_vbox = cond_vbox;
338 808 hiro
        cond_edit->cond_hbox_list = NULL;
339 808 hiro
        cond_edit->hdr_list = NULL;
340 808 hiro
        cond_edit->rule_hdr_list = NULL;
341 836 hiro
        cond_edit->add_hbox = NULL;
342 808 hiro
343 808 hiro
        return cond_edit;
344 808 hiro
}
345 808 hiro
346 808 hiro
void prefs_filter_edit_clear_cond_edit(FilterCondEdit *cond_edit)
347 808 hiro
{
348 808 hiro
        while (cond_edit->cond_hbox_list) {
349 808 hiro
                CondHBox *hbox = (CondHBox *)cond_edit->cond_hbox_list->data;
350 808 hiro
                prefs_filter_edit_remove_cond_hbox(cond_edit, hbox);
351 808 hiro
        }
352 808 hiro
353 1532 hiro
        procheader_header_list_destroy(cond_edit->hdr_list);
354 808 hiro
        cond_edit->hdr_list = NULL;
355 808 hiro
        procheader_header_list_destroy(cond_edit->rule_hdr_list);
356 808 hiro
        cond_edit->rule_hdr_list = NULL;
357 808 hiro
}
358 808 hiro
359 1 hiro
static void prefs_filter_edit_clear(void)
360 1 hiro
{
361 808 hiro
        prefs_filter_edit_clear_cond_edit(&rule_edit_window.cond_edit);
362 808 hiro
363 1 hiro
        while (rule_edit_window.action_hbox_list) {
364 1 hiro
                ActionHBox *hbox =
365 1 hiro
                        (ActionHBox *)rule_edit_window.action_hbox_list->data;
366 1 hiro
                prefs_filter_edit_remove_action_hbox(hbox);
367 1 hiro
        }
368 1 hiro
}
369 1 hiro
370 2042 hiro
static void prefs_filter_edit_rule_to_dialog(FilterRule *rule,
371 2042 hiro
                                             const gchar *default_name)
372 1 hiro
{
373 2776 hiro
        gint index = 1;
374 1 hiro
        static gint count = 1;
375 1 hiro
376 1 hiro
        if (rule && rule->name)
377 1 hiro
                gtk_entry_set_text(GTK_ENTRY(rule_edit_window.name_entry),
378 1 hiro
                                   rule->name);
379 2042 hiro
        else if (default_name)
380 2042 hiro
                gtk_entry_set_text(GTK_ENTRY(rule_edit_window.name_entry),
381 2042 hiro
                                   default_name);
382 1 hiro
        else {
383 1 hiro
                gchar rule_name[32];
384 1 hiro
                g_snprintf(rule_name, sizeof(rule_name), "Rule %d", count++);
385 1 hiro
                gtk_entry_set_text(GTK_ENTRY(rule_edit_window.name_entry),
386 1 hiro
                                   rule_name);
387 1 hiro
        }
388 1 hiro
389 1 hiro
        if (rule) {
390 1 hiro
                index = menu_find_option_menu_index
391 1 hiro
                        (GTK_OPTION_MENU(rule_edit_window.bool_op_optmenu),
392 1 hiro
                         GINT_TO_POINTER(rule->bool_op), NULL);
393 1 hiro
                if (index < 0)
394 2776 hiro
                        index = 1;
395 1 hiro
        }
396 1 hiro
        if (index >= 0) {
397 1 hiro
                gtk_option_menu_set_history
398 1 hiro
                        (GTK_OPTION_MENU(rule_edit_window.bool_op_optmenu),
399 1 hiro
                         index);
400 1 hiro
        }
401 1 hiro
402 198 hiro
        gtkut_scrolled_window_reset_position
403 198 hiro
                (GTK_SCROLLED_WINDOW(rule_edit_window.cond_scrolled_win));
404 198 hiro
        gtkut_scrolled_window_reset_position
405 198 hiro
                (GTK_SCROLLED_WINDOW(rule_edit_window.action_scrolled_win));
406 198 hiro
407 808 hiro
        prefs_filter_edit_add_rule_cond(&rule_edit_window.cond_edit, rule);
408 1 hiro
        prefs_filter_edit_add_rule_action(rule);
409 1 hiro
}
410 1 hiro
411 811 hiro
void prefs_filter_edit_set_header_list(FilterCondEdit *cond_edit,
412 811 hiro
                                       FilterRule *rule)
413 1 hiro
{
414 1 hiro
        GSList *list;
415 1 hiro
        GSList *rule_hdr_list = NULL;
416 1 hiro
        GSList *cur;
417 1 hiro
        FilterCond *cond;
418 1 hiro
419 1532 hiro
        procheader_header_list_destroy(cond_edit->hdr_list);
420 808 hiro
        cond_edit->hdr_list = NULL;
421 808 hiro
        procheader_header_list_destroy(cond_edit->rule_hdr_list);
422 808 hiro
        cond_edit->rule_hdr_list = NULL;
423 1 hiro
424 1 hiro
        list = prefs_filter_get_header_list();
425 808 hiro
        cond_edit->hdr_list = list;
426 1 hiro
427 1 hiro
        if (!rule)
428 1 hiro
                return;
429 1 hiro
430 1 hiro
        for (cur = rule->cond_list; cur != NULL; cur = cur->next) {
431 1 hiro
                cond = (FilterCond *)cur->data;
432 1 hiro
433 1 hiro
                if (cond->type == FLT_COND_HEADER &&
434 1 hiro
                    procheader_find_header_list
435 1 hiro
                        (rule_hdr_list, cond->header_name) < 0)
436 1 hiro
                        rule_hdr_list = procheader_add_header_list
437 1 hiro
                                (rule_hdr_list, cond->header_name, NULL);
438 1 hiro
        }
439 1 hiro
440 808 hiro
        cond_edit->rule_hdr_list = rule_hdr_list;
441 1532 hiro
        cond_edit->hdr_list = procheader_merge_header_list_dup(list,
442 1532 hiro
                                                               rule_hdr_list);
443 1533 hiro
        procheader_header_list_destroy(list);
444 1 hiro
}
445 1 hiro
446 808 hiro
static void prefs_filter_edit_update_header_list(FilterCondEdit *cond_edit)
447 1 hiro
{
448 1 hiro
        GSList *list;
449 1 hiro
450 1532 hiro
        procheader_header_list_destroy(cond_edit->hdr_list);
451 808 hiro
        cond_edit->hdr_list = NULL;
452 1 hiro
453 1 hiro
        list = prefs_filter_get_header_list();
454 1532 hiro
        cond_edit->hdr_list = procheader_merge_header_list_dup
455 1532 hiro
                (list, cond_edit->rule_hdr_list);
456 1532 hiro
        procheader_header_list_destroy(list);
457 1 hiro
}
458 1 hiro
459 808 hiro
CondHBox *prefs_filter_edit_cond_hbox_create(FilterCondEdit *cond_edit)
460 1 hiro
{
461 1 hiro
        CondHBox *cond_hbox;
462 1 hiro
        GtkWidget *hbox;
463 1 hiro
        GtkWidget *cond_type_optmenu;
464 1 hiro
        GtkWidget *match_type_optmenu;
465 1 hiro
        GtkWidget *size_match_optmenu;
466 1 hiro
        GtkWidget *age_match_optmenu;
467 905 hiro
        GtkWidget *status_match_optmenu;
468 1 hiro
        GtkWidget *menu;
469 1 hiro
        GtkWidget *menuitem;
470 1 hiro
        GtkWidget *key_entry;
471 1 hiro
        GtkObject *spin_btn_adj;
472 1 hiro
        GtkWidget *spin_btn;
473 1 hiro
        GtkWidget *label;
474 1 hiro
        GtkWidget *del_btn;
475 1 hiro
        GtkWidget *add_btn;
476 45 hiro
        GtkWidget *del_img;
477 45 hiro
        GtkWidget *add_img;
478 2461 hiro
        GtkWidget *match_menu_in_addr;
479 2461 hiro
        GtkWidget *match_menu_not_in_addr;
480 1 hiro
481 1 hiro
        cond_hbox = g_new0(CondHBox, 1);
482 1 hiro
483 1 hiro
        hbox = gtk_hbox_new(FALSE, 4);
484 1 hiro
        gtk_widget_show(hbox);
485 1 hiro
486 1 hiro
        cond_type_optmenu = gtk_option_menu_new();
487 1 hiro
        gtk_widget_show(cond_type_optmenu);
488 1 hiro
        gtk_box_pack_start(GTK_BOX(hbox), cond_type_optmenu, FALSE, FALSE, 0);
489 1 hiro
490 1 hiro
#define COND_MENUITEM_ADD(str, action)                                            \
491 1 hiro
{                                                                            \
492 1 hiro
        MENUITEM_ADD(menu, menuitem, str, action);                            \
493 1 hiro
        g_signal_connect(G_OBJECT(menuitem), "activate",                    \
494 1 hiro
                         G_CALLBACK(prefs_filter_cond_activated_cb),            \
495 1 hiro
                         cond_hbox);                                            \
496 1 hiro
}
497 1 hiro
498 1 hiro
        menu = gtk_menu_new();
499 198 hiro
        gtk_widget_show(menu);
500 1 hiro
        MENUITEM_ADD(menu, menuitem, NULL,        PF_COND_SEPARATOR);
501 1 hiro
        COND_MENUITEM_ADD(_("To or Cc"),          PF_COND_TO_OR_CC);
502 1 hiro
        COND_MENUITEM_ADD(_("Any header"),        PF_COND_ANY_HEADER);
503 1 hiro
        COND_MENUITEM_ADD(_("Edit header..."),    PF_COND_EDIT_HEADER);
504 1 hiro
505 1 hiro
        MENUITEM_ADD(menu, menuitem, NULL,        PF_COND_SEPARATOR);
506 1 hiro
        COND_MENUITEM_ADD(_("Message body"),      PF_COND_BODY);
507 1 hiro
        COND_MENUITEM_ADD(_("Result of command"), PF_COND_CMD_TEST);
508 1 hiro
        COND_MENUITEM_ADD(_("Size"),              PF_COND_SIZE);
509 1 hiro
        COND_MENUITEM_ADD(_("Age"),               PF_COND_AGE);
510 905 hiro
511 905 hiro
        MENUITEM_ADD(menu, menuitem, NULL,        PF_COND_SEPARATOR);
512 905 hiro
        COND_MENUITEM_ADD(_("Unread"),            PF_COND_UNREAD);
513 905 hiro
        COND_MENUITEM_ADD(_("Marked"),            PF_COND_MARK);
514 905 hiro
        COND_MENUITEM_ADD(_("Has color label"),   PF_COND_COLOR_LABEL);
515 905 hiro
        COND_MENUITEM_ADD(_("Has attachment"),    PF_COND_MIME);
516 1 hiro
        /* COND_MENUITEM_ADD(_("Account"),           PF_COND_ACCOUNT); */
517 1 hiro
518 1 hiro
        gtk_option_menu_set_menu(GTK_OPTION_MENU(cond_type_optmenu), menu);
519 1 hiro
520 1 hiro
#undef COND_MENUITEM_ADD
521 1 hiro
522 1 hiro
        match_type_optmenu = gtk_option_menu_new();
523 1 hiro
        gtk_widget_show(match_type_optmenu);
524 1 hiro
        gtk_box_pack_start(GTK_BOX(hbox), match_type_optmenu, FALSE, FALSE, 0);
525 1 hiro
526 2461 hiro
#define MATCH_MENUITEM_ADD(str, action)                                            \
527 2461 hiro
{                                                                            \
528 2461 hiro
        MENUITEM_ADD(menu, menuitem, str, action);                            \
529 2461 hiro
        g_signal_connect(G_OBJECT(menuitem), "activate",                    \
530 2461 hiro
                         G_CALLBACK(prefs_filter_match_activated_cb),            \
531 2461 hiro
                         cond_hbox);                                            \
532 2461 hiro
}
533 1 hiro
        menu = gtk_menu_new();
534 198 hiro
        gtk_widget_show(menu);
535 2461 hiro
        MATCH_MENUITEM_ADD(_("contains"),               PF_MATCH_CONTAIN);
536 2461 hiro
        MATCH_MENUITEM_ADD(_("doesn't contain"),        PF_MATCH_NOT_CONTAIN);
537 2461 hiro
        MATCH_MENUITEM_ADD(_("is"),                     PF_MATCH_EQUAL);
538 2461 hiro
        MATCH_MENUITEM_ADD(_("is not"),                 PF_MATCH_NOT_EQUAL);
539 1113 hiro
#if defined(USE_ONIGURUMA) || defined(HAVE_REGCOMP)
540 2461 hiro
        MATCH_MENUITEM_ADD(_("match to regex"),         PF_MATCH_REGEX);
541 2461 hiro
        MATCH_MENUITEM_ADD(_("doesn't match to regex"), PF_MATCH_NOT_REGEX);
542 979 hiro
#endif
543 2461 hiro
        MATCH_MENUITEM_ADD(_("is in addressbook"),      PF_MATCH_IN_ADDRESSBOOK);
544 2461 hiro
        match_menu_in_addr = menuitem;
545 2462 hiro
        MATCH_MENUITEM_ADD(_("is not in addressbook"),  PF_MATCH_NOT_IN_ADDRESSBOOK);
546 2461 hiro
        match_menu_not_in_addr = menuitem;
547 1 hiro
        gtk_option_menu_set_menu(GTK_OPTION_MENU(match_type_optmenu), menu);
548 1 hiro
549 2461 hiro
#undef MATCH_MENUITEM_ADD
550 2461 hiro
551 1 hiro
        size_match_optmenu = gtk_option_menu_new();
552 198 hiro
        gtk_widget_show(size_match_optmenu);
553 1 hiro
        gtk_box_pack_start(GTK_BOX(hbox), size_match_optmenu, FALSE, FALSE, 0);
554 1 hiro
555 1 hiro
        menu = gtk_menu_new();
556 198 hiro
        gtk_widget_show(menu);
557 1 hiro
        MENUITEM_ADD(menu, menuitem, _("is larger than"), PF_SIZE_LARGER);
558 1 hiro
        MENUITEM_ADD(menu, menuitem, _("is smaller than"), PF_SIZE_SMALLER);
559 1 hiro
        gtk_option_menu_set_menu(GTK_OPTION_MENU(size_match_optmenu), menu);
560 1 hiro
561 1 hiro
        age_match_optmenu = gtk_option_menu_new();
562 198 hiro
        gtk_widget_show(age_match_optmenu);
563 1 hiro
        gtk_box_pack_start(GTK_BOX(hbox), age_match_optmenu, FALSE, FALSE, 0);
564 1 hiro
565 1 hiro
        menu = gtk_menu_new();
566 198 hiro
        gtk_widget_show(menu);
567 1 hiro
        MENUITEM_ADD(menu, menuitem, _("is longer than"), PF_AGE_LONGER);
568 1 hiro
        MENUITEM_ADD(menu, menuitem, _("is shorter than"), PF_AGE_SHORTER);
569 1 hiro
        gtk_option_menu_set_menu(GTK_OPTION_MENU(age_match_optmenu), menu);
570 1 hiro
571 905 hiro
        status_match_optmenu = gtk_option_menu_new();
572 905 hiro
        gtk_widget_show(status_match_optmenu);
573 905 hiro
        gtk_box_pack_start(GTK_BOX(hbox), status_match_optmenu,
574 905 hiro
                           FALSE, FALSE, 0);
575 905 hiro
576 905 hiro
        menu = gtk_menu_new();
577 905 hiro
        gtk_widget_show(menu);
578 905 hiro
        MENUITEM_ADD(menu, menuitem, _("matches to status"), PF_STATUS_MATCH);
579 905 hiro
        MENUITEM_ADD(menu, menuitem, _("doesn't match to status"),
580 905 hiro
                     PF_STATUS_NOT_MATCH);
581 905 hiro
        gtk_option_menu_set_menu(GTK_OPTION_MENU(status_match_optmenu), menu);
582 905 hiro
583 1 hiro
        key_entry = gtk_entry_new();
584 1 hiro
        gtk_widget_show(key_entry);
585 1 hiro
        gtk_box_pack_start(GTK_BOX(hbox), key_entry, TRUE, TRUE, 0);
586 1 hiro
587 2542 hiro
        spin_btn_adj = gtk_adjustment_new(0, 0, 99999, 1, 10, 0);
588 1 hiro
        spin_btn = gtk_spin_button_new(GTK_ADJUSTMENT(spin_btn_adj), 1, 0);
589 1 hiro
        gtk_box_pack_start(GTK_BOX(hbox), spin_btn, FALSE, FALSE, 0);
590 1 hiro
        gtk_widget_set_size_request(spin_btn, 64, -1);
591 1 hiro
        gtk_spin_button_set_numeric(GTK_SPIN_BUTTON(spin_btn), TRUE);
592 1 hiro
593 1 hiro
        label = gtk_label_new(_("KB"));
594 1 hiro
        gtk_box_pack_start(GTK_BOX(hbox), label, FALSE, FALSE, 0);
595 1 hiro
596 45 hiro
        del_img = gtk_image_new_from_stock
597 45 hiro
                (GTK_STOCK_REMOVE, GTK_ICON_SIZE_MENU);
598 45 hiro
        gtk_widget_show(del_img);
599 1 hiro
600 1 hiro
        del_btn = gtk_button_new();
601 45 hiro
        gtk_container_add(GTK_CONTAINER(del_btn), del_img);
602 1 hiro
        gtk_widget_show(del_btn);
603 1 hiro
        gtk_box_pack_end(GTK_BOX(hbox), del_btn, FALSE, FALSE, 0);
604 1 hiro
605 45 hiro
        add_img = gtk_image_new_from_stock(GTK_STOCK_ADD, GTK_ICON_SIZE_MENU);
606 45 hiro
        gtk_widget_show(add_img);
607 1 hiro
608 1 hiro
        add_btn = gtk_button_new();
609 45 hiro
        gtk_container_add(GTK_CONTAINER(add_btn), add_img);
610 1 hiro
        gtk_widget_show(add_btn);
611 1 hiro
        gtk_box_pack_end(GTK_BOX(hbox), add_btn, FALSE, FALSE, 0);
612 1 hiro
613 1 hiro
        g_signal_connect(G_OBJECT(del_btn), "clicked",
614 1 hiro
                         G_CALLBACK(prefs_filter_cond_del_cb), cond_hbox);
615 1 hiro
        g_signal_connect(G_OBJECT(add_btn), "clicked",
616 1 hiro
                         G_CALLBACK(prefs_filter_cond_add_cb), cond_hbox);
617 1 hiro
618 1 hiro
        cond_hbox->hbox = hbox;
619 1 hiro
        cond_hbox->cond_type_optmenu = cond_type_optmenu;
620 1 hiro
        cond_hbox->match_type_optmenu = match_type_optmenu;
621 1 hiro
        cond_hbox->size_match_optmenu = size_match_optmenu;
622 1 hiro
        cond_hbox->age_match_optmenu = age_match_optmenu;
623 905 hiro
        cond_hbox->status_match_optmenu = status_match_optmenu;
624 1 hiro
        cond_hbox->key_entry = key_entry;
625 1 hiro
        cond_hbox->spin_btn = spin_btn;
626 1 hiro
        cond_hbox->label = label;
627 2461 hiro
        cond_hbox->match_menu_in_addr = match_menu_in_addr;
628 2461 hiro
        cond_hbox->match_menu_not_in_addr = match_menu_not_in_addr;
629 1 hiro
        cond_hbox->del_btn = del_btn;
630 1 hiro
        cond_hbox->add_btn = add_btn;
631 1 hiro
        cond_hbox->cur_type = PF_COND_HEADER;
632 1 hiro
        cond_hbox->cur_header_name = NULL;
633 808 hiro
        cond_hbox->cond_edit = cond_edit;
634 1 hiro
635 808 hiro
        prefs_filter_edit_set_cond_header_menu(cond_edit, cond_hbox);
636 1 hiro
        gtk_option_menu_set_history(GTK_OPTION_MENU(cond_type_optmenu), 0);
637 1 hiro
638 1 hiro
        return cond_hbox;
639 1 hiro
}
640 1 hiro
641 804 hiro
ActionHBox *prefs_filter_edit_action_hbox_create(void)
642 1 hiro
{
643 1 hiro
        ActionHBox *action_hbox;
644 1 hiro
        GtkWidget *hbox;
645 1 hiro
        GtkWidget *action_type_optmenu;
646 1 hiro
        GtkWidget *menu;
647 1 hiro
        GtkWidget *menuitem;
648 1 hiro
        GtkWidget *label;
649 1 hiro
        GtkWidget *folder_entry;
650 1 hiro
        GtkWidget *cmd_entry;
651 1 hiro
        GtkWidget *address_entry;
652 45 hiro
        GtkWidget *folder_img;
653 1 hiro
        GtkWidget *folder_sel_btn;
654 1 hiro
        GtkWidget *clabel_optmenu;
655 1 hiro
        GtkWidget *del_btn;
656 1 hiro
        GtkWidget *add_btn;
657 45 hiro
        GtkWidget *del_img;
658 45 hiro
        GtkWidget *add_img;
659 1 hiro
660 1 hiro
        action_hbox = g_new0(ActionHBox, 1);
661 1 hiro
662 1 hiro
        hbox = gtk_hbox_new(FALSE, 4);
663 1 hiro
        gtk_widget_show(hbox);
664 1 hiro
665 1 hiro
        action_type_optmenu = gtk_option_menu_new();
666 1 hiro
        gtk_widget_show(action_type_optmenu);
667 1 hiro
        gtk_box_pack_start(GTK_BOX(hbox), action_type_optmenu, FALSE, FALSE, 0);
668 1 hiro
669 1 hiro
        memset(action_hbox->action_type_menu_items, 0,
670 1 hiro
               sizeof(action_hbox->action_type_menu_items));
671 1 hiro
672 1 hiro
#define ACTION_MENUITEM_ADD(str, action)                                      \
673 1 hiro
{                                                                              \
674 1 hiro
        MENUITEM_ADD(menu, menuitem, str, action);                              \
675 1 hiro
        action_hbox->action_type_menu_items[action] = menuitem;                      \
676 1 hiro
        g_signal_connect(G_OBJECT(menuitem), "activate",                      \
677 1 hiro
                         G_CALLBACK(prefs_filter_action_activated_cb),              \
678 1 hiro
                         action_hbox);                                              \
679 1 hiro
}
680 1 hiro
681 1 hiro
        menu = gtk_menu_new();
682 198 hiro
        gtk_widget_show(menu);
683 1 hiro
        ACTION_MENUITEM_ADD(_("Move to"),               PF_ACTION_MOVE);
684 1 hiro
        ACTION_MENUITEM_ADD(_("Copy to"),               PF_ACTION_COPY);
685 1 hiro
        ACTION_MENUITEM_ADD(_("Don't receive"),         PF_ACTION_NOT_RECEIVE);
686 1 hiro
        ACTION_MENUITEM_ADD(_("Delete from server"),    PF_ACTION_DELETE);
687 1 hiro
688 1 hiro
        MENUITEM_ADD(menu, menuitem, NULL,              PF_ACTION_SEPARATOR);
689 1 hiro
        ACTION_MENUITEM_ADD(_("Set mark"),              PF_ACTION_MARK);
690 1 hiro
        ACTION_MENUITEM_ADD(_("Set color"),             PF_ACTION_COLOR_LABEL);
691 1 hiro
        ACTION_MENUITEM_ADD(_("Mark as read"),          PF_ACTION_MARK_READ);
692 1 hiro
693 1 hiro
#if 0
694 1 hiro
        MENUITEM_ADD(menu, menuitem, NULL,              PF_ACTION_SEPARATOR);
695 1 hiro
        ACTION_MENUITEM_ADD(_("Forward"),               PF_ACTION_FORWARD);
696 1 hiro
        ACTION_MENUITEM_ADD(_("Forward as attachment"), PF_ACTION_FORWARD_AS_ATTACHMENT);
697 1 hiro
        ACTION_MENUITEM_ADD(_("Redirect"),              PF_ACTION_REDIRECT);
698 1 hiro
#endif
699 1 hiro
700 1 hiro
        MENUITEM_ADD(menu, menuitem, NULL,              PF_ACTION_SEPARATOR);
701 1 hiro
        ACTION_MENUITEM_ADD(_("Execute command"),       PF_ACTION_EXEC);
702 1 hiro
703 1 hiro
        MENUITEM_ADD(menu, menuitem, NULL,              PF_ACTION_SEPARATOR);
704 1 hiro
        ACTION_MENUITEM_ADD(_("Stop rule evaluation"),  PF_ACTION_STOP_EVAL);
705 1 hiro
706 1 hiro
        gtk_option_menu_set_menu(GTK_OPTION_MENU(action_type_optmenu), menu);
707 1 hiro
708 1 hiro
#undef ACTION_MENUITEM_ADD
709 1 hiro
710 1 hiro
        label = gtk_label_new(_("folder:"));
711 1 hiro
        gtk_widget_show(label);
712 1 hiro
        gtk_box_pack_start(GTK_BOX(hbox), label, FALSE, FALSE, 0);
713 1 hiro
714 1 hiro
        folder_entry = gtk_entry_new();
715 1 hiro
        gtk_widget_show(folder_entry);
716 1 hiro
        gtk_box_pack_start(GTK_BOX(hbox), folder_entry, TRUE, TRUE, 0);
717 1 hiro
718 503 hiro
        folder_img = stock_pixbuf_widget(rule_edit_window.window,
719 2388 hiro
                                         STOCK_PIXMAP_FOLDER_OPEN);
720 45 hiro
        gtk_widget_show(folder_img);
721 1 hiro
722 1 hiro
        folder_sel_btn = gtk_button_new();
723 45 hiro
        gtk_container_add(GTK_CONTAINER(folder_sel_btn), folder_img);
724 1 hiro
        gtk_widget_show(folder_sel_btn);
725 1 hiro
        gtk_box_pack_start(GTK_BOX(hbox), folder_sel_btn, FALSE, FALSE, 0);
726 1 hiro
727 1 hiro
        cmd_entry = gtk_entry_new();
728 1 hiro
        gtk_widget_show(cmd_entry);
729 1 hiro
        gtk_box_pack_start(GTK_BOX(hbox), cmd_entry, TRUE, TRUE, 0);
730 1 hiro
731 1 hiro
        address_entry = gtk_entry_new();
732 1 hiro
        gtk_widget_show(address_entry);
733 1 hiro
        gtk_box_pack_start(GTK_BOX(hbox), address_entry, TRUE, TRUE, 0);
734 1 hiro
735 1 hiro
        clabel_optmenu = gtk_option_menu_new();
736 1 hiro
        gtk_widget_show(clabel_optmenu);
737 1 hiro
        gtk_box_pack_start(GTK_BOX(hbox), clabel_optmenu, FALSE, FALSE, 0);
738 1 hiro
739 1 hiro
        menu = colorlabel_create_color_menu();
740 1 hiro
        gtk_option_menu_set_menu(GTK_OPTION_MENU(clabel_optmenu), menu);
741 1 hiro
742 45 hiro
        del_img = gtk_image_new_from_stock
743 45 hiro
                (GTK_STOCK_REMOVE, GTK_ICON_SIZE_MENU);
744 45 hiro
        gtk_widget_show(del_img);
745 1 hiro
746 1 hiro
        del_btn = gtk_button_new();
747 45 hiro
        gtk_container_add(GTK_CONTAINER(del_btn), del_img);
748 1 hiro
        gtk_widget_show(del_btn);
749 1 hiro
        gtk_box_pack_end(GTK_BOX(hbox), del_btn, FALSE, FALSE, 0);
750 1 hiro
751 45 hiro
        add_img = gtk_image_new_from_stock(GTK_STOCK_ADD, GTK_ICON_SIZE_MENU);
752 45 hiro
        gtk_widget_show(add_img);
753 1 hiro
754 1 hiro
        add_btn = gtk_button_new();
755 45 hiro
        gtk_container_add(GTK_CONTAINER(add_btn), add_img);
756 1 hiro
        gtk_widget_show(add_btn);
757 1 hiro
        gtk_box_pack_end(GTK_BOX(hbox), add_btn, FALSE, FALSE, 0);
758 1 hiro
759 1 hiro
        g_signal_connect(G_OBJECT(folder_sel_btn), "clicked",
760 1 hiro
                         G_CALLBACK(prefs_filter_action_select_dest_cb),
761 1 hiro
                         action_hbox);
762 1 hiro
        g_signal_connect(G_OBJECT(del_btn), "clicked",
763 1 hiro
                         G_CALLBACK(prefs_filter_action_del_cb), action_hbox);
764 1 hiro
        g_signal_connect(G_OBJECT(add_btn), "clicked",
765 1 hiro
                         G_CALLBACK(prefs_filter_action_add_cb), action_hbox);
766 1 hiro
767 1 hiro
        action_hbox->hbox = hbox;
768 1 hiro
        action_hbox->action_type_optmenu = action_type_optmenu;
769 1 hiro
        action_hbox->label = label;
770 1 hiro
        action_hbox->folder_entry = folder_entry;
771 1 hiro
        action_hbox->cmd_entry = cmd_entry;
772 1 hiro
        action_hbox->address_entry = address_entry;
773 1 hiro
        action_hbox->folder_sel_btn = folder_sel_btn;
774 1 hiro
        action_hbox->clabel_optmenu = clabel_optmenu;
775 1 hiro
        action_hbox->del_btn = del_btn;
776 1 hiro
        action_hbox->add_btn = add_btn;
777 1 hiro
778 1 hiro
        return action_hbox;
779 1 hiro
}
780 1 hiro
781 804 hiro
void prefs_filter_edit_cond_hbox_set(CondHBox *hbox, FilterCond *cond)
782 1 hiro
{
783 1 hiro
        GtkOptionMenu *cond_type_optmenu =
784 1 hiro
                GTK_OPTION_MENU(hbox->cond_type_optmenu);
785 1 hiro
        GtkOptionMenu *match_type_optmenu =
786 1 hiro
                GTK_OPTION_MENU(hbox->match_type_optmenu);
787 1 hiro
        gint cond_index = -1;
788 1 hiro
        gint match_index = -1;
789 1 hiro
        CondMenuType cond_type = PF_COND_NONE;
790 1 hiro
        MatchMenuType match_type = PF_MATCH_NONE;
791 1 hiro
        SizeMatchType size_type = PF_SIZE_LARGER;
792 1 hiro
        AgeMatchType age_type = PF_AGE_LONGER;
793 905 hiro
        StatusMatchType status_type = PF_STATUS_MATCH;
794 1 hiro
795 1 hiro
        switch (cond->type) {
796 1 hiro
        case FLT_COND_HEADER:
797 1 hiro
                cond_type = PF_COND_HEADER; break;
798 1 hiro
        case FLT_COND_TO_OR_CC:
799 1 hiro
                cond_type = PF_COND_TO_OR_CC; break;
800 1 hiro
        case FLT_COND_ANY_HEADER:
801 1 hiro
                cond_type = PF_COND_ANY_HEADER; break;
802 1 hiro
        case FLT_COND_BODY:
803 1 hiro
                cond_type = PF_COND_BODY; break;
804 1 hiro
        case FLT_COND_CMD_TEST:
805 1 hiro
                cond_type = PF_COND_CMD_TEST; break;
806 1 hiro
        case FLT_COND_SIZE_GREATER:
807 1 hiro
                cond_type = PF_COND_SIZE;
808 1 hiro
                if (FLT_IS_NOT_MATCH(cond->match_flag))
809 1 hiro
                        size_type = PF_SIZE_SMALLER;
810 1 hiro
                else
811 1 hiro
                        size_type = PF_SIZE_LARGER;
812 1 hiro
                break;
813 1 hiro
        case FLT_COND_AGE_GREATER:
814 1 hiro
                cond_type = PF_COND_AGE;
815 1 hiro
                if (FLT_IS_NOT_MATCH(cond->match_flag))
816 1 hiro
                        age_type = PF_AGE_SHORTER;
817 1 hiro
                else
818 1 hiro
                        age_type = PF_AGE_LONGER;
819 1 hiro
                break;
820 905 hiro
        case FLT_COND_UNREAD:
821 905 hiro
                cond_type = PF_COND_UNREAD; break;
822 905 hiro
        case FLT_COND_MARK:
823 905 hiro
                cond_type = PF_COND_MARK; break;
824 905 hiro
        case FLT_COND_COLOR_LABEL:
825 905 hiro
                cond_type = PF_COND_COLOR_LABEL; break;
826 905 hiro
        case FLT_COND_MIME:
827 905 hiro
                cond_type = PF_COND_MIME; break;
828 1 hiro
        case FLT_COND_ACCOUNT:
829 1 hiro
                cond_type = PF_COND_ACCOUNT; break;
830 1 hiro
        default:
831 1 hiro
                break;
832 1 hiro
        }
833 1 hiro
834 1 hiro
        switch (cond->type) {
835 1 hiro
        case FLT_COND_HEADER:
836 1 hiro
        case FLT_COND_TO_OR_CC:
837 1 hiro
        case FLT_COND_ANY_HEADER:
838 1 hiro
        case FLT_COND_BODY:
839 1 hiro
                switch (cond->match_type) {
840 1 hiro
                case FLT_CONTAIN:
841 1 hiro
                        if (FLT_IS_NOT_MATCH(cond->match_flag))
842 1 hiro
                                match_type = PF_MATCH_NOT_CONTAIN;
843 1 hiro
                        else
844 1 hiro
                                match_type = PF_MATCH_CONTAIN;
845 1 hiro
                        break;
846 1 hiro
                case FLT_EQUAL:
847 1 hiro
                        if (FLT_IS_NOT_MATCH(cond->match_flag))
848 1 hiro
                                match_type = PF_MATCH_NOT_EQUAL;
849 1 hiro
                        else
850 1 hiro
                                match_type = PF_MATCH_EQUAL;
851 1 hiro
                        break;
852 1 hiro
                case FLT_REGEX:
853 1 hiro
                        if (FLT_IS_NOT_MATCH(cond->match_flag))
854 1 hiro
                                match_type = PF_MATCH_NOT_REGEX;
855 1 hiro
                        else
856 1 hiro
                                match_type = PF_MATCH_REGEX;
857 1 hiro
                        break;
858 2461 hiro
                case FLT_IN_ADDRESSBOOK:
859 2461 hiro
                        if (FLT_IS_NOT_MATCH(cond->match_flag))
860 2461 hiro
                                match_type = PF_MATCH_NOT_IN_ADDRESSBOOK;
861 2461 hiro
                        else
862 2461 hiro
                                match_type = PF_MATCH_IN_ADDRESSBOOK;
863 2461 hiro
                        break;
864 1 hiro
                }
865 1 hiro
                break;
866 905 hiro
        case FLT_COND_UNREAD:
867 905 hiro
        case FLT_COND_MARK:
868 905 hiro
        case FLT_COND_COLOR_LABEL:
869 905 hiro
        case FLT_COND_MIME:
870 905 hiro
                if (FLT_IS_NOT_MATCH(cond->match_flag))
871 905 hiro
                        status_type = PF_STATUS_NOT_MATCH;
872 905 hiro
                else
873 905 hiro
                        status_type = PF_STATUS_MATCH;
874 905 hiro
                break;
875 1 hiro
        default:
876 1 hiro
                break;
877 1 hiro
        }
878 1 hiro
879 1 hiro
        if (cond_type == PF_COND_HEADER)
880 1 hiro
                cond_index = procheader_find_header_list
881 808 hiro
                        (hbox->cond_edit->hdr_list, cond->header_name);
882 1 hiro
        else
883 1 hiro
                cond_index = menu_find_option_menu_index
884 1 hiro
                        (cond_type_optmenu, GINT_TO_POINTER(cond_type), NULL);
885 1 hiro
        if (cond_index >= 0) {
886 1 hiro
                GtkWidget *menuitem;
887 1 hiro
888 1 hiro
                if (cond_type == PF_COND_SIZE || cond_type == PF_COND_AGE) {
889 1 hiro
                        gtk_spin_button_set_value
890 1 hiro
                                (GTK_SPIN_BUTTON(hbox->spin_btn),
891 1 hiro
                                 (gfloat)cond->int_value);
892 1 hiro
                } else {
893 1 hiro
                        gtk_entry_set_text(GTK_ENTRY(hbox->key_entry),
894 1 hiro
                                           cond->str_value ?
895 1 hiro
                                           cond->str_value : "");
896 1 hiro
                }
897 1 hiro
                gtk_option_menu_set_history(cond_type_optmenu, cond_index);
898 1 hiro
                menuitem = gtk_menu_get_active
899 1 hiro
                        (GTK_MENU(gtk_option_menu_get_menu(cond_type_optmenu)));
900 1 hiro
                gtk_menu_item_activate(GTK_MENU_ITEM(menuitem));
901 1 hiro
        }
902 1 hiro
903 1 hiro
        match_index = menu_find_option_menu_index
904 1 hiro
                (match_type_optmenu, GINT_TO_POINTER(match_type), NULL);
905 1 hiro
        if (match_index >= 0)
906 1 hiro
                gtk_option_menu_set_history(match_type_optmenu, match_index);
907 1 hiro
        if (cond_type == PF_COND_SIZE)
908 1 hiro
                gtk_option_menu_set_history
909 1 hiro
                        (GTK_OPTION_MENU(hbox->size_match_optmenu), size_type);
910 1 hiro
        else if (cond_type == PF_COND_AGE)
911 1 hiro
                gtk_option_menu_set_history
912 1 hiro
                        (GTK_OPTION_MENU(hbox->age_match_optmenu), age_type);
913 905 hiro
        else if (cond_type == PF_COND_UNREAD || cond_type == PF_COND_MARK ||
914 905 hiro
                 cond_type == PF_COND_COLOR_LABEL || cond_type == PF_COND_MIME)
915 905 hiro
                gtk_option_menu_set_history
916 905 hiro
                        (GTK_OPTION_MENU(hbox->status_match_optmenu),
917 905 hiro
                         status_type);
918 2461 hiro
919 2461 hiro
        if (match_type == PF_MATCH_IN_ADDRESSBOOK ||
920 2461 hiro
            match_type == PF_MATCH_NOT_IN_ADDRESSBOOK)
921 2461 hiro
                gtk_widget_hide(hbox->key_entry);
922 1 hiro
}
923 1 hiro
924 804 hiro
void prefs_filter_edit_action_hbox_set(ActionHBox *hbox, FilterAction *action)
925 1 hiro
{
926 1 hiro
        GtkOptionMenu *type_optmenu = GTK_OPTION_MENU(hbox->action_type_optmenu);
927 1 hiro
        GtkWidget *menu;
928 1 hiro
        ActionMenuType type = PF_ACTION_NONE;
929 1 hiro
930 1 hiro
        menu = gtk_option_menu_get_menu(type_optmenu);
931 1 hiro
932 1 hiro
        switch (action->type) {
933 1 hiro
        case FLT_ACTION_MOVE:
934 1 hiro
                type = PF_ACTION_MOVE; break;
935 1 hiro
        case FLT_ACTION_COPY:
936 1 hiro
                type = PF_ACTION_COPY; break;
937 1 hiro
        case FLT_ACTION_NOT_RECEIVE:
938 1 hiro
                type = PF_ACTION_NOT_RECEIVE; break;
939 1 hiro
        case FLT_ACTION_DELETE:
940 1 hiro
                type = PF_ACTION_DELETE; break;
941 1 hiro
        case FLT_ACTION_EXEC:
942 1 hiro
                type = PF_ACTION_EXEC; break;
943 1 hiro
        case FLT_ACTION_MARK:
944 1 hiro
                type = PF_ACTION_MARK; break;
945 1 hiro
        case FLT_ACTION_COLOR_LABEL:
946 1 hiro
                type = PF_ACTION_COLOR_LABEL; break;
947 1 hiro
        case FLT_ACTION_MARK_READ:
948 1 hiro
                type = PF_ACTION_MARK_READ; break;
949 1 hiro
        case FLT_ACTION_STOP_EVAL:
950 1 hiro
                type = PF_ACTION_STOP_EVAL; break;
951 1 hiro
        default:
952 1 hiro
                break;
953 1 hiro
        }
954 1 hiro
955 1 hiro
        switch (type) {
956 1 hiro
        case PF_ACTION_MOVE:
957 1 hiro
        case PF_ACTION_COPY:
958 1 hiro
                gtk_entry_set_text(GTK_ENTRY(hbox->folder_entry),
959 1 hiro
                                   action->str_value ? action->str_value : "");
960 1 hiro
                break;
961 1 hiro
        case PF_ACTION_EXEC:
962 1 hiro
                gtk_entry_set_text(GTK_ENTRY(hbox->cmd_entry),
963 1 hiro
                                   action->str_value ? action->str_value : "");
964 1 hiro
                break;
965 1 hiro
        case PF_ACTION_COLOR_LABEL:
966 1 hiro
                gtk_option_menu_set_history
967 1 hiro
                        (GTK_OPTION_MENU(hbox->clabel_optmenu),
968 1 hiro
                         action->int_value - 1);
969 1 hiro
                break;
970 1 hiro
        default:
971 1 hiro
                break;
972 1 hiro
        }
973 1 hiro
974 1 hiro
        prefs_filter_edit_set_action_hbox_widgets(hbox, type);
975 1 hiro
}
976 1 hiro
977 804 hiro
void prefs_filter_edit_cond_hbox_select(CondHBox *hbox, CondMenuType type,
978 804 hiro
                                        const gchar *header_name)
979 1 hiro
{
980 1 hiro
        gint index;
981 1 hiro
        GtkOptionMenu *cond_type_optmenu =
982 1 hiro
                GTK_OPTION_MENU(hbox->cond_type_optmenu);
983 1 hiro
        GtkWidget *menu;
984 1 hiro
985 1 hiro
        if (type == PF_COND_HEADER) {
986 1 hiro
                if (header_name)
987 1 hiro
                        index = procheader_find_header_list
988 808 hiro
                                (hbox->cond_edit->hdr_list, header_name);
989 1 hiro
                else
990 1 hiro
                        index = 0;
991 1 hiro
        } else
992 1 hiro
                index = menu_find_option_menu_index
993 1 hiro
                        (cond_type_optmenu, GINT_TO_POINTER(type), NULL);
994 1 hiro
995 1 hiro
        if (index < 0)
996 1 hiro
                index = 0;
997 1 hiro
998 1 hiro
        menu = gtk_option_menu_get_menu(cond_type_optmenu);
999 1 hiro
        gtk_option_menu_set_history(cond_type_optmenu, index);
1000 1 hiro
}
1001 1 hiro
1002 804 hiro
void prefs_filter_edit_set_cond_hbox_widgets(CondHBox *hbox, CondMenuType type)
1003 1 hiro
{
1004 2461 hiro
        MatchMenuType match_type;
1005 2461 hiro
1006 1 hiro
        switch (type) {
1007 1 hiro
        case PF_COND_HEADER:
1008 1 hiro
        case PF_COND_TO_OR_CC:
1009 1 hiro
        case PF_COND_ANY_HEADER:
1010 1 hiro
        case PF_COND_BODY:
1011 1 hiro
                gtk_widget_show(hbox->match_type_optmenu);
1012 1 hiro
                gtk_widget_hide(hbox->size_match_optmenu);
1013 1 hiro
                gtk_widget_hide(hbox->age_match_optmenu);
1014 905 hiro
                gtk_widget_hide(hbox->status_match_optmenu);
1015 2461 hiro
                match_type = menu_get_option_menu_active_index
1016 2461 hiro
                        (GTK_OPTION_MENU(hbox->match_type_optmenu));
1017 2461 hiro
                if (match_type == PF_MATCH_IN_ADDRESSBOOK ||
1018 2461 hiro
                    match_type == PF_MATCH_NOT_IN_ADDRESSBOOK)
1019 2461 hiro
                        gtk_widget_hide(hbox->key_entry);
1020 2461 hiro
                else
1021 2461 hiro
                        gtk_widget_show(hbox->key_entry);
1022 1 hiro
                gtk_widget_hide(hbox->spin_btn);
1023 1 hiro
                gtk_widget_hide(hbox->label);
1024 2461 hiro
                if (type == PF_COND_HEADER || type == PF_COND_TO_OR_CC) {
1025 2461 hiro
                        gtk_widget_show(hbox->match_menu_in_addr);
1026 2461 hiro
                        gtk_widget_show(hbox->match_menu_not_in_addr);
1027 2461 hiro
                } else {
1028 2461 hiro
                        gtk_widget_hide(hbox->match_menu_in_addr);
1029 2461 hiro
                        gtk_widget_hide(hbox->match_menu_not_in_addr);
1030 2461 hiro
                        if (match_type == PF_MATCH_IN_ADDRESSBOOK ||
1031 2461 hiro
                            match_type == PF_MATCH_NOT_IN_ADDRESSBOOK) {
1032 2461 hiro
                                gtk_option_menu_set_history(GTK_OPTION_MENU(hbox->match_type_optmenu), 0);
1033 2461 hiro
                                gtk_widget_show(hbox->key_entry);
1034 2461 hiro
                        }
1035 2461 hiro
                }
1036 1 hiro
                break;
1037 1 hiro
        case PF_COND_CMD_TEST:
1038 1 hiro
                gtk_widget_hide(hbox->match_type_optmenu);
1039 1 hiro
                gtk_widget_hide(hbox->size_match_optmenu);
1040 1 hiro
                gtk_widget_hide(hbox->age_match_optmenu);
1041 905 hiro
                gtk_widget_hide(hbox->status_match_optmenu);
1042 1 hiro
                gtk_widget_show(hbox->key_entry);
1043 1 hiro
                gtk_widget_hide(hbox->spin_btn);
1044 1 hiro
                gtk_widget_hide(hbox->label);
1045 1 hiro
                break;
1046 1 hiro
        case PF_COND_SIZE:
1047 1 hiro
                gtk_widget_hide(hbox->match_type_optmenu);
1048 1 hiro
                gtk_widget_show(hbox->size_match_optmenu);
1049 1 hiro
                gtk_widget_hide(hbox->age_match_optmenu);
1050 905 hiro
                gtk_widget_hide(hbox->status_match_optmenu);
1051 1 hiro
                gtk_widget_hide(hbox->key_entry);
1052 1 hiro
                gtk_widget_show(hbox->spin_btn);
1053 1 hiro
                gtk_widget_show(hbox->label);
1054 234 hiro
                gtk_label_set_text(GTK_LABEL(hbox->label), _("KB"));
1055 1 hiro
                break;
1056 1 hiro
        case PF_COND_AGE:
1057 1 hiro
                gtk_widget_hide(hbox->match_type_optmenu);
1058 1 hiro
                gtk_widget_hide(hbox->size_match_optmenu);
1059 1 hiro
                gtk_widget_show(hbox->age_match_optmenu);
1060 905 hiro
                gtk_widget_hide(hbox->status_match_optmenu);
1061 1 hiro
                gtk_widget_hide(hbox->key_entry);
1062 1 hiro
                gtk_widget_show(hbox->spin_btn);
1063 234 hiro
                gtk_widget_show(hbox->label);
1064 234 hiro
                gtk_label_set_text(GTK_LABEL(hbox->label), _("day(s)"));
1065 1 hiro
                break;
1066 905 hiro
        case PF_COND_UNREAD:
1067 905 hiro
        case PF_COND_MARK:
1068 905 hiro
        case PF_COND_COLOR_LABEL:
1069 905 hiro
        case PF_COND_MIME:
1070 905 hiro
                gtk_widget_hide(hbox->match_type_optmenu);
1071 905 hiro
                gtk_widget_hide(hbox->size_match_optmenu);
1072 905 hiro
                gtk_widget_hide(hbox->age_match_optmenu);
1073 905 hiro
                gtk_widget_show(hbox->status_match_optmenu);
1074 905 hiro
                gtk_widget_hide(hbox->key_entry);
1075 905 hiro
                gtk_widget_hide(hbox->spin_btn);
1076 905 hiro
                gtk_widget_hide(hbox->label);
1077 905 hiro
                break;
1078 1 hiro
        case PF_COND_ACCOUNT:
1079 1 hiro
                gtk_widget_hide(hbox->match_type_optmenu);
1080 1 hiro
                gtk_widget_hide(hbox->size_match_optmenu);
1081 1 hiro
                gtk_widget_hide(hbox->age_match_optmenu);
1082 905 hiro
                gtk_widget_hide(hbox->status_match_optmenu);
1083 1 hiro
                gtk_widget_hide(hbox->key_entry);
1084 1 hiro
                /* gtk_widget_show(hbox->account_optmenu); */
1085 1 hiro
                gtk_widget_hide(hbox->spin_btn);
1086 1 hiro
                gtk_widget_hide(hbox->label);
1087 1 hiro
                break;
1088 1 hiro
        default:
1089 1 hiro
                break;
1090 1 hiro
        }
1091 1 hiro
}
1092 1 hiro
1093 804 hiro
void prefs_filter_edit_set_action_hbox_widgets(ActionHBox *hbox,
1094 804 hiro
                                               ActionMenuType type)
1095 1 hiro
{
1096 1 hiro
        GtkOptionMenu *type_optmenu = GTK_OPTION_MENU(hbox->action_type_optmenu);
1097 1 hiro
        gint index;
1098 1 hiro
1099 1 hiro
        switch (type) {
1100 1 hiro
        case PF_ACTION_MOVE:
1101 1 hiro
        case PF_ACTION_COPY:
1102 1 hiro
                gtk_widget_show(hbox->label);
1103 1 hiro
                gtk_label_set_text(GTK_LABEL(hbox->label), _("folder:"));
1104 1 hiro
                gtk_widget_show(hbox->folder_entry);
1105 1 hiro
                gtk_widget_show(hbox->folder_sel_btn);
1106 1 hiro
                gtk_widget_hide(hbox->cmd_entry);
1107 1 hiro
                gtk_widget_hide(hbox->address_entry);
1108 1 hiro
                gtk_widget_hide(hbox->clabel_optmenu);
1109 1 hiro
                break;
1110 1 hiro
        case PF_ACTION_NOT_RECEIVE:
1111 1 hiro
        case PF_ACTION_DELETE:
1112 1 hiro
        case PF_ACTION_MARK:
1113 1 hiro
        case PF_ACTION_MARK_READ:
1114 1 hiro
        case PF_ACTION_STOP_EVAL:
1115 1 hiro
                gtk_widget_hide(hbox->label);
1116 1 hiro
                gtk_widget_hide(hbox->folder_entry);
1117 1 hiro
                gtk_widget_hide(hbox->folder_sel_btn);
1118 1 hiro
                gtk_widget_hide(hbox->cmd_entry);
1119 1 hiro
                gtk_widget_hide(hbox->address_entry);
1120 1 hiro
                gtk_widget_hide(hbox->clabel_optmenu);
1121 1 hiro
                break;
1122 1 hiro
        case PF_ACTION_EXEC:
1123 1 hiro
        case PF_ACTION_EXEC_ASYNC:
1124 1 hiro
                gtk_widget_hide(hbox->label);
1125 1 hiro
                gtk_widget_hide(hbox->folder_entry);
1126 1 hiro
                gtk_widget_hide(hbox->folder_sel_btn);
1127 1 hiro
                gtk_widget_show(hbox->cmd_entry);
1128 1 hiro
                gtk_widget_hide(hbox->address_entry);
1129 1 hiro
                gtk_widget_hide(hbox->clabel_optmenu);
1130 1 hiro
                break;
1131 1 hiro
        case PF_ACTION_COLOR_LABEL:
1132 1 hiro
                gtk_widget_hide(hbox->label);
1133 1 hiro
                gtk_widget_hide(hbox->folder_entry);
1134 1 hiro
                gtk_widget_hide(hbox->folder_sel_btn);
1135 1 hiro
                gtk_widget_hide(hbox->cmd_entry);
1136 1 hiro
                gtk_widget_hide(hbox->address_entry);
1137 1 hiro
                gtk_widget_show(hbox->clabel_optmenu);
1138 1 hiro
                break;
1139 1 hiro
        case PF_ACTION_FORWARD:
1140 1 hiro
        case PF_ACTION_FORWARD_AS_ATTACHMENT:
1141 1 hiro
        case PF_ACTION_REDIRECT:
1142 1 hiro
                gtk_widget_show(hbox->label);
1143 1 hiro
                gtk_label_set_text(GTK_LABEL(hbox->label), _("address:"));
1144 1 hiro
                gtk_widget_hide(hbox->folder_entry);
1145 1 hiro
                gtk_widget_hide(hbox->folder_sel_btn);
1146 1 hiro
                gtk_widget_hide(hbox->cmd_entry);
1147 1 hiro
                gtk_widget_show(hbox->address_entry);
1148 1 hiro
                gtk_widget_hide(hbox->clabel_optmenu);
1149 1 hiro
                break;
1150 1 hiro
        default:
1151 1 hiro
                break;
1152 1 hiro
        }
1153 1 hiro
1154 1 hiro
        index = menu_find_option_menu_index(type_optmenu, GINT_TO_POINTER(type),
1155 1 hiro
                                            NULL);
1156 1 hiro
        gtk_option_menu_set_history(type_optmenu, index);
1157 1 hiro
        prefs_filter_edit_set_action_hbox_menus_sensitive();
1158 1 hiro
}
1159 1 hiro
1160 1 hiro
static void prefs_filter_edit_set_action_hbox_menu_sensitive
1161 1 hiro
        (ActionHBox *hbox, ActionMenuType type, gboolean sensitive)
1162 1 hiro
{
1163 1 hiro
        GtkWidget *menuitem;
1164 1 hiro
1165 1 hiro
        menuitem = hbox->action_type_menu_items[type];
1166 1 hiro
        if (menuitem)
1167 1 hiro
                gtk_widget_set_sensitive(menuitem, sensitive);
1168 1 hiro
}
1169 1 hiro
1170 1 hiro
static void prefs_filter_edit_set_action_hbox_menus_sensitive(void)
1171 1 hiro
{
1172 1 hiro
        GSList *cur;
1173 1 hiro
        ActionHBox *cur_hbox;
1174 1 hiro
        ActionMenuType menu_type;
1175 1 hiro
        ActionMenuType cur_type;
1176 1 hiro
        gboolean action_menu_selection[PF_ACTION_NONE];
1177 1 hiro
        gboolean action_menu_sensitive[PF_ACTION_NONE];
1178 1 hiro
1179 1 hiro
        prefs_filter_edit_get_action_hbox_menus_selection
1180 1 hiro
                (action_menu_selection);
1181 1 hiro
1182 1 hiro
        for (cur = rule_edit_window.action_hbox_list; cur != NULL;
1183 1 hiro
             cur = cur->next) {
1184 1 hiro
                cur_hbox = (ActionHBox *)cur->data;
1185 1 hiro
                menu_type = prefs_filter_edit_get_action_hbox_type(cur_hbox);
1186 1 hiro
                for (cur_type = PF_ACTION_MOVE; cur_type < PF_ACTION_NONE;
1187 1 hiro
                     cur_type++)
1188 1 hiro
                        action_menu_sensitive[cur_type] = TRUE;
1189 1 hiro
1190 1 hiro
                for (cur_type = PF_ACTION_MOVE; cur_type < PF_ACTION_NONE;
1191 1 hiro
                     cur_type++) {
1192 1 hiro
                        switch (cur_type) {
1193 1 hiro
                        case PF_ACTION_MOVE:
1194 1 hiro
                        case PF_ACTION_NOT_RECEIVE:
1195 1 hiro
                        case PF_ACTION_DELETE:
1196 1 hiro
                                if (action_menu_selection[cur_type] == TRUE &&
1197 1 hiro
                                    menu_type != cur_type) {
1198 1 hiro
                                        action_menu_sensitive[PF_ACTION_MOVE] = FALSE;
1199 1 hiro
                                        action_menu_sensitive[PF_ACTION_NOT_RECEIVE] = FALSE;
1200 1 hiro
                                        action_menu_sensitive[PF_ACTION_DELETE] = FALSE;
1201 1 hiro
                                }
1202 1 hiro
                                break;
1203 1 hiro
                        case PF_ACTION_MARK:
1204 1 hiro
                        case PF_ACTION_COLOR_LABEL:
1205 1 hiro
                        case PF_ACTION_MARK_READ:
1206 1 hiro
                        case PF_ACTION_STOP_EVAL:
1207 1 hiro
                                if (action_menu_selection[cur_type] == TRUE &&
1208 1 hiro
                                    menu_type != cur_type)
1209 1 hiro
                                        action_menu_sensitive[cur_type] = FALSE;
1210 1 hiro
                                break;
1211 1 hiro
                        default:
1212 1 hiro
                                break;
1213 1 hiro
                        }
1214 1 hiro
                }
1215 1 hiro
1216 1 hiro
                for (cur_type = PF_ACTION_MOVE; cur_type < PF_ACTION_NONE;
1217 1 hiro
                     cur_type++) {
1218 1 hiro
                        prefs_filter_edit_set_action_hbox_menu_sensitive
1219 1 hiro
                                (cur_hbox, cur_type,
1220 1 hiro
                                 action_menu_sensitive[cur_type]);
1221 1 hiro
                }
1222 1 hiro
        }
1223 1 hiro
}
1224 1 hiro
1225 1 hiro
static void prefs_filter_edit_get_action_hbox_menus_selection(gboolean *selection)
1226 1 hiro
{
1227 1 hiro
        GSList *cur;
1228 1 hiro
        ActionHBox *cur_hbox;
1229 1 hiro
        ActionMenuType menu_type;
1230 1 hiro
        ActionMenuType cur_type;
1231 1 hiro
1232 1 hiro
        for (cur_type = PF_ACTION_MOVE; cur_type < PF_ACTION_NONE; cur_type++)
1233 1 hiro
                selection[cur_type] = FALSE;
1234 1 hiro
1235 1 hiro
        for (cur = rule_edit_window.action_hbox_list; cur != NULL;
1236 1 hiro
             cur = cur->next) {
1237 1 hiro
                cur_hbox = (ActionHBox *)cur->data;
1238 1 hiro
                menu_type = prefs_filter_edit_get_action_hbox_type(cur_hbox);
1239 1 hiro
                if (menu_type >= PF_ACTION_MOVE && menu_type < PF_ACTION_NONE)
1240 1 hiro
                        selection[menu_type] = TRUE;
1241 1 hiro
        }
1242 1 hiro
}
1243 1 hiro
1244 1 hiro
static ActionMenuType prefs_filter_edit_get_action_hbox_type(ActionHBox *hbox)
1245 1 hiro
{
1246 1 hiro
        GtkWidget *menuitem;
1247 1 hiro
        ActionMenuType type;
1248 1 hiro
1249 1 hiro
        g_return_val_if_fail(hbox != NULL, PF_ACTION_NONE);
1250 1 hiro
1251 1 hiro
        menuitem = gtk_menu_get_active
1252 1 hiro
                (GTK_MENU(gtk_option_menu_get_menu
1253 1 hiro
                        (GTK_OPTION_MENU(hbox->action_type_optmenu))));
1254 1 hiro
        type = GPOINTER_TO_INT(g_object_get_data(G_OBJECT(menuitem),
1255 1 hiro
                                                 MENU_VAL_ID));
1256 1 hiro
1257 1 hiro
        return type;
1258 1 hiro
}
1259 1 hiro
1260 808 hiro
void prefs_filter_edit_insert_cond_hbox(FilterCondEdit *cond_edit,
1261 808 hiro
                                        CondHBox *hbox, gint pos)
1262 1 hiro
{
1263 808 hiro
        g_return_if_fail(cond_edit != NULL);
1264 1 hiro
        g_return_if_fail(hbox != NULL);
1265 1 hiro
1266 808 hiro
        if (!cond_edit->cond_hbox_list) {
1267 1 hiro
                gtk_widget_set_sensitive(hbox->del_btn, FALSE);
1268 808 hiro
        } else if (cond_edit->cond_hbox_list &&
1269 808 hiro
                   !cond_edit->cond_hbox_list->next) {
1270 1 hiro
                CondHBox *top_hbox =
1271 808 hiro
                        (CondHBox *)cond_edit->cond_hbox_list->data;
1272 1 hiro
                gtk_widget_set_sensitive(top_hbox->del_btn, TRUE);
1273 1 hiro
        }
1274 1 hiro
1275 808 hiro
        gtk_box_pack_start(GTK_BOX(cond_edit->cond_vbox),
1276 1 hiro
                           hbox->hbox, FALSE, FALSE, 0);
1277 1 hiro
        if (pos >= 0) {
1278 808 hiro
                gtk_box_reorder_child(GTK_BOX(cond_edit->cond_vbox),
1279 1 hiro
                                      hbox->hbox, pos);
1280 1 hiro
        }
1281 1 hiro
1282 808 hiro
        cond_edit->cond_hbox_list =
1283 808 hiro
                g_slist_insert(cond_edit->cond_hbox_list, hbox, pos);
1284 1 hiro
}
1285 1 hiro
1286 1 hiro
static void prefs_filter_edit_insert_action_hbox(ActionHBox *hbox, gint pos)
1287 1 hiro
{
1288 1 hiro
        g_return_if_fail(hbox != NULL);
1289 1 hiro
1290 1 hiro
        if (!rule_edit_window.action_hbox_list) {
1291 1 hiro
                gtk_widget_set_sensitive(hbox->del_btn, FALSE);
1292 1 hiro
        } else if (rule_edit_window.action_hbox_list &&
1293 1 hiro
                   !rule_edit_window.action_hbox_list->next) {
1294 1 hiro
                ActionHBox *top_hbox =
1295 1 hiro
                        (ActionHBox *)rule_edit_window.action_hbox_list->data;
1296 1 hiro
                gtk_widget_set_sensitive(top_hbox->del_btn, TRUE);
1297 1 hiro
        }
1298 1 hiro
1299 1 hiro
        gtk_box_pack_start(GTK_BOX(rule_edit_window.action_vbox),
1300 1 hiro
                           hbox->hbox, FALSE, FALSE, 0);
1301 1 hiro
        if (pos >= 0) {
1302 1 hiro
                gtk_box_reorder_child(GTK_BOX(rule_edit_window.action_vbox),
1303 1 hiro
                                      hbox->hbox, pos);
1304 1 hiro
        }
1305 1 hiro
1306 1 hiro
        rule_edit_window.action_hbox_list =
1307 1 hiro
                g_slist_insert(rule_edit_window.action_hbox_list, hbox, pos);
1308 1 hiro
}
1309 1 hiro
1310 808 hiro
static void prefs_filter_edit_remove_cond_hbox(FilterCondEdit *cond_edit,
1311 808 hiro
                                               CondHBox *hbox)
1312 1 hiro
{
1313 808 hiro
        g_return_if_fail(cond_edit != NULL);
1314 1 hiro
        g_return_if_fail(hbox != NULL);
1315 808 hiro
        g_return_if_fail(cond_edit->cond_hbox_list != NULL);
1316 1 hiro
1317 808 hiro
        cond_edit->cond_hbox_list =
1318 808 hiro
                g_slist_remove(cond_edit->cond_hbox_list, hbox);
1319 1 hiro
        gtk_widget_destroy(hbox->hbox);
1320 1 hiro
        g_free(hbox);
1321 1 hiro
1322 808 hiro
        if (cond_edit->cond_hbox_list && !cond_edit->cond_hbox_list->next) {
1323 808 hiro
                hbox = (CondHBox *)cond_edit->cond_hbox_list->data;
1324 1 hiro
                gtk_widget_set_sensitive(hbox->del_btn, FALSE);
1325 1 hiro
        }
1326 1 hiro
}
1327 1 hiro
1328 1 hiro
static void prefs_filter_edit_remove_action_hbox(ActionHBox *hbox)
1329 1 hiro
{
1330 1 hiro
        g_return_if_fail(hbox != NULL);
1331 1 hiro
        g_return_if_fail(rule_edit_window.action_hbox_list != NULL);
1332 1 hiro
1333 1 hiro
        rule_edit_window.action_hbox_list =
1334 1 hiro
                g_slist_remove(rule_edit_window.action_hbox_list, hbox);
1335 1 hiro
        gtk_widget_destroy(hbox->hbox);
1336 1 hiro
        g_free(hbox);
1337 1 hiro
1338 1 hiro
        prefs_filter_edit_set_action_hbox_menus_sensitive();
1339 1 hiro
1340 1 hiro
        if (rule_edit_window.action_hbox_list &&
1341 1 hiro
            !rule_edit_window.action_hbox_list->next) {
1342 1 hiro
                hbox = (ActionHBox *)rule_edit_window.action_hbox_list->data;
1343 1 hiro
                gtk_widget_set_sensitive(hbox->del_btn, FALSE);
1344 1 hiro
        }
1345 1 hiro
}
1346 1 hiro
1347 879 hiro
void prefs_filter_edit_add_rule_cond(FilterCondEdit *cond_edit,
1348 879 hiro
                                     FilterRule *rule)
1349 1 hiro
{
1350 1 hiro
        CondHBox *hbox;
1351 1 hiro
        GSList *cur;
1352 1 hiro
        FilterCond *cond;
1353 1 hiro
1354 1 hiro
        if (!rule || !rule->cond_list) {
1355 808 hiro
                hbox = prefs_filter_edit_cond_hbox_create(cond_edit);
1356 1 hiro
                prefs_filter_edit_set_cond_hbox_widgets(hbox, PF_COND_HEADER);
1357 808 hiro
                prefs_filter_edit_insert_cond_hbox(cond_edit, hbox, -1);
1358 836 hiro
                if (cond_edit->add_hbox)
1359 836 hiro
                        cond_edit->add_hbox(hbox);
1360 1 hiro
                return;
1361 1 hiro
        }
1362 1 hiro
1363 1 hiro
        for (cur = rule->cond_list; cur != NULL; cur = cur->next) {
1364 1 hiro
                cond = (FilterCond *)cur->data;
1365 1 hiro
1366 808 hiro
                hbox = prefs_filter_edit_cond_hbox_create(cond_edit);
1367 1 hiro
                prefs_filter_edit_cond_hbox_set(hbox, cond);
1368 808 hiro
                prefs_filter_edit_insert_cond_hbox(cond_edit, hbox, -1);
1369 836 hiro
                if (cond_edit->add_hbox)
1370 836 hiro
                        cond_edit->add_hbox(hbox);
1371 1 hiro
        }
1372 1 hiro
}
1373 1 hiro
1374 1 hiro
static void prefs_filter_edit_add_rule_action(FilterRule *rule)
1375 1 hiro
{
1376 1 hiro
        ActionHBox *hbox;
1377 1 hiro
        GSList *cur;
1378 1 hiro
1379 1 hiro
        if (!rule || !rule->action_list) {
1380 1 hiro
                hbox = prefs_filter_edit_action_hbox_create();
1381 1 hiro
                prefs_filter_edit_insert_action_hbox(hbox, -1);
1382 1 hiro
                prefs_filter_edit_set_action_hbox_widgets(hbox, PF_ACTION_MOVE);
1383 1 hiro
                return;
1384 1 hiro
        }
1385 1 hiro
1386 1 hiro
        for (cur = rule->action_list; cur != NULL; cur = cur->next) {
1387 1 hiro
                FilterAction *action = (FilterAction *)cur->data;
1388 1 hiro
1389 1 hiro
                hbox = prefs_filter_edit_action_hbox_create();
1390 1 hiro
                prefs_filter_edit_insert_action_hbox(hbox, -1);
1391 1 hiro
                prefs_filter_edit_action_hbox_set(hbox, action);
1392 1 hiro
        }
1393 1 hiro
}
1394 1 hiro
1395 808 hiro
static void prefs_filter_edit_set_cond_header_menu(FilterCondEdit *cond_edit,
1396 808 hiro
                                                   CondHBox *hbox)
1397 1 hiro
{
1398 1 hiro
        GSList *cur;
1399 1 hiro
        GtkWidget *menu;
1400 1 hiro
        GtkWidget *menuitem;
1401 1 hiro
        gint pos = 0;
1402 1 hiro
        GList *child;
1403 1 hiro
1404 1 hiro
        menu = gtk_option_menu_get_menu
1405 1 hiro
                (GTK_OPTION_MENU(hbox->cond_type_optmenu));
1406 1 hiro
1407 1 hiro
        /* destroy header items */
1408 1 hiro
        child = GTK_MENU_SHELL(menu)->children;
1409 1 hiro
        while (child != NULL) {
1410 1 hiro
                GList *next = child->next;
1411 1 hiro
                menuitem = GTK_WIDGET(child->data);
1412 1 hiro
                if (!g_object_get_data(G_OBJECT(menuitem), "header_str"))
1413 1 hiro
                        break;
1414 1 hiro
                gtk_widget_destroy(menuitem);
1415 1 hiro
                child = next;
1416 1 hiro
        }
1417 1 hiro
1418 808 hiro
        for (cur = cond_edit->hdr_list; cur != NULL; cur = cur->next, pos++) {
1419 1 hiro
                Header *header = (Header *)cur->data;
1420 1 hiro
1421 1 hiro
                menuitem = gtk_menu_item_new_with_label(header->name);
1422 1 hiro
                gtk_widget_show(menuitem);
1423 1 hiro
                gtk_menu_insert(GTK_MENU(menu), menuitem, pos);
1424 1 hiro
                g_object_set_data(G_OBJECT(menuitem), MENU_VAL_ID,
1425 1 hiro
                                  GINT_TO_POINTER(PF_COND_HEADER));
1426 1 hiro
                g_object_set_data(G_OBJECT(menuitem), "header_str",
1427 1 hiro
                                  header->name);
1428 1 hiro
                g_signal_connect(G_OBJECT(menuitem), "activate",
1429 1 hiro
                                 G_CALLBACK(prefs_filter_cond_activated_cb),
1430 1 hiro
                                 hbox);
1431 1 hiro
        }
1432 1 hiro
1433 1 hiro
        if (hbox->cur_type == PF_COND_HEADER)
1434 1 hiro
                prefs_filter_edit_cond_hbox_select
1435 1 hiro
                        (hbox, hbox->cur_type, hbox->cur_header_name);
1436 1 hiro
}
1437 1 hiro
1438 808 hiro
static void prefs_filter_edit_activate_cond_header(FilterCondEdit *cond_edit,
1439 808 hiro
                                                   const gchar *header)
1440 1 hiro
{
1441 1 hiro
        gint index;
1442 1 hiro
        CondHBox *hbox;
1443 1 hiro
        GtkWidget *menu;
1444 1 hiro
        GtkWidget *menuitem;
1445 1 hiro
        GList *cur;
1446 1 hiro
        gchar *menu_header;
1447 1 hiro
1448 1 hiro
        g_return_if_fail(header != NULL);
1449 808 hiro
        g_return_if_fail(cond_edit != NULL);
1450 808 hiro
        g_return_if_fail(cond_edit->cond_hbox_list != NULL);
1451 1 hiro
1452 808 hiro
        hbox = (CondHBox *)cond_edit->cond_hbox_list->data;
1453 1 hiro
        menu = gtk_option_menu_get_menu
1454 1 hiro
                (GTK_OPTION_MENU(hbox->cond_type_optmenu));
1455 1 hiro
1456 1 hiro
        for (cur = GTK_MENU_SHELL(menu)->children, index = 0;
1457 1 hiro
             cur != NULL; cur = cur->next, index++) {
1458 1 hiro
                menuitem = GTK_WIDGET(cur->data);
1459 1 hiro
                menu_header = g_object_get_data(G_OBJECT(menuitem),
1460 1 hiro
                                                "header_str");
1461 1 hiro
                if (!menu_header)
1462 1 hiro
                        break;
1463 333 hiro
                if (!g_ascii_strcasecmp(menu_header, header)) {
1464 1 hiro
                        gtk_option_menu_set_history
1465 1 hiro
                                (GTK_OPTION_MENU(hbox->cond_type_optmenu),
1466 1 hiro
                                 index);
1467 1 hiro
                        gtk_menu_item_activate(GTK_MENU_ITEM(menuitem));
1468 1 hiro
                        break;
1469 1 hiro
                }
1470 1 hiro
        }
1471 1 hiro
}
1472 1 hiro
1473 1 hiro
static gint edit_header_list_dialog_deleted(GtkWidget *widget,
1474 1 hiro
                                            GdkEventAny *event, gpointer data)
1475 1 hiro
{
1476 1 hiro
        edit_header_list_dialog.finished = TRUE;
1477 1 hiro
        return TRUE;
1478 1 hiro
}
1479 1 hiro
1480 1 hiro
static gboolean edit_header_list_dialog_key_pressed(GtkWidget *widget,
1481 1 hiro
                                                    GdkEventKey *event,
1482 1 hiro
                                                    gpointer data)
1483 1 hiro
{
1484 1 hiro
        if (event && event->keyval == GDK_Escape)
1485 1 hiro
                edit_header_list_dialog.finished = TRUE;
1486 1 hiro
        return FALSE;
1487 1 hiro
}
1488 1 hiro
1489 1 hiro
static void edit_header_list_dialog_add(void)
1490 1 hiro
{
1491 1 hiro
        GtkCList *clist = GTK_CLIST(edit_header_list_dialog.clist);
1492 1 hiro
        const gchar *text;
1493 1 hiro
        gchar *ctext[1];
1494 1 hiro
        gint row;
1495 1 hiro
        gchar *row_text;
1496 1 hiro
1497 1 hiro
        text = gtk_entry_get_text(GTK_ENTRY(edit_header_list_dialog.entry));
1498 1 hiro
        if (text[0] == '\0') return;
1499 1 hiro
1500 1 hiro
        for (row = 0; gtk_clist_get_text(clist, row, 0, &row_text) != 0;
1501 1 hiro
             row++) {
1502 333 hiro
                if (g_ascii_strcasecmp(row_text, text) == 0) return;
1503 1 hiro
        }
1504 1 hiro
1505 1 hiro
        ctext[0] = (gchar *)text;
1506 1 hiro
        gtk_clist_append(clist, ctext);
1507 1 hiro
}
1508 1 hiro
1509 1 hiro
static void edit_header_list_dialog_delete(void)
1510 1 hiro
{
1511 1 hiro
        GtkCList *clist = GTK_CLIST(edit_header_list_dialog.clist);
1512 1 hiro
        gint row;
1513 1 hiro
1514 1 hiro
        if (!clist->selection) return;
1515 1 hiro
1516 1 hiro
        row = GPOINTER_TO_INT(clist->selection->data);
1517 1 hiro
        gtk_clist_remove(clist, row);
1518 1 hiro
}
1519 1 hiro
1520 1 hiro
static void edit_header_list_dialog_ok(void)
1521 1 hiro
{
1522 1 hiro
        edit_header_list_dialog.finished = TRUE;
1523 1 hiro
        edit_header_list_dialog.ok = TRUE;
1524 1 hiro
}
1525 1 hiro
1526 1 hiro
static void edit_header_list_dialog_cancel(void)
1527 1 hiro
{
1528 1 hiro
        edit_header_list_dialog.finished = TRUE;
1529 1 hiro
}
1530 1 hiro
1531 1 hiro
static void prefs_filter_edit_edit_header_list_dialog_create(void)
1532 1 hiro
{
1533 1 hiro
        GtkWidget *window;
1534 1 hiro
        GtkWidget *vbox;
1535 1 hiro
        GtkWidget *hbox;
1536 1 hiro
1537 1 hiro
        GtkWidget *vbox2;
1538 1 hiro
        GtkWidget *scrwin;
1539 1 hiro
        GtkWidget *clist;
1540 1 hiro
1541 1 hiro
        GtkWidget *entry_hbox;
1542 1 hiro
        GtkWidget *label;
1543 1 hiro
        GtkWidget *entry;
1544 1 hiro
1545 1 hiro
        GtkWidget *btn_vbox;
1546 1 hiro
        GtkWidget *add_btn;
1547 1 hiro
        GtkWidget *del_btn;
1548 1 hiro
1549 1 hiro
        GtkWidget *confirm_area;
1550 1 hiro
        GtkWidget *ok_btn;
1551 1 hiro
        GtkWidget *cancel_btn;
1552 1 hiro
1553 1 hiro
        gchar *title[1];
1554 1 hiro
1555 1 hiro
        window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
1556 1 hiro
        gtk_container_set_border_width(GTK_CONTAINER(window), 8);
1557 1 hiro
        gtk_window_position(GTK_WINDOW(window),GTK_WIN_POS_CENTER);
1558 1 hiro
        gtk_window_set_modal(GTK_WINDOW(window), TRUE);
1559 1 hiro
        gtk_window_set_policy(GTK_WINDOW(window), FALSE, TRUE, FALSE);
1560 1 hiro
        gtk_window_set_title(GTK_WINDOW(window), _("Edit header list"));
1561 1 hiro
1562 1 hiro
        g_signal_connect(G_OBJECT(window), "delete_event",
1563 1 hiro
                         G_CALLBACK(edit_header_list_dialog_deleted), NULL);
1564 1 hiro
        g_signal_connect(G_OBJECT(window), "key_press_event",
1565 1 hiro
                         G_CALLBACK(edit_header_list_dialog_key_pressed), NULL);
1566 1 hiro
1567 1 hiro
        vbox = gtk_vbox_new(FALSE, 6);
1568 1 hiro
        gtk_container_add(GTK_CONTAINER(window), vbox);
1569 1 hiro
1570 1 hiro
        hbox = gtk_hbox_new(FALSE, 8);
1571 1 hiro
        gtk_box_pack_start(GTK_BOX(vbox), hbox, TRUE, TRUE, 0);
1572 1 hiro
1573 1 hiro
        vbox2 = gtk_vbox_new(FALSE, 8);
1574 1 hiro
        gtk_box_pack_start(GTK_BOX(hbox), vbox2, TRUE, TRUE, 0);
1575 1 hiro
1576 1 hiro
        scrwin = gtk_scrolled_window_new(NULL, NULL);
1577 1 hiro
        gtk_widget_set_size_request(scrwin, 120, 160);
1578 1 hiro
        gtk_box_pack_start(GTK_BOX(vbox2), scrwin, TRUE, TRUE, 0);
1579 1 hiro
        gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(scrwin),
1580 1 hiro
                                       GTK_POLICY_AUTOMATIC,
1581 1 hiro
                                       GTK_POLICY_AUTOMATIC);
1582 1 hiro
1583 1 hiro
        title[0] = _("Headers");
1584 1 hiro
        clist = gtk_clist_new_with_titles(1, title);
1585 1 hiro
        gtk_container_add(GTK_CONTAINER(scrwin), clist);
1586 1 hiro
        gtk_clist_set_column_width(GTK_CLIST(clist), 0, 80);
1587 1 hiro
        gtk_clist_set_selection_mode(GTK_CLIST(clist), GTK_SELECTION_BROWSE);
1588 1577 hiro
        gtkut_clist_set_redraw(GTK_CLIST(clist));
1589 1 hiro
        GTK_WIDGET_UNSET_FLAGS(GTK_CLIST(clist)->column[0].button,
1590 1 hiro
                               GTK_CAN_FOCUS);
1591 1 hiro
1592 1 hiro
        entry_hbox = gtk_hbox_new(FALSE, 8);
1593 1 hiro
        gtk_box_pack_start(GTK_BOX(vbox), entry_hbox, FALSE, TRUE, 0);
1594 1 hiro
1595 1 hiro
        label = gtk_label_new(_("Header:"));
1596 1 hiro
        gtk_box_pack_start(GTK_BOX(entry_hbox), label, FALSE, FALSE, 0);
1597 1 hiro
1598 1 hiro
        entry = gtk_entry_new();
1599 1 hiro
        gtk_box_pack_start(GTK_BOX(entry_hbox), entry, TRUE, TRUE, 0);
1600 1 hiro
1601 1 hiro
        btn_vbox = gtk_vbox_new(FALSE, 8);
1602 1 hiro
        gtk_box_pack_start(GTK_BOX(hbox), btn_vbox, FALSE, FALSE, 0);
1603 1 hiro
1604 1 hiro
        add_btn = gtk_button_new_with_label(_("Add"));
1605 1 hiro
        gtk_box_pack_start(GTK_BOX(btn_vbox), add_btn, FALSE, FALSE, 0);
1606 1 hiro
1607 1 hiro
        del_btn = gtk_button_new_with_label(_(" Delete "));
1608 1 hiro
        gtk_box_pack_start(GTK_BOX(btn_vbox), del_btn, FALSE, FALSE, 0);
1609 1 hiro
1610 31 hiro
        gtkut_stock_button_set_create(&confirm_area, &ok_btn, GTK_STOCK_OK,
1611 31 hiro
                                      &cancel_btn, GTK_STOCK_CANCEL,
1612 31 hiro
                                      NULL, NULL);
1613 1 hiro
        gtk_box_pack_end(GTK_BOX(vbox), confirm_area, FALSE, FALSE, 0);
1614 1 hiro
        gtk_widget_grab_default(ok_btn);
1615 1 hiro
1616 1 hiro
        g_signal_connect(G_OBJECT(add_btn), "clicked",
1617 1 hiro
                         G_CALLBACK(edit_header_list_dialog_add), NULL);
1618 1 hiro
        g_signal_connect(G_OBJECT(del_btn), "clicked",
1619 1 hiro
                         G_CALLBACK(edit_header_list_dialog_delete), NULL);
1620 1 hiro
        g_signal_connect(G_OBJECT(ok_btn), "clicked",
1621 1 hiro
                         G_CALLBACK(edit_header_list_dialog_ok), NULL);
1622 1 hiro
        g_signal_connect(G_OBJECT(cancel_btn), "clicked",
1623 1 hiro
                         G_CALLBACK(edit_header_list_dialog_cancel), NULL);
1624 1 hiro
1625 1 hiro
        manage_window_set_transient(GTK_WINDOW(window));
1626 1 hiro
1627 1 hiro
        gtk_widget_show_all(window);
1628 1 hiro
1629 1 hiro
        edit_header_list_dialog.window = window;
1630 1 hiro
        edit_header_list_dialog.clist = clist;
1631 1 hiro
        edit_header_list_dialog.entry = entry;
1632 1 hiro
        edit_header_list_dialog.finished = FALSE;
1633 1 hiro
        edit_header_list_dialog.ok = FALSE;
1634 1 hiro
}
1635 1 hiro
1636 1 hiro
static void prefs_filter_edit_edit_header_list_dialog_set(void)
1637 1 hiro
{
1638 1 hiro
        GtkCList *clist = GTK_CLIST(edit_header_list_dialog.clist);
1639 1 hiro
        GSList *list;
1640 1 hiro
        GSList *cur;
1641 1 hiro
        gchar *text[1];
1642 1 hiro
1643 1 hiro
        gtk_clist_freeze(clist);
1644 1 hiro
1645 1 hiro
        list = prefs_filter_get_user_header_list();
1646 1 hiro
        for (cur = list; cur != NULL; cur = cur->next) {
1647 1 hiro
                Header *header = (Header *)cur->data;
1648 1 hiro
                text[0] = header->name;
1649 1 hiro
                gtk_clist_append(clist, text);
1650 1 hiro
        }
1651 1 hiro
1652 1 hiro
        gtk_clist_thaw(clist);
1653 1 hiro
}
1654 1 hiro
1655 1 hiro
static GSList *prefs_filter_edit_edit_header_list_dialog_get(void)
1656 1 hiro
{
1657 1 hiro
        GtkCList *clist = GTK_CLIST(edit_header_list_dialog.clist);
1658 1 hiro
        gint row;
1659 1 hiro
        gchar *text;
1660 1 hiro
        GSList *list = NULL;
1661 1 hiro
1662 1 hiro
        for (row = 0; gtk_clist_get_text(clist, row, 0, &text) != 0; row++)
1663 1 hiro
                list = procheader_add_header_list(list, text, NULL);
1664 1 hiro
1665 1 hiro
        return list;
1666 1 hiro
}
1667 1 hiro
1668 808 hiro
static void prefs_filter_edit_edit_header_list(FilterCondEdit *cond_edit)
1669 1 hiro
{
1670 1 hiro
        GSList *list;
1671 1 hiro
        GSList *cur;
1672 1 hiro
1673 1 hiro
        prefs_filter_edit_edit_header_list_dialog_create();
1674 1 hiro
        prefs_filter_edit_edit_header_list_dialog_set();
1675 1 hiro
1676 1 hiro
        while (edit_header_list_dialog.finished == FALSE)
1677 1 hiro
                gtk_main_iteration();
1678 1 hiro
1679 1 hiro
        if (edit_header_list_dialog.ok == TRUE) {
1680 1 hiro
                list = prefs_filter_edit_edit_header_list_dialog_get();
1681 1 hiro
                prefs_filter_set_user_header_list(list);
1682 808 hiro
                prefs_filter_edit_update_header_list(cond_edit);
1683 808 hiro
                for (cur = cond_edit->cond_hbox_list; cur != NULL;
1684 1 hiro
                     cur = cur->next) {
1685 1 hiro
                        CondHBox *hbox = (CondHBox *)cur->data;
1686 808 hiro
                        prefs_filter_edit_set_cond_header_menu(cond_edit, hbox);
1687 1 hiro
                }
1688 1532 hiro
                prefs_filter_write_user_header_list();
1689 1 hiro
        }
1690 1 hiro
1691 1 hiro
        gtk_widget_destroy(edit_header_list_dialog.window);
1692 1 hiro
        edit_header_list_dialog.window = NULL;
1693 1 hiro
        edit_header_list_dialog.clist = NULL;
1694 1 hiro
        edit_header_list_dialog.entry = NULL;
1695 1 hiro
        edit_header_list_dialog.finished = FALSE;
1696 1 hiro
        edit_header_list_dialog.ok = FALSE;
1697 1 hiro
}
1698 1 hiro
1699 811 hiro
FilterCond *prefs_filter_edit_cond_hbox_to_cond(CondHBox *hbox,
1700 813 hiro
                                                gboolean case_sens,
1701 811 hiro
                                                gchar **error_msg)
1702 811 hiro
{
1703 811 hiro
        FilterCond *cond = NULL;
1704 811 hiro
        GtkWidget *cond_type_menuitem;
1705 811 hiro
        CondMenuType cond_menu_type;
1706 811 hiro
        MatchMenuType match_menu_type;
1707 811 hiro
        const gchar *header_name;
1708 811 hiro
        const gchar *key_str;
1709 811 hiro
        gint int_value;
1710 811 hiro
        FilterMatchType match_type = FLT_CONTAIN;
1711 811 hiro
        FilterMatchFlag match_flag = 0;
1712 811 hiro
        SizeMatchType size_type;
1713 811 hiro
        AgeMatchType age_type;
1714 905 hiro
        StatusMatchType status_type;
1715 811 hiro
        gchar *error_msg_ = NULL;
1716 811 hiro
1717 811 hiro
        cond_type_menuitem = gtk_menu_get_active
1718 811 hiro
                (GTK_MENU(gtk_option_menu_get_menu
1719 811 hiro
                        (GTK_OPTION_MENU(hbox->cond_type_optmenu))));
1720 811 hiro
        cond_menu_type = GPOINTER_TO_INT
1721 811 hiro
                (g_object_get_data(G_OBJECT(cond_type_menuitem), MENU_VAL_ID));
1722 811 hiro
1723 811 hiro
        match_menu_type = menu_get_option_menu_active_index
1724 811 hiro
                (GTK_OPTION_MENU(hbox->match_type_optmenu));
1725 811 hiro
1726 811 hiro
        key_str = gtk_entry_get_text(GTK_ENTRY(hbox->key_entry));
1727 811 hiro
1728 811 hiro
        switch (match_menu_type) {
1729 811 hiro
        case PF_MATCH_CONTAIN:
1730 811 hiro
                match_type = FLT_CONTAIN;
1731 811 hiro
                break;
1732 811 hiro
        case PF_MATCH_NOT_CONTAIN:
1733 811 hiro
                match_type = FLT_CONTAIN;
1734 811 hiro
                match_flag |= FLT_NOT_MATCH;
1735 811 hiro
                break;
1736 811 hiro
        case PF_MATCH_EQUAL:
1737 811 hiro
                match_type = FLT_EQUAL;
1738 811 hiro
                break;
1739 811 hiro
        case PF_MATCH_NOT_EQUAL:
1740 811 hiro
                match_type = FLT_EQUAL;
1741 811 hiro
                match_flag |= FLT_NOT_MATCH;
1742 811 hiro
                break;
1743 811 hiro
        case PF_MATCH_REGEX:
1744 811 hiro
                match_type = FLT_REGEX;
1745 811 hiro
                break;
1746 811 hiro
        case PF_MATCH_NOT_REGEX:
1747 811 hiro
                match_type = FLT_REGEX;
1748 811 hiro
                match_flag |= FLT_NOT_MATCH;
1749 811 hiro
                break;
1750 2461 hiro
        case PF_MATCH_IN_ADDRESSBOOK:
1751 2461 hiro
                match_type = FLT_IN_ADDRESSBOOK;
1752 2461 hiro
                break;
1753 2461 hiro
        case PF_MATCH_NOT_IN_ADDRESSBOOK:
1754 2461 hiro
                match_type = FLT_IN_ADDRESSBOOK;
1755 2461 hiro
                match_flag |= FLT_NOT_MATCH;
1756 2461 hiro
                break;
1757 811 hiro
        default:
1758 811 hiro
                break;
1759 811 hiro
        }
1760 811 hiro
1761 813 hiro
        if (case_sens)
1762 813 hiro
                match_flag |= FLT_CASE_SENS;
1763 813 hiro
1764 811 hiro
        switch (cond_menu_type) {
1765 811 hiro
        case PF_COND_HEADER:
1766 811 hiro
                header_name = g_object_get_data
1767 811 hiro
                        (G_OBJECT(cond_type_menuitem), "header_str");
1768 811 hiro
                cond = filter_cond_new(FLT_COND_HEADER,
1769 811 hiro
                                       match_type, match_flag,
1770 811 hiro
                                       header_name, key_str);
1771 811 hiro
                break;
1772 811 hiro
        case PF_COND_TO_OR_CC:
1773 811 hiro
                cond = filter_cond_new(FLT_COND_TO_OR_CC, match_type,
1774 811 hiro
                                       match_flag, NULL, key_str);
1775 811 hiro
                break;
1776 811 hiro
        case PF_COND_ANY_HEADER:
1777 811 hiro
                cond = filter_cond_new(FLT_COND_ANY_HEADER, match_type,
1778 811 hiro
                                       match_flag, NULL, key_str);
1779 811 hiro
                break;
1780 811 hiro
        case PF_COND_BODY:
1781 811 hiro
                cond = filter_cond_new(FLT_COND_BODY, match_type,
1782 811 hiro
                                       match_flag, NULL, key_str);
1783 811 hiro
                break;
1784 811 hiro
        case PF_COND_CMD_TEST:
1785 811 hiro
                if (key_str && *key_str)
1786 811 hiro
                        cond = filter_cond_new(FLT_COND_CMD_TEST,
1787 811 hiro
                                               0, 0, NULL, key_str);
1788 811 hiro
                else
1789 811 hiro
                        error_msg_ = _("Command is not specified.");
1790 811 hiro
                break;
1791 811 hiro
        case PF_COND_SIZE:
1792 811 hiro
                size_type = menu_get_option_menu_active_index
1793 811 hiro
                         (GTK_OPTION_MENU(hbox->size_match_optmenu));
1794 811 hiro
                match_flag = size_type == PF_SIZE_LARGER ? 0 : FLT_NOT_MATCH;
1795 811 hiro
                int_value = gtk_spin_button_get_value_as_int
1796 811 hiro
                        (GTK_SPIN_BUTTON(hbox->spin_btn));
1797 811 hiro
                cond = filter_cond_new(FLT_COND_SIZE_GREATER,
1798 811 hiro
                                       0, match_flag, NULL, itos(int_value));
1799 811 hiro
                break;
1800 811 hiro
        case PF_COND_AGE:
1801 811 hiro
                age_type = menu_get_option_menu_active_index
1802 811 hiro
                         (GTK_OPTION_MENU(hbox->age_match_optmenu));
1803 811 hiro
                match_flag = age_type == PF_AGE_LONGER ? 0 : FLT_NOT_MATCH;
1804 811 hiro
                int_value = gtk_spin_button_get_value_as_int
1805 811 hiro
                        (GTK_SPIN_BUTTON(hbox->spin_btn));
1806 811 hiro
                cond = filter_cond_new(FLT_COND_AGE_GREATER,
1807 811 hiro
                                       0, match_flag, NULL, itos(int_value));
1808 811 hiro
                break;
1809 905 hiro
        case PF_COND_UNREAD:
1810 905 hiro
                status_type = menu_get_option_menu_active_index
1811 905 hiro
                        (GTK_OPTION_MENU(hbox->status_match_optmenu));
1812 905 hiro
                match_flag = status_type == PF_STATUS_MATCH ? 0 : FLT_NOT_MATCH;
1813 905 hiro
                cond = filter_cond_new(FLT_COND_UNREAD, 0, match_flag,
1814 905 hiro
                                       NULL, NULL);
1815 905 hiro
                break;
1816 905 hiro
        case PF_COND_MARK:
1817 905 hiro
                status_type = menu_get_option_menu_active_index
1818 905 hiro
                        (GTK_OPTION_MENU(hbox->status_match_optmenu));
1819 905 hiro
                match_flag = status_type == PF_STATUS_MATCH ? 0 : FLT_NOT_MATCH;
1820 905 hiro
                cond = filter_cond_new(FLT_COND_MARK, 0, match_flag,
1821 905 hiro
                                       NULL, NULL);
1822 905 hiro
                break;
1823 905 hiro
        case PF_COND_COLOR_LABEL:
1824 905 hiro
                status_type = menu_get_option_menu_active_index
1825 905 hiro
                        (GTK_OPTION_MENU(hbox->status_match_optmenu));
1826 905 hiro
                match_flag = status_type == PF_STATUS_MATCH ? 0 : FLT_NOT_MATCH;
1827 905 hiro
                cond = filter_cond_new(FLT_COND_COLOR_LABEL, 0, match_flag,
1828 905 hiro
                                       NULL, NULL);
1829 905 hiro
                break;
1830 905 hiro
        case PF_COND_MIME:
1831 905 hiro
                status_type = menu_get_option_menu_active_index
1832 905 hiro
                        (GTK_OPTION_MENU(hbox->status_match_optmenu));
1833 905 hiro
                match_flag = status_type == PF_STATUS_MATCH ? 0 : FLT_NOT_MATCH;
1834 905 hiro
                cond = filter_cond_new(FLT_COND_MIME, 0, match_flag,
1835 905 hiro
                                       NULL, NULL);
1836 905 hiro
                break;
1837 811 hiro
        case PF_COND_ACCOUNT:
1838 811 hiro
        case PF_COND_EDIT_HEADER:
1839 811 hiro
        default:
1840 811 hiro
                break;
1841 811 hiro
        }
1842 811 hiro
1843 811 hiro
        if (error_msg)
1844 811 hiro
                *error_msg = error_msg_;
1845 811 hiro
1846 811 hiro
        return cond;
1847 811 hiro
}
1848 811 hiro
1849 811 hiro
FilterAction *prefs_filter_edit_action_hbox_to_action(ActionHBox *hbox,
1850 811 hiro
                                                      gchar **error_msg)
1851 811 hiro
{
1852 811 hiro
        FilterAction *action = NULL;
1853 811 hiro
        ActionMenuType action_menu_type;
1854 811 hiro
        const gchar *str;
1855 811 hiro
        guint color;
1856 811 hiro
        gchar *error_msg_ = NULL;
1857 811 hiro
1858 811 hiro
        action_menu_type = prefs_filter_edit_get_action_hbox_type(hbox);
1859 811 hiro
1860 811 hiro
        switch (action_menu_type) {
1861 811 hiro
        case PF_ACTION_MOVE:
1862 811 hiro
                str = gtk_entry_get_text(GTK_ENTRY(hbox->folder_entry));
1863 811 hiro
                if (str && *str)
1864 811 hiro
                        action = filter_action_new(FLT_ACTION_MOVE,
1865 811 hiro
                                                   str);
1866 811 hiro
                else
1867 811 hiro
                        error_msg_ = _("Destination folder is not specified.");
1868 811 hiro
                break;
1869 811 hiro
        case PF_ACTION_COPY:
1870 811 hiro
                str = gtk_entry_get_text(GTK_ENTRY(hbox->folder_entry));
1871 811 hiro
                if (str && *str)
1872 811 hiro
                        action = filter_action_new(FLT_ACTION_COPY, str);
1873 811 hiro
                else
1874 811 hiro
                        error_msg_ = _("Destination folder is not specified.");
1875 811 hiro
                break;
1876 811 hiro
        case PF_ACTION_NOT_RECEIVE:
1877 811 hiro
                action = filter_action_new(FLT_ACTION_NOT_RECEIVE, NULL);
1878 811 hiro
                break;
1879 811 hiro
        case PF_ACTION_DELETE:
1880 811 hiro
                action = filter_action_new(FLT_ACTION_DELETE, NULL);
1881 811 hiro
                break;
1882 811 hiro
        case PF_ACTION_EXEC:
1883 811 hiro
                str = gtk_entry_get_text(GTK_ENTRY(hbox->cmd_entry));
1884 811 hiro
                if (str && *str)
1885 811 hiro
                        action = filter_action_new(FLT_ACTION_EXEC, str);
1886 811 hiro
                else
1887 811 hiro
                        error_msg_ = _("Command is not specified.");
1888 811 hiro
                break;
1889 811 hiro
        case PF_ACTION_EXEC_ASYNC:
1890 811 hiro
                str = gtk_entry_get_text(GTK_ENTRY(hbox->cmd_entry));
1891 811 hiro
                if (str && *str)
1892 811 hiro
                        action = filter_action_new(FLT_ACTION_EXEC_ASYNC, str);
1893 811 hiro
                else
1894 811 hiro
                        error_msg_ = _("Command is not specified.");
1895 811 hiro
                break;
1896 811 hiro
        case PF_ACTION_MARK:
1897 811 hiro
                action = filter_action_new(FLT_ACTION_MARK, NULL);
1898 811 hiro
                break;
1899 811 hiro
        case PF_ACTION_COLOR_LABEL:
1900 811 hiro
                color = colorlabel_get_color_menu_active_item
1901 811 hiro
                        (gtk_option_menu_get_menu
1902 811 hiro
                         (GTK_OPTION_MENU(hbox->clabel_optmenu)));
1903 811 hiro
                action = filter_action_new(FLT_ACTION_COLOR_LABEL,
1904 811 hiro
                                           itos(color));
1905 811 hiro
                break;
1906 811 hiro
        case PF_ACTION_MARK_READ:
1907 811 hiro
                action = filter_action_new(FLT_ACTION_MARK_READ, NULL);
1908 811 hiro
                break;
1909 811 hiro
        case PF_ACTION_FORWARD:
1910 811 hiro
        case PF_ACTION_FORWARD_AS_ATTACHMENT:
1911 811 hiro
        case PF_ACTION_REDIRECT:
1912 811 hiro
                break;
1913 811 hiro
        case PF_ACTION_STOP_EVAL:
1914 811 hiro
                action = filter_action_new(FLT_ACTION_STOP_EVAL, NULL);
1915 811 hiro
                break;
1916 811 hiro
        case PF_ACTION_SEPARATOR:
1917 811 hiro
        default:
1918 811 hiro
                break;
1919 811 hiro
        }
1920 811 hiro
1921 811 hiro
        if (error_msg)
1922 811 hiro
                *error_msg = error_msg_;
1923 811 hiro
1924 811 hiro
        return action;
1925 811 hiro
}
1926 811 hiro
1927 874 hiro
GSList *prefs_filter_edit_cond_edit_to_list(FilterCondEdit *cond_edit,
1928 874 hiro
                                            gboolean case_sens)
1929 874 hiro
{
1930 874 hiro
        GSList *cur;
1931 874 hiro
        FilterCond *cond;
1932 874 hiro
        GSList *cond_list = NULL;
1933 874 hiro
1934 874 hiro
        for (cur = cond_edit->cond_hbox_list; cur != NULL; cur = cur->next) {
1935 874 hiro
                CondHBox *hbox = (CondHBox *)cur->data;
1936 874 hiro
                gchar *error_msg;
1937 874 hiro
1938 874 hiro
                cond = prefs_filter_edit_cond_hbox_to_cond(hbox, case_sens,
1939 874 hiro
                                                           &error_msg);
1940 874 hiro
                if (cond) {
1941 874 hiro
                        cond_list = g_slist_append(cond_list, cond);
1942 874 hiro
                } else {
1943 874 hiro
                        if (!error_msg)
1944 874 hiro
                                error_msg = _("Invalid condition exists.");
1945 874 hiro
                        alertpanel_error("%s", error_msg);
1946 874 hiro
                        filter_cond_list_free(cond_list);
1947 874 hiro
                        return NULL;
1948 874 hiro
                }
1949 874 hiro
        }
1950 874 hiro
1951 874 hiro
        return cond_list;
1952 874 hiro
}
1953 874 hiro
1954 1 hiro
static FilterRule *prefs_filter_edit_dialog_to_rule(void)
1955 1 hiro
{
1956 1 hiro
        FilterRule *rule = NULL;
1957 1 hiro
        GSList *cur;
1958 1 hiro
        const gchar *rule_name;
1959 2776 hiro
        FilterBoolOp bool_op;
1960 1 hiro
        GSList *cond_list = NULL;
1961 1 hiro
        GSList *action_list = NULL;
1962 1 hiro
        GtkWidget *bool_op_menuitem;
1963 1 hiro
        gchar *error_msg = NULL;
1964 1 hiro
1965 1 hiro
        rule_name = gtk_entry_get_text(GTK_ENTRY(rule_edit_window.name_entry));
1966 1 hiro
        if (!rule_name || *rule_name == '\0') {
1967 1 hiro
                error_msg = _("Rule name is not specified.");
1968 1 hiro
                goto error;
1969 1 hiro
        }
1970 1 hiro
1971 1 hiro
        bool_op_menuitem = gtk_menu_get_active
1972 1 hiro
                (GTK_MENU(gtk_option_menu_get_menu
1973 1 hiro
                        (GTK_OPTION_MENU(rule_edit_window.bool_op_optmenu))));
1974 1 hiro
        bool_op = GPOINTER_TO_INT
1975 1 hiro
                (g_object_get_data(G_OBJECT(bool_op_menuitem), MENU_VAL_ID));
1976 1 hiro
1977 874 hiro
        cond_list = prefs_filter_edit_cond_edit_to_list
1978 874 hiro
                (&rule_edit_window.cond_edit, FALSE);
1979 874 hiro
        if (!cond_list)
1980 874 hiro
                return NULL;
1981 1 hiro
1982 1 hiro
        for (cur = rule_edit_window.action_hbox_list; cur != NULL;
1983 1 hiro
             cur = cur->next) {
1984 1 hiro
                ActionHBox *hbox = (ActionHBox *)cur->data;
1985 811 hiro
                FilterAction *action;
1986 1 hiro
1987 811 hiro
                action = prefs_filter_edit_action_hbox_to_action(hbox,
1988 811 hiro
                                                                 &error_msg);
1989 1 hiro
                if (action)
1990 1 hiro
                        action_list = g_slist_append(action_list, action);
1991 1 hiro
                else {
1992 1 hiro
                        if (!error_msg)
1993 1 hiro
                                error_msg = _("Invalid action exists.");
1994 1 hiro
                        goto error;
1995 1 hiro
                }
1996 1 hiro
        }
1997 1 hiro
1998 1 hiro
error:
1999 1 hiro
        if (error_msg || !cond_list || !action_list) {
2000 1 hiro
                if (!error_msg) {
2001 1 hiro
                        if (!cond_list)
2002 1 hiro
                                error_msg = _("Condition not exist.");
2003 1 hiro
                        else
2004 1 hiro
                                error_msg = _("Action not exist.");
2005 1 hiro
                }
2006 1 hiro
                alertpanel_error("%s", error_msg);
2007 1 hiro
                if (cond_list)
2008 1 hiro
                        filter_cond_list_free(cond_list);
2009 1 hiro
                if (action_list)
2010 1 hiro
                        filter_action_list_free(action_list);
2011 1 hiro
                return NULL;
2012 1 hiro
        }
2013 1 hiro
2014 1 hiro
        rule = filter_rule_new(rule_name, bool_op, cond_list, action_list);
2015 1 hiro
2016 1 hiro
        return rule;
2017 1 hiro
}
2018 1 hiro
2019 1 hiro
/* callback functions */
2020 1 hiro
2021 1 hiro
static gint prefs_filter_edit_deleted(GtkWidget *widget, GdkEventAny *event,
2022 1 hiro
                                      gpointer data)
2023 1 hiro
{
2024 1 hiro
        prefs_filter_edit_cancel();
2025 1 hiro
        return TRUE;
2026 1 hiro
}
2027 1 hiro
2028 1 hiro
static gboolean prefs_filter_edit_key_pressed(GtkWidget *widget,
2029 1 hiro
                                              GdkEventKey *event,
2030 1 hiro
                                              gpointer data)
2031 1 hiro
{
2032 1 hiro
        if (event && event->keyval == GDK_Escape)
2033 1 hiro
                prefs_filter_edit_cancel();
2034 1 hiro
        return FALSE;
2035 1 hiro
}
2036 1 hiro
2037 1 hiro
static void prefs_filter_edit_ok(void)
2038 1 hiro
{
2039 1 hiro
        FilterRule *rule;
2040 1 hiro
2041 1 hiro
        rule = prefs_filter_edit_dialog_to_rule();
2042 1 hiro
        if (rule) {
2043 1 hiro
                rule_edit_window.new_rule = rule;
2044 1 hiro
                rule_edit_window.edit_finished = TRUE;
2045 1 hiro
        }
2046 1 hiro
}
2047 1 hiro
2048 1 hiro
static void prefs_filter_edit_cancel(void)
2049 1 hiro
{
2050 1 hiro
        rule_edit_window.new_rule = NULL;
2051 1 hiro
        rule_edit_window.edit_finished = TRUE;
2052 1 hiro
}
2053 1 hiro
2054 1 hiro
static void prefs_filter_cond_activated_cb(GtkWidget *widget, gpointer data)
2055 1 hiro
{
2056 1 hiro
        CondHBox *hbox = (CondHBox *)data;
2057 808 hiro
        FilterCondEdit *cond_edit = hbox->cond_edit;
2058 1 hiro
        CondMenuType type;
2059 1 hiro
2060 1 hiro
        type = GPOINTER_TO_INT
2061 1 hiro
                (g_object_get_data(G_OBJECT(widget), MENU_VAL_ID));
2062 1 hiro
2063 1 hiro
        if (type == PF_COND_EDIT_HEADER) {
2064 808 hiro
                prefs_filter_edit_edit_header_list(cond_edit);
2065 1 hiro
                prefs_filter_edit_cond_hbox_select
2066 1 hiro
                        (hbox, hbox->cur_type, hbox->cur_header_name);
2067 1 hiro
        } else {
2068 1 hiro
                hbox->cur_type = type;
2069 1 hiro
                g_free(hbox->cur_header_name);
2070 1 hiro
                hbox->cur_header_name = NULL;
2071 1 hiro
2072 1 hiro
                prefs_filter_edit_set_cond_hbox_widgets(hbox, type);
2073 1 hiro
                if (type == PF_COND_HEADER) {
2074 1 hiro
                        gchar *header_name;
2075 1 hiro
                        gchar *header_field;
2076 1 hiro
2077 1 hiro
                        header_name = (gchar *)g_object_get_data
2078 1 hiro
                                (G_OBJECT(widget), "header_str");
2079 1 hiro
                        header_field = prefs_filter_get_msg_header_field
2080 1 hiro
                                (header_name);
2081 1 hiro
                        if (header_field)
2082 1 hiro
                                gtk_entry_set_text(GTK_ENTRY(hbox->key_entry),
2083 1 hiro
                                                   header_field);
2084 1 hiro
                        hbox->cur_header_name = g_strdup(header_name);
2085 1 hiro
                }
2086 1 hiro
        }
2087 1 hiro
}
2088 1 hiro
2089 2461 hiro
static void prefs_filter_match_activated_cb(GtkWidget *widget, gpointer data)
2090 2461 hiro
{
2091 2461 hiro
        CondHBox *hbox = (CondHBox *)data;
2092 2461 hiro
        GtkWidget *cond_type_menuitem;
2093 2461 hiro
        CondMenuType cond_menu_type;
2094 2461 hiro
2095 2461 hiro
        cond_type_menuitem = gtk_menu_get_active
2096 2461 hiro
                (GTK_MENU(gtk_option_menu_get_menu
2097 2461 hiro
                        (GTK_OPTION_MENU(hbox->cond_type_optmenu))));
2098 2461 hiro
        cond_menu_type = GPOINTER_TO_INT
2099 2461 hiro
                (g_object_get_data(G_OBJECT(cond_type_menuitem), MENU_VAL_ID));
2100 2461 hiro
2101 2461 hiro
        prefs_filter_edit_set_cond_hbox_widgets(hbox, cond_menu_type);
2102 2461 hiro
}
2103 2461 hiro
2104 1 hiro
static void prefs_filter_action_activated_cb(GtkWidget *widget, gpointer data)
2105 1 hiro
{
2106 1 hiro
        ActionHBox *hbox = (ActionHBox *)data;
2107 1 hiro
        ActionMenuType type;
2108 1 hiro
2109 1 hiro
        type = GPOINTER_TO_INT
2110 1 hiro
                (g_object_get_data(G_OBJECT(widget), MENU_VAL_ID));
2111 1 hiro
        prefs_filter_edit_set_action_hbox_widgets(hbox, type);
2112 1 hiro
}
2113 1 hiro
2114 1 hiro
static void prefs_filter_action_select_dest_cb(GtkWidget *widget, gpointer data)
2115 1 hiro
{
2116 1 hiro
        ActionHBox *hbox = (ActionHBox *)data;
2117 1 hiro
2118 1 hiro
        FolderItem *dest;
2119 1 hiro
        gchar *id;
2120 1 hiro
2121 1 hiro
        dest = foldersel_folder_sel(NULL, FOLDER_SEL_COPY, NULL);
2122 1 hiro
        if (!dest || !dest->path) return;
2123 1 hiro
2124 1 hiro
        id = folder_item_get_identifier(dest);
2125 1 hiro
        if (id) {
2126 1 hiro
                gtk_entry_set_text(GTK_ENTRY(hbox->folder_entry), id);
2127 1 hiro
                g_free(id);
2128 1 hiro
        }
2129 1 hiro
}
2130 1 hiro
2131 1 hiro
static void prefs_filter_cond_del_cb(GtkWidget *widget, gpointer data)
2132 1 hiro
{
2133 1 hiro
        CondHBox *hbox = (CondHBox *)data;
2134 808 hiro
        FilterCondEdit *cond_edit = hbox->cond_edit;
2135 1 hiro
2136 808 hiro
        if (cond_edit->cond_hbox_list && cond_edit->cond_hbox_list->next)
2137 808 hiro
                prefs_filter_edit_remove_cond_hbox(cond_edit, hbox);
2138 1 hiro
}
2139 1 hiro
2140 1 hiro
static void prefs_filter_cond_add_cb(GtkWidget *widget, gpointer data)
2141 1 hiro
{
2142 1 hiro
        CondHBox *hbox = (CondHBox *)data;
2143 1 hiro
        CondHBox *new_hbox;
2144 808 hiro
        FilterCondEdit *cond_edit = hbox->cond_edit;
2145 1 hiro
        gint index;
2146 1 hiro
2147 808 hiro
        index = g_slist_index(cond_edit->cond_hbox_list, hbox);
2148 1 hiro
        g_return_if_fail(index >= 0);
2149 808 hiro
        new_hbox = prefs_filter_edit_cond_hbox_create(cond_edit);
2150 1 hiro
        prefs_filter_edit_set_cond_hbox_widgets(new_hbox, PF_COND_HEADER);
2151 808 hiro
        prefs_filter_edit_insert_cond_hbox(cond_edit, new_hbox, index + 1);
2152 836 hiro
        if (cond_edit->add_hbox)
2153 836 hiro
                cond_edit->add_hbox(new_hbox);
2154 1 hiro
}
2155 1 hiro
2156 1 hiro
static void prefs_filter_action_del_cb(GtkWidget *widget, gpointer data)
2157 1 hiro
{
2158 1 hiro
        ActionHBox *hbox = (ActionHBox *)data;
2159 1 hiro
2160 1 hiro
        if (rule_edit_window.action_hbox_list &&
2161 1 hiro
            rule_edit_window.action_hbox_list->next)
2162 1 hiro
                prefs_filter_edit_remove_action_hbox(hbox);
2163 1 hiro
}
2164 1 hiro
2165 1 hiro
static void prefs_filter_action_add_cb(GtkWidget *widget, gpointer data)
2166 1 hiro
{
2167 1 hiro
        ActionHBox *hbox = (ActionHBox *)data;
2168 1 hiro
        ActionHBox *new_hbox;
2169 1 hiro
        gboolean action_menu_selection[PF_ACTION_NONE];
2170 1 hiro
        gint index;
2171 1 hiro
2172 1 hiro
        prefs_filter_edit_get_action_hbox_menus_selection(action_menu_selection);
2173 1 hiro
2174 1 hiro
        index = g_slist_index(rule_edit_window.action_hbox_list, hbox);
2175 1 hiro
        g_return_if_fail(index >= 0);
2176 1 hiro
        new_hbox = prefs_filter_edit_action_hbox_create();
2177 1 hiro
        prefs_filter_edit_insert_action_hbox(new_hbox, index + 1);
2178 1 hiro
        if (action_menu_selection[PF_ACTION_MOVE] == TRUE ||
2179 1 hiro
            action_menu_selection[PF_ACTION_NOT_RECEIVE] == TRUE ||
2180 1 hiro
            action_menu_selection[PF_ACTION_DELETE] == TRUE)
2181 1 hiro
                prefs_filter_edit_set_action_hbox_widgets(new_hbox,
2182 1 hiro
                                                          PF_ACTION_COPY);
2183 1 hiro
        else
2184 1 hiro
                prefs_filter_edit_set_action_hbox_widgets(new_hbox,
2185 1 hiro
                                                          PF_ACTION_MOVE);
2186 1 hiro
}