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