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

Sonnet

  • sources
  • kde-4.14
  • kdelibs
  • 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 
27 K_PLUGIN_FACTORY(EnchantClientFactory, registerPlugin<QSpellEnchantClient>();)
28 K_EXPORT_PLUGIN(EnchantClientFactory("kspell_enchant"))
29 
30 using namespace Sonnet;
31 
32 static 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 
48 QSpellEnchantClient::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 
57 QSpellEnchantClient::~QSpellEnchantClient()
58 {
59  enchant_broker_free(m_broker);
60 }
61 
62 SpellerPlugin *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 
83 QStringList QSpellEnchantClient::languages() const
84 {
85  return m_languages.toList();
86 }
87 
88 void QSpellEnchantClient::addLanguage(const QString &lang)
89 {
90  m_languages.insert(lang);
91 }
92 
93 void 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"
enchantclient.h
QSpellEnchantClient::addLanguage
void addLanguage(const QString &lang)
Definition: enchantclient.cpp:88
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
QSet::insert
const_iterator insert(const T &value)
K_PLUGIN_FACTORY
#define K_PLUGIN_FACTORY(name, pluginRegistrations)
QSpellEnchantClient::~QSpellEnchantClient
~QSpellEnchantClient()
Definition: enchantclient.cpp:57
QObject
kpluginloader.h
QSpellEnchantClient::QSpellEnchantClient
QSpellEnchantClient(QObject *parent, const QVariantList &)
Definition: enchantclient.cpp:48
QSpellEnchantDict
Definition: enchantdict.h:29
QSpellEnchantClient::languages
virtual QStringList languages() const
Definition: enchantclient.cpp:83
QString
QHash::remove
int remove(const Key &key)
QStringList
Sonnet::SpellerPlugin
QSpellEnchantClient::createSpeller
virtual SpellerPlugin * createSpeller(const QString &language)
Definition: enchantclient.cpp:62
kpluginfactory.h
QSet::toList
QList< T > toList() const
QString::fromLatin1
QString fromLatin1(const char *str, int size)
QSpellEnchantClient
Definition: enchantclient.h:35
enchantdict.h
QSpellEnchantClient::removeDictRef
void removeDictRef(EnchantDict *dict)
Definition: enchantclient.cpp:93
K_EXPORT_PLUGIN
#define K_EXPORT_PLUGIN(factory)
Sonnet::Client
QString::toUtf8
QByteArray toUtf8() const
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Mon Jun 22 2020 13:24:40 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

Sonnet

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

kdelibs API Reference

Skip menu "kdelibs 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

Search



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