summaryrefslogtreecommitdiff
path: root/src/libs/utils
diff options
context:
space:
mode:
authorChristian Kandeler <christian.kandeler@nokia.com>2012-08-23 15:53:58 +0200
committerhjk <qthjk@ovi.com>2012-08-27 17:00:03 +0200
commite669f054069c3a1214a31c4c1d7d9269659c31c4 (patch)
treed611e865215dc8ee705a640fdf3e35660542632f /src/libs/utils
parentb674b59b3d652fa9c5d74dc4e16380e3a5d23882 (diff)
downloadqt-creator-e669f054069c3a1214a31c4c1d7d9269659c31c4.tar.gz
Utils: Introduce HostOsInfo class.
The class' member functions are intended to be used instead of the Q_OS_* macros in all contexts where the latter are not syntactically required. This lowers the likelihood of changes made on one platform breaking the build on another, e.g. due to the code model missing symbols in #ifdef'ed out code when refactoring. Change-Id: I4a54788591b4c8f8d589b8368a6c683d4155c9fa Reviewed-by: hjk <qthjk@ovi.com>
Diffstat (limited to 'src/libs/utils')
-rw-r--r--src/libs/utils/buildablehelperlibrary.cpp10
-rw-r--r--src/libs/utils/consoleprocess_unix.cpp20
-rw-r--r--src/libs/utils/detailsbutton.cpp12
-rw-r--r--src/libs/utils/detailswidget.cpp23
-rw-r--r--src/libs/utils/environment.cpp241
-rw-r--r--src/libs/utils/environmentmodel.cpp8
-rw-r--r--src/libs/utils/fileutils.cpp15
-rw-r--r--src/libs/utils/fileutils.h2
-rw-r--r--src/libs/utils/filewizarddialog.cpp20
-rw-r--r--src/libs/utils/hostosinfo.cpp58
-rw-r--r--src/libs/utils/hostosinfo.h53
-rw-r--r--src/libs/utils/pathlisteditor.cpp9
-rw-r--r--src/libs/utils/stringutils.cpp13
-rw-r--r--src/libs/utils/stylehelper.cpp8
-rw-r--r--src/libs/utils/synchronousprocess.cpp32
-rw-r--r--src/libs/utils/utils.pro6
-rw-r--r--src/libs/utils/utils.qbs2
17 files changed, 302 insertions, 230 deletions
diff --git a/src/libs/utils/buildablehelperlibrary.cpp b/src/libs/utils/buildablehelperlibrary.cpp
index 485895d863..21f9b91ef3 100644
--- a/src/libs/utils/buildablehelperlibrary.cpp
+++ b/src/libs/utils/buildablehelperlibrary.cpp
@@ -38,8 +38,9 @@
#include <QDateTime>
#include <utils/environment.h>
-#include <utils/synchronousprocess.h>
#include <utils/fileutils.h>
+#include <utils/hostosinfo.h>
+#include <utils/synchronousprocess.h>
#include <QDesktopServices>
#include <QDebug>
@@ -121,14 +122,13 @@ QString BuildableHelperLibrary::qtVersionForQMake(const QString &qmakePath, bool
QStringList BuildableHelperLibrary::possibleQMakeCommands()
{
// On windows no one has renamed qmake, right?
-#ifdef Q_OS_WIN
- return QStringList(QLatin1String("qmake.exe"));
-#else
+ if (HostOsInfo::isWindowsHost())
+ return QStringList(QLatin1String("qmake.exe"));
+
// On unix some distributions renamed qmake to avoid clashes
QStringList result;
result << QLatin1String("qmake-qt4") << QLatin1String("qmake4") << QLatin1String("qmake");
return result;
-#endif
}
// Copy helper source files to a target directory, replacing older files.
diff --git a/src/libs/utils/consoleprocess_unix.cpp b/src/libs/utils/consoleprocess_unix.cpp
index 4c51445567..9e000eb2bc 100644
--- a/src/libs/utils/consoleprocess_unix.cpp
+++ b/src/libs/utils/consoleprocess_unix.cpp
@@ -33,6 +33,8 @@
#include "environment.h"
#include "qtcprocess.h"
+#include <utils/hostosinfo.h>
+
#include <QCoreApplication>
#include <QDir>
#include <QSettings>
@@ -134,12 +136,14 @@ bool ConsoleProcess::start(const QString &program, const QString &args)
}
}
+ if (Utils::HostOsInfo::isMacHost()) {
+ xtermArgs << (QCoreApplication::applicationDirPath()
+ + QLatin1String("/../Resources/qtcreator_process_stub"));
+ } else {
+ xtermArgs << (QCoreApplication::applicationDirPath()
+ + QLatin1String("/qtcreator_process_stub"));
+ }
xtermArgs
-#ifdef Q_OS_MAC
- << (QCoreApplication::applicationDirPath() + QLatin1String("/../Resources/qtcreator_process_stub"))
-#else
- << (QCoreApplication::applicationDirPath() + QLatin1String("/qtcreator_process_stub"))
-#endif
<< modeOption(d->m_mode)
<< d->m_stubServer.fullServerName()
<< msgPromptToClose()
@@ -279,11 +283,9 @@ void ConsoleProcess::stubExited()
QString ConsoleProcess::defaultTerminalEmulator()
{
-#ifdef Q_OS_MAC
- return QLatin1String("/usr/X11/bin/xterm");
-#else
+ if (Utils::HostOsInfo::isMacHost())
+ return QLatin1String("/usr/X11/bin/xterm");
return QLatin1String("xterm");
-#endif
}
QString ConsoleProcess::terminalEmulator(const QSettings *settings)
diff --git a/src/libs/utils/detailsbutton.cpp b/src/libs/utils/detailsbutton.cpp
index aa95ea2848..178f22a585 100644
--- a/src/libs/utils/detailsbutton.cpp
+++ b/src/libs/utils/detailsbutton.cpp
@@ -30,6 +30,7 @@
#include "detailsbutton.h"
+#include <utils/hostosinfo.h>
#include <utils/stylehelper.h>
#include <QPropertyAnimation>
@@ -83,11 +84,9 @@ QSize DetailsButton::sizeHint() const
{
// TODO: Adjust this when icons become available!
const int w = fontMetrics().width(text()) + 32;
-#ifdef Q_OS_MAC
- return QSize(w, 34);
-#else
+ if (HostOsInfo::isMacHost())
+ return QSize(w, 34);
return QSize(w, 22);
-#endif
}
bool DetailsButton::event(QEvent *e)
@@ -120,11 +119,10 @@ void DetailsButton::paintEvent(QPaintEvent *e)
QWidget::paintEvent(e);
QPainter p(this);
-#ifndef Q_OS_MAC
+
// draw hover animation
- if (!isDown() && m_fader > 0)
+ if (!HostOsInfo::isMacHost() && !isDown() && m_fader > 0)
p.fillRect(rect().adjusted(1, 1, -2, -2), QColor(255, 255, 255, int(m_fader*180)));
-#endif
if (isChecked()) {
if (m_checkedPixmap.isNull() || m_checkedPixmap.size() != contentsRect().size())
diff --git a/src/libs/utils/detailswidget.cpp b/src/libs/utils/detailswidget.cpp
index ff5b8ca083..e0e40f6127 100644
--- a/src/libs/utils/detailswidget.cpp
+++ b/src/libs/utils/detailswidget.cpp
@@ -30,6 +30,7 @@
#include "detailswidget.h"
#include "detailsbutton.h"
+#include "hostosinfo.h"
#include <QStack>
#include <QPropertyAnimation>
@@ -143,10 +144,10 @@ QPixmap DetailsWidgetPrivate::cacheBackground(const QSize &size)
QRect topRect(0, 0, size.width(), topHeight);
QRect fullRect(0, 0, size.width(), size.height());
-#ifdef Q_OS_MAC
- p.fillRect(fullRect, qApp->palette().window().color());
-#endif
- p.fillRect(fullRect, QColor(255, 255, 255, 40));
+ if (HostOsInfo::isMacHost())
+ p.fillRect(fullRect, qApp->palette().window().color());
+ else
+ p.fillRect(fullRect, QColor(255, 255, 255, 40));
QLinearGradient lg(topRect.topLeft(), topRect.bottomLeft());
lg.setColorAt(0, QColor(255, 255, 255, 130));
@@ -188,11 +189,10 @@ void DetailsWidgetPrivate::changeHoverState(bool hovered)
{
if (!m_toolWidget)
return;
-#ifdef Q_OS_MAC
- m_toolWidget->setOpacity(hovered ? 1.0 : 0);
-#else
- m_toolWidget->fadeTo(hovered ? 1.0 : 0);
-#endif
+ if (HostOsInfo::isMacHost())
+ m_toolWidget->setOpacity(hovered ? 1.0 : 0);
+ else
+ m_toolWidget->fadeTo(hovered ? 1.0 : 0);
m_hovered = hovered;
}
@@ -381,9 +381,8 @@ void DetailsWidget::setToolWidget(Utils::FadingPanel *widget)
d->m_toolWidget->adjustSize();
d->m_grid->addWidget(d->m_toolWidget, 0, 1, 1, 1, Qt::AlignRight);
-#ifdef Q_OS_MAC
- d->m_toolWidget->setOpacity(1.0);
-#endif
+ if (HostOsInfo::isMacHost())
+ d->m_toolWidget->setOpacity(1.0);
d->changeHoverState(d->m_hovered);
}
diff --git a/src/libs/utils/environment.cpp b/src/libs/utils/environment.cpp
index 97650cb2bb..03eb5c72a7 100644
--- a/src/libs/utils/environment.cpp
+++ b/src/libs/utils/environment.cpp
@@ -30,6 +30,8 @@
#include "environment.h"
+#include "hostosinfo.h"
+
#include <QDir>
#include <QProcess>
#include <QString>
@@ -41,18 +43,18 @@ public:
SystemEnvironment()
: Environment(QProcess::systemEnvironment())
{
-#ifdef Q_OS_LINUX
- QString ldLibraryPath = value(QLatin1String("LD_LIBRARY_PATH"));
- QDir lib(QCoreApplication::applicationDirPath());
- lib.cd("../lib");
- QString toReplace = lib.path();
- lib.cd("qtcreator");
- toReplace.append(QLatin1String(":"));
- toReplace.append(lib.path());
-
- if (ldLibraryPath.startsWith(toReplace))
- set(QLatin1String("LD_LIBRARY_PATH"), ldLibraryPath.remove(0, toReplace.length()));
-#endif
+ if (Utils::HostOsInfo::isLinuxHost()) {
+ QString ldLibraryPath = value(QLatin1String("LD_LIBRARY_PATH"));
+ QDir lib(QCoreApplication::applicationDirPath());
+ lib.cd("../lib");
+ QString toReplace = lib.path();
+ lib.cd("qtcreator");
+ toReplace.append(QLatin1String(":"));
+ toReplace.append(lib.path());
+
+ if (ldLibraryPath.startsWith(toReplace))
+ set(QLatin1String("LD_LIBRARY_PATH"), ldLibraryPath.remove(0, toReplace.length()));
+ }
}
};
@@ -60,6 +62,11 @@ Q_GLOBAL_STATIC(SystemEnvironment, staticSystemEnvironment)
namespace Utils {
+static QChar varSeparator()
+{
+ return HostOsInfo::isWindowsHost() ? QLatin1Char(';') : QLatin1Char(':');
+}
+
static bool sortEnvironmentItem(const EnvironmentItem &a, const EnvironmentItem &b)
{
return a.name < b.name;
@@ -104,11 +111,10 @@ Environment::Environment(const QStringList &env)
foreach (const QString &s, env) {
int i = s.indexOf(QLatin1Char('='));
if (i >= 0) {
-#ifdef Q_OS_WIN
- m_values.insert(s.left(i).toUpper(), s.mid(i+1));
-#else
- m_values.insert(s.left(i), s.mid(i+1));
-#endif
+ if (HostOsInfo::isWindowsHost())
+ m_values.insert(s.left(i).toUpper(), s.mid(i+1));
+ else
+ m_values.insert(s.left(i), s.mid(i+1));
}
}
}
@@ -128,32 +134,18 @@ QStringList Environment::toStringList() const
void Environment::set(const QString &key, const QString &value)
{
-#ifdef Q_OS_WIN
- QString _key = key.toUpper();
-#else
- const QString &_key = key;
-#endif
- m_values.insert(_key, value);
+ m_values.insert(HostOsInfo::isWindowsHost() ? key.toUpper() : key, value);
}
void Environment::unset(const QString &key)
{
-#ifdef Q_OS_WIN
- QString _key = key.toUpper();
-#else
- const QString &_key = key;
-#endif
- m_values.remove(_key);
+ m_values.remove(HostOsInfo::isWindowsHost() ? key.toUpper() : key);
}
void Environment::appendOrSet(const QString &key, const QString &value, const QString &sep)
{
-#ifdef Q_OS_WIN
- QString _key = key.toUpper();
-#else
- const QString &_key = key;
-#endif
- QMap<QString, QString>::iterator it = m_values.find(key);
+ const QString &_key = HostOsInfo::isWindowsHost() ? key.toUpper() : key;
+ QMap<QString, QString>::iterator it = m_values.find(_key);
if (it == m_values.end()) {
m_values.insert(_key, value);
} else {
@@ -166,12 +158,8 @@ void Environment::appendOrSet(const QString &key, const QString &value, const QS
void Environment::prependOrSet(const QString&key, const QString &value, const QString &sep)
{
-#ifdef Q_OS_WIN
- QString _key = key.toUpper();
-#else
- const QString &_key = key;
-#endif
- QMap<QString, QString>::iterator it = m_values.find(key);
+ const QString &_key = HostOsInfo::isWindowsHost() ? key.toUpper() : key;
+ QMap<QString, QString>::iterator it = m_values.find(_key);
if (it == m_values.end()) {
m_values.insert(_key, value);
} else {
@@ -184,38 +172,33 @@ void Environment::prependOrSet(const QString&key, const QString &value, const QS
void Environment::appendOrSetPath(const QString &value)
{
-#ifdef Q_OS_WIN
- const QChar sep = QLatin1Char(';');
-#else
- const QChar sep = QLatin1Char(':');
-#endif
- appendOrSet(QLatin1String("PATH"), QDir::toNativeSeparators(value), QString(sep));
+ appendOrSet(QLatin1String("PATH"), QDir::toNativeSeparators(value), QString(varSeparator()));
}
void Environment::prependOrSetPath(const QString &value)
{
-#ifdef Q_OS_WIN
- const QChar sep = QLatin1Char(';');
-#else
- const QChar sep = QLatin1Char(':');
-#endif
- prependOrSet(QLatin1String("PATH"), QDir::toNativeSeparators(value), QString(sep));
+ prependOrSet(QLatin1String("PATH"), QDir::toNativeSeparators(value), QString(varSeparator()));
}
void Environment::prependOrSetLibrarySearchPath(const QString &value)
{
-#ifdef Q_OS_MAC
- Q_UNUSED(value);
- // we could set DYLD_LIBRARY_PATH on Mac but it is unnecessary in practice
-#elif defined(Q_OS_WIN)
- const QChar sep = QLatin1Char(';');
- const QLatin1String path("PATH");
- prependOrSet(path, QDir::toNativeSeparators(value), QString(sep));
-#elif defined(Q_OS_UNIX)
- const QChar sep = QLatin1Char(':');
- const QLatin1String path("LD_LIBRARY_PATH");
- prependOrSet(path, QDir::toNativeSeparators(value), QString(sep));
-#endif
+ switch (HostOsInfo::hostOs()) {
+ case HostOsInfo::HostOsWindows: {
+ const QChar sep = QLatin1Char(';');
+ const QLatin1String path("PATH");
+ prependOrSet(path, QDir::toNativeSeparators(value), QString(sep));
+ break;
+ }
+ case HostOsInfo::HostOsLinux:
+ case HostOsInfo::HostOsOtherUnix: {
+ const QChar sep = QLatin1Char(':');
+ const QLatin1String path("LD_LIBRARY_PATH");
+ prependOrSet(path, QDir::toNativeSeparators(value), QString(sep));
+ break;
+ }
+ default: // we could set DYLD_LIBRARY_PATH on Mac but it is unnecessary in practice
+ break;
+ }
}
Environment Environment::systemEnvironment()
@@ -233,14 +216,15 @@ QString Environment::searchInPath(const QString &executable,
{
QStringList execs;
execs << executable;
-#ifdef Q_OS_WIN
- // Check all the executable extensions on windows:
- QStringList extensions = value(QLatin1String("PATHEXT")).split(QLatin1Char(';'));
-
- // .exe.bat is legal (and run when starting new.exe), so always go through the complete list once:
- foreach (const QString &ext, extensions)
- execs << executable + ext.toLower();
-#endif
+ if (HostOsInfo::isWindowsHost()) {
+ // Check all the executable extensions on windows:
+ QStringList extensions = value(QLatin1String("PATHEXT")).split(QLatin1Char(';'));
+
+ // .exe.bat is legal (and run when starting new.exe), so always go through the
+ // complete list once:
+ foreach (const QString &ext, extensions)
+ execs << executable + ext.toLower();
+ }
return searchInPath(execs, additionalDirs);
}
@@ -287,12 +271,7 @@ QString Environment::searchInPath(const QStringList &executables,
QStringList Environment::path() const
{
-#ifdef Q_OS_WIN
- const QChar sep = QLatin1Char(';');
-#else
- const QChar sep = QLatin1Char(':');
-#endif
- return m_values.value(QLatin1String("PATH")).split(sep, QString::SkipEmptyParts);
+ return m_values.value(QLatin1String("PATH")).split(varSeparator(), QString::SkipEmptyParts);
}
QString Environment::value(const QString &key) const
@@ -425,68 +404,68 @@ QString Environment::expandVariables(const QString &input) const
{
QString result = input;
-#ifdef Q_OS_WIN
- for (int vStart = -1, i = 0; i < result.length(); ) {
- if (result.at(i++) == QLatin1Char('%')) {
- if (vStart > 0) {
- const_iterator it = m_values.constFind(result.mid(vStart, i - vStart - 1).toUpper());
- if (it != m_values.constEnd()) {
- result.replace(vStart - 1, i - vStart + 1, *it);
- i = vStart - 1 + it->length();
- vStart = -1;
+ if (HostOsInfo::isWindowsHost()) {
+ for (int vStart = -1, i = 0; i < result.length(); ) {
+ if (result.at(i++) == QLatin1Char('%')) {
+ if (vStart > 0) {
+ const_iterator it = m_values.constFind(result.mid(vStart, i - vStart - 1).toUpper());
+ if (it != m_values.constEnd()) {
+ result.replace(vStart - 1, i - vStart + 1, *it);
+ i = vStart - 1 + it->length();
+ vStart = -1;
+ } else {
+ vStart = i;
+ }
} else {
vStart = i;
}
- } else {
- vStart = i;
}
}
- }
-#else
- enum { BASE, OPTIONALVARIABLEBRACE, VARIABLE, BRACEDVARIABLE } state = BASE;
- int vStart = -1;
-
- for (int i = 0; i < result.length();) {
- QChar c = result.at(i++);
- if (state == BASE) {
- if (c == QLatin1Char('$'))
- state = OPTIONALVARIABLEBRACE;
- } else if (state == OPTIONALVARIABLEBRACE) {
- if (c == QLatin1Char('{')) {
- state = BRACEDVARIABLE;
- vStart = i;
- } else if (c.isLetterOrNumber() || c == QLatin1Char('_')) {
- state = VARIABLE;
- vStart = i - 1;
- } else {
- state = BASE;
- }
- } else if (state == BRACEDVARIABLE) {
- if (c == QLatin1Char('}')) {
- const_iterator it = m_values.constFind(result.mid(vStart, i - 1 - vStart));
- if (it != constEnd()) {
- result.replace(vStart - 2, i - vStart + 2, *it);
- i = vStart - 2 + it->length();
+ } else {
+ enum { BASE, OPTIONALVARIABLEBRACE, VARIABLE, BRACEDVARIABLE } state = BASE;
+ int vStart = -1;
+
+ for (int i = 0; i < result.length();) {
+ QChar c = result.at(i++);
+ if (state == BASE) {
+ if (c == QLatin1Char('$'))
+ state = OPTIONALVARIABLEBRACE;
+ } else if (state == OPTIONALVARIABLEBRACE) {
+ if (c == QLatin1Char('{')) {
+ state = BRACEDVARIABLE;
+ vStart = i;
+ } else if (c.isLetterOrNumber() || c == QLatin1Char('_')) {
+ state = VARIABLE;
+ vStart = i - 1;
+ } else {
+ state = BASE;
}
- state = BASE;
- }
- } else if (state == VARIABLE) {
- if (!c.isLetterOrNumber() && c != QLatin1Char('_')) {
- const_iterator it = m_values.constFind(result.mid(vStart, i - vStart - 1));
- if (it != constEnd()) {
- result.replace(vStart - 1, i - vStart, *it);
- i = vStart - 1 + it->length();
+ } else if (state == BRACEDVARIABLE) {
+ if (c == QLatin1Char('}')) {
+ const_iterator it = m_values.constFind(result.mid(vStart, i - 1 - vStart));
+ if (it != constEnd()) {
+ result.replace(vStart - 2, i - vStart + 2, *it);
+ i = vStart - 2 + it->length();
+ }
+ state = BASE;
+ }
+ } else if (state == VARIABLE) {
+ if (!c.isLetterOrNumber() && c != QLatin1Char('_')) {
+ const_iterator it = m_values.constFind(result.mid(vStart, i - vStart - 1));
+ if (it != constEnd()) {
+ result.replace(vStart - 1, i - vStart, *it);
+ i = vStart - 1 + it->length();
+ }
+ state = BASE;
}
- state = BASE;
}
}
+ if (state == VARIABLE) {
+ const_iterator it = m_values.constFind(result.mid(vStart));
+ if (it != constEnd())
+ result.replace(vStart - 1, result.length() - vStart + 1, *it);
+ }
}
- if (state == VARIABLE) {
- const_iterator it = m_values.constFind(result.mid(vStart));
- if (it != constEnd())
- result.replace(vStart - 1, result.length() - vStart + 1, *it);
- }
-#endif
return result;
}
diff --git a/src/libs/utils/environmentmodel.cpp b/src/libs/utils/environmentmodel.cpp
index dd1ac90ba8..c3f129498d 100644
--- a/src/libs/utils/environmentmodel.cpp
+++ b/src/libs/utils/environmentmodel.cpp
@@ -31,6 +31,7 @@
#include "environmentmodel.h"
#include <utils/environment.h>
+#include <utils/hostosinfo.h>
#include <QFont>
@@ -202,11 +203,8 @@ bool EnvironmentModel::setData(const QModelIndex &index, const QVariant &value,
if (index.column() == 0) {
//fail if a variable with the same name already exists
-#if defined(Q_OS_WIN)
- const QString &newName = value.toString().toUpper();
-#else
- const QString &newName = value.toString();
-#endif
+ const QString &newName = HostOsInfo::isWindowsHost()
+ ? value.toString().toUpper() : value.toString();
// Does the new name exist already?
if (d->m_resultEnvironment.hasKey(newName) || newName.isEmpty())
return false;
diff --git a/src/libs/utils/fileutils.cpp b/src/libs/utils/fileutils.cpp
index fc539b0441..3ef845514e 100644
--- a/src/libs/utils/fileutils.cpp
+++ b/src/libs/utils/fileutils.cpp
@@ -31,6 +31,7 @@
#include "fileutils.h"
#include "savefile.h"
+#include "hostosinfo.h"
#include "qtcassert.h"
#include <QDir>
@@ -412,12 +413,8 @@ TempFileSaver::~TempFileSaver()
On windows filenames are compared case insensitively.
*/
-
-#ifdef Q_OS_WIN
-Qt::CaseSensitivity FileName::cs = Qt::CaseInsensitive;
-#else
-Qt::CaseSensitivity FileName::cs = Qt::CaseSensitive;
-#endif
+const Qt::CaseSensitivity FileName::cs
+ = HostOsInfo::isWindowsHost() ? Qt::CaseInsensitive : Qt::CaseSensitive;
FileName::FileName()
: QString()
@@ -581,10 +578,8 @@ FileName &FileName::append(QChar str)
QT_BEGIN_NAMESPACE
uint qHash(const Utils::FileName &a)
{
-#ifdef Q_OS_WIN
- return qHash(a.toString().toUpper());
-#else
+ if (Utils::HostOsInfo::isWindowsHost())
+ return qHash(a.toString().toUpper());
return qHash(a.toString());
-#endif
}
QT_END_NAMESPACE
diff --git a/src/libs/utils/fileutils.h b/src/libs/utils/fileutils.h
index 34227753c4..2047d91193 100644
--- a/src/libs/utils/fileutils.h
+++ b/src/libs/utils/fileutils.h
@@ -175,7 +175,7 @@ public:
using QString::isNull;
using QString::clear;
private:
- static Qt::CaseSensitivity cs;
+ static const Qt::CaseSensitivity cs;
FileName(const QString &string);
};
diff --git a/src/libs/utils/filewizarddialog.cpp b/src/libs/utils/filewizarddialog.cpp
index 50521b2e20..bc52de6097 100644
--- a/src/libs/utils/filewizarddialog.cpp
+++ b/src/libs/utils/filewizarddialog.cpp
@@ -31,6 +31,8 @@
#include "filewizarddialog.h"
#include "filewizardpage.h"
+#include "hostosinfo.h"
+
#include <QAbstractButton>
/*!
@@ -49,15 +51,15 @@ FileWizardDialog::FileWizardDialog(QWidget *parent) :
setWindowFlags(windowFlags() & ~Qt::WindowContextHelpButtonHint);
setOption(QWizard::NoCancelButton, false);
setOption(QWizard::NoDefaultButton, false);
-#ifdef Q_OS_MAC
- setButtonLayout(QList<QWizard::WizardButton>()
- << QWizard::CancelButton
- << QWizard::Stretch
- << QWizard::BackButton
- << QWizard::NextButton
- << QWizard::CommitButton
- << QWizard::FinishButton);
-#endif
+ if (HostOsInfo::isMacHost()) {
+ setButtonLayout(QList<QWizard::WizardButton>()
+ << QWizard::CancelButton
+ << QWizard::Stretch
+ << QWizard::BackButton
+ << QWizard::NextButton
+ << QWizard::CommitButton
+ << QWizard::FinishButton);
+ }
const int filePageId = addPage(m_filePage);
wizardProgress()->item(filePageId)->setTitle(tr("Location"));
connect(m_filePage, SIGNAL(activated()), button(QWizard::FinishButton), SLOT(animateClick()));
diff --git a/src/libs/utils/hostosinfo.cpp b/src/libs/utils/hostosinfo.cpp
new file mode 100644
index 0000000000..d00887f719
--- /dev/null
+++ b/src/libs/utils/hostosinfo.cpp
@@ -0,0 +1,58 @@
+/**************************************************************************
+**
+** This file is part of Qt Creator
+**
+** Copyright (c) 2012 Nokia Corporation and/or its subsidiary(-ies).
+**
+** Contact: http://www.qt-project.org/
+**
+**
+** GNU Lesser General Public License Usage
+**
+** 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, Nokia gives you certain additional
+** rights. These rights are described in the Nokia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** Other Usage
+**
+** Alternatively, this file may be used in accordance with the terms and
+** conditions contained in a signed written agreement between you and Nokia.
+**
+**
+**************************************************************************/
+#include "hostosinfo.h"
+
+namespace Utils {
+
+HostOsInfo::HostOs HostOsInfo::hostOs()
+{
+#if defined(Q_OS_WIN)
+ return HostOsWindows;
+#elif defined(Q_OS_LINUX)
+ return HostOsLinux;
+#elif defined(Q_OS_MAC)
+ return HostOsMac;
+#elif defined(Q_OS_UNIX)
+ return HostOsOtherUnix;
+#else
+ return HostOsOther;
+#endif
+}
+
+bool HostOsInfo::isAnyUnixHost()
+{
+#ifdef Q_OS_UNIX
+ return true;
+#else
+ return false;
+#endif
+}
+
+} // namespace Utils
diff --git a/src/libs/utils/hostosinfo.h b/src/libs/utils/hostosinfo.h
new file mode 100644
index 0000000000..e456ff7e73
--- /dev/null
+++ b/src/libs/utils/hostosinfo.h
@@ -0,0 +1,53 @@
+/**************************************************************************
+**
+** This file is part of Qt Creator
+**
+** Copyright (c) 2012 Nokia Corporation and/or its subsidiary(-ies).
+**
+** Contact: http://www.qt-project.org/
+**
+**
+** GNU Lesser General Public License Usage
+**
+** 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, Nokia gives you certain additional
+** rights. These rights are described in the Nokia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** Other Usage
+**
+** Alternatively, this file may be used in accordance with the terms and
+** conditions contained in a signed written agreement between you and Nokia.
+**
+**
+**************************************************************************/
+#ifndef HOSTOSINFO_H
+#define HOSTOSINFO_H
+
+#include "utils_global.h"
+
+namespace Utils {
+
+class QTCREATOR_UTILS_EXPORT HostOsInfo
+{
+public:
+ // Add more as needed.
+ enum HostOs { HostOsWindows, HostOsLinux, HostOsMac, HostOsOtherUnix, HostOsOther };
+
+ static HostOs hostOs();
+
+ static bool isWindowsHost() { return hostOs() == HostOsWindows; }
+ static bool isLinuxHost() { return hostOs() == HostOsLinux; }
+ static bool isMacHost() { return hostOs() == HostOsMac; }
+ static bool isAnyUnixHost();
+};
+
+} // namespace Utils
+
+#endif // HOSTOSINFO_H
diff --git a/src/libs/utils/pathlisteditor.cpp b/src/libs/utils/pathlisteditor.cpp
index ba1e85238c..df4c64652c 100644
--- a/src/libs/utils/pathlisteditor.cpp
+++ b/src/libs/utils/pathlisteditor.cpp
@@ -30,6 +30,8 @@
#include "pathlisteditor.h"
+#include "hostosinfo.h"
+
#include <QVBoxLayout>
#include <QHBoxLayout>
#include <QPlainTextEdit>
@@ -254,12 +256,7 @@ void PathListEditor::slotInsert()
QChar PathListEditor::separator()
{
-#ifdef Q_OS_WIN
- static const QChar rc(QLatin1Char(';'));
-#else
- static const QChar rc(QLatin1Char(':'));
-#endif
- return rc;
+ return HostOsInfo::isWindowsHost() ? QLatin1Char(';') : QLatin1Char(':');
}
// Add a button "Import from 'Path'"
diff --git a/src/libs/utils/stringutils.cpp b/src/libs/utils/stringutils.cpp
index 7d06ed9a8c..c6ddb87c18 100644
--- a/src/libs/utils/stringutils.cpp
+++ b/src/libs/utils/stringutils.cpp
@@ -30,6 +30,8 @@
#include "stringutils.h"
+#include "hostosinfo.h"
+
#include <QString>
#include <QStringList>
#include <QFileInfo>
@@ -95,19 +97,17 @@ QTCREATOR_UTILS_EXPORT QString commonPath(const QStringList &files)
lastSeparatorPos = common.lastIndexOf(QLatin1Char('\\'));
if (lastSeparatorPos == -1)
return QString();
-#ifdef Q_OS_UNIX
- if (lastSeparatorPos == 0) // Unix: "/a", "/b" -> '/'
+ if (HostOsInfo::isAnyUnixHost() && lastSeparatorPos == 0) // Unix: "/a", "/b" -> '/'
lastSeparatorPos = 1;
-#endif
common.truncate(lastSeparatorPos);
return common;
}
QTCREATOR_UTILS_EXPORT QString withTildeHomePath(const QString &path)
{
-#ifdef Q_OS_WIN
- QString outPath = path;
-#else
+ if (HostOsInfo::isWindowsHost())
+ return path;
+
static const QString homePath = QDir::homePath();
QFileInfo fi(QDir::cleanPath(path));
@@ -116,7 +116,6 @@ QTCREATOR_UTILS_EXPORT QString withTildeHomePath(const QString &path)
outPath = QLatin1Char('~') + outPath.mid(homePath.size());
else
outPath = path;
-#endif
return outPath;
}
diff --git a/src/libs/utils/stylehelper.cpp b/src/libs/utils/stylehelper.cpp
index af2e0dd8fd..bd5ec37dda 100644
--- a/src/libs/utils/stylehelper.cpp
+++ b/src/libs/utils/stylehelper.cpp
@@ -30,6 +30,8 @@
#include "stylehelper.h"
+#include "hostosinfo.h"
+
#include <QPixmapCache>
#include <QWidget>
#include <QRect>
@@ -69,11 +71,7 @@ QColor StyleHelper::mergedColors(const QColor &colorA, const QColor &colorB, int
qreal StyleHelper::sidebarFontSize()
{
-#if defined(Q_OS_MAC)
- return 10;
-#else
- return 7.5;
-#endif
+ return HostOsInfo::isMacHost() ? 10 : 7.5;
}
QPalette StyleHelper::sidebarFontPalette(const QPalette &original)
diff --git a/src/libs/utils/synchronousprocess.cpp b/src/libs/utils/synchronousprocess.cpp
index 1017693581..b2b540cae1 100644
--- a/src/libs/utils/synchronousprocess.cpp
+++ b/src/libs/utils/synchronousprocess.cpp
@@ -29,6 +29,8 @@
**************************************************************************/
#include "synchronousprocess.h"
+
+#include "hostosinfo.h"
#include <qtcassert.h>
#include <QDebug>
@@ -599,18 +601,6 @@ bool SynchronousProcess::stopProcess(QProcess &p)
// Path utilities
-enum OS_Type { OS_Mac, OS_Windows, OS_Unix };
-
-#ifdef Q_OS_WIN
-static const OS_Type pathOS = OS_Windows;
-#else
-# ifdef Q_OS_MAC
-static const OS_Type pathOS = OS_Mac;
-# else
-static const OS_Type pathOS = OS_Unix;
-# endif
-#endif
-
// Locate a binary in a directory, applying all kinds of
// extensions the operating system supports.
static QString checkBinary(const QDir &dir, const QString &binary)
@@ -622,16 +612,18 @@ static QString checkBinary(const QDir &dir, const QString &binary)
// Does the OS have some weird extension concept or does the
// binary have a 3 letter extension?
- if (pathOS == OS_Unix)
+ if (HostOsInfo::isAnyUnixHost() && !HostOsInfo::isMacHost())
return QString();
const int dotIndex = binary.lastIndexOf(QLatin1Char('.'));
if (dotIndex != -1 && dotIndex == binary.size() - 4)
return QString();
- switch (pathOS) {
- case OS_Unix:
+ switch (HostOsInfo::hostOs()) {
+ case HostOsInfo::HostOsLinux:
+ case HostOsInfo::HostOsOtherUnix:
+ case HostOsInfo::HostOsOther:
break;
- case OS_Windows: {
+ case HostOsInfo::HostOsWindows: {
static const char *windowsExtensions[] = {".cmd", ".bat", ".exe", ".com" };
// Check the Windows extensions using the order
const int windowsExtensionCount = sizeof(windowsExtensions)/sizeof(const char*);
@@ -642,7 +634,7 @@ static QString checkBinary(const QDir &dir, const QString &binary)
}
}
break;
- case OS_Mac: {
+ case HostOsInfo::HostOsMac: {
// Check for Mac app folders
const QFileInfo appFolder(dir.filePath(binary + QLatin1String(".app")));
if (appFolder.isDir()) {
@@ -667,7 +659,7 @@ QString SynchronousProcess::locateBinary(const QString &path, const QString &bin
return checkBinary(absInfo.dir(), absInfo.fileName());
// Windows finds binaries in the current directory
- if (pathOS == OS_Windows) {
+ if (HostOsInfo::isWindowsHost()) {
const QString currentDirBinary = checkBinary(QDir::current(), binary);
if (!currentDirBinary.isEmpty())
return currentDirBinary;
@@ -694,9 +686,7 @@ QString SynchronousProcess::locateBinary(const QString &binary)
QChar SynchronousProcess::pathSeparator()
{
- if (pathOS == OS_Windows)
- return QLatin1Char(';');
- return QLatin1Char(':');
+ return HostOsInfo::isWindowsHost() ? QLatin1Char(';') : QLatin1Char(':');
}
} // namespace Utils
diff --git a/src/libs/utils/utils.pro b/src/libs/utils/utils.pro
index 7829c45097..fa2d8ccc71 100644
--- a/src/libs/utils/utils.pro
+++ b/src/libs/utils/utils.pro
@@ -13,10 +13,12 @@ lessThan(QT_MAJOR_VERSION, 5) {
}
HEADERS += \
- proxyaction.h
+ proxyaction.h \
+ hostosinfo.h
SOURCES += \
- proxyaction.cpp
+ proxyaction.cpp \
+ hostosinfo.cpp
win32: LIBS += -lUser32
# PortsGatherer
diff --git a/src/libs/utils/utils.qbs b/src/libs/utils/utils.qbs
index 10e8d28422..10775ce8a9 100644
--- a/src/libs/utils/utils.qbs
+++ b/src/libs/utils/utils.qbs
@@ -154,6 +154,8 @@ QtcLibrary {
"utils_global.h",
"wizard.cpp",
"wizard.h",
+ "hostosinfo.cpp",
+ "hostosinfo.h",
"persistentsettings.h",
"settingsselector.h",
"buildablehelperlibrary.cpp",