[prev in list] [next in list] [prev in thread] [next in thread]
List: kde-commits
Subject: kdelibs/kdecore
From: Waldo Bastian <bastian () kde ! org>
Date: 2003-03-31 15:56:55
[Download RAW message or body]
CVS commit by waba:
Make it possible to access the default values for config entries.
M +39 -14 kconfig.cpp 1.70
M +20 -2 kconfig.h 1.52
--- kdelibs/kdecore/kconfig.cpp #1.69:1.70
@@ -44,5 +44,5 @@ KConfig::KConfig( const QString& fileNam
bool bReadOnly, bool bUseKderc, const char *resType )
: KConfigBase(), bGroupImmutable(false), bFileImmutable(false),
- bForceGlobal(false)
+ bForceGlobal(false), bForceDefault(false)
{
// set the object's read-only status.
@@ -202,5 +202,8 @@ void KConfig::putData(const KEntryKey &_
// now either add or replace the data
+ if (!bForceDefault)
+ {
KEntry &entry = aEntryMap[_key];
+
if (entry.bImmutable)
return;
@@ -207,14 +210,24 @@ void KConfig::putData(const KEntryKey &_
entry = _data;
-
entry.bGlobal |= bForceGlobal; // force to kdeglobals
+ }
- if (_key.bDefault)
+ if (_key.bDefault || bForceDefault)
{
- // We have added the data as default value,
- // add it as normal value as well.
+ // Either:
+ // * We have added the data as default value
+ // and now add it as normal value as well.
+ // Or:
+ // * We haven't added it at all
+ // and now force it as default.
+
KEntryKey key(_key);
- key.bDefault = false;
- aEntryMap[key] = _data;
+ key.bDefault = bForceDefault;
+ KEntry &entry = aEntryMap[key];
+ if (entry.bImmutable)
+ return;
+
+ entry = _data;
+ entry.bGlobal |= bForceGlobal; // force to kdeglobals
}
}
@@ -222,5 +235,17 @@ void KConfig::putData(const KEntryKey &_
KEntry KConfig::lookupData(const KEntryKey &_key) const
{
- KEntryMapConstIterator aIt = aEntryMap.find(_key);
+ KEntryMapConstIterator aIt;
+ if (!bForceDefault)
+ {
+ // This is the common path
+ aIt = aEntryMap.find(_key);
+ }
+ else
+ {
+ KEntryKey key(_key);
+ key.bDefault = true;
+ aIt = aEntryMap.find(key);
+ }
+
if (aIt != aEntryMap.end())
{
--- kdelibs/kdecore/kconfig.h #1.51:1.52
@@ -134,4 +134,21 @@ public:
/**
+ * Forces all following read- and write-operations being
+ * performed on the default values instead of the actual
+ * values.
+ * @param force true to force usage of default values
+ * @see #forceDefault
+ */
+ void setForceDefault( bool force ) { bForceDefault = force; }
+
+ /**
+ * Returns true if all read- and write-operations are performed on
+ * the default entries instead of the actual entries.
+ * @return true if writing to default entries is active
+ * @see #setForceDefault
+ */
+ bool forceDefault() const { return bForceDefault; }
+
+ /**
* Checks whether the config file contains the update @p id
* as contained in @p updateFile. If not, it runs kconf_update
@@ -230,4 +247,5 @@ private:
bool bFileImmutable : 1; // Current file is immutable.
bool bForceGlobal : 1; // Apply everything to kdeglobals.
+ bool bForceDefault : 1; // Operate on the default values
protected:
virtual void virtual_hook( int id, void* data );
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic