Commit 585b005e authored by Jan Möbius's avatar Jan Möbius

Removed patches



git-svn-id: http://www.openflipper.org/svnrepo/OpenFlipper/branches/Free@15768 383ad7c9-94d9-4d36-a494-682f7c89f535
parent e9d91d23
Index: INIFile/INIFile.cc
===================================================================
--- INIFile/INIFile.cc (revision 13956)
+++ INIFile/INIFile.cc (working copy)
@@ -59,11 +59,13 @@
#include <QTextStream>
#include <QStringList>
+const int versionID=2;
// -----------------------------------------------------------------------------
-INIFile::INIFile()
+INIFile::INIFile() :
+ filename_(""),
+ content_(0)
{
- mf_isConnected = false;
}
@@ -78,24 +80,28 @@
// -----------------------------------------------------------------------------
bool INIFile::connect( const QString& _filename,
- const bool _create )
+ const bool _create )
{
+
QFile inputFile( _filename );
if( is_connected() )
disconnect();
// open given file for reading
- if ( inputFile.exists() && inputFile.open(QIODevice::ReadOnly | QIODevice::Text) ) {
+ if ( inputFile.exists() ) {
+ content_ = new QSettings(_filename,QSettings::IniFormat);
- // Successfull?
- m_filename = _filename;
+ filename_ = _filename;
- // try to parse the INI file
- mf_isConnected = parseFile( inputFile );
+ // Try to get the version of our ini file compatibility flag
+ if ( content_->contains("FileVersion") ) {
+ int fileVersion = content_->value("FileVersion").toInt();
+ if ( fileVersion != versionID ) {
+ std::cerr << "Incompatible ini file version version detected!" << std::endl;
+ }
+ }
- inputFile.close();
-
} else if( _create ) {
// file does not exist yet, but user wants to create it.
@@ -106,23 +112,24 @@
QIODevice::WriteOnly |
QIODevice::Truncate ) ) {
- mf_isConnected = true;
- m_filename = _filename;
outputFile.close();
- } else {
+ content_ = new QSettings(_filename,QSettings::IniFormat);
- std::cerr << "Unable to create File : " << std::endl;
- mf_isConnected = false;
+ filename_ = _filename;
+ // Set the file version
+ content_->setValue("FileVersion",versionID);
+
+ } else {
+ std::cerr << "Failed to connect!" << std::endl;
}
} else {
std::cerr << "Unable to open File : " << std::endl;
- mf_isConnected = false;
}
- return mf_isConnected;
+ return is_connected();
}
@@ -131,133 +138,39 @@
void INIFile::disconnect()
{
- writeFile();
- mf_isConnected = false;
-}
-
-
-// -----------------------------------------------------------------------------
-
-bool INIFile::parseFile( QFile & _inputStream )
-{
- QString line, section;
- bool inSection = false;
-
- // read file line by line
- while( !_inputStream.atEnd() ) {
-
- // get new line
- QByteArray lineBuffer = _inputStream.readLine();
- line = QString(lineBuffer);
- line = line.trimmed();
-
- if( line.isEmpty() || line[ 0 ] == '#' )
- continue;
-
- // does line contain the start of a section?
- if( line[ 0 ] == '[' && line[ line.length()-1 ] == ']' ) {
-
- // yes
- section = line.mid( 1, line.length() - 2 );
- inSection = true;
-
- } else if( inSection ) {
- // try to split line into a key and a value
- QString key, value;
-
- int pos;
- pos = line.indexOf( '=' );
-
- if( pos != -1 )
- {
- key = line.mid( 0, pos );
- key = key.trimmed();
- value = line.mid( pos + 1, line.length() - 1 );
- value = value.trimmed();
-
- if( key.isEmpty() || value.isEmpty() )
- continue;
-
- // store value in string-map
- m_iniData[ section ][ key ] = value;
- }
-
- }
+ if ( content_) {
+ content_->sync();
+ delete(content_);
+ content_ = 0;
+ filename_ = "";
}
-
- return true;
}
-
// -----------------------------------------------------------------------------
-bool INIFile::writeFile( void )
+bool INIFile::section_exists( const QString & _section )
{
- if( !mf_isConnected )
- return false;
-
- // open file for writing
- QFile outputFile(m_filename);
-
- if ( ! outputFile.open( QIODevice::WriteOnly ) )
- return false;
-
- QTextStream out(&outputFile);
-
- // file is open, start writing of data
- SectionMap::const_iterator sIter, sEnd;
- EntryMap::const_iterator eIter, eEnd;
-
- sEnd = m_iniData.end();
- for( sIter = m_iniData.begin(); sIter != sEnd; ++sIter ) {
- // write name of current section
- out << "[" << sIter->first << "]\n";
-
- eEnd = sIter->second.end();
- for( eIter = sIter->second.begin(); eIter != eEnd; ++eIter ) {
- out << eIter->first << "=";
- out << eIter->second;
- out << "\n";
- }
-
- out << "\n\n";
- }
-
- outputFile.close();
-
- return true;
+ return( content_->childGroups().contains(_section) );
}
-
// -----------------------------------------------------------------------------
-bool INIFile::section_exists( const QString & _section ) const
+bool INIFile::entry_exists(const QString & _section, const QString & _key)
{
- return( m_iniData.find( _section ) != m_iniData.end() );
-}
+ bool exists = false;
-// -----------------------------------------------------------------------------
+ content_->beginGroup(_section);
+ exists = content_->childKeys().contains(_key);
-bool INIFile::entry_exists(const QString & _section, const QString & _key) const
-{
- static SectionMap::const_iterator mapIter;
+ content_->endGroup();
- return( (mapIter = m_iniData.find( _section )) != m_iniData.end()
- && mapIter->second.find( _key ) != mapIter->second.end() );
-}
-
-// -----------------------------------------------------------------------------
-
-void INIFile::add_section( const QString & _sectionname )
-{
- if( m_iniData.find( _sectionname ) == m_iniData.end() )
- m_iniData[ _sectionname ] = EntryMap();
+ return( exists );
}
@@ -265,10 +178,12 @@
void INIFile::add_entry( const QString & _section,
- const QString & _key,
- const QString & _value )
+ const QString & _key,
+ const QString & _value )
{
- m_iniData[ _section ][ _key ] = _value;
+ content_->beginGroup(_section);
+ content_->setValue(_key,_value);
+ content_->endGroup();
}
@@ -276,10 +191,12 @@
void INIFile::add_entry( const QString & _section,
- const QString & _key,
- const double & _value)
+ const QString & _key,
+ const double & _value)
{
- m_iniData[ _section ][ _key ] = QString::number( _value );
+ content_->beginGroup(_section);
+ content_->setValue(_key,_value);
+ content_->endGroup();
}
@@ -287,10 +204,12 @@
void INIFile::add_entry( const QString & _section,
- const QString & _key,
- const float & _value)
+ const QString & _key,
+ const float & _value)
{
- m_iniData[ _section ][ _key ] = QString::number( _value );
+ content_->beginGroup(_section);
+ content_->setValue(_key,_value);
+ content_->endGroup();
}
@@ -298,10 +217,12 @@
void INIFile::add_entry( const QString & _section,
- const QString & _key ,
- const int & _value)
+ const QString & _key ,
+ const int & _value)
{
- m_iniData[ _section ][ _key ] = QString::number( _value );
+ content_->beginGroup(_section);
+ content_->setValue(_key,_value);
+ content_->endGroup();
}
@@ -309,10 +230,12 @@
void INIFile::add_entry( const QString & _section,
- const QString & _key ,
- const unsigned int & _value)
+ const QString & _key ,
+ const unsigned int & _value)
{
- m_iniData[ _section ][ _key ] = QString::number( _value );
+ content_->beginGroup(_section);
+ content_->setValue(_key,_value);
+ content_->endGroup();
}
@@ -320,10 +243,12 @@
void INIFile::add_entry( const QString & _section,
- const QString & _key ,
- const bool & _value)
+ const QString & _key ,
+ const bool & _value)
{
- m_iniData[ _section ][ _key ] = (_value ? "true" : "false");
+ content_->beginGroup(_section);
+ content_->setValue(_key,_value);
+ content_->endGroup();
}
@@ -331,14 +256,16 @@
void INIFile::add_entry( const QString & _section,
- const QString & _key,
- const std::vector<float> & _value)
+ const QString & _key,
+ const std::vector<float> & _value)
{
- QString list;
- std::vector<float>::const_iterator viter;
- for(viter = _value.begin();viter!=_value.end();++viter)
- list += QString::number( *viter ) + ";";
- m_iniData[ _section ][ _key ] = list;
+ QList<QVariant> list;
+ for ( unsigned int i = 0 ; i < _value.size() ; ++i )
+ list.append(_value[i]);
+
+ content_->beginGroup(_section);
+ content_->setValue(_key,list);
+ content_->endGroup();
}
@@ -349,11 +276,13 @@
const QString & _key,
const std::vector<double> & _value)
{
- QString list;
- std::vector<double>::const_iterator viter;
- for(viter = _value.begin();viter!=_value.end();++viter)
- list += QString::number( *viter ) + ";";
- m_iniData[ _section ][ _key ] = list;
+ QList<QVariant> list;
+ for ( unsigned int i = 0 ; i < _value.size() ; ++i )
+ list.append(_value[i]);
+
+ content_->beginGroup(_section);
+ content_->setValue(_key,list);
+ content_->endGroup();
}
@@ -364,53 +293,55 @@
const QString & _key,
const std::vector<bool> & _value)
{
- QString list;
- std::vector<bool>::const_iterator viter;
- for(viter = _value.begin();viter!=_value.end();++viter){
- if (*viter == true)
- list += "true;";
- else
- list += "false;";
- }
- m_iniData[ _section ][ _key ] = list;
+ QList<QVariant> list;
+ for ( unsigned int i = 0 ; i < _value.size() ; ++i )
+ list.append(_value[i]);
+
+ content_->beginGroup(_section);
+ content_->setValue(_key,list);
+ content_->endGroup();
}
// -----------------------------------------------------------------------------
void INIFile::add_entry( const QString & _section,
- const QString & _key,
- const std::vector<int> & _value)
+ const QString & _key,
+ const std::vector<int> & _value)
{
- QString list;
- std::vector<int>::const_iterator viter;
- for(viter = _value.begin();viter!=_value.end();++viter)
- list += QString::number( *viter ) + ";";
- m_iniData[ _section ][ _key ] = list;
+ QList<QVariant> list;
+ for ( unsigned int i = 0 ; i < _value.size() ; ++i )
+ list.append(_value[i]);
+
+ content_->beginGroup(_section);
+ content_->setValue(_key,list);
+ content_->endGroup();
}
// -----------------------------------------------------------------------------
void INIFile::add_entry( const QString & _section,
- const QString & _key,
- const std::vector<QString> & _value)
+ const QString & _key,
+ const std::vector<QString> & _value)
{
- QString list;
- std::vector<QString>::const_iterator viter;
- for(viter = _value.begin();viter!=_value.end();++viter) {
- list += *viter + ";";
- }
- m_iniData[ _section ][ _key ] = list;
+ QList<QVariant> list;
+ for ( unsigned int i = 0 ; i < _value.size() ; ++i )
+ list.append(_value[i]);
+
+ content_->beginGroup(_section);
+ content_->setValue(_key,list);
+ content_->endGroup();
}
// -----------------------------------------------------------------------------
void INIFile::add_entry( const QString & _section,
- const QString & _key,
- const QStringList & _value)
+ const QString & _key,
+ const QStringList & _value)
{
- QString list = _value.join(";");
- m_iniData[ _section ][ _key ] = list;
+ content_->beginGroup(_section);
+ content_->setValue(_key,_value);
+ content_->endGroup();
}
@@ -418,14 +349,9 @@
void INIFile::delete_entry( const QString & _section, const QString & _key )
{
- SectionMap::iterator sIter;
- EntryMap::iterator eIter;
-
- if( (sIter = m_iniData.find( _section )) == m_iniData.end() )
- return;
-
- if( (eIter = sIter->second.find( _key )) != sIter->second.end() )
- sIter->second.erase( eIter );
+ content_->beginGroup(_section);
+ content_->remove(_key);
+ content_->endGroup();
}
@@ -433,7 +359,7 @@
void INIFile::delete_section( const QString & _sectionname )
{
- m_iniData.erase( _sectionname );
+ content_->remove(_sectionname);
}
@@ -441,22 +367,22 @@
bool INIFile::get_entry( QString & _val,
- const QString & _section,
- const QString & _key ) const
+ const QString & _section,
+ const QString & _key ) const
{
- SectionMap::const_iterator sIter;
- EntryMap::const_iterator eIter;
- // does the given section exist?
- if( (sIter = m_iniData.find( _section )) == m_iniData.end() )
- return false;
+ bool found = false;
- // does the given entry exist?
- if( (eIter = sIter->second.find( _key )) == sIter->second.end() )
- return false;
+ content_->beginGroup(_section);
- _val = eIter->second;
- return true;
+ if ( content_->contains(_key)) {
+ found = true;
+ _val = content_->value(_key).toString();
+ }
+
+ content_->endGroup();
+
+ return found;
}
@@ -464,23 +390,22 @@
bool INIFile::get_entry( double & _val,
- const QString & _section,
- const QString & _key ) const
+ const QString & _section,
+ const QString & _key ) const
{
- SectionMap::const_iterator sIter;
- EntryMap::const_iterator eIter;
- // does the given section exist?
- if( (sIter = m_iniData.find( _section )) == m_iniData.end() )
- return false;
+ bool found = false;
- // does the given entry exist?
- if( (eIter = sIter->second.find( _key )) == sIter->second.end() )
- return false;
+ content_->beginGroup(_section);
- bool ok;
- _val = eIter->second.toDouble(&ok);
- return( ok );
+ if ( content_->contains(_key)) {
+ found = true;
+ _val = content_->value(_key).toFloat(&found);
+ }
+
+ content_->endGroup();
+
+ return found;
}
@@ -488,23 +413,22 @@
bool INIFile::get_entry( float & _val,
- const QString & _section,
- const QString & _key ) const
+ const QString & _section,
+ const QString & _key ) const
{
- SectionMap::const_iterator sIter;
- EntryMap::const_iterator eIter;
- // does the given section exist?
- if( (sIter = m_iniData.find( _section )) == m_iniData.end() )
- return false;
+ bool found = false;
- // does the given entry exist?
- if( (eIter = sIter->second.find( _key )) == sIter->second.end() )
- return false;
+ content_->beginGroup(_section);
- bool ok;
- _val = eIter->second.toFloat(&ok);
- return( ok );
+ if ( content_->contains(_key)) {
+ found = true;
+ _val = content_->value(_key).toFloat(&found);
+ }
+
+ content_->endGroup();
+
+ return found;
}
@@ -512,46 +436,44 @@
bool INIFile::get_entry( int & _val,
- const QString & _section,
- const QString & _key ) const
+ const QString & _section,
+ const QString & _key ) const
{
- SectionMap::const_iterator sIter;
- EntryMap::const_iterator eIter;
- // does the given section exist?
- if( (sIter = m_iniData.find( _section )) == m_iniData.end() )
- return false;
+ bool found = false;
- // does the given entry exist?
- if( (eIter = sIter->second.find( _key )) == sIter->second.end() )
- return false;
+ content_->beginGroup(_section);
- bool ok;
- _val = eIter->second.toInt(&ok);
- return( ok );
+ if ( content_->contains(_key)) {
+ found = true;
+ _val = content_->value(_key).toInt(&found);
+ }
+
+ content_->endGroup();
+
+ return found;
}
// -----------------------------------------------------------------------------
bool INIFile::get_entry( unsigned int & _val,
- const QString & _section,
- const QString & _key ) const
+ const QString & _section,
+ const QString & _key ) const
{
- SectionMap::const_iterator sIter;
- EntryMap::const_iterator eIter;
- // does the given section exist?
- if( (sIter = m_iniData.find( _section )) == m_iniData.end() )
- return false;
+ bool found = false;
- // does the given entry exist?
- if( (eIter = sIter->second.find( _key )) == sIter->second.end() )
- return false;
+ content_->beginGroup(_section);
- bool ok;
- _val = eIter->second.toUInt(&ok);
- return( ok );
+ if ( content_->contains(_key)) {
+ found = true;
+ _val = content_->value(_key).toUInt(&found);
+ }
+
+ content_->endGroup();
+
+ return found;
}
@@ -559,26 +481,22 @@
bool INIFile::get_entry( bool & _val,
- const QString & _section,
- const QString & _key) const
+ const QString & _section,
+ const QString & _key) const