diff options
author | Andrew <forkk@forkk.net> | 2013-11-28 21:40:40 -0600 |
---|---|---|
committer | Andrew <forkk@forkk.net> | 2013-11-28 21:40:40 -0600 |
commit | f3a9dde52e99385eba01c9356ed8ef9548833e34 (patch) | |
tree | 557ddb2f51f4f1517f58a4a3e43201229a5b1abc /gui/dialogs/AccountListDialog.cpp | |
parent | bfc9e1e5d598f354dd39e5c2eb51d5e51585359b (diff) | |
download | MultiMC-f3a9dde52e99385eba01c9356ed8ef9548833e34.tar MultiMC-f3a9dde52e99385eba01c9356ed8ef9548833e34.tar.gz MultiMC-f3a9dde52e99385eba01c9356ed8ef9548833e34.tar.lz MultiMC-f3a9dde52e99385eba01c9356ed8ef9548833e34.tar.xz MultiMC-f3a9dde52e99385eba01c9356ed8ef9548833e34.zip |
Rework the password dialog
It's now used as a general purpose "account edit dialog". It'll be used
for entering usernames, passwords, or both.
Diffstat (limited to 'gui/dialogs/AccountListDialog.cpp')
-rw-r--r-- | gui/dialogs/AccountListDialog.cpp | 91 |
1 files changed, 38 insertions, 53 deletions
diff --git a/gui/dialogs/AccountListDialog.cpp b/gui/dialogs/AccountListDialog.cpp index 29f3838d..dfac4989 100644 --- a/gui/dialogs/AccountListDialog.cpp +++ b/gui/dialogs/AccountListDialog.cpp @@ -23,7 +23,7 @@ #include <logic/auth/AuthenticateTask.h> #include <logic/net/NetJob.h> -#include <gui/dialogs/LoginDialog.h> +#include <gui/dialogs/EditAccountDialog.h> #include <gui/dialogs/ProgressDialog.h> #include <gui/dialogs/AccountSelectDialog.h> @@ -40,10 +40,12 @@ AccountListDialog::AccountListDialog(QWidget *parent) : ui->listView->setModel(m_accounts.get()); QItemSelectionModel* selectionModel = ui->listView->selectionModel(); + connect(selectionModel, &QItemSelectionModel::selectionChanged, [this] (const QItemSelection& sel, const QItemSelection& dsel) { updateButtonStates(); }); - connect(m_accounts.get(), &MojangAccountList::listChanged, - [this] () { updateButtonStates(); }); + + connect(m_accounts.get(), SIGNAL(listChanged), SLOT(listChanged)); + connect(m_accounts.get(), SIGNAL(activeAccountChanged), SLOT(listChanged)); updateButtonStates(); } @@ -53,10 +55,15 @@ AccountListDialog::~AccountListDialog() delete ui; } +void AccountListDialog::listChanged() +{ + updateButtonStates(); +} + void AccountListDialog::on_addAccountBtn_clicked() { - doLogin("Please log in 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() @@ -66,16 +73,9 @@ void AccountListDialog::on_rmAccountBtn_clicked() { QModelIndex selected = selection.first(); m_accounts->removeAccount(selected); - - emit activeAccountChanged(); } } -void AccountListDialog::on_editAccountBtn_clicked() -{ - // TODO -} - void AccountListDialog::on_setDefaultBtn_clicked() { QModelIndexList selection = ui->listView->selectionModel()->selectedIndexes(); @@ -84,16 +84,12 @@ void AccountListDialog::on_setDefaultBtn_clicked() QModelIndex selected = selection.first(); MojangAccountPtr account = selected.data(MojangAccountList::PointerRole).value<MojangAccountPtr>(); m_accounts->setActiveAccount(account->username()); - - emit activeAccountChanged(); } } void AccountListDialog::on_noDefaultBtn_clicked() { m_accounts->setActiveAccount(""); - - emit activeAccountChanged(); } void AccountListDialog::on_closeBtnBox_rejected() @@ -107,58 +103,47 @@ void AccountListDialog::updateButtonStates() QModelIndexList selection = ui->listView->selectionModel()->selectedIndexes(); ui->rmAccountBtn->setEnabled(selection.size() > 0); - ui->editAccountBtn->setEnabled(selection.size() > 0); ui->setDefaultBtn->setEnabled(selection.size() > 0); ui->noDefaultBtn->setDown(m_accounts->activeAccount().get() == nullptr); } -void AccountListDialog::doLogin(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. - LoginDialog loginDialog(this); + EditAccountDialog loginDialog(errMsg, this, EditAccountDialog::UsernameField | EditAccountDialog::PasswordField); loginDialog.exec(); if (loginDialog.result() == QDialog::Accepted) { - QString username(loginDialog.getUsername()); - QString password(loginDialog.getPassword()); + QString username(loginDialog.username()); + QString password(loginDialog.password()); MojangAccountPtr account = MojangAccountPtr(new MojangAccount(username)); - ProgressDialog* progDialog = new ProgressDialog(this); - m_authTask = new AuthenticateTask(account, password, progDialog); - connect(m_authTask, SIGNAL(succeeded()), SLOT(onLoginComplete()), Qt::QueuedConnection); - connect(m_authTask, SIGNAL(failed(QString)), SLOT(doLogin(QString)), Qt::QueuedConnection); - progDialog->exec(m_authTask); - //delete m_authTask; + ProgressDialog progDialog(this); + AuthenticateTask authTask(account, password, &progDialog); + if (progDialog.exec(&authTask)) + { + // Add the authenticated account to the accounts list. + MojangAccountPtr account = authTask.getMojangAccount(); + m_accounts->addAccount(account); + + // 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://skins.minecraft.net/MinecraftSkins/" + profile.name() + ".png"), + meta); + job->addNetAction(action); + meta->stale = true; + } + + job->start(); + } } } -void AccountListDialog::onLoginComplete() -{ - // Add the authenticated account to the accounts list. - MojangAccountPtr account = m_authTask->getMojangAccount(); - m_accounts->addAccount(account); - - emit activeAccountChanged(); - - //ui->listView->update(); - - // 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://skins.minecraft.net/MinecraftSkins/" + profile.name() + ".png"), - meta); - job->addNetAction(action); - meta->stale = true; - } - - connect(job, SIGNAL(succeeded()), SIGNAL(activeAccountChanged())); - job->start(); -} - |