KDECore
ksharedconfig.cpp
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #include "ksharedconfig.h"
00023 #include "kconfigbackend.h"
00024 #include "kconfiggroup.h"
00025 #include "kcomponentdata.h"
00026 #include "kglobal.h"
00027 #include "kconfig_p.h"
00028
00029 K_GLOBAL_STATIC(QList<KSharedConfig*>, globalSharedConfigList)
00030
00031 KSharedConfigPtr KSharedConfig::openConfig( const QString& fileName,
00032 OpenFlags flags ,
00033 const char *resType)
00034 {
00035 return openConfig(KGlobal::mainComponent(), fileName, flags, resType);
00036 }
00037
00038 KSharedConfigPtr KSharedConfig::openConfig( const KComponentData &componentData,
00039 const QString& fileName,
00040 OpenFlags flags,
00041 const char *resType)
00042 {
00043 const QList<KSharedConfig*> *list = globalSharedConfigList;
00044 if (list) {
00045 for(QList<KSharedConfig*>::ConstIterator it = list->begin(); it != list->end(); ++it) {
00046 if ( (*it)->name() == fileName &&
00047 (*it)->d_ptr->openFlags == flags &&
00048
00049
00050 (*it)->componentData() == componentData
00051 ) {
00052 return KSharedConfigPtr(*it);
00053 }
00054 }
00055 }
00056 return KSharedConfigPtr(new KSharedConfig(componentData, fileName, flags, resType));
00057 }
00058
00059
00060 KSharedConfig::KSharedConfig( const KComponentData &componentData,
00061 const QString &fileName,
00062 OpenFlags flags,
00063 const char *resType)
00064 : KConfig(componentData, fileName, flags, resType)
00065 {
00066 globalSharedConfigList->append(this);
00067 }
00068
00069 KSharedConfig::~KSharedConfig()
00070 {
00071 if (!globalSharedConfigList.isDestroyed()) {
00072 globalSharedConfigList->removeAll(this);
00073 }
00074 }
00075
00076 KConfigGroup KSharedConfig::groupImpl(const QByteArray &groupName)
00077 {
00078 KSharedConfigPtr ptr(this);
00079 return KConfigGroup( ptr, groupName.constData());
00080 }
00081
00082 const KConfigGroup KSharedConfig::groupImpl(const QByteArray &groupName) const
00083 {
00084 const KSharedConfigPtr ptr(const_cast<KSharedConfig*>(this));
00085 return KConfigGroup( ptr, groupName.constData());
00086 }