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