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