Add force save behavior to KEntryMap

Summary:
Fix the following bug, if an entry is set on HOME/.config/kdeglobals and on a specific config file like kcmfonts
When you hit restore defaults button and apply, value will be not wrote on the specific file, but then the value is the one from kdeglobals
This patch ensure we write the key to the specific configuration file on those case with an empty value. KConfig will take default value automatically

Test Plan:
Added a test to ensure flag is working
Tested using some KCM to ensure all is working fine

Reviewers: ervin, dfaure, meven, crossi, hchain

Reviewed By: ervin, dfaure, meven

Subscribers: kde-frameworks-devel

Tags: #frameworks

Differential Revision: https://phabricator.kde.org/D28128
wilder
Benjamin Port 6 years ago
parent 65cc12ab3e
commit be28e096c5
  1. 27
      autotests/kconfigtest.cpp
  2. 2
      autotests/kconfigtest.h
  3. 4
      src/core/kconfigdata.cpp
  4. 7
      src/core/kconfigdata.h
  5. 5
      src/core/kconfigini.cpp

@ -1949,3 +1949,30 @@ void KConfigTest::testNotify()
QCOMPARE(otherWatcherSpy[0][0].value<KConfigGroup>().name(), QStringLiteral("TopLevelGroup"));
QCOMPARE(otherWatcherSpy[0][1].value<QByteArrayList>(), QByteArrayList({"someGlobalEntry"}));
}
void KConfigTest::testKdeglobalsVsDefault()
{
// Add testRestore key with global value in kdeglobals
KConfig glob(QStringLiteral("kdeglobals"));
KConfigGroup generalGlob(&glob, "General");
generalGlob.writeEntry("testRestore", "global");
QVERIFY(glob.sync());
KConfig local(QStringLiteral(TEST_SUBDIR "restorerc"));
KConfigGroup generalLocal(&local, "General");
// Check if we get global and not the default value from cpp (defaultcpp) when reading data from restorerc
QCOMPARE(generalLocal.readEntry("testRestore", "defaultcpp"), "global");
// Add test restore key with restore value in restorerc file
generalLocal.writeEntry("testRestore", "restore");
QVERIFY(local.sync());
local.reparseConfiguration();
// We expect to get the value from restorerc file
QCOMPARE(generalLocal.readEntry("testRestore", "defaultcpp"), "restore");
// Revert to default testRestore key and we expect to get default value and not the global one
generalLocal.revertToDefault("testRestore");
local.sync();
local.reparseConfiguration();
QCOMPARE(generalLocal.readEntry("testRestore", "defaultcpp"), "defaultcpp");
}

@ -73,6 +73,8 @@ private Q_SLOTS:
void testThreads();
void testKdeglobalsVsDefault();
// should be last
void testSyncOnExit();
};

@ -100,6 +100,10 @@ bool KEntryMap::setEntry(const QByteArray &group, const QByteArray &key, const Q
k = it.key();
e = *it;
//qDebug() << "found existing entry for key" << k;
// If overridden entry is global and not default. And it's overridden by a non global
if (e.bGlobal && !(options & EntryGlobal) && !k.bDefault) {
e.bOverridesGlobal = true;
}
} else {
// make sure the group marker is in the map
KEntryMap const *that = this;

@ -24,7 +24,7 @@ struct KEntry {
KEntry()
: mValue(), bDirty(false),
bGlobal(false), bImmutable(false), bDeleted(false), bExpand(false), bReverted(false),
bLocalizedCountry(false), bNotify(false) {}
bLocalizedCountry(false), bNotify(false), bOverridesGlobal(false) {}
/** @internal */
QByteArray mValue;
/**
@ -58,6 +58,11 @@ struct KEntry {
bool bLocalizedCountry: 1;
bool bNotify: 1;
/**
* Entry will need to be written on a non global file even if it matches default value
*/
bool bOverridesGlobal: 1;
};
// These operators are used to check whether an entry which is about

@ -429,7 +429,10 @@ bool KConfigIniBackend::writeConfig(const QByteArray &locale, KEntryMap &entryMa
// only write entries that have the same "globality" as the file
if (it->bGlobal == bGlobal) {
if (it->bReverted) {
if (it->bReverted && it->bOverridesGlobal) {
it->bDeleted = true;
writeMap[key] = *it;
} else if (it->bReverted) {
writeMap.remove(key);
} else if (!it->bDeleted) {
writeMap[key] = *it;

Loading…
Cancel
Save