2004-10-26 [colin] 0.9.12cvs132.2
[claws.git] / src / prefs_folder_item.c
1 /*
2  * Sylpheed -- a GTK+ based, lightweight, and fast e-mail client
3  * Copyright (C) 1999-2001 Hiroyuki Yamamoto
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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, 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 "intl.h"
29 #include "defs.h"
30 #include "folder.h"
31 #include "prefs_folder_item.h"
32 #include "folderview.h"
33 #include "summaryview.h"
34 #include "menu.h"
35 #include "account.h"
36 #include "prefs_gtk.h"
37 #include "manage_window.h"
38 #include "utils.h"
39 #include "addr_compl.h"
40 #include "prefs_common.h"
41 #include "gtkutils.h"
42 #include "filtering.h"
43 #include "folder_item_prefs.h"
44 #include "gtk/colorsel.h"
45
46 #if USE_ASPELL
47 #include "gtkaspell.h"
48 #endif
49
50 #define ASSIGN_STRING(string, value) \
51         { \
52                 g_free(string); \
53                 string = (value); \
54         }
55
56 typedef struct _FolderItemGeneralPage FolderItemGeneralPage;
57 typedef struct _FolderItemComposePage FolderItemComposePage;
58
59 struct _FolderItemGeneralPage
60 {
61         PrefsPage page;
62
63         FolderItem *item;
64
65         GtkWidget *table;
66         GtkWidget *checkbtn_simplify_subject;
67         GtkWidget *entry_simplify_subject;
68         GtkWidget *checkbtn_folder_chmod;
69         GtkWidget *entry_folder_chmod;
70         GtkWidget *folder_color_btn;
71         GtkWidget *checkbtn_enable_processing;
72         GtkWidget *checkbtn_newmailcheck;
73
74         /* appy to sub folders */
75         GtkWidget *simplify_subject_rec_checkbtn;
76         GtkWidget *folder_chmod_rec_checkbtn;
77         GtkWidget *folder_color_rec_checkbtn;
78         GtkWidget *enable_processing_rec_checkbtn;
79         GtkWidget *newmailcheck_rec_checkbtn;
80
81         gint       folder_color;
82 };
83
84 struct _FolderItemComposePage
85 {
86         PrefsPage page;
87
88         FolderItem *item;
89
90         GtkWidget *window;
91         GtkWidget *table;
92         GtkWidget *checkbtn_request_return_receipt;
93         GtkWidget *checkbtn_save_copy_to_folder;
94         GtkWidget *checkbtn_default_to;
95         GtkWidget *entry_default_to;
96         GtkWidget *checkbtn_default_reply_to;
97         GtkWidget *entry_default_reply_to;
98         GtkWidget *checkbtn_enable_default_account;
99         GtkWidget *optmenu_default_account;
100 #if USE_ASPELL
101         GtkWidget *checkbtn_enable_default_dictionary;
102         GtkWidget *optmenu_default_dictionary;
103 #endif
104
105         /* apply to sub folders */
106         GtkWidget *request_return_receipt_rec_checkbtn;
107         GtkWidget *save_copy_to_folder_rec_checkbtn;
108         GtkWidget *default_to_rec_checkbtn;
109         GtkWidget *default_reply_to_rec_checkbtn;
110         GtkWidget *default_account_rec_checkbtn;
111 #if USE_ASPELL
112         GtkWidget *default_dictionary_rec_checkbtn;
113 #endif
114
115 };
116
117
118 static void general_save_folder_prefs(FolderItem *folder, FolderItemGeneralPage *page);
119 static void compose_save_folder_prefs(FolderItem *folder, FolderItemComposePage *page);
120
121 static gboolean general_save_recurse_func(GNode *node, gpointer data);
122 static gboolean compose_save_recurse_func(GNode *node, gpointer data);
123
124 gint prefs_folder_item_chmod_mode               (gchar *folder_chmod);
125
126 static void folder_color_set_dialog(GtkWidget *widget, gpointer data);
127
128 #define SAFE_STRING(str) \
129         (str) ? (str) : ""
130
131 void prefs_folder_item_general_create_widget_func(PrefsPage * page_,
132                                                    GtkWindow * window,
133                                                    gpointer data)
134 {
135         FolderItemGeneralPage *page = (FolderItemGeneralPage *) page_;
136         FolderItem *item = (FolderItem *) data;
137         guint rowcount;
138
139         GtkWidget *table;
140         GtkWidget *hbox;
141         GtkWidget *label;
142         
143         GtkWidget *checkbtn_simplify_subject;
144         GtkWidget *entry_simplify_subject;
145         GtkWidget *checkbtn_folder_chmod;
146         GtkWidget *entry_folder_chmod;
147         GtkWidget *folder_color;
148         GtkWidget *folder_color_btn;
149         GtkWidget *checkbtn_enable_processing;
150         GtkWidget *checkbtn_newmailcheck;
151
152         GtkWidget *simplify_subject_rec_checkbtn;
153         GtkWidget *folder_chmod_rec_checkbtn;
154         GtkWidget *folder_color_rec_checkbtn;
155         GtkWidget *enable_processing_rec_checkbtn;
156         GtkWidget *newmailcheck_rec_checkbtn;
157         
158         page->item         = item;
159
160         /* Table */
161         table = gtk_table_new(5, 2, FALSE);
162         gtk_table_set_row_spacings(GTK_TABLE(table), 4);
163         gtk_table_set_col_spacings(GTK_TABLE(table), 4);
164         rowcount = 0;
165
166         /* Apply to subfolders */
167         label = gtk_label_new(_("Apply to\nsubfolders"));
168         gtk_misc_set_alignment(GTK_MISC(label), 0.5, 0.5);
169         gtk_table_attach(GTK_TABLE(table), label, 2, 3,
170                          rowcount, rowcount + 1, GTK_SHRINK, GTK_SHRINK, 0, 0);
171         rowcount++;
172
173         /* Simplify Subject */
174         checkbtn_simplify_subject = gtk_check_button_new_with_label(_("Simplify Subject RegExp: "));
175         gtk_table_attach(GTK_TABLE(table), checkbtn_simplify_subject, 0, 1, 
176                          rowcount, rowcount + 1, GTK_SHRINK | GTK_FILL, GTK_FILL, 0, 0);
177         gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(checkbtn_simplify_subject), 
178                                      item->prefs->enable_simplify_subject);
179
180         entry_simplify_subject = gtk_entry_new();
181         gtk_table_attach(GTK_TABLE(table), entry_simplify_subject, 1, 2, 
182                          rowcount, rowcount + 1, GTK_EXPAND | GTK_FILL, GTK_FILL, 0, 0);
183         SET_TOGGLE_SENSITIVITY(checkbtn_simplify_subject, entry_simplify_subject);
184         gtk_entry_set_text(GTK_ENTRY(entry_simplify_subject), 
185                            SAFE_STRING(item->prefs->simplify_subject_regexp));
186
187         simplify_subject_rec_checkbtn = gtk_check_button_new();
188         gtk_table_attach(GTK_TABLE(table), simplify_subject_rec_checkbtn, 2, 3, 
189                          rowcount, rowcount + 1, GTK_SHRINK, GTK_SHRINK, 0, 0);
190
191         rowcount++;
192
193         /* Folder chmod */
194         checkbtn_folder_chmod = gtk_check_button_new_with_label(_("Folder chmod: "));
195         gtk_table_attach(GTK_TABLE(table), checkbtn_folder_chmod, 0, 1, 
196                          rowcount, rowcount + 1, GTK_SHRINK | GTK_FILL, GTK_FILL, 0, 0);
197
198         gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(checkbtn_folder_chmod), 
199                                      item->prefs->enable_folder_chmod);
200
201         entry_folder_chmod = gtk_entry_new();
202         gtk_table_attach(GTK_TABLE(table), entry_folder_chmod, 1, 2, 
203                          rowcount, rowcount + 1, GTK_EXPAND | GTK_FILL, GTK_FILL, 0, 0);
204         SET_TOGGLE_SENSITIVITY(checkbtn_folder_chmod, entry_folder_chmod);
205         if (item->prefs->folder_chmod) {
206                 gchar *buf;
207
208                 buf = g_strdup_printf("%o", item->prefs->folder_chmod);
209                 gtk_entry_set_text(GTK_ENTRY(entry_folder_chmod), buf);
210                 g_free(buf);
211         }
212         
213         folder_chmod_rec_checkbtn = gtk_check_button_new();
214         gtk_table_attach(GTK_TABLE(table), folder_chmod_rec_checkbtn, 2, 3, 
215                          rowcount, rowcount + 1, GTK_SHRINK, GTK_SHRINK, 0, 0);
216
217         rowcount++;
218         
219         /* Folder color */
220         folder_color = gtk_label_new(_("Folder color: "));
221         gtk_misc_set_alignment(GTK_MISC(folder_color), 0, 0.5);
222         gtk_table_attach(GTK_TABLE(table), folder_color, 0, 1, 
223                          rowcount, rowcount + 1, GTK_SHRINK | GTK_FILL, GTK_FILL, 0, 0);
224
225         hbox = gtk_hbox_new(FALSE, 0);
226         gtk_table_attach(GTK_TABLE(table), hbox, 1, 2, 
227                          rowcount, rowcount + 1, GTK_EXPAND | GTK_FILL, GTK_FILL, 0, 0);
228
229         folder_color_btn = gtk_button_new_with_label("");
230         gtk_widget_set_size_request(folder_color_btn, 36, 26);
231         gtk_box_pack_start (GTK_BOX(hbox), folder_color_btn, FALSE, FALSE, 0);
232
233         page->folder_color = item->prefs->color;
234
235         g_signal_connect(G_OBJECT(folder_color_btn), "clicked",
236                          G_CALLBACK(folder_color_set_dialog),
237                          page);
238
239         gtkut_set_widget_bgcolor_rgb(folder_color_btn, item->prefs->color);
240
241         folder_color_rec_checkbtn = gtk_check_button_new();
242         gtk_table_attach(GTK_TABLE(table), folder_color_rec_checkbtn, 2, 3, 
243                          rowcount, rowcount + 1, GTK_SHRINK, GTK_SHRINK, 0, 0);
244
245         rowcount++;
246
247         /* Enable processing at startup */
248         checkbtn_enable_processing = gtk_check_button_new_with_label(_("Process at startup"));
249         gtk_table_attach(GTK_TABLE(table), checkbtn_enable_processing, 0, 2, 
250                          rowcount, rowcount + 1, GTK_EXPAND | GTK_FILL, GTK_FILL, 0, 0);
251
252         gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(checkbtn_enable_processing), 
253                                      item->prefs->enable_processing);
254
255         enable_processing_rec_checkbtn = gtk_check_button_new();
256         gtk_table_attach(GTK_TABLE(table), enable_processing_rec_checkbtn, 2, 3, 
257                          rowcount, rowcount + 1, GTK_SHRINK, GTK_SHRINK, 0, 0);
258         
259         rowcount++;
260
261         /* Check folder for new mail */
262         checkbtn_newmailcheck = gtk_check_button_new_with_label(_("Scan for new mail"));
263         gtk_table_attach(GTK_TABLE(table), checkbtn_newmailcheck, 0, 2,
264                          rowcount, rowcount+1, GTK_EXPAND | GTK_FILL, GTK_FILL, 0, 0);
265         
266         gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(checkbtn_newmailcheck),
267                                                                  item->prefs->newmailcheck);
268         newmailcheck_rec_checkbtn = gtk_check_button_new();
269         gtk_table_attach(GTK_TABLE(table), newmailcheck_rec_checkbtn, 2, 3, 
270                          rowcount, rowcount + 1, GTK_SHRINK, GTK_SHRINK, 0, 0);
271
272         rowcount++;
273
274         gtk_widget_show_all(table);
275
276         page->table = table;
277         page->checkbtn_simplify_subject = checkbtn_simplify_subject;
278         page->entry_simplify_subject = entry_simplify_subject;
279         page->checkbtn_folder_chmod = checkbtn_folder_chmod;
280         page->entry_folder_chmod = entry_folder_chmod;
281         page->folder_color_btn = folder_color_btn;
282         page->checkbtn_enable_processing = checkbtn_enable_processing;
283         page->checkbtn_newmailcheck = checkbtn_newmailcheck;
284
285         page->simplify_subject_rec_checkbtn  = simplify_subject_rec_checkbtn;
286         page->folder_chmod_rec_checkbtn      = folder_chmod_rec_checkbtn;
287         page->folder_color_rec_checkbtn      = folder_color_rec_checkbtn;
288         page->enable_processing_rec_checkbtn = enable_processing_rec_checkbtn;
289         page->newmailcheck_rec_checkbtn      = newmailcheck_rec_checkbtn;
290
291         page->page.widget = table;
292 }
293
294 void prefs_folder_item_general_destroy_widget_func(PrefsPage *page_) 
295 {
296         /* FolderItemGeneralPage *page = (FolderItemGeneralPage *) page_; */
297 }
298
299 /** \brief  Save the prefs in page to folder.
300  *
301  *  If the folder is not the one  specified in page->item, then only those properties 
302  *  that have the relevant 'appy to sub folders' button checked are saved
303  */
304 static void general_save_folder_prefs(FolderItem *folder, FolderItemGeneralPage *page)
305 {
306         FolderItemPrefs *prefs = folder->prefs;
307         gchar *buf;
308         gboolean all = FALSE;
309
310         g_return_if_fail(prefs != NULL);
311
312         if (page->item == folder) 
313                 all = TRUE;
314
315         if (all || gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(page->simplify_subject_rec_checkbtn))) {
316                 prefs->enable_simplify_subject =
317                         gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(page->checkbtn_simplify_subject));
318                 ASSIGN_STRING(prefs->simplify_subject_regexp,
319                               gtk_editable_get_chars(GTK_EDITABLE(page->entry_simplify_subject), 0, -1));
320         }
321         
322         if (all || gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(page->folder_chmod_rec_checkbtn))) {
323                 prefs->enable_folder_chmod = 
324                         gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(page->checkbtn_folder_chmod));
325                 buf = gtk_editable_get_chars(GTK_EDITABLE(page->entry_folder_chmod), 0, -1);
326                 prefs->folder_chmod = prefs_folder_item_chmod_mode(buf);
327                 g_free(buf);
328         }
329
330         if (all || gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(page->folder_color_rec_checkbtn))) {
331                 prefs->color = page->folder_color;
332         
333                 /* update folder view */
334                 if (prefs->color > 0)
335                         folder_item_update(folder, F_ITEM_UPDATE_MSGCNT);
336         }
337
338         if (all || gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(page->enable_processing_rec_checkbtn))) {
339                 prefs->enable_processing = 
340                         gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(page->checkbtn_enable_processing));
341         }
342
343         if (all ||  gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(page->newmailcheck_rec_checkbtn))) {
344                 prefs->newmailcheck = 
345                         gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(page->checkbtn_newmailcheck));
346         }
347
348         folder_item_prefs_save_config(folder);
349 }       
350
351 static gboolean general_save_recurse_func(GNode *node, gpointer data)
352 {
353         FolderItem *item = (FolderItem *) node->data;
354         FolderItemGeneralPage *page = (FolderItemGeneralPage *) data;
355
356         g_return_val_if_fail(item != NULL, TRUE);
357         g_return_val_if_fail(page != NULL, TRUE);
358
359         general_save_folder_prefs(item, page);
360
361         /* optimise by not continuing if none of the 'apply to sub folders'
362            check boxes are selected - and optimise the checking by only doing
363            it once */
364         if ((node == page->item->node) &&
365             !(gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(page->simplify_subject_rec_checkbtn)) ||
366               gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(page->folder_chmod_rec_checkbtn)) ||
367               gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(page->folder_color_rec_checkbtn)) ||
368               gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(page->enable_processing_rec_checkbtn)) ||
369               gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(page->newmailcheck_rec_checkbtn))))
370                 return TRUE;
371         else 
372                 return FALSE;
373 }
374
375 void prefs_folder_item_general_save_func(PrefsPage *page_) 
376 {
377         FolderItemGeneralPage *page = (FolderItemGeneralPage *) page_;
378
379         g_node_traverse(page->item->node, G_PRE_ORDER, G_TRAVERSE_ALL,
380                         -1, general_save_recurse_func, page);
381
382 }
383
384 void prefs_folder_item_compose_create_widget_func(PrefsPage * page_,
385                                                    GtkWindow * window,
386                                                    gpointer data)
387 {
388         FolderItemComposePage *page = (FolderItemComposePage *) page_;
389         FolderItem *item = (FolderItem *) data;
390         guint rowcount;
391
392         GtkWidget *table;
393         GtkWidget *label;
394         
395         GtkWidget *checkbtn_request_return_receipt;
396         GtkWidget *checkbtn_save_copy_to_folder;
397         GtkWidget *checkbtn_default_to;
398         GtkWidget *entry_default_to;
399         GtkWidget *checkbtn_default_reply_to;
400         GtkWidget *entry_default_reply_to;
401         GtkWidget *checkbtn_enable_default_account;
402         GtkWidget *optmenu_default_account;
403         GtkWidget *optmenu_default_account_menu;
404         GtkWidget *optmenu_default_account_menuitem;
405 #if USE_ASPELL
406         GtkWidget *checkbtn_enable_default_dictionary;
407         GtkWidget *optmenu_default_dictionary;
408 #endif
409         GtkWidget *request_return_receipt_rec_checkbtn;
410         GtkWidget *save_copy_to_folder_rec_checkbtn;
411         GtkWidget *default_to_rec_checkbtn;
412         GtkWidget *default_reply_to_rec_checkbtn;
413         GtkWidget *default_account_rec_checkbtn;
414 #if USE_ASPELL
415         GtkWidget *default_dictionary_rec_checkbtn;
416 #endif
417
418         GList *cur_ac;
419         GList *account_list;
420 #if USE_ASPELL
421         gchar *dictionary;
422 #endif
423         PrefsAccount *ac_prefs;
424         GtkOptionMenu *optmenu;
425         GtkWidget *menu;
426         GtkWidget *menuitem;
427         gint account_index, index;
428
429         page->item         = item;
430
431         /* Table */
432 #if USE_ASPELL
433 # define TABLEHEIGHT 6
434 #else
435 # define TABLEHEIGHT 5
436 #endif
437         table = gtk_table_new(TABLEHEIGHT, 2, FALSE);
438         gtk_table_set_row_spacings(GTK_TABLE(table), 4);
439         gtk_table_set_col_spacings(GTK_TABLE(table), 4);
440         rowcount = 0;
441
442         /* Apply to subfolders */
443         label = gtk_label_new(_("Apply to\nsubfolders"));
444         gtk_misc_set_alignment(GTK_MISC(label), 0.5, 0.5);
445         gtk_table_attach(GTK_TABLE(table), label, 2, 3,
446                          rowcount, rowcount + 1, GTK_SHRINK, GTK_SHRINK, 0, 0);
447         rowcount++;
448
449         /* Request Return Receipt */
450         checkbtn_request_return_receipt = gtk_check_button_new_with_label
451                 (_("Request Return Receipt"));
452         gtk_table_attach(GTK_TABLE(table), checkbtn_request_return_receipt, 
453                          0, 2, rowcount, rowcount + 1, GTK_SHRINK | GTK_FILL, 
454                          GTK_FILL, 0, 0);
455         gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(checkbtn_request_return_receipt),
456                                      item->ret_rcpt ? TRUE : FALSE);
457
458         request_return_receipt_rec_checkbtn = gtk_check_button_new();
459         gtk_table_attach(GTK_TABLE(table), request_return_receipt_rec_checkbtn, 2, 3, 
460                          rowcount, rowcount + 1, GTK_SHRINK, GTK_SHRINK, 0, 0);
461         
462         rowcount++;
463
464         /* Save Copy to Folder */
465         checkbtn_save_copy_to_folder = gtk_check_button_new_with_label
466                 (_("Save copy of outgoing messages to this folder instead of Sent"));
467         gtk_table_attach(GTK_TABLE(table), checkbtn_save_copy_to_folder, 0, 2, 
468                          rowcount, rowcount + 1, GTK_SHRINK | GTK_FILL, GTK_FILL, 0, 0);
469         gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(checkbtn_save_copy_to_folder),
470                                      item->prefs->save_copy_to_folder ? TRUE : FALSE);
471
472         save_copy_to_folder_rec_checkbtn = gtk_check_button_new();
473         gtk_table_attach(GTK_TABLE(table), save_copy_to_folder_rec_checkbtn, 2, 3, 
474                          rowcount, rowcount + 1, GTK_SHRINK, GTK_SHRINK, 0, 0);
475         
476         rowcount++;
477
478         /* Default To */
479         checkbtn_default_to = gtk_check_button_new_with_label(_("Default To: "));
480         gtk_table_attach(GTK_TABLE(table), checkbtn_default_to, 0, 1, 
481                          rowcount, rowcount + 1, GTK_SHRINK | GTK_FILL, GTK_SHRINK, 0, 0);
482         gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(checkbtn_default_to), 
483                                      item->prefs->enable_default_to);
484
485         entry_default_to = gtk_entry_new();
486         gtk_table_attach(GTK_TABLE(table), entry_default_to, 1, 2,
487                          rowcount, rowcount + 1, GTK_EXPAND | GTK_FILL, GTK_SHRINK, 0, 0);
488         SET_TOGGLE_SENSITIVITY(checkbtn_default_to, entry_default_to);
489         gtk_entry_set_text(GTK_ENTRY(entry_default_to), SAFE_STRING(item->prefs->default_to));
490         address_completion_register_entry(GTK_ENTRY(entry_default_to));
491
492         default_to_rec_checkbtn = gtk_check_button_new();
493         gtk_table_attach(GTK_TABLE(table), default_to_rec_checkbtn, 2, 3, 
494                          rowcount, rowcount + 1, GTK_SHRINK, GTK_SHRINK, 0, 0);
495         
496         rowcount++;
497
498         /* Default address to reply to */
499         checkbtn_default_reply_to = gtk_check_button_new_with_label(_("Send replies to: "));
500         gtk_table_attach(GTK_TABLE(table), checkbtn_default_reply_to, 0, 1, 
501                          rowcount, rowcount + 1, GTK_SHRINK | GTK_FILL, GTK_SHRINK, 0, 0);
502         gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(checkbtn_default_reply_to), 
503                                      item->prefs->enable_default_reply_to);
504
505         entry_default_reply_to = gtk_entry_new();
506         gtk_table_attach(GTK_TABLE(table), entry_default_reply_to, 1, 2,
507                          rowcount, rowcount + 1, GTK_EXPAND | GTK_FILL, GTK_SHRINK, 0, 0);
508         SET_TOGGLE_SENSITIVITY(checkbtn_default_reply_to, entry_default_reply_to);
509         gtk_entry_set_text(GTK_ENTRY(entry_default_reply_to), SAFE_STRING(item->prefs->default_reply_to));
510         address_completion_register_entry(GTK_ENTRY(entry_default_reply_to));
511
512         default_reply_to_rec_checkbtn = gtk_check_button_new();
513         gtk_table_attach(GTK_TABLE(table), default_reply_to_rec_checkbtn, 2, 3, 
514                          rowcount, rowcount + 1, GTK_SHRINK, GTK_SHRINK, 0, 0);
515         
516         rowcount++;
517
518         /* Default account */
519         checkbtn_enable_default_account = gtk_check_button_new_with_label(_("Default account: "));
520         gtk_table_attach(GTK_TABLE(table), checkbtn_enable_default_account, 0, 1, 
521                          rowcount, rowcount + 1, GTK_SHRINK | GTK_FILL, GTK_SHRINK, 0, 0);
522         gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(checkbtn_enable_default_account), 
523                                      item->prefs->enable_default_account);
524
525         optmenu_default_account = gtk_option_menu_new ();
526         gtk_table_attach(GTK_TABLE(table), optmenu_default_account, 1, 2, 
527                          rowcount, rowcount + 1, GTK_EXPAND | GTK_FILL, GTK_SHRINK, 0, 0);
528         optmenu_default_account_menu = gtk_menu_new ();
529
530         account_list = account_get_list();
531         account_index = 0;
532         index = 0;
533         for (cur_ac = account_list; cur_ac != NULL; cur_ac = cur_ac->next) {
534                 ac_prefs = (PrefsAccount *)cur_ac->data;
535                 MENUITEM_ADD (optmenu_default_account_menu, optmenu_default_account_menuitem,
536                                         ac_prefs->account_name?ac_prefs->account_name : _("Untitled"),
537                                         ac_prefs->account_id);
538                 /* get the index for menu's set_history (sad method?) */
539                 if (ac_prefs->account_id == item->prefs->default_account)
540                         account_index = index;
541                 index++;                        
542         }
543
544         optmenu = GTK_OPTION_MENU(optmenu_default_account);
545         gtk_option_menu_set_menu(optmenu, optmenu_default_account_menu);
546
547         gtk_option_menu_set_history(optmenu, account_index);
548
549         menu = gtk_option_menu_get_menu(optmenu);
550         menuitem = gtk_menu_get_active(GTK_MENU(menu));
551         gtk_menu_item_activate(GTK_MENU_ITEM(menuitem));
552
553         SET_TOGGLE_SENSITIVITY(checkbtn_enable_default_account, optmenu_default_account);
554
555         default_account_rec_checkbtn = gtk_check_button_new();
556         gtk_table_attach(GTK_TABLE(table), default_account_rec_checkbtn, 2, 3, 
557                          rowcount, rowcount + 1, GTK_SHRINK, GTK_SHRINK, 0, 0);
558         
559         rowcount++;
560
561 #if USE_ASPELL
562         /* Default dictionary */
563         checkbtn_enable_default_dictionary = gtk_check_button_new_with_label(_("Default dictionary: "));
564         gtk_table_attach(GTK_TABLE(table), checkbtn_enable_default_dictionary, 0, 1,
565                          rowcount, rowcount + 1, GTK_SHRINK | GTK_FILL, GTK_SHRINK, 0, 0);
566         gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(checkbtn_enable_default_dictionary),
567                                      item->prefs->enable_default_dictionary);
568
569         optmenu_default_dictionary = gtk_option_menu_new();
570         gtk_table_attach(GTK_TABLE(table), optmenu_default_dictionary, 1, 2,
571                          rowcount, rowcount + 1, GTK_EXPAND | GTK_FILL, GTK_SHRINK, 0, 0);
572
573         gtk_option_menu_set_menu(GTK_OPTION_MENU(optmenu_default_dictionary), 
574                                  gtkaspell_dictionary_option_menu_new(
575                                          prefs_common.aspell_path));
576
577         dictionary = item->prefs->default_dictionary;
578
579         optmenu = GTK_OPTION_MENU(optmenu_default_dictionary);
580
581         menu = gtk_option_menu_get_menu(optmenu);
582         if (dictionary)
583                 gtkaspell_set_dictionary_menu_active_item(optmenu_default_dictionary, dictionary);
584         menuitem = gtk_menu_get_active(GTK_MENU(menu));
585         gtk_menu_item_activate(GTK_MENU_ITEM(menuitem));
586
587         SET_TOGGLE_SENSITIVITY(checkbtn_enable_default_dictionary, optmenu_default_dictionary);
588
589         default_dictionary_rec_checkbtn = gtk_check_button_new();
590         gtk_table_attach(GTK_TABLE(table), default_dictionary_rec_checkbtn, 2, 3, 
591                          rowcount, rowcount + 1, GTK_SHRINK, GTK_SHRINK, 0, 0);
592         
593         rowcount++;
594 #endif
595
596         gtk_widget_show_all(table);
597
598         page->window = GTK_WIDGET(window);
599         page->table = table;
600         page->checkbtn_request_return_receipt = checkbtn_request_return_receipt;
601         page->checkbtn_save_copy_to_folder = checkbtn_save_copy_to_folder;
602         page->checkbtn_default_to = checkbtn_default_to;
603         page->entry_default_to = entry_default_to;
604         page->checkbtn_default_reply_to = checkbtn_default_reply_to;
605         page->entry_default_reply_to = entry_default_reply_to;
606         page->checkbtn_enable_default_account = checkbtn_enable_default_account;
607         page->optmenu_default_account = optmenu_default_account;
608 #ifdef USE_ASPELL
609         page->checkbtn_enable_default_dictionary = checkbtn_enable_default_dictionary;
610         page->optmenu_default_dictionary = optmenu_default_dictionary;
611 #endif
612
613         page->request_return_receipt_rec_checkbtn = request_return_receipt_rec_checkbtn;
614         page->save_copy_to_folder_rec_checkbtn    = save_copy_to_folder_rec_checkbtn;
615         page->default_to_rec_checkbtn             = default_to_rec_checkbtn;
616         page->default_reply_to_rec_checkbtn       = default_reply_to_rec_checkbtn;
617         page->default_account_rec_checkbtn        = default_account_rec_checkbtn;
618 #if USE_ASPELL
619         page->default_dictionary_rec_checkbtn = default_dictionary_rec_checkbtn;
620 #endif
621
622         address_completion_start(page->window);
623
624         page->page.widget = table;
625 }
626
627 void prefs_folder_item_compose_destroy_widget_func(PrefsPage *page_) 
628 {
629         FolderItemComposePage *page = (FolderItemComposePage *) page_;
630
631         address_completion_unregister_entry(GTK_ENTRY(page->entry_default_to));
632         address_completion_unregister_entry(GTK_ENTRY(page->entry_default_reply_to));
633         address_completion_end(page->window);
634 }
635
636 /** \brief  Save the prefs in page to folder.
637  *
638  *  If the folder is not the one  specified in page->item, then only those properties 
639  *  that have the relevant 'appy to sub folders' button checked are saved
640  */
641 static void compose_save_folder_prefs(FolderItem *folder, FolderItemComposePage *page)
642 {
643         FolderItemPrefs *prefs = folder->prefs;
644         GtkWidget *menu;
645         GtkWidget *menuitem;
646         gboolean all = FALSE;
647
648         if (page->item == folder) 
649                 all = TRUE;
650
651         g_return_if_fail(prefs != NULL);
652
653         if (all || gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(page->request_return_receipt_rec_checkbtn))) {
654                 prefs->request_return_receipt = 
655                         gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(page->checkbtn_request_return_receipt));
656                 /* MIGRATION */    
657                 folder->ret_rcpt = prefs->request_return_receipt;
658         }
659
660         if (all || gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(page->save_copy_to_folder_rec_checkbtn))) {
661                 prefs->save_copy_to_folder = 
662                         gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(page->checkbtn_save_copy_to_folder));
663         }
664
665         if (all || gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(page->default_to_rec_checkbtn))) {
666
667                 prefs->enable_default_to = 
668                         gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(page->checkbtn_default_to));
669                 ASSIGN_STRING(prefs->default_to,
670                               gtk_editable_get_chars(GTK_EDITABLE(page->entry_default_to), 0, -1));
671         }
672
673         if (all || gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(page->default_reply_to_rec_checkbtn))) {
674                 prefs->enable_default_reply_to = 
675                         gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(page->checkbtn_default_reply_to));
676                 ASSIGN_STRING(prefs->default_reply_to,
677                               gtk_editable_get_chars(GTK_EDITABLE(page->entry_default_reply_to), 0, -1));
678         }
679
680         if (all || gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(page->default_account_rec_checkbtn))) {
681                 prefs->enable_default_account = 
682                         gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(page->checkbtn_enable_default_account));
683                 menu = gtk_option_menu_get_menu(GTK_OPTION_MENU(page->optmenu_default_account));
684                 menuitem = gtk_menu_get_active(GTK_MENU(menu));
685                 prefs->default_account = GPOINTER_TO_INT(g_object_get_data(G_OBJECT(menuitem), MENU_VAL_ID));
686         }
687
688 #if USE_ASPELL
689         if (all || gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(page->default_dictionary_rec_checkbtn))) {
690                 prefs->enable_default_dictionary =
691                         gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(page->checkbtn_enable_default_dictionary));
692                 menu = gtk_option_menu_get_menu(GTK_OPTION_MENU(page->optmenu_default_dictionary));
693                 ASSIGN_STRING(prefs->default_dictionary,
694                               gtkaspell_get_dictionary_menu_active_item(menu));
695         }
696 #endif
697
698         folder_item_prefs_save_config(folder);
699 }       
700
701 static gboolean compose_save_recurse_func(GNode *node, gpointer data)
702 {
703         FolderItem *item = (FolderItem *) node->data;
704         FolderItemComposePage *page = (FolderItemComposePage *) data;
705
706         g_return_val_if_fail(item != NULL, TRUE);
707         g_return_val_if_fail(page != NULL, TRUE);
708
709         compose_save_folder_prefs(item, page);
710
711         /* optimise by not continuing if none of the 'apply to sub folders'
712            check boxes are selected - and optimise the checking by only doing
713            it once */
714         if ((node == page->item->node) &&
715             !(gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(page->request_return_receipt_rec_checkbtn)) ||
716               gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(page->save_copy_to_folder_rec_checkbtn)) ||
717               gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(page->default_to_rec_checkbtn)) ||
718               gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(page->default_reply_to_rec_checkbtn)) ||
719               gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(page->default_account_rec_checkbtn)) 
720 #if USE_ASPELL
721               || gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(page->default_dictionary_rec_checkbtn))
722 #endif
723                     ))
724                 return TRUE;
725         else 
726                 return FALSE;
727 }
728
729 void prefs_folder_item_compose_save_func(PrefsPage *page_) 
730 {
731         FolderItemComposePage *page = (FolderItemComposePage *) page_;
732
733         g_node_traverse(page->item->node, G_PRE_ORDER, G_TRAVERSE_ALL,
734                         -1, compose_save_recurse_func, page);
735
736 }
737
738 gint prefs_folder_item_chmod_mode(gchar *folder_chmod) 
739 {
740         gint newmode = 0;
741         gchar *tmp;
742
743         if (folder_chmod) {
744                 newmode = strtol(folder_chmod, &tmp, 8);
745                 if (!(*(folder_chmod) && !(*tmp)))
746                         newmode = 0;
747         }
748
749         return newmode;
750 }
751
752 static void folder_color_set_dialog(GtkWidget *widget, gpointer data)
753 {
754         FolderItemGeneralPage *page = (FolderItemGeneralPage *) data;
755         gint rgbcolor;
756
757         rgbcolor = colorsel_select_color_rgb(_("Pick color for folder"), 
758                                              page->folder_color);
759         gtkut_set_widget_bgcolor_rgb(page->folder_color_btn, rgbcolor);
760         page->folder_color = rgbcolor;
761 }
762
763
764 FolderItemGeneralPage folder_item_general_page;
765
766 static void register_general_page()
767 {
768         static gchar *pfi_general_path[2];
769
770         pfi_general_path[0] = _("General");
771         pfi_general_path[1] = NULL;
772
773         folder_item_general_page.page.path = pfi_general_path;
774         folder_item_general_page.page.create_widget = prefs_folder_item_general_create_widget_func;
775         folder_item_general_page.page.destroy_widget = prefs_folder_item_general_destroy_widget_func;
776         folder_item_general_page.page.save_page = prefs_folder_item_general_save_func;
777         
778         prefs_folder_item_register_page((PrefsPage *) &folder_item_general_page);
779 }
780
781 FolderItemComposePage folder_item_compose_page;
782
783 static void register_compose_page(void)
784 {
785         static gchar *pfi_compose_path[2];
786
787         pfi_compose_path[0] = _("Compose");
788         pfi_compose_path[1] = NULL;
789
790         folder_item_compose_page.page.path = pfi_compose_path;
791         folder_item_compose_page.page.create_widget = prefs_folder_item_compose_create_widget_func;
792         folder_item_compose_page.page.destroy_widget = prefs_folder_item_compose_destroy_widget_func;
793         folder_item_compose_page.page.save_page = prefs_folder_item_compose_save_func;
794         
795         prefs_folder_item_register_page((PrefsPage *) &folder_item_compose_page);
796 }
797
798 static GSList *prefs_pages = NULL;
799
800 void prefs_folder_item_open(FolderItem *item)
801 {
802         gchar *id, *title;
803
804         if (prefs_pages == NULL) {
805                 register_general_page();
806                 register_compose_page();
807         }
808
809         id = folder_item_get_identifier (item);
810         title = g_strdup_printf (_("%s - Settings for folder"), id);
811         g_free (id);
812         prefswindow_open(title, prefs_pages, item);
813         g_free (title);
814 }
815
816 void prefs_folder_item_register_page(PrefsPage *page)
817 {
818         prefs_pages = g_slist_append(prefs_pages, page);
819 }
820
821 void prefs_folder_item_unregister_page(PrefsPage *page)
822 {
823         prefs_pages = g_slist_remove(prefs_pages, page);
824 }