Source Code (Use browser search to find items of interest.)
Class Index
kdelibs'KConfig (./kdelibs/kdecore/kconfig.h:44)
class KConfig : public KConfigBase
{
Q_OBJECT
public:
/**
* Construct a KConfig object.
*
* @param 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
* @p bUseKDEGlobals).
* @param bReadOnly Set the config object's read-only status.
* @param bUseKDEGlobals Toggle reading the global KDE configuration file.
*/
KConfig( const QString& fileName = QString::null,
bool bReadOnly = false, bool bUseKDEGlobals = true);
/**
* Destructor.
*
* Writes back any dirty configuration entries, and destroys
* dynamically created objects.
*/
virtual ~KConfig();
/**
* Clears all entries out of the @p dirtyEntryMap, so the
* values will not be written to disk on a later call to
* @ref sync().
*
* @param 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 KConfigBase::rollback
*/
virtual void rollback(bool bDeep = true);
/**
* @return @p true if the specified group is known.
*
* @param _pGroup The group to search for.
* @returns @p true if the group exists.
*/
virtual bool hasGroup(const QString &_pGroup) const;
/**
* Retrieve a list of groups that are known.
* @returns The list of groups.
*/
virtual QStringList groupList() const;
/*
* Check if the key has an entry in the currently active group. Use
* this to determine if a key is not specified for the current group
* (@p hasKey returns @p false). Keys with null data are considered
* nonexistent.
*
* @param pKey The key to search for.
*/
virtual bool hasKey(const QString &pKey) const;
/**
* Retrieve 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.
*
* @param pGroup A group to get keys from.
* @return A map of entries in the group specified, indexed by key.
* The returned map may be empty if the group is not found.
*/
virtual QMap<QString, QString> entryMap(const QString &pGroup) const;
/**
* Clear all internal data structures and then reread
* configuration information from disk.
*/
virtual void reparseConfiguration();
protected:
/**
* Retrieve a map (tree) of the entries in the specified group.
*
* Do not use this function, the implementation / return type are
* subject to change.
*
* @param pGroup the group to provide a KEntryMap for.
* @return The map of the entries in the group.
* @internal
*/
virtual KEntryMap internalEntryMap(const QString &pGroup) const;
/**
* Returns a copy of the internal map used to hold all entries.
*
* Do not use this function, the implementation / return type are
* subject to change.
*
* @param pGroup the group to provide a KEntryMap for.
* @return The map of the entries in the group.
* @internal
*/
virtual KEntryMap internalEntryMap() const { return aEntryMap; }
/**
* Insert a key,value pair into the internal storage mechanism of
* the configuration object.
*
* @param _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.
* @param _data the KEntry that is to be stored.
*/
virtual void putData(const KEntryKey &_key, const KEntry &_data);
/**
* Look up an entry in the config object's internal structure.
*
* @param _key The key to look up It contains information both on
* the group of the key and the entry's key itself.
* @return the KEntry value (data) found for the key. KEntry.aValue
* will be the null string if nothing was located.
*/
virtual KEntry lookupData(const KEntryKey &_key) const;
/**
* 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 @ref KEntryKey
* set to @ref QString::null.
*/
KEntryMap aEntryMap;
private:
/**
* indicates whether the internal data cache is full or empty.
* If it is empty, the config files on disk will need to be
* reopened and read before any reading can take place.
*/
bool isCached;
/**
* timer which is periodically triggered to flush out the
* data cache.
*/
QTimer *cacheTimer;
/**
* The last time a value was either read or written. Used to
* determine a cache time threshold. Because lookupData() is
* called for reads and writes, we only need to update the time
* there; we can ignore putData().
*
* @see #lookupData, #putData
*/
QTime lastIoOp;
/**
* time between flush attempts. We initialize this to 30 seconds.
*/
int flushInterval;
/**
* @internal
* copy-construction and assignment are not allowed
*/
KConfig( const KConfig& );
/**
* @internal
* copy-construction and assignment are not allowed
*/
KConfig& operator= ( const KConfig& rConfig );
/**
* Checks whether the cache is loaded from disk, and loads it if
* needed. Not actually a const function, so we need to do some
* internal funny business to get around constness, but needed to be
* const because of where it is called from (functions that really
* *should* remain const).
*/
void cacheCheck() const;
private slots:
/**
* attempts to flush the entry cache. Will set isCached
* variable to the appropriate value upon completion.
*/
void flushCache();
private:
KConfigPrivate *d;
};
inline bool KConfig::hasGroup(const QString &_pGroup) const
{
// cacheCheck();
KEntryKey groupKey( _pGroup, QString::fromLatin1(""));
return aEntryMap.contains(groupKey);
}
kdelibs'KConfig::KConfig() (./kdelibs/kdecore/kconfig.cpp:44)
KConfig::KConfig( const QString& fileName,
bool bReadOnly, bool bUseKderc )
: KConfigBase(), flushInterval(30)
{
// set the object's read-only status.
setReadOnly(bReadOnly);
// for right now we will hardcode that we are using the INI
// back end driver. In the future this should be converted over to
// a object factory of some sorts.
KConfigINIBackEnd *aBackEnd = new KConfigINIBackEnd(this,
fileName,
QString::fromLatin1("config"),
bUseKderc);
// set the object's back end pointer to this new backend
backEnd = aBackEnd;
// need to set this before we actually parse so as to avoid
// infinite looping when parseConfigFiles calls things like
// hasGroup, putData, etc. which would then try to load
// the cache if it isCached was false.
isCached = true;
// read initial information off disk
reparseConfiguration();
// we let KStandardDirs add custom user config files. It will do
// this only once. So only the first call ever to this constructor
// will anything else than return here We have to reparse here as
// configuration files may appear after customized directories have
// been added. and the info they contain needs to be inserted into the
// config object.
// Since this makes only sense for config directories, addCustomized
// returns true only if new config directories appeared.
if (KGlobal::dirs()->addCustomized(this))
reparseConfiguration();
// cache flushing setup
// cacheTimer = new QTimer(this, "cacheTimer");
// connect(cacheTimer, SIGNAL(timeout()), SLOT(flushCache()));
// initial cache timeout of 30 seconds. It will auto-adjust.
// cacheTimer->start(flushInterval * 1000);
}
kdelibs'KConfig::~KConfig() (./kdelibs/kdecore/kconfig.cpp:88)
KConfig::~KConfig()
{
sync();
delete backEnd;
}
kdelibs'KConfig::rollback() (./kdelibs/kdecore/kconfig.cpp:95)
void KConfig::rollback(bool bDeep)
{
KConfigBase::rollback(bDeep);
if (!bDeep)
return; // object's bDeep flag is set in KConfigBase method
// clear any dirty flags that entries might have set
for (KEntryMapIterator aIt = aEntryMap.begin();
aIt != aEntryMap.end(); ++aIt)
(*aIt).bDirty = false;
}
kdelibs'KConfig::groupList() (./kdelibs/kdecore/kconfig.cpp:108)
QStringList KConfig::groupList() const
{
QStringList retList;
// cacheCheck();
KEntryMapConstIterator aIt;
for (aIt = aEntryMap.begin(); aIt != aEntryMap.end(); ++aIt)
if (aIt.key().key == QString::fromLatin1(""))
retList.append(aIt.key().group);
return retList;
}
kdelibs'KConfig::hasKey() (./kdelibs/kdecore/kconfig.cpp:122)
bool KConfig::hasKey(const QString &pKey) const
{
KEntryKey aEntryKey;
KEntryMapConstIterator aIt;
// cacheCheck();
if (!locale().isNull()) {
// try the localized key first
QString aKey = pKey;
aKey += '[';
aKey += locale();
aKey += ']';
aEntryKey.group = group();
aEntryKey.key = aKey;
aIt = aEntryMap.find(aEntryKey);
if (aIt != aEntryMap.end() && !(*aIt).aValue.isNull())
return true;
}
// try the non-localized version
aEntryKey.group = group();
aEntryKey.key = pKey;
aIt = aEntryMap.find(aEntryKey);
return (aIt != aEntryMap.end() && !(*aIt).aValue.isNull());
}
kdelibs'KConfig::entryMap() (./kdelibs/kdecore/kconfig.cpp:152)
QMap<QString, QString> KConfig::entryMap(const QString &pGroup) const
{
QMap<QString, QString> tmpMap;
KEntryMapConstIterator aIt;
KEntry aEntry;
KEntryKey groupKey( pGroup, QString::fromLatin1("") );
// cacheCheck();
aIt = aEntryMap.find(groupKey);
++aIt; // advance past special group entry marker
for (; aIt.key().group == pGroup && aIt != aEntryMap.end(); ++aIt)
tmpMap.insert(aIt.key().key, (*aIt).aValue);
return tmpMap;
}
kdelibs'KConfig::reparseConfiguration() (./kdelibs/kdecore/kconfig.cpp:168)
void KConfig::reparseConfiguration()
{
// do this right away to avoid infinite loops inside parseConfigFiles()
// if it chooses to call putData or lookupData or something which will
// call cacheCheck() --> reparseConfiguration() --> you get it
// isCached = true;
aEntryMap.clear();
// add the "default group" marker to the map
KEntryKey groupKey(QString::fromLatin1("<default>"), QString::fromLatin1(""));
aEntryMap.insert(groupKey, KEntry());
parseConfigFiles();
}
kdelibs'KConfig::internalEntryMap() (./kdelibs/kdecore/kconfig.cpp:183)
KEntryMap KConfig::internalEntryMap(const QString &pGroup) const
{
KEntry aEntry;
KEntryMapConstIterator aIt;
KEntryKey aKey(pGroup, QString::fromLatin1(""));
KEntryMap tmpEntryMap;
// cacheCheck();
aIt = aEntryMap.find(aKey);
if (aIt == aEntryMap.end()) {
// the special group key is not in the map,
// so it must be an invalid group. Return
// an empty map.
return tmpEntryMap;
}
// we now have a pointer to the nodes we want to copy.
for (; aIt.key().group == pGroup && aIt != aEntryMap.end(); ++aIt)
tmpEntryMap.insert(aIt.key(), *aIt);
return tmpEntryMap;
}
kdelibs'KConfig::putData() (./kdelibs/kdecore/kconfig.cpp:206)
void KConfig::putData(const KEntryKey &_key, const KEntry &_data)
{
// cacheCheck();
// check to see if the special group key is present,
// and if not, put it in.
if (!hasGroup(_key.group)) {
KEntryKey groupKey( _key.group, QString::fromLatin1(""));
aEntryMap.insert(groupKey, KEntry());
}
// now either add or replace the data
KEntryMapIterator aIt = aEntryMap.find(_key);
if (aIt != aEntryMap.end())
aEntryMap.replace(_key, _data);
else
aEntryMap.insert(_key, _data);
}
kdelibs'KConfig::lookupData() (./kdelibs/kdecore/kconfig.cpp:225)
KEntry KConfig::lookupData(const KEntryKey &_key) const
{
// cacheCheck();
KEntryMapConstIterator aIt;
aIt = aEntryMap.find(_key);
if (aIt != aEntryMap.end())
return *aIt;
else {
return KEntry();
}
}
kdelibs'KConfig::cacheCheck() (./kdelibs/kdecore/kconfig.cpp:239)
void KConfig::cacheCheck() const
{
KConfig *that = const_cast<KConfig *>(this);
that->lastIoOp = QTime::currentTime();
if (!isCached) {
that->reparseConfiguration();
}
}
kdelibs'KConfig::flushCache() (./kdelibs/kdecore/kconfig.cpp:248)
void KConfig::flushCache()
{
if (!isCached) {
// don't need to do anything
return;
}
if (isDirty()) {
// if the config object has dirty status, we can't flush it
return;
}
// check if time of last I/O operation occured within timeout zone
if (lastIoOp.addSecs(flushInterval) > QTime::currentTime()) {
// IO occured within the flush interval. Increase flush interval
// and reset timer accordingly.
flushInterval += (int)(flushInterval * .66);
} else {
// no I/O within the timeout period. Flush the cache.
isCached = false;
aEntryMap.clear();
KEntryKey groupKey(QString::fromLatin1("<default>"), QString::fromLatin1(""));
aEntryMap.insert(groupKey, KEntry());
// reset the interval to 30 second checks
flushInterval = 30;
}
cacheTimer->changeInterval(flushInterval * 1000);
}
kdelibs'KConfig::hasGroup() (./kdelibs/kdecore/kconfig.h:244)
inline bool KConfig::hasGroup(const QString &_pGroup) const
{
// cacheCheck();
KEntryKey groupKey( _pGroup, QString::fromLatin1(""));
return aEntryMap.contains(groupKey);
}