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

Sonnet

  • sources
  • kde-4.12
  • kdelibs
  • sonnet
  • plugins
  • enchant
enchantdict.cpp
Go to the documentation of this file.
1 // -*- Mode: C++; c-basic-offset: 4; indent-tabs-mode: nil; -*-
20 #include "enchantdict.h"
21 #include "enchantclient.h"
22 
23 #include <QtCore/QTextCodec>
24 #include <QtCore/QDebug>
25 
26 using namespace Sonnet;
27 
28 QSpellEnchantDict::QSpellEnchantDict(QSpellEnchantClient *client,
29  EnchantBroker *broker,
30  EnchantDict *dict,
31  const QString &language)
32  : SpellerPlugin(language),
33  m_broker(broker),
34  m_dict(dict),
35  m_client(client)
36 {
37  qDebug()<<"Enchant dict for"<<language << dict;
38 }
39 
40 QSpellEnchantDict::~QSpellEnchantDict()
41 {
42  //Enchant caches dictionaries, so it will always return the same one.
43  // therefore we do not want to delete the EnchantDict here but in the
44  // client when it knows that nothing is using it anymore
45  m_client->removeDictRef(m_dict);
46 }
47 
48 bool QSpellEnchantDict::isCorrect(const QString &word) const
49 {
50  int wrong = enchant_dict_check(m_dict, word.toUtf8(),
51  word.toUtf8().length());
52  return !wrong;
53 }
54 
55 QStringList QSpellEnchantDict::suggest(const QString &word) const
56 {
57  /* Needed for Unicode conversion */
58  QTextCodec *codec = QTextCodec::codecForName("utf8");
59 
60  size_t number = 0;
61  char **suggestions =
62  enchant_dict_suggest(m_dict, word.toUtf8(), word.toUtf8().length(),
63  &number);
64 
65  QStringList qsug;
66  for (size_t i = 0; i < number; ++i) {
67  qsug.append(codec->toUnicode(suggestions[i]));
68  }
69 
70  if (suggestions && number)
71  enchant_dict_free_string_list(m_dict, suggestions);
72  return qsug;
73 }
74 
75 bool QSpellEnchantDict::storeReplacement(const QString &bad,
76  const QString &good)
77 {
78  enchant_dict_store_replacement(m_dict,
79  bad.toUtf8(), bad.toUtf8().length(),
80  good.toUtf8(), good.toUtf8().length());
81  return true;
82 }
83 
84 bool QSpellEnchantDict::addToPersonal(const QString &word)
85 {
86  qDebug() << "QSpellEnchantDict::addToPersonal: word = "
87  << word;
88  enchant_dict_add_to_pwl(m_dict, word.toUtf8(),
89  word.toUtf8().length());
90  return true;
91 }
92 
93 bool QSpellEnchantDict::addToSession(const QString &word)
94 {
95  enchant_dict_add_to_session(m_dict, word.toUtf8(),
96  word.toUtf8().length());
97  return true;
98 }
enchantclient.h
QSpellEnchantDict::isCorrect
virtual bool isCorrect(const QString &word) const
Definition: enchantdict.cpp:48
QString
QSpellEnchantDict::addToPersonal
virtual bool addToPersonal(const QString &word)
Definition: enchantdict.cpp:84
QSpellEnchantDict::storeReplacement
virtual bool storeReplacement(const QString &bad, const QString &good)
Definition: enchantdict.cpp:75
QSpellEnchantDict::addToSession
virtual bool addToSession(const QString &word)
Definition: enchantdict.cpp:93
QSpellEnchantDict::suggest
virtual QStringList suggest(const QString &word) const
Definition: enchantdict.cpp:55
QStringList
QSpellEnchantDict::QSpellEnchantDict
QSpellEnchantDict(QSpellEnchantClient *client, EnchantBroker *broker, EnchantDict *dict, const QString &language)
Definition: enchantdict.cpp:28
Sonnet::SpellerPlugin
QSpellEnchantDict::~QSpellEnchantDict
~QSpellEnchantDict()
Definition: enchantdict.cpp:40
QSpellEnchantClient
Definition: enchantclient.h:35
enchantdict.h
QSpellEnchantClient::removeDictRef
void removeDictRef(EnchantDict *dict)
Definition: enchantclient.cpp:93
This file is part of the KDE documentation.
Documentation copyright © 1996-2014 The KDE developers.
Generated on Tue Oct 14 2014 22:49:51 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
  • kjsembed
  •   WTF
  • KNewStuff
  • KParts
  • KPty
  • Kross
  • KUnitConversion
  • KUtils
  • Nepomuk
  • Nepomuk-Core
  • 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