• Skip to content
  • Skip to link menu
  • KDE API Reference
  • kdelibs-4.14.38 API Reference
  • KDE Home
  • Contact Us
 

KDECore

  • kdecore
  • sonnet
settings.cpp
Go to the documentation of this file.
1// -*- Mode: C++; c-basic-offset: 4; indent-tabs-mode: nil; -*-
22#include "settings_p.h"
23
24#include "loader_p.h"
25
26#include <kconfig.h>
27#include <kconfiggroup.h>
28#include <kdebug.h>
29#include <kglobal.h>
30#include <klocale.h>
31
32#include <QtCore/QMap>
33#include <QtCore/QMutableStringListIterator>
34
35namespace Sonnet
36{
37class Settings::Private
38{
39public:
40 Loader* loader; //can't be a Ptr since we don't want to hold a ref on it
41 bool modified;
42
43 QString defaultLanguage;
44 QString defaultClient;
45
46 bool checkUppercase;
47 bool skipRunTogether;
48 bool backgroundCheckerEnabled;
49 bool checkerEnabledByDefault;
50
51 int disablePercentage;
52 int disableWordCount;
53
54 QMap<QString, bool> ignore;
55};
56
57Settings::Settings(Loader *loader)
58 :d(new Private)
59{
60 d->loader = loader;
61
62 d->modified = false;
63 d->checkerEnabledByDefault = false;
64}
65
66Settings::~Settings()
67{
68 delete d;
69}
70
71void Settings::setDefaultLanguage(const QString &lang)
72{
73 const QStringList cs = d->loader->languages();
74 if (cs.indexOf(lang) != -1 &&
75 d->defaultLanguage != lang) {
76 d->defaultLanguage = lang;
77 //readIgnoreList();
78 d->modified = true;
79 d->loader->changed();
80 }
81}
82
83QString Settings::defaultLanguage() const
84{
85 return d->defaultLanguage;
86}
87
88void Settings::setDefaultClient(const QString &client)
89{
90 //Different from setDefaultLanguage because
91 //the number of clients can't be even close
92 //as big as the number of languages
93 if (d->loader->clients().contains(client)) {
94 d->defaultClient = client;
95 d->modified = true;
96 d->loader->changed();
97 }
98}
99
100QString Settings::defaultClient() const
101{
102 return d->defaultClient;
103}
104
105void Settings::setCheckUppercase(bool check)
106{
107 if (d->checkUppercase != check) {
108 d->modified = true;
109 d->checkUppercase = check;
110 }
111}
112
113bool Settings::checkUppercase() const
114{
115 return d->checkUppercase;
116}
117
118void Settings::setSkipRunTogether(bool skip)
119{
120 if (d->skipRunTogether != skip) {
121 d->modified = true;
122 d->skipRunTogether = skip;
123 }
124}
125
126bool Settings::skipRunTogether() const
127{
128 return d->skipRunTogether;
129}
130
131void Settings::setCheckerEnabledByDefault(bool check)
132{
133 if (d->checkerEnabledByDefault != check) {
134 d->modified = true;
135 d->checkerEnabledByDefault = check;
136 }
137}
138
139bool Settings::checkerEnabledByDefault() const
140{
141 return d->checkerEnabledByDefault;
142}
143
144void Settings::setBackgroundCheckerEnabled(bool enable)
145{
146 if (d->backgroundCheckerEnabled != enable) {
147 d->modified = true;
148 d->backgroundCheckerEnabled = enable;
149 }
150}
151
152bool Settings::backgroundCheckerEnabled() const
153{
154 return d->backgroundCheckerEnabled;
155}
156
157void Settings::setCurrentIgnoreList(const QStringList &ignores)
158{
159 setQuietIgnoreList(ignores);
160 d->modified = true;
161}
162
163void Settings::setQuietIgnoreList(const QStringList &ignores)
164{
165 d->ignore = QMap<QString, bool>();//clear out
166 for (QStringList::const_iterator itr = ignores.begin();
167 itr != ignores.end(); ++itr) {
168 d->ignore.insert(*itr, true);
169 }
170}
171
172QStringList Settings::currentIgnoreList() const
173{
174 return d->ignore.keys();
175}
176
177void Settings::addWordToIgnore(const QString &word)
178{
179 if (!d->ignore.contains(word)) {
180 d->modified = true;
181 d->ignore.insert( word, true );
182 }
183}
184
185bool Settings::ignore( const QString& word )
186{
187 return d->ignore.contains( word );
188}
189
190void Settings::readIgnoreList(KConfig *config)
191{
192 const KConfigGroup conf(config, "Spelling");
193 const QString ignoreEntry = QString::fromLatin1( "ignore_%1" ).arg(d->defaultLanguage);
194 const QStringList ignores = conf.readEntry(ignoreEntry, QStringList());
195 setQuietIgnoreList(ignores);
196}
197
198int Settings::disablePercentageWordError() const
199{
200 return d->disablePercentage;
201}
202
203int Settings::disableWordErrorCount() const
204{
205 return d->disableWordCount;
206}
207
208void Settings::save(KConfig *config)
209{
210 KConfigGroup conf(config, "Spelling");
211 conf.writeEntry("defaultClient", d->defaultClient);
212 conf.writeEntry("defaultLanguage", d->defaultLanguage);
213 conf.writeEntry("checkUppercase", d->checkUppercase);
214 conf.writeEntry("skipRunTogether", d->skipRunTogether);
215 conf.writeEntry("backgroundCheckerEnabled", d->backgroundCheckerEnabled);
216 conf.writeEntry("checkerEnabledByDefault", d->checkerEnabledByDefault);
217 QString defaultLanguage = QString::fromLatin1( "ignore_%1" ).arg(d->defaultLanguage);
218 if(conf.hasKey(defaultLanguage) && d->ignore.isEmpty())
219 conf.deleteEntry(defaultLanguage);
220 else if(!d->ignore.isEmpty())
221 conf.writeEntry(defaultLanguage, d->ignore.keys());
222
223 conf.sync();
224}
225
226void Settings::restore(KConfig *config)
227{
228 KConfigGroup conf(config, "Spelling");
229 d->defaultClient = conf.readEntry("defaultClient",
230 QString());
231 d->defaultLanguage = conf.readEntry(
232 "defaultLanguage", KGlobal::locale()->language());
233
234 //same defaults are in the default filter (filter.cpp)
235 d->checkUppercase = conf.readEntry(
236 "checkUppercase", true);
237
238 d->skipRunTogether = conf.readEntry(
239 "skipRunTogether", true);
240
241 d->backgroundCheckerEnabled = conf.readEntry(
242 "backgroundCheckerEnabled", true);
243
244 d->checkerEnabledByDefault = conf.readEntry(
245 "checkerEnabledByDefault", false);
246
247 d->disablePercentage = conf.readEntry("Sonnet_AsYouTypeDisablePercentage", 42);
248 d->disableWordCount = conf.readEntry("Sonnet_AsYouTypeDisableWordCount", 100);
249
250 readIgnoreList(config);
251}
252
253
254bool Settings::modified() const
255{
256 return d->modified;
257}
258
259void Settings::setModified(bool modified)
260{
261 d->modified = modified;
262}
263
264}
265
KConfigGroup
A class for one specific group in a KConfig object.
Definition: kconfiggroup.h:54
KConfigGroup::readEntry
T readEntry(const QString &key, const T &aDefault) const
Reads the value of an entry specified by pKey in the current group.
Definition: kconfiggroup.h:248
KConfigGroup::hasKey
bool hasKey(const QString &key) const
Checks whether the key has an entry in this group.
Definition: kconfiggroup.cpp:1155
KConfigGroup::writeEntry
void writeEntry(const QString &key, const QVariant &value, WriteConfigFlags pFlags=Normal)
Writes a value to the configuration object.
Definition: kconfiggroup.cpp:1037
KConfigGroup::sync
void sync()
Definition: kconfiggroup.cpp:595
KConfigGroup::deleteEntry
void deleteEntry(const QString &pKey, WriteConfigFlags pFlags=Normal)
Deletes the entry specified by pKey in the current group.
Definition: kconfiggroup.cpp:1112
KConfig
The central class of the KDE configuration data system.
Definition: kconfig.h:71
QMap
QStringList
QString
Sonnet::Settings::Loader
friend class Loader
Definition: settings_p.h:79
kconfig.h
kconfiggroup.h
kdebug.h
kglobal.h
klocale.h
cs
static Qt::CaseSensitivity cs
Definition: kmountpoint.cpp:37
loader_p.h
KGlobal::locale
KLocale * locale()
Returns the global locale object.
Definition: kglobal.cpp:170
Sonnet
The sonnet namespace.
Definition: backgroundchecker.h:34
settings_p.h
This file is part of the KDE documentation.
Documentation copyright © 1996-2023 The KDE developers.
Generated on Mon Feb 20 2023 00:00:00 by doxygen 1.9.6 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

KDECore

Skip menu "KDECore"
  • Main Page
  • Namespace List
  • Namespace Members
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • File Members
  • Modules
  • Related Pages

kdelibs-4.14.38 API Reference

Skip menu "kdelibs-4.14.38 API Reference"
  • DNSSD
  • Interfaces
  •   KHexEdit
  •   KMediaPlayer
  •   KSpeech
  •   KTextEditor
  • kconf_update
  • KDE3Support
  •   KUnitTest
  • KDECore
  • KDED
  • KDEsu
  • KDEUI
  • KDEWebKit
  • KDocTools
  • KFile
  • KHTML
  • KImgIO
  • KInit
  • kio
  • KIOSlave
  • KJS
  •   KJS-API
  •   WTF
  • kjsembed
  • KNewStuff
  • KParts
  • KPty
  • Kross
  • KUnitConversion
  • KUtils
  • Nepomuk
  • Plasma
  • Solid
  • Sonnet
  • ThreadWeaver
Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal