4fb637caeda12dc48fa7e5484a6d951a0aabe83f
[claws.git] / src / prefs_folder_item.c
1 /*
2  * Sylpheed -- a GTK+ based, lightweight, and fast e-mail client
3  * Copyright (C) 1999-2006 Hiroyuki Yamamoto and the Sylpheed-Claws team
4  *
5  * This program is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License as published by
7  * the Free Software Foundation; either version 2 of the License, or
8  * (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program; if not, write to the Free Software
17  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18  */
19
20 /* alfons - all folder item specific settings should migrate into 
21  * folderlist.xml!!! the old folderitemrc file will only serve for a few 
22  * versions (for compatibility) */
23
24 #ifdef HAVE_CONFIG_H
25 #  include "config.h"
26 #endif
27
28 #include "defs.h"
29
30 #include <glib.h>
31 #include <glib/gi18n.h>
32 #include "folder.h"
33 #include "prefs_folder_item.h"
34 #include "folderview.h"
35 #include "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 static RecvProtocol item_protocol(FolderItem *item)
422 {
423         if (!item)
424                 return A_NONE;
425         if (!item->folder)
426                 return A_NONE;
427         if (!item->folder->account)
428                 return A_NONE;
429         return item->folder->account->protocol;
430 }
431 void prefs_folder_item_compose_create_widget_func(PrefsPage * page_,
432                                                    GtkWindow * window,
433                                                    gpointer data)
434 {
435         FolderItemComposePage *page = (FolderItemComposePage *) page_;
436         FolderItem *item = (FolderItem *) data;
437         guint rowcount;
438
439         GtkWidget *table;
440         GtkWidget *label;
441         
442         GtkWidget *checkbtn_request_return_receipt = NULL;
443         GtkWidget *checkbtn_save_copy_to_folder = NULL;
444         GtkWidget *checkbtn_default_to = NULL;
445         GtkWidget *entry_default_to = NULL;
446         GtkWidget *checkbtn_default_reply_to = NULL;
447         GtkWidget *entry_default_reply_to = NULL;
448         GtkWidget *checkbtn_enable_default_account = NULL;
449         GtkWidget *optmenu_default_account = NULL;
450         GtkWidget *optmenu_default_account_menu = NULL;
451         GtkWidget *optmenu_default_account_menuitem = NULL;
452 #if USE_ASPELL
453         GtkWidget *checkbtn_enable_default_dictionary = NULL;
454         GtkWidget *optmenu_default_dictionary = NULL;
455 #endif
456         GtkWidget *request_return_receipt_rec_checkbtn = NULL;
457         GtkWidget *save_copy_to_folder_rec_checkbtn = NULL;
458         GtkWidget *default_to_rec_checkbtn = NULL;
459         GtkWidget *default_reply_to_rec_checkbtn = NULL;
460         GtkWidget *default_account_rec_checkbtn = NULL;
461 #if USE_ASPELL
462         GtkWidget *default_dictionary_rec_checkbtn = NULL;
463 #endif
464
465         GList *cur_ac;
466         GList *account_list;
467 #if USE_ASPELL
468         gchar *dictionary;
469 #endif
470         PrefsAccount *ac_prefs;
471         GtkOptionMenu *optmenu;
472         GtkWidget *menu;
473         GtkWidget *menuitem;
474         gint account_index, index;
475
476         page->item         = item;
477
478         /* Table */
479 #if USE_ASPELL
480 # define TABLEHEIGHT 6
481 #else
482 # define TABLEHEIGHT 5
483 #endif
484         table = gtk_table_new(TABLEHEIGHT, 2, FALSE);
485         gtk_table_set_row_spacings(GTK_TABLE(table), 4);
486         gtk_table_set_col_spacings(GTK_TABLE(table), 4);
487         rowcount = 0;
488
489         /* Apply to subfolders */
490         label = gtk_label_new(_("Apply to\nsubfolders"));
491         gtk_misc_set_alignment(GTK_MISC(label), 0.5, 0.5);
492         gtk_table_attach(GTK_TABLE(table), label, 2, 3,
493                          rowcount, rowcount + 1, GTK_SHRINK, GTK_SHRINK, 0, 0);
494         rowcount++;
495
496         if (item_protocol(item) != A_NNTP) {
497                 /* Request Return Receipt */
498                 checkbtn_request_return_receipt = gtk_check_button_new_with_label
499                         (_("Request Return Receipt"));
500                 gtk_table_attach(GTK_TABLE(table), checkbtn_request_return_receipt, 
501                                  0, 2, rowcount, rowcount + 1, GTK_SHRINK | GTK_FILL, 
502                                  GTK_FILL, 0, 0);
503                 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(checkbtn_request_return_receipt),
504                                              item->ret_rcpt ? TRUE : FALSE);
505
506                 request_return_receipt_rec_checkbtn = gtk_check_button_new();
507                 gtk_table_attach(GTK_TABLE(table), request_return_receipt_rec_checkbtn, 2, 3, 
508                                  rowcount, rowcount + 1, GTK_SHRINK, GTK_SHRINK, 0, 0);
509
510                 rowcount++;
511
512                 /* Save Copy to Folder */
513                 checkbtn_save_copy_to_folder = gtk_check_button_new_with_label
514                         (_("Save copy of outgoing messages to this folder instead of Sent"));
515                 gtk_table_attach(GTK_TABLE(table), checkbtn_save_copy_to_folder, 0, 2, 
516                                  rowcount, rowcount + 1, GTK_SHRINK | GTK_FILL, GTK_FILL, 0, 0);
517                 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(checkbtn_save_copy_to_folder),
518                                              item->prefs->save_copy_to_folder ? TRUE : FALSE);
519
520                 save_copy_to_folder_rec_checkbtn = gtk_check_button_new();
521                 gtk_table_attach(GTK_TABLE(table), save_copy_to_folder_rec_checkbtn, 2, 3, 
522                                  rowcount, rowcount + 1, GTK_SHRINK, GTK_SHRINK, 0, 0);
523
524                 rowcount++;
525
526                 /* Default To */
527                 checkbtn_default_to = gtk_check_button_new_with_label(_("Default To: "));
528                 gtk_table_attach(GTK_TABLE(table), checkbtn_default_to, 0, 1, 
529                                  rowcount, rowcount + 1, GTK_SHRINK | GTK_FILL, GTK_SHRINK, 0, 0);
530                 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(checkbtn_default_to), 
531                                              item->prefs->enable_default_to);
532
533                 entry_default_to = gtk_entry_new();
534                 gtk_table_attach(GTK_TABLE(table), entry_default_to, 1, 2,
535                                  rowcount, rowcount + 1, GTK_EXPAND | GTK_FILL, GTK_SHRINK, 0, 0);
536                 SET_TOGGLE_SENSITIVITY(checkbtn_default_to, entry_default_to);
537                 gtk_entry_set_text(GTK_ENTRY(entry_default_to), SAFE_STRING(item->prefs->default_to));
538                 address_completion_register_entry(GTK_ENTRY(entry_default_to));
539
540                 default_to_rec_checkbtn = gtk_check_button_new();
541                 gtk_table_attach(GTK_TABLE(table), default_to_rec_checkbtn, 2, 3, 
542                                  rowcount, rowcount + 1, GTK_SHRINK, GTK_SHRINK, 0, 0);
543
544                 rowcount++;
545
546                 /* Default address to reply to */
547                 checkbtn_default_reply_to = gtk_check_button_new_with_label(_("Default To for replies: "));
548                 gtk_table_attach(GTK_TABLE(table), checkbtn_default_reply_to, 0, 1, 
549                                  rowcount, rowcount + 1, GTK_SHRINK | GTK_FILL, GTK_SHRINK, 0, 0);
550                 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(checkbtn_default_reply_to), 
551                                              item->prefs->enable_default_reply_to);
552
553                 entry_default_reply_to = gtk_entry_new();
554                 gtk_table_attach(GTK_TABLE(table), entry_default_reply_to, 1, 2,
555                                  rowcount, rowcount + 1, GTK_EXPAND | GTK_FILL, GTK_SHRINK, 0, 0);
556                 SET_TOGGLE_SENSITIVITY(checkbtn_default_reply_to, entry_default_reply_to);
557                 gtk_entry_set_text(GTK_ENTRY(entry_default_reply_to), SAFE_STRING(item->prefs->default_reply_to));
558                 address_completion_register_entry(GTK_ENTRY(entry_default_reply_to));
559
560                 default_reply_to_rec_checkbtn = gtk_check_button_new();
561                 gtk_table_attach(GTK_TABLE(table), default_reply_to_rec_checkbtn, 2, 3, 
562                                  rowcount, rowcount + 1, GTK_SHRINK, GTK_SHRINK, 0, 0);
563
564                 rowcount++;
565         }
566         /* Default account */
567         checkbtn_enable_default_account = gtk_check_button_new_with_label(_("Default account: "));
568         gtk_table_attach(GTK_TABLE(table), checkbtn_enable_default_account, 0, 1, 
569                          rowcount, rowcount + 1, GTK_SHRINK | GTK_FILL, GTK_SHRINK, 0, 0);
570         gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(checkbtn_enable_default_account), 
571                                      item->prefs->enable_default_account);
572
573         optmenu_default_account = gtk_option_menu_new ();
574         gtk_table_attach(GTK_TABLE(table), optmenu_default_account, 1, 2, 
575                          rowcount, rowcount + 1, GTK_EXPAND | GTK_FILL, GTK_SHRINK, 0, 0);
576         optmenu_default_account_menu = gtk_menu_new ();
577
578         account_list = account_get_list();
579         account_index = 0;
580         index = 0;
581         for (cur_ac = account_list; cur_ac != NULL; cur_ac = cur_ac->next) {
582                 ac_prefs = (PrefsAccount *)cur_ac->data;
583                 if (item->folder->account &&
584                     ( (item_protocol(item) == A_NNTP && ac_prefs->protocol != A_NNTP)
585                     ||(item_protocol(item) != A_NNTP && ac_prefs->protocol == A_NNTP))) 
586                         continue;
587
588                 if (item->folder->klass->type != F_NEWS && ac_prefs->protocol == A_NNTP)
589                         continue;
590
591                 MENUITEM_ADD (optmenu_default_account_menu, optmenu_default_account_menuitem,
592                                         ac_prefs->account_name?ac_prefs->account_name : _("Untitled"),
593                                         ac_prefs->account_id);
594                 /* get the index for menu's set_history (sad method?) */
595                 if (ac_prefs->account_id == item->prefs->default_account)
596                         account_index = index;
597                 index++;                        
598         }
599
600         optmenu = GTK_OPTION_MENU(optmenu_default_account);
601         gtk_option_menu_set_menu(optmenu, optmenu_default_account_menu);
602
603         gtk_option_menu_set_history(optmenu, account_index);
604
605         menu = gtk_option_menu_get_menu(optmenu);
606         menuitem = gtk_menu_get_active(GTK_MENU(menu));
607         gtk_menu_item_activate(GTK_MENU_ITEM(menuitem));
608
609         SET_TOGGLE_SENSITIVITY(checkbtn_enable_default_account, optmenu_default_account);
610
611         default_account_rec_checkbtn = gtk_check_button_new();
612         gtk_table_attach(GTK_TABLE(table), default_account_rec_checkbtn, 2, 3, 
613                          rowcount, rowcount + 1, GTK_SHRINK, GTK_SHRINK, 0, 0);
614         rowcount++;
615
616 #if USE_ASPELL
617         /* Default dictionary */
618         checkbtn_enable_default_dictionary = gtk_check_button_new_with_label(_("Default dictionary: "));
619         gtk_table_attach(GTK_TABLE(table), checkbtn_enable_default_dictionary, 0, 1,
620                          rowcount, rowcount + 1, GTK_SHRINK | GTK_FILL, GTK_SHRINK, 0, 0);
621         gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(checkbtn_enable_default_dictionary),
622                                      item->prefs->enable_default_dictionary);
623
624         optmenu_default_dictionary = gtk_option_menu_new();
625         gtk_table_attach(GTK_TABLE(table), optmenu_default_dictionary, 1, 2,
626                          rowcount, rowcount + 1, GTK_EXPAND | GTK_FILL, GTK_SHRINK, 0, 0);
627
628         gtk_option_menu_set_menu(GTK_OPTION_MENU(optmenu_default_dictionary), 
629                                  gtkaspell_dictionary_option_menu_new(
630                                          prefs_common.aspell_path));
631
632         dictionary = item->prefs->default_dictionary;
633
634         optmenu = GTK_OPTION_MENU(optmenu_default_dictionary);
635
636         menu = gtk_option_menu_get_menu(optmenu);
637         if (dictionary)
638                 gtkaspell_set_dictionary_menu_active_item(optmenu_default_dictionary, dictionary);
639         menuitem = gtk_menu_get_active(GTK_MENU(menu));
640         gtk_menu_item_activate(GTK_MENU_ITEM(menuitem));
641
642         SET_TOGGLE_SENSITIVITY(checkbtn_enable_default_dictionary, optmenu_default_dictionary);
643
644         default_dictionary_rec_checkbtn = gtk_check_button_new();
645         gtk_table_attach(GTK_TABLE(table), default_dictionary_rec_checkbtn, 2, 3, 
646                          rowcount, rowcount + 1, GTK_SHRINK, GTK_SHRINK, 0, 0);
647         
648         rowcount++;
649 #endif
650
651         gtk_widget_show_all(table);
652
653         page->window = GTK_WIDGET(window);
654         page->table = table;
655         page->checkbtn_request_return_receipt = checkbtn_request_return_receipt;
656         page->checkbtn_save_copy_to_folder = checkbtn_save_copy_to_folder;
657         page->checkbtn_default_to = checkbtn_default_to;
658         page->entry_default_to = entry_default_to;
659         page->checkbtn_default_reply_to = checkbtn_default_reply_to;
660         page->entry_default_reply_to = entry_default_reply_to;
661         page->checkbtn_enable_default_account = checkbtn_enable_default_account;
662         page->optmenu_default_account = optmenu_default_account;
663 #ifdef USE_ASPELL
664         page->checkbtn_enable_default_dictionary = checkbtn_enable_default_dictionary;
665         page->optmenu_default_dictionary = optmenu_default_dictionary;
666 #endif
667
668         page->request_return_receipt_rec_checkbtn = request_return_receipt_rec_checkbtn;
669         page->save_copy_to_folder_rec_checkbtn    = save_copy_to_folder_rec_checkbtn;
670         page->default_to_rec_checkbtn             = default_to_rec_checkbtn;
671         page->default_reply_to_rec_checkbtn       = default_reply_to_rec_checkbtn;
672         page->default_account_rec_checkbtn        = default_account_rec_checkbtn;
673 #if USE_ASPELL
674         page->default_dictionary_rec_checkbtn = default_dictionary_rec_checkbtn;
675 #endif
676
677         address_completion_start(page->window);
678
679         page->page.widget = table;
680 }
681
682 void prefs_folder_item_compose_destroy_widget_func(PrefsPage *page_) 
683 {
684         FolderItemComposePage *page = (FolderItemComposePage *) page_;
685
686         if (page->entry_default_to)
687                 address_completion_unregister_entry(GTK_ENTRY(page->entry_default_to));
688         if (page->entry_default_reply_to)
689                 address_completion_unregister_entry(GTK_ENTRY(page->entry_default_reply_to));
690         address_completion_end(page->window);
691 }
692
693 /** \brief  Save the prefs in page to folder.
694  *
695  *  If the folder is not the one  specified in page->item, then only those properties 
696  *  that have the relevant 'appy to sub folders' button checked are saved
697  */
698 static void compose_save_folder_prefs(FolderItem *folder, FolderItemComposePage *page)
699 {
700         FolderItemPrefs *prefs = folder->prefs;
701         GtkWidget *menu;
702         GtkWidget *menuitem;
703         gboolean all = FALSE;
704
705         if (page->item == folder) 
706                 all = TRUE;
707
708         g_return_if_fail(prefs != NULL);
709
710         if (item_protocol(folder) != A_NNTP) {
711                 if (all || gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(page->request_return_receipt_rec_checkbtn))) {
712                         prefs->request_return_receipt = 
713                                 gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(page->checkbtn_request_return_receipt));
714                         /* MIGRATION */    
715                         folder->ret_rcpt = prefs->request_return_receipt;
716                 }
717
718                 if (all || gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(page->save_copy_to_folder_rec_checkbtn))) {
719                         prefs->save_copy_to_folder = 
720                                 gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(page->checkbtn_save_copy_to_folder));
721                 }
722
723                 if (all || gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(page->default_to_rec_checkbtn))) {
724
725                         prefs->enable_default_to = 
726                                 gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(page->checkbtn_default_to));
727                         ASSIGN_STRING(prefs->default_to,
728                                       gtk_editable_get_chars(GTK_EDITABLE(page->entry_default_to), 0, -1));
729                 }
730
731                 if (all || gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(page->default_reply_to_rec_checkbtn))) {
732                         prefs->enable_default_reply_to = 
733                                 gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(page->checkbtn_default_reply_to));
734                         ASSIGN_STRING(prefs->default_reply_to,
735                                       gtk_editable_get_chars(GTK_EDITABLE(page->entry_default_reply_to), 0, -1));
736                 }
737         } else {
738                 prefs->request_return_receipt = FALSE;
739                 prefs->save_copy_to_folder = FALSE;
740                 prefs->enable_default_to = FALSE;
741                 prefs->enable_default_reply_to = FALSE;
742         }
743         if (all || gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(page->default_account_rec_checkbtn))) {
744                 prefs->enable_default_account = 
745                         gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(page->checkbtn_enable_default_account));
746                 menu = gtk_option_menu_get_menu(GTK_OPTION_MENU(page->optmenu_default_account));
747                 menuitem = gtk_menu_get_active(GTK_MENU(menu));
748                 prefs->default_account = GPOINTER_TO_INT(g_object_get_data(G_OBJECT(menuitem), MENU_VAL_ID));
749         }
750
751 #if USE_ASPELL
752         if (all || gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(page->default_dictionary_rec_checkbtn))) {
753                 prefs->enable_default_dictionary =
754                         gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(page->checkbtn_enable_default_dictionary));
755                 menu = gtk_option_menu_get_menu(GTK_OPTION_MENU(page->optmenu_default_dictionary));
756                 ASSIGN_STRING(prefs->default_dictionary,
757                               gtkaspell_get_dictionary_menu_active_item(menu));
758         }
759 #endif
760
761         folder_item_prefs_save_config(folder);
762 }       
763
764 static gboolean compose_save_recurse_func(GNode *node, gpointer data)
765 {
766         FolderItem *item = (FolderItem *) node->data;
767         FolderItemComposePage *page = (FolderItemComposePage *) data;
768
769         g_return_val_if_fail(item != NULL, TRUE);
770         g_return_val_if_fail(page != NULL, TRUE);
771
772         compose_save_folder_prefs(item, page);
773
774         /* optimise by not continuing if none of the 'apply to sub folders'
775            check boxes are selected - and optimise the checking by only doing
776            it once */
777         if ((node == page->item->node) && item_protocol(item) != A_NNTP &&
778             !(gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(page->request_return_receipt_rec_checkbtn)) ||
779               gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(page->save_copy_to_folder_rec_checkbtn)) ||
780               gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(page->default_to_rec_checkbtn)) ||
781               gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(page->default_account_rec_checkbtn)) ||
782 #if USE_ASPELL
783               gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(page->default_dictionary_rec_checkbtn)) ||
784 #endif
785               gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(page->default_reply_to_rec_checkbtn))))
786                 return TRUE;
787
788         if ((node == page->item->node) &&
789             !(gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(page->default_account_rec_checkbtn)) 
790 #if USE_ASPELL
791               || gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(page->default_dictionary_rec_checkbtn))
792 #endif
793                     ))
794                 return TRUE;
795         else 
796                 return FALSE;
797 }
798
799 void prefs_folder_item_compose_save_func(PrefsPage *page_) 
800 {
801         FolderItemComposePage *page = (FolderItemComposePage *) page_;
802
803         g_node_traverse(page->item->node, G_PRE_ORDER, G_TRAVERSE_ALL,
804                         -1, compose_save_recurse_func, page);
805
806 }
807
808 gint prefs_folder_item_chmod_mode(gchar *folder_chmod) 
809 {
810         gint newmode = 0;
811         gchar *tmp;
812
813         if (folder_chmod) {
814                 newmode = strtol(folder_chmod, &tmp, 8);
815                 if (!(*(folder_chmod) && !(*tmp)))
816                         newmode = 0;
817         }
818
819         return newmode;
820 }
821
822 static void folder_color_set_dialog(GtkWidget *widget, gpointer data)
823 {
824         FolderItemGeneralPage *page = (FolderItemGeneralPage *) data;
825         gint rgbcolor;
826
827         rgbcolor = colorsel_select_color_rgb(_("Pick color for folder"), 
828                                              page->folder_color);
829         gtkut_set_widget_bgcolor_rgb(page->folder_color_btn, rgbcolor);
830         page->folder_color = rgbcolor;
831 }
832
833
834 static void register_general_page()
835 {
836         static gchar *pfi_general_path[2];
837         static FolderItemGeneralPage folder_item_general_page;
838
839         pfi_general_path[0] = _("General");
840         pfi_general_path[1] = NULL;
841
842         folder_item_general_page.page.path = pfi_general_path;
843         folder_item_general_page.page.create_widget = prefs_folder_item_general_create_widget_func;
844         folder_item_general_page.page.destroy_widget = prefs_folder_item_general_destroy_widget_func;
845         folder_item_general_page.page.save_page = prefs_folder_item_general_save_func;
846         
847         prefs_folder_item_register_page((PrefsPage *) &folder_item_general_page);
848 }
849
850
851 static void register_compose_page(void)
852 {
853         static gchar *pfi_compose_path[2];
854         static FolderItemComposePage folder_item_compose_page;
855
856         pfi_compose_path[0] = _("Compose");
857         pfi_compose_path[1] = NULL;
858
859         folder_item_compose_page.page.path = pfi_compose_path;
860         folder_item_compose_page.page.create_widget = prefs_folder_item_compose_create_widget_func;
861         folder_item_compose_page.page.destroy_widget = prefs_folder_item_compose_destroy_widget_func;
862         folder_item_compose_page.page.save_page = prefs_folder_item_compose_save_func;
863         
864         prefs_folder_item_register_page((PrefsPage *) &folder_item_compose_page);
865 }
866
867 static GSList *prefs_pages = NULL;
868
869 void prefs_folder_item_open(FolderItem *item)
870 {
871         gchar *id, *title;
872
873         if (prefs_pages == NULL) {
874                 register_general_page();
875                 register_compose_page();
876         }
877
878         id = folder_item_get_identifier (item);
879         title = g_strdup_printf (_("Properties for folder %s"), id);
880         g_free (id);
881         prefswindow_open(title, prefs_pages, item,
882                         &prefs_common.folderitemwin_width, &prefs_common.folderitemwin_height);
883         g_free (title);
884 }
885
886 void prefs_folder_item_register_page(PrefsPage *page)
887 {
888         prefs_pages = g_slist_append(prefs_pages, page);
889 }
890
891 void prefs_folder_item_unregister_page(PrefsPage *page)
892 {
893         prefs_pages = g_slist_remove(prefs_pages, page);
894 }