File indexing completed on 2024-04-28 04:00:53

0001 /*
0002  * voikkoclient.cpp
0003  *
0004  * SPDX-FileCopyrightText: 2015 Jesse Jaara <jesse.jaara@gmail.com>
0005  *
0006  * SPDX-License-Identifier: LGPL-2.1-or-later
0007  */
0008 
0009 #include "voikkoclient.h"
0010 #include "voikkodebug.h"
0011 #include "voikkodict.h"
0012 
0013 VoikkoClient::VoikkoClient(QObject *parent)
0014     : Sonnet::Client(parent)
0015 {
0016     qCDebug(SONNET_VOIKKO) << "Initializing Voikko spell checker plugin.";
0017 
0018     char **dictionaries = voikkoListSupportedSpellingLanguages(nullptr);
0019 
0020     if (!dictionaries) {
0021         return;
0022     }
0023 
0024     for (int i = 0; dictionaries[i] != nullptr; ++i) {
0025         QString language = QString::fromUtf8(dictionaries[i]);
0026         m_supportedLanguages.append(language);
0027         qCDebug(SONNET_VOIKKO) << "Found dictionary for language:" << language;
0028     }
0029 
0030     voikkoFreeCstrArray(dictionaries);
0031 }
0032 
0033 VoikkoClient::~VoikkoClient()
0034 {
0035 }
0036 
0037 int VoikkoClient::reliability() const
0038 {
0039     return 50;
0040 }
0041 
0042 Sonnet::SpellerPlugin *VoikkoClient::createSpeller(const QString &language)
0043 {
0044     VoikkoDict *speller = new VoikkoDict(language);
0045     if (speller->initFailed()) {
0046         delete speller;
0047         return nullptr;
0048     }
0049 
0050     return speller;
0051 }
0052 
0053 QStringList VoikkoClient::languages() const
0054 {
0055     return m_supportedLanguages;
0056 }
0057 
0058 QString VoikkoClient::name() const
0059 {
0060     return QStringLiteral("Voikko");
0061 }
0062 
0063 #include "moc_voikkoclient.cpp"