add default_reply_to folder option (closes patch 581044)
[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_default_reply_to;
55         GtkWidget *entry_default_reply_to;
56         GtkWidget *checkbtn_simplify_subject;
57         GtkWidget *entry_simplify_subject;
58         GtkWidget *checkbtn_folder_chmod;
59         GtkWidget *entry_folder_chmod;
60         GtkWidget *checkbtn_enable_default_account;
61         GtkWidget *optmenu_default_account;
62         GtkWidget *folder_color;
63         GtkWidget *folder_color_btn;
64 };
65
66 static GtkWidget *color_dialog;
67
68 static PrefParam param[] = {
69         {"sort_by_number", "FALSE", &tmp_prefs.sort_by_number, P_BOOL,
70          NULL, NULL, NULL},
71         {"sort_by_size", "FALSE", &tmp_prefs.sort_by_size, P_BOOL,
72          NULL, NULL, NULL},
73         {"sort_by_date", "FALSE", &tmp_prefs.sort_by_date, P_BOOL,
74          NULL, NULL, NULL},
75         {"sort_by_from", "FALSE", &tmp_prefs.sort_by_from, P_BOOL,
76          NULL, NULL, NULL},
77         {"sort_by_subject", "FALSE", &tmp_prefs.sort_by_subject, P_BOOL,
78          NULL, NULL, NULL},
79         {"sort_by_score", "FALSE", &tmp_prefs.sort_by_score, P_BOOL,
80          NULL, NULL, NULL},
81         {"sort_descending", "FALSE", &tmp_prefs.sort_descending, P_BOOL,
82          NULL, NULL, NULL},
83         /*{"enable_thread", "TRUE", &tmp_prefs.enable_thread, P_BOOL,
84          NULL, NULL, NULL},*/
85         {"hide_score", "-9999", &tmp_prefs.kill_score, P_INT,
86          NULL, NULL, NULL},
87         {"important_score", "1", &tmp_prefs.important_score, P_INT,
88          NULL, NULL, NULL},
89         /* MIGRATION */  
90         {"request_return_receipt", "", &tmp_prefs.request_return_receipt, P_BOOL,
91          NULL, NULL, NULL},
92         {"enable_default_to", "", &tmp_prefs.enable_default_to, P_BOOL,
93          NULL, NULL, NULL},
94         {"default_to", "", &tmp_prefs.default_to, P_STRING,
95          NULL, NULL, NULL},
96         {"enable_default_reply_to", "", &tmp_prefs.enable_default_reply_to, P_BOOL,
97          NULL, NULL, NULL},
98         {"default_reply_to", "", &tmp_prefs.default_reply_to, P_STRING,
99          NULL, NULL, NULL},
100         {"enable_simplify_subject", "", &tmp_prefs.enable_simplify_subject, P_BOOL,
101          NULL, NULL, NULL},
102         {"simplify_subject_regexp", "", &tmp_prefs.simplify_subject_regexp, P_STRING,
103          NULL, NULL, NULL},
104         {"enable_folder_chmod", "", &tmp_prefs.enable_folder_chmod, P_BOOL,
105          NULL, NULL, NULL},
106         {"folder_chmod", "", &tmp_prefs.folder_chmod, P_INT,
107          NULL, NULL, NULL},
108         {"enable_default_account", "", &tmp_prefs.enable_default_account, P_BOOL,
109          NULL, NULL, NULL},
110         {"default_account", NULL, &tmp_prefs.default_account, P_INT,
111          NULL, NULL, NULL},
112         {"save_copy_to_folder", NULL, &tmp_prefs.save_copy_to_folder, P_BOOL,
113          NULL, NULL, NULL},
114         {"folder_color", "", &tmp_prefs.color, P_INT,
115          NULL, NULL, NULL},
116         {NULL, NULL, NULL, P_OTHER, NULL, NULL, NULL}
117 };
118
119 void prefs_folder_item_delete_cb                (GtkWidget *widget, GdkEventAny *event, 
120                                                  struct PrefsFolderItemDialog *dialog);
121 void prefs_folder_item_cancel_cb                (GtkWidget *widget, 
122                                                  struct PrefsFolderItemDialog *dialog);
123 void prefs_folder_item_ok_cb                    (GtkWidget *widget, 
124                                                  struct PrefsFolderItemDialog *dialog);
125 gint prefs_folder_item_chmod_mode               (gchar *folder_chmod);
126
127 static void set_button_color(guint rgbvalue, GtkWidget *button);
128 static void folder_color_set_dialog(GtkWidget *widget, gpointer data);
129 static void folder_color_set_dialog_ok(GtkWidget *widget, gpointer data);
130 static void folder_color_set_dialog_cancel(GtkWidget *widget, gpointer data);
131 static void folder_color_set_dialog_key_pressed(GtkWidget *widget,
132                                                 GdkEventKey *event,
133                                                 gpointer data);
134
135
136 void prefs_folder_item_read_config(FolderItem * item)
137 {
138         gchar * id;
139
140         id = folder_item_get_identifier(item);
141
142         tmp_prefs.scoring = NULL;
143         tmp_prefs.processing = NULL;
144         prefs_read_config(param, id, FOLDERITEM_RC);
145         g_free(id);
146
147         *item->prefs = tmp_prefs;
148
149         /*
150          * MIGRATION: next lines are migration code. the idea is that
151          *            if used regularly, claws folder config ends up
152          *            in the same file as sylpheed-main
153          */
154
155         item->ret_rcpt = tmp_prefs.request_return_receipt ? TRUE : FALSE;
156
157         /* MIGRATION: 0.7.8main+ has persistent sort order. claws had the sort
158          *            order in different members, which is ofcourse a little
159          *            bit phoney. */
160         if (item->sort_key == SORT_BY_NONE) {
161                 item->sort_key  = (tmp_prefs.sort_by_number  ? SORT_BY_NUMBER  :
162                                    tmp_prefs.sort_by_size    ? SORT_BY_SIZE    :
163                                    tmp_prefs.sort_by_date    ? SORT_BY_DATE    :
164                                    tmp_prefs.sort_by_from    ? SORT_BY_FROM    :
165                                    tmp_prefs.sort_by_subject ? SORT_BY_SUBJECT :
166                                    tmp_prefs.sort_by_score   ? SORT_BY_SCORE   :
167                                                                  SORT_BY_NONE);
168                 item->sort_type = tmp_prefs.sort_descending ? SORT_DESCENDING : SORT_ASCENDING;
169         }                                                               
170 }
171
172 void prefs_folder_item_save_config(FolderItem * item)
173 {       
174         gchar * id;
175
176         tmp_prefs = * item->prefs;
177
178         id = folder_item_get_identifier(item);
179
180         prefs_save_config(param, id, FOLDERITEM_RC);
181         g_free(id);
182
183         /* MIGRATION: make sure migrated items are not saved
184          */
185 }
186
187 void prefs_folder_item_set_config(FolderItem * item,
188                                   int sort_type, gint sort_mode)
189 {
190         g_assert(item);
191         g_warning("prefs_folder_item_set_config() should never be called\n");
192         item->sort_key  = sort_type;
193         item->sort_type = sort_mode;
194 }
195
196 PrefsFolderItem * prefs_folder_item_new(void)
197 {
198         PrefsFolderItem * prefs;
199
200         prefs = g_new0(PrefsFolderItem, 1);
201
202         tmp_prefs.sort_by_number = FALSE;
203         tmp_prefs.sort_by_size = FALSE;
204         tmp_prefs.sort_by_date = FALSE;
205         tmp_prefs.sort_by_from = FALSE;
206         tmp_prefs.sort_by_subject = FALSE;
207         tmp_prefs.sort_by_score = FALSE;
208         tmp_prefs.sort_descending = FALSE;
209         tmp_prefs.kill_score = -9999;
210         tmp_prefs.important_score = 9999;
211
212         tmp_prefs.request_return_receipt = FALSE;
213         tmp_prefs.enable_default_to = FALSE;
214         tmp_prefs.default_to = NULL;
215         tmp_prefs.enable_default_reply_to = FALSE;
216         tmp_prefs.default_reply_to = NULL;
217         tmp_prefs.enable_simplify_subject = FALSE;
218         tmp_prefs.simplify_subject_regexp = NULL;
219         tmp_prefs.enable_folder_chmod = FALSE;
220         tmp_prefs.folder_chmod = 0;
221         tmp_prefs.enable_default_account = FALSE;
222         tmp_prefs.default_account = 0;
223         tmp_prefs.save_copy_to_folder = FALSE;
224         tmp_prefs.color = 0;
225
226         tmp_prefs.scoring = NULL;
227         tmp_prefs.processing = NULL;
228
229         * prefs = tmp_prefs;
230         
231         return prefs;
232 }
233
234 void prefs_folder_item_free(PrefsFolderItem * prefs)
235 {
236         if (prefs->default_to) 
237                 g_free(prefs->default_to);
238         if (prefs->default_reply_to) 
239                 g_free(prefs->default_reply_to);
240         if (prefs->scoring != NULL)
241                 prefs_scoring_free(prefs->scoring);
242         g_free(prefs);
243 }
244
245 gint prefs_folder_item_get_sort_mode(FolderItem * item)
246 {
247         g_assert(item != NULL);
248         g_warning("prefs_folder_item_get_sort_mode() should never be called\n");
249         return item->sort_key;
250 }
251
252 gint prefs_folder_item_get_sort_type(FolderItem * item)
253 {
254         g_assert(item != NULL);
255         g_warning("prefs_folder_item_get_sort_type() should never be called\n");
256         return item->sort_type;
257 }
258
259 #define SAFE_STRING(str) \
260         (str) ? (str) : ""
261
262 void prefs_folder_item_create(void *folderview, FolderItem *item) 
263 {
264         struct PrefsFolderItemDialog *dialog;
265         guint rowcount;
266         gchar *folder_identifier, *infotext;
267
268         GtkWidget *window;
269         GtkWidget *table;
270         GtkWidget *infolabel;
271         GtkWidget *ok_btn;
272         GtkWidget *cancel_btn;
273         GtkWidget *confirm_area;
274         
275         GtkWidget *checkbtn_request_return_receipt;
276         GtkWidget *checkbtn_save_copy_to_folder;
277         GtkWidget *checkbtn_default_to;
278         GtkWidget *entry_default_to;
279         GtkWidget *checkbtn_default_reply_to;
280         GtkWidget *entry_default_reply_to;
281         GtkWidget *checkbtn_simplify_subject;
282         GtkWidget *entry_simplify_subject;
283         GtkWidget *checkbtn_folder_chmod;
284         GtkWidget *entry_folder_chmod;
285         GtkWidget *checkbtn_enable_default_account;
286         GtkWidget *optmenu_default_account;
287         GtkWidget *optmenu_default_account_menu;
288         GtkWidget *optmenu_default_account_menuitem;
289         GtkWidget *folder_color;
290         GtkWidget *folder_color_btn;
291         GList *cur_ac;
292         GList *account_list;
293         PrefsAccount *ac_prefs;
294         GtkOptionMenu *optmenu;
295         GtkWidget *menu;
296         GtkWidget *menuitem;
297         gint account_index, index;
298
299         dialog = g_new0(struct PrefsFolderItemDialog, 1);
300         dialog->folderview = folderview;
301         dialog->item       = item;
302
303         /* Window */
304         window = gtk_window_new (GTK_WINDOW_DIALOG);
305         gtk_window_set_title (GTK_WINDOW(window),
306                               _("Folder Property"));
307         gtk_container_set_border_width (GTK_CONTAINER (window), 8);
308         gtk_window_position (GTK_WINDOW (window), GTK_WIN_POS_CENTER);
309         gtk_window_set_policy (GTK_WINDOW (window), FALSE, TRUE, FALSE);
310         gtk_signal_connect (GTK_OBJECT(window), "delete_event",
311                             GTK_SIGNAL_FUNC(prefs_folder_item_delete_cb), dialog);
312         MANAGE_WINDOW_SIGNALS_CONNECT (window);
313
314         /* Table */
315         table = gtk_table_new(8, 2, FALSE);
316         gtk_widget_show(table);
317         gtk_table_set_row_spacings(GTK_TABLE(table), VSPACING_NARROW);
318         gtk_container_add(GTK_CONTAINER (window), table);
319         rowcount = 0;
320
321         /* Label */
322         folder_identifier = folder_item_get_identifier(item);
323         infotext = g_strconcat(_("Folder Property for "), folder_identifier, NULL);
324         infolabel = gtk_label_new(infotext);
325         gtk_table_attach(GTK_TABLE(table), infolabel, 0, 2, rowcount, 
326                          rowcount + 1, GTK_SHRINK | GTK_FILL, GTK_SHRINK, 0, 0);
327         gtk_widget_show(infolabel);
328         rowcount++;
329
330         /* Request Return Receipt */
331         checkbtn_request_return_receipt = gtk_check_button_new_with_label
332                 (_("Request Return Receipt"));
333         gtk_widget_show(checkbtn_request_return_receipt);
334         gtk_table_attach(GTK_TABLE(table), checkbtn_request_return_receipt, 
335                          0, 2, rowcount, rowcount + 1, GTK_SHRINK | GTK_FILL, 
336                          GTK_SHRINK, 0, 0);
337         gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(checkbtn_request_return_receipt),
338                                      item->ret_rcpt ? TRUE : FALSE);
339
340         rowcount++;
341
342         /* Save Copy to Folder */
343         checkbtn_save_copy_to_folder = gtk_check_button_new_with_label
344                 (_("Save copy of outgoing messages to this folder instead of Sent"));
345         gtk_widget_show(checkbtn_save_copy_to_folder);
346         gtk_table_attach(GTK_TABLE(table), checkbtn_save_copy_to_folder, 0, 2, 
347                          rowcount, rowcount + 1, GTK_SHRINK | GTK_FILL, GTK_SHRINK, 0, 0);
348         gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(checkbtn_save_copy_to_folder),
349                                      item->prefs->save_copy_to_folder ? TRUE : FALSE);
350
351         rowcount++;
352
353         /* Default To */
354         checkbtn_default_to = gtk_check_button_new_with_label(_("Default To: "));
355         gtk_widget_show(checkbtn_default_to);
356         gtk_table_attach(GTK_TABLE(table), checkbtn_default_to, 0, 1, 
357                          rowcount, rowcount + 1, GTK_SHRINK | GTK_FILL, GTK_SHRINK, 0, 0);
358         gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(checkbtn_default_to), 
359                                      item->prefs->enable_default_to);
360
361         entry_default_to = gtk_entry_new();
362         gtk_widget_show(entry_default_to);
363         gtk_table_attach_defaults(GTK_TABLE(table), entry_default_to, 1, 2, rowcount, rowcount + 1);
364         SET_TOGGLE_SENSITIVITY(checkbtn_default_to, entry_default_to);
365         gtk_entry_set_text(GTK_ENTRY(entry_default_to), SAFE_STRING(item->prefs->default_to));
366         address_completion_register_entry(GTK_ENTRY(entry_default_to));
367
368         rowcount++;
369
370         /* Default Reply-To */
371         checkbtn_default_reply_to = gtk_check_button_new_with_label(_("Default Reply-To: "));
372         gtk_widget_show(checkbtn_default_reply_to);
373         gtk_table_attach(GTK_TABLE(table), checkbtn_default_reply_to, 0, 1, 
374                          rowcount, rowcount + 1, GTK_SHRINK | GTK_FILL, GTK_SHRINK, 0, 0);
375         gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(checkbtn_default_reply_to), 
376                                      item->prefs->enable_default_reply_to);
377
378         entry_default_reply_to = gtk_entry_new();
379         gtk_widget_show(entry_default_reply_to);
380         gtk_table_attach_defaults(GTK_TABLE(table), entry_default_reply_to, 1, 2, rowcount, rowcount + 1);
381         SET_TOGGLE_SENSITIVITY(checkbtn_default_reply_to, entry_default_reply_to);
382         gtk_entry_set_text(GTK_ENTRY(entry_default_reply_to), SAFE_STRING(item->prefs->default_reply_to));
383         address_completion_register_entry(GTK_ENTRY(entry_default_reply_to));
384
385         rowcount++;
386
387         /* Simplify Subject */
388         checkbtn_simplify_subject = gtk_check_button_new_with_label(_("Simplify Subject RegExp: "));
389         gtk_widget_show(checkbtn_simplify_subject);
390         gtk_table_attach(GTK_TABLE(table), checkbtn_simplify_subject, 0, 1, 
391                          rowcount, rowcount + 1, GTK_SHRINK | GTK_FILL, GTK_SHRINK, 0, 0);
392         gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(checkbtn_simplify_subject), 
393                                      item->prefs->enable_simplify_subject);
394
395         entry_simplify_subject = gtk_entry_new();
396         gtk_widget_show(entry_simplify_subject);
397         gtk_table_attach_defaults(GTK_TABLE(table), entry_simplify_subject, 1, 2, 
398                                   rowcount, rowcount + 1);
399         SET_TOGGLE_SENSITIVITY(checkbtn_simplify_subject, entry_simplify_subject);
400         gtk_entry_set_text(GTK_ENTRY(entry_simplify_subject), 
401                            SAFE_STRING(item->prefs->simplify_subject_regexp));
402
403         rowcount++;
404
405         /* Folder chmod */
406         checkbtn_folder_chmod = gtk_check_button_new_with_label(_("Folder chmod: "));
407         gtk_widget_show(checkbtn_folder_chmod);
408         gtk_table_attach(GTK_TABLE(table), checkbtn_folder_chmod, 0, 1, 
409                          rowcount, rowcount + 1, GTK_SHRINK | GTK_FILL, GTK_SHRINK, 0, 0);
410
411         gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(checkbtn_folder_chmod), 
412                                      item->prefs->enable_folder_chmod);
413
414         entry_folder_chmod = gtk_entry_new();
415         gtk_widget_show(entry_folder_chmod);
416         gtk_table_attach_defaults(GTK_TABLE(table), entry_folder_chmod, 1, 2, 
417                                   rowcount, rowcount + 1);
418         SET_TOGGLE_SENSITIVITY(checkbtn_folder_chmod, entry_folder_chmod);
419         if (item->prefs->folder_chmod) {
420                 gchar *buf;
421
422                 buf = g_strdup_printf("%o", item->prefs->folder_chmod);
423                 gtk_entry_set_text(GTK_ENTRY(entry_folder_chmod), buf);
424                 g_free(buf);
425         }
426         
427         rowcount++;
428
429         /* Default account */
430         checkbtn_enable_default_account = gtk_check_button_new_with_label(_("Default account: "));
431         gtk_widget_show(checkbtn_enable_default_account);
432         gtk_table_attach(GTK_TABLE(table), checkbtn_enable_default_account, 0, 1, 
433                          rowcount, rowcount + 1, GTK_SHRINK | GTK_FILL, GTK_SHRINK, 0, 0);
434         gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(checkbtn_enable_default_account), 
435                                      item->prefs->enable_default_account);
436
437         optmenu_default_account = gtk_option_menu_new ();
438         gtk_widget_show (optmenu_default_account);
439         gtk_table_attach_defaults(GTK_TABLE(table), optmenu_default_account, 1, 2, 
440                                   rowcount, rowcount + 1);
441         optmenu_default_account_menu = gtk_menu_new ();
442
443         account_list = account_get_list();
444         account_index = 0;
445         index = 0;
446         for (cur_ac = account_list; cur_ac != NULL; cur_ac = cur_ac->next) {
447                 ac_prefs = (PrefsAccount *)cur_ac->data;
448                 MENUITEM_ADD (optmenu_default_account_menu, optmenu_default_account_menuitem,
449                                         ac_prefs->account_name?ac_prefs->account_name : _("Untitled"),
450                                         ac_prefs->account_id);
451                 /* get the index for menu's set_history (sad method?) */
452                 if (ac_prefs->account_id == item->prefs->default_account)
453                         account_index = index;
454                 index++;                        
455         }
456
457         dialog->item->prefs->default_account = item->prefs->default_account;
458
459         optmenu=GTK_OPTION_MENU(optmenu_default_account);
460         gtk_option_menu_set_menu(optmenu, optmenu_default_account_menu);
461
462         gtk_option_menu_set_history(optmenu, account_index);
463
464         menu = gtk_option_menu_get_menu(optmenu);
465         menuitem = gtk_menu_get_active(GTK_MENU(menu));
466         gtk_menu_item_activate(GTK_MENU_ITEM(menuitem));
467
468         SET_TOGGLE_SENSITIVITY(checkbtn_enable_default_account, optmenu_default_account);
469
470         rowcount++;
471
472         /* Folder color */
473         folder_color = gtk_label_new(_("Folder color: "));
474         gtk_misc_set_alignment(GTK_MISC(folder_color), 0, 0.5);
475         gtk_widget_show(folder_color);
476         gtk_table_attach_defaults(GTK_TABLE(table), folder_color, 0, 1, 
477                          rowcount, rowcount + 1);
478
479         folder_color_btn = gtk_button_new_with_label("");
480         gtk_widget_set_usize(folder_color_btn, 36, 26);
481         gtk_container_set_border_width(GTK_CONTAINER(folder_color_btn), 2);
482         gtk_widget_show(folder_color_btn);
483         gtk_table_attach(GTK_TABLE(table), folder_color_btn,
484                          1, 2, rowcount, rowcount + 1,
485                          GTK_SHRINK, 0, 0, 0);
486
487         dialog->item->prefs->color = item->prefs->color;
488
489         gtk_signal_connect(GTK_OBJECT(folder_color_btn), "clicked",
490                            GTK_SIGNAL_FUNC(folder_color_set_dialog),
491                            dialog);
492
493         set_button_color(item->prefs->color, folder_color_btn);
494
495         rowcount++;
496
497         /* Ok and Cancle Buttons */
498         gtkut_button_set_create(&confirm_area, &ok_btn, _("OK"),
499                                 &cancel_btn, _("Cancel"), NULL, NULL);
500         gtk_widget_show(confirm_area);
501         gtk_table_attach_defaults(GTK_TABLE(table), confirm_area, 0, 2, 
502                                   rowcount, rowcount + 1);
503         gtk_widget_grab_default(ok_btn);
504         gtk_signal_connect (GTK_OBJECT(ok_btn), "clicked",
505                             GTK_SIGNAL_FUNC(prefs_folder_item_ok_cb), dialog);
506         gtk_signal_connect (GTK_OBJECT(cancel_btn), "clicked",
507                             GTK_SIGNAL_FUNC(prefs_folder_item_cancel_cb), dialog);
508
509         dialog->window = window;
510         dialog->checkbtn_request_return_receipt = checkbtn_request_return_receipt;
511         dialog->checkbtn_save_copy_to_folder = checkbtn_save_copy_to_folder;
512         dialog->checkbtn_default_to = checkbtn_default_to;
513         dialog->entry_default_to = entry_default_to;
514         dialog->checkbtn_default_reply_to = checkbtn_default_reply_to;
515         dialog->entry_default_reply_to = entry_default_reply_to;
516         dialog->checkbtn_simplify_subject = checkbtn_simplify_subject;
517         dialog->entry_simplify_subject = entry_simplify_subject;
518         dialog->checkbtn_folder_chmod = checkbtn_folder_chmod;
519         dialog->entry_folder_chmod = entry_folder_chmod;
520         dialog->checkbtn_enable_default_account = checkbtn_enable_default_account;
521         dialog->optmenu_default_account = optmenu_default_account;
522         dialog->folder_color = folder_color;
523         dialog->folder_color_btn = folder_color_btn;
524
525         g_free(infotext);
526
527         address_completion_start(window);
528
529         gtk_widget_show(window);
530 }
531
532 void prefs_folder_item_destroy(struct PrefsFolderItemDialog *dialog) 
533 {
534         address_completion_unregister_entry(GTK_ENTRY(dialog->entry_default_to));
535         address_completion_unregister_entry(GTK_ENTRY(dialog->entry_default_reply_to));
536         address_completion_end(dialog->window);
537         gtk_widget_destroy(dialog->window);
538         g_free(dialog);
539 }
540
541 void prefs_folder_item_cancel_cb(GtkWidget *widget, 
542                                  struct PrefsFolderItemDialog *dialog) 
543 {
544         prefs_folder_item_destroy(dialog);
545 }
546
547 void prefs_folder_item_delete_cb(GtkWidget *widget, GdkEventAny *event, 
548                                  struct PrefsFolderItemDialog *dialog) 
549 {
550         prefs_folder_item_destroy(dialog);
551 }
552
553 void prefs_folder_item_ok_cb(GtkWidget *widget, 
554                              struct PrefsFolderItemDialog *dialog) 
555 {
556         gchar *buf;
557         PrefsFolderItem *prefs = dialog->item->prefs;
558         GtkWidget *menu;
559         GtkWidget *menuitem;
560         gboolean   old_simplify_val;
561         gchar     *old_simplify_str;
562
563         g_return_if_fail(prefs != NULL);
564
565         old_simplify_val = prefs->enable_simplify_subject;
566         old_simplify_str = prefs->simplify_subject_regexp;
567
568         prefs->request_return_receipt = 
569             gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(dialog->checkbtn_request_return_receipt));
570         /* MIGRATION */    
571         dialog->item->ret_rcpt = prefs->request_return_receipt;
572
573         prefs->save_copy_to_folder = 
574             gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(dialog->checkbtn_save_copy_to_folder));
575
576         prefs->enable_default_to = 
577             gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(dialog->checkbtn_default_to));
578         g_free(prefs->default_to);
579         prefs->default_to = 
580             gtk_editable_get_chars(GTK_EDITABLE(dialog->entry_default_to), 0, -1);
581
582         prefs->enable_default_reply_to = 
583             gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(dialog->checkbtn_default_reply_to));
584         g_free(prefs->default_reply_to);
585         prefs->default_reply_to = 
586             gtk_editable_get_chars(GTK_EDITABLE(dialog->entry_default_reply_to), 0, -1);
587
588         prefs->enable_simplify_subject =
589             gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(dialog->checkbtn_simplify_subject));
590         prefs->simplify_subject_regexp = 
591             gtk_editable_get_chars(GTK_EDITABLE(dialog->entry_simplify_subject), 0, -1);
592         
593         if (dialog->item == dialog->folderview->summaryview->folder_item &&
594             (prefs->enable_simplify_subject != old_simplify_val ||  
595             0 != strcmp2(prefs->simplify_subject_regexp, old_simplify_str))) 
596                 summary_show(dialog->folderview->summaryview, dialog->item);
597                 
598         if (old_simplify_str) g_free(old_simplify_str);
599
600         prefs->enable_folder_chmod = 
601             gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(dialog->checkbtn_folder_chmod));
602         buf = gtk_editable_get_chars(GTK_EDITABLE(dialog->entry_folder_chmod), 0, -1);
603         prefs->folder_chmod = prefs_folder_item_chmod_mode(buf);
604         g_free(buf);
605
606         prefs->enable_default_account = 
607             gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(dialog->checkbtn_enable_default_account));
608         menu = gtk_option_menu_get_menu(GTK_OPTION_MENU(dialog->optmenu_default_account));
609         menuitem = gtk_menu_get_active(GTK_MENU(menu));
610         prefs->default_account = GPOINTER_TO_INT(gtk_object_get_user_data(GTK_OBJECT(menuitem)));
611
612         prefs->color = dialog->item->prefs->color;
613         /* update folder view */
614         if (prefs->color > 0)
615                 folderview_update_item(dialog->item, FALSE);
616
617         prefs_folder_item_save_config(dialog->item);
618         prefs_folder_item_destroy(dialog);
619 }
620
621 gint prefs_folder_item_chmod_mode(gchar *folder_chmod) 
622 {
623         gint newmode = 0;
624         gchar *tmp;
625
626         if (folder_chmod) {
627                 newmode = strtol(folder_chmod, &tmp, 8);
628                 if (!(*(folder_chmod) && !(*tmp)))
629                         newmode = 0;
630         }
631
632         return newmode;
633 }
634
635 static void set_button_color(guint rgbvalue, GtkWidget *button)
636 {
637         GtkStyle *newstyle;
638         GdkColor gdk_color;
639
640         gtkut_convert_int_to_gdk_color(rgbvalue, &gdk_color);
641         newstyle = gtk_style_copy(gtk_widget_get_default_style());
642         newstyle->bg[GTK_STATE_NORMAL]   = gdk_color;
643         newstyle->bg[GTK_STATE_PRELIGHT] = gdk_color;
644         newstyle->bg[GTK_STATE_ACTIVE]   = gdk_color;
645         gtk_widget_set_style(GTK_WIDGET(button), newstyle);
646 }
647
648 static void folder_color_set_dialog(GtkWidget *widget, gpointer data)
649 {
650         struct PrefsFolderItemDialog *folder_dialog = data;
651         GtkColorSelectionDialog *dialog;
652         gdouble color[4] = {0.0, 0.0, 0.0, 0.0};
653         guint rgbcolor;
654
655         color_dialog = gtk_color_selection_dialog_new(_("Pick color for folder"));
656         gtk_window_set_position(GTK_WINDOW(color_dialog), GTK_WIN_POS_CENTER);
657         gtk_window_set_modal(GTK_WINDOW(color_dialog), TRUE);
658         gtk_window_set_policy(GTK_WINDOW(color_dialog), FALSE, FALSE, FALSE);
659         manage_window_set_transient(GTK_WINDOW(color_dialog));
660
661         gtk_signal_connect(GTK_OBJECT(GTK_COLOR_SELECTION_DIALOG(color_dialog)->ok_button),
662                            "clicked", GTK_SIGNAL_FUNC(folder_color_set_dialog_ok), data);
663         gtk_signal_connect(GTK_OBJECT(GTK_COLOR_SELECTION_DIALOG(color_dialog)->cancel_button),
664                            "clicked", GTK_SIGNAL_FUNC(folder_color_set_dialog_cancel), data);
665         gtk_signal_connect(GTK_OBJECT(color_dialog), "key_press_event",
666                            GTK_SIGNAL_FUNC(folder_color_set_dialog_key_pressed),
667                            data);
668
669         rgbcolor = folder_dialog->item->prefs->color;
670         color[0] = (gdouble) ((rgbcolor & 0xff0000) >> 16) / 255.0;
671         color[1] = (gdouble) ((rgbcolor & 0x00ff00) >>  8) / 255.0;
672         color[2] = (gdouble)  (rgbcolor & 0x0000ff)        / 255.0;
673
674         dialog = GTK_COLOR_SELECTION_DIALOG(color_dialog);
675         gtk_color_selection_set_color(GTK_COLOR_SELECTION(dialog->colorsel), color);
676
677         gtk_widget_show(color_dialog);
678 }
679
680 static void folder_color_set_dialog_ok(GtkWidget *widget, gpointer data)
681 {
682         struct PrefsFolderItemDialog *folder_dialog = data;
683         GtkColorSelection *colorsel = (GtkColorSelection *)
684                                 ((GtkColorSelectionDialog *) color_dialog)->colorsel;
685         gdouble color[4];
686         guint red, green, blue, rgbvalue;
687
688         gtk_color_selection_get_color(colorsel, color);
689
690         red      = (guint) (color[0] * 255.0);
691         green    = (guint) (color[1] * 255.0);
692         blue     = (guint) (color[2] * 255.0);
693         rgbvalue = (guint) ((red * 0x10000) | (green * 0x100) | blue);
694
695         folder_dialog->item->prefs->color = rgbvalue;
696         set_button_color(rgbvalue, folder_dialog->folder_color_btn);
697
698         gtk_widget_destroy(color_dialog);
699 }
700
701 static void folder_color_set_dialog_cancel(GtkWidget *widget, gpointer data)
702 {
703         gtk_widget_destroy(color_dialog);
704 }
705
706 static void folder_color_set_dialog_key_pressed(GtkWidget *widget,
707                                                 GdkEventKey *event,
708                                                 gpointer data)
709 {
710         gtk_widget_destroy(color_dialog);
711 }
712