• Skip to content
  • Skip to link menu
  • KDE API Reference
  • kdelibs-4.14.38 API Reference
  • KDE Home
  • Contact Us
 

Sonnet

  • sonnet
  • plugins
  • enchant
enchantclient.cpp
Go to the documentation of this file.
1// -*- Mode: C++; c-basic-offset: 4; indent-tabs-mode: nil; -*-
20#include "enchantclient.h"
21#include "enchantdict.h"
22
23#include <kpluginfactory.h>
24#include <kpluginloader.h>
25#include <QtCore/QDebug>
26
27K_PLUGIN_FACTORY(EnchantClientFactory, registerPlugin<QSpellEnchantClient>();)
28K_EXPORT_PLUGIN(EnchantClientFactory("kspell_enchant"))
29
30using namespace Sonnet;
31
32static void enchantDictDescribeFn(const char * const lang_tag,
33 const char * const provider_name,
34 const char * const provider_desc,
35 const char * const provider_file,
36 void * user_data)
37{
38 QSpellEnchantClient *client =
39 reinterpret_cast<QSpellEnchantClient*>(user_data);
40 //qDebug()<<lang_tag<<provider_name<<provider_desc<<provider_file;
41 Q_UNUSED(provider_name);
42 Q_UNUSED(provider_desc);
43 Q_UNUSED(provider_file);
44 client->addLanguage(QString::fromLatin1(lang_tag));
45
46}
47
48QSpellEnchantClient::QSpellEnchantClient(QObject *parent, const QVariantList& /* args */)
49 : Client(parent)
50{
51 m_broker = enchant_broker_init();
52 enchant_broker_list_dicts(m_broker,
53 enchantDictDescribeFn,
54 this);
55}
56
57QSpellEnchantClient::~QSpellEnchantClient()
58{
59 enchant_broker_free(m_broker);
60}
61
62SpellerPlugin *QSpellEnchantClient::createSpeller(
63 const QString &language)
64{
65 EnchantDict *dict = enchant_broker_request_dict(m_broker,
66 language.toUtf8());
67
68 if (!dict) {
69#ifndef NDEBUG
70 const char *err = enchant_broker_get_error(m_broker);
71 qDebug()<<"Couldn't create speller for"<<language<<": "<<err;
72#endif
73 return 0;
74 } else {
75 //Enchant caches dictionaries, so it will always return the same one.
76 int refs = m_dictRefs[dict];
77 ++refs;
78 m_dictRefs[dict] = refs;
79 return new QSpellEnchantDict(this, m_broker, dict, language);
80 }
81}
82
83QStringList QSpellEnchantClient::languages() const
84{
85 return m_languages.toList();
86}
87
88void QSpellEnchantClient::addLanguage(const QString &lang)
89{
90 m_languages.insert(lang);
91}
92
93void QSpellEnchantClient::removeDictRef(EnchantDict *dict)
94{
95 int refs = m_dictRefs[dict];
96 --refs;
97 m_dictRefs[dict] = refs;
98 if (refs <= 0) {
99 m_dictRefs.remove(dict);
100 enchant_broker_free_dict(m_broker, dict);
101 }
102}
103
104#include "enchantclient.moc"
K_PLUGIN_FACTORY
#define K_PLUGIN_FACTORY(name, pluginRegistrations)
K_EXPORT_PLUGIN
#define K_EXPORT_PLUGIN(factory)
QObject
QSpellEnchantClient
Definition: enchantclient.h:36
QSpellEnchantClient::addLanguage
void addLanguage(const QString &lang)
Definition: enchantclient.cpp:88
QSpellEnchantClient::removeDictRef
void removeDictRef(EnchantDict *dict)
Definition: enchantclient.cpp:93
QSpellEnchantClient::languages
virtual QStringList languages() const
Definition: enchantclient.cpp:83
QSpellEnchantClient::createSpeller
virtual SpellerPlugin * createSpeller(const QString &language)
Definition: enchantclient.cpp:62
QSpellEnchantClient::QSpellEnchantClient
QSpellEnchantClient(QObject *parent, const QVariantList &)
Definition: enchantclient.cpp:48
QSpellEnchantClient::~QSpellEnchantClient
~QSpellEnchantClient()
Definition: enchantclient.cpp:57
QSpellEnchantDict
Definition: enchantdict.h:30
Sonnet::Client
Sonnet::SpellerPlugin
enchantDictDescribeFn
static void enchantDictDescribeFn(const char *const lang_tag, const char *const provider_name, const char *const provider_desc, const char *const provider_file, void *user_data)
Definition: enchantclient.cpp:32
enchantclient.h
enchantdict.h
kpluginfactory.h
kpluginloader.h
Sonnet
kspell_aspellclient.h
This file is part of the KDE documentation.
Documentation copyright © 1996-2023 The KDE developers.
Generated on Mon Feb 20 2023 00:00:00 by doxygen 1.9.6 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

Sonnet

Skip menu "Sonnet"
  • Main Page
  • Namespace List
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • File Members
  • Related Pages

kdelibs-4.14.38 API Reference

Skip menu "kdelibs-4.14.38 API Reference"
  • DNSSD
  • Interfaces
  •   KHexEdit
  •   KMediaPlayer
  •   KSpeech
  •   KTextEditor
  • kconf_update
  • KDE3Support
  •   KUnitTest
  • KDECore
  • KDED
  • KDEsu
  • KDEUI
  • KDEWebKit
  • KDocTools
  • KFile
  • KHTML
  • KImgIO
  • KInit
  • kio
  • KIOSlave
  • KJS
  •   KJS-API
  •   WTF
  • kjsembed
  • KNewStuff
  • KParts
  • KPty
  • Kross
  • KUnitConversion
  • KUtils
  • Nepomuk
  • Plasma
  • Solid
  • Sonnet
  • ThreadWeaver
Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal