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