diff --git a/autotests/kconfigtest.h b/autotests/kconfigtest.h --- a/autotests/kconfigtest.h +++ b/autotests/kconfigtest.h @@ -73,6 +73,8 @@ void testThreads(); + void testKdeglobalsVSDefault(); + // should be last void testSyncOnExit(); }; diff --git a/autotests/kconfigtest.cpp b/autotests/kconfigtest.cpp --- a/autotests/kconfigtest.cpp +++ b/autotests/kconfigtest.cpp @@ -1949,3 +1949,23 @@ QCOMPARE(otherWatcherSpy[0][0].value().name(), QStringLiteral("TopLevelGroup")); QCOMPARE(otherWatcherSpy[0][1].value(), QByteArrayList({"someGlobalEntry"})); } + +void KConfigTest::testKdeglobalsVSDefault() +{ + 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"); + QCOMPARE(generalLocal.readEntry("testRestore", "defaultcpp"), "global"); + generalLocal.writeEntry("testRestore", "restore"); + QVERIFY(local.sync()); + QCOMPARE(generalLocal.readEntry("testRestore", "defaultcpp"), "restore"); + + generalLocal.revertToDefault("testRestore"); + local.sync(); + local.reparseConfiguration(); + QCOMPARE(generalLocal.readEntry("testRestore", "defaultcpp"), "defaultcpp"); +} diff --git a/autotests/kentrymaptest.h b/autotests/kentrymaptest.h --- a/autotests/kentrymaptest.h +++ b/autotests/kentrymaptest.h @@ -30,6 +30,7 @@ static const EntryOption EntryExpansion = KEntryMap::EntryExpansion; static const EntryOption EntryDefault = KEntryMap::EntryDefault; static const EntryOption EntryLocalized = KEntryMap::EntryLocalized; + static const EntryOption EntryForceSave = KEntryMap::EntryForceSave; private Q_SLOTS: void testKeyOrder(); void testSimple(); @@ -39,6 +40,7 @@ void testGlobal(); void testImmutable(); void testLocale(); + void testForceSave(); }; #endif // KENTRYMAPTEST_H diff --git a/autotests/kentrymaptest.cpp b/autotests/kentrymaptest.cpp --- a/autotests/kentrymaptest.cpp +++ b/autotests/kentrymaptest.cpp @@ -186,3 +186,14 @@ map.setEntry(group1, key1, translated, EntryLocalized); // set the translated entry to a different locale QCOMPARE(map.findEntry(group1, key1, SearchLocalized)->mValue, translated); } + +void KEntryMapTest::testForceSave() +{ + KEntryMap map; + + map.setEntry(group1, key1, value1, EntryForceSave); + QCOMPARE(map.findEntry(group1, key1)->bForceSave, true); // verify the force save bit is set + + map.setEntry(group1, key1, value1, EntryOptions()); + QCOMPARE(map.findEntry(group1, key1)->bForceSave, true); // verify the force save bit is still set +} diff --git a/src/core/kconfigdata.h b/src/core/kconfigdata.h --- a/src/core/kconfigdata.h +++ b/src/core/kconfigdata.h @@ -24,7 +24,7 @@ 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 @@ bool bLocalizedCountry: 1; bool bNotify: 1; + + /** + * Entry will need to be written on a not global file even if it matches default value + */ + bool bOverridesGlobal: 1; }; // These operators are used to check whether an entry which is about diff --git a/src/core/kconfigdata.cpp b/src/core/kconfigdata.cpp --- a/src/core/kconfigdata.cpp +++ b/src/core/kconfigdata.cpp @@ -100,6 +100,11 @@ 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; diff --git a/src/core/kconfigini.cpp b/src/core/kconfigini.cpp --- a/src/core/kconfigini.cpp +++ b/src/core/kconfigini.cpp @@ -429,7 +429,10 @@ // 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;