2008-09-17 [colin] 3.5.0cvs112
[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 (item->prefs->default_dictionary &&
943             strchr(item->prefs->default_dictionary, '-')) {
944                 *(strchr(item->prefs->default_dictionary, '-')) = '\0';
945         }
946         if (dictionary)
947                 gtkaspell_set_dictionary_menu_active_item(
948                         GTK_COMBO_BOX(combo_default_dictionary), dictionary);
949
950         SET_TOGGLE_SENSITIVITY(checkbtn_enable_default_dictionary, combo_default_dictionary);
951
952         default_dictionary_rec_checkbtn = gtk_check_button_new();
953         gtk_table_attach(GTK_TABLE(table), default_dictionary_rec_checkbtn, 2, 3, 
954                          rowcount, rowcount + 1, GTK_SHRINK, GTK_SHRINK, 0, 0);
955         
956         rowcount++;
957
958         /* Default dictionary */
959         checkbtn_enable_default_alt_dictionary = gtk_check_button_new_with_label(_("Default alternate dictionary"));
960         gtk_table_attach(GTK_TABLE(table), checkbtn_enable_default_alt_dictionary, 0, 1,
961                          rowcount, rowcount + 1, GTK_SHRINK | GTK_FILL, GTK_SHRINK, 0, 0);
962         gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(checkbtn_enable_default_alt_dictionary),
963                                      item->prefs->enable_default_alt_dictionary);
964
965         combo_default_alt_dictionary = gtkaspell_dictionary_combo_new(FALSE);
966         gtk_table_attach(GTK_TABLE(table), combo_default_alt_dictionary, 1, 2,
967                          rowcount, rowcount + 1, GTK_EXPAND | GTK_FILL, GTK_SHRINK, 0, 0);
968
969         dictionary = item->prefs->default_alt_dictionary;
970         if (dictionary && strrchr(dictionary, '/')) {
971                 gchar *tmp = g_strdup(strrchr(dictionary, '/')+1);
972                 g_free(item->prefs->default_alt_dictionary);
973                 item->prefs->default_alt_dictionary = tmp;
974                 dictionary = item->prefs->default_alt_dictionary;
975         }
976         if (item->prefs->default_alt_dictionary &&
977             strchr(item->prefs->default_alt_dictionary, '-')) {
978                 *(strchr(item->prefs->default_alt_dictionary, '-')) = '\0';
979         }
980         if (dictionary)
981                 gtkaspell_set_dictionary_menu_active_item(
982                         GTK_COMBO_BOX(combo_default_alt_dictionary), dictionary);
983
984         SET_TOGGLE_SENSITIVITY(checkbtn_enable_default_alt_dictionary, combo_default_alt_dictionary);
985
986         default_alt_dictionary_rec_checkbtn = gtk_check_button_new();
987         gtk_table_attach(GTK_TABLE(table), default_alt_dictionary_rec_checkbtn, 2, 3, 
988                          rowcount, rowcount + 1, GTK_SHRINK, GTK_SHRINK, 0, 0);
989         
990         rowcount++;
991 #endif
992
993         gtk_widget_show_all(table);
994
995         page->window = GTK_WIDGET(window);
996         page->table = table;
997         page->no_save_warning = no_save_warning;
998         page->checkbtn_request_return_receipt = checkbtn_request_return_receipt;
999         page->checkbtn_save_copy_to_folder = checkbtn_save_copy_to_folder;
1000         page->checkbtn_default_to = checkbtn_default_to;
1001         page->entry_default_to = entry_default_to;
1002         page->checkbtn_default_reply_to = checkbtn_default_reply_to;
1003         page->entry_default_reply_to = entry_default_reply_to;
1004         page->checkbtn_enable_default_account = checkbtn_enable_default_account;
1005         page->optmenu_default_account = optmenu_default_account;
1006 #ifdef USE_ENCHANT
1007         page->checkbtn_enable_default_dictionary = checkbtn_enable_default_dictionary;
1008         page->combo_default_dictionary = combo_default_dictionary;
1009         page->checkbtn_enable_default_alt_dictionary = checkbtn_enable_default_alt_dictionary;
1010         page->combo_default_alt_dictionary = combo_default_alt_dictionary;
1011 #endif
1012
1013         page->request_return_receipt_rec_checkbtn = request_return_receipt_rec_checkbtn;
1014         page->save_copy_to_folder_rec_checkbtn    = save_copy_to_folder_rec_checkbtn;
1015         page->default_to_rec_checkbtn             = default_to_rec_checkbtn;
1016         page->default_reply_to_rec_checkbtn       = default_reply_to_rec_checkbtn;
1017         page->default_account_rec_checkbtn        = default_account_rec_checkbtn;
1018 #if USE_ENCHANT
1019         page->default_dictionary_rec_checkbtn = default_dictionary_rec_checkbtn;
1020         page->default_alt_dictionary_rec_checkbtn = default_alt_dictionary_rec_checkbtn;
1021 #endif
1022
1023         page->page.widget = table;
1024 }
1025
1026 static void prefs_folder_item_compose_destroy_widget_func(PrefsPage *page_) 
1027 {
1028         FolderItemComposePage *page = (FolderItemComposePage *) page_;
1029
1030         if (page->entry_default_to)
1031                 address_completion_unregister_entry(GTK_ENTRY(page->entry_default_to));
1032         if (page->entry_default_reply_to)
1033                 address_completion_unregister_entry(GTK_ENTRY(page->entry_default_reply_to));
1034 }
1035
1036 /** \brief  Save the prefs in page to folder.
1037  *
1038  *  If the folder is not the one  specified in page->item, then only those properties 
1039  *  that have the relevant 'apply to sub folders' button checked are saved
1040  */
1041 static void compose_save_folder_prefs(FolderItem *folder, FolderItemComposePage *page)
1042 {
1043         FolderItemPrefs *prefs = folder->prefs;
1044
1045         gboolean all = FALSE;
1046
1047         if (folder->path == NULL)
1048                 return;
1049
1050         if (page->item == folder) 
1051                 all = TRUE;
1052
1053         g_return_if_fail(prefs != NULL);
1054
1055         if (item_protocol(folder) != A_NNTP) {
1056                 if (all || gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(page->request_return_receipt_rec_checkbtn))) {
1057                         prefs->request_return_receipt = 
1058                                 gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(page->checkbtn_request_return_receipt));
1059                         /* MIGRATION */    
1060                         folder->ret_rcpt = prefs->request_return_receipt;
1061                 }
1062
1063                 if (all || gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(page->save_copy_to_folder_rec_checkbtn))) {
1064                         prefs->save_copy_to_folder = 
1065                                 gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(page->checkbtn_save_copy_to_folder));
1066                 }
1067
1068                 if (all || gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(page->default_to_rec_checkbtn))) {
1069
1070                         prefs->enable_default_to = 
1071                                 gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(page->checkbtn_default_to));
1072                         ASSIGN_STRING(prefs->default_to,
1073                                       gtk_editable_get_chars(GTK_EDITABLE(page->entry_default_to), 0, -1));
1074                 }
1075
1076                 if (all || gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(page->default_reply_to_rec_checkbtn))) {
1077                         prefs->enable_default_reply_to = 
1078                                 gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(page->checkbtn_default_reply_to));
1079                         ASSIGN_STRING(prefs->default_reply_to,
1080                                       gtk_editable_get_chars(GTK_EDITABLE(page->entry_default_reply_to), 0, -1));
1081                 }
1082         } else {
1083                 prefs->request_return_receipt = FALSE;
1084                 prefs->save_copy_to_folder = FALSE;
1085                 prefs->enable_default_to = FALSE;
1086                 prefs->enable_default_reply_to = FALSE;
1087         }
1088
1089         if (all || gtk_toggle_button_get_active(
1090                                 GTK_TOGGLE_BUTTON(page->default_account_rec_checkbtn))) {
1091                 prefs->enable_default_account = 
1092                         gtk_toggle_button_get_active(
1093                                         GTK_TOGGLE_BUTTON(page->checkbtn_enable_default_account));
1094                 prefs->default_account = combobox_get_active_data(
1095                                 GTK_COMBO_BOX(page->optmenu_default_account));
1096         }
1097
1098 #if USE_ENCHANT
1099         if (all || gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(page->default_dictionary_rec_checkbtn))) {
1100                 prefs->enable_default_dictionary =
1101                         gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(page->checkbtn_enable_default_dictionary));
1102                 ASSIGN_STRING(prefs->default_dictionary,
1103                               gtkaspell_get_dictionary_menu_active_item(
1104                                         GTK_COMBO_BOX(page->combo_default_dictionary)));
1105         }
1106         if (all || gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(page->default_alt_dictionary_rec_checkbtn))) {
1107                 prefs->enable_default_alt_dictionary =
1108                         gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(page->checkbtn_enable_default_alt_dictionary));
1109                 ASSIGN_STRING(prefs->default_alt_dictionary,
1110                               gtkaspell_get_dictionary_menu_active_item(
1111                                       GTK_COMBO_BOX(page->combo_default_alt_dictionary)));
1112         }
1113 #endif
1114
1115         folder_item_prefs_save_config(folder);
1116 }       
1117
1118 static gboolean compose_save_recurse_func(GNode *node, gpointer data)
1119 {
1120         FolderItem *item = (FolderItem *) node->data;
1121         FolderItemComposePage *page = (FolderItemComposePage *) data;
1122
1123         g_return_val_if_fail(item != NULL, TRUE);
1124         g_return_val_if_fail(page != NULL, TRUE);
1125
1126         compose_save_folder_prefs(item, page);
1127
1128         /* optimise by not continuing if none of the 'apply to sub folders'
1129            check boxes are selected - and optimise the checking by only doing
1130            it once */
1131         if ((node == page->item->node) && item_protocol(item) != A_NNTP &&
1132             !(gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(page->request_return_receipt_rec_checkbtn)) ||
1133               gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(page->save_copy_to_folder_rec_checkbtn)) ||
1134               gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(page->default_to_rec_checkbtn)) ||
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               gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(page->default_reply_to_rec_checkbtn))))
1141                 return TRUE;
1142         else if ((node == page->item->node) && item_protocol(item) == A_NNTP &&
1143             !(gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(page->default_account_rec_checkbtn)) 
1144 #if USE_ENCHANT
1145               || gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(page->default_dictionary_rec_checkbtn))
1146               || gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(page->default_alt_dictionary_rec_checkbtn))
1147 #endif
1148                     ))
1149                 return TRUE;
1150         else 
1151                 return FALSE;
1152 }
1153
1154 static void prefs_folder_item_compose_save_func(PrefsPage *page_) 
1155 {
1156         FolderItemComposePage *page = (FolderItemComposePage *) page_;
1157
1158         g_node_traverse(page->item->node, G_PRE_ORDER, G_TRAVERSE_ALL,
1159                         -1, compose_save_recurse_func, page);
1160
1161 }
1162
1163 static void prefs_folder_item_templates_create_widget_func(PrefsPage * page_,
1164                                                    GtkWindow * window,
1165                                                    gpointer data)
1166 {
1167         FolderItemTemplatesPage *page = (FolderItemTemplatesPage *) page_;
1168         FolderItem *item = (FolderItem *) data;
1169
1170         GtkWidget *notebook;
1171         GtkWidget *vbox;
1172         GtkWidget *page_vbox;
1173         GtkWidget *no_save_warning;
1174         GtkWidget *new_msg_format_rec_checkbtn;
1175         GtkWidget *reply_format_rec_checkbtn;
1176         GtkWidget *forward_format_rec_checkbtn;
1177
1178         page->item = item;
1179
1180         page_vbox = gtk_vbox_new (FALSE, 0);
1181         gtk_widget_show (page_vbox);
1182         
1183         if (!can_save) {
1184                 no_save_warning = gtk_label_new(
1185                         _("<i>These preferences will not be saved as this folder "
1186                         "is a top-level one. However you can use them to set them "
1187                         "to the whole mailbox tree using \"Apply to subfolders\".</i>"));
1188                 gtk_label_set_use_markup(GTK_LABEL(no_save_warning), TRUE);
1189                 gtk_label_set_line_wrap(GTK_LABEL(no_save_warning), TRUE);
1190                 gtk_misc_set_alignment(GTK_MISC(no_save_warning), 0.0, 0.5);
1191                 gtk_box_pack_start(GTK_BOX(page_vbox), no_save_warning, FALSE, FALSE, 4);
1192         }
1193
1194         /* Notebook */
1195         notebook = gtk_notebook_new();
1196         gtk_widget_show(notebook);
1197         gtk_box_pack_start(GTK_BOX(page_vbox), notebook, TRUE, TRUE, 0);
1198
1199         /* compose format */
1200         vbox = gtk_vbox_new (FALSE, VSPACING);
1201         gtk_widget_show (vbox);
1202         gtk_container_set_border_width (GTK_CONTAINER (vbox), VBOX_BORDER);
1203
1204         quotefmt_create_new_msg_fmt_widgets(
1205                                 window,
1206                                 vbox,
1207                                 &page->checkbtn_compose_with_format,
1208                                 &page->compose_override_from_format,
1209                                 &page->compose_subject_format,
1210                                 &page->compose_body_format,
1211                                 FALSE, FALSE);
1212         address_completion_register_entry(GTK_ENTRY(page->compose_override_from_format),
1213                         TRUE);
1214
1215         new_msg_format_rec_checkbtn = gtk_check_button_new_with_label(
1216                         _("Apply to subfolders"));
1217         gtk_box_pack_end (GTK_BOX(vbox), new_msg_format_rec_checkbtn, FALSE, FALSE, 0);
1218         gtk_notebook_append_page(GTK_NOTEBOOK(notebook), vbox, gtk_label_new(_("Compose")));
1219
1220         /* reply format */
1221         vbox = gtk_vbox_new (FALSE, VSPACING);
1222         gtk_widget_show (vbox);
1223         gtk_container_set_border_width (GTK_CONTAINER (vbox), VBOX_BORDER);
1224
1225         quotefmt_create_reply_fmt_widgets(
1226                                 window,
1227                                 vbox,
1228                                 &page->checkbtn_reply_with_format,
1229                                 &page->reply_override_from_format,
1230                                 &page->reply_quotemark,
1231                                 &page->reply_body_format,
1232                                 FALSE, FALSE);
1233         address_completion_register_entry(GTK_ENTRY(page->reply_override_from_format),
1234                         TRUE);
1235
1236         reply_format_rec_checkbtn = gtk_check_button_new_with_label(
1237                         _("Apply to subfolders"));
1238         gtk_box_pack_end (GTK_BOX(vbox), reply_format_rec_checkbtn, FALSE, FALSE, 0);
1239         gtk_notebook_append_page(GTK_NOTEBOOK(notebook), vbox, gtk_label_new(_("Reply")));
1240
1241         /* forward format */
1242         vbox = gtk_vbox_new (FALSE, VSPACING);
1243         gtk_widget_show (vbox);
1244         gtk_container_set_border_width (GTK_CONTAINER (vbox), VBOX_BORDER);
1245
1246         quotefmt_create_forward_fmt_widgets(
1247                                 window,
1248                                 vbox,
1249                                 &page->checkbtn_forward_with_format,
1250                                 &page->forward_override_from_format,
1251                                 &page->forward_quotemark,
1252                                 &page->forward_body_format,
1253                                 FALSE, FALSE);
1254         address_completion_register_entry(GTK_ENTRY(page->forward_override_from_format),
1255                         TRUE);
1256
1257         forward_format_rec_checkbtn = gtk_check_button_new_with_label(
1258                         _("Apply to subfolders"));
1259         gtk_box_pack_end (GTK_BOX(vbox), forward_format_rec_checkbtn, FALSE, FALSE, 0);
1260         gtk_notebook_append_page(GTK_NOTEBOOK(notebook), vbox, gtk_label_new(_("Forward")));
1261
1262         /* information button */
1263         quotefmt_add_info_button(window, page_vbox);
1264
1265         gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(page->checkbtn_compose_with_format),
1266                         item->prefs->compose_with_format);
1267         pref_set_entry_from_pref(GTK_ENTRY(page->compose_override_from_format),
1268                         item->prefs->compose_override_from_format);
1269         pref_set_entry_from_pref(GTK_ENTRY(page->compose_subject_format),
1270                         item->prefs->compose_subject_format);
1271         pref_set_textview_from_pref(GTK_TEXT_VIEW(page->compose_body_format),
1272                         item->prefs->compose_body_format);
1273
1274         gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(page->checkbtn_reply_with_format),
1275                         item->prefs->reply_with_format);
1276         pref_set_entry_from_pref(GTK_ENTRY(page->reply_quotemark),
1277                         item->prefs->reply_quotemark);
1278         pref_set_entry_from_pref(GTK_ENTRY(page->reply_override_from_format),
1279                         item->prefs->reply_override_from_format);
1280         pref_set_textview_from_pref(GTK_TEXT_VIEW(page->reply_body_format),
1281                         item->prefs->reply_body_format);
1282
1283         gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(page->checkbtn_forward_with_format),
1284                         item->prefs->forward_with_format);
1285         pref_set_entry_from_pref(GTK_ENTRY(page->forward_quotemark),
1286                         item->prefs->forward_quotemark);
1287         pref_set_entry_from_pref(GTK_ENTRY(page->forward_override_from_format),
1288                         item->prefs->forward_override_from_format);
1289         pref_set_textview_from_pref(GTK_TEXT_VIEW(page->forward_body_format),
1290                         item->prefs->forward_body_format);
1291
1292         gtk_widget_show_all(page_vbox);
1293
1294         page->window = GTK_WIDGET(window);
1295
1296         page->new_msg_format_rec_checkbtn = new_msg_format_rec_checkbtn;
1297         page->reply_format_rec_checkbtn = reply_format_rec_checkbtn;
1298         page->forward_format_rec_checkbtn = forward_format_rec_checkbtn;
1299
1300         page->page.widget = page_vbox;
1301 }
1302
1303 static void prefs_folder_item_templates_destroy_widget_func(PrefsPage *page_) 
1304 {
1305         FolderItemTemplatesPage *page = (FolderItemTemplatesPage *) page_;
1306
1307         if (page->compose_override_from_format)
1308                 address_completion_unregister_entry(GTK_ENTRY(page->compose_override_from_format));             
1309         if (page->reply_override_from_format)
1310                 address_completion_unregister_entry(GTK_ENTRY(page->reply_override_from_format));               
1311         if (page->forward_override_from_format)
1312                 address_completion_unregister_entry(GTK_ENTRY(page->forward_override_from_format));             
1313 }
1314
1315 /** \brief  Save the prefs in page to folder.
1316  *
1317  *  If the folder is not the one  specified in page->item, then only those properties 
1318  *  that have the relevant 'apply to sub folders' button checked are saved
1319  */
1320 static void templates_save_folder_prefs(FolderItem *folder, FolderItemTemplatesPage *page)
1321 {
1322         FolderItemPrefs *prefs = folder->prefs;
1323         gboolean all = FALSE;
1324
1325         if (folder->path == NULL)
1326                 return;
1327
1328         if (page->item == folder) 
1329                 all = TRUE;
1330
1331         g_return_if_fail(prefs != NULL);
1332
1333         /* save and check formats */
1334
1335         if (all || gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(page->new_msg_format_rec_checkbtn))) {
1336                 
1337                 prefs->compose_with_format =
1338                         gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(page->checkbtn_compose_with_format));
1339                 prefs->compose_override_from_format = pref_get_pref_from_entry(
1340                                 GTK_ENTRY(page->compose_override_from_format));
1341                 prefs->compose_subject_format = pref_get_pref_from_entry(
1342                                 GTK_ENTRY(page->compose_subject_format));
1343                 prefs->compose_body_format = pref_get_pref_from_textview(
1344                                 GTK_TEXT_VIEW(page->compose_body_format));
1345                 quotefmt_check_new_msg_formats(prefs->compose_with_format,
1346                                                 prefs->compose_override_from_format,
1347                                                 prefs->compose_subject_format,
1348                                                 prefs->compose_body_format);
1349         }
1350
1351         if (all || gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(page->reply_format_rec_checkbtn))) {
1352                 prefs->reply_with_format =
1353                         gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(page->checkbtn_reply_with_format));
1354                 prefs->reply_quotemark = gtk_editable_get_chars(
1355                                 GTK_EDITABLE(page->reply_quotemark), 0, -1);
1356                 prefs->reply_override_from_format = pref_get_pref_from_entry(
1357                                 GTK_ENTRY(page->reply_override_from_format));
1358                 prefs->reply_body_format = pref_get_pref_from_textview(
1359                                 GTK_TEXT_VIEW(page->reply_body_format));
1360                 quotefmt_check_reply_formats(prefs->reply_with_format,
1361                                                                                 prefs->reply_override_from_format,
1362                                                                                 prefs->reply_quotemark,
1363                                                                                 prefs->reply_body_format);
1364         }
1365
1366         if (all || gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(page->forward_format_rec_checkbtn))) {
1367                 prefs->forward_with_format =
1368                         gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(page->checkbtn_forward_with_format));
1369                 prefs->forward_quotemark = gtk_editable_get_chars(
1370                                 GTK_EDITABLE(page->forward_quotemark), 0, -1);
1371                 prefs->forward_override_from_format = pref_get_pref_from_entry(
1372                                 GTK_ENTRY(page->forward_override_from_format));
1373                 prefs->forward_body_format = pref_get_pref_from_textview(
1374                                 GTK_TEXT_VIEW(page->forward_body_format));
1375                 quotefmt_check_forward_formats(prefs->forward_with_format,
1376                                                                                 prefs->forward_override_from_format,
1377                                                                                 prefs->forward_quotemark,
1378                                                                                 prefs->forward_body_format);
1379         }
1380
1381         folder_item_prefs_save_config(folder);
1382 }       
1383
1384 static gboolean templates_save_recurse_func(GNode *node, gpointer data)
1385 {
1386         FolderItem *item = (FolderItem *) node->data;
1387         FolderItemTemplatesPage *page = (FolderItemTemplatesPage *) data;
1388
1389         g_return_val_if_fail(item != NULL, TRUE);
1390         g_return_val_if_fail(page != NULL, TRUE);
1391
1392         templates_save_folder_prefs(item, page);
1393
1394         /* optimise by not continuing if none of the 'apply to sub folders'
1395            check boxes are selected - and optimise the checking by only doing
1396            it once */
1397         if ((node == page->item->node) &&
1398             !(gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(page->new_msg_format_rec_checkbtn)) ||
1399               gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(page->reply_format_rec_checkbtn)) ||
1400               gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(page->forward_format_rec_checkbtn))))
1401                 return TRUE;
1402         else 
1403                 return FALSE;
1404
1405         return FALSE;
1406 }
1407
1408 static void prefs_folder_item_templates_save_func(PrefsPage *page_) 
1409 {
1410         FolderItemTemplatesPage *page = (FolderItemTemplatesPage *) page_;
1411
1412         g_node_traverse(page->item->node, G_PRE_ORDER, G_TRAVERSE_ALL,
1413                         -1, templates_save_recurse_func, page);
1414
1415 }
1416
1417 static gint prefs_folder_item_chmod_mode(gchar *folder_chmod) 
1418 {
1419         gint newmode = 0;
1420         gchar *tmp;
1421
1422         if (folder_chmod) {
1423                 newmode = strtol(folder_chmod, &tmp, 8);
1424                 if (!(*(folder_chmod) && !(*tmp)))
1425                         newmode = 0;
1426         }
1427
1428         return newmode;
1429 }
1430
1431 static void folder_color_set_dialog(GtkWidget *widget, gpointer data)
1432 {
1433         FolderItemGeneralPage *page = (FolderItemGeneralPage *) data;
1434         gint rgbcolor;
1435
1436         rgbcolor = colorsel_select_color_rgb(_("Pick color for folder"), 
1437                                              page->folder_color);
1438         gtkut_set_widget_bgcolor_rgb(page->folder_color_btn, rgbcolor);
1439         page->folder_color = rgbcolor;
1440 }
1441
1442 static void clean_cache_cb(GtkWidget *widget, gpointer data)
1443 {
1444         FolderItemGeneralPage *page = (FolderItemGeneralPage *) data;
1445         FolderItem *item = page->item;
1446         gboolean was_open = FALSE;
1447         FolderView *folderview = NULL;
1448
1449         if (alertpanel_full(_("Discard cache"), 
1450                             _("Do you really want to discard the local cached "
1451                               "data for this folder?"),
1452                                  GTK_STOCK_CANCEL, _("+Discard"), NULL, FALSE,
1453                                  NULL, ALERT_WARNING, G_ALERTDEFAULT)
1454                 != G_ALERTALTERNATE)
1455                 return;
1456         
1457         if (mainwindow_get_mainwindow())
1458                 folderview = mainwindow_get_mainwindow()->folderview;
1459
1460         if (folderview && item->opened) {
1461                 folderview_close_opened(folderview);
1462                 was_open = TRUE;
1463         }
1464         folder_item_discard_cache(item);
1465         if (was_open)
1466                 folderview_select(folderview,item);
1467 }
1468
1469 static regex_t *summary_compile_simplify_regexp(gchar *simplify_subject_regexp)
1470 {
1471         int err;
1472         gchar buf[BUFFSIZE];
1473         regex_t *preg = NULL;
1474
1475         preg = g_new0(regex_t, 1);
1476
1477         err = string_match_precompile(simplify_subject_regexp, 
1478                                       preg, REG_EXTENDED);
1479         if (err) {
1480                 regerror(err, preg, buf, BUFFSIZE);
1481                 g_free(preg);
1482                 preg = NULL;
1483         }
1484
1485         return preg;
1486 }
1487
1488 static void folder_regexp_test_cb(GtkWidget *widget, gpointer data)
1489 {
1490         static GdkColor red;
1491         static gboolean colors_initialised = FALSE;
1492         static gchar buf[BUFFSIZE];
1493         FolderItemGeneralPage *page = (FolderItemGeneralPage *)data;
1494         gchar *test_string, *regexp;
1495         regex_t *preg;
1496
1497         regexp = g_strdup(gtk_entry_get_text(GTK_ENTRY(page->entry_simplify_subject)));
1498         test_string = g_strdup(gtk_entry_get_text(GTK_ENTRY(page->entry_regexp_test_string)));
1499
1500         if (!regexp || !regexp[0]) {
1501                 gtk_widget_modify_base(page->entry_simplify_subject,
1502                                 GTK_STATE_NORMAL, NULL);
1503                 if (test_string) {
1504                         gtk_entry_set_text(GTK_ENTRY(page->entry_regexp_test_result), test_string);
1505                         g_free(test_string);
1506                 }
1507                 return;
1508         }
1509
1510         if (!test_string || !test_string[0]) {
1511                 g_free(regexp);
1512                 return;
1513         }
1514
1515         if (!colors_initialised) {
1516                 gdk_color_parse("#ff7070", &red);
1517                 colors_initialised = gdk_colormap_alloc_color(
1518                         gdk_colormap_get_system(), &red, FALSE, TRUE);
1519         }
1520
1521         preg = summary_compile_simplify_regexp(regexp);
1522         if (colors_initialised) {
1523                 gtk_widget_modify_base(page->entry_simplify_subject,
1524                                 GTK_STATE_NORMAL, preg ? NULL : &red);
1525         }
1526
1527         if (preg != NULL) {
1528                 string_remove_match(buf, BUFFSIZE, test_string, preg);
1529
1530                 gtk_entry_set_text(GTK_ENTRY(page->entry_regexp_test_result), buf);
1531
1532                 regfree(preg);
1533                 g_free(preg);
1534         }
1535
1536         g_free(test_string);
1537         g_free(regexp);
1538 }
1539
1540 static gchar *folder_regexp_get_subject_example(void)
1541 {
1542         MsgInfo *msginfo_selected;
1543         SummaryView *summaryview = NULL;
1544
1545         if (!mainwindow_get_mainwindow())
1546                 return NULL;
1547         summaryview = mainwindow_get_mainwindow()->summaryview;
1548
1549         msginfo_selected = summary_get_selected_msg(summaryview);
1550         return msginfo_selected ? g_strdup(msginfo_selected->subject) : NULL;
1551 }
1552
1553 static void folder_regexp_set_subject_example_cb(GtkWidget *widget, gpointer data)
1554 {
1555         FolderItemGeneralPage *page = (FolderItemGeneralPage *)data;
1556
1557         if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(page->checkbtn_simplify_subject))) {
1558                 gchar *subject = folder_regexp_get_subject_example();
1559                 if (subject) {
1560                         gtk_entry_set_text(GTK_ENTRY(page->entry_regexp_test_string), subject);
1561                         g_free(subject);
1562                 }
1563         }
1564 }
1565
1566 static void register_general_page()
1567 {
1568         static gchar *pfi_general_path[3];
1569         static FolderItemGeneralPage folder_item_general_page;
1570
1571         pfi_general_path[0] = _("Folder");
1572         pfi_general_path[1] = _("General");
1573         pfi_general_path[2] = NULL;
1574
1575         folder_item_general_page.page.path = pfi_general_path;
1576         folder_item_general_page.page.create_widget = prefs_folder_item_general_create_widget_func;
1577         folder_item_general_page.page.destroy_widget = prefs_folder_item_general_destroy_widget_func;
1578         folder_item_general_page.page.save_page = prefs_folder_item_general_save_func;
1579         
1580         prefs_folder_item_register_page((PrefsPage *) &folder_item_general_page);
1581 }
1582
1583
1584 static void register_compose_page(void)
1585 {
1586         static gchar *pfi_compose_path[3];
1587         static FolderItemComposePage folder_item_compose_page;
1588
1589         pfi_compose_path[0] = _("Folder");
1590         pfi_compose_path[1] = _("Compose");
1591         pfi_compose_path[2] = NULL;
1592
1593         folder_item_compose_page.page.path = pfi_compose_path;
1594         folder_item_compose_page.page.create_widget = prefs_folder_item_compose_create_widget_func;
1595         folder_item_compose_page.page.destroy_widget = prefs_folder_item_compose_destroy_widget_func;
1596         folder_item_compose_page.page.save_page = prefs_folder_item_compose_save_func;
1597         
1598         prefs_folder_item_register_page((PrefsPage *) &folder_item_compose_page);
1599 }
1600
1601 static void register_templates_page(void)
1602 {
1603         static gchar *pfi_templates_path[3];
1604         static FolderItemTemplatesPage folder_item_templates_page;
1605
1606         pfi_templates_path[0] = _("Folder");
1607         pfi_templates_path[1] = _("Templates");
1608         pfi_templates_path[2] = NULL;
1609
1610         folder_item_templates_page.page.path = pfi_templates_path;
1611         folder_item_templates_page.page.create_widget = prefs_folder_item_templates_create_widget_func;
1612         folder_item_templates_page.page.destroy_widget = prefs_folder_item_templates_destroy_widget_func;
1613         folder_item_templates_page.page.save_page = prefs_folder_item_templates_save_func;
1614         
1615         prefs_folder_item_register_page((PrefsPage *) &folder_item_templates_page);
1616 }
1617
1618 static GSList *prefs_pages = NULL;
1619
1620 static void prefs_folder_item_address_completion_start(GtkWindow * window)
1621 {
1622         address_completion_start(GTK_WIDGET(window));
1623 }
1624
1625 static void prefs_folder_item_address_completion_end(GtkWindow * window)
1626 {
1627         address_completion_end(GTK_WIDGET(window));
1628 }
1629
1630 void prefs_folder_item_open(FolderItem *item)
1631 {
1632         gchar *id, *title;
1633         if (prefs_pages == NULL) {
1634                 register_general_page();
1635                 register_compose_page();
1636                 register_templates_page();
1637         }
1638
1639         if (item->path) {
1640                 id = folder_item_get_identifier (item);
1641                 can_save = TRUE;
1642         } else {
1643                 id = g_strdup(item->name);
1644                 can_save = FALSE;
1645         }
1646         title = g_strdup_printf (_("Properties for folder %s"), id);
1647         g_free (id);
1648         prefswindow_open(title, prefs_pages, item,
1649                         &prefs_common.folderitemwin_width, &prefs_common.folderitemwin_height,
1650                         prefs_folder_item_address_completion_start,
1651                         prefs_folder_item_address_completion_end);
1652
1653         g_free (title);
1654 }
1655
1656 static void prefs_folder_item_register_page(PrefsPage *page)
1657 {
1658         prefs_pages = g_slist_append(prefs_pages, page);
1659 }
1660
1661 static void prefs_folder_item_unregister_page(PrefsPage *page)
1662 {
1663         prefs_pages = g_slist_remove(prefs_pages, page);
1664 }