aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--autotests/kconfigtest.cpp34
-rw-r--r--autotests/kconfigtest.h1
-rw-r--r--docs/options.md6
-rw-r--r--src/core/kconfig.cpp8
4 files changed, 49 insertions, 0 deletions
diff --git a/autotests/kconfigtest.cpp b/autotests/kconfigtest.cpp
index e92197f3..2b905b57 100644
--- a/autotests/kconfigtest.cpp
+++ b/autotests/kconfigtest.cpp
@@ -552,6 +552,40 @@ void KConfigTest::testPersistenceOfExpandFlagForPath()
testPath();
}
+void KConfigTest::testPathQtHome()
+{
+ {
+ QFile file(testConfigDir() + "/pathtest");
+ file.open(QIODevice::WriteOnly | QIODevice::Text);
+ QTextStream out(&file);
+ out.setCodec("UTF-8");
+ out << "[Test Group]" << endl
+ << "dataDir[$e]=$QT_DATA_HOME/kconfigtest" << endl
+ << "cacheDir[$e]=$QT_CACHE_HOME/kconfigtest" << endl
+ << "configDir[$e]=$QT_CONFIG_HOME/kconfigtest" << endl;
+ }
+ KConfig cf2(TEST_SUBDIR "pathtest");
+ KConfigGroup group = cf2.group("Test Group");
+ qunsetenv("QT_DATA_HOME");
+ qunsetenv("QT_CACHE_HOME");
+ qunsetenv("QT_CONFIG_HOME");
+ QVERIFY(group.hasKey("dataDir"));
+ QCOMPARE(group.readEntry("dataDir", QString()), QStandardPaths::writableLocation(QStandardPaths::GenericDataLocation).append(QStringLiteral("/kconfigtest")));
+ QVERIFY(group.hasKey("cacheDir"));
+ QCOMPARE(group.readEntry("cacheDir", QString()), QStandardPaths::writableLocation(QStandardPaths::GenericCacheLocation).append(QStringLiteral("/kconfigtest")));
+ QVERIFY(group.hasKey("configDir"));
+ QCOMPARE(group.readEntry("configDir", QString()), QStandardPaths::writableLocation(QStandardPaths::GenericConfigLocation).append(QStringLiteral("/kconfigtest")));
+ qputenv("QT_DATA_HOME","/1");
+ qputenv("QT_CACHE_HOME","/2");
+ qputenv("QT_CONFIG_HOME","/3");
+ QVERIFY(group.hasKey("dataDir"));
+ QCOMPARE(group.readEntry("dataDir", QString()), QStringLiteral("/1/kconfigtest"));
+ QVERIFY(group.hasKey("cacheDir"));
+ QCOMPARE(group.readEntry("cacheDir", QString()), QStringLiteral("/2/kconfigtest"));
+ QVERIFY(group.hasKey("configDir"));
+ QCOMPARE(group.readEntry("configDir", QString()), QStringLiteral("/3/kconfigtest"));
+}
+
void KConfigTest::testComplex()
{
KConfig sc2(TEST_SUBDIR "kconfigtest");
diff --git a/autotests/kconfigtest.h b/autotests/kconfigtest.h
index be0a17ea..0a3de477 100644
--- a/autotests/kconfigtest.h
+++ b/autotests/kconfigtest.h
@@ -41,6 +41,7 @@ private Q_SLOTS:
void testLocale();
void testEncoding();
void testPath();
+ void testPathQtHome();
void testPersistenceOfExpandFlagForPath();
void testComplex();
void testEnums();
diff --git a/docs/options.md b/docs/options.md
index c7a6c061..ba7e2d89 100644
--- a/docs/options.md
+++ b/docs/options.md
@@ -90,4 +90,10 @@ The following syntax for environment variables is also supported:
Name[$ei]=${USER}
+There are three environment variables that have a fallback strategy if the
+environment variable is not set. They instead map to a location from QStanardPaths.
+They are:
+ `$QT_CACHE_HOME` - QStandardPaths::GenericConfigLocation
+ `$QT_CONFIG_HOME` - QStandardPaths::GenericConfigLocation
+ `$QT_DATA_HOME` - QStandardPaths::GenericDataLocation
diff --git a/src/core/kconfig.cpp b/src/core/kconfig.cpp
index 07fa6f55..9f17e579 100644
--- a/src/core/kconfig.cpp
+++ b/src/core/kconfig.cpp
@@ -221,6 +221,14 @@ QString KConfigPrivate::expandString(const QString &value)
QByteArray pEnv = qgetenv(aVarName.toLatin1().constData());
if (!pEnv.isEmpty()) {
env = QString::fromLocal8Bit(pEnv.constData());
+ } else {
+ if (aVarName == QStringLiteral("QT_DATA_HOME")) {
+ env = QStandardPaths::writableLocation(QStandardPaths::GenericDataLocation);
+ } else if (aVarName == QStringLiteral("QT_CONFIG_HOME")) {
+ env = QStandardPaths::writableLocation(QStandardPaths::GenericConfigLocation);
+ } else if (aVarName == QStringLiteral("QT_CACHE_HOME")) {
+ env = QStandardPaths::writableLocation(QStandardPaths::GenericCacheLocation);
+ }
}
}
aValue.replace(nDollarPos, nEndPos - nDollarPos, env);