2007-01-10 [colin] 2.7.0cvs6
[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 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 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_chkbtn;
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_chkbtn = gtk_check_button_new();
249         gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(dummy_chkbtn), type != F_INBOX);
250         gtk_widget_set_sensitive(dummy_chkbtn, 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_chkbtn, 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 startup"));
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 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 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 void prefs_folder_item_compose_create_widget_func(PrefsPage * page_,
584                                                    GtkWindow * window,
585                                                    gpointer data)
586 {
587         FolderItemComposePage *page = (FolderItemComposePage *) page_;
588         FolderItem *item = (FolderItem *) data;
589         guint rowcount;
590
591         GtkWidget *table;
592         GtkWidget *label;
593         
594         GtkWidget *no_save_warning = NULL;
595         GtkWidget *checkbtn_request_return_receipt = NULL;
596         GtkWidget *checkbtn_save_copy_to_folder = NULL;
597         GtkWidget *checkbtn_default_to = NULL;
598         GtkWidget *entry_default_to = NULL;
599         GtkWidget *checkbtn_default_reply_to = NULL;
600         GtkWidget *entry_default_reply_to = NULL;
601         GtkWidget *checkbtn_enable_default_account = NULL;
602         GtkWidget *optmenu_default_account = NULL;
603         GtkWidget *optmenu_default_account_menu = NULL;
604         GtkWidget *optmenu_default_account_menuitem = NULL;
605 #if USE_ASPELL
606         GtkWidget *checkbtn_enable_default_dictionary = NULL;
607         GtkWidget *optmenu_default_dictionary = NULL;
608         GtkWidget *checkbtn_enable_default_alt_dictionary = NULL;
609         GtkWidget *optmenu_default_alt_dictionary = NULL;
610 #endif
611         GtkWidget *request_return_receipt_rec_checkbtn = NULL;
612         GtkWidget *save_copy_to_folder_rec_checkbtn = NULL;
613         GtkWidget *default_to_rec_checkbtn = NULL;
614         GtkWidget *default_reply_to_rec_checkbtn = NULL;
615         GtkWidget *default_account_rec_checkbtn = NULL;
616 #if USE_ASPELL
617         GtkWidget *default_dictionary_rec_checkbtn = NULL;
618         GtkWidget *default_alt_dictionary_rec_checkbtn = NULL;
619 #endif
620
621         GList *cur_ac;
622         GList *account_list;
623 #if USE_ASPELL
624         gchar *dictionary;
625 #endif
626         PrefsAccount *ac_prefs;
627         GtkOptionMenu *optmenu;
628         GtkWidget *menu;
629         GtkWidget *menuitem;
630         gint account_index, index;
631
632         page->item         = item;
633
634         /* Table */
635 #if USE_ASPELL
636 # define TABLEHEIGHT 7
637 #else
638 # define TABLEHEIGHT 6
639 #endif
640         table = gtk_table_new(TABLEHEIGHT, 3, FALSE);
641         gtk_container_set_border_width (GTK_CONTAINER (table), VBOX_BORDER);
642         gtk_table_set_row_spacings(GTK_TABLE(table), 4);
643         gtk_table_set_col_spacings(GTK_TABLE(table), 4);
644         rowcount = 0;
645
646         if (!can_save) {
647                 no_save_warning = gtk_label_new(
648                         _("<i>These preferences will not be saved as this folder "
649                         "is a top-level one. However you can use them to set them "
650                         "to the whole mailbox tree using \"Apply to subfolders\".</i>"));
651                 gtk_label_set_use_markup(GTK_LABEL(no_save_warning), TRUE);
652                 gtk_label_set_line_wrap(GTK_LABEL(no_save_warning), TRUE);
653                 gtk_misc_set_alignment(GTK_MISC(no_save_warning), 0.0, 0.5);
654                 gtk_table_attach(GTK_TABLE(table), no_save_warning, 0, 3,
655                          rowcount, rowcount + 1, GTK_FILL, 0, 0, 0);
656                 rowcount++;
657         }
658         
659         /* Apply to subfolders */
660         label = gtk_label_new(_("Apply to\nsubfolders"));
661         gtk_misc_set_alignment(GTK_MISC(label), 0.5, 0.5);
662         gtk_table_attach(GTK_TABLE(table), label, 2, 3,
663                          rowcount, rowcount + 1, GTK_SHRINK, GTK_SHRINK, 0, 0);
664         rowcount++;
665
666         if (item_protocol(item) != A_NNTP) {
667                 /* Request Return Receipt */
668                 checkbtn_request_return_receipt = gtk_check_button_new_with_label
669                         (_("Request Return Receipt"));
670                 gtk_table_attach(GTK_TABLE(table), checkbtn_request_return_receipt, 
671                                  0, 2, rowcount, rowcount + 1, GTK_SHRINK | GTK_FILL, 
672                                  GTK_FILL, 0, 0);
673                 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(checkbtn_request_return_receipt),
674                                              item->ret_rcpt ? TRUE : FALSE);
675
676                 request_return_receipt_rec_checkbtn = gtk_check_button_new();
677                 gtk_table_attach(GTK_TABLE(table), request_return_receipt_rec_checkbtn, 2, 3, 
678                                  rowcount, rowcount + 1, GTK_SHRINK, GTK_SHRINK, 0, 0);
679
680                 rowcount++;
681
682                 /* Save Copy to Folder */
683                 checkbtn_save_copy_to_folder = gtk_check_button_new_with_label
684                         (_("Save copy of outgoing messages to this folder instead of Sent"));
685                 gtk_table_attach(GTK_TABLE(table), checkbtn_save_copy_to_folder, 0, 2, 
686                                  rowcount, rowcount + 1, GTK_SHRINK | GTK_FILL, GTK_FILL, 0, 0);
687                 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(checkbtn_save_copy_to_folder),
688                                              item->prefs->save_copy_to_folder ? TRUE : FALSE);
689
690                 save_copy_to_folder_rec_checkbtn = gtk_check_button_new();
691                 gtk_table_attach(GTK_TABLE(table), save_copy_to_folder_rec_checkbtn, 2, 3, 
692                                  rowcount, rowcount + 1, GTK_SHRINK, GTK_SHRINK, 0, 0);
693
694                 rowcount++;
695
696                 /* Default To */
697                 checkbtn_default_to = gtk_check_button_new_with_label(_("Default To:"));
698                 gtk_table_attach(GTK_TABLE(table), checkbtn_default_to, 0, 1, 
699                                  rowcount, rowcount + 1, GTK_SHRINK | GTK_FILL, GTK_SHRINK, 0, 0);
700                 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(checkbtn_default_to), 
701                                              item->prefs->enable_default_to);
702
703                 entry_default_to = gtk_entry_new();
704                 gtk_table_attach(GTK_TABLE(table), entry_default_to, 1, 2,
705                                  rowcount, rowcount + 1, GTK_EXPAND | GTK_FILL, GTK_SHRINK, 0, 0);
706                 SET_TOGGLE_SENSITIVITY(checkbtn_default_to, entry_default_to);
707                 gtk_entry_set_text(GTK_ENTRY(entry_default_to), SAFE_STRING(item->prefs->default_to));
708                 address_completion_register_entry(GTK_ENTRY(entry_default_to),
709                                 TRUE);
710
711                 default_to_rec_checkbtn = gtk_check_button_new();
712                 gtk_table_attach(GTK_TABLE(table), default_to_rec_checkbtn, 2, 3, 
713                                  rowcount, rowcount + 1, GTK_SHRINK, GTK_SHRINK, 0, 0);
714
715                 rowcount++;
716
717                 /* Default address to reply to */
718                 checkbtn_default_reply_to = gtk_check_button_new_with_label(_("Default To: for replies"));
719                 gtk_table_attach(GTK_TABLE(table), checkbtn_default_reply_to, 0, 1, 
720                                  rowcount, rowcount + 1, GTK_SHRINK | GTK_FILL, GTK_SHRINK, 0, 0);
721                 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(checkbtn_default_reply_to), 
722                                              item->prefs->enable_default_reply_to);
723
724                 entry_default_reply_to = gtk_entry_new();
725                 gtk_table_attach(GTK_TABLE(table), entry_default_reply_to, 1, 2,
726                                  rowcount, rowcount + 1, GTK_EXPAND | GTK_FILL, GTK_SHRINK, 0, 0);
727                 SET_TOGGLE_SENSITIVITY(checkbtn_default_reply_to, entry_default_reply_to);
728                 gtk_entry_set_text(GTK_ENTRY(entry_default_reply_to), SAFE_STRING(item->prefs->default_reply_to));
729                 address_completion_register_entry(
730                                 GTK_ENTRY(entry_default_reply_to), TRUE);
731
732                 default_reply_to_rec_checkbtn = gtk_check_button_new();
733                 gtk_table_attach(GTK_TABLE(table), default_reply_to_rec_checkbtn, 2, 3, 
734                                  rowcount, rowcount + 1, GTK_SHRINK, GTK_SHRINK, 0, 0);
735
736                 rowcount++;
737         }
738         /* Default account */
739         checkbtn_enable_default_account = gtk_check_button_new_with_label(_("Default account"));
740         gtk_table_attach(GTK_TABLE(table), checkbtn_enable_default_account, 0, 1, 
741                          rowcount, rowcount + 1, GTK_SHRINK | GTK_FILL, GTK_SHRINK, 0, 0);
742         gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(checkbtn_enable_default_account), 
743                                      item->prefs->enable_default_account);
744
745         optmenu_default_account = gtk_option_menu_new ();
746         gtk_table_attach(GTK_TABLE(table), optmenu_default_account, 1, 2, 
747                          rowcount, rowcount + 1, GTK_EXPAND | GTK_FILL, GTK_SHRINK, 0, 0);
748         optmenu_default_account_menu = gtk_menu_new ();
749
750         account_list = account_get_list();
751         account_index = 0;
752         index = 0;
753         for (cur_ac = account_list; cur_ac != NULL; cur_ac = cur_ac->next) {
754                 ac_prefs = (PrefsAccount *)cur_ac->data;
755                 if (item->folder->account &&
756                     ( (item_protocol(item) == A_NNTP && ac_prefs->protocol != A_NNTP)
757                     ||(item_protocol(item) != A_NNTP && ac_prefs->protocol == A_NNTP))) 
758                         continue;
759
760                 if (item->folder->klass->type != F_NEWS && ac_prefs->protocol == A_NNTP)
761                         continue;
762
763                 MENUITEM_ADD (optmenu_default_account_menu, optmenu_default_account_menuitem,
764                                         ac_prefs->account_name?ac_prefs->account_name : _("Untitled"),
765                                         ac_prefs->account_id);
766                 /* get the index for menu's set_history (sad method?) */
767                 if (ac_prefs->account_id == item->prefs->default_account)
768                         account_index = index;
769                 index++;                        
770         }
771
772         optmenu = GTK_OPTION_MENU(optmenu_default_account);
773         gtk_option_menu_set_menu(optmenu, optmenu_default_account_menu);
774
775         gtk_option_menu_set_history(optmenu, account_index);
776
777         menu = gtk_option_menu_get_menu(optmenu);
778         menuitem = gtk_menu_get_active(GTK_MENU(menu));
779         gtk_menu_item_activate(GTK_MENU_ITEM(menuitem));
780
781         SET_TOGGLE_SENSITIVITY(checkbtn_enable_default_account, optmenu_default_account);
782
783         default_account_rec_checkbtn = gtk_check_button_new();
784         gtk_table_attach(GTK_TABLE(table), default_account_rec_checkbtn, 2, 3, 
785                          rowcount, rowcount + 1, GTK_SHRINK, GTK_SHRINK, 0, 0);
786         rowcount++;
787
788 #if USE_ASPELL
789         /* Default dictionary */
790         checkbtn_enable_default_dictionary = gtk_check_button_new_with_label(_("Default dictionary"));
791         gtk_table_attach(GTK_TABLE(table), checkbtn_enable_default_dictionary, 0, 1,
792                          rowcount, rowcount + 1, GTK_SHRINK | GTK_FILL, GTK_SHRINK, 0, 0);
793         gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(checkbtn_enable_default_dictionary),
794                                      item->prefs->enable_default_dictionary);
795
796         optmenu_default_dictionary = gtk_option_menu_new();
797         gtk_table_attach(GTK_TABLE(table), optmenu_default_dictionary, 1, 2,
798                          rowcount, rowcount + 1, GTK_EXPAND | GTK_FILL, GTK_SHRINK, 0, 0);
799
800         gtk_option_menu_set_menu(GTK_OPTION_MENU(optmenu_default_dictionary), 
801                                  gtkaspell_dictionary_option_menu_new(
802                                          prefs_common.aspell_path));
803
804         dictionary = item->prefs->default_dictionary;
805
806         optmenu = GTK_OPTION_MENU(optmenu_default_dictionary);
807
808         menu = gtk_option_menu_get_menu(optmenu);
809         if (dictionary)
810                 gtkaspell_set_dictionary_menu_active_item(optmenu_default_dictionary, dictionary);
811         menuitem = gtk_menu_get_active(GTK_MENU(menu));
812         gtk_menu_item_activate(GTK_MENU_ITEM(menuitem));
813
814         SET_TOGGLE_SENSITIVITY(checkbtn_enable_default_dictionary, optmenu_default_dictionary);
815
816         default_dictionary_rec_checkbtn = gtk_check_button_new();
817         gtk_table_attach(GTK_TABLE(table), default_dictionary_rec_checkbtn, 2, 3, 
818                          rowcount, rowcount + 1, GTK_SHRINK, GTK_SHRINK, 0, 0);
819         
820         rowcount++;
821
822         /* Default dictionary */
823         checkbtn_enable_default_alt_dictionary = gtk_check_button_new_with_label(_("Default alternate dictionary"));
824         gtk_table_attach(GTK_TABLE(table), checkbtn_enable_default_alt_dictionary, 0, 1,
825                          rowcount, rowcount + 1, GTK_SHRINK | GTK_FILL, GTK_SHRINK, 0, 0);
826         gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(checkbtn_enable_default_alt_dictionary),
827                                      item->prefs->enable_default_alt_dictionary);
828
829         optmenu_default_alt_dictionary = gtk_option_menu_new();
830         gtk_table_attach(GTK_TABLE(table), optmenu_default_alt_dictionary, 1, 2,
831                          rowcount, rowcount + 1, GTK_EXPAND | GTK_FILL, GTK_SHRINK, 0, 0);
832
833         gtk_option_menu_set_menu(GTK_OPTION_MENU(optmenu_default_alt_dictionary), 
834                                  gtkaspell_dictionary_option_menu_new_with_refresh(
835                                          prefs_common.aspell_path, FALSE));
836
837         dictionary = item->prefs->default_alt_dictionary;
838
839         optmenu = GTK_OPTION_MENU(optmenu_default_alt_dictionary);
840
841         menu = gtk_option_menu_get_menu(optmenu);
842         if (dictionary)
843                 gtkaspell_set_dictionary_menu_active_item(optmenu_default_alt_dictionary, dictionary);
844         menuitem = gtk_menu_get_active(GTK_MENU(menu));
845         gtk_menu_item_activate(GTK_MENU_ITEM(menuitem));
846
847         SET_TOGGLE_SENSITIVITY(checkbtn_enable_default_alt_dictionary, optmenu_default_alt_dictionary);
848
849         default_alt_dictionary_rec_checkbtn = gtk_check_button_new();
850         gtk_table_attach(GTK_TABLE(table), default_alt_dictionary_rec_checkbtn, 2, 3, 
851                          rowcount, rowcount + 1, GTK_SHRINK, GTK_SHRINK, 0, 0);
852         
853         rowcount++;
854 #endif
855
856         gtk_widget_show_all(table);
857
858         page->window = GTK_WIDGET(window);
859         page->table = table;
860         page->no_save_warning = no_save_warning;
861         page->checkbtn_request_return_receipt = checkbtn_request_return_receipt;
862         page->checkbtn_save_copy_to_folder = checkbtn_save_copy_to_folder;
863         page->checkbtn_default_to = checkbtn_default_to;
864         page->entry_default_to = entry_default_to;
865         page->checkbtn_default_reply_to = checkbtn_default_reply_to;
866         page->entry_default_reply_to = entry_default_reply_to;
867         page->checkbtn_enable_default_account = checkbtn_enable_default_account;
868         page->optmenu_default_account = optmenu_default_account;
869 #ifdef USE_ASPELL
870         page->checkbtn_enable_default_dictionary = checkbtn_enable_default_dictionary;
871         page->optmenu_default_dictionary = optmenu_default_dictionary;
872         page->checkbtn_enable_default_alt_dictionary = checkbtn_enable_default_alt_dictionary;
873         page->optmenu_default_alt_dictionary = optmenu_default_alt_dictionary;
874 #endif
875
876         page->request_return_receipt_rec_checkbtn = request_return_receipt_rec_checkbtn;
877         page->save_copy_to_folder_rec_checkbtn    = save_copy_to_folder_rec_checkbtn;
878         page->default_to_rec_checkbtn             = default_to_rec_checkbtn;
879         page->default_reply_to_rec_checkbtn       = default_reply_to_rec_checkbtn;
880         page->default_account_rec_checkbtn        = default_account_rec_checkbtn;
881 #if USE_ASPELL
882         page->default_dictionary_rec_checkbtn = default_dictionary_rec_checkbtn;
883         page->default_alt_dictionary_rec_checkbtn = default_alt_dictionary_rec_checkbtn;
884 #endif
885
886         address_completion_start(page->window);
887
888         page->page.widget = table;
889 }
890
891 void prefs_folder_item_compose_destroy_widget_func(PrefsPage *page_) 
892 {
893         FolderItemComposePage *page = (FolderItemComposePage *) page_;
894
895         if (page->entry_default_to)
896                 address_completion_unregister_entry(GTK_ENTRY(page->entry_default_to));
897         if (page->entry_default_reply_to)
898                 address_completion_unregister_entry(GTK_ENTRY(page->entry_default_reply_to));
899         address_completion_end(page->window);
900 }
901
902 /** \brief  Save the prefs in page to folder.
903  *
904  *  If the folder is not the one  specified in page->item, then only those properties 
905  *  that have the relevant 'apply to sub folders' button checked are saved
906  */
907 static void compose_save_folder_prefs(FolderItem *folder, FolderItemComposePage *page)
908 {
909         FolderItemPrefs *prefs = folder->prefs;
910         GtkWidget *menu;
911         GtkWidget *menuitem;
912         gboolean all = FALSE;
913
914         if (folder->path == NULL)
915                 return;
916
917         if (page->item == folder) 
918                 all = TRUE;
919
920         g_return_if_fail(prefs != NULL);
921
922         if (item_protocol(folder) != A_NNTP) {
923                 if (all || gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(page->request_return_receipt_rec_checkbtn))) {
924                         prefs->request_return_receipt = 
925                                 gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(page->checkbtn_request_return_receipt));
926                         /* MIGRATION */    
927                         folder->ret_rcpt = prefs->request_return_receipt;
928                 }
929
930                 if (all || gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(page->save_copy_to_folder_rec_checkbtn))) {
931                         prefs->save_copy_to_folder = 
932                                 gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(page->checkbtn_save_copy_to_folder));
933                 }
934
935                 if (all || gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(page->default_to_rec_checkbtn))) {
936
937                         prefs->enable_default_to = 
938                                 gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(page->checkbtn_default_to));
939                         ASSIGN_STRING(prefs->default_to,
940                                       gtk_editable_get_chars(GTK_EDITABLE(page->entry_default_to), 0, -1));
941                 }
942
943                 if (all || gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(page->default_reply_to_rec_checkbtn))) {
944                         prefs->enable_default_reply_to = 
945                                 gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(page->checkbtn_default_reply_to));
946                         ASSIGN_STRING(prefs->default_reply_to,
947                                       gtk_editable_get_chars(GTK_EDITABLE(page->entry_default_reply_to), 0, -1));
948                 }
949         } else {
950                 prefs->request_return_receipt = FALSE;
951                 prefs->save_copy_to_folder = FALSE;
952                 prefs->enable_default_to = FALSE;
953                 prefs->enable_default_reply_to = FALSE;
954         }
955         if (all || gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(page->default_account_rec_checkbtn))) {
956                 prefs->enable_default_account = 
957                         gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(page->checkbtn_enable_default_account));
958                 menu = gtk_option_menu_get_menu(GTK_OPTION_MENU(page->optmenu_default_account));
959                 menuitem = gtk_menu_get_active(GTK_MENU(menu));
960                 prefs->default_account = GPOINTER_TO_INT(g_object_get_data(G_OBJECT(menuitem), MENU_VAL_ID));
961         }
962
963 #if USE_ASPELL
964         if (all || gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(page->default_dictionary_rec_checkbtn))) {
965                 prefs->enable_default_dictionary =
966                         gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(page->checkbtn_enable_default_dictionary));
967                 menu = gtk_option_menu_get_menu(GTK_OPTION_MENU(page->optmenu_default_dictionary));
968                 ASSIGN_STRING(prefs->default_dictionary,
969                               gtkaspell_get_dictionary_menu_active_item(menu));
970         }
971         if (all || gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(page->default_alt_dictionary_rec_checkbtn))) {
972                 prefs->enable_default_alt_dictionary =
973                         gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(page->checkbtn_enable_default_alt_dictionary));
974                 menu = gtk_option_menu_get_menu(GTK_OPTION_MENU(page->optmenu_default_alt_dictionary));
975                 ASSIGN_STRING(prefs->default_alt_dictionary,
976                               gtkaspell_get_dictionary_menu_active_item(menu));
977         }
978 #endif
979
980         folder_item_prefs_save_config(folder);
981 }       
982
983 static gboolean compose_save_recurse_func(GNode *node, gpointer data)
984 {
985         FolderItem *item = (FolderItem *) node->data;
986         FolderItemComposePage *page = (FolderItemComposePage *) data;
987
988         g_return_val_if_fail(item != NULL, TRUE);
989         g_return_val_if_fail(page != NULL, TRUE);
990
991         compose_save_folder_prefs(item, page);
992
993         /* optimise by not continuing if none of the 'apply to sub folders'
994            check boxes are selected - and optimise the checking by only doing
995            it once */
996         if ((node == page->item->node) && item_protocol(item) != A_NNTP &&
997             !(gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(page->request_return_receipt_rec_checkbtn)) ||
998               gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(page->save_copy_to_folder_rec_checkbtn)) ||
999               gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(page->default_to_rec_checkbtn)) ||
1000               gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(page->default_account_rec_checkbtn)) ||
1001 #if USE_ASPELL
1002               gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(page->default_dictionary_rec_checkbtn)) ||
1003               gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(page->default_alt_dictionary_rec_checkbtn)) ||
1004 #endif
1005               gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(page->default_reply_to_rec_checkbtn))))
1006                 return TRUE;
1007         else if ((node == page->item->node) && item_protocol(item) == A_NNTP &&
1008             !(gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(page->default_account_rec_checkbtn)) 
1009 #if USE_ASPELL
1010               || gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(page->default_dictionary_rec_checkbtn))
1011               || gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(page->default_alt_dictionary_rec_checkbtn))
1012 #endif
1013                     ))
1014                 return TRUE;
1015         else 
1016                 return FALSE;
1017 }
1018
1019 void prefs_folder_item_compose_save_func(PrefsPage *page_) 
1020 {
1021         FolderItemComposePage *page = (FolderItemComposePage *) page_;
1022
1023         g_node_traverse(page->item->node, G_PRE_ORDER, G_TRAVERSE_ALL,
1024                         -1, compose_save_recurse_func, page);
1025
1026 }
1027
1028 gint prefs_folder_item_chmod_mode(gchar *folder_chmod) 
1029 {
1030         gint newmode = 0;
1031         gchar *tmp;
1032
1033         if (folder_chmod) {
1034                 newmode = strtol(folder_chmod, &tmp, 8);
1035                 if (!(*(folder_chmod) && !(*tmp)))
1036                         newmode = 0;
1037         }
1038
1039         return newmode;
1040 }
1041
1042 static void folder_color_set_dialog(GtkWidget *widget, gpointer data)
1043 {
1044         FolderItemGeneralPage *page = (FolderItemGeneralPage *) data;
1045         gint rgbcolor;
1046
1047         rgbcolor = colorsel_select_color_rgb(_("Pick color for folder"), 
1048                                              page->folder_color);
1049         gtkut_set_widget_bgcolor_rgb(page->folder_color_btn, rgbcolor);
1050         page->folder_color = rgbcolor;
1051 }
1052
1053 static regex_t *summary_compile_simplify_regexp(gchar *simplify_subject_regexp)
1054 {
1055         int err;
1056         gchar buf[BUFFSIZE];
1057         regex_t *preg = NULL;
1058
1059         preg = g_new0(regex_t, 1);
1060
1061         err = string_match_precompile(simplify_subject_regexp, 
1062                                       preg, REG_EXTENDED);
1063         if (err) {
1064                 regerror(err, preg, buf, BUFFSIZE);
1065                 g_free(preg);
1066                 preg = NULL;
1067         }
1068
1069         return preg;
1070 }
1071
1072 static void folder_regexp_test_cb(GtkWidget *widget, gpointer data)
1073 {
1074         static GdkColor red;
1075         static gboolean colors_initialised = FALSE;
1076         static gchar buf[BUFFSIZE];
1077         FolderItemGeneralPage *page = (FolderItemGeneralPage *)data;
1078         gchar *test_string, *regexp;
1079         regex_t *preg;
1080
1081         regexp = g_strdup(gtk_entry_get_text(GTK_ENTRY(page->entry_simplify_subject)));
1082         test_string = g_strdup(gtk_entry_get_text(GTK_ENTRY(page->entry_regexp_test_string)));
1083
1084         if (!regexp || !regexp[0]) {
1085                 gtk_widget_modify_base(page->entry_simplify_subject,
1086                                 GTK_STATE_NORMAL, NULL);
1087                 if (test_string) {
1088                         gtk_entry_set_text(GTK_ENTRY(page->entry_regexp_test_result), test_string);
1089                         g_free(test_string);
1090                 }
1091                 return;
1092         }
1093
1094         if (!test_string || !test_string[0]) {
1095                 g_free(regexp);
1096                 return;
1097         }
1098
1099         if (!colors_initialised) {
1100                 gdk_color_parse("#ff7070", &red);
1101                 colors_initialised = gdk_colormap_alloc_color(
1102                         gdk_colormap_get_system(), &red, FALSE, TRUE);
1103         }
1104
1105         preg = summary_compile_simplify_regexp(regexp);
1106         if (colors_initialised) {
1107                 gtk_widget_modify_base(page->entry_simplify_subject,
1108                                 GTK_STATE_NORMAL, preg ? NULL : &red);
1109         }
1110
1111         if (preg != NULL) {
1112                 string_remove_match(buf, BUFFSIZE, test_string, preg);
1113
1114                 gtk_entry_set_text(GTK_ENTRY(page->entry_regexp_test_result), buf);
1115
1116                 regfree(preg);
1117                 g_free(preg);
1118         }
1119
1120         g_free(test_string);
1121         g_free(regexp);
1122 }
1123
1124 static gchar *folder_regexp_get_subject_example(void)
1125 {
1126         MsgInfo *msginfo_selected;
1127         SummaryView *summaryview = NULL;
1128
1129         if (!mainwindow_get_mainwindow())
1130                 return NULL;
1131         summaryview = mainwindow_get_mainwindow()->summaryview;
1132
1133         msginfo_selected = summary_get_selected_msg(summaryview);
1134         return msginfo_selected ? g_strdup(msginfo_selected->subject) : NULL;
1135 }
1136
1137 static void folder_regexp_set_subject_example_cb(GtkWidget *widget, gpointer data)
1138 {
1139         FolderItemGeneralPage *page = (FolderItemGeneralPage *)data;
1140
1141         if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(page->checkbtn_simplify_subject))) {
1142                 gchar *subject = folder_regexp_get_subject_example();
1143                 if (subject) {
1144                         gtk_entry_set_text(GTK_ENTRY(page->entry_regexp_test_string), subject);
1145                         g_free(subject);
1146                 }
1147         }
1148 }
1149
1150 static void register_general_page()
1151 {
1152         static gchar *pfi_general_path[2];
1153         static FolderItemGeneralPage folder_item_general_page;
1154
1155         pfi_general_path[0] = _("General");
1156         pfi_general_path[1] = NULL;
1157
1158         folder_item_general_page.page.path = pfi_general_path;
1159         folder_item_general_page.page.create_widget = prefs_folder_item_general_create_widget_func;
1160         folder_item_general_page.page.destroy_widget = prefs_folder_item_general_destroy_widget_func;
1161         folder_item_general_page.page.save_page = prefs_folder_item_general_save_func;
1162         
1163         prefs_folder_item_register_page((PrefsPage *) &folder_item_general_page);
1164 }
1165
1166
1167 static void register_compose_page(void)
1168 {
1169         static gchar *pfi_compose_path[2];
1170         static FolderItemComposePage folder_item_compose_page;
1171
1172         pfi_compose_path[0] = _("Compose");
1173         pfi_compose_path[1] = NULL;
1174
1175         folder_item_compose_page.page.path = pfi_compose_path;
1176         folder_item_compose_page.page.create_widget = prefs_folder_item_compose_create_widget_func;
1177         folder_item_compose_page.page.destroy_widget = prefs_folder_item_compose_destroy_widget_func;
1178         folder_item_compose_page.page.save_page = prefs_folder_item_compose_save_func;
1179         
1180         prefs_folder_item_register_page((PrefsPage *) &folder_item_compose_page);
1181 }
1182
1183 static GSList *prefs_pages = NULL;
1184
1185 void prefs_folder_item_open(FolderItem *item)
1186 {
1187         gchar *id, *title;
1188         if (prefs_pages == NULL) {
1189                 register_general_page();
1190                 register_compose_page();
1191         }
1192
1193         if (item->path) {
1194                 id = folder_item_get_identifier (item);
1195                 can_save = TRUE;
1196         } else {
1197                 id = g_strdup(item->name);
1198                 can_save = FALSE;
1199         }
1200         title = g_strdup_printf (_("Properties for folder %s"), id);
1201         g_free (id);
1202         prefswindow_open(title, prefs_pages, item,
1203                         &prefs_common.folderitemwin_width, &prefs_common.folderitemwin_height);
1204         
1205         g_free (title);
1206 }
1207
1208 void prefs_folder_item_register_page(PrefsPage *page)
1209 {
1210         prefs_pages = g_slist_append(prefs_pages, page);
1211 }
1212
1213 void prefs_folder_item_unregister_page(PrefsPage *page)
1214 {
1215         prefs_pages = g_slist_remove(prefs_pages, page);
1216 }