[gspell/wip/expose-enchant: 1/3] Checker: expose EnchantDict



commit 093e04483c4a3713b280d411b053c8aa826456ca
Author: Sébastien Wilmet <swilmet gnome org>
Date:   Sat Jul 15 10:52:51 2017 +0200

    Checker: expose EnchantDict
    
    I initially didn't want to expose the use of Enchant, because I thought
    that gspell could use directly hunspell instead. But I think this won't
    happen, Enchant provides a C API while hunspell is in C++, so it's
    simpler to use Enchant in gspell.
    
    So the use of Enchant is now part of the API, if it needs to change in
    the future, we can just bump the API/major version of gspell. This will
    anyway happen regularly to port gspell to new major versions of GTK+.
    
    This commit will normally permit to implement the following feature in
    gnome-builder (even if I would prefer that it's implemented in gspell,
    to make the feature available to all applications):
    https://bugzilla.gnome.org/show_bug.cgi?id=765616

 configure.ac                           |    4 +-
 docs/reference/gspell-1.0-sections.txt |    1 +
 gspell/gspell-checker.c                |   36 ++++++++++++++++++++++++++-----
 gspell/gspell-checker.h                |    4 +++
 4 files changed, 37 insertions(+), 8 deletions(-)
---
diff --git a/configure.ac b/configure.ac
index 9e51fd9..b8185d0 100644
--- a/configure.ac
+++ b/configure.ac
@@ -90,8 +90,8 @@ AX_COMPILER_FLAGS([WARN_CFLAGS], [WARN_LDFLAGS], [yes])
 # Dynamic linking dependencies
 AX_REQUIRE_DEFINED([AX_PKG_CHECK_MODULES])
 AX_PKG_CHECK_MODULES([DEP],
-                    [glib-2.0 >= $glib_req  gtk+-3.0 >= $gtk_req],
-                    [enchant >= $enchant_req])
+                    [glib-2.0 >= $glib_req  gtk+-3.0 >= $gtk_req  enchant >= $enchant_req],
+                    [])
 
 # iso-codes
 AX_REQUIRE_DEFINED([PKG_CHECK_EXISTS])
diff --git a/docs/reference/gspell-1.0-sections.txt b/docs/reference/gspell-1.0-sections.txt
index b18b53d..05d1cd8 100644
--- a/docs/reference/gspell-1.0-sections.txt
+++ b/docs/reference/gspell-1.0-sections.txt
@@ -14,6 +14,7 @@ gspell_checker_add_word_to_personal
 gspell_checker_add_word_to_session
 gspell_checker_clear_session
 gspell_checker_set_correction
+gspell_checker_get_enchant_dict
 <SUBSECTION Standard>
 GspellCheckerClass
 GSPELL_TYPE_CHECKER
diff --git a/gspell/gspell-checker.c b/gspell/gspell-checker.c
index aa2cb6f..e7d100a 100644
--- a/gspell/gspell-checker.c
+++ b/gspell/gspell-checker.c
@@ -24,7 +24,6 @@
 
 #include "gspell-checker.h"
 #include "gspell-checker-private.h"
-#include <enchant.h>
 #include <glib/gi18n-lib.h>
 #include <string.h>
 #include "gspell-utils.h"
@@ -44,11 +43,10 @@
  * If the #GspellChecker:language property is %NULL, it means that no
  * dictonaries are available, in which case the #GspellChecker is in a
  * “disabled” (but allowed) state.
- */
-
-/* Enchant is currently used under the hood, but it is an implementation detail,
- * it is *NOT* part of the gspell API. A future gspell version can be based on
- * another library (e.g. using directly hunspell).
+ *
+ * gspell uses the [Enchant](https://abiword.github.io/enchant/) library. The
+ * use of Enchant is part of the gspell API, #GspellChecker exposes the
+ * EnchantDict with the gspell_checker_get_enchant_dict() function.
  */
 
 typedef struct _GspellCheckerPrivate GspellCheckerPrivate;
@@ -640,4 +638,30 @@ gspell_checker_set_correction (GspellChecker *checker,
                                        replacement, replacement_length);
 }
 
+/**
+ * gspell_checker_get_enchant_dict:
+ * @checker: a #GspellChecker.
+ *
+ * Gets the EnchantDict currently used by @checker. It permits to extend
+ * #GspellChecker with more features. Note that by doing so, the other classes
+ * in gspell may no longer work well.
+ *
+ * #GspellChecker re-creates a new EnchantDict when the #GspellChecker:language
+ * is changed and when the session is cleared.
+ *
+ * Returns: (transfer none) (nullable): the EnchantDict currently used by
+ * @checker.
+ * Since: 1.6
+ */
+EnchantDict *
+gspell_checker_get_enchant_dict (GspellChecker *checker)
+{
+       GspellCheckerPrivate *priv;
+
+       g_return_val_if_fail (GSPELL_IS_CHECKER (checker), NULL);
+
+       priv = gspell_checker_get_instance_private (checker);
+       return priv->dict;
+}
+
 /* ex:set ts=8 noet: */
diff --git a/gspell/gspell-checker.h b/gspell/gspell-checker.h
index fc94a56..bab3617 100644
--- a/gspell/gspell-checker.h
+++ b/gspell/gspell-checker.h
@@ -26,6 +26,7 @@
 #endif
 
 #include <glib-object.h>
+#include <enchant.h>
 #include <gspell/gspell-language.h>
 #include <gspell/gspell-version.h>
 
@@ -123,6 +124,9 @@ void                gspell_checker_set_correction           (GspellChecker *checker,
                                                         const gchar   *replacement,
                                                         gssize         replacement_length);
 
+GSPELL_AVAILABLE_IN_1_6
+EnchantDict *  gspell_checker_get_enchant_dict         (GspellChecker *checker);
+
 G_END_DECLS
 
 #endif  /* GSPELL_CHECKER_H */


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]