A bit more room for alertpanel messages
[claws.git] / src / prefs_spelling.c
blob02f82596d906ef37775975ce373d300aeafd3001
1 /*
2 * Sylpheed -- a GTK+ based, lightweight, and fast e-mail client
3 * Copyright (C) 2002-2012 Hiroyuki Yamamoto & the Claws Mail team
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.
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.
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/>.
20 #ifdef HAVE_CONFIG_H
21 # include "config.h"
22 #include "claws-features.h"
23 #endif
25 #if USE_ENCHANT
27 #include "defs.h"
29 #include <stdio.h>
30 #include <stdlib.h>
32 #include <glib.h>
33 #include <glib/gi18n.h>
34 #include <gtk/gtk.h>
36 #include "utils.h"
37 #include "prefs_common.h"
38 #include "prefs_gtk.h"
40 #include "gtk/gtkutils.h"
41 #include "gtk/prefswindow.h"
42 #include "gtk/filesel.h"
43 #include "gtk/colorsel.h"
44 #include "gtk/combobox.h"
46 typedef struct _SpellingPage
48 PrefsPage page;
50 GtkWidget *window; /* do not modify */
52 GtkWidget *automatic_frame;
53 GtkWidget *dictionary_frame;
55 GtkWidget *enable_aspell_checkbtn;
56 GtkWidget *recheck_when_changing_dict_checkbtn;
57 GtkWidget *check_while_typing_checkbtn;
58 GtkWidget *use_alternate_checkbtn;
60 GtkWidget *default_dict_label;
61 GtkWidget *default_dict_combo;
63 GtkWidget *default_alt_dict_label;
64 GtkWidget *default_alt_dict_combo;
66 GtkWidget *both_dict_check;
68 GtkWidget *misspelled_label;
69 GtkWidget *misspelled_colorbtn;
70 GtkWidget *misspelled_useblack_label;
72 gint misspell_col;
73 } SpellingPage;
75 static void prefs_spelling_colorsel(GtkWidget *widget,
76 gpointer data)
78 SpellingPage *spelling = (SpellingPage *) data;
79 gint rgbcolor;
81 rgbcolor = colorsel_select_color_rgb(_("Pick color for misspelled word"),
82 spelling->misspell_col);
83 gtkut_set_widget_bgcolor_rgb(spelling->misspelled_colorbtn, rgbcolor);
84 spelling->misspell_col = rgbcolor;
87 #define SAFE_STRING(str) \
88 (str) ? (str) : ""
90 static void prefs_spelling_create_widget(PrefsPage *_page, GtkWindow *window, gpointer data)
92 SpellingPage *prefs_spelling = (SpellingPage *) _page;
94 GtkWidget *vbox1, *vbox2;
96 GtkWidget *enable_aspell_checkbtn;
97 GtkWidget *check_while_typing_checkbtn;
98 GtkWidget *recheck_when_changing_dict_checkbtn;
99 GtkWidget *use_alternate_checkbtn;
101 GtkWidget *automatic_frame;
102 GtkWidget *dictionary_frame;
104 GtkWidget *table;
106 GtkWidget *default_dict_label;
107 GtkWidget *default_dict_combo;
109 GtkWidget *default_alt_dict_label;
110 GtkWidget *default_alt_dict_combo;
111 GtkWidget *both_dict_check;
112 #ifdef WIN32
113 GtkWidget *get_dictionaries_btn;
114 #endif
116 GtkWidget *misspelled_label;
117 GtkWidget *misspelled_hbox;
118 GtkWidget *misspelled_colorbtn;
120 vbox1 = gtk_vbox_new (FALSE, VSPACING);
121 gtk_widget_show (vbox1);
122 gtk_container_set_border_width (GTK_CONTAINER (vbox1), VBOX_BORDER);
124 vbox2 = gtk_vbox_new (FALSE, 0);
125 gtk_widget_show (vbox2);
126 gtk_box_pack_start (GTK_BOX (vbox1), vbox2, FALSE, FALSE, 0);
128 enable_aspell_checkbtn = gtk_check_button_new_with_label(
129 _("Enable spell checker"));
130 gtk_widget_show(enable_aspell_checkbtn);
131 gtk_box_pack_start(GTK_BOX(vbox2), enable_aspell_checkbtn, TRUE, TRUE, 0);
133 use_alternate_checkbtn = gtk_check_button_new_with_label(
134 _("Enable alternate dictionary"));
135 gtk_widget_show(use_alternate_checkbtn);
136 gtk_box_pack_start(GTK_BOX(vbox2), use_alternate_checkbtn, TRUE, TRUE, 0);
138 CLAWS_SET_TIP(use_alternate_checkbtn,
139 _("Faster switching with last used dictionary"));
141 vbox2 = gtkut_get_options_frame(vbox1, &automatic_frame, _("Automatic spell checking"));
143 check_while_typing_checkbtn = gtk_check_button_new_with_label(
144 _("Check while typing"));
145 gtk_widget_show(check_while_typing_checkbtn);
146 gtk_box_pack_start(GTK_BOX(vbox2), check_while_typing_checkbtn, TRUE, TRUE, 0);
148 recheck_when_changing_dict_checkbtn = gtk_check_button_new_with_label(
149 _("Re-check message when changing dictionary"));
150 gtk_widget_show(recheck_when_changing_dict_checkbtn);
151 gtk_box_pack_start(GTK_BOX(vbox2), recheck_when_changing_dict_checkbtn, TRUE, TRUE, 0);
153 vbox2 = gtkut_get_options_frame(vbox1, &dictionary_frame, _("Dictionary"));
155 table = gtk_table_new(6, 4, FALSE);
156 gtk_widget_show(table);
157 gtk_container_set_border_width(GTK_CONTAINER(table), 0);
158 gtk_table_set_row_spacings(GTK_TABLE(table), 4);
159 gtk_table_set_col_spacings(GTK_TABLE(table), 8);
161 gtk_box_pack_start(GTK_BOX(vbox2), table, TRUE, TRUE, 0);
163 default_dict_label = gtk_label_new(_("Default dictionary"));
164 gtk_widget_show(default_dict_label);
165 gtk_table_attach(GTK_TABLE (table), default_dict_label, 0, 1, 0, 1,
166 (GtkAttachOptions) (GTK_FILL),
167 (GtkAttachOptions) (0), 0, 2);
168 gtk_label_set_justify(GTK_LABEL(default_dict_label), GTK_JUSTIFY_RIGHT);
169 gtk_misc_set_alignment(GTK_MISC(default_dict_label), 1, 0.5);
171 default_dict_combo = gtkaspell_dictionary_combo_new(TRUE);
172 gtk_widget_set_size_request(default_dict_combo, 180, -1);
173 gtk_table_attach (GTK_TABLE (table), default_dict_combo, 1, 2, 0, 1,
174 GTK_SHRINK, 0, 0, 0);
176 default_alt_dict_label = gtk_label_new(_("Default alternate dictionary"));
177 gtk_widget_show(default_alt_dict_label);
178 gtk_table_attach(GTK_TABLE (table), default_alt_dict_label, 0, 1, 1, 2,
179 (GtkAttachOptions) (GTK_FILL),
180 (GtkAttachOptions) (0), 0, 2);
181 gtk_label_set_justify(GTK_LABEL(default_alt_dict_label), GTK_JUSTIFY_RIGHT);
182 gtk_misc_set_alignment(GTK_MISC(default_alt_dict_label), 1, 0.5);
184 default_alt_dict_combo = gtkaspell_dictionary_combo_new(FALSE);
185 gtk_widget_set_size_request(default_alt_dict_combo, 180, -1);
186 gtk_table_attach (GTK_TABLE (table), default_alt_dict_combo, 1, 2, 1, 2,
187 GTK_SHRINK, 0, 0, 0);
189 both_dict_check = gtk_check_button_new_with_label(
190 _("Check with both dictionaries"));
191 gtk_widget_show(both_dict_check);
192 gtk_table_attach (GTK_TABLE (table), both_dict_check, 1, 2, 2, 3,
193 GTK_SHRINK, 0, 0, 0);
195 #ifdef WIN32
196 get_dictionaries_btn = gtkut_get_link_btn(GTK_WIDGET(window),
197 DICTS_URI, _("Get more dictionaries..."));
199 gtk_widget_show(get_dictionaries_btn);
200 gtk_table_attach (GTK_TABLE (table), get_dictionaries_btn, 1, 2, 3, 4,
201 GTK_SHRINK, 0, 0, 0);
202 #endif
203 misspelled_hbox = gtk_hbox_new(FALSE, 10);
204 gtk_widget_show(misspelled_hbox);
205 gtk_box_pack_start(GTK_BOX(vbox1), misspelled_hbox, FALSE, FALSE, 0);
207 misspelled_label = gtk_label_new(_("Misspelled word color"));
208 gtk_widget_show(misspelled_label);
209 gtk_box_pack_start(GTK_BOX(misspelled_hbox), misspelled_label,
210 FALSE, FALSE, 0);
211 gtk_label_set_justify(GTK_LABEL(misspelled_label), GTK_JUSTIFY_RIGHT);
212 gtk_misc_set_alignment(GTK_MISC(misspelled_label), 1, 0.5);
214 misspelled_colorbtn = gtk_button_new_with_label("");
215 gtk_widget_show(misspelled_colorbtn);
216 gtk_box_pack_start(GTK_BOX(misspelled_hbox), misspelled_colorbtn,
217 FALSE, FALSE, 0);
218 gtk_widget_set_size_request(misspelled_colorbtn, 30, 20);
219 CLAWS_SET_TIP(misspelled_colorbtn,
220 _("Pick color for misspelled word. "
221 "Use black to underline"));
223 SET_TOGGLE_SENSITIVITY(enable_aspell_checkbtn, automatic_frame);
224 SET_TOGGLE_SENSITIVITY(enable_aspell_checkbtn, dictionary_frame);
225 SET_TOGGLE_SENSITIVITY(enable_aspell_checkbtn, misspelled_label);
226 SET_TOGGLE_SENSITIVITY(enable_aspell_checkbtn, misspelled_colorbtn);
227 SET_TOGGLE_SENSITIVITY(enable_aspell_checkbtn, use_alternate_checkbtn);
228 SET_TOGGLE_SENSITIVITY(use_alternate_checkbtn, default_alt_dict_label);
229 SET_TOGGLE_SENSITIVITY(use_alternate_checkbtn, default_alt_dict_combo);
230 SET_TOGGLE_SENSITIVITY(use_alternate_checkbtn, both_dict_check);
232 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(enable_aspell_checkbtn),
233 prefs_common.enable_aspell);
234 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(both_dict_check),
235 prefs_common.use_both_dicts);
236 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(check_while_typing_checkbtn),
237 prefs_common.check_while_typing);
238 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(recheck_when_changing_dict_checkbtn),
239 prefs_common.recheck_when_changing_dict);
240 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(use_alternate_checkbtn),
241 prefs_common.use_alternate);
242 if (prefs_common.dictionary &&
243 strrchr(prefs_common.dictionary, '/')) {
244 gchar *tmp = g_strdup(strrchr(prefs_common.dictionary, '/')+1);
245 g_free(prefs_common.dictionary);
246 prefs_common.dictionary = tmp;
248 if (prefs_common.alt_dictionary &&
249 strrchr(prefs_common.alt_dictionary, '/')) {
250 gchar *tmp = g_strdup(strrchr(prefs_common.alt_dictionary, '/')+1);
251 g_free(prefs_common.alt_dictionary);
252 prefs_common.alt_dictionary = tmp;
254 if (prefs_common.dictionary &&
255 strchr(prefs_common.dictionary, '-')) {
256 *(strchr(prefs_common.dictionary, '-')) = '\0';
258 if (prefs_common.alt_dictionary &&
259 strchr(prefs_common.alt_dictionary, '-')) {
260 *(strchr(prefs_common.alt_dictionary, '-')) = '\0';
262 gtkaspell_set_dictionary_menu_active_item(GTK_COMBO_BOX(default_dict_combo),
263 prefs_common.dictionary);
265 gtkaspell_set_dictionary_menu_active_item(GTK_COMBO_BOX(default_alt_dict_combo),
266 prefs_common.alt_dictionary);
268 g_signal_connect(G_OBJECT(misspelled_colorbtn), "clicked",
269 G_CALLBACK(prefs_spelling_colorsel), prefs_spelling);
271 prefs_spelling->misspell_col = prefs_common.misspelled_col;
272 gtkut_set_widget_bgcolor_rgb(misspelled_colorbtn, prefs_spelling->misspell_col);
274 prefs_spelling->window = GTK_WIDGET(window);
275 prefs_spelling->automatic_frame = automatic_frame;
276 prefs_spelling->dictionary_frame = dictionary_frame;
277 prefs_spelling->enable_aspell_checkbtn = enable_aspell_checkbtn;
278 prefs_spelling->check_while_typing_checkbtn
279 = check_while_typing_checkbtn;
280 prefs_spelling->recheck_when_changing_dict_checkbtn
281 = recheck_when_changing_dict_checkbtn;
282 prefs_spelling->use_alternate_checkbtn = use_alternate_checkbtn;
283 prefs_spelling->default_dict_label = default_dict_label;
284 prefs_spelling->default_dict_combo = default_dict_combo;
285 prefs_spelling->default_alt_dict_label = default_alt_dict_label;
286 prefs_spelling->default_alt_dict_combo = default_alt_dict_combo;
287 prefs_spelling->misspelled_label = misspelled_label;
288 prefs_spelling->misspelled_colorbtn = misspelled_colorbtn;
289 prefs_spelling->both_dict_check = both_dict_check;
291 prefs_spelling->page.widget = vbox1;
294 static void prefs_spelling_save(PrefsPage *_page)
296 SpellingPage *spelling = (SpellingPage *) _page;
298 prefs_common.enable_aspell =
299 gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(spelling->enable_aspell_checkbtn));
300 prefs_common.check_while_typing =
301 gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(spelling->check_while_typing_checkbtn));
302 prefs_common.recheck_when_changing_dict =
303 gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(spelling->recheck_when_changing_dict_checkbtn));
304 prefs_common.use_alternate =
305 gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(spelling->use_alternate_checkbtn));
306 prefs_common.use_both_dicts =
307 gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(spelling->both_dict_check));
309 g_free(prefs_common.dictionary);
310 prefs_common.dictionary =
311 gtkaspell_get_dictionary_menu_active_item(
312 GTK_COMBO_BOX(spelling->default_dict_combo));
314 g_free(prefs_common.alt_dictionary);
315 prefs_common.alt_dictionary =
316 gtkaspell_get_dictionary_menu_active_item(
317 GTK_COMBO_BOX(spelling->default_alt_dict_combo));
319 prefs_common.misspelled_col = spelling->misspell_col;
322 static void prefs_spelling_destroy_widget(PrefsPage *_page)
324 /* SpellingPage *spelling = (SpellingPage *) _page; */
328 SpellingPage *prefs_spelling;
330 void prefs_spelling_init(void)
332 SpellingPage *page;
333 static gchar *path[3];
334 const gchar* language = NULL;
336 path[0] = _("Compose");
337 path[1] = _("Spell Checking");
338 path[2] = NULL;
340 page = g_new0(SpellingPage, 1);
341 page->page.path = path;
342 page->page.create_widget = prefs_spelling_create_widget;
343 page->page.destroy_widget = prefs_spelling_destroy_widget;
344 page->page.save_page = prefs_spelling_save;
345 page->page.weight = 180.0;
347 prefs_gtk_register_page((PrefsPage *) page);
348 prefs_spelling = page;
350 language = g_getenv("LANG");
351 if (language == NULL)
352 language = "en";
353 else if (!strcmp(language, "POSIX") || !strcmp(language, "C"))
354 language = "en";
356 if (!prefs_common.dictionary)
357 prefs_common.dictionary = g_strdup_printf("%s",
358 language);
359 if (!strlen(prefs_common.dictionary)
360 || !strcmp(prefs_common.dictionary,"(None"))
361 prefs_common.dictionary = g_strdup_printf("%s",
362 language);
363 if (strcasestr(prefs_common.dictionary,".utf"))
364 *(strcasestr(prefs_common.dictionary,".utf")) = '\0';
365 if (strstr(prefs_common.dictionary,"@"))
366 *(strstr(prefs_common.dictionary,"@")) = '\0';
369 void prefs_spelling_done(void)
371 prefs_gtk_unregister_page((PrefsPage *) prefs_spelling);
372 g_free(prefs_spelling);
375 #endif /* USE_ENCHANT */