Sonnet

ispellcheckerclient.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 "ispellcheckerclient.h"
8#include "ispellcheckerdebug.h"
9#include "ispellcheckerdict.h"
10
11using namespace Sonnet;
12
13ISpellCheckerClient::ISpellCheckerClient(QObject *parent)
14 : Client(parent)
15{
16 qCDebug(SONNET_ISPELLCHECKER) << " ISpellCheckerClient::ISpellCheckerClient";
17
18 // init com if needed, use same variant as e.g. Qt in qtbase/src/corelib/io/qfilesystemengine_win.cpp
19 CoInitialize(nullptr);
20
21 // get factory & collect all known languages + instantiate the spell checkers for them
22 ISpellCheckerFactory *spellCheckerFactory = nullptr;
23 if (SUCCEEDED(CoCreateInstance(__uuidof(SpellCheckerFactory), nullptr, CLSCTX_INPROC_SERVER, IID_PPV_ARGS(&spellCheckerFactory))) && spellCheckerFactory) {
24 // if we have a factory, cache the language names
25 IEnumString *enumLanguages = nullptr;
26 if (SUCCEEDED(spellCheckerFactory->get_SupportedLanguages(&enumLanguages))) {
27 HRESULT hr = S_OK;
28 while (S_OK == hr) {
29 LPOLESTR string = nullptr;
30 hr = enumLanguages->Next(1, &string, nullptr);
31 if (S_OK == hr) {
32 ISpellChecker *spellChecker = nullptr;
33 if (SUCCEEDED(spellCheckerFactory->CreateSpellChecker(string, &spellChecker)) && spellChecker) {
34 m_languages.insert(QString::fromWCharArray(string), spellChecker);
35 }
36 CoTaskMemFree(string);
37 }
38 }
39 enumLanguages->Release();
40 }
41 spellCheckerFactory->Release();
42 }
43}
44
45ISpellCheckerClient::~ISpellCheckerClient()
46{
47 // FIXME: we at the moment leak all checkers as sonnet does the cleanup to late for proper com cleanup :/
48}
49
50SpellerPlugin *ISpellCheckerClient::createSpeller(const QString &language)
51{
52 // create requested spellchecker if we know the language
53 qCDebug(SONNET_ISPELLCHECKER) << " SpellerPlugin *ISpellCheckerClient::createSpeller(const QString &language) ;" << language;
54 const auto it = m_languages.find(language);
55 if (it != m_languages.end()) {
56 return new ISpellCheckerDict(it.value(), language);
57 }
58 return nullptr;
59}
60
61QStringList ISpellCheckerClient::languages() const
62{
63 return m_languages.keys();
64}
65
66#include "moc_ispellcheckerclient.cpp"
The sonnet namespace.
iterator end()
iterator find(const Key &key)
QList< Key > keys() const const
QString fromWCharArray(const wchar_t *string, qsizetype size)
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Sat Dec 21 2024 17:02:15 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.