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