Skip to content

Commit

Permalink
Support for Enchant2
Browse files Browse the repository at this point in the history
  • Loading branch information
Ri0n committed Sep 8, 2017
1 parent 24f7d20 commit 98938fa
Showing 1 changed file with 17 additions and 3 deletions.
20 changes: 17 additions & 3 deletions tools/spellchecker/enchantchecker.cpp
Expand Up @@ -31,20 +31,30 @@
#include "enchant++.h"
#include "enchantchecker.h"

static enchant::Broker *brocker;

EnchantChecker::EnchantChecker()
: spellers_(EnchantDictList())
, allLanguages_(QStringList())
{
if (enchant::Broker *instance = enchant::Broker::instance())
#ifdef HAVE_ENCHANT2
brocker = new enchant::Broker();
#else
brocker = enchant::Broker::instance();
#endif
if (brocker)
{
instance->list_dicts(enchantDictDescribeFn, static_cast<void*>(this));
brocker->list_dicts(enchantDictDescribeFn, static_cast<void*>(this));
setActiveLanguages(getAllLanguages());
}
}

EnchantChecker::~EnchantChecker()
{
clearSpellers();
#ifdef HAVE_ENCHANT2
delete brocker;
#endif
}

bool EnchantChecker::isCorrect(const QString& word)
Expand Down Expand Up @@ -80,7 +90,11 @@ bool EnchantChecker::add(const QString& word)
if (!spellers_.isEmpty()) {
QString trimmed_word = word.trimmed();
if(!word.isEmpty()) {
#ifdef HAVE_ENCHANT2
spellers_.first()->add(word.toUtf8().constData());
#else
spellers_.first()->add_to_pwl(word.toUtf8().constData());
#endif
result = true;
}
}
Expand Down Expand Up @@ -111,7 +125,7 @@ void EnchantChecker::setActiveLanguages(const QList<QString>& langs)
continue;

try {
spellers_ << enchant::Broker::instance()->request_dict(lang.toStdString());
spellers_ << brocker->request_dict(lang.toStdString());
} catch (enchant::Exception &e) {
qWarning() << QString("Enchant error: %1").arg(e.what());
}
Expand Down

0 comments on commit 98938fa

Please sign in to comment.