2006-10-12 [colin] 2.5.5cvs4
[claws.git] / src / prefs_message.c
1 /*
2  * Sylpheed -- a GTK+ based, lightweight, and fast e-mail client
3  * Copyright (C) 2005-2006 Colin Leroy <colin@colino.net> & 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 #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 *chkbtn_disphdrpane;
50         GtkWidget *chkbtn_disphdr;
51         GtkWidget *chkbtn_dispxface;
52
53         GtkWidget *chkbtn_html;
54         GtkWidget *chkbtn_html_plugin;
55         GtkWidget *spinbtn_linespc;
56
57         GtkWidget *chkbtn_smoothscroll;
58         GtkWidget *spinbtn_scrollstep;
59         GtkWidget *chkbtn_halfpage;
60
61         GtkWidget *chkbtn_attach_desc;
62         GtkWidget *chkbtn_respect_flowed_format;
63 } MessagePage;
64
65 static void disphdr_pane_toggled(GtkToggleButton *toggle_btn, GtkWidget *widget)
66 {
67         gboolean is_active;
68
69         is_active = gtk_toggle_button_get_active(toggle_btn);
70
71         gtk_widget_set_sensitive(widget, !is_active);
72 }
73
74 void prefs_message_create_widget(PrefsPage *_page, GtkWindow *window, 
75                                   gpointer data)
76 {
77         MessagePage *prefs_message = (MessagePage *) _page;
78         
79         GtkWidget *vbox1;
80         GtkWidget *vbox2;
81         GtkWidget *hbox1;
82         GtkWidget *chkbtn_disphdrpane;
83         GtkWidget *chkbtn_disphdr;
84         GtkWidget *chkbtn_dispxface;
85
86         GtkWidget *button_edit_disphdr;
87         GtkWidget *chkbtn_html;
88         GtkWidget *chkbtn_html_plugin;
89         GtkWidget *hbox_linespc;
90         GtkWidget *label_linespc;
91         GtkObject *spinbtn_linespc_adj;
92         GtkWidget *spinbtn_linespc;
93
94         GtkWidget *frame;
95         GtkWidget *vbox_scr;
96         GtkWidget *chkbtn_smoothscroll;
97         GtkWidget *hbox_scr;
98         GtkWidget *label_scr;
99         GtkObject *spinbtn_scrollstep_adj;
100         GtkWidget *spinbtn_scrollstep;
101         GtkWidget *chkbtn_halfpage;
102
103         GtkWidget *chkbtn_attach_desc;
104         GtkWidget *chkbtn_respect_flowed_format;
105
106         vbox1 = gtk_vbox_new (FALSE, VSPACING);
107         gtk_widget_show (vbox1);
108         gtk_container_set_border_width (GTK_CONTAINER (vbox1), VBOX_BORDER);
109
110         PACK_FRAME(vbox1, frame, _("Headers"));
111         
112         vbox2 = gtk_vbox_new (FALSE, 0);
113         gtk_widget_show (vbox2);
114         gtk_container_add(GTK_CONTAINER(frame), vbox2);
115         gtk_container_set_border_width(GTK_CONTAINER(vbox2), 8);
116
117         PACK_CHECK_BUTTON(vbox2, chkbtn_disphdrpane,
118                           _("Display header pane above message view"));
119
120 #if HAVE_LIBCOMPFACE
121         PACK_CHECK_BUTTON(vbox2, chkbtn_dispxface,
122                           _("Display (X-)Face in message view"));
123 #else
124         PACK_CHECK_BUTTON(vbox2, chkbtn_dispxface,
125                           _("Display Face in message view"));
126 #endif
127
128         gtk_widget_set_sensitive(chkbtn_dispxface, 
129                 !prefs_common.display_header_pane);
130
131         g_signal_connect(G_OBJECT(chkbtn_disphdrpane), "toggled",
132                          G_CALLBACK(disphdr_pane_toggled), chkbtn_dispxface);
133
134         hbox1 = gtk_hbox_new (FALSE, 8);
135         gtk_widget_show (hbox1);
136         gtk_box_pack_start (GTK_BOX (vbox2), hbox1, FALSE, TRUE, 0);
137
138         PACK_CHECK_BUTTON(hbox1, chkbtn_disphdr,
139                           _("Display headers in message view"));
140
141         button_edit_disphdr = gtk_button_new_from_stock(GTK_STOCK_EDIT);
142         gtk_widget_show (button_edit_disphdr);
143         gtk_box_pack_start (GTK_BOX (hbox1), button_edit_disphdr,
144                           FALSE, TRUE, 0);
145         g_signal_connect (G_OBJECT (button_edit_disphdr), "clicked",
146                           G_CALLBACK (prefs_display_header_open),
147                           NULL);
148
149         SET_TOGGLE_SENSITIVITY(chkbtn_disphdr, button_edit_disphdr);
150
151         PACK_FRAME(vbox1, frame, _("HTML messages"));
152         
153         vbox2 = gtk_vbox_new (FALSE, 0);
154         gtk_widget_show (vbox2);
155         gtk_container_add(GTK_CONTAINER(frame), vbox2);
156         gtk_container_set_border_width(GTK_CONTAINER(vbox2), 8);
157
158         PACK_CHECK_BUTTON(vbox2, chkbtn_html,
159                           _("Render HTML messages as text"));
160
161         PACK_CHECK_BUTTON(vbox2, chkbtn_html_plugin,
162                           _("Render HTML-only messages with plugin if possible"));
163
164         hbox1 = gtk_hbox_new (FALSE, 32);
165         gtk_widget_show (hbox1);
166         gtk_box_pack_start (GTK_BOX (vbox2), 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, 16);
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
191         PACK_FRAME(vbox1, frame, _("Scroll"));
192
193         vbox_scr = gtk_vbox_new (FALSE, 0);
194         gtk_widget_show (vbox_scr);
195         gtk_container_add (GTK_CONTAINER (frame), vbox_scr);
196         gtk_container_set_border_width (GTK_CONTAINER (vbox_scr), 8);
197
198         PACK_CHECK_BUTTON(vbox_scr, chkbtn_halfpage, _("Half page"));
199
200         hbox1 = gtk_hbox_new (FALSE, 32);
201         gtk_widget_show (hbox1);
202         gtk_box_pack_start (GTK_BOX (vbox_scr), hbox1, FALSE, TRUE, 0);
203
204         PACK_CHECK_BUTTON(hbox1, chkbtn_smoothscroll, _("Smooth scroll"));
205
206         hbox_scr = gtk_hbox_new (FALSE, 8);
207         gtk_widget_show (hbox_scr);
208         gtk_box_pack_start (GTK_BOX (hbox1), hbox_scr, FALSE, FALSE, 0);
209
210         label_scr = gtk_label_new (_("Step"));
211         gtk_widget_show (label_scr);
212         gtk_box_pack_start (GTK_BOX (hbox_scr), label_scr, FALSE, FALSE, 0);
213
214         spinbtn_scrollstep_adj = gtk_adjustment_new (1, 1, 100, 1, 10, 10);
215         spinbtn_scrollstep = gtk_spin_button_new
216                 (GTK_ADJUSTMENT (spinbtn_scrollstep_adj), 1, 0);
217         gtk_widget_show (spinbtn_scrollstep);
218         gtk_box_pack_start (GTK_BOX (hbox_scr), spinbtn_scrollstep,
219                             FALSE, FALSE, 0);
220         gtk_widget_set_size_request (spinbtn_scrollstep, 64, -1);
221         gtk_spin_button_set_numeric (GTK_SPIN_BUTTON (spinbtn_scrollstep),
222                                      TRUE);
223
224         label_scr = gtk_label_new (_("pixel(s)"));
225         gtk_widget_show (label_scr);
226         gtk_box_pack_start (GTK_BOX (hbox_scr), label_scr, FALSE, FALSE, 0);
227
228         SET_TOGGLE_SENSITIVITY (chkbtn_smoothscroll, hbox_scr)
229
230         vbox2 = gtk_vbox_new (FALSE, 0);
231         gtk_widget_show (vbox2);
232         PACK_CHECK_BUTTON(vbox2, chkbtn_attach_desc,
233                           _("Show attachment descriptions (rather than names)"));
234         PACK_CHECK_BUTTON(vbox2, chkbtn_respect_flowed_format,
235                           _("Respect flowed format"));
236         gtk_box_pack_start (GTK_BOX (vbox1), vbox2,
237                           FALSE, TRUE, 0);
238
239         gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(chkbtn_disphdrpane),
240                 prefs_common.display_header_pane);
241
242         gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(chkbtn_dispxface),
243                 prefs_common.display_xface);
244
245         gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(chkbtn_disphdr),
246                 prefs_common.display_header);
247         gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(chkbtn_html),
248                 prefs_common.render_html);
249         gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(chkbtn_html_plugin),
250                 prefs_common.invoke_plugin_on_html);
251         gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(chkbtn_smoothscroll),
252                 prefs_common.enable_smooth_scroll);
253         gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(chkbtn_halfpage),
254                 prefs_common.scroll_halfpage);
255         gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(chkbtn_attach_desc),
256                 prefs_common.attach_desc);
257         gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(chkbtn_respect_flowed_format),
258                 prefs_common.respect_flowed_format);
259         gtk_spin_button_set_value(GTK_SPIN_BUTTON(spinbtn_linespc),
260                 prefs_common.line_space);
261         gtk_spin_button_set_value(GTK_SPIN_BUTTON(spinbtn_scrollstep),
262                 prefs_common.scroll_step);
263                 
264         prefs_message->window = GTK_WIDGET(window);
265         prefs_message->chkbtn_disphdrpane = chkbtn_disphdrpane;
266         prefs_message->chkbtn_dispxface = chkbtn_dispxface;
267         prefs_message->chkbtn_disphdr = chkbtn_disphdr;
268         prefs_message->chkbtn_html = chkbtn_html;
269         prefs_message->chkbtn_html_plugin = chkbtn_html_plugin;
270         prefs_message->spinbtn_linespc = spinbtn_linespc;
271         prefs_message->chkbtn_smoothscroll = chkbtn_smoothscroll;
272         prefs_message->spinbtn_scrollstep = spinbtn_scrollstep;
273         prefs_message->chkbtn_halfpage = chkbtn_halfpage;
274         prefs_message->chkbtn_attach_desc = chkbtn_attach_desc;
275         prefs_message->chkbtn_respect_flowed_format = chkbtn_respect_flowed_format;
276
277         prefs_message->page.widget = vbox1;
278 }
279
280 void prefs_message_save(PrefsPage *_page)
281 {
282         MessagePage *page = (MessagePage *) _page;
283
284         prefs_common.display_header_pane = gtk_toggle_button_get_active(
285                 GTK_TOGGLE_BUTTON(page->chkbtn_disphdrpane));
286         prefs_common.display_xface = gtk_toggle_button_get_active(
287                 GTK_TOGGLE_BUTTON(page->chkbtn_dispxface));
288         prefs_common.display_header = gtk_toggle_button_get_active(
289                 GTK_TOGGLE_BUTTON(page->chkbtn_disphdr));
290         prefs_common.render_html = gtk_toggle_button_get_active(
291                 GTK_TOGGLE_BUTTON(page->chkbtn_html));
292         prefs_common.invoke_plugin_on_html = gtk_toggle_button_get_active(
293                 GTK_TOGGLE_BUTTON(page->chkbtn_html_plugin));
294         prefs_common.enable_smooth_scroll = gtk_toggle_button_get_active(
295                 GTK_TOGGLE_BUTTON(page->chkbtn_smoothscroll));
296         prefs_common.scroll_halfpage = gtk_toggle_button_get_active(
297                 GTK_TOGGLE_BUTTON(page->chkbtn_halfpage));
298         prefs_common.attach_desc = gtk_toggle_button_get_active(
299                 GTK_TOGGLE_BUTTON(page->chkbtn_attach_desc));
300         prefs_common.respect_flowed_format = gtk_toggle_button_get_active(
301                 GTK_TOGGLE_BUTTON(page->chkbtn_respect_flowed_format));
302         prefs_common.line_space = gtk_spin_button_get_value_as_int(
303                 GTK_SPIN_BUTTON(page->spinbtn_linespc));
304         prefs_common.scroll_step = gtk_spin_button_get_value_as_int(
305                 GTK_SPIN_BUTTON(page->spinbtn_scrollstep));
306
307         main_window_reflect_prefs_all_real(FALSE);
308 }
309
310 static void prefs_message_destroy_widget(PrefsPage *_page)
311 {
312 }
313
314 MessagePage *prefs_message;
315
316 void prefs_message_init(void)
317 {
318         MessagePage *page;
319         static gchar *path[3];
320
321         path[0] = _("Message View");
322         path[1] = _("Text Options");
323         path[2] = NULL;
324
325         page = g_new0(MessagePage, 1);
326         page->page.path = path;
327         page->page.create_widget = prefs_message_create_widget;
328         page->page.destroy_widget = prefs_message_destroy_widget;
329         page->page.save_page = prefs_message_save;
330         page->page.weight = 170.0;
331         prefs_gtk_register_page((PrefsPage *) page);
332         prefs_message = page;
333 }
334
335 void prefs_message_done(void)
336 {
337         prefs_gtk_unregister_page((PrefsPage *) prefs_message);
338         g_free(prefs_message);
339 }