Sonnet
enchantdict.cpp
Go to the documentation of this file.
00001 // -*- Mode: C++; c-basic-offset: 4; indent-tabs-mode: nil; -*- 00020 #include "enchantdict.h" 00021 #include "enchantclient.h" 00022 00023 #include <QtCore/QTextCodec> 00024 #include <QtCore/QDebug> 00025 00026 using namespace Sonnet; 00027 00028 QSpellEnchantDict::QSpellEnchantDict(QSpellEnchantClient *client, 00029 EnchantBroker *broker, 00030 EnchantDict *dict, 00031 const QString &language) 00032 : SpellerPlugin(language), 00033 m_broker(broker), 00034 m_dict(dict), 00035 m_client(client) 00036 { 00037 qDebug()<<"Enchant dict for"<<language << dict; 00038 } 00039 00040 QSpellEnchantDict::~QSpellEnchantDict() 00041 { 00042 //Enchant caches dictionaries, so it will always return the same one. 00043 // therefore we do not want to delete the EnchantDict here but in the 00044 // client when it knows that nothing is using it anymore 00045 m_client->removeDictRef(m_dict); 00046 } 00047 00048 bool QSpellEnchantDict::isCorrect(const QString &word) const 00049 { 00050 int wrong = enchant_dict_check(m_dict, word.toUtf8(), 00051 word.toUtf8().length()); 00052 return !wrong; 00053 } 00054 00055 QStringList QSpellEnchantDict::suggest(const QString &word) const 00056 { 00057 /* Needed for Unicode conversion */ 00058 QTextCodec *codec = QTextCodec::codecForName("utf8"); 00059 00060 size_t number = 0; 00061 char **suggestions = 00062 enchant_dict_suggest(m_dict, word.toUtf8(), word.toUtf8().length(), 00063 &number); 00064 00065 QStringList qsug; 00066 for (size_t i = 0; i < number; ++i) { 00067 qsug.append(codec->toUnicode(suggestions[i])); 00068 } 00069 00070 if (suggestions && number) 00071 enchant_dict_free_string_list(m_dict, suggestions); 00072 return qsug; 00073 } 00074 00075 bool QSpellEnchantDict::storeReplacement(const QString &bad, 00076 const QString &good) 00077 { 00078 enchant_dict_store_replacement(m_dict, 00079 bad.toUtf8(), bad.toUtf8().length(), 00080 good.toUtf8(), good.toUtf8().length()); 00081 return true; 00082 } 00083 00084 bool QSpellEnchantDict::addToPersonal(const QString &word) 00085 { 00086 qDebug() << "QSpellEnchantDict::addToPersonal: word = " 00087 << word; 00088 enchant_dict_add_to_pwl(m_dict, word.toUtf8(), 00089 word.toUtf8().length()); 00090 return true; 00091 } 00092 00093 bool QSpellEnchantDict::addToSession(const QString &word) 00094 { 00095 enchant_dict_add_to_session(m_dict, word.toUtf8(), 00096 word.toUtf8().length()); 00097 return true; 00098 }
KDE 4.6 API Reference