45ff47628291edeb2743856843d79577dd3264a6
[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_gtk.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 #include "filtering.h"
43 #include "folder_item_prefs.h"
44
45 struct FolderItemGeneralPage
46 {
47         PrefsPage page;
48
49         FolderItem *item;
50
51         GtkWidget *table;
52         GtkWidget *checkbtn_simplify_subject;
53         GtkWidget *entry_simplify_subject;
54         GtkWidget *checkbtn_folder_chmod;
55         GtkWidget *entry_folder_chmod;
56         GtkWidget *folder_color;
57         GtkWidget *folder_color_btn;
58
59         GtkWidget *color_dialog;
60 };
61
62 struct FolderItemComposePage
63 {
64         PrefsPage page;
65
66         FolderItem *item;
67
68         GtkWidget *window;
69         GtkWidget *table;
70         GtkWidget *checkbtn_request_return_receipt;
71         GtkWidget *checkbtn_save_copy_to_folder;
72         GtkWidget *checkbtn_default_to;
73         GtkWidget *entry_default_to;
74         GtkWidget *checkbtn_default_reply_to;
75         GtkWidget *entry_default_reply_to;
76         GtkWidget *checkbtn_enable_default_account;
77         GtkWidget *optmenu_default_account;
78 };
79
80
81 gint prefs_folder_item_chmod_mode               (gchar *folder_chmod);
82
83 static void set_button_color(guint rgbvalue, GtkWidget *button);
84 static void folder_color_set_dialog(GtkWidget *widget, gpointer data);
85 static void folder_color_set_dialog_ok(GtkWidget *widget, gpointer data);
86 static void folder_color_set_dialog_cancel(GtkWidget *widget, gpointer data);
87 static void folder_color_set_dialog_key_pressed(GtkWidget *widget,
88                                                 GdkEventKey *event,
89                                                 gpointer data);
90
91 #define SAFE_STRING(str) \
92         (str) ? (str) : ""
93
94 void prefs_folder_item_general_create_widget_func(PrefsPage * _page,
95                                                    GtkWindow * window,
96                                                    gpointer data)
97 {
98         struct FolderItemGeneralPage *page = (struct FolderItemGeneralPage *) _page;
99         FolderItem *item = (FolderItem *) data;
100         guint rowcount;
101
102         GtkWidget *table;
103         GtkWidget *hbox;
104         
105         GtkWidget *checkbtn_simplify_subject;
106         GtkWidget *entry_simplify_subject;
107         GtkWidget *checkbtn_folder_chmod;
108         GtkWidget *entry_folder_chmod;
109         GtkWidget *folder_color;
110         GtkWidget *folder_color_btn;
111         GtkWidget *menu;
112         GtkWidget *menuitem;
113         gint account_index, index;
114
115         page->item         = item;
116
117         /* Table */
118         table = gtk_table_new(3, 2, FALSE);
119         gtk_widget_show(table);
120         gtk_table_set_row_spacings(GTK_TABLE(table), -1);
121         rowcount = 0;
122
123         /* Simplify Subject */
124         checkbtn_simplify_subject = gtk_check_button_new_with_label(_("Simplify Subject RegExp: "));
125         gtk_widget_show(checkbtn_simplify_subject);
126         gtk_table_attach(GTK_TABLE(table), checkbtn_simplify_subject, 0, 1, 
127                          rowcount, rowcount + 1, GTK_SHRINK | GTK_FILL, GTK_SHRINK, 0, 0);
128         gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(checkbtn_simplify_subject), 
129                                      item->prefs->enable_simplify_subject);
130
131         entry_simplify_subject = gtk_entry_new();
132         gtk_widget_show(entry_simplify_subject);
133         gtk_table_attach_defaults(GTK_TABLE(table), entry_simplify_subject, 1, 2, 
134                                   rowcount, rowcount + 1);
135         SET_TOGGLE_SENSITIVITY(checkbtn_simplify_subject, entry_simplify_subject);
136         gtk_entry_set_text(GTK_ENTRY(entry_simplify_subject), 
137                            SAFE_STRING(item->prefs->simplify_subject_regexp));
138
139         rowcount++;
140
141         /* Folder chmod */
142         checkbtn_folder_chmod = gtk_check_button_new_with_label(_("Folder chmod: "));
143         gtk_widget_show(checkbtn_folder_chmod);
144         gtk_table_attach(GTK_TABLE(table), checkbtn_folder_chmod, 0, 1, 
145                          rowcount, rowcount + 1, GTK_SHRINK | GTK_FILL, GTK_SHRINK, 0, 0);
146
147         gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(checkbtn_folder_chmod), 
148                                      item->prefs->enable_folder_chmod);
149
150         entry_folder_chmod = gtk_entry_new();
151         gtk_widget_show(entry_folder_chmod);
152         gtk_table_attach_defaults(GTK_TABLE(table), entry_folder_chmod, 1, 2, 
153                                   rowcount, rowcount + 1);
154         SET_TOGGLE_SENSITIVITY(checkbtn_folder_chmod, entry_folder_chmod);
155         if (item->prefs->folder_chmod) {
156                 gchar *buf;
157
158                 buf = g_strdup_printf("%o", item->prefs->folder_chmod);
159                 gtk_entry_set_text(GTK_ENTRY(entry_folder_chmod), buf);
160                 g_free(buf);
161         }
162         
163         rowcount++;
164
165         /* Folder color */
166         folder_color = gtk_label_new(_("Folder color: "));
167         gtk_misc_set_alignment(GTK_MISC(folder_color), 0, 0.5);
168         gtk_widget_show(folder_color);
169         gtk_table_attach_defaults(GTK_TABLE(table), folder_color, 0, 1, 
170                          rowcount, rowcount + 1);
171
172         hbox = gtk_hbox_new (FALSE, 0);
173         gtk_widget_show (hbox);
174         gtk_table_attach_defaults(GTK_TABLE(table), hbox, 1, 2, 
175                                   rowcount, rowcount + 1);
176
177         folder_color_btn = gtk_button_new_with_label("");
178         gtk_widget_show (hbox);
179         gtk_widget_set_usize(folder_color_btn, 36, 26);
180         gtk_box_pack_start (GTK_BOX (hbox), folder_color_btn, FALSE, FALSE, 0);
181
182         page->item->prefs->color = item->prefs->color;
183
184         gtk_signal_connect(GTK_OBJECT(folder_color_btn), "clicked",
185                            GTK_SIGNAL_FUNC(folder_color_set_dialog),
186                            page);
187
188         set_button_color(item->prefs->color, folder_color_btn);
189
190         rowcount++;
191
192         page->table = table;
193         page->checkbtn_simplify_subject = checkbtn_simplify_subject;
194         page->entry_simplify_subject = entry_simplify_subject;
195         page->checkbtn_folder_chmod = checkbtn_folder_chmod;
196         page->entry_folder_chmod = entry_folder_chmod;
197         page->folder_color = folder_color;
198         page->folder_color_btn = folder_color_btn;
199
200         page->page.widget = table;
201 }
202
203 void prefs_folder_item_general_destroy_widget_func(PrefsPage *_page) 
204 {
205         struct FolderItemGeneralPage *page = (struct FolderItemGeneralPage *) _page;
206 }
207
208 void prefs_folder_item_general_save_func(PrefsPage *_page) 
209 {
210         gchar *buf;
211         struct FolderItemGeneralPage *page = (struct FolderItemGeneralPage *) _page;
212         FolderItemPrefs *prefs = page->item->prefs;
213         GtkWidget *menu;
214         GtkWidget *menuitem;
215         gboolean   old_simplify_val;
216         gchar     *old_simplify_str;
217
218         g_return_if_fail(prefs != NULL);
219
220         old_simplify_val = prefs->enable_simplify_subject;
221         old_simplify_str = prefs->simplify_subject_regexp;
222
223         prefs->enable_simplify_subject =
224             gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(page->checkbtn_simplify_subject));
225         prefs->simplify_subject_regexp = 
226             gtk_editable_get_chars(GTK_EDITABLE(page->entry_simplify_subject), 0, -1);
227         
228 /*
229         if (page->item == page->folderview->summaryview->folder_item &&
230             (prefs->enable_simplify_subject != old_simplify_val ||  
231             0 != strcmp2(prefs->simplify_subject_regexp, old_simplify_str))) {
232                 summary_clear_all(page->folderview->summaryview);
233                 page->folderview->opened = NULL;
234                 page->folderview->selected = NULL;
235                 folderview_select(page->folderview, page->item);
236         }
237 */
238         if (old_simplify_str) g_free(old_simplify_str);
239
240         prefs->enable_folder_chmod = 
241             gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(page->checkbtn_folder_chmod));
242         buf = gtk_editable_get_chars(GTK_EDITABLE(page->entry_folder_chmod), 0, -1);
243         prefs->folder_chmod = prefs_folder_item_chmod_mode(buf);
244         g_free(buf);
245
246         prefs->color = page->item->prefs->color;
247         /* update folder view */
248         if (prefs->color > 0)
249                 folder_item_update(page->item, F_ITEM_UPDATE_MSGCNT);
250
251         folder_item_prefs_save_config(page->item);
252 }
253
254 void prefs_folder_item_compose_create_widget_func(PrefsPage * _page,
255                                                    GtkWindow * window,
256                                                    gpointer data)
257 {
258         struct FolderItemComposePage *page = (struct FolderItemComposePage *) _page;
259         FolderItem *item = (FolderItem *) data;
260         guint rowcount;
261
262         GtkWidget *table;
263         
264         GtkWidget *checkbtn_request_return_receipt;
265         GtkWidget *checkbtn_save_copy_to_folder;
266         GtkWidget *checkbtn_default_to;
267         GtkWidget *entry_default_to;
268         GtkWidget *checkbtn_default_reply_to;
269         GtkWidget *entry_default_reply_to;
270         GtkWidget *checkbtn_enable_default_account;
271         GtkWidget *optmenu_default_account;
272         GtkWidget *optmenu_default_account_menu;
273         GtkWidget *optmenu_default_account_menuitem;
274         GList *cur_ac;
275         GList *account_list;
276         PrefsAccount *ac_prefs;
277         GtkOptionMenu *optmenu;
278         GtkWidget *menu;
279         GtkWidget *menuitem;
280         gint account_index, index;
281
282         page->item         = item;
283
284         /* Table */
285         table = gtk_table_new(5, 2, FALSE);
286         gtk_widget_show(table);
287         gtk_table_set_row_spacings(GTK_TABLE(table), -1);
288         rowcount = 0;
289
290         /* Request Return Receipt */
291         checkbtn_request_return_receipt = gtk_check_button_new_with_label
292                 (_("Request Return Receipt"));
293         gtk_widget_show(checkbtn_request_return_receipt);
294         gtk_table_attach(GTK_TABLE(table), checkbtn_request_return_receipt, 
295                          0, 2, rowcount, rowcount + 1, GTK_SHRINK | GTK_FILL, 
296                          GTK_FILL, 0, 0);
297         gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(checkbtn_request_return_receipt),
298                                      item->ret_rcpt ? TRUE : FALSE);
299
300         rowcount++;
301
302         /* Save Copy to Folder */
303         checkbtn_save_copy_to_folder = gtk_check_button_new_with_label
304                 (_("Save copy of outgoing messages to this folder instead of Sent"));
305         gtk_widget_show(checkbtn_save_copy_to_folder);
306         gtk_table_attach(GTK_TABLE(table), checkbtn_save_copy_to_folder, 0, 2, 
307                          rowcount, rowcount + 1, GTK_SHRINK | GTK_FILL, GTK_FILL, 0, 0);
308         gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(checkbtn_save_copy_to_folder),
309                                      item->prefs->save_copy_to_folder ? TRUE : FALSE);
310
311         rowcount++;
312
313         /* Default To */
314         checkbtn_default_to = gtk_check_button_new_with_label(_("Default To: "));
315         gtk_widget_show(checkbtn_default_to);
316         gtk_table_attach(GTK_TABLE(table), checkbtn_default_to, 0, 1, 
317                          rowcount, rowcount + 1, GTK_SHRINK | GTK_FILL, GTK_SHRINK, 0, 0);
318         gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(checkbtn_default_to), 
319                                      item->prefs->enable_default_to);
320
321         entry_default_to = gtk_entry_new();
322         gtk_widget_show(entry_default_to);
323         gtk_table_attach_defaults(GTK_TABLE(table), entry_default_to, 1, 2, rowcount, rowcount + 1);
324         SET_TOGGLE_SENSITIVITY(checkbtn_default_to, entry_default_to);
325         gtk_entry_set_text(GTK_ENTRY(entry_default_to), SAFE_STRING(item->prefs->default_to));
326         address_completion_register_entry(GTK_ENTRY(entry_default_to));
327
328         rowcount++;
329
330         /* Default address to reply to */
331         checkbtn_default_reply_to = gtk_check_button_new_with_label(_("Send replies to: "));
332         gtk_widget_show(checkbtn_default_reply_to);
333         gtk_table_attach(GTK_TABLE(table), checkbtn_default_reply_to, 0, 1, 
334                          rowcount, rowcount + 1, GTK_SHRINK | GTK_FILL, GTK_SHRINK, 0, 0);
335         gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(checkbtn_default_reply_to), 
336                                      item->prefs->enable_default_reply_to);
337
338         entry_default_reply_to = gtk_entry_new();
339         gtk_widget_show(entry_default_reply_to);
340         gtk_table_attach_defaults(GTK_TABLE(table), entry_default_reply_to, 1, 2, rowcount, rowcount + 1);
341         SET_TOGGLE_SENSITIVITY(checkbtn_default_reply_to, entry_default_reply_to);
342         gtk_entry_set_text(GTK_ENTRY(entry_default_reply_to), SAFE_STRING(item->prefs->default_reply_to));
343         address_completion_register_entry(GTK_ENTRY(entry_default_reply_to));
344
345         rowcount++;
346
347         /* Default account */
348         checkbtn_enable_default_account = gtk_check_button_new_with_label(_("Default account: "));
349         gtk_widget_show(checkbtn_enable_default_account);
350         gtk_table_attach(GTK_TABLE(table), checkbtn_enable_default_account, 0, 1, 
351                          rowcount, rowcount + 1, GTK_SHRINK | GTK_FILL, GTK_SHRINK, 0, 0);
352         gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(checkbtn_enable_default_account), 
353                                      item->prefs->enable_default_account);
354
355         optmenu_default_account = gtk_option_menu_new ();
356         gtk_widget_show (optmenu_default_account);
357         gtk_table_attach_defaults(GTK_TABLE(table), optmenu_default_account, 1, 2, 
358                                   rowcount, rowcount + 1);
359         optmenu_default_account_menu = gtk_menu_new ();
360
361         account_list = account_get_list();
362         account_index = 0;
363         index = 0;
364         for (cur_ac = account_list; cur_ac != NULL; cur_ac = cur_ac->next) {
365                 ac_prefs = (PrefsAccount *)cur_ac->data;
366                 MENUITEM_ADD (optmenu_default_account_menu, optmenu_default_account_menuitem,
367                                         ac_prefs->account_name?ac_prefs->account_name : _("Untitled"),
368                                         ac_prefs->account_id);
369                 /* get the index for menu's set_history (sad method?) */
370                 if (ac_prefs->account_id == item->prefs->default_account)
371                         account_index = index;
372                 index++;                        
373         }
374
375         page->item->prefs->default_account = item->prefs->default_account;
376
377         optmenu = GTK_OPTION_MENU(optmenu_default_account);
378         gtk_option_menu_set_menu(optmenu, optmenu_default_account_menu);
379
380         gtk_option_menu_set_history(optmenu, account_index);
381
382         menu = gtk_option_menu_get_menu(optmenu);
383         menuitem = gtk_menu_get_active(GTK_MENU(menu));
384         gtk_menu_item_activate(GTK_MENU_ITEM(menuitem));
385
386         SET_TOGGLE_SENSITIVITY(checkbtn_enable_default_account, optmenu_default_account);
387
388         rowcount++;
389
390         page->window = GTK_WIDGET(window);
391         page->table = table;
392         page->checkbtn_request_return_receipt = checkbtn_request_return_receipt;
393         page->checkbtn_save_copy_to_folder = checkbtn_save_copy_to_folder;
394         page->checkbtn_default_to = checkbtn_default_to;
395         page->entry_default_to = entry_default_to;
396         page->checkbtn_default_reply_to = checkbtn_default_reply_to;
397         page->entry_default_reply_to = entry_default_reply_to;
398         page->checkbtn_enable_default_account = checkbtn_enable_default_account;
399         page->optmenu_default_account = optmenu_default_account;
400
401         address_completion_start(page->window);
402
403         page->page.widget = table;
404 }
405
406 void prefs_folder_item_compose_destroy_widget_func(PrefsPage *_page) 
407 {
408         struct FolderItemComposePage *page = (struct FolderItemComposePage *) _page;
409
410         address_completion_unregister_entry(GTK_ENTRY(page->entry_default_to));
411         address_completion_unregister_entry(GTK_ENTRY(page->entry_default_reply_to));
412         address_completion_end(page->window);
413 }
414
415 void prefs_folder_item_compose_save_func(PrefsPage *_page) 
416 {
417         gchar *buf;
418         struct FolderItemComposePage *page = (struct FolderItemComposePage *) _page;
419         FolderItemPrefs *prefs = page->item->prefs;
420         GtkWidget *menu;
421         GtkWidget *menuitem;
422
423         g_return_if_fail(prefs != NULL);
424
425         prefs->request_return_receipt = 
426             gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(page->checkbtn_request_return_receipt));
427         /* MIGRATION */    
428         page->item->ret_rcpt = prefs->request_return_receipt;
429
430         prefs->save_copy_to_folder = 
431             gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(page->checkbtn_save_copy_to_folder));
432
433         prefs->enable_default_to = 
434             gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(page->checkbtn_default_to));
435         g_free(prefs->default_to);
436         prefs->default_to = 
437             gtk_editable_get_chars(GTK_EDITABLE(page->entry_default_to), 0, -1);
438
439         prefs->enable_default_reply_to = 
440             gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(page->checkbtn_default_reply_to));
441         g_free(prefs->default_reply_to);
442         prefs->default_reply_to = 
443             gtk_editable_get_chars(GTK_EDITABLE(page->entry_default_reply_to), 0, -1);
444
445         prefs->enable_default_account = 
446             gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(page->checkbtn_enable_default_account));
447         menu = gtk_option_menu_get_menu(GTK_OPTION_MENU(page->optmenu_default_account));
448         menuitem = gtk_menu_get_active(GTK_MENU(menu));
449         prefs->default_account = GPOINTER_TO_INT(gtk_object_get_user_data(GTK_OBJECT(menuitem)));
450
451         folder_item_prefs_save_config(page->item);
452 }
453
454 gint prefs_folder_item_chmod_mode(gchar *folder_chmod) 
455 {
456         gint newmode = 0;
457         gchar *tmp;
458
459         if (folder_chmod) {
460                 newmode = strtol(folder_chmod, &tmp, 8);
461                 if (!(*(folder_chmod) && !(*tmp)))
462                         newmode = 0;
463         }
464
465         return newmode;
466 }
467
468 static void set_button_color(guint rgbvalue, GtkWidget *button)
469 {
470         GtkStyle *newstyle;
471         GdkColor gdk_color;
472
473         gtkut_convert_int_to_gdk_color(rgbvalue, &gdk_color);
474         newstyle = gtk_style_copy(gtk_widget_get_default_style());
475         newstyle->bg[GTK_STATE_NORMAL]   = gdk_color;
476         newstyle->bg[GTK_STATE_PRELIGHT] = gdk_color;
477         newstyle->bg[GTK_STATE_ACTIVE]   = gdk_color;
478         gtk_widget_set_style(GTK_WIDGET(button), newstyle);
479 }
480
481 static void folder_color_set_dialog(GtkWidget *widget, gpointer data)
482 {
483         struct FolderItemGeneralPage *page = (struct FolderItemGeneralPage *) data;
484         GtkColorSelectionDialog *dialog;
485         gdouble color[4] = {0.0, 0.0, 0.0, 0.0};
486         guint rgbcolor;
487
488         page->color_dialog = gtk_color_selection_dialog_new(_("Pick color for folder"));
489         gtk_window_set_position(GTK_WINDOW(page->color_dialog), GTK_WIN_POS_CENTER);
490         gtk_window_set_modal(GTK_WINDOW(page->color_dialog), TRUE);
491         gtk_window_set_policy(GTK_WINDOW(page->color_dialog), FALSE, FALSE, FALSE);
492         manage_window_set_transient(GTK_WINDOW(page->color_dialog));
493
494         gtk_signal_connect(GTK_OBJECT(GTK_COLOR_SELECTION_DIALOG(page->color_dialog)->ok_button),
495                            "clicked", GTK_SIGNAL_FUNC(folder_color_set_dialog_ok), data);
496         gtk_signal_connect(GTK_OBJECT(GTK_COLOR_SELECTION_DIALOG(page->color_dialog)->cancel_button),
497                            "clicked", GTK_SIGNAL_FUNC(folder_color_set_dialog_cancel), data);
498         gtk_signal_connect(GTK_OBJECT(page->color_dialog), "key_press_event",
499                            GTK_SIGNAL_FUNC(folder_color_set_dialog_key_pressed),
500                            data);
501
502         rgbcolor = page->item->prefs->color;
503         color[0] = (gdouble) ((rgbcolor & 0xff0000) >> 16) / 255.0;
504         color[1] = (gdouble) ((rgbcolor & 0x00ff00) >>  8) / 255.0;
505         color[2] = (gdouble)  (rgbcolor & 0x0000ff)        / 255.0;
506
507         dialog = GTK_COLOR_SELECTION_DIALOG(page->color_dialog);
508         gtk_color_selection_set_color(GTK_COLOR_SELECTION(dialog->colorsel), color);
509
510         gtk_widget_show(page->color_dialog);
511 }
512
513 static void folder_color_set_dialog_ok(GtkWidget *widget, gpointer data)
514 {
515         struct FolderItemGeneralPage *page = (struct FolderItemGeneralPage *) data;
516         GtkColorSelection *colorsel = (GtkColorSelection *)
517                                 ((GtkColorSelectionDialog *) page->color_dialog)->colorsel;
518         gdouble color[4];
519         guint red, green, blue, rgbvalue;
520
521         gtk_color_selection_get_color(colorsel, color);
522
523         red      = (guint) (color[0] * 255.0);
524         green    = (guint) (color[1] * 255.0);
525         blue     = (guint) (color[2] * 255.0);
526         rgbvalue = (guint) ((red * 0x10000) | (green * 0x100) | blue);
527
528         page->item->prefs->color = rgbvalue;
529         set_button_color(rgbvalue, page->folder_color_btn);
530
531         gtk_widget_destroy(page->color_dialog);
532 }
533
534 static void folder_color_set_dialog_cancel(GtkWidget *widget, gpointer data)
535 {
536         struct FolderItemGeneralPage *page = (struct FolderItemGeneralPage *) data;
537         gtk_widget_destroy(page->color_dialog);
538 }
539
540 static void folder_color_set_dialog_key_pressed(GtkWidget *widget,
541                                                 GdkEventKey *event,
542                                                 gpointer data)
543 {
544         struct FolderItemGeneralPage *page = (struct FolderItemGeneralPage *) data;
545         gtk_widget_destroy(page->color_dialog);
546 }
547
548 struct FolderItemGeneralPage folder_item_general_page;
549
550 static void register_general_page()
551 {
552         folder_item_general_page.page.path = _("General");
553         folder_item_general_page.page.create_widget = prefs_folder_item_general_create_widget_func;
554         folder_item_general_page.page.destroy_widget = prefs_folder_item_general_destroy_widget_func;
555         folder_item_general_page.page.save_page = prefs_folder_item_general_save_func;
556         
557         prefs_folder_item_register_page((PrefsPage *) &folder_item_general_page);
558 }
559
560 struct FolderItemComposePage folder_item_compose_page;
561
562 static void register_compose_page()
563 {
564         folder_item_compose_page.page.path = _("Compose");
565         folder_item_compose_page.page.create_widget = prefs_folder_item_compose_create_widget_func;
566         folder_item_compose_page.page.destroy_widget = prefs_folder_item_compose_destroy_widget_func;
567         folder_item_compose_page.page.save_page = prefs_folder_item_compose_save_func;
568         
569         prefs_folder_item_register_page((PrefsPage *) &folder_item_compose_page);
570 }
571
572 static GSList *prefs_pages = NULL;
573
574 void prefs_folder_item_open(FolderItem *item)
575 {
576         if (prefs_pages == NULL) {
577                 register_general_page();
578                 register_compose_page();
579         }
580
581         prefswindow_open(_("Settings for folder"), prefs_pages, item);
582 }
583
584 void prefs_folder_item_register_page(PrefsPage *page)
585 {
586         prefs_pages = g_slist_append(prefs_pages, page);
587 }
588
589 void prefs_folder_item_unregister_page(PrefsPage *page)
590 {
591         prefs_pages = g_slist_remove(prefs_pages, page);
592 }