fix(hunspell): Remove hunspell cos we not use it

Fixes: https://github.com/status-im/status-desktop/issues/8424
This commit is contained in:
Boris Melnik 2022-11-24 22:08:01 +03:00 committed by Michał
parent 2307356a54
commit 555192427e
4 changed files with 1 additions and 246 deletions

View File

@ -21,11 +21,7 @@ macro(add_target name type)
set_target_properties(${name} PROPERTIES CXX_STANDARD 11 AUTOMOC ON)
if(APPLE)
target_include_directories(${name} PUBLIC include include/Qt ${CMAKE_SOURCE_DIR}/../../bottles/hunspell/include)
else()
target_include_directories(${name} PUBLIC include include/Qt)
endif()
target_include_directories(${name} PUBLIC include include/Qt)
target_link_libraries(${name} PRIVATE Qt5::Core Qt5::Gui Qt5::Widgets Qt5::Qml Qt5::Quick Qt5::Network Qt5::Multimedia SortFilterProxyModel)

View File

@ -1,54 +0,0 @@
#ifndef DOSSPELLCHECKER_H
#define DOSSPELLCHECKER_H
#include <QObject>
#include <QVariant>
#include <QQuickTextDocument>
#include <QSyntaxHighlighter>
#ifdef Q_OS_MACOS
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 Q_OS_MACOS
Hunspell *m_hunspell;
#endif
QTextCodec *m_codec;
};
#endif // DOSSPELLCHECKER_H

View File

@ -75,7 +75,6 @@
#include "DOtherSide/Status/SoundManager.h"
#include "DOtherSide/Status/QClipboardProxy.h"
#include "DOtherSide/Status/RXValidator.h"
#include "DOtherSide/DosSpellchecker.h"
#include <qqmlsortfilterproxymodeltypes.h>
@ -86,7 +85,6 @@ void register_meta_types()
qRegisterMetaType<QVector<int>>();
qmlRegisterType<StatusWindow>("DotherSide", 0 , 1, "StatusWindow");
qmlRegisterType<StatusSyntaxHighlighterHelper>("DotherSide", 0 , 1, "StatusSyntaxHighlighter");
qmlRegisterType<SpellChecker>("DotherSide", 0, 1, "SpellChecker");
qmlRegisterSingletonType<QClipboardProxy>("DotherSide", 0 , 1, "QClipboardProxy", &QClipboardProxy::qmlInstance);
qmlRegisterType<RXValidator>("DotherSide", 0, 1, "RXValidator");
qqsfpm::registerTypes();

View File

@ -1,185 +0,0 @@
#include "../include/DOtherSide/DosSpellchecker.h"
#ifdef Q_OS_MACOS
#include "hunspell/hunspell.hxx"
#endif
#include <QTextCodec>
#include <QFile>
#include <QDebug>
#include <QLocale>
#include <QRegularExpression>
#include <QGuiApplication>
#include <QDir>
#include <QInputMethod>
SpellChecker::SpellChecker(QObject *parent)
: QObject(parent)
#ifdef Q_OS_MACOS
, m_hunspell(nullptr)
#endif
, m_userDict("userDict_")
{
}
SpellChecker::~SpellChecker()
{
#ifdef Q_OS_MACOS
delete m_hunspell;
#endif
}
bool SpellChecker::spell(const QString &word)
{
#ifdef Q_OS_MACOS
return m_hunspell->spell(m_codec->fromUnicode(word).toStdString());
#else
return true;
#endif
}
bool SpellChecker::isInit() const
{
#ifdef Q_OS_MACOS
return !m_hunspell;
#else
return true;
#endif
}
void SpellChecker::initHunspell()
{
#ifdef Q_OS_MACOS
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 Q_OS_MACOS
std::vector<std::string> wordlist;
wordlist = m_hunspell->suggest(m_codec->fromUnicode(word).toStdString());
numSuggestions = static_cast<int>(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 Q_OS_MACOS
m_hunspell->add(m_codec->fromUnicode(word).constData());
#endif
}
void SpellChecker::addToUserWordlist(const QString &word)
{
#ifdef Q_OS_MACOS
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();
}
}