diff options
author | David Faure <faure@kde.org> | 2012-08-08 17:56:22 +0200 |
---|---|---|
committer | Qt by Nokia <qt-info@nokia.com> | 2012-08-09 13:48:16 +0200 |
commit | 977441f61cc42b7f29e48980577105323fbd3b47 (patch) | |
tree | cba6cd58b3bbda03de0266fe3f903dbaa0be5ac2 /src/corelib | |
parent | a23da5fd6bca918366cfe744270e590905e97412 (diff) |
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>
Diffstat (limited to 'src/corelib')
-rw-r--r-- | src/corelib/io/qstandardpaths.cpp | 12 | ||||
-rw-r--r-- | src/corelib/io/qstandardpaths_blackberry.cpp | 14 | ||||
-rw-r--r-- | src/corelib/io/qstandardpaths_json.cpp | 14 | ||||
-rw-r--r-- | src/corelib/io/qstandardpaths_mac.cpp | 14 | ||||
-rw-r--r-- | src/corelib/io/qstandardpaths_unix.cpp | 20 | ||||
-rw-r--r-- | src/corelib/io/qstandardpaths_win.cpp | 14 |
6 files changed, 20 insertions, 68 deletions
diff --git a/src/corelib/io/qstandardpaths.cpp b/src/corelib/io/qstandardpaths.cpp index 37950db018..48664b5012 100644 --- a/src/corelib/io/qstandardpaths.cpp +++ b/src/corelib/io/qstandardpaths.cpp @@ -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 diff --git a/src/corelib/io/qstandardpaths_blackberry.cpp b/src/corelib/io/qstandardpaths_blackberry.cpp index 34948a7927..983173b66a 100644 --- a/src/corelib/io/qstandardpaths_blackberry.cpp +++ b/src/corelib/io/qstandardpaths_blackberry.cpp @@ -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(""); diff --git a/src/corelib/io/qstandardpaths_json.cpp b/src/corelib/io/qstandardpaths_json.cpp index df52c7d0ea..57978754e5 100644 --- a/src/corelib/io/qstandardpaths_json.cpp +++ b/src/corelib/io/qstandardpaths_json.cpp @@ -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) { diff --git a/src/corelib/io/qstandardpaths_mac.cpp b/src/corelib/io/qstandardpaths_mac.cpp index 0f3a950e49..dfc802a78c 100644 --- a/src/corelib/io/qstandardpaths_mac.cpp +++ b/src/corelib/io/qstandardpaths_mac.cpp @@ -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) { diff --git a/src/corelib/io/qstandardpaths_unix.cpp b/src/corelib/io/qstandardpaths_unix.cpp index f44ccd1c93..3939f1e968 100644 --- a/src/corelib/io/qstandardpaths_unix.cpp +++ b/src/corelib/io/qstandardpaths_unix.cpp @@ -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" diff --git a/src/corelib/io/qstandardpaths_win.cpp b/src/corelib/io/qstandardpaths_win.cpp index 245dbbfc40..f918e02880 100644 --- a/src/corelib/io/qstandardpaths_win.cpp +++ b/src/corelib/io/qstandardpaths_win.cpp @@ -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()) |