aboutsummaryrefslogtreecommitdiff
path: root/src/core/kconfig.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/core/kconfig.cpp')
-rw-r--r--src/core/kconfig.cpp303
1 files changed, 173 insertions, 130 deletions
diff --git a/src/core/kconfig.cpp b/src/core/kconfig.cpp
index b311a366..4f5553d5 100644
--- a/src/core/kconfig.cpp
+++ b/src/core/kconfig.cpp
@@ -30,8 +30,14 @@
#include <fcntl.h>
#ifdef Q_OS_WIN
-static inline FILE* popen(const char *cmd, const char *mode) { return _popen(cmd, mode); }
-static inline int pclose(FILE* stream) { return _pclose(stream); }
+static inline FILE *popen(const char *cmd, const char *mode)
+{
+ return _popen(cmd, mode);
+}
+static inline int pclose(FILE *stream)
+{
+ return _pclose(stream);
+}
#else
#include <unistd.h>
#endif
@@ -49,7 +55,7 @@ static inline int pclose(FILE* stream) { return _pclose(stream); }
#include <QtCore/QProcess>
#include <QtCore/QSet>
-bool KConfigPrivate::mappingsRegistered=false;
+bool KConfigPrivate::mappingsRegistered = false;
KConfigPrivate::KConfigPrivate(KConfig::OpenFlags flags,
QStandardPaths::StandardLocation resourceType)
@@ -61,13 +67,14 @@ KConfigPrivate::KConfigPrivate(KConfig::OpenFlags flags,
sGlobalFileName = QStandardPaths::writableLocation(QStandardPaths::GenericConfigLocation) + QLatin1String("/kdeglobals");
static int use_etc_kderc = -1;
- if (use_etc_kderc < 0)
- use_etc_kderc = !qEnvironmentVariableIsSet("KDE_SKIP_KDERC"); // for unit tests
+ if (use_etc_kderc < 0) {
+ use_etc_kderc = !qEnvironmentVariableIsSet("KDE_SKIP_KDERC"); // for unit tests
+ }
if (use_etc_kderc) {
etc_kderc =
#ifdef Q_OS_WIN
- QFile::decodeName( qgetenv("WINDIR") + "/kde4rc" );
+ QFile::decodeName(qgetenv("WINDIR") + "/kde4rc");
#else
QLatin1String("/etc/kde4rc");
#endif
@@ -98,7 +105,6 @@ KConfigPrivate::KConfigPrivate(KConfig::OpenFlags flags,
#endif
}
-
bool KConfigPrivate::lockLocal()
{
if (mBackend) {
@@ -108,10 +114,10 @@ bool KConfigPrivate::lockLocal()
return true;
}
-void KConfigPrivate::copyGroup(const QByteArray& source, const QByteArray& destination,
- KConfigGroup *otherGroup, KConfigBase::WriteConfigFlags flags) const
+void KConfigPrivate::copyGroup(const QByteArray &source, const QByteArray &destination,
+ KConfigGroup *otherGroup, KConfigBase::WriteConfigFlags flags) const
{
- KEntryMap& otherMap = otherGroup->config()->d_ptr->entryMap;
+ KEntryMap &otherMap = otherGroup->config()->d_ptr->entryMap;
const int len = source.length();
const bool sameName = (destination == source);
@@ -120,15 +126,17 @@ void KConfigPrivate::copyGroup(const QByteArray& source, const QByteArray& desti
// as dirty erroneously
bool dirtied = false;
- for (KEntryMap::ConstIterator entryMapIt( entryMap.constBegin() ); entryMapIt != entryMap.constEnd(); ++entryMapIt) {
- const QByteArray& group = entryMapIt.key().mGroup;
+ for (KEntryMap::ConstIterator entryMapIt(entryMap.constBegin()); entryMapIt != entryMap.constEnd(); ++entryMapIt) {
+ const QByteArray &group = entryMapIt.key().mGroup;
- if (!group.startsWith(source)) // nothing to do
+ if (!group.startsWith(source)) { // nothing to do
continue;
+ }
// don't copy groups that start with the same prefix, but are not sub-groups
- if (group.length() > len && group[len] != '\x1d')
+ if (group.length() > len && group[len] != '\x1d') {
continue;
+ }
KEntryKey newKey = entryMapIt.key();
@@ -136,8 +144,9 @@ void KConfigPrivate::copyGroup(const QByteArray& source, const QByteArray& desti
newKey.bLocal = true;
}
- if (!sameName)
+ if (!sameName) {
newKey.mGroup.replace(0, len, destination);
+ }
KEntry entry = entryMap[ entryMapIt.key() ];
dirtied = entry.bDirty = flags & KConfigBase::Persistent;
@@ -154,33 +163,35 @@ void KConfigPrivate::copyGroup(const QByteArray& source, const QByteArray& desti
}
}
-QString KConfigPrivate::expandString(const QString& value)
+QString KConfigPrivate::expandString(const QString &value)
{
QString aValue = value;
// check for environment variables and make necessary translations
- int nDollarPos = aValue.indexOf( QLatin1Char('$') );
- while( nDollarPos != -1 && nDollarPos+1 < aValue.length()) {
+ int nDollarPos = aValue.indexOf(QLatin1Char('$'));
+ while (nDollarPos != -1 && nDollarPos + 1 < aValue.length()) {
// there is at least one $
- if( aValue[nDollarPos+1] == QLatin1Char('(') ) {
- int nEndPos = nDollarPos+1;
+ if (aValue[nDollarPos + 1] == QLatin1Char('(')) {
+ int nEndPos = nDollarPos + 1;
// the next character is not $
- while ( (nEndPos <= aValue.length()) && (aValue[nEndPos]!=QLatin1Char(')')) )
+ while ((nEndPos <= aValue.length()) && (aValue[nEndPos] != QLatin1Char(')'))) {
nEndPos++;
+ }
nEndPos++;
- QString cmd = aValue.mid( nDollarPos+2, nEndPos-nDollarPos-3 );
+ QString cmd = aValue.mid(nDollarPos + 2, nEndPos - nDollarPos - 3);
QString result;
#if 0 // Removed in KDE Frameworks 5. No such concept anymore. Just set your PATH.
- QByteArray oldpath = qgetenv( "PATH" );
+ QByteArray oldpath = qgetenv("PATH");
QByteArray newpath;
if (KComponentData::hasMainComponent()) {
newpath = QFile::encodeName(KGlobal::dirs()->resourceDirs("exe").join(QChar::fromLatin1(KPATH_SEPARATOR)));
- if (!newpath.isEmpty() && !oldpath.isEmpty())
+ if (!newpath.isEmpty() && !oldpath.isEmpty()) {
newpath += KPATH_SEPARATOR;
+ }
}
newpath += oldpath;
- qputenv( "PATH", newpath);
+ qputenv("PATH", newpath);
#endif
// FIXME: wince does not have pipes
@@ -193,58 +204,61 @@ QString KConfigPrivate::expandString(const QString& value)
}
#endif
#if 0 // Removed in KDE Frameworks 5, see above.
- qputenv( "PATH", oldpath);
+ qputenv("PATH", oldpath);
#endif
- aValue.replace( nDollarPos, nEndPos-nDollarPos, result );
+ aValue.replace(nDollarPos, nEndPos - nDollarPos, result);
nDollarPos += result.length();
- } else if( aValue[nDollarPos+1] != QLatin1Char('$') ) {
- int nEndPos = nDollarPos+1;
+ } else if (aValue[nDollarPos + 1] != QLatin1Char('$')) {
+ int nEndPos = nDollarPos + 1;
// the next character is not $
QString aVarName;
- if ( aValue[nEndPos] == QLatin1Char('{') ) {
- while ( (nEndPos <= aValue.length()) && (aValue[nEndPos] != QLatin1Char('}')) )
+ if (aValue[nEndPos] == QLatin1Char('{')) {
+ while ((nEndPos <= aValue.length()) && (aValue[nEndPos] != QLatin1Char('}'))) {
nEndPos++;
+ }
nEndPos++;
- aVarName = aValue.mid( nDollarPos+2, nEndPos-nDollarPos-3 );
+ aVarName = aValue.mid(nDollarPos + 2, nEndPos - nDollarPos - 3);
} else {
- while ( nEndPos <= aValue.length() &&
+ while (nEndPos <= aValue.length() &&
(aValue[nEndPos].isNumber() ||
- aValue[nEndPos].isLetter() ||
- aValue[nEndPos] == QLatin1Char('_') ) )
+ aValue[nEndPos].isLetter() ||
+ aValue[nEndPos] == QLatin1Char('_'))) {
nEndPos++;
- aVarName = aValue.mid( nDollarPos+1, nEndPos-nDollarPos-1 );
+ }
+ aVarName = aValue.mid(nDollarPos + 1, nEndPos - nDollarPos - 1);
}
QString env;
if (!aVarName.isEmpty()) {
#ifdef Q_OS_WIN
- if (aVarName == QLatin1String("HOME"))
+ if (aVarName == QLatin1String("HOME")) {
env = QDir::homePath();
- else
+ } else
#endif
{
QByteArray pEnv = qgetenv(aVarName.toLatin1().constData());
- if( !pEnv.isEmpty() )
+ if (!pEnv.isEmpty()) {
env = QString::fromLocal8Bit(pEnv.constData());
+ }
}
- aValue.replace(nDollarPos, nEndPos-nDollarPos, env);
+ aValue.replace(nDollarPos, nEndPos - nDollarPos, env);
nDollarPos += env.length();
- } else
- aValue.remove( nDollarPos, nEndPos-nDollarPos );
+ } else {
+ aValue.remove(nDollarPos, nEndPos - nDollarPos);
+ }
} else {
// remove one of the dollar signs
- aValue.remove( nDollarPos, 1 );
+ aValue.remove(nDollarPos, 1);
nDollarPos++;
}
- nDollarPos = aValue.indexOf( QLatin1Char('$'), nDollarPos );
+ nDollarPos = aValue.indexOf(QLatin1Char('$'), nDollarPos);
}
return aValue;
}
-
-KConfig::KConfig(const QString& file, OpenFlags mode,
+KConfig::KConfig(const QString &file, OpenFlags mode,
QStandardPaths::StandardLocation resourceType)
- : d_ptr(new KConfigPrivate(mode, resourceType))
+ : d_ptr(new KConfigPrivate(mode, resourceType))
{
d_ptr->changeFileName(file); // set the local file name
@@ -252,7 +266,7 @@ KConfig::KConfig(const QString& file, OpenFlags mode,
reparseConfiguration();
}
-KConfig::KConfig(const QString& file, const QString& backend, QStandardPaths::StandardLocation resourceType)
+KConfig::KConfig(const QString &file, const QString &backend, QStandardPaths::StandardLocation resourceType)
: d_ptr(new KConfigPrivate(SimpleConfig, resourceType))
{
d_ptr->mBackend = KConfigBackend::create(file, backend);
@@ -271,8 +285,9 @@ KConfig::KConfig(KConfigPrivate &d)
KConfig::~KConfig()
{
Q_D(KConfig);
- if (d->bDirty && (d->mBackend && d->mBackend->ref.load() == 1))
+ if (d->bDirty && (d->mBackend && d->mBackend->ref.load() == 1)) {
sync();
+ }
delete d;
}
@@ -281,8 +296,8 @@ QStringList KConfig::groupList() const
Q_D(const KConfig);
QSet<QString> groups;
- for (KEntryMap::ConstIterator entryMapIt( d->entryMap.constBegin() ); entryMapIt != d->entryMap.constEnd(); ++entryMapIt) {
- const KEntryKey& key = entryMapIt.key();
+ for (KEntryMap::ConstIterator entryMapIt(d->entryMap.constBegin()); entryMapIt != d->entryMap.constEnd(); ++entryMapIt) {
+ const KEntryKey &key = entryMapIt.key();
const QByteArray group = key.mGroup;
if (key.mKey.isNull() && !group.isEmpty() && group != "<default>" && group != "$Version") {
const QString groupname = QString::fromUtf8(group);
@@ -293,13 +308,13 @@ QStringList KConfig::groupList() const
return groups.toList();
}
-QStringList KConfigPrivate::groupList(const QByteArray& group) const
+QStringList KConfigPrivate::groupList(const QByteArray &group) const
{
QByteArray theGroup = group + '\x1d';
QSet<QString> groups;
- for (KEntryMap::ConstIterator entryMapIt( entryMap.constBegin() ); entryMapIt != entryMap.constEnd(); ++entryMapIt) {
- const KEntryKey& key = entryMapIt.key();
+ for (KEntryMap::ConstIterator entryMapIt(entryMap.constBegin()); entryMapIt != entryMap.constEnd(); ++entryMapIt) {
+ const KEntryKey &key = entryMapIt.key();
if (key.mKey.isNull() && key.mGroup.startsWith(theGroup)) {
const QString groupname = QString::fromUtf8(key.mGroup.mid(theGroup.length()));
groups << groupname.left(groupname.indexOf(QLatin1Char('\x1d')));
@@ -310,14 +325,14 @@ QStringList KConfigPrivate::groupList(const QByteArray& group) const
}
// List all sub groups, including subsubgroups
-QSet<QByteArray> KConfigPrivate::allSubGroups(const QByteArray& parentGroup) const
+QSet<QByteArray> KConfigPrivate::allSubGroups(const QByteArray &parentGroup) const
{
QSet<QByteArray> groups;
QByteArray theGroup = parentGroup + '\x1d';
groups << parentGroup;
for (KEntryMap::const_iterator entryMapIt = entryMap.begin(); entryMapIt != entryMap.end(); ++entryMapIt) {
- const KEntryKey& key = entryMapIt.key();
+ const KEntryKey &key = entryMapIt.key();
if (key.mKey.isNull() && key.mGroup.startsWith(theGroup)) {
groups << key.mGroup;
}
@@ -325,21 +340,21 @@ QSet<QByteArray> KConfigPrivate::allSubGroups(const QByteArray& parentGroup) con
return groups;
}
-bool KConfigPrivate::hasNonDeletedEntries(const QByteArray& group) const
+bool KConfigPrivate::hasNonDeletedEntries(const QByteArray &group) const
{
const QSet<QByteArray> allGroups = allSubGroups(group);
- Q_FOREACH(const QByteArray& aGroup, allGroups) {
+ Q_FOREACH (const QByteArray &aGroup, allGroups) {
// Could be optimized, let's use the slow way for now
// Check for any non-deleted entry
- if (!keyListImpl(aGroup).isEmpty())
+ if (!keyListImpl(aGroup).isEmpty()) {
return true;
+ }
}
return false;
}
-
-QStringList KConfigPrivate::keyListImpl(const QByteArray& theGroup) const
+QStringList KConfigPrivate::keyListImpl(const QByteArray &theGroup) const
{
QStringList keys;
@@ -350,9 +365,10 @@ QStringList KConfigPrivate::keyListImpl(const QByteArray& theGroup) const
QSet<QString> tmp;
for (; it != theEnd && it.key().mGroup == theGroup; ++it) {
- const KEntryKey& key = it.key();
- if (key.mGroup == theGroup && !key.mKey.isNull() && !it->bDeleted)
+ const KEntryKey &key = it.key();
+ if (key.mGroup == theGroup && !key.mKey.isNull() && !it->bDeleted) {
tmp << QString::fromUtf8(key.mKey);
+ }
}
keys = tmp.toList();
}
@@ -360,14 +376,14 @@ QStringList KConfigPrivate::keyListImpl(const QByteArray& theGroup) const
return keys;
}
-QStringList KConfig::keyList(const QString& aGroup) const
+QStringList KConfig::keyList(const QString &aGroup) const
{
Q_D(const KConfig);
const QByteArray theGroup(aGroup.isEmpty() ? "<default>" : aGroup.toUtf8());
return d->keyListImpl(theGroup);
}
-QMap<QString,QString> KConfig::entryMap(const QString& aGroup) const
+QMap<QString, QString> KConfig::entryMap(const QString &aGroup) const
{
Q_D(const KConfig);
QMap<QString, QString> theMap;
@@ -386,9 +402,9 @@ QMap<QString,QString> KConfig::entryMap(const QString& aGroup) const
// with the non-localized entry
if (!theMap.contains(key)) {
if (it->bExpand) {
- theMap.insert(key,KConfigPrivate::expandString(QString::fromUtf8(it->mValue.constData())));
+ theMap.insert(key, KConfigPrivate::expandString(QString::fromUtf8(it->mValue.constData())));
} else {
- theMap.insert(key,QString::fromUtf8(it->mValue.constData()));
+ theMap.insert(key, QString::fromUtf8(it->mValue.constData()));
}
}
}
@@ -422,7 +438,7 @@ bool KConfig::sync()
// Rewrite global/local config only if there is a dirty entry in it.
bool writeGlobals = false;
bool writeLocals = false;
- Q_FOREACH (const KEntry& e, d->entryMap) {
+ Q_FOREACH (const KEntry &e, d->entryMap) {
if (e.bDirty) {
if (e.bGlobal) {
writeGlobals = true;
@@ -472,8 +488,9 @@ void KConfig::markAsClean()
// clear any dirty flags that entries might have set
const KEntryMapIterator theEnd = d->entryMap.end();
- for (KEntryMapIterator it = d->entryMap.begin(); it != theEnd; ++it)
+ for (KEntryMapIterator it = d->entryMap.begin(); it != theEnd; ++it) {
it->bDirty = false;
+ }
}
bool KConfig::isDirty() const
@@ -485,7 +502,7 @@ bool KConfig::isDirty() const
void KConfig::checkUpdate(const QString &id, const QString &updateFile)
{
const KConfigGroup cg(this, "$Version");
- const QString cfg_id = updateFile+QLatin1Char(':')+id;
+ const QString cfg_id = updateFile + QLatin1Char(':') + id;
const QStringList ids = cg.readEntry("update_info", QStringList());
if (!ids.contains(cfg_id)) {
#if 0
@@ -497,18 +514,20 @@ void KConfig::checkUpdate(const QString &id, const QString &updateFile)
}
}
-KConfig* KConfig::copyTo(const QString &file, KConfig *config) const
+KConfig *KConfig::copyTo(const QString &file, KConfig *config) const
{
Q_D(const KConfig);
- if (!config)
+ if (!config) {
config = new KConfig(QString(), SimpleConfig, d->resourceType);
+ }
config->d_func()->changeFileName(file);
config->d_func()->entryMap = d->entryMap;
config->d_func()->bFileImmutable = false;
const KEntryMapIterator theEnd = config->d_func()->entryMap.end();
- for (KEntryMapIterator it = config->d_func()->entryMap.begin(); it != theEnd; ++it)
+ for (KEntryMapIterator it = config->d_func()->entryMap.begin(); it != theEnd; ++it) {
it->bDirty = true;
+ }
config->d_ptr->bDirty = true;
return config;
@@ -522,7 +541,7 @@ QString KConfig::name() const
Q_GLOBAL_STATIC(QString, globalMainConfigName)
-void KConfig::setMainConfigName(const QString& str)
+void KConfig::setMainConfigName(const QString &str)
{
*globalMainConfigName() = str;
}
@@ -531,20 +550,21 @@ QString KConfig::mainConfigName()
{
// --config on the command line overrides everything else
const QStringList args = QCoreApplication::arguments();
- for (int i = 1; i < args.count() ; ++i) {
- if (args.at(i) == QLatin1String("--config") && i < args.count()-1) {
- return args.at(i+1);
+ for (int i = 1; i < args.count(); ++i) {
+ if (args.at(i) == QLatin1String("--config") && i < args.count() - 1) {
+ return args.at(i + 1);
}
}
const QString globalName = *globalMainConfigName();
- if (!globalName.isEmpty())
+ if (!globalName.isEmpty()) {
return globalName;
+ }
QString appName = QCoreApplication::applicationName();
return appName + QLatin1String("rc");
}
-void KConfigPrivate::changeFileName(const QString& name)
+void KConfigPrivate::changeFileName(const QString &name)
{
fileName = name;
@@ -564,8 +584,9 @@ void KConfigPrivate::changeFileName(const QString& name)
}
} else if (QDir::isAbsolutePath(fileName)) {
fileName = QFileInfo(fileName).canonicalFilePath();
- if (fileName.isEmpty()) // file doesn't exist (yet)
+ if (fileName.isEmpty()) { // file doesn't exist (yet)
fileName = name;
+ }
file = fileName;
} else {
file = QStandardPaths::writableLocation(resourceType) + QLatin1Char('/') + fileName;
@@ -579,10 +600,11 @@ void KConfigPrivate::changeFileName(const QString& name)
bSuppressGlobal = (file.compare(sGlobalFileName, Qt::CaseInsensitive) == 0);
#endif
- if (bDynamicBackend || !mBackend) // allow dynamic changing of backend
+ if (bDynamicBackend || !mBackend) { // allow dynamic changing of backend
mBackend = KConfigBackend::create(file);
- else
+ } else {
mBackend->setFilePath(file);
+ }
configState = mBackend->accessMode();
}
@@ -595,30 +617,34 @@ void KConfig::reparseConfiguration()
}
// Don't lose pending changes
- if (!d->isReadOnly() && d->bDirty)
+ if (!d->isReadOnly() && d->bDirty) {
sync();
+ }
d->entryMap.clear();
d->bFileImmutable = false;
// Parse all desired files from the least to the most specific.
- if (d->wantGlobals())
+ if (d->wantGlobals()) {
d->parseGlobalFiles();
+ }
d->parseConfigFiles();
}
-
QStringList KConfigPrivate::getGlobalFiles() const
{
QStringList globalFiles;
- Q_FOREACH (const QString& dir1, QStandardPaths::locateAll(QStandardPaths::GenericConfigLocation, QLatin1String("kdeglobals")))
+ Q_FOREACH (const QString &dir1, QStandardPaths::locateAll(QStandardPaths::GenericConfigLocation, QLatin1String("kdeglobals"))) {
globalFiles.push_front(dir1);
- Q_FOREACH (const QString& dir2, QStandardPaths::locateAll(QStandardPaths::GenericConfigLocation, QLatin1String("system.kdeglobals")))
+ }
+ Q_FOREACH (const QString &dir2, QStandardPaths::locateAll(QStandardPaths::GenericConfigLocation, QLatin1String("system.kdeglobals"))) {
globalFiles.push_front(dir2);
- if (!etc_kderc.isEmpty())
+ }
+ if (!etc_kderc.isEmpty()) {
globalFiles.push_front(etc_kderc);
+ }
return globalFiles;
}
@@ -630,8 +656,8 @@ void KConfigPrivate::parseGlobalFiles()
// TODO: can we cache the values in etc_kderc / other global files
// on a per-application basis?
const QByteArray utf8Locale = locale.toUtf8();
- Q_FOREACH(const QString& file, globalFiles) {
- KConfigBackend::ParseOptions parseOpts = KConfigBackend::ParseGlobal|KConfigBackend::ParseExpansions;
+ Q_FOREACH (const QString &file, globalFiles) {
+ KConfigBackend::ParseOptions parseOpts = KConfigBackend::ParseGlobal | KConfigBackend::ParseExpansions;
#ifndef Q_OS_WIN
if (file != sGlobalFileName)
#else
@@ -640,8 +666,9 @@ void KConfigPrivate::parseGlobalFiles()
parseOpts |= KConfigBackend::ParseDefaults;
QExplicitlySharedDataPointer<KConfigBackend> backend = KConfigBackend::create(file);
- if ( backend->parseConfig( utf8Locale, entryMap, parseOpts) == KConfigBackend::ParseImmutable)
+ if (backend->parseConfig(utf8Locale, entryMap, parseOpts) == KConfigBackend::ParseImmutable) {
break;
+ }
}
}
@@ -660,20 +687,22 @@ void KConfigPrivate::parseConfigFiles()
if (QDir::isAbsolutePath(fileName)) {
files << fileName;
} else {
- Q_FOREACH (const QString& f, QStandardPaths::locateAll(resourceType, fileName))
+ Q_FOREACH (const QString &f, QStandardPaths::locateAll(resourceType, fileName)) {
files.prepend(f);
+ }
}
}
} else {
files << mBackend->filePath();
}
- if (!isSimple())
+ if (!isSimple()) {
files = extraFiles.toList() + files;
+ }
// qDebug() << "parsing local files" << files;
const QByteArray utf8Locale = locale.toUtf8();
- foreach(const QString& file, files) {
+ foreach (const QString &file, files) {
#ifndef Q_OS_WIN
if (file == mBackend->filePath()) {
#else
@@ -692,17 +721,19 @@ void KConfigPrivate::parseConfigFiles()
} else {
QExplicitlySharedDataPointer<KConfigBackend> backend = KConfigBackend::create(file);
bFileImmutable = (backend->parseConfig(utf8Locale, entryMap,
- KConfigBackend::ParseDefaults|KConfigBackend::ParseExpansions)
+ KConfigBackend::ParseDefaults | KConfigBackend::ParseExpansions)
== KConfigBackend::ParseImmutable);
}
- if (bFileImmutable)
+ if (bFileImmutable) {
break;
+ }
}
#pragma message("TODO: enable kiosk feature again (resource restrictions), but without KStandardDirs... Needs a class in the kconfig framework.")
#if 0
- if (componentData.dirs()->isRestrictedResource(resourceType, fileName))
+ if (componentData.dirs()->isRestrictedResource(resourceType, fileName)) {
bFileImmutable = true;
+ }
#endif
}
}
@@ -713,10 +744,10 @@ KConfig::AccessMode KConfig::accessMode() const
return d->configState;
}
-void KConfig::addConfigSources(const QStringList& files)
+void KConfig::addConfigSources(const QStringList &files)
{
Q_D(KConfig);
- Q_FOREACH(const QString& file, files) {
+ Q_FOREACH (const QString &file, files) {
d->extraFiles.push(file);
}
@@ -731,7 +762,7 @@ QString KConfig::locale() const
return d->locale;
}
-bool KConfigPrivate::setLocale(const QString& aLocale)
+bool KConfigPrivate::setLocale(const QString &aLocale)
{
if (aLocale != locale) {
locale = aLocale;
@@ -740,7 +771,7 @@ bool KConfigPrivate::setLocale(const QString& aLocale)
return false;
}
-bool KConfig::setLocale(const QString& locale)
+bool KConfig::setLocale(const QString &locale)
{
Q_D(KConfig);
if (d->setLocale(locale)) {
@@ -768,7 +799,7 @@ bool KConfig::isImmutable() const
return d->bFileImmutable;
}
-bool KConfig::isGroupImmutableImpl(const QByteArray& aGroup) const
+bool KConfig::isGroupImmutableImpl(const QByteArray &aGroup) const
{
Q_D(const KConfig);
return isImmutable() || d->entryMap.getEntryOption(aGroup, 0, 0, KEntryMap::EntryImmutable);
@@ -802,26 +833,29 @@ const KConfigGroup KConfig::groupImpl(const QByteArray &group) const
KEntryMap::EntryOptions convertToOptions(KConfig::WriteConfigFlags flags)
{
- KEntryMap::EntryOptions options=0;
+ KEntryMap::EntryOptions options = 0;
- if (flags&KConfig::Persistent)
+ if (flags & KConfig::Persistent) {
options |= KEntryMap::EntryDirty;
- if (flags&KConfig::Global)
+ }
+ if (flags & KConfig::Global) {
options |= KEntryMap::EntryGlobal;
- if (flags&KConfig::Localized)
+ }
+ if (flags & KConfig::Localized) {
options |= KEntryMap::EntryLocalized;
+ }
return options;
}
void KConfig::deleteGroupImpl(const QByteArray &aGroup, WriteConfigFlags flags)
{
Q_D(KConfig);
- KEntryMap::EntryOptions options = convertToOptions(flags)|KEntryMap::EntryDeleted;
+ KEntryMap::EntryOptions options = convertToOptions(flags) | KEntryMap::EntryDeleted;
const QSet<QByteArray> groups = d->allSubGroups(aGroup);
- Q_FOREACH (const QByteArray& group, groups) {
+ Q_FOREACH (const QByteArray &group, groups) {
const QStringList keys = d->keyListImpl(group);
- Q_FOREACH (const QString& _key, keys) {
+ Q_FOREACH (const QString &_key, keys) {
const QByteArray &key = _key.toUtf8();
if (d->canWriteEntry(group, key.constData())) {
d->entryMap.setEntry(group, key, QByteArray(), options);
@@ -838,14 +872,14 @@ bool KConfig::isConfigWritable(bool warnUser)
if (warnUser && !allWritable) {
QString errorMsg;
- if (d->mBackend) // TODO how can be it be null? Set errorMsg appropriately
+ if (d->mBackend) { // TODO how can be it be null? Set errorMsg appropriately
errorMsg = d->mBackend->nonWritableErrorMessage();
+ }
// Note: We don't ask the user if we should not ask this question again because we can't save the answer.
errorMsg += QCoreApplication::translate("KConfig", "Please contact your system administrator.");
QString cmdToExec = QStandardPaths::findExecutable(QString::fromLatin1("kdialog"));
- if (!cmdToExec.isEmpty())
- {
+ if (!cmdToExec.isEmpty()) {
QProcess::execute(cmdToExec, QStringList()
<< QString::fromLatin1("--title") << QCoreApplication::applicationName()
<< QString::fromLatin1("--msgbox") << errorMsg);
@@ -857,7 +891,7 @@ bool KConfig::isConfigWritable(bool warnUser)
return allWritable;
}
-bool KConfig::hasGroupImpl(const QByteArray& aGroup) const
+bool KConfig::hasGroupImpl(const QByteArray &aGroup) const
{
Q_D(const KConfig);
@@ -867,55 +901,64 @@ bool KConfig::hasGroupImpl(const QByteArray& aGroup) const
return d->hasNonDeletedEntries(aGroup);
}
-bool KConfigPrivate::canWriteEntry(const QByteArray& group, const char* key, bool isDefault) const
+bool KConfigPrivate::canWriteEntry(const QByteArray &group, const char *key, bool isDefault) const
{
if (bFileImmutable ||
- entryMap.getEntryOption(group, key, KEntryMap::SearchLocalized, KEntryMap::EntryImmutable))
+ entryMap.getEntryOption(group, key, KEntryMap::SearchLocalized, KEntryMap::EntryImmutable)) {
return isDefault;
+ }
return true;
}
-void KConfigPrivate::putData( const QByteArray& group, const char* key,
- const QByteArray& value, KConfigBase::WriteConfigFlags flags, bool expand)
+void KConfigPrivate::putData(const QByteArray &group, const char *key,
+ const QByteArray &value, KConfigBase::WriteConfigFlags flags, bool expand)
{
KEntryMap::EntryOptions options = convertToOptions(flags);
- if (bForceGlobal)
+ if (bForceGlobal) {
options |= KEntryMap::EntryGlobal;
- if (expand)
+ }
+ if (expand) {
options |= KEntryMap::EntryExpansion;
+ }
- if (value.isNull()) // deleting entry
+ if (value.isNull()) { // deleting entry
options |= KEntryMap::EntryDeleted;
+ }
bool dirtied = entryMap.setEntry(group, key, value, options);
- if (dirtied && (flags & KConfigBase::Persistent))
+ if (dirtied && (flags & KConfigBase::Persistent)) {
bDirty = true;
+ }
}
-void KConfigPrivate::revertEntry(const QByteArray& group, const char* key)
+void KConfigPrivate::revertEntry(const QByteArray &group, const char *key)
{
bool dirtied = entryMap.revertEntry(group, key);
- if (dirtied)
+ if (dirtied) {
bDirty = true;
+ }
}
-QByteArray KConfigPrivate::lookupData(const QByteArray& group, const char* key,
+QByteArray KConfigPrivate::lookupData(const QByteArray &group, const char *key,
KEntryMap::SearchFlags flags) const
{
- if (bReadDefaults)
+ if (bReadDefaults) {
flags |= KEntryMap::SearchDefaults;
+ }
const KEntryMapConstIterator it = entryMap.findEntry(group, key, flags);
- if (it == entryMap.constEnd())
+ if (it == entryMap.constEnd()) {
return QByteArray();
+ }
return it->mValue;
}
-QString KConfigPrivate::lookupData(const QByteArray& group, const char* key,
+QString KConfigPrivate::lookupData(const QByteArray &group, const char *key,
KEntryMap::SearchFlags flags, bool *expand) const
{
- if (bReadDefaults)
+ if (bReadDefaults) {
flags |= KEntryMap::SearchDefaults;
+ }
return entryMap.getEntry(group, key, QString(), flags, expand);
}
@@ -925,7 +968,7 @@ QStandardPaths::StandardLocation KConfig::locationType() const
return d->resourceType;
}
-void KConfig::virtual_hook(int /*id*/, void* /*data*/)
+void KConfig::virtual_hook(int /*id*/, void * /*data*/)
{
- /* nothing */
+ /* nothing */
}