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