2007-02-09 [paul] 2.7.2cvs35
[claws.git] / src / prefs_msg_colors.c
1 /*
2  * Sylpheed -- a GTK+ based, lightweight, and fast e-mail client
3  * Copyright (C) 2004-2007 Hiroyuki Yamamoto & The Claws Mail 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 *btn_quote_level1;
49         GtkWidget *btn_quote_level2;
50         GtkWidget *btn_quote_level3;
51         GtkWidget *btn_quote_level1_bg;
52         GtkWidget *btn_quote_level2_bg;
53         GtkWidget *btn_quote_level3_bg;
54         GtkWidget *btn_uri;
55         GtkWidget *btn_tgt_folder;
56         GtkWidget *btn_signature;
57         GtkWidget *btn_color_new;
58         /* custom colors */
59         GtkWidget *custom_color[COLORLABELS];
60 } color_buttons;
61
62 typedef struct _MsgColorsPage
63 {
64         PrefsPage page;
65
66         GtkWidget *window;
67         
68         GtkWidget *checkbtn_enable_colors;
69         GtkWidget *checkbtn_enable_bgcolors;
70         GtkWidget *checkbtn_recycle_colors;
71
72         /* custom colors */
73         GtkWidget *entry_custom_colorlabel[COLORLABELS];
74 } MsgColorsPage;
75
76 static GtkWidget *color_dialog;
77
78 static void quote_color_set_dialog              (GtkWidget      *widget,
79                                                  gpointer        data);
80 static void quote_colors_set_dialog_ok          (GtkWidget      *widget,
81                                                  gpointer        data);
82 static void quote_colors_set_dialog_cancel      (GtkWidget      *widget,
83                                                  gpointer        data);
84 static gboolean quote_colors_set_dialog_key_pressed     (GtkWidget      *widget,
85                                                  GdkEventKey    *event,
86                                                  gpointer        data);
87 static void set_button_bg_color                 (GtkWidget      *widget,
88                                                  gint            color);
89 static void prefs_msg_colors_reset_custom_colors(GtkWidget *widget,
90                                                  gpointer        data);
91
92 static void prefs_msg_colors_create_widget(PrefsPage *_page, GtkWindow *window, 
93                                     gpointer data)
94 {
95         MsgColorsPage *prefs_msg_colors = (MsgColorsPage *) _page;
96         
97         GtkWidget *vbox1;
98         GtkWidget *vbox2;
99         GtkWidget *checkbtn_enable_colors;
100         GtkWidget *label_quote_level1;
101         GtkWidget *label_quote_level2;
102         GtkWidget *label_quote_level3;
103         GtkWidget *label_quote_color1;
104         GtkWidget *label_quote_color2;
105         GtkWidget *label_quote_color3;
106         GtkWidget *checkbtn_enable_bgcolors;
107         GtkWidget *label_quote_bgcolor1;
108         GtkWidget *label_quote_bgcolor2;
109         GtkWidget *label_quote_bgcolor3;
110         GtkWidget *lable_uri;
111         GtkWidget *label_signature;
112         GtkWidget *label_tgt_folder;
113         GtkWidget *checkbtn_recycle_colors;
114         GtkWidget *hbox;
115         GtkWidget *label_color_new;
116         GtkWidget *frame_msg;
117         GtkWidget *frame_folder;
118         GtkWidget *frame_quote;
119         GtkWidget *vbox3;
120         GtkWidget *hbox_quote;
121         GtkWidget *vbox_quotefg;
122         GtkWidget *vbox_quotebg;
123         /* custom colors */
124         GtkWidget *vbox_color_labels;
125         GtkWidget *hbox_custom_colors;
126         GtkWidget *vbox_custom_colors;
127         GtkWidget *vbox_custom_colors1;
128         GtkWidget *vbox_custom_colors2;
129         GtkWidget *frame_custom_colors;
130         GtkWidget *hbox_reset_custom_colors;
131         GtkWidget *btn_reset_custom_colors;
132         GtkWidget *hbox_custom_color[COLORLABELS];
133         GtkWidget *entry_custom_colorlabel[COLORLABELS];
134         gint c;
135         GtkTooltips *tooltips;
136         gchar *tooltip_btn_text = NULL;
137         gchar *tooltip_entry_text = NULL;
138
139         vbox1 = gtk_vbox_new (FALSE, VSPACING_NARROW);
140         gtk_widget_show (vbox1);
141         gtk_container_set_border_width (GTK_CONTAINER (vbox1), VBOX_BORDER);
142
143         vbox2 = gtkut_get_options_frame(vbox1, &frame_msg, _("Message view"));
144
145         hbox = gtk_hbox_new(FALSE, 8);
146         gtk_widget_show (hbox);
147         hbox_quote = gtk_hbox_new(FALSE, 8);
148         gtk_widget_show (hbox_quote);
149         vbox_quotefg = gtk_vbox_new(FALSE, 8);
150         gtk_widget_show (vbox_quotefg);
151         vbox_quotebg = gtk_vbox_new(FALSE, 8);
152 #if GTK_CHECK_VERSION(2, 8, 0)
153         gtk_widget_show (vbox_quotebg);
154 #endif  
155         
156         gtk_box_pack_start (GTK_BOX (vbox2), hbox, FALSE, TRUE, 0);
157         PACK_CHECK_BUTTON (hbox, checkbtn_enable_colors,
158                            _("Enable coloration of message text"));
159
160         vbox3 = gtkut_get_options_frame(vbox2, &frame_quote, _("Quote"));
161
162         gtk_box_pack_start (GTK_BOX (vbox3), hbox_quote, FALSE, TRUE, 0);
163         gtk_box_pack_start (GTK_BOX (hbox_quote), vbox_quotefg, FALSE, TRUE, 0);
164         gtk_box_pack_start (GTK_BOX (hbox_quote), vbox_quotebg, FALSE, TRUE, 0);
165
166         hbox = gtk_hbox_new(FALSE, 8);
167         gtk_widget_show (hbox);
168         gtk_box_pack_start (GTK_BOX (vbox_quotefg), hbox, FALSE, TRUE, 0);
169
170         PACK_CHECK_BUTTON (hbox, checkbtn_recycle_colors,
171                            _("Cycle quote colors"));
172         SET_TOGGLE_SENSITIVITY(checkbtn_enable_colors, checkbtn_recycle_colors);
173         tooltips = gtk_tooltips_new();
174         gtk_tooltips_set_tip(tooltips, checkbtn_recycle_colors,
175                              _("If there are more than 3 quote levels, the colors will be reused"),
176                              NULL);
177
178         hbox = gtk_hbox_new(FALSE, 8);
179         gtk_widget_show (hbox);
180         gtk_box_pack_start (GTK_BOX (vbox_quotefg), hbox, FALSE, TRUE, 0);
181
182         label_quote_level1 = gtk_label_new (_("1st Level"));
183         gtk_widget_show(label_quote_level1);
184         gtk_box_pack_start (GTK_BOX(hbox), label_quote_level1, 
185                             FALSE, FALSE, 0);
186         SET_TOGGLE_SENSITIVITY(checkbtn_enable_colors, label_quote_level1);
187
188         label_quote_color1 = gtk_label_new (_("Text"));
189         gtk_widget_show(label_quote_color1);
190         gtk_box_pack_end (GTK_BOX(hbox), label_quote_color1, 
191                             FALSE, FALSE, 0);
192         SET_TOGGLE_SENSITIVITY(checkbtn_enable_colors, label_quote_color1);
193                 
194         color_buttons.btn_quote_level1 = gtk_button_new();
195         gtk_widget_show(color_buttons.btn_quote_level1);
196         gtk_widget_set_size_request (color_buttons.btn_quote_level1, 30, 20);
197         gtk_box_pack_end (GTK_BOX(hbox), color_buttons.btn_quote_level1, 
198                             FALSE, FALSE, 0);
199         SET_TOGGLE_SENSITIVITY(checkbtn_enable_colors, color_buttons.btn_quote_level1);
200         tooltips = gtk_tooltips_new();
201         gtk_tooltips_set_tip(tooltips, color_buttons.btn_quote_level1,
202                              Q_("Tooltip|Pick color for 1st level text"), NULL);
203
204         hbox = gtk_hbox_new(FALSE, 8);
205         gtk_widget_show (hbox);
206         gtk_box_pack_start (GTK_BOX (vbox_quotefg), hbox, FALSE, TRUE, 0);
207
208         label_quote_level2 = gtk_label_new (_("2nd Level"));
209         gtk_widget_show(label_quote_level2);
210         gtk_box_pack_start (GTK_BOX(hbox), label_quote_level2, 
211                             FALSE, FALSE, 0);
212         SET_TOGGLE_SENSITIVITY(checkbtn_enable_colors, label_quote_level2);
213
214         label_quote_color2 = gtk_label_new (_("Text"));
215         gtk_widget_show(label_quote_color2);
216         gtk_box_pack_end (GTK_BOX(hbox), label_quote_color2, 
217                             FALSE, FALSE, 0);
218         SET_TOGGLE_SENSITIVITY(checkbtn_enable_colors, label_quote_color2);
219
220         color_buttons.btn_quote_level2 = gtk_button_new();
221         gtk_widget_show(color_buttons.btn_quote_level2);
222         gtk_widget_set_size_request (color_buttons.btn_quote_level2, 30, 20);
223         gtk_box_pack_end (GTK_BOX(hbox), color_buttons.btn_quote_level2, 
224                             FALSE, FALSE, 0);
225         SET_TOGGLE_SENSITIVITY(checkbtn_enable_colors, color_buttons.btn_quote_level2);
226         tooltips = gtk_tooltips_new();
227         gtk_tooltips_set_tip(tooltips, color_buttons.btn_quote_level2,
228                              Q_("Tooltip|Pick color for 2nd level text"), NULL);
229
230         hbox = gtk_hbox_new(FALSE, 8);
231         gtk_widget_show (hbox);
232         gtk_box_pack_start (GTK_BOX (vbox_quotefg), hbox, FALSE, TRUE, 0);
233
234         label_quote_level3 = gtk_label_new (_("3rd Level"));
235         gtk_widget_show(label_quote_level3);
236         gtk_box_pack_start (GTK_BOX(hbox), label_quote_level3, 
237                             FALSE, FALSE, 0);
238         SET_TOGGLE_SENSITIVITY(checkbtn_enable_colors, label_quote_level3);
239
240         label_quote_color3 = gtk_label_new (_("Text"));
241         gtk_widget_show(label_quote_color3);
242         gtk_box_pack_end (GTK_BOX(hbox), label_quote_color3, 
243                             FALSE, FALSE, 0);
244         SET_TOGGLE_SENSITIVITY(checkbtn_enable_colors, label_quote_color3);
245
246         color_buttons.btn_quote_level3 = gtk_button_new();
247         gtk_widget_show(color_buttons.btn_quote_level3);
248         gtk_widget_set_size_request (color_buttons.btn_quote_level3, 30, 20);
249         gtk_box_pack_end (GTK_BOX(hbox), color_buttons.btn_quote_level3, 
250                             FALSE, FALSE, 0);
251         SET_TOGGLE_SENSITIVITY(checkbtn_enable_colors, color_buttons.btn_quote_level3);
252         tooltips = gtk_tooltips_new();
253         gtk_tooltips_set_tip(tooltips, color_buttons.btn_quote_level3,
254                              Q_("Tooltip|Pick color for 3rd level text"), NULL);
255
256         hbox = gtk_hbox_new(FALSE, 8);
257         gtk_widget_show (hbox);
258         gtk_box_pack_start (GTK_BOX (vbox_quotebg), hbox, FALSE, TRUE, 0);
259
260         PACK_CHECK_BUTTON (hbox, checkbtn_enable_bgcolors,
261                            _("Enable coloration of text background"));
262         SET_TOGGLE_SENSITIVITY(checkbtn_enable_colors, checkbtn_enable_bgcolors);
263
264         hbox = gtk_hbox_new(FALSE, 8);
265         gtk_widget_show (hbox);
266         SET_TOGGLE_SENSITIVITY(checkbtn_enable_colors, hbox);
267         gtk_box_pack_start (GTK_BOX (vbox_quotebg), hbox, FALSE, TRUE, 0);
268         
269         color_buttons.btn_quote_level1_bg = gtk_button_new();
270         gtk_widget_show(color_buttons.btn_quote_level1_bg);
271         gtk_widget_set_size_request (color_buttons.btn_quote_level1_bg, 30, 20);
272         gtk_box_pack_start (GTK_BOX(hbox), color_buttons.btn_quote_level1_bg, 
273                             FALSE, FALSE, 0);
274         SET_TOGGLE_SENSITIVITY(checkbtn_enable_bgcolors, color_buttons.btn_quote_level1_bg);
275         tooltips = gtk_tooltips_new();
276         gtk_tooltips_set_tip(tooltips, color_buttons.btn_quote_level1_bg,
277                              Q_("Tooltip|Pick color for 1st level text background"), NULL);
278
279         label_quote_bgcolor1 = gtk_label_new (_("Background"));
280         gtk_widget_show(label_quote_bgcolor1);
281         gtk_box_pack_start (GTK_BOX(hbox), label_quote_bgcolor1, 
282                             FALSE, FALSE, 0);
283         SET_TOGGLE_SENSITIVITY(checkbtn_enable_bgcolors, label_quote_bgcolor1);
284
285         hbox = gtk_hbox_new(FALSE, 8);
286         gtk_widget_show (hbox);
287         SET_TOGGLE_SENSITIVITY(checkbtn_enable_colors, hbox);
288         gtk_box_pack_start (GTK_BOX (vbox_quotebg), hbox, FALSE, TRUE, 0);
289         
290         color_buttons.btn_quote_level2_bg = gtk_button_new();
291         gtk_widget_show(color_buttons.btn_quote_level2_bg);
292         gtk_widget_set_size_request (color_buttons.btn_quote_level2_bg, 30, 20);
293         gtk_box_pack_start (GTK_BOX(hbox), color_buttons.btn_quote_level2_bg, 
294                             FALSE, FALSE, 0);
295         SET_TOGGLE_SENSITIVITY(checkbtn_enable_bgcolors, color_buttons.btn_quote_level2_bg);
296         tooltips = gtk_tooltips_new();
297         gtk_tooltips_set_tip(tooltips, color_buttons.btn_quote_level2_bg,
298                              Q_("Tooltip|Pick color for 2nd level text background"), NULL);
299
300         label_quote_bgcolor2 = gtk_label_new (_("Background"));
301         gtk_widget_show(label_quote_bgcolor2);
302         gtk_box_pack_start (GTK_BOX(hbox), label_quote_bgcolor2, 
303                             FALSE, FALSE, 0);
304         SET_TOGGLE_SENSITIVITY(checkbtn_enable_bgcolors, label_quote_bgcolor2);
305
306         hbox = gtk_hbox_new(FALSE, 8);
307         gtk_widget_show (hbox);
308         SET_TOGGLE_SENSITIVITY(checkbtn_enable_colors, hbox);
309         gtk_box_pack_start (GTK_BOX (vbox_quotebg), hbox, FALSE, TRUE, 0);
310         
311         color_buttons.btn_quote_level3_bg = gtk_button_new();
312         gtk_widget_show(color_buttons.btn_quote_level3_bg);
313         gtk_widget_set_size_request (color_buttons.btn_quote_level3_bg, 30, 20);
314         gtk_box_pack_start (GTK_BOX(hbox), color_buttons.btn_quote_level3_bg, 
315                             FALSE, FALSE, 0);
316         SET_TOGGLE_SENSITIVITY(checkbtn_enable_bgcolors, color_buttons.btn_quote_level3_bg);
317         tooltips = gtk_tooltips_new();
318         gtk_tooltips_set_tip(tooltips, color_buttons.btn_quote_level3_bg,
319                              Q_("Tooltip|Pick color for 3rd level text background"), NULL);
320
321         label_quote_bgcolor3 = gtk_label_new (_("Background"));
322         gtk_widget_show(label_quote_bgcolor3);
323         gtk_box_pack_start (GTK_BOX(hbox), label_quote_bgcolor3, 
324                             FALSE, FALSE, 0);
325         SET_TOGGLE_SENSITIVITY(checkbtn_enable_bgcolors, label_quote_bgcolor3);
326
327         hbox = gtk_hbox_new(FALSE, 8);
328         gtk_widget_show (hbox);
329         gtk_box_pack_start (GTK_BOX (vbox2), hbox, FALSE, TRUE, 0);
330
331         color_buttons.btn_uri = gtk_button_new();
332         gtk_widget_show(color_buttons.btn_uri);
333         gtk_widget_set_size_request (color_buttons.btn_uri, 30, 20);
334         gtk_box_pack_start (GTK_BOX(hbox), color_buttons.btn_uri, 
335                             FALSE, FALSE, 0);
336         SET_TOGGLE_SENSITIVITY(checkbtn_enable_colors, color_buttons.btn_uri);
337         tooltips = gtk_tooltips_new();
338         gtk_tooltips_set_tip(tooltips, color_buttons.btn_uri,
339                              Q_("Tooltip|Pick color for links"), NULL);
340
341         lable_uri = gtk_label_new (_("URI link"));
342         gtk_widget_show(lable_uri);
343         gtk_box_pack_start (GTK_BOX(hbox), lable_uri, FALSE, FALSE, 0);
344         SET_TOGGLE_SENSITIVITY(checkbtn_enable_colors, lable_uri);
345
346         hbox = gtk_hbox_new(FALSE, 8);
347         gtk_widget_show (hbox);
348         gtk_box_pack_start (GTK_BOX (vbox2), hbox, FALSE, TRUE, 0);
349
350         color_buttons.btn_signature = gtk_button_new();
351         gtk_widget_show(color_buttons.btn_signature);
352         gtk_widget_set_size_request (color_buttons.btn_signature, 30, 20);
353         gtk_box_pack_start (GTK_BOX(hbox), color_buttons.btn_signature, 
354                             FALSE, FALSE, 0);
355         SET_TOGGLE_SENSITIVITY(checkbtn_enable_colors, color_buttons.btn_signature);
356         tooltips = gtk_tooltips_new();
357         gtk_tooltips_set_tip(tooltips, color_buttons.btn_signature,
358                              Q_("Tooltip|Pick color for signatures"), NULL);
359
360         label_signature = gtk_label_new (_("Signatures"));
361         gtk_widget_show(label_signature);
362         gtk_box_pack_start (GTK_BOX(hbox), label_signature, FALSE, FALSE, 0);
363         SET_TOGGLE_SENSITIVITY(checkbtn_enable_colors, label_signature);
364
365         vbox2 = gtkut_get_options_frame(vbox1, &frame_folder, _("Folder list"));
366
367         hbox = gtk_hbox_new(FALSE, 8);
368         gtk_widget_show (hbox);
369         gtk_box_pack_start (GTK_BOX (vbox2), hbox, FALSE, TRUE, 0);
370
371         color_buttons.btn_tgt_folder = gtk_button_new();
372         gtk_widget_show(color_buttons.btn_tgt_folder);
373         gtk_widget_set_size_request (color_buttons.btn_tgt_folder, 30, 20);
374         gtk_box_pack_start (GTK_BOX(hbox), color_buttons.btn_tgt_folder, 
375                             FALSE, FALSE, 0);
376         tooltips = gtk_tooltips_new();
377         gtk_tooltips_set_tip(tooltips, color_buttons.btn_tgt_folder,
378                              _("Pick color for Target folder. "
379                                "Target folder is used when the option 'Execute immediately "
380                                "when moving or deleting messages' is turned off"), NULL);
381
382         label_tgt_folder = gtk_label_new (_("Target folder"));
383         gtk_widget_show(label_tgt_folder);
384         gtk_box_pack_start (GTK_BOX(hbox), label_tgt_folder, FALSE, FALSE, 0);
385
386         hbox = gtk_hbox_new(FALSE, 8);
387         gtk_widget_show (hbox);
388         gtk_box_pack_start (GTK_BOX (vbox2), hbox, FALSE, FALSE, 0);
389
390         color_buttons.btn_color_new = gtk_button_new();
391         gtk_widget_show (color_buttons.btn_color_new);
392         gtk_widget_set_size_request (color_buttons.btn_color_new, 30, 20);
393         gtk_box_pack_start (GTK_BOX(hbox), color_buttons.btn_color_new,
394                             FALSE, FALSE, 0);
395         tooltips = gtk_tooltips_new();
396         gtk_tooltips_set_tip(tooltips, color_buttons.btn_color_new,
397                              _("Pick color for folders containing new messages"), NULL);
398
399         label_color_new = gtk_label_new (_("Folder containing new messages"));
400         gtk_widget_show(label_color_new);
401         gtk_box_pack_start (GTK_BOX(hbox), label_color_new, FALSE, FALSE, 0);
402
403         /* custom colors */
404         vbox_color_labels = gtkut_get_options_frame(vbox1,
405                                 &frame_custom_colors, _("Color labels"));
406
407         vbox_custom_colors = gtk_vbox_new (FALSE, VSPACING_NARROW);
408         gtk_widget_show (vbox_custom_colors);
409         gtk_box_pack_start(GTK_BOX(vbox_color_labels), vbox_custom_colors,
410                 FALSE, FALSE, 0);
411
412         hbox_custom_colors = gtk_hbox_new(FALSE, 8);
413         gtk_widget_show(hbox_custom_colors);
414         gtk_box_pack_start(GTK_BOX (vbox_custom_colors), hbox_custom_colors,
415                                    FALSE, TRUE, 0);
416
417         vbox_custom_colors1 = gtk_vbox_new (FALSE, VSPACING_NARROW);
418         gtk_widget_show (vbox_custom_colors1);
419         gtk_box_pack_start (GTK_BOX (hbox_custom_colors), vbox_custom_colors1, FALSE, FALSE, 0);
420
421         vbox_custom_colors2 = gtk_vbox_new (FALSE, VSPACING_NARROW);
422         gtk_widget_show (vbox_custom_colors2);
423         gtk_box_pack_start (GTK_BOX (hbox_custom_colors), vbox_custom_colors2, FALSE, FALSE, 0);
424
425         for (c = 0; c < 4; c++) {
426                 /* TRANSLATORS: 'color %d' refers to the filtering/processing 
427                    rule name and should not be translated */
428                 tooltip_btn_text = g_strdup_printf(Q_("Tooltip|Pick color for 'color %d'"), c+1);
429
430                 /* TRANSLATORS: 'color %d' refers to the filtering/processing 
431                    rule name and should not be translated */
432                 tooltip_entry_text = g_strdup_printf(_("Set label for 'color %d'"), c+1);
433
434                 hbox_custom_color[c] = gtk_hbox_new(FALSE, 8);
435                 gtk_widget_show(hbox_custom_color[c]);
436                 gtk_box_pack_start(GTK_BOX (vbox_custom_colors1), hbox_custom_color[c],
437                                    FALSE, TRUE, 0);
438
439                 color_buttons.custom_color[c] = gtk_button_new();
440                 gtk_widget_show(color_buttons.custom_color[c]);
441                 gtk_widget_set_size_request(color_buttons.custom_color[c], 30, 20);
442                 gtk_box_pack_start(GTK_BOX (hbox_custom_color[c]), color_buttons.custom_color[c],
443                                    FALSE, FALSE, 0);
444                 tooltips = gtk_tooltips_new();
445                 gtk_tooltips_set_tip(tooltips, color_buttons.custom_color[c],
446                                      tooltip_btn_text, NULL);
447
448                 entry_custom_colorlabel[c] = gtk_entry_new();
449                 gtk_widget_show (entry_custom_colorlabel[c]);
450                 gtk_box_pack_start(GTK_BOX (hbox_custom_color[c]), entry_custom_colorlabel[c],
451                                    FALSE, FALSE, 0);
452                 tooltips = gtk_tooltips_new();
453                 gtk_tooltips_set_tip(tooltips, entry_custom_colorlabel[c],
454                                      tooltip_entry_text, NULL);
455         }
456
457         for (c = 4; c < COLORLABELS; c++) {
458                 /* TRANSLATORS: 'color %d' refers to the filtering/processing 
459                    rule name and should not be translated */
460                 tooltip_btn_text = g_strdup_printf(Q_("Tooltip|Pick color for 'color %d'"), c+1);
461
462                 /* TRANSLATORS: 'color %d' refers to the filtering/processing 
463                    rule name and should not be translated */
464                 tooltip_entry_text = g_strdup_printf(_("Set label for 'color %d'"), c+1);
465
466                 hbox_custom_color[c] = gtk_hbox_new(FALSE, 8);
467                 gtk_widget_show(hbox_custom_color[c]);
468                 gtk_box_pack_start(GTK_BOX (vbox_custom_colors2), hbox_custom_color[c],
469                                    FALSE, TRUE, 0);
470
471                 color_buttons.custom_color[c] = gtk_button_new();
472                 gtk_widget_show(color_buttons.custom_color[c]);
473                 gtk_widget_set_size_request(color_buttons.custom_color[c], 30, 20);
474                 gtk_box_pack_start(GTK_BOX (hbox_custom_color[c]), color_buttons.custom_color[c],
475                                    FALSE, FALSE, 0);
476                 tooltips = gtk_tooltips_new();
477                 gtk_tooltips_set_tip(tooltips, color_buttons.custom_color[c],
478                                      tooltip_btn_text, NULL);
479
480                 entry_custom_colorlabel[c] = gtk_entry_new();
481                 gtk_widget_show (entry_custom_colorlabel[c]);
482                 gtk_box_pack_start(GTK_BOX (hbox_custom_color[c]), entry_custom_colorlabel[c],
483                                    FALSE, FALSE, 0);
484                 tooltips = gtk_tooltips_new();
485                 gtk_tooltips_set_tip(tooltips, entry_custom_colorlabel[c],
486                                      tooltip_entry_text, NULL);
487         }
488
489         g_free(tooltip_btn_text);
490         g_free(tooltip_entry_text);
491
492         hbox_reset_custom_colors = gtk_hbox_new(FALSE, 8);
493         gtk_widget_show (hbox_reset_custom_colors);
494         gtk_box_pack_start(GTK_BOX (vbox_color_labels), hbox_reset_custom_colors,
495                            FALSE, FALSE, 0);
496
497         btn_reset_custom_colors = gtk_button_new_with_label(_(" Use default "));
498         gtk_widget_show(btn_reset_custom_colors);
499         gtk_box_pack_start(GTK_BOX(hbox_reset_custom_colors), btn_reset_custom_colors,
500                 FALSE, FALSE, 0);
501
502         g_signal_connect(G_OBJECT(color_buttons.btn_quote_level1), "clicked",
503                          G_CALLBACK(quote_color_set_dialog), "LEVEL1");
504         g_signal_connect(G_OBJECT(color_buttons.btn_quote_level2), "clicked",
505                          G_CALLBACK(quote_color_set_dialog), "LEVEL2");
506         g_signal_connect(G_OBJECT(color_buttons.btn_quote_level3), "clicked",
507                          G_CALLBACK(quote_color_set_dialog), "LEVEL3");
508         g_signal_connect(G_OBJECT(color_buttons.btn_quote_level1_bg), "clicked",
509                          G_CALLBACK(quote_color_set_dialog), "LEVEL1BG");
510         g_signal_connect(G_OBJECT(color_buttons.btn_quote_level2_bg), "clicked",
511                          G_CALLBACK(quote_color_set_dialog), "LEVEL2BG");
512         g_signal_connect(G_OBJECT(color_buttons.btn_quote_level3_bg), "clicked",
513                          G_CALLBACK(quote_color_set_dialog), "LEVEL3BG");
514         g_signal_connect(G_OBJECT(color_buttons.btn_uri), "clicked",
515                          G_CALLBACK(quote_color_set_dialog), "URI");
516         g_signal_connect(G_OBJECT(color_buttons.btn_tgt_folder), "clicked",
517                          G_CALLBACK(quote_color_set_dialog), "TGTFLD");
518         g_signal_connect(G_OBJECT(color_buttons.btn_signature), "clicked",
519                          G_CALLBACK(quote_color_set_dialog), "SIGNATURE");
520         g_signal_connect(G_OBJECT(color_buttons.btn_color_new), "clicked",
521                          G_CALLBACK(quote_color_set_dialog), "NEW");
522         /* custom colors */
523         for (c = 0; c < COLORLABELS; c++) {
524                 g_signal_connect(G_OBJECT(color_buttons.custom_color[c]), "clicked",
525                                  G_CALLBACK(quote_color_set_dialog), GINT_TO_POINTER(c));
526         }
527
528         g_signal_connect(G_OBJECT(btn_reset_custom_colors), "clicked",
529                          G_CALLBACK(prefs_msg_colors_reset_custom_colors), prefs_msg_colors);
530
531         set_button_bg_color(color_buttons.btn_quote_level1,
532                             prefs_common.quote_level1_col);
533         set_button_bg_color(color_buttons.btn_quote_level2,
534                             prefs_common.quote_level2_col);
535         set_button_bg_color(color_buttons.btn_quote_level3,
536                             prefs_common.quote_level3_col);
537         set_button_bg_color(color_buttons.btn_quote_level1_bg,
538                             prefs_common.quote_level1_bgcol);
539         set_button_bg_color(color_buttons.btn_quote_level2_bg,
540                             prefs_common.quote_level2_bgcol);
541         set_button_bg_color(color_buttons.btn_quote_level3_bg,
542                             prefs_common.quote_level3_bgcol);
543         set_button_bg_color(color_buttons.btn_uri,
544                             prefs_common.uri_col);
545         set_button_bg_color(color_buttons.btn_tgt_folder,
546                             prefs_common.tgt_folder_col);
547         set_button_bg_color(color_buttons.btn_signature,
548                             prefs_common.signature_col);
549         set_button_bg_color(color_buttons.btn_color_new,
550                             prefs_common.color_new);
551         /* custom colors */
552         for (c = 0; c < COLORLABELS; c++) {
553                 set_button_bg_color(color_buttons.custom_color[c],
554                                     prefs_common.custom_colorlabel[c].color);
555                 gtk_entry_set_text(GTK_ENTRY (entry_custom_colorlabel[c]), 
556                                    gettext(SAFE_STRING (prefs_common.custom_colorlabel[c].label)));
557         }
558
559         gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(checkbtn_enable_colors),
560                                      prefs_common.enable_color);
561         gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(checkbtn_enable_bgcolors),
562                                      prefs_common.enable_bgcolor);
563         gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(checkbtn_recycle_colors),
564                                      prefs_common.recycle_quote_colors);
565
566         prefs_msg_colors->checkbtn_enable_colors        = checkbtn_enable_colors;
567         prefs_msg_colors->checkbtn_enable_bgcolors      = checkbtn_enable_bgcolors;
568         prefs_msg_colors->checkbtn_recycle_colors       = checkbtn_recycle_colors;
569         /* custom colors */
570         for (c = 0; c < COLORLABELS; c++) {
571                 prefs_msg_colors->entry_custom_colorlabel[c] = entry_custom_colorlabel[c];
572         }
573
574         prefs_msg_colors->page.widget = vbox1;
575 }
576
577 static void quote_color_set_dialog(GtkWidget *widget, gpointer data)
578 {
579         gchar *type = (gchar *)data;
580         gchar *title = NULL;
581         gdouble color[4] = {0.0, 0.0, 0.0, 0.0};
582         gint rgbvalue = 0;
583         GtkColorSelectionDialog *dialog;
584         gint c;
585
586         /* custom colors */
587         /* leave the extra space at the end of the title, this is for translators' convenience */
588         for (c = 0; c < COLORLABELS; c++) {
589                 if (GPOINTER_TO_INT(type) == c) {
590                         /* TRANSLATORS: 'color %d' refers to the filtering/processing 
591                            rule name and should not be translated */
592                         title = g_strdup_printf(Q_("Dialog title|Pick color for 'color %d'"), c+1);
593                         rgbvalue = prefs_common.custom_colorlabel[c].color;
594                         break;
595                 }
596         }
597         /* other colors */
598         if (c == COLORLABELS) {
599                 if(g_ascii_strcasecmp(type, "LEVEL1") == 0) {
600                         title = g_strdup(Q_("Dialog title|Pick color for 1st level text"));
601                         rgbvalue = prefs_common.quote_level1_col;
602                 } else if(g_ascii_strcasecmp(type, "LEVEL2") == 0) {
603                         title = g_strdup(Q_("Dialog title|Pick color for 2nd level text"));
604                         rgbvalue = prefs_common.quote_level2_col;
605                 } else if(g_ascii_strcasecmp(type, "LEVEL3") == 0) {
606                         title = g_strdup(Q_("Dialog title|Pick color for 3rd level text"));
607                         rgbvalue = prefs_common.quote_level3_col;
608                 } else if(g_ascii_strcasecmp(type, "LEVEL1BG") == 0) {
609                         title = g_strdup(Q_("Dialog title|Pick color for 1st level text background"));
610                         rgbvalue = prefs_common.quote_level1_bgcol;
611                 } else if(g_ascii_strcasecmp(type, "LEVEL2BG") == 0) {
612                         title = g_strdup(Q_("Dialog title|Pick color for 2nd level text background"));
613                         rgbvalue = prefs_common.quote_level2_bgcol;
614                 } else if(g_ascii_strcasecmp(type, "LEVEL3BG") == 0) {
615                         title = g_strdup(Q_("Dialog title|Pick color for 3rd level text background"));
616                         rgbvalue = prefs_common.quote_level3_bgcol;
617                 } else if(g_ascii_strcasecmp(type, "URI") == 0) {
618                         title = g_strdup(Q_("Dialog title|Pick color for links"));
619                         rgbvalue = prefs_common.uri_col;
620                 } else if(g_ascii_strcasecmp(type, "TGTFLD") == 0) {
621                         title = g_strdup(Q_("Dialog title|Pick color for target folder"));
622                         rgbvalue = prefs_common.tgt_folder_col;
623                 } else if(g_ascii_strcasecmp(type, "SIGNATURE") == 0) {
624                         title = g_strdup(Q_("Dialog title|Pick color for signatures"));
625                         rgbvalue = prefs_common.signature_col;
626                 } else if(g_ascii_strcasecmp(type, "NEW") == 0) {
627                         title = g_strdup(Q_("Dialog title|Pick color for folder"));
628                         rgbvalue = prefs_common.color_new;
629                 } else {
630                         /* Should never be called */
631                         g_warning("Unrecognized datatype '%s' in quote_color_set_dialog\n", type);
632                         return;
633                 }
634         }
635
636         color_dialog = gtk_color_selection_dialog_new(title);
637         g_free(title);
638         gtk_window_set_position(GTK_WINDOW(color_dialog), GTK_WIN_POS_CENTER);
639         gtk_window_set_modal(GTK_WINDOW(color_dialog), TRUE);
640         gtk_window_set_resizable(GTK_WINDOW(color_dialog), FALSE);
641         manage_window_set_transient(GTK_WINDOW(color_dialog));
642
643         g_signal_connect(G_OBJECT(GTK_COLOR_SELECTION_DIALOG(color_dialog)->cancel_button),
644                          "clicked", G_CALLBACK(quote_colors_set_dialog_cancel), data);
645         g_signal_connect(G_OBJECT(GTK_COLOR_SELECTION_DIALOG(color_dialog)->ok_button),
646                          "clicked", G_CALLBACK(quote_colors_set_dialog_ok), data);
647         g_signal_connect(G_OBJECT(color_dialog), "key_press_event",
648                          G_CALLBACK(quote_colors_set_dialog_key_pressed),data);
649
650         /* preselect the previous color in the color selection dialog */
651         color[0] = (gdouble) ((rgbvalue & 0xff0000) >> 16) / 255.0;
652         color[1] = (gdouble) ((rgbvalue & 0x00ff00) >>  8) / 255.0;
653         color[2] = (gdouble)  (rgbvalue & 0x0000ff)        / 255.0;
654         dialog = GTK_COLOR_SELECTION_DIALOG(color_dialog);
655         gtk_color_selection_set_color
656                 (GTK_COLOR_SELECTION(dialog->colorsel), color);
657
658         gtk_widget_show(color_dialog);
659 }
660
661 static void quote_colors_set_dialog_ok(GtkWidget *widget, gpointer data)
662 {
663         GtkColorSelection *colorsel = (GtkColorSelection *)
664                                                 ((GtkColorSelectionDialog *)color_dialog)->colorsel;
665         gdouble color[4];
666         gint red, green, blue, rgbvalue;
667         gchar *type = (gchar *)data;
668         gint c;
669
670         gtk_color_selection_get_color(colorsel, color);
671
672         red      = (gint) (color[0] * 255.0);
673         green    = (gint) (color[1] * 255.0);
674         blue     = (gint) (color[2] * 255.0);
675         rgbvalue = (gint) ((red * 0x10000) | (green * 0x100) | blue);
676
677
678         /* custom colors */
679         for (c = 0; c < COLORLABELS; c++) {
680                 if (GPOINTER_TO_INT(type) == c) {
681                         prefs_common.custom_colorlabel[c].color = rgbvalue;
682                         set_button_bg_color(color_buttons.custom_color[c], rgbvalue);
683                         break;
684                 }
685         }
686         /* other colors */
687         if (c == COLORLABELS) {
688                 if (g_ascii_strcasecmp(type, "LEVEL1") == 0) {
689                         prefs_common.quote_level1_col = rgbvalue;
690                         set_button_bg_color(color_buttons.btn_quote_level1, rgbvalue);
691                 } else if (g_ascii_strcasecmp(type, "LEVEL2") == 0) {
692                         prefs_common.quote_level2_col = rgbvalue;
693                         set_button_bg_color(color_buttons.btn_quote_level2, rgbvalue);
694                 } else if (g_ascii_strcasecmp(type, "LEVEL3") == 0) {
695                         prefs_common.quote_level3_col = rgbvalue;
696                         set_button_bg_color(color_buttons.btn_quote_level3, rgbvalue);
697                 } else if (g_ascii_strcasecmp(type, "LEVEL1BG") == 0) {
698                         prefs_common.quote_level1_bgcol = rgbvalue;
699                         set_button_bg_color(color_buttons.btn_quote_level1_bg, rgbvalue);
700                 } else if (g_ascii_strcasecmp(type, "LEVEL2BG") == 0) {
701                         prefs_common.quote_level2_bgcol = rgbvalue;
702                         set_button_bg_color(color_buttons.btn_quote_level2_bg, rgbvalue);
703                 } else if (g_ascii_strcasecmp(type, "LEVEL3BG") == 0) {
704                         prefs_common.quote_level3_bgcol = rgbvalue;
705                         set_button_bg_color(color_buttons.btn_quote_level3_bg, rgbvalue);
706                 } else if (g_ascii_strcasecmp(type, "URI") == 0) {
707                         prefs_common.uri_col = rgbvalue;
708                         set_button_bg_color(color_buttons.btn_uri, rgbvalue);
709                 } else if (g_ascii_strcasecmp(type, "TGTFLD") == 0) {
710                         prefs_common.tgt_folder_col = rgbvalue;
711                         set_button_bg_color(color_buttons.btn_tgt_folder, rgbvalue);
712                         folderview_set_target_folder_color(prefs_common.tgt_folder_col);
713                 } else if (g_ascii_strcasecmp(type, "SIGNATURE") == 0) {
714                         prefs_common.signature_col = rgbvalue;
715                         set_button_bg_color(color_buttons.btn_signature, rgbvalue);
716                 } else if (g_ascii_strcasecmp(type, "NEW") == 0) {
717                         prefs_common.color_new = rgbvalue;
718                         set_button_bg_color(color_buttons.btn_color_new, rgbvalue);
719                 } else {
720                         fprintf(stderr, "Unrecognized datatype '%s' in quote_color_set_dialog_ok\n", type);
721                 }
722         }
723
724         gtk_widget_destroy(color_dialog);
725 }
726
727 static void quote_colors_set_dialog_cancel(GtkWidget *widget, gpointer data)
728 {
729         gtk_widget_destroy(color_dialog);
730 }
731
732 static gboolean quote_colors_set_dialog_key_pressed(GtkWidget *widget,
733                                                 GdkEventKey *event,
734                                                 gpointer data)
735 {
736         if (event) {
737                 switch (event->keyval) {
738                         case GDK_Escape:
739                                 gtk_button_clicked(GTK_BUTTON(GTK_COLOR_SELECTION_DIALOG
740                                                         (widget)->cancel_button));
741                                 return TRUE;
742                         case GDK_Return: 
743                         case GDK_KP_Enter:
744                                 /* NOTE: changing focus makes widget accept all currently 
745                                  * changed settings! */
746                                 gtk_widget_grab_focus
747                                         (GTK_COLOR_SELECTION_DIALOG
748                                                 (widget)->ok_button);
749                                 /* call ok handler */                                           
750                                 gtk_button_clicked(GTK_BUTTON
751                                         (GTK_COLOR_SELECTION_DIALOG
752                                                 (widget)->ok_button));
753                                 return TRUE;
754                         default:
755                                 break;
756                 }
757         }
758         return FALSE;
759 }
760
761 static void set_button_bg_color(GtkWidget *widget, gint rgbvalue)
762 {
763         GtkStyle *newstyle;
764         GdkColor color;
765
766         gtkut_convert_int_to_gdk_color(rgbvalue, &color);
767         newstyle = gtk_style_copy(gtk_widget_get_default_style());
768         newstyle->bg[GTK_STATE_NORMAL]   = color;
769         newstyle->bg[GTK_STATE_PRELIGHT] = color;
770         newstyle->bg[GTK_STATE_ACTIVE]   = color;
771
772         gtk_widget_set_style(GTK_WIDGET(widget), newstyle);
773 }
774
775 static void prefs_msg_colors_save(PrefsPage *_page)
776 {
777         MsgColorsPage *page = (MsgColorsPage *) _page;
778         gint c;
779
780         prefs_common.enable_color = 
781                 gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(page->checkbtn_enable_colors));
782         prefs_common.enable_bgcolor = 
783                 gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(page->checkbtn_enable_bgcolors));
784         prefs_common.recycle_quote_colors =
785                 gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(page->checkbtn_recycle_colors));
786
787         /* custom colors */
788         for (c = 0; c < COLORLABELS; c++) {
789                 g_free(prefs_common.custom_colorlabel[c].label);
790                 prefs_common.custom_colorlabel[c].label =
791                         gtk_editable_get_chars(GTK_EDITABLE(page->entry_custom_colorlabel[c]), 0, -1);
792         }
793         colorlabel_update_colortable_from_prefs();
794
795         main_window_reflect_prefs_all();
796         main_window_reflect_prefs_custom_colors(mainwindow_get_mainwindow());
797 }
798
799 static void prefs_msg_colors_reset_custom_colors(GtkWidget *widget, gpointer data)
800 {
801 #define CL(x)           (((gulong) (x) >> (gulong) 8) & 0xFFUL) 
802 #define CR(r, g, b)     ((CL(r) << (gulong) 16) | \
803                          (CL(g) << (gulong)  8) | \
804                          (CL(b)))
805         MsgColorsPage *page = (MsgColorsPage *) data;
806         GdkColor color;
807         gint c;
808
809         for (c = 0; c < COLORLABELS; c++) {
810                 color = colorlabel_get_default_color(c);
811                 prefs_common.custom_colorlabel[c].color =
812                                                         (gint)CR(color.red, color.green, color.blue);
813                 set_button_bg_color(color_buttons.custom_color[c],
814                                                         prefs_common.custom_colorlabel[c].color);
815                 gtk_entry_set_text(GTK_ENTRY (page->entry_custom_colorlabel[c]),
816                                                         gettext(SAFE_STRING (colorlabel_get_color_default_text(c))));
817         }
818
819 #undef CR
820 #undef CL
821 }
822
823 static void prefs_msg_colors_destroy_widget(PrefsPage *_page)
824 {
825 }
826
827 MsgColorsPage *prefs_msg_colors;
828
829 void prefs_msg_colors_init(void)
830 {
831         MsgColorsPage *page;
832         static gchar *path[3];
833
834         path[0] = _("Display");
835         path[1] = _("Colors");
836         path[2] = NULL;
837
838         page = g_new0(MsgColorsPage, 1);
839         page->page.path = path;
840         page->page.create_widget = prefs_msg_colors_create_widget;
841         page->page.destroy_widget = prefs_msg_colors_destroy_widget;
842         page->page.save_page = prefs_msg_colors_save;
843         page->page.weight = 165.0;
844         prefs_gtk_register_page((PrefsPage *) page);
845         prefs_msg_colors = page;
846 }
847
848 void prefs_msg_colors_done(void)
849 {
850         prefs_gtk_unregister_page((PrefsPage *) prefs_msg_colors);
851         g_free(prefs_msg_colors);
852 }
853