diff --git a/autotests/kentrymaptest.h b/autotests/kentrymaptest.h --- a/autotests/kentrymaptest.h +++ b/autotests/kentrymaptest.h @@ -43,6 +43,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(); @@ -52,6 +53,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 @@ -199,3 +199,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 @@ -71,6 +71,11 @@ bool bLocalizedCountry: 1; bool bNotify: 1; + + /** + * Entry will need to be wrote on a not global file even if it match default value + */ + bool bForceSave: 1; }; // These operators are used to check whether an entry which is about @@ -175,6 +180,7 @@ EntryRawKey = 32, EntryLocalizedCountry = 64, EntryNotify = 128, + EntryForceSave = 256, EntryDefault = (SearchDefaults << 16), EntryLocalized = (SearchLocalized << 16) }; diff --git a/src/core/kconfigdata.cpp b/src/core/kconfigdata.cpp --- a/src/core/kconfigdata.cpp +++ b/src/core/kconfigdata.cpp @@ -136,6 +136,13 @@ e.bDirty = e.bDirty || (options & EntryDirty); e.bNotify = e.bNotify || (options & EntryNotify); + // If overidded entry is global and not default. And it's overrided by a non global + if (e.bGlobal && !(options & EntryGlobal) && !k.bDefault) + { + e.bForceSave = true; + } + e.bForceSave = e.bForceSave || (options & EntryForceSave); + e.bGlobal = (options & EntryGlobal); //we can't use || here, because changes to entries in //kdeglobals would be written to kdeglobals instead //of the local config file, regardless of the globals flag diff --git a/src/core/kconfigini.cpp b/src/core/kconfigini.cpp --- a/src/core/kconfigini.cpp +++ b/src/core/kconfigini.cpp @@ -442,7 +442,7 @@ // only write entries that have the same "globality" as the file if (it->bGlobal == bGlobal) { - if (it->bReverted) { + if (it->bReverted && !it->bForceSave) { writeMap.remove(key); } else if (!it->bDeleted) { writeMap[key] = *it;