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 <tqfile.h>
00027 #include <tqdir.h>
00028 #include <tqtextstream.h>
00029
00030 #include <tdeapplication.h>
00031 #include <tdeglobal.h>
00032 #include <tdelocale.h>
00033 #include <kcharsets.h>
00034
00035 #include "tdeconfigbase.h"
00036 #include "tdeconfigbackend.h"
00037 #include "kdebug.h"
00038 #include "kstandarddirs.h"
00039 #include "kstringhandler.h"
00040
00041 class TDEConfigBase::TDEConfigBasePrivate
00042 {
00043 public:
00044 TDEConfigBasePrivate() : readDefaults(false) { };
00045
00046 public:
00047 bool readDefaults;
00048 };
00049
00050 TDEConfigBase::TDEConfigBase()
00051 : backEnd(0L), bDirty(false), bLocaleInitialized(false),
00052 bReadOnly(false), bExpand(false), d(0)
00053 {
00054 setGroup(TQString::null);
00055 }
00056
00057 TDEConfigBase::~TDEConfigBase()
00058 {
00059 delete d;
00060 }
00061
00062 void TDEConfigBase::setLocale()
00063 {
00064 bLocaleInitialized = true;
00065
00066 if (TDEGlobal::locale())
00067 aLocaleString = TDEGlobal::locale()->language().utf8();
00068 else
00069 aLocaleString = TDELocale::defaultLanguage().utf8();
00070 if (backEnd)
00071 backEnd->setLocaleString(aLocaleString);
00072 }
00073
00074 TQString TDEConfigBase::locale() const
00075 {
00076 return TQString::fromUtf8(aLocaleString);
00077 }
00078
00079 void TDEConfigBase::setGroup( const TQString& group )
00080 {
00081 if ( group.isEmpty() )
00082 mGroup = "<default>";
00083 else
00084 mGroup = group.utf8();
00085 }
00086
00087 void TDEConfigBase::setGroup( const char *pGroup )
00088 {
00089 setGroup(TQCString(pGroup));
00090 }
00091
00092 void TDEConfigBase::setGroup( const TQCString &group )
00093 {
00094 if ( group.isEmpty() )
00095 mGroup = "<default>";
00096 else
00097 mGroup = group;
00098 }
00099
00100 TQString TDEConfigBase::group() const {
00101 return TQString::fromUtf8(mGroup);
00102 }
00103
00104 void TDEConfigBase::setDesktopGroup()
00105 {
00106 mGroup = "Desktop Entry";
00107 }
00108
00109 bool TDEConfigBase::hasKey(const TQString &key) const
00110 {
00111 return hasKey(key.utf8().data());
00112 }
00113
00114 bool TDEConfigBase::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 TDEConfigBase::hasTranslatedKey(const char* pKey) const
00135 {
00136 KEntryKey aEntryKey(mGroup, 0);
00137 aEntryKey.c_key = pKey;
00138 aEntryKey.bDefault = readDefaults();
00139
00140 if (!locale().isNull()) {
00141
00142 aEntryKey.bLocal = true;
00143 KEntry entry = lookupData(aEntryKey);
00144 if (!entry.mValue.isNull())
00145 return true;
00146 aEntryKey.bLocal = false;
00147 }
00148
00149 return false;
00150 }
00151
00152 bool TDEConfigBase::hasGroup(const TQString &group) const
00153 {
00154 return internalHasGroup( group.utf8());
00155 }
00156
00157 bool TDEConfigBase::hasGroup(const char *_pGroup) const
00158 {
00159 return internalHasGroup( TQCString(_pGroup));
00160 }
00161
00162 bool TDEConfigBase::hasGroup(const TQCString &_pGroup) const
00163 {
00164 return internalHasGroup( _pGroup);
00165 }
00166
00167 bool TDEConfigBase::isImmutable() const
00168 {
00169 return (getConfigState() != ReadWrite);
00170 }
00171
00172 bool TDEConfigBase::groupIsImmutable(const TQString &group) const
00173 {
00174 if (getConfigState() != ReadWrite)
00175 return true;
00176
00177 KEntryKey groupKey(group.utf8(), 0);
00178 KEntry entry = lookupData(groupKey);
00179 return entry.bImmutable;
00180 }
00181
00182 bool TDEConfigBase::entryIsImmutable(const TQString &key) const
00183 {
00184 if (getConfigState() != ReadWrite)
00185 return true;
00186
00187 KEntryKey entryKey(mGroup, 0);
00188 KEntry aEntryData = lookupData(entryKey);
00189 if (aEntryData.bImmutable)
00190 return true;
00191
00192 TQCString utf8_key = key.utf8();
00193 entryKey.c_key = utf8_key.data();
00194 aEntryData = lookupData(entryKey);
00195 if (aEntryData.bImmutable)
00196 return true;
00197
00198 entryKey.bLocal = true;
00199 aEntryData = lookupData(entryKey);
00200 return aEntryData.bImmutable;
00201 }
00202
00203
00204 TQString TDEConfigBase::readEntryUntranslated( const TQString& pKey,
00205 const TQString& aDefault ) const
00206 {
00207 return TDEConfigBase::readEntryUntranslated(pKey.utf8().data(), aDefault);
00208 }
00209
00210
00211 TQString TDEConfigBase::readEntryUntranslated( const char *pKey,
00212 const TQString& aDefault ) const
00213 {
00214 TQCString result = readEntryUtf8(pKey);
00215 if (result.isNull())
00216 return aDefault;
00217 return TQString::fromUtf8(result);
00218 }
00219
00220
00221 TQString TDEConfigBase::readEntry( const TQString& pKey,
00222 const TQString& aDefault ) const
00223 {
00224 return TDEConfigBase::readEntry(pKey.utf8().data(), aDefault);
00225 }
00226
00227 TQString TDEConfigBase::readEntry( const char *pKey,
00228 const TQString& aDefault ) const
00229 {
00230
00231
00232
00233
00234 if (!bLocaleInitialized && TDEGlobal::_locale) {
00235
00236 TDEConfigBase *that = const_cast<TDEConfigBase *>(this);
00237 that->setLocale();
00238 }
00239
00240 TQString aValue;
00241
00242 bool expand = false;
00243
00244
00245 KEntry aEntryData;
00246 KEntryKey entryKey(mGroup, 0);
00247 entryKey.c_key = pKey;
00248 entryKey.bDefault = readDefaults();
00249 entryKey.bLocal = true;
00250 aEntryData = lookupData(entryKey);
00251 if (!aEntryData.mValue.isNull()) {
00252
00253 aValue = KStringHandler::from8Bit( aEntryData.mValue.data() );
00254 expand = aEntryData.bExpand;
00255 } else {
00256 entryKey.bLocal = false;
00257 aEntryData = lookupData(entryKey);
00258 if (!aEntryData.mValue.isNull()) {
00259 aValue = TQString::fromUtf8(aEntryData.mValue.data());
00260 if (aValue.isNull())
00261 {
00262 static const TQString &emptyString = TDEGlobal::staticQString("");
00263 aValue = emptyString;
00264 }
00265 expand = aEntryData.bExpand;
00266 } else {
00267 aValue = aDefault;
00268 }
00269 }
00270
00271
00272 if( expand || bExpand )
00273 {
00274
00275 int nDollarPos = aValue.find( '$' );
00276
00277 while( nDollarPos != -1 && nDollarPos+1 < static_cast<int>(aValue.length())) {
00278
00279 if( (aValue)[nDollarPos+1] == '(' ) {
00280 uint nEndPos = nDollarPos+1;
00281
00282 while ( (nEndPos <= aValue.length()) && (aValue[nEndPos]!=')') )
00283 nEndPos++;
00284 nEndPos++;
00285 TQString cmd = aValue.mid( nDollarPos+2, nEndPos-nDollarPos-3 );
00286
00287 TQString result;
00288 FILE *fs = popen(TQFile::encodeName(cmd).data(), "r");
00289 if (fs)
00290 {
00291 {
00292 TQTextStream ts(fs, IO_ReadOnly);
00293 result = ts.read().stripWhiteSpace();
00294 }
00295 pclose(fs);
00296 }
00297 aValue.replace( nDollarPos, nEndPos-nDollarPos, result );
00298 } else if( (aValue)[nDollarPos+1] != '$' ) {
00299 uint nEndPos = nDollarPos+1;
00300
00301 TQString aVarName;
00302 if (aValue[nEndPos]=='{')
00303 {
00304 while ( (nEndPos <= aValue.length()) && (aValue[nEndPos]!='}') )
00305 nEndPos++;
00306 nEndPos++;
00307 aVarName = aValue.mid( nDollarPos+2, nEndPos-nDollarPos-3 );
00308 }
00309 else
00310 {
00311 while ( nEndPos <= aValue.length() && (aValue[nEndPos].isNumber()
00312 || aValue[nEndPos].isLetter() || aValue[nEndPos]=='_' ) )
00313 nEndPos++;
00314 aVarName = aValue.mid( nDollarPos+1, nEndPos-nDollarPos-1 );
00315 }
00316 const char* pEnv = 0;
00317 if (!aVarName.isEmpty())
00318 pEnv = getenv( aVarName.ascii() );
00319 if( pEnv ) {
00320
00321
00322
00323 aValue.replace( nDollarPos, nEndPos-nDollarPos, KStringHandler::from8Bit( pEnv ) );
00324 } else
00325 aValue.remove( nDollarPos, nEndPos-nDollarPos );
00326 } else {
00327
00328 aValue.remove( nDollarPos, 1 );
00329 nDollarPos++;
00330 }
00331 nDollarPos = aValue.find( '$', nDollarPos );
00332 }
00333 }
00334
00335 return aValue;
00336 }
00337
00338 TQCString TDEConfigBase::readEntryUtf8( const char *pKey) const
00339 {
00340
00341 KEntryKey entryKey(mGroup, 0);
00342 entryKey.bDefault = readDefaults();
00343 entryKey.c_key = pKey;
00344 KEntry aEntryData = lookupData(entryKey);
00345 if (aEntryData.bExpand)
00346 {
00347
00348 return readEntry(pKey, TQString::null).utf8();
00349 }
00350 return aEntryData.mValue;
00351 }
00352
00353 TQVariant TDEConfigBase::readPropertyEntry( const TQString& pKey,
00354 TQVariant::Type type ) const
00355 {
00356 return readPropertyEntry(pKey.utf8().data(), type);
00357 }
00358
00359 TQVariant TDEConfigBase::readPropertyEntry( const char *pKey,
00360 TQVariant::Type type ) const
00361 {
00362 TQVariant va;
00363 if ( !hasKey( pKey ) ) return va;
00364 (void)va.cast(type);
00365 return readPropertyEntry(pKey, va);
00366 }
00367
00368 TQVariant TDEConfigBase::readPropertyEntry( const TQString& pKey,
00369 const TQVariant &aDefault ) const
00370 {
00371 return readPropertyEntry(pKey.utf8().data(), aDefault);
00372 }
00373
00374 TQVariant TDEConfigBase::readPropertyEntry( const char *pKey,
00375 const TQVariant &aDefault ) const
00376 {
00377 if ( !hasKey( pKey ) ) return aDefault;
00378
00379 TQVariant tmp = aDefault;
00380
00381 switch( aDefault.type() )
00382 {
00383 case TQVariant::Invalid:
00384 return TQVariant();
00385 case TQVariant::String:
00386 return TQVariant( readEntry( pKey, aDefault.toString() ) );
00387 case TQVariant::StringList:
00388 return TQVariant( readListEntry( pKey ) );
00389 case TQVariant::List: {
00390 TQStringList strList = readListEntry( pKey );
00391 TQStringList::ConstIterator it = strList.begin();
00392 TQStringList::ConstIterator end = strList.end();
00393 TQValueList<TQVariant> list;
00394
00395 for (; it != end; ++it ) {
00396 tmp = *it;
00397 list.append( tmp );
00398 }
00399 return TQVariant( list );
00400 }
00401 case TQVariant::Font:
00402 return TQVariant( readFontEntry( pKey, &tmp.asFont() ) );
00403 case TQVariant::Point:
00404 return TQVariant( readPointEntry( pKey, &tmp.asPoint() ) );
00405 case TQVariant::Rect:
00406 return TQVariant( readRectEntry( pKey, &tmp.asRect() ) );
00407 case TQVariant::Size:
00408 return TQVariant( readSizeEntry( pKey, &tmp.asSize() ) );
00409 case TQVariant::Color:
00410 return TQVariant( readColorEntry( pKey, &tmp.asColor() ) );
00411 case TQVariant::Int:
00412 return TQVariant( readNumEntry( pKey, aDefault.toInt() ) );
00413 case TQVariant::UInt:
00414 return TQVariant( readUnsignedNumEntry( pKey, aDefault.toUInt() ) );
00415 case TQVariant::LongLong:
00416 return TQVariant( readNum64Entry( pKey, aDefault.toLongLong() ) );
00417 case TQVariant::ULongLong:
00418 return TQVariant( readUnsignedNum64Entry( pKey, aDefault.toULongLong() ) );
00419 case TQVariant::Bool:
00420 return TQVariant( readBoolEntry( pKey, aDefault.toBool() ), 0 );
00421 case TQVariant::Double:
00422 return TQVariant( readDoubleNumEntry( pKey, aDefault.toDouble() ) );
00423 case TQVariant::DateTime:
00424 return TQVariant( readDateTimeEntry( pKey, &tmp.asDateTime() ) );
00425 case TQVariant::Date:
00426 return TQVariant(TQT_TQDATE_OBJECT(readDateTimeEntry( pKey, &tmp.asDateTime() ).date()));
00427
00428 case TQVariant::Pixmap:
00429 case TQVariant::Image:
00430 case TQVariant::Brush:
00431 case TQVariant::Palette:
00432 case TQVariant::ColorGroup:
00433 case TQVariant::Map:
00434 case TQVariant::IconSet:
00435 case TQVariant::CString:
00436 case TQVariant::PointArray:
00437 case TQVariant::Region:
00438 case TQVariant::Bitmap:
00439 case TQVariant::Cursor:
00440 case TQVariant::SizePolicy:
00441 case TQVariant::Time:
00442 #ifdef USE_QT3
00443 case TQVariant::ByteArray:
00444 #endif // USE_QT3
00445 case TQVariant::BitArray:
00446 case TQVariant::KeySequence:
00447 case TQVariant::Pen:
00448 #ifdef USE_QT4
00449 case TQVariant::Char:
00450 case TQVariant::Url:
00451 case TQVariant::Locale:
00452 case TQVariant::RectF:
00453 case TQVariant::SizeF:
00454 case TQVariant::Line:
00455 case TQVariant::LineF:
00456 case TQVariant::PointF:
00457 case TQVariant::RegExp:
00458 case TQVariant::Hash:
00459 case TQVariant::TextLength:
00460 case QVariant::TextFormat:
00461 case TQVariant::Matrix:
00462 case TQVariant::Transform:
00463 case TQVariant::Matrix4x4:
00464 case TQVariant::Vector2D:
00465 case TQVariant::Vector3D:
00466 case TQVariant::Vector4D:
00467 case TQVariant::Quaternion:
00468 case TQVariant::UserType:
00469 #endif // USE_QT4
00470 break;
00471 }
00472
00473 Q_ASSERT( 0 );
00474 return TQVariant();
00475 }
00476
00477 int TDEConfigBase::readListEntry( const TQString& pKey,
00478 TQStrList &list, char sep ) const
00479 {
00480 return readListEntry(pKey.utf8().data(), list, sep);
00481 }
00482
00483 int TDEConfigBase::readListEntry( const char *pKey,
00484 TQStrList &list, char sep ) const
00485 {
00486 if( !hasKey( pKey ) )
00487 return 0;
00488
00489 TQCString str_list = readEntryUtf8( pKey );
00490 if (str_list.isEmpty())
00491 return 0;
00492
00493 list.clear();
00494 TQCString value = "";
00495 int len = str_list.length();
00496
00497 for (int i = 0; i < len; i++) {
00498 if (str_list[i] != sep && str_list[i] != '\\') {
00499 value += str_list[i];
00500 continue;
00501 }
00502 if (str_list[i] == '\\') {
00503 i++;
00504 if ( i < len )
00505 value += str_list[i];
00506 continue;
00507 }
00508
00509
00510
00511
00512
00513 list.append( value );
00514 value.truncate(0);
00515 }
00516
00517 if ( str_list[len-1] != sep || ( len > 1 && str_list[len-2] == '\\' ) )
00518 list.append( value );
00519 return list.count();
00520 }
00521
00522 TQStringList TDEConfigBase::readListEntry( const TQString& pKey, char sep ) const
00523 {
00524 return readListEntry(pKey.utf8().data(), sep);
00525 }
00526
00527 TQStringList TDEConfigBase::readListEntry( const char *pKey, char sep ) const
00528 {
00529 static const TQString& emptyString = TDEGlobal::staticQString("");
00530
00531 TQStringList list;
00532 if( !hasKey( pKey ) )
00533 return list;
00534 TQString str_list = readEntry( pKey );
00535 if( str_list.isEmpty() )
00536 return list;
00537 TQString value(emptyString);
00538 int len = str_list.length();
00539
00540 value.reserve( len );
00541 for( int i = 0; i < len; i++ )
00542 {
00543 if( str_list[i] != sep && str_list[i] != '\\' )
00544 {
00545 value += str_list[i];
00546 continue;
00547 }
00548 if( str_list[i] == '\\' )
00549 {
00550 i++;
00551 if ( i < len )
00552 value += str_list[i];
00553 continue;
00554 }
00555 TQString finalvalue( value );
00556 finalvalue.squeeze();
00557 list.append( finalvalue );
00558 value.truncate( 0 );
00559 }
00560 if ( str_list[len-1] != sep || ( len > 1 && str_list[len-2] == '\\' ) )
00561 {
00562 value.squeeze();
00563 list.append( value );
00564 }
00565 return list;
00566 }
00567
00568 TQStringList TDEConfigBase::readListEntry( const char* pKey, const TQStringList& aDefault,
00569 char sep ) const
00570 {
00571 if ( !hasKey( pKey ) )
00572 return aDefault;
00573 else
00574 return readListEntry( pKey, sep );
00575 }
00576
00577 TQValueList<int> TDEConfigBase::readIntListEntry( const TQString& pKey ) const
00578 {
00579 return readIntListEntry(pKey.utf8().data());
00580 }
00581
00582 TQValueList<int> TDEConfigBase::readIntListEntry( const char *pKey ) const
00583 {
00584 TQStringList strlist = readListEntry(pKey);
00585 TQValueList<int> list;
00586 TQStringList::ConstIterator end(strlist.end());
00587 for (TQStringList::ConstIterator it = strlist.begin(); it != end; ++it)
00588
00589
00590 list << (*it).toInt();
00591
00592 return list;
00593 }
00594
00595 TQString TDEConfigBase::readPathEntry( const TQString& pKey, const TQString& pDefault ) const
00596 {
00597 return readPathEntry(pKey.utf8().data(), pDefault);
00598 }
00599
00600 TQString TDEConfigBase::readPathEntry( const char *pKey, const TQString& pDefault ) const
00601 {
00602 const bool bExpandSave = bExpand;
00603 bExpand = true;
00604 TQString aValue = readEntry( pKey, pDefault );
00605 bExpand = bExpandSave;
00606 return aValue;
00607 }
00608
00609 TQStringList TDEConfigBase::readPathListEntry( const TQString& pKey, char sep ) const
00610 {
00611 return readPathListEntry(pKey.utf8().data(), sep);
00612 }
00613
00614 TQStringList TDEConfigBase::readPathListEntry( const char *pKey, char sep ) const
00615 {
00616 const bool bExpandSave = bExpand;
00617 bExpand = true;
00618 TQStringList aValue = readListEntry( pKey, sep );
00619 bExpand = bExpandSave;
00620 return aValue;
00621 }
00622
00623 int TDEConfigBase::readNumEntry( const TQString& pKey, int nDefault) const
00624 {
00625 return readNumEntry(pKey.utf8().data(), nDefault);
00626 }
00627
00628 int TDEConfigBase::readNumEntry( const char *pKey, int nDefault) const
00629 {
00630 TQCString aValue = readEntryUtf8( pKey );
00631 if( aValue.isNull() )
00632 return nDefault;
00633 else if( aValue == "true" || aValue == "on" || aValue == "yes" )
00634 return 1;
00635 else
00636 {
00637 bool ok;
00638 int rc = aValue.toInt( &ok );
00639 return( ok ? rc : nDefault );
00640 }
00641 }
00642
00643
00644 unsigned int TDEConfigBase::readUnsignedNumEntry( const TQString& pKey, unsigned int nDefault) const
00645 {
00646 return readUnsignedNumEntry(pKey.utf8().data(), nDefault);
00647 }
00648
00649 unsigned int TDEConfigBase::readUnsignedNumEntry( const char *pKey, unsigned int nDefault) const
00650 {
00651 TQCString aValue = readEntryUtf8( pKey );
00652 if( aValue.isNull() )
00653 return nDefault;
00654 else
00655 {
00656 bool ok;
00657 unsigned int rc = aValue.toUInt( &ok );
00658 return( ok ? rc : nDefault );
00659 }
00660 }
00661
00662
00663 long TDEConfigBase::readLongNumEntry( const TQString& pKey, long nDefault) const
00664 {
00665 return readLongNumEntry(pKey.utf8().data(), nDefault);
00666 }
00667
00668 long TDEConfigBase::readLongNumEntry( const char *pKey, long nDefault) const
00669 {
00670 TQCString aValue = readEntryUtf8( pKey );
00671 if( aValue.isNull() )
00672 return nDefault;
00673 else
00674 {
00675 bool ok;
00676 long rc = aValue.toLong( &ok );
00677 return( ok ? rc : nDefault );
00678 }
00679 }
00680
00681
00682 unsigned long TDEConfigBase::readUnsignedLongNumEntry( const TQString& pKey, unsigned long nDefault) const
00683 {
00684 return readUnsignedLongNumEntry(pKey.utf8().data(), nDefault);
00685 }
00686
00687 unsigned long TDEConfigBase::readUnsignedLongNumEntry( const char *pKey, unsigned long nDefault) const
00688 {
00689 TQCString aValue = readEntryUtf8( pKey );
00690 if( aValue.isNull() )
00691 return nDefault;
00692 else
00693 {
00694 bool ok;
00695 unsigned long rc = aValue.toULong( &ok );
00696 return( ok ? rc : nDefault );
00697 }
00698 }
00699
00700 TQ_INT64 TDEConfigBase::readNum64Entry( const TQString& pKey, TQ_INT64 nDefault) const
00701 {
00702 return readNum64Entry(pKey.utf8().data(), nDefault);
00703 }
00704
00705 TQ_INT64 TDEConfigBase::readNum64Entry( const char *pKey, TQ_INT64 nDefault) const
00706 {
00707
00708 TQString aValue = readEntry( pKey );
00709 if( aValue.isNull() )
00710 return nDefault;
00711 else
00712 {
00713 bool ok;
00714 TQ_INT64 rc = aValue.toLongLong( &ok );
00715 return( ok ? rc : nDefault );
00716 }
00717 }
00718
00719
00720 TQ_UINT64 TDEConfigBase::readUnsignedNum64Entry( const TQString& pKey, TQ_UINT64 nDefault) const
00721 {
00722 return readUnsignedNum64Entry(pKey.utf8().data(), nDefault);
00723 }
00724
00725 TQ_UINT64 TDEConfigBase::readUnsignedNum64Entry( const char *pKey, TQ_UINT64 nDefault) const
00726 {
00727
00728 TQString aValue = readEntry( pKey );
00729 if( aValue.isNull() )
00730 return nDefault;
00731 else
00732 {
00733 bool ok;
00734 TQ_UINT64 rc = aValue.toULongLong( &ok );
00735 return( ok ? rc : nDefault );
00736 }
00737 }
00738
00739 double TDEConfigBase::readDoubleNumEntry( const TQString& pKey, double nDefault) const
00740 {
00741 return readDoubleNumEntry(pKey.utf8().data(), nDefault);
00742 }
00743
00744 double TDEConfigBase::readDoubleNumEntry( const char *pKey, double nDefault) const
00745 {
00746 TQCString aValue = readEntryUtf8( pKey );
00747 if( aValue.isNull() )
00748 return nDefault;
00749 else
00750 {
00751 bool ok;
00752 double rc = aValue.toDouble( &ok );
00753 return( ok ? rc : nDefault );
00754 }
00755 }
00756
00757
00758 bool TDEConfigBase::readBoolEntry( const TQString& pKey, bool bDefault ) const
00759 {
00760 return readBoolEntry(pKey.utf8().data(), bDefault);
00761 }
00762
00763 bool TDEConfigBase::readBoolEntry( const char *pKey, bool bDefault ) const
00764 {
00765 TQCString aValue = readEntryUtf8( pKey );
00766
00767 if( aValue.isNull() )
00768 return bDefault;
00769 else
00770 {
00771 if( aValue == "true" || aValue == "on" || aValue == "yes" || aValue == "1" )
00772 return true;
00773 else
00774 {
00775 bool bOK;
00776 int val = aValue.toInt( &bOK );
00777 if( bOK && val != 0 )
00778 return true;
00779 else
00780 return false;
00781 }
00782 }
00783 }
00784
00785 TQFont TDEConfigBase::readFontEntry( const TQString& pKey, const TQFont* pDefault ) const
00786 {
00787 return readFontEntry(pKey.utf8().data(), pDefault);
00788 }
00789
00790 TQFont TDEConfigBase::readFontEntry( const char *pKey, const TQFont* pDefault ) const
00791 {
00792 TQFont aRetFont;
00793
00794 TQString aValue = readEntry( pKey );
00795 if( !aValue.isNull() ) {
00796 if ( aValue.contains( ',' ) > 5 ) {
00797
00798 if ( !aRetFont.fromString( aValue ) && pDefault )
00799 aRetFont = *pDefault;
00800 }
00801 else {
00802
00803
00804
00805 int nIndex = aValue.find( ',' );
00806 if( nIndex == -1 ){
00807 if( pDefault )
00808 aRetFont = *pDefault;
00809 return aRetFont;
00810 }
00811 aRetFont.setFamily( aValue.left( nIndex ) );
00812
00813
00814 int nOldIndex = nIndex;
00815 nIndex = aValue.find( ',', nOldIndex+1 );
00816 if( nIndex == -1 ){
00817 if( pDefault )
00818 aRetFont = *pDefault;
00819 return aRetFont;
00820 }
00821
00822 aRetFont.setPointSize( aValue.mid( nOldIndex+1,
00823 nIndex-nOldIndex-1 ).toInt() );
00824
00825
00826 nOldIndex = nIndex;
00827 nIndex = aValue.find( ',', nOldIndex+1 );
00828
00829 if( nIndex == -1 ){
00830 if( pDefault )
00831 aRetFont = *pDefault;
00832 return aRetFont;
00833 }
00834
00835 aRetFont.setStyleHint( (TQFont::StyleHint)aValue.mid( nOldIndex+1, nIndex-nOldIndex-1 ).toUInt() );
00836
00837
00838 nOldIndex = nIndex;
00839 nIndex = aValue.find( ',', nOldIndex+1 );
00840
00841 if( nIndex == -1 ){
00842 if( pDefault )
00843 aRetFont = *pDefault;
00844 return aRetFont;
00845 }
00846
00847 TQString chStr=aValue.mid( nOldIndex+1,
00848 nIndex-nOldIndex-1 );
00849
00850 nOldIndex = nIndex;
00851 nIndex = aValue.find( ',', nOldIndex+1 );
00852
00853 if( nIndex == -1 ){
00854 if( pDefault )
00855 aRetFont = *pDefault;
00856 return aRetFont;
00857 }
00858
00859 aRetFont.setWeight( aValue.mid( nOldIndex+1,
00860 nIndex-nOldIndex-1 ).toUInt() );
00861
00862
00863 uint nFontBits = aValue.right( aValue.length()-nIndex-1 ).toUInt();
00864
00865 aRetFont.setItalic( nFontBits & 0x01 );
00866 aRetFont.setUnderline( nFontBits & 0x02 );
00867 aRetFont.setStrikeOut( nFontBits & 0x04 );
00868 aRetFont.setFixedPitch( nFontBits & 0x08 );
00869 aRetFont.setRawMode( nFontBits & 0x20 );
00870 }
00871 }
00872 else
00873 {
00874 if( pDefault )
00875 aRetFont = *pDefault;
00876 }
00877
00878 return aRetFont;
00879 }
00880
00881
00882 TQRect TDEConfigBase::readRectEntry( const TQString& pKey, const TQRect* pDefault ) const
00883 {
00884 return readRectEntry(pKey.utf8().data(), pDefault);
00885 }
00886
00887 TQRect TDEConfigBase::readRectEntry( const char *pKey, const TQRect* pDefault ) const
00888 {
00889 TQCString aValue = readEntryUtf8(pKey);
00890
00891 if (!aValue.isEmpty())
00892 {
00893 int left, top, width, height;
00894
00895 if (sscanf(aValue.data(), "%d,%d,%d,%d", &left, &top, &width, &height) == 4)
00896 {
00897 return TQRect(left, top, width, height);
00898 }
00899 }
00900 if (pDefault)
00901 return *pDefault;
00902 return TQRect();
00903 }
00904
00905
00906 TQPoint TDEConfigBase::readPointEntry( const TQString& pKey,
00907 const TQPoint* pDefault ) const
00908 {
00909 return readPointEntry(pKey.utf8().data(), pDefault);
00910 }
00911
00912 TQPoint TDEConfigBase::readPointEntry( const char *pKey,
00913 const TQPoint* pDefault ) const
00914 {
00915 TQCString aValue = readEntryUtf8(pKey);
00916
00917 if (!aValue.isEmpty())
00918 {
00919 int x,y;
00920
00921 if (sscanf(aValue.data(), "%d,%d", &x, &y) == 2)
00922 {
00923 return TQPoint(x,y);
00924 }
00925 }
00926 if (pDefault)
00927 return *pDefault;
00928 return TQPoint();
00929 }
00930
00931 TQSize TDEConfigBase::readSizeEntry( const TQString& pKey,
00932 const TQSize* pDefault ) const
00933 {
00934 return readSizeEntry(pKey.utf8().data(), pDefault);
00935 }
00936
00937 TQSize TDEConfigBase::readSizeEntry( const char *pKey,
00938 const TQSize* pDefault ) const
00939 {
00940 TQCString aValue = readEntryUtf8(pKey);
00941
00942 if (!aValue.isEmpty())
00943 {
00944 int width,height;
00945
00946 if (sscanf(aValue.data(), "%d,%d", &width, &height) == 2)
00947 {
00948 return TQSize(width, height);
00949 }
00950 }
00951 if (pDefault)
00952 return *pDefault;
00953 return TQSize();
00954 }
00955
00956
00957 TQColor TDEConfigBase::readColorEntry( const TQString& pKey,
00958 const TQColor* pDefault ) const
00959 {
00960 return readColorEntry(pKey.utf8().data(), pDefault);
00961 }
00962
00963 TQColor TDEConfigBase::readColorEntry( const char *pKey,
00964 const TQColor* pDefault ) const
00965 {
00966 TQColor aRetColor;
00967 int nRed = 0, nGreen = 0, nBlue = 0;
00968
00969 TQString aValue = readEntry( pKey );
00970 if( !aValue.isEmpty() )
00971 {
00972 if ( aValue.at(0) == (QChar)'#' )
00973 {
00974 aRetColor.setNamedColor(aValue);
00975 }
00976 else
00977 {
00978
00979 bool bOK;
00980
00981
00982 int nIndex = aValue.find( ',' );
00983
00984 if( nIndex == -1 ){
00985
00986 if( pDefault )
00987 aRetColor = *pDefault;
00988 return aRetColor;
00989 }
00990
00991 nRed = aValue.left( nIndex ).toInt( &bOK );
00992
00993
00994 int nOldIndex = nIndex;
00995 nIndex = aValue.find( ',', nOldIndex+1 );
00996
00997 if( nIndex == -1 ){
00998
00999 if( pDefault )
01000 aRetColor = *pDefault;
01001 return aRetColor;
01002 }
01003 nGreen = aValue.mid( nOldIndex+1,
01004 nIndex-nOldIndex-1 ).toInt( &bOK );
01005
01006
01007 nBlue = aValue.right( aValue.length()-nIndex-1 ).toInt( &bOK );
01008
01009 aRetColor.setRgb( nRed, nGreen, nBlue );
01010 }
01011 }
01012 else {
01013
01014 if( pDefault )
01015 aRetColor = *pDefault;
01016 }
01017
01018 return aRetColor;
01019 }
01020
01021
01022 TQDateTime TDEConfigBase::readDateTimeEntry( const TQString& pKey,
01023 const TQDateTime* pDefault ) const
01024 {
01025 return readDateTimeEntry(pKey.utf8().data(), pDefault);
01026 }
01027
01028
01029 TQDateTime TDEConfigBase::readDateTimeEntry( const char *pKey,
01030 const TQDateTime* pDefault ) const
01031 {
01032 if( !hasKey( pKey ) )
01033 {
01034 if( pDefault )
01035 return *pDefault;
01036 else
01037 return TQDateTime::currentDateTime();
01038 }
01039
01040 TQStrList list;
01041 int count = readListEntry( pKey, list, ',' );
01042 if( count == 6 ) {
01043 TQDate date( atoi( list.at( 0 ) ), atoi( list.at( 1 ) ),
01044 atoi( list.at( 2 ) ) );
01045 TQTime time( atoi( list.at( 3 ) ), atoi( list.at( 4 ) ),
01046 atoi( list.at( 5 ) ) );
01047
01048 return TQDateTime( date, time );
01049 }
01050
01051 return TQDateTime::currentDateTime();
01052 }
01053
01054 void TDEConfigBase::writeEntry( const TQString& pKey, const TQString& value,
01055 bool bPersistent,
01056 bool bGlobal,
01057 bool bNLS )
01058 {
01059 writeEntry(pKey.utf8().data(), value, bPersistent, bGlobal, bNLS);
01060 }
01061
01062 void TDEConfigBase::writeEntry( const char *pKey, const TQString& value,
01063 bool bPersistent,
01064 bool bGlobal,
01065 bool bNLS )
01066 {
01067 writeEntry(pKey, value, bPersistent, bGlobal, bNLS, false);
01068 }
01069
01070 void TDEConfigBase::writeEntry( const char *pKey, const TQString& value,
01071 bool bPersistent,
01072 bool bGlobal,
01073 bool bNLS,
01074 bool bExpand )
01075 {
01076
01077
01078
01079
01080
01081 if( bPersistent )
01082 setDirty(true);
01083
01084 if (!bLocaleInitialized && TDEGlobal::locale())
01085 setLocale();
01086
01087 KEntryKey entryKey(mGroup, pKey);
01088 entryKey.bLocal = bNLS;
01089
01090 KEntry aEntryData;
01091 aEntryData.mValue = value.utf8();
01092 aEntryData.bGlobal = bGlobal;
01093 aEntryData.bNLS = bNLS;
01094 aEntryData.bExpand = bExpand;
01095
01096 if (bPersistent)
01097 aEntryData.bDirty = true;
01098
01099
01100 putData(entryKey, aEntryData, true);
01101 }
01102
01103 void TDEConfigBase::writePathEntry( const TQString& pKey, const TQString & path,
01104 bool bPersistent, bool bGlobal,
01105 bool bNLS)
01106 {
01107 writePathEntry(pKey.utf8().data(), path, bPersistent, bGlobal, bNLS);
01108 }
01109
01110
01111 static bool cleanHomeDirPath( TQString &path, const TQString &homeDir )
01112 {
01113 #ifdef Q_WS_WIN //safer
01114 if (!TQDir::convertSeparators(path).startsWith(TQDir::convertSeparators(homeDir)))
01115 return false;
01116 #else
01117 if (!path.startsWith(homeDir))
01118 return false;
01119 #endif
01120
01121 unsigned int len = homeDir.length();
01122
01123 if (len && (path.length() == len || path[len] == '/')) {
01124 path.replace(0, len, TQString::fromLatin1("$HOME"));
01125 return true;
01126 } else
01127 return false;
01128 }
01129
01130 static TQString translatePath( TQString path )
01131 {
01132 if (path.isEmpty())
01133 return path;
01134
01135
01136 path.replace('$', "$$");
01137
01138 bool startsWithFile = path.startsWith("file:", false);
01139
01140
01141
01142 if (((!startsWithFile) && (path[0] != '/')) || (startsWithFile && (path[5] != '/'))) {
01143 return path;
01144 }
01145
01146 if (startsWithFile) {
01147 path.remove(0,5);
01148 }
01149
01150
01151 while (path[0] == '/' && path[1] == '/') {
01152 path.remove(0,1);
01153 }
01154
01155
01156
01157
01158
01159 TQString homeDir0 = TQFile::decodeName(getenv("HOME"));
01160 TQString homeDir1 = TQDir::homeDirPath();
01161 TQString homeDir2 = TQDir(homeDir1).canonicalPath();
01162 if (cleanHomeDirPath(path, homeDir0) ||
01163 cleanHomeDirPath(path, homeDir1) ||
01164 cleanHomeDirPath(path, homeDir2) ) {
01165
01166 }
01167
01168 if (startsWithFile)
01169 path.prepend( "file://" );
01170
01171 return path;
01172 }
01173
01174 void TDEConfigBase::writePathEntry( const char *pKey, const TQString & path,
01175 bool bPersistent, bool bGlobal,
01176 bool bNLS)
01177 {
01178 writeEntry(pKey, translatePath(path), bPersistent, bGlobal, bNLS, true);
01179 }
01180
01181 void TDEConfigBase::writePathEntry( const char *pKey, const TQString & path,
01182 bool bPersistent, bool bGlobal,
01183 bool bNLS, bool expand)
01184 {
01185 writeEntry(pKey, translatePath(path), bPersistent, bGlobal, bNLS, expand);
01186 }
01187
01188 void TDEConfigBase::writePathEntry ( const TQString& pKey, const TQStringList &list,
01189 char sep , bool bPersistent,
01190 bool bGlobal, bool bNLS )
01191 {
01192 writePathEntry(pKey.utf8().data(), list, sep, bPersistent, bGlobal, bNLS);
01193 }
01194
01195 void TDEConfigBase::writePathEntry ( const char *pKey, const TQStringList &list,
01196 char sep , bool bPersistent,
01197 bool bGlobal, bool bNLS )
01198 {
01199 if( list.isEmpty() )
01200 {
01201 writeEntry( pKey, TQString::fromLatin1(""), bPersistent );
01202 return;
01203 }
01204 TQStringList new_list;
01205 TQStringList::ConstIterator it = list.begin();
01206 for( ; it != list.end(); ++it )
01207 {
01208 TQString value = *it;
01209 new_list.append( translatePath(value) );
01210 }
01211 writeEntry( pKey, new_list, sep, bPersistent, bGlobal, bNLS, true );
01212 }
01213
01214 void TDEConfigBase::deleteEntry( const TQString& pKey,
01215 bool bNLS,
01216 bool bGlobal)
01217 {
01218 deleteEntry(pKey.utf8().data(), bNLS, bGlobal);
01219 }
01220
01221 void TDEConfigBase::deleteEntry( const char *pKey,
01222 bool bNLS,
01223 bool bGlobal)
01224 {
01225
01226
01227
01228
01229
01230 setDirty(true);
01231
01232 if (!bLocaleInitialized && TDEGlobal::locale())
01233 setLocale();
01234
01235 KEntryKey entryKey(mGroup, pKey);
01236 KEntry aEntryData;
01237
01238 aEntryData.bGlobal = bGlobal;
01239 aEntryData.bNLS = bNLS;
01240 aEntryData.bDirty = true;
01241 aEntryData.bDeleted = true;
01242
01243
01244 putData(entryKey, aEntryData, true);
01245 }
01246
01247 bool TDEConfigBase::deleteGroup( const TQString& group, bool bDeep, bool bGlobal )
01248 {
01249 KEntryMap aEntryMap = internalEntryMap(group);
01250
01251 if (!bDeep) {
01252
01253 return aEntryMap.isEmpty();
01254 }
01255
01256 bool dirty = false;
01257 bool checkGroup = true;
01258
01259 KEntryMapIterator aIt;
01260 for (aIt = aEntryMap.begin(); aIt != aEntryMap.end(); ++aIt)
01261 {
01262 if (!aIt.key().mKey.isEmpty() && !aIt.key().bDefault && !(*aIt).bDeleted)
01263 {
01264 (*aIt).bDeleted = true;
01265 (*aIt).bDirty = true;
01266 (*aIt).bGlobal = bGlobal;
01267 (*aIt).mValue = 0;
01268 putData(aIt.key(), *aIt, checkGroup);
01269 checkGroup = false;
01270 dirty = true;
01271 }
01272 }
01273 if (dirty)
01274 setDirty(true);
01275 return true;
01276 }
01277
01278 void TDEConfigBase::writeEntry ( const TQString& pKey, const TQVariant &prop,
01279 bool bPersistent,
01280 bool bGlobal, bool bNLS )
01281 {
01282 writeEntry(pKey.utf8().data(), prop, bPersistent, bGlobal, bNLS);
01283 }
01284
01285 void TDEConfigBase::writeEntry ( const char *pKey, const TQVariant &prop,
01286 bool bPersistent,
01287 bool bGlobal, bool bNLS )
01288 {
01289 switch( prop.type() )
01290 {
01291 case TQVariant::Invalid:
01292 writeEntry( pKey, "", bPersistent, bGlobal, bNLS );
01293 return;
01294 case TQVariant::String:
01295 writeEntry( pKey, prop.toString(), bPersistent, bGlobal, bNLS );
01296 return;
01297 case TQVariant::StringList:
01298 writeEntry( pKey, prop.toStringList(), ',', bPersistent, bGlobal, bNLS );
01299 return;
01300 case TQVariant::List: {
01301 TQValueList<TQVariant> list = prop.toList();
01302 TQValueList<TQVariant>::ConstIterator it = list.begin();
01303 TQValueList<TQVariant>::ConstIterator end = list.end();
01304 TQStringList strList;
01305
01306 for (; it != end; ++it )
01307 strList.append( (*it).toString() );
01308
01309 writeEntry( pKey, strList, ',', bPersistent, bGlobal, bNLS );
01310
01311 return;
01312 }
01313 case TQVariant::Font:
01314 writeEntry( pKey, prop.toFont(), bPersistent, bGlobal, bNLS );
01315 return;
01316 case TQVariant::Point:
01317 writeEntry( pKey, prop.toPoint(), bPersistent, bGlobal, bNLS );
01318 return;
01319 case TQVariant::Rect:
01320 writeEntry( pKey, prop.toRect(), bPersistent, bGlobal, bNLS );
01321 return;
01322 case TQVariant::Size:
01323 writeEntry( pKey, prop.toSize(), bPersistent, bGlobal, bNLS );
01324 return;
01325 case TQVariant::Color:
01326 writeEntry( pKey, prop.toColor(), bPersistent, bGlobal, bNLS );
01327 return;
01328 case TQVariant::Int:
01329 writeEntry( pKey, prop.toInt(), bPersistent, bGlobal, bNLS );
01330 return;
01331 case TQVariant::UInt:
01332 writeEntry( pKey, prop.toUInt(), bPersistent, bGlobal, bNLS );
01333 return;
01334 case TQVariant::LongLong:
01335 writeEntry( pKey, prop.toLongLong(), bPersistent, bGlobal, bNLS );
01336 return;
01337 case TQVariant::ULongLong:
01338 writeEntry( pKey, prop.toULongLong(), bPersistent, bGlobal, bNLS );
01339 return;
01340 case TQVariant::Bool:
01341 writeEntry( pKey, prop.toBool(), bPersistent, bGlobal, bNLS );
01342 return;
01343 case TQVariant::Double:
01344 writeEntry( pKey, prop.toDouble(), bPersistent, bGlobal, 'g', 6, bNLS );
01345 return;
01346 case TQVariant::DateTime:
01347 writeEntry( pKey, prop.toDateTime(), bPersistent, bGlobal, bNLS);
01348 return;
01349 case TQVariant::Date:
01350 writeEntry( pKey, TQDateTime(prop.toDate()), bPersistent, bGlobal, bNLS);
01351 return;
01352
01353 case TQVariant::Pixmap:
01354 case TQVariant::Image:
01355 case TQVariant::Brush:
01356 case TQVariant::Palette:
01357 case TQVariant::ColorGroup:
01358 case TQVariant::Map:
01359 case TQVariant::IconSet:
01360 case TQVariant::CString:
01361 case TQVariant::PointArray:
01362 case TQVariant::Region:
01363 case TQVariant::Bitmap:
01364 case TQVariant::Cursor:
01365 case TQVariant::SizePolicy:
01366 case TQVariant::Time:
01367 #ifdef USE_QT3
01368 case TQVariant::ByteArray:
01369 #endif // USE_QT3
01370 case TQVariant::BitArray:
01371 case TQVariant::KeySequence:
01372 case TQVariant::Pen:
01373 #ifdef USE_QT4
01374 case TQVariant::Char:
01375 case TQVariant::Url:
01376 case TQVariant::Locale:
01377 case TQVariant::RectF:
01378 case TQVariant::SizeF:
01379 case TQVariant::Line:
01380 case TQVariant::LineF:
01381 case TQVariant::PointF:
01382 case TQVariant::RegExp:
01383 case TQVariant::Hash:
01384 case TQVariant::TextLength:
01385 case QVariant::TextFormat:
01386 case TQVariant::Matrix:
01387 case TQVariant::Transform:
01388 case TQVariant::Matrix4x4:
01389 case TQVariant::Vector2D:
01390 case TQVariant::Vector3D:
01391 case TQVariant::Vector4D:
01392 case TQVariant::Quaternion:
01393 case TQVariant::UserType:
01394 #endif // USE_QT4
01395 break;
01396 }
01397
01398 Q_ASSERT( 0 );
01399 }
01400
01401 void TDEConfigBase::writeEntry ( const TQString& pKey, const TQStrList &list,
01402 char sep , bool bPersistent,
01403 bool bGlobal, bool bNLS )
01404 {
01405 writeEntry(pKey.utf8().data(), list, sep, bPersistent, bGlobal, bNLS);
01406 }
01407
01408 void TDEConfigBase::writeEntry ( const char *pKey, const TQStrList &list,
01409 char sep , bool bPersistent,
01410 bool bGlobal, bool bNLS )
01411 {
01412 if( list.isEmpty() )
01413 {
01414 writeEntry( pKey, TQString::fromLatin1(""), bPersistent );
01415 return;
01416 }
01417 TQString str_list;
01418 TQStrListIterator it( list );
01419 for( ; it.current(); ++it )
01420 {
01421 uint i;
01422 TQString value;
01423
01424
01425
01426 value = KStringHandler::from8Bit(it.current());
01427 uint strLengh(value.length());
01428 for( i = 0; i < strLengh; i++ )
01429 {
01430 if( value[i] == sep || value[i] == '\\' )
01431 str_list += '\\';
01432 str_list += value[i];
01433 }
01434 str_list += sep;
01435 }
01436 if( str_list.at(str_list.length() - 1) == (QChar)sep )
01437 str_list.truncate( str_list.length() -1 );
01438 writeEntry( pKey, str_list, bPersistent, bGlobal, bNLS );
01439 }
01440
01441 void TDEConfigBase::writeEntry ( const TQString& pKey, const TQStringList &list,
01442 char sep , bool bPersistent,
01443 bool bGlobal, bool bNLS )
01444 {
01445 writeEntry(pKey.utf8().data(), list, sep, bPersistent, bGlobal, bNLS);
01446 }
01447
01448 void TDEConfigBase::writeEntry ( const char *pKey, const TQStringList &list,
01449 char sep , bool bPersistent,
01450 bool bGlobal, bool bNLS )
01451 {
01452 writeEntry(pKey, list, sep, bPersistent, bGlobal, bNLS, false);
01453 }
01454
01455 void TDEConfigBase::writeEntry ( const char *pKey, const TQStringList &list,
01456 char sep, bool bPersistent,
01457 bool bGlobal, bool bNLS, bool bExpand )
01458 {
01459 if( list.isEmpty() )
01460 {
01461 writeEntry( pKey, TQString::fromLatin1(""), bPersistent );
01462 return;
01463 }
01464 TQString str_list;
01465 str_list.reserve( 4096 );
01466 TQStringList::ConstIterator it = list.begin();
01467 for( ; it != list.end(); ++it )
01468 {
01469 TQString value = *it;
01470 uint i;
01471 uint strLength(value.length());
01472 for( i = 0; i < strLength; i++ )
01473 {
01474 if( value[i] == sep || value[i] == '\\' )
01475 str_list += '\\';
01476 str_list += value[i];
01477 }
01478 str_list += sep;
01479 }
01480 if( str_list.at(str_list.length() - 1) == (QChar)sep )
01481 str_list.truncate( str_list.length() -1 );
01482 writeEntry( pKey, str_list, bPersistent, bGlobal, bNLS, bExpand );
01483 }
01484
01485 void TDEConfigBase::writeEntry ( const TQString& pKey, const TQValueList<int> &list,
01486 bool bPersistent, bool bGlobal, bool bNLS )
01487 {
01488 writeEntry(pKey.utf8().data(), list, bPersistent, bGlobal, bNLS);
01489 }
01490
01491 void TDEConfigBase::writeEntry ( const char *pKey, const TQValueList<int> &list,
01492 bool bPersistent, bool bGlobal, bool bNLS )
01493 {
01494 TQStringList strlist;
01495 TQValueList<int>::ConstIterator end = list.end();
01496 for (TQValueList<int>::ConstIterator it = list.begin(); it != end; it++)
01497 strlist << TQString::number(*it);
01498 writeEntry(pKey, strlist, ',', bPersistent, bGlobal, bNLS );
01499 }
01500
01501 void TDEConfigBase::writeEntry( const TQString& pKey, int nValue,
01502 bool bPersistent, bool bGlobal,
01503 bool bNLS )
01504 {
01505 writeEntry( pKey, TQString::number(nValue), bPersistent, bGlobal, bNLS );
01506 }
01507
01508 void TDEConfigBase::writeEntry( const char *pKey, int nValue,
01509 bool bPersistent, bool bGlobal,
01510 bool bNLS )
01511 {
01512 writeEntry( pKey, TQString::number(nValue), bPersistent, bGlobal, bNLS );
01513 }
01514
01515
01516 void TDEConfigBase::writeEntry( const TQString& pKey, unsigned int nValue,
01517 bool bPersistent, bool bGlobal,
01518 bool bNLS )
01519 {
01520 writeEntry( pKey, TQString::number(nValue), bPersistent, bGlobal, bNLS );
01521 }
01522
01523 void TDEConfigBase::writeEntry( const char *pKey, unsigned int nValue,
01524 bool bPersistent, bool bGlobal,
01525 bool bNLS )
01526 {
01527 writeEntry( pKey, TQString::number(nValue), bPersistent, bGlobal, bNLS );
01528 }
01529
01530
01531 void TDEConfigBase::writeEntry( const TQString& pKey, long nValue,
01532 bool bPersistent, bool bGlobal,
01533 bool bNLS )
01534 {
01535 writeEntry( pKey, TQString::number(nValue), bPersistent, bGlobal, bNLS );
01536 }
01537
01538 void TDEConfigBase::writeEntry( const char *pKey, long nValue,
01539 bool bPersistent, bool bGlobal,
01540 bool bNLS )
01541 {
01542 writeEntry( pKey, TQString::number(nValue), bPersistent, bGlobal, bNLS );
01543 }
01544
01545
01546 void TDEConfigBase::writeEntry( const TQString& pKey, unsigned long nValue,
01547 bool bPersistent, bool bGlobal,
01548 bool bNLS )
01549 {
01550 writeEntry( pKey, TQString::number(nValue), bPersistent, bGlobal, bNLS );
01551 }
01552
01553 void TDEConfigBase::writeEntry( const char *pKey, unsigned long nValue,
01554 bool bPersistent, bool bGlobal,
01555 bool bNLS )
01556 {
01557 writeEntry( pKey, TQString::number(nValue), bPersistent, bGlobal, bNLS );
01558 }
01559
01560 void TDEConfigBase::writeEntry( const TQString& pKey, TQ_INT64 nValue,
01561 bool bPersistent, bool bGlobal,
01562 bool bNLS )
01563 {
01564 writeEntry( pKey, TQString::number(nValue), bPersistent, bGlobal, bNLS );
01565 }
01566
01567 void TDEConfigBase::writeEntry( const char *pKey, TQ_INT64 nValue,
01568 bool bPersistent, bool bGlobal,
01569 bool bNLS )
01570 {
01571 writeEntry( pKey, TQString::number(nValue), bPersistent, bGlobal, bNLS );
01572 }
01573
01574
01575 void TDEConfigBase::writeEntry( const TQString& pKey, TQ_UINT64 nValue,
01576 bool bPersistent, bool bGlobal,
01577 bool bNLS )
01578 {
01579 writeEntry( pKey, TQString::number(nValue), bPersistent, bGlobal, bNLS );
01580 }
01581
01582 void TDEConfigBase::writeEntry( const char *pKey, TQ_UINT64 nValue,
01583 bool bPersistent, bool bGlobal,
01584 bool bNLS )
01585 {
01586 writeEntry( pKey, TQString::number(nValue), bPersistent, bGlobal, bNLS );
01587 }
01588
01589 void TDEConfigBase::writeEntry( const TQString& pKey, double nValue,
01590 bool bPersistent, bool bGlobal,
01591 char format, int precision,
01592 bool bNLS )
01593 {
01594 writeEntry( pKey, TQString::number(nValue, format, precision),
01595 bPersistent, bGlobal, bNLS );
01596 }
01597
01598 void TDEConfigBase::writeEntry( const char *pKey, double nValue,
01599 bool bPersistent, bool bGlobal,
01600 char format, int precision,
01601 bool bNLS )
01602 {
01603 writeEntry( pKey, TQString::number(nValue, format, precision),
01604 bPersistent, bGlobal, bNLS );
01605 }
01606
01607
01608 void TDEConfigBase::writeEntry( const TQString& pKey, bool bValue,
01609 bool bPersistent,
01610 bool bGlobal,
01611 bool bNLS )
01612 {
01613 writeEntry(pKey.utf8().data(), bValue, bPersistent, bGlobal, bNLS);
01614 }
01615
01616 void TDEConfigBase::writeEntry( const char *pKey, bool bValue,
01617 bool bPersistent,
01618 bool bGlobal,
01619 bool bNLS )
01620 {
01621 TQString aValue;
01622
01623 if( bValue )
01624 aValue = "true";
01625 else
01626 aValue = "false";
01627
01628 writeEntry( pKey, aValue, bPersistent, bGlobal, bNLS );
01629 }
01630
01631
01632 void TDEConfigBase::writeEntry( const TQString& pKey, const TQFont& rFont,
01633 bool bPersistent, bool bGlobal,
01634 bool bNLS )
01635 {
01636 writeEntry(pKey.utf8().data(), rFont, bPersistent, bGlobal, bNLS);
01637 }
01638
01639 void TDEConfigBase::writeEntry( const char *pKey, const TQFont& rFont,
01640 bool bPersistent, bool bGlobal,
01641 bool bNLS )
01642 {
01643 writeEntry( pKey, TQString(rFont.toString()), bPersistent, bGlobal, bNLS );
01644 }
01645
01646
01647 void TDEConfigBase::writeEntry( const TQString& pKey, const TQRect& rRect,
01648 bool bPersistent, bool bGlobal,
01649 bool bNLS )
01650 {
01651 writeEntry(pKey.utf8().data(), rRect, bPersistent, bGlobal, bNLS);
01652 }
01653
01654 void TDEConfigBase::writeEntry( const char *pKey, const TQRect& rRect,
01655 bool bPersistent, bool bGlobal,
01656 bool bNLS )
01657 {
01658 TQStrList list;
01659 TQCString tempstr;
01660 list.insert( 0, tempstr.setNum( rRect.left() ) );
01661 list.insert( 1, tempstr.setNum( rRect.top() ) );
01662 list.insert( 2, tempstr.setNum( rRect.width() ) );
01663 list.insert( 3, tempstr.setNum( rRect.height() ) );
01664
01665 writeEntry( pKey, list, ',', bPersistent, bGlobal, bNLS );
01666 }
01667
01668
01669 void TDEConfigBase::writeEntry( const TQString& pKey, const TQPoint& rPoint,
01670 bool bPersistent, bool bGlobal,
01671 bool bNLS )
01672 {
01673 writeEntry(pKey.utf8().data(), rPoint, bPersistent, bGlobal, bNLS);
01674 }
01675
01676 void TDEConfigBase::writeEntry( const char *pKey, const TQPoint& rPoint,
01677 bool bPersistent, bool bGlobal,
01678 bool bNLS )
01679 {
01680 TQStrList list;
01681 TQCString tempstr;
01682 list.insert( 0, tempstr.setNum( rPoint.x() ) );
01683 list.insert( 1, tempstr.setNum( rPoint.y() ) );
01684
01685 writeEntry( pKey, list, ',', bPersistent, bGlobal, bNLS );
01686 }
01687
01688
01689 void TDEConfigBase::writeEntry( const TQString& pKey, const TQSize& rSize,
01690 bool bPersistent, bool bGlobal,
01691 bool bNLS )
01692 {
01693 writeEntry(pKey.utf8().data(), rSize, bPersistent, bGlobal, bNLS);
01694 }
01695
01696 void TDEConfigBase::writeEntry( const char *pKey, const TQSize& rSize,
01697 bool bPersistent, bool bGlobal,
01698 bool bNLS )
01699 {
01700 TQStrList list;
01701 TQCString tempstr;
01702 list.insert( 0, tempstr.setNum( rSize.width() ) );
01703 list.insert( 1, tempstr.setNum( rSize.height() ) );
01704
01705 writeEntry( pKey, list, ',', bPersistent, bGlobal, bNLS );
01706 }
01707
01708 void TDEConfigBase::writeEntry( const TQString& pKey, const TQColor& rColor,
01709 bool bPersistent,
01710 bool bGlobal,
01711 bool bNLS )
01712 {
01713 writeEntry( pKey.utf8().data(), rColor, bPersistent, bGlobal, bNLS);
01714 }
01715
01716 void TDEConfigBase::writeEntry( const char *pKey, const TQColor& rColor,
01717 bool bPersistent,
01718 bool bGlobal,
01719 bool bNLS )
01720 {
01721 TQString aValue;
01722 if (rColor.isValid())
01723 aValue.sprintf( "%d,%d,%d", rColor.red(), rColor.green(), rColor.blue() );
01724 else
01725 aValue = "invalid";
01726
01727 writeEntry( pKey, aValue, bPersistent, bGlobal, bNLS );
01728 }
01729
01730 void TDEConfigBase::writeEntry( const TQString& pKey, const TQDateTime& rDateTime,
01731 bool bPersistent, bool bGlobal,
01732 bool bNLS )
01733 {
01734 writeEntry(pKey.utf8().data(), rDateTime, bPersistent, bGlobal, bNLS);
01735 }
01736
01737 void TDEConfigBase::writeEntry( const char *pKey, const TQDateTime& rDateTime,
01738 bool bPersistent, bool bGlobal,
01739 bool bNLS )
01740 {
01741 TQStrList list;
01742 TQCString tempstr;
01743
01744 TQTime time = TQT_TQTIME_OBJECT(rDateTime.time());
01745 TQDate date = TQT_TQDATE_OBJECT(rDateTime.date());
01746
01747 list.insert( 0, tempstr.setNum( date.year() ) );
01748 list.insert( 1, tempstr.setNum( date.month() ) );
01749 list.insert( 2, tempstr.setNum( date.day() ) );
01750
01751 list.insert( 3, tempstr.setNum( time.hour() ) );
01752 list.insert( 4, tempstr.setNum( time.minute() ) );
01753 list.insert( 5, tempstr.setNum( time.second() ) );
01754
01755 writeEntry( pKey, list, ',', bPersistent, bGlobal, bNLS );
01756 }
01757
01758 void TDEConfigBase::parseConfigFiles()
01759 {
01760 if (!bLocaleInitialized && TDEGlobal::_locale) {
01761 setLocale();
01762 }
01763 if (backEnd)
01764 {
01765 backEnd->parseConfigFiles();
01766 bReadOnly = (backEnd->getConfigState() == ReadOnly);
01767 }
01768 }
01769
01770 void TDEConfigBase::sync()
01771 {
01772 if (isReadOnly())
01773 return;
01774
01775 if (backEnd)
01776 backEnd->sync();
01777 if (bDirty)
01778 rollback();
01779 }
01780
01781 TDEConfigBase::ConfigState TDEConfigBase::getConfigState() const {
01782 if (backEnd)
01783 return backEnd->getConfigState();
01784 return ReadOnly;
01785 }
01786
01787 void TDEConfigBase::rollback( bool )
01788 {
01789 bDirty = false;
01790 }
01791
01792
01793 void TDEConfigBase::setReadDefaults(bool b)
01794 {
01795 if (!d)
01796 {
01797 if (!b) return;
01798 d = new TDEConfigBasePrivate();
01799 }
01800
01801 d->readDefaults = b;
01802 }
01803
01804 bool TDEConfigBase::readDefaults() const
01805 {
01806 return (d && d->readDefaults);
01807 }
01808
01809 void TDEConfigBase::revertToDefault(const TQString &key)
01810 {
01811 setDirty(true);
01812
01813 KEntryKey aEntryKey(mGroup, key.utf8());
01814 aEntryKey.bDefault = true;
01815
01816 if (!locale().isNull()) {
01817
01818 aEntryKey.bLocal = true;
01819 KEntry entry = lookupData(aEntryKey);
01820 if (entry.mValue.isNull())
01821 entry.bDeleted = true;
01822
01823 entry.bDirty = true;
01824 putData(aEntryKey, entry, true);
01825 aEntryKey.bLocal = false;
01826 }
01827
01828
01829 KEntry entry = lookupData(aEntryKey);
01830 if (entry.mValue.isNull())
01831 entry.bDeleted = true;
01832 entry.bDirty = true;
01833 putData(aEntryKey, entry, true);
01834 }
01835
01836 bool TDEConfigBase::hasDefault(const TQString &key) const
01837 {
01838 KEntryKey aEntryKey(mGroup, key.utf8());
01839 aEntryKey.bDefault = true;
01840
01841 if (!locale().isNull()) {
01842
01843 aEntryKey.bLocal = true;
01844 KEntry entry = lookupData(aEntryKey);
01845 if (!entry.mValue.isNull())
01846 return true;
01847
01848 aEntryKey.bLocal = false;
01849 }
01850
01851
01852 KEntry entry = lookupData(aEntryKey);
01853 if (!entry.mValue.isNull())
01854 return true;
01855
01856 return false;
01857 }
01858
01859
01860
01861 TDEConfigGroup::TDEConfigGroup(TDEConfigBase *master, const TQString &group)
01862 {
01863 mMaster = master;
01864 backEnd = mMaster->backEnd;
01865 bLocaleInitialized = true;
01866 bReadOnly = mMaster->bReadOnly;
01867 bExpand = false;
01868 bDirty = false;
01869 mGroup = group.utf8();
01870 aLocaleString = mMaster->aLocaleString;
01871 setReadDefaults(mMaster->readDefaults());
01872 }
01873
01874 TDEConfigGroup::TDEConfigGroup(TDEConfigBase *master, const TQCString &group)
01875 {
01876 mMaster = master;
01877 backEnd = mMaster->backEnd;
01878 bLocaleInitialized = true;
01879 bReadOnly = mMaster->bReadOnly;
01880 bExpand = false;
01881 bDirty = false;
01882 mGroup = group;
01883 aLocaleString = mMaster->aLocaleString;
01884 setReadDefaults(mMaster->readDefaults());
01885 }
01886
01887 TDEConfigGroup::TDEConfigGroup(TDEConfigBase *master, const char * group)
01888 {
01889 mMaster = master;
01890 backEnd = mMaster->backEnd;
01891 bLocaleInitialized = true;
01892 bReadOnly = mMaster->bReadOnly;
01893 bExpand = false;
01894 bDirty = false;
01895 mGroup = group;
01896 aLocaleString = mMaster->aLocaleString;
01897 setReadDefaults(mMaster->readDefaults());
01898 }
01899
01900 void TDEConfigGroup::deleteGroup(bool bGlobal)
01901 {
01902 mMaster->deleteGroup(TDEConfigBase::group(), true, bGlobal);
01903 }
01904
01905 bool TDEConfigGroup::groupIsImmutable() const
01906 {
01907 return mMaster->groupIsImmutable(TDEConfigBase::group());
01908 }
01909
01910 void TDEConfigGroup::setDirty(bool _bDirty)
01911 {
01912 mMaster->setDirty(_bDirty);
01913 }
01914
01915 void TDEConfigGroup::putData(const KEntryKey &_key, const KEntry &_data, bool _checkGroup)
01916 {
01917 mMaster->putData(_key, _data, _checkGroup);
01918 }
01919
01920 KEntry TDEConfigGroup::lookupData(const KEntryKey &_key) const
01921 {
01922 return mMaster->lookupData(_key);
01923 }
01924
01925 void TDEConfigGroup::sync()
01926 {
01927 mMaster->sync();
01928 }
01929
01930 void TDEConfigBase::virtual_hook( int, void* )
01931 { }
01932
01933 void TDEConfigGroup::virtual_hook( int id, void* data )
01934 { TDEConfigBase::virtual_hook( id, data ); }
01935
01936 bool TDEConfigBase::checkConfigFilesWritable(bool warnUser)
01937 {
01938 if (backEnd)
01939 return backEnd->checkConfigFilesWritable(warnUser);
01940 else
01941 return false;
01942 }
01943
01944 #include "tdeconfigbase.moc"