forked from qt-creator/qt-creator
GitLab: Access GitlabParameter singleton more directly
Change-Id: Ib4d333b6419bb2bdcdcf124d22d0473f6fd91cb9 Reviewed-by: Christian Stenger <christian.stenger@qt.io>
This commit is contained in:
@@ -159,12 +159,11 @@ void GitLabDialog::resetTreeView(QTreeView *treeView, QAbstractItemModel *model)
|
|||||||
void GitLabDialog::updateRemotes()
|
void GitLabDialog::updateRemotes()
|
||||||
{
|
{
|
||||||
m_remoteComboBox->clear();
|
m_remoteComboBox->clear();
|
||||||
const GitLabParameters *global = GitLabPlugin::globalParameters();
|
for (const GitLabServer &server : std::as_const(gitLabParameters().gitLabServers))
|
||||||
for (const GitLabServer &server : std::as_const(global->gitLabServers))
|
|
||||||
m_remoteComboBox->addItem(server.displayString(), QVariant::fromValue(server));
|
m_remoteComboBox->addItem(server.displayString(), QVariant::fromValue(server));
|
||||||
|
|
||||||
m_remoteComboBox->setCurrentIndex(m_remoteComboBox->findData(
|
m_remoteComboBox->setCurrentIndex(m_remoteComboBox->findData(
|
||||||
QVariant::fromValue(global->currentDefaultServer())));
|
QVariant::fromValue(gitLabParameters().currentDefaultServer())));
|
||||||
}
|
}
|
||||||
|
|
||||||
void GitLabDialog::keyPressEvent(QKeyEvent *event)
|
void GitLabDialog::keyPressEvent(QKeyEvent *event)
|
||||||
@@ -198,8 +197,7 @@ void GitLabDialog::requestMainViewUpdate()
|
|||||||
if (!m_currentServerId.isValid())
|
if (!m_currentServerId.isValid())
|
||||||
m_currentServerId = m_remoteComboBox->currentData().value<GitLabServer>().id;
|
m_currentServerId = m_remoteComboBox->currentData().value<GitLabServer>().id;
|
||||||
if (m_currentServerId.isValid()) {
|
if (m_currentServerId.isValid()) {
|
||||||
const GitLabParameters *global = GitLabPlugin::globalParameters();
|
const GitLabServer server = gitLabParameters().serverForId(m_currentServerId);
|
||||||
const GitLabServer server = global->serverForId(m_currentServerId);
|
|
||||||
m_remoteComboBox->setCurrentIndex(m_remoteComboBox->findData(QVariant::fromValue(server)));
|
m_remoteComboBox->setCurrentIndex(m_remoteComboBox->findData(QVariant::fromValue(server)));
|
||||||
}
|
}
|
||||||
m_remoteComboBox->setEnabled(!linked);
|
m_remoteComboBox->setEnabled(!linked);
|
||||||
|
|||||||
@@ -132,7 +132,7 @@ void GitLabServerWidget::setGitLabServer(const GitLabServer &server)
|
|||||||
class GitLabOptionsWidget : public Core::IOptionsPageWidget
|
class GitLabOptionsWidget : public Core::IOptionsPageWidget
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
explicit GitLabOptionsWidget(GitLabParameters *parameters);
|
GitLabOptionsWidget();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void showEditServerDialog();
|
void showEditServerDialog();
|
||||||
@@ -151,8 +151,8 @@ private:
|
|||||||
FilePathAspect m_curl;
|
FilePathAspect m_curl;
|
||||||
};
|
};
|
||||||
|
|
||||||
GitLabOptionsWidget::GitLabOptionsWidget(GitLabParameters *params)
|
GitLabOptionsWidget::GitLabOptionsWidget()
|
||||||
: m_parameters(params)
|
: m_parameters(&gitLabParameters())
|
||||||
{
|
{
|
||||||
auto defaultLabel = new QLabel(Tr::tr("Default:"), this);
|
auto defaultLabel = new QLabel(Tr::tr("Default:"), this);
|
||||||
m_defaultGitLabServer = new QComboBox(this);
|
m_defaultGitLabServer = new QComboBox(this);
|
||||||
@@ -178,14 +178,14 @@ GitLabOptionsWidget::GitLabOptionsWidget(GitLabParameters *params)
|
|||||||
}, Column { m_add, m_edit, m_remove, st },
|
}, Column { m_add, m_edit, m_remove, st },
|
||||||
}.attachTo(this);
|
}.attachTo(this);
|
||||||
|
|
||||||
m_curl.setValue(params->curl);
|
m_curl.setValue(m_parameters->curl);
|
||||||
|
|
||||||
for (const auto &gitLabServer : params->gitLabServers) {
|
for (const auto &gitLabServer : m_parameters->gitLabServers) {
|
||||||
m_defaultGitLabServer->addItem(gitLabServer.displayString(),
|
m_defaultGitLabServer->addItem(gitLabServer.displayString(),
|
||||||
QVariant::fromValue(gitLabServer));
|
QVariant::fromValue(gitLabServer));
|
||||||
}
|
}
|
||||||
|
|
||||||
const GitLabServer found = params->currentDefaultServer();
|
const GitLabServer found = m_parameters->currentDefaultServer();
|
||||||
if (found.id.isValid()) {
|
if (found.id.isValid()) {
|
||||||
m_defaultGitLabServer->setCurrentIndex(m_defaultGitLabServer->findData(
|
m_defaultGitLabServer->setCurrentIndex(m_defaultGitLabServer->findData(
|
||||||
QVariant::fromValue(found)));
|
QVariant::fromValue(found)));
|
||||||
@@ -298,12 +298,12 @@ void GitLabOptionsWidget::updateButtonsState()
|
|||||||
|
|
||||||
// GitLabOptionsPage
|
// GitLabOptionsPage
|
||||||
|
|
||||||
GitLabOptionsPage::GitLabOptionsPage(GitLabParameters *p)
|
GitLabOptionsPage::GitLabOptionsPage()
|
||||||
{
|
{
|
||||||
setId(Constants::GITLAB_SETTINGS);
|
setId(Constants::GITLAB_SETTINGS);
|
||||||
setDisplayName(Tr::tr("GitLab"));
|
setDisplayName(Tr::tr("GitLab"));
|
||||||
setCategory(VcsBase::Constants::VCS_SETTINGS_CATEGORY);
|
setCategory(VcsBase::Constants::VCS_SETTINGS_CATEGORY);
|
||||||
setWidgetCreator([p] { return new GitLabOptionsWidget(p); });
|
setWidgetCreator([] { return new GitLabOptionsWidget; });
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace GitLab
|
} // namespace GitLab
|
||||||
|
|||||||
@@ -3,8 +3,6 @@
|
|||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include "gitlabparameters.h"
|
|
||||||
|
|
||||||
#include <coreplugin/dialogs/ioptionspage.h>
|
#include <coreplugin/dialogs/ioptionspage.h>
|
||||||
|
|
||||||
namespace GitLab {
|
namespace GitLab {
|
||||||
@@ -14,7 +12,7 @@ namespace Constants { const char GITLAB_SETTINGS[] = "GitLab"; }
|
|||||||
class GitLabOptionsPage : public Core::IOptionsPage
|
class GitLabOptionsPage : public Core::IOptionsPage
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
explicit GitLabOptionsPage(GitLabParameters *p);
|
GitLabOptionsPage();
|
||||||
};
|
};
|
||||||
|
|
||||||
} // GitLab
|
} // GitLab
|
||||||
|
|||||||
@@ -3,6 +3,8 @@
|
|||||||
|
|
||||||
#include "gitlabparameters.h"
|
#include "gitlabparameters.h"
|
||||||
|
|
||||||
|
#include <coreplugin/icore.h>
|
||||||
|
|
||||||
#include <utils/algorithm.h>
|
#include <utils/algorithm.h>
|
||||||
#include <utils/hostosinfo.h>
|
#include <utils/hostosinfo.h>
|
||||||
#include <utils/qtcsettings.h>
|
#include <utils/qtcsettings.h>
|
||||||
@@ -202,4 +204,10 @@ GitLabServer GitLabParameters::serverForId(const Utils::Id &id) const
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
GitLabParameters &gitLabParameters()
|
||||||
|
{
|
||||||
|
static GitLabParameters theGitLabParameters;
|
||||||
|
return theGitLabParameters;
|
||||||
|
}
|
||||||
|
|
||||||
} // namespace GitLab
|
} // namespace GitLab
|
||||||
|
|||||||
@@ -74,6 +74,8 @@ public:
|
|||||||
Utils::FilePath curl;
|
Utils::FilePath curl;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
GitLabParameters &gitLabParameters();
|
||||||
|
|
||||||
} // namespace GitLab
|
} // namespace GitLab
|
||||||
|
|
||||||
Q_DECLARE_METATYPE(GitLab::GitLabServer)
|
Q_DECLARE_METATYPE(GitLab::GitLabServer)
|
||||||
|
|||||||
@@ -45,13 +45,7 @@ public:
|
|||||||
void handleUser(const User &user);
|
void handleUser(const User &user);
|
||||||
void handleEvents(const Events &events, const QDateTime &timeStamp);
|
void handleEvents(const Events &events, const QDateTime &timeStamp);
|
||||||
|
|
||||||
void onSettingsChanged() {
|
GitLabOptionsPage optionsPage;
|
||||||
if (dialog)
|
|
||||||
dialog->updateRemotes();
|
|
||||||
}
|
|
||||||
|
|
||||||
GitLabParameters parameters;
|
|
||||||
GitLabOptionsPage optionsPage{¶meters};
|
|
||||||
QHash<ProjectExplorer::Project *, GitLabProjectSettings *> projectSettings;
|
QHash<ProjectExplorer::Project *, GitLabProjectSettings *> projectSettings;
|
||||||
QPointer<GitLabDialog> dialog;
|
QPointer<GitLabDialog> dialog;
|
||||||
|
|
||||||
@@ -80,7 +74,7 @@ GitLabPlugin::~GitLabPlugin()
|
|||||||
void GitLabPlugin::initialize()
|
void GitLabPlugin::initialize()
|
||||||
{
|
{
|
||||||
dd = new GitLabPluginPrivate;
|
dd = new GitLabPluginPrivate;
|
||||||
dd->parameters.fromSettings(Core::ICore::settings());
|
gitLabParameters().fromSettings(Core::ICore::settings());
|
||||||
|
|
||||||
setupGitlabProjectPanel();
|
setupGitlabProjectPanel();
|
||||||
|
|
||||||
@@ -98,7 +92,7 @@ void GitLabPlugin::initialize()
|
|||||||
void GitLabPlugin::openView()
|
void GitLabPlugin::openView()
|
||||||
{
|
{
|
||||||
if (dd->dialog.isNull()) {
|
if (dd->dialog.isNull()) {
|
||||||
while (!dd->parameters.isValid()) {
|
while (!gitLabParameters().isValid()) {
|
||||||
QMessageBox::warning(Core::ICore::dialogParent(), Tr::tr("Error"),
|
QMessageBox::warning(Core::ICore::dialogParent(), Tr::tr("Error"),
|
||||||
Tr::tr("Invalid GitLab configuration. For a fully functional "
|
Tr::tr("Invalid GitLab configuration. For a fully functional "
|
||||||
"configuration, you need to set up host name or address and "
|
"configuration, you need to set up host name or address and "
|
||||||
@@ -253,23 +247,6 @@ void GitLabPluginPrivate::handleEvents(const Events &events, const QDateTime &ti
|
|||||||
createAndSendEventsRequest(timeStamp, events.pageInfo.currentPage + 1);
|
createAndSendEventsRequest(timeStamp, events.pageInfo.currentPage + 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
QList<GitLabServer> GitLabPlugin::allGitLabServers()
|
|
||||||
{
|
|
||||||
QTC_ASSERT(dd, return {});
|
|
||||||
return dd->parameters.gitLabServers;
|
|
||||||
}
|
|
||||||
|
|
||||||
GitLabServer GitLabPlugin::gitLabServerForId(const Utils::Id &id)
|
|
||||||
{
|
|
||||||
QTC_ASSERT(dd, return {});
|
|
||||||
return dd->parameters.serverForId(id);
|
|
||||||
}
|
|
||||||
|
|
||||||
GitLabParameters *GitLabPlugin::globalParameters()
|
|
||||||
{
|
|
||||||
return &dd->parameters;
|
|
||||||
}
|
|
||||||
|
|
||||||
GitLabProjectSettings *GitLabPlugin::projectSettings(ProjectExplorer::Project *project)
|
GitLabProjectSettings *GitLabPlugin::projectSettings(ProjectExplorer::Project *project)
|
||||||
{
|
{
|
||||||
QTC_ASSERT(project, return nullptr);
|
QTC_ASSERT(project, return nullptr);
|
||||||
@@ -280,17 +257,12 @@ GitLabProjectSettings *GitLabPlugin::projectSettings(ProjectExplorer::Project *p
|
|||||||
return settings;
|
return settings;
|
||||||
}
|
}
|
||||||
|
|
||||||
GitLabOptionsPage *GitLabPlugin::optionsPage()
|
|
||||||
{
|
|
||||||
QTC_ASSERT(dd, return {});
|
|
||||||
return &dd->optionsPage;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool GitLabPlugin::handleCertificateIssue(const Utils::Id &serverId)
|
bool GitLabPlugin::handleCertificateIssue(const Utils::Id &serverId)
|
||||||
{
|
{
|
||||||
QTC_ASSERT(dd, return false);
|
QTC_ASSERT(dd, return false);
|
||||||
|
|
||||||
GitLabServer server = dd->parameters.serverForId(serverId);
|
GitLabParameters ¶ms = gitLabParameters();
|
||||||
|
GitLabServer server = params.serverForId(serverId);
|
||||||
if (QMessageBox::question(Core::ICore::dialogParent(),
|
if (QMessageBox::question(Core::ICore::dialogParent(),
|
||||||
Tr::tr("Certificate Error"),
|
Tr::tr("Certificate Error"),
|
||||||
Tr::tr(
|
Tr::tr(
|
||||||
@@ -299,10 +271,12 @@ bool GitLabPlugin::handleCertificateIssue(const Utils::Id &serverId)
|
|||||||
"Note: This can expose you to man-in-the-middle attack.")
|
"Note: This can expose you to man-in-the-middle attack.")
|
||||||
.arg(server.host))
|
.arg(server.host))
|
||||||
== QMessageBox::Yes) {
|
== QMessageBox::Yes) {
|
||||||
int index = dd->parameters.gitLabServers.indexOf(server);
|
int index = params.gitLabServers.indexOf(server);
|
||||||
server.validateCert = false;
|
server.validateCert = false;
|
||||||
dd->parameters.gitLabServers.replace(index, server);
|
params.gitLabServers.replace(index, server);
|
||||||
dd->onSettingsChanged();
|
if (dd->dialog)
|
||||||
|
dd->dialog->updateRemotes();
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
|
|||||||
@@ -13,7 +13,6 @@ namespace GitLab {
|
|||||||
|
|
||||||
class Events;
|
class Events;
|
||||||
class GitLabProjectSettings;
|
class GitLabProjectSettings;
|
||||||
class GitLabOptionsPage;
|
|
||||||
|
|
||||||
class GitLabPlugin : public ExtensionSystem::IPlugin
|
class GitLabPlugin : public ExtensionSystem::IPlugin
|
||||||
{
|
{
|
||||||
@@ -26,11 +25,7 @@ public:
|
|||||||
|
|
||||||
void initialize() override;
|
void initialize() override;
|
||||||
|
|
||||||
static QList<GitLabServer> allGitLabServers();
|
|
||||||
static GitLabServer gitLabServerForId(const Utils::Id &id);
|
|
||||||
static GitLabParameters *globalParameters();
|
|
||||||
static GitLabProjectSettings *projectSettings(ProjectExplorer::Project *project);
|
static GitLabProjectSettings *projectSettings(ProjectExplorer::Project *project);
|
||||||
static GitLabOptionsPage *optionsPage();
|
|
||||||
static bool handleCertificateIssue(const Utils::Id &serverId);
|
static bool handleCertificateIssue(const Utils::Id &serverId);
|
||||||
|
|
||||||
static void linkedStateChanged(bool enabled);
|
static void linkedStateChanged(bool enabled);
|
||||||
|
|||||||
@@ -95,7 +95,7 @@ void GitLabProjectSettings::load()
|
|||||||
if (!m_id.isValid() || m_host.isEmpty())
|
if (!m_id.isValid() || m_host.isEmpty())
|
||||||
m_linked = false;
|
m_linked = false;
|
||||||
else
|
else
|
||||||
m_linked = GitLabPlugin::globalParameters()->serverForId(m_id).id.isValid();
|
m_linked = gitLabParameters().serverForId(m_id).id.isValid();
|
||||||
}
|
}
|
||||||
|
|
||||||
void GitLabProjectSettings::save()
|
void GitLabProjectSettings::save()
|
||||||
@@ -184,7 +184,7 @@ GitLabProjectSettingsWidget::GitLabProjectSettingsWidget(ProjectExplorer::Projec
|
|||||||
connect(m_hostCB, &QComboBox::currentIndexChanged, this, [this] {
|
connect(m_hostCB, &QComboBox::currentIndexChanged, this, [this] {
|
||||||
m_infoLabel->setVisible(false);
|
m_infoLabel->setVisible(false);
|
||||||
});
|
});
|
||||||
connect(GitLabPlugin::globalParameters(), &GitLabParameters::changed,
|
connect(&gitLabParameters(), &GitLabParameters::changed,
|
||||||
this, &GitLabProjectSettingsWidget::updateUi);
|
this, &GitLabProjectSettingsWidget::updateUi);
|
||||||
updateUi();
|
updateUi();
|
||||||
}
|
}
|
||||||
@@ -266,7 +266,7 @@ void GitLabProjectSettingsWidget::onConnectionChecked(const Project &project,
|
|||||||
void GitLabProjectSettingsWidget::updateUi()
|
void GitLabProjectSettingsWidget::updateUi()
|
||||||
{
|
{
|
||||||
m_linkedGitLabServer->clear();
|
m_linkedGitLabServer->clear();
|
||||||
const QList<GitLabServer> allServers = GitLabPlugin::allGitLabServers();
|
const QList<GitLabServer> allServers = gitLabParameters().gitLabServers;
|
||||||
for (const GitLabServer &server : allServers) {
|
for (const GitLabServer &server : allServers) {
|
||||||
const QString display = server.host + " (" + server.description + ')';
|
const QString display = server.host + " (" + server.description + ')';
|
||||||
m_linkedGitLabServer->addItem(display, QVariant::fromValue(server));
|
m_linkedGitLabServer->addItem(display, QVariant::fromValue(server));
|
||||||
@@ -289,13 +289,13 @@ void GitLabProjectSettingsWidget::updateUi()
|
|||||||
const Utils::Id id = m_projectSettings->currentServer();
|
const Utils::Id id = m_projectSettings->currentServer();
|
||||||
const QString serverHost = m_projectSettings->currentServerHost();
|
const QString serverHost = m_projectSettings->currentServerHost();
|
||||||
if (id.isValid()) {
|
if (id.isValid()) {
|
||||||
const GitLabServer server = GitLabPlugin::gitLabServerForId(id);
|
const GitLabServer server = gitLabParameters().serverForId(id);
|
||||||
auto [remoteHost, projName, port] = GitLabProjectSettings::remotePartsFromRemote(serverHost);
|
auto [remoteHost, projName, port] = GitLabProjectSettings::remotePartsFromRemote(serverHost);
|
||||||
if (server.id.isValid() && server.host == remoteHost) { // found config
|
if (server.id.isValid() && server.host == remoteHost) { // found config
|
||||||
m_projectSettings->setLinked(true);
|
m_projectSettings->setLinked(true);
|
||||||
m_hostCB->setCurrentIndex(m_hostCB->findData(QVariant::fromValue(serverHost)));
|
m_hostCB->setCurrentIndex(m_hostCB->findData(QVariant::fromValue(serverHost)));
|
||||||
m_linkedGitLabServer->setCurrentIndex(
|
m_linkedGitLabServer->setCurrentIndex(
|
||||||
m_linkedGitLabServer->findData(QVariant::fromValue(server)));
|
m_linkedGitLabServer->findData(QVariant::fromValue(server)));
|
||||||
GitLabPlugin::linkedStateChanged(true);
|
GitLabPlugin::linkedStateChanged(true);
|
||||||
} else {
|
} else {
|
||||||
m_projectSettings->setLinked(false);
|
m_projectSettings->setLinked(false);
|
||||||
|
|||||||
@@ -83,8 +83,7 @@ QString Query::toString() const
|
|||||||
QueryRunner::QueryRunner(const Query &query, const Id &id, QObject *parent)
|
QueryRunner::QueryRunner(const Query &query, const Id &id, QObject *parent)
|
||||||
: QObject(parent)
|
: QObject(parent)
|
||||||
{
|
{
|
||||||
const GitLabParameters *p = GitLabPlugin::globalParameters();
|
const auto server = gitLabParameters().serverForId(id);
|
||||||
const auto server = p->serverForId(id);
|
|
||||||
QStringList args = server.curlArguments();
|
QStringList args = server.curlArguments();
|
||||||
if (query.hasPaginatedResults())
|
if (query.hasPaginatedResults())
|
||||||
args << "-i";
|
args << "-i";
|
||||||
@@ -95,7 +94,7 @@ QueryRunner::QueryRunner(const Query &query, const Id &id, QObject *parent)
|
|||||||
url.append(':' + QString::number(server.port));
|
url.append(':' + QString::number(server.port));
|
||||||
url += query.toString();
|
url += query.toString();
|
||||||
args << url;
|
args << url;
|
||||||
m_process.setCommand({p->curl, args});
|
m_process.setCommand({gitLabParameters().curl, args});
|
||||||
connect(&m_process, &Process::done, this, [this, id] {
|
connect(&m_process, &Process::done, this, [this, id] {
|
||||||
if (m_process.result() != ProcessResult::FinishedWithSuccess) {
|
if (m_process.result() != ProcessResult::FinishedWithSuccess) {
|
||||||
const int exitCode = m_process.exitCode();
|
const int exitCode = m_process.exitCode();
|
||||||
|
|||||||
Reference in New Issue
Block a user