aboutsummaryrefslogtreecommitdiffstats
path: root/e-util/e-spell-text-view.c
blob: 623713acc8b282a09b850091ace5639d6ff92184 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
/*
 * e-spell-text-view.c
 *
 * This program is free software; you can redistribute it and/or modify it
 * under the terms of the GNU Lesser General Public License as published by
 * the Free Software Foundation.
 *
 * This program is distributed in the hope that it will be useful, but
 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
 * or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
 * for more details.
 *
 * You should have received a copy of the GNU Lesser General Public License
 * along with this program; if not, see <http://www.gnu.org/licenses/>.
 *
 */

/* Just a proxy for GtkSpell Text View spell checker */

#ifdef HAVE_CONFIG_H
#include <config.h>
#endif

#include <gtk/gtk.h>

#ifdef WITH_GTKSPELL
#include <gtkspell/gtkspell.h>
#endif

#include "e-spell-text-view.h"

/**
 * e_spell_text_view_is_supported:
 *
 * Returns whether evolution was compiled with GtkSpell3. If it returns
 * %FALSE, all the other e_spell_text_view_... functions do nothing.
 *
 * Returns: Whether evolution was compiled with GtkSpell3
 *
 * Since: 3.12
 **/
gboolean
e_spell_text_view_is_supported (void)
{
#ifdef WITH_GTKSPELL
    return TRUE;
#else /* WITH_GTKSPELL */
    return FALSE;
#endif /* WITH_GTKSPELL */
}

/**
 * e_spell_text_view_attach:
 * @text_view: a #GtkTextView
 *
 * Attaches a spell checker into the @text_view, if spell-checking is
 * enabled in Evolution.
 *
 * Returns: Whether successfully attached the spell checker
 *
 * Since: 3.12
 **/
gboolean
e_spell_text_view_attach (GtkTextView *text_view)
{
#ifdef WITH_GTKSPELL
    GtkSpellChecker *spell;
    GSettings *settings;
    gchar **strv;
    gboolean success;

    settings = g_settings_new ("org.gnome.evolution.mail");

    /* do nothing, if spell-checking is disabled */
    if (!g_settings_get_boolean (settings, "composer-inline-spelling")) {
        g_object_unref (settings);
        return FALSE;
    }

    strv = g_settings_get_strv (settings, "composer-spell-languages");
    g_object_unref (settings);

    spell = gtk_spell_checker_new ();
    g_object_set (G_OBJECT (spell), "decode-language-codes", TRUE, NULL);
    if (strv)
        gtk_spell_checker_set_language (spell, strv[0], NULL);
    success = gtk_spell_checker_attach (spell, text_view);

    g_strfreev (strv);

    return success;
#else /* WITH_GTKSPELL */
    return FALSE;
#endif /* WITH_GTKSPELL */
}

/**
 * e_spell_text_view_recheck_all:
 * @text_view: a #GtkTextView with attached spell checker
 *
 * Checks whole content of the @text_view for spell-errors,
 * if it has previously attached spell-checker with
 * e_spell_text_view_attach().
 *
 * Since: 3.12
 **/
void
e_spell_text_view_recheck_all (GtkTextView *text_view)
{
#ifdef WITH_GTKSPELL
    GtkSpellChecker *spell;

    spell = gtk_spell_checker_get_from_text_view (text_view);
    if (spell)
        gtk_spell_checker_recheck_all (spell);
#endif /* WITH_GTKSPELL */
}