• 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
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 }
38 
39 QSpellEnchantDict::~QSpellEnchantDict()
40 {
41  //Enchant caches dictionaries, so it will always return the same one.
42  // therefore we do not want to delete the EnchantDict here but in the
43  // client when it knows that nothing is using it anymore
44  m_client->removeDictRef(m_dict);
45 }
46 
47 bool QSpellEnchantDict::isCorrect(const QString &word) const
48 {
49  int wrong = enchant_dict_check(m_dict, word.toUtf8(),
50  word.toUtf8().length());
51  return !wrong;
52 }
53 
54 QStringList QSpellEnchantDict::suggest(const QString &word) const
55 {
56  /* Needed for Unicode conversion */
57  QTextCodec *codec = QTextCodec::codecForName("utf8");
58 
59  size_t number = 0;
60  char **suggestions =
61  enchant_dict_suggest(m_dict, word.toUtf8(), word.toUtf8().length(),
62  &number);
63 
64  QStringList qsug;
65  for (size_t i = 0; i < number; ++i) {
66  qsug.append(codec->toUnicode(suggestions[i]));
67  }
68 
69  if (suggestions && number)
70  enchant_dict_free_string_list(m_dict, suggestions);
71  return qsug;
72 }
73 
74 bool QSpellEnchantDict::storeReplacement(const QString &bad,
75  const QString &good)
76 {
77  enchant_dict_store_replacement(m_dict,
78  bad.toUtf8(), bad.toUtf8().length(),
79  good.toUtf8(), good.toUtf8().length());
80  return true;
81 }
82 
83 bool QSpellEnchantDict::addToPersonal(const QString &word)
84 {
85  enchant_dict_add(m_dict, word.toUtf8(), word.toUtf8().length());
86  return true;
87 }
88 
89 bool QSpellEnchantDict::addToSession(const QString &word)
90 {
91  enchant_dict_add_to_session(m_dict, word.toUtf8(),
92  word.toUtf8().length());
93  return true;
94 }
enchantclient.h
QSpellEnchantDict::isCorrect
virtual bool isCorrect(const QString &word) const
Definition: enchantdict.cpp:47
QByteArray::length
int length() const
QSpellEnchantDict::addToPersonal
virtual bool addToPersonal(const QString &word)
Definition: enchantdict.cpp:83
QSpellEnchantDict::storeReplacement
virtual bool storeReplacement(const QString &bad, const QString &good)
Definition: enchantdict.cpp:74
QList::append
void append(const T &value)
QSpellEnchantDict::addToSession
virtual bool addToSession(const QString &word)
Definition: enchantdict.cpp:89
QSpellEnchantDict::suggest
virtual QStringList suggest(const QString &word) const
Definition: enchantdict.cpp:54
QSpellEnchantDict::QSpellEnchantDict
QSpellEnchantDict(QSpellEnchantClient *client, EnchantBroker *broker, EnchantDict *dict, const QString &language)
Definition: enchantdict.cpp:28
QString
QTextCodec
QStringList
Sonnet::SpellerPlugin
QTextCodec::codecForName
QTextCodec * codecForName(const QByteArray &name)
QSpellEnchantDict::~QSpellEnchantDict
~QSpellEnchantDict()
Definition: enchantdict.cpp:39
QSpellEnchantClient
Definition: enchantclient.h:35
enchantdict.h
QSpellEnchantClient::removeDictRef
void removeDictRef(EnchantDict *dict)
Definition: enchantclient.cpp:93
QTextCodec::toUnicode
QString toUnicode(const QByteArray &a) const
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