6#include "settingsimpl_p.h"
27 ~DictionaryModel()
override
40 void setDefaultLanguage(
const QString &language)
42 m_defaultDictionary = language;
53 const int row = idx.
row();
54 const auto language = m_availableDictionaries.
keys().at(row);
55 const auto inPreferredDictionaries = m_preferredDictionaries.
contains(m_availableDictionaries.
keys().at(row));
57 if (inPreferredDictionaries) {
58 m_preferredDictionaries.
remove(language);
60 m_preferredDictionaries[language] = m_availableDictionaries.
values().
at(row);
76 return m_availableDictionaries.
keys().at(row);
77 case Settings::LanguageCodeRole:
78 return m_availableDictionaries.
values().
at(row);
80 return m_preferredDictionaries.
contains(m_availableDictionaries.
keys().at(row));
81 case Settings::DefaultRole:
82 return data(
index, Settings::LanguageCodeRole) == m_defaultDictionary;
90 return m_availableDictionaries.
count();
98 {Settings::PreferredRole, QByteArrayLiteral(
"isPreferred")},
99 {Settings::LanguageCodeRole, QByteArrayLiteral(
"languageCode")},
100 {Settings::DefaultRole, QByteArrayLiteral(
"isDefault")},
113 Loader *loader =
nullptr;
114 DictionaryModel *dictionaryModel =
nullptr;
117Settings::Settings(
QObject *parent)
119 , d(new SettingsPrivate)
121 d->loader = Loader::openLoader();
124Settings::~Settings() =
default;
126void Settings::setDefaultLanguage(
const QString &lang)
128 if (defaultLanguage() == lang) {
131 d->loader->settings()->setDefaultLanguage(lang);
132 Q_EMIT defaultLanguageChanged();
133 Q_EMIT modifiedChanged();
135 if (d->dictionaryModel) {
136 d->dictionaryModel->setDefaultLanguage(lang);
140QString Settings::defaultLanguage()
const
142 return d->loader->settings()->defaultLanguage();
145void Settings::setPreferredLanguages(
const QStringList &lang)
147 if (!d->loader->settings()->setPreferredLanguages(lang)) {
150 Q_EMIT modifiedChanged();
151 Q_EMIT preferredLanguagesChanged();
156 return d->loader->settings()->preferredLanguages();
159void Settings::setDefaultClient(
const QString &client)
161 if (!d->loader->settings()->setDefaultClient(client)) {
164 Q_EMIT defaultClientChanged();
165 Q_EMIT modifiedChanged();
168QString Settings::defaultClient()
const
170 return d->loader->settings()->defaultClient();
173void Settings::setSkipUppercase(
bool skip)
175 if (!d->loader->settings()->setCheckUppercase(!skip)) {
178 Q_EMIT skipUppercaseChanged();
179 Q_EMIT modifiedChanged();
182bool Settings::skipUppercase()
const
184 return !d->loader->settings()->checkUppercase();
187void Settings::setAutodetectLanguage(
bool detect)
189 if (!d->loader->settings()->setAutodetectLanguage(detect)) {
192 Q_EMIT autodetectLanguageChanged();
193 Q_EMIT modifiedChanged();
196bool Settings::autodetectLanguage()
const
198 return d->loader->settings()->autodetectLanguage();
201void Settings::setSkipRunTogether(
bool skip)
203 if (skipRunTogether() == skip) {
206 d->loader->settings()->setSkipRunTogether(skip);
207 Q_EMIT skipRunTogetherChanged();
208 Q_EMIT modifiedChanged();
211bool Settings::skipRunTogether()
const
213 return d->loader->settings()->skipRunTogether();
216void Settings::setCheckerEnabledByDefault(
bool check)
218 if (checkerEnabledByDefault() == check) {
221 d->loader->settings()->setCheckerEnabledByDefault(check);
222 Q_EMIT checkerEnabledByDefaultChanged();
223 Q_EMIT modifiedChanged();
226bool Settings::checkerEnabledByDefault()
const
228 return d->loader->settings()->checkerEnabledByDefault();
231void Settings::setBackgroundCheckerEnabled(
bool enable)
233 if (backgroundCheckerEnabled() == enable) {
236 d->loader->settings()->setBackgroundCheckerEnabled(enable);
237 Q_EMIT backgroundCheckerEnabledChanged();
238 Q_EMIT modifiedChanged();
241bool Settings::backgroundCheckerEnabled()
const
243 return d->loader->settings()->backgroundCheckerEnabled();
246void Settings::setCurrentIgnoreList(
const QStringList &ignores)
248 if (currentIgnoreList() == ignores) {
251 d->loader->settings()->setCurrentIgnoreList(ignores);
252 Q_EMIT currentIgnoreListChanged();
253 Q_EMIT modifiedChanged();
258 return d->loader->settings()->currentIgnoreList();
263 return d->loader->clients();
268 d->loader->settings()->save();
269 Q_EMIT modifiedChanged();
272bool Settings::modified()
const
274 return d->loader->settings()->modified();
282 l.
append(QStringLiteral(
"KMail"));
283 l.
append(QStringLiteral(
"KOrganizer"));
284 l.
append(QStringLiteral(
"KAddressBook"));
285 l.
append(QStringLiteral(
"KHTML"));
286 l.
append(QStringLiteral(
"KIO"));
287 l.
append(QStringLiteral(
"KJS"));
288 l.
append(QStringLiteral(
"Konqueror"));
289 l.
append(QStringLiteral(
"Sonnet"));
290 l.
append(QStringLiteral(
"Kontact"));
291 l.
append(QStringLiteral(
"Qt"));
292 l.
append(QStringLiteral(
"Okular"));
293 l.
append(QStringLiteral(
"KMix"));
294 l.
append(QStringLiteral(
"Amarok"));
295 l.
append(QStringLiteral(
"KDevelop"));
296 l.
append(QStringLiteral(
"Nepomuk"));
300bool Settings::defaultSkipUppercase()
305bool Settings::defaultAutodetectLanguage()
310bool Settings::defaultBackgroundCheckerEnabled()
315bool Settings::defaultCheckerEnabledByDefault()
320bool Settings::defauktSkipRunTogether()
325QString Settings::defaultDefaultLanguage()
338 if (d->dictionaryModel) {
339 return d->dictionaryModel;
342 d->dictionaryModel =
new DictionaryModel(
this);
343 d->dictionaryModel->setDefaultLanguage(defaultLanguage());
344 return d->dictionaryModel;
348#include "moc_settings.cpp"
349#include "settings.moc"
QMap< QString, QString > preferredDictionaries() const
QMap< QString, QString > availableDictionaries() const
bool checkIndex(const QModelIndex &index, CheckIndexOptions options) const const
void dataChanged(const QModelIndex &topLeft, const QModelIndex &bottomRight, const QList< int > &roles)
virtual QModelIndex index(int row, int column, const QModelIndex &parent) const const override
void append(QList< T > &&value)
const_reference at(qsizetype i) const const
QString name() const const
bool contains(const Key &key) const const
size_type count() const const
QList< Key > keys() const const
size_type remove(const Key &key)
QList< T > values() const const
QObject * parent() const const
T qobject_cast(QObject *object)