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

Sonnet

enchantclient.cpp

Go to the documentation of this file.
00001 // -*- Mode: C++; c-basic-offset: 4; indent-tabs-mode: nil; -*-
00020 #include "enchantclient.h"
00021 #include "enchantdict.h"
00022 
00023 #include <kpluginfactory.h>
00024 #include <kpluginloader.h>
00025 #include <QtCore/QDebug>
00026 
00027 K_PLUGIN_FACTORY(EnchantClientFactory, registerPlugin<QSpellEnchantClient>();)
00028 K_EXPORT_PLUGIN(EnchantClientFactory("kspell_enchant"))
00029 
00030 using namespace Sonnet;
00031 
00032 static void enchantDictDescribeFn(const char * const lang_tag,
00033                                   const char * const provider_name,
00034                                   const char * const provider_desc,
00035                                   const char * const provider_file,
00036                                   void * user_data)
00037 {
00038     QSpellEnchantClient *client =
00039         reinterpret_cast<QSpellEnchantClient*>(user_data);
00040     //qDebug()<<lang_tag<<provider_name<<provider_desc<<provider_file;
00041     Q_UNUSED(provider_name);
00042     Q_UNUSED(provider_desc);
00043     Q_UNUSED(provider_file);
00044     client->addLanguage(QString::fromLatin1(lang_tag));
00045 
00046 }
00047 
00048 QSpellEnchantClient::QSpellEnchantClient(QObject *parent, const QVariantList& /* args */)
00049     : Client(parent)
00050 {
00051     m_broker = enchant_broker_init();
00052     enchant_broker_list_dicts(m_broker,
00053                               enchantDictDescribeFn,
00054                               this);
00055 }
00056 
00057 QSpellEnchantClient::~QSpellEnchantClient()
00058 {
00059     enchant_broker_free(m_broker);
00060 }
00061 
00062 SpellerPlugin *QSpellEnchantClient::createSpeller(
00063     const QString &language)
00064 {
00065     EnchantDict *dict = enchant_broker_request_dict(m_broker,
00066                                                     language.toUtf8());
00067 
00068     if (!dict) {
00069         const char *err = enchant_broker_get_error(m_broker);
00070 #ifndef NDEBUG
00071         qDebug()<<"Couldn't create speller for"<<language<<": "<<err;
00072 #endif
00073         return 0;
00074     } else {
00075         //Enchant caches dictionaries, so it will always return the same one.
00076         int refs = m_dictRefs[dict];
00077         ++refs;
00078         m_dictRefs[dict] = refs;
00079         return new QSpellEnchantDict(this, m_broker, dict, language);
00080     }
00081 }
00082 
00083 QStringList QSpellEnchantClient::languages() const
00084 {
00085     return m_languages.toList();
00086 }
00087 
00088 void QSpellEnchantClient::addLanguage(const QString &lang)
00089 {
00090     m_languages.insert(lang);
00091 }
00092 
00093 void QSpellEnchantClient::removeDictRef(EnchantDict *dict)
00094 {
00095     int refs = m_dictRefs[dict];
00096     --refs;
00097     m_dictRefs[dict] = refs;
00098     if (refs <= 0) {
00099         m_dictRefs.remove(dict);
00100         enchant_broker_free_dict(m_broker, dict);
00101     }
00102 }
00103 
00104 #include "enchantclient.moc"

Sonnet

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

kdelibs

Skip menu "kdelibs"
  • DNSSD
  • Interfaces
  •   KHexEdit
  •   KMediaPlayer
  •   KSpeech
  •   KTextEditor
  • Kate
  • kconf_update
  • KDE3Support
  •   KUnitTest
  • KDECore
  • KDED
  • KDEsu
  • KDEUI
  • KDocTools
  • KFile
  • KHTML
  • KImgIO
  • KInit
  • KIO
  • KIOSlave
  • KJS
  •   KJS-API
  •   WTF
  • kjsembed
  • KNewStuff
  • KParts
  • Kross
  • KUtils
  • Nepomuk
  • Solid
  • Sonnet
  • ThreadWeaver
Generated for kdelibs by doxygen 1.5.4
This website is maintained by Adriaan de Groot and Allen Winter.
KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal