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