summaryrefslogtreecommitdiffstats
path: root/gui/dialogs/AccountListDialog.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'gui/dialogs/AccountListDialog.cpp')
-rw-r--r--gui/dialogs/AccountListDialog.cpp71
1 files changed, 28 insertions, 43 deletions
diff --git a/gui/dialogs/AccountListDialog.cpp b/gui/dialogs/AccountListDialog.cpp
index a38035a6..688cffa8 100644
--- a/gui/dialogs/AccountListDialog.cpp
+++ b/gui/dialogs/AccountListDialog.cpp
@@ -26,6 +26,7 @@
#include <gui/dialogs/EditAccountDialog.h>
#include <gui/dialogs/ProgressDialog.h>
#include <gui/dialogs/AccountSelectDialog.h>
+#include <gui/dialogs/LoginDialog.h>
#include "CustomMessageBox.h"
#include <logic/tasks/Task.h>
#include <logic/auth/YggdrasilTask.h>
@@ -45,10 +46,11 @@ AccountListDialog::AccountListDialog(QWidget *parent)
// Expand the account column
ui->listView->header()->setSectionResizeMode(1, QHeaderView::Stretch);
- QItemSelectionModel* selectionModel = ui->listView->selectionModel();
+ QItemSelectionModel *selectionModel = ui->listView->selectionModel();
- connect(selectionModel, &QItemSelectionModel::selectionChanged,
- [this] (const QItemSelection& sel, const QItemSelection& dsel) { updateButtonStates(); });
+ connect(selectionModel, &QItemSelectionModel::selectionChanged,
+ [this](const QItemSelection &sel, const QItemSelection &dsel)
+ { updateButtonStates(); });
connect(m_accounts.get(), SIGNAL(listChanged()), SLOT(listChanged()));
connect(m_accounts.get(), SIGNAL(activeAccountChanged()), SLOT(listChanged()));
@@ -68,7 +70,8 @@ void AccountListDialog::listChanged()
void AccountListDialog::on_addAccountBtn_clicked()
{
- addAccount(tr("Please enter your Mojang or Minecraft account username and password to add your account."));
+ addAccount(tr("Please enter your Mojang or Minecraft account username and password to add "
+ "your account."));
}
void AccountListDialog::on_rmAccountBtn_clicked()
@@ -87,7 +90,8 @@ void AccountListDialog::on_setDefaultBtn_clicked()
if (selection.size() > 0)
{
QModelIndex selected = selection.first();
- MojangAccountPtr account = selected.data(MojangAccountList::PointerRole).value<MojangAccountPtr>();
+ MojangAccountPtr account =
+ selected.data(MojangAccountList::PointerRole).value<MojangAccountPtr>();
m_accounts->setActiveAccount(account->username());
}
}
@@ -113,48 +117,29 @@ void AccountListDialog::updateButtonStates()
ui->noDefaultBtn->setDown(m_accounts->activeAccount().get() == nullptr);
}
-void AccountListDialog::addAccount(const QString& errMsg)
+void AccountListDialog::addAccount(const QString &errMsg)
{
- // TODO: We can use the login dialog for this for now, but we'll have to make something better for it eventually.
- EditAccountDialog loginDialog(errMsg, this, EditAccountDialog::UsernameField | EditAccountDialog::PasswordField);
- loginDialog.exec();
+ // TODO: The login dialog isn't quite done yet
+ MojangAccountPtr account = LoginDialog::newAccount(this, errMsg);
- if (loginDialog.result() == QDialog::Accepted)
+ if (account != nullptr)
{
- QString username(loginDialog.username());
- QString password(loginDialog.password());
-
- MojangAccountPtr account = MojangAccount::createFromUsername(username);
- ProgressDialog progDialog(this);
- auto task = account->login(nullptr, password);
- progDialog.exec(task.get());
- if(task->successful())
- {
- m_accounts->addAccount(account);
- if (m_accounts->count() == 1)
- m_accounts->setActiveAccount(account->username());
-
- // Grab associated player skins
- auto job = new NetJob("Player skins: " + account->username());
-
- for(AccountProfile profile : account->profiles())
- {
- auto meta = MMC->metacache()->resolveEntry("skins", profile.name + ".png");
- auto action = CacheDownload::make(
- QUrl("http://" + URLConstants::SKINS_BASE + profile.name + ".png"),
- meta);
- job->addNetAction(action);
- meta->stale = true;
- }
-
- job->start();
- }
- else
+ m_accounts->addAccount(account);
+ if (m_accounts->count() == 1)
+ m_accounts->setActiveAccount(account->username());
+
+ // Grab associated player skins
+ auto job = new NetJob("Player skins: " + account->username());
+
+ for (AccountProfile profile : account->profiles())
{
- auto reason = task->failReason();
- auto dlg = CustomMessageBox::selectable(this, tr("Login error."), reason, QMessageBox::Critical);
- dlg->exec();
- delete dlg;
+ auto meta = MMC->metacache()->resolveEntry("skins", profile.name + ".png");
+ auto action = CacheDownload::make(
+ QUrl("http://" + URLConstants::SKINS_BASE + profile.name + ".png"), meta);
+ job->addNetAction(action);
+ meta->stale = true;
}
+
+ job->start();
}
}