Commit 6274875a authored by Christian Kandeler's avatar Christian Kandeler

QbsProjectManager: Allow to use default qbs settings dir.

By default, we use a dedicated qbs settings dir located in Creator's
settings path, so that different instances of Qt Creator won't
overwrite each other's profiles. Users for whom this is not a concern
can now choose to use the normal qbs settings dir.

Change-Id: I0119228a48cfee430686ab51f69864866f4ba270
Reviewed-by: default avatarJoerg Bornemann <joerg.bornemann@theqtcompany.com>
parent c165f2f0
......@@ -31,6 +31,7 @@
#include "qbsinstallstep.h"
#include "qbsproject.h"
#include "qbsprojectmanagerconstants.h"
#include "qbsprojectmanagersettings.h"
#include <coreplugin/documentmanager.h>
#include <coreplugin/icore.h>
......@@ -285,8 +286,10 @@ QString QbsBuildConfiguration::equivalentCommandLine(const BuildStep *buildStep)
}
Utils::QtcProcess::addArgs(&commandLine, QStringList() << QLatin1String("-f")
<< buildStep->project()->projectFilePath().toUserOutput());
Utils::QtcProcess::addArgs(&commandLine, QStringList() << QLatin1String("--settings-dir")
<< QDir::toNativeSeparators(Core::ICore::userResourcePath()));
if (QbsProjectManagerSettings::useCreatorSettingsDirForQbs()) {
Utils::QtcProcess::addArgs(&commandLine, QStringList() << QLatin1String("--settings-dir")
<< QDir::toNativeSeparators(QbsProjectManagerSettings::qbsSettingsBaseDir()));
}
if (stepProxy.dryRun())
Utils::QtcProcess::addArg(&commandLine, QLatin1String("--dry-run"));
if (stepProxy.keepGoing())
......
......@@ -29,6 +29,7 @@
#include "qbsparser.h"
#include "qbsproject.h"
#include "qbsprojectmanagerconstants.h"
#include "qbsprojectmanagersettings.h"
#include "ui_qbsbuildstepconfigwidget.h"
......@@ -455,6 +456,8 @@ QbsBuildStepConfigWidget::QbsBuildStepConfigWidget(QbsBuildStep *step) :
connect(m_step, SIGNAL(displayNameChanged()), this, SLOT(updateState()));
connect(m_step, SIGNAL(qbsConfigurationChanged()), this, SLOT(updateState()));
connect(m_step, SIGNAL(qbsBuildOptionsChanged()), this, SLOT(updateState()));
connect(&QbsProjectManagerSettings::instance(), &QbsProjectManagerSettings::settingsBaseChanged,
this, &QbsBuildStepConfigWidget::updateState);
setContentsMargins(0, 0, 0, 0);
......
......@@ -29,6 +29,7 @@
#include "customqbspropertiesdialog.h"
#include "qbsconstants.h"
#include "qbsprojectmanager.h"
#include "qbsprojectmanagersettings.h"
#include <coreplugin/icore.h>
#include <projectexplorer/kit.h>
......@@ -51,7 +52,7 @@ class QbsProfilesSettingsWidget : public QWidget
public:
QbsProfilesSettingsWidget(QWidget *parent = 0);
void applyCustomProperties();
void apply();
private slots:
void refreshKitsList();
......@@ -71,7 +72,10 @@ private:
};
QbsProfilesSettingsPage::QbsProfilesSettingsPage(QObject *parent)
: Core::IOptionsPage(parent), m_widget(0)
: Core::IOptionsPage(parent)
, m_widget(0)
, m_useQtcSettingsDirPersistent(QbsProjectManagerSettings::useCreatorSettingsDirForQbs())
{
setId("AA.QbsProfiles");
setDisplayName(QCoreApplication::translate("QbsProjectManager", "Profiles"));
......@@ -91,32 +95,41 @@ QWidget *QbsProfilesSettingsPage::widget()
void QbsProfilesSettingsPage::apply()
{
if (m_widget)
m_widget->applyCustomProperties();
m_widget->apply();
m_useQtcSettingsDirPersistent = QbsProjectManagerSettings::useCreatorSettingsDirForQbs();
}
void QbsProfilesSettingsPage::finish()
{
delete m_widget;
m_widget = 0;
QbsProjectManagerSettings::setUseCreatorSettingsDirForQbs(m_useQtcSettingsDirPersistent);
QbsProjectManagerSettings::writeSettings();
}
QbsProfilesSettingsWidget::QbsProfilesSettingsWidget(QWidget *parent)
: QWidget(parent)
, m_model(Core::ICore::userResourcePath())
, m_model(QbsProjectManagerSettings::qbsSettingsBaseDir())
, m_applyingProperties(false)
{
m_model.setEditable(false);
m_ui.setupUi(this);
m_ui.settingsDirCheckBox->setChecked(QbsProjectManagerSettings::useCreatorSettingsDirForQbs());
connect(ProjectExplorer::KitManager::instance(), &ProjectExplorer::KitManager::kitsChanged,
this, &QbsProfilesSettingsWidget::refreshKitsList);
connect(m_ui.settingsDirCheckBox, &QCheckBox::stateChanged, [this]() {
QbsProjectManagerSettings::setUseCreatorSettingsDirForQbs(m_ui.settingsDirCheckBox->isChecked());
m_model.updateSettingsDir(QbsProjectManagerSettings::qbsSettingsBaseDir());
displayCurrentProfile();
});
connect(m_ui.expandButton, SIGNAL(clicked()), m_ui.propertiesView, SLOT(expandAll()));
connect(m_ui.collapseButton, SIGNAL(clicked()), m_ui.propertiesView, SLOT(collapseAll()));
connect(m_ui.editButton, SIGNAL(clicked()), SLOT(editProfile()));
refreshKitsList();
}
void QbsProfilesSettingsWidget::applyCustomProperties()
void QbsProfilesSettingsWidget::apply()
{
QTC_ASSERT(!m_applyingProperties, return);
m_applyingProperties = true; // The following will cause kitsChanged() to be emitted.
......
......@@ -43,6 +43,7 @@ private:
void finish() override;
QbsProfilesSettingsWidget *m_widget;
bool m_useQtcSettingsDirPersistent;
};
} // namespace Internal
......
......@@ -6,14 +6,21 @@
<rect>
<x>0</x>
<y>0</y>
<width>421</width>
<height>315</height>
<width>537</width>
<height>458</height>
</rect>
</property>
<property name="windowTitle">
<string>Form</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout_2">
<item>
<widget class="QCheckBox" name="settingsDirCheckBox">
<property name="text">
<string>Store profiles in Qt Creator settings directory</string>
</property>
</widget>
</item>
<item>
<layout class="QFormLayout" name="formLayout">
<item row="0" column="0">
......
......@@ -30,6 +30,7 @@
#include "qbsproject.h"
#include "qbsprojectmanagerconstants.h"
#include "qbsprojectmanagerplugin.h"
#include "qbsprojectmanagersettings.h"
#include <coreplugin/icore.h>
#include <coreplugin/messagemanager.h>
......@@ -62,7 +63,6 @@ QbsManager *QbsManager::m_instance = 0;
QbsManager::QbsManager() :
m_defaultPropertyProvider(new DefaultPropertyProvider)
{
m_settings = new qbs::Settings(Core::ICore::userResourcePath());
m_instance = this;
setObjectName(QLatin1String("QbsProjectManager"));
......@@ -74,6 +74,8 @@ QbsManager::QbsManager() :
&QbsManager::handleKitUpdate);
connect(ProjectExplorer::KitManager::instance(), &ProjectExplorer::KitManager::kitRemoved, this,
&QbsManager::handleKitRemoval);
connect(&QbsProjectManagerSettings::instance(), &QbsProjectManagerSettings::settingsBaseChanged,
this, &QbsManager::updateAllProfiles);
m_logSink = new QbsLogSink(this);
int level = qbs::LoggerWarning;
......@@ -121,12 +123,12 @@ QString QbsManager::profileForKit(const ProjectExplorer::Kit *k)
if (!k)
return QString();
updateProfileIfNecessary(k);
return m_settings->value(qtcProfilePrefix() + k->id().toString()).toString();
return settings()->value(qtcProfilePrefix() + k->id().toString()).toString();
}
void QbsManager::setProfileForKit(const QString &name, const ProjectExplorer::Kit *k)
{
m_settings->setValue(qtcProfilePrefix() + k->id().toString(), name);
settings()->setValue(qtcProfilePrefix() + k->id().toString(), name);
}
void QbsManager::updateProfileIfNecessary(const ProjectExplorer::Kit *kit)
......@@ -137,6 +139,22 @@ void QbsManager::updateProfileIfNecessary(const ProjectExplorer::Kit *kit)
addProfileFromKit(kit);
}
void QbsManager::updateAllProfiles()
{
foreach (const auto * const kit, ProjectExplorer::KitManager::kits())
addProfileFromKit(kit);
}
qbs::Settings *QbsManager::settings()
{
if (!m_settings
|| m_settings->baseDirectory() != QbsProjectManagerSettings::qbsSettingsBaseDir()) {
delete m_settings;
m_settings = new qbs::Settings(QbsProjectManagerSettings::qbsSettingsBaseDir());
}
return m_settings;
}
void QbsManager::addProfile(const QString &name, const QVariantMap &data)
{
qbs::Profile profile(name, settings());
......@@ -217,9 +235,9 @@ void QbsManager::handleKitRemoval(ProjectExplorer::Kit *kit)
{
m_kitsToBeSetupForQbs.removeOne(kit);
const QString key = qtcProfilePrefix() + kit->id().toString();
const QString profileName = m_settings->value(key).toString();
m_settings->remove(key);
qbs::Profile(profileName, m_settings).removeProfile();
const QString profileName = settings()->value(key).toString();
settings()->remove(key);
qbs::Profile(profileName, settings()).removeProfile();
}
} // namespace Internal
......
......@@ -69,7 +69,7 @@ public:
void updateProfileIfNecessary(const ProjectExplorer::Kit *kit);
static qbs::Settings *settings() { return m_settings; }
static qbs::Settings *settings();
static Internal::QbsLogSink *logSink() { return m_logSink; }
static QbsManager *instance() { return m_instance; }
......@@ -77,6 +77,7 @@ private:
void addProfile(const QString &name, const QVariantMap &data);
void addQtProfileFromKit(const QString &profileName, const ProjectExplorer::Kit *k);
void addProfileFromKit(const ProjectExplorer::Kit *k);
void updateAllProfiles();
void handleKitUpdate(ProjectExplorer::Kit *kit);
void handleKitRemoval(ProjectExplorer::Kit *kit);
......
......@@ -38,6 +38,7 @@ HEADERS = \
qbsprojectmanager_global.h \
qbsprojectmanagerconstants.h \
qbsprojectmanagerplugin.h \
qbsprojectmanagersettings.h \
qbsprojectparser.h \
qbsrunconfiguration.h \
qbsconstants.h
......@@ -60,6 +61,7 @@ SOURCES = \
qbsprojectfile.cpp \
qbsprojectmanager.cpp \
qbsprojectmanagerplugin.cpp \
qbsprojectmanagersettings.cpp \
qbsprojectparser.cpp \
qbsrunconfiguration.cpp
......
......@@ -104,6 +104,8 @@ QtcPlugin {
"qbsprojectmanagerconstants.h",
"qbsprojectmanagerplugin.cpp",
"qbsprojectmanagerplugin.h",
"qbsprojectmanagersettings.cpp",
"qbsprojectmanagersettings.h",
"qbsprojectparser.cpp",
"qbsprojectparser.h",
"qbsrunconfiguration.cpp",
......
/****************************************************************************
**
** Copyright (C) 2016 The Qt Company Ltd.
** Contact: https://www.qt.io/licensing/
**
** This file is part of Qt Creator.
**
** Commercial License Usage
** Licensees holding valid commercial Qt licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and The Qt Company. For licensing terms
** and conditions see https://www.qt.io/terms-conditions. For further
** information use the contact form at https://www.qt.io/contact-us.
**
** GNU General Public License Usage
** Alternatively, this file may be used under the terms of the GNU
** General Public License version 3 as published by the Free Software
** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
** included in the packaging of this file. Please review the following
** information to ensure the GNU General Public License requirements will
** be met: https://www.gnu.org/licenses/gpl-3.0.html.
**
****************************************************************************/
#include "qbsprojectmanagersettings.h"
#include <coreplugin/icore.h>
namespace QbsProjectManager {
namespace Internal {
static QString settingsId() { return QLatin1String("QbsProjectManager"); }
static QString useCreatorDirKey() { return QLatin1String("useCreatorDir"); }
QbsProjectManagerSettings::QbsProjectManagerSettings()
{
readSettings();
}
void QbsProjectManagerSettings::readSettings()
{
QSettings * const settings = Core::ICore::settings();
settings->beginGroup(settingsId());
m_useCreatorSettings = settings->value(useCreatorDirKey(), true).toBool();
settings->endGroup();
}
void QbsProjectManagerSettings::doWriteSettings()
{
QSettings * const settings = Core::ICore::settings();
settings->beginGroup(settingsId());
settings->setValue(useCreatorDirKey(), m_useCreatorSettings);
settings->endGroup();
}
QbsProjectManagerSettings &QbsProjectManagerSettings::instance()
{
static QbsProjectManagerSettings settings;
return settings;
}
void QbsProjectManagerSettings::setUseCreatorSettingsDirForQbs(bool useCreatorDir)
{
if (instance().m_useCreatorSettings == useCreatorDir)
return;
instance().m_useCreatorSettings = useCreatorDir;
emit instance().settingsBaseChanged();
}
bool QbsProjectManagerSettings::useCreatorSettingsDirForQbs()
{
return instance().m_useCreatorSettings;
}
QString QbsProjectManagerSettings::qbsSettingsBaseDir()
{
return instance().m_useCreatorSettings ? Core::ICore::userResourcePath() : QString();
}
} // namespace Internal
} // namespace QbsProjectManager
/****************************************************************************
**
** Copyright (C) 2016 The Qt Company Ltd.
** Contact: https://www.qt.io/licensing/
**
** This file is part of Qt Creator.
**
** Commercial License Usage
** Licensees holding valid commercial Qt licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and The Qt Company. For licensing terms
** and conditions see https://www.qt.io/terms-conditions. For further
** information use the contact form at https://www.qt.io/contact-us.
**
** GNU General Public License Usage
** Alternatively, this file may be used under the terms of the GNU
** General Public License version 3 as published by the Free Software
** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
** included in the packaging of this file. Please review the following
** information to ensure the GNU General Public License requirements will
** be met: https://www.gnu.org/licenses/gpl-3.0.html.
**
****************************************************************************/
#ifndef QBSPROJECTMANAGERSETTINGS_H
#define QBSPROJECTMANAGERSETTINGS_H
#include <QObject>
namespace QbsProjectManager {
namespace Internal {
class QbsProjectManagerSettings : public QObject
{
Q_OBJECT
public:
static QbsProjectManagerSettings &instance();
static void setUseCreatorSettingsDirForQbs(bool useCreatorDir);
static bool useCreatorSettingsDirForQbs();
static QString qbsSettingsBaseDir();
static void writeSettings() { instance().doWriteSettings(); }
signals:
void settingsBaseChanged();
private:
QbsProjectManagerSettings();
void readSettings();
void doWriteSettings();
bool m_useCreatorSettings;
};
} // namespace Internal
} // namespace QbsProjectManager
#endif // Include guard.
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