1 /*************************************************************************** 2 * 2007-2021 by Peter Semiletov * 3 * peter.semiletov@gmail.com * 4 * * 5 * This program is free software; you can redistribute it and/or modify * 6 * it under the terms of the GNU General Public License as published by * 7 * the Free Software Foundation; either version 3 of the License, or * 8 * (at your option) any later version. * 9 * * 10 * This program is distributed in the hope that it will be useful, * 11 * but WITHOUT ANY WARRANTY; without even the implied warranty of * 12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * 13 * GNU General Public License for more details. * 14 * * 15 * You should have received a copy of the GNU General Public License * 16 * along with this program; if not, write to the * 17 * Free Software Foundation, Inc., * 18 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * 19 ***************************************************************************/ 20 21 #ifndef SPELLCHECKER_H 22 #define SPELLCHECKER_H 23 24 #ifdef ASPELL_ENABLE 25 #include "aspell.h" 26 #endif 27 28 #ifdef HUNSPELL_ENABLE 29 #include <hunspell/hunspell.hxx> 30 #endif 31 32 33 #include <QDebug> 34 #include <QString> 35 #include <QStringList> 36 #include <QHash> 37 38 39 class CSpellchecker 40 { 41 42 public: 43 44 QString language; 45 QString dir_dicts; 46 QString dir_user_dicts; 47 QStringList modules_list; 48 49 bool loaded; 50 51 CSpellchecker(const QString & lang,const QString & dir_path,const QString & dir_user)52 CSpellchecker (const QString &lang, 53 const QString &dir_path, 54 const QString &dir_user): language (lang), dir_dicts (dir_path), dir_user_dicts (dir_user), loaded(false) 55 {}; 56 ~CSpellchecker()57 virtual ~CSpellchecker() {}; 58 59 virtual void load_dict() = 0; //uses current language 60 virtual void save_user_dict() = 0; //uses current language 61 virtual void change_lang (const QString &lang) = 0; //set current language 62 virtual void add_to_user_dict (const QString &word) = 0; 63 virtual void remove_from_user_dict (const QString &word) = 0; 64 virtual bool check (const QString &word) = 0; 65 virtual void get_speller_modules_list() = 0; 66 virtual QStringList get_suggestions_list (const QString &word) = 0; 67 }; 68 69 70 #ifdef ASPELL_ENABLE 71 72 class CAspellchecker: public CSpellchecker 73 { 74 75 public: 76 77 AspellConfig *spell_config; 78 AspellCanHaveError *ret; 79 AspellSpeller *speller; 80 81 CAspellchecker (const QString &lang, const QString &dir_path = "", const QString &dir_user = ""); 82 ~CAspellchecker(); 83 save_user_dict()84 void save_user_dict() {}; //not needed due to Aspell implementation 85 void load_dict(); 86 void change_lang (const QString &lang); 87 void add_to_user_dict (const QString &word); 88 void remove_from_user_dict (const QString &word); 89 bool check (const QString &word); 90 void get_speller_modules_list(); 91 QStringList get_suggestions_list (const QString &word); 92 }; 93 94 QString aspell_default_dict_path(); 95 96 #endif 97 98 99 #ifdef HUNSPELL_ENABLE 100 101 class CHunspellChecker: public CSpellchecker 102 { 103 104 public: 105 106 Hunspell *speller; 107 108 QStringList user_words; 109 const char *encoding; //depercated (old Hunspell versions) but supported 110 std::string str_encoding; //new approach 111 112 CHunspellChecker (const QString &lang, const QString &dir_path = "", const QString &dir_user = ""); 113 ~CHunspellChecker(); 114 115 void save_user_dict(); 116 void load_dict(); 117 void change_lang (const QString &lang); 118 void add_to_user_dict (const QString &word); 119 void remove_from_user_dict (const QString &word); 120 bool check (const QString &word); 121 void get_speller_modules_list(); 122 QStringList get_suggestions_list (const QString &word); 123 }; 124 125 QString hunspell_default_dict_path(); 126 127 128 #endif 129 130 #endif 131