Bazaar: Remove direct accesses to singletons

Change-Id: Ie736597dcc17256fc1ef912689ef86e706acbd99
Reviewed-by: Orgad Shaneh <orgads@gmail.com>
This commit is contained in:
hjk
2020-01-24 14:10:01 +01:00
parent f39e9be2f2
commit 60f0e06942
6 changed files with 33 additions and 40 deletions

View File

@@ -168,7 +168,7 @@ BazaarPluginPrivate::BazaarPluginPrivate()
connect(m_client, &VcsBaseClient::changed, vcsCtrl, &BazaarControl::changed); connect(m_client, &VcsBaseClient::changed, vcsCtrl, &BazaarControl::changed);
new OptionsPage(vcsCtrl, this); new OptionsPage(vcsCtrl, &m_bazaarSettings, this);
const auto describeFunc = [this](const QString &source, const QString &id) { const auto describeFunc = [this](const QString &source, const QString &id) {
m_client->view(source, id); m_client->view(source, id);
@@ -187,11 +187,6 @@ BazaarPluginPrivate::BazaarPluginPrivate()
createMenu(context); createMenu(context);
} }
BazaarPluginPrivate *BazaarPluginPrivate::instance()
{
return dd;
}
BazaarClient *BazaarPluginPrivate::client() const BazaarClient *BazaarPluginPrivate::client() const
{ {
return m_client; return m_client;
@@ -635,7 +630,7 @@ void BazaarPluginPrivate::uncommit()
const VcsBasePluginState state = currentState(); const VcsBasePluginState state = currentState();
QTC_ASSERT(state.hasTopLevel(), return); QTC_ASSERT(state.hasTopLevel(), return);
UnCommitDialog dialog(ICore::dialogParent()); UnCommitDialog dialog(this, ICore::dialogParent());
if (dialog.exec() == QDialog::Accepted) if (dialog.exec() == QDialog::Accepted)
m_client->synchronousUncommit(state.topLevel(), dialog.revision(), dialog.extraOptions()); m_client->synchronousUncommit(state.topLevel(), dialog.revision(), dialog.extraOptions());
} }

View File

@@ -59,7 +59,6 @@ public:
BazaarPluginPrivate(); BazaarPluginPrivate();
~BazaarPluginPrivate() final; ~BazaarPluginPrivate() final;
static BazaarPluginPrivate *instance();
BazaarClient *client() const; BazaarClient *client() const;
protected: protected:

View File

@@ -42,53 +42,53 @@ class OptionsPageWidget final : public Core::IOptionsPageWidget
Q_DECLARE_TR_FUNCTIONS(Bazaar::Internal::OptionsPageWidget) Q_DECLARE_TR_FUNCTIONS(Bazaar::Internal::OptionsPageWidget)
public: public:
OptionsPageWidget(Core::IVersionControl *control); OptionsPageWidget(Core::IVersionControl *control, BazaarSettings *settings);
void apply() final; void apply() final;
private: private:
Ui::OptionsPage m_ui; Ui::OptionsPage m_ui;
Core::IVersionControl *m_control; Core::IVersionControl *m_control;
BazaarClient *m_client; BazaarSettings *m_settings;
}; };
void OptionsPageWidget::apply() void OptionsPageWidget::apply()
{ {
VcsBaseClientSettings s = BazaarPluginPrivate::instance()->client()->settings(); BazaarSettings s = *m_settings;
s.setValue(BazaarSettings::binaryPathKey, m_ui.commandChooser->rawPath()); s.setValue(BazaarSettings::binaryPathKey, m_ui.commandChooser->rawPath());
s.setValue(BazaarSettings::userNameKey, m_ui.defaultUsernameLineEdit->text().trimmed()); s.setValue(BazaarSettings::userNameKey, m_ui.defaultUsernameLineEdit->text().trimmed());
s.setValue(BazaarSettings::userEmailKey, m_ui.defaultEmailLineEdit->text().trimmed()); s.setValue(BazaarSettings::userEmailKey, m_ui.defaultEmailLineEdit->text().trimmed());
s.setValue(BazaarSettings::logCountKey, m_ui.logEntriesCount->value()); s.setValue(BazaarSettings::logCountKey, m_ui.logEntriesCount->value());
s.setValue(BazaarSettings::timeoutKey, m_ui.timeout->value()); s.setValue(BazaarSettings::timeoutKey, m_ui.timeout->value());
const bool notify = m_client->settings() != s; if (*m_settings == s)
m_client->settings() = s; return;
if (notify)
emit m_control->configurationChanged(); *m_settings = s;
emit m_control->configurationChanged();
} }
OptionsPageWidget::OptionsPageWidget(Core::IVersionControl *control) OptionsPageWidget::OptionsPageWidget(Core::IVersionControl *control, BazaarSettings *settings)
: m_control(control), m_client(BazaarPluginPrivate::instance()->client()) : m_control(control), m_settings(settings)
{ {
m_ui.setupUi(this); m_ui.setupUi(this);
m_ui.commandChooser->setExpectedKind(Utils::PathChooser::ExistingCommand); m_ui.commandChooser->setExpectedKind(Utils::PathChooser::ExistingCommand);
m_ui.commandChooser->setPromptDialogTitle(tr("Bazaar Command")); m_ui.commandChooser->setPromptDialogTitle(tr("Bazaar Command"));
m_ui.commandChooser->setHistoryCompleter(QLatin1String("Bazaar.Command.History")); m_ui.commandChooser->setHistoryCompleter(QLatin1String("Bazaar.Command.History"));
VcsBaseClientSettings s = m_client->settings(); m_ui.commandChooser->setPath(m_settings->stringValue(BazaarSettings::binaryPathKey));
m_ui.commandChooser->setPath(s.stringValue(BazaarSettings::binaryPathKey)); m_ui.defaultUsernameLineEdit->setText(m_settings->stringValue(BazaarSettings::userNameKey));
m_ui.defaultUsernameLineEdit->setText(s.stringValue(BazaarSettings::userNameKey)); m_ui.defaultEmailLineEdit->setText(m_settings->stringValue(BazaarSettings::userEmailKey));
m_ui.defaultEmailLineEdit->setText(s.stringValue(BazaarSettings::userEmailKey)); m_ui.logEntriesCount->setValue(m_settings->intValue(BazaarSettings::logCountKey));
m_ui.logEntriesCount->setValue(s.intValue(BazaarSettings::logCountKey)); m_ui.timeout->setValue(m_settings->intValue(BazaarSettings::timeoutKey));
m_ui.timeout->setValue(s.intValue(BazaarSettings::timeoutKey));
} }
OptionsPage::OptionsPage(Core::IVersionControl *control, QObject *parent) : OptionsPage::OptionsPage(Core::IVersionControl *control, BazaarSettings *settings, QObject *parent) :
Core::IOptionsPage(parent) Core::IOptionsPage(parent)
{ {
setId(VcsBase::Constants::VCS_ID_BAZAAR); setId(VcsBase::Constants::VCS_ID_BAZAAR);
setDisplayName(OptionsPageWidget::tr("Bazaar")); setDisplayName(OptionsPageWidget::tr("Bazaar"));
setWidgetCreator([control] { return new OptionsPageWidget(control); }); setWidgetCreator([control, settings] { return new OptionsPageWidget(control, settings); });
setCategory(Constants::VCS_SETTINGS_CATEGORY); setCategory(Constants::VCS_SETTINGS_CATEGORY);
} }

View File

@@ -30,10 +30,12 @@
namespace Bazaar { namespace Bazaar {
namespace Internal { namespace Internal {
class BazaarSettings;
class OptionsPage final : public Core::IOptionsPage class OptionsPage final : public Core::IOptionsPage
{ {
public: public:
OptionsPage(Core::IVersionControl *control, QObject *parent); OptionsPage(Core::IVersionControl *control, BazaarSettings *settings, QObject *parent);
}; };
} // namespace Internal } // namespace Internal

View File

@@ -35,7 +35,8 @@
namespace Bazaar { namespace Bazaar {
namespace Internal { namespace Internal {
UnCommitDialog::UnCommitDialog(QWidget *parent) : QDialog(parent), UnCommitDialog::UnCommitDialog(BazaarPluginPrivate *bzrPlugin, QWidget *parent) :
QDialog(parent),
m_ui(new Ui::UnCommitDialog) m_ui(new Ui::UnCommitDialog)
{ {
m_ui->setupUi(this); m_ui->setupUi(this);
@@ -43,7 +44,12 @@ UnCommitDialog::UnCommitDialog(QWidget *parent) : QDialog(parent),
auto dryRunBtn = new QPushButton(tr("Dry Run")); auto dryRunBtn = new QPushButton(tr("Dry Run"));
dryRunBtn->setToolTip(tr("Test the outcome of removing the last committed revision, without actually removing anything.")); dryRunBtn->setToolTip(tr("Test the outcome of removing the last committed revision, without actually removing anything."));
m_ui->buttonBox->addButton(dryRunBtn, QDialogButtonBox::ApplyRole); m_ui->buttonBox->addButton(dryRunBtn, QDialogButtonBox::ApplyRole);
connect(dryRunBtn, &QPushButton::clicked, this, &UnCommitDialog::dryRun); connect(dryRunBtn, &QPushButton::clicked, this, [this, bzrPlugin] {
QTC_ASSERT(bzrPlugin->currentState().hasTopLevel(), return);
bzrPlugin->client()->synchronousUncommit(bzrPlugin->currentState().topLevel(),
revision(),
extraOptions() << QLatin1String("--dry-run"));
});
} }
UnCommitDialog::~UnCommitDialog() UnCommitDialog::~UnCommitDialog()
@@ -66,14 +72,5 @@ QString UnCommitDialog::revision() const
return m_ui->revisionLineEdit->text().trimmed(); return m_ui->revisionLineEdit->text().trimmed();
} }
void UnCommitDialog::dryRun()
{
BazaarPluginPrivate *bzrPlugin = BazaarPluginPrivate::instance();
QTC_ASSERT(bzrPlugin->currentState().hasTopLevel(), return);
bzrPlugin->client()->synchronousUncommit(bzrPlugin->currentState().topLevel(),
revision(),
extraOptions() << QLatin1String("--dry-run"));
}
} // namespace Internal } // namespace Internal
} // namespace Bazaar } // namespace Bazaar

View File

@@ -32,20 +32,20 @@ namespace Internal {
namespace Ui { class UnCommitDialog; } namespace Ui { class UnCommitDialog; }
class BazaarPluginPrivate;
class UnCommitDialog : public QDialog class UnCommitDialog : public QDialog
{ {
Q_OBJECT Q_OBJECT
public: public:
explicit UnCommitDialog(QWidget *parent = nullptr); explicit UnCommitDialog(BazaarPluginPrivate *plugin, QWidget *parent = nullptr);
~UnCommitDialog() override; ~UnCommitDialog() override;
QStringList extraOptions() const; QStringList extraOptions() const;
QString revision() const; QString revision() const;
private: private:
void dryRun();
Ui::UnCommitDialog *m_ui; Ui::UnCommitDialog *m_ui;
}; };