8cff6f9a00f4287762f9293bd9b0ac66c7dd492a
[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 2 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, write to the Free Software
17  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
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 "prefs_folder_item.h"
34 #include "folderview.h"
35 #include "folder.h"
36 #include "summaryview.h"
37 #include "menu.h"
38 #include "account.h"
39 #include "prefs_gtk.h"
40 #include "manage_window.h"
41 #include "utils.h"
42 #include "addr_compl.h"
43 #include "prefs_common.h"
44 #include "gtkutils.h"
45 #include "filtering.h"
46 #include "folder_item_prefs.h"
47 #include "gtk/colorsel.h"
48 #include "string_match.h"
49
50 #if USE_ASPELL
51 #include "gtkaspell.h"
52 #endif
53
54 #define ASSIGN_STRING(string, value) \
55         { \
56                 g_free(string); \
57                 string = (value); \
58         }
59
60 typedef struct _FolderItemGeneralPage FolderItemGeneralPage;
61 typedef struct _FolderItemComposePage FolderItemComposePage;
62 static gboolean can_save = TRUE;
63
64 struct _FolderItemGeneralPage
65 {
66         PrefsPage page;
67
68         FolderItem *item;
69
70         GtkWidget *table;
71         GtkWidget *no_save_warning;
72         GtkWidget *folder_type;
73         GtkWidget *checkbtn_simplify_subject;
74         GtkWidget *entry_simplify_subject;
75         GtkWidget *entry_regexp_test_string;
76         GtkWidget *entry_regexp_test_result;
77         GtkWidget *checkbtn_folder_chmod;
78         GtkWidget *entry_folder_chmod;
79         GtkWidget *folder_color_btn;
80         GtkWidget *checkbtn_enable_processing;
81         GtkWidget *checkbtn_newmailcheck;
82         GtkWidget *checkbtn_offlinesync;
83
84         /* apply to sub folders */
85         GtkWidget *simplify_subject_rec_checkbtn;
86         GtkWidget *folder_chmod_rec_checkbtn;
87         GtkWidget *folder_color_rec_checkbtn;
88         GtkWidget *enable_processing_rec_checkbtn;
89         GtkWidget *newmailcheck_rec_checkbtn;
90         GtkWidget *offlinesync_rec_checkbtn;
91
92         gint       folder_color;
93 };
94
95 struct _FolderItemComposePage
96 {
97         PrefsPage page;
98
99         FolderItem *item;
100
101         GtkWidget *window;
102         GtkWidget *table;
103         GtkWidget *no_save_warning;
104         GtkWidget *checkbtn_request_return_receipt;
105         GtkWidget *checkbtn_save_copy_to_folder;
106         GtkWidget *checkbtn_default_to;
107         GtkWidget *entry_default_to;
108         GtkWidget *checkbtn_default_reply_to;
109         GtkWidget *entry_default_reply_to;
110         GtkWidget *checkbtn_enable_default_account;
111         GtkWidget *optmenu_default_account;
112 #if USE_ASPELL
113         GtkWidget *checkbtn_enable_default_dictionary;
114         GtkWidget *checkbtn_enable_default_alt_dictionary;
115         GtkWidget *optmenu_default_dictionary;
116         GtkWidget *optmenu_default_alt_dictionary;
117 #endif
118
119         /* apply to sub folders */
120         GtkWidget *request_return_receipt_rec_checkbtn;
121         GtkWidget *save_copy_to_folder_rec_checkbtn;
122         GtkWidget *default_to_rec_checkbtn;
123         GtkWidget *default_reply_to_rec_checkbtn;
124         GtkWidget *default_account_rec_checkbtn;
125 #if USE_ASPELL
126         GtkWidget *default_dictionary_rec_checkbtn;
127         GtkWidget *default_alt_dictionary_rec_checkbtn;
128 #endif
129 };
130
131
132 static void general_save_folder_prefs(FolderItem *folder, FolderItemGeneralPage *page);
133 static void compose_save_folder_prefs(FolderItem *folder, FolderItemComposePage *page);
134
135 static gboolean general_save_recurse_func(GNode *node, gpointer data);
136 static gboolean compose_save_recurse_func(GNode *node, gpointer data);
137
138 static gint prefs_folder_item_chmod_mode                (gchar *folder_chmod);
139
140 static void folder_color_set_dialog(GtkWidget *widget, gpointer data);
141 static void folder_regexp_test_cb(GtkWidget *widget, gpointer data);
142 static void folder_regexp_set_subject_example_cb(GtkWidget *widget, gpointer data);
143
144 #define SAFE_STRING(str) \
145         (str) ? (str) : ""
146
147 static void prefs_folder_item_general_create_widget_func(PrefsPage * page_,
148                                                    GtkWindow * window,
149                                                    gpointer data)
150 {
151         FolderItemGeneralPage *page = (FolderItemGeneralPage *) page_;
152         FolderItem *item = (FolderItem *) data;
153         guint rowcount;
154
155
156         GtkWidget *table;
157         GtkWidget *hbox;
158         GtkWidget *label;
159         
160         GtkWidget *folder_type_menu;
161         GtkWidget *folder_type;
162         GtkWidget *dummy_checkbtn;
163         GtkWidget *menuitem;
164         SpecialFolderItemType type;
165         
166         GtkWidget *no_save_warning = NULL;
167         GtkWidget *checkbtn_simplify_subject;
168         GtkWidget *entry_simplify_subject;
169         GtkWidget *hbox_regexp;
170         GtkWidget *label_regexp_test;
171         GtkWidget *entry_regexp_test_string;
172         GtkWidget *left_arrow;
173         GtkWidget *entry_regexp_test_result;
174
175         GtkWidget *checkbtn_folder_chmod;
176         GtkWidget *entry_folder_chmod;
177         GtkWidget *folder_color;
178         GtkWidget *folder_color_btn;
179         GtkWidget *checkbtn_enable_processing;
180         GtkWidget *checkbtn_newmailcheck;
181         GtkWidget *checkbtn_offlinesync;
182
183         GtkWidget *simplify_subject_rec_checkbtn;
184         GtkWidget *folder_chmod_rec_checkbtn;
185         GtkWidget *folder_color_rec_checkbtn;
186         GtkWidget *enable_processing_rec_checkbtn;
187         GtkWidget *newmailcheck_rec_checkbtn;
188         GtkWidget *offlinesync_rec_checkbtn;
189         GtkTooltips *tooltips;
190
191         page->item         = item;
192
193         /* Table */
194         table = gtk_table_new(7, 4, FALSE);
195         gtk_container_set_border_width (GTK_CONTAINER (table), VBOX_BORDER);
196         gtk_table_set_row_spacings(GTK_TABLE(table), 4);
197         gtk_table_set_col_spacings(GTK_TABLE(table), 4);
198         rowcount = 0;
199
200         if (!can_save) {
201                 no_save_warning = gtk_label_new(
202                         _("<i>These preferences will not be saved as this folder "
203                         "is a top-level one. However you can use them to set them "
204                         "to the whole mailbox tree using \"Apply to subfolders\".</i>"));
205                 gtk_label_set_use_markup(GTK_LABEL(no_save_warning), TRUE);
206                 gtk_label_set_line_wrap(GTK_LABEL(no_save_warning), TRUE);
207                 gtk_misc_set_alignment(GTK_MISC(no_save_warning), 0.0, 0.5);
208                 gtk_table_attach(GTK_TABLE(table), no_save_warning, 0, 4,
209                          rowcount, rowcount + 1, GTK_FILL, 0, 0, 0);
210                 rowcount++;
211         }
212         
213         /* Apply to subfolders */
214         label = gtk_label_new(_("Apply to\nsubfolders"));
215         gtk_misc_set_alignment(GTK_MISC(label), 0.5, 0.5);
216         gtk_table_attach(GTK_TABLE(table), label, 3, 4,
217                          rowcount, rowcount + 1, GTK_SHRINK, GTK_SHRINK, 0, 0);
218         rowcount++;
219
220         /* folder_type */
221         folder_type = gtk_option_menu_new ();
222         gtk_widget_show (folder_type);
223
224         type = F_NORMAL;
225         if (item->stype == F_INBOX)
226                 type = F_INBOX;
227         else if (folder_has_parent_of_type(item, F_OUTBOX))
228                 type = F_OUTBOX;
229         else if (folder_has_parent_of_type(item, F_DRAFT))
230                 type = F_DRAFT;
231         else if (folder_has_parent_of_type(item, F_QUEUE))
232                 type = F_QUEUE;
233         else if (folder_has_parent_of_type(item, F_TRASH))
234                 type = F_TRASH;
235
236         folder_type_menu = gtk_menu_new ();
237
238         MENUITEM_ADD (folder_type_menu, menuitem, _("Normal"),  F_NORMAL);
239         MENUITEM_ADD (folder_type_menu, menuitem, _("Inbox"),  F_INBOX);
240         MENUITEM_ADD (folder_type_menu, menuitem, _("Outbox"),  F_OUTBOX);
241         MENUITEM_ADD (folder_type_menu, menuitem, _("Drafts"),  F_DRAFT);
242         MENUITEM_ADD (folder_type_menu, menuitem, _("Queue"),  F_QUEUE);
243         MENUITEM_ADD (folder_type_menu, menuitem, _("Trash"),  F_TRASH);
244         gtk_option_menu_set_menu (GTK_OPTION_MENU (folder_type), folder_type_menu);
245
246         gtk_option_menu_set_history(GTK_OPTION_MENU(folder_type), type);
247
248         dummy_checkbtn = gtk_check_button_new();
249         gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(dummy_checkbtn), type != F_INBOX);
250         gtk_widget_set_sensitive(dummy_checkbtn, FALSE);
251
252         if (type == item->stype && type == F_NORMAL)
253                 gtk_widget_set_sensitive(folder_type, TRUE);
254         else
255                 gtk_widget_set_sensitive(folder_type, FALSE);
256
257         label = gtk_label_new(_("Folder type"));
258         gtk_misc_set_alignment(GTK_MISC(label), 0, 0.5);
259         gtk_table_attach(GTK_TABLE(table), label, 0, 1, 
260                          rowcount, rowcount + 1, GTK_SHRINK | GTK_FILL, GTK_FILL, 0, 0);
261         gtk_table_attach(GTK_TABLE(table), folder_type, 1, 2, 
262                          rowcount, rowcount + 1, GTK_SHRINK | GTK_FILL, GTK_FILL, 0, 0);
263         gtk_table_attach(GTK_TABLE(table), dummy_checkbtn, 3, 4, 
264                          rowcount, rowcount + 1, GTK_SHRINK, GTK_SHRINK, 0, 0);
265
266         rowcount++;
267
268         /* Simplify Subject */
269         checkbtn_simplify_subject = gtk_check_button_new_with_label(_("Simplify Subject RegExp"));
270         gtk_table_attach(GTK_TABLE(table), checkbtn_simplify_subject, 0, 1, 
271                          rowcount, rowcount + 1, GTK_SHRINK | GTK_FILL, GTK_FILL, 0, 0);
272         gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(checkbtn_simplify_subject), 
273                                      item->prefs->enable_simplify_subject);
274
275         g_signal_connect(G_OBJECT(checkbtn_simplify_subject), "toggled",
276                         G_CALLBACK(folder_regexp_set_subject_example_cb), page);
277
278         entry_simplify_subject = gtk_entry_new();
279         gtk_table_attach(GTK_TABLE(table), entry_simplify_subject, 1, 3, 
280                          rowcount, rowcount + 1, GTK_EXPAND | GTK_FILL, GTK_FILL, 0, 0);
281         SET_TOGGLE_SENSITIVITY(checkbtn_simplify_subject, entry_simplify_subject);
282         gtk_entry_set_text(GTK_ENTRY(entry_simplify_subject), 
283                            SAFE_STRING(item->prefs->simplify_subject_regexp));
284
285         g_signal_connect(G_OBJECT(entry_simplify_subject), "changed",
286                         G_CALLBACK(folder_regexp_test_cb), page);
287
288         simplify_subject_rec_checkbtn = gtk_check_button_new();
289         gtk_table_attach(GTK_TABLE(table), simplify_subject_rec_checkbtn, 3, 4, 
290                          rowcount, rowcount + 1, GTK_SHRINK, GTK_SHRINK, 0, 0);
291
292         rowcount++;
293
294         /* Test RegExp */
295         label_regexp_test = gtk_label_new(_("Test RegExp"));
296         gtk_misc_set_alignment(GTK_MISC(label_regexp_test), 0, 0.5);
297         gtk_table_attach(GTK_TABLE(table), label_regexp_test, 0, 1, 
298                          rowcount, rowcount + 1, GTK_SHRINK | GTK_FILL, GTK_FILL, 0, 0);
299         SET_TOGGLE_SENSITIVITY(checkbtn_simplify_subject, label_regexp_test);
300
301         entry_regexp_test_string = gtk_entry_new();
302         gtk_table_attach(GTK_TABLE(table), entry_regexp_test_string, 1, 2, 
303                          rowcount, rowcount + 1, GTK_EXPAND | GTK_FILL, GTK_FILL, 0, 0);
304         SET_TOGGLE_SENSITIVITY(checkbtn_simplify_subject, entry_regexp_test_string);
305
306         g_signal_connect(G_OBJECT(entry_regexp_test_string), "changed",
307                         G_CALLBACK(folder_regexp_test_cb), page);
308
309         hbox_regexp = gtk_hbox_new (FALSE, 4);
310         gtk_widget_show (hbox_regexp);
311         gtk_table_attach(GTK_TABLE(table), hbox_regexp, 2, 3, 
312                          rowcount, rowcount + 1, GTK_EXPAND | GTK_FILL, GTK_FILL, 0, 0);
313
314         left_arrow = gtk_arrow_new(GTK_ARROW_RIGHT, GTK_SHADOW_OUT);
315         gtk_widget_show(left_arrow);
316         gtk_box_pack_start (GTK_BOX(hbox_regexp), left_arrow, FALSE, FALSE, 0);
317         SET_TOGGLE_SENSITIVITY(checkbtn_simplify_subject, left_arrow);
318
319         entry_regexp_test_result = gtk_entry_new();
320         gtk_box_pack_end (GTK_BOX(hbox_regexp), entry_regexp_test_result, TRUE, TRUE, 0);
321         SET_TOGGLE_SENSITIVITY(checkbtn_simplify_subject, entry_regexp_test_result);
322         gtk_entry_set_editable(GTK_ENTRY(entry_regexp_test_result), FALSE);
323
324         rowcount++;
325
326         /* Folder chmod */
327         checkbtn_folder_chmod = gtk_check_button_new_with_label(_("Folder chmod"));
328         gtk_table_attach(GTK_TABLE(table), checkbtn_folder_chmod, 0, 1, 
329                          rowcount, rowcount + 1, GTK_SHRINK | GTK_FILL, GTK_FILL, 0, 0);
330
331         gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(checkbtn_folder_chmod), 
332                                      item->prefs->enable_folder_chmod);
333
334         entry_folder_chmod = gtk_entry_new();
335         gtk_table_attach(GTK_TABLE(table), entry_folder_chmod, 1, 2, 
336                          rowcount, rowcount + 1, GTK_EXPAND | GTK_FILL, GTK_FILL, 0, 0);
337         SET_TOGGLE_SENSITIVITY(checkbtn_folder_chmod, entry_folder_chmod);
338         if (item->prefs->folder_chmod) {
339                 gchar *buf;
340
341                 buf = g_strdup_printf("%o", item->prefs->folder_chmod);
342                 gtk_entry_set_text(GTK_ENTRY(entry_folder_chmod), buf);
343                 g_free(buf);
344         }
345         
346         folder_chmod_rec_checkbtn = gtk_check_button_new();
347         gtk_table_attach(GTK_TABLE(table), folder_chmod_rec_checkbtn, 3, 4, 
348                          rowcount, rowcount + 1, GTK_SHRINK, GTK_SHRINK, 0, 0);
349
350         rowcount++;
351         
352         /* Folder color */
353         folder_color = gtk_label_new(_("Folder color"));
354         gtk_misc_set_alignment(GTK_MISC(folder_color), 0, 0.5);
355         gtk_table_attach(GTK_TABLE(table), folder_color, 0, 1, 
356                          rowcount, rowcount + 1, GTK_SHRINK | GTK_FILL, GTK_FILL, 0, 0);
357
358         hbox = gtk_hbox_new(FALSE, 0);
359         gtk_table_attach(GTK_TABLE(table), hbox, 1, 2, 
360                          rowcount, rowcount + 1, GTK_EXPAND | GTK_FILL, GTK_FILL, 0, 0);
361
362         folder_color_btn = gtk_button_new_with_label("");
363         gtk_widget_set_size_request(folder_color_btn, 36, 26);
364         gtk_box_pack_start (GTK_BOX(hbox), folder_color_btn, FALSE, FALSE, 0);
365         tooltips = gtk_tooltips_new();
366         gtk_tooltips_set_tip(tooltips, folder_color_btn,
367                              _("Pick color for folder"), NULL);
368
369         page->folder_color = item->prefs->color;
370
371         g_signal_connect(G_OBJECT(folder_color_btn), "clicked",
372                          G_CALLBACK(folder_color_set_dialog),
373                          page);
374
375         gtkut_set_widget_bgcolor_rgb(folder_color_btn, item->prefs->color);
376
377         folder_color_rec_checkbtn = gtk_check_button_new();
378         gtk_table_attach(GTK_TABLE(table), folder_color_rec_checkbtn, 3, 4, 
379                          rowcount, rowcount + 1, GTK_SHRINK, GTK_SHRINK, 0, 0);
380
381         rowcount++;
382
383         /* Enable processing at startup */
384         checkbtn_enable_processing = gtk_check_button_new_with_label(_("Process at start-up"));
385         gtk_table_attach(GTK_TABLE(table), checkbtn_enable_processing, 0, 2, 
386                          rowcount, rowcount + 1, GTK_EXPAND | GTK_FILL, GTK_FILL, 0, 0);
387
388         gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(checkbtn_enable_processing), 
389                                      item->prefs->enable_processing);
390
391         enable_processing_rec_checkbtn = gtk_check_button_new();
392         gtk_table_attach(GTK_TABLE(table), enable_processing_rec_checkbtn, 3, 4, 
393                          rowcount, rowcount + 1, GTK_SHRINK, GTK_SHRINK, 0, 0);
394         
395         rowcount++;
396
397         /* Check folder for new mail */
398         checkbtn_newmailcheck = gtk_check_button_new_with_label(_("Scan for new mail"));
399         gtk_table_attach(GTK_TABLE(table), checkbtn_newmailcheck, 0, 2,
400                          rowcount, rowcount+1, GTK_EXPAND | GTK_FILL, GTK_FILL, 0, 0);
401         
402         gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(checkbtn_newmailcheck),
403                                                                  item->prefs->newmailcheck);
404         newmailcheck_rec_checkbtn = gtk_check_button_new();
405         gtk_table_attach(GTK_TABLE(table), newmailcheck_rec_checkbtn, 3, 4, 
406                          rowcount, rowcount + 1, GTK_SHRINK, GTK_SHRINK, 0, 0);
407
408         rowcount++;
409
410         /* Synchronise folder for offline use */
411         checkbtn_offlinesync = gtk_check_button_new_with_label(_("Synchronise for offline use"));
412         gtk_table_attach(GTK_TABLE(table), checkbtn_offlinesync, 0, 2,
413                          rowcount, rowcount+1, GTK_EXPAND | GTK_FILL, GTK_FILL, 0, 0);
414         
415         offlinesync_rec_checkbtn = gtk_check_button_new();
416         gtk_table_attach(GTK_TABLE(table), offlinesync_rec_checkbtn, 3, 4, 
417                          rowcount, rowcount + 1, GTK_SHRINK, GTK_SHRINK, 0, 0);
418
419         if (item->folder && (item->folder->klass->type != F_IMAP && 
420             item->folder->klass->type != F_NEWS)) {
421                  item->prefs->offlinesync = TRUE;
422                 gtk_widget_set_sensitive(GTK_WIDGET(checkbtn_offlinesync),
423                                                                  FALSE);
424                 gtk_widget_set_sensitive(GTK_WIDGET(offlinesync_rec_checkbtn),
425                                                                  FALSE);
426         
427         }
428         gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(checkbtn_offlinesync),
429                                                                  item->prefs->offlinesync);
430         rowcount++;
431
432         gtk_widget_show_all(table);
433
434         page->table = table;
435         page->folder_type = folder_type;
436         page->no_save_warning = no_save_warning;
437         page->checkbtn_simplify_subject = checkbtn_simplify_subject;
438         page->entry_simplify_subject = entry_simplify_subject;
439         page->entry_regexp_test_string = entry_regexp_test_string;
440         page->entry_regexp_test_result = entry_regexp_test_result;
441         page->checkbtn_folder_chmod = checkbtn_folder_chmod;
442         page->entry_folder_chmod = entry_folder_chmod;
443         page->folder_color_btn = folder_color_btn;
444         page->checkbtn_enable_processing = checkbtn_enable_processing;
445         page->checkbtn_newmailcheck = checkbtn_newmailcheck;
446         page->checkbtn_offlinesync = checkbtn_offlinesync;
447
448         page->simplify_subject_rec_checkbtn  = simplify_subject_rec_checkbtn;
449         page->folder_chmod_rec_checkbtn      = folder_chmod_rec_checkbtn;
450         page->folder_color_rec_checkbtn      = folder_color_rec_checkbtn;
451         page->enable_processing_rec_checkbtn = enable_processing_rec_checkbtn;
452         page->newmailcheck_rec_checkbtn      = newmailcheck_rec_checkbtn;
453         page->offlinesync_rec_checkbtn       = offlinesync_rec_checkbtn;
454
455         page->page.widget = table;
456
457         folder_regexp_set_subject_example_cb(NULL, page);
458 }
459
460 static void prefs_folder_item_general_destroy_widget_func(PrefsPage *page_) 
461 {
462         /* FolderItemGeneralPage *page = (FolderItemGeneralPage *) page_; */
463 }
464
465 /** \brief  Save the prefs in page to folder.
466  *
467  *  If the folder is not the one  specified in page->item, then only those properties 
468  *  that have the relevant 'apply to sub folders' button checked are saved
469  */
470 static void general_save_folder_prefs(FolderItem *folder, FolderItemGeneralPage *page)
471 {
472         FolderItemPrefs *prefs = folder->prefs;
473         gchar *buf;
474         gboolean all = FALSE;
475         SpecialFolderItemType type = F_NORMAL;
476         GtkWidget *menu;
477         GtkWidget *menuitem;
478
479         if (folder->path == NULL)
480                 return;
481
482         g_return_if_fail(prefs != NULL);
483
484         if (page->item == folder) 
485                 all = TRUE;
486
487         menu = gtk_option_menu_get_menu(GTK_OPTION_MENU(page->folder_type));
488         menuitem = gtk_menu_get_active(GTK_MENU(menu));
489         type = GPOINTER_TO_INT
490                 (g_object_get_data(G_OBJECT(menuitem), MENU_VAL_ID));
491         if (all && folder->stype != type) {
492                 folder_item_change_type(folder, type);
493         }
494
495         if (all || gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(page->simplify_subject_rec_checkbtn))) {
496                 prefs->enable_simplify_subject =
497                         gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(page->checkbtn_simplify_subject));
498                 ASSIGN_STRING(prefs->simplify_subject_regexp,
499                               gtk_editable_get_chars(GTK_EDITABLE(page->entry_simplify_subject), 0, -1));
500         }
501         
502         if (all || gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(page->folder_chmod_rec_checkbtn))) {
503                 prefs->enable_folder_chmod = 
504                         gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(page->checkbtn_folder_chmod));
505                 buf = gtk_editable_get_chars(GTK_EDITABLE(page->entry_folder_chmod), 0, -1);
506                 prefs->folder_chmod = prefs_folder_item_chmod_mode(buf);
507                 g_free(buf);
508         }
509
510         if (all || gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(page->folder_color_rec_checkbtn))) {
511                 int old_color = prefs->color;
512                 prefs->color = page->folder_color;
513         
514                 /* update folder view */
515                 if (prefs->color != old_color)
516                         folder_item_update(folder, F_ITEM_UPDATE_MSGCNT);
517         }
518
519         if (all || gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(page->enable_processing_rec_checkbtn))) {
520                 prefs->enable_processing = 
521                         gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(page->checkbtn_enable_processing));
522         }
523
524         if (all ||  gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(page->newmailcheck_rec_checkbtn))) {
525                 prefs->newmailcheck = 
526                         gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(page->checkbtn_newmailcheck));
527         }
528
529         if (all ||  gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(page->offlinesync_rec_checkbtn))) {
530                 prefs->offlinesync = 
531                         gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(page->checkbtn_offlinesync));
532         }
533
534         folder_item_prefs_save_config(folder);
535 }       
536
537 static gboolean general_save_recurse_func(GNode *node, gpointer data)
538 {
539         FolderItem *item = (FolderItem *) node->data;
540         FolderItemGeneralPage *page = (FolderItemGeneralPage *) data;
541
542         g_return_val_if_fail(item != NULL, TRUE);
543         g_return_val_if_fail(page != NULL, TRUE);
544
545         general_save_folder_prefs(item, page);
546
547         /* optimise by not continuing if none of the 'apply to sub folders'
548            check boxes are selected - and optimise the checking by only doing
549            it once */
550         if ((node == page->item->node) &&
551             !(gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(page->simplify_subject_rec_checkbtn)) ||
552               gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(page->folder_chmod_rec_checkbtn)) ||
553               gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(page->folder_color_rec_checkbtn)) ||
554               gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(page->enable_processing_rec_checkbtn)) ||
555               gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(page->newmailcheck_rec_checkbtn)) ||
556               gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(page->offlinesync_rec_checkbtn))))
557                 return TRUE;
558         else 
559                 return FALSE;
560 }
561
562 static void prefs_folder_item_general_save_func(PrefsPage *page_) 
563 {
564         FolderItemGeneralPage *page = (FolderItemGeneralPage *) page_;
565
566         g_node_traverse(page->item->node, G_PRE_ORDER, G_TRAVERSE_ALL,
567                         -1, general_save_recurse_func, page);
568         
569         main_window_set_menu_sensitive(mainwindow_get_mainwindow());
570
571 }
572
573 static RecvProtocol item_protocol(FolderItem *item)
574 {
575         if (!item)
576                 return A_NONE;
577         if (!item->folder)
578                 return A_NONE;
579         if (!item->folder->account)
580                 return A_NONE;
581         return item->folder->account->protocol;
582 }
583
584 static void prefs_folder_item_compose_create_widget_func(PrefsPage * page_,
585                                                    GtkWindow * window,
586                                                    gpointer data)
587 {
588         FolderItemComposePage *page = (FolderItemComposePage *) page_;
589         FolderItem *item = (FolderItem *) data;
590         guint rowcount;
591
592         GtkWidget *table;
593         GtkWidget *label;
594         
595         GtkWidget *no_save_warning = NULL;
596         GtkWidget *checkbtn_request_return_receipt = NULL;
597         GtkWidget *checkbtn_save_copy_to_folder = NULL;
598         GtkWidget *checkbtn_default_to = NULL;
599         GtkWidget *entry_default_to = NULL;
600         GtkWidget *checkbtn_default_reply_to = NULL;
601         GtkWidget *entry_default_reply_to = NULL;
602         GtkWidget *checkbtn_enable_default_account = NULL;
603         GtkWidget *optmenu_default_account = NULL;
604         GtkWidget *optmenu_default_account_menu = NULL;
605         GtkWidget *optmenu_default_account_menuitem = NULL;
606 #if USE_ASPELL
607         GtkWidget *checkbtn_enable_default_dictionary = NULL;
608         GtkWidget *optmenu_default_dictionary = NULL;
609         GtkWidget *checkbtn_enable_default_alt_dictionary = NULL;
610         GtkWidget *optmenu_default_alt_dictionary = NULL;
611 #endif
612         GtkWidget *request_return_receipt_rec_checkbtn = NULL;
613         GtkWidget *save_copy_to_folder_rec_checkbtn = NULL;
614         GtkWidget *default_to_rec_checkbtn = NULL;
615         GtkWidget *default_reply_to_rec_checkbtn = NULL;
616         GtkWidget *default_account_rec_checkbtn = NULL;
617 #if USE_ASPELL
618         GtkWidget *default_dictionary_rec_checkbtn = NULL;
619         GtkWidget *default_alt_dictionary_rec_checkbtn = NULL;
620 #endif
621
622         GList *cur_ac;
623         GList *account_list;
624 #if USE_ASPELL
625         gchar *dictionary;
626 #endif
627         PrefsAccount *ac_prefs;
628         GtkOptionMenu *optmenu;
629         GtkWidget *menu;
630         GtkWidget *menuitem;
631         gint account_index, index;
632
633         page->item         = item;
634
635         /* Table */
636 #if USE_ASPELL
637 # define TABLEHEIGHT 7
638 #else
639 # define TABLEHEIGHT 6
640 #endif
641         table = gtk_table_new(TABLEHEIGHT, 3, FALSE);
642         gtk_container_set_border_width (GTK_CONTAINER (table), VBOX_BORDER);
643         gtk_table_set_row_spacings(GTK_TABLE(table), 4);
644         gtk_table_set_col_spacings(GTK_TABLE(table), 4);
645         rowcount = 0;
646
647         if (!can_save) {
648                 no_save_warning = gtk_label_new(
649                         _("<i>These preferences will not be saved as this folder "
650                         "is a top-level one. However you can use them to set them "
651                         "to the whole mailbox tree using \"Apply to subfolders\".</i>"));
652                 gtk_label_set_use_markup(GTK_LABEL(no_save_warning), TRUE);
653                 gtk_label_set_line_wrap(GTK_LABEL(no_save_warning), TRUE);
654                 gtk_misc_set_alignment(GTK_MISC(no_save_warning), 0.0, 0.5);
655                 gtk_table_attach(GTK_TABLE(table), no_save_warning, 0, 3,
656                          rowcount, rowcount + 1, GTK_FILL, 0, 0, 0);
657                 rowcount++;
658         }
659         
660         /* Apply to subfolders */
661         label = gtk_label_new(_("Apply to\nsubfolders"));
662         gtk_misc_set_alignment(GTK_MISC(label), 0.5, 0.5);
663         gtk_table_attach(GTK_TABLE(table), label, 2, 3,
664                          rowcount, rowcount + 1, GTK_SHRINK, GTK_SHRINK, 0, 0);
665         rowcount++;
666
667         if (item_protocol(item) != A_NNTP) {
668                 /* Request Return Receipt */
669                 checkbtn_request_return_receipt = gtk_check_button_new_with_label
670                         (_("Request Return Receipt"));
671                 gtk_table_attach(GTK_TABLE(table), checkbtn_request_return_receipt, 
672                                  0, 2, rowcount, rowcount + 1, GTK_SHRINK | GTK_FILL, 
673                                  GTK_FILL, 0, 0);
674                 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(checkbtn_request_return_receipt),
675                                              item->ret_rcpt ? TRUE : FALSE);
676
677                 request_return_receipt_rec_checkbtn = gtk_check_button_new();
678                 gtk_table_attach(GTK_TABLE(table), request_return_receipt_rec_checkbtn, 2, 3, 
679                                  rowcount, rowcount + 1, GTK_SHRINK, GTK_SHRINK, 0, 0);
680
681                 rowcount++;
682
683                 /* Save Copy to Folder */
684                 checkbtn_save_copy_to_folder = gtk_check_button_new_with_label
685                         (_("Save copy of outgoing messages to this folder instead of Sent"));
686                 gtk_table_attach(GTK_TABLE(table), checkbtn_save_copy_to_folder, 0, 2, 
687                                  rowcount, rowcount + 1, GTK_SHRINK | GTK_FILL, GTK_FILL, 0, 0);
688                 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(checkbtn_save_copy_to_folder),
689                                              item->prefs->save_copy_to_folder ? TRUE : FALSE);
690
691                 save_copy_to_folder_rec_checkbtn = gtk_check_button_new();
692                 gtk_table_attach(GTK_TABLE(table), save_copy_to_folder_rec_checkbtn, 2, 3, 
693                                  rowcount, rowcount + 1, GTK_SHRINK, GTK_SHRINK, 0, 0);
694
695                 rowcount++;
696
697                 /* Default To */
698                 checkbtn_default_to = gtk_check_button_new_with_label(_("Default To:"));
699                 gtk_table_attach(GTK_TABLE(table), checkbtn_default_to, 0, 1, 
700                                  rowcount, rowcount + 1, GTK_SHRINK | GTK_FILL, GTK_SHRINK, 0, 0);
701                 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(checkbtn_default_to), 
702                                              item->prefs->enable_default_to);
703
704                 entry_default_to = gtk_entry_new();
705                 gtk_table_attach(GTK_TABLE(table), entry_default_to, 1, 2,
706                                  rowcount, rowcount + 1, GTK_EXPAND | GTK_FILL, GTK_SHRINK, 0, 0);
707                 SET_TOGGLE_SENSITIVITY(checkbtn_default_to, entry_default_to);
708                 gtk_entry_set_text(GTK_ENTRY(entry_default_to), SAFE_STRING(item->prefs->default_to));
709                 address_completion_register_entry(GTK_ENTRY(entry_default_to),
710                                 TRUE);
711
712                 default_to_rec_checkbtn = gtk_check_button_new();
713                 gtk_table_attach(GTK_TABLE(table), default_to_rec_checkbtn, 2, 3, 
714                                  rowcount, rowcount + 1, GTK_SHRINK, GTK_SHRINK, 0, 0);
715
716                 rowcount++;
717
718                 /* Default address to reply to */
719                 checkbtn_default_reply_to = gtk_check_button_new_with_label(_("Default To: for replies"));
720                 gtk_table_attach(GTK_TABLE(table), checkbtn_default_reply_to, 0, 1, 
721                                  rowcount, rowcount + 1, GTK_SHRINK | GTK_FILL, GTK_SHRINK, 0, 0);
722                 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(checkbtn_default_reply_to), 
723                                              item->prefs->enable_default_reply_to);
724
725                 entry_default_reply_to = gtk_entry_new();
726                 gtk_table_attach(GTK_TABLE(table), entry_default_reply_to, 1, 2,
727                                  rowcount, rowcount + 1, GTK_EXPAND | GTK_FILL, GTK_SHRINK, 0, 0);
728                 SET_TOGGLE_SENSITIVITY(checkbtn_default_reply_to, entry_default_reply_to);
729                 gtk_entry_set_text(GTK_ENTRY(entry_default_reply_to), SAFE_STRING(item->prefs->default_reply_to));
730                 address_completion_register_entry(
731                                 GTK_ENTRY(entry_default_reply_to), TRUE);
732
733                 default_reply_to_rec_checkbtn = gtk_check_button_new();
734                 gtk_table_attach(GTK_TABLE(table), default_reply_to_rec_checkbtn, 2, 3, 
735                                  rowcount, rowcount + 1, GTK_SHRINK, GTK_SHRINK, 0, 0);
736
737                 rowcount++;
738         }
739         /* Default account */
740         checkbtn_enable_default_account = gtk_check_button_new_with_label(_("Default account"));
741         gtk_table_attach(GTK_TABLE(table), checkbtn_enable_default_account, 0, 1, 
742                          rowcount, rowcount + 1, GTK_SHRINK | GTK_FILL, GTK_SHRINK, 0, 0);
743         gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(checkbtn_enable_default_account), 
744                                      item->prefs->enable_default_account);
745
746         optmenu_default_account = gtk_option_menu_new ();
747         gtk_table_attach(GTK_TABLE(table), optmenu_default_account, 1, 2, 
748                          rowcount, rowcount + 1, GTK_EXPAND | GTK_FILL, GTK_SHRINK, 0, 0);
749         optmenu_default_account_menu = gtk_menu_new ();
750
751         account_list = account_get_list();
752         account_index = 0;
753         index = 0;
754         for (cur_ac = account_list; cur_ac != NULL; cur_ac = cur_ac->next) {
755                 ac_prefs = (PrefsAccount *)cur_ac->data;
756                 if (item->folder->account &&
757                     ( (item_protocol(item) == A_NNTP && ac_prefs->protocol != A_NNTP)
758                     ||(item_protocol(item) != A_NNTP && ac_prefs->protocol == A_NNTP))) 
759                         continue;
760
761                 if (item->folder->klass->type != F_NEWS && ac_prefs->protocol == A_NNTP)
762                         continue;
763
764                 MENUITEM_ADD (optmenu_default_account_menu, optmenu_default_account_menuitem,
765                                         ac_prefs->account_name?ac_prefs->account_name : _("Untitled"),
766                                         ac_prefs->account_id);
767                 /* get the index for menu's set_history (sad method?) */
768                 if (ac_prefs->account_id == item->prefs->default_account)
769                         account_index = index;
770                 index++;                        
771         }
772
773         optmenu = GTK_OPTION_MENU(optmenu_default_account);
774         gtk_option_menu_set_menu(optmenu, optmenu_default_account_menu);
775
776         gtk_option_menu_set_history(optmenu, account_index);
777
778         menu = gtk_option_menu_get_menu(optmenu);
779         menuitem = gtk_menu_get_active(GTK_MENU(menu));
780         gtk_menu_item_activate(GTK_MENU_ITEM(menuitem));
781
782         SET_TOGGLE_SENSITIVITY(checkbtn_enable_default_account, optmenu_default_account);
783
784         default_account_rec_checkbtn = gtk_check_button_new();
785         gtk_table_attach(GTK_TABLE(table), default_account_rec_checkbtn, 2, 3, 
786                          rowcount, rowcount + 1, GTK_SHRINK, GTK_SHRINK, 0, 0);
787         rowcount++;
788
789 #if USE_ASPELL
790         /* Default dictionary */
791         checkbtn_enable_default_dictionary = gtk_check_button_new_with_label(_("Default dictionary"));
792         gtk_table_attach(GTK_TABLE(table), checkbtn_enable_default_dictionary, 0, 1,
793                          rowcount, rowcount + 1, GTK_SHRINK | GTK_FILL, GTK_SHRINK, 0, 0);
794         gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(checkbtn_enable_default_dictionary),
795                                      item->prefs->enable_default_dictionary);
796
797         optmenu_default_dictionary = gtk_option_menu_new();
798         gtk_table_attach(GTK_TABLE(table), optmenu_default_dictionary, 1, 2,
799                          rowcount, rowcount + 1, GTK_EXPAND | GTK_FILL, GTK_SHRINK, 0, 0);
800
801         gtk_option_menu_set_menu(GTK_OPTION_MENU(optmenu_default_dictionary), 
802                                  gtkaspell_dictionary_option_menu_new(
803                                          prefs_common.aspell_path));
804
805         dictionary = item->prefs->default_dictionary;
806
807         optmenu = GTK_OPTION_MENU(optmenu_default_dictionary);
808
809         menu = gtk_option_menu_get_menu(optmenu);
810         if (dictionary)
811                 gtkaspell_set_dictionary_menu_active_item(optmenu_default_dictionary, dictionary);
812         menuitem = gtk_menu_get_active(GTK_MENU(menu));
813         gtk_menu_item_activate(GTK_MENU_ITEM(menuitem));
814
815         SET_TOGGLE_SENSITIVITY(checkbtn_enable_default_dictionary, optmenu_default_dictionary);
816
817         default_dictionary_rec_checkbtn = gtk_check_button_new();
818         gtk_table_attach(GTK_TABLE(table), default_dictionary_rec_checkbtn, 2, 3, 
819                          rowcount, rowcount + 1, GTK_SHRINK, GTK_SHRINK, 0, 0);
820         
821         rowcount++;
822
823         /* Default dictionary */
824         checkbtn_enable_default_alt_dictionary = gtk_check_button_new_with_label(_("Default alternate dictionary"));
825         gtk_table_attach(GTK_TABLE(table), checkbtn_enable_default_alt_dictionary, 0, 1,
826                          rowcount, rowcount + 1, GTK_SHRINK | GTK_FILL, GTK_SHRINK, 0, 0);
827         gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(checkbtn_enable_default_alt_dictionary),
828                                      item->prefs->enable_default_alt_dictionary);
829
830         optmenu_default_alt_dictionary = gtk_option_menu_new();
831         gtk_table_attach(GTK_TABLE(table), optmenu_default_alt_dictionary, 1, 2,
832                          rowcount, rowcount + 1, GTK_EXPAND | GTK_FILL, GTK_SHRINK, 0, 0);
833
834         gtk_option_menu_set_menu(GTK_OPTION_MENU(optmenu_default_alt_dictionary), 
835                                  gtkaspell_dictionary_option_menu_new_with_refresh(
836                                          prefs_common.aspell_path, FALSE));
837
838         dictionary = item->prefs->default_alt_dictionary;
839
840         optmenu = GTK_OPTION_MENU(optmenu_default_alt_dictionary);
841
842         menu = gtk_option_menu_get_menu(optmenu);
843         if (dictionary)
844                 gtkaspell_set_dictionary_menu_active_item(optmenu_default_alt_dictionary, dictionary);
845         menuitem = gtk_menu_get_active(GTK_MENU(menu));
846         gtk_menu_item_activate(GTK_MENU_ITEM(menuitem));
847
848         SET_TOGGLE_SENSITIVITY(checkbtn_enable_default_alt_dictionary, optmenu_default_alt_dictionary);
849
850         default_alt_dictionary_rec_checkbtn = gtk_check_button_new();
851         gtk_table_attach(GTK_TABLE(table), default_alt_dictionary_rec_checkbtn, 2, 3, 
852                          rowcount, rowcount + 1, GTK_SHRINK, GTK_SHRINK, 0, 0);
853         
854         rowcount++;
855 #endif
856
857         gtk_widget_show_all(table);
858
859         page->window = GTK_WIDGET(window);
860         page->table = table;
861         page->no_save_warning = no_save_warning;
862         page->checkbtn_request_return_receipt = checkbtn_request_return_receipt;
863         page->checkbtn_save_copy_to_folder = checkbtn_save_copy_to_folder;
864         page->checkbtn_default_to = checkbtn_default_to;
865         page->entry_default_to = entry_default_to;
866         page->checkbtn_default_reply_to = checkbtn_default_reply_to;
867         page->entry_default_reply_to = entry_default_reply_to;
868         page->checkbtn_enable_default_account = checkbtn_enable_default_account;
869         page->optmenu_default_account = optmenu_default_account;
870 #ifdef USE_ASPELL
871         page->checkbtn_enable_default_dictionary = checkbtn_enable_default_dictionary;
872         page->optmenu_default_dictionary = optmenu_default_dictionary;
873         page->checkbtn_enable_default_alt_dictionary = checkbtn_enable_default_alt_dictionary;
874         page->optmenu_default_alt_dictionary = optmenu_default_alt_dictionary;
875 #endif
876
877         page->request_return_receipt_rec_checkbtn = request_return_receipt_rec_checkbtn;
878         page->save_copy_to_folder_rec_checkbtn    = save_copy_to_folder_rec_checkbtn;
879         page->default_to_rec_checkbtn             = default_to_rec_checkbtn;
880         page->default_reply_to_rec_checkbtn       = default_reply_to_rec_checkbtn;
881         page->default_account_rec_checkbtn        = default_account_rec_checkbtn;
882 #if USE_ASPELL
883         page->default_dictionary_rec_checkbtn = default_dictionary_rec_checkbtn;
884         page->default_alt_dictionary_rec_checkbtn = default_alt_dictionary_rec_checkbtn;
885 #endif
886
887         address_completion_start(page->window);
888
889         page->page.widget = table;
890 }
891
892 static void prefs_folder_item_compose_destroy_widget_func(PrefsPage *page_) 
893 {
894         FolderItemComposePage *page = (FolderItemComposePage *) page_;
895
896         if (page->entry_default_to)
897                 address_completion_unregister_entry(GTK_ENTRY(page->entry_default_to));
898         if (page->entry_default_reply_to)
899                 address_completion_unregister_entry(GTK_ENTRY(page->entry_default_reply_to));
900         address_completion_end(page->window);
901 }
902
903 /** \brief  Save the prefs in page to folder.
904  *
905  *  If the folder is not the one  specified in page->item, then only those properties 
906  *  that have the relevant 'apply to sub folders' button checked are saved
907  */
908 static void compose_save_folder_prefs(FolderItem *folder, FolderItemComposePage *page)
909 {
910         FolderItemPrefs *prefs = folder->prefs;
911         GtkWidget *menu;
912         GtkWidget *menuitem;
913         gboolean all = FALSE;
914
915         if (folder->path == NULL)
916                 return;
917
918         if (page->item == folder) 
919                 all = TRUE;
920
921         g_return_if_fail(prefs != NULL);
922
923         if (item_protocol(folder) != A_NNTP) {
924                 if (all || gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(page->request_return_receipt_rec_checkbtn))) {
925                         prefs->request_return_receipt = 
926                                 gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(page->checkbtn_request_return_receipt));
927                         /* MIGRATION */    
928                         folder->ret_rcpt = prefs->request_return_receipt;
929                 }
930
931                 if (all || gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(page->save_copy_to_folder_rec_checkbtn))) {
932                         prefs->save_copy_to_folder = 
933                                 gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(page->checkbtn_save_copy_to_folder));
934                 }
935
936                 if (all || gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(page->default_to_rec_checkbtn))) {
937
938                         prefs->enable_default_to = 
939                                 gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(page->checkbtn_default_to));
940                         ASSIGN_STRING(prefs->default_to,
941                                       gtk_editable_get_chars(GTK_EDITABLE(page->entry_default_to), 0, -1));
942                 }
943
944                 if (all || gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(page->default_reply_to_rec_checkbtn))) {
945                         prefs->enable_default_reply_to = 
946                                 gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(page->checkbtn_default_reply_to));
947                         ASSIGN_STRING(prefs->default_reply_to,
948                                       gtk_editable_get_chars(GTK_EDITABLE(page->entry_default_reply_to), 0, -1));
949                 }
950         } else {
951                 prefs->request_return_receipt = FALSE;
952                 prefs->save_copy_to_folder = FALSE;
953                 prefs->enable_default_to = FALSE;
954                 prefs->enable_default_reply_to = FALSE;
955         }
956         if (all || gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(page->default_account_rec_checkbtn))) {
957                 prefs->enable_default_account = 
958                         gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(page->checkbtn_enable_default_account));
959                 menu = gtk_option_menu_get_menu(GTK_OPTION_MENU(page->optmenu_default_account));
960                 menuitem = gtk_menu_get_active(GTK_MENU(menu));
961                 prefs->default_account = GPOINTER_TO_INT(g_object_get_data(G_OBJECT(menuitem), MENU_VAL_ID));
962         }
963
964 #if USE_ASPELL
965         if (all || gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(page->default_dictionary_rec_checkbtn))) {
966                 prefs->enable_default_dictionary =
967                         gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(page->checkbtn_enable_default_dictionary));
968                 menu = gtk_option_menu_get_menu(GTK_OPTION_MENU(page->optmenu_default_dictionary));
969                 ASSIGN_STRING(prefs->default_dictionary,
970                               gtkaspell_get_dictionary_menu_active_item(menu));
971         }
972         if (all || gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(page->default_alt_dictionary_rec_checkbtn))) {
973                 prefs->enable_default_alt_dictionary =
974                         gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(page->checkbtn_enable_default_alt_dictionary));
975                 menu = gtk_option_menu_get_menu(GTK_OPTION_MENU(page->optmenu_default_alt_dictionary));
976                 ASSIGN_STRING(prefs->default_alt_dictionary,
977                               gtkaspell_get_dictionary_menu_active_item(menu));
978         }
979 #endif
980
981         folder_item_prefs_save_config(folder);
982 }       
983
984 static gboolean compose_save_recurse_func(GNode *node, gpointer data)
985 {
986         FolderItem *item = (FolderItem *) node->data;
987         FolderItemComposePage *page = (FolderItemComposePage *) data;
988
989         g_return_val_if_fail(item != NULL, TRUE);
990         g_return_val_if_fail(page != NULL, TRUE);
991
992         compose_save_folder_prefs(item, page);
993
994         /* optimise by not continuing if none of the 'apply to sub folders'
995            check boxes are selected - and optimise the checking by only doing
996            it once */
997         if ((node == page->item->node) && item_protocol(item) != A_NNTP &&
998             !(gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(page->request_return_receipt_rec_checkbtn)) ||
999               gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(page->save_copy_to_folder_rec_checkbtn)) ||
1000               gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(page->default_to_rec_checkbtn)) ||
1001               gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(page->default_account_rec_checkbtn)) ||
1002 #if USE_ASPELL
1003               gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(page->default_dictionary_rec_checkbtn)) ||
1004               gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(page->default_alt_dictionary_rec_checkbtn)) ||
1005 #endif
1006               gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(page->default_reply_to_rec_checkbtn))))
1007                 return TRUE;
1008         else if ((node == page->item->node) && item_protocol(item) == A_NNTP &&
1009             !(gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(page->default_account_rec_checkbtn)) 
1010 #if USE_ASPELL
1011               || gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(page->default_dictionary_rec_checkbtn))
1012               || gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(page->default_alt_dictionary_rec_checkbtn))
1013 #endif
1014                     ))
1015                 return TRUE;
1016         else 
1017                 return FALSE;
1018 }
1019
1020 static void prefs_folder_item_compose_save_func(PrefsPage *page_) 
1021 {
1022         FolderItemComposePage *page = (FolderItemComposePage *) page_;
1023
1024         g_node_traverse(page->item->node, G_PRE_ORDER, G_TRAVERSE_ALL,
1025                         -1, compose_save_recurse_func, page);
1026
1027 }
1028
1029 static gint prefs_folder_item_chmod_mode(gchar *folder_chmod) 
1030 {
1031         gint newmode = 0;
1032         gchar *tmp;
1033
1034         if (folder_chmod) {
1035                 newmode = strtol(folder_chmod, &tmp, 8);
1036                 if (!(*(folder_chmod) && !(*tmp)))
1037                         newmode = 0;
1038         }
1039
1040         return newmode;
1041 }
1042
1043 static void folder_color_set_dialog(GtkWidget *widget, gpointer data)
1044 {
1045         FolderItemGeneralPage *page = (FolderItemGeneralPage *) data;
1046         gint rgbcolor;
1047
1048         rgbcolor = colorsel_select_color_rgb(_("Pick color for folder"), 
1049                                              page->folder_color);
1050         gtkut_set_widget_bgcolor_rgb(page->folder_color_btn, rgbcolor);
1051         page->folder_color = rgbcolor;
1052 }
1053
1054 static regex_t *summary_compile_simplify_regexp(gchar *simplify_subject_regexp)
1055 {
1056         int err;
1057         gchar buf[BUFFSIZE];
1058         regex_t *preg = NULL;
1059
1060         preg = g_new0(regex_t, 1);
1061
1062         err = string_match_precompile(simplify_subject_regexp, 
1063                                       preg, REG_EXTENDED);
1064         if (err) {
1065                 regerror(err, preg, buf, BUFFSIZE);
1066                 g_free(preg);
1067                 preg = NULL;
1068         }
1069
1070         return preg;
1071 }
1072
1073 static void folder_regexp_test_cb(GtkWidget *widget, gpointer data)
1074 {
1075         static GdkColor red;
1076         static gboolean colors_initialised = FALSE;
1077         static gchar buf[BUFFSIZE];
1078         FolderItemGeneralPage *page = (FolderItemGeneralPage *)data;
1079         gchar *test_string, *regexp;
1080         regex_t *preg;
1081
1082         regexp = g_strdup(gtk_entry_get_text(GTK_ENTRY(page->entry_simplify_subject)));
1083         test_string = g_strdup(gtk_entry_get_text(GTK_ENTRY(page->entry_regexp_test_string)));
1084
1085         if (!regexp || !regexp[0]) {
1086                 gtk_widget_modify_base(page->entry_simplify_subject,
1087                                 GTK_STATE_NORMAL, NULL);
1088                 if (test_string) {
1089                         gtk_entry_set_text(GTK_ENTRY(page->entry_regexp_test_result), test_string);
1090                         g_free(test_string);
1091                 }
1092                 return;
1093         }
1094
1095         if (!test_string || !test_string[0]) {
1096                 g_free(regexp);
1097                 return;
1098         }
1099
1100         if (!colors_initialised) {
1101                 gdk_color_parse("#ff7070", &red);
1102                 colors_initialised = gdk_colormap_alloc_color(
1103                         gdk_colormap_get_system(), &red, FALSE, TRUE);
1104         }
1105
1106         preg = summary_compile_simplify_regexp(regexp);
1107         if (colors_initialised) {
1108                 gtk_widget_modify_base(page->entry_simplify_subject,
1109                                 GTK_STATE_NORMAL, preg ? NULL : &red);
1110         }
1111
1112         if (preg != NULL) {
1113                 string_remove_match(buf, BUFFSIZE, test_string, preg);
1114
1115                 gtk_entry_set_text(GTK_ENTRY(page->entry_regexp_test_result), buf);
1116
1117                 regfree(preg);
1118                 g_free(preg);
1119         }
1120
1121         g_free(test_string);
1122         g_free(regexp);
1123 }
1124
1125 static gchar *folder_regexp_get_subject_example(void)
1126 {
1127         MsgInfo *msginfo_selected;
1128         SummaryView *summaryview = NULL;
1129
1130         if (!mainwindow_get_mainwindow())
1131                 return NULL;
1132         summaryview = mainwindow_get_mainwindow()->summaryview;
1133
1134         msginfo_selected = summary_get_selected_msg(summaryview);
1135         return msginfo_selected ? g_strdup(msginfo_selected->subject) : NULL;
1136 }
1137
1138 static void folder_regexp_set_subject_example_cb(GtkWidget *widget, gpointer data)
1139 {
1140         FolderItemGeneralPage *page = (FolderItemGeneralPage *)data;
1141
1142         if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(page->checkbtn_simplify_subject))) {
1143                 gchar *subject = folder_regexp_get_subject_example();
1144                 if (subject) {
1145                         gtk_entry_set_text(GTK_ENTRY(page->entry_regexp_test_string), subject);
1146                         g_free(subject);
1147                 }
1148         }
1149 }
1150
1151 static void register_general_page()
1152 {
1153         static gchar *pfi_general_path[2];
1154         static FolderItemGeneralPage folder_item_general_page;
1155
1156         pfi_general_path[0] = _("General");
1157         pfi_general_path[1] = NULL;
1158
1159         folder_item_general_page.page.path = pfi_general_path;
1160         folder_item_general_page.page.create_widget = prefs_folder_item_general_create_widget_func;
1161         folder_item_general_page.page.destroy_widget = prefs_folder_item_general_destroy_widget_func;
1162         folder_item_general_page.page.save_page = prefs_folder_item_general_save_func;
1163         
1164         prefs_folder_item_register_page((PrefsPage *) &folder_item_general_page);
1165 }
1166
1167
1168 static void register_compose_page(void)
1169 {
1170         static gchar *pfi_compose_path[2];
1171         static FolderItemComposePage folder_item_compose_page;
1172
1173         pfi_compose_path[0] = _("Compose");
1174         pfi_compose_path[1] = NULL;
1175
1176         folder_item_compose_page.page.path = pfi_compose_path;
1177         folder_item_compose_page.page.create_widget = prefs_folder_item_compose_create_widget_func;
1178         folder_item_compose_page.page.destroy_widget = prefs_folder_item_compose_destroy_widget_func;
1179         folder_item_compose_page.page.save_page = prefs_folder_item_compose_save_func;
1180         
1181         prefs_folder_item_register_page((PrefsPage *) &folder_item_compose_page);
1182 }
1183
1184 static GSList *prefs_pages = NULL;
1185
1186 void prefs_folder_item_open(FolderItem *item)
1187 {
1188         gchar *id, *title;
1189         if (prefs_pages == NULL) {
1190                 register_general_page();
1191                 register_compose_page();
1192         }
1193
1194         if (item->path) {
1195                 id = folder_item_get_identifier (item);
1196                 can_save = TRUE;
1197         } else {
1198                 id = g_strdup(item->name);
1199                 can_save = FALSE;
1200         }
1201         title = g_strdup_printf (_("Properties for folder %s"), id);
1202         g_free (id);
1203         prefswindow_open(title, prefs_pages, item,
1204                         &prefs_common.folderitemwin_width, &prefs_common.folderitemwin_height);
1205         
1206         g_free (title);
1207 }
1208
1209 void prefs_folder_item_register_page(PrefsPage *page)
1210 {
1211         prefs_pages = g_slist_append(prefs_pages, page);
1212 }
1213
1214 void prefs_folder_item_unregister_page(PrefsPage *page)
1215 {
1216         prefs_pages = g_slist_remove(prefs_pages, page);
1217 }