Sonnet

ispellcheckerdict.cpp
1/*
2 SPDX-FileCopyrightText: 2019 Christoph Cullmann <cullmann@kde.org>
3
4 SPDX-License-Identifier: LGPL-2.0-or-later
5*/
6
7#include "ispellcheckerdict.h"
8#include "ispellcheckerdebug.h"
9
10using namespace Sonnet;
11
12ISpellCheckerDict::ISpellCheckerDict(ISpellChecker *spellChecker, const QString &language)
13 : SpellerPlugin(language)
14 , m_spellChecker(spellChecker)
15{
16 Q_ASSERT(m_spellChecker);
17}
18
19ISpellCheckerDict::~ISpellCheckerDict()
20{
21 // we don't own m_spellChecker!
22}
23
24bool ISpellCheckerDict::isCorrect(const QString &word) const
25{
26 // check if we are incorrect, we only need to check one enum entry for that, only empty enum means OK
27 bool ok = true;
28 IEnumSpellingError *enumSpellingError = nullptr;
29 if (SUCCEEDED(m_spellChecker->Check(word.toStdWString().c_str(), &enumSpellingError))) {
30 ISpellingError *spellingError = nullptr;
31 if (S_OK == enumSpellingError->Next(&spellingError)) {
32 ok = false;
33 spellingError->Release();
34 }
35 enumSpellingError->Release();
36 }
37 return ok;
38}
39
40QStringList ISpellCheckerDict::suggest(const QString &word) const
41{
42 // query suggestions
43 QStringList replacements;
44 IEnumString *words = nullptr;
45 if (SUCCEEDED(m_spellChecker->Suggest(word.toStdWString().c_str(), &words))) {
46 HRESULT hr = S_OK;
47 while (S_OK == hr) {
48 LPOLESTR string = nullptr;
49 hr = words->Next(1, &string, nullptr);
50 if (S_OK == hr) {
51 replacements.push_back(QString::fromWCharArray(string));
52 CoTaskMemFree(string);
53 }
54 }
55 words->Release();
56 }
57 return replacements;
58}
59
60bool ISpellCheckerDict::storeReplacement(const QString &bad, const QString &good)
61{
62 Q_UNUSED(bad);
63 Q_UNUSED(good);
64 qCDebug(SONNET_ISPELLCHECKER) << "ISpellCheckerDict::storeReplacement not implemented";
65 return false;
66}
67
68bool ISpellCheckerDict::addToPersonal(const QString &word)
69{
70 // add word "permanently" to the dictionary
71 return SUCCEEDED(m_spellChecker->Add(word.toStdWString().c_str()));
72}
73
74bool ISpellCheckerDict::addToSession(const QString &word)
75{
76 // ignore word for this session
77 return SUCCEEDED(m_spellChecker->Ignore(word.toStdWString().c_str()));
78}
The sonnet namespace.
void push_back(parameter_type value)
QString fromWCharArray(const wchar_t *string, qsizetype size)
std::wstring toStdWString() const const
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Mon Nov 4 2024 16:29:33 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.