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