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