00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #include <qcolor.h>
00023 #include <qvariant.h>
00024
00025 #include <kconfig.h>
00026 #include <kstandarddirs.h>
00027 #include <kglobal.h>
00028 #include <kglobalsettings.h>
00029 #include <kdebug.h>
00030
00031 #include "kstringhandler.h"
00032
00033 #include "kconfigskeleton.h"
00034
00035 void KConfigSkeletonItem::readImmutability( KConfig *config )
00036 {
00037 mIsImmutable = config->entryIsImmutable( mKey );
00038 }
00039
00040
00041 KConfigSkeleton::ItemString::ItemString( const QString &group, const QString &key,
00042 QString &reference,
00043 const QString &defaultValue,
00044 Type type )
00045 : KConfigSkeletonGenericItem<QString>( group, key, reference, defaultValue ),
00046 mType( type )
00047 {
00048 }
00049
00050 void KConfigSkeleton::ItemString::writeConfig( KConfig *config )
00051 {
00052 if ( mReference != mLoadedValue )
00053 {
00054 config->setGroup( mGroup );
00055 if ((mDefault == mReference) && !config->hasDefault( mKey))
00056 config->revertToDefault( mKey );
00057 else if ( mType == Path )
00058 config->writePathEntry( mKey, mReference );
00059 else if ( mType == Password )
00060 config->writeEntry( mKey, KStringHandler::obscure( mReference ) );
00061 else
00062 config->writeEntry( mKey, mReference );
00063 }
00064 }
00065
00066
00067 void KConfigSkeleton::ItemString::readConfig( KConfig *config )
00068 {
00069 config->setGroup( mGroup );
00070
00071 if ( mType == Path )
00072 {
00073 mReference = config->readPathEntry( mKey, mDefault );
00074 }
00075 else if ( mType == Password )
00076 {
00077 QString value = config->readEntry( mKey,
00078 KStringHandler::obscure( mDefault ) );
00079 mReference = KStringHandler::obscure( value );
00080 }
00081 else
00082 {
00083 mReference = config->readEntry( mKey, mDefault );
00084 }
00085
00086 mLoadedValue = mReference;
00087
00088 readImmutability( config );
00089 }
00090
00091 void KConfigSkeleton::ItemString::setProperty(const QVariant & p)
00092 {
00093 mReference = p.toString();
00094 }
00095
00096 QVariant KConfigSkeleton::ItemString::property() const
00097 {
00098 return QVariant(mReference);
00099 }
00100
00101 KConfigSkeleton::ItemPassword::ItemPassword( const QString &group, const QString &key,
00102 QString &reference,
00103 const QString &defaultValue)
00104 : ItemString( group, key, reference, defaultValue, Password )
00105 {
00106 }
00107
00108 KConfigSkeleton::ItemPath::ItemPath( const QString &group, const QString &key,
00109 QString &reference,
00110 const QString &defaultValue)
00111 : ItemString( group, key, reference, defaultValue, Path )
00112 {
00113 }
00114
00115 KConfigSkeleton::ItemProperty::ItemProperty( const QString &group,
00116 const QString &key,
00117 QVariant &reference,
00118 QVariant defaultValue )
00119 : KConfigSkeletonGenericItem<QVariant>( group, key, reference, defaultValue )
00120 {
00121 }
00122
00123 void KConfigSkeleton::ItemProperty::readConfig( KConfig *config )
00124 {
00125 config->setGroup( mGroup );
00126 mReference = config->readPropertyEntry( mKey, mDefault );
00127 mLoadedValue = mReference;
00128
00129 readImmutability( config );
00130 }
00131
00132 void KConfigSkeleton::ItemProperty::setProperty(const QVariant & p)
00133 {
00134 mReference = p;
00135 }
00136
00137 QVariant KConfigSkeleton::ItemProperty::property() const
00138 {
00139 return mReference;
00140 }
00141
00142 KConfigSkeleton::ItemBool::ItemBool( const QString &group, const QString &key,
00143 bool &reference, bool defaultValue )
00144 : KConfigSkeletonGenericItem<bool>( group, key, reference, defaultValue )
00145 {
00146 }
00147
00148 void KConfigSkeleton::ItemBool::readConfig( KConfig *config )
00149 {
00150 config->setGroup( mGroup );
00151 mReference = config->readBoolEntry( mKey, mDefault );
00152 mLoadedValue = mReference;
00153
00154 readImmutability( config );
00155 }
00156
00157 void KConfigSkeleton::ItemBool::setProperty(const QVariant & p)
00158 {
00159 mReference = p.toBool();
00160 }
00161
00162 QVariant KConfigSkeleton::ItemBool::property() const
00163 {
00164 return QVariant( mReference, 42 );
00165 }
00166
00167
00168 KConfigSkeleton::ItemInt::ItemInt( const QString &group, const QString &key,
00169 int &reference, int defaultValue )
00170 : KConfigSkeletonGenericItem<int>( group, key, reference, defaultValue )
00171 ,mHasMin(false), mHasMax(false)
00172 {
00173 }
00174
00175 void KConfigSkeleton::ItemInt::readConfig( KConfig *config )
00176 {
00177 config->setGroup( mGroup );
00178 mReference = config->readNumEntry( mKey, mDefault );
00179 if (mHasMin)
00180 mReference = QMAX(mReference, mMin);
00181 if (mHasMax)
00182 mReference = QMIN(mReference, mMax);
00183 mLoadedValue = mReference;
00184
00185 readImmutability( config );
00186 }
00187
00188 void KConfigSkeleton::ItemInt::setProperty(const QVariant & p)
00189 {
00190 mReference = p.toInt();
00191 }
00192
00193 QVariant KConfigSkeleton::ItemInt::property() const
00194 {
00195 return QVariant(mReference);
00196 }
00197
00198 QVariant KConfigSkeleton::ItemInt::minValue() const
00199 {
00200 if (mHasMin)
00201 return QVariant(mMin);
00202 return QVariant();
00203 }
00204
00205 QVariant KConfigSkeleton::ItemInt::maxValue() const
00206 {
00207 if (mHasMax)
00208 return QVariant(mMax);
00209 return QVariant();
00210 }
00211
00212 void KConfigSkeleton::ItemInt::setMinValue(int v)
00213 {
00214 mHasMin = true;
00215 mMin = v;
00216 }
00217
00218 void KConfigSkeleton::ItemInt::setMaxValue(int v)
00219 {
00220 mHasMax = true;
00221 mMax = v;
00222 }
00223
00224
00225 KConfigSkeleton::ItemInt64::ItemInt64( const QString &group, const QString &key,
00226 Q_INT64 &reference, Q_INT64 defaultValue )
00227 : KConfigSkeletonGenericItem<Q_INT64>( group, key, reference, defaultValue )
00228 ,mHasMin(false), mHasMax(false)
00229 {
00230 }
00231
00232 void KConfigSkeleton::ItemInt64::readConfig( KConfig *config )
00233 {
00234 config->setGroup( mGroup );
00235 mReference = config->readNum64Entry( mKey, mDefault );
00236 if (mHasMin)
00237 mReference = QMAX(mReference, mMin);
00238 if (mHasMax)
00239 mReference = QMIN(mReference, mMax);
00240 mLoadedValue = mReference;
00241
00242 readImmutability( config );
00243 }
00244
00245 void KConfigSkeleton::ItemInt64::setProperty(const QVariant & p)
00246 {
00247 mReference = p.toLongLong();
00248 }
00249
00250 QVariant KConfigSkeleton::ItemInt64::property() const
00251 {
00252 return QVariant(mReference);
00253 }
00254
00255 QVariant KConfigSkeleton::ItemInt64::minValue() const
00256 {
00257 if (mHasMin)
00258 return QVariant(mMin);
00259 return QVariant();
00260 }
00261
00262 QVariant KConfigSkeleton::ItemInt64::maxValue() const
00263 {
00264 if (mHasMax)
00265 return QVariant(mMax);
00266 return QVariant();
00267 }
00268
00269 void KConfigSkeleton::ItemInt64::setMinValue(Q_INT64 v)
00270 {
00271 mHasMin = true;
00272 mMin = v;
00273 }
00274
00275 void KConfigSkeleton::ItemInt64::setMaxValue(Q_INT64 v)
00276 {
00277 mHasMax = true;
00278 mMax = v;
00279 }
00280
00281 KConfigSkeleton::ItemEnum::ItemEnum( const QString &group, const QString &key,
00282 int &reference,
00283 const QValueList<Choice> &choices,
00284 int defaultValue )
00285 : ItemInt( group, key, reference, defaultValue ), mChoices( choices )
00286 {
00287 }
00288
00289 void KConfigSkeleton::ItemEnum::readConfig( KConfig *config )
00290 {
00291 config->setGroup( mGroup );
00292 if (!config->hasKey(mKey))
00293 {
00294 mReference = mDefault;
00295 }
00296 else
00297 {
00298 int i = 0;
00299 mReference = -1;
00300 QString tmp = config->readEntry( mKey ).lower();
00301 for(QValueList<Choice>::ConstIterator it = mChoices.begin();
00302 it != mChoices.end(); ++it, ++i)
00303 {
00304 if ((*it).name.lower() == tmp)
00305 {
00306 mReference = i;
00307 break;
00308 }
00309 }
00310 if (mReference == -1)
00311 mReference = config->readNumEntry( mKey, mDefault );
00312 }
00313 mLoadedValue = mReference;
00314
00315 readImmutability( config );
00316 }
00317
00318 void KConfigSkeleton::ItemEnum::writeConfig( KConfig *config )
00319 {
00320 if ( mReference != mLoadedValue )
00321 {
00322 config->setGroup( mGroup );
00323 if ((mDefault == mReference) && !config->hasDefault( mKey))
00324 config->revertToDefault( mKey );
00325 else if ((mReference >= 0) && (mReference < (int) mChoices.count()))
00326 config->writeEntry( mKey, mChoices[mReference].name );
00327 else
00328 config->writeEntry( mKey, mReference );
00329 }
00330 }
00331
00332 QValueList<KConfigSkeleton::ItemEnum::Choice> KConfigSkeleton::ItemEnum::choices() const
00333 {
00334 return mChoices;
00335 }
00336
00337
00338 KConfigSkeleton::ItemUInt::ItemUInt( const QString &group, const QString &key,
00339 unsigned int &reference,
00340 unsigned int defaultValue )
00341 : KConfigSkeletonGenericItem<unsigned int>( group, key, reference, defaultValue )
00342 ,mHasMin(false), mHasMax(false)
00343 {
00344 }
00345
00346 void KConfigSkeleton::ItemUInt::readConfig( KConfig *config )
00347 {
00348 config->setGroup( mGroup );
00349 mReference = config->readUnsignedNumEntry( mKey, mDefault );
00350 if (mHasMin)
00351 mReference = QMAX(mReference, mMin);
00352 if (mHasMax)
00353 mReference = QMIN(mReference, mMax);
00354 mLoadedValue = mReference;
00355
00356 readImmutability( config );
00357 }
00358
00359 void KConfigSkeleton::ItemUInt::setProperty(const QVariant & p)
00360 {
00361 mReference = p.toUInt();
00362 }
00363
00364 QVariant KConfigSkeleton::ItemUInt::property() const
00365 {
00366 return QVariant(mReference);
00367 }
00368
00369 QVariant KConfigSkeleton::ItemUInt::minValue() const
00370 {
00371 if (mHasMin)
00372 return QVariant(mMin);
00373 return QVariant();
00374 }
00375
00376 QVariant KConfigSkeleton::ItemUInt::maxValue() const
00377 {
00378 if (mHasMax)
00379 return QVariant(mMax);
00380 return QVariant();
00381 }
00382
00383 void KConfigSkeleton::ItemUInt::setMinValue(unsigned int v)
00384 {
00385 mHasMin = true;
00386 mMin = v;
00387 }
00388
00389 void KConfigSkeleton::ItemUInt::setMaxValue(unsigned int v)
00390 {
00391 mHasMax = true;
00392 mMax = v;
00393 }
00394
00395
00396 KConfigSkeleton::ItemUInt64::ItemUInt64( const QString &group, const QString &key,
00397 Q_UINT64 &reference, Q_UINT64 defaultValue )
00398 : KConfigSkeletonGenericItem<Q_UINT64>( group, key, reference, defaultValue )
00399 ,mHasMin(false), mHasMax(false)
00400 {
00401 }
00402
00403 void KConfigSkeleton::ItemUInt64::readConfig( KConfig *config )
00404 {
00405 config->setGroup( mGroup );
00406 mReference = config->readUnsignedNum64Entry( mKey, mDefault );
00407 if (mHasMin)
00408 mReference = QMAX(mReference, mMin);
00409 if (mHasMax)
00410 mReference = QMIN(mReference, mMax);
00411 mLoadedValue = mReference;
00412
00413 readImmutability( config );
00414 }
00415
00416 void KConfigSkeleton::ItemUInt64::setProperty(const QVariant & p)
00417 {
00418 mReference = p.toULongLong();
00419 }
00420
00421 QVariant KConfigSkeleton::ItemUInt64::property() const
00422 {
00423 return QVariant(mReference);
00424 }
00425
00426 QVariant KConfigSkeleton::ItemUInt64::minValue() const
00427 {
00428 if (mHasMin)
00429 return QVariant(mMin);
00430 return QVariant();
00431 }
00432
00433 QVariant KConfigSkeleton::ItemUInt64::maxValue() const
00434 {
00435 if (mHasMax)
00436 return QVariant(mMax);
00437 return QVariant();
00438 }
00439
00440 void KConfigSkeleton::ItemUInt64::setMinValue(Q_UINT64 v)
00441 {
00442 mHasMin = true;
00443 mMin = v;
00444 }
00445
00446 void KConfigSkeleton::ItemUInt64::setMaxValue(Q_UINT64 v)
00447 {
00448 mHasMax = true;
00449 mMax = v;
00450 }
00451
00452 KConfigSkeleton::ItemLong::ItemLong( const QString &group, const QString &key,
00453 long &reference, long defaultValue )
00454 : KConfigSkeletonGenericItem<long>( group, key, reference, defaultValue )
00455 ,mHasMin(false), mHasMax(false)
00456 {
00457 }
00458
00459 void KConfigSkeleton::ItemLong::readConfig( KConfig *config )
00460 {
00461 config->setGroup( mGroup );
00462 mReference = config->readLongNumEntry( mKey, mDefault );
00463 if (mHasMin)
00464 mReference = QMAX(mReference, mMin);
00465 if (mHasMax)
00466 mReference = QMIN(mReference, mMax);
00467 mLoadedValue = mReference;
00468
00469 readImmutability( config );
00470 }
00471
00472 void KConfigSkeleton::ItemLong::setProperty(const QVariant & p)
00473 {
00474 mReference = p.toLongLong();
00475 }
00476
00477 QVariant KConfigSkeleton::ItemLong::property() const
00478 {
00479 return QVariant((Q_LLONG) mReference);
00480 }
00481
00482 QVariant KConfigSkeleton::ItemLong::minValue() const
00483 {
00484 if (mHasMin)
00485 return QVariant((Q_LLONG) mMin);
00486 return QVariant();
00487 }
00488
00489 QVariant KConfigSkeleton::ItemLong::maxValue() const
00490 {
00491 if (mHasMax)
00492 return QVariant((Q_LLONG) mMax);
00493 return QVariant();
00494 }
00495
00496 void KConfigSkeleton::ItemLong::setMinValue(long v)
00497 {
00498 mHasMin = true;
00499 mMin = v;
00500 }
00501
00502 void KConfigSkeleton::ItemLong::setMaxValue(long v)
00503 {
00504 mHasMax = true;
00505 mMax = v;
00506 }
00507
00508
00509 KConfigSkeleton::ItemULong::ItemULong( const QString &group, const QString &key,
00510 unsigned long &reference,
00511 unsigned long defaultValue )
00512 : KConfigSkeletonGenericItem<unsigned long>( group, key, reference, defaultValue )
00513 ,mHasMin(false), mHasMax(false)
00514 {
00515 }
00516
00517 void KConfigSkeleton::ItemULong::readConfig( KConfig *config )
00518 {
00519 config->setGroup( mGroup );
00520 mReference = config->readUnsignedLongNumEntry( mKey, mDefault );
00521 if (mHasMin)
00522 mReference = QMAX(mReference, mMin);
00523 if (mHasMax)
00524 mReference = QMIN(mReference, mMax);
00525 mLoadedValue = mReference;
00526
00527 readImmutability( config );
00528 }
00529
00530 void KConfigSkeleton::ItemULong::setProperty(const QVariant & p)
00531 {
00532 mReference = p.toULongLong();
00533 }
00534
00535 QVariant KConfigSkeleton::ItemULong::property() const
00536 {
00537 return QVariant((Q_ULLONG) mReference);
00538 }
00539
00540 QVariant KConfigSkeleton::ItemULong::minValue() const
00541 {
00542 if (mHasMin)
00543 return QVariant((Q_ULLONG) mMin);
00544 return QVariant();
00545 }
00546
00547 QVariant KConfigSkeleton::ItemULong::maxValue() const
00548 {
00549 if (mHasMax)
00550 return QVariant((Q_ULLONG) mMax);
00551 return QVariant();
00552 }
00553
00554 void KConfigSkeleton::ItemULong::setMinValue(unsigned long v)
00555 {
00556 mHasMin = true;
00557 mMin = v;
00558 }
00559
00560 void KConfigSkeleton::ItemULong::setMaxValue(unsigned long v)
00561 {
00562 mHasMax = true;
00563 mMax = v;
00564 }
00565
00566
00567 KConfigSkeleton::ItemDouble::ItemDouble( const QString &group, const QString &key,
00568 double &reference, double defaultValue )
00569 : KConfigSkeletonGenericItem<double>( group, key, reference, defaultValue )
00570 ,mHasMin(false), mHasMax(false)
00571 {
00572 }
00573
00574 void KConfigSkeleton::ItemDouble::readConfig( KConfig *config )
00575 {
00576 config->setGroup( mGroup );
00577 mReference = config->readDoubleNumEntry( mKey, mDefault );
00578 if (mHasMin)
00579 mReference = QMAX(mReference, mMin);
00580 if (mHasMax)
00581 mReference = QMIN(mReference, mMax);
00582 mLoadedValue = mReference;
00583
00584 readImmutability( config );
00585 }
00586
00587 void KConfigSkeleton::ItemDouble::setProperty(const QVariant & p)
00588 {
00589 mReference = p.toDouble();
00590 }
00591
00592 QVariant KConfigSkeleton::ItemDouble::property() const
00593 {
00594 return QVariant(mReference);
00595 }
00596
00597 QVariant KConfigSkeleton::ItemDouble::minValue() const
00598 {
00599 if (mHasMin)
00600 return QVariant(mMin);
00601 return QVariant();
00602 }
00603
00604 QVariant KConfigSkeleton::ItemDouble::maxValue() const
00605 {
00606 if (mHasMax)
00607 return QVariant(mMax);
00608 return QVariant();
00609 }
00610
00611 void KConfigSkeleton::ItemDouble::setMinValue(double v)
00612 {
00613 mHasMin = true;
00614 mMin = v;
00615 }
00616
00617 void KConfigSkeleton::ItemDouble::setMaxValue(double v)
00618 {
00619 mHasMax = true;
00620 mMax = v;
00621 }
00622
00623
00624 KConfigSkeleton::ItemColor::ItemColor( const QString &group, const QString &key,
00625 QColor &reference,
00626 const QColor &defaultValue )
00627 : KConfigSkeletonGenericItem<QColor>( group, key, reference, defaultValue )
00628 {
00629 }
00630
00631 void KConfigSkeleton::ItemColor::readConfig( KConfig *config )
00632 {
00633 config->setGroup( mGroup );
00634 mReference = config->readColorEntry( mKey, &mDefault );
00635 mLoadedValue = mReference;
00636
00637 readImmutability( config );
00638 }
00639
00640 void KConfigSkeleton::ItemColor::setProperty(const QVariant & p)
00641 {
00642 mReference = p.toColor();
00643 }
00644
00645 QVariant KConfigSkeleton::ItemColor::property() const
00646 {
00647 return QVariant(mReference);
00648 }
00649
00650
00651 KConfigSkeleton::ItemFont::ItemFont( const QString &group, const QString &key,
00652 QFont &reference,
00653 const QFont &defaultValue )
00654 : KConfigSkeletonGenericItem<QFont>( group, key, reference, defaultValue )
00655 {
00656 }
00657
00658 void KConfigSkeleton::ItemFont::readConfig( KConfig *config )
00659 {
00660 config->setGroup( mGroup );
00661 mReference = config->readFontEntry( mKey, &mDefault );
00662 mLoadedValue = mReference;
00663
00664 readImmutability( config );
00665 }
00666
00667 void KConfigSkeleton::ItemFont::setProperty(const QVariant & p)
00668 {
00669 mReference = p.toFont();
00670 }
00671
00672 QVariant KConfigSkeleton::ItemFont::property() const
00673 {
00674 return QVariant(mReference);
00675 }
00676
00677
00678 KConfigSkeleton::ItemRect::ItemRect( const QString &group, const QString &key,
00679 QRect &reference,
00680 const QRect &defaultValue )
00681 : KConfigSkeletonGenericItem<QRect>( group, key, reference, defaultValue )
00682 {
00683 }
00684
00685 void KConfigSkeleton::ItemRect::readConfig( KConfig *config )
00686 {
00687 config->setGroup( mGroup );
00688 mReference = config->readRectEntry( mKey, &mDefault );
00689 mLoadedValue = mReference;
00690
00691 readImmutability( config );
00692 }
00693
00694 void KConfigSkeleton::ItemRect::setProperty(const QVariant & p)
00695 {
00696 mReference = p.toRect();
00697 }
00698
00699 QVariant KConfigSkeleton::ItemRect::property() const
00700 {
00701 return QVariant(mReference);
00702 }
00703
00704
00705 KConfigSkeleton::ItemPoint::ItemPoint( const QString &group, const QString &key,
00706 QPoint &reference,
00707 const QPoint &defaultValue )
00708 : KConfigSkeletonGenericItem<QPoint>( group, key, reference, defaultValue )
00709 {
00710 }
00711
00712 void KConfigSkeleton::ItemPoint::readConfig( KConfig *config )
00713 {
00714 config->setGroup( mGroup );
00715 mReference = config->readPointEntry( mKey, &mDefault );
00716 mLoadedValue = mReference;
00717
00718 readImmutability( config );
00719 }
00720
00721 void KConfigSkeleton::ItemPoint::setProperty(const QVariant & p)
00722 {
00723 mReference = p.toPoint();
00724 }
00725
00726 QVariant KConfigSkeleton::ItemPoint::property() const
00727 {
00728 return QVariant(mReference);
00729 }
00730
00731
00732 KConfigSkeleton::ItemSize::ItemSize( const QString &group, const QString &key,
00733 QSize &reference,
00734 const QSize &defaultValue )
00735 : KConfigSkeletonGenericItem<QSize>( group, key, reference, defaultValue )
00736 {
00737 }
00738
00739 void KConfigSkeleton::ItemSize::readConfig( KConfig *config )
00740 {
00741 config->setGroup( mGroup );
00742 mReference = config->readSizeEntry( mKey, &mDefault );
00743 mLoadedValue = mReference;
00744
00745 readImmutability( config );
00746 }
00747
00748 void KConfigSkeleton::ItemSize::setProperty(const QVariant & p)
00749 {
00750 mReference = p.toSize();
00751 }
00752
00753 QVariant KConfigSkeleton::ItemSize::property() const
00754 {
00755 return QVariant(mReference);
00756 }
00757
00758
00759 KConfigSkeleton::ItemDateTime::ItemDateTime( const QString &group, const QString &key,
00760 QDateTime &reference,
00761 const QDateTime &defaultValue )
00762 : KConfigSkeletonGenericItem<QDateTime>( group, key, reference, defaultValue )
00763 {
00764 }
00765
00766 void KConfigSkeleton::ItemDateTime::readConfig( KConfig *config )
00767 {
00768 config->setGroup( mGroup );
00769 mReference = config->readDateTimeEntry( mKey, &mDefault );
00770 mLoadedValue = mReference;
00771
00772 readImmutability( config );
00773 }
00774
00775 void KConfigSkeleton::ItemDateTime::setProperty(const QVariant & p)
00776 {
00777 mReference = p.toDateTime();
00778 }
00779
00780 QVariant KConfigSkeleton::ItemDateTime::property() const
00781 {
00782 return QVariant(mReference);
00783 }
00784
00785
00786 KConfigSkeleton::ItemStringList::ItemStringList( const QString &group, const QString &key,
00787 QStringList &reference,
00788 const QStringList &defaultValue )
00789 : KConfigSkeletonGenericItem<QStringList>( group, key, reference, defaultValue )
00790 {
00791 }
00792
00793 void KConfigSkeleton::ItemStringList::readConfig( KConfig *config )
00794 {
00795 config->setGroup( mGroup );
00796 if ( !config->hasKey( mKey ) )
00797 mReference = mDefault;
00798 else
00799 mReference = config->readListEntry( mKey );
00800 mLoadedValue = mReference;
00801
00802 readImmutability( config );
00803 }
00804
00805 void KConfigSkeleton::ItemStringList::setProperty(const QVariant & p)
00806 {
00807 mReference = p.toStringList();
00808 }
00809
00810 QVariant KConfigSkeleton::ItemStringList::property() const
00811 {
00812 return QVariant(mReference);
00813 }
00814
00815
00816 KConfigSkeleton::ItemIntList::ItemIntList( const QString &group, const QString &key,
00817 QValueList<int> &reference,
00818 const QValueList<int> &defaultValue )
00819 : KConfigSkeletonGenericItem<QValueList<int> >( group, key, reference, defaultValue )
00820 {
00821 }
00822
00823 void KConfigSkeleton::ItemIntList::readConfig( KConfig *config )
00824 {
00825 config->setGroup( mGroup );
00826 if ( !config->hasKey( mKey ) )
00827 mReference = mDefault;
00828 else
00829 mReference = config->readIntListEntry( mKey );
00830 mLoadedValue = mReference;
00831
00832 readImmutability( config );
00833 }
00834
00835 void KConfigSkeleton::ItemIntList::setProperty(const QVariant &)
00836 {
00837
00838 }
00839
00840 QVariant KConfigSkeleton::ItemIntList::property() const
00841 {
00842
00843 return QVariant();
00844 }
00845
00846
00847 KConfigSkeleton::KConfigSkeleton( const QString &configname )
00848 : mCurrentGroup( "No Group" ), mUseDefaults(false)
00849 {
00850 kdDebug(177) << "Creating KConfigSkeleton (" << (void *)this << ")" << endl;
00851
00852 if ( !configname.isEmpty() )
00853 {
00854 mConfig = KSharedConfig::openConfig( configname );
00855 }
00856 else
00857 {
00858 mConfig = KGlobal::sharedConfig();
00859 }
00860 }
00861
00862 KConfigSkeleton::KConfigSkeleton(KSharedConfig::Ptr config)
00863 : mCurrentGroup( "No Group" ), mUseDefaults(false)
00864 {
00865 kdDebug(177) << "Creating KConfigSkeleton (" << (void *)this << ")" << endl;
00866 mConfig = config;
00867 }
00868
00869
00870 KConfigSkeleton::~KConfigSkeleton()
00871 {
00872 KConfigSkeletonItem::List::ConstIterator it;
00873 for( it = mItems.begin(); it != mItems.end(); ++it )
00874 {
00875 delete *it;
00876 }
00877 }
00878
00879 void KConfigSkeleton::setCurrentGroup( const QString &group )
00880 {
00881 mCurrentGroup = group;
00882 }
00883
00884 KConfig *KConfigSkeleton::config() const
00885 {
00886 return mConfig;
00887 }
00888
00889 bool KConfigSkeleton::useDefaults(bool b)
00890 {
00891 if (b == mUseDefaults)
00892 return mUseDefaults;
00893
00894 mUseDefaults = b;
00895 KConfigSkeletonItem::List::ConstIterator it;
00896 for( it = mItems.begin(); it != mItems.end(); ++it )
00897 {
00898 (*it)->swapDefault();
00899 }
00900
00901 usrUseDefaults(b);
00902 return !mUseDefaults;
00903 }
00904
00905 void KConfigSkeleton::setDefaults()
00906 {
00907 KConfigSkeletonItem::List::ConstIterator it;
00908 for( it = mItems.begin(); it != mItems.end(); ++it ) {
00909 (*it)->setDefault();
00910 }
00911
00912 usrSetDefaults();
00913 }
00914
00915 void KConfigSkeleton::readConfig()
00916 {
00917 kdDebug(177) << "KConfigSkeleton::readConfig()" << endl;
00918
00919 QString origGroup = mConfig->group();
00920
00921 KConfigSkeletonItem::List::ConstIterator it;
00922 for( it = mItems.begin(); it != mItems.end(); ++it )
00923 {
00924 (*it)->readConfig( mConfig );
00925 }
00926
00927 usrReadConfig();
00928
00929 mConfig->setGroup(origGroup);
00930 }
00931
00932 void KConfigSkeleton::writeConfig()
00933 {
00934 kdDebug(177) << "KConfigSkeleton::writeConfig()" << endl;
00935
00936 QString origGroup = mConfig->group();
00937
00938 KConfigSkeletonItem::List::ConstIterator it;
00939 for( it = mItems.begin(); it != mItems.end(); ++it )
00940 {
00941 (*it)->writeConfig( mConfig );
00942 }
00943
00944 usrWriteConfig();
00945
00946 mConfig->sync();
00947
00948 readConfig();
00949
00950 mConfig->setGroup(origGroup);
00951 }
00952
00953 void KConfigSkeleton::addItem( KConfigSkeletonItem *item, const QString &name )
00954 {
00955 item->setName( name.isEmpty() ? item->key() : name );
00956 mItems.append( item );
00957 mItemDict.insert( item->name(), item );
00958 item->readDefault( mConfig );
00959 }
00960
00961 KConfigSkeleton::ItemString *KConfigSkeleton::addItemString( const QString &name, QString &reference,
00962 const QString &defaultValue, const QString &key )
00963 {
00964 KConfigSkeleton::ItemString *item;
00965 item = new KConfigSkeleton::ItemString( mCurrentGroup, key.isEmpty() ? name : key,
00966 reference, defaultValue,
00967 KConfigSkeleton::ItemString::Normal );
00968 addItem( item, name );
00969 return item;
00970 }
00971
00972 KConfigSkeleton::ItemPassword *KConfigSkeleton::addItemPassword( const QString &name, QString &reference,
00973 const QString &defaultValue, const QString &key )
00974 {
00975 KConfigSkeleton::ItemPassword *item;
00976 item = new KConfigSkeleton::ItemPassword( mCurrentGroup, key.isNull() ? name : key,
00977 reference, defaultValue );
00978 addItem( item, name );
00979 return item;
00980 }
00981
00982 KConfigSkeleton::ItemPath *KConfigSkeleton::addItemPath( const QString &name, QString &reference,
00983 const QString &defaultValue, const QString &key )
00984 {
00985 KConfigSkeleton::ItemPath *item;
00986 item = new KConfigSkeleton::ItemPath( mCurrentGroup, key.isNull() ? name : key,
00987 reference, defaultValue );
00988 addItem( item, name );
00989 return item;
00990 }
00991
00992 KConfigSkeleton::ItemProperty *KConfigSkeleton::addItemProperty( const QString &name, QVariant &reference,
00993 const QVariant &defaultValue, const QString &key )
00994 {
00995 KConfigSkeleton::ItemProperty *item;
00996 item = new KConfigSkeleton::ItemProperty( mCurrentGroup, key.isNull() ? name : key,
00997 reference, defaultValue );
00998 addItem( item, name );
00999 return item;
01000 }
01001
01002 KConfigSkeleton::ItemBool *KConfigSkeleton::addItemBool( const QString &name, bool &reference,
01003 bool defaultValue, const QString &key )
01004 {
01005 KConfigSkeleton::ItemBool *item;
01006 item = new KConfigSkeleton::ItemBool( mCurrentGroup, key.isNull() ? name : key,
01007 reference, defaultValue );
01008 addItem( item, name );
01009 return item;
01010 }
01011
01012 KConfigSkeleton::ItemInt *KConfigSkeleton::addItemInt( const QString &name, int &reference,
01013 int defaultValue, const QString &key )
01014 {
01015 KConfigSkeleton::ItemInt *item;
01016 item = new KConfigSkeleton::ItemInt( mCurrentGroup, key.isNull() ? name : key,
01017 reference, defaultValue );
01018 addItem( item, name );
01019 return item;
01020 }
01021
01022 KConfigSkeleton::ItemUInt *KConfigSkeleton::addItemUInt( const QString &name, unsigned int &reference,
01023 unsigned int defaultValue, const QString &key )
01024 {
01025 KConfigSkeleton::ItemUInt *item;
01026 item = new KConfigSkeleton::ItemUInt( mCurrentGroup, key.isNull() ? name : key,
01027 reference, defaultValue );
01028 addItem( item, name );
01029 return item;
01030 }
01031
01032 KConfigSkeleton::ItemInt64 *KConfigSkeleton::addItemInt64( const QString &name, Q_INT64 &reference,
01033 Q_INT64 defaultValue, const QString &key )
01034 {
01035 KConfigSkeleton::ItemInt64 *item;
01036 item = new KConfigSkeleton::ItemInt64( mCurrentGroup, key.isNull() ? name : key,
01037 reference, defaultValue );
01038 addItem( item, name );
01039 return item;
01040 }
01041
01042 KConfigSkeleton::ItemUInt64 *KConfigSkeleton::addItemUInt64( const QString &name, Q_UINT64 &reference,
01043 Q_UINT64 defaultValue, const QString &key )
01044 {
01045 KConfigSkeleton::ItemUInt64 *item;
01046 item = new KConfigSkeleton::ItemUInt64( mCurrentGroup, key.isNull() ? name : key,
01047 reference, defaultValue );
01048 addItem( item, name );
01049 return item;
01050 }
01051
01052 KConfigSkeleton::ItemLong *KConfigSkeleton::addItemLong( const QString &name, long &reference,
01053 long defaultValue, const QString &key )
01054 {
01055 KConfigSkeleton::ItemLong *item;
01056 item = new KConfigSkeleton::ItemLong( mCurrentGroup, key.isNull() ? name : key,
01057 reference, defaultValue );
01058 addItem( item, name );
01059 return item;
01060 }
01061
01062 KConfigSkeleton::ItemULong *KConfigSkeleton::addItemULong( const QString &name, unsigned long &reference,
01063 unsigned long defaultValue, const QString &key )
01064 {
01065 KConfigSkeleton::ItemULong *item;
01066 item = new KConfigSkeleton::ItemULong( mCurrentGroup, key.isNull() ? name : key,
01067 reference, defaultValue );
01068 addItem( item, name );
01069 return item;
01070 }
01071
01072 KConfigSkeleton::ItemDouble *KConfigSkeleton::addItemDouble( const QString &name, double &reference,
01073 double defaultValue, const QString &key )
01074 {
01075 KConfigSkeleton::ItemDouble *item;
01076 item = new KConfigSkeleton::ItemDouble( mCurrentGroup, key.isNull() ? name : key,
01077 reference, defaultValue );
01078 addItem( item, name );
01079 return item;
01080 }
01081
01082 KConfigSkeleton::ItemColor *KConfigSkeleton::addItemColor( const QString &name, QColor &reference,
01083 const QColor &defaultValue, const QString &key )
01084 {
01085 KConfigSkeleton::ItemColor *item;
01086 item = new KConfigSkeleton::ItemColor( mCurrentGroup, key.isNull() ? name : key,
01087 reference, defaultValue );
01088 addItem( item, name );
01089 return item;
01090 }
01091
01092 KConfigSkeleton::ItemFont *KConfigSkeleton::addItemFont( const QString &name, QFont &reference,
01093 const QFont &defaultValue, const QString &key )
01094 {
01095 KConfigSkeleton::ItemFont *item;
01096 item = new KConfigSkeleton::ItemFont( mCurrentGroup, key.isNull() ? name : key,
01097 reference, defaultValue );
01098 addItem( item, name );
01099 return item;
01100 }
01101
01102 KConfigSkeleton::ItemRect *KConfigSkeleton::addItemRect( const QString &name, QRect &reference,
01103 const QRect &defaultValue, const QString &key )
01104 {
01105 KConfigSkeleton::ItemRect *item;
01106 item = new KConfigSkeleton::ItemRect( mCurrentGroup, key.isNull() ? name : key,
01107 reference, defaultValue );
01108 addItem( item, name );
01109 return item;
01110 }
01111
01112 KConfigSkeleton::ItemPoint *KConfigSkeleton::addItemPoint( const QString &name, QPoint &reference,
01113 const QPoint &defaultValue, const QString &key )
01114 {
01115 KConfigSkeleton::ItemPoint *item;
01116 item = new KConfigSkeleton::ItemPoint( mCurrentGroup, key.isNull() ? name : key,
01117 reference, defaultValue );
01118 addItem( item, name );
01119 return item;
01120 }
01121
01122 KConfigSkeleton::ItemSize *KConfigSkeleton::addItemSize( const QString &name, QSize &reference,
01123 const QSize &defaultValue, const QString &key )
01124 {
01125 KConfigSkeleton::ItemSize *item;
01126 item = new KConfigSkeleton::ItemSize( mCurrentGroup, key.isNull() ? name : key,
01127 reference, defaultValue );
01128 addItem( item, name );
01129 return item;
01130 }
01131
01132 KConfigSkeleton::ItemDateTime *KConfigSkeleton::addItemDateTime( const QString &name, QDateTime &reference,
01133 const QDateTime &defaultValue, const QString &key )
01134 {
01135 KConfigSkeleton::ItemDateTime *item;
01136 item = new KConfigSkeleton::ItemDateTime( mCurrentGroup, key.isNull() ? name : key,
01137 reference, defaultValue );
01138 addItem( item, name );
01139 return item;
01140 }
01141
01142 KConfigSkeleton::ItemStringList *KConfigSkeleton::addItemStringList( const QString &name, QStringList &reference,
01143 const QStringList &defaultValue, const QString &key )
01144 {
01145 KConfigSkeleton::ItemStringList *item;
01146 item = new KConfigSkeleton::ItemStringList( mCurrentGroup, key.isNull() ? name : key,
01147 reference, defaultValue );
01148 addItem( item, name );
01149 return item;
01150 }
01151
01152 KConfigSkeleton::ItemIntList *KConfigSkeleton::addItemIntList( const QString &name, QValueList<int> &reference,
01153 const QValueList<int> &defaultValue, const QString &key )
01154 {
01155 KConfigSkeleton::ItemIntList *item;
01156 item = new KConfigSkeleton::ItemIntList( mCurrentGroup, key.isNull() ? name : key,
01157 reference, defaultValue );
01158 addItem( item, name );
01159 return item;
01160 }
01161
01162 bool KConfigSkeleton::isImmutable(const QString &name)
01163 {
01164 KConfigSkeletonItem *item = findItem(name);
01165 return !item || item->isImmutable();
01166 }
01167
01168 KConfigSkeletonItem *KConfigSkeleton::findItem(const QString &name)
01169 {
01170 return mItemDict.find(name);
01171 }