2 * Sylpheed -- a GTK+ based, lightweight, and fast e-mail client
3 * Copyright (C) 2002 Hiroyuki Yamamoto & the Sylpheed-Claws 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 2 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, write to the Free Software
17 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
21 * General functions for accessing address book files.
40 #include "prefs_common.h"
41 #include "prefs_gtk.h"
43 #include "gtk/gtkutils.h"
44 #include "gtk/prefswindow.h"
45 #include "gtk/filesel.h"
46 #include "gtk/colorsel.h"
48 typedef struct _SpellingPage
52 GtkWidget *window; /* do not modify */
54 GtkWidget *checkbtn_enable_aspell;
55 GtkWidget *entry_aspell_path;
56 GtkWidget *btn_aspell_path;
57 GtkWidget *optmenu_dictionary;
58 GtkWidget *optmenu_sugmode;
59 GtkWidget *misspelled_btn;
60 GtkWidget *checkbtn_use_alternate;
61 GtkWidget *checkbtn_check_while_typing;
66 static void prefs_spelling_enable(SpellingPage *spelling, gboolean enable)
68 gtk_widget_set_sensitive(spelling->entry_aspell_path, enable);
69 gtk_widget_set_sensitive(spelling->optmenu_dictionary, enable);
70 gtk_widget_set_sensitive(spelling->optmenu_sugmode, enable);
71 gtk_widget_set_sensitive(spelling->btn_aspell_path, enable);
72 gtk_widget_set_sensitive(spelling->misspelled_btn, enable);
73 gtk_widget_set_sensitive(spelling->checkbtn_use_alternate, enable);
74 gtk_widget_set_sensitive(spelling->checkbtn_check_while_typing, enable);
77 static void prefs_spelling_checkbtn_enable_aspell_toggle_cb
81 SpellingPage *spelling = (SpellingPage *) data;
84 toggled = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget));
85 prefs_spelling_enable(spelling, toggled);
88 static void prefs_spelling_btn_aspell_path_clicked_cb(GtkWidget *widget,
91 SpellingPage *spelling = (SpellingPage *) data;
95 file_path = filesel_select_file(_("Select dictionaries location"),
96 prefs_common.aspell_path);
97 if (file_path != NULL) {
98 gchar *tmp_path, *tmp;
100 tmp_path = g_dirname(file_path);
101 tmp = g_strdup_printf("%s%s", tmp_path, G_DIR_SEPARATOR_S);
104 new_menu = gtkaspell_dictionary_option_menu_new(tmp);
105 gtk_option_menu_set_menu(GTK_OPTION_MENU(spelling->optmenu_dictionary),
108 gtk_entry_set_text(GTK_ENTRY(spelling->entry_aspell_path), tmp);
109 /* select first one */
110 gtk_option_menu_set_history(GTK_OPTION_MENU(
111 spelling->optmenu_dictionary), 0);
118 static void prefs_spelling_colorsel(GtkWidget *widget,
121 SpellingPage *spelling = (SpellingPage *) data;
124 rgbcolor = colorsel_select_color_rgb(_("Pick color for misspelled word"),
125 spelling->misspell_col);
126 gtkut_set_widget_bgcolor_rgb(spelling->misspelled_btn, rgbcolor);
127 spelling->misspell_col = rgbcolor;
130 #define SAFE_STRING(str) \
133 void prefs_spelling_create_widget(PrefsPage *_page, GtkWindow *window, gpointer data)
135 SpellingPage *prefs_spelling = (SpellingPage *) _page;
139 /* START GLADE CODE */
141 GtkWidget *checkbtn_enable_aspell;
142 GtkWidget *checkbtn_check_while_typing;
143 GtkWidget *checkbtn_use_alternate;
146 GtkWidget *entry_aspell_path;
148 GtkWidget *optmenu_dictionary;
149 GtkWidget *optmenu_dictionary_menu;
151 GtkWidget *optmenu_sugmode;
152 GtkWidget *optmenu_sugmode_menu;
154 GtkWidget *btn_aspell_path;
156 GtkWidget *misspelled_btn;
158 table = gtk_table_new(8, 3, FALSE);
159 gtk_widget_show(table);
160 gtk_container_set_border_width(GTK_CONTAINER(table), 8);
161 gtk_table_set_row_spacings(GTK_TABLE(table), 4);
162 gtk_table_set_col_spacings(GTK_TABLE(table), 8);
164 checkbtn_enable_aspell =
165 gtk_check_button_new_with_label(_("Enable spell checker"));
166 gtk_widget_show(checkbtn_enable_aspell);
167 gtk_table_attach(GTK_TABLE(table), checkbtn_enable_aspell, 0, 3, 0,
168 1, (GtkAttachOptions) (GTK_FILL),
169 (GtkAttachOptions) (0), 0, 0);
171 checkbtn_check_while_typing =
172 gtk_check_button_new_with_label(_("Check while typing"));
173 gtk_widget_show(checkbtn_check_while_typing);
174 gtk_table_attach(GTK_TABLE(table), checkbtn_check_while_typing, 0,
175 3, 1, 2, (GtkAttachOptions) (GTK_FILL),
176 (GtkAttachOptions) (0), 0, 0);
178 checkbtn_use_alternate =
179 gtk_check_button_new_with_label(_
180 ("Enable alternate dictionary"));
181 gtk_widget_show(checkbtn_use_alternate);
182 gtk_table_attach(GTK_TABLE(table), checkbtn_use_alternate, 0, 3, 2,
183 3, (GtkAttachOptions) (GTK_FILL),
184 (GtkAttachOptions) (0), 0, 0);
188 ("Enabling an alternate dictionary makes switching\nwith the last used dictionary faster"));
189 gtk_widget_show(label1);
190 gtk_table_attach(GTK_TABLE(table), label1, 0, 3, 3, 4,
191 (GtkAttachOptions) (GTK_FILL),
192 (GtkAttachOptions) (0), 0, 0);
193 gtk_misc_set_alignment(GTK_MISC(label1), 7.45058e-09, 0.5);
195 label2 = gtk_label_new(_("Dictionaries path:"));
196 gtk_widget_show(label2);
197 gtk_table_attach(GTK_TABLE(table), label2, 0, 1, 4, 5,
198 (GtkAttachOptions) (GTK_FILL),
199 (GtkAttachOptions) (0), 0, 0);
200 gtk_label_set_justify(GTK_LABEL(label2), GTK_JUSTIFY_RIGHT);
201 gtk_misc_set_alignment(GTK_MISC(label2), 1, 0.5);
203 entry_aspell_path = gtk_entry_new();
204 gtk_widget_show(entry_aspell_path);
205 gtk_table_attach(GTK_TABLE(table), entry_aspell_path, 1, 2, 4, 5,
206 (GtkAttachOptions) (GTK_EXPAND | GTK_FILL),
207 (GtkAttachOptions) (0), 0, 0);
209 label3 = gtk_label_new(_("Default dictionary:"));
210 gtk_widget_show(label3);
211 gtk_table_attach(GTK_TABLE(table), label3, 0, 1, 5, 6,
212 (GtkAttachOptions) (GTK_FILL),
213 (GtkAttachOptions) (0), 0, 0);
214 gtk_label_set_justify(GTK_LABEL(label3), GTK_JUSTIFY_RIGHT);
215 gtk_misc_set_alignment(GTK_MISC(label3), 1, 0.5);
217 optmenu_dictionary = gtk_option_menu_new();
218 gtk_widget_show(optmenu_dictionary);
219 gtk_table_attach(GTK_TABLE(table), optmenu_dictionary, 1, 3, 5, 6,
220 (GtkAttachOptions) (GTK_FILL),
221 (GtkAttachOptions) (0), 0, 0);
222 optmenu_dictionary_menu = gtk_menu_new();
223 gtk_option_menu_set_menu(GTK_OPTION_MENU(optmenu_dictionary),
224 optmenu_dictionary_menu);
226 label4 = gtk_label_new(_("Default suggestion mode:"));
227 gtk_widget_show(label4);
228 gtk_table_attach(GTK_TABLE(table), label4, 0, 1, 6, 7,
229 (GtkAttachOptions) (GTK_FILL),
230 (GtkAttachOptions) (0), 0, 0);
231 gtk_label_set_justify(GTK_LABEL(label4), GTK_JUSTIFY_RIGHT);
232 gtk_misc_set_alignment(GTK_MISC(label4), 1, 0.5);
234 optmenu_sugmode = gtk_option_menu_new();
235 gtk_widget_show(optmenu_sugmode);
236 gtk_table_attach(GTK_TABLE(table), optmenu_sugmode, 1, 3, 6, 7,
237 (GtkAttachOptions) (GTK_FILL),
238 (GtkAttachOptions) (0), 0, 0);
239 optmenu_sugmode_menu = gtk_menu_new();
240 gtk_option_menu_set_menu(GTK_OPTION_MENU(optmenu_sugmode),
241 optmenu_sugmode_menu);
243 label5 = gtk_label_new(_("Misspelled word color:"));
244 gtk_widget_show(label5);
245 gtk_table_attach(GTK_TABLE(table), label5, 0, 1, 7, 8,
246 (GtkAttachOptions) (GTK_FILL),
247 (GtkAttachOptions) (0), 0, 0);
248 gtk_label_set_justify(GTK_LABEL(label5), GTK_JUSTIFY_RIGHT);
249 gtk_misc_set_alignment(GTK_MISC(label5), 1, 0.5);
251 btn_aspell_path = gtk_button_new_with_label(_(" ... "));
252 gtk_widget_show(btn_aspell_path);
253 gtk_table_attach(GTK_TABLE(table), btn_aspell_path, 2, 3, 4, 5,
254 (GtkAttachOptions) (GTK_FILL),
255 (GtkAttachOptions) (0), 0, 0);
257 hbox1 = gtk_hbox_new(FALSE, 0);
258 gtk_widget_show(hbox1);
259 gtk_table_attach(GTK_TABLE(table), hbox1, 1, 2, 7, 8,
260 (GtkAttachOptions) (GTK_FILL),
261 (GtkAttachOptions) (GTK_FILL), 0, 0);
263 misspelled_btn = gtk_button_new_with_label("");
264 gtk_widget_show(misspelled_btn);
265 gtk_box_pack_start(GTK_BOX(hbox1), misspelled_btn, FALSE, FALSE,
267 gtk_widget_set_usize(misspelled_btn, 30, 20);
270 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(checkbtn_enable_aspell),
271 prefs_common.enable_aspell);
272 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(checkbtn_check_while_typing),
273 prefs_common.check_while_typing);
274 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(checkbtn_use_alternate),
275 prefs_common.use_alternate);
276 gtk_entry_set_text(GTK_ENTRY(entry_aspell_path),
277 SAFE_STRING(prefs_common.aspell_path));
279 gtk_signal_connect(GTK_OBJECT(checkbtn_enable_aspell), "toggled",
280 GTK_SIGNAL_FUNC(prefs_spelling_checkbtn_enable_aspell_toggle_cb),
282 gtk_signal_connect(GTK_OBJECT(btn_aspell_path), "clicked",
283 GTK_SIGNAL_FUNC(prefs_spelling_btn_aspell_path_clicked_cb),
285 gtk_signal_connect(GTK_OBJECT(misspelled_btn), "clicked",
286 GTK_SIGNAL_FUNC(prefs_spelling_colorsel), prefs_spelling);
288 gtk_option_menu_set_menu(GTK_OPTION_MENU(optmenu_dictionary),
289 gtkaspell_dictionary_option_menu_new(prefs_common.aspell_path));
291 for (cur = GTK_MENU_SHELL(gtk_option_menu_get_menu(GTK_OPTION_MENU(optmenu_dictionary)))->children;
292 cur != NULL; cur = cur->next) {
296 menuitem = GTK_WIDGET(cur->data);
297 dict_name = gtk_object_get_data(GTK_OBJECT(menuitem),
299 if (!strcmp2(dict_name, prefs_common.dictionary)) {
300 gtk_option_menu_set_history(GTK_OPTION_MENU(optmenu_dictionary), n);
305 gtk_option_menu_set_menu(GTK_OPTION_MENU(optmenu_sugmode),
306 gtkaspell_sugmode_option_menu_new(prefs_common.aspell_sugmode));
307 gtkaspell_sugmode_option_menu_set(GTK_OPTION_MENU(optmenu_sugmode),
308 prefs_common.aspell_sugmode);
310 prefs_spelling->misspell_col = prefs_common.misspelled_col;
311 gtkut_set_widget_bgcolor_rgb(misspelled_btn, prefs_spelling->misspell_col);
313 prefs_spelling->window
314 = GTK_WIDGET(window);
315 prefs_spelling->checkbtn_enable_aspell
316 = checkbtn_enable_aspell;
317 prefs_spelling->entry_aspell_path
319 prefs_spelling->btn_aspell_path
321 prefs_spelling->optmenu_dictionary
322 = optmenu_dictionary;
323 prefs_spelling->optmenu_sugmode
325 prefs_spelling->checkbtn_use_alternate
326 = checkbtn_use_alternate;
327 prefs_spelling->checkbtn_check_while_typing
328 = checkbtn_check_while_typing;
329 prefs_spelling->misspelled_btn
332 prefs_spelling->page.widget = table;
334 prefs_spelling_enable(prefs_spelling, prefs_common.enable_aspell);
337 void prefs_spelling_save(PrefsPage *_page)
339 SpellingPage *spelling = (SpellingPage *) _page;
341 prefs_common.enable_aspell =
342 gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(spelling->checkbtn_enable_aspell));
343 prefs_common.check_while_typing =
344 gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(spelling->checkbtn_check_while_typing));
345 prefs_common.use_alternate =
346 gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(spelling->checkbtn_use_alternate));
348 if (prefs_common.aspell_path)
349 g_free(prefs_common.aspell_path);
350 prefs_common.aspell_path =
351 gtk_editable_get_chars(GTK_EDITABLE(spelling->entry_aspell_path), 0, -1);
353 if (prefs_common.dictionary != NULL)
354 g_free(prefs_common.dictionary);
355 prefs_common.dictionary =
356 gtkaspell_get_dictionary_menu_active_item(
357 gtk_option_menu_get_menu(
359 spelling->optmenu_dictionary)));
361 prefs_common.aspell_sugmode =
362 gtkaspell_get_sugmode_from_option_menu(
363 GTK_OPTION_MENU(spelling->optmenu_sugmode));
365 prefs_common.misspelled_col = spelling->misspell_col;
368 static void prefs_spelling_destroy_widget(PrefsPage *_page)
370 /* SpellingPage *spelling = (SpellingPage *) _page; */
374 SpellingPage *prefs_spelling;
376 void prefs_spelling_init(void)
380 page = g_new0(SpellingPage, 1);
381 page->page.path = _("Compose/Spell Checker");
382 page->page.create_widget = prefs_spelling_create_widget;
383 page->page.destroy_widget = prefs_spelling_destroy_widget;
384 page->page.save_page = prefs_spelling_save;
385 page->page.weight = 50.0;
386 prefs_gtk_register_page((PrefsPage *) page);
387 prefs_spelling = page;
390 void prefs_spelling_done(void)
392 prefs_gtk_unregister_page((PrefsPage *) prefs_spelling);
393 g_free(prefs_spelling);
396 #endif /* USE_ASPELL */