kdecore Library API Documentation

kconfigskeleton.cpp

00001 /* 00002 This file is part of KOrganizer. 00003 Copyright (c) 2000,2001 Cornelius Schumacher <schumacher@kde.org> 00004 Copyright (c) 2003 Waldo Bastian <bastian@kde.org> 00005 00006 This library is free software; you can redistribute it and/or 00007 modify it under the terms of the GNU Library General Public 00008 License as published by the Free Software Foundation; either 00009 version 2 of the License, or (at your option) any later version. 00010 00011 This library is distributed in the hope that it will be useful, 00012 but WITHOUT ANY WARRANTY; without even the implied warranty of 00013 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00014 Library General Public License for more details. 00015 00016 You should have received a copy of the GNU Library General Public License 00017 along with this library; see the file COPYING.LIB. If not, write to 00018 the Free Software Foundation, Inc., 59 Temple Place - Suite 330, 00019 Boston, MA 02111-1307, USA. 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 ) // WABA: Is this test needed? 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 /* dummy */ ); 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 ) // WABA: Is this test needed? 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 & p) 00836 { 00837 // TODO: Not yet supported 00838 } 00839 00840 QVariant KConfigSkeleton::ItemIntList::property() const 00841 { 00842 // TODO: Not yet supported 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 KConfigSkeletonItem::List::ConstIterator it; 00920 for( it = mItems.begin(); it != mItems.end(); ++it ) 00921 { 00922 (*it)->readConfig( mConfig ); 00923 } 00924 00925 usrReadConfig(); 00926 } 00927 00928 void KConfigSkeleton::writeConfig() 00929 { 00930 kdDebug(177) << "KConfigSkeleton::writeConfig()" << endl; 00931 00932 KConfigSkeletonItem::List::ConstIterator it; 00933 for( it = mItems.begin(); it != mItems.end(); ++it ) 00934 { 00935 (*it)->writeConfig( mConfig ); 00936 } 00937 00938 usrWriteConfig(); 00939 00940 mConfig->sync(); 00941 00942 readConfig(); 00943 } 00944 00945 void KConfigSkeleton::addItem( KConfigSkeletonItem *item, const QString &name ) 00946 { 00947 item->setName( name.isEmpty() ? item->key() : name ); 00948 mItems.append( item ); 00949 mItemDict.insert( item->name(), item ); 00950 item->readDefault( mConfig ); 00951 } 00952 00953 KConfigSkeleton::ItemString *KConfigSkeleton::addItemString( const QString &name, QString &reference, 00954 const QString &defaultValue, const QString &key ) 00955 { 00956 KConfigSkeleton::ItemString *item; 00957 item = new KConfigSkeleton::ItemString( mCurrentGroup, key.isEmpty() ? name : key, 00958 reference, defaultValue, 00959 KConfigSkeleton::ItemString::Normal ); 00960 addItem( item, name ); 00961 return item; 00962 } 00963 00964 KConfigSkeleton::ItemPassword *KConfigSkeleton::addItemPassword( const QString &name, QString &reference, 00965 const QString &defaultValue, const QString &key ) 00966 { 00967 KConfigSkeleton::ItemPassword *item; 00968 item = new KConfigSkeleton::ItemPassword( mCurrentGroup, key.isNull() ? name : key, 00969 reference, defaultValue ); 00970 addItem( item, name ); 00971 return item; 00972 } 00973 00974 KConfigSkeleton::ItemPath *KConfigSkeleton::addItemPath( const QString &name, QString &reference, 00975 const QString &defaultValue, const QString &key ) 00976 { 00977 KConfigSkeleton::ItemPath *item; 00978 item = new KConfigSkeleton::ItemPath( mCurrentGroup, key.isNull() ? name : key, 00979 reference, defaultValue ); 00980 addItem( item, name ); 00981 return item; 00982 } 00983 00984 KConfigSkeleton::ItemProperty *KConfigSkeleton::addItemProperty( const QString &name, QVariant &reference, 00985 const QVariant &defaultValue, const QString &key ) 00986 { 00987 KConfigSkeleton::ItemProperty *item; 00988 item = new KConfigSkeleton::ItemProperty( mCurrentGroup, key.isNull() ? name : key, 00989 reference, defaultValue ); 00990 addItem( item, name ); 00991 return item; 00992 } 00993 00994 KConfigSkeleton::ItemBool *KConfigSkeleton::addItemBool( const QString &name, bool &reference, 00995 bool defaultValue, const QString &key ) 00996 { 00997 KConfigSkeleton::ItemBool *item; 00998 item = new KConfigSkeleton::ItemBool( mCurrentGroup, key.isNull() ? name : key, 00999 reference, defaultValue ); 01000 addItem( item, name ); 01001 return item; 01002 } 01003 01004 KConfigSkeleton::ItemInt *KConfigSkeleton::addItemInt( const QString &name, int &reference, 01005 int defaultValue, const QString &key ) 01006 { 01007 KConfigSkeleton::ItemInt *item; 01008 item = new KConfigSkeleton::ItemInt( mCurrentGroup, key.isNull() ? name : key, 01009 reference, defaultValue ); 01010 addItem( item, name ); 01011 return item; 01012 } 01013 01014 KConfigSkeleton::ItemUInt *KConfigSkeleton::addItemUInt( const QString &name, unsigned int &reference, 01015 unsigned int defaultValue, const QString &key ) 01016 { 01017 KConfigSkeleton::ItemUInt *item; 01018 item = new KConfigSkeleton::ItemUInt( mCurrentGroup, key.isNull() ? name : key, 01019 reference, defaultValue ); 01020 addItem( item, name ); 01021 return item; 01022 } 01023 01024 KConfigSkeleton::ItemInt64 *KConfigSkeleton::addItemInt64( const QString &name, Q_INT64 &reference, 01025 Q_INT64 defaultValue, const QString &key ) 01026 { 01027 KConfigSkeleton::ItemInt64 *item; 01028 item = new KConfigSkeleton::ItemInt64( mCurrentGroup, key.isNull() ? name : key, 01029 reference, defaultValue ); 01030 addItem( item, name ); 01031 return item; 01032 } 01033 01034 KConfigSkeleton::ItemUInt64 *KConfigSkeleton::addItemUInt64( const QString &name, Q_UINT64 &reference, 01035 Q_UINT64 defaultValue, const QString &key ) 01036 { 01037 KConfigSkeleton::ItemUInt64 *item; 01038 item = new KConfigSkeleton::ItemUInt64( mCurrentGroup, key.isNull() ? name : key, 01039 reference, defaultValue ); 01040 addItem( item, name ); 01041 return item; 01042 } 01043 01044 KConfigSkeleton::ItemLong *KConfigSkeleton::addItemLong( const QString &name, long &reference, 01045 long defaultValue, const QString &key ) 01046 { 01047 KConfigSkeleton::ItemLong *item; 01048 item = new KConfigSkeleton::ItemLong( mCurrentGroup, key.isNull() ? name : key, 01049 reference, defaultValue ); 01050 addItem( item, name ); 01051 return item; 01052 } 01053 01054 KConfigSkeleton::ItemULong *KConfigSkeleton::addItemULong( const QString &name, unsigned long &reference, 01055 unsigned long defaultValue, const QString &key ) 01056 { 01057 KConfigSkeleton::ItemULong *item; 01058 item = new KConfigSkeleton::ItemULong( mCurrentGroup, key.isNull() ? name : key, 01059 reference, defaultValue ); 01060 addItem( item, name ); 01061 return item; 01062 } 01063 01064 KConfigSkeleton::ItemDouble *KConfigSkeleton::addItemDouble( const QString &name, double &reference, 01065 double defaultValue, const QString &key ) 01066 { 01067 KConfigSkeleton::ItemDouble *item; 01068 item = new KConfigSkeleton::ItemDouble( mCurrentGroup, key.isNull() ? name : key, 01069 reference, defaultValue ); 01070 addItem( item, name ); 01071 return item; 01072 } 01073 01074 KConfigSkeleton::ItemColor *KConfigSkeleton::addItemColor( const QString &name, QColor &reference, 01075 const QColor &defaultValue, const QString &key ) 01076 { 01077 KConfigSkeleton::ItemColor *item; 01078 item = new KConfigSkeleton::ItemColor( mCurrentGroup, key.isNull() ? name : key, 01079 reference, defaultValue ); 01080 addItem( item, name ); 01081 return item; 01082 } 01083 01084 KConfigSkeleton::ItemFont *KConfigSkeleton::addItemFont( const QString &name, QFont &reference, 01085 const QFont &defaultValue, const QString &key ) 01086 { 01087 KConfigSkeleton::ItemFont *item; 01088 item = new KConfigSkeleton::ItemFont( mCurrentGroup, key.isNull() ? name : key, 01089 reference, defaultValue ); 01090 addItem( item, name ); 01091 return item; 01092 } 01093 01094 KConfigSkeleton::ItemRect *KConfigSkeleton::addItemRect( const QString &name, QRect &reference, 01095 const QRect &defaultValue, const QString &key ) 01096 { 01097 KConfigSkeleton::ItemRect *item; 01098 item = new KConfigSkeleton::ItemRect( mCurrentGroup, key.isNull() ? name : key, 01099 reference, defaultValue ); 01100 addItem( item, name ); 01101 return item; 01102 } 01103 01104 KConfigSkeleton::ItemPoint *KConfigSkeleton::addItemPoint( const QString &name, QPoint &reference, 01105 const QPoint &defaultValue, const QString &key ) 01106 { 01107 KConfigSkeleton::ItemPoint *item; 01108 item = new KConfigSkeleton::ItemPoint( mCurrentGroup, key.isNull() ? name : key, 01109 reference, defaultValue ); 01110 addItem( item, name ); 01111 return item; 01112 } 01113 01114 KConfigSkeleton::ItemSize *KConfigSkeleton::addItemSize( const QString &name, QSize &reference, 01115 const QSize &defaultValue, const QString &key ) 01116 { 01117 KConfigSkeleton::ItemSize *item; 01118 item = new KConfigSkeleton::ItemSize( mCurrentGroup, key.isNull() ? name : key, 01119 reference, defaultValue ); 01120 addItem( item, name ); 01121 return item; 01122 } 01123 01124 KConfigSkeleton::ItemDateTime *KConfigSkeleton::addItemDateTime( const QString &name, QDateTime &reference, 01125 const QDateTime &defaultValue, const QString &key ) 01126 { 01127 KConfigSkeleton::ItemDateTime *item; 01128 item = new KConfigSkeleton::ItemDateTime( mCurrentGroup, key.isNull() ? name : key, 01129 reference, defaultValue ); 01130 addItem( item, name ); 01131 return item; 01132 } 01133 01134 KConfigSkeleton::ItemStringList *KConfigSkeleton::addItemStringList( const QString &name, QStringList &reference, 01135 const QStringList &defaultValue, const QString &key ) 01136 { 01137 KConfigSkeleton::ItemStringList *item; 01138 item = new KConfigSkeleton::ItemStringList( mCurrentGroup, key.isNull() ? name : key, 01139 reference, defaultValue ); 01140 addItem( item, name ); 01141 return item; 01142 } 01143 01144 KConfigSkeleton::ItemIntList *KConfigSkeleton::addItemIntList( const QString &name, QValueList<int> &reference, 01145 const QValueList<int> &defaultValue, const QString &key ) 01146 { 01147 KConfigSkeleton::ItemIntList *item; 01148 item = new KConfigSkeleton::ItemIntList( mCurrentGroup, key.isNull() ? name : key, 01149 reference, defaultValue ); 01150 addItem( item, name ); 01151 return item; 01152 } 01153 01154 bool KConfigSkeleton::isImmutable(const QString &name) 01155 { 01156 KConfigSkeletonItem *item = findItem(name); 01157 return !item || item->isImmutable(); 01158 } 01159 01160 KConfigSkeletonItem *KConfigSkeleton::findItem(const QString &name) 01161 { 01162 return mItemDict.find(name); 01163 }
KDE Logo
This file is part of the documentation for kdecore Library Version 3.2.3.
Documentation copyright © 1996-2004 the KDE developers.
Generated on Sun Oct 10 18:54:55 2004 by doxygen 1.3.7 written by Dimitri van Heesch, © 1997-2003