-rw-r--r-- | microkde/kconfig.cpp | 44 |
1 files changed, 41 insertions, 3 deletions
diff --git a/microkde/kconfig.cpp b/microkde/kconfig.cpp index 3f23ed2..b882adb 100644 --- a/microkde/kconfig.cpp +++ b/microkde/kconfig.cpp | |||
@@ -245,220 +245,258 @@ void KConfig::load() | |||
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; | 340 | QMap<QString,bool>::Iterator itBool; |
341 | QMap<QString,bool>::Iterator delBool; | ||
342 | while ( itBool != mBoolMap.end() ) { | ||
343 | pos = itBool.key().find( group ); | ||
344 | if (pos == 0) { | ||
345 | delBool = itBool; | ||
346 | ++itBool; | ||
347 | mBoolMap.remove(delBool); | ||
348 | dirty = true; | ||
349 | } | ||
350 | |||
351 | } | ||
352 | /* | ||
341 | for( itBool = mBoolMap.begin(); itBool != mBoolMap.end(); ++itBool ) | 353 | for( itBool = mBoolMap.begin(); itBool != mBoolMap.end(); ++itBool ) |
342 | { | 354 | { |
343 | pos = itBool.key().find( group ); | 355 | pos = itBool.key().find( group ); |
344 | if (pos == 0) { | 356 | if (pos == 0) { |
345 | mBoolMap.remove(itBool); | 357 | mBoolMap.remove(itBool); |
346 | dirty = true; | 358 | dirty = true; |
347 | } | 359 | } |
348 | } | 360 | } |
361 | */ | ||
362 | QMap<QString,QString>::Iterator itString = mStringMap.begin(); | ||
363 | QMap<QString,QString>::Iterator delString ; | ||
364 | while( itString != mStringMap.end() ) { | ||
365 | pos = itString.key().find( group ); | ||
366 | if (pos == 0) { | ||
367 | delString = itString; | ||
368 | ++itString; | ||
369 | mStringMap.remove(delString); | ||
370 | //qDebug("delte++++++++++++++++++ "); | ||
371 | dirty = true; | ||
372 | } | ||
349 | 373 | ||
350 | QMap<QString,QString>::Iterator itString; | 374 | } |
375 | /* this leads to a memory access violation | ||
351 | for( itString = mStringMap.begin(); itString != mStringMap.end(); ++itString ) | 376 | for( itString = mStringMap.begin(); itString != mStringMap.end(); ++itString ) |
352 | { | 377 | { |
353 | pos = itString.key().find( group ); | 378 | pos = itString.key().find( group ); |
354 | if (pos == 0) { | 379 | if (pos == 0) { |
355 | mStringMap.remove(itString); | 380 | mStringMap.remove(itString); |
356 | dirty = true; | 381 | dirty = true; |
357 | } | 382 | } |
358 | } | 383 | } |
359 | 384 | */ | |
360 | QMap<QString,QDateTime>::Iterator itDateTime; | 385 | QMap<QString,QDateTime>::Iterator itDateTime= mDateTimeMap.begin(); |
386 | QMap<QString,QDateTime>::Iterator delDateTime; | ||
387 | while ( itDateTime != mDateTimeMap.end() ) { | ||
388 | pos = itDateTime.key().find( group ); | ||
389 | if (pos == 0) { | ||
390 | delDateTime = itDateTime; | ||
391 | ++itDateTime; | ||
392 | mDateTimeMap.remove(delDateTime); | ||
393 | dirty = true; | ||
394 | } | ||
395 | |||
396 | } | ||
397 | /* | ||
361 | for( itDateTime = mDateTimeMap.begin(); itDateTime != mDateTimeMap.end(); ++itDateTime ) | 398 | for( itDateTime = mDateTimeMap.begin(); itDateTime != mDateTimeMap.end(); ++itDateTime ) |
362 | { | 399 | { |
363 | pos = itDateTime.key().find( group ); | 400 | pos = itDateTime.key().find( group ); |
364 | if (pos == 0) { | 401 | if (pos == 0) { |
365 | mDateTimeMap.remove(itDateTime); | 402 | mDateTimeMap.remove(itDateTime); |
366 | dirty = true; | 403 | dirty = true; |
367 | } | 404 | } |
368 | } | 405 | } |
406 | */ | ||
369 | 407 | ||
370 | if (dirty) | 408 | if (dirty) |
371 | mDirty = true; | 409 | mDirty = true; |
372 | 410 | ||
373 | return dirty; | 411 | return dirty; |
374 | 412 | ||
375 | } | 413 | } |
376 | 414 | ||
377 | //US I took the following hasGroup method from a newer version from KDE. | 415 | //US I took the following hasGroup method from a newer version from KDE. |
378 | /** | 416 | /** |
379 | * Returns true if the specified group is known about. | 417 | * Returns true if the specified group is known about. |
380 | * | 418 | * |
381 | * @param group The group to search for. | 419 | * @param group The group to search for. |
382 | * @return Whether the group exists. | 420 | * @return Whether the group exists. |
383 | */ | 421 | */ |
384 | bool KConfig::hasGroup(const QString &group) const | 422 | bool KConfig::hasGroup(const QString &group) const |
385 | { | 423 | { |
386 | QMap<QString,bool>::ConstIterator itBool; | 424 | QMap<QString,bool>::ConstIterator itBool; |
387 | for( itBool = mBoolMap.begin(); itBool != mBoolMap.end(); ++itBool ) | 425 | for( itBool = mBoolMap.begin(); itBool != mBoolMap.end(); ++itBool ) |
388 | { | 426 | { |
389 | if (itBool.key().find( group ) == 0) { | 427 | if (itBool.key().find( group ) == 0) { |
390 | return true; | 428 | return true; |
391 | } | 429 | } |
392 | } | 430 | } |
393 | 431 | ||
394 | QMap<QString,QString>::ConstIterator itString; | 432 | QMap<QString,QString>::ConstIterator itString; |
395 | for( itString = mStringMap.begin(); itString != mStringMap.end(); ++itString ) | 433 | for( itString = mStringMap.begin(); itString != mStringMap.end(); ++itString ) |
396 | { | 434 | { |
397 | if (itString.key().find( group ) == 0) { | 435 | if (itString.key().find( group ) == 0) { |
398 | return true; | 436 | return true; |
399 | } | 437 | } |
400 | } | 438 | } |
401 | 439 | ||
402 | QMap<QString,QDateTime>::ConstIterator itDateTime; | 440 | QMap<QString,QDateTime>::ConstIterator itDateTime; |
403 | for( itDateTime = mDateTimeMap.begin(); itDateTime != mDateTimeMap.end(); ++itDateTime ) | 441 | for( itDateTime = mDateTimeMap.begin(); itDateTime != mDateTimeMap.end(); ++itDateTime ) |
404 | { | 442 | { |
405 | if (itDateTime.key().find( group ) == 0) { | 443 | if (itDateTime.key().find( group ) == 0) { |
406 | return true; | 444 | return true; |
407 | } | 445 | } |
408 | } | 446 | } |
409 | 447 | ||
410 | return false; | 448 | return false; |
411 | } | 449 | } |
412 | 450 | ||
413 | void KConfig::deleteEntry( const QString &key) | 451 | void KConfig::deleteEntry( const QString &key) |
414 | { | 452 | { |
415 | bool dirty = false; | 453 | bool dirty = false; |
416 | 454 | ||
417 | QMap<QString,bool>::Iterator itBool = mBoolMap.find( mGroup + key ); | 455 | QMap<QString,bool>::Iterator itBool = mBoolMap.find( mGroup + key ); |
418 | if ( itBool != mBoolMap.end() ) { | 456 | if ( itBool != mBoolMap.end() ) { |
419 | mBoolMap.remove(itBool); | 457 | mBoolMap.remove(itBool); |
420 | dirty = true; | 458 | dirty = true; |
421 | } | 459 | } |
422 | 460 | ||
423 | 461 | ||
424 | QMap<QString,QString>::Iterator itString = mStringMap.find( mGroup + key ); | 462 | QMap<QString,QString>::Iterator itString = mStringMap.find( mGroup + key ); |
425 | if ( itString != mStringMap.end() ) { | 463 | if ( itString != mStringMap.end() ) { |
426 | mStringMap.remove(itString); | 464 | mStringMap.remove(itString); |
427 | dirty = true; | 465 | dirty = true; |
428 | } | 466 | } |
429 | 467 | ||
430 | 468 | ||
431 | QMap<QString,QDateTime>::Iterator itDateTime = mDateTimeMap.find( mGroup + key ); | 469 | QMap<QString,QDateTime>::Iterator itDateTime = mDateTimeMap.find( mGroup + key ); |
432 | if ( itDateTime != mDateTimeMap.end() ) { | 470 | if ( itDateTime != mDateTimeMap.end() ) { |
433 | mDateTimeMap.remove(itDateTime); | 471 | mDateTimeMap.remove(itDateTime); |
434 | dirty = true; | 472 | dirty = true; |
435 | } | 473 | } |
436 | 474 | ||
437 | if (dirty) | 475 | if (dirty) |
438 | mDirty = true; | 476 | mDirty = true; |
439 | 477 | ||
440 | } | 478 | } |
441 | 479 | ||
442 | //US | 480 | //US |
443 | QString KConfig::getFileName() | 481 | QString KConfig::getFileName() |
444 | { | 482 | { |
445 | return mFileName; | 483 | return mFileName; |
446 | } | 484 | } |
447 | 485 | ||
448 | bool KConfig::hasKey( const QString &key) | 486 | bool KConfig::hasKey( const QString &key) |
449 | { | 487 | { |
450 | QMap<QString,bool>::Iterator itBool = mBoolMap.find( mGroup + key ); | 488 | QMap<QString,bool>::Iterator itBool = mBoolMap.find( mGroup + key ); |
451 | if ( itBool != mBoolMap.end() ) { | 489 | if ( itBool != mBoolMap.end() ) { |
452 | return true; | 490 | return true; |
453 | } | 491 | } |
454 | 492 | ||
455 | QMap<QString,QString>::Iterator itString = mStringMap.find( mGroup + key ); | 493 | QMap<QString,QString>::Iterator itString = mStringMap.find( mGroup + key ); |
456 | if ( itString != mStringMap.end() ) { | 494 | if ( itString != mStringMap.end() ) { |
457 | return true; | 495 | return true; |
458 | } | 496 | } |
459 | 497 | ||
460 | QMap<QString,QDateTime>::Iterator itDateTime = mDateTimeMap.find( mGroup + key ); | 498 | QMap<QString,QDateTime>::Iterator itDateTime = mDateTimeMap.find( mGroup + key ); |
461 | if ( itDateTime != mDateTimeMap.end() ) { | 499 | if ( itDateTime != mDateTimeMap.end() ) { |
462 | return true; | 500 | return true; |
463 | } | 501 | } |
464 | 502 | ||