fix(Spellchecking): Add check for hunspell existence
This commit is contained in:
parent
3c7b498e74
commit
75d0382e97
|
@ -32,9 +32,12 @@ macx {
|
||||||
hunspellTarget.commands = brew install hunspell
|
hunspellTarget.commands = brew install hunspell
|
||||||
QMAKE_EXTRA_TARGETS += hunspellTarget
|
QMAKE_EXTRA_TARGETS += hunspellTarget
|
||||||
|
|
||||||
|
exists (/usr/local/lib/libhunspell-1.7.a) {
|
||||||
LIBS += -L"/usr/local/lib" -lhunspell-1.7
|
LIBS += -L"/usr/local/lib" -lhunspell-1.7
|
||||||
INCLUDEPATH += /usr/local/include/hunspell
|
INCLUDEPATH += /usr/local/include/hunspell
|
||||||
|
DEFINES += USE_HUNSPELL
|
||||||
|
message("hunspell exists in /usr/local/lib")
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
ios {
|
ios {
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
#include "spellchecker.h"
|
#include "spellchecker.h"
|
||||||
|
|
||||||
#ifdef Q_OS_MACOS
|
#ifdef USE_HUNSPELL
|
||||||
#include "hunspell.hxx"
|
#include "hunspell.hxx"
|
||||||
#endif
|
#endif
|
||||||
#include <QTextCodec>
|
#include <QTextCodec>
|
||||||
|
@ -14,24 +14,24 @@
|
||||||
|
|
||||||
SpellChecker::SpellChecker(QObject *parent)
|
SpellChecker::SpellChecker(QObject *parent)
|
||||||
: QObject(parent)
|
: QObject(parent)
|
||||||
#ifdef Q_OS_MACOS
|
, m_userDict("userDict_")
|
||||||
|
#ifdef USE_HUNSPELL
|
||||||
, m_hunspell(nullptr)
|
, m_hunspell(nullptr)
|
||||||
#endif
|
#endif
|
||||||
, m_userDict("userDict_")
|
|
||||||
{
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
SpellChecker::~SpellChecker()
|
SpellChecker::~SpellChecker()
|
||||||
{
|
{
|
||||||
#ifdef Q_OS_MACOS
|
#ifdef USE_HUNSPELL
|
||||||
delete m_hunspell;
|
delete m_hunspell;
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
bool SpellChecker::spell(const QString &word)
|
bool SpellChecker::spell(const QString &word)
|
||||||
{
|
{
|
||||||
#ifdef Q_OS_MACOS
|
#ifdef USE_HUNSPELL
|
||||||
return m_hunspell->spell(m_codec->fromUnicode(word).toStdString());
|
return m_hunspell->spell(m_codec->fromUnicode(word).toStdString());
|
||||||
#else
|
#else
|
||||||
return true;
|
return true;
|
||||||
|
@ -40,15 +40,15 @@ bool SpellChecker::spell(const QString &word)
|
||||||
|
|
||||||
bool SpellChecker::isInit() const
|
bool SpellChecker::isInit() const
|
||||||
{
|
{
|
||||||
#ifdef Q_OS_MACOS
|
#ifdef USE_HUNSPELL
|
||||||
return !m_hunspell;
|
return !m_hunspell;
|
||||||
#endif
|
#endif
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
void SpellChecker::initHunspell()
|
void SpellChecker::initHunspell()
|
||||||
{
|
{
|
||||||
#ifdef Q_OS_MACOS
|
#ifdef USE_HUNSPELL
|
||||||
if (m_hunspell) {
|
if (m_hunspell) {
|
||||||
delete m_hunspell;
|
delete m_hunspell;
|
||||||
}
|
}
|
||||||
|
@ -109,7 +109,7 @@ QVariantList SpellChecker::suggest(const QString &word)
|
||||||
{
|
{
|
||||||
int numSuggestions = 0;
|
int numSuggestions = 0;
|
||||||
QVariantList suggestions;
|
QVariantList suggestions;
|
||||||
#ifdef Q_OS_MACOS
|
#ifdef USE_HUNSPELL
|
||||||
std::vector<std::string> wordlist;
|
std::vector<std::string> wordlist;
|
||||||
wordlist = m_hunspell->suggest(m_codec->fromUnicode(word).toStdString());
|
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)
|
void SpellChecker::ignoreWord(const QString &word)
|
||||||
{
|
{
|
||||||
#ifdef Q_OS_MACOS
|
#ifdef USE_HUNSPELL
|
||||||
m_hunspell->add(m_codec->fromUnicode(word).constData());
|
m_hunspell->add(m_codec->fromUnicode(word).constData());
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
void SpellChecker::addToUserWordlist(const QString &word)
|
void SpellChecker::addToUserWordlist(const QString &word)
|
||||||
{
|
{
|
||||||
#ifdef Q_OS_MACOS
|
#ifdef USE_HUNSPELL
|
||||||
QString userDict = m_userDict + m_lang + ".txt";
|
QString userDict = m_userDict + m_lang + ".txt";
|
||||||
if (!userDict.isEmpty()) {
|
if (!userDict.isEmpty()) {
|
||||||
QFile userDictonaryFile(userDict);
|
QFile userDictonaryFile(userDict);
|
||||||
|
|
|
@ -6,7 +6,7 @@
|
||||||
#include <QQuickTextDocument>
|
#include <QQuickTextDocument>
|
||||||
#include <QSyntaxHighlighter>
|
#include <QSyntaxHighlighter>
|
||||||
|
|
||||||
#ifdef Q_OS_MACOS
|
#ifdef USE_HUNSPELL
|
||||||
class Hunspell;
|
class Hunspell;
|
||||||
#endif
|
#endif
|
||||||
class QTextCodec;
|
class QTextCodec;
|
||||||
|
@ -45,7 +45,7 @@ private:
|
||||||
QString m_userDict;
|
QString m_userDict;
|
||||||
|
|
||||||
QQuickTextDocument *m_document;
|
QQuickTextDocument *m_document;
|
||||||
#ifdef Q_OS_MACOS
|
#ifdef USE_HUNSPELL
|
||||||
Hunspell *m_hunspell;
|
Hunspell *m_hunspell;
|
||||||
#endif
|
#endif
|
||||||
QTextCodec *m_codec;
|
QTextCodec *m_codec;
|
||||||
|
|
Loading…
Reference in New Issue