forked from qt-creator/qt-creator
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>
This commit is contained in:
committed by
André Hartmann
parent
2f51a42461
commit
4ce5964422
@@ -31,11 +31,14 @@
|
|||||||
#include <utils/fileutils.h>
|
#include <utils/fileutils.h>
|
||||||
#include <utils/hostosinfo.h>
|
#include <utils/hostosinfo.h>
|
||||||
|
|
||||||
|
#include <QClipboard>
|
||||||
#include <QDir>
|
#include <QDir>
|
||||||
#include <QFile>
|
#include <QFile>
|
||||||
|
#include <QGuiApplication>
|
||||||
#include <QPushButton>
|
#include <QPushButton>
|
||||||
#include <QRegularExpression>
|
#include <QRegularExpression>
|
||||||
#include <QTextStream>
|
#include <QTextStream>
|
||||||
|
#include <QTimer>
|
||||||
|
|
||||||
namespace Gerrit {
|
namespace Gerrit {
|
||||||
namespace Internal {
|
namespace Internal {
|
||||||
@@ -83,12 +86,19 @@ AuthenticationDialog::AuthenticationDialog(GerritServer *server) :
|
|||||||
if (button == anonymous)
|
if (button == anonymous)
|
||||||
m_authenticated = false;
|
m_authenticated = false;
|
||||||
});
|
});
|
||||||
QPushButton *okButton = ui->buttonBox->button(QDialogButtonBox::Ok);
|
ui->buttonBox->button(QDialogButtonBox::Ok)->setEnabled(false);
|
||||||
okButton->setEnabled(false);
|
connect(ui->passwordLineEdit, &QLineEdit::editingFinished,
|
||||||
connect(ui->passwordLineEdit, &QLineEdit::editingFinished, this, [this, server, okButton] {
|
this, &AuthenticationDialog::checkCredentials);
|
||||||
setupCredentials();
|
m_checkTimer = new QTimer(this);
|
||||||
const int result = server->testConnection();
|
m_checkTimer->setSingleShot(true);
|
||||||
okButton->setEnabled(result == 200);
|
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())
|
if (!ui->userLineEdit->text().isEmpty())
|
||||||
ui->passwordLineEdit->setFocus();
|
ui->passwordLineEdit->setFocus();
|
||||||
@@ -129,6 +139,10 @@ bool AuthenticationDialog::setupCredentials()
|
|||||||
bool found = false;
|
bool found = false;
|
||||||
const QString user = ui->userLineEdit->text().trimmed();
|
const QString user = ui->userLineEdit->text().trimmed();
|
||||||
const QString password = ui->passwordLineEdit->text().trimmed();
|
const QString password = ui->passwordLineEdit->text().trimmed();
|
||||||
|
|
||||||
|
if (user.isEmpty() || password.isEmpty())
|
||||||
|
return false;
|
||||||
|
|
||||||
for (QString &line : m_allMachines) {
|
for (QString &line : m_allMachines) {
|
||||||
const QString machine = findEntry(line, "machine");
|
const QString machine = findEntry(line, "machine");
|
||||||
if (machine == m_server->host) {
|
if (machine == m_server->host) {
|
||||||
@@ -145,5 +159,13 @@ bool AuthenticationDialog::setupCredentials()
|
|||||||
return saver.finalize();
|
return saver.finalize();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void AuthenticationDialog::checkCredentials()
|
||||||
|
{
|
||||||
|
int result = 400;
|
||||||
|
if (setupCredentials())
|
||||||
|
result = m_server->testConnection();
|
||||||
|
ui->buttonBox->button(QDialogButtonBox::Ok)->setEnabled(result == 200);
|
||||||
|
}
|
||||||
|
|
||||||
} // Internal
|
} // Internal
|
||||||
} // Gerrit
|
} // Gerrit
|
||||||
|
|||||||
@@ -29,6 +29,10 @@
|
|||||||
#include <QCoreApplication>
|
#include <QCoreApplication>
|
||||||
#include <QDialog>
|
#include <QDialog>
|
||||||
|
|
||||||
|
QT_BEGIN_NAMESPACE
|
||||||
|
class QTimer;
|
||||||
|
QT_END_NAMESPACE
|
||||||
|
|
||||||
namespace Gerrit {
|
namespace Gerrit {
|
||||||
namespace Internal {
|
namespace Internal {
|
||||||
|
|
||||||
@@ -48,11 +52,13 @@ public:
|
|||||||
private:
|
private:
|
||||||
void readExistingConf();
|
void readExistingConf();
|
||||||
bool setupCredentials();
|
bool setupCredentials();
|
||||||
|
void checkCredentials();
|
||||||
Ui::AuthenticationDialog *ui = nullptr;
|
Ui::AuthenticationDialog *ui = nullptr;
|
||||||
GerritServer *m_server = nullptr;
|
GerritServer *m_server = nullptr;
|
||||||
QString m_netrcFileName;
|
QString m_netrcFileName;
|
||||||
QStringList m_allMachines;
|
QStringList m_allMachines;
|
||||||
bool m_authenticated = true;
|
bool m_authenticated = true;
|
||||||
|
QTimer *m_checkTimer = nullptr;
|
||||||
};
|
};
|
||||||
|
|
||||||
} // Internal
|
} // Internal
|
||||||
|
|||||||
Reference in New Issue
Block a user