diff options
Diffstat (limited to 'gui/MainWindow.cpp')
-rw-r--r-- | gui/MainWindow.cpp | 98 |
1 files changed, 36 insertions, 62 deletions
diff --git a/gui/MainWindow.cpp b/gui/MainWindow.cpp index 854091c6..fd35e94e 100644 --- a/gui/MainWindow.cpp +++ b/gui/MainWindow.cpp @@ -69,10 +69,6 @@ #include "logic/lists/IconList.h" #include "logic/lists/JavaVersionList.h" -#include "logic/auth/flows/AuthenticateTask.h" -#include "logic/auth/flows/RefreshTask.h" -#include "logic/auth/flows/ValidateTask.h" - #include "logic/BaseInstance.h" #include "logic/InstanceFactory.h" #include "logic/MinecraftProcess.h" @@ -210,9 +206,9 @@ MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWi for(AccountProfile profile : account->profiles()) { - auto meta = MMC->metacache()->resolveEntry("skins", profile.name() + ".png"); + auto meta = MMC->metacache()->resolveEntry("skins", profile.name + ".png"); auto action = CacheDownload::make( - QUrl("http://skins.minecraft.net/MinecraftSkins/" + profile.name() + ".png"), + QUrl("http://skins.minecraft.net/MinecraftSkins/" + profile.name + ".png"), meta); job->addNetAction(action); meta->stale = true; @@ -310,9 +306,9 @@ void MainWindow::repopulateAccountsMenu() section->setEnabled(false); accountMenu->addAction(section); - for (AccountProfile profile : account->profiles()) + for (auto profile : account->profiles()) { - QAction *action = new QAction(profile.name(), this); + QAction *action = new QAction(profile.name, this); action->setData(account->username()); action->setCheckable(true); if(active_username == account->username()) @@ -320,7 +316,7 @@ void MainWindow::repopulateAccountsMenu() action->setChecked(true); } - action->setIcon(SkinUtils::getFaceFromCache(profile.name())); + action->setIcon(SkinUtils::getFaceFromCache(profile.name)); accountMenu->addAction(action); connect(action, SIGNAL(triggered(bool)), SLOT(changeActiveAccount())); } @@ -378,7 +374,7 @@ void MainWindow::activeAccountChanged() const AccountProfile *profile = account->currentProfile(); if (profile != nullptr) { - accountMenuButton->setIcon(SkinUtils::getFaceFromCache(profile->name())); + accountMenuButton->setIcon(SkinUtils::getFaceFromCache(profile->name)); return; } } @@ -781,79 +777,58 @@ void MainWindow::doLaunch() accounts->setActiveAccount(account->username()); } - if (account.get() != nullptr) - { - doLaunchInst(m_selectedInstance, account); - } -} - -void MainWindow::doLaunchInst(BaseInstance* instance, MojangAccountPtr account) -{ - // We'll need to validate the access token to make sure the account is still logged in. - ProgressDialog progDialog(this); - RefreshTask refreshtask(account, &progDialog); - progDialog.exec(&refreshtask); + // if no account is selected, we bail + if (!account.get()) + return; - if (refreshtask.successful()) - { - prepareLaunch(m_selectedInstance, account); - } - else + // do the login. if the account has an access token, try to refresh it first. + if(account->accountStatus() != NotVerified) { - YggdrasilTask::Error *error = refreshtask.getError(); + // We'll need to validate the access token to make sure the account is still logged in. + ProgressDialog progDialog(this); + progDialog.setSkipButton(true, tr("Play Offline")); + auto task = account->login(); + progDialog.exec(task.get()); - if (error != nullptr) + auto status = account->accountStatus(); + if(status == Online) // Online mode! Refresh the token. { - if (error->getErrorMessage().contains("invalid token", Qt::CaseInsensitive)) - { - // TODO: Allow the user to enter their password and "refresh" their access token. - if (doRefreshToken(account, tr("Your account's access token is invalid. Please enter your password to log in again."))) - doLaunchInst(instance, account); - } - else - { - CustomMessageBox::selectable( - this, tr("Access Token Validation Error"), - tr("There was an error when trying to validate your access token.\n" - "Details: %s").arg(error->getDisplayMessage()), - QMessageBox::Warning, QMessageBox::Ok)->exec(); - } + updateInstance(m_selectedInstance, account); + return; } - else + else if(status == Verified) // Offline mode with a verified account { - CustomMessageBox::selectable( - this, tr("Access Token Validation Error"), - tr("There was an unknown error when trying to validate your access token." - "The authentication server might be down, or you might not be connected to " - "the Internet."), - QMessageBox::Warning, QMessageBox::Ok)->exec(); + launchInstance(m_selectedInstance, account); + return; } } + if (loginWithPassword(account, tr("Your account is currently not logged in. Please enter your password to log in again."))) + updateInstance(m_selectedInstance, account); } -bool MainWindow::doRefreshToken(MojangAccountPtr account, const QString& errorMsg) +bool MainWindow::loginWithPassword(MojangAccountPtr account, const QString& errorMsg) { EditAccountDialog passDialog(errorMsg, this, EditAccountDialog::PasswordField); if (passDialog.exec() == QDialog::Accepted) { // To refresh the token, we just create an authenticate task with the given account and the user's password. ProgressDialog progDialog(this); - AuthenticateTask authTask(account, passDialog.password(), &progDialog); - progDialog.exec(&authTask); - if (authTask.successful()) + auto task = account->login(passDialog.password()); + progDialog.exec(task.get()); + if(task->successful()) return true; else { // If the authentication task failed, recurse with the task's error message. - return doRefreshToken(account, authTask.failReason()); + return loginWithPassword(account, task->failReason()); } } - else return false; + return false; } -void MainWindow::prepareLaunch(BaseInstance* instance, MojangAccountPtr account) +void MainWindow::updateInstance(BaseInstance* instance, MojangAccountPtr account) { - Task *updateTask = instance->doUpdate(true); + auto updateTask = instance->doUpdate(true); if (!updateTask) { launchInstance(instance, account); @@ -861,10 +836,9 @@ void MainWindow::prepareLaunch(BaseInstance* instance, MojangAccountPtr account) else { ProgressDialog tDialog(this); - connect(updateTask, &Task::succeeded, [this, instance, account] { launchInstance(instance, account); }); - connect(updateTask, SIGNAL(failed(QString)), SLOT(onGameUpdateError(QString))); - tDialog.exec(updateTask); - delete updateTask; + connect(updateTask.get(), &Task::succeeded, [this, instance, account] { launchInstance(instance, account); }); + connect(updateTask.get(), SIGNAL(failed(QString)), SLOT(onGameUpdateError(QString))); + tDialog.exec(updateTask.get()); } } |