• Skip to content
  • Skip to link menu
KDE 4.1 API Reference
  • KDE API Reference
  • kdelibs
  • Sitemap
  • Contact Us
 

KDECore

KConfig Class Reference

#include <KConfig>

Inheritance diagram for KConfig:

Inheritance graph
[legend]

List of all members.


Detailed Description

The central class of the KDE configuration data system.

Quickstart:

Get the default application config object via KGlobal::config().

Load a specific configuration file:

 KConfig config( "/etc/kderc", KConfig::SimpleConfig );

Load the configuration of a specific component (taking into account possible custom dirs in KStandardDirs):

 KConfig config( componentData(), "pluginrc" );

In general it is recommended to use KSharedConfig instead of creating multiple instances of KConfig to avoid the overhead of separate objects or concerns about synchronizing writes to disk even if the configuration object is updated from multiple code paths. KSharedConfig provides a set of open methods as counterparts for the KConfig constructors.

See also:
KSharedConfig, KConfigGroup, the techbase HOWTO on KConfig.

Definition at line 70 of file kconfig.h.


Public Types

enum  OpenFlag {
  IncludeGlobals = 0x01, CascadeConfig = 0x02, SimpleConfig = 0x00, NoCascade = IncludeGlobals,
  NoGlobals = CascadeConfig, FullConfig = IncludeGlobals|CascadeConfig
}

Public Member Functions

void checkUpdate (const QString &id, const QString &updateFile)
const KComponentData & componentData () const
KConfig * copyTo (const QString &file, KConfig *config=0) const
QMap< QString, QString > entryMap (const QString &aGroup=QString()) const
QStringList groupList () const
 KConfig (const QString &file, const QString &backend, const char *resourceType="config")
 KConfig (const KComponentData &componentData, const QString &file=QString(), OpenFlags mode=FullConfig, const char *resourceType="config")
 KConfig (const QString &file=QString(), OpenFlags mode=FullConfig, const char *resourceType="config")
void markAsClean ()
QString name () const
void reparseConfiguration ()
void sync ()
virtual ~KConfig ()
AccessMode accessMode () const
bool isConfigWritable (bool warnUser)
void addConfigSources (const QStringList &sources)
bool forceGlobal () const
void setForceGlobal (bool force)
bool isImmutable () const
QString locale () const
bool setLocale (const QString &aLocale)
bool readDefaults () const
void setReadDefaults (bool b)

Protected Member Functions

virtual void deleteGroupImpl (const QByteArray &group, WriteConfigFlags flags=Normal)
virtual const KConfigGroup groupImpl (const QByteArray &b) const
virtual KConfigGroup groupImpl (const QByteArray &b)
virtual bool hasGroupImpl (const QByteArray &group) const
virtual bool isGroupImmutableImpl (const QByteArray &aGroup) const
 KConfig (KConfigPrivate &d)
virtual void virtual_hook (int id, void *data)

Protected Attributes

KConfigPrivate *const d_ptr

Member Enumeration Documentation

enum KConfig::OpenFlag

Enumerator:
IncludeGlobals  Blend kdeglobals into the config object.
CascadeConfig  Cascade to system-wide config files.
SimpleConfig  The following are convenience definitions for the basic mode.

Do not combine them with anything. Just a single config file.

NoCascade  Include user's globals, but omit system settings.
NoGlobals  Cascade to system settings, but omit user's globals.
FullConfig  Fully-fledged config, including globals and cascading to system settings.

Definition at line 73 of file kconfig.h.


Constructor & Destructor Documentation

KConfig::KConfig ( const QString &  file = QString(),
OpenFlags  mode = FullConfig,
const char *  resourceType = "config" 
) [explicit]

Definition at line 163 of file kconfig.cpp.

KConfig::KConfig ( const KComponentData &  componentData,
const QString &  file = QString(),
OpenFlags  mode = FullConfig,
const char *  resourceType = "config" 
) [explicit]

Definition at line 173 of file kconfig.cpp.

KConfig::KConfig ( const QString &  file,
const QString &  backend,
const char *  resourceType = "config" 
)

Definition at line 183 of file kconfig.cpp.

KConfig::~KConfig (  )  [virtual]

Definition at line 199 of file kconfig.cpp.

KConfig::KConfig ( KConfigPrivate &  d  )  [protected]

Definition at line 194 of file kconfig.cpp.


Member Function Documentation

KConfig::AccessMode KConfig::accessMode (  )  const [virtual]

configuration object state

Reimplemented from superclass.

Implements KConfigBase.

Definition at line 531 of file kconfig.cpp.

void KConfig::addConfigSources ( const QStringList &  sources  ) 

extra config files

Sets the merge stack to the list of files. The stack is last in first out with the top of the stack being the most specific config file. The files in the merge stack will be read before the file passed to the constructor and any files that cascade from that file. This means that the entries read from the files in the merge stack will be treated as defaults. This function will automatically call reparseConfiguration() for you.

Note:
: Most specific config file is relative to this list, the overall most specific file of this KConfig object is still the file it was created with, no matter which file is passed last into this function. This means that writing always goes to the file which was used to create the KConfig object.
Parameters:
files A list of extra config files.

Definition at line 537 of file kconfig.cpp.

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

Definition at line 366 of file kconfig.cpp.

const KComponentData & KConfig::componentData (  )  const

Definition at line 207 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
Returns:
the same as config if it was set, otherwise a new KConfig object. In that case, do not forget to delete it!

Definition at line 377 of file kconfig.cpp.

void KConfig::deleteGroupImpl ( const QByteArray &  group,
WriteConfigFlags  flags = Normal 
) [protected, virtual]

Implements KConfigBase.

Definition at line 633 of file kconfig.cpp.

QMap< QString, QString > KConfig::entryMap ( const QString &  aGroup = QString()  )  const

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

Only the actual entry as a string is returned.

Parameters:
aGroup The group to get entries from.
Returns:
A map of entries in the group specified, indexed by key. The returned map may be empty if the group is empty, or not found.
See also:
QMap

Definition at line 264 of file kconfig.cpp.

bool KConfig::forceGlobal (  )  const

Returns whether all entries are being written to kdeglobals.

Returns:
true if all entries are being written to kdeglobals
See also:
setForceGlobal
Deprecated:

Definition at line 604 of file kconfig.cpp.

const KConfigGroup KConfig::groupImpl ( const QByteArray &  b  )  const [protected, virtual]

Implements KConfigBase.

Definition at line 615 of file kconfig.cpp.

KConfigGroup KConfig::groupImpl ( const QByteArray &  b  )  [protected, virtual]

Implements KConfigBase.

Definition at line 610 of file kconfig.cpp.

QStringList KConfig::groupList (  )  const [virtual]

Reimplemented from superclass.

Implements KConfigBase.

Definition at line 213 of file kconfig.cpp.

bool KConfig::hasGroupImpl ( const QByteArray &  group  )  const [protected, virtual]

Implements KConfigBase.

Definition at line 684 of file kconfig.cpp.

bool KConfig::isConfigWritable ( bool  warnUser  ) 

Return false if the user cannot write to this KConfig instance, for instance because of permission problems.

Parameters:
warnUser if true, show a message box telling the user to contact his system administrator for getting this problem fixed.

Definition at line 659 of file kconfig.cpp.

bool KConfig::isGroupImmutableImpl ( const QByteArray &  aGroup  )  const [protected, virtual]

Implements KConfigBase.

Definition at line 592 of file kconfig.cpp.

bool KConfig::isImmutable (  )  const [virtual]

immutability

Reimplemented from superclass.

Implements KConfigBase.

Definition at line 586 of file kconfig.cpp.

QString KConfig::locale (  )  const

locales

Returns the current locale.

Definition at line 549 of file kconfig.cpp.

void KConfig::markAsClean (  )  [virtual]

Reimplemented from superclass.

Implements KConfigBase.

Definition at line 355 of file kconfig.cpp.

QString KConfig::name (  )  const

Returns the filename passed to the constructor.

Definition at line 394 of file kconfig.cpp.

bool KConfig::readDefaults (  )  const

Definition at line 580 of file kconfig.cpp.

void KConfig::reparseConfiguration (  ) 

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

Definition at line 445 of file kconfig.cpp.

void KConfig::setForceGlobal ( bool  force  ) 

global

Forces all following write-operations to be performed on kdeglobals, independent of the Global flag in writeEntry().

Parameters:
force true to force writing to kdeglobals
See also:
forceGlobal

Definition at line 598 of file kconfig.cpp.

bool KConfig::setLocale ( const QString &  aLocale  ) 

Sets the locale to aLocale.

The global locale is used by default.

Note:
If set to the empty string, no locale will be matched. This effectively disables reading translated entries.
Returns:
true if locale was changed and configuration was reparsed.

Definition at line 564 of file kconfig.cpp.

void KConfig::setReadDefaults ( bool  b  ) 

defaults

When set, all readEntry calls return the system-wide (default) values instead of the user's preference. This is off by default.

Definition at line 574 of file kconfig.cpp.

void KConfig::sync (  )  [virtual]

Reimplemented from superclass.

Implements KConfigBase.

Definition at line 290 of file kconfig.cpp.

void KConfig::virtual_hook ( int  id,
void *  data 
) [protected, virtual]

Virtual hook, used to add new "virtual" functions while maintaining binary compatibility.

Unused in this class.

Reimplemented from KConfigBase.

Definition at line 735 of file kconfig.cpp.


Member Data Documentation

KConfigPrivate* const KConfig::d_ptr [protected]

Definition at line 267 of file kconfig.h.


The documentation for this class was generated from the following files:
  • kconfig.h
  • kconfig.cpp

KDECore

Skip menu "KDECore"
  • Main Page
  • Modules
  • Namespace List
  • Class Hierarchy
  • Alphabetical List
  • Class List
  • File List
  • Namespace Members
  • Class Members
  • Related Pages

kdelibs

Skip menu "kdelibs"
  • DNSSD
  • Interfaces
  •   KHexEdit
  •   KMediaPlayer
  •   KSpeech
  •   KTextEditor
  • Kate
  • kconf_update
  • KDE3Support
  •   KUnitTest
  • KDECore
  • KDED
  • KDEsu
  • KDEUI
  • KDocTools
  • KFile
  • KHTML
  • KImgIO
  • KInit
  • KIO
  • KIOSlave
  • KJS
  •   KJS-API
  •   WTF
  • kjsembed
  • KNewStuff
  • KParts
  • Kross
  • KUtils
  • Nepomuk
  • Solid
  • Sonnet
  • ThreadWeaver
Generated for kdelibs by doxygen 1.5.4
This website is maintained by Adriaan de Groot and Allen Winter.
KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal