1/*
2 * SPDX-FileCopyrightText: 2007 Zack Rusin <zack@kde.org>
3 *
4 * SPDX-License-Identifier: LGPL-2.1-or-later
5 */
6#ifndef SONNET_SPELLER_H
7#define SONNET_SPELLER_H
8
9#include <QMap>
10#include <QString>
11#include <QStringList>
12
13#include "sonnetcore_export.h"
14
15#include <memory>
16
17namespace Sonnet
18{
19class SpellerPrivate;
20/*!
21 * \class Sonnet::Speller
22 * \inheaderfile Sonnet/Speller
23 * \inmodule SonnetCore
24 *
25 * \brief class used for actual spell checking.
26 *
27 * Spell checker object.
28 */
29class SONNETCORE_EXPORT Speller
30{
31public:
32 /*!
33 */
34 explicit Speller(const QString &lang = QString());
35 ~Speller();
36
37 Speller(const Speller &speller);
38 Speller &operator=(const Speller &speller);
39
40 /*!
41 * Returns \c true if the speller supports currently selected
42 * language.
43 */
44 bool isValid() const;
45
46 /*!
47 * Sets the language supported by this speller.
48 */
49 void setLanguage(const QString &lang);
50
51 /*!
52 * Returns language supported by this speller.
53 */
54 QString language() const;
55
56 /*!
57 * Checks the given word.
58 * Returns false if the word is misspelled. true otherwise
59 */
60 bool isCorrect(const QString &word) const;
61
62 /*!
63 * Checks the given word.
64 * Returns true if the word is misspelled. false otherwise
65 */
66 bool isMisspelled(const QString &word) const;
67
68 /*!
69 * Fetches suggestions for the word.
70 *
71 * Returns list of all suggestions for the word
72 */
73 QStringList suggest(const QString &word) const;
74
75 /*!
76 * Convenience method calling isCorrect() and suggest()
77 * if the word isn't correct.
78 */
79 bool checkAndSuggest(const QString &word, QStringList &suggestions) const;
80
81 /*!
82 * Stores user defined good replacement for the bad word.
83 *
84 * Returns \c true on success
85 */
86 bool storeReplacement(const QString &bad, const QString &good);
87
88 /*!
89 * Adds word to the list of of personal words.
90 * Returns true on success
91 */
92 bool addToPersonal(const QString &word);
93
94 /*!
95 * Adds word to the words recognizable in the current session.
96 * Returns true on success
97 */
98 bool addToSession(const QString &word);
99
100public: // Configuration API
101 /*!
102 * \value CheckUppercase
103 * \value SkipRunTogether
104 * \value AutoDetectLanguage
105 */
106 enum Attribute {
107 CheckUppercase,
108 SkipRunTogether,
109 AutoDetectLanguage,
110 };
111 /*!
112 */
113 void save();
114 /*!
115 */
116 void restore();
117
118 /*!
119 * Returns names of all supported backends (e.g. ISpell, ASpell)
120 */
121 QStringList availableBackends() const;
122
123 /*!
124 * Returns a list of supported languages.
125 *
126 * \note use availableDictionaries
127 */
128 QStringList availableLanguages() const;
129
130 /*!
131 * Returns a localized list of names of supported languages.
132 *
133 * \note use availableDictionaries
134 */
135 QStringList availableLanguageNames() const;
136
137 /*!
138 * Returns a map of all available dictionaries with language descriptions and
139 * their codes. The key is the description, the code the value.
140 */
141 QMap<QString, QString> availableDictionaries() const;
142
143 /*!
144 * Returns a map of user preferred dictionaries with language descriptions and
145 * their codes. The key is the description, the code the value.
146 * \since 5.54
147 */
148 QMap<QString, QString> preferredDictionaries() const;
149
150 /*!
151 */
152 void setDefaultLanguage(const QString &lang);
153 /*!
154 */
155 QString defaultLanguage() const;
156
157 /*!
158 */
159 void setDefaultClient(const QString &client);
160 /*!
161 */
162 QString defaultClient() const;
163
164 /*!
165 */
166 void setAttribute(Attribute attr, bool b = true);
167 /*!
168 */
169 bool testAttribute(Attribute attr) const;
170
171private:
172 std::unique_ptr<SpellerPrivate> const d;
173};
174}
175#endif
176

source code of sonnet/src/core/speller.h