[prev in list] [next in list] [prev in thread] [next in thread]
List: kde-core-devel
Subject: Re: kdelibs/kdecore
From: Waldo Bastian <bastian () kde ! org>
Date: 2003-09-23 15:11:53
[Download RAW message or body]
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
On Tuesday 23 September 2003 11:42, Matthias Kretz wrote:
> On Tuesday September 23 2003 11:19, Waldo Bastian wrote:
> > Maybe KConfig should
> > provide a factory for refcounted config objects for such cases?
>
> Yes, that would be great. The same problem happens with embedding KCMs in
> your app. The KCM cannot reuse the KConfig object (because
> KGlobal::config() is not always the right config object and if you want to
> keep the flexibility to load the KCM somewhere else using KGlobal::config()
> in a KCM is a no-no). So it would be good to get the same KConfig object as
> is used in the application if the KCM is loaded in-process, else keeping
> sync is a mess.
Please review the following patch.
Cheers,
Waldo
- --
bastian@kde.org -=|[ SuSE, The Linux Desktop Experts ]|=- bastian@suse.com
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.0.6 (GNU/Linux)
Comment: For info see http://www.gnupg.org
iD8DBQE/cGK5N4pvrENfboIRAs7pAJ9ZB+B90na7ZARLMU6gViHKNmdohACdGU37
oloR8D41ywC+Dwo/AFjZND4=
=JQ2A
-----END PGP SIGNATURE-----
["ksharedconfig.patch" (text/x-diff)]
Index: kinstance.cpp
===================================================================
RCS file: /home/kde/kdelibs/kdecore/kinstance.cpp,v
retrieving revision 1.38
diff -u -r1.38 kinstance.cpp
--- kinstance.cpp 20 Nov 2002 21:29:36 -0000 1.38
+++ kinstance.cpp 23 Sep 2003 15:01:44 -0000
@@ -45,6 +45,7 @@
KMimeSourceFactory* mimeSourceFactory;
QString configName;
bool ownAboutdata;
+ KSharedConfig::Ptr sharedConfig;
};
KInstance::KInstance( const QCString& name)
@@ -98,6 +99,7 @@
d = new KInstancePrivate ();
d->ownAboutdata = src->d->ownAboutdata;
+ d->sharedConfig = src->d->sharedConfig;
src->_dirs = 0L;
src->_config = 0L;
@@ -117,7 +119,8 @@
delete _iconLoader;
_iconLoader = 0;
- delete _config;
+
+ // delete _config; // Do not delete, stored in d->sharedConfig
_config = 0;
delete _dirs;
_dirs = 0;
@@ -146,28 +149,29 @@
if( _config == 0 ) {
if ( !d->configName.isEmpty() )
{
- _config = new KConfig( d->configName );
+ d->sharedConfig = KSharedConfig::openConfig( d->configName );
+
// Check whether custom config files are allowed.
- _config->setGroup( "KDE Action Restrictions" );
- if (_config->readBoolEntry( "custom_config", true))
+ d->sharedConfig->setGroup( "KDE Action Restrictions" );
+ if (d->sharedConfig->readBoolEntry( "custom_config", true))
{
- _config->setGroup(QString::null);
+ d->sharedConfig->setGroup(QString::null);
}
else
{
- delete _config;
- _config = 0;
+ d->sharedConfig = 0;
}
}
- if ( _config == 0 )
+ if ( d->sharedConfig == 0 )
{
if ( !_name.isEmpty() )
- _config = new KConfig( _name + "rc");
+ d->sharedConfig = KSharedConfig::openConfig( _name + "rc");
else
- _config = new KConfig();
+ d->sharedConfig = KSharedConfig::openConfig( QString::null );
}
+ _config = d->sharedConfig;
if (_dirs)
if (_dirs->addCustomized(_config))
_config->reparseConfiguration();
Index: kconfig.cpp
===================================================================
RCS file: /home/kde/kdelibs/kdecore/kconfig.cpp,v
retrieving revision 1.75
diff -u -r1.75 kconfig.cpp
--- kconfig.cpp 19 Sep 2003 22:51:47 -0000 1.75
+++ kconfig.cpp 23 Sep 2003 15:01:44 -0000
@@ -55,6 +55,7 @@
fileName,
resType,
bUseKderc);
+
// set the object's back end pointer to this new backend
backEnd = aBackEnd;
@@ -314,6 +315,33 @@
void KConfig::virtual_hook( int id, void* data )
{ KConfigBase::virtual_hook( id, data ); }
+QPtrList<KSharedConfig> *KSharedConfig::s_list = 0;
+KSharedConfig::Ptr KSharedConfig::openConfig(const QString& fileName)
+{
+ if (s_list)
+ {
+ for(KSharedConfig* config = s_list->first(); (config = s_list->next());)
+ {
+ if (config->backEnd->fileName() == fileName)
+ return config;
+ }
+ }
+ return new KSharedConfig(fileName);
+}
+
+KSharedConfig::KSharedConfig( const QString& fileName )
+ : KConfig(fileName)
+{
+ if (!s_list)
+ s_list = new QPtrList<KSharedConfig>;
+
+ s_list->append(this);
+}
+
+KSharedConfig::~KSharedConfig()
+{
+ s_list->removeRef(this);
+}
#include "kconfig.moc"
Index: kconfig.h
===================================================================
RCS file: /home/kde/kdelibs/kdecore/kconfig.h,v
retrieving revision 1.60
diff -u -r1.60 kconfig.h
--- kconfig.h 19 Sep 2003 22:51:47 -0000 1.60
+++ kconfig.h 23 Sep 2003 15:01:44 -0000
@@ -26,6 +26,9 @@
class QTimer;
+#include <qptrlist.h>
+
+#include "ksharedptr.h"
#include "kconfigbase.h"
class KConfigPrivate;
@@ -249,5 +252,23 @@
KConfigPrivate *d;
};
+class KSharedConfig : public KConfig, public KShared
+{
+ friend class QPtrList<KSharedConfig>;
+public:
+ typedef KSharedPtr<KSharedConfig> Ptr;
+
+public:
+ /**
+ * Returns a ref-counted pointer to a shared read-write config object.
+ */
+ static KSharedConfig::Ptr openConfig(const QString& fileName);
+
+private:
+ KSharedConfig( const QString& fileName );
+ ~KSharedConfig();
+
+ static QPtrList<KSharedConfig> *s_list;
+};
#endif
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic