1 /*
2 * e-spell-text-view.c
3 *
4 * This program is free software; you can redistribute it and/or modify it
5 * under the terms of the GNU Lesser General Public License as published by
6 * the Free Software Foundation.
7 *
8 * This program is distributed in the hope that it will be useful, but
9 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
10 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
11 * for more details.
12 *
13 * You should have received a copy of the GNU Lesser General Public License
14 * along with this program; if not, see <http://www.gnu.org/licenses/>.
15 *
16 */
17
18 /* Just a proxy for GtkSpell Text View spell checker */
19
20 #include "evolution-config.h"
21
22 #include <gtk/gtk.h>
23
24 #ifdef HAVE_GSPELL
25 #include <gspell/gspell.h>
26 #endif
27
28 #include "e-misc-utils.h"
29 #include "e-spell-text-view.h"
30
31 /**
32 * e_spell_text_view_is_supported:
33 *
34 * Returns whether evolution was compiled with GtkSpell3. If it returns
35 * %FALSE, all the other e_spell_text_view_... functions do nothing.
36 *
37 * Returns: Whether evolution was compiled with GtkSpell3
38 *
39 * Since: 3.12
40 **/
41 gboolean
e_spell_text_view_is_supported(void)42 e_spell_text_view_is_supported (void)
43 {
44 #ifdef HAVE_GSPELL
45 return TRUE;
46 #else /* HAVE_GSPELL */
47 return FALSE;
48 #endif /* HAVE_GSPELL */
49 }
50
51 /**
52 * e_spell_text_view_attach:
53 * @text_view: a #GtkTextView
54 *
55 * Attaches a spell checker into the @text_view, if spell-checking is
56 * enabled in Evolution.
57 *
58 * Since: 3.12
59 **/
60 void
e_spell_text_view_attach(GtkTextView * text_view)61 e_spell_text_view_attach (GtkTextView *text_view)
62 {
63 #ifdef HAVE_GSPELL
64 GspellTextView *spell_view;
65 GspellTextBuffer *spell_buffer;
66 GspellChecker *checker;
67 const GspellLanguage *language = NULL;
68 GtkTextBuffer *text_buffer;
69 GSettings *settings;
70 gchar **strv;
71
72 g_return_if_fail (GTK_IS_TEXT_VIEW (text_view));
73
74 settings = e_util_ref_settings ("org.gnome.evolution.mail");
75
76 /* do nothing, if spell-checking is disabled */
77 if (!g_settings_get_boolean (settings, "composer-inline-spelling")) {
78 g_object_unref (settings);
79 return;
80 }
81
82 strv = g_settings_get_strv (settings, "composer-spell-languages");
83 g_object_unref (settings);
84
85 if (strv) {
86 gint ii;
87
88 for (ii = 0; strv[ii] && !language; ii++) {
89 language = gspell_language_lookup (strv[ii]);
90 }
91 }
92
93 g_strfreev (strv);
94
95 checker = gspell_checker_new (language);
96 text_buffer = gtk_text_view_get_buffer (text_view);
97 spell_buffer = gspell_text_buffer_get_from_gtk_text_buffer (text_buffer);
98 gspell_text_buffer_set_spell_checker (spell_buffer, checker);
99 g_object_unref (checker);
100
101 spell_view = gspell_text_view_get_from_gtk_text_view (text_view);
102 gspell_text_view_set_inline_spell_checking (spell_view, TRUE);
103 gspell_text_view_set_enable_language_menu (spell_view, TRUE);
104 #endif /* HAVE_GSPELL */
105 }
106