Sonnet

ispellcheckerdict.cpp
1 /*
2  SPDX-FileCopyrightText: 2019 Christoph Cullmann <[email protected]>
3 
4  SPDX-License-Identifier: LGPL-2.0-or-later
5 */
6 
7 #include "ispellcheckerdict.h"
8 #include "ispellcheckerdebug.h"
9 
10 using namespace Sonnet;
11 
12 ISpellCheckerDict::ISpellCheckerDict(ISpellChecker *spellChecker, const QString &language)
13  : SpellerPlugin(language)
14  , m_spellChecker(spellChecker)
15 {
16  Q_ASSERT(m_spellChecker);
17 }
18 
19 ISpellCheckerDict::~ISpellCheckerDict()
20 {
21  // we don't own m_spellChecker!
22 }
23 
24 bool 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 
40 QStringList 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 
60 bool 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 
68 bool 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 
74 bool ISpellCheckerDict::addToSession(const QString &word)
75 {
76  // ignore word for this session
77  return SUCCEEDED(m_spellChecker->Ignore(word.toStdWString().c_str()));
78 }
void push_back(const T &value)
QString fromWCharArray(const wchar_t *string, int size)
std::wstring toStdWString() const const
The sonnet namespace.
This file is part of the KDE documentation.
Documentation copyright © 1996-2022 The KDE developers.
Generated on Sun Sep 25 2022 04:14:52 by doxygen 1.8.17 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.