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) (side-by-side diff) | |
tree | 8ee90d686081c52e7c69b5ce946e9b1a7d690001 /microkde/kconfig.cpp | |
parent | 11edc920afe4f274c0964436633aa632c8288a40 (diff) | |
download | kdepimpi-a08aff328d4393031d5ba7d622c2b05705a89d73.zip kdepimpi-a08aff328d4393031d5ba7d622c2b05705a89d73.tar.gz kdepimpi-a08aff328d4393031d5ba7d622c2b05705a89d73.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,19 +1,21 @@ #include <qfile.h> -#include <qtextstream.h> +#include <q3textstream.h> #include <qwidget.h> +//Added by qt3to4: +#include <Q3ValueList> #include "kdebug.h" #include "kurl.h" #include "kstandarddirs.h" #include "kconfig.h" QString KConfig::mGroup = ""; //QString KConfig::mGroup = "General"; KConfig::KConfig( const QString &fileName ) : mFileName( fileName ), mDirty( false ) { mTempGroup = ""; load(); @@ -40,37 +42,37 @@ QString KConfig::tempGroup() const { void KConfig::setGroup( const QString &group ) { mGroup = group; if ( mGroup.right( 1 ) != "/" ) mGroup += "/"; } //US QString KConfig::group() const { return mGroup; } //US added method -QValueList<int> KConfig::readIntListEntry( const QString & key) +Q3ValueList<int> KConfig::readIntListEntry( const QString & key) { // qDebug("KConfig::readIntListEntry key=%s:", key.latin1()); - QValueList<int> result; + Q3ValueList<int> result; QMap<QString,QString>::ConstIterator mit = mStringMap.find( mGroup + key ); if ( mit == mStringMap.end() ) { return result; } QStringList valuesAsStrings = QStringList::split(":", *mit ); bool ok = false; bool ok2 = true; int val; for ( QStringList::Iterator sit = valuesAsStrings.begin(); sit != valuesAsStrings.end(); ++sit ) { val = (*sit).toInt(&ok); result << val; if (ok == false) { @@ -98,33 +100,33 @@ int KConfig::readNumEntry( const QString & key, int def ) return def; } QString KConfig::readEntry( const QString &key, const QString &def ) { QMap<QString,QString>::ConstIterator it = mStringMap.find( mGroup + key ); if ( it == mStringMap.end() ) { return def; } return QString::fromUtf8((*it).latin1()); } QSize KConfig::readSizeEntry( const QString &key, QSize* def ) { - QValueList<int> intlist = readIntListEntry(key); + Q3ValueList<int> intlist = readIntListEntry(key); if (intlist.count() < 2) { if (def) return *def; else return QSize(); } QSize ret; ret.setWidth(intlist[0]); ret.setHeight(intlist[1]); return ret; } @@ -181,37 +183,37 @@ QFont KConfig::readFontEntry( const QString & e, QFont *def ) return f; } QDateTime KConfig::readDateTimeEntry( const QString &key, const QDateTime *def ) { QMap<QString,QDateTime>::ConstIterator it = mDateTimeMap.find( mGroup + key ); if ( it == mDateTimeMap.end() ) { if ( def ) return *def; else return QDateTime(); } return *it; } //US added method -void KConfig::writeEntry( const QString &key, const QValueList<int> &value) +void KConfig::writeEntry( const QString &key, const Q3ValueList<int> &value) { QStringList valuesAsStrings; - QValueList<int>::ConstIterator it; + Q3ValueList<int>::ConstIterator it; for( it = value.begin(); it != value.end(); ++it ) { valuesAsStrings << QString::number(*it); } mStringMap.insert( mGroup + key, valuesAsStrings.join(":") ); mDirty = true; } void KConfig::writeEntry( const QString & key , int num ) { writeEntry( key, QString::number ( num ) ); } void KConfig::writeEntry( const QString &key, const QString &value ) @@ -233,71 +235,71 @@ void KConfig::writeEntry( const QString &key, bool value) mBoolMap.insert( mGroup + key, value ); mDirty = true; } void KConfig::writeEntry( const QString & e, const QColor & c ) { QStringList l; l.append( QString::number ( c.red() ) ); l.append( QString::number ( c.green() ) ); l.append( QString::number ( c.blue() ) ); writeEntry( e.utf8(), l ); } void KConfig::writeEntry( const QString & e, const QSize & s ) { - QValueList<int> intlist; + Q3ValueList<int> intlist; intlist << s.width() << s.height(); writeEntry( e, intlist ); } void KConfig::writeEntry( const QString & e , const QFont & f ) { QStringList font; font.append( f.family()); font.append( (!f.bold ()?"nonbold":"bold") ); font.append( QString::number ( f.pointSize () ) ); font.append( !f.italic ()?"nonitalic":"italic" ); writeEntry( e, font ); } void KConfig::writeEntry( const QString &key, const QDateTime &dt ) { mDateTimeMap.insert( mGroup + key, dt ); } void KConfig::load() { QFile f( mFileName ); - if ( !f.open( IO_ReadOnly ) ) { + if ( !f.open( QIODevice::ReadOnly ) ) { //qDebug("KConfig: could not open file %s ",mFileName.latin1() ); return; } mBoolMap.clear(); mStringMap.clear(); - QTextStream t( &f ); - t.setEncoding( QTextStream::Latin1 ); + Q3TextStream t( &f ); + t.setEncoding( Q3TextStream::Latin1 ); QString line = t.readLine(); while ( !line.isNull() ) { - QStringList tokens = QStringList::split( ",", line ); + QStringList tokens = line.split(','); if ( tokens[0] == "bool" ) { bool value = false; if ( tokens[2] == "1" ) value = true; mBoolMap.insert( tokens[1], value ); } else if ( tokens[0] == "QString" ) { QString value = tokens[2]; mStringMap.insert( tokens[1], value ); } else if ( tokens[0] == "QDateTime" ) { #if 0 int year = tokens[2].toInt(); QDateTime dt( QDate( year, tokens[3].toInt(), tokens[4].toInt() ), QTime( tokens[5].toInt(), tokens[6].toInt(), tokens[7].toInt() ) ); mDateTimeMap.insert( tokens[1], dt ); @@ -310,41 +312,41 @@ void KConfig::load() void KConfig::sync() { if ( !mDirty ) return; //qDebug("KConfig::sync() %s ",mFileName.latin1() ); //kdDebug() << "KConfig::sync(): " << mFileName << endl; //US I took the following code from a newer version of KDE // Create the containing dir if needed KURL path; path.setPath(mFileName); QString dir=path.directory(); KStandardDirs::makeDir(dir); QFile f( mFileName ); - if ( !f.open( IO_WriteOnly ) ) { + if ( !f.open( QIODevice::WriteOnly ) ) { qDebug("KConfig::sync() Can't open file %s ",mFileName.latin1() ); return; } - QTextStream t( &f ); - t.setEncoding( QTextStream::Latin1 ); + Q3TextStream t( &f ); + t.setEncoding( Q3TextStream::Latin1 ); QMap<QString,bool>::ConstIterator itBool; for( itBool = mBoolMap.begin(); itBool != mBoolMap.end(); ++itBool ) { t << "bool," << itBool.key() << "," << ( *itBool ? "1" : "0" ) << endl; } QMap<QString,QString>::ConstIterator itString; for( itString = mStringMap.begin(); itString != mStringMap.end(); ++itString ) { t << "QString," << itString.key() << "," << (*itString ) << endl; } QMap<QString,QDateTime>::ConstIterator itDateTime; for( itDateTime = mDateTimeMap.begin(); itDateTime != mDateTimeMap.end(); ++itDateTime ) { QDateTime dt = *itDateTime; t << "QDateTime," << itDateTime.key() << "," << dt.date().year() << "," << dt.date().month() << "," |