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