Remove code duplication in QStandardPaths implementations

Using the new getter to access the "test mode" setting.

Change-Id: Id26a350cd3fab4bf2e5f58ba67bc7323f99c9cc3
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
Reviewed-by: Oswald Buddenhagen <oswald.buddenhagen@nokia.com>
This commit is contained in:
David Faure 2012-08-08 17:56:22 +02:00 committed by Qt by Nokia
parent a23da5fd6b
commit 977441f61c
6 changed files with 20 additions and 68 deletions

View File

@ -333,6 +333,12 @@ QString QStandardPaths::displayName(StandardLocation type)
On Windows, everything goes to a "qttest" directory under Application Data.
*/
static bool qsp_testMode = false;
void QStandardPaths::enableTestMode(bool testMode)
{
qsp_testMode = testMode;
}
/*!
\fn void QStandardPaths::isTestModeEnabled()
@ -342,6 +348,12 @@ QString QStandardPaths::displayName(StandardLocation type)
Returns true if test mode is enabled in QStandardPaths; otherwise returns false.
*/
bool QStandardPaths::isTestModeEnabled()
{
return qsp_testMode;
}
QT_END_NAMESPACE
#endif // QT_NO_STANDARDPATHS

View File

@ -48,20 +48,8 @@
QT_BEGIN_NAMESPACE
static bool qsp_testMode = false;
void QStandardPaths::enableTestMode(bool testMode)
{
qsp_testMode = testMode;
}
bool QStandardPaths::isTestModeEnabled()
{
return qsp_testMode;
}
static QString testModeInsert() {
if (qsp_testMode)
if (QStandardPaths::isTestModeEnabled())
return QStringLiteral("/.qttest");
else
return QStringLiteral("");

View File

@ -66,8 +66,6 @@ public:
Q_GLOBAL_STATIC(QStandardPathsPrivate, configCache);
static bool qsp_testMode = false;
/*!
\internal
Substitute environment variables in the form ${name}
@ -111,16 +109,6 @@ static QString substituteEnvVars(const QJsonValue & value)
return str;
}
void QStandardPaths::enableTestMode(bool testMode)
{
qsp_testMode = testMode;
}
bool QStandardPaths::isTestModeEnabled()
{
return qsp_testMode;
}
static void appendOrganizationAndApp(QString &path)
{
const QString org = QCoreApplication::organizationName();
@ -150,7 +138,7 @@ QStringList QStandardPaths::standardLocations(StandardLocation type)
break;
}
if (qsp_testMode) {
if (isTestModeEnabled()) {
const QString qttestDir = QDir::homePath() + QLatin1String("/.qttest");
QString path;
switch (type) {

View File

@ -90,18 +90,6 @@ OSType translateLocation(QStandardPaths::StandardLocation type)
}
}
static bool qsp_testMode = false;
void QStandardPaths::enableTestMode(bool testMode)
{
qsp_testMode = testMode;
}
bool QStandardPaths::isTestModeEnabled()
{
return qsp_testMode;
}
/*
Constructs a full unicode path from a FSRef.
*/
@ -140,7 +128,7 @@ static QString macLocation(QStandardPaths::StandardLocation type, short domain)
QString QStandardPaths::writableLocation(StandardLocation type)
{
if (qsp_testMode) {
if (isTestModeEnabled()) {
const QString qttestDir = QDir::homePath() + QLatin1String("/.qttest");
QString path;
switch (type) {

View File

@ -63,18 +63,6 @@ static void appendOrganizationAndApp(QString &path)
path += QLatin1Char('/') + appName;
}
static bool qsp_testMode = false;
void QStandardPaths::enableTestMode(bool testMode)
{
qsp_testMode = testMode;
}
bool QStandardPaths::isTestModeEnabled()
{
return qsp_testMode;
}
QString QStandardPaths::writableLocation(StandardLocation type)
{
switch (type) {
@ -87,7 +75,7 @@ QString QStandardPaths::writableLocation(StandardLocation type)
{
// http://standards.freedesktop.org/basedir-spec/basedir-spec-0.6.html
QString xdgCacheHome = QFile::decodeName(qgetenv("XDG_CACHE_HOME"));
if (qsp_testMode)
if (isTestModeEnabled())
xdgCacheHome = QDir::homePath() + QLatin1String("/.qttest/cache");
if (xdgCacheHome.isEmpty())
xdgCacheHome = QDir::homePath() + QLatin1String("/.cache");
@ -99,7 +87,7 @@ QString QStandardPaths::writableLocation(StandardLocation type)
case GenericDataLocation:
{
QString xdgDataHome = QFile::decodeName(qgetenv("XDG_DATA_HOME"));
if (qsp_testMode)
if (isTestModeEnabled())
xdgDataHome = QDir::homePath() + QLatin1String("/.qttest/share");
if (xdgDataHome.isEmpty())
xdgDataHome = QDir::homePath() + QLatin1String("/.local/share");
@ -111,7 +99,7 @@ QString QStandardPaths::writableLocation(StandardLocation type)
{
// http://standards.freedesktop.org/basedir-spec/latest/
QString xdgConfigHome = QFile::decodeName(qgetenv("XDG_CONFIG_HOME"));
if (qsp_testMode)
if (isTestModeEnabled())
xdgConfigHome = QDir::homePath() + QLatin1String("/.qttest/config");
if (xdgConfigHome.isEmpty())
xdgConfigHome = QDir::homePath() + QLatin1String("/.config");
@ -158,7 +146,7 @@ QString QStandardPaths::writableLocation(StandardLocation type)
if (xdgConfigHome.isEmpty())
xdgConfigHome = QDir::homePath() + QLatin1String("/.config");
QFile file(xdgConfigHome + QLatin1String("/user-dirs.dirs"));
if (!qsp_testMode && file.open(QIODevice::ReadOnly)) {
if (!isTestModeEnabled() && file.open(QIODevice::ReadOnly)) {
QHash<QString, QString> lines;
QTextStream stream(&file);
// Only look for lines like: XDG_DESKTOP_DIR="$HOME/Desktop"

View File

@ -85,18 +85,6 @@ static QString convertCharArray(const wchar_t *path)
return QDir::fromNativeSeparators(QString::fromWCharArray(path));
}
static bool qsp_testMode = false;
void QStandardPaths::enableTestMode(bool testMode)
{
qsp_testMode = testMode;
}
bool QStandardPaths::isTestModeEnabled()
{
return qsp_testMode;
}
QString QStandardPaths::writableLocation(StandardLocation type)
{
QString result;
@ -117,7 +105,7 @@ QString QStandardPaths::writableLocation(StandardLocation type)
if (SHGetSpecialFolderPath(0, path, CSIDL_LOCAL_APPDATA, FALSE))
#endif
result = convertCharArray(path);
if (qsp_testMode)
if (isTestModeEnabled())
result += QLatin1String("/qttest");
if (type != GenericDataLocation) {
if (!QCoreApplication::organizationName().isEmpty())