diff options
author | hjk <hjk@qt.io> | 2022-08-02 17:59:16 +0200 |
---|---|---|
committer | hjk <hjk@qt.io> | 2022-08-03 09:44:08 +0000 |
commit | dac9dff4595505773bf86795cb7817f1954264da (patch) | |
tree | 2d384577c385c429217d5b150877fcc10c59369a /src/plugins/git/gerrit/authenticationdialog.cpp | |
parent | de08f08a2101e96857fa194f84ad7c24c5392667 (diff) | |
download | qt-creator-dac9dff4595505773bf86795cb7817f1954264da.tar.gz |
Gerrit: inline authenticationdialog.ui
Also, replace /#/settings/http-password by /#/settings/#HTTPCredentials
There should probably be some stretch between the form and
the buttonbox, but it wasn't there in the .ui so I left it
out for now.
Change-Id: Ie07a3283261a1070a489e454f9fb86c0c6dc2ca8
Reviewed-by: Orgad Shaneh <orgads@gmail.com>
Reviewed-by: <github-actions-qt-creator@cristianadam.eu>
Diffstat (limited to 'src/plugins/git/gerrit/authenticationdialog.cpp')
-rw-r--r-- | src/plugins/git/gerrit/authenticationdialog.cpp | 96 |
1 files changed, 69 insertions, 27 deletions
diff --git a/src/plugins/git/gerrit/authenticationdialog.cpp b/src/plugins/git/gerrit/authenticationdialog.cpp index a78b569fee..dfecd3e9e2 100644 --- a/src/plugins/git/gerrit/authenticationdialog.cpp +++ b/src/plugins/git/gerrit/authenticationdialog.cpp @@ -24,21 +24,27 @@ ****************************************************************************/ #include "authenticationdialog.h" -#include "ui_authenticationdialog.h" + #include "gerritserver.h" #include <utils/fileutils.h> #include <utils/hostosinfo.h> +#include <utils/layoutbuilder.h> #include <QClipboard> +#include <QDialogButtonBox> #include <QDir> #include <QFile> #include <QGuiApplication> +#include <QLabel> +#include <QLineEdit> #include <QPushButton> #include <QRegularExpression> #include <QTextStream> #include <QTimer> +using namespace Utils; + namespace Gerrit { namespace Internal { @@ -65,49 +71,85 @@ static bool replaceEntry(QString &line, const QString &type, const QString &valu return true; } -AuthenticationDialog::AuthenticationDialog(GerritServer *server) : - ui(new Ui::AuthenticationDialog), - m_server(server) +AuthenticationDialog::AuthenticationDialog(GerritServer *server) + : m_server(server) { - ui->setupUi(this); - ui->descriptionLabel->setText(ui->descriptionLabel->text().replace( - "LINK_PLACEHOLDER", server->url() + "/#/settings/http-password")); - ui->descriptionLabel->setOpenExternalLinks(true); - ui->serverLineEdit->setText(server->host); - ui->userLineEdit->setText(server->user.userName); + setWindowTitle(tr("Authentication")); + resize(400, 334); + + // FIXME: Take html out of this translatable string. + const QString desc = tr( + "<html><head/><body><p>Gerrit server with HTTP was detected, but you need " + "to set up credentials for it.</p><p>To get your password, " + "<a href=\"LINK_PLACEHOLDER\"><span style=\" text-decoration: " + "underline; color:#007af4;\">click here</span></a> (sign in if needed). " + "Click Generate Password if the password is blank, and copy the user name " + "and password to this form.</p><p>Choose Anonymous if you do not want " + "authentication for this server. In this case, changes that require " + "authentication (like draft changes or private projects) will not be displayed." + "</p></body></html>") + .replace("LINK_PLACEHOLDER", server->url() + "/#/settings/#HTTPCredentials"); + + auto descriptionLabel = new QLabel(desc); + descriptionLabel->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::MinimumExpanding); + descriptionLabel->setTextFormat(Qt::RichText); + descriptionLabel->setWordWrap(true); + descriptionLabel->setOpenExternalLinks(true); + + m_userLineEdit = new QLineEdit(server->user.userName); + + m_passwordLineEdit = new QLineEdit; + + auto serverLineEdit = new QLineEdit(server->host); + serverLineEdit->setEnabled(false); + + m_buttonBox = new QDialogButtonBox(QDialogButtonBox::Cancel|QDialogButtonBox::Ok); + m_netrcFileName = QDir::homePath() + '/' + QLatin1String(Utils::HostOsInfo::isWindowsHost() ? "_netrc" : ".netrc"); + + using namespace Layouting; + Column { + descriptionLabel, + Form { + tr("Server:"), serverLineEdit, br, + tr("&User:"), m_userLineEdit, br, + tr("&Password:"), m_passwordLineEdit, br, + }, + m_buttonBox, + }.attachTo(this); + readExistingConf(); - QPushButton *anonymous = ui->buttonBox->addButton(tr("Anonymous"), QDialogButtonBox::AcceptRole); - connect(ui->buttonBox, &QDialogButtonBox::clicked, + QPushButton *anonymous = m_buttonBox->addButton(tr("Anonymous"), QDialogButtonBox::AcceptRole); + connect(m_buttonBox, &QDialogButtonBox::clicked, this, [this, anonymous](QAbstractButton *button) { if (button == anonymous) m_authenticated = false; }); - ui->buttonBox->button(QDialogButtonBox::Ok)->setEnabled(false); - connect(ui->passwordLineEdit, &QLineEdit::editingFinished, + m_buttonBox->button(QDialogButtonBox::Ok)->setEnabled(false); + connect(m_passwordLineEdit, &QLineEdit::editingFinished, this, &AuthenticationDialog::checkCredentials); m_checkTimer = new QTimer(this); m_checkTimer->setSingleShot(true); connect(m_checkTimer, &QTimer::timeout, this, &AuthenticationDialog::checkCredentials); - connect(ui->passwordLineEdit, &QLineEdit::textChanged, [this]() { - if (QGuiApplication::clipboard()->text() == ui->passwordLineEdit->text()) { + connect(m_passwordLineEdit, &QLineEdit::textChanged, [this]() { + if (QGuiApplication::clipboard()->text() == m_passwordLineEdit->text()) { checkCredentials(); return; } m_checkTimer->start(2000); }); - if (!ui->userLineEdit->text().isEmpty()) - ui->passwordLineEdit->setFocus(); -} + if (!m_userLineEdit->text().isEmpty()) + m_passwordLineEdit->setFocus(); -AuthenticationDialog::~AuthenticationDialog() -{ - delete ui; + connect(m_buttonBox, &QDialogButtonBox::accepted, this, &QDialog::accept); + connect(m_buttonBox, &QDialogButtonBox::rejected, this, &QDialog::reject); } +AuthenticationDialog::~AuthenticationDialog() = default; + void AuthenticationDialog::readExistingConf() { QFile netrcFile(m_netrcFileName); @@ -123,9 +165,9 @@ void AuthenticationDialog::readExistingConf() const QString login = findEntry(line, "login"); const QString password = findEntry(line, "password"); if (!login.isEmpty()) - ui->userLineEdit->setText(login); + m_userLineEdit->setText(login); if (!password.isEmpty()) - ui->passwordLineEdit->setText(password); + m_passwordLineEdit->setText(password); } } netrcFile.close(); @@ -136,8 +178,8 @@ bool AuthenticationDialog::setupCredentials() QString netrcContents; QTextStream out(&netrcContents); bool found = false; - const QString user = ui->userLineEdit->text().trimmed(); - const QString password = ui->passwordLineEdit->text().trimmed(); + const QString user = m_userLineEdit->text().trimmed(); + const QString password = m_passwordLineEdit->text().trimmed(); if (user.isEmpty() || password.isEmpty()) return false; @@ -165,7 +207,7 @@ void AuthenticationDialog::checkCredentials() int result = 400; if (setupCredentials()) result = m_server->testConnection(); - ui->buttonBox->button(QDialogButtonBox::Ok)->setEnabled(result == 200); + m_buttonBox->button(QDialogButtonBox::Ok)->setEnabled(result == 200); } } // Internal |