diff --git a/src/plugins/git/CMakeLists.txt b/src/plugins/git/CMakeLists.txt index 5bcf4685291..3aaee139c2d 100644 --- a/src/plugins/git/CMakeLists.txt +++ b/src/plugins/git/CMakeLists.txt @@ -8,7 +8,7 @@ add_qtc_plugin(Git branchview.cpp branchview.h changeselectiondialog.cpp changeselectiondialog.h changeselectiondialog.ui commitdata.cpp commitdata.h - gerrit/authenticationdialog.cpp gerrit/authenticationdialog.h gerrit/authenticationdialog.ui + gerrit/authenticationdialog.cpp gerrit/authenticationdialog.h gerrit/branchcombobox.cpp gerrit/branchcombobox.h gerrit/gerritdialog.cpp gerrit/gerritdialog.h gerrit/gerritdialog.ui gerrit/gerritmodel.cpp gerrit/gerritmodel.h diff --git a/src/plugins/git/gerrit/authenticationdialog.cpp b/src/plugins/git/gerrit/authenticationdialog.cpp index a78b569feec..dfecd3e9e2b 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 #include +#include #include +#include #include #include #include +#include +#include #include #include #include #include +using namespace Utils; + namespace Gerrit { namespace Internal { @@ -65,48 +71,84 @@ 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( + "

Gerrit server with HTTP was detected, but you need " + "to set up credentials for it.

To get your password, " + "click here (sign in if needed). " + "Click Generate Password if the password is blank, and copy the user name " + "and password to this form.

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." + "

") + .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(); + + connect(m_buttonBox, &QDialogButtonBox::accepted, this, &QDialog::accept); + connect(m_buttonBox, &QDialogButtonBox::rejected, this, &QDialog::reject); } -AuthenticationDialog::~AuthenticationDialog() -{ - delete ui; -} +AuthenticationDialog::~AuthenticationDialog() = default; void AuthenticationDialog::readExistingConf() { @@ -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 diff --git a/src/plugins/git/gerrit/authenticationdialog.h b/src/plugins/git/gerrit/authenticationdialog.h index 7556c5bd0b4..32584d2258c 100644 --- a/src/plugins/git/gerrit/authenticationdialog.h +++ b/src/plugins/git/gerrit/authenticationdialog.h @@ -29,6 +29,8 @@ #include QT_BEGIN_NAMESPACE +class QDialogButtonBox; +class QLineEdit; class QTimer; QT_END_NAMESPACE @@ -37,8 +39,6 @@ namespace Internal { class GerritServer; -namespace Ui { class AuthenticationDialog; } - class AuthenticationDialog : public QDialog { Q_DECLARE_TR_FUNCTIONS(Gerrit::Internal::AuthenticationDialog) @@ -52,12 +52,15 @@ private: void readExistingConf(); bool setupCredentials(); void checkCredentials(); - Ui::AuthenticationDialog *ui = nullptr; + GerritServer *m_server = nullptr; QString m_netrcFileName; QStringList m_allMachines; bool m_authenticated = true; QTimer *m_checkTimer = nullptr; + QLineEdit *m_userLineEdit; + QLineEdit *m_passwordLineEdit; + QDialogButtonBox *m_buttonBox; }; } // Internal diff --git a/src/plugins/git/gerrit/authenticationdialog.ui b/src/plugins/git/gerrit/authenticationdialog.ui deleted file mode 100644 index 5fd21bd7580..00000000000 --- a/src/plugins/git/gerrit/authenticationdialog.ui +++ /dev/null @@ -1,127 +0,0 @@ - - - Gerrit::Internal::AuthenticationDialog - - - - 0 - 0 - 400 - 334 - - - - Authentication - - - - - - - 0 - 0 - - - - <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> - - - Qt::RichText - - - true - - - - - - - - - &User: - - - userLineEdit - - - - - - - - - - &Password: - - - passwordLineEdit - - - - - - - - - - Server: - - - - - - - false - - - - - - - - - Qt::Horizontal - - - QDialogButtonBox::Cancel|QDialogButtonBox::Ok - - - - - - - - - buttonBox - accepted() - Gerrit::Internal::AuthenticationDialog - accept() - - - 248 - 254 - - - 157 - 274 - - - - - buttonBox - rejected() - Gerrit::Internal::AuthenticationDialog - reject() - - - 316 - 260 - - - 286 - 274 - - - - - diff --git a/src/plugins/git/git.qbs b/src/plugins/git/git.qbs index ad22026f28e..971ee7ad2fb 100644 --- a/src/plugins/git/git.qbs +++ b/src/plugins/git/git.qbs @@ -74,7 +74,6 @@ QtcPlugin { files: [ "authenticationdialog.cpp", "authenticationdialog.h", - "authenticationdialog.ui", "branchcombobox.cpp", "branchcombobox.h", "gerritdialog.cpp",