KConfig Class Reference

`#include <kconfig.h>`

Inheritance diagram for KConfig:

## Public Member Functions

| KConfig (const QString &fileName=QString::null, bool bReadOnly=false, bool bUseKDEGlobals=true, const char *resType="config")
| KConfig (KConfigBackEnd *backEnd, bool bReadOnly=false)
virtual | ~KConfig ()
virtual void | rollback (bool bDeep=true)
virtual QStringList | groupList () const
virtual QMap< QString, QString > | entryMap (const QString &pGroup) const
virtual void | reparseConfiguration ()
void | setFileWriteMode (int mode)
void | setForceGlobal (bool force)
bool | forceGlobal () const
void | checkUpdate (const QString &id, const QString &updateFile)
KConfig * | copyTo (const QString &file, KConfig *config=0) const
KLockFile::Ptr | lockFile (bool bGlobal=false)
Public Member Functions inherited from KConfigBase
| KConfigBase ()
virtual | ~KConfigBase ()
void | setGroup (const QString &group)
void | setDesktopGroup ()
QString | group () const
bool | hasGroup (const QString &group) const
QString | locale () const
QString | readEntry (const QString &pKey, const QString &aDefault=QString::null) const
QString | readEntry (const char *pKey, const QString &aDefault=QString::null) const
QVariant | readPropertyEntry (const QString &pKey, QVariant::Type) const
QVariant | readPropertyEntry (const char *pKey, QVariant::Type) const
QVariant | readPropertyEntry (const QString &pKey, const QVariant &aDefault) const
QVariant | readPropertyEntry (const char *pKey, const QVariant &aDefault) const
int | readListEntry (const QString &pKey, QStrList &list, char sep= ',') const
int | readListEntry (const char *pKey, QStrList &list, char sep= ',') const
QStringList | readListEntry (const QString &pKey, char sep= ',') const
QStringList | readListEntry (const char *pKey, char sep= ',') const
QStringList | readListEntry (const char *pKey, const QStringList &aDefault, char sep= ',') const
QValueList< int > | readIntListEntry (const QString &pKey) const
QValueList< int > | readIntListEntry (const char *pKey) const
QString | readPathEntry (const QString &pKey, const QString &aDefault=QString::null) const
QString | readPathEntry (const char *pKey, const QString &aDefault=QString::null) const
QStringList | readPathListEntry (const QString &pKey, char sep= ',') const
QStringList | readPathListEntry (const char *pKey, char sep= ',') const
int | readNumEntry (const QString &pKey, int nDefault=0) const
int | readNumEntry (const char *pKey, int nDefault=0) const
unsigned int | readUnsignedNumEntry (const QString &pKey, unsigned int nDefault=0) const
unsigned int | readUnsignedNumEntry (const char *pKey, unsigned int nDefault=0) const
long | readLongNumEntry (const QString &pKey, long nDefault=0) const
long | readLongNumEntry (const char *pKey, long nDefault=0) const
unsigned long | readUnsignedLongNumEntry (const QString &pKey, unsigned long nDefault=0) const
unsigned long | readUnsignedLongNumEntry (const char *pKey, unsigned long nDefault=0) const
Q_INT64 | readNum64Entry (const QString &pKey, Q_INT64 nDefault=0) const
Q_INT64 | readNum64Entry (const char *pKey, Q_INT64 nDefault=0) const
Q_UINT64 | readUnsignedNum64Entry (const QString &pKey, Q_UINT64 nDefault=0) const
Q_UINT64 | readUnsignedNum64Entry (const char *pKey, Q_UINT64 nDefault=0) const
double | readDoubleNumEntry (const QString &pKey, double nDefault=0.0) const
double | readDoubleNumEntry (const char *pKey, double nDefault=0.0) const
QFont | readFontEntry (const QString &pKey, const QFont *pDefault=0L) const
QFont | readFontEntry (const char *pKey, const QFont *pDefault=0L) const
bool | readBoolEntry (const QString &pKey, bool bDefault=false) const
bool | readBoolEntry (const char *pKey, bool bDefault=false) const
QRect | readRectEntry (const QString &pKey, const QRect *pDefault=0L) const
QRect | readRectEntry (const char *pKey, const QRect *pDefault=0L) const
QPoint | readPointEntry (const QString &pKey, const QPoint *pDefault=0L) const
QPoint | readPointEntry (const char *pKey, const QPoint *pDefault=0L) const
QSize | readSizeEntry (const QString &pKey, const QSize *pDefault=0L) const
QSize | readSizeEntry (const char *pKey, const QSize *pDefault=0L) const
QColor | readColorEntry (const QString &pKey, const QColor *pDefault=0L) const
QColor | readColorEntry (const char *pKey, const QColor *pDefault=0L) const
QDateTime | readDateTimeEntry (const QString &pKey, const QDateTime *pDefault=0L) const
QDateTime | readDateTimeEntry (const char *pKey, const QDateTime *pDefault=0L) const
QString | readEntryUntranslated (const QString &pKey, const QString &aDefault=QString::null) const
QString | readEntryUntranslated (const char *pKey, const QString &aDefault=QString::null) const
void | writeEntry (const QString &pKey, const QString &pValue, bool bPersistent=true, bool bGlobal=false, bool bNLS=false)
void | writeEntry (const char *pKey, const QString &pValue, bool bPersistent=true, bool bGlobal=false, bool bNLS=false)
void | writeEntry (const QString &pKey, const QVariant &rValue, bool bPersistent=true, bool bGlobal=false, bool bNLS=false)
void | writeEntry (const char *pKey, const QVariant &rValue, bool bPersistent=true, bool bGlobal=false, bool bNLS=false)
void | writeEntry (const QString &pKey, const QStrList &rValue, char sep= ',', bool bPersistent=true, bool bGlobal=false, bool bNLS=false)
void | writeEntry (const char *pKey, const QStrList &rValue, char sep= ',', bool bPersistent=true, bool bGlobal=false, bool bNLS=false)
void | writeEntry (const QString &pKey, const QStringList &rValue, char sep= ',', bool bPersistent=true, bool bGlobal=false, bool bNLS=false)
void | writeEntry (const char *pKey, const QStringList &rValue, char sep= ',', bool bPersistent=true, bool bGlobal=false, bool bNLS=false)
void | writeEntry (const QString &pKey, const QValueList< int > &rValue, bool bPersistent=true, bool bGlobal=false, bool bNLS=false)
void | writeEntry (const char *pKey, const QValueList< int > &rValue, bool bPersistent=true, bool bGlobal=false, bool bNLS=false)
void | writeEntry (const QString &pKey, const char *pValue, bool bPersistent=true, bool bGlobal=false, bool bNLS=false)
void | writeEntry (const char *pKey, const char *pValue, bool bPersistent=true, bool bGlobal=false, bool bNLS=false)
void | writeEntry (const QString &pKey, int nValue, bool bPersistent=true, bool bGlobal=false, bool bNLS=false)
void | writeEntry (const char *pKey, int nValue, bool bPersistent=true, bool bGlobal=false, bool bNLS=false)
void | writeEntry (const QString &pKey, unsigned int nValue, bool bPersistent=true, bool bGlobal=false, bool bNLS=false)
void | writeEntry (const char *pKey, unsigned int nValue, bool bPersistent=true, bool bGlobal=false, bool bNLS=false)
void | writeEntry (const QString &pKey, long nValue, bool bPersistent=true, bool bGlobal=false, bool bNLS=false)
void | writeEntry (const char *pKey, long nValue, bool bPersistent=true, bool bGlobal=false, bool bNLS=false)
void | writeEntry (const QString &pKey, unsigned long nValue, bool bPersistent=true, bool bGlobal=false, bool bNLS=false)
void | writeEntry (const char *pKey, unsigned long nValue, bool bPersistent=true, bool bGlobal=false, bool bNLS=false)
void | writeEntry (const QString &pKey, Q_INT64 nValue, bool bPersistent=true, bool bGlobal=false, bool bNLS=false)
void | writeEntry (const char *pKey, Q_INT64 nValue, bool bPersistent=true, bool bGlobal=false, bool bNLS=false)
void | writeEntry (const QString &pKey, Q_UINT64 nValue, bool bPersistent=true, bool bGlobal=false, bool bNLS=false)
void | writeEntry (const char *pKey, Q_UINT64 nValue, bool bPersistent=true, bool bGlobal=false, bool bNLS=false)
void | writeEntry (const QString &pKey, double nValue, bool bPersistent=true, bool bGlobal=false, char format= 'g', int precision=6, bool bNLS=false)
void | writeEntry (const char *pKey, double nValue, bool bPersistent=true, bool bGlobal=false, char format= 'g', int precision=6, bool bNLS=false)
void | writeEntry (const QString &pKey, bool bValue, bool bPersistent=true, bool bGlobal=false, bool bNLS=false)
void | writeEntry (const char *pKey, bool bValue, bool bPersistent=true, bool bGlobal=false, bool bNLS=false)
void | writeEntry (const QString &pKey, const QFont &rFont, bool bPersistent=true, bool bGlobal=false, bool bNLS=false)
void | writeEntry (const char *pKey, const QFont &rFont, bool bPersistent=true, bool bGlobal=false, bool bNLS=false)
void | writeEntry (const QString &pKey, const QColor &rColor, bool bPersistent=true, bool bGlobal=false, bool bNLS=false)
void | writeEntry (const char *pKey, const QColor &rColor, bool bPersistent=true, bool bGlobal=false, bool bNLS=false)
void | writeEntry (const QString &pKey, const QDateTime &rDateTime, bool bPersistent=true, bool bGlobal=false, bool bNLS=false)
void | writeEntry (const char *pKey, const QDateTime &rDateTime, bool bPersistent=true, bool bGlobal=false, bool bNLS=false)
void | writeEntry (const QString &pKey, const QRect &rValue, bool bPersistent=true, bool bGlobal=false, bool bNLS=false)
void | writeEntry (const char *pKey, const QRect &rValue, bool bPersistent=true, bool bGlobal=false, bool bNLS=false)
void | writeEntry (const QString &pKey, const QPoint &rValue, bool bPersistent=true, bool bGlobal=false, bool bNLS=false)
void | writeEntry (const char *pKey, const QPoint &rValue, bool bPersistent=true, bool bGlobal=false, bool bNLS=false)
void | writeEntry (const QString &pKey, const QSize &rValue, bool bPersistent=true, bool bGlobal=false, bool bNLS=false)
void | writeEntry (const char *pKey, const QSize &rValue, bool bPersistent=true, bool bGlobal=false, bool bNLS=false)
void | writePathEntry (const QString &pKey, const QString &path, bool bPersistent=true, bool bGlobal=false, bool bNLS=false)
void | writePathEntry (const char *pKey, const QString &path, bool bPersistent=true, bool bGlobal=false, bool bNLS=false)
void | writePathEntry (const QString &pKey, const QStringList &rValue, char sep= ',', bool bPersistent=true, bool bGlobal=false, bool bNLS=false)
void | writePathEntry (const char *pKey, const QStringList &rValue, char sep= ',', bool bPersistent=true, bool bGlobal=false, bool bNLS=false)
void | deleteEntry (const QString &pKey, bool bNLS=false, bool bGlobal=false)
void | deleteEntry (const char *pKey, bool bNLS=false, bool bGlobal=false)
bool | deleteGroup (const QString &group, bool bDeep=true, bool bGlobal=false)
void | setDollarExpansion (bool _bExpand=true)
bool | isDollarExpansion () const
virtual void | sync ()
bool | isDirty () const
virtual void | setReadOnly (bool _ro)
bool | isReadOnly () const
bool | hasKey (const QString &key) const
bool | isImmutable () const
bool | groupIsImmutable (const QString &group) const
bool | entryIsImmutable (const QString &key) const
ConfigState | getConfigState () const
bool | checkConfigFilesWritable (bool warnUser)
void | setReadDefaults (bool b)
bool | readDefaults () const
void | revertToDefault (const QString &key)
bool | hasDefault (const QString &key) const
void | setGroup (const QCString &pGroup)
void | setGroup (const char *pGroup)
bool | hasGroup (const QCString &_pGroup) const
bool | hasGroup (const char *_pGroup) const
bool | hasKey (const char *pKey) const

## Protected Member Functions

virtual bool | internalHasGroup (const QCString &group) const
virtual KEntryMap | internalEntryMap (const QString &pGroup) const
virtual KEntryMap | internalEntryMap () const
virtual void | putData (const KEntryKey &_key, const KEntry &_data, bool _checkGroup=true)
virtual KEntry | lookupData (const KEntryKey &_key) const
virtual void | virtual_hook (int id, void *data)
Protected Member Functions inherited from KConfigBase
void | setLocale ()
virtual void | setDirty (bool _bDirty=true)
virtual void | parseConfigFiles ()
QCString | readEntryUtf8 (const char *pKey) const

## Protected Attributes

KEntryMap | aEntryMap
Protected Attributes inherited from KConfigBase
KConfigBackEnd * | backEnd
QCString | mGroup
QCString | aLocaleString
bool | bDirty
bool | bLocaleInitialized
bool | bReadOnly
bool | bExpand

## Additional Inherited Members

Public Types inherited from KConfigBase
enum | ConfigState { NoAccess, ReadOnly, ReadWrite }

## Detailed Description

Access KDE Configuration entries.

This class implements KDE's default configuration system.

Author
  Kalle Dalheimer kalle.nosp@m.@kde.nosp@m..org, Preston Brown pbrow.nosp@m.n@kd.nosp@m.e.org

See also
  KGlobal::config(), KConfigBase, KSimpleConfig KDE Configuration Management class

Definition at line 43 of file kconfig.h.

## Constructor & Destructor Documentation

KConfig::KConfig | ( | const QString & | fileName = `QString::null`,
|  | bool | bReadOnly = `false`,
|  | bool | bUseKDEGlobals = `true`,
|  | const char * | resType = `"config"`
| ) |  |

Constructs a KConfig object.

Parameters

  fileName | A file to parse in addition to the system-wide file(s). If it is not provided, only global KDE configuration data will be read (depending on the value of `bUseKDEGlobals`).
  bReadOnly | Set the config object's read-only status. Note that the object will automatically become read-only if either the user does not have write permission to `fileName` or if no file was specified.
  bUseKDEGlobals | Toggle reading the global KDE configuration file.
  resType | the place to look in (config, data, etc) See KStandardDirs.

Definition at line 44 of file kconfig.cpp.

KConfig::~KConfig | ( |  | ) |

virtual

Destructs the KConfig object.

Writes back any dirty configuration entries, and destroys dynamically created objects.

Definition at line 87 of file kconfig.cpp.

## Member Function Documentation

void KConfig::checkUpdate | ( | const QString & | id,
|  | const QString & | updateFile
| ) |  |

Checks whether the config file contains the update `id` as contained in `updateFile`.

If not, it runs kconf_update to update the config file.

If you install config update files with critical fixes you may wish to use this method to verify that a critical update has indeed been performed to catch the case where a user restores an old config file from backup that has not been updated yet.

Parameters

  id | the update to check
  updateFile | the file containing the update

Since
  3.1

Definition at line 287 of file kconfig.cpp.

KConfig * KConfig::copyTo | ( | const QString & | file,
|  | KConfig * | config = `0`
| ) |  | const

Copies all entries from this config object to a new config object that will save itself to `file`.

Actual saving to `file` happens when the returned object is destructed or when sync() is called upon it.

Parameters

  file | the new config object will save itself to.
  config | optional config object to reuse

Since
  3.2

Definition at line 303 of file kconfig.cpp.

QMap< QString, QString > KConfig::entryMap | ( | const QString & | pGroup | ) | const

virtual

Returns a map (tree) of entries for all entries in a particular group.

Only the actual entry string is returned, none of the other internal data should be included.

Parameters

  pGroup | A group to get keys from.

Returns
  A map of entries in the group specified, indexed by key. The returned map may be empty if the group is not found.

Implements KConfigBase.

Definition at line 141 of file kconfig.cpp.

bool KConfig::forceGlobal | ( |  | ) | const

inline

Returns true if all entries are being written into kdeglobals.

Returns
  true if all entries are being written into kdeglobals

See also
  setForceGlobal

Definition at line 136 of file kconfig.h.

QStringList KConfig::groupList | ( |  | ) | const

virtual

Returns a list of groups that are known.

Returns
  a list of of groups

Implements KConfigBase.

Definition at line 107 of file kconfig.cpp.

KEntryMap KConfig::internalEntryMap | ( | const QString & | pGroup | ) | const

protected virtual

Returns a map (tree) of the entries in the specified group.

This may or may not return all entries that belong to the config object. The only guarantee that you are given is that any entries that are dirty (i.e. modified and not yet written back to the disk) will be contained in the map. Some derivative classes may choose to return everything.

Do not use this function, the implementation / return type are subject to change.

Parameters

  pGroup | The group to provide a KEntryMap for.

Returns
  The map of the entries in the group.

Implements KConfigBase.

Definition at line 178 of file kconfig.cpp.

virtual KEntryMap KConfig::internalEntryMap | ( |  | ) | const

inline protected virtual

Returns a map (tree) of the entries in the tree.

Do not use this function, the implementation / return type are subject to change.

Returns
  A map of the entries in the tree.

Implements KConfigBase.

Definition at line 212 of file kconfig.h.

bool KConfig::internalHasGroup | ( | const QCString & | group | ) | const

protected virtual

Returns true if the specified group is known.

Parameters

  group | The group to search for.

Returns
  true if the group exists.

Implements KConfigBase.

Definition at line 254 of file kconfig.cpp.

KLockFile::Ptr KConfig::lockFile | ( | bool | bGlobal = `false` | ) |

Returns a lock file object for the configuration file or 0 if the backend does not support locking.

Parameters

  bGlobal | if true, return the lock file for the global config file

NOTE: KConfig::sync() requires a lock on both the normal and global config file. When calling KConfig::sync() while having a lock on the global config file, the normal config file MUST be locked AS WELL and the normal config file MUST be locked BEFORE the global config file! Otherwise there is a risk of deadlock.

Since
  3.3

Definition at line 280 of file kconfig.cpp.

KEntry KConfig::lookupData | ( | const KEntryKey & | _key | ) | const

protected virtual

Looks up an entry in the config object's internal structure.

Parameters

  _key | The key to look up It contains information both on the group of the key and the entry's key itself.

Returns
  the KEntry value (data) found for the key. KEntry.aValue will be the null string if nothing was located.

Implements KConfigBase.

Definition at line 238 of file kconfig.cpp.

void KConfig::putData | ( | const KEntryKey & | _key,
|  | const KEntry & | _data,
|  | bool | _checkGroup = `true`
| ) |  |

protected virtual

Inserts a (key, value) pair into the internal storage mechanism of the configuration object.

Parameters

  _key | The key to insert. It contains information both on the group of the key and the key itself. If the key already exists, the old value will be replaced.
  _data | the KEntry that is to be stored.
  _checkGroup | When false, assume that the group already exists.

Implements KConfigBase.

Definition at line 202 of file kconfig.cpp.

void KConfig::reparseConfiguration | ( |  | ) |

virtual

Clears all internal data structures and then reread configuration information from disk.

Implements KConfigBase.

Definition at line 161 of file kconfig.cpp.

void KConfig::rollback | ( | bool | bDeep = `true` | ) |

virtual

Clears all entries out of the `dirtyEntryMap`, so the values will not be written to disk on a later call to sync().

Parameters

  bDeep | If true, the dirty map is actually emptied. otherwise, the config object's global dirty flag is set to false, but the dirty entries remain in the dirty entry map.

See also
  KConfigBase::rollback

Reimplemented from KConfigBase.

Definition at line 94 of file kconfig.cpp.

void KConfig::setFileWriteMode | ( | int | mode | ) |

Set the file mode for newly created files.

Parameters

  mode | the mode for new files as described in chmod(2)

See also
  man:chmod(2) for a description of `mode`

Definition at line 275 of file kconfig.cpp.

void KConfig::setForceGlobal | ( | bool | force | ) |

inline

Forces all following write-operations being performed on kdeglobals, independent of the bGlobal flag in writeEntry().

Parameters

  force | true to force writing in kdeglobals

See also
  forceGlobal

Definition at line 129 of file kconfig.h.

## Member Data Documentation

KEntryMap KConfig::aEntryMap

protected

Contains all key,value entries, as well as some "special" keys which indicate the start of a group of entries.

These special keys will have the .key portion of their KEntryKey set to QString::null.

Definition at line 243 of file kconfig.h.

The documentation for this class was generated from the following files:

- kconfig.h
- kconfig.cpp

KDE Home | KDE Accessibility Home | Description of Access Keys