2006-04-06 [mones] 2.1.0cvs7
[claws.git] / src / prefs_msg_colors.c
1 /*
2  * Sylpheed -- a GTK+ based, lightweight, and fast e-mail client
3  * Copyright (C) 2004-2006 Hiroyuki Yamamoto & The Sylpheed-Claws Team
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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18  */
19
20 #ifdef HAVE_CONFIG_H
21 #  include "config.h"
22 #endif
23
24 #include "defs.h"
25
26 #include <stdio.h>
27 #include <stdlib.h>
28
29 #include <glib.h>
30 #include <glib/gi18n.h>
31 #include <gtk/gtk.h>
32 #include <gdk/gdkkeysyms.h>
33
34 #include "prefs_common.h"
35 #include "prefs_gtk.h"
36
37 #include "gtk/gtkutils.h"
38 #include "gtk/prefswindow.h"
39
40 #include "manage_window.h"
41 #include "mainwindow.h"
42 #include "colorlabel.h"
43
44 #define SAFE_STRING(str) \
45         (str) ? (str) : ""
46
47 static struct MessageColorButtons {
48         GtkWidget *quote_level1_btn;
49         GtkWidget *quote_level2_btn;
50         GtkWidget *quote_level3_btn;
51         GtkWidget *uri_btn;
52         GtkWidget *tgt_folder_btn;
53         GtkWidget *signature_btn;
54         GtkWidget *color_new_btn;
55         /* custom colors */
56         GtkWidget *custom_color[COLORLABELS];
57 } color_buttons;
58
59 typedef struct _MsgColorsPage
60 {
61         PrefsPage page;
62
63         GtkWidget *window;
64         
65         GtkWidget *chkbtn_enablecol;
66         GtkWidget *chkbtn_recycle_colors;
67
68         /* custom colors */
69         GtkWidget *custom_colorlabel_entry[COLORLABELS];
70 } MsgColorsPage;
71
72 static GtkWidget *color_dialog;
73
74 static void quote_color_set_dialog              (GtkWidget      *widget,
75                                                  gpointer        data);
76 static void quote_colors_set_dialog_ok          (GtkWidget      *widget,
77                                                  gpointer        data);
78 static void quote_colors_set_dialog_cancel      (GtkWidget      *widget,
79                                                  gpointer        data);
80 static gboolean quote_colors_set_dialog_key_pressed     (GtkWidget      *widget,
81                                                  GdkEventKey    *event,
82                                                  gpointer        data);
83 static void set_button_bg_color                 (GtkWidget      *widget,
84                                                  gint            color);
85 static void prefs_msg_colors_reset_custom_colors(GtkWidget *widget,
86                                                  gpointer        data);
87
88 void prefs_msg_colors_create_widget(PrefsPage *_page, GtkWindow *window, 
89                                     gpointer data)
90 {
91         MsgColorsPage *prefs_msg_colors = (MsgColorsPage *) _page;
92         
93         GtkWidget *vbox1;
94         GtkWidget *vbox2;
95         GtkWidget *chkbtn_enablecol;
96         GtkWidget *quotelevel1_label;
97         GtkWidget *quotelevel2_label;
98         GtkWidget *quotelevel3_label;
99         GtkWidget *uri_label;
100         GtkWidget *signature_label;
101         GtkWidget *tgt_folder_label;
102         GtkWidget *chkbtn_recycle_colors;
103         GtkWidget *hbox;
104         GtkWidget *color_new_label;
105         GtkWidget *msg_frame;
106         GtkWidget *folder_frame;
107         /* custom colors */
108         GtkWidget *vbox_custom_colors;
109         GtkWidget *frame_custom_colors;
110         GtkWidget *hbox_reset_custom_colors;
111         GtkWidget *reset_custom_colors_btn;
112         GtkWidget *hbox_custom_color[COLORLABELS];
113         GtkWidget *custom_colorlabel_entry[COLORLABELS];
114         gint c;
115
116         vbox1 = gtk_vbox_new (FALSE, VSPACING_NARROW);
117         gtk_widget_show (vbox1);
118         gtk_container_set_border_width (GTK_CONTAINER (vbox1), VBOX_BORDER);
119
120         PACK_FRAME(vbox1, msg_frame, _("Message view"));
121
122         vbox2 = gtk_vbox_new (FALSE, VSPACING_NARROW);
123         gtk_widget_show (vbox2);
124         gtk_container_add (GTK_CONTAINER (msg_frame), vbox2);
125         gtk_container_set_border_width (GTK_CONTAINER (vbox2), VBOX_BORDER);
126
127         hbox = gtk_hbox_new(FALSE, 8);
128         gtk_widget_show (hbox);
129         gtk_box_pack_start (GTK_BOX (vbox2), hbox, FALSE, TRUE, 0);
130
131         PACK_CHECK_BUTTON (hbox, chkbtn_enablecol,
132                            _("Enable coloration of message text"));
133
134         hbox = gtk_hbox_new(FALSE, 8);
135         gtk_widget_show (hbox);
136         gtk_box_pack_start (GTK_BOX (vbox2), hbox, FALSE, TRUE, 0);
137
138         color_buttons.quote_level1_btn = gtk_button_new();
139         gtk_widget_show(color_buttons.quote_level1_btn);
140         gtk_widget_set_size_request (color_buttons.quote_level1_btn, 30, 20);
141         gtk_box_pack_start (GTK_BOX(hbox), color_buttons.quote_level1_btn, 
142                             FALSE, FALSE, 0);
143         SET_TOGGLE_SENSITIVITY(chkbtn_enablecol, color_buttons.quote_level1_btn);
144
145         quotelevel1_label = gtk_label_new (_("Quoted Text - First Level"));
146         gtk_widget_show(quotelevel1_label);
147         gtk_box_pack_start (GTK_BOX(hbox), quotelevel1_label, 
148                             FALSE, FALSE, 0);
149         SET_TOGGLE_SENSITIVITY(chkbtn_enablecol, quotelevel1_label);
150                 
151         hbox = gtk_hbox_new(FALSE, 8);
152         gtk_widget_show (hbox);
153         gtk_box_pack_start (GTK_BOX (vbox2), hbox, FALSE, TRUE, 0);
154
155         color_buttons.quote_level2_btn = gtk_button_new();
156         gtk_widget_show(color_buttons.quote_level2_btn);
157         gtk_widget_set_size_request (color_buttons.quote_level2_btn, 30, 20);
158         gtk_box_pack_start (GTK_BOX(hbox), color_buttons.quote_level2_btn, 
159                             FALSE, FALSE, 0);
160         SET_TOGGLE_SENSITIVITY(chkbtn_enablecol, color_buttons.quote_level2_btn);
161
162         quotelevel2_label = gtk_label_new (_("Quoted Text - Second Level"));
163         gtk_widget_show(quotelevel2_label);
164         gtk_box_pack_start (GTK_BOX(hbox), quotelevel2_label, 
165                             FALSE, FALSE, 0);
166         SET_TOGGLE_SENSITIVITY(chkbtn_enablecol, quotelevel2_label);
167
168         hbox = gtk_hbox_new(FALSE, 8);
169         gtk_widget_show (hbox);
170         gtk_box_pack_start (GTK_BOX (vbox2), hbox, FALSE, TRUE, 0);
171
172         color_buttons.quote_level3_btn = gtk_button_new();
173         gtk_widget_show(color_buttons.quote_level3_btn);
174         gtk_widget_set_size_request (color_buttons.quote_level3_btn, 30, 20);
175         gtk_box_pack_start (GTK_BOX(hbox), color_buttons.quote_level3_btn, 
176                             FALSE, FALSE, 0);
177         SET_TOGGLE_SENSITIVITY(chkbtn_enablecol, color_buttons.quote_level3_btn);
178
179         quotelevel3_label = gtk_label_new (_("Quoted Text - Third Level"));
180         gtk_widget_show(quotelevel3_label);
181         gtk_box_pack_start (GTK_BOX(hbox), quotelevel3_label, 
182                             FALSE, FALSE, 0);
183         SET_TOGGLE_SENSITIVITY(chkbtn_enablecol, quotelevel3_label);
184
185         hbox = gtk_hbox_new(FALSE, 8);
186         gtk_widget_show (hbox);
187         gtk_box_pack_start (GTK_BOX (vbox2), hbox, FALSE, TRUE, 0);
188
189         PACK_CHECK_BUTTON (hbox, chkbtn_recycle_colors,
190                            _("Cycle quote colors"));
191         SET_TOGGLE_SENSITIVITY(chkbtn_enablecol, chkbtn_recycle_colors);
192
193         hbox = gtk_hbox_new(FALSE, 8);
194         gtk_widget_show (hbox);
195         gtk_box_pack_start (GTK_BOX (vbox2), hbox, FALSE, TRUE, 0);
196
197         color_buttons.uri_btn = gtk_button_new();
198         gtk_widget_show(color_buttons.uri_btn);
199         gtk_widget_set_size_request (color_buttons.uri_btn, 30, 20);
200         gtk_box_pack_start (GTK_BOX(hbox), color_buttons.uri_btn, 
201                             FALSE, FALSE, 0);
202         SET_TOGGLE_SENSITIVITY(chkbtn_enablecol, color_buttons.uri_btn);
203
204         uri_label = gtk_label_new (_("URI link"));
205         gtk_widget_show(uri_label);
206         gtk_box_pack_start (GTK_BOX(hbox), uri_label, FALSE, FALSE, 0);
207         SET_TOGGLE_SENSITIVITY(chkbtn_enablecol, uri_label);
208
209         hbox = gtk_hbox_new(FALSE, 8);
210         gtk_widget_show (hbox);
211         gtk_box_pack_start (GTK_BOX (vbox2), hbox, FALSE, TRUE, 0);
212
213         color_buttons.signature_btn = gtk_button_new();
214         gtk_widget_show(color_buttons.signature_btn);
215         gtk_widget_set_size_request (color_buttons.signature_btn, 30, 20);
216         gtk_box_pack_start (GTK_BOX(hbox), color_buttons.signature_btn, 
217                             FALSE, FALSE, 0);
218         SET_TOGGLE_SENSITIVITY(chkbtn_enablecol, color_buttons.signature_btn);
219
220         signature_label = gtk_label_new (_("Signatures"));
221         gtk_widget_show(signature_label);
222         gtk_box_pack_start (GTK_BOX(hbox), signature_label, FALSE, FALSE, 0);
223         SET_TOGGLE_SENSITIVITY(chkbtn_enablecol, signature_label);
224
225         PACK_FRAME(vbox1, folder_frame, _("Folder list"));
226
227         vbox2 = gtk_vbox_new (FALSE, VSPACING_NARROW);
228         gtk_widget_show (vbox2);
229         gtk_container_add (GTK_CONTAINER (folder_frame), vbox2);
230         gtk_container_set_border_width (GTK_CONTAINER (vbox2), VBOX_BORDER);
231
232         hbox = gtk_hbox_new(FALSE, 8);
233         gtk_widget_show (hbox);
234         gtk_box_pack_start (GTK_BOX (vbox2), hbox, FALSE, TRUE, 0);
235
236         color_buttons.tgt_folder_btn = gtk_button_new();
237         gtk_widget_show(color_buttons.tgt_folder_btn);
238         gtk_widget_set_size_request (color_buttons.tgt_folder_btn, 30, 20);
239         gtk_box_pack_start (GTK_BOX(hbox), color_buttons.tgt_folder_btn, 
240                             FALSE, FALSE, 0);
241
242         tgt_folder_label = gtk_label_new (_("Target folder"));
243         gtk_widget_show(tgt_folder_label);
244         gtk_box_pack_start (GTK_BOX(hbox), tgt_folder_label, FALSE, FALSE, 0);
245
246         hbox = gtk_hbox_new(FALSE, 8);
247         gtk_widget_show (hbox);
248         gtk_box_pack_start (GTK_BOX (vbox2), hbox, FALSE, FALSE, 0);
249
250         color_buttons.color_new_btn = gtk_button_new();
251         gtk_widget_show (color_buttons.color_new_btn);
252         gtk_widget_set_size_request (color_buttons.color_new_btn, 30, 20);
253         gtk_box_pack_start (GTK_BOX(hbox), color_buttons.color_new_btn,
254                             FALSE, FALSE, 0);
255
256         color_new_label = gtk_label_new (_("Folder containing new messages"));
257         gtk_widget_show(color_new_label);
258         gtk_box_pack_start (GTK_BOX(hbox), color_new_label, FALSE, FALSE, 0);
259
260         /* custom colors */
261         PACK_FRAME (vbox1, frame_custom_colors, _("Color labels"));
262
263         vbox_custom_colors = gtk_vbox_new (FALSE, VSPACING_NARROW);
264         gtk_widget_show (vbox_custom_colors);
265         gtk_container_add (GTK_CONTAINER (frame_custom_colors), vbox_custom_colors);
266         gtk_container_set_border_width (GTK_CONTAINER (vbox_custom_colors), VBOX_BORDER);
267
268         for (c = 0; c < COLORLABELS; c++) {
269                 hbox_custom_color[c] = gtk_hbox_new(FALSE, 8);
270                 gtk_widget_show (hbox_custom_color[c]);
271                 gtk_box_pack_start (GTK_BOX (vbox_custom_colors), hbox_custom_color[c],
272                                 FALSE, TRUE, 0);
273                 color_buttons.custom_color[c] = gtk_button_new();
274                 gtk_widget_show (color_buttons.custom_color[c]);
275                 gtk_widget_set_size_request (color_buttons.custom_color[c], 30, 20);
276                 gtk_box_pack_start (GTK_BOX (hbox_custom_color[c]), color_buttons.custom_color[c],
277                                 FALSE, FALSE, 0);
278                 custom_colorlabel_entry[c] = gtk_entry_new();
279                 gtk_widget_show (custom_colorlabel_entry[c]);
280                 gtk_box_pack_start (GTK_BOX (hbox_custom_color[c]), custom_colorlabel_entry[c],
281                                 FALSE, FALSE, 0);
282         }
283
284         hbox_reset_custom_colors = gtk_hbox_new(FALSE, 8);
285         gtk_widget_show (hbox_reset_custom_colors);
286         gtk_box_pack_start (GTK_BOX (vbox_custom_colors), hbox_reset_custom_colors,
287                 FALSE, TRUE, 0);
288
289         reset_custom_colors_btn = gtk_button_new_with_label (_(" Use default "));
290         gtk_widget_show (reset_custom_colors_btn);
291         gtk_box_pack_start (GTK_BOX (hbox_reset_custom_colors), reset_custom_colors_btn,
292                 FALSE, FALSE, 0);
293
294         g_signal_connect(G_OBJECT(color_buttons.quote_level1_btn), "clicked",
295                          G_CALLBACK(quote_color_set_dialog), "LEVEL1");
296         g_signal_connect(G_OBJECT(color_buttons.quote_level2_btn), "clicked",
297                          G_CALLBACK(quote_color_set_dialog), "LEVEL2");
298         g_signal_connect(G_OBJECT(color_buttons.quote_level3_btn), "clicked",
299                          G_CALLBACK(quote_color_set_dialog), "LEVEL3");
300         g_signal_connect(G_OBJECT(color_buttons.uri_btn), "clicked",
301                          G_CALLBACK(quote_color_set_dialog), "URI");
302         g_signal_connect(G_OBJECT(color_buttons.tgt_folder_btn), "clicked",
303                          G_CALLBACK(quote_color_set_dialog), "TGTFLD");
304         g_signal_connect(G_OBJECT(color_buttons.signature_btn), "clicked",
305                          G_CALLBACK(quote_color_set_dialog), "SIGNATURE");
306         g_signal_connect(G_OBJECT(color_buttons.color_new_btn), "clicked",
307                          G_CALLBACK(quote_color_set_dialog), "NEW");
308         /* custom colors */
309         for (c = 0; c < COLORLABELS; c++) {
310                 g_signal_connect(G_OBJECT(color_buttons.custom_color[c]), "clicked",
311                                  G_CALLBACK(quote_color_set_dialog), GINT_TO_POINTER(c));
312         }
313
314         g_signal_connect(G_OBJECT(reset_custom_colors_btn), "clicked",
315                          G_CALLBACK(prefs_msg_colors_reset_custom_colors), prefs_msg_colors);
316
317         set_button_bg_color(color_buttons.quote_level1_btn,
318                             prefs_common.quote_level1_col);
319         set_button_bg_color(color_buttons.quote_level2_btn,
320                             prefs_common.quote_level2_col);
321         set_button_bg_color(color_buttons.quote_level3_btn,
322                             prefs_common.quote_level3_col);
323         set_button_bg_color(color_buttons.uri_btn,
324                             prefs_common.uri_col);
325         set_button_bg_color(color_buttons.tgt_folder_btn,
326                             prefs_common.tgt_folder_col);
327         set_button_bg_color(color_buttons.signature_btn,
328                             prefs_common.signature_col);
329         set_button_bg_color(color_buttons.color_new_btn,
330                             prefs_common.color_new);
331         /* custom colors */
332         for (c = 0; c < COLORLABELS; c++) {
333                 set_button_bg_color(color_buttons.custom_color[c],
334                                     prefs_common.custom_colorlabel[c].color);
335                 gtk_entry_set_text(GTK_ENTRY (custom_colorlabel_entry[c]), 
336                                    SAFE_STRING (prefs_common.custom_colorlabel[c].label));
337         }
338
339         gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(chkbtn_enablecol),
340                                      prefs_common.enable_color);
341         gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(chkbtn_recycle_colors),
342                                      prefs_common.recycle_quote_colors);
343
344         prefs_msg_colors->chkbtn_enablecol      = chkbtn_enablecol;
345         prefs_msg_colors->chkbtn_recycle_colors = chkbtn_recycle_colors;
346         /* custom colors */
347         for (c = 0; c < COLORLABELS; c++) {
348                 prefs_msg_colors->custom_colorlabel_entry[c] = custom_colorlabel_entry[c];
349         }
350
351         prefs_msg_colors->page.widget = vbox1;
352 }
353
354 static void quote_color_set_dialog(GtkWidget *widget, gpointer data)
355 {
356         gchar *type = (gchar *)data;
357         gchar *title = NULL;
358         gdouble color[4] = {0.0, 0.0, 0.0, 0.0};
359         gint rgbvalue = 0;
360         GtkColorSelectionDialog *dialog;
361         gint c;
362
363         /* custom colors */
364         for (c = 0; c < COLORLABELS; c++) {
365                 if (GPOINTER_TO_INT(type) == c) {
366                         title = g_strdup_printf(_("Pick color for color #%d"), c+1);
367                         rgbvalue = prefs_common.custom_colorlabel[c].color;
368                         break;
369                 }
370         }
371         /* other colors */
372         if (c == COLORLABELS) {
373                 if(g_ascii_strcasecmp(type, "LEVEL1") == 0) {
374                         title = g_strdup(_("Pick color for quotation level 1"));
375                         rgbvalue = prefs_common.quote_level1_col;
376                 } else if(g_ascii_strcasecmp(type, "LEVEL2") == 0) {
377                         title = g_strdup(_("Pick color for quotation level 2"));
378                         rgbvalue = prefs_common.quote_level2_col;
379                 } else if(g_ascii_strcasecmp(type, "LEVEL3") == 0) {
380                         title = g_strdup(_("Pick color for quotation level 3"));
381                         rgbvalue = prefs_common.quote_level3_col;
382                 } else if(g_ascii_strcasecmp(type, "URI") == 0) {
383                         title = g_strdup(_("Pick color for URI"));
384                         rgbvalue = prefs_common.uri_col;
385                 } else if(g_ascii_strcasecmp(type, "TGTFLD") == 0) {
386                         title = g_strdup(_("Pick color for target folder"));
387                         rgbvalue = prefs_common.tgt_folder_col;
388                 } else if(g_ascii_strcasecmp(type, "SIGNATURE") == 0) {
389                         title = g_strdup(_("Pick color for signatures"));
390                         rgbvalue = prefs_common.signature_col;
391                 } else if(g_ascii_strcasecmp(type, "NEW") == 0) {
392                         title = g_strdup(_("Pick color for folder"));
393                         rgbvalue = prefs_common.color_new;
394                 } else {
395                         /* Should never be called */
396                         g_warning("Unrecognized datatype '%s' in quote_color_set_dialog\n", type);
397                         return;
398                 }
399         }
400
401         color_dialog = gtk_color_selection_dialog_new(title);
402         g_free(title);
403         gtk_window_set_position(GTK_WINDOW(color_dialog), GTK_WIN_POS_CENTER);
404         gtk_window_set_modal(GTK_WINDOW(color_dialog), TRUE);
405         gtk_window_set_resizable(GTK_WINDOW(color_dialog), FALSE);
406         manage_window_set_transient(GTK_WINDOW(color_dialog));
407
408         g_signal_connect(G_OBJECT(GTK_COLOR_SELECTION_DIALOG(color_dialog)->cancel_button),
409                          "clicked", G_CALLBACK(quote_colors_set_dialog_cancel), data);
410         g_signal_connect(G_OBJECT(GTK_COLOR_SELECTION_DIALOG(color_dialog)->ok_button),
411                          "clicked", G_CALLBACK(quote_colors_set_dialog_ok), data);
412         g_signal_connect(G_OBJECT(color_dialog), "key_press_event",
413                          G_CALLBACK(quote_colors_set_dialog_key_pressed),data);
414
415         /* preselect the previous color in the color selection dialog */
416         color[0] = (gdouble) ((rgbvalue & 0xff0000) >> 16) / 255.0;
417         color[1] = (gdouble) ((rgbvalue & 0x00ff00) >>  8) / 255.0;
418         color[2] = (gdouble)  (rgbvalue & 0x0000ff)        / 255.0;
419         dialog = GTK_COLOR_SELECTION_DIALOG(color_dialog);
420         gtk_color_selection_set_color
421                 (GTK_COLOR_SELECTION(dialog->colorsel), color);
422
423         gtk_widget_show(color_dialog);
424 }
425
426 static void quote_colors_set_dialog_ok(GtkWidget *widget, gpointer data)
427 {
428         GtkColorSelection *colorsel = (GtkColorSelection *)
429                                                 ((GtkColorSelectionDialog *)color_dialog)->colorsel;
430         gdouble color[4];
431         gint red, green, blue, rgbvalue;
432         gchar *type = (gchar *)data;
433         gint c;
434
435         gtk_color_selection_get_color(colorsel, color);
436
437         red      = (gint) (color[0] * 255.0);
438         green    = (gint) (color[1] * 255.0);
439         blue     = (gint) (color[2] * 255.0);
440         rgbvalue = (gint) ((red * 0x10000) | (green * 0x100) | blue);
441
442
443         /* custom colors */
444         for (c = 0; c < COLORLABELS; c++) {
445                 if (GPOINTER_TO_INT(type) == c) {
446                         prefs_common.custom_colorlabel[c].color = rgbvalue;
447                         set_button_bg_color(color_buttons.custom_color[c], rgbvalue);
448                         break;
449                 }
450         }
451         /* other colors */
452         if (c == COLORLABELS) {
453                 if (g_ascii_strcasecmp(type, "LEVEL1") == 0) {
454                         prefs_common.quote_level1_col = rgbvalue;
455                         set_button_bg_color(color_buttons.quote_level1_btn, rgbvalue);
456                 } else if (g_ascii_strcasecmp(type, "LEVEL2") == 0) {
457                         prefs_common.quote_level2_col = rgbvalue;
458                         set_button_bg_color(color_buttons.quote_level2_btn, rgbvalue);
459                 } else if (g_ascii_strcasecmp(type, "LEVEL3") == 0) {
460                         prefs_common.quote_level3_col = rgbvalue;
461                         set_button_bg_color(color_buttons.quote_level3_btn, rgbvalue);
462                 } else if (g_ascii_strcasecmp(type, "URI") == 0) {
463                         prefs_common.uri_col = rgbvalue;
464                         set_button_bg_color(color_buttons.uri_btn, rgbvalue);
465                 } else if (g_ascii_strcasecmp(type, "TGTFLD") == 0) {
466                         prefs_common.tgt_folder_col = rgbvalue;
467                         set_button_bg_color(color_buttons.tgt_folder_btn, rgbvalue);
468                         folderview_set_target_folder_color(prefs_common.tgt_folder_col);
469                 } else if (g_ascii_strcasecmp(type, "SIGNATURE") == 0) {
470                         prefs_common.signature_col = rgbvalue;
471                         set_button_bg_color(color_buttons.signature_btn, rgbvalue);
472                 } else if (g_ascii_strcasecmp(type, "NEW") == 0) {
473                         prefs_common.color_new = rgbvalue;
474                         set_button_bg_color(color_buttons.color_new_btn, rgbvalue);
475                 } else {
476                         fprintf(stderr, "Unrecognized datatype '%s' in quote_color_set_dialog_ok\n", type);
477                 }
478         }
479
480         gtk_widget_destroy(color_dialog);
481 }
482
483 static void quote_colors_set_dialog_cancel(GtkWidget *widget, gpointer data)
484 {
485         gtk_widget_destroy(color_dialog);
486 }
487
488 static gboolean quote_colors_set_dialog_key_pressed(GtkWidget *widget,
489                                                 GdkEventKey *event,
490                                                 gpointer data)
491 {
492         if (event) {
493                 switch (event->keyval) {
494                         case GDK_Escape:
495                                 gtk_button_clicked(GTK_BUTTON(GTK_COLOR_SELECTION_DIALOG
496                                                         (widget)->cancel_button));
497                                 return TRUE;
498                         case GDK_Return: 
499                         case GDK_KP_Enter:
500                                 /* NOTE: changing focus makes widget accept all currently 
501                                  * changed settings! */
502                                 gtk_widget_grab_focus
503                                         (GTK_COLOR_SELECTION_DIALOG
504                                                 (widget)->ok_button);
505                                 /* call ok handler */                                           
506                                 gtk_button_clicked(GTK_BUTTON
507                                         (GTK_COLOR_SELECTION_DIALOG
508                                                 (widget)->ok_button));
509                                 return TRUE;
510                         default:
511                                 break;
512                 }
513         }
514         return FALSE;
515 }
516
517 static void set_button_bg_color(GtkWidget *widget, gint rgbvalue)
518 {
519         GtkStyle *newstyle;
520         GdkColor color;
521
522         gtkut_convert_int_to_gdk_color(rgbvalue, &color);
523         newstyle = gtk_style_copy(gtk_widget_get_default_style());
524         newstyle->bg[GTK_STATE_NORMAL]   = color;
525         newstyle->bg[GTK_STATE_PRELIGHT] = color;
526         newstyle->bg[GTK_STATE_ACTIVE]   = color;
527
528         gtk_widget_set_style(GTK_WIDGET(widget), newstyle);
529 }
530
531 void prefs_msg_colors_save(PrefsPage *_page)
532 {
533         MsgColorsPage *page = (MsgColorsPage *) _page;
534         gint c;
535
536         prefs_common.enable_color = 
537                 gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(page->chkbtn_enablecol));
538         prefs_common.recycle_quote_colors =
539                 gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(page->chkbtn_recycle_colors));
540
541         /* custom colors */
542         for (c = 0; c < COLORLABELS; c++) {
543                 g_free(prefs_common.custom_colorlabel[c].label);
544                 prefs_common.custom_colorlabel[c].label =
545                         gtk_editable_get_chars(GTK_EDITABLE(page->custom_colorlabel_entry[c]), 0, -1);
546         }
547         colorlabel_update_colortable_from_prefs();
548
549         main_window_reflect_prefs_all();
550         main_window_reflect_prefs_custom_colors(mainwindow_get_mainwindow());
551 }
552
553 static void prefs_msg_colors_reset_custom_colors(GtkWidget *widget, gpointer data)
554 {
555 #define CL(x)           (((gulong) (x) >> (gulong) 8) & 0xFFUL) 
556 #define CR(r, g, b)     ((CL(r) << (gulong) 16) | \
557                          (CL(g) << (gulong)  8) | \
558                          (CL(b)))
559         MsgColorsPage *page = (MsgColorsPage *) data;
560         GdkColor color;
561         gint c;
562
563         for (c = 0; c < COLORLABELS; c++) {
564                 color = colorlabel_get_default_color(c);
565                 prefs_common.custom_colorlabel[c].color =
566                                                         (gint)CR(color.red, color.green, color.blue);
567                 set_button_bg_color(color_buttons.custom_color[c],
568                                                         prefs_common.custom_colorlabel[c].color);
569                 gtk_entry_set_text(GTK_ENTRY (page->custom_colorlabel_entry[c]),
570                                                         SAFE_STRING (colorlabel_get_color_default_text(c)));
571         }
572
573 #undef CR
574 #undef CL
575 }
576
577 static void prefs_msg_colors_destroy_widget(PrefsPage *_page)
578 {
579 }
580
581 MsgColorsPage *prefs_msg_colors;
582
583 void prefs_msg_colors_init(void)
584 {
585         MsgColorsPage *page;
586         static gchar *path[3];
587
588         path[0] = _("Display");
589         path[1] = _("Colors");
590         path[2] = NULL;
591
592         page = g_new0(MsgColorsPage, 1);
593         page->page.path = path;
594         page->page.create_widget = prefs_msg_colors_create_widget;
595         page->page.destroy_widget = prefs_msg_colors_destroy_widget;
596         page->page.save_page = prefs_msg_colors_save;
597         page->page.weight = 165.0;
598         prefs_gtk_register_page((PrefsPage *) page);
599         prefs_msg_colors = page;
600 }
601
602 void prefs_msg_colors_done(void)
603 {
604         prefs_gtk_unregister_page((PrefsPage *) prefs_msg_colors);
605         g_free(prefs_msg_colors);
606 }
607