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