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 speller.h <Sonnet/Speller>
22 *
23 * Spell checker object.
24 *
25 * @short class used for actual spell checking
26 */
27class SONNETCORE_EXPORT Speller
28{
29public:
30 explicit Speller(const QString &lang = QString());
31 ~Speller();
32
33 Speller(const Speller &speller);
34 Speller &operator=(const Speller &speller);
35
36 /**
37 * @return @c true if the speller supports currently selected
38 * language.
39 */
40 bool isValid() const;
41
42 /**
43 * Sets the language supported by this speller.
44 */
45 void setLanguage(const QString &lang);
46
47 /**
48 * @return language supported by this speller.
49 */
50 QString language() const;
51
52 /**
53 * Checks the given word.
54 * @return false if the word is misspelled. true otherwise
55 */
56 bool isCorrect(const QString &word) const;
57
58 /**
59 * Checks the given word.
60 * @return true if the word is misspelled. false otherwise
61 */
62 bool isMisspelled(const QString &word) const;
63
64 /**
65 * Fetches suggestions for the word.
66 *
67 * @return list of all suggestions for the word
68 */
69 QStringList suggest(const QString &word) const;
70
71 /**
72 * Convenience method calling isCorrect() and suggest()
73 * if the word isn't correct.
74 */
75 bool checkAndSuggest(const QString &word, QStringList &suggestions) const;
76
77 /**
78 * Stores user defined good replacement for the bad word.
79 * @return @c true on success
80 */
81 bool storeReplacement(const QString &bad, const QString &good);
82
83 /**
84 * Adds word to the list of of personal words.
85 * @return true on success
86 */
87 bool addToPersonal(const QString &word);
88
89 /**
90 * Adds word to the words recognizable in the current session.
91 * @return true on success
92 */
93 bool addToSession(const QString &word);
94
95public: // Configuration API
96 enum Attribute {
97 CheckUppercase,
98 SkipRunTogether,
99 AutoDetectLanguage,
100 };
101 void save();
102 void restore();
103
104 /**
105 * @return names of all supported backends (e.g. ISpell, ASpell)
106 */
107 QStringList availableBackends() const;
108
109 /**
110 * @return a list of supported languages.
111 *
112 * Note: use availableDictionaries
113 */
114 QStringList availableLanguages() const;
115
116 /**
117 * @return a localized list of names of supported languages.
118 *
119 * Note: use availableDictionaries
120 */
121 QStringList availableLanguageNames() const;
122
123 /**
124 * @return a map of all available dictionaries with language descriptions and
125 * their codes. The key is the description, the code the value.
126 */
127 QMap<QString, QString> availableDictionaries() const;
128
129 /**
130 * @return a map of user preferred dictionaries with language descriptions and
131 * their codes. The key is the description, the code the value.
132 * @since 5.54
133 */
134 QMap<QString, QString> preferredDictionaries() const;
135
136 void setDefaultLanguage(const QString &lang);
137 QString defaultLanguage() const;
138
139 void setDefaultClient(const QString &client);
140 QString defaultClient() const;
141
142 void setAttribute(Attribute attr, bool b = true);
143 bool testAttribute(Attribute attr) const;
144
145private:
146 std::unique_ptr<SpellerPrivate> const d;
147};
148}
149#endif
150

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