1
#include "koreanplugin.h"
2
#include "koreanlanguagefeatures.h"
3
#include "spellpredictworker.h"
7
KoreanPlugin::KoreanPlugin(QObject *parent) :
8
AbstractLanguagePlugin(parent)
9
, m_koreanLanguageFeatures(new KoreanLanguageFeatures)
10
, m_spellCheckEnabled(false)
11
, m_processingSpelling(false)
13
m_spellPredictThread = new QThread();
14
m_spellPredictWorker = new SpellPredictWorker();
15
m_spellPredictWorker->moveToThread(m_spellPredictThread);
17
connect(m_spellPredictWorker, SIGNAL(newSpellingSuggestions(QString, QStringList)), this, SLOT(spellCheckFinishedProcessing(QString, QStringList)));
18
connect(m_spellPredictWorker, SIGNAL(newPredictionSuggestions(QString, QStringList)), this, SIGNAL(newPredictionSuggestions(QString, QStringList)));
19
connect(this, SIGNAL(newSpellCheckWord(QString)), m_spellPredictWorker, SLOT(newSpellCheckWord(QString)));
20
connect(this, SIGNAL(setSpellPredictLanguage(QString, QString)), m_spellPredictWorker, SLOT(setLanguage(QString, QString)));
21
connect(this, SIGNAL(setSpellCheckLimit(int)), m_spellPredictWorker, SLOT(setSpellCheckLimit(int)));
22
connect(this, SIGNAL(parsePredictionText(QString, QString)), m_spellPredictWorker, SLOT(parsePredictionText(QString, QString)));
23
connect(this, SIGNAL(addToUserWordList(QString)), m_spellPredictWorker, SLOT(addToUserWordList(QString)));
24
connect(this, SIGNAL(addOverride(QString, QString)), m_spellPredictWorker, SLOT(addOverride(QString, QString)));
25
m_spellPredictThread->start();
29
KoreanPlugin::~KoreanPlugin()
31
m_spellPredictWorker->deleteLater();
32
m_spellPredictThread->quit();
33
m_spellPredictThread->wait();
36
AbstractLanguageFeatures* KoreanPlugin::languageFeature()
38
return m_koreanLanguageFeatures;
41
void KoreanPlugin::predict(const QString& surroundingLeft, const QString& preedit)
43
Q_EMIT parsePredictionText(surroundingLeft, preedit);
46
void KoreanPlugin::wordCandidateSelected(QString word)
52
void KoreanPlugin::spellCheckerSuggest(const QString& word, int limit)
54
m_nextSpellWord = word;
55
// Don't accept new words whilst we're processing, so we only process the
56
// most recent input once the current processing has completed
57
if (!m_processingSpelling) {
58
m_processingSpelling = true;
59
Q_EMIT setSpellCheckLimit(limit);
60
Q_EMIT newSpellCheckWord(word);
64
void KoreanPlugin::addToSpellCheckerUserWordList(const QString& word)
66
Q_EMIT addToUserWordList(word);
69
bool KoreanPlugin::setLanguage(const QString& languageId, const QString& pluginPath)
71
Q_EMIT setSpellPredictLanguage(languageId, pluginPath);
72
loadOverrides(pluginPath);
76
void KoreanPlugin::addSpellingOverride(const QString& orig, const QString& overriden)
78
Q_EMIT addOverride(orig, overriden);
81
void KoreanPlugin::loadOverrides(const QString& pluginPath) {
82
QFile overrideFile(pluginPath + QDir::separator() + "overrides.csv");
83
if (overrideFile.open(QIODevice::ReadOnly | QIODevice::Text)) {
84
QTextStream overrideStream(&overrideFile);
85
while (!overrideStream.atEnd()) {
86
QString line = overrideStream.readLine();
87
QStringList components = line.split(",");
88
if (components.length() == 2) {
89
addSpellingOverride(components.first(), components.last());
95
void KoreanPlugin::spellCheckFinishedProcessing(QString word, QStringList suggestions) {
96
Q_EMIT newSpellingSuggestions(word, suggestions);
97
if (word != m_nextSpellWord) {
98
Q_EMIT newSpellCheckWord(m_nextSpellWord);
100
m_processingSpelling = false;