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