From c99dfd8f631289d66c5aa1d667073530e9c30860 Mon Sep 17 00:00:00 2001 From: David Faure Date: Fri, 11 Jul 2014 01:37:37 +0200 Subject: [PATCH] QSettings: use QStandardPaths to get XDG_CONFIG_HOME. This allows to use the "test mode" of QStandardPaths in unittests, to stay away from the user's real settings. Change-Id: I1cb1f63a4bff35dfe236924c4dcd7cf761ee50c1 Reviewed-by: Oswald Buddenhagen Reviewed-by: Thiago Macieira --- qmake/Makefile.unix | 2 +- qmake/Makefile.win32 | 2 +- qmake/qmake.pri | 2 +- src/corelib/io/qsettings.cpp | 6 ++++++ 4 files changed, 9 insertions(+), 3 deletions(-) diff --git a/qmake/Makefile.unix b/qmake/Makefile.unix index 52873203a0..10c72bf28f 100644 --- a/qmake/Makefile.unix +++ b/qmake/Makefile.unix @@ -103,7 +103,7 @@ CPPFLAGS = -g $(EXTRA_CPPFLAGS) \ -DQT_BUILD_QMAKE -DQT_BOOTSTRAPPED -DPROEVALUATOR_FULL \ -DQT_NO_TEXTCODEC -DQT_NO_UNICODETABLES -DQT_NO_COMPONENT -DQT_NO_COMPRESS \ -DQT_NO_THREAD -DQT_NO_QOBJECT -DQT_NO_GEOM_VARIANT -DQT_NO_DATASTREAM \ - -DQT_CRYPTOGRAPHICHASH_ONLY_SHA1 -DQT_JSON_READONLY + -DQT_CRYPTOGRAPHICHASH_ONLY_SHA1 -DQT_JSON_READONLY -DQT_NO_STANDARDPATHS CXXFLAGS = $(EXTRA_CXXFLAGS) $(CPPFLAGS) diff --git a/qmake/Makefile.win32 b/qmake/Makefile.win32 index 62dc7bcdf8..93c462fc60 100644 --- a/qmake/Makefile.win32 +++ b/qmake/Makefile.win32 @@ -41,7 +41,7 @@ CFLAGS_BARE = -c -Fo./ -Fdqmake.pdb \ -DQT_BUILD_QMAKE -DQT_BOOTSTRAPPED -DPROEVALUATOR_FULL \ -DQT_NO_TEXTCODEC -DQT_NO_UNICODETABLES -DQT_NO_COMPONENT -DQT_NO_COMPRESS \ -DQT_NO_THREAD -DQT_NO_QOBJECT -DQT_NO_GEOM_VARIANT -DQT_NO_DATASTREAM \ - -DUNICODE -DQT_CRYPTOGRAPHICHASH_ONLY_SHA1 -DQT_JSON_READONLY + -DUNICODE -DQT_CRYPTOGRAPHICHASH_ONLY_SHA1 -DQT_JSON_READONLY -DQT_NO_STANDARDPATHS CFLAGS = -Yuqmake_pch.h -FIqmake_pch.h -Fpqmake_pch.pch $(CFLAGS_BARE) $(CFLAGS) $(EXTRA_CPPFLAGS) CXXFLAGS_BARE = $(CFLAGS_BARE) diff --git a/qmake/qmake.pri b/qmake/qmake.pri index 4457b2643b..4de41d63e6 100644 --- a/qmake/qmake.pri +++ b/qmake/qmake.pri @@ -159,7 +159,7 @@ bootstrap { #Qt code QT_BOOTSTRAPPED \ QT_NO_TEXTCODEC QT_NO_UNICODETABLES QT_NO_COMPONENT QT_NO_COMPRESS \ QT_NO_THREAD QT_NO_QOBJECT QT_NO_GEOM_VARIANT QT_NO_DATASTREAM \ - QT_CRYPTOGRAPHICHASH_ONLY_SHA1 QT_JSON_READONLY + QT_CRYPTOGRAPHICHASH_ONLY_SHA1 QT_JSON_READONLY QT_NO_STANDARDPATHS INCLUDEPATH += \ $$QT.core.includes $$QT.core_private.includes \ diff --git a/src/corelib/io/qsettings.cpp b/src/corelib/io/qsettings.cpp index 1748170324..5db545347d 100644 --- a/src/corelib/io/qsettings.cpp +++ b/src/corelib/io/qsettings.cpp @@ -53,6 +53,7 @@ #include "qmutex.h" #include "qlibraryinfo.h" #include "qtemporaryfile.h" +#include "qstandardpaths.h" #ifndef QT_NO_TEXTCODEC # include "qtextcodec.h" @@ -1140,6 +1141,8 @@ static void initDefaultPaths(QMutexLocker *locker) pathHash->insert(pathHashKey(QSettings::IniFormat, QSettings::SystemScope), windowsConfigPath(CSIDL_COMMON_APPDATA) + QDir::separator()); #else + +#ifdef QT_NO_STANDARDPATHS QString userPath; char *env = getenv("XDG_CONFIG_HOME"); if (env == 0) { @@ -1153,6 +1156,9 @@ static void initDefaultPaths(QMutexLocker *locker) userPath += QLatin1Char('/'); userPath += QFile::decodeName(env); } +#else + QString userPath = QStandardPaths::writableLocation(QStandardPaths::GenericConfigLocation); +#endif userPath += QLatin1Char('/'); pathHash->insert(pathHashKey(QSettings::IniFormat, QSettings::UserScope), userPath);