From 08b2f6c715b579bd89dce312a0daa72d92a9a43a Mon Sep 17 00:00:00 2001 From: Silent Date: Mon, 8 Mar 2021 21:10:55 +0100 Subject: [PATCH] AchievementLoginDialog: Lock out "Login" if fields aren't filled --- src/duckstation-qt/achievementlogindialog.cpp | 16 ++++++++++------ src/duckstation-qt/achievementlogindialog.h | 1 + src/duckstation-qt/achievementlogindialog.ui | 3 +++ 3 files changed, 14 insertions(+), 6 deletions(-) diff --git a/src/duckstation-qt/achievementlogindialog.cpp b/src/duckstation-qt/achievementlogindialog.cpp index cb65c8fe6..fe9940f0f 100644 --- a/src/duckstation-qt/achievementlogindialog.cpp +++ b/src/duckstation-qt/achievementlogindialog.cpp @@ -16,11 +16,6 @@ void AchievementLoginDialog::loginClicked() { const std::string username(m_ui.userName->text().toStdString()); const std::string password(m_ui.password->text().toStdString()); - if (username.empty() || password.empty()) - { - QMessageBox::critical(this, tr("Login Error"), tr("A user name and password must be provided.")); - return; - } // TODO: Make cancellable. m_ui.status->setText(tr("Logging in...")); @@ -52,6 +47,10 @@ void AchievementLoginDialog::connectUi() { connect(m_ui.login, &QPushButton::clicked, this, &AchievementLoginDialog::loginClicked); connect(m_ui.cancel, &QPushButton::clicked, this, &AchievementLoginDialog::cancelClicked); + + auto enableLoginButton = [this](const QString&) { m_ui.login->setEnabled(canEnableLoginButton()); }; + connect(m_ui.userName, &QLineEdit::textChanged, enableLoginButton); + connect(m_ui.password, &QLineEdit::textChanged, enableLoginButton); } void AchievementLoginDialog::enableUI(bool enabled) @@ -59,5 +58,10 @@ void AchievementLoginDialog::enableUI(bool enabled) m_ui.userName->setEnabled(enabled); m_ui.password->setEnabled(enabled); m_ui.cancel->setEnabled(enabled); - m_ui.login->setEnabled(enabled); + m_ui.login->setEnabled(enabled && canEnableLoginButton()); +} + +bool AchievementLoginDialog::canEnableLoginButton() const +{ + return !m_ui.userName->text().isEmpty() && !m_ui.password->text().isEmpty(); } diff --git a/src/duckstation-qt/achievementlogindialog.h b/src/duckstation-qt/achievementlogindialog.h index c40c146f5..8d251fd1a 100644 --- a/src/duckstation-qt/achievementlogindialog.h +++ b/src/duckstation-qt/achievementlogindialog.h @@ -17,6 +17,7 @@ private Q_SLOTS: private: void connectUi(); void enableUI(bool enabled); + bool canEnableLoginButton() const; Ui::AchievementLoginDialog m_ui; }; diff --git a/src/duckstation-qt/achievementlogindialog.ui b/src/duckstation-qt/achievementlogindialog.ui index 08a3fab62..429b8df08 100644 --- a/src/duckstation-qt/achievementlogindialog.ui +++ b/src/duckstation-qt/achievementlogindialog.ui @@ -125,6 +125,9 @@ + + false + &Login