Commit d0a44fa4 authored by Tim Jenssen's avatar Tim Jenssen

introduce installsettingspath as an argument

Change-Id: I2435ddd09e25a73bd70efe847990dcfc57b8680e
Reviewed-by: Riitta-Leena Miettinen's avatarLeena Miettinen <riitta-leena.miettinen@qt.io>
Reviewed-by: Tim Jenssen's avatarTim Jenssen <tim.jenssen@qt.io>
parent bf970a59
......@@ -146,6 +146,11 @@
\li -settingspath <path>
\li Override the default path where user settings are stored.
\row
\li -installsettingspath <path>
\li Override the default path from where user-independent settings are read
(for example written by the installer).
\row
\li -color <color>
\li Core plugin: override the selected UI color.
......
......@@ -74,6 +74,7 @@ const char fixedOptionsC[] =
" -version Display program version\n"
" -client Attempt to connect to already running first instance\n"
" -settingspath <path> Override the default path where user settings are stored\n"
" -installsettingspath <path> Override the default path from where user-independent settings are read\n"
" -pid <pid> Attempt to connect to instance given by pid\n"
" -block Block until editor is closed\n"
" -pluginpath <path> Add a custom search path for plugins\n";
......@@ -85,6 +86,7 @@ const char HELP_OPTION4[] = "--help";
const char VERSION_OPTION[] = "-version";
const char CLIENT_OPTION[] = "-client";
const char SETTINGS_OPTION[] = "-settingspath";
const char INSTALL_SETTINGS_OPTION[] = "-installsettingspath";
const char TEST_OPTION[] = "-test";
const char PID_OPTION[] = "-pid";
const char BLOCK_OPTION[] = "-block";
......@@ -142,6 +144,11 @@ static void printHelp(const QString &a0)
displayHelpText(help);
}
static QString resourcePath()
{
return QDir::cleanPath(QCoreApplication::applicationDirPath() + '/' + RELATIVE_DATA_PATH);
}
static inline QString msgCoreLoadFailure(const QString &why)
{
return QCoreApplication::translate("Application", "Failed to load core: %1").arg(why);
......@@ -219,14 +226,20 @@ static inline QStringList getPluginPaths()
return rc;
}
static void setupInstallSettings()
static void setupInstallSettings(QString &installSettingspath)
{
if (!QFileInfo(installSettingspath).isDir()) {
displayHelpText(QString("-installsettingspath needs to be the path where a %1/%2.ini exist.").arg(
QLatin1String(Core::Constants::IDE_SETTINGSVARIANT_STR), QLatin1String(Core::Constants::IDE_CASED_ID)));
installSettingspath.clear();
}
// Check if the default install settings contain a setting for the actual install settings.
// This can be an absolute path, or a path relative to applicationDirPath().
// The result is interpreted like -settingspath, but for SystemScope
static const char kInstallSettingsKey[] = "Settings/InstallSettings";
QSettings::setPath(QSettings::IniFormat, QSettings::SystemScope,
QCoreApplication::applicationDirPath() + '/' + RELATIVE_DATA_PATH);
installSettingspath.isEmpty() ? resourcePath() : installSettingspath);
QSettings installSettings(QSettings::IniFormat, QSettings::UserScope,
QLatin1String(Core::Constants::IDE_SETTINGSVARIANT_STR),
QLatin1String(Core::Constants::IDE_CASED_ID));
......@@ -290,7 +303,7 @@ static inline QSettings *userSettings()
void loadFonts()
{
const QDir dir(QCoreApplication::applicationDirPath() + '/' + RELATIVE_DATA_PATH + "/fonts/");
const QDir dir(resourcePath() + "/fonts/");
foreach (const QFileInfo &fileInfo, dir.entryInfoList(QStringList("*.ttf"), QDir::Files))
QFontDatabase::addApplicationFont(fileInfo.absoluteFilePath());
......@@ -344,34 +357,29 @@ int main(int argc, char **argv)
app.setAttribute(Qt::AA_UseHighDpiPixmaps);
// Manually determine -settingspath command line option
// 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;
QStringList arguments = app.arguments(); // adapted arguments list is passed to plugin manager later
QMutableStringListIterator it(arguments);
bool testOptionProvided = false;
QStringList pluginArguments;
QStringListIterator it(app.arguments());
while (it.hasNext()) {
const QString &arg = it.next();
if (arg == QLatin1String(SETTINGS_OPTION)) {
it.remove();
if (it.hasNext()) {
if (arg == SETTINGS_OPTION && it.hasNext())
settingsPath = QDir::fromNativeSeparators(it.next());
it.remove();
}
} else if (arg == QLatin1String(PLUGINPATH_OPTION)) {
it.remove();
if (it.hasNext()) {
customPluginPaths << QDir::fromNativeSeparators(it.next());
it.remove();
}
} else if (arg == QLatin1String(TEST_OPTION)) {
testOptionProvided = true;
}
else if (arg == INSTALL_SETTINGS_OPTION && it.hasNext())
installSettingsPath = QDir::fromNativeSeparators(it.next());
else if (arg == PLUGINPATH_OPTION && it.hasNext())
customPluginPaths += QDir::fromNativeSeparators(it.next());
else
pluginArguments.append(arg);
}
QScopedPointer<Utils::TemporaryDirectory> temporaryCleanSettingsDir;
if (settingsPath.isEmpty() && testOptionProvided) {
if (settingsPath.isEmpty() && pluginArguments.contains(TEST_OPTION)) {
temporaryCleanSettingsDir.reset(new Utils::TemporaryDirectory("qtc-test-settings"));
if (!temporaryCleanSettingsDir->isValid())
return 1;
......@@ -382,7 +390,7 @@ int main(int argc, char **argv)
// Must be done before any QSettings class is created
QSettings::setDefaultFormat(QSettings::IniFormat);
setupInstallSettings();
setupInstallSettings(installSettingsPath);
// plugin manager takes control of this settings object
QSettings *settings = userSettings();
......@@ -401,8 +409,7 @@ int main(int argc, char **argv)
QString overrideLanguage = settings->value(QLatin1String("General/OverrideLanguage")).toString();
if (!overrideLanguage.isEmpty())
uiLanguages.prepend(overrideLanguage);
const QString &creatorTrPath = QCoreApplication::applicationDirPath()
+ '/' + RELATIVE_DATA_PATH + "/translations";
const QString &creatorTrPath = resourcePath() + "/translations";
foreach (QString locale, uiLanguages) {
locale = QLocale(locale).name();
if (translator.load(QString::fromLatin1(Core::Constants::IDE_ID) + "_" + locale, creatorTrPath)) {
......@@ -432,7 +439,7 @@ int main(int argc, char **argv)
const QStringList pluginPaths = getPluginPaths() + customPluginPaths;
PluginManager::setPluginPaths(pluginPaths);
QMap<QString, QString> foundAppOptions;
if (arguments.size() > 1) {
if (pluginArguments.size() > 1) {
QMap<QString, bool> appOptions;
appOptions.insert(QLatin1String(HELP_OPTION1), false);
appOptions.insert(QLatin1String(HELP_OPTION2), false);
......@@ -443,7 +450,7 @@ int main(int argc, char **argv)
appOptions.insert(QLatin1String(PID_OPTION), true);
appOptions.insert(QLatin1String(BLOCK_OPTION), false);
QString errorMessage;
if (!PluginManager::parseOptions(arguments, appOptions, &foundAppOptions, &errorMessage)) {
if (!PluginManager::parseOptions(pluginArguments, appOptions, &foundAppOptions, &errorMessage)) {
displayError(errorMessage);
printHelp(QFileInfo(app.applicationFilePath()).baseName());
return -1;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment