2021-02-26 14:44:53 +00:00
|
|
|
#include "achievementlogindialog.h"
|
2022-03-26 13:51:37 +00:00
|
|
|
#include "core/cheevos.h"
|
2021-02-26 14:44:53 +00:00
|
|
|
#include "qthostinterface.h"
|
|
|
|
#include <QtWidgets/QMessageBox>
|
|
|
|
|
|
|
|
AchievementLoginDialog::AchievementLoginDialog(QWidget* parent) : QDialog(parent)
|
|
|
|
{
|
|
|
|
m_ui.setupUi(this);
|
|
|
|
setWindowFlags(windowFlags() & ~Qt::WindowContextHelpButtonHint);
|
2021-12-13 21:05:42 +00:00
|
|
|
|
|
|
|
m_login = m_ui.buttonBox->addButton(tr("&Login"), QDialogButtonBox::AcceptRole);
|
|
|
|
m_login->setEnabled(false);
|
2021-02-26 14:44:53 +00:00
|
|
|
connectUi();
|
|
|
|
}
|
|
|
|
|
|
|
|
AchievementLoginDialog::~AchievementLoginDialog() = default;
|
|
|
|
|
|
|
|
void AchievementLoginDialog::loginClicked()
|
|
|
|
{
|
2021-04-20 15:40:49 +00:00
|
|
|
const QString username(m_ui.userName->text());
|
|
|
|
const QString password(m_ui.password->text());
|
2021-02-26 14:44:53 +00:00
|
|
|
|
|
|
|
// TODO: Make cancellable.
|
|
|
|
m_ui.status->setText(tr("Logging in..."));
|
|
|
|
enableUI(false);
|
|
|
|
|
2021-04-20 15:58:49 +00:00
|
|
|
QtHostInterface::GetInstance()->executeOnEmulationThread([this, username, password]() {
|
|
|
|
const bool result = Cheevos::Login(username.toStdString().c_str(), password.toStdString().c_str());
|
|
|
|
QMetaObject::invokeMethod(this, "processLoginResult", Qt::QueuedConnection, Q_ARG(bool, result));
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
void AchievementLoginDialog::cancelClicked()
|
|
|
|
{
|
|
|
|
done(1);
|
|
|
|
}
|
2021-02-26 14:44:53 +00:00
|
|
|
|
2021-04-20 15:58:49 +00:00
|
|
|
void AchievementLoginDialog::processLoginResult(bool result)
|
|
|
|
{
|
2021-02-26 14:44:53 +00:00
|
|
|
if (!result)
|
|
|
|
{
|
|
|
|
QMessageBox::critical(this, tr("Login Error"),
|
|
|
|
tr("Login failed. Please check your username and password, and try again."));
|
|
|
|
m_ui.status->setText(tr("Login failed."));
|
|
|
|
enableUI(true);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
done(0);
|
|
|
|
}
|
|
|
|
|
|
|
|
void AchievementLoginDialog::connectUi()
|
|
|
|
{
|
2021-12-13 21:05:42 +00:00
|
|
|
connect(m_ui.buttonBox, &QDialogButtonBox::accepted, this, &AchievementLoginDialog::loginClicked);
|
|
|
|
connect(m_ui.buttonBox, &QDialogButtonBox::rejected, this, &AchievementLoginDialog::cancelClicked);
|
2021-03-08 20:10:55 +00:00
|
|
|
|
2021-12-13 21:05:42 +00:00
|
|
|
auto enableLoginButton = [this](const QString&) { m_login->setEnabled(canEnableLoginButton()); };
|
2021-03-08 20:10:55 +00:00
|
|
|
connect(m_ui.userName, &QLineEdit::textChanged, enableLoginButton);
|
|
|
|
connect(m_ui.password, &QLineEdit::textChanged, enableLoginButton);
|
2021-02-26 14:44:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void AchievementLoginDialog::enableUI(bool enabled)
|
|
|
|
{
|
|
|
|
m_ui.userName->setEnabled(enabled);
|
|
|
|
m_ui.password->setEnabled(enabled);
|
2021-12-13 21:05:42 +00:00
|
|
|
m_ui.buttonBox->button(QDialogButtonBox::Cancel)->setEnabled(enabled);
|
|
|
|
m_login->setEnabled(enabled && canEnableLoginButton());
|
2021-03-08 20:10:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool AchievementLoginDialog::canEnableLoginButton() const
|
|
|
|
{
|
|
|
|
return !m_ui.userName->text().isEmpty() && !m_ui.password->text().isEmpty();
|
2021-02-26 14:44:53 +00:00
|
|
|
}
|