From 75d0382e97fc9ce6abf16b64bc534ad08c1bec95 Mon Sep 17 00:00:00 2001 From: "B.Melnik" Date: Thu, 21 Oct 2021 17:44:22 +0300 Subject: [PATCH] fix(Spellchecking): Add check for hunspell existence --- ui/StatusQ/sandbox/sandbox.pro | 9 ++++++--- ui/StatusQ/sandbox/spellchecker.cpp | 24 ++++++++++++------------ ui/StatusQ/sandbox/spellchecker.h | 4 ++-- 3 files changed, 20 insertions(+), 17 deletions(-) diff --git a/ui/StatusQ/sandbox/sandbox.pro b/ui/StatusQ/sandbox/sandbox.pro index b858d6fca5..bd923196a8 100644 --- a/ui/StatusQ/sandbox/sandbox.pro +++ b/ui/StatusQ/sandbox/sandbox.pro @@ -32,9 +32,12 @@ macx { hunspellTarget.commands = brew install hunspell QMAKE_EXTRA_TARGETS += hunspellTarget - - LIBS += -L"/usr/local/lib" -lhunspell-1.7 - INCLUDEPATH += /usr/local/include/hunspell + exists (/usr/local/lib/libhunspell-1.7.a) { + LIBS += -L"/usr/local/lib" -lhunspell-1.7 + INCLUDEPATH += /usr/local/include/hunspell + DEFINES += USE_HUNSPELL + message("hunspell exists in /usr/local/lib") + } } ios { diff --git a/ui/StatusQ/sandbox/spellchecker.cpp b/ui/StatusQ/sandbox/spellchecker.cpp index d1625eeac0..5b338ae9de 100644 --- a/ui/StatusQ/sandbox/spellchecker.cpp +++ b/ui/StatusQ/sandbox/spellchecker.cpp @@ -1,6 +1,6 @@ #include "spellchecker.h" -#ifdef Q_OS_MACOS +#ifdef USE_HUNSPELL #include "hunspell.hxx" #endif #include @@ -14,24 +14,24 @@ SpellChecker::SpellChecker(QObject *parent) : QObject(parent) -#ifdef Q_OS_MACOS + , m_userDict("userDict_") +#ifdef USE_HUNSPELL , m_hunspell(nullptr) #endif - , m_userDict("userDict_") { } SpellChecker::~SpellChecker() { -#ifdef Q_OS_MACOS +#ifdef USE_HUNSPELL delete m_hunspell; #endif } bool SpellChecker::spell(const QString &word) { -#ifdef Q_OS_MACOS +#ifdef USE_HUNSPELL return m_hunspell->spell(m_codec->fromUnicode(word).toStdString()); #else return true; @@ -40,15 +40,15 @@ bool SpellChecker::spell(const QString &word) bool SpellChecker::isInit() const { -#ifdef Q_OS_MACOS +#ifdef USE_HUNSPELL return !m_hunspell; -#endif - +#endif + return false; } void SpellChecker::initHunspell() { -#ifdef Q_OS_MACOS +#ifdef USE_HUNSPELL if (m_hunspell) { delete m_hunspell; } @@ -109,7 +109,7 @@ QVariantList SpellChecker::suggest(const QString &word) { int numSuggestions = 0; QVariantList suggestions; -#ifdef Q_OS_MACOS +#ifdef USE_HUNSPELL std::vector wordlist; wordlist = m_hunspell->suggest(m_codec->fromUnicode(word).toStdString()); @@ -128,14 +128,14 @@ QVariantList SpellChecker::suggest(const QString &word) void SpellChecker::ignoreWord(const QString &word) { -#ifdef Q_OS_MACOS +#ifdef USE_HUNSPELL m_hunspell->add(m_codec->fromUnicode(word).constData()); #endif } void SpellChecker::addToUserWordlist(const QString &word) { -#ifdef Q_OS_MACOS +#ifdef USE_HUNSPELL QString userDict = m_userDict + m_lang + ".txt"; if (!userDict.isEmpty()) { QFile userDictonaryFile(userDict); diff --git a/ui/StatusQ/sandbox/spellchecker.h b/ui/StatusQ/sandbox/spellchecker.h index ba123ee0d9..81479a6f4c 100644 --- a/ui/StatusQ/sandbox/spellchecker.h +++ b/ui/StatusQ/sandbox/spellchecker.h @@ -6,7 +6,7 @@ #include #include -#ifdef Q_OS_MACOS +#ifdef USE_HUNSPELL class Hunspell; #endif class QTextCodec; @@ -45,7 +45,7 @@ private: QString m_userDict; QQuickTextDocument *m_document; -#ifdef Q_OS_MACOS +#ifdef USE_HUNSPELL Hunspell *m_hunspell; #endif QTextCodec *m_codec;