5c47894e97621024abc8d8bf1b6b7fa7f5423199
[claws.git] / src / prefs_folder_item.c
1 /*
2  * Sylpheed -- a GTK+ based, lightweight, and fast e-mail client
3  * Copyright (C) 1999-2007 Hiroyuki Yamamoto and the Claws Mail team
4  *
5  * This program is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License as published by
7  * the Free Software Foundation; either version 3 of the License, or
8  * (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program. If not, see <http://www.gnu.org/licenses/>.
17  * 
18  */
19
20 /* alfons - all folder item specific settings should migrate into 
21  * folderlist.xml!!! the old folderitemrc file will only serve for a few 
22  * versions (for compatibility) */
23
24 #ifdef HAVE_CONFIG_H
25 #  include "config.h"
26 #endif
27
28 #include "defs.h"
29
30 #include <glib.h>
31 #include <glib/gi18n.h>
32 #include "folder.h"
33 #include "prefs_folder_item.h"
34 #include "folderview.h"
35 #include "folder.h"
36 #include "summaryview.h"
37 #include "menu.h"
38 #include "account.h"
39 #include "prefs_gtk.h"
40 #include "manage_window.h"
41 #include "utils.h"
42 #include "addr_compl.h"
43 #include "prefs_common.h"
44 #include "gtkutils.h"
45 #include "filtering.h"
46 #include "folder_item_prefs.h"
47 #include "gtk/colorsel.h"
48 #include "string_match.h"
49 #include "quote_fmt.h"
50
51 #if USE_ASPELL
52 #include "gtkaspell.h"
53 #endif
54
55 #define ASSIGN_STRING(string, value) \
56         { \
57                 g_free(string); \
58                 string = (value); \
59         }
60
61 typedef struct _FolderItemGeneralPage FolderItemGeneralPage;
62 typedef struct _FolderItemComposePage FolderItemComposePage;
63 typedef struct _FolderItemTemplatesPage FolderItemTemplatesPage;
64 static gboolean can_save = TRUE;
65
66 struct _FolderItemGeneralPage
67 {
68         PrefsPage page;
69
70         FolderItem *item;
71
72         GtkWidget *table;
73         GtkWidget *no_save_warning;
74         GtkWidget *folder_type;
75         GtkWidget *checkbtn_simplify_subject;
76         GtkWidget *entry_simplify_subject;
77         GtkWidget *entry_regexp_test_string;
78         GtkWidget *entry_regexp_test_result;
79         GtkWidget *checkbtn_folder_chmod;
80         GtkWidget *entry_folder_chmod;
81         GtkWidget *folder_color_btn;
82         GtkWidget *checkbtn_enable_processing;
83         GtkWidget *checkbtn_newmailcheck;
84         GtkWidget *checkbtn_offlinesync;
85         GtkWidget *label_offlinesync;
86         GtkWidget *entry_offlinesync;
87         GtkWidget *label_end_offlinesync;
88         GtkWidget *checkbtn_remove_old_offlinesync;
89         
90         /* apply to sub folders */
91         GtkWidget *simplify_subject_rec_checkbtn;
92         GtkWidget *folder_chmod_rec_checkbtn;
93         GtkWidget *folder_color_rec_checkbtn;
94         GtkWidget *enable_processing_rec_checkbtn;
95         GtkWidget *newmailcheck_rec_checkbtn;
96         GtkWidget *offlinesync_rec_checkbtn;
97
98         gint       folder_color;
99 };
100
101 struct _FolderItemComposePage
102 {
103         PrefsPage page;
104
105         FolderItem *item;
106
107         GtkWidget *window;
108         GtkWidget *table;
109         GtkWidget *no_save_warning;
110         GtkWidget *checkbtn_request_return_receipt;
111         GtkWidget *checkbtn_save_copy_to_folder;
112         GtkWidget *checkbtn_default_to;
113         GtkWidget *entry_default_to;
114         GtkWidget *checkbtn_default_reply_to;
115         GtkWidget *entry_default_reply_to;
116         GtkWidget *checkbtn_enable_default_account;
117         GtkWidget *optmenu_default_account;
118 #if USE_ASPELL
119         GtkWidget *checkbtn_enable_default_dictionary;
120         GtkWidget *checkbtn_enable_default_alt_dictionary;
121         GtkWidget *optmenu_default_dictionary;
122         GtkWidget *optmenu_default_alt_dictionary;
123 #endif
124
125         /* apply to sub folders */
126         GtkWidget *request_return_receipt_rec_checkbtn;
127         GtkWidget *save_copy_to_folder_rec_checkbtn;
128         GtkWidget *default_to_rec_checkbtn;
129         GtkWidget *default_reply_to_rec_checkbtn;
130         GtkWidget *default_account_rec_checkbtn;
131 #if USE_ASPELL
132         GtkWidget *default_dictionary_rec_checkbtn;
133         GtkWidget *default_alt_dictionary_rec_checkbtn;
134 #endif
135 };
136
137 struct _FolderItemTemplatesPage
138 {
139         PrefsPage page;
140
141         FolderItem *item;
142
143         GtkWidget *window;
144         GtkWidget *table;
145         GtkWidget *checkbtn_compose_with_format;
146         GtkWidget *compose_subject_format;
147         GtkWidget *compose_body_format;
148         GtkWidget *checkbtn_reply_with_format;
149         GtkWidget *reply_quotemark;
150         GtkWidget *reply_body_format;
151         GtkWidget *checkbtn_forward_with_format;
152         GtkWidget *forward_quotemark;
153         GtkWidget *forward_body_format;
154
155         /* apply to sub folders */
156         GtkWidget *new_msg_format_rec_checkbtn;
157         GtkWidget *reply_format_rec_checkbtn;
158         GtkWidget *forward_format_rec_checkbtn;
159 };
160
161
162 static void general_save_folder_prefs(FolderItem *folder, FolderItemGeneralPage *page);
163 static void compose_save_folder_prefs(FolderItem *folder, FolderItemComposePage *page);
164 static void templates_save_folder_prefs(FolderItem *folder, FolderItemTemplatesPage *page);
165
166 static gboolean general_save_recurse_func(GNode *node, gpointer data);
167 static gboolean compose_save_recurse_func(GNode *node, gpointer data);
168 static gboolean templates_save_recurse_func(GNode *node, gpointer data);
169
170 static gint prefs_folder_item_chmod_mode                (gchar *folder_chmod);
171
172 static void folder_color_set_dialog(GtkWidget *widget, gpointer data);
173 static void folder_regexp_test_cb(GtkWidget *widget, gpointer data);
174 static void folder_regexp_set_subject_example_cb(GtkWidget *widget, gpointer data);
175
176 #define SAFE_STRING(str) \
177         (str) ? (str) : ""
178
179 static void prefs_folder_item_general_create_widget_func(PrefsPage * page_,
180                                                    GtkWindow * window,
181                                                    gpointer data)
182 {
183         FolderItemGeneralPage *page = (FolderItemGeneralPage *) page_;
184         FolderItem *item = (FolderItem *) data;
185         guint rowcount;
186
187         GtkWidget *table;
188         GtkWidget *hbox, *hbox2, *hbox_spc;
189         GtkWidget *label;
190         
191         GtkWidget *folder_type_menu;
192         GtkWidget *folder_type;
193         GtkWidget *dummy_checkbtn;
194         GtkWidget *menuitem;
195         SpecialFolderItemType type;
196         
197         GtkWidget *no_save_warning = NULL;
198         GtkWidget *checkbtn_simplify_subject;
199         GtkWidget *entry_simplify_subject;
200         GtkWidget *hbox_regexp;
201         GtkWidget *label_regexp_test;
202         GtkWidget *entry_regexp_test_string;
203         GtkWidget *left_arrow;
204         GtkWidget *entry_regexp_test_result;
205
206         GtkWidget *checkbtn_folder_chmod;
207         GtkWidget *entry_folder_chmod;
208         GtkWidget *folder_color;
209         GtkWidget *folder_color_btn;
210         GtkWidget *checkbtn_enable_processing;
211         GtkWidget *checkbtn_newmailcheck;
212         GtkWidget *checkbtn_offlinesync;
213         GtkWidget *label_offlinesync;
214         GtkWidget *entry_offlinesync;
215         GtkWidget *label_end_offlinesync;
216         GtkWidget *checkbtn_remove_old_offlinesync;
217
218         GtkWidget *simplify_subject_rec_checkbtn;
219         GtkWidget *folder_chmod_rec_checkbtn;
220         GtkWidget *folder_color_rec_checkbtn;
221         GtkWidget *enable_processing_rec_checkbtn;
222         GtkWidget *newmailcheck_rec_checkbtn;
223         GtkWidget *offlinesync_rec_checkbtn;
224         GtkTooltips *tooltips;
225
226         tooltips = gtk_tooltips_new();
227         page->item         = item;
228
229         /* Table */
230         table = gtk_table_new(9, 4, FALSE);
231         gtk_container_set_border_width (GTK_CONTAINER (table), VBOX_BORDER);
232         gtk_table_set_row_spacings(GTK_TABLE(table), 4);
233         gtk_table_set_col_spacings(GTK_TABLE(table), 4);
234         rowcount = 0;
235
236         if (!can_save) {
237                 no_save_warning = gtk_label_new(
238                         _("<i>These preferences will not be saved as this folder "
239                         "is a top-level one. However you can use them to set them "
240                         "to the whole mailbox tree using \"Apply to subfolders\".</i>"));
241                 gtk_label_set_use_markup(GTK_LABEL(no_save_warning), TRUE);
242                 gtk_label_set_line_wrap(GTK_LABEL(no_save_warning), TRUE);
243                 gtk_misc_set_alignment(GTK_MISC(no_save_warning), 0.0, 0.5);
244                 gtk_table_attach(GTK_TABLE(table), no_save_warning, 0, 4,
245                          rowcount, rowcount + 1, GTK_FILL, 0, 0, 0);
246                 rowcount++;
247         }
248         
249         /* Apply to subfolders */
250         label = gtk_label_new(_("Apply to\nsubfolders"));
251         gtk_misc_set_alignment(GTK_MISC(label), 0.5, 0.5);
252         gtk_table_attach(GTK_TABLE(table), label, 3, 4,
253                          rowcount, rowcount + 1, GTK_SHRINK, GTK_SHRINK, 0, 0);
254         rowcount++;
255
256         /* folder_type */
257         folder_type = gtk_option_menu_new ();
258         gtk_widget_show (folder_type);
259
260         type = F_NORMAL;
261         if (item->stype == F_INBOX)
262                 type = F_INBOX;
263         else if (folder_has_parent_of_type(item, F_OUTBOX))
264                 type = F_OUTBOX;
265         else if (folder_has_parent_of_type(item, F_DRAFT))
266                 type = F_DRAFT;
267         else if (folder_has_parent_of_type(item, F_QUEUE))
268                 type = F_QUEUE;
269         else if (folder_has_parent_of_type(item, F_TRASH))
270                 type = F_TRASH;
271
272         folder_type_menu = gtk_menu_new ();
273
274         MENUITEM_ADD (folder_type_menu, menuitem, _("Normal"),  F_NORMAL);
275         MENUITEM_ADD (folder_type_menu, menuitem, _("Inbox"),  F_INBOX);
276         MENUITEM_ADD (folder_type_menu, menuitem, _("Outbox"),  F_OUTBOX);
277         MENUITEM_ADD (folder_type_menu, menuitem, _("Drafts"),  F_DRAFT);
278         MENUITEM_ADD (folder_type_menu, menuitem, _("Queue"),  F_QUEUE);
279         MENUITEM_ADD (folder_type_menu, menuitem, _("Trash"),  F_TRASH);
280         gtk_option_menu_set_menu (GTK_OPTION_MENU (folder_type), folder_type_menu);
281
282         gtk_option_menu_set_history(GTK_OPTION_MENU(folder_type), type);
283
284         dummy_checkbtn = gtk_check_button_new();
285         gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(dummy_checkbtn), type != F_INBOX);
286         gtk_widget_set_sensitive(dummy_checkbtn, FALSE);
287
288         if (type == item->stype && type == F_NORMAL)
289                 gtk_widget_set_sensitive(folder_type, TRUE);
290         else
291                 gtk_widget_set_sensitive(folder_type, FALSE);
292
293         label = gtk_label_new(_("Folder type"));
294         gtk_misc_set_alignment(GTK_MISC(label), 0, 0.5);
295         gtk_table_attach(GTK_TABLE(table), label, 0, 1, 
296                          rowcount, rowcount + 1, GTK_SHRINK | GTK_FILL, GTK_FILL, 0, 0);
297         gtk_table_attach(GTK_TABLE(table), folder_type, 1, 2, 
298                          rowcount, rowcount + 1, GTK_SHRINK | GTK_FILL, GTK_FILL, 0, 0);
299         gtk_table_attach(GTK_TABLE(table), dummy_checkbtn, 3, 4, 
300                          rowcount, rowcount + 1, GTK_SHRINK, GTK_SHRINK, 0, 0);
301
302         rowcount++;
303
304         /* Simplify Subject */
305         checkbtn_simplify_subject = gtk_check_button_new_with_label(_("Simplify Subject RegExp"));
306         gtk_table_attach(GTK_TABLE(table), checkbtn_simplify_subject, 0, 1, 
307                          rowcount, rowcount + 1, GTK_SHRINK | GTK_FILL, GTK_FILL, 0, 0);
308         gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(checkbtn_simplify_subject), 
309                                      item->prefs->enable_simplify_subject);
310
311         g_signal_connect(G_OBJECT(checkbtn_simplify_subject), "toggled",
312                         G_CALLBACK(folder_regexp_set_subject_example_cb), page);
313
314         entry_simplify_subject = gtk_entry_new();
315         gtk_table_attach(GTK_TABLE(table), entry_simplify_subject, 1, 3, 
316                          rowcount, rowcount + 1, GTK_EXPAND | GTK_FILL, GTK_FILL, 0, 0);
317         SET_TOGGLE_SENSITIVITY(checkbtn_simplify_subject, entry_simplify_subject);
318         gtk_entry_set_text(GTK_ENTRY(entry_simplify_subject), 
319                            SAFE_STRING(item->prefs->simplify_subject_regexp));
320
321         g_signal_connect(G_OBJECT(entry_simplify_subject), "changed",
322                         G_CALLBACK(folder_regexp_test_cb), page);
323
324         simplify_subject_rec_checkbtn = gtk_check_button_new();
325         gtk_table_attach(GTK_TABLE(table), simplify_subject_rec_checkbtn, 3, 4, 
326                          rowcount, rowcount + 1, GTK_SHRINK, GTK_SHRINK, 0, 0);
327
328         rowcount++;
329
330         /* Test RegExp */
331         label_regexp_test = gtk_label_new(_("Test RegExp"));
332         gtk_misc_set_alignment(GTK_MISC(label_regexp_test), 0, 0.5);
333         gtk_table_attach(GTK_TABLE(table), label_regexp_test, 0, 1, 
334                          rowcount, rowcount + 1, GTK_SHRINK | GTK_FILL, GTK_FILL, 0, 0);
335         SET_TOGGLE_SENSITIVITY(checkbtn_simplify_subject, label_regexp_test);
336
337         entry_regexp_test_string = gtk_entry_new();
338         gtk_table_attach(GTK_TABLE(table), entry_regexp_test_string, 1, 2, 
339                          rowcount, rowcount + 1, GTK_EXPAND | GTK_FILL, GTK_FILL, 0, 0);
340         SET_TOGGLE_SENSITIVITY(checkbtn_simplify_subject, entry_regexp_test_string);
341
342         g_signal_connect(G_OBJECT(entry_regexp_test_string), "changed",
343                         G_CALLBACK(folder_regexp_test_cb), page);
344
345         hbox_regexp = gtk_hbox_new (FALSE, 4);
346         gtk_widget_show (hbox_regexp);
347         gtk_table_attach(GTK_TABLE(table), hbox_regexp, 2, 3, 
348                          rowcount, rowcount + 1, GTK_EXPAND | GTK_FILL, GTK_FILL, 0, 0);
349
350         left_arrow = gtk_arrow_new(GTK_ARROW_RIGHT, GTK_SHADOW_OUT);
351         gtk_widget_show(left_arrow);
352         gtk_box_pack_start (GTK_BOX(hbox_regexp), left_arrow, FALSE, FALSE, 0);
353         SET_TOGGLE_SENSITIVITY(checkbtn_simplify_subject, left_arrow);
354
355         entry_regexp_test_result = gtk_entry_new();
356         gtk_box_pack_end (GTK_BOX(hbox_regexp), entry_regexp_test_result, TRUE, TRUE, 0);
357         SET_TOGGLE_SENSITIVITY(checkbtn_simplify_subject, entry_regexp_test_result);
358         gtk_entry_set_editable(GTK_ENTRY(entry_regexp_test_result), FALSE);
359
360         rowcount++;
361
362         /* Folder chmod */
363         checkbtn_folder_chmod = gtk_check_button_new_with_label(_("Folder chmod"));
364         gtk_table_attach(GTK_TABLE(table), checkbtn_folder_chmod, 0, 1, 
365                          rowcount, rowcount + 1, GTK_SHRINK | GTK_FILL, GTK_FILL, 0, 0);
366
367         gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(checkbtn_folder_chmod), 
368                                      item->prefs->enable_folder_chmod);
369
370         entry_folder_chmod = gtk_entry_new();
371         gtk_table_attach(GTK_TABLE(table), entry_folder_chmod, 1, 2, 
372                          rowcount, rowcount + 1, GTK_EXPAND | GTK_FILL, GTK_FILL, 0, 0);
373         SET_TOGGLE_SENSITIVITY(checkbtn_folder_chmod, entry_folder_chmod);
374         if (item->prefs->folder_chmod) {
375                 gchar *buf;
376
377                 buf = g_strdup_printf("%o", item->prefs->folder_chmod);
378                 gtk_entry_set_text(GTK_ENTRY(entry_folder_chmod), buf);
379                 g_free(buf);
380         }
381         
382         folder_chmod_rec_checkbtn = gtk_check_button_new();
383         gtk_table_attach(GTK_TABLE(table), folder_chmod_rec_checkbtn, 3, 4, 
384                          rowcount, rowcount + 1, GTK_SHRINK, GTK_SHRINK, 0, 0);
385
386         rowcount++;
387         
388         /* Folder color */
389         folder_color = gtk_label_new(_("Folder color"));
390         gtk_misc_set_alignment(GTK_MISC(folder_color), 0, 0.5);
391         gtk_table_attach(GTK_TABLE(table), folder_color, 0, 1, 
392                          rowcount, rowcount + 1, GTK_SHRINK | GTK_FILL, GTK_FILL, 0, 0);
393
394         hbox = gtk_hbox_new(FALSE, 0);
395         gtk_table_attach(GTK_TABLE(table), hbox, 1, 2, 
396                          rowcount, rowcount + 1, GTK_EXPAND | GTK_FILL, GTK_FILL, 0, 0);
397
398         folder_color_btn = gtk_button_new_with_label("");
399         gtk_widget_set_size_request(folder_color_btn, 36, 26);
400         gtk_box_pack_start (GTK_BOX(hbox), folder_color_btn, FALSE, FALSE, 0);
401         gtk_tooltips_set_tip(tooltips, folder_color_btn,
402                              _("Pick color for folder"), NULL);
403
404         page->folder_color = item->prefs->color;
405
406         g_signal_connect(G_OBJECT(folder_color_btn), "clicked",
407                          G_CALLBACK(folder_color_set_dialog),
408                          page);
409
410         gtkut_set_widget_bgcolor_rgb(folder_color_btn, item->prefs->color);
411
412         folder_color_rec_checkbtn = gtk_check_button_new();
413         gtk_table_attach(GTK_TABLE(table), folder_color_rec_checkbtn, 3, 4, 
414                          rowcount, rowcount + 1, GTK_SHRINK, GTK_SHRINK, 0, 0);
415
416         rowcount++;
417
418         /* Enable processing at startup */
419         checkbtn_enable_processing = gtk_check_button_new_with_label(_("Process at start-up"));
420         gtk_table_attach(GTK_TABLE(table), checkbtn_enable_processing, 0, 2, 
421                          rowcount, rowcount + 1, GTK_EXPAND | GTK_FILL, GTK_FILL, 0, 0);
422
423         gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(checkbtn_enable_processing), 
424                                      item->prefs->enable_processing);
425
426         enable_processing_rec_checkbtn = gtk_check_button_new();
427         gtk_table_attach(GTK_TABLE(table), enable_processing_rec_checkbtn, 3, 4, 
428                          rowcount, rowcount + 1, GTK_SHRINK, GTK_SHRINK, 0, 0);
429         
430         rowcount++;
431
432         /* Check folder for new mail */
433         checkbtn_newmailcheck = gtk_check_button_new_with_label(_("Scan for new mail"));
434         gtk_tooltips_set_tip(tooltips, checkbtn_newmailcheck,
435                              _("Turn this option on if mail is delivered directly "
436                                "to this folder by server side filtering on IMAP or "
437                                "by an external application"), NULL);
438         gtk_table_attach(GTK_TABLE(table), checkbtn_newmailcheck, 0, 2,
439                          rowcount, rowcount+1, GTK_EXPAND | GTK_FILL, GTK_FILL, 0, 0);
440         
441         gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(checkbtn_newmailcheck),
442                                                                  item->prefs->newmailcheck);
443         newmailcheck_rec_checkbtn = gtk_check_button_new();
444         gtk_table_attach(GTK_TABLE(table), newmailcheck_rec_checkbtn, 3, 4, 
445                          rowcount, rowcount + 1, GTK_SHRINK, GTK_SHRINK, 0, 0);
446
447         rowcount++;
448
449         /* Synchronise folder for offline use */
450         checkbtn_offlinesync = gtk_check_button_new_with_label(_("Synchronise for offline use"));
451         gtk_table_attach(GTK_TABLE(table), checkbtn_offlinesync, 0, 2,
452                          rowcount, rowcount+1, GTK_EXPAND | GTK_FILL, GTK_FILL, 0, 0);
453         
454         offlinesync_rec_checkbtn = gtk_check_button_new();
455         gtk_table_attach(GTK_TABLE(table), offlinesync_rec_checkbtn, 3, 4, 
456                          rowcount, rowcount + 1, GTK_SHRINK, GTK_SHRINK, 0, 0);
457
458         rowcount++;
459
460         hbox = gtk_hbox_new (FALSE, 8);
461         gtk_widget_show (hbox);
462         gtk_table_attach(GTK_TABLE(table), hbox, 0, 4,
463                          rowcount, rowcount+1, GTK_EXPAND | GTK_FILL, GTK_FILL, 0, 0);
464         rowcount++;
465
466         hbox_spc = gtk_hbox_new (FALSE, 0);
467         gtk_widget_show (hbox_spc);
468         gtk_box_pack_start (GTK_BOX (hbox), hbox_spc, FALSE, FALSE, 0);
469         gtk_widget_set_size_request (hbox_spc, 12, -1);
470
471         label_offlinesync = gtk_label_new(_("Fetch message bodies from the last"));
472         gtk_widget_show (label_offlinesync);
473         gtk_box_pack_start (GTK_BOX (hbox), label_offlinesync, FALSE, FALSE, 0);
474
475         entry_offlinesync = gtk_entry_new();
476         gtk_widget_set_size_request (entry_offlinesync, 64, -1);
477         gtk_widget_show (entry_offlinesync);
478         gtk_tooltips_set_tip(tooltips, entry_offlinesync, _("0: all bodies"), NULL);
479         gtk_box_pack_start (GTK_BOX (hbox), entry_offlinesync, FALSE, FALSE, 0);
480
481         label_end_offlinesync = gtk_label_new(_("days"));
482         gtk_widget_show (label_end_offlinesync);
483         gtk_box_pack_start (GTK_BOX (hbox), label_end_offlinesync, FALSE, FALSE, 0);
484
485         checkbtn_remove_old_offlinesync = gtk_check_button_new_with_label(
486                                                 _("Remove older messages bodies"));
487
488         hbox2 = gtk_hbox_new (FALSE, 8);
489         gtk_widget_show (hbox2);
490         gtk_table_attach(GTK_TABLE(table), hbox2, 0, 4,
491                          rowcount, rowcount+1, GTK_EXPAND | GTK_FILL, GTK_FILL, 0, 0);
492         rowcount++;
493
494         hbox_spc = gtk_hbox_new (FALSE, 0);
495         gtk_widget_show (hbox_spc);
496         gtk_box_pack_start (GTK_BOX (hbox2), hbox_spc, FALSE, FALSE, 0);
497         gtk_widget_set_size_request (hbox_spc, 12, -1);
498         gtk_box_pack_start (GTK_BOX (hbox2), checkbtn_remove_old_offlinesync, FALSE, FALSE, 0);
499
500         SET_TOGGLE_SENSITIVITY (checkbtn_offlinesync, hbox);
501         SET_TOGGLE_SENSITIVITY (checkbtn_offlinesync, hbox2);
502         
503         gtk_widget_show_all(table);
504
505         if (item->folder && (item->folder->klass->type != F_IMAP && 
506             item->folder->klass->type != F_NEWS)) {
507                 item->prefs->offlinesync = TRUE;
508                 item->prefs->offlinesync_days = 0;
509                 item->prefs->remove_old_bodies = FALSE;
510
511                 gtk_widget_set_sensitive(GTK_WIDGET(checkbtn_offlinesync),
512                                                                  FALSE);
513                 gtk_widget_set_sensitive(GTK_WIDGET(offlinesync_rec_checkbtn),
514                                                                  FALSE);
515                 gtk_widget_hide(GTK_WIDGET(checkbtn_offlinesync));
516                 gtk_widget_hide(GTK_WIDGET(hbox));
517                 gtk_widget_hide(GTK_WIDGET(hbox2));
518                 gtk_widget_hide(GTK_WIDGET(offlinesync_rec_checkbtn));
519         
520         }
521         gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(checkbtn_offlinesync),
522                                                                  item->prefs->offlinesync);
523         gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(checkbtn_remove_old_offlinesync),
524                                                                  item->prefs->remove_old_bodies);
525         gtk_entry_set_text(GTK_ENTRY(entry_offlinesync), itos(item->prefs->offlinesync_days));
526
527         page->table = table;
528         page->folder_type = folder_type;
529         page->no_save_warning = no_save_warning;
530         page->checkbtn_simplify_subject = checkbtn_simplify_subject;
531         page->entry_simplify_subject = entry_simplify_subject;
532         page->entry_regexp_test_string = entry_regexp_test_string;
533         page->entry_regexp_test_result = entry_regexp_test_result;
534         page->checkbtn_folder_chmod = checkbtn_folder_chmod;
535         page->entry_folder_chmod = entry_folder_chmod;
536         page->folder_color_btn = folder_color_btn;
537         page->checkbtn_enable_processing = checkbtn_enable_processing;
538         page->checkbtn_newmailcheck = checkbtn_newmailcheck;
539         page->checkbtn_offlinesync = checkbtn_offlinesync;
540         page->label_offlinesync = label_offlinesync;
541         page->entry_offlinesync = entry_offlinesync;
542         page->label_end_offlinesync = label_end_offlinesync;
543         page->checkbtn_remove_old_offlinesync = checkbtn_remove_old_offlinesync;
544
545         page->simplify_subject_rec_checkbtn  = simplify_subject_rec_checkbtn;
546         page->folder_chmod_rec_checkbtn      = folder_chmod_rec_checkbtn;
547         page->folder_color_rec_checkbtn      = folder_color_rec_checkbtn;
548         page->enable_processing_rec_checkbtn = enable_processing_rec_checkbtn;
549         page->newmailcheck_rec_checkbtn      = newmailcheck_rec_checkbtn;
550         page->offlinesync_rec_checkbtn       = offlinesync_rec_checkbtn;
551
552         page->page.widget = table;
553
554         folder_regexp_set_subject_example_cb(NULL, page);
555 }
556
557 static void prefs_folder_item_general_destroy_widget_func(PrefsPage *page_) 
558 {
559         /* FolderItemGeneralPage *page = (FolderItemGeneralPage *) page_; */
560 }
561
562 /** \brief  Save the prefs in page to folder.
563  *
564  *  If the folder is not the one  specified in page->item, then only those properties 
565  *  that have the relevant 'apply to sub folders' button checked are saved
566  */
567 static void general_save_folder_prefs(FolderItem *folder, FolderItemGeneralPage *page)
568 {
569         FolderItemPrefs *prefs = folder->prefs;
570         gchar *buf;
571         gboolean all = FALSE;
572         SpecialFolderItemType type = F_NORMAL;
573         GtkWidget *menu;
574         GtkWidget *menuitem;
575
576         if (folder->path == NULL)
577                 return;
578
579         g_return_if_fail(prefs != NULL);
580
581         if (page->item == folder) 
582                 all = TRUE;
583
584         menu = gtk_option_menu_get_menu(GTK_OPTION_MENU(page->folder_type));
585         menuitem = gtk_menu_get_active(GTK_MENU(menu));
586         type = GPOINTER_TO_INT
587                 (g_object_get_data(G_OBJECT(menuitem), MENU_VAL_ID));
588         if (all && folder->stype != type) {
589                 folder_item_change_type(folder, type);
590         }
591
592         if (all || gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(page->simplify_subject_rec_checkbtn))) {
593                 prefs->enable_simplify_subject =
594                         gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(page->checkbtn_simplify_subject));
595                 ASSIGN_STRING(prefs->simplify_subject_regexp,
596                               gtk_editable_get_chars(GTK_EDITABLE(page->entry_simplify_subject), 0, -1));
597         }
598         
599         if (all || gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(page->folder_chmod_rec_checkbtn))) {
600                 prefs->enable_folder_chmod = 
601                         gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(page->checkbtn_folder_chmod));
602                 buf = gtk_editable_get_chars(GTK_EDITABLE(page->entry_folder_chmod), 0, -1);
603                 prefs->folder_chmod = prefs_folder_item_chmod_mode(buf);
604                 g_free(buf);
605         }
606
607         if (all || gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(page->folder_color_rec_checkbtn))) {
608                 int old_color = prefs->color;
609                 prefs->color = page->folder_color;
610         
611                 /* update folder view */
612                 if (prefs->color != old_color)
613                         folder_item_update(folder, F_ITEM_UPDATE_MSGCNT);
614         }
615
616         if (all || gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(page->enable_processing_rec_checkbtn))) {
617                 prefs->enable_processing = 
618                         gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(page->checkbtn_enable_processing));
619         }
620
621         if (all ||  gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(page->newmailcheck_rec_checkbtn))) {
622                 prefs->newmailcheck = 
623                         gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(page->checkbtn_newmailcheck));
624         }
625
626         if (all ||  gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(page->offlinesync_rec_checkbtn))) {
627                 prefs->offlinesync = 
628                         gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(page->checkbtn_offlinesync));
629                 prefs->offlinesync_days = 
630                         atoi(gtk_entry_get_text(GTK_ENTRY(page->entry_offlinesync)));
631                 prefs->remove_old_bodies =
632                         gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(page->checkbtn_remove_old_offlinesync));
633         }
634
635         folder_item_prefs_save_config(folder);
636 }       
637
638 static gboolean general_save_recurse_func(GNode *node, gpointer data)
639 {
640         FolderItem *item = (FolderItem *) node->data;
641         FolderItemGeneralPage *page = (FolderItemGeneralPage *) data;
642
643         g_return_val_if_fail(item != NULL, TRUE);
644         g_return_val_if_fail(page != NULL, TRUE);
645
646         general_save_folder_prefs(item, page);
647
648         /* optimise by not continuing if none of the 'apply to sub folders'
649            check boxes are selected - and optimise the checking by only doing
650            it once */
651         if ((node == page->item->node) &&
652             !(gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(page->simplify_subject_rec_checkbtn)) ||
653               gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(page->folder_chmod_rec_checkbtn)) ||
654               gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(page->folder_color_rec_checkbtn)) ||
655               gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(page->enable_processing_rec_checkbtn)) ||
656               gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(page->newmailcheck_rec_checkbtn)) ||
657               gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(page->offlinesync_rec_checkbtn))))
658                 return TRUE;
659         else 
660                 return FALSE;
661 }
662
663 static void prefs_folder_item_general_save_func(PrefsPage *page_) 
664 {
665         FolderItemGeneralPage *page = (FolderItemGeneralPage *) page_;
666
667         g_node_traverse(page->item->node, G_PRE_ORDER, G_TRAVERSE_ALL,
668                         -1, general_save_recurse_func, page);
669         
670         main_window_set_menu_sensitive(mainwindow_get_mainwindow());
671
672 }
673
674 static RecvProtocol item_protocol(FolderItem *item)
675 {
676         if (!item)
677                 return A_NONE;
678         if (!item->folder)
679                 return A_NONE;
680         if (!item->folder->account)
681                 return A_NONE;
682         return item->folder->account->protocol;
683 }
684
685 static void prefs_folder_item_compose_create_widget_func(PrefsPage * page_,
686                                                    GtkWindow * window,
687                                                    gpointer data)
688 {
689         FolderItemComposePage *page = (FolderItemComposePage *) page_;
690         FolderItem *item = (FolderItem *) data;
691         guint rowcount;
692
693         GtkWidget *table;
694         GtkWidget *label;
695         
696         GtkWidget *no_save_warning = NULL;
697         GtkWidget *checkbtn_request_return_receipt = NULL;
698         GtkWidget *checkbtn_save_copy_to_folder = NULL;
699         GtkWidget *checkbtn_default_to = NULL;
700         GtkWidget *entry_default_to = NULL;
701         GtkWidget *checkbtn_default_reply_to = NULL;
702         GtkWidget *entry_default_reply_to = NULL;
703         GtkWidget *checkbtn_enable_default_account = NULL;
704         GtkWidget *optmenu_default_account = NULL;
705         GtkWidget *optmenu_default_account_menu = NULL;
706         GtkWidget *optmenu_default_account_menuitem = NULL;
707 #if USE_ASPELL
708         GtkWidget *checkbtn_enable_default_dictionary = NULL;
709         GtkWidget *optmenu_default_dictionary = NULL;
710         GtkWidget *checkbtn_enable_default_alt_dictionary = NULL;
711         GtkWidget *optmenu_default_alt_dictionary = NULL;
712 #endif
713         GtkWidget *request_return_receipt_rec_checkbtn = NULL;
714         GtkWidget *save_copy_to_folder_rec_checkbtn = NULL;
715         GtkWidget *default_to_rec_checkbtn = NULL;
716         GtkWidget *default_reply_to_rec_checkbtn = NULL;
717         GtkWidget *default_account_rec_checkbtn = NULL;
718 #if USE_ASPELL
719         GtkWidget *default_dictionary_rec_checkbtn = NULL;
720         GtkWidget *default_alt_dictionary_rec_checkbtn = NULL;
721 #endif
722
723         GList *cur_ac;
724         GList *account_list;
725 #if USE_ASPELL
726         gchar *dictionary;
727 #endif
728         PrefsAccount *ac_prefs;
729         GtkOptionMenu *optmenu;
730         GtkWidget *menu;
731         GtkWidget *menuitem;
732         gint account_index, index;
733
734         page->item         = item;
735
736         /* Table */
737 #if USE_ASPELL
738 # define TABLEHEIGHT 7
739 #else
740 # define TABLEHEIGHT 6
741 #endif
742         table = gtk_table_new(TABLEHEIGHT, 3, FALSE);
743         gtk_container_set_border_width (GTK_CONTAINER (table), VBOX_BORDER);
744         gtk_table_set_row_spacings(GTK_TABLE(table), 4);
745         gtk_table_set_col_spacings(GTK_TABLE(table), 4);
746         rowcount = 0;
747
748         if (!can_save) {
749                 no_save_warning = gtk_label_new(
750                         _("<i>These preferences will not be saved as this folder "
751                         "is a top-level one. However you can use them to set them "
752                         "to the whole mailbox tree using \"Apply to subfolders\".</i>"));
753                 gtk_label_set_use_markup(GTK_LABEL(no_save_warning), TRUE);
754                 gtk_label_set_line_wrap(GTK_LABEL(no_save_warning), TRUE);
755                 gtk_misc_set_alignment(GTK_MISC(no_save_warning), 0.0, 0.5);
756                 gtk_table_attach(GTK_TABLE(table), no_save_warning, 0, 3,
757                          rowcount, rowcount + 1, GTK_FILL, 0, 0, 0);
758                 rowcount++;
759         }
760         
761         /* Apply to subfolders */
762         label = gtk_label_new(_("Apply to\nsubfolders"));
763         gtk_misc_set_alignment(GTK_MISC(label), 0.5, 0.5);
764         gtk_table_attach(GTK_TABLE(table), label, 2, 3,
765                          rowcount, rowcount + 1, GTK_SHRINK, GTK_SHRINK, 0, 0);
766         rowcount++;
767
768         if (item_protocol(item) != A_NNTP) {
769                 /* Request Return Receipt */
770                 checkbtn_request_return_receipt = gtk_check_button_new_with_label
771                         (_("Request Return Receipt"));
772                 gtk_table_attach(GTK_TABLE(table), checkbtn_request_return_receipt, 
773                                  0, 2, rowcount, rowcount + 1, GTK_SHRINK | GTK_FILL, 
774                                  GTK_FILL, 0, 0);
775                 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(checkbtn_request_return_receipt),
776                                              item->ret_rcpt ? TRUE : FALSE);
777
778                 request_return_receipt_rec_checkbtn = gtk_check_button_new();
779                 gtk_table_attach(GTK_TABLE(table), request_return_receipt_rec_checkbtn, 2, 3, 
780                                  rowcount, rowcount + 1, GTK_SHRINK, GTK_SHRINK, 0, 0);
781
782                 rowcount++;
783
784                 /* Save Copy to Folder */
785                 checkbtn_save_copy_to_folder = gtk_check_button_new_with_label
786                         (_("Save copy of outgoing messages to this folder instead of Sent"));
787                 gtk_table_attach(GTK_TABLE(table), checkbtn_save_copy_to_folder, 0, 2, 
788                                  rowcount, rowcount + 1, GTK_SHRINK | GTK_FILL, GTK_FILL, 0, 0);
789                 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(checkbtn_save_copy_to_folder),
790                                              item->prefs->save_copy_to_folder ? TRUE : FALSE);
791
792                 save_copy_to_folder_rec_checkbtn = gtk_check_button_new();
793                 gtk_table_attach(GTK_TABLE(table), save_copy_to_folder_rec_checkbtn, 2, 3, 
794                                  rowcount, rowcount + 1, GTK_SHRINK, GTK_SHRINK, 0, 0);
795
796                 rowcount++;
797
798                 /* Default To */
799                 checkbtn_default_to = gtk_check_button_new_with_label(_("Default To:"));
800                 gtk_table_attach(GTK_TABLE(table), checkbtn_default_to, 0, 1, 
801                                  rowcount, rowcount + 1, GTK_SHRINK | GTK_FILL, GTK_SHRINK, 0, 0);
802                 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(checkbtn_default_to), 
803                                              item->prefs->enable_default_to);
804
805                 entry_default_to = gtk_entry_new();
806                 gtk_table_attach(GTK_TABLE(table), entry_default_to, 1, 2,
807                                  rowcount, rowcount + 1, GTK_EXPAND | GTK_FILL, GTK_SHRINK, 0, 0);
808                 SET_TOGGLE_SENSITIVITY(checkbtn_default_to, entry_default_to);
809                 gtk_entry_set_text(GTK_ENTRY(entry_default_to), SAFE_STRING(item->prefs->default_to));
810                 address_completion_register_entry(GTK_ENTRY(entry_default_to),
811                                 TRUE);
812
813                 default_to_rec_checkbtn = gtk_check_button_new();
814                 gtk_table_attach(GTK_TABLE(table), default_to_rec_checkbtn, 2, 3, 
815                                  rowcount, rowcount + 1, GTK_SHRINK, GTK_SHRINK, 0, 0);
816
817                 rowcount++;
818
819                 /* Default address to reply to */
820                 checkbtn_default_reply_to = gtk_check_button_new_with_label(_("Default To: for replies"));
821                 gtk_table_attach(GTK_TABLE(table), checkbtn_default_reply_to, 0, 1, 
822                                  rowcount, rowcount + 1, GTK_SHRINK | GTK_FILL, GTK_SHRINK, 0, 0);
823                 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(checkbtn_default_reply_to), 
824                                              item->prefs->enable_default_reply_to);
825
826                 entry_default_reply_to = gtk_entry_new();
827                 gtk_table_attach(GTK_TABLE(table), entry_default_reply_to, 1, 2,
828                                  rowcount, rowcount + 1, GTK_EXPAND | GTK_FILL, GTK_SHRINK, 0, 0);
829                 SET_TOGGLE_SENSITIVITY(checkbtn_default_reply_to, entry_default_reply_to);
830                 gtk_entry_set_text(GTK_ENTRY(entry_default_reply_to), SAFE_STRING(item->prefs->default_reply_to));
831                 address_completion_register_entry(
832                                 GTK_ENTRY(entry_default_reply_to), TRUE);
833
834                 default_reply_to_rec_checkbtn = gtk_check_button_new();
835                 gtk_table_attach(GTK_TABLE(table), default_reply_to_rec_checkbtn, 2, 3, 
836                                  rowcount, rowcount + 1, GTK_SHRINK, GTK_SHRINK, 0, 0);
837
838                 rowcount++;
839         }
840         /* Default account */
841         checkbtn_enable_default_account = gtk_check_button_new_with_label(_("Default account"));
842         gtk_table_attach(GTK_TABLE(table), checkbtn_enable_default_account, 0, 1, 
843                          rowcount, rowcount + 1, GTK_SHRINK | GTK_FILL, GTK_SHRINK, 0, 0);
844         gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(checkbtn_enable_default_account), 
845                                      item->prefs->enable_default_account);
846
847         optmenu_default_account = gtk_option_menu_new ();
848         gtk_table_attach(GTK_TABLE(table), optmenu_default_account, 1, 2, 
849                          rowcount, rowcount + 1, GTK_EXPAND | GTK_FILL, GTK_SHRINK, 0, 0);
850         optmenu_default_account_menu = gtk_menu_new ();
851
852         account_list = account_get_list();
853         account_index = 0;
854         index = 0;
855         for (cur_ac = account_list; cur_ac != NULL; cur_ac = cur_ac->next) {
856                 ac_prefs = (PrefsAccount *)cur_ac->data;
857                 if (item->folder->account &&
858                     ( (item_protocol(item) == A_NNTP && ac_prefs->protocol != A_NNTP)
859                     ||(item_protocol(item) != A_NNTP && ac_prefs->protocol == A_NNTP))) 
860                         continue;
861
862                 if (item->folder->klass->type != F_NEWS && ac_prefs->protocol == A_NNTP)
863                         continue;
864
865                 MENUITEM_ADD (optmenu_default_account_menu, optmenu_default_account_menuitem,
866                                         ac_prefs->account_name?ac_prefs->account_name : _("Untitled"),
867                                         ac_prefs->account_id);
868                 /* get the index for menu's set_history (sad method?) */
869                 if (ac_prefs->account_id == item->prefs->default_account)
870                         account_index = index;
871                 index++;                        
872         }
873
874         optmenu = GTK_OPTION_MENU(optmenu_default_account);
875         gtk_option_menu_set_menu(optmenu, optmenu_default_account_menu);
876
877         gtk_option_menu_set_history(optmenu, account_index);
878
879         menu = gtk_option_menu_get_menu(optmenu);
880         menuitem = gtk_menu_get_active(GTK_MENU(menu));
881         gtk_menu_item_activate(GTK_MENU_ITEM(menuitem));
882
883         SET_TOGGLE_SENSITIVITY(checkbtn_enable_default_account, optmenu_default_account);
884
885         default_account_rec_checkbtn = gtk_check_button_new();
886         gtk_table_attach(GTK_TABLE(table), default_account_rec_checkbtn, 2, 3, 
887                          rowcount, rowcount + 1, GTK_SHRINK, GTK_SHRINK, 0, 0);
888         rowcount++;
889
890 #if USE_ASPELL
891         /* Default dictionary */
892         checkbtn_enable_default_dictionary = gtk_check_button_new_with_label(_("Default dictionary"));
893         gtk_table_attach(GTK_TABLE(table), checkbtn_enable_default_dictionary, 0, 1,
894                          rowcount, rowcount + 1, GTK_SHRINK | GTK_FILL, GTK_SHRINK, 0, 0);
895         gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(checkbtn_enable_default_dictionary),
896                                      item->prefs->enable_default_dictionary);
897
898         optmenu_default_dictionary = gtk_option_menu_new();
899         gtk_table_attach(GTK_TABLE(table), optmenu_default_dictionary, 1, 2,
900                          rowcount, rowcount + 1, GTK_EXPAND | GTK_FILL, GTK_SHRINK, 0, 0);
901
902         gtk_option_menu_set_menu(GTK_OPTION_MENU(optmenu_default_dictionary), 
903                                  gtkaspell_dictionary_option_menu_new(
904                                          prefs_common.aspell_path));
905
906         dictionary = item->prefs->default_dictionary;
907
908         optmenu = GTK_OPTION_MENU(optmenu_default_dictionary);
909
910         menu = gtk_option_menu_get_menu(optmenu);
911         if (dictionary)
912                 gtkaspell_set_dictionary_menu_active_item(optmenu_default_dictionary, dictionary);
913         menuitem = gtk_menu_get_active(GTK_MENU(menu));
914         gtk_menu_item_activate(GTK_MENU_ITEM(menuitem));
915
916         SET_TOGGLE_SENSITIVITY(checkbtn_enable_default_dictionary, optmenu_default_dictionary);
917
918         default_dictionary_rec_checkbtn = gtk_check_button_new();
919         gtk_table_attach(GTK_TABLE(table), default_dictionary_rec_checkbtn, 2, 3, 
920                          rowcount, rowcount + 1, GTK_SHRINK, GTK_SHRINK, 0, 0);
921         
922         rowcount++;
923
924         /* Default dictionary */
925         checkbtn_enable_default_alt_dictionary = gtk_check_button_new_with_label(_("Default alternate dictionary"));
926         gtk_table_attach(GTK_TABLE(table), checkbtn_enable_default_alt_dictionary, 0, 1,
927                          rowcount, rowcount + 1, GTK_SHRINK | GTK_FILL, GTK_SHRINK, 0, 0);
928         gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(checkbtn_enable_default_alt_dictionary),
929                                      item->prefs->enable_default_alt_dictionary);
930
931         optmenu_default_alt_dictionary = gtk_option_menu_new();
932         gtk_table_attach(GTK_TABLE(table), optmenu_default_alt_dictionary, 1, 2,
933                          rowcount, rowcount + 1, GTK_EXPAND | GTK_FILL, GTK_SHRINK, 0, 0);
934
935         gtk_option_menu_set_menu(GTK_OPTION_MENU(optmenu_default_alt_dictionary), 
936                                  gtkaspell_dictionary_option_menu_new_with_refresh(
937                                          prefs_common.aspell_path, FALSE));
938
939         dictionary = item->prefs->default_alt_dictionary;
940
941         optmenu = GTK_OPTION_MENU(optmenu_default_alt_dictionary);
942
943         menu = gtk_option_menu_get_menu(optmenu);
944         if (dictionary)
945                 gtkaspell_set_dictionary_menu_active_item(optmenu_default_alt_dictionary, dictionary);
946         menuitem = gtk_menu_get_active(GTK_MENU(menu));
947         gtk_menu_item_activate(GTK_MENU_ITEM(menuitem));
948
949         SET_TOGGLE_SENSITIVITY(checkbtn_enable_default_alt_dictionary, optmenu_default_alt_dictionary);
950
951         default_alt_dictionary_rec_checkbtn = gtk_check_button_new();
952         gtk_table_attach(GTK_TABLE(table), default_alt_dictionary_rec_checkbtn, 2, 3, 
953                          rowcount, rowcount + 1, GTK_SHRINK, GTK_SHRINK, 0, 0);
954         
955         rowcount++;
956 #endif
957
958         gtk_widget_show_all(table);
959
960         page->window = GTK_WIDGET(window);
961         page->table = table;
962         page->no_save_warning = no_save_warning;
963         page->checkbtn_request_return_receipt = checkbtn_request_return_receipt;
964         page->checkbtn_save_copy_to_folder = checkbtn_save_copy_to_folder;
965         page->checkbtn_default_to = checkbtn_default_to;
966         page->entry_default_to = entry_default_to;
967         page->checkbtn_default_reply_to = checkbtn_default_reply_to;
968         page->entry_default_reply_to = entry_default_reply_to;
969         page->checkbtn_enable_default_account = checkbtn_enable_default_account;
970         page->optmenu_default_account = optmenu_default_account;
971 #ifdef USE_ASPELL
972         page->checkbtn_enable_default_dictionary = checkbtn_enable_default_dictionary;
973         page->optmenu_default_dictionary = optmenu_default_dictionary;
974         page->checkbtn_enable_default_alt_dictionary = checkbtn_enable_default_alt_dictionary;
975         page->optmenu_default_alt_dictionary = optmenu_default_alt_dictionary;
976 #endif
977
978         page->request_return_receipt_rec_checkbtn = request_return_receipt_rec_checkbtn;
979         page->save_copy_to_folder_rec_checkbtn    = save_copy_to_folder_rec_checkbtn;
980         page->default_to_rec_checkbtn             = default_to_rec_checkbtn;
981         page->default_reply_to_rec_checkbtn       = default_reply_to_rec_checkbtn;
982         page->default_account_rec_checkbtn        = default_account_rec_checkbtn;
983 #if USE_ASPELL
984         page->default_dictionary_rec_checkbtn = default_dictionary_rec_checkbtn;
985         page->default_alt_dictionary_rec_checkbtn = default_alt_dictionary_rec_checkbtn;
986 #endif
987
988         address_completion_start(page->window);
989
990         page->page.widget = table;
991 }
992
993 static void prefs_folder_item_compose_destroy_widget_func(PrefsPage *page_) 
994 {
995         FolderItemComposePage *page = (FolderItemComposePage *) page_;
996
997         if (page->entry_default_to)
998                 address_completion_unregister_entry(GTK_ENTRY(page->entry_default_to));
999         if (page->entry_default_reply_to)
1000                 address_completion_unregister_entry(GTK_ENTRY(page->entry_default_reply_to));
1001         address_completion_end(page->window);
1002 }
1003
1004 /** \brief  Save the prefs in page to folder.
1005  *
1006  *  If the folder is not the one  specified in page->item, then only those properties 
1007  *  that have the relevant 'apply to sub folders' button checked are saved
1008  */
1009 static void compose_save_folder_prefs(FolderItem *folder, FolderItemComposePage *page)
1010 {
1011         FolderItemPrefs *prefs = folder->prefs;
1012         GtkWidget *menu;
1013         GtkWidget *menuitem;
1014         gboolean all = FALSE;
1015
1016         if (folder->path == NULL)
1017                 return;
1018
1019         if (page->item == folder) 
1020                 all = TRUE;
1021
1022         g_return_if_fail(prefs != NULL);
1023
1024         if (item_protocol(folder) != A_NNTP) {
1025                 if (all || gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(page->request_return_receipt_rec_checkbtn))) {
1026                         prefs->request_return_receipt = 
1027                                 gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(page->checkbtn_request_return_receipt));
1028                         /* MIGRATION */    
1029                         folder->ret_rcpt = prefs->request_return_receipt;
1030                 }
1031
1032                 if (all || gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(page->save_copy_to_folder_rec_checkbtn))) {
1033                         prefs->save_copy_to_folder = 
1034                                 gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(page->checkbtn_save_copy_to_folder));
1035                 }
1036
1037                 if (all || gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(page->default_to_rec_checkbtn))) {
1038
1039                         prefs->enable_default_to = 
1040                                 gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(page->checkbtn_default_to));
1041                         ASSIGN_STRING(prefs->default_to,
1042                                       gtk_editable_get_chars(GTK_EDITABLE(page->entry_default_to), 0, -1));
1043                 }
1044
1045                 if (all || gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(page->default_reply_to_rec_checkbtn))) {
1046                         prefs->enable_default_reply_to = 
1047                                 gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(page->checkbtn_default_reply_to));
1048                         ASSIGN_STRING(prefs->default_reply_to,
1049                                       gtk_editable_get_chars(GTK_EDITABLE(page->entry_default_reply_to), 0, -1));
1050                 }
1051         } else {
1052                 prefs->request_return_receipt = FALSE;
1053                 prefs->save_copy_to_folder = FALSE;
1054                 prefs->enable_default_to = FALSE;
1055                 prefs->enable_default_reply_to = FALSE;
1056         }
1057         if (all || gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(page->default_account_rec_checkbtn))) {
1058                 prefs->enable_default_account = 
1059                         gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(page->checkbtn_enable_default_account));
1060                 menu = gtk_option_menu_get_menu(GTK_OPTION_MENU(page->optmenu_default_account));
1061                 menuitem = gtk_menu_get_active(GTK_MENU(menu));
1062                 prefs->default_account = GPOINTER_TO_INT(g_object_get_data(G_OBJECT(menuitem), MENU_VAL_ID));
1063         }
1064
1065 #if USE_ASPELL
1066         if (all || gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(page->default_dictionary_rec_checkbtn))) {
1067                 prefs->enable_default_dictionary =
1068                         gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(page->checkbtn_enable_default_dictionary));
1069                 menu = gtk_option_menu_get_menu(GTK_OPTION_MENU(page->optmenu_default_dictionary));
1070                 ASSIGN_STRING(prefs->default_dictionary,
1071                               gtkaspell_get_dictionary_menu_active_item(menu));
1072         }
1073         if (all || gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(page->default_alt_dictionary_rec_checkbtn))) {
1074                 prefs->enable_default_alt_dictionary =
1075                         gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(page->checkbtn_enable_default_alt_dictionary));
1076                 menu = gtk_option_menu_get_menu(GTK_OPTION_MENU(page->optmenu_default_alt_dictionary));
1077                 ASSIGN_STRING(prefs->default_alt_dictionary,
1078                               gtkaspell_get_dictionary_menu_active_item(menu));
1079         }
1080 #endif
1081
1082         folder_item_prefs_save_config(folder);
1083 }       
1084
1085 static gboolean compose_save_recurse_func(GNode *node, gpointer data)
1086 {
1087         FolderItem *item = (FolderItem *) node->data;
1088         FolderItemComposePage *page = (FolderItemComposePage *) data;
1089
1090         g_return_val_if_fail(item != NULL, TRUE);
1091         g_return_val_if_fail(page != NULL, TRUE);
1092
1093         compose_save_folder_prefs(item, page);
1094
1095         /* optimise by not continuing if none of the 'apply to sub folders'
1096            check boxes are selected - and optimise the checking by only doing
1097            it once */
1098         if ((node == page->item->node) && item_protocol(item) != A_NNTP &&
1099             !(gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(page->request_return_receipt_rec_checkbtn)) ||
1100               gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(page->save_copy_to_folder_rec_checkbtn)) ||
1101               gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(page->default_to_rec_checkbtn)) ||
1102               gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(page->default_account_rec_checkbtn)) ||
1103 #if USE_ASPELL
1104               gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(page->default_dictionary_rec_checkbtn)) ||
1105               gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(page->default_alt_dictionary_rec_checkbtn)) ||
1106 #endif
1107               gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(page->default_reply_to_rec_checkbtn))))
1108                 return TRUE;
1109         else if ((node == page->item->node) && item_protocol(item) == A_NNTP &&
1110             !(gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(page->default_account_rec_checkbtn)) 
1111 #if USE_ASPELL
1112               || gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(page->default_dictionary_rec_checkbtn))
1113               || gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(page->default_alt_dictionary_rec_checkbtn))
1114 #endif
1115                     ))
1116                 return TRUE;
1117         else 
1118                 return FALSE;
1119 }
1120
1121 static void prefs_folder_item_compose_save_func(PrefsPage *page_) 
1122 {
1123         FolderItemComposePage *page = (FolderItemComposePage *) page_;
1124
1125         g_node_traverse(page->item->node, G_PRE_ORDER, G_TRAVERSE_ALL,
1126                         -1, compose_save_recurse_func, page);
1127
1128 }
1129
1130 static void prefs_folder_item_templates_create_widget_func(PrefsPage * page_,
1131                                                    GtkWindow * window,
1132                                                    gpointer data)
1133 {
1134         FolderItemTemplatesPage *page = (FolderItemTemplatesPage *) page_;
1135         FolderItem *item = (FolderItem *) data;
1136
1137         GtkWidget *table;
1138         GtkWidget *label;
1139         guint rowcount;
1140         GtkWidget *vbox;
1141         GtkWidget *alignment;
1142         GtkWidget *new_msg_format_rec_checkbtn;
1143         GtkWidget *reply_format_rec_checkbtn;
1144         GtkWidget *forward_format_rec_checkbtn;
1145
1146         page->item         = item;
1147
1148         /* Table */
1149         table = gtk_table_new(5, 3, FALSE);
1150         gtk_container_set_border_width (GTK_CONTAINER (table), VBOX_BORDER);
1151         gtk_table_set_row_spacings(GTK_TABLE(table), 4);
1152         gtk_table_set_col_spacings(GTK_TABLE(table), 4);
1153         rowcount = 0;
1154
1155         /* Apply to subfolders */
1156         label = gtk_label_new(_("Apply to\nsubfolders"));
1157         gtk_misc_set_alignment(GTK_MISC(label), 0.5, 0.5);
1158         gtk_table_attach(GTK_TABLE(table), label, 2, 3,
1159                          rowcount, rowcount + 1, GTK_SHRINK, GTK_SHRINK, 0, 0);
1160         rowcount++;
1161
1162         /* compose format */
1163         vbox = gtk_vbox_new (FALSE, VSPACING);
1164         gtk_widget_show (vbox);
1165         gtk_container_set_border_width (GTK_CONTAINER (vbox), 0);
1166         gtk_table_attach(GTK_TABLE(table), vbox, 1, 2, 
1167                          rowcount, rowcount + 1, GTK_EXPAND | GTK_FILL, GTK_FILL, 0, 0);
1168
1169         quotefmt_create_new_msg_fmt_widgets(
1170                                 window,
1171                                 vbox,
1172                                 &page->checkbtn_compose_with_format,
1173                                 _("Use a specific format for new messages"),
1174                                 &page->compose_subject_format,
1175                                 &page->compose_body_format,
1176                                 FALSE);
1177
1178         vbox = gtk_vbox_new (FALSE, VSPACING);
1179         gtk_widget_show (vbox);
1180         gtk_container_set_border_width (GTK_CONTAINER (vbox), 0);
1181         gtk_table_attach(GTK_TABLE(table), vbox, 2, 3, 
1182                          rowcount, rowcount + 1, GTK_SHRINK, GTK_FILL, 0, 0);
1183
1184         new_msg_format_rec_checkbtn = gtk_check_button_new();
1185         gtk_box_pack_start (GTK_BOX(vbox), new_msg_format_rec_checkbtn, FALSE, FALSE, 0);
1186         alignment = gtk_alignment_new(0, 1, 0, 0);      
1187         gtk_box_pack_start (GTK_BOX(vbox), alignment, FALSE, FALSE, 0);
1188
1189         rowcount++;
1190
1191         /* reply format */
1192         vbox = gtk_vbox_new (FALSE, VSPACING);
1193         gtk_widget_show (vbox);
1194         gtk_container_set_border_width (GTK_CONTAINER (vbox), 0);
1195         gtk_table_attach(GTK_TABLE(table), vbox, 1, 2, 
1196                          rowcount, rowcount + 1, GTK_EXPAND | GTK_FILL, GTK_FILL, 0, 0);
1197
1198         quotefmt_create_reply_fmt_widgets(
1199                                 window,
1200                                 vbox,
1201                                 &page->checkbtn_reply_with_format,
1202                                 _("Use a specific reply quote format"),
1203                                 &page->reply_quotemark,
1204                                 &page->reply_body_format,
1205                                 FALSE);
1206
1207         vbox = gtk_vbox_new (FALSE, VSPACING);
1208         gtk_widget_show (vbox);
1209         gtk_container_set_border_width (GTK_CONTAINER (vbox), 0);
1210         gtk_table_attach(GTK_TABLE(table), vbox, 2, 3, 
1211                          rowcount, rowcount + 1, GTK_SHRINK, GTK_FILL, 0, 0);
1212
1213         reply_format_rec_checkbtn = gtk_check_button_new();
1214         gtk_box_pack_start (GTK_BOX(vbox), reply_format_rec_checkbtn, FALSE, FALSE, 0);
1215         alignment = gtk_alignment_new(0, 1, 0, 0);      
1216         gtk_box_pack_start (GTK_BOX(vbox), alignment, FALSE, FALSE, 0);
1217
1218         rowcount++;
1219
1220         /* forward format */
1221         vbox = gtk_vbox_new (FALSE, VSPACING);
1222         gtk_widget_show (vbox);
1223         gtk_container_set_border_width (GTK_CONTAINER (vbox), 0);
1224         gtk_table_attach(GTK_TABLE(table), vbox, 1, 2, 
1225                          rowcount, rowcount + 1, GTK_EXPAND | GTK_FILL, GTK_FILL, 0, 0);
1226
1227         quotefmt_create_forward_fmt_widgets(
1228                                 window,
1229                                 vbox,
1230                                 &page->checkbtn_forward_with_format,
1231                                 _("Use a specific forward quote format"),
1232                                 &page->forward_quotemark,
1233                                 &page->forward_body_format,
1234                                 FALSE);
1235
1236         vbox = gtk_vbox_new (FALSE, VSPACING);
1237         gtk_widget_show (vbox);
1238         gtk_container_set_border_width (GTK_CONTAINER (vbox), 0);
1239         gtk_table_attach(GTK_TABLE(table), vbox, 2, 3, 
1240                          rowcount, rowcount + 1, GTK_SHRINK, GTK_FILL, 0, 0);
1241
1242         forward_format_rec_checkbtn = gtk_check_button_new();
1243         gtk_box_pack_start (GTK_BOX(vbox), forward_format_rec_checkbtn, FALSE, FALSE, 0);
1244         alignment = gtk_alignment_new(0, 1, 0, 0);      
1245         gtk_box_pack_start (GTK_BOX(vbox), alignment, FALSE, FALSE, 0);
1246
1247         rowcount++;
1248
1249         /* information button */
1250         vbox = gtk_vbox_new (FALSE, VSPACING);
1251         gtk_widget_show (vbox);
1252         gtk_container_set_border_width (GTK_CONTAINER (vbox), 0);
1253         gtk_table_attach(GTK_TABLE(table), vbox, 1, 2, 
1254                          rowcount, rowcount + 1, GTK_EXPAND | GTK_FILL, GTK_FILL, 0, 0);
1255         rowcount++;
1256         quotefmt_add_info_button(window, vbox);
1257
1258
1259         gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(page->checkbtn_compose_with_format),
1260                         item->prefs->compose_with_format);
1261         pref_set_entry_from_pref(GTK_ENTRY(page->compose_subject_format),
1262                         item->prefs->compose_subject_format);
1263         pref_set_textview_from_pref(GTK_TEXT_VIEW(page->compose_body_format),
1264                         item->prefs->compose_body_format);
1265
1266         gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(page->checkbtn_reply_with_format),
1267                         item->prefs->reply_with_format);
1268         pref_set_entry_from_pref(GTK_ENTRY(page->reply_quotemark),
1269                         item->prefs->reply_quotemark);
1270         pref_set_textview_from_pref(GTK_TEXT_VIEW(page->reply_body_format),
1271                         item->prefs->reply_body_format);
1272
1273         gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(page->checkbtn_forward_with_format),
1274                         item->prefs->forward_with_format);
1275         pref_set_entry_from_pref(GTK_ENTRY(page->forward_quotemark),
1276                         item->prefs->forward_quotemark);
1277         pref_set_textview_from_pref(GTK_TEXT_VIEW(page->forward_body_format),
1278                         item->prefs->forward_body_format);
1279
1280         gtk_widget_show_all(table);
1281
1282         page->window = GTK_WIDGET(window);
1283         page->table = table;
1284
1285         page->new_msg_format_rec_checkbtn = new_msg_format_rec_checkbtn;
1286         page->reply_format_rec_checkbtn = reply_format_rec_checkbtn;
1287         page->forward_format_rec_checkbtn = forward_format_rec_checkbtn;
1288
1289         page->page.widget = table;
1290 }
1291
1292 static void prefs_folder_item_templates_destroy_widget_func(PrefsPage *page_) 
1293 {
1294         /* FolderItemTemplatesPage *page = (FolderItemTemplatesPage *) page_; */
1295 }
1296
1297 /** \brief  Save the prefs in page to folder.
1298  *
1299  *  If the folder is not the one  specified in page->item, then only those properties 
1300  *  that have the relevant 'apply to sub folders' button checked are saved
1301  */
1302 static void templates_save_folder_prefs(FolderItem *folder, FolderItemTemplatesPage *page)
1303 {
1304         FolderItemPrefs *prefs = folder->prefs;
1305         gboolean all = FALSE;
1306
1307         if (folder->path == NULL)
1308                 return;
1309
1310         if (page->item == folder) 
1311                 all = TRUE;
1312
1313         g_return_if_fail(prefs != NULL);
1314
1315         /* save and check formats */
1316
1317         if (all || gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(page->new_msg_format_rec_checkbtn))) {
1318                 prefs->compose_with_format =
1319                         gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(page->checkbtn_compose_with_format));
1320                 prefs->compose_subject_format = pref_get_pref_from_entry(
1321                                 GTK_ENTRY(page->compose_subject_format));
1322                 prefs->compose_body_format = pref_get_pref_from_textview(
1323                                 GTK_TEXT_VIEW(page->compose_body_format));
1324                 quotefmt_check_new_msg_formats(prefs->compose_with_format,
1325                                                                                 prefs->compose_subject_format,
1326                                                                                 prefs->compose_body_format);
1327         }
1328
1329         if (all || gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(page->reply_format_rec_checkbtn))) {
1330                 prefs->reply_with_format =
1331                         gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(page->checkbtn_reply_with_format));
1332                 prefs->reply_quotemark = gtk_editable_get_chars(
1333                                 GTK_EDITABLE(page->reply_quotemark), 0, -1);
1334                 prefs->reply_body_format = pref_get_pref_from_textview(
1335                                 GTK_TEXT_VIEW(page->reply_body_format));
1336                 quotefmt_check_reply_formats(prefs->reply_with_format,
1337                                                                                 prefs->reply_quotemark,
1338                                                                                 prefs->reply_body_format);
1339         }
1340
1341         if (all || gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(page->forward_format_rec_checkbtn))) {
1342                 prefs->forward_with_format =
1343                         gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(page->checkbtn_forward_with_format));
1344                 prefs->forward_quotemark = gtk_editable_get_chars(
1345                                 GTK_EDITABLE(page->forward_quotemark), 0, -1);
1346                 prefs->forward_body_format = pref_get_pref_from_textview(
1347                                 GTK_TEXT_VIEW(page->forward_body_format));
1348                 quotefmt_check_forward_formats(prefs->forward_with_format,
1349                                                                                 prefs->forward_quotemark,
1350                                                                                 prefs->forward_body_format);
1351         }
1352
1353         folder_item_prefs_save_config(folder);
1354 }       
1355
1356 static gboolean templates_save_recurse_func(GNode *node, gpointer data)
1357 {
1358         FolderItem *item = (FolderItem *) node->data;
1359         FolderItemTemplatesPage *page = (FolderItemTemplatesPage *) data;
1360
1361         g_return_val_if_fail(item != NULL, TRUE);
1362         g_return_val_if_fail(page != NULL, TRUE);
1363
1364         templates_save_folder_prefs(item, page);
1365
1366         /* optimise by not continuing if none of the 'apply to sub folders'
1367            check boxes are selected - and optimise the checking by only doing
1368            it once */
1369         if ((node == page->item->node) &&
1370             !(gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(page->new_msg_format_rec_checkbtn)) ||
1371               gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(page->reply_format_rec_checkbtn)) ||
1372               gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(page->forward_format_rec_checkbtn))))
1373                 return TRUE;
1374         else 
1375                 return FALSE;
1376
1377         return FALSE;
1378 }
1379
1380 static void prefs_folder_item_templates_save_func(PrefsPage *page_) 
1381 {
1382         FolderItemTemplatesPage *page = (FolderItemTemplatesPage *) page_;
1383
1384         g_node_traverse(page->item->node, G_PRE_ORDER, G_TRAVERSE_ALL,
1385                         -1, templates_save_recurse_func, page);
1386
1387 }
1388
1389 static gint prefs_folder_item_chmod_mode(gchar *folder_chmod) 
1390 {
1391         gint newmode = 0;
1392         gchar *tmp;
1393
1394         if (folder_chmod) {
1395                 newmode = strtol(folder_chmod, &tmp, 8);
1396                 if (!(*(folder_chmod) && !(*tmp)))
1397                         newmode = 0;
1398         }
1399
1400         return newmode;
1401 }
1402
1403 static void folder_color_set_dialog(GtkWidget *widget, gpointer data)
1404 {
1405         FolderItemGeneralPage *page = (FolderItemGeneralPage *) data;
1406         gint rgbcolor;
1407
1408         rgbcolor = colorsel_select_color_rgb(_("Pick color for folder"), 
1409                                              page->folder_color);
1410         gtkut_set_widget_bgcolor_rgb(page->folder_color_btn, rgbcolor);
1411         page->folder_color = rgbcolor;
1412 }
1413
1414 static regex_t *summary_compile_simplify_regexp(gchar *simplify_subject_regexp)
1415 {
1416         int err;
1417         gchar buf[BUFFSIZE];
1418         regex_t *preg = NULL;
1419
1420         preg = g_new0(regex_t, 1);
1421
1422         err = string_match_precompile(simplify_subject_regexp, 
1423                                       preg, REG_EXTENDED);
1424         if (err) {
1425                 regerror(err, preg, buf, BUFFSIZE);
1426                 g_free(preg);
1427                 preg = NULL;
1428         }
1429
1430         return preg;
1431 }
1432
1433 static void folder_regexp_test_cb(GtkWidget *widget, gpointer data)
1434 {
1435         static GdkColor red;
1436         static gboolean colors_initialised = FALSE;
1437         static gchar buf[BUFFSIZE];
1438         FolderItemGeneralPage *page = (FolderItemGeneralPage *)data;
1439         gchar *test_string, *regexp;
1440         regex_t *preg;
1441
1442         regexp = g_strdup(gtk_entry_get_text(GTK_ENTRY(page->entry_simplify_subject)));
1443         test_string = g_strdup(gtk_entry_get_text(GTK_ENTRY(page->entry_regexp_test_string)));
1444
1445         if (!regexp || !regexp[0]) {
1446                 gtk_widget_modify_base(page->entry_simplify_subject,
1447                                 GTK_STATE_NORMAL, NULL);
1448                 if (test_string) {
1449                         gtk_entry_set_text(GTK_ENTRY(page->entry_regexp_test_result), test_string);
1450                         g_free(test_string);
1451                 }
1452                 return;
1453         }
1454
1455         if (!test_string || !test_string[0]) {
1456                 g_free(regexp);
1457                 return;
1458         }
1459
1460         if (!colors_initialised) {
1461                 gdk_color_parse("#ff7070", &red);
1462                 colors_initialised = gdk_colormap_alloc_color(
1463                         gdk_colormap_get_system(), &red, FALSE, TRUE);
1464         }
1465
1466         preg = summary_compile_simplify_regexp(regexp);
1467         if (colors_initialised) {
1468                 gtk_widget_modify_base(page->entry_simplify_subject,
1469                                 GTK_STATE_NORMAL, preg ? NULL : &red);
1470         }
1471
1472         if (preg != NULL) {
1473                 string_remove_match(buf, BUFFSIZE, test_string, preg);
1474
1475                 gtk_entry_set_text(GTK_ENTRY(page->entry_regexp_test_result), buf);
1476
1477                 regfree(preg);
1478                 g_free(preg);
1479         }
1480
1481         g_free(test_string);
1482         g_free(regexp);
1483 }
1484
1485 static gchar *folder_regexp_get_subject_example(void)
1486 {
1487         MsgInfo *msginfo_selected;
1488         SummaryView *summaryview = NULL;
1489
1490         if (!mainwindow_get_mainwindow())
1491                 return NULL;
1492         summaryview = mainwindow_get_mainwindow()->summaryview;
1493
1494         msginfo_selected = summary_get_selected_msg(summaryview);
1495         return msginfo_selected ? g_strdup(msginfo_selected->subject) : NULL;
1496 }
1497
1498 static void folder_regexp_set_subject_example_cb(GtkWidget *widget, gpointer data)
1499 {
1500         FolderItemGeneralPage *page = (FolderItemGeneralPage *)data;
1501
1502         if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(page->checkbtn_simplify_subject))) {
1503                 gchar *subject = folder_regexp_get_subject_example();
1504                 if (subject) {
1505                         gtk_entry_set_text(GTK_ENTRY(page->entry_regexp_test_string), subject);
1506                         g_free(subject);
1507                 }
1508         }
1509 }
1510
1511 static void register_general_page()
1512 {
1513         static gchar *pfi_general_path[2];
1514         static FolderItemGeneralPage folder_item_general_page;
1515
1516         pfi_general_path[0] = _("General");
1517         pfi_general_path[1] = NULL;
1518
1519         folder_item_general_page.page.path = pfi_general_path;
1520         folder_item_general_page.page.create_widget = prefs_folder_item_general_create_widget_func;
1521         folder_item_general_page.page.destroy_widget = prefs_folder_item_general_destroy_widget_func;
1522         folder_item_general_page.page.save_page = prefs_folder_item_general_save_func;
1523         
1524         prefs_folder_item_register_page((PrefsPage *) &folder_item_general_page);
1525 }
1526
1527
1528 static void register_compose_page(void)
1529 {
1530         static gchar *pfi_compose_path[2];
1531         static FolderItemComposePage folder_item_compose_page;
1532
1533         pfi_compose_path[0] = _("Compose");
1534         pfi_compose_path[1] = NULL;
1535
1536         folder_item_compose_page.page.path = pfi_compose_path;
1537         folder_item_compose_page.page.create_widget = prefs_folder_item_compose_create_widget_func;
1538         folder_item_compose_page.page.destroy_widget = prefs_folder_item_compose_destroy_widget_func;
1539         folder_item_compose_page.page.save_page = prefs_folder_item_compose_save_func;
1540         
1541         prefs_folder_item_register_page((PrefsPage *) &folder_item_compose_page);
1542 }
1543
1544 static void register_templates_page(void)
1545 {
1546         static gchar *pfi_templates_path[2];
1547         static FolderItemTemplatesPage folder_item_templates_page;
1548
1549         pfi_templates_path[0] = _("Templates");
1550         pfi_templates_path[1] = NULL;
1551
1552         folder_item_templates_page.page.path = pfi_templates_path;
1553         folder_item_templates_page.page.create_widget = prefs_folder_item_templates_create_widget_func;
1554         folder_item_templates_page.page.destroy_widget = prefs_folder_item_templates_destroy_widget_func;
1555         folder_item_templates_page.page.save_page = prefs_folder_item_templates_save_func;
1556         
1557         prefs_folder_item_register_page((PrefsPage *) &folder_item_templates_page);
1558 }
1559
1560 static GSList *prefs_pages = NULL;
1561
1562 void prefs_folder_item_open(FolderItem *item)
1563 {
1564         gchar *id, *title;
1565         if (prefs_pages == NULL) {
1566                 register_general_page();
1567                 register_compose_page();
1568                 register_templates_page();
1569         }
1570
1571         if (item->path) {
1572                 id = folder_item_get_identifier (item);
1573                 can_save = TRUE;
1574         } else {
1575                 id = g_strdup(item->name);
1576                 can_save = FALSE;
1577         }
1578         title = g_strdup_printf (_("Properties for folder %s"), id);
1579         g_free (id);
1580         prefswindow_open(title, prefs_pages, item,
1581                         &prefs_common.folderitemwin_width, &prefs_common.folderitemwin_height);
1582         
1583         g_free (title);
1584 }
1585
1586 void prefs_folder_item_register_page(PrefsPage *page)
1587 {
1588         prefs_pages = g_slist_append(prefs_pages, page);
1589 }
1590
1591 void prefs_folder_item_unregister_page(PrefsPage *page)
1592 {
1593         prefs_pages = g_slist_remove(prefs_pages, page);
1594 }