Create a new login dialog

This commit is contained in:
Taeyeon Mori
2014-04-16 16:19:12 +02:00
parent bf1632e4ed
commit 4674aad125
5 changed files with 320 additions and 42 deletions

View File

@ -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());
m_accounts->addAccount(account);
if (m_accounts->count() == 1)
m_accounts->setActiveAccount(account->username());
MojangAccountPtr account = MojangAccount::createFromUsername(username);
ProgressDialog progDialog(this);
auto task = account->login(nullptr, password);
progDialog.exec(task.get());
if(task->successful())
// Grab associated player skins
auto job = new NetJob("Player skins: " + account->username());
for (AccountProfile profile : account->profiles())
{
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
{
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();
}
}