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 QTextStream ts(fs, IO_ReadOnly);
00274 result = ts.read().stripWhiteSpace();
00275 pclose(fs);
00276 }
00277 aValue.replace( nDollarPos, nEndPos-nDollarPos, result );
00278 } else if( (aValue)[nDollarPos+1] != '$' ) {
00279 uint nEndPos = nDollarPos+1;
00280
00281 QString aVarName;
00282 if (aValue[nEndPos]=='{')
00283 {
00284 while ( (nEndPos <= aValue.length()) && (aValue[nEndPos]!='}') )
00285 nEndPos++;
00286 nEndPos++;
00287 aVarName = aValue.mid( nDollarPos+2, nEndPos-nDollarPos-3 );
00288 }
00289 else
00290 {
00291 while ( nEndPos <= aValue.length() && (aValue[nEndPos].isNumber()
00292 || aValue[nEndPos].isLetter() || aValue[nEndPos]=='_' ) )
00293 nEndPos++;
00294 aVarName = aValue.mid( nDollarPos+1, nEndPos-nDollarPos-1 );
00295 }
00296 const char* pEnv = 0;
00297 if (!aVarName.isEmpty())
00298 pEnv = getenv( aVarName.ascii() );
00299 if( pEnv ) {
00300
00301
00302
00303 aValue.replace( nDollarPos, nEndPos-nDollarPos, KStringHandler::from8Bit( pEnv ) );
00304 } else
00305 aValue.remove( nDollarPos, nEndPos-nDollarPos );
00306 } else {
00307
00308 aValue.remove( nDollarPos, 1 );
00309 nDollarPos++;
00310 }
00311 nDollarPos = aValue.find( '$', nDollarPos );
00312 }
00313 }
00314
00315 return aValue;
00316 }
00317
00318 QCString KConfigBase::readEntryUtf8( const char *pKey) const
00319 {
00320
00321 KEntryKey entryKey(mGroup, 0);
00322 entryKey.bDefault = readDefaults();
00323 entryKey.c_key = pKey;
00324 KEntry aEntryData = lookupData(entryKey);
00325 if (aEntryData.bExpand)
00326 {
00327
00328 return readEntry(pKey, QString::null).utf8();
00329 }
00330 return aEntryData.mValue;
00331 }
00332
00333 QVariant KConfigBase::readPropertyEntry( const QString& pKey,
00334 QVariant::Type type ) const
00335 {
00336 return readPropertyEntry(pKey.utf8().data(), type);
00337 }
00338
00339 QVariant KConfigBase::readPropertyEntry( const char *pKey,
00340 QVariant::Type type ) const
00341 {
00342 QVariant va;
00343 if ( !hasKey( pKey ) ) return va;
00344 (void)va.cast(type);
00345 return readPropertyEntry(pKey, va);
00346 }
00347
00348 QVariant KConfigBase::readPropertyEntry( const QString& pKey,
00349 const QVariant &aDefault ) const
00350 {
00351 return readPropertyEntry(pKey.utf8().data(), aDefault);
00352 }
00353
00354 QVariant KConfigBase::readPropertyEntry( const char *pKey,
00355 const QVariant &aDefault ) const
00356 {
00357 if ( !hasKey( pKey ) ) return aDefault;
00358
00359 QVariant tmp = aDefault;
00360
00361 switch( aDefault.type() )
00362 {
00363 case QVariant::Invalid:
00364 return QVariant();
00365 case QVariant::String:
00366 return QVariant( readEntry( pKey, aDefault.toString() ) );
00367 case QVariant::StringList:
00368 return QVariant( readListEntry( pKey ) );
00369 case QVariant::List: {
00370 QStringList strList = readListEntry( pKey );
00371 QStringList::ConstIterator it = strList.begin();
00372 QStringList::ConstIterator end = strList.end();
00373 QValueList<QVariant> list;
00374
00375 for (; it != end; ++it ) {
00376 tmp = *it;
00377 list.append( tmp );
00378 }
00379 return QVariant( list );
00380 }
00381 case QVariant::Font:
00382 return QVariant( readFontEntry( pKey, &tmp.asFont() ) );
00383 case QVariant::Point:
00384 return QVariant( readPointEntry( pKey, &tmp.asPoint() ) );
00385 case QVariant::Rect:
00386 return QVariant( readRectEntry( pKey, &tmp.asRect() ) );
00387 case QVariant::Size:
00388 return QVariant( readSizeEntry( pKey, &tmp.asSize() ) );
00389 case QVariant::Color:
00390 return QVariant( readColorEntry( pKey, &tmp.asColor() ) );
00391 case QVariant::Int:
00392 return QVariant( readNumEntry( pKey, aDefault.toInt() ) );
00393 case QVariant::UInt:
00394 return QVariant( readUnsignedNumEntry( pKey, aDefault.toUInt() ) );
00395 case QVariant::LongLong:
00396 return QVariant( readNum64Entry( pKey, aDefault.toLongLong() ) );
00397 case QVariant::ULongLong:
00398 return QVariant( readUnsignedNum64Entry( pKey, aDefault.toULongLong() ) );
00399 case QVariant::Bool:
00400 return QVariant( readBoolEntry( pKey, aDefault.toBool() ), 0 );
00401 case QVariant::Double:
00402 return QVariant( readDoubleNumEntry( pKey, aDefault.toDouble() ) );
00403 case QVariant::DateTime:
00404 return QVariant( readDateTimeEntry( pKey, &tmp.asDateTime() ) );
00405 case QVariant::Date:
00406 return QVariant(readDateTimeEntry( pKey, &tmp.asDateTime() ).date());
00407
00408 case QVariant::Pixmap:
00409 case QVariant::Image:
00410 case QVariant::Brush:
00411 case QVariant::Palette:
00412 case QVariant::ColorGroup:
00413 case QVariant::Map:
00414 case QVariant::IconSet:
00415 case QVariant::CString:
00416 case QVariant::PointArray:
00417 case QVariant::Region:
00418 case QVariant::Bitmap:
00419 case QVariant::Cursor:
00420 case QVariant::SizePolicy:
00421 case QVariant::Time:
00422 case QVariant::ByteArray:
00423 case QVariant::BitArray:
00424 case QVariant::KeySequence:
00425 case QVariant::Pen:
00426 break;
00427 }
00428
00429 Q_ASSERT( 0 );
00430 return QVariant();
00431 }
00432
00433 int KConfigBase::readListEntry( const QString& pKey,
00434 QStrList &list, char sep ) const
00435 {
00436 return readListEntry(pKey.utf8().data(), list, sep);
00437 }
00438
00439 int KConfigBase::readListEntry( const char *pKey,
00440 QStrList &list, char sep ) const
00441 {
00442 if( !hasKey( pKey ) )
00443 return 0;
00444
00445 QCString str_list = readEntryUtf8( pKey );
00446 if (str_list.isEmpty())
00447 return 0;
00448
00449 list.clear();
00450 QCString value = "";
00451 int len = str_list.length();
00452
00453 for (int i = 0; i < len; i++) {
00454 if (str_list[i] != sep && str_list[i] != '\\') {
00455 value += str_list[i];
00456 continue;
00457 }
00458 if (str_list[i] == '\\') {
00459 i++;
00460 if ( i < len )
00461 value += str_list[i];
00462 continue;
00463 }
00464
00465
00466
00467
00468
00469 list.append( value );
00470 value.truncate(0);
00471 }
00472
00473 if ( str_list[len-1] != sep || ( len > 1 && str_list[len-2] == '\\' ) )
00474 list.append( value );
00475 return list.count();
00476 }
00477
00478 QStringList KConfigBase::readListEntry( const QString& pKey, char sep ) const
00479 {
00480 return readListEntry(pKey.utf8().data(), sep);
00481 }
00482
00483 QStringList KConfigBase::readListEntry( const char *pKey, char sep ) const
00484 {
00485 static const QString& emptyString = KGlobal::staticQString("");
00486
00487 QStringList list;
00488 if( !hasKey( pKey ) )
00489 return list;
00490 QString str_list = readEntry( pKey );
00491 if( str_list.isEmpty() )
00492 return list;
00493 QString value(emptyString);
00494 int len = str_list.length();
00495
00496 value.reserve( len );
00497 for( int i = 0; i < len; i++ )
00498 {
00499 if( str_list[i] != sep && str_list[i] != '\\' )
00500 {
00501 value += str_list[i];
00502 continue;
00503 }
00504 if( str_list[i] == '\\' )
00505 {
00506 i++;
00507 if ( i < len )
00508 value += str_list[i];
00509 continue;
00510 }
00511 QString finalvalue( value );
00512 finalvalue.squeeze();
00513 list.append( finalvalue );
00514 value.truncate( 0 );
00515 }
00516 if ( str_list[len-1] != sep || ( len > 1 && str_list[len-2] == '\\' ) )
00517 {
00518 value.squeeze();
00519 list.append( value );
00520 }
00521 return list;
00522 }
00523
00524 QValueList<int> KConfigBase::readIntListEntry( const QString& pKey ) const
00525 {
00526 return readIntListEntry(pKey.utf8().data());
00527 }
00528
00529 QValueList<int> KConfigBase::readIntListEntry( const char *pKey ) const
00530 {
00531 QStringList strlist = readListEntry(pKey);
00532 QValueList<int> list;
00533 for (QStringList::ConstIterator it = strlist.begin(); it != strlist.end(); it++)
00534
00535
00536 list << (*it).toInt();
00537
00538 return list;
00539 }
00540
00541 QString KConfigBase::readPathEntry( const QString& pKey, const QString& pDefault ) const
00542 {
00543 return readPathEntry(pKey.utf8().data(), pDefault);
00544 }
00545
00546 QString KConfigBase::readPathEntry( const char *pKey, const QString& pDefault ) const
00547 {
00548 const bool bExpandSave = bExpand;
00549 bExpand = true;
00550 QString aValue = readEntry( pKey, pDefault );
00551 bExpand = bExpandSave;
00552 return aValue;
00553 }
00554
00555 QStringList KConfigBase::readPathListEntry( const QString& pKey, char sep ) const
00556 {
00557 return readPathListEntry(pKey.utf8().data(), sep);
00558 }
00559
00560 QStringList KConfigBase::readPathListEntry( const char *pKey, char sep ) const
00561 {
00562 const bool bExpandSave = bExpand;
00563 bExpand = true;
00564 QStringList aValue = readListEntry( pKey, sep );
00565 bExpand = bExpandSave;
00566 return aValue;
00567 }
00568
00569 int KConfigBase::readNumEntry( const QString& pKey, int nDefault) const
00570 {
00571 return readNumEntry(pKey.utf8().data(), nDefault);
00572 }
00573
00574 int KConfigBase::readNumEntry( const char *pKey, int nDefault) const
00575 {
00576 QCString aValue = readEntryUtf8( pKey );
00577 if( aValue.isNull() )
00578 return nDefault;
00579 else if( aValue == "true" || aValue == "on" || aValue == "yes" )
00580 return 1;
00581 else
00582 {
00583 bool ok;
00584 int rc = aValue.toInt( &ok );
00585 return( ok ? rc : nDefault );
00586 }
00587 }
00588
00589
00590 unsigned int KConfigBase::readUnsignedNumEntry( const QString& pKey, unsigned int nDefault) const
00591 {
00592 return readUnsignedNumEntry(pKey.utf8().data(), nDefault);
00593 }
00594
00595 unsigned int KConfigBase::readUnsignedNumEntry( const char *pKey, unsigned int nDefault) const
00596 {
00597 QCString aValue = readEntryUtf8( pKey );
00598 if( aValue.isNull() )
00599 return nDefault;
00600 else
00601 {
00602 bool ok;
00603 unsigned int rc = aValue.toUInt( &ok );
00604 return( ok ? rc : nDefault );
00605 }
00606 }
00607
00608
00609 long KConfigBase::readLongNumEntry( const QString& pKey, long nDefault) const
00610 {
00611 return readLongNumEntry(pKey.utf8().data(), nDefault);
00612 }
00613
00614 long KConfigBase::readLongNumEntry( const char *pKey, long nDefault) const
00615 {
00616 QCString aValue = readEntryUtf8( pKey );
00617 if( aValue.isNull() )
00618 return nDefault;
00619 else
00620 {
00621 bool ok;
00622 long rc = aValue.toLong( &ok );
00623 return( ok ? rc : nDefault );
00624 }
00625 }
00626
00627
00628 unsigned long KConfigBase::readUnsignedLongNumEntry( const QString& pKey, unsigned long nDefault) const
00629 {
00630 return readUnsignedLongNumEntry(pKey.utf8().data(), nDefault);
00631 }
00632
00633 unsigned long KConfigBase::readUnsignedLongNumEntry( const char *pKey, unsigned long nDefault) const
00634 {
00635 QCString aValue = readEntryUtf8( pKey );
00636 if( aValue.isNull() )
00637 return nDefault;
00638 else
00639 {
00640 bool ok;
00641 unsigned long rc = aValue.toULong( &ok );
00642 return( ok ? rc : nDefault );
00643 }
00644 }
00645
00646 Q_INT64 KConfigBase::readNum64Entry( const QString& pKey, Q_INT64 nDefault) const
00647 {
00648 return readNum64Entry(pKey.utf8().data(), nDefault);
00649 }
00650
00651 Q_INT64 KConfigBase::readNum64Entry( const char *pKey, Q_INT64 nDefault) const
00652 {
00653
00654 QString aValue = readEntry( pKey );
00655 if( aValue.isNull() )
00656 return nDefault;
00657 else
00658 {
00659 bool ok;
00660 Q_INT64 rc = aValue.toLongLong( &ok );
00661 return( ok ? rc : nDefault );
00662 }
00663 }
00664
00665
00666 Q_UINT64 KConfigBase::readUnsignedNum64Entry( const QString& pKey, Q_UINT64 nDefault) const
00667 {
00668 return readUnsignedNum64Entry(pKey.utf8().data(), nDefault);
00669 }
00670
00671 Q_UINT64 KConfigBase::readUnsignedNum64Entry( const char *pKey, Q_UINT64 nDefault) const
00672 {
00673
00674 QString aValue = readEntry( pKey );
00675 if( aValue.isNull() )
00676 return nDefault;
00677 else
00678 {
00679 bool ok;
00680 Q_UINT64 rc = aValue.toULongLong( &ok );
00681 return( ok ? rc : nDefault );
00682 }
00683 }
00684
00685 double KConfigBase::readDoubleNumEntry( const QString& pKey, double nDefault) const
00686 {
00687 return readDoubleNumEntry(pKey.utf8().data(), nDefault);
00688 }
00689
00690 double KConfigBase::readDoubleNumEntry( const char *pKey, double nDefault) const
00691 {
00692 QCString aValue = readEntryUtf8( pKey );
00693 if( aValue.isNull() )
00694 return nDefault;
00695 else
00696 {
00697 bool ok;
00698 double rc = aValue.toDouble( &ok );
00699 return( ok ? rc : nDefault );
00700 }
00701 }
00702
00703
00704 bool KConfigBase::readBoolEntry( const QString& pKey, const bool bDefault ) const
00705 {
00706 return readBoolEntry(pKey.utf8().data(), bDefault);
00707 }
00708
00709 bool KConfigBase::readBoolEntry( const char *pKey, const bool bDefault ) const
00710 {
00711 QCString aValue = readEntryUtf8( pKey );
00712
00713 if( aValue.isNull() )
00714 return bDefault;
00715 else
00716 {
00717 if( aValue == "true" || aValue == "on" || aValue == "yes" || aValue == "1" )
00718 return true;
00719 else
00720 {
00721 bool bOK;
00722 int val = aValue.toInt( &bOK );
00723 if( bOK && val != 0 )
00724 return true;
00725 else
00726 return false;
00727 }
00728 }
00729 }
00730
00731 QFont KConfigBase::readFontEntry( const QString& pKey, const QFont* pDefault ) const
00732 {
00733 return readFontEntry(pKey.utf8().data(), pDefault);
00734 }
00735
00736 QFont KConfigBase::readFontEntry( const char *pKey, const QFont* pDefault ) const
00737 {
00738 QFont aRetFont;
00739
00740 QString aValue = readEntry( pKey );
00741 if( !aValue.isNull() ) {
00742 if ( aValue.contains( ',' ) > 5 ) {
00743
00744 if ( !aRetFont.fromString( aValue ) && pDefault )
00745 aRetFont = *pDefault;
00746 }
00747 else {
00748
00749
00750
00751 int nIndex = aValue.find( ',' );
00752 if( nIndex == -1 ){
00753 if( pDefault )
00754 aRetFont = *pDefault;
00755 return aRetFont;
00756 }
00757 aRetFont.setFamily( aValue.left( nIndex ) );
00758
00759
00760 int nOldIndex = nIndex;
00761 nIndex = aValue.find( ',', nOldIndex+1 );
00762 if( nIndex == -1 ){
00763 if( pDefault )
00764 aRetFont = *pDefault;
00765 return aRetFont;
00766 }
00767
00768 aRetFont.setPointSize( aValue.mid( nOldIndex+1,
00769 nIndex-nOldIndex-1 ).toInt() );
00770
00771
00772 nOldIndex = nIndex;
00773 nIndex = aValue.find( ',', nOldIndex+1 );
00774
00775 if( nIndex == -1 ){
00776 if( pDefault )
00777 aRetFont = *pDefault;
00778 return aRetFont;
00779 }
00780
00781 aRetFont.setStyleHint( (QFont::StyleHint)aValue.mid( nOldIndex+1, nIndex-nOldIndex-1 ).toUInt() );
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 QString chStr=aValue.mid( nOldIndex+1,
00794 nIndex-nOldIndex-1 );
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 aRetFont.setWeight( aValue.mid( nOldIndex+1,
00806 nIndex-nOldIndex-1 ).toUInt() );
00807
00808
00809 uint nFontBits = aValue.right( aValue.length()-nIndex-1 ).toUInt();
00810
00811 aRetFont.setItalic( nFontBits & 0x01 );
00812 aRetFont.setUnderline( nFontBits & 0x02 );
00813 aRetFont.setStrikeOut( nFontBits & 0x04 );
00814 aRetFont.setFixedPitch( nFontBits & 0x08 );
00815 aRetFont.setRawMode( nFontBits & 0x20 );
00816 }
00817 }
00818 else
00819 {
00820 if( pDefault )
00821 aRetFont = *pDefault;
00822 }
00823
00824 return aRetFont;
00825 }
00826
00827
00828 QRect KConfigBase::readRectEntry( const QString& pKey, const QRect* pDefault ) const
00829 {
00830 return readRectEntry(pKey.utf8().data(), pDefault);
00831 }
00832
00833 QRect KConfigBase::readRectEntry( const char *pKey, const QRect* pDefault ) const
00834 {
00835 QCString aValue = readEntryUtf8(pKey);
00836
00837 if (!aValue.isEmpty())
00838 {
00839 int left, top, width, height;
00840
00841 if (sscanf(aValue.data(), "%d,%d,%d,%d", &left, &top, &width, &height) == 4)
00842 {
00843 return QRect(left, top, width, height);
00844 }
00845 }
00846 if (pDefault)
00847 return *pDefault;
00848 return QRect();
00849 }
00850
00851
00852 QPoint KConfigBase::readPointEntry( const QString& pKey,
00853 const QPoint* pDefault ) const
00854 {
00855 return readPointEntry(pKey.utf8().data(), pDefault);
00856 }
00857
00858 QPoint KConfigBase::readPointEntry( const char *pKey,
00859 const QPoint* pDefault ) const
00860 {
00861 QCString aValue = readEntryUtf8(pKey);
00862
00863 if (!aValue.isEmpty())
00864 {
00865 int x,y;
00866
00867 if (sscanf(aValue.data(), "%d,%d", &x, &y) == 2)
00868 {
00869 return QPoint(x,y);
00870 }
00871 }
00872 if (pDefault)
00873 return *pDefault;
00874 return QPoint();
00875 }
00876
00877 QSize KConfigBase::readSizeEntry( const QString& pKey,
00878 const QSize* pDefault ) const
00879 {
00880 return readSizeEntry(pKey.utf8().data(), pDefault);
00881 }
00882
00883 QSize KConfigBase::readSizeEntry( const char *pKey,
00884 const QSize* pDefault ) const
00885 {
00886 QCString aValue = readEntryUtf8(pKey);
00887
00888 if (!aValue.isEmpty())
00889 {
00890 int width,height;
00891
00892 if (sscanf(aValue.data(), "%d,%d", &width, &height) == 2)
00893 {
00894 return QSize(width, height);
00895 }
00896 }
00897 if (pDefault)
00898 return *pDefault;
00899 return QSize();
00900 }
00901
00902
00903 QColor KConfigBase::readColorEntry( const QString& pKey,
00904 const QColor* pDefault ) const
00905 {
00906 return readColorEntry(pKey.utf8().data(), pDefault);
00907 }
00908
00909 QColor KConfigBase::readColorEntry( const char *pKey,
00910 const QColor* pDefault ) const
00911 {
00912 QColor aRetColor;
00913 int nRed = 0, nGreen = 0, nBlue = 0;
00914
00915 QString aValue = readEntry( pKey );
00916 if( !aValue.isEmpty() )
00917 {
00918 if ( aValue.at(0) == '#' )
00919 {
00920 aRetColor.setNamedColor(aValue);
00921 }
00922 else
00923 {
00924
00925 bool bOK;
00926
00927
00928 int nIndex = aValue.find( ',' );
00929
00930 if( nIndex == -1 ){
00931
00932 if( pDefault )
00933 aRetColor = *pDefault;
00934 return aRetColor;
00935 }
00936
00937 nRed = aValue.left( nIndex ).toInt( &bOK );
00938
00939
00940 int nOldIndex = nIndex;
00941 nIndex = aValue.find( ',', nOldIndex+1 );
00942
00943 if( nIndex == -1 ){
00944
00945 if( pDefault )
00946 aRetColor = *pDefault;
00947 return aRetColor;
00948 }
00949 nGreen = aValue.mid( nOldIndex+1,
00950 nIndex-nOldIndex-1 ).toInt( &bOK );
00951
00952
00953 nBlue = aValue.right( aValue.length()-nIndex-1 ).toInt( &bOK );
00954
00955 aRetColor.setRgb( nRed, nGreen, nBlue );
00956 }
00957 }
00958 else {
00959
00960 if( pDefault )
00961 aRetColor = *pDefault;
00962 }
00963
00964 return aRetColor;
00965 }
00966
00967
00968 QDateTime KConfigBase::readDateTimeEntry( const QString& pKey,
00969 const QDateTime* pDefault ) const
00970 {
00971 return readDateTimeEntry(pKey.utf8().data(), pDefault);
00972 }
00973
00974
00975 QDateTime KConfigBase::readDateTimeEntry( const char *pKey,
00976 const QDateTime* pDefault ) const
00977 {
00978 if( !hasKey( pKey ) )
00979 {
00980 if( pDefault )
00981 return *pDefault;
00982 else
00983 return QDateTime::currentDateTime();
00984 }
00985
00986 QStrList list;
00987 int count = readListEntry( pKey, list, ',' );
00988 if( count == 6 ) {
00989 QDate date( atoi( list.at( 0 ) ), atoi( list.at( 1 ) ),
00990 atoi( list.at( 2 ) ) );
00991 QTime time( atoi( list.at( 3 ) ), atoi( list.at( 4 ) ),
00992 atoi( list.at( 5 ) ) );
00993
00994 return QDateTime( date, time );
00995 }
00996
00997 return QDateTime::currentDateTime();
00998 }
00999
01000 void KConfigBase::writeEntry( const QString& pKey, const QString& value,
01001 bool bPersistent,
01002 bool bGlobal,
01003 bool bNLS )
01004 {
01005 writeEntry(pKey.utf8().data(), value, bPersistent, bGlobal, bNLS);
01006 }
01007
01008 void KConfigBase::writeEntry( const char *pKey, const QString& value,
01009 bool bPersistent,
01010 bool bGlobal,
01011 bool bNLS )
01012 {
01013
01014
01015
01016
01017
01018 if( bPersistent )
01019 setDirty(true);
01020
01021 if (!bLocaleInitialized && KGlobal::locale())
01022 setLocale();
01023
01024 KEntryKey entryKey(mGroup, pKey);
01025 entryKey.bLocal = bNLS;
01026
01027 KEntry aEntryData;
01028 aEntryData.mValue = value.utf8();
01029 aEntryData.bGlobal = bGlobal;
01030 aEntryData.bNLS = bNLS;
01031
01032 if (bPersistent)
01033 aEntryData.bDirty = true;
01034
01035
01036 putData(entryKey, aEntryData, true);
01037 }
01038
01039 void KConfigBase::writePathEntry( const QString& pKey, const QString & path,
01040 bool bPersistent, bool bGlobal,
01041 bool bNLS)
01042 {
01043 writePathEntry(pKey.utf8().data(), path, bPersistent, bGlobal, bNLS);
01044 }
01045
01046
01047 static bool cleanHomeDirPath( QString &path, const QString &homeDir )
01048 {
01049 if (!path.startsWith(homeDir))
01050 return false;
01051
01052 unsigned int len = homeDir.length();
01053
01054 if (path.length() == len || path[len] == '/') {
01055 path = path.replace(0, len, QString::fromLatin1("$HOME"));
01056 return true;
01057 } else
01058 return false;
01059 }
01060
01061 static QString translatePath( QString path )
01062 {
01063 if (path.isEmpty())
01064 return path;
01065
01066 bool startsWithFile = path.startsWith("file:", false);
01067
01068
01069
01070 if (!startsWithFile && path[0] != '/' ||
01071 startsWithFile && path[5] != '/')
01072 return path;
01073
01074 if (startsWithFile)
01075 path.remove(0,5);
01076
01077
01078
01079
01080
01081 QString homeDir0 = QFile::decodeName(getenv("HOME"));
01082 QString homeDir1 = QDir::homeDirPath();
01083 QString homeDir2 = QDir(homeDir1).canonicalPath();
01084 if (cleanHomeDirPath(path, homeDir0) ||
01085 cleanHomeDirPath(path, homeDir1) ||
01086 cleanHomeDirPath(path, homeDir2) ) {
01087
01088 }
01089
01090 if (startsWithFile)
01091 path.prepend( "file:" );
01092
01093 return path;
01094 }
01095
01096 void KConfigBase::writePathEntry( const char *pKey, const QString & path,
01097 bool bPersistent, bool bGlobal,
01098 bool bNLS)
01099 {
01100 writeEntry(pKey, translatePath(path), bPersistent, bGlobal, bNLS);
01101 }
01102
01103 void KConfigBase::writePathEntry ( const QString& pKey, const QStringList &list,
01104 char sep , bool bPersistent,
01105 bool bGlobal, bool bNLS )
01106 {
01107 writePathEntry(pKey.utf8().data(), list, sep, bPersistent, bGlobal, bNLS);
01108 }
01109
01110 void KConfigBase::writePathEntry ( const char *pKey, const QStringList &list,
01111 char sep , bool bPersistent,
01112 bool bGlobal, bool bNLS )
01113 {
01114 if( list.isEmpty() )
01115 {
01116 writeEntry( pKey, QString::fromLatin1(""), bPersistent );
01117 return;
01118 }
01119 QStringList new_list;
01120 QStringList::ConstIterator it = list.begin();
01121 for( ; it != list.end(); ++it )
01122 {
01123 QString value = *it;
01124 new_list.append( translatePath(value) );
01125 }
01126 writeEntry( pKey, new_list, sep, bPersistent, bGlobal, bNLS );
01127 }
01128
01129 void KConfigBase::deleteEntry( const QString& pKey,
01130 bool bNLS,
01131 bool bGlobal)
01132 {
01133 deleteEntry(pKey.utf8().data(), bNLS, bGlobal);
01134 }
01135
01136 void KConfigBase::deleteEntry( const char *pKey,
01137 bool bNLS,
01138 bool bGlobal)
01139 {
01140
01141
01142
01143
01144
01145 setDirty(true);
01146
01147 if (!bLocaleInitialized && KGlobal::locale())
01148 setLocale();
01149
01150 KEntryKey entryKey(mGroup, pKey);
01151 KEntry aEntryData;
01152
01153 aEntryData.bGlobal = bGlobal;
01154 aEntryData.bNLS = bNLS;
01155 aEntryData.bDirty = true;
01156 aEntryData.bDeleted = true;
01157
01158
01159 putData(entryKey, aEntryData, true);
01160 }
01161
01162 bool KConfigBase::deleteGroup( const QString& group, bool bDeep, bool bGlobal )
01163 {
01164 KEntryMap aEntryMap = internalEntryMap(group);
01165
01166 if (!bDeep) {
01167
01168 return aEntryMap.isEmpty();
01169 }
01170
01171 bool dirty = false;
01172 bool checkGroup = true;
01173
01174 KEntryMapIterator aIt;
01175 for (aIt = aEntryMap.begin(); aIt != aEntryMap.end(); ++aIt)
01176 {
01177 if (!aIt.key().mKey.isEmpty() && !aIt.key().bDefault && !(*aIt).bDeleted)
01178 {
01179 (*aIt).bDeleted = true;
01180 (*aIt).bDirty = true;
01181 (*aIt).bGlobal = bGlobal;
01182 (*aIt).mValue = 0;
01183 putData(aIt.key(), *aIt, checkGroup);
01184 checkGroup = false;
01185 dirty = true;
01186 }
01187 }
01188 if (dirty)
01189 setDirty(true);
01190 return true;
01191 }
01192
01193 void KConfigBase::writeEntry ( const QString& pKey, const QVariant &prop,
01194 bool bPersistent,
01195 bool bGlobal, bool bNLS )
01196 {
01197 writeEntry(pKey.utf8().data(), prop, bPersistent, bGlobal, bNLS);
01198 }
01199
01200 void KConfigBase::writeEntry ( const char *pKey, const QVariant &prop,
01201 bool bPersistent,
01202 bool bGlobal, bool bNLS )
01203 {
01204 switch( prop.type() )
01205 {
01206 case QVariant::Invalid:
01207 writeEntry( pKey, "", bPersistent, bGlobal, bNLS );
01208 return;
01209 case QVariant::String:
01210 writeEntry( pKey, prop.toString(), bPersistent, bGlobal, bNLS );
01211 return;
01212 case QVariant::StringList:
01213 writeEntry( pKey, prop.toStringList(), ',', bPersistent, bGlobal, bNLS );
01214 return;
01215 case QVariant::List: {
01216 QValueList<QVariant> list = prop.toList();
01217 QValueList<QVariant>::ConstIterator it = list.begin();
01218 QValueList<QVariant>::ConstIterator end = list.end();
01219 QStringList strList;
01220
01221 for (; it != end; ++it )
01222 strList.append( (*it).toString() );
01223
01224 writeEntry( pKey, strList, ',', bPersistent, bGlobal, bNLS );
01225
01226 return;
01227 }
01228 case QVariant::Font:
01229 writeEntry( pKey, prop.toFont(), bPersistent, bGlobal, bNLS );
01230 return;
01231 case QVariant::Point:
01232 writeEntry( pKey, prop.toPoint(), bPersistent, bGlobal, bNLS );
01233 return;
01234 case QVariant::Rect:
01235 writeEntry( pKey, prop.toRect(), bPersistent, bGlobal, bNLS );
01236 return;
01237 case QVariant::Size:
01238 writeEntry( pKey, prop.toSize(), bPersistent, bGlobal, bNLS );
01239 return;
01240 case QVariant::Color:
01241 writeEntry( pKey, prop.toColor(), bPersistent, bGlobal, bNLS );
01242 return;
01243 case QVariant::Int:
01244 writeEntry( pKey, prop.toInt(), bPersistent, bGlobal, bNLS );
01245 return;
01246 case QVariant::UInt:
01247 writeEntry( pKey, prop.toUInt(), bPersistent, bGlobal, bNLS );
01248 return;
01249 case QVariant::LongLong:
01250 writeEntry( pKey, prop.toLongLong(), bPersistent, bGlobal, bNLS );
01251 return;
01252 case QVariant::ULongLong:
01253 writeEntry( pKey, prop.toULongLong(), bPersistent, bGlobal, bNLS );
01254 return;
01255 case QVariant::Bool:
01256 writeEntry( pKey, prop.toBool(), bPersistent, bGlobal, bNLS );
01257 return;
01258 case QVariant::Double:
01259 writeEntry( pKey, prop.toDouble(), bPersistent, bGlobal, 'g', 6, bNLS );
01260 return;
01261 case QVariant::DateTime:
01262 writeEntry( pKey, prop.toDateTime(), bPersistent, bGlobal, bNLS);
01263 return;
01264 case QVariant::Date:
01265 writeEntry( pKey, QDateTime(prop.toDate()), bPersistent, bGlobal, bNLS);
01266 return;
01267
01268 case QVariant::Pixmap:
01269 case QVariant::Image:
01270 case QVariant::Brush:
01271 case QVariant::Palette:
01272 case QVariant::ColorGroup:
01273 case QVariant::Map:
01274 case QVariant::IconSet:
01275 case QVariant::CString:
01276 case QVariant::PointArray:
01277 case QVariant::Region:
01278 case QVariant::Bitmap:
01279 case QVariant::Cursor:
01280 case QVariant::SizePolicy:
01281 case QVariant::Time:
01282 case QVariant::ByteArray:
01283 case QVariant::BitArray:
01284 case QVariant::KeySequence:
01285 case QVariant::Pen:
01286 break;
01287 }
01288
01289 Q_ASSERT( 0 );
01290 }
01291
01292 void KConfigBase::writeEntry ( const QString& pKey, const QStrList &list,
01293 char sep , bool bPersistent,
01294 bool bGlobal, bool bNLS )
01295 {
01296 writeEntry(pKey.utf8().data(), list, sep, bPersistent, bGlobal, bNLS);
01297 }
01298
01299 void KConfigBase::writeEntry ( const char *pKey, const QStrList &list,
01300 char sep , bool bPersistent,
01301 bool bGlobal, bool bNLS )
01302 {
01303 if( list.isEmpty() )
01304 {
01305 writeEntry( pKey, QString::fromLatin1(""), bPersistent );
01306 return;
01307 }
01308 QString str_list;
01309 QStrListIterator it( list );
01310 for( ; it.current(); ++it )
01311 {
01312 uint i;
01313 QString value;
01314
01315
01316
01317 value = KStringHandler::from8Bit(it.current());
01318 for( i = 0; i < value.length(); i++ )
01319 {
01320 if( value[i] == sep || value[i] == '\\' )
01321 str_list += '\\';
01322 str_list += value[i];
01323 }
01324 str_list += sep;
01325 }
01326 if( str_list.at(str_list.length() - 1) == sep )
01327 str_list.truncate( str_list.length() -1 );
01328 writeEntry( pKey, str_list, bPersistent, bGlobal, bNLS );
01329 }
01330
01331 void KConfigBase::writeEntry ( const QString& pKey, const QStringList &list,
01332 char sep , bool bPersistent,
01333 bool bGlobal, bool bNLS )
01334 {
01335 writeEntry(pKey.utf8().data(), list, sep, bPersistent, bGlobal, bNLS);
01336 }
01337
01338 void KConfigBase::writeEntry ( const char *pKey, const QStringList &list,
01339 char sep , bool bPersistent,
01340 bool bGlobal, bool bNLS )
01341 {
01342 if( list.isEmpty() )
01343 {
01344 writeEntry( pKey, QString::fromLatin1(""), bPersistent );
01345 return;
01346 }
01347 QString str_list;
01348 QStringList::ConstIterator it = list.begin();
01349 for( ; it != list.end(); ++it )
01350 {
01351 QString value = *it;
01352 uint i;
01353 for( i = 0; i < value.length(); i++ )
01354 {
01355 if( value[i] == sep || value[i] == '\\' )
01356 str_list += '\\';
01357 str_list += value[i];
01358 }
01359 str_list += sep;
01360 }
01361 if( str_list.at(str_list.length() - 1) == sep )
01362 str_list.truncate( str_list.length() -1 );
01363 writeEntry( pKey, str_list, bPersistent, bGlobal, bNLS );
01364 }
01365
01366 void KConfigBase::writeEntry ( const QString& pKey, const QValueList<int> &list,
01367 bool bPersistent, bool bGlobal, bool bNLS )
01368 {
01369 writeEntry(pKey.utf8().data(), list, bPersistent, bGlobal, bNLS);
01370 }
01371
01372 void KConfigBase::writeEntry ( const char *pKey, const QValueList<int> &list,
01373 bool bPersistent, bool bGlobal, bool bNLS )
01374 {
01375 QStringList strlist;
01376 QValueList<int>::ConstIterator end = list.end();
01377 for (QValueList<int>::ConstIterator it = list.begin(); it != end; it++)
01378 strlist << QString::number(*it);
01379 writeEntry(pKey, strlist, ',', bPersistent, bGlobal, bNLS );
01380 }
01381
01382 void KConfigBase::writeEntry( const QString& pKey, int nValue,
01383 bool bPersistent, bool bGlobal,
01384 bool bNLS )
01385 {
01386 writeEntry( pKey, QString::number(nValue), bPersistent, bGlobal, bNLS );
01387 }
01388
01389 void KConfigBase::writeEntry( const char *pKey, int nValue,
01390 bool bPersistent, bool bGlobal,
01391 bool bNLS )
01392 {
01393 writeEntry( pKey, QString::number(nValue), bPersistent, bGlobal, bNLS );
01394 }
01395
01396
01397 void KConfigBase::writeEntry( const QString& pKey, unsigned int nValue,
01398 bool bPersistent, bool bGlobal,
01399 bool bNLS )
01400 {
01401 writeEntry( pKey, QString::number(nValue), bPersistent, bGlobal, bNLS );
01402 }
01403
01404 void KConfigBase::writeEntry( const char *pKey, unsigned int nValue,
01405 bool bPersistent, bool bGlobal,
01406 bool bNLS )
01407 {
01408 writeEntry( pKey, QString::number(nValue), bPersistent, bGlobal, bNLS );
01409 }
01410
01411
01412 void KConfigBase::writeEntry( const QString& pKey, long nValue,
01413 bool bPersistent, bool bGlobal,
01414 bool bNLS )
01415 {
01416 writeEntry( pKey, QString::number(nValue), bPersistent, bGlobal, bNLS );
01417 }
01418
01419 void KConfigBase::writeEntry( const char *pKey, long nValue,
01420 bool bPersistent, bool bGlobal,
01421 bool bNLS )
01422 {
01423 writeEntry( pKey, QString::number(nValue), bPersistent, bGlobal, bNLS );
01424 }
01425
01426
01427 void KConfigBase::writeEntry( const QString& pKey, unsigned long nValue,
01428 bool bPersistent, bool bGlobal,
01429 bool bNLS )
01430 {
01431 writeEntry( pKey, QString::number(nValue), bPersistent, bGlobal, bNLS );
01432 }
01433
01434 void KConfigBase::writeEntry( const char *pKey, unsigned long nValue,
01435 bool bPersistent, bool bGlobal,
01436 bool bNLS )
01437 {
01438 writeEntry( pKey, QString::number(nValue), bPersistent, bGlobal, bNLS );
01439 }
01440
01441 void KConfigBase::writeEntry( const QString& pKey, Q_INT64 nValue,
01442 bool bPersistent, bool bGlobal,
01443 bool bNLS )
01444 {
01445 writeEntry( pKey, QString::number(nValue), bPersistent, bGlobal, bNLS );
01446 }
01447
01448 void KConfigBase::writeEntry( const char *pKey, Q_INT64 nValue,
01449 bool bPersistent, bool bGlobal,
01450 bool bNLS )
01451 {
01452 writeEntry( pKey, QString::number(nValue), bPersistent, bGlobal, bNLS );
01453 }
01454
01455
01456 void KConfigBase::writeEntry( const QString& pKey, Q_UINT64 nValue,
01457 bool bPersistent, bool bGlobal,
01458 bool bNLS )
01459 {
01460 writeEntry( pKey, QString::number(nValue), bPersistent, bGlobal, bNLS );
01461 }
01462
01463 void KConfigBase::writeEntry( const char *pKey, Q_UINT64 nValue,
01464 bool bPersistent, bool bGlobal,
01465 bool bNLS )
01466 {
01467 writeEntry( pKey, QString::number(nValue), bPersistent, bGlobal, bNLS );
01468 }
01469
01470 void KConfigBase::writeEntry( const QString& pKey, double nValue,
01471 bool bPersistent, bool bGlobal,
01472 char format, int precision,
01473 bool bNLS )
01474 {
01475 writeEntry( pKey, QString::number(nValue, format, precision),
01476 bPersistent, bGlobal, bNLS );
01477 }
01478
01479 void KConfigBase::writeEntry( const char *pKey, double nValue,
01480 bool bPersistent, bool bGlobal,
01481 char format, int precision,
01482 bool bNLS )
01483 {
01484 writeEntry( pKey, QString::number(nValue, format, precision),
01485 bPersistent, bGlobal, bNLS );
01486 }
01487
01488
01489 void KConfigBase::writeEntry( const QString& pKey, bool bValue,
01490 bool bPersistent,
01491 bool bGlobal,
01492 bool bNLS )
01493 {
01494 writeEntry(pKey.utf8().data(), bValue, bPersistent, bGlobal, bNLS);
01495 }
01496
01497 void KConfigBase::writeEntry( const char *pKey, bool bValue,
01498 bool bPersistent,
01499 bool bGlobal,
01500 bool bNLS )
01501 {
01502 QString aValue;
01503
01504 if( bValue )
01505 aValue = "true";
01506 else
01507 aValue = "false";
01508
01509 writeEntry( pKey, aValue, bPersistent, bGlobal, bNLS );
01510 }
01511
01512
01513 void KConfigBase::writeEntry( const QString& pKey, const QFont& rFont,
01514 bool bPersistent, bool bGlobal,
01515 bool bNLS )
01516 {
01517 writeEntry(pKey.utf8().data(), rFont, bPersistent, bGlobal, bNLS);
01518 }
01519
01520 void KConfigBase::writeEntry( const char *pKey, const QFont& rFont,
01521 bool bPersistent, bool bGlobal,
01522 bool bNLS )
01523 {
01524 writeEntry( pKey, rFont.toString(), bPersistent, bGlobal, bNLS );
01525 }
01526
01527
01528 void KConfigBase::writeEntry( const QString& pKey, const QRect& rRect,
01529 bool bPersistent, bool bGlobal,
01530 bool bNLS )
01531 {
01532 writeEntry(pKey.utf8().data(), rRect, bPersistent, bGlobal, bNLS);
01533 }
01534
01535 void KConfigBase::writeEntry( const char *pKey, const QRect& rRect,
01536 bool bPersistent, bool bGlobal,
01537 bool bNLS )
01538 {
01539 QStrList list;
01540 QCString tempstr;
01541 list.insert( 0, tempstr.setNum( rRect.left() ) );
01542 list.insert( 1, tempstr.setNum( rRect.top() ) );
01543 list.insert( 2, tempstr.setNum( rRect.width() ) );
01544 list.insert( 3, tempstr.setNum( rRect.height() ) );
01545
01546 writeEntry( pKey, list, ',', bPersistent, bGlobal, bNLS );
01547 }
01548
01549
01550 void KConfigBase::writeEntry( const QString& pKey, const QPoint& rPoint,
01551 bool bPersistent, bool bGlobal,
01552 bool bNLS )
01553 {
01554 writeEntry(pKey.utf8().data(), rPoint, bPersistent, bGlobal, bNLS);
01555 }
01556
01557 void KConfigBase::writeEntry( const char *pKey, const QPoint& rPoint,
01558 bool bPersistent, bool bGlobal,
01559 bool bNLS )
01560 {
01561 QStrList list;
01562 QCString tempstr;
01563 list.insert( 0, tempstr.setNum( rPoint.x() ) );
01564 list.insert( 1, tempstr.setNum( rPoint.y() ) );
01565
01566 writeEntry( pKey, list, ',', bPersistent, bGlobal, bNLS );
01567 }
01568
01569
01570 void KConfigBase::writeEntry( const QString& pKey, const QSize& rSize,
01571 bool bPersistent, bool bGlobal,
01572 bool bNLS )
01573 {
01574 writeEntry(pKey.utf8().data(), rSize, bPersistent, bGlobal, bNLS);
01575 }
01576
01577 void KConfigBase::writeEntry( const char *pKey, const QSize& rSize,
01578 bool bPersistent, bool bGlobal,
01579 bool bNLS )
01580 {
01581 QStrList list;
01582 QCString tempstr;
01583 list.insert( 0, tempstr.setNum( rSize.width() ) );
01584 list.insert( 1, tempstr.setNum( rSize.height() ) );
01585
01586 writeEntry( pKey, list, ',', bPersistent, bGlobal, bNLS );
01587 }
01588
01589 void KConfigBase::writeEntry( const QString& pKey, const QColor& rColor,
01590 bool bPersistent,
01591 bool bGlobal,
01592 bool bNLS )
01593 {
01594 writeEntry( pKey.utf8().data(), rColor, bPersistent, bGlobal, bNLS);
01595 }
01596
01597 void KConfigBase::writeEntry( const char *pKey, const QColor& rColor,
01598 bool bPersistent,
01599 bool bGlobal,
01600 bool bNLS )
01601 {
01602 QString aValue;
01603 if (rColor.isValid())
01604 aValue.sprintf( "%d,%d,%d", rColor.red(), rColor.green(), rColor.blue() );
01605 else
01606 aValue = "invalid";
01607
01608 writeEntry( pKey, aValue, bPersistent, bGlobal, bNLS );
01609 }
01610
01611 void KConfigBase::writeEntry( const QString& pKey, const QDateTime& rDateTime,
01612 bool bPersistent, bool bGlobal,
01613 bool bNLS )
01614 {
01615 writeEntry(pKey.utf8().data(), rDateTime, bPersistent, bGlobal, bNLS);
01616 }
01617
01618 void KConfigBase::writeEntry( const char *pKey, const QDateTime& rDateTime,
01619 bool bPersistent, bool bGlobal,
01620 bool bNLS )
01621 {
01622 QStrList list;
01623 QCString tempstr;
01624
01625 QTime time = rDateTime.time();
01626 QDate date = rDateTime.date();
01627
01628 list.insert( 0, tempstr.setNum( date.year() ) );
01629 list.insert( 1, tempstr.setNum( date.month() ) );
01630 list.insert( 2, tempstr.setNum( date.day() ) );
01631
01632 list.insert( 3, tempstr.setNum( time.hour() ) );
01633 list.insert( 4, tempstr.setNum( time.minute() ) );
01634 list.insert( 5, tempstr.setNum( time.second() ) );
01635
01636 writeEntry( pKey, list, ',', bPersistent, bGlobal, bNLS );
01637 }
01638
01639 void KConfigBase::parseConfigFiles()
01640 {
01641 if (!bLocaleInitialized && KGlobal::_locale) {
01642 setLocale();
01643 }
01644 if (backEnd)
01645 {
01646 backEnd->parseConfigFiles();
01647 bReadOnly = (backEnd->getConfigState() == ReadOnly);
01648 }
01649 }
01650
01651 void KConfigBase::sync()
01652 {
01653 if (isReadOnly())
01654 return;
01655
01656 if (backEnd)
01657 backEnd->sync();
01658 if (bDirty)
01659 rollback();
01660 }
01661
01662 KConfigBase::ConfigState KConfigBase::getConfigState() const {
01663 if (backEnd)
01664 return backEnd->getConfigState();
01665 return ReadOnly;
01666 }
01667
01668 void KConfigBase::rollback( bool )
01669 {
01670 bDirty = false;
01671 }
01672
01673
01674 void KConfigBase::setReadDefaults(bool b)
01675 {
01676 if (!d)
01677 {
01678 if (!b) return;
01679 d = new KConfigBasePrivate();
01680 }
01681
01682 d->readDefaults = b;
01683 }
01684
01685 bool KConfigBase::readDefaults() const
01686 {
01687 return (d && d->readDefaults);
01688 }
01689
01690 void KConfigBase::revertToDefault(const QString &key)
01691 {
01692 setDirty(true);
01693
01694 KEntryKey aEntryKey(mGroup, key.utf8());
01695 aEntryKey.bDefault = true;
01696
01697 if (!locale().isNull()) {
01698
01699 aEntryKey.bLocal = true;
01700 KEntry entry = lookupData(aEntryKey);
01701 if (entry.mValue.isNull())
01702 entry.bDeleted = true;
01703
01704 entry.bDirty = true;
01705 putData(aEntryKey, entry, true);
01706 aEntryKey.bLocal = false;
01707 }
01708
01709
01710 KEntry entry = lookupData(aEntryKey);
01711 if (entry.mValue.isNull())
01712 entry.bDeleted = true;
01713 entry.bDirty = true;
01714 putData(aEntryKey, entry, true);
01715 }
01716
01717 bool KConfigBase::hasDefault(const QString &key) const
01718 {
01719 KEntryKey aEntryKey(mGroup, key.utf8());
01720 aEntryKey.bDefault = true;
01721
01722 if (!locale().isNull()) {
01723
01724 aEntryKey.bLocal = true;
01725 KEntry entry = lookupData(aEntryKey);
01726 if (!entry.mValue.isNull())
01727 return true;
01728
01729 aEntryKey.bLocal = false;
01730 }
01731
01732
01733 KEntry entry = lookupData(aEntryKey);
01734 if (!entry.mValue.isNull())
01735 return true;
01736
01737 return false;
01738 }
01739
01740
01741
01742 KConfigGroup::KConfigGroup(KConfigBase *master, const QString &group)
01743 {
01744 mMaster = master;
01745 backEnd = mMaster->backEnd;
01746 bLocaleInitialized = true;
01747 bReadOnly = mMaster->bReadOnly;
01748 bExpand = false;
01749 bDirty = false;
01750 mGroup = group.utf8();
01751 aLocaleString = mMaster->aLocaleString;
01752 setReadDefaults(mMaster->readDefaults());
01753 }
01754
01755 KConfigGroup::KConfigGroup(KConfigBase *master, const QCString &group)
01756 {
01757 mMaster = master;
01758 backEnd = mMaster->backEnd;
01759 bLocaleInitialized = true;
01760 bReadOnly = mMaster->bReadOnly;
01761 bExpand = false;
01762 bDirty = false;
01763 mGroup = group;
01764 aLocaleString = mMaster->aLocaleString;
01765 setReadDefaults(mMaster->readDefaults());
01766 }
01767
01768 KConfigGroup::KConfigGroup(KConfigBase *master, const char * group)
01769 {
01770 mMaster = master;
01771 backEnd = mMaster->backEnd;
01772 bLocaleInitialized = true;
01773 bReadOnly = mMaster->bReadOnly;
01774 bExpand = false;
01775 bDirty = false;
01776 mGroup = group;
01777 aLocaleString = mMaster->aLocaleString;
01778 setReadDefaults(mMaster->readDefaults());
01779 }
01780
01781 void KConfigGroup::deleteGroup(bool bGlobal)
01782 {
01783 mMaster->deleteGroup(KConfigBase::group(), false, bGlobal);
01784 }
01785
01786 void KConfigGroup::setDirty(bool _bDirty)
01787 {
01788 mMaster->setDirty(_bDirty);
01789 }
01790
01791 void KConfigGroup::putData(const KEntryKey &_key, const KEntry &_data, bool _checkGroup)
01792 {
01793 mMaster->putData(_key, _data, _checkGroup);
01794 }
01795
01796 KEntry KConfigGroup::lookupData(const KEntryKey &_key) const
01797 {
01798 return mMaster->lookupData(_key);
01799 }
01800
01801 void KConfigGroup::sync()
01802 {
01803 mMaster->sync();
01804 }
01805
01806 void KConfigBase::virtual_hook( int, void* )
01807 { }
01808
01809 void KConfigGroup::virtual_hook( int id, void* data )
01810 { KConfigBase::virtual_hook( id, data ); }
01811
01812 bool KConfigBase::checkConfigFilesWritable(bool warnUser)
01813 {
01814 if (backEnd)
01815 return backEnd->checkConfigFilesWritable(warnUser);
01816 else
01817 return false;
01818 }
01819
01820 #include "kconfigbase.moc"