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