[PATCH] virtualizing methods in KConfigSkeleton
Andreas Pakulat
apaku at gmx.de
Thu May 24 15:58:07 BST 2007
Hi,
attached is the patch to KConfigSkeleton and kconfig_compiler to
virtualize the 4 methods: readConfig(),writeConfig(),useDefaults(bool)
and setDefaults().
On top of the virtual I changed the two *Defaults() methods back to how
they worked before Adam Treat changed them (that is as in KDE3) - this
was overlooked by Laurent when he reverted read/writeConfig.
Also I extended the api dox to more clearly state when you can override
usr* and when you should override read/writeConfig and use/setDefaults.
I already converted all occurences of ::writeConfig(); in trunk/KDE,
trunk/koffice and trunk/multimedia/amarok to ::self()->writeConfig();
because the static writeConfig will vanish from kconfig_compiler
generated code when this is committed. There are a few occurences in
extragear which I couldn't convert because I don't see CMakeLists.txt in
pim,utils and office and thus couldn't do a test-build.
Any objections against comitting this on Monday 28th?
Andreas
--
Good night to spend with family, but avoid arguments with your mate's
new lover.
-------------- next part --------------
Index: kdecore/kconfig_compiler/kconfig_compiler.cpp
===================================================================
--- kdecore/kconfig_compiler/kconfig_compiler.cpp (Revision 667521)
+++ kdecore/kconfig_compiler/kconfig_compiler.cpp (Arbeitskopie)
@@ -1532,14 +1532,6 @@ int main( int argc, char **argv )
h << endl;
}
- // Static writeConfig method for singleton
- if ( singleton ) {
- h << " static" << endl;
- h << " void writeConfig()" << endl;
- h << " {" << endl;
- h << " static_cast<KConfigSkeleton*>(self())->writeConfig();" << endl;
- h << " }" << endl;
- }
// Signal definition.
if( hasSignals ) {
Index: kdeui/config/kconfigskeleton.cpp
===================================================================
--- kdeui/config/kconfigskeleton.cpp (Revision 667521)
+++ kdeui/config/kconfigskeleton.cpp (Arbeitskopie)
@@ -976,11 +976,25 @@ KConfigSkeletonItem::List KConfigSkeleto
bool KConfigSkeleton::useDefaults(bool b)
{
- return usrUseDefaults(b);
+ if (b == mUseDefaults)
+ return mUseDefaults;
+
+ mUseDefaults = b;
+ KConfigSkeletonItem::List::ConstIterator it;
+ for( it = mItems.begin(); it != mItems.end(); ++it )
+ {
+ (*it)->swapDefault();
+ }
+ usrUseDefaults(b);
+ return !mUseDefaults;
}
void KConfigSkeleton::setDefaults()
{
+ KConfigSkeletonItem::List::ConstIterator it;
+ for( it = mItems.begin(); it != mItems.end(); ++it ) {
+ (*it)->setDefault();
+ }
usrSetDefaults();
}
@@ -1011,29 +1025,14 @@ void KConfigSkeleton::writeConfig()
readConfig();
emit configChanged();
-
}
bool KConfigSkeleton::usrUseDefaults(bool b)
{
- if (b == mUseDefaults)
- return mUseDefaults;
-
- mUseDefaults = b;
- KConfigSkeletonItem::List::ConstIterator it;
- for( it = mItems.begin(); it != mItems.end(); ++it )
- {
- (*it)->swapDefault();
- }
- return !mUseDefaults;
}
void KConfigSkeleton::usrSetDefaults()
{
- KConfigSkeletonItem::List::ConstIterator it;
- for( it = mItems.begin(); it != mItems.end(); ++it ) {
- (*it)->setDefault();
- }
}
void KConfigSkeleton::usrReadConfig()
Index: kdeui/config/kconfigskeleton.h
===================================================================
--- kdeui/config/kconfigskeleton.h (Revision 667521)
+++ kdeui/config/kconfigskeleton.h (Arbeitskopie)
@@ -937,26 +937,35 @@ public:
/**
* Set all registered items to their default values.
- * This method is implemented by usrSetDefaults(), which can be overridden
- * in derived classes if you have special requirements.
+ * This method calls usrSetDefaults() after setting the defaults for the
+ * registered items. You can overridde usrSetDefaults() in derived classes
+ * if you have special requirements.
+ * If you need more fine-grained control of setting the default values of
+ * the registered items you can override setDefaults() in a derived class.
*/
- void setDefaults();
+ virtual void setDefaults();
/**
* Read preferences from config file. All registered items are set to the
* values read from disk.
- * This method is implemented by usrReadConfig(), which can be overridden
+ * This method calls usrReadConfig() after reading the settings of the
+ * registered items from the KConfig. You can overridde usrReadConfig()
* in derived classes if you have special requirements.
+ * If you need more fine-grained control of storing the settings from
+ * the registered items you can override readConfig() in a derived class.
*/
- void readConfig();
+ virtual void readConfig();
/**
* Write preferences to config file. The values of all registered items are
* written to disk.
- * This method is implemented by usrWriteConfig(), which can be overridden
+ * This method calls usrWriteConfig() after writing the settings from the
+ * registered items to the KConfig. You can overridde usrWriteConfig()
* in derived classes if you have special requirements.
+ * If you need more fine-grained control of storing the settings from
+ * the registered items you can override writeConfig() in a derived class.
*/
- void writeConfig();
+ virtual void writeConfig();
/**
* Set the config file group for subsequent addItem() calls. It is valid
@@ -1295,7 +1304,10 @@ public:
* Specify whether this object should reflect the actual values or the
* default values.
* This method is implemented by usrUseDefaults(), which can be overridden
- * in derived classes if you have special requirements.
+ * in derived classes if you have special requirements and can call
+ * usrUseDefaults() directly.
+ * If you don't have control wether useDefaults() or usrUseDefaults() is
+ * called override useDefaults() directly.
* @param b true to make this object reflect the default values,
* false to make it reflect the actual values.
* @return The state prior to this call
More information about the kde-core-devel
mailing list