author | zecke <zecke> | 2004-12-24 21:31:52 (UTC) |
---|---|---|
committer | zecke <zecke> | 2004-12-24 21:31:52 (UTC) |
commit | d36845f5f7e7d6bd49529524cdc9f39ce1164491 (patch) (unidiff) | |
tree | 913eda7d766c40639f218d27303f9c3909069833 /library | |
parent | 884f95d4ad11efa472919f8485ba518748109ccc (diff) | |
download | opie-d36845f5f7e7d6bd49529524cdc9f39ce1164491.zip opie-d36845f5f7e7d6bd49529524cdc9f39ce1164491.tar.gz opie-d36845f5f7e7d6bd49529524cdc9f39ce1164491.tar.bz2 |
Whitespace changes
-rw-r--r-- | library/config.cpp | 10 |
1 files changed, 5 insertions, 5 deletions
diff --git a/library/config.cpp b/library/config.cpp index 0bfb476..664ca34 100644 --- a/library/config.cpp +++ b/library/config.cpp | |||
@@ -278,303 +278,303 @@ void Config::writeEntry( const QString &key, const QStringList &lst, const QChar | |||
278 | QString s; | 278 | QString s; |
279 | QStringList::ConstIterator it = lst.begin(); | 279 | QStringList::ConstIterator it = lst.begin(); |
280 | for ( ; it != lst.end(); ++it ) | 280 | for ( ; it != lst.end(); ++it ) |
281 | s += *it + sep; | 281 | s += *it + sep; |
282 | writeEntry( key, s ); | 282 | writeEntry( key, s ); |
283 | } | 283 | } |
284 | 284 | ||
285 | /*! | 285 | /*! |
286 | Removes the \a key entry from the current group. Does nothing if | 286 | Removes the \a key entry from the current group. Does nothing if |
287 | there is no such entry. | 287 | there is no such entry. |
288 | */ | 288 | */ |
289 | 289 | ||
290 | void Config::removeEntry( const QString &key ) | 290 | void Config::removeEntry( const QString &key ) |
291 | { | 291 | { |
292 | if ( git == groups.end() ) { | 292 | if ( git == groups.end() ) { |
293 | qWarning( "no group set" ); | 293 | qWarning( "no group set" ); |
294 | return; | 294 | return; |
295 | } | 295 | } |
296 | ( *git ).remove( key ); | 296 | ( *git ).remove( key ); |
297 | changed = TRUE; | 297 | changed = TRUE; |
298 | } | 298 | } |
299 | 299 | ||
300 | /*! | 300 | /*! |
301 | \fn bool Config::operator == ( const Config & other ) const | 301 | \fn bool Config::operator == ( const Config & other ) const |
302 | 302 | ||
303 | Tests for equality with \a other. Config objects are equal if they refer to the same filename. | 303 | Tests for equality with \a other. Config objects are equal if they refer to the same filename. |
304 | */ | 304 | */ |
305 | 305 | ||
306 | /*! | 306 | /*! |
307 | \fn bool Config::operator != ( const Config & other ) const | 307 | \fn bool Config::operator != ( const Config & other ) const |
308 | 308 | ||
309 | Tests for inequality with \a other. Config objects are equal if they refer to the same filename. | 309 | Tests for inequality with \a other. Config objects are equal if they refer to the same filename. |
310 | */ | 310 | */ |
311 | 311 | ||
312 | /*! | 312 | /*! |
313 | \fn QString Config::readEntry( const QString &key, const QString &deflt ) const | 313 | \fn QString Config::readEntry( const QString &key, const QString &deflt ) const |
314 | 314 | ||
315 | Reads a string entry stored with \a key, defaulting to \a deflt if there is no entry. | 315 | Reads a string entry stored with \a key, defaulting to \a deflt if there is no entry. |
316 | */ | 316 | */ |
317 | 317 | ||
318 | /*! | 318 | /*! |
319 | \internal | 319 | \internal |
320 | For compatibility, non-const version. | 320 | For compatibility, non-const version. |
321 | */ | 321 | */ |
322 | QString Config::readEntry( const QString &key, const QString &deflt ) | 322 | QString Config::readEntry( const QString &key, const QString &deflt ) |
323 | { | 323 | { |
324 | QString res = readEntryDirect( key+"["+lang+"]" ); | 324 | QString res = readEntryDirect( key+"["+lang+"]" ); |
325 | if ( !res.isNull() ) | 325 | if ( !res.isNull() ) |
326 | return res; | 326 | return res; |
327 | if ( !glang.isEmpty() ) { | 327 | if ( !glang.isEmpty() ) { |
328 | res = readEntryDirect( key+"["+glang+"]" ); | 328 | res = readEntryDirect( key+"["+glang+"]" ); |
329 | if ( !res.isNull() ) | 329 | if ( !res.isNull() ) |
330 | return res; | 330 | return res; |
331 | } | 331 | } |
332 | return readEntryDirect( key, deflt ); | 332 | return readEntryDirect( key, deflt ); |
333 | } | 333 | } |
334 | 334 | ||
335 | /*! | 335 | /*! |
336 | \fn QString Config::readEntryCrypt( const QString &key, const QString &deflt ) const | 336 | \fn QString Config::readEntryCrypt( const QString &key, const QString &deflt ) const |
337 | 337 | ||
338 | Reads an encrypted string entry stored with \a key, defaulting to \a deflt if there is no entry. | 338 | Reads an encrypted string entry stored with \a key, defaulting to \a deflt if there is no entry. |
339 | */ | 339 | */ |
340 | 340 | ||
341 | /*! | 341 | /*! |
342 | \internal | 342 | \internal |
343 | For compatibility, non-const version. | 343 | For compatibility, non-const version. |
344 | */ | 344 | */ |
345 | QString Config::readEntryCrypt( const QString &key, const QString &deflt ) | 345 | QString Config::readEntryCrypt( const QString &key, const QString &deflt ) |
346 | { | 346 | { |
347 | QString res = readEntryDirect( key+"["+lang+"]" ); | 347 | QString res = readEntryDirect( key+"["+lang+"]" ); |
348 | if ( res.isNull() && glang.isEmpty() ) | 348 | if ( res.isNull() && glang.isEmpty() ) |
349 | res = readEntryDirect( key+"["+glang+"]" ); | 349 | res = readEntryDirect( key+"["+glang+"]" ); |
350 | if ( res.isNull() ) | 350 | if ( res.isNull() ) |
351 | res = readEntryDirect( key, QString::null ); | 351 | res = readEntryDirect( key, QString::null ); |
352 | if ( res.isNull() ) | 352 | if ( res.isNull() ) |
353 | return deflt; | 353 | return deflt; |
354 | return decipher(res); | 354 | return decipher(res); |
355 | } | 355 | } |
356 | 356 | ||
357 | /*! | 357 | /*! |
358 | \fn QString Config::readEntryDirect( const QString &key, const QString &deflt ) const | 358 | \fn QString Config::readEntryDirect( const QString &key, const QString &deflt ) const |
359 | \internal | 359 | \internal |
360 | */ | 360 | */ |
361 | 361 | ||
362 | /*! | 362 | /*! |
363 | \internal | 363 | \internal |
364 | For compatibility, non-const version. | 364 | For compatibility, non-const version. |
365 | */ | 365 | */ |
366 | QString Config::readEntryDirect( const QString &key, const QString &deflt ) | 366 | QString Config::readEntryDirect( const QString &key, const QString &deflt ) |
367 | { | 367 | { |
368 | if ( git == groups.end() ) { | 368 | if ( git == groups.end() ) { |
369 | //qWarning( "no group set" ); | 369 | //qWarning( "no group set" ); |
370 | return deflt; | 370 | return deflt; |
371 | } | 371 | } |
372 | ConfigGroup::ConstIterator it = ( *git ).find( key ); | 372 | ConfigGroup::ConstIterator it = ( *git ).find( key ); |
373 | if ( it != ( *git ).end() ) | 373 | if ( it != ( *git ).end() ) |
374 | return *it; | 374 | return *it; |
375 | else | 375 | else |
376 | return deflt; | 376 | return deflt; |
377 | } | 377 | } |
378 | 378 | ||
379 | /*! | 379 | /*! |
380 | \fn int Config::readNumEntry( const QString &key, int deflt ) const | 380 | \fn int Config::readNumEntry( const QString &key, int deflt ) const |
381 | Reads a numeric entry stored with \a key, defaulting to \a deflt if there is no entry. | 381 | Reads a numeric entry stored with \a key, defaulting to \a deflt if there is no entry. |
382 | */ | 382 | */ |
383 | 383 | ||
384 | /*! | 384 | /*! |
385 | \internal | 385 | \internal |
386 | For compatibility, non-const version. | 386 | For compatibility, non-const version. |
387 | */ | 387 | */ |
388 | int Config::readNumEntry( const QString &key, int deflt ) | 388 | int Config::readNumEntry( const QString &key, int deflt ) |
389 | { | 389 | { |
390 | QString s = readEntry( key ); | 390 | QString s = readEntry( key ); |
391 | if ( s.isEmpty() ) | 391 | if ( s.isEmpty() ) |
392 | return deflt; | 392 | return deflt; |
393 | else | 393 | else |
394 | return s.toInt(); | 394 | return s.toInt(); |
395 | } | 395 | } |
396 | 396 | ||
397 | /*! | 397 | /*! |
398 | \fn bool Config::readBoolEntry( const QString &key, bool deflt ) const | 398 | \fn bool Config::readBoolEntry( const QString &key, bool deflt ) const |
399 | Reads a bool entry stored with \a key, defaulting to \a deflt if there is no entry. | 399 | Reads a bool entry stored with \a key, defaulting to \a deflt if there is no entry. |
400 | */ | 400 | */ |
401 | 401 | ||
402 | /*! | 402 | /*! |
403 | \internal | 403 | \internal |
404 | For compatibility, non-const version. | 404 | For compatibility, non-const version. |
405 | */ | 405 | */ |
406 | bool Config::readBoolEntry( const QString &key, bool deflt ) | 406 | bool Config::readBoolEntry( const QString &key, bool deflt ) |
407 | { | 407 | { |
408 | QString s = readEntry( key ); | 408 | QString s = readEntry( key ); |
409 | if ( s.isEmpty() ) | 409 | if ( s.isEmpty() ) |
410 | return deflt; | 410 | return deflt; |
411 | else | 411 | else |
412 | return (bool)s.toInt(); | 412 | return (bool)s.toInt(); |
413 | } | 413 | } |
414 | 414 | ||
415 | /*! | 415 | /*! |
416 | \fn QStringList Config::readListEntry( const QString &key, const QChar &sep ) const | 416 | \fn QStringList Config::readListEntry( const QString &key, const QChar &sep ) const |
417 | Reads a string list entry stored with \a key, and with \a sep as the separator. | 417 | Reads a string list entry stored with \a key, and with \a sep as the separator. |
418 | */ | 418 | */ |
419 | 419 | ||
420 | /*! | 420 | /*! |
421 | \internal | 421 | \internal |
422 | For compatibility, non-const version. | 422 | For compatibility, non-const version. |
423 | */ | 423 | */ |
424 | QStringList Config::readListEntry( const QString &key, const QChar &sep ) | 424 | QStringList Config::readListEntry( const QString &key, const QChar &sep ) |
425 | { | 425 | { |
426 | QString s = readEntry( key ); | 426 | QString s = readEntry( key ); |
427 | if ( s.isEmpty() ) | 427 | if ( s.isEmpty() ) |
428 | return QStringList(); | 428 | return QStringList(); |
429 | else | 429 | else |
430 | return QStringList::split( sep, s ); | 430 | return QStringList::split( sep, s ); |
431 | } | 431 | } |
432 | 432 | ||
433 | /*! | 433 | /*! |
434 | Removes all entries from the current group. | 434 | Removes all entries from the current group. |
435 | */ | 435 | */ |
436 | void Config::clearGroup() | 436 | void Config::clearGroup() |
437 | { | 437 | { |
438 | if ( git == groups.end() ) { | 438 | if ( git == groups.end() ) { |
439 | qWarning( "no group set" ); | 439 | qWarning( "no group set" ); |
440 | return; | 440 | return; |
441 | } | 441 | } |
442 | if ( !(*git).isEmpty() ) { | 442 | if ( !(*git).isEmpty() ) { |
443 | ( *git ).clear(); | 443 | ( *git ).clear(); |
444 | changed = TRUE; | 444 | changed = TRUE; |
445 | } | 445 | } |
446 | } | 446 | } |
447 | 447 | ||
448 | /*! | 448 | /*! |
449 | \internal | 449 | \internal |
450 | */ | 450 | */ |
451 | void Config::write( const QString &fn ) | 451 | void Config::write( const QString &fn ) |
452 | { | 452 | { |
453 | QString strNewFile; | 453 | QString strNewFile; |
454 | if ( !fn.isEmpty() ) | 454 | if ( !fn.isEmpty() ) |
455 | filename = fn; | 455 | filename = fn; |
456 | strNewFile = filename + ".new"; | 456 | strNewFile = filename + ".new"; |
457 | 457 | ||
458 | QFile f( strNewFile ); | 458 | QFile f( strNewFile ); |
459 | if ( !f.open( IO_WriteOnly|IO_Raw ) ) { | 459 | if ( !f.open( IO_WriteOnly|IO_Raw ) ) { |
460 | qWarning( "could not open for writing `%s'", strNewFile.latin1() ); | 460 | qWarning( "could not open for writing `%s'", strNewFile.latin1() ); |
461 | git = groups.end(); | 461 | git = groups.end(); |
462 | return; | 462 | return; |
463 | } | 463 | } |
464 | 464 | ||
465 | QString str; | 465 | QString str; |
466 | QCString cstr; | 466 | QCString cstr; |
467 | QMap< QString, ConfigGroup >::Iterator g_it = groups.begin(); | 467 | QMap< QString, ConfigGroup >::Iterator g_it = groups.begin(); |
468 | 468 | ||
469 | for ( ; g_it != groups.end(); ++g_it ) { | 469 | for ( ; g_it != groups.end(); ++g_it ) { |
470 | str += "[" + g_it.key() + "]\n"; | 470 | str += "[" + g_it.key() + "]\n"; |
471 | ConfigGroup::Iterator e_it = ( *g_it ).begin(); | 471 | ConfigGroup::Iterator e_it = ( *g_it ).begin(); |
472 | for ( ; e_it != ( *g_it ).end(); ++e_it ) | 472 | for ( ; e_it != ( *g_it ).end(); ++e_it ) |
473 | str += e_it.key() + " = " + *e_it + "\n"; | 473 | str += e_it.key() + " = " + *e_it + "\n"; |
474 | } | 474 | } |
475 | cstr = str.utf8(); | 475 | cstr = str.utf8(); |
476 | 476 | ||
477 | int total_length; | 477 | int total_length; |
478 | total_length = f.writeBlock( cstr.data(), cstr.length() ); | 478 | total_length = f.writeBlock( cstr.data(), cstr.length() ); |
479 | if ( total_length != int(cstr.length()) ) { | 479 | if ( total_length != int(cstr.length()) ) { |
480 | QMessageBox::critical( 0, QObject::tr("Out of Space"), | 480 | QMessageBox::critical( 0, QObject::tr("Out of Space"), |
481 | QObject::tr("There was a problem creating\nConfiguration Information \nfor this program.\n\nPlease free up some space and\ntry again.") ); | 481 | QObject::tr("There was a problem creating\nConfiguration Information \nfor this program.\n\nPlease free up some space and\ntry again.") ); |
482 | f.close(); | 482 | f.close(); |
483 | QFile::remove( strNewFile ); | 483 | QFile::remove( strNewFile ); |
484 | return; | 484 | return; |
485 | } | 485 | } |
486 | 486 | ||
487 | f.close(); | 487 | f.close(); |
488 | // now rename the file... | 488 | // now rename the file... |
489 | if ( rename( strNewFile, filename ) < 0 ) { | 489 | if ( rename( strNewFile, filename ) < 0 ) { |
490 | qWarning( "problem renaming the file %s to %s", strNewFile.latin1(), | 490 | qWarning( "problem renaming the file %s to %s", strNewFile.latin1(), |
491 | filename.latin1() ); | 491 | filename.latin1() ); |
492 | QFile::remove( strNewFile ); | 492 | QFile::remove( strNewFile ); |
493 | } | 493 | } |
494 | } | 494 | } |
495 | 495 | ||
496 | /*! | 496 | /*! |
497 | Returns whether the Config is in a valid state. | 497 | Returns whether the Config is in a valid state. |
498 | */ | 498 | */ |
499 | bool Config::isValid() const | 499 | bool Config::isValid() const |
500 | { | 500 | { |
501 | return groups.end() != git; | 501 | return groups.end() != git; |
502 | } | 502 | } |
503 | 503 | ||
504 | /*! | 504 | /*! |
505 | \internal | 505 | \internal |
506 | */ | 506 | */ |
507 | void Config::read() | 507 | void Config::read() |
508 | { | 508 | { |
509 | changed = FALSE; | 509 | changed = FALSE; |
510 | 510 | ||
511 | if ( !QFileInfo( filename ).exists() ) { | 511 | if ( !QFileInfo( filename ).exists() ) { |
512 | git = groups.end(); | 512 | git = groups.end(); |
513 | return; | 513 | return; |
514 | } | 514 | } |
515 | 515 | ||
516 | QFile f( filename ); | 516 | QFile f( filename ); |
517 | if ( !f.open( IO_ReadOnly ) ) { | 517 | if ( !f.open( IO_ReadOnly ) ) { |
518 | git = groups.end(); | 518 | git = groups.end(); |
519 | return; | 519 | return; |
520 | } | 520 | } |
521 | 521 | ||
522 | 522 | ||
523 | // hack to avoid problems if big files are passed to test | 523 | // hack to avoid problems if big files are passed to test |
524 | // if they are valid configs ( like passing a mp3 ... ) | 524 | // if they are valid configs ( like passing a mp3 ... ) |
525 | // I just hope that there are no conf files > 100000 byte | 525 | // I just hope that there are no conf files > 100000 byte |
526 | // not the best solution, find something else later | 526 | // not the best solution, find something else later |
527 | if ( f.getch()!='[' ||f.size() > 100000 ) { | 527 | if ( f.getch()!='[' ||f.size() > 100000 ) { |
528 | git = groups.end(); | 528 | git = groups.end(); |
529 | return; | 529 | return; |
530 | } | 530 | } |
531 | f.ungetch('['); | 531 | f.ungetch('['); |
532 | 532 | ||
533 | 533 | ||
534 | QTextStream s( &f ); | 534 | QTextStream s( &f ); |
535 | #if QT_VERSION <= 230 && defined(QT_NO_CODECS) | 535 | #if QT_VERSION <= 230 && defined(QT_NO_CODECS) |
536 | // The below should work, but doesn't in Qt 2.3.0 | 536 | // The below should work, but doesn't in Qt 2.3.0 |
537 | s.setCodec( QTextCodec::codecForMib( 106 ) ); | 537 | s.setCodec( QTextCodec::codecForMib( 106 ) ); |
538 | #else | 538 | #else |
539 | s.setEncoding( QTextStream::UnicodeUTF8 ); | 539 | s.setEncoding( QTextStream::UnicodeUTF8 ); |
540 | #endif | 540 | #endif |
541 | 541 | ||
542 | QStringList list = QStringList::split('\n', s.read() ); | 542 | QStringList list = QStringList::split('\n', s.read() ); |
543 | f.close(); | 543 | f.close(); |
544 | 544 | ||
545 | for ( QStringList::Iterator it = list.begin(); it != list.end(); ++it ) { | 545 | for ( QStringList::Iterator it = list.begin(); it != list.end(); ++it ) { |
546 | if ( !parse( *it ) ) { | 546 | if ( !parse( *it ) ) { |
547 | git = groups.end(); | 547 | git = groups.end(); |
548 | return; | 548 | return; |
549 | } | 549 | } |
550 | } | 550 | } |
551 | } | 551 | } |
552 | 552 | ||
553 | /*! | 553 | /*! |
554 | \internal | 554 | \internal |
555 | */ | 555 | */ |
556 | bool Config::parse( const QString &l ) | 556 | bool Config::parse( const QString &l ) |
557 | { | 557 | { |
558 | QString line = l.stripWhiteSpace(); | 558 | QString line = l.stripWhiteSpace(); |
559 | 559 | ||
560 | if ( line [0] == QChar ( '#' )) | 560 | if ( line [0] == QChar ( '#' )) |
561 | return true; // ignore comments | 561 | return true; // ignore comments |
562 | 562 | ||
563 | if ( line[ 0 ] == QChar( '[' ) ) { | 563 | if ( line[ 0 ] == QChar( '[' ) ) { |
564 | QString gname = line; | 564 | QString gname = line; |
565 | gname = gname.remove( 0, 1 ); | 565 | gname = gname.remove( 0, 1 ); |
566 | if ( gname[ (int)gname.length() - 1 ] == QChar( ']' ) ) | 566 | if ( gname[ (int)gname.length() - 1 ] == QChar( ']' ) ) |
567 | gname = gname.remove( gname.length() - 1, 1 ); | 567 | gname = gname.remove( gname.length() - 1, 1 ); |
568 | git = groups.insert( gname, ConfigGroup() ); | 568 | git = groups.insert( gname, ConfigGroup() ); |
569 | } else if ( !line.isEmpty() ) { | 569 | } else if ( !line.isEmpty() ) { |
570 | if ( git == groups.end() ) | 570 | if ( git == groups.end() ) |
571 | return FALSE; | 571 | return FALSE; |
572 | int eq = line.find( '=' ); | 572 | int eq = line.find( '=' ); |
573 | if ( eq == -1 ) | 573 | if ( eq == -1 ) |
574 | return FALSE; | 574 | return FALSE; |
575 | QString key = line.left(eq).stripWhiteSpace(); | 575 | QString key = line.left(eq).stripWhiteSpace(); |
576 | QString value = line.mid(eq+1).stripWhiteSpace(); | 576 | QString value = line.mid(eq+1).stripWhiteSpace(); |
577 | ( *git ).insert( key, value ); | 577 | ( *git ).insert( key, value ); |
578 | } | 578 | } |
579 | return TRUE; | 579 | return TRUE; |
580 | } | 580 | } |