fix persistence of folder sort mode (broken by adapting Hiro's new folder persistence...
[claws.git] / src / prefs_folder_item.c
1 /*
2  * Sylpheed -- a GTK+ based, lightweight, and fast e-mail client
3  * Copyright (C) 1999-2001 Hiroyuki Yamamoto
4  *
5  * This program is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License as published by
7  * the Free Software Foundation; either version 2 of the License, or
8  * (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program; if not, write to the Free Software
17  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
18  */
19
20 /* alfons - all folder item specific settings should migrate into 
21  * folderlist.xml!!! the old folderitemrc file will only serve for a few 
22  * versions (for compatibility) */
23
24 #ifdef HAVE_CONFIG_H
25 #  include "config.h"
26 #endif
27
28 #include "intl.h"
29 #include "defs.h"
30 #include "folder.h"
31 #include "prefs_folder_item.h"
32 #include "folderview.h"
33 #include "summaryview.h"
34 #include "menu.h"
35 #include "account.h"
36 #include "prefs.h"
37 #include "manage_window.h"
38 #include "utils.h"
39 #include "addr_compl.h"
40
41 PrefsFolderItem tmp_prefs;
42
43 struct PrefsFolderItemDialog
44 {
45         FolderView *folderview;
46         FolderItem *item;
47         GtkWidget *window;
48         GtkWidget *checkbtn_request_return_receipt;
49         GtkWidget *checkbtn_save_copy_to_folder;
50         GtkWidget *checkbtn_default_to;
51         GtkWidget *entry_default_to;
52         GtkWidget *checkbtn_simplify_subject;
53         GtkWidget *entry_simplify_subject;
54         GtkWidget *checkbtn_folder_chmod;
55         GtkWidget *entry_folder_chmod;
56         GtkWidget *checkbtn_enable_default_account;
57         GtkWidget *optmenu_default_account;
58 };
59
60 static PrefParam param[] = {
61         {"sort_by_number", "FALSE", &tmp_prefs.sort_by_number, P_BOOL,
62          NULL, NULL, NULL},
63         {"sort_by_size", "FALSE", &tmp_prefs.sort_by_size, P_BOOL,
64          NULL, NULL, NULL},
65         {"sort_by_date", "FALSE", &tmp_prefs.sort_by_date, P_BOOL,
66          NULL, NULL, NULL},
67         {"sort_by_from", "FALSE", &tmp_prefs.sort_by_from, P_BOOL,
68          NULL, NULL, NULL},
69         {"sort_by_subject", "FALSE", &tmp_prefs.sort_by_subject, P_BOOL,
70          NULL, NULL, NULL},
71         {"sort_by_score", "FALSE", &tmp_prefs.sort_by_score, P_BOOL,
72          NULL, NULL, NULL},
73         {"sort_descending", "FALSE", &tmp_prefs.sort_descending, P_BOOL,
74          NULL, NULL, NULL},
75         /*{"enable_thread", "TRUE", &tmp_prefs.enable_thread, P_BOOL,
76          NULL, NULL, NULL},*/
77         {"kill_score", "-9999", &tmp_prefs.kill_score, P_INT,
78          NULL, NULL, NULL},
79         {"important_score", "1", &tmp_prefs.important_score, P_INT,
80          NULL, NULL, NULL},
81         /* MIGRATION */  
82         {"request_return_receipt", "", &tmp_prefs.request_return_receipt, P_BOOL,
83          NULL, NULL, NULL},
84         {"enable_default_to", "", &tmp_prefs.enable_default_to, P_BOOL,
85          NULL, NULL, NULL},
86         {"default_to", "", &tmp_prefs.default_to, P_STRING,
87          NULL, NULL, NULL},
88         {"enable_simplify_subject", "", &tmp_prefs.enable_simplify_subject, P_BOOL,
89          NULL, NULL, NULL},
90         {"simplify_subject_regexp", "", &tmp_prefs.simplify_subject_regexp, P_STRING,
91          NULL, NULL, NULL},
92         {"enable_folder_chmod", "", &tmp_prefs.enable_folder_chmod, P_BOOL,
93          NULL, NULL, NULL},
94         {"folder_chmod", "", &tmp_prefs.folder_chmod, P_INT,
95          NULL, NULL, NULL},
96         {"enable_default_account", "", &tmp_prefs.enable_default_account, P_BOOL,
97          NULL, NULL, NULL},
98         {"default_account", NULL, &tmp_prefs.default_account, P_INT,
99          NULL, NULL, NULL},
100         {"save_copy_to_folder", NULL, &tmp_prefs.save_copy_to_folder, P_BOOL,
101          NULL, NULL, NULL},
102         {NULL, NULL, NULL, P_OTHER, NULL, NULL, NULL}
103 };
104
105 void prefs_folder_item_delete_cb                (GtkWidget *widget, GdkEventAny *event, 
106                                                  struct PrefsFolderItemDialog *dialog);
107 void prefs_folder_item_cancel_cb                (GtkWidget *widget, 
108                                                  struct PrefsFolderItemDialog *dialog);
109 void prefs_folder_item_ok_cb                    (GtkWidget *widget, 
110                                                  struct PrefsFolderItemDialog *dialog);
111 gint prefs_folder_item_chmod_mode               (gchar *folder_chmod);
112
113
114 void prefs_folder_item_read_config(FolderItem * item)
115 {
116         gchar * id;
117
118         id = folder_item_get_identifier(item);
119
120         tmp_prefs.scoring = NULL;
121         tmp_prefs.processing = NULL;
122         prefs_read_config(param, id, FOLDERITEM_RC);
123         g_free(id);
124
125         *item->prefs = tmp_prefs;
126
127         /*
128          * MIGRATION: next lines are migration code. the idea is that
129          *            if used regularly, claws folder config ends up
130          *            in the same file as sylpheed-main
131          */
132
133         item->ret_rcpt = tmp_prefs.request_return_receipt ? TRUE : FALSE;
134
135         /* MIGRATION: 0.7.8main+ has persistent sort order. claws had the sort
136          *            order in different members, which is ofcourse a little
137          *            bit phoney. */
138         if (item->sort_key == SORT_BY_NONE) {
139                 item->sort_key  = (tmp_prefs.sort_by_number  ? SORT_BY_NUMBER  :
140                                    tmp_prefs.sort_by_size    ? SORT_BY_SIZE    :
141                                    tmp_prefs.sort_by_date    ? SORT_BY_DATE    :
142                                    tmp_prefs.sort_by_from    ? SORT_BY_FROM    :
143                                    tmp_prefs.sort_by_subject ? SORT_BY_SUBJECT :
144                                    tmp_prefs.sort_by_score   ? SORT_BY_SCORE   :
145                                                                  SORT_BY_NONE);
146                 item->sort_type = tmp_prefs.sort_descending ? SORT_DESCENDING : SORT_ASCENDING;
147         }                                                               
148 }
149
150 void prefs_folder_item_save_config(FolderItem * item)
151 {       
152         gchar * id;
153
154         tmp_prefs = * item->prefs;
155
156         id = folder_item_get_identifier(item);
157
158         prefs_save_config(param, id, FOLDERITEM_RC);
159         g_free(id);
160
161         /* MIGRATION: make sure migrated items are not saved
162          */
163 }
164
165 void prefs_folder_item_set_config(FolderItem * item,
166                                   int sort_type, gint sort_mode)
167 {
168         g_assert(item);
169         g_warning("prefs_folder_item_set_config() should never be called\n");
170         item->sort_key  = sort_type;
171         item->sort_type = sort_mode;
172 }
173
174 PrefsFolderItem * prefs_folder_item_new(void)
175 {
176         PrefsFolderItem * prefs;
177
178         prefs = g_new0(PrefsFolderItem, 1);
179
180         tmp_prefs.sort_by_number = FALSE;
181         tmp_prefs.sort_by_size = FALSE;
182         tmp_prefs.sort_by_date = FALSE;
183         tmp_prefs.sort_by_from = FALSE;
184         tmp_prefs.sort_by_subject = FALSE;
185         tmp_prefs.sort_by_score = FALSE;
186         tmp_prefs.sort_descending = FALSE;
187         tmp_prefs.kill_score = -9999;
188         tmp_prefs.important_score = 9999;
189
190         tmp_prefs.request_return_receipt = FALSE;
191         tmp_prefs.enable_default_to = FALSE;
192         tmp_prefs.default_to = NULL;
193         tmp_prefs.enable_simplify_subject = FALSE;
194         tmp_prefs.simplify_subject_regexp = NULL;
195         tmp_prefs.enable_folder_chmod = FALSE;
196         tmp_prefs.folder_chmod = 0;
197         tmp_prefs.enable_default_account = FALSE;
198         tmp_prefs.default_account = 0;
199         tmp_prefs.save_copy_to_folder = FALSE;
200
201         tmp_prefs.scoring = NULL;
202         tmp_prefs.processing = NULL;
203
204         * prefs = tmp_prefs;
205         
206         return prefs;
207 }
208
209 void prefs_folder_item_free(PrefsFolderItem * prefs)
210 {
211         if (prefs->default_to) 
212                 g_free(prefs->default_to);
213         if (prefs->scoring != NULL)
214                 prefs_scoring_free(prefs->scoring);
215         g_free(prefs);
216 }
217
218 gint prefs_folder_item_get_sort_mode(FolderItem * item)
219 {
220         g_assert(item != NULL);
221         g_warning("prefs_folder_item_get_sort_mode() should never be called\n");
222         return item->sort_key;
223 }
224
225 gint prefs_folder_item_get_sort_type(FolderItem * item)
226 {
227         g_assert(item != NULL);
228         g_warning("prefs_folder_item_get_sort_type() should never be called\n");
229         return item->sort_type;
230 }
231
232 #define SAFE_STRING(str) \
233         (str) ? (str) : ""
234
235 void prefs_folder_item_create(void *folderview, FolderItem *item) 
236 {
237         struct PrefsFolderItemDialog *dialog;
238         guint rowcount;
239         gchar *folder_identifier, *infotext;
240
241         GtkWidget *window;
242         GtkWidget *table;
243         GtkWidget *infolabel;
244         GtkWidget *ok_btn;
245         GtkWidget *cancel_btn;
246         GtkWidget *confirm_area;
247         
248         GtkWidget *checkbtn_request_return_receipt;
249         GtkWidget *checkbtn_save_copy_to_folder;
250         GtkWidget *checkbtn_default_to;
251         GtkWidget *entry_default_to;
252         GtkWidget *checkbtn_simplify_subject;
253         GtkWidget *entry_simplify_subject;
254         GtkWidget *checkbtn_folder_chmod;
255         GtkWidget *entry_folder_chmod;
256         GtkWidget *checkbtn_enable_default_account;
257         GtkWidget *optmenu_default_account;
258         GtkWidget *optmenu_default_account_menu;
259         GtkWidget *optmenu_default_account_menuitem;
260         GList *cur_ac;
261         GList *account_list;
262         PrefsAccount *ac_prefs;
263         GtkOptionMenu *optmenu;
264         GtkWidget *menu;
265         GtkWidget *menuitem;
266         gint account_index, index;
267
268         dialog = g_new0(struct PrefsFolderItemDialog, 1);
269         dialog->folderview = folderview;
270         dialog->item       = item;
271
272         /* Window */
273         window = gtk_window_new (GTK_WINDOW_DIALOG);
274         gtk_window_set_title (GTK_WINDOW(window),
275                               _("Folder Property"));
276         gtk_container_set_border_width (GTK_CONTAINER (window), 8);
277         gtk_window_position (GTK_WINDOW (window), GTK_WIN_POS_CENTER);
278         gtk_window_set_policy (GTK_WINDOW (window), FALSE, TRUE, FALSE);
279         gtk_signal_connect (GTK_OBJECT(window), "delete_event",
280                             GTK_SIGNAL_FUNC(prefs_folder_item_delete_cb), dialog);
281         MANAGE_WINDOW_SIGNALS_CONNECT (window);
282
283         /* Table */
284         table = gtk_table_new(4, 2, FALSE);
285         gtk_widget_show(table);
286         gtk_table_set_row_spacings(GTK_TABLE(table), VSPACING_NARROW);
287         gtk_container_add(GTK_CONTAINER (window), table);
288         rowcount = 0;
289
290         /* Label */
291         folder_identifier = folder_item_get_identifier(item);
292         infotext = g_strconcat(_("Folder Property for "), folder_identifier, NULL);
293         infolabel = gtk_label_new(infotext);
294         gtk_table_attach(GTK_TABLE(table), infolabel, 0, 2, rowcount, 
295                          rowcount + 1, GTK_SHRINK | GTK_FILL, GTK_SHRINK, 0, 0);
296         gtk_widget_show(infolabel);
297         rowcount++;
298
299         /* Request Return Receipt */
300         checkbtn_request_return_receipt = gtk_check_button_new_with_label
301                 (_("Request Return Receipt"));
302         gtk_widget_show(checkbtn_request_return_receipt);
303         gtk_table_attach(GTK_TABLE(table), checkbtn_request_return_receipt, 
304                          0, 2, rowcount, rowcount + 1, GTK_SHRINK | GTK_FILL, 
305                          GTK_SHRINK, 0, 0);
306         gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(checkbtn_request_return_receipt),
307                                      item->ret_rcpt ? TRUE : FALSE);
308
309         rowcount++;
310
311         /* Save Copy to Folder */
312         checkbtn_save_copy_to_folder = gtk_check_button_new_with_label
313                 (_("Save copy of outgoing messages to this folder instead of Sent"));
314         gtk_widget_show(checkbtn_save_copy_to_folder);
315         gtk_table_attach(GTK_TABLE(table), checkbtn_save_copy_to_folder, 0, 2, 
316                          rowcount, rowcount + 1, GTK_SHRINK | GTK_FILL, GTK_SHRINK, 0, 0);
317         gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(checkbtn_save_copy_to_folder),
318                                      item->prefs->save_copy_to_folder ? TRUE : FALSE);
319
320         rowcount++;
321
322         /* Default To */
323         checkbtn_default_to = gtk_check_button_new_with_label(_("Default To: "));
324         gtk_widget_show(checkbtn_default_to);
325         gtk_table_attach(GTK_TABLE(table), checkbtn_default_to, 0, 1, 
326                          rowcount, rowcount + 1, GTK_SHRINK | GTK_FILL, GTK_SHRINK, 0, 0);
327         gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(checkbtn_default_to), 
328                                      item->prefs->enable_default_to);
329
330         entry_default_to = gtk_entry_new();
331         gtk_widget_show(entry_default_to);
332         gtk_table_attach_defaults(GTK_TABLE(table), entry_default_to, 1, 2, rowcount, rowcount + 1);
333         SET_TOGGLE_SENSITIVITY(checkbtn_default_to, entry_default_to);
334         gtk_entry_set_text(GTK_ENTRY(entry_default_to), SAFE_STRING(item->prefs->default_to));
335         address_completion_register_entry(GTK_ENTRY(entry_default_to));
336
337         rowcount++;
338
339         /* Simplify Subject */
340         checkbtn_simplify_subject = gtk_check_button_new_with_label(_("Simplify Subject RegExp: "));
341         gtk_widget_show(checkbtn_simplify_subject);
342         gtk_table_attach(GTK_TABLE(table), checkbtn_simplify_subject, 0, 1, 
343                          rowcount, rowcount + 1, GTK_SHRINK | GTK_FILL, GTK_SHRINK, 0, 0);
344         gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(checkbtn_simplify_subject), 
345                                      item->prefs->enable_simplify_subject);
346
347         entry_simplify_subject = gtk_entry_new();
348         gtk_widget_show(entry_simplify_subject);
349         gtk_table_attach_defaults(GTK_TABLE(table), entry_simplify_subject, 1, 2, 
350                                   rowcount, rowcount + 1);
351         SET_TOGGLE_SENSITIVITY(checkbtn_simplify_subject, entry_simplify_subject);
352         gtk_entry_set_text(GTK_ENTRY(entry_simplify_subject), 
353                            SAFE_STRING(item->prefs->simplify_subject_regexp));
354
355         rowcount++;
356
357         /* Folder chmod */
358         checkbtn_folder_chmod = gtk_check_button_new_with_label(_("Folder chmod: "));
359         gtk_widget_show(checkbtn_folder_chmod);
360         gtk_table_attach(GTK_TABLE(table), checkbtn_folder_chmod, 0, 1, 
361                          rowcount, rowcount + 1, GTK_SHRINK | GTK_FILL, GTK_SHRINK, 0, 0);
362
363         gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(checkbtn_folder_chmod), 
364                                      item->prefs->enable_folder_chmod);
365
366         entry_folder_chmod = gtk_entry_new();
367         gtk_widget_show(entry_folder_chmod);
368         gtk_table_attach_defaults(GTK_TABLE(table), entry_folder_chmod, 1, 2, 
369                                   rowcount, rowcount + 1);
370         SET_TOGGLE_SENSITIVITY(checkbtn_folder_chmod, entry_folder_chmod);
371         if (item->prefs->folder_chmod) {
372                 gchar *buf;
373
374                 buf = g_strdup_printf("%o", item->prefs->folder_chmod);
375                 gtk_entry_set_text(GTK_ENTRY(entry_folder_chmod), buf);
376                 g_free(buf);
377         }
378         
379         rowcount++;
380
381         /* Default account */
382         checkbtn_enable_default_account = gtk_check_button_new_with_label(_("Default account: "));
383         gtk_widget_show(checkbtn_enable_default_account);
384         gtk_table_attach(GTK_TABLE(table), checkbtn_enable_default_account, 0, 1, 
385                          rowcount, rowcount + 1, GTK_SHRINK | GTK_FILL, GTK_SHRINK, 0, 0);
386         gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(checkbtn_enable_default_account), 
387                                      item->prefs->enable_default_account);
388
389         optmenu_default_account = gtk_option_menu_new ();
390         gtk_widget_show (optmenu_default_account);
391         gtk_table_attach_defaults(GTK_TABLE(table), optmenu_default_account, 1, 2, 
392                                   rowcount, rowcount + 1);
393         optmenu_default_account_menu = gtk_menu_new ();
394
395         account_list = account_get_list();
396         account_index = 0;
397         index = 0;
398         for (cur_ac = account_list; cur_ac != NULL; cur_ac = cur_ac->next) {
399                 ac_prefs = (PrefsAccount *)cur_ac->data;
400                 MENUITEM_ADD (optmenu_default_account_menu, optmenu_default_account_menuitem,
401                                         ac_prefs->account_name?ac_prefs->account_name : _("Untitled"),
402                                         ac_prefs->account_id);
403                 /* get the index for menu's set_history (sad method?) */
404                 if (ac_prefs->account_id == item->prefs->default_account)
405                         account_index = index;
406                 index++;                        
407         }
408
409         dialog->item->prefs->default_account = item->prefs->default_account;
410
411         optmenu=GTK_OPTION_MENU(optmenu_default_account);
412         gtk_option_menu_set_menu(optmenu, optmenu_default_account_menu);
413
414         gtk_option_menu_set_history(optmenu, account_index);
415
416         menu = gtk_option_menu_get_menu(optmenu);
417         menuitem = gtk_menu_get_active(GTK_MENU(menu));
418         gtk_menu_item_activate(GTK_MENU_ITEM(menuitem));
419
420         SET_TOGGLE_SENSITIVITY(checkbtn_enable_default_account, optmenu_default_account);
421
422         rowcount++;
423
424         /* Ok and Cancle Buttons */
425         gtkut_button_set_create(&confirm_area, &ok_btn, _("OK"),
426                                 &cancel_btn, _("Cancel"), NULL, NULL);
427         gtk_widget_show(confirm_area);
428         gtk_table_attach_defaults(GTK_TABLE(table), confirm_area, 0, 2, 
429                                   rowcount, rowcount + 1);
430         gtk_widget_grab_default(ok_btn);
431         gtk_signal_connect (GTK_OBJECT(ok_btn), "clicked",
432                             GTK_SIGNAL_FUNC(prefs_folder_item_ok_cb), dialog);
433         gtk_signal_connect (GTK_OBJECT(cancel_btn), "clicked",
434                             GTK_SIGNAL_FUNC(prefs_folder_item_cancel_cb), dialog);
435
436         dialog->window = window;
437         dialog->checkbtn_request_return_receipt = checkbtn_request_return_receipt;
438         dialog->checkbtn_save_copy_to_folder = checkbtn_save_copy_to_folder;
439         dialog->checkbtn_default_to = checkbtn_default_to;
440         dialog->entry_default_to = entry_default_to;
441         dialog->checkbtn_simplify_subject = checkbtn_simplify_subject;
442         dialog->entry_simplify_subject = entry_simplify_subject;
443         dialog->checkbtn_folder_chmod = checkbtn_folder_chmod;
444         dialog->entry_folder_chmod = entry_folder_chmod;
445         dialog->checkbtn_enable_default_account = checkbtn_enable_default_account;
446         dialog->optmenu_default_account = optmenu_default_account;
447
448         g_free(infotext);
449
450         address_completion_start(window);
451
452         gtk_widget_show(window);
453 }
454
455 void prefs_folder_item_destroy(struct PrefsFolderItemDialog *dialog) 
456 {
457         address_completion_unregister_entry(GTK_ENTRY(dialog->entry_default_to));
458         address_completion_end(dialog->window);
459         gtk_widget_destroy(dialog->window);
460         g_free(dialog);
461 }
462
463 void prefs_folder_item_cancel_cb(GtkWidget *widget, 
464                                  struct PrefsFolderItemDialog *dialog) 
465 {
466         prefs_folder_item_destroy(dialog);
467 }
468
469 void prefs_folder_item_delete_cb(GtkWidget *widget, GdkEventAny *event, 
470                                  struct PrefsFolderItemDialog *dialog) 
471 {
472         prefs_folder_item_destroy(dialog);
473 }
474
475 void prefs_folder_item_ok_cb(GtkWidget *widget, 
476                              struct PrefsFolderItemDialog *dialog) 
477 {
478         gchar *buf;
479         PrefsFolderItem *prefs = dialog->item->prefs;
480         GtkWidget *menu;
481         GtkWidget *menuitem;
482         gboolean   old_simplify_val;
483         gchar     *old_simplify_str;
484
485         g_return_if_fail(prefs != NULL);
486
487         old_simplify_val = prefs->enable_simplify_subject;
488         old_simplify_str = prefs->simplify_subject_regexp;
489
490         prefs->request_return_receipt = 
491             gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(dialog->checkbtn_request_return_receipt));
492         /* MIGRATION */    
493         dialog->item->ret_rcpt = prefs->request_return_receipt;
494
495         prefs->save_copy_to_folder = 
496             gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(dialog->checkbtn_save_copy_to_folder));
497
498         prefs->enable_default_to = 
499             gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(dialog->checkbtn_default_to));
500         g_free(prefs->default_to);
501         prefs->default_to = 
502             gtk_editable_get_chars(GTK_EDITABLE(dialog->entry_default_to), 0, -1);
503
504         prefs->enable_simplify_subject =
505             gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(dialog->checkbtn_simplify_subject));
506         prefs->simplify_subject_regexp = 
507             gtk_editable_get_chars(GTK_EDITABLE(dialog->entry_simplify_subject), 0, -1);
508         
509         if (dialog->item == dialog->folderview->summaryview->folder_item &&
510             (prefs->enable_simplify_subject != old_simplify_val ||  
511             0 != strcmp2(prefs->simplify_subject_regexp, old_simplify_str))) 
512                 summary_show(dialog->folderview->summaryview, dialog->item, FALSE);
513                 
514         if (old_simplify_str) g_free(old_simplify_str);
515
516         prefs->enable_folder_chmod = 
517             gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(dialog->checkbtn_folder_chmod));
518         buf = gtk_editable_get_chars(GTK_EDITABLE(dialog->entry_folder_chmod), 0, -1);
519         prefs->folder_chmod = prefs_folder_item_chmod_mode(buf);
520         g_free(buf);
521
522         prefs->enable_default_account = 
523             gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(dialog->checkbtn_enable_default_account));
524         menu = gtk_option_menu_get_menu(GTK_OPTION_MENU(dialog->optmenu_default_account));
525         menuitem = gtk_menu_get_active(GTK_MENU(menu));
526         prefs->default_account = GPOINTER_TO_INT(gtk_object_get_user_data(GTK_OBJECT(menuitem)));
527
528
529         prefs_folder_item_save_config(dialog->item);
530         prefs_folder_item_destroy(dialog);
531 }
532
533 gint prefs_folder_item_chmod_mode(gchar *folder_chmod) 
534 {
535         gint newmode = 0;
536         gchar *tmp;
537
538         if (folder_chmod) {
539                 newmode = strtol(folder_chmod, &tmp, 8);
540                 if (!(*(folder_chmod) && !(*tmp)))
541                         newmode = 0;
542         }
543
544         return newmode;
545 }