author | zautrix <zautrix> | 2004-07-08 09:52:31 (UTC) |
---|---|---|
committer | zautrix <zautrix> | 2004-07-08 09:52:31 (UTC) |
commit | 40cf8102d2f38b5e952b889ffbd19cb1d428fc9b (patch) (unidiff) | |
tree | d6b0a7855560b68910e1e63a3dc114316b653433 /microkde | |
parent | e8628e6e3e98f2276fb69bbc545866cc9a022228 (diff) | |
download | kdepimpi-40cf8102d2f38b5e952b889ffbd19cb1d428fc9b.zip kdepimpi-40cf8102d2f38b5e952b889ffbd19cb1d428fc9b.tar.gz kdepimpi-40cf8102d2f38b5e952b889ffbd19cb1d428fc9b.tar.bz2 |
Fix in kconfig::readfont
-rw-r--r-- | microkde/kconfig.cpp | 2 |
1 files changed, 1 insertions, 1 deletions
diff --git a/microkde/kconfig.cpp b/microkde/kconfig.cpp index 71db891..737b3f2 100644 --- a/microkde/kconfig.cpp +++ b/microkde/kconfig.cpp | |||
@@ -1,509 +1,509 @@ | |||
1 | #include <qfile.h> | 1 | #include <qfile.h> |
2 | #include <qtextstream.h> | 2 | #include <qtextstream.h> |
3 | #include <qwidget.h> | 3 | #include <qwidget.h> |
4 | 4 | ||
5 | #include "kdebug.h" | 5 | #include "kdebug.h" |
6 | 6 | ||
7 | #include "kurl.h" | 7 | #include "kurl.h" |
8 | #include "kstandarddirs.h" | 8 | #include "kstandarddirs.h" |
9 | #include "kconfig.h" | 9 | #include "kconfig.h" |
10 | 10 | ||
11 | QString KConfig::mGroup = ""; | 11 | QString KConfig::mGroup = ""; |
12 | //QString KConfig::mGroup = "General"; | 12 | //QString KConfig::mGroup = "General"; |
13 | 13 | ||
14 | KConfig::KConfig( const QString &fileName ) | 14 | KConfig::KConfig( const QString &fileName ) |
15 | : mFileName( fileName ), mDirty( false ) | 15 | : mFileName( fileName ), mDirty( false ) |
16 | { | 16 | { |
17 | kdDebug() << "KConfig::KConfig(): '" << fileName << "'" << endl; | 17 | kdDebug() << "KConfig::KConfig(): '" << fileName << "'" << endl; |
18 | 18 | ||
19 | load(); | 19 | load(); |
20 | 20 | ||
21 | } | 21 | } |
22 | 22 | ||
23 | 23 | ||
24 | KConfig::~KConfig() | 24 | KConfig::~KConfig() |
25 | { | 25 | { |
26 | sync(); | 26 | sync(); |
27 | } | 27 | } |
28 | 28 | ||
29 | void KConfig::setGroup( const QString &group ) | 29 | void KConfig::setGroup( const QString &group ) |
30 | { | 30 | { |
31 | kdDebug() << "KConfig::setGroup(): '" << group << "'" << endl; | 31 | kdDebug() << "KConfig::setGroup(): '" << group << "'" << endl; |
32 | 32 | ||
33 | mGroup = group; | 33 | mGroup = group; |
34 | 34 | ||
35 | if ( mGroup.right( 1 ) != "/" ) mGroup += "/"; | 35 | if ( mGroup.right( 1 ) != "/" ) mGroup += "/"; |
36 | } | 36 | } |
37 | 37 | ||
38 | //US | 38 | //US |
39 | QString KConfig::group() const { | 39 | QString KConfig::group() const { |
40 | return mGroup; | 40 | return mGroup; |
41 | } | 41 | } |
42 | 42 | ||
43 | //US added method | 43 | //US added method |
44 | QValueList<int> KConfig::readIntListEntry( const QString & key) | 44 | QValueList<int> KConfig::readIntListEntry( const QString & key) |
45 | { | 45 | { |
46 | // qDebug("KConfig::readIntListEntry key=%s:", key.latin1()); | 46 | // qDebug("KConfig::readIntListEntry key=%s:", key.latin1()); |
47 | 47 | ||
48 | QValueList<int> result; | 48 | QValueList<int> result; |
49 | 49 | ||
50 | QMap<QString,QString>::ConstIterator mit = mStringMap.find( mGroup + key ); | 50 | QMap<QString,QString>::ConstIterator mit = mStringMap.find( mGroup + key ); |
51 | 51 | ||
52 | if ( mit == mStringMap.end() ) { | 52 | if ( mit == mStringMap.end() ) { |
53 | return result; | 53 | return result; |
54 | } | 54 | } |
55 | 55 | ||
56 | QStringList valuesAsStrings = QStringList::split(":", *mit ); | 56 | QStringList valuesAsStrings = QStringList::split(":", *mit ); |
57 | bool ok = false; | 57 | bool ok = false; |
58 | bool ok2 = true; | 58 | bool ok2 = true; |
59 | int val; | 59 | int val; |
60 | 60 | ||
61 | for ( QStringList::Iterator sit = valuesAsStrings.begin(); sit != valuesAsStrings.end(); ++sit ) { | 61 | for ( QStringList::Iterator sit = valuesAsStrings.begin(); sit != valuesAsStrings.end(); ++sit ) { |
62 | val = (*sit).toInt(&ok); | 62 | val = (*sit).toInt(&ok); |
63 | result << val; | 63 | result << val; |
64 | if (ok == false) { | 64 | if (ok == false) { |
65 | qDebug("KConfig::readIntListEntry str=%s , int=%n:", (*sit).latin1(), &val); | 65 | qDebug("KConfig::readIntListEntry str=%s , int=%n:", (*sit).latin1(), &val); |
66 | ok2 = false; | 66 | ok2 = false; |
67 | } | 67 | } |
68 | } | 68 | } |
69 | 69 | ||
70 | if (ok2 == false) | 70 | if (ok2 == false) |
71 | { | 71 | { |
72 | kdDebug() << "KConfig::readIntListEntry: error while reading one of the intvalues." << endl; | 72 | kdDebug() << "KConfig::readIntListEntry: error while reading one of the intvalues." << endl; |
73 | qDebug("KConfig::readIntListEntry: error while reading one of the intvalues."); | 73 | qDebug("KConfig::readIntListEntry: error while reading one of the intvalues."); |
74 | } | 74 | } |
75 | 75 | ||
76 | return result; | 76 | return result; |
77 | } | 77 | } |
78 | 78 | ||
79 | int KConfig::readNumEntry( const QString & key, int def ) | 79 | int KConfig::readNumEntry( const QString & key, int def ) |
80 | { | 80 | { |
81 | QString res = readEntry(key, QString::number(def ) ); | 81 | QString res = readEntry(key, QString::number(def ) ); |
82 | bool ok = false; | 82 | bool ok = false; |
83 | int result = res.toInt(&ok); | 83 | int result = res.toInt(&ok); |
84 | if ( ok ) | 84 | if ( ok ) |
85 | return result; | 85 | return result; |
86 | return def; | 86 | return def; |
87 | } | 87 | } |
88 | 88 | ||
89 | QString KConfig::readEntry( const QString &key, const QString &def ) | 89 | QString KConfig::readEntry( const QString &key, const QString &def ) |
90 | { | 90 | { |
91 | QMap<QString,QString>::ConstIterator it = mStringMap.find( mGroup + key ); | 91 | QMap<QString,QString>::ConstIterator it = mStringMap.find( mGroup + key ); |
92 | 92 | ||
93 | if ( it == mStringMap.end() ) { | 93 | if ( it == mStringMap.end() ) { |
94 | return def; | 94 | return def; |
95 | } | 95 | } |
96 | 96 | ||
97 | return *it; | 97 | return *it; |
98 | } | 98 | } |
99 | 99 | ||
100 | QStringList KConfig::readListEntry( const QString &key ) | 100 | QStringList KConfig::readListEntry( const QString &key ) |
101 | { | 101 | { |
102 | QMap<QString,QString>::ConstIterator it = mStringMap.find( mGroup + key ); | 102 | QMap<QString,QString>::ConstIterator it = mStringMap.find( mGroup + key ); |
103 | 103 | ||
104 | if ( it == mStringMap.end() ) { | 104 | if ( it == mStringMap.end() ) { |
105 | return QStringList(); | 105 | return QStringList(); |
106 | } | 106 | } |
107 | return QStringList::split(":", *it ); | 107 | return QStringList::split(":", *it ); |
108 | 108 | ||
109 | } | 109 | } |
110 | 110 | ||
111 | bool KConfig::readBoolEntry( const QString &key, bool def ) | 111 | bool KConfig::readBoolEntry( const QString &key, bool def ) |
112 | { | 112 | { |
113 | QMap<QString,bool>::ConstIterator it = mBoolMap.find( mGroup + key ); | 113 | QMap<QString,bool>::ConstIterator it = mBoolMap.find( mGroup + key ); |
114 | 114 | ||
115 | if ( it == mBoolMap.end() ) { | 115 | if ( it == mBoolMap.end() ) { |
116 | return def; | 116 | return def; |
117 | } | 117 | } |
118 | 118 | ||
119 | return *it; | 119 | return *it; |
120 | } | 120 | } |
121 | 121 | ||
122 | QColor KConfig::readColorEntry( const QString & e, QColor *def ) | 122 | QColor KConfig::readColorEntry( const QString & e, QColor *def ) |
123 | { | 123 | { |
124 | 124 | ||
125 | QStringList l; | 125 | QStringList l; |
126 | l = readListEntry( e ); | 126 | l = readListEntry( e ); |
127 | if (l.count() != 3 ) { | 127 | if (l.count() != 3 ) { |
128 | if ( def ) | 128 | if ( def ) |
129 | return *def; | 129 | return *def; |
130 | else | 130 | else |
131 | return QColor(); | 131 | return QColor(); |
132 | } | 132 | } |
133 | QColor c ( l[0].toInt(), l[1].toInt(), l[2].toInt() ); | 133 | QColor c ( l[0].toInt(), l[1].toInt(), l[2].toInt() ); |
134 | return c; | 134 | return c; |
135 | } | 135 | } |
136 | 136 | ||
137 | QFont KConfig::readFontEntry( const QString & e, QFont *def ) | 137 | QFont KConfig::readFontEntry( const QString & e, QFont *def ) |
138 | { | 138 | { |
139 | QStringList font = readListEntry( e ); | 139 | QStringList font = readListEntry( e ); |
140 | if ( font.isEmpty() ) | 140 | if ( font.isEmpty() ) |
141 | return *def; | 141 | return *def; |
142 | QFont f; | 142 | QFont f; |
143 | f.setFamily( font[0]); | 143 | f.setFamily( font[0]); |
144 | f.setBold ( font[1] == "bold"); | 144 | f.setBold ( font[1] == "bold"); |
145 | f.setPointSize ( font[2].toInt()); | 145 | f.setPointSize ( font[2].toInt()); |
146 | f.setItalic( font[1] == "italic" ); | 146 | f.setItalic( font[3] == "italic" ); |
147 | return f; | 147 | return f; |
148 | } | 148 | } |
149 | 149 | ||
150 | QDateTime KConfig::readDateTimeEntry( const QString &key, const QDateTime *def ) | 150 | QDateTime KConfig::readDateTimeEntry( const QString &key, const QDateTime *def ) |
151 | { | 151 | { |
152 | QMap<QString,QDateTime>::ConstIterator it = mDateTimeMap.find( mGroup + key ); | 152 | QMap<QString,QDateTime>::ConstIterator it = mDateTimeMap.find( mGroup + key ); |
153 | 153 | ||
154 | if ( it == mDateTimeMap.end() ) { | 154 | if ( it == mDateTimeMap.end() ) { |
155 | if ( def ) return *def; | 155 | if ( def ) return *def; |
156 | else return QDateTime(); | 156 | else return QDateTime(); |
157 | } | 157 | } |
158 | 158 | ||
159 | return *it; | 159 | return *it; |
160 | } | 160 | } |
161 | 161 | ||
162 | //US added method | 162 | //US added method |
163 | void KConfig::writeEntry( const QString &key, const QValueList<int> &value) | 163 | void KConfig::writeEntry( const QString &key, const QValueList<int> &value) |
164 | { | 164 | { |
165 | QStringList valuesAsStrings; | 165 | QStringList valuesAsStrings; |
166 | 166 | ||
167 | QValueList<int>::ConstIterator it; | 167 | QValueList<int>::ConstIterator it; |
168 | 168 | ||
169 | for( it = value.begin(); it != value.end(); ++it ) | 169 | for( it = value.begin(); it != value.end(); ++it ) |
170 | { | 170 | { |
171 | valuesAsStrings << QString::number(*it); | 171 | valuesAsStrings << QString::number(*it); |
172 | } | 172 | } |
173 | 173 | ||
174 | mStringMap.insert( mGroup + key, valuesAsStrings.join(":") ); | 174 | mStringMap.insert( mGroup + key, valuesAsStrings.join(":") ); |
175 | mDirty = true; | 175 | mDirty = true; |
176 | } | 176 | } |
177 | 177 | ||
178 | void KConfig::writeEntry( const QString & key , int num ) | 178 | void KConfig::writeEntry( const QString & key , int num ) |
179 | { | 179 | { |
180 | writeEntry( key, QString::number ( num ) ); | 180 | writeEntry( key, QString::number ( num ) ); |
181 | } | 181 | } |
182 | 182 | ||
183 | void KConfig::writeEntry( const QString &key, const QString &value ) | 183 | void KConfig::writeEntry( const QString &key, const QString &value ) |
184 | { | 184 | { |
185 | mStringMap.insert( mGroup + key, value ); | 185 | mStringMap.insert( mGroup + key, value ); |
186 | 186 | ||
187 | mDirty = true; | 187 | mDirty = true; |
188 | } | 188 | } |
189 | 189 | ||
190 | void KConfig::writeEntry( const QString &key, const QStringList &value ) | 190 | void KConfig::writeEntry( const QString &key, const QStringList &value ) |
191 | { | 191 | { |
192 | mStringMap.insert( mGroup + key, value.join(":") ); | 192 | mStringMap.insert( mGroup + key, value.join(":") ); |
193 | 193 | ||
194 | mDirty = true; | 194 | mDirty = true; |
195 | } | 195 | } |
196 | 196 | ||
197 | void KConfig::writeEntry( const QString &key, bool value) | 197 | void KConfig::writeEntry( const QString &key, bool value) |
198 | { | 198 | { |
199 | mBoolMap.insert( mGroup + key, value ); | 199 | mBoolMap.insert( mGroup + key, value ); |
200 | 200 | ||
201 | mDirty = true; | 201 | mDirty = true; |
202 | } | 202 | } |
203 | 203 | ||
204 | void KConfig::writeEntry( const QString & e, const QColor & c ) | 204 | void KConfig::writeEntry( const QString & e, const QColor & c ) |
205 | { | 205 | { |
206 | QStringList l; | 206 | QStringList l; |
207 | l.append( QString::number ( c.red() ) ); | 207 | l.append( QString::number ( c.red() ) ); |
208 | l.append( QString::number ( c.green() ) ); | 208 | l.append( QString::number ( c.green() ) ); |
209 | l.append( QString::number ( c.blue() ) ); | 209 | l.append( QString::number ( c.blue() ) ); |
210 | writeEntry( e, l ); | 210 | writeEntry( e, l ); |
211 | } | 211 | } |
212 | 212 | ||
213 | void KConfig::writeEntry( const QString & e , const QFont & f ) | 213 | void KConfig::writeEntry( const QString & e , const QFont & f ) |
214 | { | 214 | { |
215 | QStringList font; | 215 | QStringList font; |
216 | font.append( f.family()); | 216 | font.append( f.family()); |
217 | font.append( (!f.bold ()?"nonbold":"bold") ); | 217 | font.append( (!f.bold ()?"nonbold":"bold") ); |
218 | font.append( QString::number ( f.pointSize () ) ); | 218 | font.append( QString::number ( f.pointSize () ) ); |
219 | font.append( !f.italic ()?"nonitalic":"italic" ); | 219 | font.append( !f.italic ()?"nonitalic":"italic" ); |
220 | writeEntry( e, font ); | 220 | writeEntry( e, font ); |
221 | } | 221 | } |
222 | 222 | ||
223 | void KConfig::writeEntry( const QString &key, const QDateTime &dt ) | 223 | void KConfig::writeEntry( const QString &key, const QDateTime &dt ) |
224 | { | 224 | { |
225 | mDateTimeMap.insert( mGroup + key, dt ); | 225 | mDateTimeMap.insert( mGroup + key, dt ); |
226 | } | 226 | } |
227 | 227 | ||
228 | void KConfig::load() | 228 | void KConfig::load() |
229 | { | 229 | { |
230 | kdDebug() << "KConfig::load(): " << mFileName << endl; | 230 | kdDebug() << "KConfig::load(): " << mFileName << endl; |
231 | 231 | ||
232 | QFile f( mFileName ); | 232 | QFile f( mFileName ); |
233 | if ( !f.open( IO_ReadOnly ) ) { | 233 | if ( !f.open( IO_ReadOnly ) ) { |
234 | qDebug("KConfig: could not open file %s ",mFileName.latin1() ); | 234 | qDebug("KConfig: could not open file %s ",mFileName.latin1() ); |
235 | return; | 235 | return; |
236 | } | 236 | } |
237 | 237 | ||
238 | mBoolMap.clear(); | 238 | mBoolMap.clear(); |
239 | mStringMap.clear(); | 239 | mStringMap.clear(); |
240 | 240 | ||
241 | QTextStream t( &f ); | 241 | QTextStream t( &f ); |
242 | 242 | ||
243 | QString line = t.readLine(); | 243 | QString line = t.readLine(); |
244 | 244 | ||
245 | while ( !line.isNull() ) { | 245 | while ( !line.isNull() ) { |
246 | QStringList tokens = QStringList::split( ",", line ); | 246 | QStringList tokens = QStringList::split( ",", line ); |
247 | if ( tokens[0] == "bool" ) { | 247 | if ( tokens[0] == "bool" ) { |
248 | bool value = false; | 248 | bool value = false; |
249 | if ( tokens[2] == "1" ) value = true; | 249 | if ( tokens[2] == "1" ) value = true; |
250 | mBoolMap.insert( tokens[1], value ); | 250 | mBoolMap.insert( tokens[1], value ); |
251 | } else if ( tokens[0] == "QString" ) { | 251 | } else if ( tokens[0] == "QString" ) { |
252 | QString value = tokens[2]; | 252 | QString value = tokens[2]; |
253 | mStringMap.insert( tokens[1], value ); | 253 | mStringMap.insert( tokens[1], value ); |
254 | } else if ( tokens[0] == "QDateTime" ) { | 254 | } else if ( tokens[0] == "QDateTime" ) { |
255 | #if 0 | 255 | #if 0 |
256 | int year = tokens[2].toInt(); | 256 | int year = tokens[2].toInt(); |
257 | QDateTime dt( QDate( year, | 257 | QDateTime dt( QDate( year, |
258 | tokens[3].toInt(), | 258 | tokens[3].toInt(), |
259 | tokens[4].toInt() ), | 259 | tokens[4].toInt() ), |
260 | QTime( tokens[5].toInt(), tokens[6].toInt(), | 260 | QTime( tokens[5].toInt(), tokens[6].toInt(), |
261 | tokens[7].toInt() ) ); | 261 | tokens[7].toInt() ) ); |
262 | mDateTimeMap.insert( tokens[1], dt ); | 262 | mDateTimeMap.insert( tokens[1], dt ); |
263 | #endif | 263 | #endif |
264 | } | 264 | } |
265 | 265 | ||
266 | line = t.readLine(); | 266 | line = t.readLine(); |
267 | } | 267 | } |
268 | } | 268 | } |
269 | 269 | ||
270 | void KConfig::sync() | 270 | void KConfig::sync() |
271 | { | 271 | { |
272 | 272 | ||
273 | if ( !mDirty ) return; | 273 | if ( !mDirty ) return; |
274 | //qDebug("KConfig::sync() %s ",mFileName.latin1() ); | 274 | //qDebug("KConfig::sync() %s ",mFileName.latin1() ); |
275 | //kdDebug() << "KConfig::sync(): " << mFileName << endl; | 275 | //kdDebug() << "KConfig::sync(): " << mFileName << endl; |
276 | 276 | ||
277 | //US I took the following code from a newer version of KDE | 277 | //US I took the following code from a newer version of KDE |
278 | // Create the containing dir if needed | 278 | // Create the containing dir if needed |
279 | KURL path; | 279 | KURL path; |
280 | path.setPath(mFileName); | 280 | path.setPath(mFileName); |
281 | QString dir=path.directory(); | 281 | QString dir=path.directory(); |
282 | KStandardDirs::makeDir(dir); | 282 | KStandardDirs::makeDir(dir); |
283 | 283 | ||
284 | QFile f( mFileName ); | 284 | QFile f( mFileName ); |
285 | if ( !f.open( IO_WriteOnly ) ) { | 285 | if ( !f.open( IO_WriteOnly ) ) { |
286 | 286 | ||
287 | qDebug("KConfig::sync() Can't open file %s ",mFileName.latin1() ); | 287 | qDebug("KConfig::sync() Can't open file %s ",mFileName.latin1() ); |
288 | 288 | ||
289 | return; | 289 | return; |
290 | } | 290 | } |
291 | 291 | ||
292 | QTextStream t( &f ); | 292 | QTextStream t( &f ); |
293 | 293 | ||
294 | QMap<QString,bool>::ConstIterator itBool; | 294 | QMap<QString,bool>::ConstIterator itBool; |
295 | for( itBool = mBoolMap.begin(); itBool != mBoolMap.end(); ++itBool ) { | 295 | for( itBool = mBoolMap.begin(); itBool != mBoolMap.end(); ++itBool ) { |
296 | t << "bool," << itBool.key() << "," << ( *itBool ? "1" : "0" ) << endl; | 296 | t << "bool," << itBool.key() << "," << ( *itBool ? "1" : "0" ) << endl; |
297 | } | 297 | } |
298 | 298 | ||
299 | QMap<QString,QString>::ConstIterator itString; | 299 | QMap<QString,QString>::ConstIterator itString; |
300 | for( itString = mStringMap.begin(); itString != mStringMap.end(); ++itString ) { | 300 | for( itString = mStringMap.begin(); itString != mStringMap.end(); ++itString ) { |
301 | t << "QString," << itString.key() << "," << (*itString ) << endl; | 301 | t << "QString," << itString.key() << "," << (*itString ) << endl; |
302 | } | 302 | } |
303 | 303 | ||
304 | QMap<QString,QDateTime>::ConstIterator itDateTime; | 304 | QMap<QString,QDateTime>::ConstIterator itDateTime; |
305 | for( itDateTime = mDateTimeMap.begin(); itDateTime != mDateTimeMap.end(); ++itDateTime ) { | 305 | for( itDateTime = mDateTimeMap.begin(); itDateTime != mDateTimeMap.end(); ++itDateTime ) { |
306 | QDateTime dt = *itDateTime; | 306 | QDateTime dt = *itDateTime; |
307 | t << "QDateTime," << itDateTime.key() << "," | 307 | t << "QDateTime," << itDateTime.key() << "," |
308 | << dt.date().year() << "," | 308 | << dt.date().year() << "," |
309 | << dt.date().month() << "," | 309 | << dt.date().month() << "," |
310 | << dt.date().day() << "," | 310 | << dt.date().day() << "," |
311 | << dt.time().hour() << "," | 311 | << dt.time().hour() << "," |
312 | << dt.time().minute() << "," | 312 | << dt.time().minute() << "," |
313 | << dt.time().second() << endl; | 313 | << dt.time().second() << endl; |
314 | } | 314 | } |
315 | 315 | ||
316 | f.close(); | 316 | f.close(); |
317 | 317 | ||
318 | mDirty = false; | 318 | mDirty = false; |
319 | } | 319 | } |
320 | 320 | ||
321 | 321 | ||
322 | //US I took the following deleteGroup method from a newer version from KDE. | 322 | //US I took the following deleteGroup method from a newer version from KDE. |
323 | /** | 323 | /** |
324 | * Deletes a configuration entry group | 324 | * Deletes a configuration entry group |
325 | * | 325 | * |
326 | * If the group is not empty and bDeep is false, nothing gets | 326 | * If the group is not empty and bDeep is false, nothing gets |
327 | * deleted and false is returned. | 327 | * deleted and false is returned. |
328 | * If this group is the current group and it is deleted, the | 328 | * If this group is the current group and it is deleted, the |
329 | * current group is undefined and should be set with setGroup() | 329 | * current group is undefined and should be set with setGroup() |
330 | * before the next operation on the configuration object. | 330 | * before the next operation on the configuration object. |
331 | * | 331 | * |
332 | * @param group The name of the group | 332 | * @param group The name of the group |
333 | * returns true if we deleted at least one entry. | 333 | * returns true if we deleted at least one entry. |
334 | */ | 334 | */ |
335 | bool KConfig::deleteGroup( const QString& group) | 335 | bool KConfig::deleteGroup( const QString& group) |
336 | { | 336 | { |
337 | bool dirty = false; | 337 | bool dirty = false; |
338 | int pos; | 338 | int pos; |
339 | 339 | ||
340 | QMap<QString,bool>::Iterator itBool = mBoolMap.begin(); | 340 | QMap<QString,bool>::Iterator itBool = mBoolMap.begin(); |
341 | QMap<QString,bool>::Iterator delBool; | 341 | QMap<QString,bool>::Iterator delBool; |
342 | 342 | ||
343 | while ( itBool != mBoolMap.end() ) { | 343 | while ( itBool != mBoolMap.end() ) { |
344 | pos = itBool.key().find( group ); | 344 | pos = itBool.key().find( group ); |
345 | if (pos == 0) { | 345 | if (pos == 0) { |
346 | delBool = itBool; | 346 | delBool = itBool; |
347 | ++itBool; | 347 | ++itBool; |
348 | mBoolMap.remove(delBool); | 348 | mBoolMap.remove(delBool); |
349 | dirty = true; | 349 | dirty = true; |
350 | } else | 350 | } else |
351 | ++itBool; | 351 | ++itBool; |
352 | 352 | ||
353 | } | 353 | } |
354 | /* | 354 | /* |
355 | for( itBool = mBoolMap.begin(); itBool != mBoolMap.end(); ++itBool ) | 355 | for( itBool = mBoolMap.begin(); itBool != mBoolMap.end(); ++itBool ) |
356 | { | 356 | { |
357 | pos = itBool.key().find( group ); | 357 | pos = itBool.key().find( group ); |
358 | if (pos == 0) { | 358 | if (pos == 0) { |
359 | mBoolMap.remove(itBool); | 359 | mBoolMap.remove(itBool); |
360 | dirty = true; | 360 | dirty = true; |
361 | } | 361 | } |
362 | } | 362 | } |
363 | */ | 363 | */ |
364 | QMap<QString,QString>::Iterator itString = mStringMap.begin(); | 364 | QMap<QString,QString>::Iterator itString = mStringMap.begin(); |
365 | QMap<QString,QString>::Iterator delString ; | 365 | QMap<QString,QString>::Iterator delString ; |
366 | while( itString != mStringMap.end() ) { | 366 | while( itString != mStringMap.end() ) { |
367 | pos = itString.key().find( group ); | 367 | pos = itString.key().find( group ); |
368 | if (pos == 0) { | 368 | if (pos == 0) { |
369 | delString = itString; | 369 | delString = itString; |
370 | ++itString; | 370 | ++itString; |
371 | mStringMap.remove(delString); | 371 | mStringMap.remove(delString); |
372 | //qDebug("delte++++++++++++++++++ "); | 372 | //qDebug("delte++++++++++++++++++ "); |
373 | dirty = true; | 373 | dirty = true; |
374 | } else | 374 | } else |
375 | ++itString; | 375 | ++itString; |
376 | 376 | ||
377 | } | 377 | } |
378 | /* this leads to a memory access violation | 378 | /* this leads to a memory access violation |
379 | for( itString = mStringMap.begin(); itString != mStringMap.end(); ++itString ) | 379 | for( itString = mStringMap.begin(); itString != mStringMap.end(); ++itString ) |
380 | { | 380 | { |
381 | pos = itString.key().find( group ); | 381 | pos = itString.key().find( group ); |
382 | if (pos == 0) { | 382 | if (pos == 0) { |
383 | mStringMap.remove(itString); | 383 | mStringMap.remove(itString); |
384 | dirty = true; | 384 | dirty = true; |
385 | } | 385 | } |
386 | } | 386 | } |
387 | */ | 387 | */ |
388 | QMap<QString,QDateTime>::Iterator itDateTime= mDateTimeMap.begin(); | 388 | QMap<QString,QDateTime>::Iterator itDateTime= mDateTimeMap.begin(); |
389 | QMap<QString,QDateTime>::Iterator delDateTime; | 389 | QMap<QString,QDateTime>::Iterator delDateTime; |
390 | while ( itDateTime != mDateTimeMap.end() ) { | 390 | while ( itDateTime != mDateTimeMap.end() ) { |
391 | pos = itDateTime.key().find( group ); | 391 | pos = itDateTime.key().find( group ); |
392 | if (pos == 0) { | 392 | if (pos == 0) { |
393 | delDateTime = itDateTime; | 393 | delDateTime = itDateTime; |
394 | ++itDateTime; | 394 | ++itDateTime; |
395 | mDateTimeMap.remove(delDateTime); | 395 | mDateTimeMap.remove(delDateTime); |
396 | dirty = true; | 396 | dirty = true; |
397 | } else | 397 | } else |
398 | ++itDateTime; | 398 | ++itDateTime; |
399 | 399 | ||
400 | } | 400 | } |
401 | /* | 401 | /* |
402 | for( itDateTime = mDateTimeMap.begin(); itDateTime != mDateTimeMap.end(); ++itDateTime ) | 402 | for( itDateTime = mDateTimeMap.begin(); itDateTime != mDateTimeMap.end(); ++itDateTime ) |
403 | { | 403 | { |
404 | pos = itDateTime.key().find( group ); | 404 | pos = itDateTime.key().find( group ); |
405 | if (pos == 0) { | 405 | if (pos == 0) { |
406 | mDateTimeMap.remove(itDateTime); | 406 | mDateTimeMap.remove(itDateTime); |
407 | dirty = true; | 407 | dirty = true; |
408 | } | 408 | } |
409 | } | 409 | } |
410 | */ | 410 | */ |
411 | 411 | ||
412 | if (dirty) | 412 | if (dirty) |
413 | mDirty = true; | 413 | mDirty = true; |
414 | 414 | ||
415 | return dirty; | 415 | return dirty; |
416 | 416 | ||
417 | } | 417 | } |
418 | 418 | ||
419 | //US I took the following hasGroup method from a newer version from KDE. | 419 | //US I took the following hasGroup method from a newer version from KDE. |
420 | /** | 420 | /** |
421 | * Returns true if the specified group is known about. | 421 | * Returns true if the specified group is known about. |
422 | * | 422 | * |
423 | * @param group The group to search for. | 423 | * @param group The group to search for. |
424 | * @return Whether the group exists. | 424 | * @return Whether the group exists. |
425 | */ | 425 | */ |
426 | bool KConfig::hasGroup(const QString &group) const | 426 | bool KConfig::hasGroup(const QString &group) const |
427 | { | 427 | { |
428 | QMap<QString,bool>::ConstIterator itBool; | 428 | QMap<QString,bool>::ConstIterator itBool; |
429 | for( itBool = mBoolMap.begin(); itBool != mBoolMap.end(); ++itBool ) | 429 | for( itBool = mBoolMap.begin(); itBool != mBoolMap.end(); ++itBool ) |
430 | { | 430 | { |
431 | if (itBool.key().find( group ) == 0) { | 431 | if (itBool.key().find( group ) == 0) { |
432 | return true; | 432 | return true; |
433 | } | 433 | } |
434 | } | 434 | } |
435 | 435 | ||
436 | QMap<QString,QString>::ConstIterator itString; | 436 | QMap<QString,QString>::ConstIterator itString; |
437 | for( itString = mStringMap.begin(); itString != mStringMap.end(); ++itString ) | 437 | for( itString = mStringMap.begin(); itString != mStringMap.end(); ++itString ) |
438 | { | 438 | { |
439 | if (itString.key().find( group ) == 0) { | 439 | if (itString.key().find( group ) == 0) { |
440 | return true; | 440 | return true; |
441 | } | 441 | } |
442 | } | 442 | } |
443 | 443 | ||
444 | QMap<QString,QDateTime>::ConstIterator itDateTime; | 444 | QMap<QString,QDateTime>::ConstIterator itDateTime; |
445 | for( itDateTime = mDateTimeMap.begin(); itDateTime != mDateTimeMap.end(); ++itDateTime ) | 445 | for( itDateTime = mDateTimeMap.begin(); itDateTime != mDateTimeMap.end(); ++itDateTime ) |
446 | { | 446 | { |
447 | if (itDateTime.key().find( group ) == 0) { | 447 | if (itDateTime.key().find( group ) == 0) { |
448 | return true; | 448 | return true; |
449 | } | 449 | } |
450 | } | 450 | } |
451 | 451 | ||
452 | return false; | 452 | return false; |
453 | } | 453 | } |
454 | 454 | ||
455 | void KConfig::deleteEntry( const QString &key) | 455 | void KConfig::deleteEntry( const QString &key) |
456 | { | 456 | { |
457 | bool dirty = false; | 457 | bool dirty = false; |
458 | 458 | ||
459 | QMap<QString,bool>::Iterator itBool = mBoolMap.find( mGroup + key ); | 459 | QMap<QString,bool>::Iterator itBool = mBoolMap.find( mGroup + key ); |
460 | if ( itBool != mBoolMap.end() ) { | 460 | if ( itBool != mBoolMap.end() ) { |
461 | mBoolMap.remove(itBool); | 461 | mBoolMap.remove(itBool); |
462 | dirty = true; | 462 | dirty = true; |
463 | } | 463 | } |
464 | 464 | ||
465 | 465 | ||
466 | QMap<QString,QString>::Iterator itString = mStringMap.find( mGroup + key ); | 466 | QMap<QString,QString>::Iterator itString = mStringMap.find( mGroup + key ); |
467 | if ( itString != mStringMap.end() ) { | 467 | if ( itString != mStringMap.end() ) { |
468 | mStringMap.remove(itString); | 468 | mStringMap.remove(itString); |
469 | dirty = true; | 469 | dirty = true; |
470 | } | 470 | } |
471 | 471 | ||
472 | 472 | ||
473 | QMap<QString,QDateTime>::Iterator itDateTime = mDateTimeMap.find( mGroup + key ); | 473 | QMap<QString,QDateTime>::Iterator itDateTime = mDateTimeMap.find( mGroup + key ); |
474 | if ( itDateTime != mDateTimeMap.end() ) { | 474 | if ( itDateTime != mDateTimeMap.end() ) { |
475 | mDateTimeMap.remove(itDateTime); | 475 | mDateTimeMap.remove(itDateTime); |
476 | dirty = true; | 476 | dirty = true; |
477 | } | 477 | } |
478 | 478 | ||
479 | if (dirty) | 479 | if (dirty) |
480 | mDirty = true; | 480 | mDirty = true; |
481 | 481 | ||
482 | } | 482 | } |
483 | 483 | ||
484 | //US | 484 | //US |
485 | QString KConfig::getFileName() | 485 | QString KConfig::getFileName() |
486 | { | 486 | { |
487 | return mFileName; | 487 | return mFileName; |
488 | } | 488 | } |
489 | 489 | ||
490 | bool KConfig::hasKey( const QString &key) | 490 | bool KConfig::hasKey( const QString &key) |
491 | { | 491 | { |
492 | QMap<QString,bool>::Iterator itBool = mBoolMap.find( mGroup + key ); | 492 | QMap<QString,bool>::Iterator itBool = mBoolMap.find( mGroup + key ); |
493 | if ( itBool != mBoolMap.end() ) { | 493 | if ( itBool != mBoolMap.end() ) { |
494 | return true; | 494 | return true; |
495 | } | 495 | } |
496 | 496 | ||
497 | QMap<QString,QString>::Iterator itString = mStringMap.find( mGroup + key ); | 497 | QMap<QString,QString>::Iterator itString = mStringMap.find( mGroup + key ); |
498 | if ( itString != mStringMap.end() ) { | 498 | if ( itString != mStringMap.end() ) { |
499 | return true; | 499 | return true; |
500 | } | 500 | } |
501 | 501 | ||
502 | QMap<QString,QDateTime>::Iterator itDateTime = mDateTimeMap.find( mGroup + key ); | 502 | QMap<QString,QDateTime>::Iterator itDateTime = mDateTimeMap.find( mGroup + key ); |
503 | if ( itDateTime != mDateTimeMap.end() ) { | 503 | if ( itDateTime != mDateTimeMap.end() ) { |
504 | return true; | 504 | return true; |
505 | } | 505 | } |
506 | 506 | ||
507 | return false; | 507 | return false; |
508 | } | 508 | } |
509 | 509 | ||