diff options
author | Andre Hartmann <aha_1980@gmx.de> | 2017-03-04 18:52:07 +0100 |
---|---|---|
committer | André Hartmann <aha_1980@gmx.de> | 2017-03-04 21:15:54 +0000 |
commit | 4ce5964422bd5420dede9624169875ee891091c3 (patch) | |
tree | a5d257544e11c1b7088a80afd1553a44e6a194f5 /src/plugins/git/gerrit/authenticationdialog.cpp | |
parent | 2f51a424616499bc4c8d260aed9237440da4a1b7 (diff) | |
download | qt-creator-4ce5964422bd5420dede9624169875ee891091c3.tar.gz |
Gerrit: Improve button enabling in AuthenticationDialog
* If the text was obviously pasted from the clipboard,
check instantly
* Otherwise, check two seconds after the last keystroke
Change-Id: I639e2f5dea596afdbb917cf0cffd0cf574d0032f
Reviewed-by: Orgad Shaneh <orgads@gmail.com>
Diffstat (limited to 'src/plugins/git/gerrit/authenticationdialog.cpp')
-rw-r--r-- | src/plugins/git/gerrit/authenticationdialog.cpp | 34 |
1 files changed, 28 insertions, 6 deletions
diff --git a/src/plugins/git/gerrit/authenticationdialog.cpp b/src/plugins/git/gerrit/authenticationdialog.cpp index 497d3bdcd0..53ad6b1fac 100644 --- a/src/plugins/git/gerrit/authenticationdialog.cpp +++ b/src/plugins/git/gerrit/authenticationdialog.cpp @@ -31,11 +31,14 @@ #include <utils/fileutils.h> #include <utils/hostosinfo.h> +#include <QClipboard> #include <QDir> #include <QFile> +#include <QGuiApplication> #include <QPushButton> #include <QRegularExpression> #include <QTextStream> +#include <QTimer> 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 |