summaryrefslogtreecommitdiff
path: root/library/config.cpp
Unidiff
Diffstat (limited to 'library/config.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--library/config.cpp26
1 files changed, 18 insertions, 8 deletions
diff --git a/library/config.cpp b/library/config.cpp
index b47c620..b28c771 100644
--- a/library/config.cpp
+++ b/library/config.cpp
@@ -460,42 +460,42 @@ void Config::write( const QString &fn )
460 QFile f( strNewFile ); 460 QFile f( strNewFile );
461 if ( !f.open( IO_WriteOnly|IO_Raw ) ) { 461 if ( !f.open( IO_WriteOnly|IO_Raw ) ) {
462 qWarning( "could not open for writing `%s'", strNewFile.latin1() ); 462 qWarning( "could not open for writing `%s'", strNewFile.latin1() );
463 git = groups.end(); 463 git = groups.end();
464 return; 464 return;
465 } 465 }
466 466
467 QString str; 467 QString str;
468 QCString cstr; 468 QCString cstr;
469 QMap< QString, ConfigGroup >::Iterator g_it = groups.begin(); 469 QMap< QString, ConfigGroup >::Iterator g_it = groups.begin();
470 470
471 for ( ; g_it != groups.end(); ++g_it ) { 471 for ( ; g_it != groups.end(); ++g_it ) {
472 str += "[" + g_it.key() + "]\n"; 472 str += "[" + g_it.key() + "]\n";
473 ConfigGroup::Iterator e_it = ( *g_it ).begin(); 473 ConfigGroup::Iterator e_it = ( *g_it ).begin();
474 for ( ; e_it != ( *g_it ).end(); ++e_it ) 474 for ( ; e_it != ( *g_it ).end(); ++e_it )
475 str += e_it.key() + " = " + *e_it + "\n"; 475 str += e_it.key() + " = " + *e_it + "\n";
476 } 476 }
477 cstr = str.utf8(); 477 cstr = str.utf8();
478 478
479 int total_length; 479 int total_length;
480 total_length = f.writeBlock( cstr.data(), cstr.length() ); 480 total_length = f.writeBlock( cstr.data(), cstr.length() );
481 if ( total_length != int(cstr.length()) ) { 481 if ( total_length != int(cstr.length()) ) {
482 QMessageBox::critical( 0, QObject::tr("Out of Space"), 482 QMessageBox::critical( 0, QObject::tr("Out of Space"),
483 QObject::tr("There was a problem creating\nConfiguration Information \nfor this program.\n\nPlease free up some space and\ntry again.") ); 483 QObject::tr("There was a problem creating\nConfiguration Information \nfor this program.\n\nPlease free up some space and\ntry again.") );
484 f.close(); 484 f.close();
485 QFile::remove( strNewFile ); 485 QFile::remove( strNewFile );
486 return; 486 return;
487 } 487 }
488 488
489 f.close(); 489 f.close();
490 // now rename the file... 490 // now rename the file...
491 if ( rename( strNewFile, filename ) < 0 ) { 491 if ( rename( strNewFile, filename ) < 0 ) {
492 qWarning( "problem renaming the file %s to %s", strNewFile.latin1(), 492 qWarning( "problem renaming the file %s to %s", strNewFile.latin1(),
493 filename.latin1() ); 493 filename.latin1() );
494 QFile::remove( strNewFile ); 494 QFile::remove( strNewFile );
495 } 495 }
496} 496}
497 497
498/*! 498/*!
499 Returns whether the Config is in a valid state. 499 Returns whether the Config is in a valid state.
500*/ 500*/
501bool Config::isValid() const 501bool Config::isValid() const
@@ -518,12 +518,22 @@ void Config::read()
518 QFile f( filename ); 518 QFile f( filename );
519 if ( !f.open( IO_ReadOnly ) ) { 519 if ( !f.open( IO_ReadOnly ) ) {
520 git = groups.end(); 520 git = groups.end();
521 return; 521 return;
522 } 522 }
523 523
524
525 // hack to avoid problems if big files are passed to test
526 // if they are valid configs ( like passing a mp3 ... )
527 // I just hope that there are no conf files > 100000 byte
528 // not the best solution, find something else later
529 if ( f.size() > 100000 ) {
530 return;
531 }
532
533
524 QTextStream s( &f ); 534 QTextStream s( &f );
525#if QT_VERSION <= 230 && defined(QT_NO_CODECS) 535#if QT_VERSION <= 230 && defined(QT_NO_CODECS)
526 // 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
527 s.setCodec( QTextCodec::codecForMib( 106 ) ); 537 s.setCodec( QTextCodec::codecForMib( 106 ) );
528#else 538#else
529 s.setEncoding( QTextStream::UnicodeUTF8 ); 539 s.setEncoding( QTextStream::UnicodeUTF8 );
@@ -543,16 +553,16 @@ void Config::read()
543/*! 553/*!
544 \internal 554 \internal
545*/ 555*/
546bool Config::parse( const QString &l ) 556bool Config::parse( const QString &l )
547{ 557{
548 QString line = l.stripWhiteSpace(); 558 QString line = l.stripWhiteSpace();
549 559
550 if ( line [0] == QChar ( '#' )) 560 if ( line [0] == QChar ( '#' ))
551 return true; // ignore comments 561 return true; // ignore comments
552 562
553 if ( line[ 0 ] == QChar( '[' ) ) { 563 if ( line[ 0 ] == QChar( '[' ) ) {
554 QString gname = line; 564 QString gname = line;
555 gname = gname.remove( 0, 1 ); 565 gname = gname.remove( 0, 1 );
556 if ( gname[ (int)gname.length() - 1 ] == QChar( ']' ) ) 566 if ( gname[ (int)gname.length() - 1 ] == QChar( ']' ) )
557 gname = gname.remove( gname.length() - 1, 1 ); 567 gname = gname.remove( gname.length() - 1, 1 );
558 git = groups.insert( gname, ConfigGroup() ); 568 git = groups.insert( gname, ConfigGroup() );