8#include "settingsimpl_p.h"
19class SettingsImplPrivate
22 Loader *loader =
nullptr;
23 bool modified =
false;
29 bool checkUppercase =
false;
30 bool skipRunTogether =
false;
31 bool backgroundCheckerEnabled =
false;
32 bool checkerEnabledByDefault =
false;
33 bool autodetectLanguage =
false;
35 int disablePercentage;
41SettingsImpl::SettingsImpl(Loader *loader)
42 : d(new SettingsImplPrivate)
47 d->checkerEnabledByDefault =
false;
51SettingsImpl::~SettingsImpl() =
default;
53bool SettingsImpl::setDefaultLanguage(
const QString &lang)
56 if (cs.
indexOf(lang) != -1 && d->defaultLanguage != lang) {
57 d->defaultLanguage = lang;
65QString SettingsImpl::defaultLanguage()
const
67 return d->defaultLanguage;
70bool SettingsImpl::setPreferredLanguages(
const QStringList &lang)
72 if (d->preferredLanguages != lang) {
74 d->preferredLanguages = lang;
83 return d->preferredLanguages;
86bool SettingsImpl::setDefaultClient(
const QString &client)
91 if (d->loader->clients().contains(client)) {
92 d->defaultClient = client;
100QString SettingsImpl::defaultClient()
const
102 return d->defaultClient;
105bool SettingsImpl::setCheckUppercase(
bool check)
107 if (d->checkUppercase != check) {
109 d->checkUppercase = check;
115bool SettingsImpl::checkUppercase()
const
117 return d->checkUppercase;
120bool SettingsImpl::setAutodetectLanguage(
bool detect)
122 if (d->autodetectLanguage != detect) {
124 d->autodetectLanguage = detect;
130bool SettingsImpl::autodetectLanguage()
const
132 return d->autodetectLanguage;
135bool SettingsImpl::setSkipRunTogether(
bool skip)
137 if (d->skipRunTogether != skip) {
139 d->skipRunTogether = skip;
145bool SettingsImpl::skipRunTogether()
const
147 return d->skipRunTogether;
150bool SettingsImpl::setCheckerEnabledByDefault(
bool check)
152 if (d->checkerEnabledByDefault != check) {
154 d->checkerEnabledByDefault = check;
160bool SettingsImpl::checkerEnabledByDefault()
const
162 return d->checkerEnabledByDefault;
165bool SettingsImpl::setBackgroundCheckerEnabled(
bool enable)
167 if (d->backgroundCheckerEnabled != enable) {
169 d->backgroundCheckerEnabled = enable;
175bool SettingsImpl::backgroundCheckerEnabled()
const
177 return d->backgroundCheckerEnabled;
180bool SettingsImpl::setCurrentIgnoreList(
const QStringList &ignores)
182 bool changed = setQuietIgnoreList(ignores);
187bool SettingsImpl::setQuietIgnoreList(
const QStringList &ignores)
189 bool changed =
false;
192 d->ignore.insert(*itr,
true);
200 return d->ignore.keys();
203bool SettingsImpl::addWordToIgnore(
const QString &word)
205 if (!d->ignore.contains(word)) {
207 d->ignore.insert(word,
true);
213bool SettingsImpl::ignore(
const QString &word)
218int SettingsImpl::disablePercentageWordError()
const
220 return d->disablePercentage;
223int SettingsImpl::disableWordErrorCount()
const
225 return d->disableWordCount;
228void SettingsImpl::save()
230 QSettings settings(QStringLiteral(
"KDE"), QStringLiteral(
"Sonnet"));
231 settings.setValue(QStringLiteral(
"defaultClient"), d->defaultClient);
232 settings.setValue(QStringLiteral(
"defaultLanguage"), d->defaultLanguage);
233 settings.setValue(QStringLiteral(
"preferredLanguages"), d->preferredLanguages);
234 settings.setValue(QStringLiteral(
"checkUppercase"), d->checkUppercase);
235 settings.setValue(QStringLiteral(
"skipRunTogether"), d->skipRunTogether);
236 settings.setValue(QStringLiteral(
"backgroundCheckerEnabled"), d->backgroundCheckerEnabled);
237 settings.setValue(QStringLiteral(
"checkerEnabledByDefault"), d->checkerEnabledByDefault);
238 settings.setValue(QStringLiteral(
"autodetectLanguage"), d->autodetectLanguage);
239 QString defaultLanguage = QStringLiteral(
"ignore_%1").
arg(d->defaultLanguage);
240 if (settings.contains(defaultLanguage) && d->ignore.isEmpty()) {
241 settings.remove(defaultLanguage);
242 }
else if (!d->ignore.isEmpty()) {
243 settings.setValue(defaultLanguage,
QStringList(d->ignore.keys()));
248void SettingsImpl::restore()
250 QSettings settings(QStringLiteral(
"KDE"), QStringLiteral(
"Sonnet"));
251 d->defaultClient = settings.value(QStringLiteral(
"defaultClient"),
QString()).toString();
252 d->defaultLanguage = settings.value(QStringLiteral(
"defaultLanguage"), Settings::defaultDefaultLanguage()).toString();
253 d->preferredLanguages = settings.value(QStringLiteral(
"preferredLanguages"), Settings::defaultPreferredLanguages()).toStringList();
256 d->checkUppercase = settings.value(QStringLiteral(
"checkUppercase"), !Settings::defaultSkipUppercase()).toBool();
257 d->skipRunTogether = settings.value(QStringLiteral(
"skipRunTogether"), Settings::defauktSkipRunTogether()).toBool();
258 d->backgroundCheckerEnabled = settings.value(QStringLiteral(
"backgroundCheckerEnabled"), Settings::defaultBackgroundCheckerEnabled()).toBool();
259 d->checkerEnabledByDefault = settings.value(QStringLiteral(
"checkerEnabledByDefault"), Settings::defaultCheckerEnabledByDefault()).toBool();
260 d->disablePercentage = settings.value(QStringLiteral(
"Sonnet_AsYouTypeDisablePercentage"), 90).toInt();
261 d->disableWordCount = settings.value(QStringLiteral(
"Sonnet_AsYouTypeDisableWordCount"), 100).toInt();
262 d->autodetectLanguage = settings.value(QStringLiteral(
"autodetectLanguage"), Settings::defaultAutodetectLanguage()).toBool();
264 const QString ignoreEntry = QStringLiteral(
"ignore_%1").
arg(d->defaultLanguage);
265 const QStringList ignores = settings.
value(ignoreEntry, Settings::defaultIgnoreList()).toStringList();
266 setQuietIgnoreList(ignores);
269bool SettingsImpl::modified()
const
274void SettingsImpl::setModified(
bool modified)
276 d->modified = modified;
T value(qsizetype i) const const
QString arg(Args &&... args) const const
bool contains(QLatin1StringView str, Qt::CaseSensitivity cs) const const
qsizetype indexOf(const QRegularExpression &re, qsizetype from) const const