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

KDECore

settings.cpp

Go to the documentation of this file.
00001 // -*- Mode: C++; c-basic-offset: 4; indent-tabs-mode: nil; -*-
00022 #include "settings_p.h"
00023 
00024 #include "loader_p.h"
00025 
00026 #include <kconfig.h>
00027 #include <kconfiggroup.h>
00028 #include <kdebug.h>
00029 #include <kglobal.h>
00030 #include <klocale.h>
00031 
00032 #include <QtCore/QMap>
00033 #include <QtCore/QMutableStringListIterator>
00034 
00035 namespace Sonnet
00036 {
00037 class Settings::Private
00038 {
00039 public:
00040     Loader*  loader; //can't be a Ptr since we don't want to hold a ref on it
00041     bool     modified;
00042 
00043     QString defaultLanguage;
00044     QString defaultClient;
00045 
00046     bool checkUppercase;
00047     bool skipRunTogether;
00048     bool backgroundCheckerEnabled;
00049     bool checkerEnabledByDefault;
00050 
00051     int disablePercentage;
00052     int disableWordCount;
00053 
00054     QMap<QString, bool> ignore;
00055 };
00056 
00057 Settings::Settings(Loader *loader)
00058     :d(new Private)
00059 {
00060     d->loader = loader;
00061 
00062     d->modified = false;
00063     d->checkerEnabledByDefault = false;
00064 }
00065 
00066 Settings::~Settings()
00067 {
00068     delete d;
00069 }
00070 
00071 void Settings::setDefaultLanguage(const QString &lang)
00072 {
00073     const QStringList cs = d->loader->languages();
00074     if (cs.indexOf(lang) != -1 &&
00075         d->defaultLanguage != lang) {
00076         d->defaultLanguage = lang;
00077         //readIgnoreList();
00078         d->modified = true;
00079         d->loader->changed();
00080     }
00081 }
00082 
00083 QString Settings::defaultLanguage() const
00084 {
00085     return d->defaultLanguage;
00086 }
00087 
00088 void Settings::setDefaultClient(const QString &client)
00089 {
00090     //Different from setDefaultLanguage because
00091     //the number of clients can't be even close
00092     //as big as the number of languages
00093     if (d->loader->clients().contains(client)) {
00094         d->defaultClient = client;
00095         d->modified = true;
00096         d->loader->changed();
00097     }
00098 }
00099 
00100 QString Settings::defaultClient() const
00101 {
00102     return d->defaultClient;
00103 }
00104 
00105 void Settings::setCheckUppercase(bool check)
00106 {
00107     if (d->checkUppercase != check) {
00108         d->modified = true;
00109         d->checkUppercase = check;
00110     }
00111 }
00112 
00113 bool Settings::checkUppercase() const
00114 {
00115     return d->checkUppercase;
00116 }
00117 
00118 void Settings::setSkipRunTogether(bool skip)
00119 {
00120     if (d->skipRunTogether != skip) {
00121         d->modified = true;
00122         d->skipRunTogether = skip;
00123     }
00124 }
00125 
00126 bool Settings::skipRunTogether() const
00127 {
00128     return d->skipRunTogether;
00129 }
00130 
00131 void Settings::setCheckerEnabledByDefault(bool check)
00132 {
00133     if (d->checkerEnabledByDefault != check) {
00134         d->modified = true;
00135         d->checkerEnabledByDefault = check;
00136     }
00137 }
00138 
00139 bool Settings::checkerEnabledByDefault() const
00140 {
00141     return d->checkerEnabledByDefault;
00142 }
00143 
00144 void Settings::setBackgroundCheckerEnabled(bool enable)
00145 {
00146     if (d->backgroundCheckerEnabled != enable) {
00147         d->modified = true;
00148         d->backgroundCheckerEnabled = enable;
00149     }
00150 }
00151 
00152 bool Settings::backgroundCheckerEnabled() const
00153 {
00154     return d->backgroundCheckerEnabled;
00155 }
00156 
00157 void Settings::setCurrentIgnoreList(const QStringList &ignores)
00158 {
00159     setQuietIgnoreList(ignores);
00160     d->modified = true;
00161 }
00162 
00163 void Settings::setQuietIgnoreList(const QStringList &ignores)
00164 {
00165     d->ignore = QMap<QString, bool>();//clear out
00166     for (QStringList::const_iterator itr = ignores.begin();
00167          itr != ignores.end(); ++itr) {
00168         d->ignore.insert(*itr, true);
00169     }
00170 }
00171 
00172 QStringList Settings::currentIgnoreList() const
00173 {
00174     return d->ignore.keys();
00175 }
00176 
00177 void Settings::addWordToIgnore(const QString &word)
00178 {
00179     if (!d->ignore.contains(word)) {
00180         d->modified = true;
00181         d->ignore.insert( word, true );
00182     }
00183 }
00184 
00185 bool Settings::ignore( const QString& word )
00186 {
00187     return d->ignore.contains( word );
00188 }
00189 
00190 void Settings::readIgnoreList(KConfig *config)
00191 {
00192     const KConfigGroup conf(config, "Spelling");
00193     const QString ignoreEntry = QString::fromLatin1( "ignore_%1" ).arg(d->defaultLanguage);
00194     const QStringList ignores = conf.readEntry(ignoreEntry, QStringList());
00195     setQuietIgnoreList(ignores);
00196 }
00197 
00198 int Settings::disablePercentageWordError() const
00199 {
00200     return d->disablePercentage;
00201 }
00202 
00203 int Settings::disableWordErrorCount() const
00204 {
00205     return d->disableWordCount;
00206 }
00207 
00208 void Settings::save(KConfig *config)
00209 {
00210     KConfigGroup conf(config, "Spelling");
00211     conf.writeEntry("defaultClient", d->defaultClient);
00212     conf.writeEntry("defaultLanguage", d->defaultLanguage);
00213     conf.writeEntry("checkUppercase", d->checkUppercase);
00214     conf.writeEntry("skipRunTogether", d->skipRunTogether);
00215     conf.writeEntry("backgroundCheckerEnabled", d->backgroundCheckerEnabled);
00216     conf.writeEntry("checkerEnabledByDefault", d->checkerEnabledByDefault);
00217     QString defaultLanguage = QString::fromLatin1( "ignore_%1" ).arg(d->defaultLanguage);
00218     if(conf.hasKey(defaultLanguage) && d->ignore.isEmpty())
00219       conf.deleteEntry(defaultLanguage);
00220     else if(!d->ignore.isEmpty())
00221         conf.writeEntry(defaultLanguage, d->ignore.keys());
00222 
00223     conf.sync();
00224 }
00225 
00226 void Settings::restore(KConfig *config)
00227 {
00228     KConfigGroup conf(config, "Spelling");
00229     d->defaultClient = conf.readEntry("defaultClient",
00230                                       QString());
00231     d->defaultLanguage = conf.readEntry(
00232         "defaultLanguage", KGlobal::locale()->language());
00233 
00234     //same defaults are in the default filter (filter.cpp)
00235     d->checkUppercase = conf.readEntry(
00236         "checkUppercase", true);
00237 
00238     d->skipRunTogether = conf.readEntry(
00239         "skipRunTogether", true);
00240 
00241     d->backgroundCheckerEnabled = conf.readEntry(
00242         "backgroundCheckerEnabled", true);
00243 
00244     d->checkerEnabledByDefault = conf.readEntry(
00245         "checkerEnabledByDefault", false);
00246 
00247     d->disablePercentage = conf.readEntry("Sonnet_AsYouTypeDisablePercentage", 42);
00248     d->disableWordCount = conf.readEntry("Sonnet_AsYouTypeDisableWordCount", 100);
00249 
00250     readIgnoreList(config);
00251 }
00252 
00253 
00254 bool Settings::modified() const
00255 {
00256     return d->modified;
00257 }
00258 
00259 void Settings::setModified(bool modified)
00260 {
00261     d->modified = modified;
00262 }
00263 
00264 }
00265 

KDECore

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

kdelibs

Skip menu "kdelibs"
  • DNSSD
  • Interfaces
  •   KHexEdit
  •   KMediaPlayer
  •   KSpeech
  •   KTextEditor
  • Kate
  • 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
Generated for kdelibs by doxygen 1.7.3
This website is maintained by Adriaan de Groot and Allen Winter.
KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal