• Skip to content
  • Skip to link menu
Trinity API Reference
  • Trinity API Reference
  • kspell2
 

kspell2

  • kspell2
settings.cpp
1 // -*- Mode: C++; c-basic-offset: 4; indent-tabs-mode: nil; -*-
2 /*
3  * settings.cpp
4  *
5  * Copyright (C) 2003 Zack Rusin <zack@kde.org>
6  *
7  * This library is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU Lesser General Public
9  * License as published by the Free Software Foundation; either
10  * version 2.1 of the License, or (at your option) any later version.
11  *
12  * This library is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15  * Lesser General Public License for more details.
16  *
17  * You should have received a copy of the GNU Lesser General Public
18  * License along with this library; if not, write to the Free Software
19  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
20  * 02110-1301 USA
21  */
22 #include "settings.h"
23 
24 #include "broker.h"
25 
26 #include <kglobal.h>
27 #include <klocale.h>
28 #include <kconfig.h>
29 #include <kdebug.h>
30 
31 #include <tqmap.h>
32 #include <tqstringlist.h>
33 
34 namespace KSpell2
35 {
36 class Settings::Private
37 {
38 public:
39  Broker* broker; //can't be a Ptr since we don't want to hold a ref on it
40  KSharedConfig::Ptr config;
41  bool modified;
42 
43  TQString defaultLanguage;
44  TQString defaultClient;
45 
46  bool checkUppercase;
47  bool skipRunTogether;
48  bool backgroundCheckerEnabled;
49 
50  TQMap<TQString, bool> ignore;
51 };
52 
53 Settings::Settings( Broker *broker, KSharedConfig *config )
54 {
55  d = new Private;
56  d->broker = broker;
57 
58  Q_ASSERT( config );
59  d->config = config;
60 
61  d->modified = false;
62  loadConfig();
63 }
64 
65 Settings::~Settings()
66 {
67  delete d; d = 0;
68 }
69 
70 KSharedConfig *Settings::sharedConfig() const
71 {
72  return d->config;
73 }
74 
75 void Settings::setDefaultLanguage( const TQString& lang )
76 {
77  TQStringList cs = d->broker->languages();
78  if ( cs.find( lang ) != cs.end() &&
79  d->defaultLanguage != lang ) {
80  d->defaultLanguage = lang;
81  readIgnoreList();
82  d->modified = true;
83  d->broker->changed();
84  }
85 }
86 
87 TQString Settings::defaultLanguage() const
88 {
89  return d->defaultLanguage;
90 }
91 
92 void Settings::setDefaultClient( const TQString& client )
93 {
94  //Different from setDefaultLanguage because
95  //the number of clients can't be even close
96  //as big as the number of languages
97  if ( d->broker->clients().contains( client ) ) {
98  d->defaultClient = client;
99  d->modified = true;
100  d->broker->changed();
101  }
102 }
103 
104 TQString Settings::defaultClient() const
105 {
106  return d->defaultClient;
107 }
108 
109 void Settings::setCheckUppercase( bool check )
110 {
111  if ( d->checkUppercase != check ) {
112  d->modified = true;
113  d->checkUppercase = check;
114  }
115 }
116 
117 bool Settings::checkUppercase() const
118 {
119  return d->checkUppercase;
120 }
121 
122 void Settings::setSkipRunTogether( bool skip )
123 {
124  if ( d->skipRunTogether != skip ) {
125  d->modified = true;
126  d->skipRunTogether = skip;
127  }
128 }
129 
130 bool Settings::skipRunTogether() const
131 {
132  return d->skipRunTogether;
133 }
134 
135 void Settings::setBackgroundCheckerEnabled( bool enable )
136 {
137  if ( d->backgroundCheckerEnabled != enable ) {
138  d->modified = true;
139  d->backgroundCheckerEnabled = enable;
140  }
141 }
142 
143 bool Settings::backgroundCheckerEnabled() const
144 {
145  return d->backgroundCheckerEnabled;
146 }
147 
148 void Settings::setCurrentIgnoreList( const TQStringList& ignores )
149 {
150  setQuietIgnoreList( ignores );
151  d->modified = true;
152 }
153 
154 void Settings::setQuietIgnoreList( const TQStringList& ignores )
155 {
156  d->ignore = TQMap<TQString, bool>();//clear out
157  for ( TQStringList::const_iterator itr = ignores.begin();
158  itr != ignores.end(); ++itr ) {
159  d->ignore.insert( *itr, true );
160  }
161 }
162 
163 TQStringList Settings::currentIgnoreList() const
164 {
165  return d->ignore.keys();
166 }
167 
168 void Settings::addWordToIgnore( const TQString& word )
169 {
170  if ( !d->ignore.contains( word ) ) {
171  d->modified = true;
172  d->ignore.insert( word, true );
173  }
174 }
175 
176 bool Settings::ignore( const TQString& word )
177 {
178  return d->ignore.contains( word );
179 }
180 
181 void Settings::readIgnoreList()
182 {
183  KConfigGroup conf( d->config, "Spelling" );
184  TQString ignoreEntry = TQString( "ignore_%1" ).arg( d->defaultLanguage );
185  TQStringList ignores = conf.readListEntry( ignoreEntry );
186  setQuietIgnoreList( ignores );
187 }
188 
189 void Settings::save()
190 {
191  if ( d->modified ) {
192  KConfigGroup conf( d->config, "Spelling" );
193  conf.writeEntry( "defaultClient", d->defaultClient );
194  conf.writeEntry( "defaultLanguage", d->defaultLanguage );
195  conf.writeEntry( "checkUppercase", d->checkUppercase );
196  conf.writeEntry( "skipRunTogether", d->skipRunTogether );
197  conf.writeEntry( "backgroundCheckerEnabled", d->backgroundCheckerEnabled );
198  conf.writeEntry( TQString( "ignore_%1" ).arg( d->defaultLanguage ),
199  d->ignore.keys() );
200  conf.sync();
201  }
202 }
203 
204 void Settings::loadConfig()
205 {
206  KConfigGroup conf( d->config, "Spelling" );
207  d->defaultClient = conf.readEntry( "defaultClient",
208  TQString::null );
209  d->defaultLanguage = conf.readEntry(
210  "defaultLanguage", KGlobal::locale()->language() );
211 
212  //same defaults are in the default filter (filter.cpp)
213  d->checkUppercase = conf.readBoolEntry(
214  "checkUppercase", true );
215 
216  d->skipRunTogether = conf.readBoolEntry(
217  "skipRunTogether", true );
218 
219  d->backgroundCheckerEnabled = conf.readBoolEntry(
220  "backgroundCheckerEnabled", true );
221 
222  readIgnoreList();
223 }
224 
225 
226 }

kspell2

Skip menu "kspell2"
  • Main Page
  • Namespace List
  • Class Hierarchy
  • Alphabetical List
  • Class List
  • File List
  • Class Members

kspell2

Skip menu "kspell2"
  • arts
  • dcop
  • dnssd
  • interfaces
  •     interface
  •     library
  •   kspeech
  •   ktexteditor
  • kabc
  • kate
  • kcmshell
  • kdecore
  • kded
  • kdefx
  • kdeprint
  • kdesu
  • kdeui
  • kdoctools
  • khtml
  • kimgio
  • kinit
  • kio
  •   bookmarks
  •   httpfilter
  •   kfile
  •   kio
  •   kioexec
  •   kpasswdserver
  •   kssl
  • kioslave
  •   http
  • kjs
  • kmdi
  •   kmdi
  • knewstuff
  • kparts
  • krandr
  • kresources
  • kspell2
  • kunittest
  • kutils
  • kwallet
  • libkmid
  • libkscreensaver
Generated for kspell2 by doxygen 1.8.6
This website is maintained by Timothy Pearson.
KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. |