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