Main: Replace preprocessor directives with HostOsInfo

Change-Id: I5d72f159baa9a6b22bcb626e55ddf6de7724d4fc
Reviewed-by: Eike Ziller <eike.ziller@theqtcompany.com>
This commit is contained in:
Orgad Shaneh
2015-07-19 10:51:34 +03:00
committed by Orgad Shaneh
parent 67cfdbd224
commit 91cd7b9a33

View File

@@ -96,42 +96,35 @@ const char PLUGINPATH_OPTION[] = "-pluginpath";
typedef QList<PluginSpec *> PluginSpecSet; typedef QList<PluginSpec *> PluginSpecSet;
// Helpers for displaying messages. Note that there is no console on Windows. // Helpers for displaying messages. Note that there is no console on Windows.
#ifdef Q_OS_WIN
// Format as <pre> HTML // Format as <pre> HTML
static inline void toHtml(QString &t) static inline QString toHtml(const QString &t)
{ {
t.replace(QLatin1Char('&'), QLatin1String("&amp;")); QString res = t;
t.replace(QLatin1Char('<'), QLatin1String("&lt;")); res.replace(QLatin1Char('&'), QLatin1String("&amp;"));
t.replace(QLatin1Char('>'), QLatin1String("&gt;")); res.replace(QLatin1Char('<'), QLatin1String("&lt;"));
t.insert(0, QLatin1String("<html><pre>")); res.replace(QLatin1Char('>'), QLatin1String("&gt;"));
t.append(QLatin1String("</pre></html>")); res.insert(0, QLatin1String("<html><pre>"));
res.append(QLatin1String("</pre></html>"));
return res;
} }
static void displayHelpText(QString t) // No console on Windows.
{
toHtml(t);
QMessageBox::information(0, QLatin1String(appNameC), t);
}
static void displayError(const QString &t) // No console on Windows.
{
QMessageBox::critical(0, QLatin1String(appNameC), t);
}
#else
static void displayHelpText(const QString &t) static void displayHelpText(const QString &t)
{ {
if (Utils::HostOsInfo::isWindowsHost())
QMessageBox::information(0, QLatin1String(appNameC), toHtml(t));
else
qWarning("%s", qPrintable(t)); qWarning("%s", qPrintable(t));
} }
static void displayError(const QString &t) static void displayError(const QString &t)
{ {
if (Utils::HostOsInfo::isWindowsHost())
QMessageBox::critical(0, QLatin1String(appNameC), t);
else
qCritical("%s", qPrintable(t)); qCritical("%s", qPrintable(t));
} }
#endif
static void printVersion(const PluginSpec *coreplugin) static void printVersion(const PluginSpec *coreplugin)
{ {
QString version; QString version;
@@ -200,19 +193,19 @@ static inline QStringList getPluginPaths()
QDir rootDir = QApplication::applicationDirPath(); QDir rootDir = QApplication::applicationDirPath();
rootDir.cdUp(); rootDir.cdUp();
const QString rootDirPath = rootDir.canonicalPath(); const QString rootDirPath = rootDir.canonicalPath();
#if !defined(Q_OS_MAC) QString pluginPath;
// 1) "plugins" (Win/Linux) if (Utils::HostOsInfo::isMacHost()) {
QString pluginPath = rootDirPath; // 1) "PlugIns" (OS X)
pluginPath = rootDirPath + QLatin1String("/PlugIns");
rc.push_back(pluginPath);
} else {
// 2) "plugins" (Win/Linux)
pluginPath = rootDirPath;
pluginPath += QLatin1Char('/'); pluginPath += QLatin1Char('/');
pluginPath += QLatin1String(IDE_LIBRARY_BASENAME); pluginPath += QLatin1String(IDE_LIBRARY_BASENAME);
pluginPath += QLatin1String("/qtcreator/plugins"); pluginPath += QLatin1String("/qtcreator/plugins");
rc.push_back(pluginPath); rc.push_back(pluginPath);
#else }
// 2) "PlugIns" (OS X)
QString pluginPath = rootDirPath;
pluginPath += QLatin1String("/PlugIns");
rc.push_back(pluginPath);
#endif
// 3) <localappdata>/plugins/<ideversion> // 3) <localappdata>/plugins/<ideversion>
// where <localappdata> is e.g. // where <localappdata> is e.g.
// "%LOCALAPPDATA%\QtProject\qtcreator" on Windows Vista and later // "%LOCALAPPDATA%\QtProject\qtcreator" on Windows Vista and later
@@ -225,11 +218,7 @@ static inline QStringList getPluginPaths()
pluginPath += QLatin1Char('/') pluginPath += QLatin1Char('/')
+ QLatin1String(Core::Constants::IDE_SETTINGSVARIANT_STR) + QLatin1String(Core::Constants::IDE_SETTINGSVARIANT_STR)
+ QLatin1Char('/'); + QLatin1Char('/');
#if !defined(Q_OS_MAC) pluginPath += QLatin1String(Utils::HostOsInfo::isMacHost() ? "Qt Creator" : "qtcreator");
pluginPath += QLatin1String("qtcreator");
#else
pluginPath += QLatin1String("Qt Creator");
#endif
pluginPath += QLatin1String("/plugins/"); pluginPath += QLatin1String("/plugins/");
pluginPath += QLatin1String(Core::Constants::IDE_VERSION_LONG); pluginPath += QLatin1String(Core::Constants::IDE_VERSION_LONG);
rc.push_back(pluginPath); rc.push_back(pluginPath);
@@ -286,11 +275,8 @@ static inline QSettings *userSettings()
return createUserSettings(); return createUserSettings();
} }
#ifdef Q_OS_MAC static const char *SHARE_PATH =
# define SHARE_PATH "/../Resources" Utils::HostOsInfo::isMacHost() ? "/../Resources" : "/../share/qtcreator";
#else
# define SHARE_PATH "/../share/qtcreator"
#endif
int main(int argc, char **argv) int main(int argc, char **argv)
{ {
@@ -391,7 +377,7 @@ int main(int argc, char **argv)
if (!overrideLanguage.isEmpty()) if (!overrideLanguage.isEmpty())
uiLanguages.prepend(overrideLanguage); uiLanguages.prepend(overrideLanguage);
const QString &creatorTrPath = QCoreApplication::applicationDirPath() const QString &creatorTrPath = QCoreApplication::applicationDirPath()
+ QLatin1String(SHARE_PATH "/translations"); + QLatin1String(SHARE_PATH) + QLatin1String("/translations");
foreach (QString locale, uiLanguages) { foreach (QString locale, uiLanguages) {
locale = QLocale(locale).name(); locale = QLocale(locale).name();
if (translator.load(QLatin1String("qtcreator_") + locale, creatorTrPath)) { if (translator.load(QLatin1String("qtcreator_") + locale, creatorTrPath)) {