2007-01-13 [colin] 2.7.0cvs21
[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 *chkbtn_enable_colors;
69         GtkWidget *chkbtn_enable_bgcolors;
70         GtkWidget *chkbtn_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 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 *chkbtn_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 *chkbtn_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 *chkbtn_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, chkbtn_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, chkbtn_recycle_colors,
171                            _("Cycle quote colors"));
172         SET_TOGGLE_SENSITIVITY(chkbtn_enable_colors, chkbtn_recycle_colors);
173         tooltips = gtk_tooltips_new();
174         gtk_tooltips_set_tip(tooltips, chkbtn_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(chkbtn_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(chkbtn_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(chkbtn_enable_colors, color_buttons.btn_quote_level1);
200         tooltips = gtk_tooltips_new();
201         gtk_tooltips_set_tip(tooltips, color_buttons.btn_quote_level1,
202                              _("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(chkbtn_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(chkbtn_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(chkbtn_enable_colors, color_buttons.btn_quote_level2);
226         tooltips = gtk_tooltips_new();
227         gtk_tooltips_set_tip(tooltips, color_buttons.btn_quote_level2,
228                              _("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(chkbtn_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(chkbtn_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(chkbtn_enable_colors, color_buttons.btn_quote_level3);
252         tooltips = gtk_tooltips_new();
253         gtk_tooltips_set_tip(tooltips, color_buttons.btn_quote_level3,
254                              _("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, chkbtn_enable_bgcolors,
261                            _("Enable coloration of text background"));
262         SET_TOGGLE_SENSITIVITY(chkbtn_enable_colors, chkbtn_enable_bgcolors);
263
264         hbox = gtk_hbox_new(FALSE, 8);
265         gtk_widget_show (hbox);
266         SET_TOGGLE_SENSITIVITY(chkbtn_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(chkbtn_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                              _("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(chkbtn_enable_bgcolors, label_quote_bgcolor1);
284
285         hbox = gtk_hbox_new(FALSE, 8);
286         gtk_widget_show (hbox);
287         SET_TOGGLE_SENSITIVITY(chkbtn_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(chkbtn_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                              _("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(chkbtn_enable_bgcolors, label_quote_bgcolor2);
305
306         hbox = gtk_hbox_new(FALSE, 8);
307         gtk_widget_show (hbox);
308         SET_TOGGLE_SENSITIVITY(chkbtn_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(chkbtn_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                              _("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(chkbtn_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(chkbtn_enable_colors, color_buttons.btn_uri);
337         tooltips = gtk_tooltips_new();
338         gtk_tooltips_set_tip(tooltips, color_buttons.btn_uri,
339                              _("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(chkbtn_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(chkbtn_enable_colors, color_buttons.btn_signature);
356         tooltips = gtk_tooltips_new();
357         gtk_tooltips_set_tip(tooltips, color_buttons.btn_signature,
358                              _("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(chkbtn_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(chkbtn_enable_colors),
560                                      prefs_common.enable_color);
561         gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(chkbtn_enable_bgcolors),
562                                      prefs_common.enable_bgcolor);
563         gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(chkbtn_recycle_colors),
564                                      prefs_common.recycle_quote_colors);
565
566         prefs_msg_colors->chkbtn_enable_colors  = chkbtn_enable_colors;
567         prefs_msg_colors->chkbtn_enable_bgcolors        = chkbtn_enable_bgcolors;
568         prefs_msg_colors->chkbtn_recycle_colors = chkbtn_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         /* leave the extra space at the end of the titles, this is for translators' convenience */
599         if (c == COLORLABELS) {
600                 if(g_ascii_strcasecmp(type, "LEVEL1") == 0) {
601                         title = g_strdup(_("Pick color for 1st level text "));
602                         rgbvalue = prefs_common.quote_level1_col;
603                 } else if(g_ascii_strcasecmp(type, "LEVEL2") == 0) {
604                         title = g_strdup(_("Pick color for 2nd level text "));
605                         rgbvalue = prefs_common.quote_level2_col;
606                 } else if(g_ascii_strcasecmp(type, "LEVEL3") == 0) {
607                         title = g_strdup(_("Pick color for 3rd level text "));
608                         rgbvalue = prefs_common.quote_level3_col;
609                 } else if(g_ascii_strcasecmp(type, "LEVEL1BG") == 0) {
610                         title = g_strdup(_("Pick color for 1st level text background "));
611                         rgbvalue = prefs_common.quote_level1_bgcol;
612                 } else if(g_ascii_strcasecmp(type, "LEVEL2BG") == 0) {
613                         title = g_strdup(_("Pick color for 2nd level text background "));
614                         rgbvalue = prefs_common.quote_level2_bgcol;
615                 } else if(g_ascii_strcasecmp(type, "LEVEL3BG") == 0) {
616                         title = g_strdup(_("Pick color for 3rd level text background "));
617                         rgbvalue = prefs_common.quote_level3_bgcol;
618                 } else if(g_ascii_strcasecmp(type, "URI") == 0) {
619                         title = g_strdup(_("Pick color for links "));
620                         rgbvalue = prefs_common.uri_col;
621                 } else if(g_ascii_strcasecmp(type, "TGTFLD") == 0) {
622                         title = g_strdup(_("Pick color for target folder"));
623                         rgbvalue = prefs_common.tgt_folder_col;
624                 } else if(g_ascii_strcasecmp(type, "SIGNATURE") == 0) {
625                         title = g_strdup(_("Pick color for signatures "));
626                         rgbvalue = prefs_common.signature_col;
627                 } else if(g_ascii_strcasecmp(type, "NEW") == 0) {
628                         title = g_strdup(_("Pick color for folder"));
629                         rgbvalue = prefs_common.color_new;
630                 } else {
631                         /* Should never be called */
632                         g_warning("Unrecognized datatype '%s' in quote_color_set_dialog\n", type);
633                         return;
634                 }
635         }
636
637         color_dialog = gtk_color_selection_dialog_new(title);
638         g_free(title);
639         gtk_window_set_position(GTK_WINDOW(color_dialog), GTK_WIN_POS_CENTER);
640         gtk_window_set_modal(GTK_WINDOW(color_dialog), TRUE);
641         gtk_window_set_resizable(GTK_WINDOW(color_dialog), FALSE);
642         manage_window_set_transient(GTK_WINDOW(color_dialog));
643
644         g_signal_connect(G_OBJECT(GTK_COLOR_SELECTION_DIALOG(color_dialog)->cancel_button),
645                          "clicked", G_CALLBACK(quote_colors_set_dialog_cancel), data);
646         g_signal_connect(G_OBJECT(GTK_COLOR_SELECTION_DIALOG(color_dialog)->ok_button),
647                          "clicked", G_CALLBACK(quote_colors_set_dialog_ok), data);
648         g_signal_connect(G_OBJECT(color_dialog), "key_press_event",
649                          G_CALLBACK(quote_colors_set_dialog_key_pressed),data);
650
651         /* preselect the previous color in the color selection dialog */
652         color[0] = (gdouble) ((rgbvalue & 0xff0000) >> 16) / 255.0;
653         color[1] = (gdouble) ((rgbvalue & 0x00ff00) >>  8) / 255.0;
654         color[2] = (gdouble)  (rgbvalue & 0x0000ff)        / 255.0;
655         dialog = GTK_COLOR_SELECTION_DIALOG(color_dialog);
656         gtk_color_selection_set_color
657                 (GTK_COLOR_SELECTION(dialog->colorsel), color);
658
659         gtk_widget_show(color_dialog);
660 }
661
662 static void quote_colors_set_dialog_ok(GtkWidget *widget, gpointer data)
663 {
664         GtkColorSelection *colorsel = (GtkColorSelection *)
665                                                 ((GtkColorSelectionDialog *)color_dialog)->colorsel;
666         gdouble color[4];
667         gint red, green, blue, rgbvalue;
668         gchar *type = (gchar *)data;
669         gint c;
670
671         gtk_color_selection_get_color(colorsel, color);
672
673         red      = (gint) (color[0] * 255.0);
674         green    = (gint) (color[1] * 255.0);
675         blue     = (gint) (color[2] * 255.0);
676         rgbvalue = (gint) ((red * 0x10000) | (green * 0x100) | blue);
677
678
679         /* custom colors */
680         for (c = 0; c < COLORLABELS; c++) {
681                 if (GPOINTER_TO_INT(type) == c) {
682                         prefs_common.custom_colorlabel[c].color = rgbvalue;
683                         set_button_bg_color(color_buttons.custom_color[c], rgbvalue);
684                         break;
685                 }
686         }
687         /* other colors */
688         if (c == COLORLABELS) {
689                 if (g_ascii_strcasecmp(type, "LEVEL1") == 0) {
690                         prefs_common.quote_level1_col = rgbvalue;
691                         set_button_bg_color(color_buttons.btn_quote_level1, rgbvalue);
692                 } else if (g_ascii_strcasecmp(type, "LEVEL2") == 0) {
693                         prefs_common.quote_level2_col = rgbvalue;
694                         set_button_bg_color(color_buttons.btn_quote_level2, rgbvalue);
695                 } else if (g_ascii_strcasecmp(type, "LEVEL3") == 0) {
696                         prefs_common.quote_level3_col = rgbvalue;
697                         set_button_bg_color(color_buttons.btn_quote_level3, rgbvalue);
698                 } else if (g_ascii_strcasecmp(type, "LEVEL1BG") == 0) {
699                         prefs_common.quote_level1_bgcol = rgbvalue;
700                         set_button_bg_color(color_buttons.btn_quote_level1_bg, rgbvalue);
701                 } else if (g_ascii_strcasecmp(type, "LEVEL2BG") == 0) {
702                         prefs_common.quote_level2_bgcol = rgbvalue;
703                         set_button_bg_color(color_buttons.btn_quote_level2_bg, rgbvalue);
704                 } else if (g_ascii_strcasecmp(type, "LEVEL3BG") == 0) {
705                         prefs_common.quote_level3_bgcol = rgbvalue;
706                         set_button_bg_color(color_buttons.btn_quote_level3_bg, rgbvalue);
707                 } else if (g_ascii_strcasecmp(type, "URI") == 0) {
708                         prefs_common.uri_col = rgbvalue;
709                         set_button_bg_color(color_buttons.btn_uri, rgbvalue);
710                 } else if (g_ascii_strcasecmp(type, "TGTFLD") == 0) {
711                         prefs_common.tgt_folder_col = rgbvalue;
712                         set_button_bg_color(color_buttons.btn_tgt_folder, rgbvalue);
713                         folderview_set_target_folder_color(prefs_common.tgt_folder_col);
714                 } else if (g_ascii_strcasecmp(type, "SIGNATURE") == 0) {
715                         prefs_common.signature_col = rgbvalue;
716                         set_button_bg_color(color_buttons.btn_signature, rgbvalue);
717                 } else if (g_ascii_strcasecmp(type, "NEW") == 0) {
718                         prefs_common.color_new = rgbvalue;
719                         set_button_bg_color(color_buttons.btn_color_new, rgbvalue);
720                 } else {
721                         fprintf(stderr, "Unrecognized datatype '%s' in quote_color_set_dialog_ok\n", type);
722                 }
723         }
724
725         gtk_widget_destroy(color_dialog);
726 }
727
728 static void quote_colors_set_dialog_cancel(GtkWidget *widget, gpointer data)
729 {
730         gtk_widget_destroy(color_dialog);
731 }
732
733 static gboolean quote_colors_set_dialog_key_pressed(GtkWidget *widget,
734                                                 GdkEventKey *event,
735                                                 gpointer data)
736 {
737         if (event) {
738                 switch (event->keyval) {
739                         case GDK_Escape:
740                                 gtk_button_clicked(GTK_BUTTON(GTK_COLOR_SELECTION_DIALOG
741                                                         (widget)->cancel_button));
742                                 return TRUE;
743                         case GDK_Return: 
744                         case GDK_KP_Enter:
745                                 /* NOTE: changing focus makes widget accept all currently 
746                                  * changed settings! */
747                                 gtk_widget_grab_focus
748                                         (GTK_COLOR_SELECTION_DIALOG
749                                                 (widget)->ok_button);
750                                 /* call ok handler */                                           
751                                 gtk_button_clicked(GTK_BUTTON
752                                         (GTK_COLOR_SELECTION_DIALOG
753                                                 (widget)->ok_button));
754                                 return TRUE;
755                         default:
756                                 break;
757                 }
758         }
759         return FALSE;
760 }
761
762 static void set_button_bg_color(GtkWidget *widget, gint rgbvalue)
763 {
764         GtkStyle *newstyle;
765         GdkColor color;
766
767         gtkut_convert_int_to_gdk_color(rgbvalue, &color);
768         newstyle = gtk_style_copy(gtk_widget_get_default_style());
769         newstyle->bg[GTK_STATE_NORMAL]   = color;
770         newstyle->bg[GTK_STATE_PRELIGHT] = color;
771         newstyle->bg[GTK_STATE_ACTIVE]   = color;
772
773         gtk_widget_set_style(GTK_WIDGET(widget), newstyle);
774 }
775
776 void prefs_msg_colors_save(PrefsPage *_page)
777 {
778         MsgColorsPage *page = (MsgColorsPage *) _page;
779         gint c;
780
781         prefs_common.enable_color = 
782                 gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(page->chkbtn_enable_colors));
783         prefs_common.enable_bgcolor = 
784                 gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(page->chkbtn_enable_bgcolors));
785         prefs_common.recycle_quote_colors =
786                 gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(page->chkbtn_recycle_colors));
787
788         /* custom colors */
789         for (c = 0; c < COLORLABELS; c++) {
790                 g_free(prefs_common.custom_colorlabel[c].label);
791                 prefs_common.custom_colorlabel[c].label =
792                         gtk_editable_get_chars(GTK_EDITABLE(page->entry_custom_colorlabel[c]), 0, -1);
793         }
794         colorlabel_update_colortable_from_prefs();
795
796         main_window_reflect_prefs_all();
797         main_window_reflect_prefs_custom_colors(mainwindow_get_mainwindow());
798 }
799
800 static void prefs_msg_colors_reset_custom_colors(GtkWidget *widget, gpointer data)
801 {
802 #define CL(x)           (((gulong) (x) >> (gulong) 8) & 0xFFUL) 
803 #define CR(r, g, b)     ((CL(r) << (gulong) 16) | \
804                          (CL(g) << (gulong)  8) | \
805                          (CL(b)))
806         MsgColorsPage *page = (MsgColorsPage *) data;
807         GdkColor color;
808         gint c;
809
810         for (c = 0; c < COLORLABELS; c++) {
811                 color = colorlabel_get_default_color(c);
812                 prefs_common.custom_colorlabel[c].color =
813                                                         (gint)CR(color.red, color.green, color.blue);
814                 set_button_bg_color(color_buttons.custom_color[c],
815                                                         prefs_common.custom_colorlabel[c].color);
816                 gtk_entry_set_text(GTK_ENTRY (page->entry_custom_colorlabel[c]),
817                                                         gettext(SAFE_STRING (colorlabel_get_color_default_text(c))));
818         }
819
820 #undef CR
821 #undef CL
822 }
823
824 static void prefs_msg_colors_destroy_widget(PrefsPage *_page)
825 {
826 }
827
828 MsgColorsPage *prefs_msg_colors;
829
830 void prefs_msg_colors_init(void)
831 {
832         MsgColorsPage *page;
833         static gchar *path[3];
834
835         path[0] = _("Display");
836         path[1] = _("Colors");
837         path[2] = NULL;
838
839         page = g_new0(MsgColorsPage, 1);
840         page->page.path = path;
841         page->page.create_widget = prefs_msg_colors_create_widget;
842         page->page.destroy_widget = prefs_msg_colors_destroy_widget;
843         page->page.save_page = prefs_msg_colors_save;
844         page->page.weight = 165.0;
845         prefs_gtk_register_page((PrefsPage *) page);
846         prefs_msg_colors = page;
847 }
848
849 void prefs_msg_colors_done(void)
850 {
851         prefs_gtk_unregister_page((PrefsPage *) prefs_msg_colors);
852         g_free(prefs_msg_colors);
853 }
854