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