aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorXavier Claessens <xclaesse@src.gnome.org>2008-04-22 18:18:04 +0800
committerXavier Claessens <xclaesse@src.gnome.org>2008-04-22 18:18:04 +0800
commitd8af806a5349ed9a64838c250ff8ff7c8de2e118 (patch)
treec5f71d2eb8ca54866bdd0fc68c32859daf31c096
parent04f109cbdd7e415aee4b0b0e466d63f2364e8c5d (diff)
downloadgsoc2013-empathy-d8af806a5349ed9a64838c250ff8ff7c8de2e118.tar
gsoc2013-empathy-d8af806a5349ed9a64838c250ff8ff7c8de2e118.tar.gz
gsoc2013-empathy-d8af806a5349ed9a64838c250ff8ff7c8de2e118.tar.bz2
gsoc2013-empathy-d8af806a5349ed9a64838c250ff8ff7c8de2e118.tar.lz
gsoc2013-empathy-d8af806a5349ed9a64838c250ff8ff7c8de2e118.tar.xz
gsoc2013-empathy-d8af806a5349ed9a64838c250ff8ff7c8de2e118.tar.zst
gsoc2013-empathy-d8af806a5349ed9a64838c250ff8ff7c8de2e118.zip
Use enchant instead of aspell. Fixes bug #460624 (Frederic Peters).
svn path=/trunk/; revision=1030
-rw-r--r--configure.ac96
-rw-r--r--libempathy-gtk/empathy-spell.c138
2 files changed, 119 insertions, 115 deletions
diff --git a/configure.ac b/configure.ac
index 8f4abc2cf..374756a56 100644
--- a/configure.ac
+++ b/configure.ac
@@ -111,52 +111,62 @@ AC_DEFINE_UNQUOTED(GETTEXT_PACKAGE,"$GETTEXT_PACKAGE",[Gettext package name])
AM_GLIB_GNU_GETTEXT
-# -----------------------------------------------------------
-# ISO codes, used for aspell support
-# -----------------------------------------------------------
-AC_MSG_CHECKING([whether iso-codes exists and has iso-639 domain])
-if $PKG_CONFIG --variable=domains iso-codes | grep -q 639 ; then
- AC_MSG_RESULT([yes])
- iso_codes_prefix=`$PKG_CONFIG --variable=prefix iso-codes`
- iso_codes_pkgconfig=iso-codes
- have_iso_codes=yes
+dnl ================================================================
+dnl spellchecking checks: enchant and iso-codes
+dnl ================================================================
+
+ENCHANT_REQUIRED=1.2.0
+ISO_CODES_REQUIRED=0.35
+
+AC_ARG_ENABLE([spell],
+ AS_HELP_STRING([--disable-spell],[Disable spell checking (default: enabled)]),
+ [enable_enchant=$enableval],
+ [enable_enchant=yes])
+
+if test "x$enable_enchant" = "xyes" ; then
+
+ PKG_CHECK_MODULES(ENCHANT, enchant >= $ENCHANT_REQUIRED, \
+ have_enchant=yes, have_enchant=no)
+
+ if test "x$have_enchant" = "xyes"; then
+
+ PKG_CHECK_EXISTS([iso-codes >= $ISO_CODES_REQUIRED],
+ [have_iso_codes=yes],[have_iso_codes=no])
+
+ if test "x$have_iso_codes" = "xyes"; then
+ AC_MSG_CHECKING([whether iso-codes has iso-639 and iso-3166 domains])
+ if $PKG_CONFIG --variable=domains iso-codes | grep 639 > /dev/null && \
+ $PKG_CONFIG --variable=domains iso-codes | grep 3166 > /dev/null ; then
+ result=yes
+ else
+ result=no
+ have_iso_codes=no
+ fi
+ AC_MSG_RESULT([$result])
+ fi
+
+ if test "x$have_iso_codes" = "xyes"; then
+ AC_DEFINE_UNQUOTED([ISO_CODES_PREFIX],["`$PKG_CONFIG --variable=prefix iso-codes`"],[ISO codes prefix])
+ AC_DEFINE([HAVE_ISO_CODES],[1],[Define if you have the iso-codes package])
+ else
+ AC_MSG_ERROR([iso-codes is required for spellchecking. Use --disable-spell to build without spellchecking support.])
+ fi
+
+ enable_enchant=yes
+ ENCHANT_CFLAGS="${ENCHANT_CFLAGS}"
+ ENCHANT_LIBS="${ENCHANT_LIBS}"
+ AC_DEFINE([HAVE_ENCHANT],[1],[Define if you have libenchant])
+ else
+ AC_MSG_ERROR([Enchant library not found or too old. Use --disable-spell to build without spellchecking support.])
+ fi
else
- AC_MSG_RESULT([no])
- iso_codes_prefix=
- iso_codes_pkgconfig=
- have_iso_codes=no
-fi
-
-AC_DEFINE_UNQUOTED([ISO_CODES_PREFIX],["$iso_codes_prefix"],[ISO codes prefix])
-
-# -----------------------------------------------------------
-# ASpell
-# -----------------------------------------------------------
-AC_ARG_ENABLE(aspell,
- AS_HELP_STRING([--enable-aspell=@<:@no/yes/auto@:>@],
- [compile with aspell support]), ,
- enable_aspell=auto)
-
-if test "x$enable_aspell" = "xyes" -a "x$have_iso_codes" != "xyes"; then
- AC_MSG_ERROR([You must have iso-codes with the iso-639 domain to use aspell.])
+ enable_enchant=no
+ ENCHANT_CFLAGS=
+ ENCHANT_LIBS=
fi
-if test "x$enable_aspell" != "xno" -a "x$have_iso_codes" = "xyes"; then
- AC_CHECK_LIB(aspell, aspell_speller_check,have_aspell=yes,have_aspell=no,)
-
- if test "x$have_aspell" = "xyes"; then
- AC_DEFINE(HAVE_ASPELL, 1, [Define if we have aspell])
- EMPATHY_LIBS="$EMPATHY_LIBS -laspell"
- else
- have_aspell=no
- fi
-else
- have_aspell=no
-fi
-
-if test "x$enable_aspell" = "xyes" -a "x$have_aspell" != "xyes"; then
- AC_MSG_ERROR([Couldn't find aspell.])
-fi
+AC_SUBST(ENCHANT_CFLAGS)
+AC_SUBST(ENCHANT_LIBS)
# -----------------------------------------------------------
diff --git a/libempathy-gtk/empathy-spell.c b/libempathy-gtk/empathy-spell.c
index db3233294..345dd79ee 100644
--- a/libempathy-gtk/empathy-spell.c
+++ b/libempathy-gtk/empathy-spell.c
@@ -28,8 +28,8 @@
#include <glib/gi18n.h>
-#ifdef HAVE_ASPELL
-#include <aspell.h>
+#ifdef HAVE_ENCHANT
+#include <enchant.h>
#endif
#include <libempathy/empathy-debug.h>
@@ -39,16 +39,11 @@
#define DEBUG_DOMAIN "Spell"
-#ifdef HAVE_ASPELL
-
-/* Note: We could use aspell_reset_cache (NULL); periodically if we wanted
- * to...
- */
+#ifdef HAVE_ENCHANT
typedef struct {
- AspellConfig *spell_config;
- AspellCanHaveError *spell_possible_err;
- AspellSpeller *spell_checker;
+ EnchantBroker *config;
+ EnchantDict *speller;
} SpellLanguage;
#define ISO_CODES_DATADIR ISO_CODES_PREFIX "/share/xml/iso-codes"
@@ -179,9 +174,9 @@ spell_notify_languages_cb (EmpathyConf *conf,
lang = l->data;
- delete_aspell_config (lang->spell_config);
- delete_aspell_speller (lang->spell_checker);
-
+ enchant_broker_free_dict (lang->config, lang->speller);
+ enchant_broker_free (lang->config);
+
g_slice_free (SpellLanguage, lang);
}
@@ -222,20 +217,11 @@ spell_setup_languages (void)
lang = g_slice_new0 (SpellLanguage);
- lang->spell_config = new_aspell_config();
-
- aspell_config_replace (lang->spell_config, "encoding", "utf-8");
- aspell_config_replace (lang->spell_config, "lang", strv[i++]);
+ lang->config = enchant_broker_init ();
+ lang->speller = enchant_broker_request_dict (lang->config, strv[i]);
- lang->spell_possible_err = new_aspell_speller (lang->spell_config);
-
- if (aspell_error_number (lang->spell_possible_err) == 0) {
- lang->spell_checker = to_aspell_speller (lang->spell_possible_err);
- languages = g_list_append (languages, lang);
- } else {
- delete_aspell_config (lang->spell_config);
- g_slice_free (SpellLanguage, lang);
- }
+ languages = g_list_append (languages, lang);
+ i++;
}
if (strv) {
@@ -265,31 +251,42 @@ empathy_spell_get_language_name (const char *code)
return dgettext ("iso_639", name);
}
-GList *
-empathy_spell_get_language_codes (void)
+static void
+enumerate_dicts (const char * const lang_tag,
+ const char * const provider_name,
+ const char * const provider_desc,
+ const char * const provider_file,
+ void * user_data)
{
- AspellConfig *config;
- AspellDictInfoList *dlist;
- AspellDictInfoEnumeration *dels;
- const AspellDictInfo *entry;
- GList *codes = NULL;
-
- config = new_aspell_config ();
- dlist = get_aspell_dict_info_list (config);
- dels = aspell_dict_info_list_elements (dlist);
-
- while ((entry = aspell_dict_info_enumeration_next (dels)) != 0) {
- if (g_list_find_custom (codes, entry->code, (GCompareFunc) strcmp)) {
- continue;
- }
+ GList **list = user_data;
+ char *lang = g_strdup(lang_tag);
- codes = g_list_append (codes, g_strdup (entry->code));
+ if (strchr (lang, '_')) {
+ /* cut country part out of language */
+ strchr (lang, '_')[0] = '\0';
}
- delete_aspell_dict_info_enumeration (dels);
- delete_aspell_config (config);
+ if (g_list_find_custom (*list, lang, (GCompareFunc) strcmp)) {
+ /* this language is already part of the list */
+ g_free (lang);
+ return;
+ }
+
+ *list = g_list_append (*list, g_strdup(lang));
+}
+
- return codes;
+GList *
+empathy_spell_get_language_codes (void)
+{
+ EnchantBroker *broker;
+ GList *list_langs = NULL;
+
+ broker = enchant_broker_init ();
+ enchant_broker_list_dicts (broker, enumerate_dicts, &list_langs);
+ enchant_broker_free (broker);
+
+ return list_langs;
}
void
@@ -302,13 +299,12 @@ empathy_spell_free_language_codes (GList *codes)
gboolean
empathy_spell_check (const gchar *word)
{
- GList *l;
- gint n_langs;
- gboolean correct = FALSE;
- gint len;
+ int enchant_result = 1;
const gchar *p;
- gunichar c;
gboolean digit;
+ gunichar c;
+ gint len;
+ GList *l;
g_return_val_if_fail (word != NULL, FALSE);
@@ -332,30 +328,27 @@ empathy_spell_check (const gchar *word)
}
len = strlen (word);
- n_langs = g_list_length (languages);
for (l = languages; l; l = l->next) {
- SpellLanguage *lang;
+ SpellLanguage *lang;
lang = l->data;
- correct = aspell_speller_check (lang->spell_checker, word, len);
- if (n_langs > 1 && correct) {
+ enchant_result = enchant_dict_check (lang->speller, word, len);
+
+ if (enchant_result == 0) {
break;
}
}
- return correct;
+ return (enchant_result == 0);
}
GList *
empathy_spell_get_suggestions (const gchar *word)
{
- GList *l1;
- GList *l2 = NULL;
- const AspellWordList *suggestions;
- AspellStringEnumeration *elements;
- const char *next;
gint len;
+ GList *l1;
+ GList *suggestion_list = NULL;
g_return_val_if_fail (word != NULL, NULL);
@@ -365,22 +358,23 @@ empathy_spell_get_suggestions (const gchar *word)
for (l1 = languages; l1; l1 = l1->next) {
SpellLanguage *lang;
+ char **suggestions;
+ size_t i, number_of_suggestions;
lang = l1->data;
- suggestions = aspell_speller_suggest (lang->spell_checker,
- word, len);
-
- elements = aspell_word_list_elements (suggestions);
-
- while ((next = aspell_string_enumeration_next (elements))) {
- l2 = g_list_append (l2, g_strdup (next));
+ suggestions = enchant_dict_suggest (lang->speller, word, len,
+ &number_of_suggestions);
+
+ for (i = 0; i < number_of_suggestions; i++) {
+ suggestion_list = g_list_append (suggestion_list,
+ g_strdup(suggestions[i]));
}
- delete_aspell_string_enumeration (elements);
+ enchant_dict_free_string_list (lang->speller, suggestions);
}
- return l2;
+ return suggestion_list;
}
gboolean
@@ -394,7 +388,7 @@ empathy_spell_supported (void)
return TRUE;
}
-#else /* not HAVE_ASPELL */
+#else /* not HAVE_ENCHANT */
gboolean
empathy_spell_supported (void)
@@ -439,7 +433,7 @@ empathy_spell_free_language_codes (GList *codes)
{
}
-#endif /* HAVE_ASPELL */
+#endif /* HAVE_ENCHANT */
void