28 #include <tqtextstream.h> 30 #include <tdeapplication.h> 31 #include <tdeglobal.h> 33 #include <kcharsets.h> 35 #include "tdeconfigbase.h" 36 #include "tdeconfigbackend.h" 38 #include "kstandarddirs.h" 39 #include "kstringhandler.h" 41 class TDEConfigBase::TDEConfigBasePrivate
52 bReadOnly(false), bExpand(false), d(0)
64 bLocaleInitialized =
true;
81 if ( group.isEmpty() )
94 if ( group.isEmpty() )
101 return TQString::fromUtf8(
mGroup);
111 return hasKey(key.utf8().data());
117 aEntryKey.c_key = pKey;
124 if (!entry.mValue.isNull())
131 return !entry.mValue.isNull();
134 bool TDEConfigBase::hasTranslatedKey(
const char* pKey)
const 137 aEntryKey.c_key = pKey;
144 if (!entry.mValue.isNull())
154 return internalHasGroup( group.utf8());
159 return internalHasGroup( TQCString(_pGroup));
164 return internalHasGroup( _pGroup);
179 return entry.bImmutable;
192 TQCString utf8_key = key.utf8();
193 entryKey.c_key = utf8_key.data();
205 const TQString& aDefault )
const 212 const TQString& aDefault )
const 214 TQCString result = readEntryUtf8(pKey);
217 return TQString::fromUtf8(result);
222 const TQString& aDefault )
const 228 const TQString& aDefault )
const 234 if (!bLocaleInitialized && TDEGlobal::_locale) {
247 entryKey.c_key = pKey;
251 if (!aEntryData.mValue.isNull()) {
258 if (!aEntryData.mValue.isNull()) {
259 aValue = TQString::fromUtf8(aEntryData.mValue.data());
263 aValue = emptyString;
272 if( expand || bExpand )
275 int nDollarPos = aValue.find(
'$' );
277 while( nDollarPos != -1 && nDollarPos+1 < static_cast<int>(aValue.length())) {
279 if( (aValue)[nDollarPos+1] ==
'(' ) {
280 uint nEndPos = nDollarPos+1;
282 while ( (nEndPos <= aValue.length()) && (aValue[nEndPos]!=
')') )
285 TQString cmd = aValue.mid( nDollarPos+2, nEndPos-nDollarPos-3 );
288 FILE *fs = popen(TQFile::encodeName(cmd).data(),
"r");
292 TQTextStream ts(fs, IO_ReadOnly);
293 result = ts.read().stripWhiteSpace();
297 aValue.replace( nDollarPos, nEndPos-nDollarPos, result );
298 }
else if( (aValue)[nDollarPos+1] !=
'$' ) {
299 uint nEndPos = nDollarPos+1;
302 if (aValue[nEndPos]==
'{')
304 while ( (nEndPos <= aValue.length()) && (aValue[nEndPos]!=
'}') )
307 aVarName = aValue.mid( nDollarPos+2, nEndPos-nDollarPos-3 );
311 while ( nEndPos <= aValue.length() && (aValue[nEndPos].isNumber()
312 || aValue[nEndPos].isLetter() || aValue[nEndPos]==
'_' ) )
314 aVarName = aValue.mid( nDollarPos+1, nEndPos-nDollarPos-1 );
316 const char* pEnv = 0;
317 if (!aVarName.isEmpty())
318 pEnv = getenv( aVarName.ascii() );
325 aValue.remove( nDollarPos, nEndPos-nDollarPos );
328 aValue.remove( nDollarPos, 1 );
331 nDollarPos = aValue.find(
'$', nDollarPos );
338 TQCString TDEConfigBase::readEntryUtf8(
const char *pKey)
const 343 entryKey.c_key = pKey;
348 return readEntry(pKey, TQString::null).utf8();
350 return aEntryData.mValue;
354 TQVariant::Type type )
const 360 TQVariant::Type type )
const 363 if ( !
hasKey( pKey ) )
return va;
369 const TQVariant &aDefault )
const 375 const TQVariant &aDefault )
const 377 if ( !
hasKey( pKey ) )
return aDefault;
379 TQVariant tmp = aDefault;
381 switch( aDefault.type() )
383 case TQVariant::Invalid:
385 case TQVariant::String:
386 return TQVariant(
readEntry( pKey, aDefault.toString() ) );
387 case TQVariant::StringList:
389 case TQVariant::List: {
391 TQStringList::ConstIterator it = strList.begin();
392 TQStringList::ConstIterator end = strList.end();
393 TQValueList<TQVariant> list;
395 for (; it != end; ++it ) {
399 return TQVariant( list );
401 case TQVariant::Font:
403 case TQVariant::Point:
405 case TQVariant::Rect:
407 case TQVariant::Size:
409 case TQVariant::Color:
412 return TQVariant(
readNumEntry( pKey, aDefault.toInt() ) );
413 case TQVariant::UInt:
415 case TQVariant::LongLong:
416 return TQVariant(
readNum64Entry( pKey, aDefault.toLongLong() ) );
417 case TQVariant::ULongLong:
419 case TQVariant::Bool:
420 return TQVariant(
readBoolEntry( pKey, aDefault.toBool() ), 0 );
421 case TQVariant::Double:
423 case TQVariant::DateTime:
425 case TQVariant::Date:
426 return TQVariant(TQT_TQDATE_OBJECT(
readDateTimeEntry( pKey, &tmp.asDateTime() ).date()));
428 case TQVariant::Pixmap:
429 case TQVariant::Image:
430 case TQVariant::Brush:
431 case TQVariant::Palette:
432 case TQVariant::ColorGroup:
434 case TQVariant::IconSet:
435 case TQVariant::CString:
436 case TQVariant::PointArray:
437 case TQVariant::Region:
438 case TQVariant::Bitmap:
439 case TQVariant::Cursor:
440 case TQVariant::SizePolicy:
441 case TQVariant::Time:
443 case TQVariant::ByteArray:
445 case TQVariant::BitArray:
446 case TQVariant::KeySequence:
449 case TQVariant::Char:
451 case TQVariant::Locale:
452 case TQVariant::RectF:
453 case TQVariant::SizeF:
454 case TQVariant::Line:
455 case TQVariant::LineF:
456 case TQVariant::PointF:
457 case TQVariant::RegExp:
458 case TQVariant::Hash:
459 case TQVariant::TextLength:
460 case QVariant::TextFormat:
461 case TQVariant::Matrix:
462 case TQVariant::Transform:
463 case TQVariant::Matrix4x4:
464 case TQVariant::Vector2D:
465 case TQVariant::Vector3D:
466 case TQVariant::Vector4D:
467 case TQVariant::Quaternion:
468 case TQVariant::UserType:
478 TQStrList &list,
char sep )
const 484 TQStrList &list,
char sep )
const 489 TQCString str_list = readEntryUtf8( pKey );
490 if (str_list.isEmpty())
494 TQCString value =
"";
495 int len = str_list.length();
497 for (
int i = 0; i < len; i++) {
498 if (str_list[i] != sep && str_list[i] !=
'\\') {
499 value += str_list[i];
502 if (str_list[i] ==
'\\') {
505 value += str_list[i];
513 list.append( value );
517 if ( str_list[len-1] != sep || ( len > 1 && str_list[len-2] ==
'\\' ) )
518 list.append( value );
535 if( str_list.isEmpty() )
537 TQString value(emptyString);
538 int len = str_list.length();
540 value.reserve( len );
541 for(
int i = 0; i < len; i++ )
543 if( str_list[i] != sep && str_list[i] !=
'\\' )
545 value += str_list[i];
548 if( str_list[i] ==
'\\' )
552 value += str_list[i];
555 TQString finalvalue( value );
556 finalvalue.squeeze();
557 list.append( finalvalue );
560 if ( str_list[len-1] != sep || ( len > 1 && str_list[len-2] ==
'\\' ) )
563 list.append( value );
585 TQValueList<int> list;
586 TQStringList::ConstIterator end(strlist.end());
587 for (TQStringList::ConstIterator it = strlist.begin(); it != end; ++it)
590 list << (*it).toInt();
602 const bool bExpandSave = bExpand;
604 TQString aValue =
readEntry( pKey, pDefault );
605 bExpand = bExpandSave;
616 const bool bExpandSave = bExpand;
619 bExpand = bExpandSave;
630 TQCString aValue = readEntryUtf8( pKey );
631 if( aValue.isNull() )
633 else if( aValue ==
"true" || aValue ==
"on" || aValue ==
"yes" )
638 int rc = aValue.toInt( &ok );
639 return( ok ? rc : nDefault );
651 TQCString aValue = readEntryUtf8( pKey );
652 if( aValue.isNull() )
657 unsigned int rc = aValue.toUInt( &ok );
658 return( ok ? rc : nDefault );
670 TQCString aValue = readEntryUtf8( pKey );
671 if( aValue.isNull() )
676 long rc = aValue.toLong( &ok );
677 return( ok ? rc : nDefault );
689 TQCString aValue = readEntryUtf8( pKey );
690 if( aValue.isNull() )
695 unsigned long rc = aValue.toULong( &ok );
696 return( ok ? rc : nDefault );
709 if( aValue.isNull() )
714 TQ_INT64 rc = aValue.toLongLong( &ok );
715 return( ok ? rc : nDefault );
729 if( aValue.isNull() )
734 TQ_UINT64 rc = aValue.toULongLong( &ok );
735 return( ok ? rc : nDefault );
746 TQCString aValue = readEntryUtf8( pKey );
747 if( aValue.isNull() )
752 double rc = aValue.toDouble( &ok );
753 return( ok ? rc : nDefault );
765 TQCString aValue = readEntryUtf8( pKey );
767 if( aValue.isNull() )
771 if( aValue ==
"true" || aValue ==
"on" || aValue ==
"yes" || aValue ==
"1" )
776 int val = aValue.toInt( &bOK );
777 if( bOK && val != 0 )
795 if( !aValue.isNull() ) {
796 if ( aValue.contains(
',' ) > 5 ) {
798 if ( !aRetFont.fromString( aValue ) && pDefault )
799 aRetFont = *pDefault;
805 int nIndex = aValue.find(
',' );
808 aRetFont = *pDefault;
811 aRetFont.setFamily( aValue.left( nIndex ) );
814 int nOldIndex = nIndex;
815 nIndex = aValue.find(
',', nOldIndex+1 );
818 aRetFont = *pDefault;
822 aRetFont.setPointSize( aValue.mid( nOldIndex+1,
823 nIndex-nOldIndex-1 ).toInt() );
827 nIndex = aValue.find(
',', nOldIndex+1 );
831 aRetFont = *pDefault;
835 aRetFont.setStyleHint( (TQFont::StyleHint)aValue.mid( nOldIndex+1, nIndex-nOldIndex-1 ).toUInt() );
839 nIndex = aValue.find(
',', nOldIndex+1 );
843 aRetFont = *pDefault;
847 TQString chStr=aValue.mid( nOldIndex+1,
848 nIndex-nOldIndex-1 );
851 nIndex = aValue.find(
',', nOldIndex+1 );
855 aRetFont = *pDefault;
859 aRetFont.setWeight( aValue.mid( nOldIndex+1,
860 nIndex-nOldIndex-1 ).toUInt() );
863 uint nFontBits = aValue.right( aValue.length()-nIndex-1 ).toUInt();
865 aRetFont.setItalic( nFontBits & 0x01 );
866 aRetFont.setUnderline( nFontBits & 0x02 );
867 aRetFont.setStrikeOut( nFontBits & 0x04 );
868 aRetFont.setFixedPitch( nFontBits & 0x08 );
869 aRetFont.setRawMode( nFontBits & 0x20 );
875 aRetFont = *pDefault;
889 TQCString aValue = readEntryUtf8(pKey);
891 if (!aValue.isEmpty())
893 int left, top, width, height;
895 if (sscanf(aValue.data(),
"%d,%d,%d,%d", &left, &top, &width, &height) == 4)
897 return TQRect(left, top, width, height);
907 const TQPoint* pDefault )
const 913 const TQPoint* pDefault )
const 915 TQCString aValue = readEntryUtf8(pKey);
917 if (!aValue.isEmpty())
921 if (sscanf(aValue.data(),
"%d,%d", &x, &y) == 2)
932 const TQSize* pDefault )
const 938 const TQSize* pDefault )
const 940 TQCString aValue = readEntryUtf8(pKey);
942 if (!aValue.isEmpty())
946 if (sscanf(aValue.data(),
"%d,%d", &width, &height) == 2)
948 return TQSize(width, height);
958 const TQColor* pDefault )
const 964 const TQColor* pDefault )
const 967 int nRed = 0, nGreen = 0, nBlue = 0;
970 if( !aValue.isEmpty() )
972 if ( aValue.at(0) == (QChar)
'#' )
974 aRetColor.setNamedColor(aValue);
982 int nIndex = aValue.find(
',' );
987 aRetColor = *pDefault;
991 nRed = aValue.left( nIndex ).toInt( &bOK );
994 int nOldIndex = nIndex;
995 nIndex = aValue.find(
',', nOldIndex+1 );
1000 aRetColor = *pDefault;
1003 nGreen = aValue.mid( nOldIndex+1,
1004 nIndex-nOldIndex-1 ).toInt( &bOK );
1007 nBlue = aValue.right( aValue.length()-nIndex-1 ).toInt( &bOK );
1009 aRetColor.setRgb( nRed, nGreen, nBlue );
1015 aRetColor = *pDefault;
1023 const TQDateTime* pDefault )
const 1030 const TQDateTime* pDefault )
const 1037 return TQDateTime::currentDateTime();
1043 TQDate date( atoi( list.at( 0 ) ), atoi( list.at( 1 ) ),
1044 atoi( list.at( 2 ) ) );
1045 TQTime time( atoi( list.at( 3 ) ), atoi( list.at( 4 ) ),
1046 atoi( list.at( 5 ) ) );
1048 return TQDateTime( date, time );
1051 return TQDateTime::currentDateTime();
1059 writeEntry(pKey.utf8().data(), value, bPersistent, bGlobal, bNLS);
1067 writeEntry(pKey, value, bPersistent, bGlobal, bNLS,
false);
1091 aEntryData.mValue = value.utf8();
1093 aEntryData.
bNLS = bNLS;
1097 aEntryData.
bDirty =
true;
1100 putData(entryKey, aEntryData,
true);
1104 bool bPersistent,
bool bGlobal,
1107 writePathEntry(pKey.utf8().data(), path, bPersistent, bGlobal, bNLS);
1111 static bool cleanHomeDirPath( TQString &path,
const TQString &homeDir )
1113 #ifdef Q_WS_WIN //safer 1114 if (!TQDir::convertSeparators(path).startsWith(TQDir::convertSeparators(homeDir)))
1117 if (!path.startsWith(homeDir))
1121 unsigned int len = homeDir.length();
1123 if (len && (path.length() == len || path[len] ==
'/')) {
1124 path.replace(0, len, TQString::fromLatin1(
"$HOME"));
1130 static TQString translatePath( TQString path )
1136 path.replace(
'$',
"$$");
1138 bool startsWithFile = path.startsWith(
"file:",
false);
1142 if (((!startsWithFile) && (path[0] !=
'/')) || (startsWithFile && (path[5] !=
'/'))) {
1146 if (startsWithFile) {
1151 while (path[0] ==
'/' && path[1] ==
'/') {
1159 TQString homeDir0 = TQFile::decodeName(getenv(
"HOME"));
1160 TQString homeDir1 = TQDir::homeDirPath();
1161 TQString homeDir2 = TQDir(homeDir1).canonicalPath();
1162 if (cleanHomeDirPath(path, homeDir0) ||
1163 cleanHomeDirPath(path, homeDir1) ||
1164 cleanHomeDirPath(path, homeDir2) ) {
1169 path.prepend(
"file://" );
1175 bool bPersistent,
bool bGlobal,
1178 writeEntry(pKey, translatePath(path), bPersistent, bGlobal, bNLS,
true);
1182 bool bPersistent,
bool bGlobal,
1183 bool bNLS,
bool expand)
1185 writeEntry(pKey, translatePath(path), bPersistent, bGlobal, bNLS, expand);
1189 char sep ,
bool bPersistent,
1190 bool bGlobal,
bool bNLS )
1192 writePathEntry(pKey.utf8().data(), list, sep, bPersistent, bGlobal, bNLS);
1196 char sep ,
bool bPersistent,
1197 bool bGlobal,
bool bNLS )
1199 if( list.isEmpty() )
1201 writeEntry( pKey, TQString::fromLatin1(
""), bPersistent );
1204 TQStringList new_list;
1205 TQStringList::ConstIterator it = list.begin();
1206 for( ; it != list.end(); ++it )
1208 TQString value = *it;
1209 new_list.append( translatePath(value) );
1211 writeEntry( pKey, new_list, sep, bPersistent, bGlobal, bNLS,
true );
1239 aEntryData.
bNLS = bNLS;
1240 aEntryData.
bDirty =
true;
1244 putData(entryKey, aEntryData,
true);
1253 return aEntryMap.isEmpty();
1257 bool checkGroup =
true;
1259 KEntryMapIterator aIt;
1260 for (aIt = aEntryMap.begin(); aIt != aEntryMap.end(); ++aIt)
1262 if (!aIt.key().mKey.isEmpty() && !aIt.key().bDefault && !(*aIt).bDeleted)
1264 (*aIt).bDeleted =
true;
1265 (*aIt).bDirty =
true;
1266 (*aIt).bGlobal = bGlobal;
1268 putData(aIt.key(), *aIt, checkGroup);
1280 bool bGlobal,
bool bNLS )
1282 writeEntry(pKey.utf8().data(), prop, bPersistent, bGlobal, bNLS);
1287 bool bGlobal,
bool bNLS )
1289 switch( prop.type() )
1291 case TQVariant::Invalid:
1292 writeEntry( pKey,
"", bPersistent, bGlobal, bNLS );
1294 case TQVariant::String:
1295 writeEntry( pKey, prop.toString(), bPersistent, bGlobal, bNLS );
1297 case TQVariant::StringList:
1298 writeEntry( pKey, prop.toStringList(),
',', bPersistent, bGlobal, bNLS );
1300 case TQVariant::List: {
1301 TQValueList<TQVariant> list = prop.toList();
1302 TQValueList<TQVariant>::ConstIterator it = list.begin();
1303 TQValueList<TQVariant>::ConstIterator end = list.end();
1304 TQStringList strList;
1306 for (; it != end; ++it )
1307 strList.append( (*it).toString() );
1309 writeEntry( pKey, strList,
',', bPersistent, bGlobal, bNLS );
1313 case TQVariant::Font:
1314 writeEntry( pKey, prop.toFont(), bPersistent, bGlobal, bNLS );
1316 case TQVariant::Point:
1317 writeEntry( pKey, prop.toPoint(), bPersistent, bGlobal, bNLS );
1319 case TQVariant::Rect:
1320 writeEntry( pKey, prop.toRect(), bPersistent, bGlobal, bNLS );
1322 case TQVariant::Size:
1323 writeEntry( pKey, prop.toSize(), bPersistent, bGlobal, bNLS );
1325 case TQVariant::Color:
1326 writeEntry( pKey, prop.toColor(), bPersistent, bGlobal, bNLS );
1328 case TQVariant::Int:
1329 writeEntry( pKey, prop.toInt(), bPersistent, bGlobal, bNLS );
1331 case TQVariant::UInt:
1332 writeEntry( pKey, prop.toUInt(), bPersistent, bGlobal, bNLS );
1334 case TQVariant::LongLong:
1335 writeEntry( pKey, prop.toLongLong(), bPersistent, bGlobal, bNLS );
1337 case TQVariant::ULongLong:
1338 writeEntry( pKey, prop.toULongLong(), bPersistent, bGlobal, bNLS );
1340 case TQVariant::Bool:
1341 writeEntry( pKey, prop.toBool(), bPersistent, bGlobal, bNLS );
1343 case TQVariant::Double:
1344 writeEntry( pKey, prop.toDouble(), bPersistent, bGlobal,
'g', 6, bNLS );
1346 case TQVariant::DateTime:
1347 writeEntry( pKey, prop.toDateTime(), bPersistent, bGlobal, bNLS);
1349 case TQVariant::Date:
1350 writeEntry( pKey, TQDateTime(prop.toDate()), bPersistent, bGlobal, bNLS);
1353 case TQVariant::Pixmap:
1354 case TQVariant::Image:
1355 case TQVariant::Brush:
1356 case TQVariant::Palette:
1357 case TQVariant::ColorGroup:
1358 case TQVariant::Map:
1359 case TQVariant::IconSet:
1360 case TQVariant::CString:
1361 case TQVariant::PointArray:
1362 case TQVariant::Region:
1363 case TQVariant::Bitmap:
1364 case TQVariant::Cursor:
1365 case TQVariant::SizePolicy:
1366 case TQVariant::Time:
1368 case TQVariant::ByteArray:
1370 case TQVariant::BitArray:
1371 case TQVariant::KeySequence:
1372 case TQVariant::Pen:
1374 case TQVariant::Char:
1375 case TQVariant::Url:
1376 case TQVariant::Locale:
1377 case TQVariant::RectF:
1378 case TQVariant::SizeF:
1379 case TQVariant::Line:
1380 case TQVariant::LineF:
1381 case TQVariant::PointF:
1382 case TQVariant::RegExp:
1383 case TQVariant::Hash:
1384 case TQVariant::TextLength:
1385 case QVariant::TextFormat:
1386 case TQVariant::Matrix:
1387 case TQVariant::Transform:
1388 case TQVariant::Matrix4x4:
1389 case TQVariant::Vector2D:
1390 case TQVariant::Vector3D:
1391 case TQVariant::Vector4D:
1392 case TQVariant::Quaternion:
1393 case TQVariant::UserType:
1402 char sep ,
bool bPersistent,
1403 bool bGlobal,
bool bNLS )
1405 writeEntry(pKey.utf8().data(), list, sep, bPersistent, bGlobal, bNLS);
1409 char sep ,
bool bPersistent,
1410 bool bGlobal,
bool bNLS )
1412 if( list.isEmpty() )
1414 writeEntry( pKey, TQString::fromLatin1(
""), bPersistent );
1418 TQStrListIterator it( list );
1419 for( ; it.current(); ++it )
1427 uint strLengh(value.length());
1428 for( i = 0; i < strLengh; i++ )
1430 if( value[i] == sep || value[i] ==
'\\' )
1432 str_list += value[i];
1436 if( str_list.at(str_list.length() - 1) == (QChar)sep )
1437 str_list.truncate( str_list.length() -1 );
1438 writeEntry( pKey, str_list, bPersistent, bGlobal, bNLS );
1442 char sep ,
bool bPersistent,
1443 bool bGlobal,
bool bNLS )
1445 writeEntry(pKey.utf8().data(), list, sep, bPersistent, bGlobal, bNLS);
1449 char sep ,
bool bPersistent,
1450 bool bGlobal,
bool bNLS )
1452 writeEntry(pKey, list, sep, bPersistent, bGlobal, bNLS,
false);
1456 char sep,
bool bPersistent,
1457 bool bGlobal,
bool bNLS,
bool bExpand )
1459 if( list.isEmpty() )
1461 writeEntry( pKey, TQString::fromLatin1(
""), bPersistent );
1465 str_list.reserve( 4096 );
1466 TQStringList::ConstIterator it = list.begin();
1467 for( ; it != list.end(); ++it )
1469 TQString value = *it;
1471 uint strLength(value.length());
1472 for( i = 0; i < strLength; i++ )
1474 if( value[i] == sep || value[i] ==
'\\' )
1476 str_list += value[i];
1480 if( str_list.at(str_list.length() - 1) == (QChar)sep )
1481 str_list.truncate( str_list.length() -1 );
1482 writeEntry( pKey, str_list, bPersistent, bGlobal, bNLS, bExpand );
1486 bool bPersistent,
bool bGlobal,
bool bNLS )
1488 writeEntry(pKey.utf8().data(), list, bPersistent, bGlobal, bNLS);
1492 bool bPersistent,
bool bGlobal,
bool bNLS )
1494 TQStringList strlist;
1495 TQValueList<int>::ConstIterator end = list.end();
1496 for (TQValueList<int>::ConstIterator it = list.begin(); it != end; it++)
1497 strlist << TQString::number(*it);
1498 writeEntry(pKey, strlist,
',', bPersistent, bGlobal, bNLS );
1502 bool bPersistent,
bool bGlobal,
1505 writeEntry( pKey, TQString::number(nValue), bPersistent, bGlobal, bNLS );
1509 bool bPersistent,
bool bGlobal,
1512 writeEntry( pKey, TQString::number(nValue), bPersistent, bGlobal, bNLS );
1517 bool bPersistent,
bool bGlobal,
1520 writeEntry( pKey, TQString::number(nValue), bPersistent, bGlobal, bNLS );
1524 bool bPersistent,
bool bGlobal,
1527 writeEntry( pKey, TQString::number(nValue), bPersistent, bGlobal, bNLS );
1532 bool bPersistent,
bool bGlobal,
1535 writeEntry( pKey, TQString::number(nValue), bPersistent, bGlobal, bNLS );
1539 bool bPersistent,
bool bGlobal,
1542 writeEntry( pKey, TQString::number(nValue), bPersistent, bGlobal, bNLS );
1547 bool bPersistent,
bool bGlobal,
1550 writeEntry( pKey, TQString::number(nValue), bPersistent, bGlobal, bNLS );
1554 bool bPersistent,
bool bGlobal,
1557 writeEntry( pKey, TQString::number(nValue), bPersistent, bGlobal, bNLS );
1561 bool bPersistent,
bool bGlobal,
1564 writeEntry( pKey, TQString::number(nValue), bPersistent, bGlobal, bNLS );
1568 bool bPersistent,
bool bGlobal,
1571 writeEntry( pKey, TQString::number(nValue), bPersistent, bGlobal, bNLS );
1576 bool bPersistent,
bool bGlobal,
1579 writeEntry( pKey, TQString::number(nValue), bPersistent, bGlobal, bNLS );
1583 bool bPersistent,
bool bGlobal,
1586 writeEntry( pKey, TQString::number(nValue), bPersistent, bGlobal, bNLS );
1590 bool bPersistent,
bool bGlobal,
1591 char format,
int precision,
1594 writeEntry( pKey, TQString::number(nValue, format, precision),
1595 bPersistent, bGlobal, bNLS );
1599 bool bPersistent,
bool bGlobal,
1600 char format,
int precision,
1603 writeEntry( pKey, TQString::number(nValue, format, precision),
1604 bPersistent, bGlobal, bNLS );
1613 writeEntry(pKey.utf8().data(), bValue, bPersistent, bGlobal, bNLS);
1628 writeEntry( pKey, aValue, bPersistent, bGlobal, bNLS );
1633 bool bPersistent,
bool bGlobal,
1636 writeEntry(pKey.utf8().data(), rFont, bPersistent, bGlobal, bNLS);
1640 bool bPersistent,
bool bGlobal,
1643 writeEntry( pKey, TQString(rFont.toString()), bPersistent, bGlobal, bNLS );
1648 bool bPersistent,
bool bGlobal,
1651 writeEntry(pKey.utf8().data(), rRect, bPersistent, bGlobal, bNLS);
1655 bool bPersistent,
bool bGlobal,
1660 list.insert( 0, tempstr.setNum( rRect.left() ) );
1661 list.insert( 1, tempstr.setNum( rRect.top() ) );
1662 list.insert( 2, tempstr.setNum( rRect.width() ) );
1663 list.insert( 3, tempstr.setNum( rRect.height() ) );
1665 writeEntry( pKey, list,
',', bPersistent, bGlobal, bNLS );
1670 bool bPersistent,
bool bGlobal,
1673 writeEntry(pKey.utf8().data(), rPoint, bPersistent, bGlobal, bNLS);
1677 bool bPersistent,
bool bGlobal,
1682 list.insert( 0, tempstr.setNum( rPoint.x() ) );
1683 list.insert( 1, tempstr.setNum( rPoint.y() ) );
1685 writeEntry( pKey, list,
',', bPersistent, bGlobal, bNLS );
1690 bool bPersistent,
bool bGlobal,
1693 writeEntry(pKey.utf8().data(), rSize, bPersistent, bGlobal, bNLS);
1697 bool bPersistent,
bool bGlobal,
1702 list.insert( 0, tempstr.setNum( rSize.width() ) );
1703 list.insert( 1, tempstr.setNum( rSize.height() ) );
1705 writeEntry( pKey, list,
',', bPersistent, bGlobal, bNLS );
1713 writeEntry( pKey.utf8().data(), rColor, bPersistent, bGlobal, bNLS);
1722 if (rColor.isValid())
1723 aValue.sprintf(
"%d,%d,%d", rColor.red(), rColor.green(), rColor.blue() );
1727 writeEntry( pKey, aValue, bPersistent, bGlobal, bNLS );
1731 bool bPersistent,
bool bGlobal,
1734 writeEntry(pKey.utf8().data(), rDateTime, bPersistent, bGlobal, bNLS);
1738 bool bPersistent,
bool bGlobal,
1744 TQTime time = TQT_TQTIME_OBJECT(rDateTime.time());
1745 TQDate date = TQT_TQDATE_OBJECT(rDateTime.date());
1747 list.insert( 0, tempstr.setNum( date.year() ) );
1748 list.insert( 1, tempstr.setNum( date.month() ) );
1749 list.insert( 2, tempstr.setNum( date.day() ) );
1751 list.insert( 3, tempstr.setNum( time.hour() ) );
1752 list.insert( 4, tempstr.setNum( time.minute() ) );
1753 list.insert( 5, tempstr.setNum( time.second() ) );
1755 writeEntry( pKey, list,
',', bPersistent, bGlobal, bNLS );
1760 if (!bLocaleInitialized && TDEGlobal::_locale) {
1798 d =
new TDEConfigBasePrivate();
1801 d->readDefaults = b;
1806 return (d && d->readDefaults);
1816 if (!
locale().isNull()) {
1818 aEntryKey.bLocal =
true;
1820 if (entry.mValue.isNull())
1824 putData(aEntryKey, entry,
true);
1825 aEntryKey.bLocal =
false;
1830 if (entry.mValue.isNull())
1833 putData(aEntryKey, entry,
true);
1841 if (!
locale().isNull()) {
1843 aEntryKey.bLocal =
true;
1845 if (!entry.mValue.isNull())
1848 aEntryKey.bLocal =
false;
1853 if (!entry.mValue.isNull())
1865 bLocaleInitialized =
true;
1866 bReadOnly = mMaster->bReadOnly;
1878 bLocaleInitialized =
true;
1879 bReadOnly = mMaster->bReadOnly;
1891 bLocaleInitialized =
true;
1892 bReadOnly = mMaster->bReadOnly;
1912 mMaster->setDirty(_bDirty);
1917 mMaster->putData(_key, _data, _checkGroup);
1922 return mMaster->lookupData(_key);
1930 void TDEConfigBase::virtual_hook(
int,
void* )
1933 void TDEConfigGroup::virtual_hook(
int id,
void* data )
1934 { TDEConfigBase::virtual_hook(
id, data ); }
1944 #include "tdeconfigbase.moc" TQString readPathEntry(const TQString &pKey, const TQString &aDefault=TQString::null) const
Reads a path.
long readLongNumEntry(const TQString &pKey, long nDefault=0) const
Reads a numerical value.
bool groupIsImmutable(const TQString &group) const
Checks whether it is possible to change the given group.
virtual void putData(const KEntryKey &_key, const KEntry &_data, bool _checkGroup=true)=0
Inserts a (key/value) pair into the internal storage mechanism of the configuration object...
virtual KEntry lookupData(const KEntryKey &_key) const
Looks up an entry in the config object's internal structure.
virtual void sync()
Flushes all changes that currently reside only in memory back to disk / permanent storage...
unsigned int readUnsignedNumEntry(const TQString &pKey, unsigned int nDefault=0) const
Reads an unsigned numerical value.
virtual KEntryMap internalEntryMap() const =0
Returns a map (tree) of the entries in the tree.
double readDoubleNumEntry(const TQString &pKey, double nDefault=0.0) const
Reads a floating point value.
bool readBoolEntry(const TQString &pKey, bool bDefault=false) const
Reads a boolean entry.
bool bDeleted
Entry has been deleted.
TQColor readColorEntry(const TQString &pKey, const TQColor *pDefault=0L) const
Reads a TQColor entry.
map/dict/list config node entry.
virtual ~TDEConfigBase()
Destructs the TDEConfigBase object.
TQValueList< int > readIntListEntry(const TQString &pKey) const
Reads a list of Integers.
TQRect readRectEntry(const TQString &pKey, const TQRect *pDefault=0L) const
Reads a TQRect entry.
void setGroup(const TQString &group)
Specifies the group in which keys will be read and written.
void deleteGroup(bool bGlobal=false)
Delete all entries in the entire group.
virtual TDEConfigBase::ConfigState getConfigState() const
Returns the state of the app-config object.
TQCString aLocaleString
The locale to retrieve keys under if possible, i.e en_US or fr.
void setDesktopGroup()
Sets the group to the "Desktop Entry" group used for desktop configuration files for applications...
bool bDefault
Entry indicates if this is a default value.
TQString language() const
Returns the language used by this object.
virtual void setDirty(bool _bDirty=true)
Sets the global dirty flag of the config object.
TQFont readFontEntry(const TQString &pKey, const TQFont *pDefault=0L) const
Reads a TQFont value.
static TQString defaultLanguage()
Returns the name of the internal language.
TQ_UINT64 readUnsignedNum64Entry(const TQString &pKey, TQ_UINT64 nDefault=0) const
Read an 64-bit unsigned numerical value.
bool readDefaults() const
static TQString from8Bit(const char *str)
Construct TQString from a c string, guessing whether it is UTF8- or Local8Bit-encoded.
TQSize readSizeEntry(const TQString &pKey, const TQSize *pDefault=0L) const
Reads a TQSize entry.
virtual void putData(const KEntryKey &_key, const KEntry &_data, bool _checkGroup=true)
Inserts a (key/value) pair into the internal storage mechanism of the configuration object...
void setLocale()
Reads the locale and put in the configuration data struct.
int readListEntry(const TQString &pKey, TQStrList &list, char sep=',') const
Reads a list of strings.
bool checkConfigFilesWritable(bool warnUser)
Check whether the config files are writable.
TDEConfigBase()
Construct a TDEConfigBase object.
TQString locale() const
Returns a the current locale.
bool bImmutable
Entry can not be modified.
KDE Configuration Management abstract base class.
key structure holding both the actual key and the the group to which it belongs.
virtual bool parseConfigFiles()=0
Parses all configuration files for a configuration object.
virtual void rollback(bool bDeep=true)
Mark the config object as "clean," i.e.
TQVariant readPropertyEntry(const TQString &pKey, TQVariant::Type) const
Reads the value of an entry specified by pKey in the current group.
void writeEntry(const TQString &pKey, const TQString &pValue, bool bPersistent=true, bool bGlobal=false, bool bNLS=false)
Writes a key/value pair.
bool deleteGroup(const TQString &group, bool bDeep=true, bool bGlobal=false)
Deletes a configuration entry group.
virtual void parseConfigFiles()
Parses all configuration files for a configuration object.
TQ_INT64 readNum64Entry(const TQString &pKey, TQ_INT64 nDefault=0) const
Reads a 64-bit numerical value.
bool bLocal
Entry is localised or not.
virtual void setDirty(bool _bDirty)
Sets the global dirty flag of the config object.
TDEConfigGroup(TDEConfigBase *master, const TQCString &group)
Construct a config group corresponding to group in master.
unsigned long readUnsignedLongNumEntry(const TQString &pKey, unsigned long nDefault=0) const
Read an unsigned numerical value.
TQString readEntry(const TQString &pKey, const TQString &aDefault=TQString::null) const
Reads the value of an entry specified by pKey in the current group.
ConfigState
Possible return values for getConfigState().
static const TQString & staticQString(const char *str)
Creates a static TQString.
TQStringList readPathListEntry(const TQString &pKey, char sep=',') const
Reads a list of string paths.
bool hasKey(const TQString &key) const
Checks whether the key has an entry in the currently active group.
void setLocaleString(const TQCString &_localeString)
Set the locale string that defines the current language.
virtual void sync(bool bMerge=true)=0
Writes configuration data to file(s).
bool bGlobal
Entry should be written to the global config file.
void writePathEntry(const TQString &pKey, const TQString &path, bool bPersistent=true, bool bGlobal=false, bool bNLS=false)
Writes a file path.
static TDELocale * locale()
Returns the global locale object.
bool hasGroup(const TQString &group) const
Returns true if the specified group is known about.
TQDateTime readDateTimeEntry(const TQString &pKey, const TQDateTime *pDefault=0L) const
Reads a TQDateTime entry.
bool checkConfigFilesWritable(bool warnUser)
Check whether the config files are writable.
bool bNLS
Entry should be written with locale tag.
bool isReadOnly() const
Returns the read-only status of the config object.
bool hasDefault(const TQString &key) const
Returns whether a default is specified for an entry in either the system wide configuration file or t...
bool entryIsImmutable(const TQString &key) const
Checks whether it is possible to change the given entry.
TDEConfigBackEnd * backEnd
A back end for loading/saving to disk in a particular format.
TQPoint readPointEntry(const TQString &pKey, const TQPoint *pDefault=0L) const
Reads a TQPoint entry.
ConfigState getConfigState() const
Returns the state of the app-config object.
void deleteEntry(const TQString &pKey, bool bNLS=false, bool bGlobal=false)
Deletes the entry specified by pKey in the current group.
virtual KEntry lookupData(const KEntryKey &_key) const =0
Looks up an entry in the config object's internal structure.
bool isImmutable() const
Checks whether this configuration file can be modified.
TQString group() const
Returns the name of the group in which we are searching for keys and from which we are retrieving ent...
void revertToDefault(const TQString &key)
Reverts the entry with key key in the current group in the application specific config file to either...
void setReadDefaults(bool b)
When set, all readEntry and readXXXEntry calls return the system wide (default) values instead of the...
int readNumEntry(const TQString &pKey, int nDefault=0) const
Reads a numerical value.
TQCString mGroup
The currently selected group.
bool bExpand
Whether to apply dollar expansion or not.
bool bDirty
Indicates whether there are any dirty entries in the config object that need to be written back to di...
bool groupIsImmutable() const
Checks whether it is possible to change this group.
bool bDirty
Must the entry be written back to disk?
TQString readEntryUntranslated(const TQString &pKey, const TQString &aDefault=TQString::null) const
Reads the value of an entry specified by pKey in the current group.
virtual void sync()
Flushes all changes that currently reside only in memory back to disk / permanent storage...