00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023 #include <stdlib.h>
00024 #include <string.h>
00025
00026 #include <qfile.h>
00027 #include <qdir.h>
00028 #include <qtextstream.h>
00029
00030 #include <kapplication.h>
00031 #include <kglobal.h>
00032 #include <klocale.h>
00033 #include <kcharsets.h>
00034
00035 #include "kconfigbase.h"
00036 #include "kconfigbackend.h"
00037 #include "kdebug.h"
00038 #include "kstandarddirs.h"
00039 #include "kstringhandler.h"
00040
00041 class KConfigBase::KConfigBasePrivate
00042 {
00043 public:
00044 KConfigBasePrivate() : readDefaults(false) { };
00045
00046 public:
00047 bool readDefaults;
00048 };
00049
00050 KConfigBase::KConfigBase()
00051 : backEnd(0L), bDirty(false), bLocaleInitialized(false),
00052 bReadOnly(false), bExpand(false), d(0)
00053 {
00054 setGroup(QString::null);
00055 }
00056
00057 KConfigBase::~KConfigBase()
00058 {
00059 delete d;
00060 }
00061
00062 void KConfigBase::setLocale()
00063 {
00064 bLocaleInitialized = true;
00065
00066 if (KGlobal::locale())
00067 aLocaleString = KGlobal::locale()->language().utf8();
00068 else
00069 aLocaleString = KLocale::defaultLanguage().utf8();
00070 if (backEnd)
00071 backEnd->setLocaleString(aLocaleString);
00072 }
00073
00074 QString KConfigBase::locale() const
00075 {
00076 return QString::fromUtf8(aLocaleString);
00077 }
00078
00079 void KConfigBase::setGroup( const QString& group )
00080 {
00081 if ( group.isEmpty() )
00082 mGroup = "<default>";
00083 else
00084 mGroup = group.utf8();
00085 }
00086
00087 void KConfigBase::setGroup( const char *pGroup )
00088 {
00089 setGroup(QCString(pGroup));
00090 }
00091
00092 void KConfigBase::setGroup( const QCString &group )
00093 {
00094 if ( group.isEmpty() )
00095 mGroup = "<default>";
00096 else
00097 mGroup = group;
00098 }
00099
00100 QString KConfigBase::group() const {
00101 return QString::fromUtf8(mGroup);
00102 }
00103
00104 void KConfigBase::setDesktopGroup()
00105 {
00106 mGroup = "Desktop Entry";
00107 }
00108
00109 bool KConfigBase::hasKey(const QString &key) const
00110 {
00111 return hasKey(key.utf8().data());
00112 }
00113
00114 bool KConfigBase::hasKey(const char *pKey) const
00115 {
00116 KEntryKey aEntryKey(mGroup, 0);
00117 aEntryKey.c_key = pKey;
00118 aEntryKey.bDefault = readDefaults();
00119
00120 if (!locale().isNull()) {
00121
00122 aEntryKey.bLocal = true;
00123 KEntry entry = lookupData(aEntryKey);
00124 if (!entry.mValue.isNull())
00125 return true;
00126 aEntryKey.bLocal = false;
00127 }
00128
00129
00130 KEntry entry = lookupData(aEntryKey);
00131 return !entry.mValue.isNull();
00132 }
00133
00134 bool KConfigBase::hasGroup(const QString &group) const
00135 {
00136 return internalHasGroup( group.utf8());
00137 }
00138
00139 bool KConfigBase::hasGroup(const char *_pGroup) const
00140 {
00141 return internalHasGroup( QCString(_pGroup));
00142 }
00143
00144 bool KConfigBase::hasGroup(const QCString &_pGroup) const
00145 {
00146 return internalHasGroup( _pGroup);
00147 }
00148
00149 bool KConfigBase::isImmutable() const
00150 {
00151 return (getConfigState() != ReadWrite);
00152 }
00153
00154 bool KConfigBase::groupIsImmutable(const QString &group) const
00155 {
00156 if (getConfigState() != ReadWrite)
00157 return true;
00158
00159 KEntryKey groupKey(group.utf8(), 0);
00160 KEntry entry = lookupData(groupKey);
00161 return entry.bImmutable;
00162 }
00163
00164 bool KConfigBase::entryIsImmutable(const QString &key) const
00165 {
00166 if (getConfigState() != ReadWrite)
00167 return true;
00168
00169 KEntryKey entryKey(mGroup, 0);
00170 KEntry aEntryData = lookupData(entryKey);
00171 if (aEntryData.bImmutable)
00172 return true;
00173
00174 QCString utf8_key = key.utf8();
00175 entryKey.c_key = utf8_key.data();
00176 aEntryData = lookupData(entryKey);
00177 if (aEntryData.bImmutable)
00178 return true;
00179
00180 entryKey.bLocal = true;
00181 aEntryData = lookupData(entryKey);
00182 return aEntryData.bImmutable;
00183 }
00184
00185
00186 QString KConfigBase::readEntryUntranslated( const QString& pKey,
00187 const QString& aDefault ) const
00188 {
00189 return KConfigBase::readEntryUntranslated(pKey.utf8().data(), aDefault);
00190 }
00191
00192
00193 QString KConfigBase::readEntryUntranslated( const char *pKey,
00194 const QString& aDefault ) const
00195 {
00196 QCString result = readEntryUtf8(pKey);
00197 if (result.isNull())
00198 return aDefault;
00199 return QString::fromUtf8(result);
00200 }
00201
00202
00203 QString KConfigBase::readEntry( const QString& pKey,
00204 const QString& aDefault ) const
00205 {
00206 return KConfigBase::readEntry(pKey.utf8().data(), aDefault);
00207 }
00208
00209 QString KConfigBase::readEntry( const char *pKey,
00210 const QString& aDefault ) const
00211 {
00212
00213
00214
00215
00216 if (!bLocaleInitialized && KGlobal::_locale) {
00217
00218 KConfigBase *that = const_cast<KConfigBase *>(this);
00219 that->setLocale();
00220 }
00221
00222 QString aValue;
00223
00224 bool expand = false;
00225
00226
00227 KEntry aEntryData;
00228 KEntryKey entryKey(mGroup, 0);
00229 entryKey.c_key = pKey;
00230 entryKey.bDefault = readDefaults();
00231 entryKey.bLocal = true;
00232 aEntryData = lookupData(entryKey);
00233 if (!aEntryData.mValue.isNull()) {
00234
00235 aValue = KStringHandler::from8Bit( aEntryData.mValue.data() );
00236 expand = aEntryData.bExpand;
00237 } else {
00238 entryKey.bLocal = false;
00239 aEntryData = lookupData(entryKey);
00240 if (!aEntryData.mValue.isNull()) {
00241 aValue = QString::fromUtf8(aEntryData.mValue.data());
00242 if (aValue.isNull())
00243 {
00244 static const QString &emptyString = KGlobal::staticQString("");
00245 aValue = emptyString;
00246 }
00247 expand = aEntryData.bExpand;
00248 } else {
00249 aValue = aDefault;
00250 }
00251 }
00252
00253
00254 if( expand || bExpand )
00255 {
00256
00257 int nDollarPos = aValue.find( '$' );
00258
00259 while( nDollarPos != -1 && nDollarPos+1 < static_cast<int>(aValue.length())) {
00260
00261 if( (aValue)[nDollarPos+1] == '(' ) {
00262 uint nEndPos = nDollarPos+1;
00263
00264 while ( (nEndPos <= aValue.length()) && (aValue[nEndPos]!=')') )
00265 nEndPos++;
00266 nEndPos++;
00267 QString cmd = aValue.mid( nDollarPos+2, nEndPos-nDollarPos-3 );
00268
00269 QString result;
00270 FILE *fs = popen(QFile::encodeName(cmd).data(), "r");
00271 if (fs)
00272 {
00273 {
00274 QTextStream ts(fs, IO_ReadOnly);
00275 result = ts.read().stripWhiteSpace();
00276 }
00277 pclose(fs);
00278 }
00279 aValue.replace( nDollarPos, nEndPos-nDollarPos, result );
00280 } else if( (aValue)[nDollarPos+1] != '$' ) {
00281 uint nEndPos = nDollarPos+1;
00282
00283 QString aVarName;
00284 if (aValue[nEndPos]=='{')
00285 {
00286 while ( (nEndPos <= aValue.length()) && (aValue[nEndPos]!='}') )
00287 nEndPos++;
00288 nEndPos++;
00289 aVarName = aValue.mid( nDollarPos+2, nEndPos-nDollarPos-3 );
00290 }
00291 else
00292 {
00293 while ( nEndPos <= aValue.length() && (aValue[nEndPos].isNumber()
00294 || aValue[nEndPos].isLetter() || aValue[nEndPos]=='_' ) )
00295 nEndPos++;
00296 aVarName = aValue.mid( nDollarPos+1, nEndPos-nDollarPos-1 );
00297 }
00298 const char* pEnv = 0;
00299 if (!aVarName.isEmpty())
00300 pEnv = getenv( aVarName.ascii() );
00301 if( pEnv ) {
00302
00303
00304
00305 aValue.replace( nDollarPos, nEndPos-nDollarPos, KStringHandler::from8Bit( pEnv ) );
00306 } else
00307 aValue.remove( nDollarPos, nEndPos-nDollarPos );
00308 } else {
00309
00310 aValue.remove( nDollarPos, 1 );
00311 nDollarPos++;
00312 }
00313 nDollarPos = aValue.find( '$', nDollarPos );
00314 }
00315 }
00316
00317 return aValue;
00318 }
00319
00320 QCString KConfigBase::readEntryUtf8( const char *pKey) const
00321 {
00322
00323 KEntryKey entryKey(mGroup, 0);
00324 entryKey.bDefault = readDefaults();
00325 entryKey.c_key = pKey;
00326 KEntry aEntryData = lookupData(entryKey);
00327 if (aEntryData.bExpand)
00328 {
00329
00330 return readEntry(pKey, QString::null).utf8();
00331 }
00332 return aEntryData.mValue;
00333 }
00334
00335 QVariant KConfigBase::readPropertyEntry( const QString& pKey,
00336 QVariant::Type type ) const
00337 {
00338 return readPropertyEntry(pKey.utf8().data(), type);
00339 }
00340
00341 QVariant KConfigBase::readPropertyEntry( const char *pKey,
00342 QVariant::Type type ) const
00343 {
00344 QVariant va;
00345 if ( !hasKey( pKey ) ) return va;
00346 (void)va.cast(type);
00347 return readPropertyEntry(pKey, va);
00348 }
00349
00350 QVariant KConfigBase::readPropertyEntry( const QString& pKey,
00351 const QVariant &aDefault ) const
00352 {
00353 return readPropertyEntry(pKey.utf8().data(), aDefault);
00354 }
00355
00356 QVariant KConfigBase::readPropertyEntry( const char *pKey,
00357 const QVariant &aDefault ) const
00358 {
00359 if ( !hasKey( pKey ) ) return aDefault;
00360
00361 QVariant tmp = aDefault;
00362
00363 switch( aDefault.type() )
00364 {
00365 case QVariant::Invalid:
00366 return QVariant();
00367 case QVariant::String:
00368 return QVariant( readEntry( pKey, aDefault.toString() ) );
00369 case QVariant::StringList:
00370 return QVariant( readListEntry( pKey ) );
00371 case QVariant::List: {
00372 QStringList strList = readListEntry( pKey );
00373 QStringList::ConstIterator it = strList.begin();
00374 QStringList::ConstIterator end = strList.end();
00375 QValueList<QVariant> list;
00376
00377 for (; it != end; ++it ) {
00378 tmp = *it;
00379 list.append( tmp );
00380 }
00381 return QVariant( list );
00382 }
00383 case QVariant::Font:
00384 return QVariant( readFontEntry( pKey, &tmp.asFont() ) );
00385 case QVariant::Point:
00386 return QVariant( readPointEntry( pKey, &tmp.asPoint() ) );
00387 case QVariant::Rect:
00388 return QVariant( readRectEntry( pKey, &tmp.asRect() ) );
00389 case QVariant::Size:
00390 return QVariant( readSizeEntry( pKey, &tmp.asSize() ) );
00391 case QVariant::Color:
00392 return QVariant( readColorEntry( pKey, &tmp.asColor() ) );
00393 case QVariant::Int:
00394 return QVariant( readNumEntry( pKey, aDefault.toInt() ) );
00395 case QVariant::UInt:
00396 return QVariant( readUnsignedNumEntry( pKey, aDefault.toUInt() ) );
00397 case QVariant::LongLong:
00398 return QVariant( readNum64Entry( pKey, aDefault.toLongLong() ) );
00399 case QVariant::ULongLong:
00400 return QVariant( readUnsignedNum64Entry( pKey, aDefault.toULongLong() ) );
00401 case QVariant::Bool:
00402 return QVariant( readBoolEntry( pKey, aDefault.toBool() ), 0 );
00403 case QVariant::Double:
00404 return QVariant( readDoubleNumEntry( pKey, aDefault.toDouble() ) );
00405 case QVariant::DateTime:
00406 return QVariant( readDateTimeEntry( pKey, &tmp.asDateTime() ) );
00407 case QVariant::Date:
00408 return QVariant(readDateTimeEntry( pKey, &tmp.asDateTime() ).date());
00409
00410 case QVariant::Pixmap:
00411 case QVariant::Image:
00412 case QVariant::Brush:
00413 case QVariant::Palette:
00414 case QVariant::ColorGroup:
00415 case QVariant::Map:
00416 case QVariant::IconSet:
00417 case QVariant::CString:
00418 case QVariant::PointArray:
00419 case QVariant::Region:
00420 case QVariant::Bitmap:
00421 case QVariant::Cursor:
00422 case QVariant::SizePolicy:
00423 case QVariant::Time:
00424 case QVariant::ByteArray:
00425 case QVariant::BitArray:
00426 case QVariant::KeySequence:
00427 case QVariant::Pen:
00428 break;
00429 }
00430
00431 Q_ASSERT( 0 );
00432 return QVariant();
00433 }
00434
00435 int KConfigBase::readListEntry( const QString& pKey,
00436 QStrList &list, char sep ) const
00437 {
00438 return readListEntry(pKey.utf8().data(), list, sep);
00439 }
00440
00441 int KConfigBase::readListEntry( const char *pKey,
00442 QStrList &list, char sep ) const
00443 {
00444 if( !hasKey( pKey ) )
00445 return 0;
00446
00447 QCString str_list = readEntryUtf8( pKey );
00448 if (str_list.isEmpty())
00449 return 0;
00450
00451 list.clear();
00452 QCString value = "";
00453 int len = str_list.length();
00454
00455 for (int i = 0; i < len; i++) {
00456 if (str_list[i] != sep && str_list[i] != '\\') {
00457 value += str_list[i];
00458 continue;
00459 }
00460 if (str_list[i] == '\\') {
00461 i++;
00462 if ( i < len )
00463 value += str_list[i];
00464 continue;
00465 }
00466
00467
00468
00469
00470
00471 list.append( value );
00472 value.truncate(0);
00473 }
00474
00475 if ( str_list[len-1] != sep || ( len > 1 && str_list[len-2] == '\\' ) )
00476 list.append( value );
00477 return list.count();
00478 }
00479
00480 QStringList KConfigBase::readListEntry( const QString& pKey, char sep ) const
00481 {
00482 return readListEntry(pKey.utf8().data(), sep);
00483 }
00484
00485 QStringList KConfigBase::readListEntry( const char *pKey, char sep ) const
00486 {
00487 static const QString& emptyString = KGlobal::staticQString("");
00488
00489 QStringList list;
00490 if( !hasKey( pKey ) )
00491 return list;
00492 QString str_list = readEntry( pKey );
00493 if( str_list.isEmpty() )
00494 return list;
00495 QString value(emptyString);
00496 int len = str_list.length();
00497
00498 value.reserve( len );
00499 for( int i = 0; i < len; i++ )
00500 {
00501 if( str_list[i] != sep && str_list[i] != '\\' )
00502 {
00503 value += str_list[i];
00504 continue;
00505 }
00506 if( str_list[i] == '\\' )
00507 {
00508 i++;
00509 if ( i < len )
00510 value += str_list[i];
00511 continue;
00512 }
00513 QString finalvalue( value );
00514 finalvalue.squeeze();
00515 list.append( finalvalue );
00516 value.truncate( 0 );
00517 }
00518 if ( str_list[len-1] != sep || ( len > 1 && str_list[len-2] == '\\' ) )
00519 {
00520 value.squeeze();
00521 list.append( value );
00522 }
00523 return list;
00524 }
00525
00526 QStringList KConfigBase::readListEntry( const char* pKey, const QStringList& aDefault,
00527 char sep ) const
00528 {
00529 if ( !hasKey( pKey ) )
00530 return aDefault;
00531 else
00532 return readListEntry( pKey, sep );
00533 }
00534
00535 QValueList<int> KConfigBase::readIntListEntry( const QString& pKey ) const
00536 {
00537 return readIntListEntry(pKey.utf8().data());
00538 }
00539
00540 QValueList<int> KConfigBase::readIntListEntry( const char *pKey ) const
00541 {
00542 QStringList strlist = readListEntry(pKey);
00543 QValueList<int> list;
00544 QStringList::ConstIterator end(strlist.end());
00545 for (QStringList::ConstIterator it = strlist.begin(); it != end; ++it)
00546
00547
00548 list << (*it).toInt();
00549
00550 return list;
00551 }
00552
00553 QString KConfigBase::readPathEntry( const QString& pKey, const QString& pDefault ) const
00554 {
00555 return readPathEntry(pKey.utf8().data(), pDefault);
00556 }
00557
00558 QString KConfigBase::readPathEntry( const char *pKey, const QString& pDefault ) const
00559 {
00560 const bool bExpandSave = bExpand;
00561 bExpand = true;
00562 QString aValue = readEntry( pKey, pDefault );
00563 bExpand = bExpandSave;
00564 return aValue;
00565 }
00566
00567 QStringList KConfigBase::readPathListEntry( const QString& pKey, char sep ) const
00568 {
00569 return readPathListEntry(pKey.utf8().data(), sep);
00570 }
00571
00572 QStringList KConfigBase::readPathListEntry( const char *pKey, char sep ) const
00573 {
00574 const bool bExpandSave = bExpand;
00575 bExpand = true;
00576 QStringList aValue = readListEntry( pKey, sep );
00577 bExpand = bExpandSave;
00578 return aValue;
00579 }
00580
00581 int KConfigBase::readNumEntry( const QString& pKey, int nDefault) const
00582 {
00583 return readNumEntry(pKey.utf8().data(), nDefault);
00584 }
00585
00586 int KConfigBase::readNumEntry( const char *pKey, int nDefault) const
00587 {
00588 QCString aValue = readEntryUtf8( pKey );
00589 if( aValue.isNull() )
00590 return nDefault;
00591 else if( aValue == "true" || aValue == "on" || aValue == "yes" )
00592 return 1;
00593 else
00594 {
00595 bool ok;
00596 int rc = aValue.toInt( &ok );
00597 return( ok ? rc : nDefault );
00598 }
00599 }
00600
00601
00602 unsigned int KConfigBase::readUnsignedNumEntry( const QString& pKey, unsigned int nDefault) const
00603 {
00604 return readUnsignedNumEntry(pKey.utf8().data(), nDefault);
00605 }
00606
00607 unsigned int KConfigBase::readUnsignedNumEntry( const char *pKey, unsigned int nDefault) const
00608 {
00609 QCString aValue = readEntryUtf8( pKey );
00610 if( aValue.isNull() )
00611 return nDefault;
00612 else
00613 {
00614 bool ok;
00615 unsigned int rc = aValue.toUInt( &ok );
00616 return( ok ? rc : nDefault );
00617 }
00618 }
00619
00620
00621 long KConfigBase::readLongNumEntry( const QString& pKey, long nDefault) const
00622 {
00623 return readLongNumEntry(pKey.utf8().data(), nDefault);
00624 }
00625
00626 long KConfigBase::readLongNumEntry( const char *pKey, long nDefault) const
00627 {
00628 QCString aValue = readEntryUtf8( pKey );
00629 if( aValue.isNull() )
00630 return nDefault;
00631 else
00632 {
00633 bool ok;
00634 long rc = aValue.toLong( &ok );
00635 return( ok ? rc : nDefault );
00636 }
00637 }
00638
00639
00640 unsigned long KConfigBase::readUnsignedLongNumEntry( const QString& pKey, unsigned long nDefault) const
00641 {
00642 return readUnsignedLongNumEntry(pKey.utf8().data(), nDefault);
00643 }
00644
00645 unsigned long KConfigBase::readUnsignedLongNumEntry( const char *pKey, unsigned long nDefault) const
00646 {
00647 QCString aValue = readEntryUtf8( pKey );
00648 if( aValue.isNull() )
00649 return nDefault;
00650 else
00651 {
00652 bool ok;
00653 unsigned long rc = aValue.toULong( &ok );
00654 return( ok ? rc : nDefault );
00655 }
00656 }
00657
00658 Q_INT64 KConfigBase::readNum64Entry( const QString& pKey, Q_INT64 nDefault) const
00659 {
00660 return readNum64Entry(pKey.utf8().data(), nDefault);
00661 }
00662
00663 Q_INT64 KConfigBase::readNum64Entry( const char *pKey, Q_INT64 nDefault) const
00664 {
00665
00666 QString aValue = readEntry( pKey );
00667 if( aValue.isNull() )
00668 return nDefault;
00669 else
00670 {
00671 bool ok;
00672 Q_INT64 rc = aValue.toLongLong( &ok );
00673 return( ok ? rc : nDefault );
00674 }
00675 }
00676
00677
00678 Q_UINT64 KConfigBase::readUnsignedNum64Entry( const QString& pKey, Q_UINT64 nDefault) const
00679 {
00680 return readUnsignedNum64Entry(pKey.utf8().data(), nDefault);
00681 }
00682
00683 Q_UINT64 KConfigBase::readUnsignedNum64Entry( const char *pKey, Q_UINT64 nDefault) const
00684 {
00685
00686 QString aValue = readEntry( pKey );
00687 if( aValue.isNull() )
00688 return nDefault;
00689 else
00690 {
00691 bool ok;
00692 Q_UINT64 rc = aValue.toULongLong( &ok );
00693 return( ok ? rc : nDefault );
00694 }
00695 }
00696
00697 double KConfigBase::readDoubleNumEntry( const QString& pKey, double nDefault) const
00698 {
00699 return readDoubleNumEntry(pKey.utf8().data(), nDefault);
00700 }
00701
00702 double KConfigBase::readDoubleNumEntry( const char *pKey, double nDefault) const
00703 {
00704 QCString aValue = readEntryUtf8( pKey );
00705 if( aValue.isNull() )
00706 return nDefault;
00707 else
00708 {
00709 bool ok;
00710 double rc = aValue.toDouble( &ok );
00711 return( ok ? rc : nDefault );
00712 }
00713 }
00714
00715
00716 bool KConfigBase::readBoolEntry( const QString& pKey, bool bDefault ) const
00717 {
00718 return readBoolEntry(pKey.utf8().data(), bDefault);
00719 }
00720
00721 bool KConfigBase::readBoolEntry( const char *pKey, bool bDefault ) const
00722 {
00723 QCString aValue = readEntryUtf8( pKey );
00724
00725 if( aValue.isNull() )
00726 return bDefault;
00727 else
00728 {
00729 if( aValue == "true" || aValue == "on" || aValue == "yes" || aValue == "1" )
00730 return true;
00731 else
00732 {
00733 bool bOK;
00734 int val = aValue.toInt( &bOK );
00735 if( bOK && val != 0 )
00736 return true;
00737 else
00738 return false;
00739 }
00740 }
00741 }
00742
00743 QFont KConfigBase::readFontEntry( const QString& pKey, const QFont* pDefault ) const
00744 {
00745 return readFontEntry(pKey.utf8().data(), pDefault);
00746 }
00747
00748 QFont KConfigBase::readFontEntry( const char *pKey, const QFont* pDefault ) const
00749 {
00750 QFont aRetFont;
00751
00752 QString aValue = readEntry( pKey );
00753 if( !aValue.isNull() ) {
00754 if ( aValue.contains( ',' ) > 5 ) {
00755
00756 if ( !aRetFont.fromString( aValue ) && pDefault )
00757 aRetFont = *pDefault;
00758 }
00759 else {
00760
00761
00762
00763 int nIndex = aValue.find( ',' );
00764 if( nIndex == -1 ){
00765 if( pDefault )
00766 aRetFont = *pDefault;
00767 return aRetFont;
00768 }
00769 aRetFont.setFamily( aValue.left( nIndex ) );
00770
00771
00772 int nOldIndex = nIndex;
00773 nIndex = aValue.find( ',', nOldIndex+1 );
00774 if( nIndex == -1 ){
00775 if( pDefault )
00776 aRetFont = *pDefault;
00777 return aRetFont;
00778 }
00779
00780 aRetFont.setPointSize( aValue.mid( nOldIndex+1,
00781 nIndex-nOldIndex-1 ).toInt() );
00782
00783
00784 nOldIndex = nIndex;
00785 nIndex = aValue.find( ',', nOldIndex+1 );
00786
00787 if( nIndex == -1 ){
00788 if( pDefault )
00789 aRetFont = *pDefault;
00790 return aRetFont;
00791 }
00792
00793 aRetFont.setStyleHint( (QFont::StyleHint)aValue.mid( nOldIndex+1, nIndex-nOldIndex-1 ).toUInt() );
00794
00795
00796 nOldIndex = nIndex;
00797 nIndex = aValue.find( ',', nOldIndex+1 );
00798
00799 if( nIndex == -1 ){
00800 if( pDefault )
00801 aRetFont = *pDefault;
00802 return aRetFont;
00803 }
00804
00805 QString chStr=aValue.mid( nOldIndex+1,
00806 nIndex-nOldIndex-1 );
00807
00808 nOldIndex = nIndex;
00809 nIndex = aValue.find( ',', nOldIndex+1 );
00810
00811 if( nIndex == -1 ){
00812 if( pDefault )
00813 aRetFont = *pDefault;
00814 return aRetFont;
00815 }
00816
00817 aRetFont.setWeight( aValue.mid( nOldIndex+1,
00818 nIndex-nOldIndex-1 ).toUInt() );
00819
00820
00821 uint nFontBits = aValue.right( aValue.length()-nIndex-1 ).toUInt();
00822
00823 aRetFont.setItalic( nFontBits & 0x01 );
00824 aRetFont.setUnderline( nFontBits & 0x02 );
00825 aRetFont.setStrikeOut( nFontBits & 0x04 );
00826 aRetFont.setFixedPitch( nFontBits & 0x08 );
00827 aRetFont.setRawMode( nFontBits & 0x20 );
00828 }
00829 }
00830 else
00831 {
00832 if( pDefault )
00833 aRetFont = *pDefault;
00834 }
00835
00836 return aRetFont;
00837 }
00838
00839
00840 QRect KConfigBase::readRectEntry( const QString& pKey, const QRect* pDefault ) const
00841 {
00842 return readRectEntry(pKey.utf8().data(), pDefault);
00843 }
00844
00845 QRect KConfigBase::readRectEntry( const char *pKey, const QRect* pDefault ) const
00846 {
00847 QCString aValue = readEntryUtf8(pKey);
00848
00849 if (!aValue.isEmpty())
00850 {
00851 int left, top, width, height;
00852
00853 if (sscanf(aValue.data(), "%d,%d,%d,%d", &left, &top, &width, &height) == 4)
00854 {
00855 return QRect(left, top, width, height);
00856 }
00857 }
00858 if (pDefault)
00859 return *pDefault;
00860 return QRect();
00861 }
00862
00863
00864 QPoint KConfigBase::readPointEntry( const QString& pKey,
00865 const QPoint* pDefault ) const
00866 {
00867 return readPointEntry(pKey.utf8().data(), pDefault);
00868 }
00869
00870 QPoint KConfigBase::readPointEntry( const char *pKey,
00871 const QPoint* pDefault ) const
00872 {
00873 QCString aValue = readEntryUtf8(pKey);
00874
00875 if (!aValue.isEmpty())
00876 {
00877 int x,y;
00878
00879 if (sscanf(aValue.data(), "%d,%d", &x, &y) == 2)
00880 {
00881 return QPoint(x,y);
00882 }
00883 }
00884 if (pDefault)
00885 return *pDefault;
00886 return QPoint();
00887 }
00888
00889 QSize KConfigBase::readSizeEntry( const QString& pKey,
00890 const QSize* pDefault ) const
00891 {
00892 return readSizeEntry(pKey.utf8().data(), pDefault);
00893 }
00894
00895 QSize KConfigBase::readSizeEntry( const char *pKey,
00896 const QSize* pDefault ) const
00897 {
00898 QCString aValue = readEntryUtf8(pKey);
00899
00900 if (!aValue.isEmpty())
00901 {
00902 int width,height;
00903
00904 if (sscanf(aValue.data(), "%d,%d", &width, &height) == 2)
00905 {
00906 return QSize(width, height);
00907 }
00908 }
00909 if (pDefault)
00910 return *pDefault;
00911 return QSize();
00912 }
00913
00914
00915 QColor KConfigBase::readColorEntry( const QString& pKey,
00916 const QColor* pDefault ) const
00917 {
00918 return readColorEntry(pKey.utf8().data(), pDefault);
00919 }
00920
00921 QColor KConfigBase::readColorEntry( const char *pKey,
00922 const QColor* pDefault ) const
00923 {