b9d102953ec065b8ba206cd2251aaf9d144e2fca
[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 } 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         PACK_FRAME(vbox1, frame, _("Headers"));
109         
110         vbox2 = gtk_vbox_new (FALSE, 0);
111         gtk_widget_show (vbox2);
112         gtk_container_add(GTK_CONTAINER(frame), vbox2);
113         gtk_container_set_border_width(GTK_CONTAINER(vbox2), 8);
114
115         PACK_CHECK_BUTTON(vbox2, chkbtn_disphdrpane,
116                           _("Display header pane above message view"));
117
118 #if HAVE_LIBCOMPFACE
119         PACK_CHECK_BUTTON(vbox2, chkbtn_dispxface,
120                           _("Display (X-)Face in message view"));
121 #else
122         PACK_CHECK_BUTTON(vbox2, chkbtn_dispxface,
123                           _("Display Face in message view"));
124 #endif
125
126         gtk_widget_set_sensitive(chkbtn_dispxface, 
127                 !prefs_common.display_header_pane);
128
129         g_signal_connect(G_OBJECT(chkbtn_disphdrpane), "toggled",
130                          G_CALLBACK(disphdr_pane_toggled), chkbtn_dispxface);
131
132         hbox1 = gtk_hbox_new (FALSE, 8);
133         gtk_widget_show (hbox1);
134         gtk_box_pack_start (GTK_BOX (vbox2), hbox1, FALSE, TRUE, 0);
135
136         PACK_CHECK_BUTTON(hbox1, chkbtn_disphdr,
137                           _("Display headers in message view"));
138
139         button_edit_disphdr = gtk_button_new_from_stock(GTK_STOCK_EDIT);
140         gtk_widget_show (button_edit_disphdr);
141         gtk_box_pack_start (GTK_BOX (hbox1), button_edit_disphdr,
142                           FALSE, TRUE, 0);
143         g_signal_connect (G_OBJECT (button_edit_disphdr), "clicked",
144                           G_CALLBACK (prefs_display_header_open),
145                           NULL);
146
147         SET_TOGGLE_SENSITIVITY(chkbtn_disphdr, button_edit_disphdr);
148
149         PACK_FRAME(vbox1, frame, _("HTML messages"));
150         
151         vbox2 = gtk_vbox_new (FALSE, 0);
152         gtk_widget_show (vbox2);
153         gtk_container_add(GTK_CONTAINER(frame), vbox2);
154         gtk_container_set_border_width(GTK_CONTAINER(vbox2), 8);
155
156         PACK_CHECK_BUTTON(vbox2, chkbtn_html,
157                           _("Render HTML messages as text"));
158
159         PACK_CHECK_BUTTON(vbox2, chkbtn_html_plugin,
160                           _("Render HTML-only messages with plugin if possible"));
161
162         hbox1 = gtk_hbox_new (FALSE, 32);
163         gtk_widget_show (hbox1);
164         gtk_box_pack_start (GTK_BOX (vbox2), hbox1, FALSE, TRUE, 0);
165
166         hbox_linespc = gtk_hbox_new (FALSE, 8);
167         gtk_widget_show (hbox1);
168         gtk_box_pack_start (GTK_BOX (hbox1), hbox_linespc, FALSE, TRUE, 0);
169
170         label_linespc = gtk_label_new (_("Line space"));
171         gtk_widget_show (label_linespc);
172         gtk_box_pack_start (GTK_BOX (hbox_linespc), label_linespc,
173                             FALSE, FALSE, 0);
174
175         spinbtn_linespc_adj = gtk_adjustment_new (2, 0, 16, 1, 1, 16);
176         spinbtn_linespc = gtk_spin_button_new
177                 (GTK_ADJUSTMENT (spinbtn_linespc_adj), 1, 0);
178         gtk_widget_show (spinbtn_linespc);
179         gtk_box_pack_start (GTK_BOX (hbox_linespc), spinbtn_linespc,
180                             FALSE, FALSE, 0);
181         gtk_widget_set_size_request (spinbtn_linespc, 64, -1);
182         gtk_spin_button_set_numeric (GTK_SPIN_BUTTON (spinbtn_linespc), TRUE);
183
184         label_linespc = gtk_label_new (_("pixel(s)"));
185         gtk_widget_show (label_linespc);
186         gtk_box_pack_start (GTK_BOX (hbox_linespc), label_linespc,
187                             FALSE, FALSE, 0);
188
189         PACK_FRAME(vbox1, frame, _("Scroll"));
190
191         vbox_scr = gtk_vbox_new (FALSE, 0);
192         gtk_widget_show (vbox_scr);
193         gtk_container_add (GTK_CONTAINER (frame), vbox_scr);
194         gtk_container_set_border_width (GTK_CONTAINER (vbox_scr), 8);
195
196         PACK_CHECK_BUTTON(vbox_scr, chkbtn_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, chkbtn_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, 10);
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 (chkbtn_smoothscroll, hbox_scr)
227
228         PACK_CHECK_BUTTON(vbox1, chkbtn_attach_desc,
229                           _("Show attachment descriptions (rather than names)"));
230
231         gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(chkbtn_disphdrpane),
232                 prefs_common.display_header_pane);
233
234         gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(chkbtn_dispxface),
235                 prefs_common.display_xface);
236
237         gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(chkbtn_disphdr),
238                 prefs_common.display_header);
239         gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(chkbtn_html),
240                 prefs_common.render_html);
241         gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(chkbtn_html_plugin),
242                 prefs_common.invoke_plugin_on_html);
243         gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(chkbtn_smoothscroll),
244                 prefs_common.enable_smooth_scroll);
245         gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(chkbtn_halfpage),
246                 prefs_common.scroll_halfpage);
247         gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(chkbtn_attach_desc),
248                 prefs_common.attach_desc);
249         gtk_spin_button_set_value(GTK_SPIN_BUTTON(spinbtn_linespc),
250                 prefs_common.line_space);
251         gtk_spin_button_set_value(GTK_SPIN_BUTTON(spinbtn_scrollstep),
252                 prefs_common.scroll_step);
253                 
254         prefs_message->window = GTK_WIDGET(window);
255         prefs_message->chkbtn_disphdrpane = chkbtn_disphdrpane;
256         prefs_message->chkbtn_dispxface = chkbtn_dispxface;
257         prefs_message->chkbtn_disphdr = chkbtn_disphdr;
258         prefs_message->chkbtn_html = chkbtn_html;
259         prefs_message->chkbtn_html_plugin = chkbtn_html_plugin;
260         prefs_message->spinbtn_linespc = spinbtn_linespc;
261         prefs_message->chkbtn_smoothscroll = chkbtn_smoothscroll;
262         prefs_message->spinbtn_scrollstep = spinbtn_scrollstep;
263         prefs_message->chkbtn_halfpage = chkbtn_halfpage;
264         prefs_message->chkbtn_attach_desc = chkbtn_attach_desc;
265         
266         prefs_message->page.widget = vbox1;
267 }
268
269 void prefs_message_save(PrefsPage *_page)
270 {
271         MessagePage *page = (MessagePage *) _page;
272
273         prefs_common.display_header_pane = gtk_toggle_button_get_active(
274                 GTK_TOGGLE_BUTTON(page->chkbtn_disphdrpane));
275         prefs_common.display_xface = gtk_toggle_button_get_active(
276                 GTK_TOGGLE_BUTTON(page->chkbtn_dispxface));
277         prefs_common.display_header = gtk_toggle_button_get_active(
278                 GTK_TOGGLE_BUTTON(page->chkbtn_disphdr));
279         prefs_common.render_html = gtk_toggle_button_get_active(
280                 GTK_TOGGLE_BUTTON(page->chkbtn_html));
281         prefs_common.invoke_plugin_on_html = gtk_toggle_button_get_active(
282                 GTK_TOGGLE_BUTTON(page->chkbtn_html_plugin));
283         prefs_common.enable_smooth_scroll = gtk_toggle_button_get_active(
284                 GTK_TOGGLE_BUTTON(page->chkbtn_smoothscroll));
285         prefs_common.scroll_halfpage = gtk_toggle_button_get_active(
286                 GTK_TOGGLE_BUTTON(page->chkbtn_halfpage));
287         prefs_common.attach_desc = gtk_toggle_button_get_active(
288                 GTK_TOGGLE_BUTTON(page->chkbtn_attach_desc));
289         prefs_common.line_space = gtk_spin_button_get_value_as_int(
290                 GTK_SPIN_BUTTON(page->spinbtn_linespc));
291         prefs_common.scroll_step = gtk_spin_button_get_value_as_int(
292                 GTK_SPIN_BUTTON(page->spinbtn_scrollstep));
293
294         main_window_reflect_prefs_all_real(FALSE);
295 }
296
297 static void prefs_message_destroy_widget(PrefsPage *_page)
298 {
299 }
300
301 MessagePage *prefs_message;
302
303 void prefs_message_init(void)
304 {
305         MessagePage *page;
306         static gchar *path[3];
307
308         path[0] = _("Message View");
309         path[1] = _("Text Options");
310         path[2] = NULL;
311
312         page = g_new0(MessagePage, 1);
313         page->page.path = path;
314         page->page.create_widget = prefs_message_create_widget;
315         page->page.destroy_widget = prefs_message_destroy_widget;
316         page->page.save_page = prefs_message_save;
317         page->page.weight = 170.0;
318         prefs_gtk_register_page((PrefsPage *) page);
319         prefs_message = page;
320 }
321
322 void prefs_message_done(void)
323 {
324         prefs_gtk_unregister_page((PrefsPage *) prefs_message);
325         g_free(prefs_message);
326 }