KDECore
ksharedconfig.cpp
Go to the documentation of this file.
00001 /* 00002 This file is part of the KDE libraries 00003 Copyright (c) 1999 Preston Brown <pbrown@kde.org> 00004 Copyright (C) 1997-1999 Matthias Kalle Dalheimer (kalle@kde.org) 00005 00006 This library is free software; you can redistribute it and/or 00007 modify it under the terms of the GNU Library General Public 00008 License as published by the Free Software Foundation; either 00009 version 2 of the License, or (at your option) any later version. 00010 00011 This library is distributed in the hope that it will be useful, 00012 but WITHOUT ANY WARRANTY; without even the implied warranty of 00013 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00014 Library General Public License for more details. 00015 00016 You should have received a copy of the GNU Library General Public License 00017 along with this library; see the file COPYING.LIB. If not, write to 00018 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 00019 Boston, MA 02110-1301, USA. 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 // qstrcmp((*it)->resource(), resType) == 0 && 00049 // (*it)->backEnd()->type() == backEnd && 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 }
KDE 4.6 API Reference