| # kdecore Library API Documentation
Overview | Class Hierarchy | Classes | Classes (annotated) | Members | Namespaces | Source Files

# 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::ItemPathList::ItemPathList( const QString &group, const QString &key,
    00817                                             QStringList &reference,
    00818                                             const QStringList &defaultValue )
    00819   : ItemStringList( group, key, reference, defaultValue )
    00820 {
    00821 }
    00822
    00823 void KConfigSkeleton::ItemPathList::readConfig( KConfig *config )
    00824 {
    00825   config->setGroup( mGroup );
    00826   if ( !config->hasKey( mKey ) )
    00827     mReference = mDefault;
    00828   else
    00829     mReference = config->readPathListEntry( mKey );
    00830   mLoadedValue = mReference;
    00831
    00832   readImmutability( config );
    00833 }
    00834
    00835 void KConfigSkeleton::ItemPathList::writeConfig( KConfig *config )
    00836 {
    00837   if ( mReference != mLoadedValue ) // WABA: Is this test needed?
    00838   {
    00839     config->setGroup( mGroup );
    00840     if ((mDefault == mReference) && !config->hasDefault( mKey))
    00841       config->revertToDefault( mKey );
    00842     else {
    00843       QStringList sl = mReference;
    00844       config->writePathEntry( mKey, sl );
    00845     }
    00846   }
    00847 }
    00848
    00849
    00850 KConfigSkeleton::ItemIntList::ItemIntList( const QString &group, const QString &key,
    00851                                       QValueList<int> &reference,
    00852                                       const QValueList<int> &defaultValue )
    00853   : KConfigSkeletonGenericItem<QValueList<int> >( group, key, reference, defaultValue )
    00854 {
    00855 }
    00856
    00857 void KConfigSkeleton::ItemIntList::readConfig( KConfig *config )
    00858 {
    00859   config->setGroup( mGroup );
    00860   if ( !config->hasKey( mKey ) )
    00861     mReference = mDefault;
    00862   else
    00863     mReference = config->readIntListEntry( mKey );
    00864   mLoadedValue = mReference;
    00865
    00866   readImmutability( config );
    00867 }
    00868
    00869 void KConfigSkeleton::ItemIntList::setProperty(const QVariant &)
    00870 {
    00871   // TODO: Not yet supported
    00872 }
    00873
    00874 QVariant KConfigSkeleton::ItemIntList::property() const
    00875 {
    00876   // TODO: Not yet supported
    00877   return QVariant();
    00878 }
    00879
    00880
    00881 KConfigSkeleton::KConfigSkeleton( const QString &configname )
    00882   : mCurrentGroup( "No Group" ), mUseDefaults(false)
    00883 {
    00884   kdDebug(177) << "Creating KConfigSkeleton (" << (void *)this << ")" << endl;
    00885
    00886   if ( !configname.isEmpty() )
    00887   {
    00888     mConfig = KSharedConfig::openConfig( configname );
    00889   }
    00890   else
    00891   {
    00892     mConfig = KGlobal::sharedConfig();
    00893   }
    00894 }
    00895
    00896 KConfigSkeleton::KConfigSkeleton(KSharedConfig::Ptr config)
    00897   : mCurrentGroup( "No Group" ), mUseDefaults(false)
    00898 {
    00899   kdDebug(177) << "Creating KConfigSkeleton (" << (void *)this << ")" << endl;
    00900   mConfig = config;
    00901 }
    00902
    00903
    00904 KConfigSkeleton::~KConfigSkeleton()
    00905 {
    00906   KConfigSkeletonItem::List::ConstIterator it;
    00907   for( it = mItems.begin(); it != mItems.end(); ++it )
    00908   {
    00909     delete *it;
    00910   }
    00911 }
    00912
    00913 void KConfigSkeleton::setCurrentGroup( const QString &group )
    00914 {
    00915   mCurrentGroup = group;
    00916 }
    00917
    00918 KConfig *KConfigSkeleton::config() const
    00919 {
    00920   return mConfig;
    00921 }
    00922
    00923 bool KConfigSkeleton::useDefaults(bool b)
    00924 {
    00925   if (b == mUseDefaults)
    00926      return mUseDefaults;
    00927
    00928   mUseDefaults = b;
    00929   KConfigSkeletonItem::List::ConstIterator it;
    00930   for( it = mItems.begin(); it != mItems.end(); ++it )
    00931   {
    00932     (*it)->swapDefault();
    00933   }
    00934
    00935   usrUseDefaults(b);
    00936   return !mUseDefaults;
    00937 }
    00938
    00939 void KConfigSkeleton::setDefaults()
    00940 {
    00941   KConfigSkeletonItem::List::ConstIterator it;
    00942   for( it = mItems.begin(); it != mItems.end(); ++it ) {
    00943     (*it)->setDefault();
    00944   }
    00945
    00946   usrSetDefaults();
    00947 }
    00948
    00949 void KConfigSkeleton::readConfig()
    00950 {
    00951   kdDebug(177) << "KConfigSkeleton::readConfig()" << endl;
    00952
    00953   QString origGroup = mConfig->group();
    00954
    00955   mConfig->reparseConfiguration();
    00956   KConfigSkeletonItem::List::ConstIterator it;
    00957   for( it = mItems.begin(); it != mItems.end(); ++it )
    00958   {
    00959     (*it)->readConfig( mConfig );
    00960   }
    00961
    00962   usrReadConfig();
    00963
    00964   mConfig->setGroup(origGroup);
    00965 }
    00966
    00967 void KConfigSkeleton::writeConfig()
    00968 {
    00969   kdDebug(177) << "KConfigSkeleton::writeConfig()" << endl;
    00970
    00971   QString origGroup = mConfig->group();
    00972
    00973   KConfigSkeletonItem::List::ConstIterator it;
    00974   for( it = mItems.begin(); it != mItems.end(); ++it )
    00975   {
    00976     (*it)->writeConfig( mConfig );
    00977   }
    00978
    00979   usrWriteConfig();
    00980
    00981   mConfig->sync();
    00982
    00983   readConfig();
    00984
    00985   mConfig->setGroup(origGroup);
    00986 }
    00987
    00988 void KConfigSkeleton::addItem( KConfigSkeletonItem *item, const QString &name )
    00989 {
    00990   item->setName( name.isEmpty() ? item->key() : name );
    00991   mItems.append( item );
    00992   mItemDict.insert( item->name(), item );
    00993   item->readDefault( mConfig );
    00994 }
    00995
    00996 KConfigSkeleton::ItemString *KConfigSkeleton::addItemString( const QString &name, QString &reference,
    00997                                      const QString &defaultValue, const QString &key )
    00998 {
    00999   KConfigSkeleton::ItemString *item;
    01000   item = new KConfigSkeleton::ItemString( mCurrentGroup, key.isEmpty() ? name : key,
    01001                                           reference, defaultValue,
    01002                                           KConfigSkeleton::ItemString::Normal );
    01003   addItem( item, name );
    01004   return item;
    01005 }
    01006
    01007 KConfigSkeleton::ItemPassword *KConfigSkeleton::addItemPassword( const QString &name, QString &reference,
    01008                                        const QString &defaultValue, const QString &key )
    01009 {
    01010   KConfigSkeleton::ItemPassword *item;
    01011   item = new KConfigSkeleton::ItemPassword( mCurrentGroup, key.isNull() ? name : key,
    01012                                           reference, defaultValue );
    01013   addItem( item, name );
    01014   return item;
    01015 }
    01016
    01017 KConfigSkeleton::ItemPath *KConfigSkeleton::addItemPath( const QString &name, QString &reference,
    01018                                    const QString &defaultValue, const QString &key )
    01019 {
    01020   KConfigSkeleton::ItemPath *item;
    01021   item = new KConfigSkeleton::ItemPath( mCurrentGroup, key.isNull() ? name : key,
    01022                                         reference, defaultValue );
    01023   addItem( item, name );
    01024   return item;
    01025 }
    01026
    01027 KConfigSkeleton::ItemProperty *KConfigSkeleton::addItemProperty( const QString &name, QVariant &reference,
    01028                                        const QVariant &defaultValue, const QString &key )
    01029 {
    01030   KConfigSkeleton::ItemProperty *item;
    01031   item = new KConfigSkeleton::ItemProperty( mCurrentGroup, key.isNull() ? name : key,
    01032                                             reference, defaultValue );
    01033   addItem( item, name );
    01034   return item;
    01035 }
    01036
    01037 KConfigSkeleton::ItemBool *KConfigSkeleton::addItemBool( const QString &name, bool &reference,
    01038                                    bool defaultValue, const QString &key )
    01039 {
    01040   KConfigSkeleton::ItemBool *item;
    01041   item = new KConfigSkeleton::ItemBool( mCurrentGroup, key.isNull() ? name : key,
    01042                                         reference, defaultValue );
    01043   addItem( item, name );
    01044   return item;
    01045 }
    01046
    01047 KConfigSkeleton::ItemInt *KConfigSkeleton::addItemInt( const QString &name, int &reference,
    01048                                   int defaultValue, const QString &key )
    01049 {
    01050   KConfigSkeleton::ItemInt *item;
    01051   item = new KConfigSkeleton::ItemInt( mCurrentGroup, key.isNull() ? name : key,
    01052                                        reference, defaultValue );
    01053   addItem( item, name );
    01054   return item;
    01055 }
    01056
    01057 KConfigSkeleton::ItemUInt *KConfigSkeleton::addItemUInt( const QString &name, unsigned int &reference,
    01058                                    unsigned int defaultValue, const QString &key )
    01059 {
    01060   KConfigSkeleton::ItemUInt *item;
    01061   item = new KConfigSkeleton::ItemUInt( mCurrentGroup, key.isNull() ? name : key,
    01062                                         reference, defaultValue );
    01063   addItem( item, name );
    01064   return item;
    01065 }
    01066
    01067 KConfigSkeleton::ItemInt64 *KConfigSkeleton::addItemInt64( const QString &name, Q_INT64 &reference,
    01068                                     Q_INT64 defaultValue, const QString &key )
    01069 {
    01070   KConfigSkeleton::ItemInt64 *item;
    01071   item = new KConfigSkeleton::ItemInt64( mCurrentGroup, key.isNull() ? name : key,
    01072                                          reference, defaultValue );
    01073   addItem( item, name );
    01074   return item;
    01075 }
    01076
    01077 KConfigSkeleton::ItemUInt64 *KConfigSkeleton::addItemUInt64( const QString &name, Q_UINT64 &reference,
    01078                                      Q_UINT64 defaultValue, const QString &key )
    01079 {
    01080   KConfigSkeleton::ItemUInt64 *item;
    01081   item = new KConfigSkeleton::ItemUInt64( mCurrentGroup, key.isNull() ? name : key,
    01082                                           reference, defaultValue );
    01083   addItem( item, name );
    01084   return item;
    01085 }
    01086
    01087 KConfigSkeleton::ItemLong *KConfigSkeleton::addItemLong( const QString &name, long &reference,
    01088                                    long defaultValue, const QString &key )
    01089 {
    01090   KConfigSkeleton::ItemLong *item;
    01091   item = new KConfigSkeleton::ItemLong( mCurrentGroup, key.isNull() ? name : key,
    01092                                         reference, defaultValue );
    01093   addItem( item, name );
    01094   return item;
    01095 }
    01096
    01097 KConfigSkeleton::ItemULong *KConfigSkeleton::addItemULong( const QString &name, unsigned long &reference,
    01098                                     unsigned long defaultValue, const QString &key )
    01099 {
    01100   KConfigSkeleton::ItemULong *item;
    01101   item = new KConfigSkeleton::ItemULong( mCurrentGroup, key.isNull() ? name : key,
    01102                                          reference, defaultValue );
    01103   addItem( item, name );
    01104   return item;
    01105 }
    01106
    01107 KConfigSkeleton::ItemDouble *KConfigSkeleton::addItemDouble( const QString &name, double &reference,
    01108                                      double defaultValue, const QString &key )
    01109 {
    01110   KConfigSkeleton::ItemDouble *item;
    01111   item = new KConfigSkeleton::ItemDouble( mCurrentGroup, key.isNull() ? name : key,
    01112                                           reference, defaultValue );
    01113   addItem( item, name );
    01114   return item;
    01115 }
    01116
    01117 KConfigSkeleton::ItemColor *KConfigSkeleton::addItemColor( const QString &name, QColor &reference,
    01118                                     const QColor &defaultValue, const QString &key )
    01119 {
    01120   KConfigSkeleton::ItemColor *item;
    01121   item = new KConfigSkeleton::ItemColor( mCurrentGroup, key.isNull() ? name : key,
    01122                                          reference, defaultValue );
    01123   addItem( item, name );
    01124   return item;
    01125 }
    01126
    01127 KConfigSkeleton::ItemFont *KConfigSkeleton::addItemFont( const QString &name, QFont &reference,
    01128                                    const QFont &defaultValue, const QString &key )
    01129 {
    01130   KConfigSkeleton::ItemFont *item;
    01131   item = new KConfigSkeleton::ItemFont( mCurrentGroup, key.isNull() ? name : key,
    01132                                         reference, defaultValue );
    01133   addItem( item, name );
    01134   return item;
    01135 }
    01136
    01137 KConfigSkeleton::ItemRect *KConfigSkeleton::addItemRect( const QString &name, QRect &reference,
    01138                                    const QRect &defaultValue, const QString &key )
    01139 {
    01140   KConfigSkeleton::ItemRect *item;
    01141   item = new KConfigSkeleton::ItemRect( mCurrentGroup, key.isNull() ? name : key,
    01142                                         reference, defaultValue );
    01143   addItem( item, name );
    01144   return item;
    01145 }
    01146
    01147 KConfigSkeleton::ItemPoint *KConfigSkeleton::addItemPoint( const QString &name, QPoint &reference,
    01148                                     const QPoint &defaultValue, const QString &key )
    01149 {
    01150   KConfigSkeleton::ItemPoint *item;
    01151   item = new KConfigSkeleton::ItemPoint( mCurrentGroup, key.isNull() ? name : key,
    01152                                          reference, defaultValue );
    01153   addItem( item, name );
    01154   return item;
    01155 }
    01156
    01157 KConfigSkeleton::ItemSize *KConfigSkeleton::addItemSize( const QString &name, QSize &reference,
    01158                                    const QSize &defaultValue, const QString &key )
    01159 {
    01160   KConfigSkeleton::ItemSize *item;
    01161   item = new KConfigSkeleton::ItemSize( mCurrentGroup, key.isNull() ? name : key,
    01162                                         reference, defaultValue );
    01163   addItem( item, name );
    01164   return item;
    01165 }
    01166
    01167 KConfigSkeleton::ItemDateTime *KConfigSkeleton::addItemDateTime( const QString &name, QDateTime &reference,
    01168                                        const QDateTime &defaultValue, const QString &key )
    01169 {
    01170   KConfigSkeleton::ItemDateTime *item;
    01171   item = new KConfigSkeleton::ItemDateTime( mCurrentGroup, key.isNull() ? name : key,
    01172                                             reference, defaultValue );
    01173   addItem( item, name );
    01174   return item;
    01175 }
    01176
    01177 KConfigSkeleton::ItemStringList *KConfigSkeleton::addItemStringList( const QString &name, QStringList &reference,
    01178                                          const QStringList &defaultValue, const QString &key )
    01179 {
    01180   KConfigSkeleton::ItemStringList *item;
    01181   item = new KConfigSkeleton::ItemStringList( mCurrentGroup, key.isNull() ? name : key,
    01182                                               reference, defaultValue );
    01183   addItem( item, name );
    01184   return item;
    01185 }
    01186
    01187 KConfigSkeleton::ItemIntList *KConfigSkeleton::addItemIntList( const QString &name, QValueList<int> &reference,
    01188                                       const QValueList<int> &defaultValue, const QString &key )
    01189 {
    01190   KConfigSkeleton::ItemIntList *item;
    01191   item = new KConfigSkeleton::ItemIntList( mCurrentGroup, key.isNull() ? name : key,
    01192                                            reference, defaultValue );
    01193   addItem( item, name );
    01194   return item;
    01195 }
    01196
    01197 bool KConfigSkeleton::isImmutable(const QString &name)
    01198 {
    01199   KConfigSkeletonItem *item = findItem(name);
    01200   return !item || item->isImmutable();
    01201 }
    01202
    01203 KConfigSkeletonItem *KConfigSkeleton::findItem(const QString &name)
    01204 {
    01205   return mItemDict.find(name);
    01206 }

This file is part of the documentation for kdecore Library Version 3.4.1.
Documentation copyright © 1996-2004 the KDE developers.
Generated on Sat Jun 11 20:18:03 2005 by doxygen 1.4.1 written by Dimitri van Heesch, © 1997-2003