From f47e64c7e24465809ef76ab5dae651f36d180c67 Mon Sep 17 00:00:00 2001 From: Boris Melnik Date: Fri, 9 Dec 2022 13:26:02 +0300 Subject: [PATCH] fix(hunspell): Remove hunspell usage in DOtherSide --- Makefile | 5 +- ui/StatusQ/sandbox/spellchecker.cpp | 181 ---------------------------- ui/StatusQ/sandbox/spellchecker.h | 54 --------- 3 files changed, 1 insertion(+), 239 deletions(-) delete mode 100644 ui/StatusQ/sandbox/spellchecker.cpp delete mode 100644 ui/StatusQ/sandbox/spellchecker.h diff --git a/Makefile b/Makefile index 654cf28733..7eff3b7318 100644 --- a/Makefile +++ b/Makefile @@ -113,7 +113,7 @@ endif ifeq ($(detected_OS),Darwin) BOTTLES_DIR := $(shell pwd)/bottles -BOTTLES := $(addprefix $(BOTTLES_DIR)/,hunspell openssl@1.1 pcre) +BOTTLES := $(addprefix $(BOTTLES_DIR)/,openssl@1.1 pcre) $(BOTTLES): | $(BOTTLES_DIR) echo -e "\e[92mFetching:\e[39m $(notdir $@) bottle" @@ -160,9 +160,6 @@ ifneq ($(detected_OS),Windows) NIM_PARAMS += --passL:"-headerpad_max_install_names" NIM_PARAMS += --passL:"-F$(QT5_LIBDIR)" - HUNSPELL := bottles/hunspell/lib/libhunspell-1.7.a - NIM_PARAMS += --passL:"$(HUNSPELL)" - export QT5_LIBDIR else NIM_PARAMS += --passL:"-L$(QT5_LIBDIR)" diff --git a/ui/StatusQ/sandbox/spellchecker.cpp b/ui/StatusQ/sandbox/spellchecker.cpp deleted file mode 100644 index 1dbfc004f8..0000000000 --- a/ui/StatusQ/sandbox/spellchecker.cpp +++ /dev/null @@ -1,181 +0,0 @@ -#include "spellchecker.h" - -#ifdef USE_HUNSPELL -#include "hunspell.hxx" -#endif -#include -#include -#include -#include - -#include -#include -#include - -SpellChecker::SpellChecker(QObject *parent) - : QObject(parent) - , m_userDict("userDict_") -#ifdef USE_HUNSPELL - , m_hunspell(nullptr) -#endif -{ - -} - -SpellChecker::~SpellChecker() -{ -#ifdef USE_HUNSPELL - delete m_hunspell; -#endif -} - -bool SpellChecker::spell(const QString &word) -{ -#ifdef USE_HUNSPELL - return m_hunspell->spell(m_codec->fromUnicode(word).toStdString()); -#else - return true; -#endif -} - -bool SpellChecker::isInit() const -{ -#ifdef USE_HUNSPELL - return !m_hunspell; -#endif - return false; -} - -void SpellChecker::initHunspell() -{ -#ifdef USE_HUNSPELL - if (m_hunspell) { - delete m_hunspell; - } - - QString dictFile = QGuiApplication::applicationDirPath() + "/dictionaries/" + m_lang + "/index.dic"; - QString affixFile = QGuiApplication::applicationDirPath() + "/dictionaries/" + m_lang + "/index.aff"; - QByteArray dictFilePathBA = dictFile.toLocal8Bit(); - QByteArray affixFilePathBA = affixFile.toLocal8Bit(); - m_hunspell = new Hunspell(affixFilePathBA.constData(), - dictFilePathBA.constData()); - - // detect encoding analyzing the SET option in the affix file - auto encoding = QStringLiteral("ISO8859-15"); - QFile _affixFile(affixFile); - if (_affixFile.open(QIODevice::ReadOnly)) { - QTextStream stream(&_affixFile); - QRegularExpression enc_detector( - QStringLiteral("^\\s*SET\\s+([A-Z0-9\\-]+)\\s*"), - QRegularExpression::CaseInsensitiveOption); - QString sLine; - QRegularExpressionMatch match; - while (!stream.atEnd()) { - sLine = stream.readLine(); - if (sLine.isEmpty()) { continue; } - match = enc_detector.match(sLine); - if (match.hasMatch()) { - encoding = match.captured(1); - qDebug() << "Encoding set to " + encoding; - break; - } - } - _affixFile.close(); - } - m_codec = QTextCodec::codecForName(encoding.toLatin1().constData()); - - QString userDict = m_userDict + m_lang + ".txt"; - - if (!userDict.isEmpty()) { - QFile userDictonaryFile(userDict); - if (userDictonaryFile.open(QIODevice::ReadOnly)) { - QTextStream stream(&userDictonaryFile); - for (QString word = stream.readLine(); - !word.isEmpty(); - word = stream.readLine()) - ignoreWord(word); - userDictonaryFile.close(); - } else { - qWarning() << "User dictionary in " << userDict - << "could not be opened"; - } - } else { - qDebug() << "User dictionary not set."; - } -#endif -} - -QVariantList SpellChecker::suggest(const QString &word) -{ - int numSuggestions = 0; - QVariantList suggestions; -#ifdef USE_HUNSPELL - std::vector wordlist; - wordlist = m_hunspell->suggest(m_codec->fromUnicode(word).toStdString()); - - numSuggestions = static_cast(wordlist.size()); - if (numSuggestions > 0) { - suggestions.reserve(numSuggestions); - for (int i = 0; i < numSuggestions; i++) { - suggestions << m_codec->toUnicode( - QByteArray::fromStdString(wordlist[i])); - } - } -#endif - - return suggestions; -} - -void SpellChecker::ignoreWord(const QString &word) -{ -#ifdef USE_HUNSPELL - m_hunspell->add(m_codec->fromUnicode(word).constData()); -#endif -} - -void SpellChecker::addToUserWordlist(const QString &word) -{ -#ifdef USE_HUNSPELL - QString userDict = m_userDict + m_lang + ".txt"; - if (!userDict.isEmpty()) { - QFile userDictonaryFile(userDict); - if (userDictonaryFile.open(QIODevice::Append)) { - QTextStream stream(&userDictonaryFile); - stream << word << "\n"; - userDictonaryFile.close(); - } else { - qWarning() << "User dictionary in " << userDict - << "could not be opened for appending a new word"; - } - } else { - qDebug() << "User dictionary not set."; - } -#endif -} - -const QString& SpellChecker::lang() const -{ - return m_lang; -} - -void SpellChecker::setLang(const QString& lang) -{ - if (m_lang != lang) { - m_lang = lang; - initHunspell(); - emit langChanged(); - } -} - -const QString& SpellChecker::userDict() const -{ - return m_userDict; -} - -void SpellChecker::setUserDict(const QString& userDict) -{ - if (m_userDict != userDict) { - m_userDict = userDict; - emit userDictChanged(); - } -} diff --git a/ui/StatusQ/sandbox/spellchecker.h b/ui/StatusQ/sandbox/spellchecker.h deleted file mode 100644 index 81479a6f4c..0000000000 --- a/ui/StatusQ/sandbox/spellchecker.h +++ /dev/null @@ -1,54 +0,0 @@ -#ifndef SPELLCHECKER_H -#define SPELLCHECKER_H - -#include -#include -#include -#include - -#ifdef USE_HUNSPELL -class Hunspell; -#endif -class QTextCodec; - -class SpellChecker : public QObject -{ - Q_OBJECT - Q_PROPERTY(QString lang READ lang WRITE setLang NOTIFY langChanged) - Q_PROPERTY(QString userDict READ userDict WRITE setUserDict NOTIFY userDictChanged) - -public: - explicit SpellChecker(QObject *parent = nullptr); - ~SpellChecker(); - - Q_INVOKABLE bool spell(const QString& word); - Q_INVOKABLE QVariantList suggest(const QString &word); - Q_INVOKABLE void ignoreWord(const QString &word); - Q_INVOKABLE void addToUserWordlist(const QString &word); - Q_INVOKABLE bool isInit() const; - - const QString& lang() const; - void setLang(const QString& lang); - - const QString& userDict() const; - void setUserDict(const QString& userDict); - -signals: - void langChanged(); - void userDictChanged(); - -private: - void initHunspell(); - -private: - QString m_lang; - QString m_userDict; - - QQuickTextDocument *m_document; -#ifdef USE_HUNSPELL - Hunspell *m_hunspell; -#endif - QTextCodec *m_codec; -}; - -#endif // SPELLCHECKER_H