diff options
author | Christian Kandeler <christian.kandeler@digia.com> | 2013-08-15 16:08:16 +0200 |
---|---|---|
committer | hjk <hjk121@nokiamail.com> | 2013-08-16 08:05:41 +0200 |
commit | 6d6842202606bd153bf8614bb4699ed45ac13d3e (patch) | |
tree | 21ff9cd97e419205cafaadbe277ab7f9b9cf15e0 | |
parent | ffae1fcb24de9f39e860bd289b2f3b443e940c45 (diff) | |
download | qt-creator-6d6842202606bd153bf8614bb4699ed45ac13d3e.tar.gz |
Utils: Introduce new class OsSpecificAspects.
This is basically a generalization of HostOsInfo for
a system that might not be the host system. HostOsInfo
is now implemented in terms of the new class.
Prospective use case: Untie Utils::Environment from
the host system.
Change-Id: If333b96674652109fcb0ad79f75aaaf5e86e17e3
Reviewed-by: hjk <hjk121@nokiamail.com>
Reviewed-by: Daniel Teske <daniel.teske@digia.com>
-rw-r--r-- | src/libs/utils/environment.cpp | 6 | ||||
-rw-r--r-- | src/libs/utils/hostosinfo.h | 41 | ||||
-rw-r--r-- | src/libs/utils/osspecificaspects.h | 74 | ||||
-rw-r--r-- | src/libs/utils/synchronousprocess.cpp | 10 | ||||
-rw-r--r-- | src/libs/utils/utils-lib.pri | 1 | ||||
-rw-r--r-- | src/libs/utils/utils.qbs | 1 | ||||
-rw-r--r-- | src/plugins/android/androidconfigurations.cpp | 6 | ||||
-rw-r--r-- | src/plugins/qt4projectmanager/librarydetailscontroller.cpp | 6 | ||||
-rw-r--r-- | src/plugins/welcome/welcomeplugin.cpp | 8 |
9 files changed, 115 insertions, 38 deletions
diff --git a/src/libs/utils/environment.cpp b/src/libs/utils/environment.cpp index e0a19db274..9c7140b202 100644 --- a/src/libs/utils/environment.cpp +++ b/src/libs/utils/environment.cpp @@ -187,14 +187,14 @@ void Environment::prependOrSetPath(const QString &value) void Environment::prependOrSetLibrarySearchPath(const QString &value) { switch (HostOsInfo::hostOs()) { - case HostOsInfo::HostOsWindows: { + case OsTypeWindows: { const QChar sep = QLatin1Char(';'); const QLatin1String path("PATH"); prependOrSet(path, QDir::toNativeSeparators(value), QString(sep)); break; } - case HostOsInfo::HostOsLinux: - case HostOsInfo::HostOsOtherUnix: { + case OsTypeLinux: + case OsTypeOtherUnix: { const QChar sep = QLatin1Char(':'); const QLatin1String path("LD_LIBRARY_PATH"); prependOrSet(path, QDir::toNativeSeparators(value), QString(sep)); diff --git a/src/libs/utils/hostosinfo.h b/src/libs/utils/hostosinfo.h index 0bb642561b..10ad8785c8 100644 --- a/src/libs/utils/hostosinfo.h +++ b/src/libs/utils/hostosinfo.h @@ -32,10 +32,12 @@ #include "utils_global.h" +#include "osspecificaspects.h" + #include <QString> #ifdef Q_OS_WIN -#define QTC_HOST_EXE_SUFFIX ".exe" +#define QTC_HOST_EXE_SUFFIX QTC_WIN_EXE_SUFFIX #else #define QTC_HOST_EXE_SUFFIX "" #endif // Q_OS_WIN @@ -45,55 +47,54 @@ namespace Utils { class QTCREATOR_UTILS_EXPORT HostOsInfo { public: - // Add more as needed. - enum HostOs { HostOsWindows, HostOsLinux, HostOsMac, HostOsOtherUnix, HostOsOther }; - static inline HostOs hostOs(); + static inline OsType hostOs(); enum HostArchitecture { HostArchitectureX86, HostArchitectureAMD64, HostArchitectureItanium, HostArchitectureArm, HostArchitectureUnknown }; static HostArchitecture hostArchitecture(); - static bool isWindowsHost() { return hostOs() == HostOsWindows; } - static bool isLinuxHost() { return hostOs() == HostOsLinux; } - static bool isMacHost() { return hostOs() == HostOsMac; } + static bool isWindowsHost() { return hostOs() == OsTypeWindows; } + static bool isLinuxHost() { return hostOs() == OsTypeLinux; } + static bool isMacHost() { return hostOs() == OsTypeMac; } static inline bool isAnyUnixHost(); static QString withExecutableSuffix(const QString &executable) { - QString finalName = executable; - if (isWindowsHost()) - finalName += QLatin1String(QTC_HOST_EXE_SUFFIX); - return finalName; + return hostOsAspects().withExecutableSuffix(executable); } static Qt::CaseSensitivity fileNameCaseSensitivity() { - return isWindowsHost() ? Qt::CaseInsensitive: Qt::CaseSensitive; + return hostOsAspects().fileNameCaseSensitivity(); } static QChar pathListSeparator() { - return isWindowsHost() ? QLatin1Char(';') : QLatin1Char(':'); + return hostOsAspects().pathListSeparator(); } static Qt::KeyboardModifier controlModifier() { - return isMacHost() ? Qt::MetaModifier : Qt::ControlModifier; + return hostOsAspects().controlModifier(); } + +private: + static OsSpecificAspects hostOsAspects() { return OsSpecificAspects(hostOs()); } }; -HostOsInfo::HostOs HostOsInfo::hostOs() + +OsType HostOsInfo::hostOs() { #if defined(Q_OS_WIN) - return HostOsWindows; + return OsTypeWindows; #elif defined(Q_OS_LINUX) - return HostOsLinux; + return OsTypeLinux; #elif defined(Q_OS_MAC) - return HostOsMac; + return OsTypeMac; #elif defined(Q_OS_UNIX) - return HostOsOtherUnix; + return OsTypeOtherUnix; #else - return HostOsOther; + return OsTypeOther; #endif } diff --git a/src/libs/utils/osspecificaspects.h b/src/libs/utils/osspecificaspects.h new file mode 100644 index 0000000000..febdcbd022 --- /dev/null +++ b/src/libs/utils/osspecificaspects.h @@ -0,0 +1,74 @@ +/************************************************************************** +** +** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/legal +** +** This file is part of Qt Creator. +** +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Digia. For licensing terms and +** conditions see http://qt.digia.com/licensing. For further information +** use the contact form at http://qt.digia.com/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +****************************************************************************/ + +#ifndef QTC_OSSPECIFICASPECTS_H +#define QTC_OSSPECIFICASPECTS_H + +#include "utils_global.h" + +#include <QString> + +#define QTC_WIN_EXE_SUFFIX ".exe" + +namespace Utils { + +// Add more as needed. +enum OsType { OsTypeWindows, OsTypeLinux, OsTypeMac, OsTypeOtherUnix, OsTypeOther }; + +class QTCREATOR_UTILS_EXPORT OsSpecificAspects +{ +public: + OsSpecificAspects(OsType osType) : m_osType(osType) { } + + QString withExecutableSuffix(const QString &executable) const { + QString finalName = executable; + if (m_osType == OsTypeWindows) + finalName += QLatin1String(QTC_WIN_EXE_SUFFIX); + return finalName; + } + + Qt::CaseSensitivity fileNameCaseSensitivity() const { + return m_osType == OsTypeWindows ? Qt::CaseInsensitive : Qt::CaseSensitive; + } + + QChar pathListSeparator() const { + return QLatin1Char(m_osType == OsTypeWindows ? ';' : ':'); + } + + Qt::KeyboardModifier controlModifier() const { + return m_osType == OsTypeMac ? Qt::MetaModifier : Qt::ControlModifier; + } + +private: + const OsType m_osType; +}; + +} // namespace Utils + +#endif // Include guard. diff --git a/src/libs/utils/synchronousprocess.cpp b/src/libs/utils/synchronousprocess.cpp index ab89569b77..f9c181c205 100644 --- a/src/libs/utils/synchronousprocess.cpp +++ b/src/libs/utils/synchronousprocess.cpp @@ -621,11 +621,11 @@ static QString checkBinary(const QDir &dir, const QString &binary) return QString(); switch (HostOsInfo::hostOs()) { - case HostOsInfo::HostOsLinux: - case HostOsInfo::HostOsOtherUnix: - case HostOsInfo::HostOsOther: + case OsTypeLinux: + case OsTypeOtherUnix: + case OsTypeOther: break; - case HostOsInfo::HostOsWindows: { + case OsTypeWindows: { static const char *windowsExtensions[] = {".cmd", ".bat", ".exe", ".com" }; // Check the Windows extensions using the order const int windowsExtensionCount = sizeof(windowsExtensions)/sizeof(const char*); @@ -636,7 +636,7 @@ static QString checkBinary(const QDir &dir, const QString &binary) } } break; - case HostOsInfo::HostOsMac: { + case OsTypeMac: { // Check for Mac app folders const QFileInfo appFolder(dir.filePath(binary + QLatin1String(".app"))); if (appFolder.isDir()) { diff --git a/src/libs/utils/utils-lib.pri b/src/libs/utils/utils-lib.pri index 138c65bf45..335fb8cfdd 100644 --- a/src/libs/utils/utils-lib.pri +++ b/src/libs/utils/utils-lib.pri @@ -167,6 +167,7 @@ HEADERS += \ $$PWD/bracematcher.h \ $$PWD/proxyaction.h \ $$PWD/hostosinfo.h \ + $$PWD/osspecificaspects.h \ $$PWD/elidinglabel.h \ $$PWD/tooltip/tooltip.h \ $$PWD/tooltip/tips.h \ diff --git a/src/libs/utils/utils.qbs b/src/libs/utils/utils.qbs index 61f3bba82d..bb3834f3aa 100644 --- a/src/libs/utils/utils.qbs +++ b/src/libs/utils/utils.qbs @@ -110,6 +110,7 @@ QtcLibrary { "newclasswidget.cpp", "newclasswidget.h", "newclasswidget.ui", + "osspecificaspects.h", "outputformat.h", "outputformatter.cpp", "outputformatter.h", diff --git a/src/plugins/android/androidconfigurations.cpp b/src/plugins/android/androidconfigurations.cpp index 82e04e7b79..7774983b36 100644 --- a/src/plugins/android/androidconfigurations.cpp +++ b/src/plugins/android/androidconfigurations.cpp @@ -335,13 +335,13 @@ void AndroidConfigurations::detectToolchainHost() { QStringList hostPatterns; switch (HostOsInfo::hostOs()) { - case HostOsInfo::HostOsLinux: + case OsTypeLinux: hostPatterns << QLatin1String("linux*"); break; - case HostOsInfo::HostOsWindows: + case OsTypeWindows: hostPatterns << QLatin1String("windows*"); break; - case HostOsInfo::HostOsMac: + case OsTypeMac: hostPatterns << QLatin1String("darwin*"); break; default: /* unknown host */ return; diff --git a/src/plugins/qt4projectmanager/librarydetailscontroller.cpp b/src/plugins/qt4projectmanager/librarydetailscontroller.cpp index abc528e4ca..8080054f6f 100644 --- a/src/plugins/qt4projectmanager/librarydetailscontroller.cpp +++ b/src/plugins/qt4projectmanager/librarydetailscontroller.cpp @@ -67,13 +67,13 @@ LibraryDetailsController::LibraryDetailsController( m_libraryDetailsWidget(libraryDetails) { switch (Utils::HostOsInfo::hostOs()) { - case Utils::HostOsInfo::HostOsMac: + case Utils::OsTypeMac: m_creatorPlatform = CreatorMac; break; - case Utils::HostOsInfo::HostOsLinux: + case Utils::OsTypeLinux: m_creatorPlatform = CreatorLinux; break; - case Utils::HostOsInfo::HostOsWindows: + case Utils::OsTypeWindows: m_creatorPlatform = CreatorWindows; break; default: diff --git a/src/plugins/welcome/welcomeplugin.cpp b/src/plugins/welcome/welcomeplugin.cpp index c9f26bbc08..befdf9d5dc 100644 --- a/src/plugins/welcome/welcomeplugin.cpp +++ b/src/plugins/welcome/welcomeplugin.cpp @@ -286,10 +286,10 @@ void WelcomeMode::initPlugins() QString WelcomeMode::platform() const { switch (HostOsInfo::hostOs()) { - case HostOsInfo::HostOsWindows: return QLatin1String("windows"); - case HostOsInfo::HostOsMac: return QLatin1String("mac"); - case HostOsInfo::HostOsLinux: return QLatin1String("linux"); - case HostOsInfo::HostOsOtherUnix: return QLatin1String("unix"); + case OsTypeWindows: return QLatin1String("windows"); + case OsTypeMac: return QLatin1String("mac"); + case OsTypeLinux: return QLatin1String("linux"); + case OsTypeOtherUnix: return QLatin1String("unix"); default: return QLatin1String("other"); } } |