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