Sonnet
kspell_aspelldict.cpp
Go to the documentation of this file.00001
00021 #include "kspell_aspelldict.h"
00022
00023 #include <kdebug.h>
00024
00025 #include <QtCore/QTextCodec>
00026
00027 using namespace Sonnet;
00028
00029 ASpellDict::ASpellDict( const QString& lang )
00030 : SpellerPlugin(lang)
00031 {
00032 m_config = new_aspell_config();
00033 aspell_config_replace( m_config, "lang", lang.toLatin1() );
00034
00035
00036 aspell_config_replace( m_config, "encoding", "utf-8" );
00037
00038 AspellCanHaveError * possible_err = new_aspell_speller( m_config );
00039
00040 if ( aspell_error_number( possible_err ) != 0 )
00041 kDebug()<< "Error : "<< aspell_error_message( possible_err );
00042 else
00043 m_speller = to_aspell_speller( possible_err );
00044
00045 }
00046
00047 ASpellDict::~ASpellDict()
00048 {
00049 delete_aspell_speller( m_speller );
00050 delete_aspell_config( m_config );
00051 }
00052
00053 bool ASpellDict::isCorrect(const QString &word) const
00054 {
00055
00056
00057 int correct = aspell_speller_check( m_speller, word.toUtf8(), word.toUtf8().length() );
00058 return correct;
00059 }
00060
00061 QStringList ASpellDict::suggest(const QString &word) const
00062 {
00063
00064 QTextCodec *codec = QTextCodec::codecForName("utf8");
00065
00066
00067
00068 const AspellWordList * suggestions = aspell_speller_suggest( m_speller,
00069 word.toUtf8(),
00070 word.toUtf8().length() );
00071
00072 AspellStringEnumeration * elements = aspell_word_list_elements( suggestions );
00073
00074 QStringList qsug;
00075 const char * cword;
00076
00077 while ( (cword = aspell_string_enumeration_next( elements )) ) {
00078
00079
00080 qsug.append( codec->toUnicode( cword ) );
00081 }
00082
00083 delete_aspell_string_enumeration( elements );
00084 return qsug;
00085 }
00086
00087
00088 bool ASpellDict::storeReplacement( const QString& bad,
00089 const QString& good )
00090 {
00091
00092
00093 return aspell_speller_store_replacement( m_speller,
00094 bad.toUtf8(), bad.toUtf8().length(),
00095 good.toUtf8(), good.toUtf8().length() );
00096 }
00097
00098 bool ASpellDict::addToPersonal( const QString& word )
00099 {
00100 kDebug() << "ASpellDict::addToPersonal: word = " << word;
00101
00102
00103 aspell_speller_add_to_personal( m_speller, word.toUtf8(),
00104 word.toUtf8().length() );
00105
00106
00107
00108 return aspell_speller_save_all_word_lists( m_speller );
00109 }
00110
00111 bool ASpellDict::addToSession( const QString& word )
00112 {
00113
00114
00115 return aspell_speller_add_to_session( m_speller, word.toUtf8(),
00116 word.toUtf8().length() );
00117 }