1 /*
2  * Sylpheed -- a GTK+ based, lightweight, and fast e-mail client
3  * Copyright (C) 2003-2012 Hiroyuki Yamamoto & 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 #include "claws-features.h"
23 #endif
24 
25 #include "defs.h"
26 
27 #include <stdio.h>
28 #include <stdlib.h>
29 
30 #include <glib.h>
31 #include <glib/gi18n.h>
32 #include <gtk/gtk.h>
33 #include <gdk/gdkkeysyms.h>
34 
35 #include "prefs_common.h"
36 #include "prefs_gtk.h"
37 
38 #include "gtk/prefswindow.h"
39 
40 typedef struct _FontsPage
41 {
42 	PrefsPage page;
43 
44 	GtkWidget *window;		/* do not modify */
45 
46 	GtkWidget *entry_folderview_smallfont;
47 	GtkWidget *entry_folderview_normalfont;
48 	GtkWidget *entry_folderview_boldfont;
49 	GtkWidget *entry_messageviewfont;
50 	GtkWidget *derive_from_normalfont_checkbutton;
51 	GtkWidget *print_checkbutton;
52 	GtkWidget *entry_messageprintfont;
53 } FontsPage;
54 
prefs_fonts_create_widget(PrefsPage * _page,GtkWindow * window,gpointer data)55 static void prefs_fonts_create_widget(PrefsPage *_page, GtkWindow *window,
56 			       gpointer data)
57 {
58 	FontsPage *prefs_fonts = (FontsPage *) _page;
59 
60 	GtkWidget *table;
61 	GtkWidget *entry_folderview_smallfont;
62 	GtkWidget *entry_folderview_normalfont;
63 	GtkWidget *entry_folderview_boldfont;
64 	GtkWidget *entry_messageviewfont;
65 	GtkWidget *tmplabel;
66 	GtkWidget *entry_messageprintfont;
67 	GtkWidget *print_checkbutton;
68 	GtkWidget *derive_from_normalfont_checkbutton;
69 	GtkWidget *vbox;
70 	gint      row = 0;
71 
72 	table = gtk_table_new(10, 2, FALSE);
73 	gtk_widget_show(table);
74 	gtk_container_set_border_width(GTK_CONTAINER(table), VBOX_BORDER);
75 	gtk_table_set_row_spacings(GTK_TABLE(table), 4);
76 	gtk_table_set_col_spacings(GTK_TABLE(table), 8);
77 
78 	/* normal font label */
79 	tmplabel = gtk_label_new (_("Folder and Message Lists"));
80 	gtk_widget_show (tmplabel);
81 	gtk_table_attach (GTK_TABLE (table), tmplabel, 0, 1, row, row+1,
82 			 (GtkAttachOptions) GTK_FILL,
83 			 (GtkAttachOptions) (0), 0, 0);
84 	gtk_label_set_justify(GTK_LABEL(tmplabel), GTK_JUSTIFY_RIGHT);
85 	gtk_misc_set_alignment(GTK_MISC(tmplabel), 1, 0.5);
86 
87 	/* normal font button */
88 	entry_folderview_normalfont = gtk_font_button_new_with_font (prefs_common.normalfont);
89 	g_object_set(G_OBJECT(entry_folderview_normalfont),
90 			      "use-font", TRUE,
91 			      NULL);
92 	gtk_widget_show (entry_folderview_normalfont);
93 	gtk_table_attach (GTK_TABLE (table), entry_folderview_normalfont, 1, 2, row, row+1,
94 			 (GtkAttachOptions) (GTK_EXPAND | GTK_FILL),
95 			 (GtkAttachOptions) (0), 0, 0);
96 	row++;
97 
98 	/* message font label */
99 	tmplabel = gtk_label_new (_("Message"));
100 	gtk_widget_show (tmplabel);
101 	gtk_table_attach (GTK_TABLE (table), tmplabel, 0, 1, row, row+1,
102 			 (GtkAttachOptions) GTK_FILL,
103 			 (GtkAttachOptions) (0), 0, 0);
104 	gtk_label_set_justify(GTK_LABEL(tmplabel), GTK_JUSTIFY_RIGHT);
105 	gtk_misc_set_alignment(GTK_MISC(tmplabel), 1, 0.5);
106 
107 	/* message font button */
108 	entry_messageviewfont = gtk_font_button_new_with_font (prefs_common.textfont);
109 	g_object_set(G_OBJECT(entry_messageviewfont),
110 			      "use-font", TRUE,
111 			      NULL);
112 	gtk_widget_show (entry_messageviewfont);
113 	gtk_table_attach (GTK_TABLE (table), entry_messageviewfont, 1, 2, row, row+1,
114 			 (GtkAttachOptions) (GTK_EXPAND | GTK_FILL),
115 			 (GtkAttachOptions) (0), 0, 0);
116 	row++;
117 
118 	vbox = gtk_vbox_new(FALSE, VSPACING_NARROW);
119 	gtk_widget_show(vbox);
120 	gtk_table_attach (GTK_TABLE (table), vbox, 0, 4, row, row+1,
121 			 (GtkAttachOptions) GTK_FILL,
122 			 (GtkAttachOptions) (0), 0, 0);
123 	row++;
124 
125 	/* derive from normal font check button */
126 	derive_from_normalfont_checkbutton = gtk_check_button_new_with_label(_("Derive small and bold fonts from Folder and Message Lists font"));
127 	gtk_widget_show(derive_from_normalfont_checkbutton);
128 	gtk_table_attach (GTK_TABLE (table), derive_from_normalfont_checkbutton, 0, 2, row, row+1,
129 			 (GtkAttachOptions) (GTK_EXPAND | GTK_FILL),
130 			 (GtkAttachOptions) (0), 0, 0);
131 	gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON(derive_from_normalfont_checkbutton),
132 		 prefs_common.derive_from_normal_font);
133 	row++;
134 
135 	/* small font label */
136 	tmplabel = gtk_label_new (_("Small"));
137 	gtk_widget_show (tmplabel);
138 	gtk_table_attach (GTK_TABLE (table), tmplabel, 0, 1, row, row+1,
139 			 (GtkAttachOptions) GTK_FILL,
140 			 (GtkAttachOptions) (0), 0, 0);
141 	gtk_label_set_justify(GTK_LABEL(tmplabel), GTK_JUSTIFY_RIGHT);
142 	gtk_misc_set_alignment(GTK_MISC(tmplabel), 1, 0.5);
143 	SET_TOGGLE_SENSITIVITY_REVERSE (derive_from_normalfont_checkbutton, tmplabel);
144 
145 	/* small font button */
146 	entry_folderview_smallfont = gtk_font_button_new_with_font (prefs_common.smallfont);
147 	g_object_set(G_OBJECT(entry_folderview_smallfont),
148 			      "use-font", TRUE,
149 			      NULL);
150 	gtk_widget_show (entry_folderview_smallfont);
151 	gtk_table_attach (GTK_TABLE (table), entry_folderview_smallfont, 1, 2, row, row+1,
152 			 (GtkAttachOptions) (GTK_EXPAND | GTK_FILL),
153 			 (GtkAttachOptions) (0), 0, 0);
154 	SET_TOGGLE_SENSITIVITY_REVERSE (derive_from_normalfont_checkbutton, entry_folderview_smallfont);
155 	row++;
156 
157 	/* bold font label */
158 	tmplabel = gtk_label_new (_("Bold"));
159 	gtk_widget_show (tmplabel);
160 	gtk_table_attach (GTK_TABLE (table), tmplabel, 0, 1, row, row+1,
161 			 (GtkAttachOptions) GTK_FILL,
162 			 (GtkAttachOptions) (0), 0, 0);
163 	gtk_label_set_justify(GTK_LABEL(tmplabel), GTK_JUSTIFY_RIGHT);
164 	gtk_misc_set_alignment(GTK_MISC(tmplabel), 1, 0.5);
165 	SET_TOGGLE_SENSITIVITY_REVERSE (derive_from_normalfont_checkbutton, tmplabel);
166 
167 	/* bold font button */
168 	entry_folderview_boldfont = gtk_font_button_new_with_font (prefs_common.boldfont);
169 	g_object_set(G_OBJECT(entry_folderview_boldfont),
170 			      "use-font", TRUE,
171 			      NULL);
172 	gtk_widget_show (entry_folderview_boldfont);
173 	gtk_table_attach (GTK_TABLE (table), entry_folderview_boldfont, 1, 2, row, row+1,
174 			 (GtkAttachOptions) (GTK_EXPAND | GTK_FILL),
175 			 (GtkAttachOptions) (0), 0, 0);
176 	SET_TOGGLE_SENSITIVITY_REVERSE (derive_from_normalfont_checkbutton, entry_folderview_boldfont);
177 	row++;
178 
179 	/* print check button */
180 	print_checkbutton = gtk_check_button_new_with_label(_("Use different font for printing"));
181 	gtk_widget_show(print_checkbutton);
182 	gtk_table_attach (GTK_TABLE (table), print_checkbutton, 0, 2, row, row+1,
183 			 (GtkAttachOptions) (GTK_EXPAND | GTK_FILL),
184 			 (GtkAttachOptions) (0), 0, 0);
185 	gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON(print_checkbutton),
186 		 prefs_common.use_different_print_font);
187 	row++;
188 
189 	/* print font label */
190 	tmplabel = gtk_label_new (_("Message Printing"));
191 	gtk_widget_show (tmplabel);
192 	gtk_table_attach (GTK_TABLE (table), tmplabel, 0, 1, row, row+1,
193 			 (GtkAttachOptions) GTK_FILL,
194 			 (GtkAttachOptions) (0), 0, 0);
195 	gtk_label_set_justify(GTK_LABEL(tmplabel), GTK_JUSTIFY_RIGHT);
196 	gtk_misc_set_alignment(GTK_MISC(tmplabel), 1, 0.5);
197 	SET_TOGGLE_SENSITIVITY (print_checkbutton, tmplabel);
198 
199 	/* print font button */
200 	entry_messageprintfont = gtk_font_button_new_with_font (prefs_common.printfont);
201 	g_object_set(G_OBJECT(entry_messageprintfont),
202 			      "use-font", TRUE,
203 			      NULL);
204 	gtk_widget_show (entry_messageprintfont);
205 	gtk_table_attach (GTK_TABLE (table), entry_messageprintfont, 1, 2, row, row+1,
206 			 (GtkAttachOptions) (GTK_EXPAND | GTK_FILL),
207 			 (GtkAttachOptions) (0), 0, 0);
208 	SET_TOGGLE_SENSITIVITY (print_checkbutton, entry_messageprintfont);
209 	row++;
210 
211 	prefs_fonts->window			= GTK_WIDGET(window);
212 	prefs_fonts->entry_folderview_smallfont = entry_folderview_smallfont;
213 	prefs_fonts->entry_folderview_normalfont = entry_folderview_normalfont;
214 	prefs_fonts->entry_folderview_boldfont   = entry_folderview_boldfont;
215 	prefs_fonts->entry_messageviewfont	= entry_messageviewfont;
216 	prefs_fonts->derive_from_normalfont_checkbutton = derive_from_normalfont_checkbutton;
217 	prefs_fonts->entry_messageprintfont	= entry_messageprintfont;
218 	prefs_fonts->print_checkbutton	   	= print_checkbutton;
219 
220 	prefs_fonts->page.widget = table;
221 }
222 
prefs_fonts_save(PrefsPage * _page)223 static void prefs_fonts_save(PrefsPage *_page)
224 {
225 	FontsPage *fonts = (FontsPage *) _page;
226 
227 	g_free(prefs_common.boldfont);
228 	prefs_common.boldfont = g_strdup(gtk_font_button_get_font_name
229 		(GTK_FONT_BUTTON(fonts->entry_folderview_boldfont)));
230 
231 	g_free(prefs_common.normalfont);
232 	prefs_common.normalfont = g_strdup(gtk_font_button_get_font_name
233 		(GTK_FONT_BUTTON(fonts->entry_folderview_normalfont)));
234 
235 	g_free(prefs_common.smallfont);
236 	prefs_common.smallfont  = g_strdup(gtk_font_button_get_font_name
237 		(GTK_FONT_BUTTON(fonts->entry_folderview_smallfont)));
238 
239 	g_free(prefs_common.textfont);
240 	prefs_common.textfont   = g_strdup(gtk_font_button_get_font_name
241 		(GTK_FONT_BUTTON(fonts->entry_messageviewfont)));
242 
243 	prefs_common.derive_from_normal_font = gtk_toggle_button_get_active
244 			(GTK_TOGGLE_BUTTON(fonts->derive_from_normalfont_checkbutton));
245 
246 	g_free(prefs_common.printfont);
247 	prefs_common.printfont   = g_strdup(gtk_font_button_get_font_name
248 		(GTK_FONT_BUTTON(fonts->entry_messageprintfont)));
249 	prefs_common.use_different_print_font = gtk_toggle_button_get_active
250 			(GTK_TOGGLE_BUTTON(fonts->print_checkbutton));
251 
252 	main_window_reflect_prefs_all();
253 }
254 
prefs_fonts_destroy_widget(PrefsPage * _page)255 static void prefs_fonts_destroy_widget(PrefsPage *_page)
256 {
257 	/* FontsPage *fonts = (FontsPage *) _page; */
258 
259 }
260 
261 FontsPage *prefs_fonts;
262 
prefs_fonts_init(void)263 void prefs_fonts_init(void)
264 {
265 	FontsPage *page;
266 	static gchar *path[3];
267 
268 	path[0] = _("Display");
269 	path[1] = _("Fonts");
270 	path[2] = NULL;
271 
272 	page = g_new0(FontsPage, 1);
273 	page->page.path = path;
274 	page->page.create_widget = prefs_fonts_create_widget;
275 	page->page.destroy_widget = prefs_fonts_destroy_widget;
276 	page->page.save_page = prefs_fonts_save;
277 	page->page.weight = 135.0;
278 	prefs_gtk_register_page((PrefsPage *) page);
279 	prefs_fonts = page;
280 }
281 
prefs_fonts_done(void)282 void prefs_fonts_done(void)
283 {
284 	prefs_gtk_unregister_page((PrefsPage *) prefs_fonts);
285 	g_free(prefs_fonts);
286 }
287