make default to address in folder property dialog really use address completion
[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 #include "intl.h"
25 #include "defs.h"
26 #include "folder.h"
27 #include "prefs_folder_item.h"
28 #include "folderview.h"
29 #include "summaryview.h"
30 #include "menu.h"
31 #include "account.h"
32 #include "prefs.h"
33 #include "manage_window.h"
34 #include "utils.h"
35 #include "addr_compl.h"
36
37 PrefsFolderItem tmp_prefs;
38
39 struct PrefsFolderItemDialog
40 {
41         FolderView *folderview;
42         FolderItem *item;
43         GtkWidget *window;
44         GtkWidget *checkbtn_request_return_receipt;
45         GtkWidget *checkbtn_save_copy_to_folder;
46         GtkWidget *checkbtn_default_to;
47         GtkWidget *entry_default_to;
48         GtkWidget *checkbtn_simplify_subject;
49         GtkWidget *entry_simplify_subject;
50         GtkWidget *checkbtn_folder_chmod;
51         GtkWidget *entry_folder_chmod;
52         GtkWidget *checkbtn_enable_default_account;
53         GtkWidget *optmenu_default_account;
54 };
55
56 static PrefParam param[] = {
57         {"sort_by_number", "FALSE", &tmp_prefs.sort_by_number, P_BOOL,
58          NULL, NULL, NULL},
59         {"sort_by_size", "FALSE", &tmp_prefs.sort_by_size, P_BOOL,
60          NULL, NULL, NULL},
61         {"sort_by_date", "FALSE", &tmp_prefs.sort_by_date, P_BOOL,
62          NULL, NULL, NULL},
63         {"sort_by_from", "FALSE", &tmp_prefs.sort_by_from, P_BOOL,
64          NULL, NULL, NULL},
65         {"sort_by_subject", "FALSE", &tmp_prefs.sort_by_subject, P_BOOL,
66          NULL, NULL, NULL},
67         {"sort_by_score", "FALSE", &tmp_prefs.sort_by_score, P_BOOL,
68          NULL, NULL, NULL},
69         {"sort_descending", "FALSE", &tmp_prefs.sort_descending, P_BOOL,
70          NULL, NULL, NULL},
71         /*{"enable_thread", "TRUE", &tmp_prefs.enable_thread, P_BOOL,
72          NULL, NULL, NULL},*/
73         {"kill_score", "-9999", &tmp_prefs.kill_score, P_INT,
74          NULL, NULL, NULL},
75         {"important_score", "1", &tmp_prefs.important_score, P_INT,
76          NULL, NULL, NULL},
77         /* MIGRATION */  
78         {"request_return_receipt", "", &tmp_prefs.request_return_receipt, P_BOOL,
79          NULL, NULL, NULL},
80         {"enable_default_to", "", &tmp_prefs.enable_default_to, P_BOOL,
81          NULL, NULL, NULL},
82         {"default_to", "", &tmp_prefs.default_to, P_STRING,
83          NULL, NULL, NULL},
84         {"enable_simplify_subject", "", &tmp_prefs.enable_simplify_subject, P_BOOL,
85          NULL, NULL, NULL},
86         {"simplify_subject_regexp", "", &tmp_prefs.simplify_subject_regexp, P_STRING,
87          NULL, NULL, NULL},
88         {"enable_folder_chmod", "", &tmp_prefs.enable_folder_chmod, P_BOOL,
89          NULL, NULL, NULL},
90         {"folder_chmod", "", &tmp_prefs.folder_chmod, P_INT,
91          NULL, NULL, NULL},
92         {"enable_default_account", "", &tmp_prefs.enable_default_account, P_BOOL,
93          NULL, NULL, NULL},
94         {"default_account", NULL, &tmp_prefs.default_account, P_INT,
95          NULL, NULL, NULL},
96         {"save_copy_to_folder", NULL, &tmp_prefs.save_copy_to_folder, P_BOOL,
97          NULL, NULL, NULL},
98         {NULL, NULL, NULL, P_OTHER, NULL, NULL, NULL}
99 };
100
101 void prefs_folder_item_delete_cb                (GtkWidget *widget, GdkEventAny *event, 
102                                                  struct PrefsFolderItemDialog *dialog);
103 void prefs_folder_item_cancel_cb                (GtkWidget *widget, 
104                                                  struct PrefsFolderItemDialog *dialog);
105 void prefs_folder_item_ok_cb                    (GtkWidget *widget, 
106                                                  struct PrefsFolderItemDialog *dialog);
107 void prefs_folder_item_default_to_cb            (GtkWidget *widget, 
108                                                  struct PrefsFolderItemDialog *dialog);
109 void prefs_folder_item_simplify_subject_cb      (GtkWidget *widget, 
110                                                  struct PrefsFolderItemDialog *dialog);
111 void prefs_folder_item_folder_chmod_cb          (GtkWidget *widget, 
112                                                  struct PrefsFolderItemDialog *dialog);
113 void prefs_folder_item_default_account_cb       (GtkWidget *widget, 
114                                                  struct PrefsFolderItemDialog *dialog);
115 gint prefs_folder_item_chmod_mode               (gchar *folder_chmod);
116
117
118 void prefs_folder_item_read_config(FolderItem * item)
119 {
120         gchar * id;
121
122         id = folder_item_get_identifier(item);
123
124         prefs_read_config(param, id, FOLDERITEM_RC);
125         g_free(id);
126
127         *item->prefs = tmp_prefs;
128
129         /* MIGRATION */
130         item->ret_rcpt = tmp_prefs.request_return_receipt ? TRUE : FALSE; 
131 }
132
133 void prefs_folder_item_save_config(FolderItem * item)
134 {       
135         gchar * id;
136
137         tmp_prefs = * item->prefs;
138
139         id = folder_item_get_identifier(item);
140
141         prefs_save_config(param, id, FOLDERITEM_RC);
142         g_free(id);
143
144         /* MIGRATION: make sure migrated items are not saved
145          */
146 }
147
148 void prefs_folder_item_set_config(FolderItem * item,
149                                   int sort_type, gint sort_mode)
150 {
151         tmp_prefs = * item->prefs;
152
153         tmp_prefs.sort_by_number = FALSE;
154         tmp_prefs.sort_by_size = FALSE;
155         tmp_prefs.sort_by_date = FALSE;
156         tmp_prefs.sort_by_from = FALSE;
157         tmp_prefs.sort_by_subject = FALSE;
158         tmp_prefs.sort_by_score = FALSE;
159
160         switch (sort_mode) {
161         case SORT_BY_NUMBER:
162                 tmp_prefs.sort_by_number = TRUE;
163                 break;
164         case SORT_BY_SIZE:
165                 tmp_prefs.sort_by_size = TRUE;
166                 break;
167         case SORT_BY_DATE:
168                 tmp_prefs.sort_by_date = TRUE;
169                 break;
170         case SORT_BY_FROM:
171                 tmp_prefs.sort_by_from = TRUE;
172                 break;
173         case SORT_BY_SUBJECT:
174                 tmp_prefs.sort_by_subject = TRUE;
175                 break;
176         case SORT_BY_SCORE:
177                 tmp_prefs.sort_by_score = TRUE;
178                 break;
179         }
180         tmp_prefs.sort_descending = (sort_type == GTK_SORT_DESCENDING);
181
182         * item->prefs = tmp_prefs;
183 }
184
185 PrefsFolderItem * prefs_folder_item_new(void)
186 {
187         PrefsFolderItem * prefs;
188
189         prefs = g_new0(PrefsFolderItem, 1);
190
191         tmp_prefs.sort_by_number = FALSE;
192         tmp_prefs.sort_by_size = FALSE;
193         tmp_prefs.sort_by_date = FALSE;
194         tmp_prefs.sort_by_from = FALSE;
195         tmp_prefs.sort_by_subject = FALSE;
196         tmp_prefs.sort_by_score = FALSE;
197         tmp_prefs.sort_descending = FALSE;
198         tmp_prefs.kill_score = -9999;
199         tmp_prefs.important_score = 9999;
200
201         tmp_prefs.request_return_receipt = FALSE;
202         tmp_prefs.enable_default_to = FALSE;
203         tmp_prefs.default_to = NULL;
204         tmp_prefs.enable_simplify_subject = FALSE;
205         tmp_prefs.simplify_subject_regexp = NULL;
206         tmp_prefs.enable_folder_chmod = FALSE;
207         tmp_prefs.folder_chmod = 0;
208         tmp_prefs.enable_default_account = FALSE;
209         tmp_prefs.default_account = 0;
210         tmp_prefs.save_copy_to_folder = FALSE;
211
212         * prefs = tmp_prefs;
213         
214         return prefs;
215 }
216
217 void prefs_folder_item_free(PrefsFolderItem * prefs)
218 {
219         if (prefs->default_to) 
220                 g_free(prefs->default_to);
221         if (prefs->scoring != NULL)
222                 prefs_scoring_free(prefs->scoring);
223         g_free(prefs);
224 }
225
226 gint prefs_folder_item_get_sort_mode(FolderItem * item)
227 {
228         tmp_prefs = * item->prefs;
229
230         if (tmp_prefs.sort_by_number)
231                 return SORT_BY_NUMBER;
232         if (tmp_prefs.sort_by_size)
233                 return SORT_BY_SIZE;
234         if (tmp_prefs.sort_by_date)
235                 return SORT_BY_DATE;
236         if (tmp_prefs.sort_by_from)
237                 return SORT_BY_FROM;
238         if (tmp_prefs.sort_by_subject)
239                 return SORT_BY_SUBJECT;
240         if (tmp_prefs.sort_by_score)
241                 return SORT_BY_SCORE;
242         return SORT_BY_NONE;
243 }
244
245 gint prefs_folder_item_get_sort_type(FolderItem * item)
246 {
247         tmp_prefs = * item->prefs;
248
249         if (tmp_prefs.sort_descending)
250                 return GTK_SORT_DESCENDING;
251         else
252                 return GTK_SORT_ASCENDING;
253 }
254
255 #define SAFE_STRING(str) \
256         (str) ? (str) : ""
257
258 void prefs_folder_item_create(void *folderview, FolderItem *item) 
259 {
260         struct PrefsFolderItemDialog *dialog;
261         guint rowcount;
262         gchar *folder_identifier, *infotext;
263
264         GtkWidget *window;
265         GtkWidget *table;
266         GtkWidget *infolabel;
267         GtkWidget *ok_btn;
268         GtkWidget *cancel_btn;
269         GtkWidget *confirm_area;
270         
271         GtkWidget *checkbtn_request_return_receipt;
272         GtkWidget *checkbtn_save_copy_to_folder;
273         GtkWidget *checkbtn_default_to;
274         GtkWidget *entry_default_to;
275         GtkWidget *checkbtn_simplify_subject;
276         GtkWidget *entry_simplify_subject;
277         GtkWidget *checkbtn_folder_chmod;
278         GtkWidget *entry_folder_chmod;
279         GtkWidget *checkbtn_enable_default_account;
280         GtkWidget *optmenu_default_account;
281         GtkWidget *optmenu_default_account_menu;
282         GtkWidget *optmenu_default_account_menuitem;
283         GList *cur_ac;
284         GList *account_list;
285         PrefsAccount *ac_prefs;
286         GtkOptionMenu *optmenu;
287         GtkWidget *menu;
288         GtkWidget *menuitem;
289         gint account_index, index;
290
291         dialog = g_new0(struct PrefsFolderItemDialog, 1);
292         dialog->folderview = folderview;
293         dialog->item       = item;
294
295         /* Window */
296         window = gtk_window_new (GTK_WINDOW_DIALOG);
297         gtk_window_set_title (GTK_WINDOW(window),
298                               _("Folder Property"));
299         gtk_container_set_border_width (GTK_CONTAINER (window), 8);
300         gtk_window_position (GTK_WINDOW (window), GTK_WIN_POS_CENTER);
301         gtk_window_set_policy (GTK_WINDOW (window), FALSE, TRUE, FALSE);
302         gtk_signal_connect (GTK_OBJECT(window), "delete_event",
303                             GTK_SIGNAL_FUNC(prefs_folder_item_delete_cb), dialog);
304         gtk_signal_connect (GTK_OBJECT(window), "focus_in_event",
305                             GTK_SIGNAL_FUNC(manage_window_focus_in), NULL);
306         gtk_signal_connect (GTK_OBJECT(window), "focus_out_event",
307                             GTK_SIGNAL_FUNC(manage_window_focus_out), NULL);
308
309         /* Table */
310         table = gtk_table_new(4, 2, FALSE);
311         gtk_widget_show(table);
312         gtk_table_set_row_spacings(GTK_TABLE(table), VSPACING_NARROW);
313         gtk_container_add(GTK_CONTAINER (window), table);
314         rowcount = 0;
315
316         /* Label */
317         folder_identifier = folder_item_get_identifier(item);
318         infotext = g_strconcat(_("Folder Property for "), folder_identifier, NULL);
319         infolabel = gtk_label_new(infotext);
320         gtk_table_attach(GTK_TABLE(table), infolabel, 0, 2, rowcount, 
321                          rowcount + 1, GTK_SHRINK | GTK_FILL, GTK_SHRINK, 0, 0);
322         gtk_widget_show(infolabel);
323         rowcount++;
324
325         /* Request Return Receipt */
326         checkbtn_request_return_receipt = gtk_check_button_new_with_label
327                 (_("Request Return Receipt"));
328         gtk_widget_show(checkbtn_request_return_receipt);
329         gtk_table_attach(GTK_TABLE(table), checkbtn_request_return_receipt, 
330                          0, 2, rowcount, rowcount + 1, GTK_SHRINK | GTK_FILL, 
331                          GTK_SHRINK, 0, 0);
332         gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(checkbtn_request_return_receipt),
333                                      item->ret_rcpt ? TRUE : FALSE);
334
335         rowcount++;
336
337         /* Save Copy to Folder */
338         checkbtn_save_copy_to_folder = gtk_check_button_new_with_label
339                 (_("Save copy of outgoing messages to this folder instead of outbox"));
340         gtk_widget_show(checkbtn_save_copy_to_folder);
341         gtk_table_attach(GTK_TABLE(table), checkbtn_save_copy_to_folder, 0, 2, 
342                          rowcount, rowcount + 1, GTK_SHRINK | GTK_FILL, GTK_SHRINK, 0, 0);
343         gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(checkbtn_save_copy_to_folder),
344                                      item->prefs->save_copy_to_folder ? TRUE : FALSE);
345
346         rowcount++;
347
348         /* Default To */
349         checkbtn_default_to = gtk_check_button_new_with_label(_("Default To: "));
350         gtk_widget_show(checkbtn_default_to);
351         gtk_table_attach(GTK_TABLE(table), checkbtn_default_to, 0, 1, 
352                          rowcount, rowcount + 1, GTK_SHRINK | GTK_FILL, GTK_SHRINK, 0, 0);
353         gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(checkbtn_default_to), 
354                                      item->prefs->enable_default_to);
355         gtk_signal_connect(GTK_OBJECT(checkbtn_default_to), "toggled",
356                             GTK_SIGNAL_FUNC(prefs_folder_item_default_to_cb), dialog);
357
358         entry_default_to = gtk_entry_new();
359         gtk_widget_show(entry_default_to);
360         gtk_table_attach_defaults(GTK_TABLE(table), entry_default_to, 1, 2, rowcount, rowcount + 1);
361         gtk_editable_set_editable(GTK_EDITABLE(entry_default_to), item->prefs->enable_default_to);
362         gtk_entry_set_text(GTK_ENTRY(entry_default_to), SAFE_STRING(item->prefs->default_to));
363         address_completion_register_entry(GTK_ENTRY(entry_default_to));
364
365         rowcount++;
366
367         /* Simplify Subject */
368         checkbtn_simplify_subject = gtk_check_button_new_with_label(_("Simplify Subject RegExp: "));
369         gtk_widget_show(checkbtn_simplify_subject);
370         gtk_table_attach(GTK_TABLE(table), checkbtn_simplify_subject, 0, 1, 
371                          rowcount, rowcount + 1, GTK_SHRINK | GTK_FILL, GTK_SHRINK, 0, 0);
372         gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(checkbtn_simplify_subject), 
373                                      item->prefs->enable_simplify_subject);
374         gtk_signal_connect(GTK_OBJECT(checkbtn_simplify_subject), "toggled",
375                            GTK_SIGNAL_FUNC(prefs_folder_item_simplify_subject_cb), dialog);
376
377         entry_simplify_subject = gtk_entry_new();
378         gtk_widget_show(entry_simplify_subject);
379         gtk_table_attach_defaults(GTK_TABLE(table), entry_simplify_subject, 1, 2, 
380                                   rowcount, rowcount + 1);
381         gtk_editable_set_editable(GTK_EDITABLE(entry_simplify_subject), 
382                                   item->prefs->enable_simplify_subject);
383         gtk_entry_set_text(GTK_ENTRY(entry_simplify_subject), 
384                            SAFE_STRING(item->prefs->simplify_subject_regexp));
385
386         rowcount++;
387
388         /* Folder chmod */
389         checkbtn_folder_chmod = gtk_check_button_new_with_label(_("Folder chmod: "));
390         gtk_widget_show(checkbtn_folder_chmod);
391         gtk_table_attach(GTK_TABLE(table), checkbtn_folder_chmod, 0, 1, 
392                          rowcount, rowcount + 1, GTK_SHRINK | GTK_FILL, GTK_SHRINK, 0, 0);
393
394         gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(checkbtn_folder_chmod), 
395                                      item->prefs->enable_folder_chmod);
396         gtk_signal_connect(GTK_OBJECT(checkbtn_folder_chmod), "toggled",
397                             GTK_SIGNAL_FUNC(prefs_folder_item_folder_chmod_cb), dialog);
398
399         entry_folder_chmod = gtk_entry_new();
400         gtk_widget_show(entry_folder_chmod);
401         gtk_table_attach_defaults(GTK_TABLE(table), entry_folder_chmod, 1, 2, 
402                                   rowcount, rowcount + 1);
403         gtk_editable_set_editable(GTK_EDITABLE(entry_folder_chmod), 
404                                   item->prefs->enable_folder_chmod);
405         if (item->prefs->folder_chmod) {
406                 gchar *buf;
407
408                 buf = g_strdup_printf("%o", item->prefs->folder_chmod);
409                 gtk_entry_set_text(GTK_ENTRY(entry_folder_chmod), buf);
410                 g_free(buf);
411         }
412         
413         rowcount++;
414
415         /* Default account */
416         checkbtn_enable_default_account = gtk_check_button_new_with_label(_("Default account: "));
417         gtk_widget_show(checkbtn_enable_default_account);
418         gtk_table_attach(GTK_TABLE(table), checkbtn_enable_default_account, 0, 1, 
419                          rowcount, rowcount + 1, GTK_SHRINK | GTK_FILL, GTK_SHRINK, 0, 0);
420         gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(checkbtn_enable_default_account), 
421                                      item->prefs->enable_default_account);
422         gtk_signal_connect(GTK_OBJECT(checkbtn_enable_default_account), "toggled",
423                             GTK_SIGNAL_FUNC(prefs_folder_item_default_account_cb), dialog);
424
425         optmenu_default_account = gtk_option_menu_new ();
426         gtk_widget_show (optmenu_default_account);
427         gtk_table_attach_defaults(GTK_TABLE(table), optmenu_default_account, 1, 2, 
428                                   rowcount, rowcount + 1);
429         optmenu_default_account_menu = gtk_menu_new ();
430
431         account_list = account_get_list();
432         account_index = 0;
433         index = 0;
434         for (cur_ac = account_list; cur_ac != NULL; cur_ac = cur_ac->next) {
435                 ac_prefs = (PrefsAccount *)cur_ac->data;
436                 MENUITEM_ADD (optmenu_default_account_menu, optmenu_default_account_menuitem,
437                                         ac_prefs->account_name?ac_prefs->account_name : _("Untitled"),
438                                         ac_prefs->account_id);
439                 /* get the index for menu's set_history (sad method?) */
440                 if (ac_prefs->account_id == item->prefs->default_account)
441                         account_index = index;
442                 index++;                        
443         }
444
445         dialog->item->prefs->default_account = item->prefs->default_account;
446
447         optmenu=GTK_OPTION_MENU(optmenu_default_account);
448         gtk_option_menu_set_menu(optmenu, optmenu_default_account_menu);
449
450         gtk_option_menu_set_history(optmenu, account_index);
451
452         menu = gtk_option_menu_get_menu(optmenu);
453         menuitem = gtk_menu_get_active(GTK_MENU(menu));
454         gtk_menu_item_activate(GTK_MENU_ITEM(menuitem));
455
456         gtk_widget_set_sensitive(optmenu_default_account, item->prefs->enable_default_account);
457
458         rowcount++;
459
460         /* Ok and Cancle Buttons */
461         gtkut_button_set_create(&confirm_area, &ok_btn, _("OK"),
462                                 &cancel_btn, _("Cancel"), NULL, NULL);
463         gtk_widget_show(confirm_area);
464         gtk_table_attach_defaults(GTK_TABLE(table), confirm_area, 0, 2, 
465                                   rowcount, rowcount + 1);
466         gtk_widget_grab_default(ok_btn);
467         gtk_signal_connect (GTK_OBJECT(ok_btn), "clicked",
468                             GTK_SIGNAL_FUNC(prefs_folder_item_ok_cb), dialog);
469         gtk_signal_connect (GTK_OBJECT(cancel_btn), "clicked",
470                             GTK_SIGNAL_FUNC(prefs_folder_item_cancel_cb), dialog);
471
472         dialog->window = window;
473         dialog->checkbtn_request_return_receipt = checkbtn_request_return_receipt;
474         dialog->checkbtn_save_copy_to_folder = checkbtn_save_copy_to_folder;
475         dialog->checkbtn_default_to = checkbtn_default_to;
476         dialog->entry_default_to = entry_default_to;
477         dialog->checkbtn_simplify_subject = checkbtn_simplify_subject;
478         dialog->entry_simplify_subject = entry_simplify_subject;
479         dialog->checkbtn_folder_chmod = checkbtn_folder_chmod;
480         dialog->entry_folder_chmod = entry_folder_chmod;
481         dialog->checkbtn_enable_default_account = checkbtn_enable_default_account;
482         dialog->optmenu_default_account = optmenu_default_account;
483
484         g_free(infotext);
485
486         address_completion_start(window);
487
488         gtk_widget_show(window);
489 }
490
491 void prefs_folder_item_destroy(struct PrefsFolderItemDialog *dialog) 
492 {
493         address_completion_unregister_entry(GTK_ENTRY(dialog->entry_default_to));
494         address_completion_end(dialog->window);
495         gtk_widget_destroy(dialog->window);
496         g_free(dialog);
497 }
498
499 void prefs_folder_item_cancel_cb(GtkWidget *widget, 
500                                  struct PrefsFolderItemDialog *dialog) 
501 {
502         prefs_folder_item_destroy(dialog);
503 }
504
505 void prefs_folder_item_delete_cb(GtkWidget *widget, GdkEventAny *event, 
506                                  struct PrefsFolderItemDialog *dialog) 
507 {
508         prefs_folder_item_destroy(dialog);
509 }
510
511 void prefs_folder_item_ok_cb(GtkWidget *widget, 
512                              struct PrefsFolderItemDialog *dialog) 
513 {
514         gchar *buf;
515         PrefsFolderItem *prefs = dialog->item->prefs;
516         GtkWidget *menu;
517         GtkWidget *menuitem;
518         gboolean   old_simplify_val;
519         gchar     *old_simplify_str;
520
521         g_return_if_fail(prefs != NULL);
522
523         old_simplify_val = prefs->enable_simplify_subject;
524         old_simplify_str = prefs->simplify_subject_regexp;
525
526         prefs->request_return_receipt = 
527             gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(dialog->checkbtn_request_return_receipt));
528         /* MIGRATION */    
529         dialog->item->ret_rcpt = prefs->request_return_receipt;
530
531         prefs->save_copy_to_folder = 
532             gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(dialog->checkbtn_save_copy_to_folder));
533
534         prefs->enable_default_to = 
535             gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(dialog->checkbtn_default_to));
536         g_free(prefs->default_to);
537         prefs->default_to = 
538             gtk_editable_get_chars(GTK_EDITABLE(dialog->entry_default_to), 0, -1);
539
540         prefs->enable_simplify_subject =
541             gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(dialog->checkbtn_simplify_subject));
542         prefs->simplify_subject_regexp = 
543             gtk_editable_get_chars(GTK_EDITABLE(dialog->entry_simplify_subject), 0, -1);
544
545         if (prefs->enable_simplify_subject != old_simplify_val ||  
546             0 != strcmp2(prefs->simplify_subject_regexp, old_simplify_str)) 
547                 summary_show(dialog->folderview->summaryview, dialog->item, TRUE);
548                 
549         if (old_simplify_str) g_free(old_simplify_str);
550
551         prefs->enable_folder_chmod = 
552             gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(dialog->checkbtn_folder_chmod));
553         buf = gtk_editable_get_chars(GTK_EDITABLE(dialog->entry_folder_chmod), 0, -1);
554         prefs->folder_chmod = prefs_folder_item_chmod_mode(buf);
555         g_free(buf);
556
557         prefs->enable_default_account = 
558             gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(dialog->checkbtn_enable_default_account));
559         menu = gtk_option_menu_get_menu(GTK_OPTION_MENU(dialog->optmenu_default_account));
560         menuitem = gtk_menu_get_active(GTK_MENU(menu));
561         prefs->default_account = GPOINTER_TO_INT(gtk_object_get_user_data(GTK_OBJECT(menuitem)));
562
563
564         prefs_folder_item_save_config(dialog->item);
565         prefs_folder_item_destroy(dialog);
566 }
567
568 void prefs_folder_item_default_to_cb(GtkWidget *widget, struct PrefsFolderItemDialog *dialog) 
569 {
570         gtk_editable_set_editable(GTK_EDITABLE(dialog->entry_default_to),
571             gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(dialog->checkbtn_default_to)));
572 }
573
574 void prefs_folder_item_simplify_subject_cb(GtkWidget *widget, struct PrefsFolderItemDialog *dialog) 
575 {
576         gtk_editable_set_editable(GTK_EDITABLE(dialog->entry_simplify_subject),
577             gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(dialog->checkbtn_simplify_subject)));
578 }
579
580 void prefs_folder_item_folder_chmod_cb(GtkWidget *widget, struct PrefsFolderItemDialog *dialog) {
581         gtk_editable_set_editable(GTK_EDITABLE(dialog->entry_folder_chmod),
582             gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(dialog->checkbtn_folder_chmod)));
583 }
584
585 gint prefs_folder_item_chmod_mode(gchar *folder_chmod) 
586 {
587         gint newmode = 0;
588         gchar *tmp;
589
590         if (folder_chmod) {
591                 newmode = strtol(folder_chmod, &tmp, 8);
592                 if (!(*(folder_chmod) && !(*tmp)))
593                         newmode = 0;
594         }
595
596         return newmode;
597 }
598
599 void prefs_folder_item_default_account_cb(GtkWidget *widget, struct PrefsFolderItemDialog *dialog) 
600 {
601         gtk_widget_set_sensitive(dialog->optmenu_default_account,
602             gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(dialog->checkbtn_enable_default_account)));
603 }