kdecore Library API Documentation

kconfigbase.cpp

00001 // -*- c-basic-offset: 2 -*-
00002 /*
00003    This file is part of the KDE libraries
00004    Copyright (c) 1999 Preston Brown <pbrown@kde.org>
00005    Copyright (c) 1997 Matthias Kalle Dalheimer <kalle@kde.org>
00006 
00007    This library is free software; you can redistribute it and/or
00008    modify it under the terms of the GNU Library General Public
00009    License as published by the Free Software Foundation; either
00010    version 2 of the License, or (at your option) any later version.
00011 
00012    This library is distributed in the hope that it will be useful,
00013    but WITHOUT ANY WARRANTY; without even the implied warranty of
00014    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00015    Library General Public License for more details.
00016 
00017    You should have received a copy of the GNU Library General Public License
00018    along with this library; see the file COPYING.LIB.  If not, write to
00019    the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
00020    Boston, MA 02111-1307, USA.
00021 */
00022 
00023 #include <stdlib.h>
00024 #include <string.h>
00025 
00026 #include <qfile.h>
00027 #include <qtextstream.h>
00028 
00029 #include <kapplication.h>
00030 #include <kglobal.h>
00031 #include <klocale.h>
00032 #include <kcharsets.h>
00033 
00034 #include "kconfigbase.h"
00035 #include "kconfigbackend.h"
00036 #include "kdebug.h"
00037 #include "kstandarddirs.h"
00038 #undef Bool
00039 
00040 static bool isUtf8(const char *buf) {
00041   int i, n;
00042   register unsigned char c;
00043   bool gotone = false;
00044 
00045 #define F 0   /* character never appears in text */
00046 #define T 1   /* character appears in plain ASCII text */
00047 #define I 2   /* character appears in ISO-8859 text */
00048 #define X 3   /* character appears in non-ISO extended ASCII (Mac, IBM PC) */
00049 
00050   static const unsigned char text_chars[256] = {
00051   /*                  BEL BS HT LF    FF CR    */
00052         F, F, F, F, F, F, F, T, T, T, T, F, T, T, F, F,  /* 0x0X */
00053         /*                              ESC          */
00054         F, F, F, F, F, F, F, F, F, F, F, T, F, F, F, F,  /* 0x1X */
00055         T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T,  /* 0x2X */
00056         T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T,  /* 0x3X */
00057         T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T,  /* 0x4X */
00058         T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T,  /* 0x5X */
00059         T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T,  /* 0x6X */
00060         T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, F,  /* 0x7X */
00061         /*            NEL                            */
00062         X, X, X, X, X, T, X, X, X, X, X, X, X, X, X, X,  /* 0x8X */
00063         X, X, X, X, X, X, X, X, X, X, X, X, X, X, X, X,  /* 0x9X */
00064         I, I, I, I, I, I, I, I, I, I, I, I, I, I, I, I,  /* 0xaX */
00065         I, I, I, I, I, I, I, I, I, I, I, I, I, I, I, I,  /* 0xbX */
00066         I, I, I, I, I, I, I, I, I, I, I, I, I, I, I, I,  /* 0xcX */
00067         I, I, I, I, I, I, I, I, I, I, I, I, I, I, I, I,  /* 0xdX */
00068         I, I, I, I, I, I, I, I, I, I, I, I, I, I, I, I,  /* 0xeX */
00069         I, I, I, I, I, I, I, I, I, I, I, I, I, I, I, I   /* 0xfX */
00070   };
00071 
00072   /* *ulen = 0; */
00073   for (i = 0; (c = buf[i]); i++) {
00074     if ((c & 0x80) == 0) {        /* 0xxxxxxx is plain ASCII */
00075       /*
00076        * Even if the whole file is valid UTF-8 sequences,
00077        * still reject it if it uses weird control characters.
00078        */
00079 
00080       if (text_chars[c] != T)
00081         return false;
00082 
00083     } else if ((c & 0x40) == 0) { /* 10xxxxxx never 1st byte */
00084       return false;
00085     } else {                           /* 11xxxxxx begins UTF-8 */
00086       int following;
00087 
00088     if ((c & 0x20) == 0) {             /* 110xxxxx */
00089       following = 1;
00090     } else if ((c & 0x10) == 0) {      /* 1110xxxx */
00091       following = 2;
00092     } else if ((c & 0x08) == 0) {      /* 11110xxx */
00093       following = 3;
00094     } else if ((c & 0x04) == 0) {      /* 111110xx */
00095       following = 4;
00096     } else if ((c & 0x02) == 0) {      /* 1111110x */
00097       following = 5;
00098     } else
00099       return false;
00100 
00101       for (n = 0; n < following; n++) {
00102         i++;
00103         if (!(c = buf[i]))
00104           goto done;
00105 
00106         if ((c & 0x80) == 0 || (c & 0x40))
00107           return false;
00108       }
00109       gotone = true;
00110     }
00111   }
00112 done:
00113   return gotone;   /* don't claim it's UTF-8 if it's all 7-bit */
00114 }
00115 
00116 #undef F
00117 #undef T
00118 #undef I
00119 #undef X
00120 
00121 
00122 KConfigBase::KConfigBase()
00123   : backEnd(0L), bDirty(false), bLocaleInitialized(false),
00124     bReadOnly(false), bExpand(false)
00125 {
00126     setGroup(QString::null);
00127 }
00128 
00129 KConfigBase::~KConfigBase()
00130 {
00131 }
00132 
00133 void KConfigBase::setLocale()
00134 {
00135   bLocaleInitialized = true;
00136 
00137   if (KGlobal::locale())
00138     aLocaleString = KGlobal::locale()->language().utf8();
00139   else
00140     aLocaleString = KLocale::defaultLanguage().utf8();
00141   if (backEnd)
00142      backEnd->setLocaleString(aLocaleString);
00143 }
00144 
00145 QString KConfigBase::locale() const
00146 {
00147   return QString::fromUtf8(aLocaleString);
00148 }
00149 
00150 void KConfigBase::setGroup( const QString& group )
00151 {
00152   if ( group.isNull() )
00153     mGroup = "<default>";
00154   else
00155     mGroup = group.utf8();
00156 }
00157 
00158 void KConfigBase::setGroup( const char *pGroup )
00159 {
00160   setGroup(QCString(pGroup));
00161 }
00162 
00163 void KConfigBase::setGroup( const QCString &group )
00164 {
00165   if ( group.isEmpty() )
00166     mGroup = "<default>";
00167   else
00168     mGroup = group;
00169 }
00170 
00171 QString KConfigBase::group() const {
00172   return QString::fromUtf8(mGroup);
00173 }
00174 
00175 void KConfigBase::setDesktopGroup()
00176 {
00177   mGroup = "Desktop Entry";
00178 }
00179 
00180 bool KConfigBase::hasKey(const QString &key) const
00181 {
00182    return hasKey(key.utf8().data());
00183 }
00184 
00185 bool KConfigBase::hasKey(const char *pKey) const
00186 {
00187   KEntryKey aEntryKey(mGroup, 0);
00188   aEntryKey.c_key = pKey;
00189 
00190   if (!locale().isNull()) {
00191     // try the localized key first
00192     aEntryKey.bLocal = true;
00193     KEntry entry = lookupData(aEntryKey);
00194     if (!entry.mValue.isNull())
00195        return true;
00196     aEntryKey.bLocal = false;
00197   }
00198 
00199   // try the non-localized version
00200   KEntry entry = lookupData(aEntryKey);
00201   return !entry.mValue.isNull();
00202 }
00203 
00204 bool KConfigBase::hasGroup(const QString &group) const
00205 {
00206   return internalHasGroup( group.utf8());
00207 }
00208 
00209 bool KConfigBase::hasGroup(const char *_pGroup) const
00210 {
00211   return internalHasGroup( QCString(_pGroup));
00212 }
00213 
00214 bool KConfigBase::hasGroup(const QCString &_pGroup) const
00215 {
00216   return internalHasGroup( _pGroup);
00217 }
00218 
00219 bool KConfigBase::isImmutable() const
00220 {
00221   return (getConfigState() != ReadWrite);
00222 }
00223 
00224 bool KConfigBase::groupIsImmutable(const QString &group) const
00225 {
00226   if (getConfigState() != ReadWrite)
00227      return true;
00228 
00229   KEntryKey groupKey(group.utf8(), 0);
00230   KEntry entry = lookupData(groupKey);
00231   return entry.bImmutable;
00232 }
00233 
00234 bool KConfigBase::entryIsImmutable(const QString &key) const
00235 {
00236   if (getConfigState() != ReadWrite)
00237      return true;
00238 
00239   KEntryKey entryKey(mGroup, 0);
00240   KEntry aEntryData = lookupData(entryKey); // Group
00241   if (aEntryData.bImmutable)
00242     return true;
00243 
00244   entryKey.c_key = key.utf8().data();
00245   aEntryData = lookupData(entryKey); // Normal entry
00246   if (aEntryData.bImmutable)
00247     return true;
00248 
00249   entryKey.bLocal = true;
00250   aEntryData = lookupData(entryKey); // Localized entry
00251   return aEntryData.bImmutable;
00252 }
00253 
00254 
00255 QString KConfigBase::readEntryUntranslated( const QString& pKey,
00256                                 const QString& aDefault ) const
00257 {
00258    return KConfigBase::readEntryUntranslated(pKey.utf8().data(), aDefault);
00259 }
00260 
00261 
00262 QString KConfigBase::readEntryUntranslated( const char *pKey,
00263                                 const QString& aDefault ) const
00264 {
00265    QCString result = readEntryUtf8(pKey);
00266    if (result.isNull())
00267       return aDefault;
00268    return QString::fromUtf8(result);
00269 }
00270 
00271 
00272 QString KConfigBase::readEntry( const QString& pKey,
00273                                 const QString& aDefault ) const
00274 {
00275    return KConfigBase::readEntry(pKey.utf8().data(), aDefault);
00276 }
00277 
00278 QString KConfigBase::readEntry( const char *pKey,
00279                                 const QString& aDefault ) const
00280 {
00281   // we need to access _locale instead of the method locale()
00282   // because calling locale() will create a locale object if it
00283   // doesn't exist, which requires KConfig, which will create a infinite
00284   // loop, and nobody likes those.
00285   if (!bLocaleInitialized && KGlobal::_locale) {
00286     // get around const'ness.
00287     KConfigBase *that = const_cast<KConfigBase *>(this);
00288     that->setLocale();
00289   }
00290 
00291   QString aValue;
00292 
00293   bool expand = false;
00294   // construct a localized version of the key
00295   // try the localized key first
00296   KEntry aEntryData;
00297   KEntryKey entryKey(mGroup, 0);
00298   entryKey.c_key = pKey;
00299   entryKey.bLocal = true;
00300   aEntryData = lookupData(entryKey);
00301   if (!aEntryData.mValue.isNull()) {
00302 
00303     // for GNOME .desktop
00304     // const char *data = aEntryData.mValue.char();
00305     if ( isUtf8(aEntryData.mValue.data() ) )
00306       aValue = QString::fromUtf8( aEntryData.mValue.data() );
00307     else
00308       aValue = QString::fromLocal8Bit(aEntryData.mValue.data());
00309     expand = aEntryData.bExpand;
00310 
00311     // Ok this sucks. QString::fromUtf8("").isNull() is true,
00312     // but QString::fromLatin1("").isNull() returns false.
00313     if (aValue.isNull())
00314     {
00315       static const QString &emptyString = KGlobal::staticQString("");
00316       aValue = emptyString;
00317     }
00318   } else {
00319     entryKey.bLocal = false;
00320     aEntryData = lookupData(entryKey);
00321     if (!aEntryData.mValue.isNull()) {
00322       aValue = QString::fromUtf8(aEntryData.mValue.data());
00323       if (aValue.isNull())
00324       {
00325         static const QString &emptyString = KGlobal::staticQString("");
00326         aValue = emptyString;
00327       }
00328       expand = aEntryData.bExpand;
00329     } else {
00330       aValue = aDefault;
00331     }
00332   }
00333 
00334   // only do dollar expansion if so desired
00335   if( expand || bExpand )
00336     {
00337       // check for environment variables and make necessary translations
00338       int nDollarPos = aValue.find( '$' );
00339 
00340       while( nDollarPos != -1 && nDollarPos+1 < static_cast<int>(aValue.length())) {
00341         // there is at least one $
00342         if( (aValue)[nDollarPos+1] == '(' ) {
00343           uint nEndPos = nDollarPos+1;
00344           // the next character is no $
00345           while ( (nEndPos <= aValue.length()) && (aValue[nEndPos]!=')') )
00346               nEndPos++;
00347           nEndPos++;
00348           QString cmd = aValue.mid( nDollarPos+2, nEndPos-nDollarPos-3 );
00349 
00350           QString result;
00351           FILE *fs = popen(QFile::encodeName(cmd).data(), "r");
00352           if (fs)
00353           {
00354              QTextStream ts(fs, IO_ReadOnly);
00355              result = ts.read().stripWhiteSpace();
00356              pclose(fs);
00357           }
00358           aValue.replace( nDollarPos, nEndPos-nDollarPos, result );
00359         } else if( (aValue)[nDollarPos+1] != '$' ) {
00360           uint nEndPos = nDollarPos+1;
00361           // the next character is no $
00362           QString aVarName;
00363           if (aValue[nEndPos]=='{')
00364           {
00365             while ( (nEndPos <= aValue.length()) && (aValue[nEndPos]!='}') )
00366                 nEndPos++;
00367             nEndPos++;
00368             aVarName = aValue.mid( nDollarPos+2, nEndPos-nDollarPos-3 );
00369           }
00370           else
00371           {
00372             while ( nEndPos <= aValue.length() && (aValue[nEndPos].isNumber()
00373                     || aValue[nEndPos].isLetter() || aValue[nEndPos]=='_' )  )
00374                 nEndPos++;
00375             aVarName = aValue.mid( nDollarPos+1, nEndPos-nDollarPos-1 );
00376           }
00377           const char* pEnv = 0;
00378           if (!aVarName.isEmpty())
00379                pEnv = getenv( aVarName.ascii() );
00380           if( pEnv ) {
00381         // !!! Sergey A. Sukiyazov <corwin@micom.don.ru> !!!
00382         // A environment variables may contain values in 8bit
00383         // locale cpecified encoding or in UTF8 encoding.
00384         if (isUtf8( pEnv ))
00385         aValue.replace( nDollarPos, nEndPos-nDollarPos, QString::fromUtf8(pEnv) );
00386         else
00387         aValue.replace( nDollarPos, nEndPos-nDollarPos, QString::fromLocal8Bit(pEnv) );
00388           } else
00389             aValue.remove( nDollarPos, nEndPos-nDollarPos );
00390         } else {
00391           // remove one of the dollar signs
00392           aValue.remove( nDollarPos, 1 );
00393           nDollarPos++;
00394         }
00395         nDollarPos = aValue.find( '$', nDollarPos );
00396       }
00397     }
00398 
00399   return aValue;
00400 }
00401 
00402 QCString KConfigBase::readEntryUtf8( const char *pKey) const
00403 {
00404   // We don't try the localized key
00405   KEntryKey entryKey(mGroup, 0);
00406   entryKey.c_key = pKey;
00407   KEntry aEntryData = lookupData(entryKey);
00408   if (aEntryData.bExpand)
00409   {
00410      // We need to do fancy, take the slow route.
00411      return readEntry(pKey, QString::null).utf8();
00412   }
00413   return aEntryData.mValue;
00414 }
00415 
00416 QVariant KConfigBase::readPropertyEntry( const QString& pKey,
00417                                           QVariant::Type type ) const
00418 {
00419   return readPropertyEntry(pKey.utf8().data(), type);
00420 }
00421 
00422 QVariant KConfigBase::readPropertyEntry( const char *pKey,
00423                                           QVariant::Type type ) const
00424 {
00425   QVariant va;
00426   if ( !hasKey( pKey ) ) return va;
00427   (void)va.cast(type);
00428   return readPropertyEntry(pKey, va);
00429 }
00430 
00431 QVariant KConfigBase::readPropertyEntry( const QString& pKey,
00432                                          const QVariant &aDefault ) const
00433 {
00434   return readPropertyEntry(pKey.utf8().data(), aDefault);
00435 }
00436 
00437 QVariant KConfigBase::readPropertyEntry( const char *pKey,
00438                                          const QVariant &aDefault ) const
00439 {
00440   if ( !hasKey( pKey ) ) return aDefault;
00441 
00442   QVariant tmp = aDefault;
00443 
00444   switch( aDefault.type() )
00445   {
00446       case QVariant::Invalid:
00447           return QVariant();
00448       case QVariant::String:
00449           return QVariant( readEntry( pKey, aDefault.toString() ) );
00450       case QVariant::StringList:
00451           return QVariant( readListEntry( pKey ) );
00452       case QVariant::List: {
00453           QStringList strList = readListEntry( pKey );
00454           QStringList::ConstIterator it = strList.begin();
00455           QStringList::ConstIterator end = strList.end();
00456           QValueList<QVariant> list;
00457 
00458           for (; it != end; ++it ) {
00459               tmp = *it;
00460               list.append( tmp );
00461           }
00462           return QVariant( list );
00463       }
00464       case QVariant::Font:
00465           return QVariant( readFontEntry( pKey, &tmp.asFont() ) );
00466       case QVariant::Point:
00467           return QVariant( readPointEntry( pKey, &tmp.asPoint() ) );
00468       case QVariant::Rect:
00469           return QVariant( readRectEntry( pKey, &tmp.asRect() ) );
00470       case QVariant::Size:
00471           return QVariant( readSizeEntry( pKey, &tmp.asSize() ) );
00472       case QVariant::Color:
00473           return QVariant( readColorEntry( pKey, &tmp.asColor() ) );
00474       case QVariant::Int:
00475           return QVariant( readNumEntry( pKey, aDefault.toInt() ) );
00476       case QVariant::UInt:
00477           return QVariant( readUnsignedNumEntry( pKey, aDefault.toUInt() ) );
00478       case QVariant::Bool:
00479           return QVariant( readBoolEntry( pKey, aDefault.toBool() ), 0 );
00480       case QVariant::Double:
00481           return QVariant( readDoubleNumEntry( pKey, aDefault.toDouble() ) );
00482       case QVariant::DateTime:
00483           return QVariant( readDateTimeEntry( pKey, &tmp.asDateTime() ) );
00484       case QVariant::Date:
00485           return QVariant(readDateTimeEntry( pKey, &tmp.asDateTime() ).date());
00486 
00487       case QVariant::Pixmap:
00488       case QVariant::Image:
00489       case QVariant::Brush:
00490       case QVariant::Palette:
00491       case QVariant::ColorGroup:
00492       case QVariant::Map:
00493       case QVariant::IconSet:
00494       case QVariant::CString:
00495       case QVariant::PointArray:
00496       case QVariant::Region:
00497       case QVariant::Bitmap:
00498       case QVariant::Cursor:
00499       case QVariant::SizePolicy:
00500       case QVariant::Time:
00501       case QVariant::ByteArray:
00502       case QVariant::BitArray:
00503       case QVariant::KeySequence:
00504       case QVariant::Pen:
00505           break;
00506   }
00507 
00508   Q_ASSERT( 0 );
00509   return QVariant();
00510 }
00511 
00512 int KConfigBase::readListEntry( const QString& pKey,
00513                                 QStrList &list, char sep ) const
00514 {
00515   return readListEntry(pKey.utf8().data(), list, sep);
00516 }
00517 
00518 int KConfigBase::readListEntry( const char *pKey,
00519                                 QStrList &list, char sep ) const
00520 {
00521   if( !hasKey( pKey ) )
00522     return 0;
00523 
00524   QCString str_list = readEntryUtf8( pKey );
00525   if (str_list.isEmpty())
00526     return 0;
00527 
00528   list.clear();
00529   QCString value = "";
00530   int len = str_list.length();
00531 
00532   for (int i = 0; i < len; i++) {
00533     if (str_list[i] != sep && str_list[i] != '\\') {
00534       value += str_list[i];
00535       continue;
00536     }
00537     if (str_list[i] == '\\') {
00538       i++;
00539       value += str_list[i];
00540       continue;
00541     }
00542     // if we fell through to here, we are at a separator.  Append
00543     // contents of value to the list
00544     // !!! Sergey A. Sukiyazov <corwin@micom.don.ru> !!!
00545     // A QStrList may contain values in 8bit locale cpecified
00546     // encoding
00547     list.append( value );
00548     value.truncate(0);
00549   }
00550 
00551   if ( str_list[len-1] != sep || ( len > 1 && str_list[len-2] == '\\' ) )
00552     list.append( value );
00553   return list.count();
00554 }
00555 
00556 QStringList KConfigBase::readListEntry( const QString& pKey, char sep ) const
00557 {
00558   return readListEntry(pKey.utf8().data(), sep);
00559 }
00560 
00561 QStringList KConfigBase::readListEntry( const char *pKey, char sep ) const
00562 {
00563   QStringList list;
00564   if( !hasKey( pKey ) )
00565     return list;
00566   QString str_list = readEntry( pKey );
00567   if( str_list.isEmpty() )
00568     return list;
00569   QString value = "";
00570   int len = str_list.length();
00571   for( int i = 0; i < len; i++ )
00572     {
00573       if( str_list[i] != sep && str_list[i] != '\\' )
00574         {
00575           value += str_list[i];
00576           continue;
00577         }
00578       if( str_list[i] == '\\' )
00579         {
00580           i++;
00581           value += str_list[i];
00582           continue;
00583         }
00584       list.append( value );
00585       value.truncate(0);
00586     }
00587   if ( str_list[len-1] != sep || ( len > 1 && str_list[len-2] == '\\' ) )
00588     list.append( value );
00589   return list;
00590 }
00591 
00592 QValueList<int> KConfigBase::readIntListEntry( const QString& pKey ) const
00593 {
00594   return readIntListEntry(pKey.utf8().data());
00595 }
00596 
00597 QValueList<int> KConfigBase::readIntListEntry( const char *pKey ) const
00598 {
00599   QStringList strlist = readListEntry(pKey);
00600   QValueList<int> list;
00601   for (QStringList::ConstIterator it = strlist.begin(); it != strlist.end(); it++)
00602     // I do not check if the toInt failed because I consider the number of items
00603     // more important than their value
00604     list << (*it).toInt();
00605 
00606   return list;
00607 }
00608 
00609 QString KConfigBase::readPathEntry( const QString& pKey, const QString& pDefault ) const
00610 {
00611   return readPathEntry(pKey.utf8().data(), pDefault);
00612 }
00613 
00614 QString KConfigBase::readPathEntry( const char *pKey, const QString& pDefault ) const
00615 {
00616   const bool bExpandSave = bExpand;
00617   bExpand = true;
00618   QString aValue = readEntry( pKey, pDefault );
00619   bExpand = bExpandSave;
00620   return aValue;
00621 }
00622 
00623 int KConfigBase::readNumEntry( const QString& pKey, int nDefault) const
00624 {
00625   return readNumEntry(pKey.utf8().data(), nDefault);
00626 }
00627 
00628 int KConfigBase::readNumEntry( const char *pKey, int nDefault) const
00629 {
00630   QCString aValue = readEntryUtf8( pKey );
00631   if( aValue.isNull() )
00632     return nDefault;
00633   else if( aValue == "true" || aValue == "on" || aValue == "yes" )
00634     return 1;
00635   else
00636     {
00637       bool ok;
00638       int rc = aValue.toInt( &ok );
00639       return( ok ? rc : nDefault );
00640     }
00641 }
00642 
00643 
00644 unsigned int KConfigBase::readUnsignedNumEntry( const QString& pKey, unsigned int nDefault) const
00645 {
00646   return readUnsignedNumEntry(pKey.utf8().data(), nDefault);
00647 }
00648 
00649 unsigned int KConfigBase::readUnsignedNumEntry( const char *pKey, unsigned int nDefault) const
00650 {
00651   QCString aValue = readEntryUtf8( pKey );
00652   if( aValue.isNull() )
00653     return nDefault;
00654   else
00655     {
00656       bool ok;
00657       unsigned int rc = aValue.toUInt( &ok );
00658       return( ok ? rc : nDefault );
00659     }
00660 }
00661 
00662 
00663 long KConfigBase::readLongNumEntry( const QString& pKey, long nDefault) const
00664 {
00665   return readLongNumEntry(pKey.utf8().data(), nDefault);
00666 }
00667 
00668 long KConfigBase::readLongNumEntry( const char *pKey, long nDefault) const
00669 {
00670   QCString aValue = readEntryUtf8( pKey );
00671   if( aValue.isNull() )
00672     return nDefault;
00673   else
00674     {
00675       bool ok;
00676       long rc = aValue.toLong( &ok );
00677       return( ok ? rc : nDefault );
00678     }
00679 }
00680 
00681 
00682 unsigned long KConfigBase::readUnsignedLongNumEntry( const QString& pKey, unsigned long nDefault) const
00683 {
00684   return readUnsignedLongNumEntry(pKey.utf8().data(), nDefault);
00685 }
00686 
00687 unsigned long KConfigBase::readUnsignedLongNumEntry( const char *pKey, unsigned long nDefault) const
00688 {
00689   QCString aValue = readEntryUtf8( pKey );
00690   if( aValue.isNull() )
00691     return nDefault;
00692   else
00693     {
00694       bool ok;
00695       unsigned long rc = aValue.toULong( &ok );
00696       return( ok ? rc : nDefault );
00697     }
00698 }
00699 
00700 double KConfigBase::readDoubleNumEntry( const QString& pKey, double nDefault) const
00701 {
00702   return readDoubleNumEntry(pKey.utf8().data(), nDefault);
00703 }
00704 
00705 double KConfigBase::readDoubleNumEntry( const char *pKey, double nDefault) const
00706 {
00707   QCString aValue = readEntryUtf8( pKey );
00708   if( aValue.isNull() )
00709     return nDefault;
00710   else
00711     {
00712       bool ok;
00713       double rc = aValue.toDouble( &ok );
00714       return( ok ? rc : nDefault );
00715     }
00716 }
00717 
00718 
00719 bool KConfigBase::readBoolEntry( const QString& pKey, const bool bDefault ) const
00720 {
00721    return readBoolEntry(pKey.utf8().data(), bDefault);
00722 }
00723 
00724 bool KConfigBase::readBoolEntry( const char *pKey, const bool bDefault ) const
00725 {
00726   QCString aValue = readEntryUtf8( pKey );
00727 
00728   if( aValue.isNull() )
00729     return bDefault;
00730   else
00731     {
00732       if( aValue == "true" || aValue == "on" || aValue == "yes" || aValue == "1" )
00733         return true;
00734       else
00735         {
00736           bool bOK;
00737           int val = aValue.toInt( &bOK );
00738           if( bOK && val != 0 )
00739             return true;
00740           else
00741             return false;
00742         }
00743     }
00744 }
00745 
00746 QFont KConfigBase::readFontEntry( const QString& pKey, const QFont* pDefault ) const
00747 {
00748   return readFontEntry(pKey.utf8().data(), pDefault);
00749 }
00750 
00751 QFont KConfigBase::readFontEntry( const char *pKey, const QFont* pDefault ) const
00752 {
00753   QFont aRetFont;
00754 
00755   QString aValue = readEntry( pKey );
00756   if( !aValue.isNull() ) {
00757     if ( aValue.contains( ',' ) > 5 ) {
00758       // KDE3 and upwards entry
00759       if ( !aRetFont.fromString( aValue ) && pDefault )
00760         aRetFont = *pDefault;
00761     }
00762     else {
00763       // backward compatibility with older font formats
00764       // ### remove KDE 3.1 ?
00765       // find first part (font family)
00766       int nIndex = aValue.find( ',' );
00767       if( nIndex == -1 ){
00768         if( pDefault )
00769           aRetFont = *pDefault;
00770         return aRetFont;
00771       }
00772       aRetFont.setFamily( aValue.left( nIndex ) );
00773 
00774       // find second part (point size)
00775       int nOldIndex = nIndex;
00776       nIndex = aValue.find( ',', nOldIndex+1 );
00777       if( nIndex == -1 ){
00778         if( pDefault )
00779           aRetFont = *pDefault;
00780         return aRetFont;
00781       }
00782 
00783       aRetFont.setPointSize( aValue.mid( nOldIndex+1,
00784                                          nIndex-nOldIndex-1 ).toInt() );
00785 
00786       // find third part (style hint)
00787       nOldIndex = nIndex;
00788       nIndex = aValue.find( ',', nOldIndex+1 );
00789 
00790       if( nIndex == -1 ){
00791         if( pDefault )
00792           aRetFont = *pDefault;
00793         return aRetFont;
00794       }
00795 
00796       aRetFont.setStyleHint( (QFont::StyleHint)aValue.mid( nOldIndex+1, nIndex-nOldIndex-1 ).toUInt() );
00797 
00798       // find fourth part (char set)
00799       nOldIndex = nIndex;
00800       nIndex = aValue.find( ',', nOldIndex+1 );
00801 
00802       if( nIndex == -1 ){
00803         if( pDefault )
00804           aRetFont = *pDefault;
00805         return aRetFont;
00806       }
00807 
00808       QString chStr=aValue.mid( nOldIndex+1,
00809                                 nIndex-nOldIndex-1 );
00810       // find fifth part (weight)
00811       nOldIndex = nIndex;
00812       nIndex = aValue.find( ',', nOldIndex+1 );
00813 
00814       if( nIndex == -1 ){
00815         if( pDefault )
00816           aRetFont = *pDefault;
00817         return aRetFont;
00818       }
00819 
00820       aRetFont.setWeight( aValue.mid( nOldIndex+1,
00821                                       nIndex-nOldIndex-1 ).toUInt() );
00822 
00823       // find sixth part (font bits)
00824       uint nFontBits = aValue.right( aValue.length()-nIndex-1 ).toUInt();
00825 
00826       aRetFont.setItalic( nFontBits & 0x01 );
00827       aRetFont.setUnderline( nFontBits & 0x02 );
00828       aRetFont.setStrikeOut( nFontBits & 0x04 );
00829       aRetFont.setFixedPitch( nFontBits & 0x08 );
00830       aRetFont.setRawMode( nFontBits & 0x20 );
00831     }
00832   }
00833   else
00834     {
00835       if( pDefault )
00836         aRetFont = *pDefault;
00837     }
00838 
00839   return aRetFont;
00840 }
00841 
00842 
00843 QRect KConfigBase::readRectEntry( const QString& pKey, const QRect* pDefault ) const
00844 {
00845   return readRectEntry(pKey.utf8().data(), pDefault);
00846 }
00847 
00848 QRect KConfigBase::readRectEntry( const char *pKey, const QRect* pDefault ) const
00849 {
00850   QCString aValue = readEntryUtf8(pKey);
00851 
00852   if (!aValue.isEmpty())
00853   {
00854     int left, top, width, height;
00855 
00856     if (sscanf(aValue.data(), "%d,%d,%d,%d", &left, &top, &width, &height) == 4)
00857     {
00858        return QRect(left, top, width, height);
00859     }
00860   }
00861   if (pDefault)
00862     return *pDefault;
00863   return QRect();
00864 }
00865 
00866 
00867 QPoint KConfigBase::readPointEntry( const QString& pKey,
00868                                     const QPoint* pDefault ) const
00869 {
00870   return readPointEntry(pKey.utf8().data(), pDefault);
00871 }
00872 
00873 QPoint KConfigBase::readPointEntry( const char *pKey,
00874                                     const QPoint* pDefault ) const
00875 {
00876   QCString aValue = readEntryUtf8(pKey);
00877 
00878   if (!aValue.isEmpty())
00879   {
00880     int x,y;
00881 
00882     if (sscanf(aValue.data(), "%d,%d", &x, &y) == 2)
00883     {
00884        return QPoint(x,y);
00885     }
00886   }
00887   if (pDefault)
00888     return *pDefault;
00889   return QPoint();
00890 }
00891 
00892 QSize KConfigBase::readSizeEntry( const QString& pKey,
00893                                   const QSize* pDefault ) const
00894 {
00895   return readSizeEntry(pKey.utf8().data(), pDefault);
00896 }
00897 
00898 QSize KConfigBase::readSizeEntry( const char *pKey,
00899                                   const QSize* pDefault ) const
00900 {
00901   QCString aValue = readEntryUtf8(pKey);
00902 
00903   if (!aValue.isEmpty())
00904   {
00905     int width,height;
00906 
00907     if (sscanf(aValue.data(), "%d,%d", &width, &height) == 2)
00908     {
00909        return QSize(width, height);
00910     }
00911   }
00912   if (pDefault)
00913     return *pDefault;
00914   return QSize();
00915 }
00916 
00917 
00918 QColor KConfigBase::readColorEntry( const QString& pKey,
00919                                     const QColor* pDefault ) const
00920 {
00921   return readColorEntry(pKey.utf8().data(), pDefault);
00922 }
00923 
00924 QColor KConfigBase::readColorEntry( const char *pKey,
00925                                     const QColor* pDefault ) const
00926 {
00927   QColor aRetColor;
00928   int nRed = 0, nGreen = 0, nBlue = 0;
00929 
00930   QString aValue = readEntry( pKey );
00931   if( !aValue.isEmpty() )
00932     {
00933       if ( aValue.at(0) == '#' )
00934         {
00935           aRetColor.setNamedColor(aValue);
00936         }
00937       else
00938         {
00939 
00940           bool bOK;
00941 
00942           // find first part (red)
00943           int nIndex = aValue.find( ',' );
00944 
00945           if( nIndex == -1 ){
00946             // return a sensible default -- Bernd
00947             if( pDefault )
00948               aRetColor = *pDefault;
00949             return aRetColor;
00950           }
00951 
00952           nRed = aValue.left( nIndex ).toInt( &bOK );
00953 
00954           // find second part (green)
00955           int nOldIndex = nIndex;
00956           nIndex = aValue.find( ',', nOldIndex+1 );
00957 
00958           if( nIndex == -1 ){
00959             // return a sensible default -- Bernd
00960             if( pDefault )
00961               aRetColor = *pDefault;
00962             return aRetColor;
00963           }
00964           nGreen = aValue.mid( nOldIndex+1,
00965                                nIndex-nOldIndex-1 ).toInt( &bOK );
00966 
00967           // find third part (blue)
00968           nBlue = aValue.right( aValue.length()-nIndex-1 ).toInt( &bOK );
00969 
00970           aRetColor.setRgb( nRed, nGreen, nBlue );
00971         }
00972     }
00973   else {
00974 
00975     if( pDefault )
00976       aRetColor = *pDefault;
00977   }
00978 
00979   return aRetColor;
00980 }
00981 
00982 
00983 QDateTime KConfigBase::readDateTimeEntry( const QString& pKey,
00984                                           const QDateTime* pDefault ) const
00985 {
00986   return readDateTimeEntry(pKey.utf8().data(), pDefault);
00987 }
00988 
00989 // ### currentDateTime() as fallback ? (Harri)
00990 QDateTime KConfigBase::readDateTimeEntry( const char *pKey,
00991                                           const QDateTime* pDefault ) const
00992 {
00993   if( !hasKey( pKey ) )
00994     {
00995       if( pDefault )
00996         return *pDefault;
00997       else
00998         return QDateTime::currentDateTime();
00999     }
01000 
01001   QStrList list;
01002   int count = readListEntry( pKey, list, ',' );
01003   if( count == 6 ) {
01004     QDate date( atoi( list.at( 0 ) ), atoi( list.at( 1 ) ),
01005                 atoi( list.at( 2 ) ) );
01006     QTime time( atoi( list.at( 3 ) ), atoi( list.at( 4 ) ),
01007                 atoi( list.at( 5 ) ) );
01008 
01009     return QDateTime( date, time );
01010   }
01011 
01012   return QDateTime::currentDateTime();
01013 }
01014 
01015 void KConfigBase::writeEntry( const QString& pKey, const QString& value,
01016                                  bool bPersistent,
01017                                  bool bGlobal,
01018                                  bool bNLS )
01019 {
01020    writeEntry(pKey.utf8().data(), value, bPersistent,  bGlobal, bNLS);
01021 }
01022 
01023 void KConfigBase::writeEntry( const char *pKey, const QString& value,
01024                                  bool bPersistent,
01025                                  bool bGlobal,
01026                                  bool bNLS )
01027 {
01028   // the KConfig object is dirty now
01029   // set this before any IO takes place so that if any derivative
01030   // classes do caching, they won't try and flush the cache out
01031   // from under us before we read. A race condition is still
01032   // possible but minimized.
01033   if( bPersistent )
01034     setDirty(true);
01035 
01036   if (!bLocaleInitialized && KGlobal::locale())
01037     setLocale();
01038 
01039   KEntryKey entryKey(mGroup, pKey);
01040   entryKey.bLocal = bNLS;
01041 
01042   KEntry aEntryData;
01043   aEntryData.mValue = value.utf8();  // set new value
01044   aEntryData.bGlobal = bGlobal;
01045   aEntryData.bNLS = bNLS;
01046 
01047   if (bPersistent)
01048     aEntryData.bDirty = true;
01049 
01050   // rewrite the new value
01051   putData(entryKey, aEntryData, true);
01052 }
01053 
01054 void KConfigBase::writePathEntry( const QString& pKey, const QString & path,
01055                                   bool bPersistent, bool bGlobal,
01056                                   bool bNLS)
01057 {
01058    writePathEntry(pKey.utf8().data(), path, bPersistent, bGlobal, bNLS);
01059 }
01060 
01061 void KConfigBase::writePathEntry( const char *pKey, const QString & path,
01062                                   bool bPersistent, bool bGlobal,
01063                                   bool bNLS)
01064 {
01065    QString value;
01066    if (!path.isEmpty())
01067    {
01068       value = KGlobal::dirs()->relativeLocation("home", path);
01069       if (value[0] != '/')
01070          value = "$HOME/"+value;
01071    }
01072    writeEntry(pKey, value, bPersistent, bGlobal, bNLS);
01073 }
01074 
01075 
01076 void KConfigBase::deleteEntry( const QString& pKey,
01077                                  bool bNLS,
01078                                  bool bGlobal)
01079 {
01080    deleteEntry(pKey.utf8().data(), bNLS, bGlobal);
01081 }
01082 
01083 void KConfigBase::deleteEntry( const char *pKey,
01084                                  bool bNLS,
01085                                  bool bGlobal)
01086 {
01087   // the KConfig object is dirty now
01088   // set this before any IO takes place so that if any derivative
01089   // classes do caching, they won't try and flush the cache out
01090   // from under us before we read. A race condition is still
01091   // possible but minimized.
01092   setDirty(true);
01093 
01094   if (!bLocaleInitialized && KGlobal::locale())
01095     setLocale();
01096 
01097   KEntryKey entryKey(mGroup, pKey);
01098   KEntry aEntryData;
01099 
01100   aEntryData.bGlobal = bGlobal;
01101   aEntryData.bNLS = bNLS;
01102   aEntryData.bDirty = true;
01103   aEntryData.bDeleted = true;
01104 
01105   // rewrite the new value
01106   putData(entryKey, aEntryData, true);
01107 }
01108 
01109 bool KConfigBase::deleteGroup( const QString& group, bool bDeep, bool bGlobal )
01110 {
01111   KEntryMap aEntryMap = internalEntryMap(group);
01112 
01113   if (!bDeep) {
01114     // Check if it empty
01115     return aEntryMap.isEmpty();
01116   }
01117 
01118   bool dirty = false;
01119   bool checkGroup = true;
01120   // we want to remove all entries in the group
01121   KEntryMapIterator aIt;
01122   for (aIt = aEntryMap.begin(); aIt != aEntryMap.end(); ++aIt)
01123   {
01124     if (!aIt.key().mKey.isEmpty() && !aIt.key().bDefault && !(*aIt).bDeleted)
01125     {
01126       (*aIt).bDeleted = true;
01127       (*aIt).bDirty = true;
01128       (*aIt).bGlobal = bGlobal;
01129       (*aIt).mValue = 0;
01130       putData(aIt.key(), *aIt, checkGroup);
01131       checkGroup = false;
01132       dirty = true;
01133     }
01134   }
01135   if (dirty)
01136      setDirty(true);
01137   return true;
01138 }
01139 
01140 void KConfigBase::writeEntry ( const QString& pKey, const QVariant &prop,
01141                                bool bPersistent,
01142                                bool bGlobal, bool bNLS )
01143 {
01144   writeEntry(pKey.utf8().data(), prop, bPersistent, bGlobal, bNLS);
01145 }
01146 
01147 void KConfigBase::writeEntry ( const char *pKey, const QVariant &prop,
01148                                bool bPersistent,
01149                                bool bGlobal, bool bNLS )
01150 {
01151   switch( prop.type() )
01152     {
01153     case QVariant::Invalid:
01154       writeEntry( pKey, "", bPersistent, bGlobal, bNLS );
01155       return;
01156     case QVariant::String:
01157       writeEntry( pKey, prop.toString(), bPersistent, bGlobal, bNLS );
01158       return;
01159     case QVariant::StringList:
01160       writeEntry( pKey, prop.toStringList(), ',', bPersistent, bGlobal, bNLS );
01161       return;
01162     case QVariant::List: {
01163         QValueList<QVariant> list = prop.toList();
01164         QValueList<QVariant>::ConstIterator it = list.begin();
01165         QValueList<QVariant>::ConstIterator end = list.end();
01166         QStringList strList;
01167 
01168         for (; it != end; ++it )
01169             strList.append( (*it).toString() );
01170 
01171         writeEntry( pKey, strList, ',', bPersistent, bGlobal, bNLS );
01172 
01173         return;
01174     }
01175     case QVariant::Font:
01176       writeEntry( pKey, prop.toFont(), bPersistent, bGlobal, bNLS );
01177       return;
01178     case QVariant::Point:
01179       writeEntry( pKey, prop.toPoint(), bPersistent, bGlobal, bNLS );
01180       return;
01181     case QVariant::Rect:
01182       writeEntry( pKey, prop.toRect(), bPersistent, bGlobal, bNLS );
01183       return;
01184     case QVariant::Size:
01185       writeEntry( pKey, prop.toSize(), bPersistent, bGlobal, bNLS );
01186       return;
01187     case QVariant::Color:
01188       writeEntry( pKey, prop.toColor(), bPersistent, bGlobal, bNLS );
01189       return;
01190     case QVariant::Int:
01191       writeEntry( pKey, prop.toInt(), bPersistent, bGlobal, bNLS );
01192       return;
01193     case QVariant::UInt:
01194       writeEntry( pKey, prop.toUInt(), bPersistent, bGlobal, bNLS );
01195       return;
01196     case QVariant::Bool:
01197       writeEntry( pKey, prop.toBool(), bPersistent, bGlobal, bNLS );
01198       return;
01199     case QVariant::Double:
01200       writeEntry( pKey, prop.toDouble(), bPersistent, bGlobal, 'g', 6, bNLS );
01201       return;
01202     case QVariant::DateTime:
01203       writeEntry( pKey, prop.toDateTime(), bPersistent, bGlobal, bNLS);
01204       return;
01205     case QVariant::Date:
01206       writeEntry( pKey, QDateTime(prop.toDate()), bPersistent, bGlobal, bNLS);
01207       return;
01208 
01209     case QVariant::Pixmap:
01210     case QVariant::Image:
01211     case QVariant::Brush:
01212     case QVariant::Palette:
01213     case QVariant::ColorGroup:
01214     case QVariant::Map:
01215     case QVariant::IconSet:
01216     case QVariant::CString:
01217     case QVariant::PointArray:
01218     case QVariant::Region:
01219     case QVariant::Bitmap:
01220     case QVariant::Cursor:
01221     case QVariant::SizePolicy:
01222     case QVariant::Time:
01223     case QVariant::ByteArray:
01224     case QVariant::BitArray:
01225     case QVariant::KeySequence:
01226     case QVariant::Pen:
01227         break;
01228     }
01229 
01230   Q_ASSERT( 0 );
01231 }
01232 
01233 void KConfigBase::writeEntry ( const QString& pKey, const QStrList &list,
01234                                char sep , bool bPersistent,
01235                                bool bGlobal, bool bNLS )
01236 {
01237   writeEntry(pKey.utf8().data(), list, sep, bPersistent, bGlobal, bNLS);
01238 }
01239 
01240 void KConfigBase::writeEntry ( const char *pKey, const QStrList &list,
01241                                char sep , bool bPersistent,
01242                                bool bGlobal, bool bNLS )
01243 {
01244   if( list.isEmpty() )
01245     {
01246       writeEntry( pKey, QString::fromLatin1(""), bPersistent );
01247       return;
01248     }
01249   QString str_list;
01250   QStrListIterator it( list );
01251   for( ; it.current(); ++it )
01252     {
01253       uint i;
01254       QString value;
01255       // !!! Sergey A. Sukiyazov <corwin@micom.don.ru> !!!
01256       // A QStrList may contain values in 8bit locale cpecified
01257       // encoding or in UTF8 encoding.
01258       if (isUtf8(it.current()))
01259         value = QString::fromUtf8(it.current());
01260       else
01261         value = QString::fromLocal8Bit(it.current());
01262       for( i = 0; i < value.length(); i++ )
01263         {
01264           if( value[i] == sep || value[i] == '\\' )
01265             str_list += '\\';
01266           str_list += value[i];
01267         }
01268       str_list += sep;
01269     }
01270   if( str_list.at(str_list.length() - 1) == sep )
01271     str_list.truncate( str_list.length() -1 );
01272   writeEntry( pKey, str_list, bPersistent, bGlobal, bNLS );
01273 }
01274 
01275 void KConfigBase::writeEntry ( const QString& pKey, const QStringList &list,
01276                                char sep , bool bPersistent,
01277                                bool bGlobal, bool bNLS )
01278 {
01279   writeEntry(pKey.utf8().data(), list, sep, bPersistent, bGlobal, bNLS);
01280 }
01281 
01282 void KConfigBase::writeEntry ( const char *pKey, const QStringList &list,
01283                                char sep , bool bPersistent,
01284                                bool bGlobal, bool bNLS )
01285 {
01286   if( list.isEmpty() )
01287     {
01288       writeEntry( pKey, QString::fromLatin1(""), bPersistent );
01289       return;
01290     }
01291   QString str_list;
01292   QStringList::ConstIterator it = list.begin();
01293   for( ; it != list.end(); ++it )
01294     {
01295       QString value = *it;
01296       uint i;
01297       for( i = 0; i < value.length(); i++ )
01298         {
01299           if( value[i] == sep || value[i] == '\\' )
01300             str_list += '\\';
01301           str_list += value[i];
01302         }
01303       str_list += sep;
01304     }
01305   if( str_list.at(str_list.length() - 1) == sep )
01306     str_list.truncate( str_list.length() -1 );
01307   writeEntry( pKey, str_list, bPersistent, bGlobal, bNLS );
01308 }
01309 
01310 void KConfigBase::writeEntry ( const QString& pKey, const QValueList<int> &list,
01311                                bool bPersistent, bool bGlobal, bool bNLS )
01312 {
01313   writeEntry(pKey.utf8().data(), list, bPersistent, bGlobal, bNLS);
01314 }
01315 
01316 void KConfigBase::writeEntry ( const char *pKey, const QValueList<int> &list,
01317                                bool bPersistent, bool bGlobal, bool bNLS )
01318 {
01319     QStringList strlist;
01320     QValueList<int>::ConstIterator end = list.end();
01321     for (QValueList<int>::ConstIterator it = list.begin(); it != end; it++)
01322         strlist << QString::number(*it);
01323     writeEntry(pKey, strlist, ',', bPersistent, bGlobal, bNLS );
01324 }
01325 
01326 void KConfigBase::writeEntry( const QString& pKey, int nValue,
01327                                  bool bPersistent, bool bGlobal,
01328                                  bool bNLS )
01329 {
01330   writeEntry( pKey, QString::number(nValue), bPersistent, bGlobal, bNLS );
01331 }
01332 
01333 void KConfigBase::writeEntry( const char *pKey, int nValue,
01334                                  bool bPersistent, bool bGlobal,
01335                                  bool bNLS )
01336 {
01337   writeEntry( pKey, QString::number(nValue), bPersistent, bGlobal, bNLS );
01338 }
01339 
01340 
01341 void KConfigBase::writeEntry( const QString& pKey, unsigned int nValue,
01342                                  bool bPersistent, bool bGlobal,
01343                                  bool bNLS )
01344 {
01345   writeEntry( pKey, QString::number(nValue), bPersistent, bGlobal, bNLS );
01346 }
01347 
01348 void KConfigBase::writeEntry( const char *pKey, unsigned int nValue,
01349                                  bool bPersistent, bool bGlobal,
01350                                  bool bNLS )
01351 {
01352   writeEntry( pKey, QString::number(nValue), bPersistent, bGlobal, bNLS );
01353 }
01354 
01355 
01356 void KConfigBase::writeEntry( const QString& pKey, long nValue,
01357                                  bool bPersistent, bool bGlobal,
01358                                  bool bNLS )
01359 {
01360   writeEntry( pKey, QString::number(nValue), bPersistent, bGlobal, bNLS );
01361 }
01362 
01363 void KConfigBase::writeEntry( const char *pKey, long nValue,
01364                                  bool bPersistent, bool bGlobal,
01365                                  bool bNLS )
01366 {
01367   writeEntry( pKey, QString::number(nValue), bPersistent, bGlobal, bNLS );
01368 }
01369 
01370 
01371 void KConfigBase::writeEntry( const QString& pKey, unsigned long nValue,
01372                                  bool bPersistent, bool bGlobal,
01373                                  bool bNLS )
01374 {
01375   writeEntry( pKey, QString::number(nValue), bPersistent, bGlobal, bNLS );
01376 }
01377 
01378 void KConfigBase::writeEntry( const char *pKey, unsigned long nValue,
01379                                  bool bPersistent, bool bGlobal,
01380                                  bool bNLS )
01381 {
01382   writeEntry( pKey, QString::number(nValue), bPersistent, bGlobal, bNLS );
01383 }
01384 
01385 
01386 void KConfigBase::writeEntry( const QString& pKey, double nValue,
01387                                  bool bPersistent, bool bGlobal,
01388                                  char format, int precision,
01389                                  bool bNLS )
01390 {
01391   writeEntry( pKey, QString::number(nValue, format, precision),
01392                      bPersistent, bGlobal, bNLS );
01393 }
01394 
01395 void KConfigBase::writeEntry( const char *pKey, double nValue,
01396                                  bool bPersistent, bool bGlobal,
01397                                  char format, int precision,
01398                                  bool bNLS )
01399 {
01400   writeEntry( pKey, QString::number(nValue, format, precision),
01401                      bPersistent, bGlobal, bNLS );
01402 }
01403 
01404 
01405 void KConfigBase::writeEntry( const QString& pKey, bool bValue,
01406                                  bool bPersistent,
01407                                  bool bGlobal,
01408                                  bool bNLS )
01409 {
01410   writeEntry(pKey.utf8().data(), bValue, bPersistent, bGlobal, bNLS);
01411 }
01412 
01413 void KConfigBase::writeEntry( const char *pKey, bool bValue,
01414                                  bool bPersistent,
01415                                  bool bGlobal,
01416                                  bool bNLS )
01417 {
01418   QString aValue;
01419 
01420   if( bValue )
01421     aValue = "true";
01422   else
01423     aValue = "false";
01424 
01425   writeEntry( pKey, aValue, bPersistent, bGlobal, bNLS );
01426 }
01427 
01428 
01429 void KConfigBase::writeEntry( const QString& pKey, const QFont& rFont,
01430                                  bool bPersistent, bool bGlobal,
01431                                  bool bNLS )
01432 {
01433   writeEntry(pKey.utf8().data(), rFont, bPersistent, bGlobal, bNLS);
01434 }
01435 
01436 void KConfigBase::writeEntry( const char *pKey, const QFont& rFont,
01437                                  bool bPersistent, bool bGlobal,
01438                                  bool bNLS )
01439 {
01440   writeEntry( pKey, rFont.toString(), bPersistent, bGlobal, bNLS );
01441 }
01442 
01443 
01444 void KConfigBase::writeEntry( const QString& pKey, const QRect& rRect,
01445                               bool bPersistent, bool bGlobal,
01446                               bool bNLS )
01447 {
01448   writeEntry(pKey.utf8().data(), rRect, bPersistent, bGlobal, bNLS);
01449 }
01450 
01451 void KConfigBase::writeEntry( const char *pKey, const QRect& rRect,
01452                               bool bPersistent, bool bGlobal,
01453                               bool bNLS )
01454 {
01455   QStrList list;
01456   QCString tempstr;
01457   list.insert( 0, tempstr.setNum( rRect.left() ) );
01458   list.insert( 1, tempstr.setNum( rRect.top() ) );
01459   list.insert( 2, tempstr.setNum( rRect.width() ) );
01460   list.insert( 3, tempstr.setNum( rRect.height() ) );
01461 
01462   writeEntry( pKey, list, ',', bPersistent, bGlobal, bNLS );
01463 }
01464 
01465 
01466 void KConfigBase::writeEntry( const QString& pKey, const QPoint& rPoint,
01467                               bool bPersistent, bool bGlobal,
01468                               bool bNLS )
01469 {
01470   writeEntry(pKey.utf8().data(), rPoint, bPersistent, bGlobal, bNLS);
01471 }
01472 
01473 void KConfigBase::writeEntry( const char *pKey, const QPoint& rPoint,
01474                               bool bPersistent, bool bGlobal,
01475                               bool bNLS )
01476 {
01477   QStrList list;
01478   QCString tempstr;
01479   list.insert( 0, tempstr.setNum( rPoint.x() ) );
01480   list.insert( 1, tempstr.setNum( rPoint.y() ) );
01481 
01482   writeEntry( pKey, list, ',', bPersistent, bGlobal, bNLS );
01483 }
01484 
01485 
01486 void KConfigBase::writeEntry( const QString& pKey, const QSize& rSize,
01487                               bool bPersistent, bool bGlobal,
01488                               bool bNLS )
01489 {
01490   writeEntry(pKey.utf8().data(), rSize, bPersistent, bGlobal, bNLS);
01491 }
01492 
01493 void KConfigBase::writeEntry( const char *pKey, const QSize& rSize,
01494                               bool bPersistent, bool bGlobal,
01495                               bool bNLS )
01496 {
01497   QStrList list;
01498   QCString tempstr;
01499   list.insert( 0, tempstr.setNum( rSize.width() ) );
01500   list.insert( 1, tempstr.setNum( rSize.height() ) );
01501 
01502   writeEntry( pKey, list, ',', bPersistent, bGlobal, bNLS );
01503 }
01504 
01505 void KConfigBase::writeEntry( const QString& pKey, const QColor& rColor,
01506                               bool bPersistent,
01507                               bool bGlobal,
01508                               bool bNLS  )
01509 {
01510   writeEntry( pKey.utf8().data(), rColor, bPersistent, bGlobal, bNLS);
01511 }
01512 
01513 void KConfigBase::writeEntry( const char *pKey, const QColor& rColor,
01514                               bool bPersistent,
01515                               bool bGlobal,
01516                               bool bNLS  )
01517 {
01518   QString aValue;
01519   if (rColor.isValid())
01520       aValue.sprintf( "%d,%d,%d", rColor.red(), rColor.green(), rColor.blue() );
01521   else
01522       aValue = "invalid";
01523 
01524   writeEntry( pKey, aValue, bPersistent, bGlobal, bNLS );
01525 }
01526 
01527 void KConfigBase::writeEntry( const QString& pKey, const QDateTime& rDateTime,
01528                               bool bPersistent, bool bGlobal,
01529                               bool bNLS )
01530 {
01531   writeEntry(pKey.utf8().data(), rDateTime, bPersistent, bGlobal, bNLS);
01532 }
01533 
01534 void KConfigBase::writeEntry( const char *pKey, const QDateTime& rDateTime,
01535                               bool bPersistent, bool bGlobal,
01536                               bool bNLS )
01537 {
01538   QStrList list;
01539   QCString tempstr;
01540 
01541   QTime time = rDateTime.time();
01542   QDate date = rDateTime.date();
01543 
01544   list.insert( 0, tempstr.setNum( date.year() ) );
01545   list.insert( 1, tempstr.setNum( date.month() ) );
01546   list.insert( 2, tempstr.setNum( date.day() ) );
01547 
01548   list.insert( 3, tempstr.setNum( time.hour() ) );
01549   list.insert( 4, tempstr.setNum( time.minute() ) );
01550   list.insert( 5, tempstr.setNum( time.second() ) );
01551 
01552   writeEntry( pKey, list, ',', bPersistent, bGlobal, bNLS );
01553 }
01554 
01555 void KConfigBase::parseConfigFiles()
01556 {
01557   if (!bLocaleInitialized && KGlobal::_locale) {
01558     setLocale();
01559   }
01560   if (backEnd)
01561   {
01562      backEnd->parseConfigFiles();
01563      bReadOnly = (backEnd->getConfigState() == ReadOnly);
01564   }
01565 }
01566 
01567 void KConfigBase::sync()
01568 {
01569   if (isReadOnly())
01570     return;
01571 
01572   if (backEnd)
01573      backEnd->sync();
01574   if (bDirty)
01575     rollback();
01576 }
01577 
01578 KConfigBase::ConfigState KConfigBase::getConfigState() const {
01579     if (backEnd)
01580        return backEnd->getConfigState();
01581     return ReadOnly;
01582 }
01583 
01584 void KConfigBase::rollback( bool /*bDeep = true*/ )
01585 {
01586   bDirty = false;
01587 }
01588 
01589 KConfigGroup::KConfigGroup(KConfigBase *master, const QString &group)
01590 {
01591   mMaster = master;
01592   backEnd = 0;
01593   bLocaleInitialized = true;
01594   bReadOnly = mMaster->bReadOnly;
01595   bExpand = false;
01596   bDirty = false; // Not used
01597   mGroup = group.utf8();
01598   aLocaleString = mMaster->aLocaleString;
01599 }
01600 
01601 KConfigGroup::KConfigGroup(KConfigBase *master, const QCString &group)
01602 {
01603   mMaster = master;
01604   backEnd = 0;
01605   bLocaleInitialized = true;
01606   bReadOnly = mMaster->bReadOnly;
01607   bExpand = false;
01608   bDirty = false; // Not used
01609   mGroup = group;
01610   aLocaleString = mMaster->aLocaleString;
01611 }
01612 
01613 KConfigGroup::KConfigGroup(KConfigBase *master, const char * group)
01614 {
01615   mMaster = master;
01616   backEnd = 0;
01617   bLocaleInitialized = true;
01618   bReadOnly = mMaster->bReadOnly;
01619   bExpand = false;
01620   bDirty = false; // Not used
01621   mGroup = group;
01622   aLocaleString = mMaster->aLocaleString;
01623 }
01624 
01625 void KConfigGroup::deleteGroup(bool bGlobal)
01626 {
01627   mMaster->deleteGroup(KConfigBase::group(), false, bGlobal);
01628 }
01629 
01630 void KConfigGroup::setDirty(bool b)
01631 {
01632   mMaster->setDirty(b);
01633 }
01634 
01635 void KConfigGroup::putData(const KEntryKey &_key, const KEntry &_data, bool _checkGroup)
01636 {
01637   mMaster->putData(_key, _data, _checkGroup);
01638 }
01639 
01640 KEntry KConfigGroup::lookupData(const KEntryKey &_key) const
01641 {
01642   return mMaster->lookupData(_key);
01643 }
01644 
01645 void KConfigGroup::sync()
01646 {
01647   mMaster->sync();
01648 }
01649 
01650 void KConfigBase::virtual_hook( int, void* )
01651 { /*BASE::virtual_hook( id, data );*/ }
01652 
01653 void KConfigGroup::virtual_hook( int id, void* data )
01654 { KConfigBase::virtual_hook( id, data ); }
01655 
01656 #include "kconfigbase.moc"
01657 
KDE Logo
This file is part of the documentation for kdelibs Version 3.1.0.
Documentation copyright © 1996-2002 the KDE developers.
Generated on Wed Oct 8 12:20:40 2003 by doxygen 1.2.18 written by Dimitri van Heesch, © 1997-2001