11#include "hspelldict.h"
13#include "hspell_debug.h"
19HSpellDict::HSpellDict(
const QString &lang)
22 int int_error = hspell_init(&m_speller, HSPELL_OPT_DEFAULT);
23 if (int_error == -1) {
24 qCWarning(SONNET_LOG_HSPELL) <<
"HSpellDict::HSpellDict: Init failed";
33 QSettings settings(QStringLiteral(
"KDE"), QStringLiteral(
"SonnetHSpellPlugin"));
36 QVariantHash replacementMap = settings.value(QStringLiteral(
"Replacements"),
QVariant()).toHash();
37 for (
const QString &key : replacementMap.keys()) {
38 m_replacements[key] = replacementMap[key].toString();
42HSpellDict::~HSpellDict()
46 hspell_uninit(m_speller);
50bool HSpellDict::isCorrect(
const QString &word)
const
52 if (m_sessionWords.contains(word)) {
56 if (m_personalWords.contains(word)) {
66 QByteArray wordISO = m_encoder.encode(word);
69 int correct = hspell_check_word(m_speller, wordISO.
constData(),
74 if (hspell_is_canonic_gimatria(wordISO.
constData()) != 0) {
83 QStringList suggestions;
85 if (m_replacements.contains(word)) {
86 suggestions.
append(m_replacements[word]);
89 struct corlist correctionList;
91 corlist_init(&correctionList);
92 const QByteArray encodedWord = m_encoder.encode(word);
93 hspell_trycorrect(m_speller, encodedWord.
constData(), &correctionList);
94 for (suggestionCount = 0; suggestionCount < corlist_n(&correctionList); suggestionCount++) {
95 suggestions.
append(m_decoder.decode(corlist_str(&correctionList, suggestionCount)));
97 corlist_free(&correctionList);
101bool HSpellDict::storeReplacement(
const QString &bad,
const QString &good)
103 m_replacements[bad] = good;
104 storePersonalWords();
108bool HSpellDict::addToPersonal(
const QString &word)
110 m_personalWords.insert(word);
111 storePersonalWords();
115bool HSpellDict::addToSession(
const QString &word)
117 m_sessionWords.insert(word);
121void HSpellDict::storePersonalWords()
123 QSettings settings(QStringLiteral(
"KDE"), QStringLiteral(
"SonnetHSpellPlugin"));
124 const QStringList personalWordsList(m_personalWords.begin(), m_personalWords.end());
125 settings.setValue(QStringLiteral(
"PersonalWords"), QVariant(personalWordsList));
126 QVariantHash variantHash;
127 for (
const QString &key : m_replacements.keys()) {
128 variantHash[key] = QVariant(m_replacements[key]);
130 settings.setValue(QStringLiteral(
"Replacements"), variantHash);
const char * constData() const const
void append(QList< T > &&value)
T value(qsizetype i) const const