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

tdespell2

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

tdespell2

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

tdespell2

Skip menu "tdespell2"
  • arts
  • dcop
  • dnssd
  • interfaces
  •   kspeech
  •     interface
  •     library
  •   tdetexteditor
  • kate
  • kded
  • kdoctools
  • kimgio
  • kjs
  • libtdemid
  • libtdescreensaver
  • tdeabc
  • tdecmshell
  • tdecore
  • tdefx
  • tdehtml
  • tdeinit
  • tdeio
  •   bookmarks
  •   httpfilter
  •   kpasswdserver
  •   kssl
  •   tdefile
  •   tdeio
  •   tdeioexec
  • tdeioslave
  •   http
  • tdemdi
  •   tdemdi
  • tdenewstuff
  • tdeparts
  • tdeprint
  • tderandr
  • tderesources
  • tdespell2
  • tdesu
  • tdeui
  • tdeunittest
  • tdeutils
  • tdewallet
Generated for tdespell2 by doxygen 1.9.1
This website is maintained by Timothy Pearson.