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