File indexing completed on 2024-04-21 04:00:55
0001 /* 0002 * SPDX-FileCopyrightText: 2007 Zack Rusin <zack@kde.org> 0003 * 0004 * SPDX-License-Identifier: LGPL-2.1-or-later 0005 */ 0006 #ifndef SONNET_SPELLER_H 0007 #define SONNET_SPELLER_H 0008 0009 #include <QMap> 0010 #include <QString> 0011 #include <QStringList> 0012 0013 #include "sonnetcore_export.h" 0014 0015 #include <memory> 0016 0017 namespace Sonnet 0018 { 0019 class SpellerPrivate; 0020 /** 0021 * @class Sonnet::Speller speller.h <Sonnet/Speller> 0022 * 0023 * Spell checker object. 0024 * 0025 * @short class used for actual spell checking 0026 */ 0027 class SONNETCORE_EXPORT Speller 0028 { 0029 public: 0030 explicit Speller(const QString &lang = QString()); 0031 ~Speller(); 0032 0033 Speller(const Speller &speller); 0034 Speller &operator=(const Speller &speller); 0035 0036 /** 0037 * @return @c true if the speller supports currently selected 0038 * language. 0039 */ 0040 bool isValid() const; 0041 0042 /** 0043 * Sets the language supported by this speller. 0044 */ 0045 void setLanguage(const QString &lang); 0046 0047 /** 0048 * @return language supported by this speller. 0049 */ 0050 QString language() const; 0051 0052 /** 0053 * Checks the given word. 0054 * @return false if the word is misspelled. true otherwise 0055 */ 0056 bool isCorrect(const QString &word) const; 0057 0058 /** 0059 * Checks the given word. 0060 * @return true if the word is misspelled. false otherwise 0061 */ 0062 bool isMisspelled(const QString &word) const; 0063 0064 /** 0065 * Fetches suggestions for the word. 0066 * 0067 * @return list of all suggestions for the word 0068 */ 0069 QStringList suggest(const QString &word) const; 0070 0071 /** 0072 * Convenience method calling isCorrect() and suggest() 0073 * if the word isn't correct. 0074 */ 0075 bool checkAndSuggest(const QString &word, QStringList &suggestions) const; 0076 0077 /** 0078 * Stores user defined good replacement for the bad word. 0079 * @return @c true on success 0080 */ 0081 bool storeReplacement(const QString &bad, const QString &good); 0082 0083 /** 0084 * Adds word to the list of of personal words. 0085 * @return true on success 0086 */ 0087 bool addToPersonal(const QString &word); 0088 0089 /** 0090 * Adds word to the words recognizable in the current session. 0091 * @return true on success 0092 */ 0093 bool addToSession(const QString &word); 0094 0095 public: // Configuration API 0096 enum Attribute { 0097 CheckUppercase, 0098 SkipRunTogether, 0099 AutoDetectLanguage, 0100 }; 0101 void save(); 0102 void restore(); 0103 0104 /** 0105 * @return names of all supported backends (e.g. ISpell, ASpell) 0106 */ 0107 QStringList availableBackends() const; 0108 0109 /** 0110 * @return a list of supported languages. 0111 * 0112 * Note: use availableDictionaries 0113 */ 0114 QStringList availableLanguages() const; 0115 0116 /** 0117 * @return a localized list of names of supported languages. 0118 * 0119 * Note: use availableDictionaries 0120 */ 0121 QStringList availableLanguageNames() const; 0122 0123 /** 0124 * @return a map of all available dictionaries with language descriptions and 0125 * their codes. The key is the description, the code the value. 0126 */ 0127 QMap<QString, QString> availableDictionaries() const; 0128 0129 /** 0130 * @return a map of user preferred dictionaries with language descriptions and 0131 * their codes. The key is the description, the code the value. 0132 * @since 5.54 0133 */ 0134 QMap<QString, QString> preferredDictionaries() const; 0135 0136 void setDefaultLanguage(const QString &lang); 0137 QString defaultLanguage() const; 0138 0139 void setDefaultClient(const QString &client); 0140 QString defaultClient() const; 0141 0142 void setAttribute(Attribute attr, bool b = true); 0143 bool testAttribute(Attribute attr) const; 0144 0145 private: 0146 std::unique_ptr<SpellerPrivate> const d; 0147 }; 0148 } 0149 #endif