2 Copyright 2013-2015 Mats Sjöberg
4 This file is part of the Pumpa programme.
6 Pumpa is free software: you can redistribute it and/or modify it
7 under the terms of the GNU General Public License as published by
8 the Free Software Foundation, either version 3 of the License, or
9 (at your option) any later version.
11 Pumpa is distributed in the hope that it will be useful, but WITHOUT
12 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
13 or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
14 License for more details.
16 You should have received a copy of the GNU General Public License
17 along with Pumpa. If not, see <http://www.gnu.org/licenses/>.
24 //------------------------------------------------------------------------------
26 QString
QASpell::s_locale
= "en_US";
28 //------------------------------------------------------------------------------
30 QASpell::QASpell(QObject
* parent
) : QObject(parent
) {
32 spell_config
= new_aspell_config();
33 aspell_config_replace(spell_config
, "lang",
34 s_locale
.toLocal8Bit().constData());
35 aspell_config_replace(spell_config
, "encoding", "ucs-2");
37 AspellCanHaveError
* possible_err
= new_aspell_speller(spell_config
);
39 if (aspell_error_number(possible_err
) != 0) {
40 qDebug() << aspell_error_message(possible_err
);
43 spell_checker
= to_aspell_speller(possible_err
);
47 //------------------------------------------------------------------------------
50 if (spell_checker
!= NULL
)
51 delete_aspell_speller(spell_checker
);
52 delete_aspell_config(spell_config
);
55 //------------------------------------------------------------------------------
57 void QASpell::setLocale(QString locale
) {
58 if (!locale
.isEmpty())
62 //------------------------------------------------------------------------------
64 bool QASpell::checksOK() const {
68 if (spell_checker
== NULL
) {
69 qDebug() << "aspell was not initialised properly!";
75 //------------------------------------------------------------------------------
77 bool QASpell::checkWord(const QString
& word
) const {
82 aspell_speller_check(spell_checker
,
83 reinterpret_cast<const char *>(word
.utf16()), -1);
87 //------------------------------------------------------------------------------
89 QStringList
QASpell::suggestions(const QString
& word
) const {
94 const AspellWordList
* wl
=
95 aspell_speller_suggest(spell_checker
,
96 reinterpret_cast<const char *>(word
.utf16()), -1);
97 AspellStringEnumeration
* w
= aspell_word_list_elements(wl
);
99 while ((cw
= aspell_string_enumeration_next(w
)) != NULL
) {
100 list
<< QString::fromUtf16(reinterpret_cast<const ushort
*>(cw
));
102 delete_aspell_string_enumeration(w
);