diff options
author | Eike Ziller <eike.ziller@qt.io> | 2018-06-06 10:32:39 +0200 |
---|---|---|
committer | Eike Ziller <eike.ziller@qt.io> | 2018-06-08 06:48:22 +0000 |
commit | 93d35399b59a7b6b1a0ad6fea9ae8b3dd0bf14f7 (patch) | |
tree | 0484791acb17dc12e1dd3d4a7ce05acc1f43c329 /src/app | |
parent | cbd4d05423da34891abba5e0c7b51b646f3aa101 (diff) |
App: Pull special command line parsing into separate function
Change-Id: I143aa3f49b3e9fb5a1aa30cf9c9364c61b95ced4
Reviewed-by: Tobias Hunger <tobias.hunger@qt.io>
Diffstat (limited to 'src/app')
-rw-r--r-- | src/app/main.cpp | 91 |
1 files changed, 50 insertions, 41 deletions
diff --git a/src/app/main.cpp b/src/app/main.cpp index 3660a111e5..2c0b28ac70 100644 --- a/src/app/main.cpp +++ b/src/app/main.cpp @@ -337,6 +337,43 @@ void loadFonts() QFontDatabase::addApplicationFont(fileInfo.absoluteFilePath()); } +struct Options +{ + QString settingsPath; + QString installSettingsPath; + QStringList customPluginPaths; + std::vector<char *> appArguments; + bool hasTestOption = false; +}; + +Options parseCommandLine(int argc, char *argv[]) +{ + Options options; + auto it = argv; + const auto end = argv + argc; + while (it != end) { + const auto arg = QString::fromLocal8Bit(*it); + const bool hasNext = it + 1 != end; + + if (arg == SETTINGS_OPTION && hasNext) { + ++it; + options.settingsPath = QDir::fromNativeSeparators(QString::fromLocal8Bit(*it)); + } else if (arg == INSTALL_SETTINGS_OPTION && hasNext) { + ++it; + options.installSettingsPath = QDir::fromNativeSeparators(QString::fromLocal8Bit(*it)); + } else if (arg == PLUGINPATH_OPTION && hasNext) { + ++it; + options.customPluginPaths += QDir::fromNativeSeparators(QString::fromLocal8Bit(*it)); + } else { // arguments that are still passed on to the application + if (arg == TEST_OPTION) + options.hasTestOption = true; + options.appArguments.push_back(*it); + } + ++it; + } + return options; +} + int main(int argc, char **argv) { #ifdef Q_OS_WIN @@ -362,68 +399,40 @@ int main(int argc, char **argv) setrlimit(RLIMIT_NOFILE, &rl); #endif - // Manually determine -settingspath and -installsettingspath command line options - // We can't use the regular way of the plugin manager, because that needs to parse plugin meta data - // but the settings path can influence which plugins are enabled - QString settingsPath; - QString installSettingsPath; - QStringList customPluginPaths; - std::vector<char *> appArguments; - bool hasTestOption = false; - - auto it = argv; - const auto end = argv + argc; - while (it != end) { - const auto arg = QString::fromLocal8Bit(*it); - const bool hasNext = it + 1 != end; - - if (arg == SETTINGS_OPTION && hasNext) { - ++it; - settingsPath = QDir::fromNativeSeparators(QString::fromLocal8Bit(*it)); - } else if (arg == INSTALL_SETTINGS_OPTION && hasNext) { - ++it; - installSettingsPath = QDir::fromNativeSeparators(QString::fromLocal8Bit(*it)); - } else if (arg == PLUGINPATH_OPTION && hasNext) { - ++it; - customPluginPaths += QDir::fromNativeSeparators(QString::fromLocal8Bit(*it)); - } else { - if (arg == TEST_OPTION) - hasTestOption = true; - appArguments.push_back(*it); - } - ++it; - } - + // Manually determine various command line options + // We can't use the regular way of the plugin manager, + // because settings can change the way plugin manager behaves + Options options = parseCommandLine(argc, argv); applicationDirPath(argv[0]); QScopedPointer<Utils::TemporaryDirectory> temporaryCleanSettingsDir; - if (settingsPath.isEmpty() && hasTestOption) { + if (options.settingsPath.isEmpty() && options.hasTestOption) { temporaryCleanSettingsDir.reset(new Utils::TemporaryDirectory("qtc-test-settings")); if (!temporaryCleanSettingsDir->isValid()) return 1; - settingsPath = temporaryCleanSettingsDir->path(); + options.settingsPath = temporaryCleanSettingsDir->path(); } - if (!settingsPath.isEmpty()) - QSettings::setPath(QSettings::IniFormat, QSettings::UserScope, settingsPath); + if (!options.settingsPath.isEmpty()) + QSettings::setPath(QSettings::IniFormat, QSettings::UserScope, options.settingsPath); // Must be done before any QSettings class is created QSettings::setDefaultFormat(QSettings::IniFormat); - setupInstallSettings(installSettingsPath); + setupInstallSettings(options.installSettingsPath); // plugin manager takes control of this settings object setHighDpiEnvironmentVariable(); SharedTools::QtSingleApplication::setAttribute(Qt::AA_ShareOpenGLContexts); - int numberofArguments = static_cast<int>(appArguments.size()); + int numberofArguments = static_cast<int>(options.appArguments.size()); SharedTools::QtSingleApplication app((QLatin1String(Core::Constants::IDE_DISPLAY_NAME)), numberofArguments, - appArguments.data()); + options.appArguments.data()); const QStringList pluginArguments = app.arguments(); /*Initialize global settings and resetup install settings with QApplication::applicationDirPath */ - setupInstallSettings(installSettingsPath); + setupInstallSettings(options.installSettingsPath); QSettings *settings = userSettings(); QSettings *globalSettings = new QSettings(QSettings::IniFormat, QSettings::SystemScope, QLatin1String(Core::Constants::IDE_SETTINGSVARIANT_STR), @@ -490,7 +499,7 @@ int main(int argc, char **argv) QNetworkProxyFactory::setUseSystemConfiguration(true); // Load - const QStringList pluginPaths = getPluginPaths() + customPluginPaths; + const QStringList pluginPaths = getPluginPaths() + options.customPluginPaths; PluginManager::setPluginPaths(pluginPaths); QMap<QString, QString> foundAppOptions; if (pluginArguments.size() > 1) { |