SVN commit 1195170 by dfaure: Make it possible to change the save location for a resource, using a new relative path. (Was looking for this in order to make kconfigtest not delete my kdebugrc). Led to an interesting discussion with coolo and his old memories of the code :) M +16 -8 kernel/kstandarddirs.cpp M +11 -0 tests/kstandarddirstest.cpp M +1 -0 tests/kstandarddirstest.h --- trunk/KDE/kdelibs/kdecore/kernel/kstandarddirs.cpp #1195169:1195170 @@ -96,8 +96,9 @@ QStringList m_prefixes; // Directory dictionaries - QMap m_absolutes; - QMap m_relatives; + QMap m_absolutes; // For each resource type, the list of absolute paths, from most local (most priority) to most global + QMap m_relatives; // Same with relative paths + // The search path is "all relative paths" < "all absolute paths", from most priority to least priority. // Caches (protected by mutex in const methods, cf ctor docu) QMap m_dircache; @@ -413,7 +414,9 @@ rels.prepend(copy); else rels.append(copy); - d->m_dircache.remove(type); // clean the cache + // clean the caches + d->m_dircache.remove(type); + d->m_savelocations.remove(type); return true; } return false; @@ -436,7 +439,9 @@ paths.prepend(copy); else paths.append(copy); - d->m_dircache.remove(type); // clean the cache + // clean the caches + d->m_dircache.remove(type); + d->m_savelocations.remove(type); return true; } return false; @@ -1481,7 +1486,7 @@ } if (!dirs.isEmpty()) { - path = dirs.last(); + path = dirs.first(); if (path.startsWith(QLatin1Char('%'))) { // grab the "data" from "%data/apps" @@ -1505,8 +1510,9 @@ dirs = d->m_absolutes.value(type); if (dirs.isEmpty()) { qFatal("KStandardDirs: The resource type %s is not registered", type); + } else { + path = realPath(dirs.first()); } - path = realPath(dirs.last()); } d->m_savelocations.insert(type, path.endsWith(QLatin1Char('/')) ? path : path + QLatin1Char('/')); @@ -2030,8 +2036,10 @@ if (!cg.readEntry(key, true)) { d->m_restrictionsActive = true; - d->m_restrictions.insert(key.toLatin1(), true); - d->m_dircache.remove(key.toLatin1()); + const QByteArray cKey = key.toLatin1(); + d->m_restrictions.insert(cKey, true); + d->m_dircache.remove(cKey); + d->m_savelocations.remove(cKey); } } } --- trunk/KDE/kdelibs/kdecore/tests/kstandarddirstest.cpp #1195169:1195170 @@ -66,6 +66,17 @@ QCOMPARE_PATHS( fooAppData, m_kdehome + "/share/apps/foo/" ); } +void KStandarddirsTest::testChangeSaveLocation() +{ + KComponentData cData("changeSave"); + QCOMPARE_PATHS(cData.dirs()->saveLocation("config"), m_kdehome + "/share/config/"); + // Can we change the save location? + const QString newSaveLoc = m_kdehome + "/newconfigdir/"; + //cData.dirs()->addResourceDir("config", newSaveLoc); // can't be done, absolute paths have less priority than relative paths + cData.dirs()->addResourceType("config", 0, "newconfigdir"); + QCOMPARE_PATHS(cData.dirs()->saveLocation("config"), newSaveLoc); +} + static bool isKdelibsInstalled() { // If there's only one dir, it's the local one (~/.kde-unit-test/share/apps/), --- trunk/KDE/kdelibs/kdecore/tests/kstandarddirstest.h #1195169:1195170 @@ -29,6 +29,7 @@ void testLocateLocal(); void testSaveLocation(); void testAppData(); + void testChangeSaveLocation(); void testFindResource(); void testFindAllResources(); void testFindAllResourcesNewDir();