Fix bug #3574: Template addressing
[claws.git] / src / prefs_msg_colors.c
blob79ca3832caaf297e3ae96622c3338d1c9c0dd935
1 /*
2 * Sylpheed -- a GTK+ based, lightweight, and fast e-mail client
3 * Copyright (C) 2004-2012 Hiroyuki Yamamoto & The Claws Mail Team
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 3 of the License, or
8 * (at your option) any later version.
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.
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
20 #ifdef HAVE_CONFIG_H
21 # include "config.h"
22 #include "claws-features.h"
23 #endif
25 #include "defs.h"
27 #include <stdio.h>
28 #include <stdlib.h>
30 #include <glib.h>
31 #include <glib/gi18n.h>
32 #include <gtk/gtk.h>
33 #include <gdk/gdkkeysyms.h>
35 #include "prefs_common.h"
36 #include "prefs_gtk.h"
38 #include "gtk/gtkutils.h"
39 #include "gtk/prefswindow.h"
41 #include "manage_window.h"
42 #include "mainwindow.h"
43 #include "colorlabel.h"
45 #define SAFE_STRING(str) \
46 (str) ? (str) : ""
48 static struct MessageColorButtons {
49 GtkWidget *btn_quote_level1;
50 GtkWidget *btn_quote_level2;
51 GtkWidget *btn_quote_level3;
52 GtkWidget *btn_quote_level1_bg;
53 GtkWidget *btn_quote_level2_bg;
54 GtkWidget *btn_quote_level3_bg;
55 GtkWidget *btn_uri;
56 GtkWidget *btn_tgt_folder;
57 GtkWidget *btn_signature;
58 GtkWidget *btn_color_new;
59 /* custom colors */
60 GtkWidget *custom_color[COLORLABELS];
61 } color_buttons;
63 typedef struct _MsgColorsPage
65 PrefsPage page;
67 GtkWidget *window;
69 GtkWidget *checkbtn_enable_colors;
70 GtkWidget *checkbtn_enable_bgcolors;
71 GtkWidget *checkbtn_recycle_colors;
73 /* custom colors */
74 GtkWidget *entry_custom_colorlabel[COLORLABELS];
75 } MsgColorsPage;
77 static GtkWidget *color_dialog;
79 static void quote_color_set_dialog (GtkWidget *widget,
80 gpointer data);
81 static void quote_colors_set_dialog_ok (GtkWidget *widget,
82 gpointer data);
83 static void quote_colors_set_dialog_cancel (GtkWidget *widget,
84 gpointer data);
85 static gboolean quote_colors_set_dialog_key_pressed (GtkWidget *widget,
86 GdkEventKey *event,
87 gpointer data);
88 static void set_button_bg_color (GtkWidget *widget,
89 gint color);
90 static void prefs_msg_colors_reset_custom_colors(GtkWidget *widget,
91 gpointer data);
93 static void prefs_msg_colors_create_widget(PrefsPage *_page, GtkWindow *window,
94 gpointer data)
96 MsgColorsPage *prefs_msg_colors = (MsgColorsPage *) _page;
98 GtkWidget *notebook;
99 GtkWidget *vbox1;
100 GtkWidget *vbox2;
101 GtkWidget *checkbtn_enable_colors;
102 GtkWidget *label_quote_level1;
103 GtkWidget *label_quote_level2;
104 GtkWidget *label_quote_level3;
105 GtkWidget *label_quote_color1;
106 GtkWidget *label_quote_color2;
107 GtkWidget *label_quote_color3;
108 GtkWidget *checkbtn_enable_bgcolors;
109 GtkWidget *label_quote_bgcolor1;
110 GtkWidget *label_quote_bgcolor2;
111 GtkWidget *label_quote_bgcolor3;
112 GtkWidget *lable_uri;
113 GtkWidget *label_signature;
114 GtkWidget *label_tgt_folder;
115 GtkWidget *checkbtn_recycle_colors;
116 GtkWidget *hbox;
117 GtkWidget *label_color_new;
118 GtkWidget *frame_msg;
119 GtkWidget *frame_folder;
120 GtkWidget *frame_quote;
121 GtkWidget *vbox3;
122 GtkWidget *hbox_quote;
123 GtkWidget *vbox_quotefg;
124 GtkWidget *vbox_quotebg;
125 /* custom colors */
126 GtkWidget *hbox_custom_colors;
127 GtkWidget *vbox_custom_colors;
128 GtkWidget *vbox_custom_colors1;
129 GtkWidget *vbox_custom_colors2;
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 gchar *tooltip_btn_text = NULL;
136 gchar *tooltip_entry_text = NULL;
138 notebook = gtk_notebook_new();
139 gtk_widget_show(notebook);
141 vbox1 = gtk_vbox_new (FALSE, VBOX_BORDER);
142 gtk_widget_show (vbox1);
143 gtk_container_set_border_width (GTK_CONTAINER (vbox1), VBOX_BORDER);
144 gtk_notebook_append_page(GTK_NOTEBOOK(notebook), vbox1,
145 gtk_label_new(_("Other")));
147 vbox2 = gtkut_get_options_frame(vbox1, &frame_msg, _("Message view"));
149 hbox = gtk_hbox_new(FALSE, VBOX_BORDER);
150 gtk_widget_show (hbox);
152 gtk_box_pack_start (GTK_BOX (vbox2), hbox, FALSE, TRUE, 0);
153 PACK_CHECK_BUTTON (hbox, checkbtn_enable_colors,
154 _("Enable coloration of message text"));
156 hbox_quote = gtk_hbox_new(FALSE, VBOX_BORDER);
157 gtk_widget_show (hbox_quote);
158 vbox_quotefg = gtk_vbox_new(FALSE, VBOX_BORDER);
159 gtk_widget_show (vbox_quotefg);
160 vbox_quotebg = gtk_vbox_new(FALSE, VBOX_BORDER);
161 gtk_widget_show (vbox_quotebg);
162 vbox3 = gtkut_get_options_frame(vbox2, &frame_quote, _("Quote"));
163 SET_TOGGLE_SENSITIVITY(checkbtn_enable_colors, frame_quote);
165 gtk_box_pack_start (GTK_BOX (vbox3), hbox_quote, FALSE, TRUE, 0);
166 gtk_box_pack_start (GTK_BOX (hbox_quote), vbox_quotefg, FALSE, TRUE, 0);
167 gtk_box_pack_start (GTK_BOX (hbox_quote), vbox_quotebg, FALSE, TRUE, 0);
169 hbox = gtk_hbox_new(FALSE, VBOX_BORDER);
170 gtk_widget_show (hbox);
171 gtk_box_pack_start (GTK_BOX (vbox_quotefg), hbox, FALSE, TRUE, 0);
173 PACK_CHECK_BUTTON (hbox, checkbtn_recycle_colors,
174 _("Cycle quote colors"));
175 SET_TOGGLE_SENSITIVITY(checkbtn_enable_colors, checkbtn_recycle_colors);
177 CLAWS_SET_TIP(checkbtn_recycle_colors,
178 _("If there are more than 3 quote levels, the colors will be reused"));
180 hbox = gtk_hbox_new(FALSE, VBOX_BORDER);
181 gtk_widget_show (hbox);
182 gtk_box_pack_start (GTK_BOX (vbox_quotefg), hbox, FALSE, TRUE, 0);
184 label_quote_level1 = gtk_label_new (_("1st Level"));
185 gtk_widget_show(label_quote_level1);
186 gtk_box_pack_start (GTK_BOX(hbox), label_quote_level1,
187 FALSE, FALSE, 0);
188 SET_TOGGLE_SENSITIVITY(checkbtn_enable_colors, label_quote_level1);
190 label_quote_color1 = gtk_label_new (_("Text"));
191 gtk_widget_show(label_quote_color1);
192 gtk_box_pack_end (GTK_BOX(hbox), label_quote_color1,
193 FALSE, FALSE, 0);
194 SET_TOGGLE_SENSITIVITY(checkbtn_enable_colors, label_quote_color1);
196 color_buttons.btn_quote_level1 = gtk_button_new();
197 gtk_widget_show(color_buttons.btn_quote_level1);
198 gtk_widget_set_size_request (color_buttons.btn_quote_level1, 30, 20);
199 gtk_box_pack_end (GTK_BOX(hbox), color_buttons.btn_quote_level1,
200 FALSE, FALSE, 0);
201 SET_TOGGLE_SENSITIVITY(checkbtn_enable_colors, color_buttons.btn_quote_level1);
203 CLAWS_SET_TIP(color_buttons.btn_quote_level1,
204 C_("Tooltip", "Pick color for 1st level text"));
206 hbox = gtk_hbox_new(FALSE, VBOX_BORDER);
207 gtk_widget_show (hbox);
208 gtk_box_pack_start (GTK_BOX (vbox_quotefg), hbox, FALSE, TRUE, 0);
210 label_quote_level2 = gtk_label_new (_("2nd Level"));
211 gtk_widget_show(label_quote_level2);
212 gtk_box_pack_start (GTK_BOX(hbox), label_quote_level2,
213 FALSE, FALSE, 0);
214 SET_TOGGLE_SENSITIVITY(checkbtn_enable_colors, label_quote_level2);
216 label_quote_color2 = gtk_label_new (_("Text"));
217 gtk_widget_show(label_quote_color2);
218 gtk_box_pack_end (GTK_BOX(hbox), label_quote_color2,
219 FALSE, FALSE, 0);
220 SET_TOGGLE_SENSITIVITY(checkbtn_enable_colors, label_quote_color2);
222 color_buttons.btn_quote_level2 = gtk_button_new();
223 gtk_widget_show(color_buttons.btn_quote_level2);
224 gtk_widget_set_size_request (color_buttons.btn_quote_level2, 30, 20);
225 gtk_box_pack_end (GTK_BOX(hbox), color_buttons.btn_quote_level2,
226 FALSE, FALSE, 0);
227 SET_TOGGLE_SENSITIVITY(checkbtn_enable_colors, color_buttons.btn_quote_level2);
229 CLAWS_SET_TIP(color_buttons.btn_quote_level2,
230 C_("Tooltip", "Pick color for 2nd level text"));
232 hbox = gtk_hbox_new(FALSE, VBOX_BORDER);
233 gtk_widget_show (hbox);
234 gtk_box_pack_start (GTK_BOX (vbox_quotefg), hbox, FALSE, TRUE, 0);
236 label_quote_level3 = gtk_label_new (_("3rd Level"));
237 gtk_widget_show(label_quote_level3);
238 gtk_box_pack_start (GTK_BOX(hbox), label_quote_level3,
239 FALSE, FALSE, 0);
240 SET_TOGGLE_SENSITIVITY(checkbtn_enable_colors, label_quote_level3);
242 label_quote_color3 = gtk_label_new (_("Text"));
243 gtk_widget_show(label_quote_color3);
244 gtk_box_pack_end (GTK_BOX(hbox), label_quote_color3,
245 FALSE, FALSE, 0);
246 SET_TOGGLE_SENSITIVITY(checkbtn_enable_colors, label_quote_color3);
248 color_buttons.btn_quote_level3 = gtk_button_new();
249 gtk_widget_show(color_buttons.btn_quote_level3);
250 gtk_widget_set_size_request (color_buttons.btn_quote_level3, 30, 20);
251 gtk_box_pack_end (GTK_BOX(hbox), color_buttons.btn_quote_level3,
252 FALSE, FALSE, 0);
253 SET_TOGGLE_SENSITIVITY(checkbtn_enable_colors, color_buttons.btn_quote_level3);
255 CLAWS_SET_TIP(color_buttons.btn_quote_level3,
256 C_("Tooltip", "Pick color for 3rd level text"));
258 hbox = gtk_hbox_new(FALSE, VBOX_BORDER);
259 gtk_widget_show (hbox);
260 gtk_box_pack_start (GTK_BOX (vbox_quotebg), hbox, FALSE, TRUE, 0);
262 PACK_CHECK_BUTTON (hbox, checkbtn_enable_bgcolors,
263 _("Enable coloration of text background"));
264 SET_TOGGLE_SENSITIVITY(checkbtn_enable_colors, checkbtn_enable_bgcolors);
266 hbox = gtk_hbox_new(FALSE, VBOX_BORDER);
267 gtk_widget_show (hbox);
268 SET_TOGGLE_SENSITIVITY(checkbtn_enable_colors, hbox);
269 gtk_box_pack_start (GTK_BOX (vbox_quotebg), hbox, FALSE, TRUE, 0);
271 color_buttons.btn_quote_level1_bg = gtk_button_new();
272 gtk_widget_show(color_buttons.btn_quote_level1_bg);
273 gtk_widget_set_size_request (color_buttons.btn_quote_level1_bg, 30, 20);
274 gtk_box_pack_start (GTK_BOX(hbox), color_buttons.btn_quote_level1_bg,
275 FALSE, FALSE, 0);
276 SET_TOGGLE_SENSITIVITY(checkbtn_enable_bgcolors, color_buttons.btn_quote_level1_bg);
278 CLAWS_SET_TIP(color_buttons.btn_quote_level1_bg,
279 C_("Tooltip", "Pick color for 1st level text background"));
281 label_quote_bgcolor1 = gtk_label_new (_("Background"));
282 gtk_widget_show(label_quote_bgcolor1);
283 gtk_box_pack_start (GTK_BOX(hbox), label_quote_bgcolor1,
284 FALSE, FALSE, 0);
285 SET_TOGGLE_SENSITIVITY(checkbtn_enable_bgcolors, label_quote_bgcolor1);
287 hbox = gtk_hbox_new(FALSE, VBOX_BORDER);
288 gtk_widget_show (hbox);
289 SET_TOGGLE_SENSITIVITY(checkbtn_enable_colors, hbox);
290 gtk_box_pack_start (GTK_BOX (vbox_quotebg), hbox, FALSE, TRUE, 0);
292 color_buttons.btn_quote_level2_bg = gtk_button_new();
293 gtk_widget_show(color_buttons.btn_quote_level2_bg);
294 gtk_widget_set_size_request (color_buttons.btn_quote_level2_bg, 30, 20);
295 gtk_box_pack_start (GTK_BOX(hbox), color_buttons.btn_quote_level2_bg,
296 FALSE, FALSE, 0);
297 SET_TOGGLE_SENSITIVITY(checkbtn_enable_bgcolors, color_buttons.btn_quote_level2_bg);
299 CLAWS_SET_TIP(color_buttons.btn_quote_level2_bg,
300 C_("Tooltip", "Pick color for 2nd level text background"));
302 label_quote_bgcolor2 = gtk_label_new (_("Background"));
303 gtk_widget_show(label_quote_bgcolor2);
304 gtk_box_pack_start (GTK_BOX(hbox), label_quote_bgcolor2,
305 FALSE, FALSE, 0);
306 SET_TOGGLE_SENSITIVITY(checkbtn_enable_bgcolors, label_quote_bgcolor2);
308 hbox = gtk_hbox_new(FALSE, VBOX_BORDER);
309 gtk_widget_show (hbox);
310 SET_TOGGLE_SENSITIVITY(checkbtn_enable_colors, hbox);
311 gtk_box_pack_start (GTK_BOX (vbox_quotebg), hbox, FALSE, TRUE, 0);
313 color_buttons.btn_quote_level3_bg = gtk_button_new();
314 gtk_widget_show(color_buttons.btn_quote_level3_bg);
315 gtk_widget_set_size_request (color_buttons.btn_quote_level3_bg, 30, 20);
316 gtk_box_pack_start (GTK_BOX(hbox), color_buttons.btn_quote_level3_bg,
317 FALSE, FALSE, 0);
318 SET_TOGGLE_SENSITIVITY(checkbtn_enable_bgcolors, color_buttons.btn_quote_level3_bg);
320 CLAWS_SET_TIP(color_buttons.btn_quote_level3_bg,
321 C_("Tooltip", "Pick color for 3rd level text background"));
323 label_quote_bgcolor3 = gtk_label_new (_("Background"));
324 gtk_widget_show(label_quote_bgcolor3);
325 gtk_box_pack_start (GTK_BOX(hbox), label_quote_bgcolor3,
326 FALSE, FALSE, 0);
327 SET_TOGGLE_SENSITIVITY(checkbtn_enable_bgcolors, label_quote_bgcolor3);
329 hbox = gtk_hbox_new(FALSE, VBOX_BORDER);
330 gtk_widget_show (hbox);
331 gtk_box_pack_start (GTK_BOX (vbox2), hbox, FALSE, TRUE, 0);
333 color_buttons.btn_uri = gtk_button_new();
334 gtk_widget_show(color_buttons.btn_uri);
335 gtk_widget_set_size_request (color_buttons.btn_uri, 30, 20);
336 gtk_box_pack_start (GTK_BOX(hbox), color_buttons.btn_uri,
337 FALSE, FALSE, 0);
338 SET_TOGGLE_SENSITIVITY(checkbtn_enable_colors, color_buttons.btn_uri);
340 CLAWS_SET_TIP(color_buttons.btn_uri,
341 C_("Tooltip", "Pick color for links"));
343 lable_uri = gtk_label_new (_("URI link"));
344 gtk_widget_show(lable_uri);
345 gtk_box_pack_start (GTK_BOX(hbox), lable_uri, FALSE, FALSE, 0);
346 SET_TOGGLE_SENSITIVITY(checkbtn_enable_colors, lable_uri);
348 hbox = gtk_hbox_new(FALSE, VBOX_BORDER);
349 gtk_widget_show (hbox);
350 gtk_box_pack_start (GTK_BOX (vbox2), hbox, FALSE, TRUE, 0);
352 color_buttons.btn_signature = gtk_button_new();
353 gtk_widget_show(color_buttons.btn_signature);
354 gtk_widget_set_size_request (color_buttons.btn_signature, 30, 20);
355 gtk_box_pack_start (GTK_BOX(hbox), color_buttons.btn_signature,
356 FALSE, FALSE, 0);
357 SET_TOGGLE_SENSITIVITY(checkbtn_enable_colors, color_buttons.btn_signature);
359 CLAWS_SET_TIP(color_buttons.btn_signature,
360 C_("Tooltip", "Pick color for signatures"));
362 label_signature = gtk_label_new (_("Signatures"));
363 gtk_widget_show(label_signature);
364 gtk_box_pack_start (GTK_BOX(hbox), label_signature, FALSE, FALSE, 0);
365 SET_TOGGLE_SENSITIVITY(checkbtn_enable_colors, label_signature);
367 vbox2 = gtkut_get_options_frame(vbox1, &frame_folder, _("Folder list"));
369 hbox = gtk_hbox_new(FALSE, VBOX_BORDER);
370 gtk_widget_show (hbox);
371 gtk_box_pack_start (GTK_BOX (vbox2), hbox, FALSE, TRUE, 0);
373 color_buttons.btn_tgt_folder = gtk_button_new();
374 gtk_widget_show(color_buttons.btn_tgt_folder);
375 gtk_widget_set_size_request (color_buttons.btn_tgt_folder, 30, 20);
376 gtk_box_pack_start (GTK_BOX(hbox), color_buttons.btn_tgt_folder,
377 FALSE, FALSE, 0);
379 CLAWS_SET_TIP(color_buttons.btn_tgt_folder,
380 _("Pick color for Target folder. "
381 "Target folder is used when the option 'Execute immediately "
382 "when moving or deleting messages' is turned off"));
384 label_tgt_folder = gtk_label_new (_("Target folder"));
385 gtk_widget_show(label_tgt_folder);
386 gtk_box_pack_start (GTK_BOX(hbox), label_tgt_folder, FALSE, FALSE, 0);
388 hbox = gtk_hbox_new(FALSE, VBOX_BORDER);
389 gtk_widget_show (hbox);
390 gtk_box_pack_start (GTK_BOX (vbox2), hbox, FALSE, FALSE, 0);
392 color_buttons.btn_color_new = gtk_button_new();
393 gtk_widget_show (color_buttons.btn_color_new);
394 gtk_widget_set_size_request (color_buttons.btn_color_new, 30, 20);
395 gtk_box_pack_start (GTK_BOX(hbox), color_buttons.btn_color_new,
396 FALSE, FALSE, 0);
398 CLAWS_SET_TIP(color_buttons.btn_color_new,
399 _("Pick color for folders containing new messages"));
401 label_color_new = gtk_label_new (_("Folder containing new messages"));
402 gtk_widget_show(label_color_new);
403 gtk_box_pack_start (GTK_BOX(hbox), label_color_new, FALSE, FALSE, 0);
405 /* custom colors */
406 vbox_custom_colors = gtk_vbox_new (FALSE, VSPACING_NARROW);
407 gtk_widget_show (vbox_custom_colors);
408 gtk_container_set_border_width (GTK_CONTAINER (vbox_custom_colors), VBOX_BORDER);
409 gtk_notebook_prepend_page(GTK_NOTEBOOK(notebook), vbox_custom_colors,
410 gtk_label_new(_("Color labels")));
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);
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);
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);
425 for (c = 0; c < (COLORLABELS>>1)+(COLORLABELS&1); 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(C_("Tooltip", "Pick color for 'color %d'"), c+1);
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);
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);
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);
445 CLAWS_SET_TIP(color_buttons.custom_color[c],
446 tooltip_btn_text);
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 CLAWS_SET_TIP(entry_custom_colorlabel[c],
453 tooltip_entry_text);
456 for (c = (COLORLABELS>>1)+(COLORLABELS&1); c < COLORLABELS; c++) {
457 /* TRANSLATORS: 'color %d' refers to the filtering/processing
458 rule name and should not be translated */
459 tooltip_btn_text = g_strdup_printf(C_("Tooltip", "Pick color for 'color %d'"), c+1);
461 /* TRANSLATORS: 'color %d' refers to the filtering/processing
462 rule name and should not be translated */
463 tooltip_entry_text = g_strdup_printf(_("Set label for 'color %d'"), c+1);
465 hbox_custom_color[c] = gtk_hbox_new(FALSE, 8);
466 gtk_widget_show(hbox_custom_color[c]);
467 gtk_box_pack_start(GTK_BOX (vbox_custom_colors2), hbox_custom_color[c],
468 FALSE, TRUE, 0);
470 color_buttons.custom_color[c] = gtk_button_new();
471 gtk_widget_show(color_buttons.custom_color[c]);
472 gtk_widget_set_size_request(color_buttons.custom_color[c], 30, 20);
473 gtk_box_pack_start(GTK_BOX (hbox_custom_color[c]), color_buttons.custom_color[c],
474 FALSE, FALSE, 0);
475 CLAWS_SET_TIP(color_buttons.custom_color[c],
476 tooltip_btn_text);
478 entry_custom_colorlabel[c] = gtk_entry_new();
479 gtk_widget_show (entry_custom_colorlabel[c]);
480 gtk_box_pack_start(GTK_BOX (hbox_custom_color[c]), entry_custom_colorlabel[c],
481 FALSE, FALSE, 0);
482 CLAWS_SET_TIP(entry_custom_colorlabel[c],
483 tooltip_entry_text);
486 g_free(tooltip_btn_text);
487 g_free(tooltip_entry_text);
489 hbox_reset_custom_colors = gtk_hbox_new(FALSE, VBOX_BORDER);
490 gtk_widget_show (hbox_reset_custom_colors);
491 gtk_box_pack_start(GTK_BOX (vbox_custom_colors), hbox_reset_custom_colors,
492 FALSE, FALSE, 0);
494 btn_reset_custom_colors = gtk_button_new_with_label(_(" Use default "));
495 gtk_widget_show(btn_reset_custom_colors);
496 gtk_box_pack_start(GTK_BOX(hbox_reset_custom_colors), btn_reset_custom_colors,
497 FALSE, FALSE, 0);
499 g_signal_connect(G_OBJECT(color_buttons.btn_quote_level1), "clicked",
500 G_CALLBACK(quote_color_set_dialog), "LEVEL1");
501 g_signal_connect(G_OBJECT(color_buttons.btn_quote_level2), "clicked",
502 G_CALLBACK(quote_color_set_dialog), "LEVEL2");
503 g_signal_connect(G_OBJECT(color_buttons.btn_quote_level3), "clicked",
504 G_CALLBACK(quote_color_set_dialog), "LEVEL3");
505 g_signal_connect(G_OBJECT(color_buttons.btn_quote_level1_bg), "clicked",
506 G_CALLBACK(quote_color_set_dialog), "LEVEL1BG");
507 g_signal_connect(G_OBJECT(color_buttons.btn_quote_level2_bg), "clicked",
508 G_CALLBACK(quote_color_set_dialog), "LEVEL2BG");
509 g_signal_connect(G_OBJECT(color_buttons.btn_quote_level3_bg), "clicked",
510 G_CALLBACK(quote_color_set_dialog), "LEVEL3BG");
511 g_signal_connect(G_OBJECT(color_buttons.btn_uri), "clicked",
512 G_CALLBACK(quote_color_set_dialog), "URI");
513 g_signal_connect(G_OBJECT(color_buttons.btn_tgt_folder), "clicked",
514 G_CALLBACK(quote_color_set_dialog), "TGTFLD");
515 g_signal_connect(G_OBJECT(color_buttons.btn_signature), "clicked",
516 G_CALLBACK(quote_color_set_dialog), "SIGNATURE");
517 g_signal_connect(G_OBJECT(color_buttons.btn_color_new), "clicked",
518 G_CALLBACK(quote_color_set_dialog), "NEW");
519 /* custom colors */
520 for (c = 0; c < COLORLABELS; c++) {
521 g_signal_connect(G_OBJECT(color_buttons.custom_color[c]), "clicked",
522 G_CALLBACK(quote_color_set_dialog), GINT_TO_POINTER(c));
525 g_signal_connect(G_OBJECT(btn_reset_custom_colors), "clicked",
526 G_CALLBACK(prefs_msg_colors_reset_custom_colors), prefs_msg_colors);
528 set_button_bg_color(color_buttons.btn_quote_level1,
529 prefs_common.quote_level1_col);
530 set_button_bg_color(color_buttons.btn_quote_level2,
531 prefs_common.quote_level2_col);
532 set_button_bg_color(color_buttons.btn_quote_level3,
533 prefs_common.quote_level3_col);
534 set_button_bg_color(color_buttons.btn_quote_level1_bg,
535 prefs_common.quote_level1_bgcol);
536 set_button_bg_color(color_buttons.btn_quote_level2_bg,
537 prefs_common.quote_level2_bgcol);
538 set_button_bg_color(color_buttons.btn_quote_level3_bg,
539 prefs_common.quote_level3_bgcol);
540 set_button_bg_color(color_buttons.btn_uri,
541 prefs_common.uri_col);
542 set_button_bg_color(color_buttons.btn_tgt_folder,
543 prefs_common.tgt_folder_col);
544 set_button_bg_color(color_buttons.btn_signature,
545 prefs_common.signature_col);
546 set_button_bg_color(color_buttons.btn_color_new,
547 prefs_common.color_new);
548 /* custom colors */
549 for (c = 0; c < COLORLABELS; c++) {
550 set_button_bg_color(color_buttons.custom_color[c],
551 prefs_common.custom_colorlabel[c].color);
552 gtk_entry_set_text(GTK_ENTRY (entry_custom_colorlabel[c]),
553 gettext(SAFE_STRING (prefs_common.custom_colorlabel[c].label)));
556 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(checkbtn_enable_colors),
557 prefs_common.enable_color);
558 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(checkbtn_enable_bgcolors),
559 prefs_common.enable_bgcolor);
560 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(checkbtn_recycle_colors),
561 prefs_common.recycle_quote_colors);
563 prefs_msg_colors->checkbtn_enable_colors = checkbtn_enable_colors;
564 prefs_msg_colors->checkbtn_enable_bgcolors = checkbtn_enable_bgcolors;
565 prefs_msg_colors->checkbtn_recycle_colors = checkbtn_recycle_colors;
566 /* custom colors */
567 for (c = 0; c < COLORLABELS; c++) {
568 prefs_msg_colors->entry_custom_colorlabel[c] = entry_custom_colorlabel[c];
570 gtk_notebook_set_current_page(GTK_NOTEBOOK(notebook), 0);
572 prefs_msg_colors->page.widget = notebook;
575 static void quote_color_set_dialog(GtkWidget *widget, gpointer data)
577 gchar *type = (gchar *)data;
578 gchar *title = NULL;
579 GdkColor color;
580 gint rgbvalue = 0;
581 GtkColorSelectionDialog *dialog;
582 GtkWidget *button_ok;
583 GtkWidget *button_cancel;
584 gint c;
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(C_("Dialog title", "Pick color for 'color %d'"), c+1);
593 rgbvalue = prefs_common.custom_colorlabel[c].color;
594 break;
597 /* other colors */
598 if (c == COLORLABELS) {
599 if(g_ascii_strcasecmp(type, "LEVEL1") == 0) {
600 title = g_strdup(C_("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(C_("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(C_("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(C_("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(C_("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(C_("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(C_("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(C_("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(C_("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(C_("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", type);
632 return;
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));
643 g_object_get(color_dialog, "ok-button", &button_ok,
644 "cancel-button", &button_cancel,
645 NULL);
647 g_signal_connect(G_OBJECT(button_cancel),
648 "clicked", G_CALLBACK(quote_colors_set_dialog_cancel), data);
649 g_signal_connect(G_OBJECT(button_ok),
650 "clicked", G_CALLBACK(quote_colors_set_dialog_ok), data);
651 g_signal_connect(G_OBJECT(color_dialog), "key_press_event",
652 G_CALLBACK(quote_colors_set_dialog_key_pressed),data);
654 /* preselect the previous color in the color selection dialog */
656 gtkut_convert_int_to_gdk_color(rgbvalue, &color);
658 dialog = GTK_COLOR_SELECTION_DIALOG(color_dialog);
659 gtk_color_selection_set_current_color
660 (GTK_COLOR_SELECTION(gtk_color_selection_dialog_get_color_selection(dialog)), &color);
662 gtk_widget_show(color_dialog);
665 static void quote_colors_set_dialog_ok(GtkWidget *widget, gpointer data)
667 GtkColorSelection *colorsel = GTK_COLOR_SELECTION(
668 gtk_color_selection_dialog_get_color_selection
669 ((GtkColorSelectionDialog *)color_dialog));
670 GdkColor color;
671 gint rgbvalue;
672 gchar *type = (gchar *)data;
673 gint c;
675 gtk_color_selection_get_current_color(colorsel, &color);
676 rgbvalue = gtkut_convert_gdk_color_to_int(&color);
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;
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 g_printerr("Unrecognized datatype '%s' in quote_color_set_dialog_ok\n", type);
725 gtk_widget_destroy(color_dialog);
728 static void quote_colors_set_dialog_cancel(GtkWidget *widget, gpointer data)
730 gtk_widget_destroy(color_dialog);
733 static gboolean quote_colors_set_dialog_key_pressed(GtkWidget *widget,
734 GdkEventKey *event,
735 gpointer data)
737 GtkColorSelectionDialog *dialog;
738 GtkWidget *button_ok;
739 GtkWidget *button_cancel;
741 dialog = GTK_COLOR_SELECTION_DIALOG(widget);
742 g_object_get(dialog, "ok-button", &button_ok,
743 "cancel-button", &button_cancel,
744 NULL);
746 if (event) {
747 switch (event->keyval) {
748 case GDK_KEY_Escape:
749 gtk_button_clicked(GTK_BUTTON(button_cancel));
750 return TRUE;
751 case GDK_KEY_Return:
752 case GDK_KEY_KP_Enter:
753 /* NOTE: changing focus makes widget accept all currently
754 * changed settings! */
755 gtk_widget_grab_focus(button_ok);
756 /* call ok handler */
757 gtk_button_clicked(GTK_BUTTON(button_ok));
758 return TRUE;
759 default:
760 break;
763 return FALSE;
766 static void set_button_bg_color(GtkWidget *widget, gint rgbvalue)
768 GtkStyle *newstyle;
769 GdkColor color;
771 gtkut_convert_int_to_gdk_color(rgbvalue, &color);
772 newstyle = gtk_style_copy(gtk_widget_get_default_style());
773 newstyle->bg[GTK_STATE_NORMAL] = color;
774 newstyle->bg[GTK_STATE_PRELIGHT] = color;
775 newstyle->bg[GTK_STATE_ACTIVE] = color;
777 gtk_widget_set_style(GTK_WIDGET(widget), newstyle);
780 static void prefs_msg_colors_save(PrefsPage *_page)
782 MsgColorsPage *page = (MsgColorsPage *) _page;
783 gint c;
785 prefs_common.enable_color =
786 gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(page->checkbtn_enable_colors));
787 prefs_common.enable_bgcolor =
788 gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(page->checkbtn_enable_bgcolors));
789 prefs_common.recycle_quote_colors =
790 gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(page->checkbtn_recycle_colors));
792 /* custom colors */
793 for (c = 0; c < COLORLABELS; c++) {
794 g_free(prefs_common.custom_colorlabel[c].label);
795 prefs_common.custom_colorlabel[c].label =
796 gtk_editable_get_chars(GTK_EDITABLE(page->entry_custom_colorlabel[c]), 0, -1);
798 colorlabel_update_colortable_from_prefs();
800 main_window_reflect_prefs_all();
801 main_window_reflect_prefs_custom_colors(mainwindow_get_mainwindow());
804 static void prefs_msg_colors_reset_custom_colors(GtkWidget *widget, gpointer data)
806 #define CL(x) (((gulong) (x) >> (gulong) 8) & 0xFFUL)
807 #define CR(r, g, b) ((CL(r) << (gulong) 16) | \
808 (CL(g) << (gulong) 8) | \
809 (CL(b)))
810 MsgColorsPage *page = (MsgColorsPage *) data;
811 GdkColor color;
812 gint c;
814 for (c = 0; c < COLORLABELS; c++) {
815 color = colorlabel_get_default_color(c);
816 prefs_common.custom_colorlabel[c].color =
817 (gint)CR(color.red, color.green, color.blue);
818 set_button_bg_color(color_buttons.custom_color[c],
819 prefs_common.custom_colorlabel[c].color);
820 gtk_entry_set_text(GTK_ENTRY (page->entry_custom_colorlabel[c]),
821 gettext(SAFE_STRING (colorlabel_get_color_default_text(c))));
824 #undef CR
825 #undef CL
828 static void prefs_msg_colors_destroy_widget(PrefsPage *_page)
832 MsgColorsPage *prefs_msg_colors;
834 void prefs_msg_colors_init(void)
836 MsgColorsPage *page;
837 static gchar *path[3];
839 path[0] = _("Display");
840 path[1] = _("Colors");
841 path[2] = NULL;
843 page = g_new0(MsgColorsPage, 1);
844 page->page.path = path;
845 page->page.create_widget = prefs_msg_colors_create_widget;
846 page->page.destroy_widget = prefs_msg_colors_destroy_widget;
847 page->page.save_page = prefs_msg_colors_save;
848 page->page.weight = 165.0;
849 prefs_gtk_register_page((PrefsPage *) page);
850 prefs_msg_colors = page;
853 void prefs_msg_colors_done(void)
855 prefs_gtk_unregister_page((PrefsPage *) prefs_msg_colors);
856 g_free(prefs_msg_colors);