diff --git a/src/plugins/git/gerrit/authenticationdialog.cpp b/src/plugins/git/gerrit/authenticationdialog.cpp index 497d3bdcd0d..53ad6b1fac3 100644 --- a/src/plugins/git/gerrit/authenticationdialog.cpp +++ b/src/plugins/git/gerrit/authenticationdialog.cpp @@ -31,11 +31,14 @@ #include #include +#include #include #include +#include #include #include #include +#include namespace Gerrit { namespace Internal { @@ -83,12 +86,19 @@ AuthenticationDialog::AuthenticationDialog(GerritServer *server) : if (button == anonymous) m_authenticated = false; }); - QPushButton *okButton = ui->buttonBox->button(QDialogButtonBox::Ok); - okButton->setEnabled(false); - connect(ui->passwordLineEdit, &QLineEdit::editingFinished, this, [this, server, okButton] { - setupCredentials(); - const int result = server->testConnection(); - okButton->setEnabled(result == 200); + ui->buttonBox->button(QDialogButtonBox::Ok)->setEnabled(false); + connect(ui->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()) { + checkCredentials(); + return; + } + + m_checkTimer->start(2000); }); if (!ui->userLineEdit->text().isEmpty()) ui->passwordLineEdit->setFocus(); @@ -129,6 +139,10 @@ bool AuthenticationDialog::setupCredentials() bool found = false; const QString user = ui->userLineEdit->text().trimmed(); const QString password = ui->passwordLineEdit->text().trimmed(); + + if (user.isEmpty() || password.isEmpty()) + return false; + for (QString &line : m_allMachines) { const QString machine = findEntry(line, "machine"); if (machine == m_server->host) { @@ -145,5 +159,13 @@ bool AuthenticationDialog::setupCredentials() return saver.finalize(); } +void AuthenticationDialog::checkCredentials() +{ + int result = 400; + if (setupCredentials()) + result = m_server->testConnection(); + ui->buttonBox->button(QDialogButtonBox::Ok)->setEnabled(result == 200); +} + } // Internal } // Gerrit diff --git a/src/plugins/git/gerrit/authenticationdialog.h b/src/plugins/git/gerrit/authenticationdialog.h index 98d06a4fe87..9b5c8324cb0 100644 --- a/src/plugins/git/gerrit/authenticationdialog.h +++ b/src/plugins/git/gerrit/authenticationdialog.h @@ -29,6 +29,10 @@ #include #include +QT_BEGIN_NAMESPACE +class QTimer; +QT_END_NAMESPACE + namespace Gerrit { namespace Internal { @@ -48,11 +52,13 @@ public: 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; }; } // Internal