diff --git a/src/plugins/hunspell/CMakeLists.txt b/src/plugins/hunspell/CMakeLists.txt --- a/src/plugins/hunspell/CMakeLists.txt +++ b/src/plugins/hunspell/CMakeLists.txt @@ -4,6 +4,15 @@ ) ecm_qt_declare_logging_category(sonnet_hunspell_PART_SRCS HEADER hunspelldebug.h IDENTIFIER SONNET_HUNSPELL CATEGORY_NAME sonnet.plugins.hunspell) +# see: https://phabricator.kde.org/R246:0a96acf251baa5c9dd042d093ab2bf8fcee10502 +set(USE_OLD_HUNSPELL_API TRUE) +if (PKG_HUNSPELL_VERSION GREATER "1.5.0") + set(USE_OLD_HUNSPELL_API FALSE) # new API introduced in v1.5.1 (cf. https://github.com/hunspell/hunspell/commit/8006703dafeebce19f2144c5cf180812eb99693a) +endif() +message(STATUS "Using old hunspell API: ${USE_OLD_HUNSPELL_API}") + +configure_file(config-hunspell.h.cmake ${CMAKE_CURRENT_BINARY_DIR}/config-hunspell.h) + add_library(sonnet_hunspell MODULE ${sonnet_hunspell_PART_SRCS}) target_include_directories(sonnet_hunspell SYSTEM PUBLIC ${HUNSPELL_INCLUDE_DIRS}) target_link_libraries(sonnet_hunspell PRIVATE KF5::SonnetCore ${HUNSPELL_LIBRARIES}) diff --git a/src/plugins/hunspell/config-hunspell.h.cmake b/src/plugins/hunspell/config-hunspell.h.cmake new file mode 100644 --- /dev/null +++ b/src/plugins/hunspell/config-hunspell.h.cmake @@ -0,0 +1 @@ +#cmakedefine01 USE_OLD_HUNSPELL_API diff --git a/src/plugins/hunspell/hunspelldict.cpp b/src/plugins/hunspell/hunspelldict.cpp --- a/src/plugins/hunspell/hunspelldict.cpp +++ b/src/plugins/hunspell/hunspelldict.cpp @@ -18,7 +18,10 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA * 02110-1301 USA */ + #include "hunspelldict.h" + +#include "config-hunspell.h" #include "hunspelldebug.h" #include @@ -102,20 +105,38 @@ if (!m_speller) { return false; } + +#if USE_OLD_HUNSPELL_API + int result = m_speller->spell(toDictEncoding(word).constData()); + qCDebug(SONNET_HUNSPELL) << " result :" << result; + return result != 0; +#else bool result = m_speller->spell(toDictEncoding(word).toStdString()); qCDebug(SONNET_HUNSPELL) << " result :" << result; return result; +#endif } QStringList HunspellDict::suggest(const QString &word) const { if (!m_speller) { return QStringList(); } + QStringList lst; +#if USE_OLD_HUNSPELL_API + char **selection; + int nbWord = m_speller->suggest(&selection, toDictEncoding(word).constData()); + for (int i = 0; i < nbWord; ++i) { + lst << m_codec->toUnicode(selection[i]); + } + m_speller->free_list(&selection, nbWord); +#else const auto suggestions = m_speller->suggest(toDictEncoding(word).toStdString()); for_each (suggestions.begin(), suggestions.end(), [this, &lst](const std::string &suggestion) { lst << m_codec->toUnicode(suggestion.c_str()); }); +#endif + return lst; }