summaryrefslogtreecommitdiff
path: root/src/app
diff options
context:
space:
mode:
Diffstat (limited to 'src/app')
-rw-r--r--src/app/main.cpp63
1 files changed, 35 insertions, 28 deletions
diff --git a/src/app/main.cpp b/src/app/main.cpp
index fa6e93ef8e..b2ccbc4f3b 100644
--- a/src/app/main.cpp
+++ b/src/app/main.cpp
@@ -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()) {
- 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;
- }
+ if (arg == SETTINGS_OPTION && it.hasNext())
+ settingsPath = QDir::fromNativeSeparators(it.next());
+ 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;