1 | /* |
2 | * SPDX-FileCopyrightText: 2020 Benjamin Port <benjamin.port@enioka.com> |
3 | * |
4 | * SPDX-License-Identifier: LGPL-2.1-or-later |
5 | */ |
6 | #ifndef SONNET_SETTINGS_H |
7 | #define SONNET_SETTINGS_H |
8 | |
9 | #include <QAbstractListModel> |
10 | #include <QObject> |
11 | #include <QString> |
12 | #include <QStringList> |
13 | |
14 | #include "sonnetcore_export.h" |
15 | |
16 | #include <memory> |
17 | |
18 | namespace Sonnet |
19 | { |
20 | class Loader; |
21 | class SettingsPrivate; |
22 | |
23 | /*! |
24 | * \class Sonnet::Settings |
25 | * \inheaderfile Sonnet/Settings |
26 | * \inmodule SonnetCore |
27 | */ |
28 | class SONNETCORE_EXPORT Settings : public QObject |
29 | { |
30 | Q_OBJECT |
31 | |
32 | /*! |
33 | * \property Sonnet::Settings::skipUppercase |
34 | * |
35 | * This property holds whether Sonnet should skip checkign words starting with an uppercase letter. |
36 | */ |
37 | Q_PROPERTY(bool skipUppercase READ skipUppercase WRITE setSkipUppercase NOTIFY skipUppercaseChanged) |
38 | |
39 | /*! |
40 | * \property Sonnet::Settings::autodetectLanguage |
41 | * |
42 | * This property holds whether Sonnet should autodetect language. |
43 | */ |
44 | Q_PROPERTY(bool autodetectLanguage READ autodetectLanguage WRITE setAutodetectLanguage NOTIFY autodetectLanguageChanged) |
45 | |
46 | /*! |
47 | * \property Sonnet::Settings::backgroundCheckerEnabled |
48 | * |
49 | * This property holds whether Sonnet should run spellchecking checks in the background. |
50 | */ |
51 | Q_PROPERTY(bool backgroundCheckerEnabled READ backgroundCheckerEnabled WRITE setBackgroundCheckerEnabled NOTIFY backgroundCheckerEnabledChanged) |
52 | |
53 | /*! |
54 | * \property Sonnet::Settings::checkerEnabledByDefault |
55 | * |
56 | * This property holds whether Sonnet should be enabled by default. |
57 | */ |
58 | Q_PROPERTY(bool checkerEnabledByDefault READ checkerEnabledByDefault WRITE setCheckerEnabledByDefault NOTIFY checkerEnabledByDefaultChanged) |
59 | |
60 | /*! |
61 | * \property Sonnet::Settings::skipRunTogether |
62 | * |
63 | * This property holds whether Sonnet should skip checking compounds words. |
64 | */ |
65 | Q_PROPERTY(bool skipRunTogether READ skipRunTogether WRITE setSkipRunTogether NOTIFY skipRunTogetherChanged) |
66 | |
67 | /*! |
68 | * \property Sonnet::Settings::currentIgnoreList |
69 | * |
70 | * This property holds the list of ignored words. |
71 | */ |
72 | Q_PROPERTY(QStringList currentIgnoreList READ currentIgnoreList WRITE setCurrentIgnoreList NOTIFY currentIgnoreListChanged) |
73 | |
74 | /*! |
75 | * \property Sonnet::Settings::preferredLanguages |
76 | * |
77 | * This property holds the list of preferred languages. |
78 | */ |
79 | Q_PROPERTY(QStringList preferredLanguages READ preferredLanguages WRITE setPreferredLanguages NOTIFY preferredLanguagesChanged) |
80 | |
81 | /*! |
82 | * \property Sonnet::Settings::defaultLanguage |
83 | * |
84 | * This property holds the default language for spell checking. |
85 | */ |
86 | Q_PROPERTY(QString defaultLanguage READ defaultLanguage WRITE setDefaultLanguage NOTIFY defaultLanguageChanged) |
87 | |
88 | /*! |
89 | * \property Sonnet::Settings::dictionaryModel |
90 | * |
91 | * This property holds a Qt Model containing all the preferred dictionaries |
92 | * with language description and theirs codes. This model makes the |
93 | * Qt::DisplayRole as well as the roles defined in DictionaryRoles |
94 | * available. |
95 | * \since 5.88 |
96 | */ |
97 | Q_PROPERTY(QAbstractListModel *dictionaryModel READ dictionaryModel CONSTANT) |
98 | |
99 | /*! |
100 | * \property Sonnet::Settings::modified |
101 | */ |
102 | Q_PROPERTY(bool modified READ modified NOTIFY modifiedChanged) |
103 | |
104 | public: |
105 | /*! |
106 | * Roles for dictionaryModel |
107 | * |
108 | * \value LanguageCodeRole |
109 | * Language code of the language. This uses "languageCode" as roleNames. |
110 | * \value PreferredRole |
111 | * This role holds whether the language is one of the preferred languages. This uses "isPreferred" as roleNames. |
112 | * \value DefaultRole |
113 | * This role holds whether the language is the default language. This uses "isDefault" as roleNames. |
114 | */ |
115 | enum DictionaryRoles { |
116 | LanguageCodeRole = Qt::UserRole + 1, |
117 | PreferredRole, |
118 | DefaultRole |
119 | }; |
120 | |
121 | /*! |
122 | */ |
123 | explicit Settings(QObject *parent = nullptr); |
124 | ~Settings() override; |
125 | |
126 | void setDefaultLanguage(const QString &lang); |
127 | |
128 | QString defaultLanguage() const; |
129 | |
130 | void setPreferredLanguages(const QStringList &lang); |
131 | |
132 | QStringList preferredLanguages() const; |
133 | |
134 | void setDefaultClient(const QString &client); |
135 | |
136 | QString defaultClient() const; |
137 | |
138 | void setSkipUppercase(bool); |
139 | |
140 | bool skipUppercase() const; |
141 | |
142 | void setAutodetectLanguage(bool); |
143 | |
144 | bool autodetectLanguage() const; |
145 | |
146 | void setSkipRunTogether(bool); |
147 | |
148 | bool skipRunTogether() const; |
149 | |
150 | void setBackgroundCheckerEnabled(bool); |
151 | |
152 | bool backgroundCheckerEnabled() const; |
153 | |
154 | void setCheckerEnabledByDefault(bool); |
155 | |
156 | bool checkerEnabledByDefault() const; |
157 | |
158 | void setCurrentIgnoreList(const QStringList &ignores); |
159 | |
160 | QStringList currentIgnoreList() const; |
161 | |
162 | QStringList clients() const; |
163 | |
164 | bool modified() const; |
165 | |
166 | QAbstractListModel *dictionaryModel(); |
167 | |
168 | /*! |
169 | * |
170 | */ |
171 | Q_INVOKABLE void save(); |
172 | |
173 | static QStringList defaultIgnoreList(); |
174 | |
175 | static bool defaultSkipUppercase(); |
176 | |
177 | static bool defaultAutodetectLanguage(); |
178 | |
179 | static bool defaultBackgroundCheckerEnabled(); |
180 | |
181 | static bool defaultCheckerEnabledByDefault(); |
182 | |
183 | static bool defauktSkipRunTogether(); |
184 | |
185 | static QString defaultDefaultLanguage(); |
186 | |
187 | static QStringList defaultPreferredLanguages(); |
188 | |
189 | Q_SIGNALS: |
190 | |
191 | void skipUppercaseChanged(); |
192 | |
193 | void autodetectLanguageChanged(); |
194 | |
195 | void backgroundCheckerEnabledChanged(); |
196 | |
197 | void defaultClientChanged(); |
198 | |
199 | void defaultLanguageChanged(); |
200 | |
201 | void preferredLanguagesChanged(); |
202 | |
203 | void skipRunTogetherChanged(); |
204 | |
205 | void checkerEnabledByDefaultChanged(); |
206 | |
207 | void currentIgnoreListChanged(); |
208 | |
209 | void modifiedChanged(); |
210 | |
211 | private: |
212 | friend class Loader; |
213 | std::unique_ptr<SettingsPrivate> const d; |
214 | }; |
215 | } |
216 | |
217 | #endif // SONNET_SETTINGS_H |
218 | |