forked from qt-creator/qt-creator
Copilot: Add support for proxy settings
For easier testing a docker file is added. You can start "buildandrun.sh" in copilot/tests/proxy to get a simple proxy server up and running. The argument "PWDMODE" in buildandrun.sh can be set to "with" and "without" to get a proxy server that needs a password or not. The username and password are user/1234. Fixes: QTCREATORBUG-29485 Change-Id: I3859c9ad04ebd4f9349e25665ba710e23fb64dea Reviewed-by: <github-actions-qt-creator@cristianadam.eu> Reviewed-by: hjk <hjk@qt.io>
This commit is contained in:
@@ -44,18 +44,21 @@ AuthWidget::AuthWidget(QWidget *parent)
|
||||
}.attachTo(this);
|
||||
// clang-format on
|
||||
|
||||
connect(m_button, &QPushButton::clicked, this, [this]() {
|
||||
if (m_status == Status::SignedIn)
|
||||
signOut();
|
||||
else if (m_status == Status::SignedOut)
|
||||
signIn();
|
||||
});
|
||||
|
||||
auto update = [this] {
|
||||
updateClient(FilePath::fromUserInput(settings().nodeJsPath.volatileValue()),
|
||||
FilePath::fromUserInput(settings().distPath.volatileValue()));
|
||||
};
|
||||
|
||||
connect(m_button, &QPushButton::clicked, this, [this, update]() {
|
||||
if (m_status == Status::SignedIn)
|
||||
signOut();
|
||||
else if (m_status == Status::SignedOut)
|
||||
signIn();
|
||||
else
|
||||
update();
|
||||
});
|
||||
|
||||
connect(&settings(), &CopilotSettings::applied, this, update);
|
||||
connect(settings().nodeJsPath.pathChooser(), &PathChooser::textChanged, this, update);
|
||||
connect(settings().distPath.pathChooser(), &PathChooser::textChanged, this, update);
|
||||
|
||||
@@ -68,35 +71,39 @@ AuthWidget::~AuthWidget()
|
||||
LanguageClientManager::shutdownClient(m_client);
|
||||
}
|
||||
|
||||
void AuthWidget::setState(const QString &buttonText, bool working)
|
||||
void AuthWidget::setState(const QString &buttonText, const QString &errorText, bool working)
|
||||
{
|
||||
m_button->setText(buttonText);
|
||||
m_button->setVisible(true);
|
||||
m_progressIndicator->setVisible(working);
|
||||
m_statusLabel->setText(errorText);
|
||||
m_statusLabel->setVisible(!m_statusLabel->text().isEmpty());
|
||||
m_button->setEnabled(!working);
|
||||
}
|
||||
|
||||
void AuthWidget::checkStatus()
|
||||
{
|
||||
if (!isEnabled())
|
||||
return;
|
||||
|
||||
QTC_ASSERT(m_client && m_client->reachable(), return);
|
||||
|
||||
setState("Checking status ...", true);
|
||||
setState("Checking status ...", {}, true);
|
||||
|
||||
m_client->requestCheckStatus(false, [this](const CheckStatusRequest::Response &response) {
|
||||
if (response.error()) {
|
||||
setState("failed: " + response.error()->message(), false);
|
||||
setState("Failed to authenticate", response.error()->message(), false);
|
||||
return;
|
||||
}
|
||||
const CheckStatusResponse result = *response.result();
|
||||
|
||||
if (result.user().isEmpty()) {
|
||||
setState("Sign in", false);
|
||||
setState("Sign in", {}, false);
|
||||
m_status = Status::SignedOut;
|
||||
return;
|
||||
}
|
||||
|
||||
setState("Sign out " + result.user(), false);
|
||||
setState("Sign out " + result.user(), {}, false);
|
||||
m_status = Status::SignedIn;
|
||||
});
|
||||
}
|
||||
@@ -105,12 +112,12 @@ void AuthWidget::updateClient(const FilePath &nodeJs, const FilePath &agent)
|
||||
{
|
||||
LanguageClientManager::shutdownClient(m_client);
|
||||
m_client = nullptr;
|
||||
setState(Tr::tr("Sign In"), false);
|
||||
setState(Tr::tr("Sign In"), {}, false);
|
||||
m_button->setEnabled(false);
|
||||
if (!nodeJs.isExecutableFile() || !agent.exists())
|
||||
return;
|
||||
|
||||
setState(Tr::tr("Sign In"), true);
|
||||
setState(Tr::tr("Sign In"), {}, true);
|
||||
|
||||
m_client = new CopilotClient(nodeJs, agent);
|
||||
connect(m_client, &Client::initialized, this, &AuthWidget::checkStatus);
|
||||
@@ -127,7 +134,7 @@ void AuthWidget::signIn()
|
||||
qCritical() << "Not implemented";
|
||||
QTC_ASSERT(m_client && m_client->reachable(), return);
|
||||
|
||||
setState("Signing in ...", true);
|
||||
setState("Signing in ...", {}, true);
|
||||
|
||||
m_client->requestSignInInitiate([this](const SignInInitiateRequest::Response &response) {
|
||||
QTC_ASSERT(!response.error(), return);
|
||||
@@ -144,19 +151,17 @@ void AuthWidget::signIn()
|
||||
m_client
|
||||
->requestSignInConfirm(response.result()->userCode(),
|
||||
[this](const SignInConfirmRequest::Response &response) {
|
||||
m_statusLabel->setText("");
|
||||
|
||||
if (response.error()) {
|
||||
QMessageBox::critical(this,
|
||||
Tr::tr("Login Failed"),
|
||||
Tr::tr(
|
||||
"The login request failed: ")
|
||||
+ response.error()->message());
|
||||
setState("Sign in", false);
|
||||
setState("Sign in", response.error()->message(), false);
|
||||
return;
|
||||
}
|
||||
|
||||
setState("Sign Out " + response.result()->user(), false);
|
||||
setState("Sign Out " + response.result()->user(), {}, false);
|
||||
});
|
||||
});
|
||||
}
|
||||
@@ -165,7 +170,7 @@ void AuthWidget::signOut()
|
||||
{
|
||||
QTC_ASSERT(m_client && m_client->reachable(), return);
|
||||
|
||||
setState("Signing out ...", true);
|
||||
setState("Signing out ...", {}, true);
|
||||
|
||||
m_client->requestSignOut([this](const SignOutRequest::Response &response) {
|
||||
QTC_ASSERT(!response.error(), return);
|
||||
|
||||
Reference in New Issue
Block a user