Fix bug #3574: Template addressing
[claws.git] / src / prefs_message.c
blob47f5e07a61f8a2ae0f248dca5bea412c15250dc0
1 /*
2 * Sylpheed -- a GTK+ based, lightweight, and fast e-mail client
3 * Copyright (C) 2005-2012 Colin Leroy <colin@colino.net> & 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"
37 #include "prefs_display_header.h"
39 #include "gtk/gtkutils.h"
40 #include "gtk/prefswindow.h"
42 #include "manage_window.h"
44 typedef struct _MessagePage
46 PrefsPage page;
48 GtkWidget *window;
50 GtkWidget *checkbtn_disphdrpane;
51 GtkWidget *checkbtn_disphdr;
52 GtkWidget *checkbtn_dispxface;
54 GtkWidget *checkbtn_html;
55 GtkWidget *checkbtn_html_plugin;
56 GtkWidget *checkbtn_promote_html_part;
57 GtkWidget *spinbtn_linespc;
59 GtkWidget *checkbtn_smoothscroll;
60 GtkWidget *spinbtn_scrollstep;
61 GtkWidget *checkbtn_halfpage;
62 GtkWidget *checkbtn_hide_quoted;
64 GtkWidget *checkbtn_attach_desc;
65 GtkWidget *entry_quote_chars;
66 } MessagePage;
68 static void disphdr_pane_toggled(GtkToggleButton *toggle_btn, GtkWidget *widget)
70 gboolean is_active;
72 is_active = gtk_toggle_button_get_active(toggle_btn);
74 gtk_widget_set_sensitive(widget, !is_active);
77 static void prefs_message_create_widget(PrefsPage *_page, GtkWindow *window,
78 gpointer data)
80 MessagePage *prefs_message = (MessagePage *) _page;
82 GtkWidget *vbox1;
83 GtkWidget *vbox2;
84 GtkWidget *hbox1;
85 GtkWidget *checkbtn_disphdrpane;
86 GtkWidget *checkbtn_disphdr;
87 GtkWidget *checkbtn_dispxface;
89 GtkWidget *button_edit_disphdr;
90 GtkWidget *checkbtn_html;
91 GtkWidget *checkbtn_html_plugin;
92 GtkWidget *checkbtn_promote_html_part;
93 GtkWidget *hbox_linespc;
94 GtkWidget *label_linespc;
95 GtkAdjustment *spinbtn_linespc_adj;
96 GtkWidget *spinbtn_linespc;
98 GtkWidget *frame;
99 GtkWidget *vbox_scr;
100 GtkWidget *checkbtn_smoothscroll;
101 GtkWidget *hbox_scr;
102 GtkWidget *label_scr;
103 GtkAdjustment *spinbtn_scrollstep_adj;
104 GtkWidget *spinbtn_scrollstep;
105 GtkWidget *checkbtn_halfpage;
106 GtkWidget *checkbtn_hide_quoted;
108 GtkWidget *checkbtn_attach_desc;
110 GtkWidget *frame_quote;
111 GtkWidget *hbox2;
112 GtkWidget *vbox_quote;
113 GtkWidget *entry_quote_chars;
114 GtkWidget *label_quote_chars;
116 vbox1 = gtk_vbox_new (FALSE, VSPACING);
117 gtk_widget_show (vbox1);
118 gtk_container_set_border_width (GTK_CONTAINER (vbox1), VBOX_BORDER);
120 vbox2 = gtkut_get_options_frame(vbox1, &frame, _("Headers"));
122 PACK_CHECK_BUTTON(vbox2, checkbtn_disphdrpane,
123 _("Display header pane above message view"));
125 #if HAVE_LIBCOMPFACE
126 PACK_CHECK_BUTTON(vbox2, checkbtn_dispxface,
127 _("Display (X-)Face in message view"));
128 #else
129 PACK_CHECK_BUTTON(vbox2, checkbtn_dispxface,
130 _("Display Face in message view"));
131 #endif
133 gtk_widget_set_sensitive(checkbtn_dispxface,
134 !prefs_common.display_header_pane);
136 g_signal_connect(G_OBJECT(checkbtn_disphdrpane), "toggled",
137 G_CALLBACK(disphdr_pane_toggled), checkbtn_dispxface);
139 hbox1 = gtk_hbox_new (FALSE, 8);
140 gtk_widget_show (hbox1);
141 gtk_box_pack_start (GTK_BOX (vbox2), hbox1, FALSE, TRUE, 0);
143 PACK_CHECK_BUTTON(hbox1, checkbtn_disphdr,
144 _("Display headers in message view"));
146 button_edit_disphdr = gtk_button_new_from_stock(GTK_STOCK_EDIT);
147 gtk_widget_show (button_edit_disphdr);
148 gtk_box_pack_start (GTK_BOX (hbox1), button_edit_disphdr,
149 FALSE, TRUE, 0);
150 g_signal_connect (G_OBJECT (button_edit_disphdr), "clicked",
151 G_CALLBACK (prefs_display_header_open),
152 NULL);
154 SET_TOGGLE_SENSITIVITY(checkbtn_disphdr, button_edit_disphdr);
156 vbox2 = gtkut_get_options_frame(vbox1, &frame, _("HTML messages"));
158 PACK_CHECK_BUTTON(vbox2, checkbtn_html,
159 _("Render HTML messages as text"));
161 PACK_CHECK_BUTTON(vbox2, checkbtn_html_plugin,
162 _("Render HTML-only messages with plugin if possible"));
164 PACK_CHECK_BUTTON(vbox2, checkbtn_promote_html_part,
165 _("Select the HTML part of multipart/alternative messages"));
167 hbox1 = gtk_hbox_new (FALSE, 32);
168 gtk_widget_show (hbox1);
169 gtk_box_pack_start (GTK_BOX (vbox1), hbox1, FALSE, TRUE, 0);
171 hbox_linespc = gtk_hbox_new (FALSE, 8);
172 gtk_widget_show (hbox1);
173 gtk_box_pack_start (GTK_BOX (hbox1), hbox_linespc, FALSE, TRUE, 0);
175 label_linespc = gtk_label_new (_("Line space"));
176 gtk_widget_show (label_linespc);
177 gtk_box_pack_start (GTK_BOX (hbox_linespc), label_linespc,
178 FALSE, FALSE, 0);
180 spinbtn_linespc_adj = GTK_ADJUSTMENT(gtk_adjustment_new (2, 0, 16, 1, 1, 0));
181 spinbtn_linespc = gtk_spin_button_new
182 (GTK_ADJUSTMENT (spinbtn_linespc_adj), 1, 0);
183 gtk_widget_show (spinbtn_linespc);
184 gtk_box_pack_start (GTK_BOX (hbox_linespc), spinbtn_linespc,
185 FALSE, FALSE, 0);
186 gtk_widget_set_size_request (spinbtn_linespc, 64, -1);
187 gtk_spin_button_set_numeric (GTK_SPIN_BUTTON (spinbtn_linespc), TRUE);
189 label_linespc = gtk_label_new (_("pixels"));
190 gtk_widget_show (label_linespc);
191 gtk_box_pack_start (GTK_BOX (hbox_linespc), label_linespc,
192 FALSE, FALSE, 0);
193 gtk_widget_show_all (hbox1);
195 vbox_scr = gtkut_get_options_frame(vbox1, &frame, _("Scroll"));
197 PACK_CHECK_BUTTON(vbox_scr, checkbtn_halfpage, _("Half page"));
199 hbox1 = gtk_hbox_new (FALSE, 32);
200 gtk_widget_show (hbox1);
201 gtk_box_pack_start (GTK_BOX (vbox_scr), hbox1, FALSE, TRUE, 0);
203 PACK_CHECK_BUTTON(hbox1, checkbtn_smoothscroll, _("Smooth scroll"));
205 hbox_scr = gtk_hbox_new (FALSE, 8);
206 gtk_widget_show (hbox_scr);
207 gtk_box_pack_start (GTK_BOX (hbox1), hbox_scr, FALSE, FALSE, 0);
209 label_scr = gtk_label_new (_("Step"));
210 gtk_widget_show (label_scr);
211 gtk_box_pack_start (GTK_BOX (hbox_scr), label_scr, FALSE, FALSE, 0);
213 spinbtn_scrollstep_adj = GTK_ADJUSTMENT(gtk_adjustment_new (1, 1, 100, 1, 10, 0));
214 spinbtn_scrollstep = gtk_spin_button_new
215 (GTK_ADJUSTMENT (spinbtn_scrollstep_adj), 1, 0);
216 gtk_widget_show (spinbtn_scrollstep);
217 gtk_box_pack_start (GTK_BOX (hbox_scr), spinbtn_scrollstep,
218 FALSE, FALSE, 0);
219 gtk_widget_set_size_request (spinbtn_scrollstep, 64, -1);
220 gtk_spin_button_set_numeric (GTK_SPIN_BUTTON (spinbtn_scrollstep),
221 TRUE);
223 label_scr = gtk_label_new (_("pixels"));
224 gtk_widget_show (label_scr);
225 gtk_box_pack_start (GTK_BOX (hbox_scr), label_scr, FALSE, FALSE, 0);
227 SET_TOGGLE_SENSITIVITY (checkbtn_smoothscroll, hbox_scr)
229 PACK_CHECK_BUTTON(vbox1, checkbtn_attach_desc,
230 _("Show attachment descriptions (rather than names)"));
232 /* quote chars */
233 PACK_FRAME (vbox1, frame_quote, _("Quotation"));
235 vbox_quote = gtk_vbox_new (FALSE, VSPACING_NARROW);
236 gtk_widget_show (vbox_quote);
237 gtk_container_add (GTK_CONTAINER (frame_quote), vbox_quote);
238 gtk_container_set_border_width (GTK_CONTAINER (vbox_quote), 8);
240 hbox1 = gtk_hbox_new (FALSE, 32);
241 gtk_widget_show (hbox1);
242 PACK_CHECK_BUTTON(vbox_quote, checkbtn_hide_quoted, _("Collapse quoted text on double click"));
243 gtk_box_pack_start (GTK_BOX (vbox_quote), hbox1, FALSE, FALSE, 0);
245 hbox2 = gtk_hbox_new (FALSE, 8);
246 gtk_widget_show (hbox2);
247 gtk_box_pack_start (GTK_BOX (hbox1), hbox2, FALSE, FALSE, 0);
249 label_quote_chars = gtk_label_new (_("Treat these characters as quotation marks: "));
250 gtk_widget_show (label_quote_chars);
251 gtk_box_pack_start (GTK_BOX (hbox2), label_quote_chars, FALSE, FALSE, 0);
253 entry_quote_chars = gtk_entry_new ();
254 gtk_widget_show (entry_quote_chars);
255 gtk_box_pack_start (GTK_BOX (hbox2), entry_quote_chars,
256 FALSE, FALSE, 0);
257 gtk_widget_set_size_request (entry_quote_chars, 64, -1);
259 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(checkbtn_disphdrpane),
260 prefs_common.display_header_pane);
262 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(checkbtn_dispxface),
263 prefs_common.display_xface);
265 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(checkbtn_disphdr),
266 prefs_common.display_header);
267 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(checkbtn_html),
268 prefs_common.render_html);
269 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(checkbtn_html_plugin),
270 prefs_common.invoke_plugin_on_html);
271 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(checkbtn_promote_html_part),
272 prefs_common.promote_html_part);
273 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(checkbtn_smoothscroll),
274 prefs_common.enable_smooth_scroll);
275 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(checkbtn_hide_quoted),
276 prefs_common.hide_quoted);
277 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(checkbtn_halfpage),
278 prefs_common.scroll_halfpage);
279 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(checkbtn_attach_desc),
280 prefs_common.attach_desc);
281 gtk_spin_button_set_value(GTK_SPIN_BUTTON(spinbtn_linespc),
282 prefs_common.line_space);
283 gtk_spin_button_set_value(GTK_SPIN_BUTTON(spinbtn_scrollstep),
284 prefs_common.scroll_step);
285 gtk_entry_set_text(GTK_ENTRY(entry_quote_chars),
286 prefs_common.quote_chars?prefs_common.quote_chars:"");
288 prefs_message->window = GTK_WIDGET(window);
289 prefs_message->checkbtn_disphdrpane = checkbtn_disphdrpane;
290 prefs_message->checkbtn_dispxface = checkbtn_dispxface;
291 prefs_message->checkbtn_disphdr = checkbtn_disphdr;
292 prefs_message->checkbtn_html = checkbtn_html;
293 prefs_message->checkbtn_html_plugin = checkbtn_html_plugin;
294 prefs_message->checkbtn_promote_html_part = checkbtn_promote_html_part;
295 prefs_message->spinbtn_linespc = spinbtn_linespc;
296 prefs_message->checkbtn_smoothscroll = checkbtn_smoothscroll;
297 prefs_message->checkbtn_hide_quoted = checkbtn_hide_quoted;
298 prefs_message->spinbtn_scrollstep = spinbtn_scrollstep;
299 prefs_message->checkbtn_halfpage = checkbtn_halfpage;
300 prefs_message->checkbtn_attach_desc = checkbtn_attach_desc;
301 prefs_message->entry_quote_chars = entry_quote_chars;
303 prefs_message->page.widget = vbox1;
306 static void prefs_message_save(PrefsPage *_page)
308 MessagePage *page = (MessagePage *) _page;
310 prefs_common.display_header_pane = gtk_toggle_button_get_active(
311 GTK_TOGGLE_BUTTON(page->checkbtn_disphdrpane));
312 prefs_common.display_xface = gtk_toggle_button_get_active(
313 GTK_TOGGLE_BUTTON(page->checkbtn_dispxface));
314 prefs_common.display_header = gtk_toggle_button_get_active(
315 GTK_TOGGLE_BUTTON(page->checkbtn_disphdr));
316 prefs_common.render_html = gtk_toggle_button_get_active(
317 GTK_TOGGLE_BUTTON(page->checkbtn_html));
318 prefs_common.invoke_plugin_on_html = gtk_toggle_button_get_active(
319 GTK_TOGGLE_BUTTON(page->checkbtn_html_plugin));
320 prefs_common.promote_html_part = gtk_toggle_button_get_active(
321 GTK_TOGGLE_BUTTON(page->checkbtn_promote_html_part));
322 prefs_common.enable_smooth_scroll = gtk_toggle_button_get_active(
323 GTK_TOGGLE_BUTTON(page->checkbtn_smoothscroll));
324 prefs_common.scroll_halfpage = gtk_toggle_button_get_active(
325 GTK_TOGGLE_BUTTON(page->checkbtn_halfpage));
326 prefs_common.hide_quoted = gtk_toggle_button_get_active(
327 GTK_TOGGLE_BUTTON(page->checkbtn_hide_quoted));
328 prefs_common.attach_desc = gtk_toggle_button_get_active(
329 GTK_TOGGLE_BUTTON(page->checkbtn_attach_desc));
330 prefs_common.line_space = gtk_spin_button_get_value_as_int(
331 GTK_SPIN_BUTTON(page->spinbtn_linespc));
332 prefs_common.scroll_step = gtk_spin_button_get_value_as_int(
333 GTK_SPIN_BUTTON(page->spinbtn_scrollstep));
335 g_free(prefs_common.quote_chars);
336 prefs_common.quote_chars = gtk_editable_get_chars(
337 GTK_EDITABLE(page->entry_quote_chars), 0, -1);
338 remove_space(prefs_common.quote_chars);
340 main_window_reflect_prefs_all_real(FALSE);
343 static void prefs_message_destroy_widget(PrefsPage *_page)
347 MessagePage *prefs_message;
349 void prefs_message_init(void)
351 MessagePage *page;
352 static gchar *path[3];
354 path[0] = _("Message View");
355 path[1] = _("Text Options");
356 path[2] = NULL;
358 page = g_new0(MessagePage, 1);
359 page->page.path = path;
360 page->page.create_widget = prefs_message_create_widget;
361 page->page.destroy_widget = prefs_message_destroy_widget;
362 page->page.save_page = prefs_message_save;
363 page->page.weight = 170.0;
364 prefs_gtk_register_page((PrefsPage *) page);
365 prefs_message = page;
368 void prefs_message_done(void)
370 prefs_gtk_unregister_page((PrefsPage *) prefs_message);
371 g_free(prefs_message);