[gnome-text-editor] spellcheck: make spell backends optional



commit ec33f18c3e21a0d17f8ea347360a2ca6dc5c98b5
Author: Christian Hergert <chergert redhat com>
Date:   Wed Feb 2 16:55:53 2022 -0800

    spellcheck: make spell backends optional
    
    This allows us to disable enchant and use a dummy spellcheck backend
    instead which can be useful when we need to compile on systems without
    enchant (until we get proper backends).
    
    Primarily though, to ease the process of doing CI on systems where getting
    it might be annoying or difficult.

 meson.build                               |  1 -
 meson_options.txt                         |  1 +
 src/editor-application-actions.c          |  9 +++-
 src/editor-empty-spell-provider-private.h | 33 ++++++++++++++
 src/editor-empty-spell-provider.c         | 71 +++++++++++++++++++++++++++++++
 src/editor-spell-provider.c               | 11 ++++-
 src/enchant/meson.build                   |  8 ++++
 src/meson.build                           |  5 ++-
 8 files changed, 135 insertions(+), 4 deletions(-)
---
diff --git a/meson.build b/meson.build
index 51cb049..bbb3c12 100644
--- a/meson.build
+++ b/meson.build
@@ -30,7 +30,6 @@ libglib_dep = dependency('gio-2.0', version: glib_req)
 libgtk_dep = dependency('gtk4', version: gtk_req)
 libgtksourceview_dep = dependency('gtksourceview-5', version: gtksourceview_req)
 libadwaita_dep = dependency('libadwaita-1')
-libenchant_dep = dependency('enchant-2', version: enchant_req)
 libicu_dep = dependency('icu-uc')
 
 # Specify minimum library versions
diff --git a/meson_options.txt b/meson_options.txt
index 5991092..efcfecc 100644
--- a/meson_options.txt
+++ b/meson_options.txt
@@ -1 +1,2 @@
 option('development', type: 'boolean', value: false, description: 'If this is a development build')
+option('enchant', type: 'feature', value: 'enabled', description: 'Use enchant for spellchecking')
diff --git a/src/editor-application-actions.c b/src/editor-application-actions.c
index 1b84247..2478829 100644
--- a/src/editor-application-actions.c
+++ b/src/editor-application-actions.c
@@ -23,7 +23,10 @@
 #include "build-ident.h"
 #include "config.h"
 
-#include <enchant.h>
+#ifdef HAVE_ENCHANT
+# include <enchant.h>
+#endif
+
 #include <glib/gi18n.h>
 
 #include "editor-application-private.h"
@@ -115,7 +118,11 @@ get_system_information (void)
                           ADW_MICRO_VERSION);
   g_string_append_printf (str,
                           "Enchant2: %s\n",
+#ifdef HAVE_ENCHANT
                           enchant_get_version ());
+#else
+                          "Unavailable");
+#endif
 
   g_string_append (str, "\n");
   g_string_append_printf (str, "gtk-theme-name: %s\n", theme_name);
diff --git a/src/editor-empty-spell-provider-private.h b/src/editor-empty-spell-provider-private.h
new file mode 100644
index 0000000..3526c4b
--- /dev/null
+++ b/src/editor-empty-spell-provider-private.h
@@ -0,0 +1,33 @@
+/* editor-empty-spell-provider-private.h
+ *
+ * Copyright 2022 Christian Hergert <chergert redhat com>
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * 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 General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ *
+ * SPDX-License-Identifier: GPL-3.0-or-later
+ */
+
+#pragma once
+
+#include "editor-spell-provider.h"
+
+G_BEGIN_DECLS
+
+#define EDITOR_TYPE_EMPTY_SPELL_PROVIDER (editor_empty_spell_provider_get_type())
+
+G_DECLARE_FINAL_TYPE (EditorEmptySpellProvider, editor_empty_spell_provider, EDITOR, EMPTY_SPELL_PROVIDER, 
EditorSpellProvider)
+
+EditorSpellProvider *editor_empty_spell_provider_new (void);
+
+G_END_DECLS
diff --git a/src/editor-empty-spell-provider.c b/src/editor-empty-spell-provider.c
new file mode 100644
index 0000000..897941e
--- /dev/null
+++ b/src/editor-empty-spell-provider.c
@@ -0,0 +1,71 @@
+/* editor-empty-spell-provider.c
+ *
+ * Copyright 2022 Christian Hergert <chergert redhat com>
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * 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 General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ *
+ * SPDX-License-Identifier: GPL-3.0-or-later
+ */
+
+#include "config.h"
+
+#include "editor-empty-spell-provider-private.h"
+
+struct _EditorEmptySpellProvider
+{
+  EditorSpellProvider parent_instance;
+};
+
+G_DEFINE_FINAL_TYPE (EditorEmptySpellProvider, editor_empty_spell_provider, EDITOR_TYPE_SPELL_PROVIDER)
+
+EditorSpellProvider *
+editor_empty_spell_provider_new (void)
+{
+  return g_object_new (EDITOR_TYPE_EMPTY_SPELL_PROVIDER, NULL);
+}
+
+static GPtrArray *
+empty_list_languages (EditorSpellProvider *provider)
+{
+  return g_ptr_array_new_with_free_func (g_object_unref);
+}
+
+static EditorSpellLanguage *
+empty_get_language (EditorSpellProvider *provider,
+                    const char          *language)
+{
+  return NULL;
+}
+
+static gboolean
+empty_supports_language (EditorSpellProvider *provider,
+                         const char          *language)
+{
+  return FALSE;
+}
+
+static void
+editor_empty_spell_provider_class_init (EditorEmptySpellProviderClass *klass)
+{
+  EditorSpellProviderClass *provider_class = EDITOR_SPELL_PROVIDER_CLASS (klass);
+
+  provider_class->list_languages = empty_list_languages;
+  provider_class->get_language = empty_get_language;
+  provider_class->supports_language = empty_supports_language;
+}
+
+static void
+editor_empty_spell_provider_init (EditorEmptySpellProvider *self)
+{
+}
diff --git a/src/editor-spell-provider.c b/src/editor-spell-provider.c
index 5e282c8..d80e261 100644
--- a/src/editor-spell-provider.c
+++ b/src/editor-spell-provider.c
@@ -20,9 +20,12 @@
 
 #include "config.h"
 
+#include "editor-empty-spell-provider-private.h"
 #include "editor-spell-provider.h"
 
-#include "enchant/editor-enchant-spell-provider.h"
+#ifdef HAVE_ENCHANT
+# include "enchant/editor-enchant-spell-provider.h"
+#endif
 
 typedef struct
 {
@@ -138,7 +141,13 @@ editor_spell_provider_get_default (void)
 
   if (instance == NULL)
     {
+#ifdef HAVE_ENCHANT
       instance = editor_enchant_spell_provider_new ();
+#endif
+
+      if (instance == NULL)
+        instance = editor_empty_spell_provider_new ();
+
       g_set_weak_pointer (&instance, instance);
     }
 
diff --git a/src/enchant/meson.build b/src/enchant/meson.build
index b3d8c03..a1ba931 100644
--- a/src/enchant/meson.build
+++ b/src/enchant/meson.build
@@ -1,6 +1,14 @@
+if get_option('enchant').enabled()
+
+libenchant_dep = dependency('enchant-2', version: enchant_req)
+
 editor_deps += [libenchant_dep, libicu_dep]
 
 editor_sources += files([
   'editor-enchant-spell-language.c',
   'editor-enchant-spell-provider.c',
 ])
+
+editor_c_args += ['-DHAVE_ENCHANT']
+
+endif
diff --git a/src/meson.build b/src/meson.build
index a4d340b..2efd692 100644
--- a/src/meson.build
+++ b/src/meson.build
@@ -7,6 +7,7 @@ editor_sources = [
   'editor-buffer-monitor.c',
   'editor-document.c',
   'editor-info-bar.c',
+  'editor-empty-spell-provider.c',
   'editor-frame-source.c',
   'editor-file-manager.c',
   'editor-joined-menu.c',
@@ -85,6 +86,8 @@ build_ident_h = vcs_tag(
        output: 'build-ident.h',
 )
 
+editor_c_args = []
+
 subdir('enchant')
 subdir('defaults')
 subdir('modelines')
@@ -94,7 +97,7 @@ editor = executable('gnome-text-editor', editor_sources + editor_enums + [build_
   include_directories: [include_directories('..'),
                         include_directories('editorconfig'),
                         include_directories('editorconfig/libeditorconfig')],
-               c_args: [ '-DHANDY_USE_UNSTABLE_API' ],
+               c_args: editor_c_args,
          dependencies: editor_deps,
               install: true,
 )


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