diff options
author | Jenkins CI <null@kde.org> | 2013-12-18 00:45:18 +0000 |
---|---|---|
committer | Jenkins CI <null@kde.org> | 2013-12-18 00:45:18 +0000 |
commit | c38b88497a833e482e6892b72c8f52adec6de857 (patch) | |
tree | 8c2d4b788cf54ab2179ffe53515d276feaeba2d1 /tier1/kconfig/src/core/ksharedconfig.cpp | |
download | kconfig-c38b88497a833e482e6892b72c8f52adec6de857.tar.gz kconfig-c38b88497a833e482e6892b72c8f52adec6de857.tar.bz2 |
Initial import from the monolithic kdelibs.
This is the beginning of revision history for this module. If you
want to look at revision history older than this, please refer to the
techbase wiki for how to use Git history grafting. At the time of
writing, this wiki is located here:
http://community.kde.org/Frameworks/GitOldHistory
If you have already performed the grafting and you don't see any
history beyond this commit, try running "git log" with the "--follow"
argument.
Branched from the monolithic repo, kdelibs frameworks branch, at commit
162066dbbecde401a7347a1cff4fe72a9c919f58
Diffstat (limited to 'tier1/kconfig/src/core/ksharedconfig.cpp')
-rw-r--r-- | tier1/kconfig/src/core/ksharedconfig.cpp | 122 |
1 files changed, 122 insertions, 0 deletions
diff --git a/tier1/kconfig/src/core/ksharedconfig.cpp b/tier1/kconfig/src/core/ksharedconfig.cpp new file mode 100644 index 00000000..0e5d1959 --- /dev/null +++ b/tier1/kconfig/src/core/ksharedconfig.cpp @@ -0,0 +1,122 @@ +/* + This file is part of the KDE libraries + Copyright (c) 1999 Preston Brown <pbrown@kde.org> + Copyright (C) 1997-1999 Matthias Kalle Dalheimer (kalle@kde.org) + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public License + along with this library; see the file COPYING.LIB. If not, write to + the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + Boston, MA 02110-1301, USA. +*/ + +#include "ksharedconfig.h" +#include "kconfigbackend.h" +#include "kconfiggroup.h" +#include "kconfig_p.h" +#include <QCoreApplication> + +void _k_globalMainConfigSync(); + +class GlobalSharedConfigList : public QList<KSharedConfig*> +{ +public: + GlobalSharedConfigList() + { + // We want to force the sync() before the QCoreApplication + // instance is gone. Otherwise we trigger a QLockFile::lock() + // after QCoreApplication is gone, calling qAppName() for a non + // existent app... + qAddPostRoutine(&_k_globalMainConfigSync); + } + + // in addition to the list, we need to hold the main config, + // so that it's not created and destroyed all the time. + KSharedConfigPtr mainConfig; +}; + + +Q_GLOBAL_STATIC(GlobalSharedConfigList, globalSharedConfigList) + +void _k_globalMainConfigSync() +{ + if (globalSharedConfigList->mainConfig) + globalSharedConfigList->mainConfig->sync(); +} + + +KSharedConfigPtr KSharedConfig::openConfig(const QString& _fileName, + OpenFlags flags, + QStandardPaths::StandardLocation resType) +{ + QString fileName(_fileName); + GlobalSharedConfigList *list = globalSharedConfigList(); + if (fileName.isEmpty() && !flags.testFlag(KConfig::SimpleConfig)) { + // Determine the config file name that KConfig will make up (see KConfigPrivate::changeFileName) + fileName = KConfig::mainConfigName(); + } + + if (list) { + for(QList<KSharedConfig*>::ConstIterator it = list->constBegin(); it != list->constEnd(); ++it) { + if ( (*it)->name() == fileName && + (*it)->d_ptr->openFlags == flags && + (*it)->locationType() == resType +// (*it)->backEnd()->type() == backEnd + ) { + return KSharedConfigPtr(*it); + } + } + } + KSharedConfigPtr ptr(new KSharedConfig(fileName, flags, resType)); + if (_fileName.isEmpty() && flags == FullConfig && resType == QStandardPaths::GenericConfigLocation) { + list->mainConfig = ptr; + + static bool userWarned = false; + if (!userWarned) { + userWarned = true; + QByteArray readOnly = qgetenv("KDE_HOME_READONLY"); + if (readOnly.isEmpty() && QCoreApplication::applicationName() != QLatin1String("kdialog")) { + if (ptr->group("General").readEntry(QLatin1String("warn_unwritable_config"), true)) + ptr->isConfigWritable(true); + } + } + } + + return ptr; +} + + +KSharedConfig::KSharedConfig(const QString &fileName, + OpenFlags flags, + QStandardPaths::StandardLocation resType) + : KConfig(fileName, flags, resType) +{ + globalSharedConfigList()->append(this); +} + +KSharedConfig::~KSharedConfig() +{ + if (!globalSharedConfigList.isDestroyed()) + globalSharedConfigList()->removeAll(this); +} + +KConfigGroup KSharedConfig::groupImpl(const QByteArray &groupName) +{ + KSharedConfigPtr ptr(this); + return KConfigGroup( ptr, groupName.constData()); +} + +const KConfigGroup KSharedConfig::groupImpl(const QByteArray &groupName) const +{ + const KSharedConfigPtr ptr(const_cast<KSharedConfig*>(this)); + return KConfigGroup( ptr, groupName.constData()); +} |