Qt/AchievementLoginDialog: Make login fully asynchronous

This commit is contained in:
Connor McLaughlin 2021-04-21 01:58:49 +10:00
parent a7017783e4
commit 2e86b65bf9
2 changed files with 13 additions and 12 deletions

View file

@ -20,15 +20,20 @@ void AchievementLoginDialog::loginClicked()
// TODO: Make cancellable.
m_ui.status->setText(tr("Logging in..."));
enableUI(false);
qApp->processEvents(QEventLoop::ExcludeUserInputEvents);
bool result;
QtHostInterface::GetInstance()->executeOnEmulationThread(
[username, password, &result]() {
result = Cheevos::Login(username.toStdString().c_str(), password.toStdString().c_str());
},
true);
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);
}
void AchievementLoginDialog::processLoginResult(bool result)
{
if (!result)
{
QMessageBox::critical(this, tr("Login Error"),
@ -41,11 +46,6 @@ void AchievementLoginDialog::loginClicked()
done(0);
}
void AchievementLoginDialog::cancelClicked()
{
done(1);
}
void AchievementLoginDialog::connectUi()
{
connect(m_ui.login, &QPushButton::clicked, this, &AchievementLoginDialog::loginClicked);

View file

@ -13,6 +13,7 @@ public:
private Q_SLOTS:
void loginClicked();
void cancelClicked();
void processLoginResult(bool result);
private:
void connectUi();