File indexing completed on 2024-05-05 04:01:24

0001 /*
0002  * kspell_aspellclient.cpp
0003  *
0004  * SPDX-FileCopyrightText: 2003 Zack Rusin <zack@kde.org>
0005  *
0006  * SPDX-License-Identifier: LGPL-2.1-or-later
0007  */
0008 
0009 #include "aspellclient.h"
0010 #include "aspelldict.h"
0011 
0012 #include "aspell_debug.h"
0013 #ifdef Q_OS_WIN
0014 #include <QCoreApplication>
0015 #endif
0016 
0017 using namespace Sonnet;
0018 
0019 ASpellClient::ASpellClient(QObject *parent)
0020     : Client(parent)
0021     , m_config(new_aspell_config())
0022 {
0023 #ifdef Q_OS_WIN
0024     aspell_config_replace(m_config, "data-dir", QString::fromLatin1("%1/data/aspell").arg(QCoreApplication::applicationDirPath()).toLatin1().constData());
0025     aspell_config_replace(m_config, "dict-dir", QString::fromLatin1("%1/data/aspell").arg(QCoreApplication::applicationDirPath()).toLatin1().constData());
0026 #endif
0027 }
0028 
0029 ASpellClient::~ASpellClient()
0030 {
0031     delete_aspell_config(m_config);
0032 }
0033 
0034 SpellerPlugin *ASpellClient::createSpeller(const QString &language)
0035 {
0036     ASpellDict *ad = new ASpellDict(language);
0037     return ad;
0038 }
0039 
0040 QStringList ASpellClient::languages() const
0041 {
0042     AspellDictInfoList *l = get_aspell_dict_info_list(m_config);
0043     AspellDictInfoEnumeration *el = aspell_dict_info_list_elements(l);
0044 
0045     QStringList langs;
0046     const AspellDictInfo *di = nullptr;
0047     while ((di = aspell_dict_info_enumeration_next(el))) {
0048         langs.append(QString::fromLatin1(di->name));
0049     }
0050 
0051     delete_aspell_dict_info_enumeration(el);
0052 
0053     return langs;
0054 }
0055 
0056 #include "moc_aspellclient.cpp"