Create a new login dialog
This commit is contained in:
parent
bf1632e4ed
commit
4674aad125
@ -303,6 +303,8 @@ gui/dialogs/CustomMessageBox.h
|
|||||||
gui/dialogs/CustomMessageBox.cpp
|
gui/dialogs/CustomMessageBox.cpp
|
||||||
gui/dialogs/EditAccountDialog.h
|
gui/dialogs/EditAccountDialog.h
|
||||||
gui/dialogs/EditAccountDialog.cpp
|
gui/dialogs/EditAccountDialog.cpp
|
||||||
|
gui/dialogs/LoginDialog.h
|
||||||
|
gui/dialogs/LoginDialog.cpp
|
||||||
gui/dialogs/AccountListDialog.h
|
gui/dialogs/AccountListDialog.h
|
||||||
gui/dialogs/AccountListDialog.cpp
|
gui/dialogs/AccountListDialog.cpp
|
||||||
gui/dialogs/AccountSelectDialog.h
|
gui/dialogs/AccountSelectDialog.h
|
||||||
@ -565,6 +567,7 @@ gui/dialogs/EditNotesDialog.ui
|
|||||||
gui/dialogs/AccountListDialog.ui
|
gui/dialogs/AccountListDialog.ui
|
||||||
gui/dialogs/AccountSelectDialog.ui
|
gui/dialogs/AccountSelectDialog.ui
|
||||||
gui/dialogs/EditAccountDialog.ui
|
gui/dialogs/EditAccountDialog.ui
|
||||||
|
gui/dialogs/LoginDialog.ui
|
||||||
gui/dialogs/UpdateDialog.ui
|
gui/dialogs/UpdateDialog.ui
|
||||||
gui/dialogs/ScreenshotDialog.ui
|
gui/dialogs/ScreenshotDialog.ui
|
||||||
gui/dialogs/NotificationDialog.ui
|
gui/dialogs/NotificationDialog.ui
|
||||||
|
@ -26,6 +26,7 @@
|
|||||||
#include <gui/dialogs/EditAccountDialog.h>
|
#include <gui/dialogs/EditAccountDialog.h>
|
||||||
#include <gui/dialogs/ProgressDialog.h>
|
#include <gui/dialogs/ProgressDialog.h>
|
||||||
#include <gui/dialogs/AccountSelectDialog.h>
|
#include <gui/dialogs/AccountSelectDialog.h>
|
||||||
|
#include <gui/dialogs/LoginDialog.h>
|
||||||
#include "CustomMessageBox.h"
|
#include "CustomMessageBox.h"
|
||||||
#include <logic/tasks/Task.h>
|
#include <logic/tasks/Task.h>
|
||||||
#include <logic/auth/YggdrasilTask.h>
|
#include <logic/auth/YggdrasilTask.h>
|
||||||
@ -45,10 +46,11 @@ AccountListDialog::AccountListDialog(QWidget *parent)
|
|||||||
// Expand the account column
|
// Expand the account column
|
||||||
ui->listView->header()->setSectionResizeMode(1, QHeaderView::Stretch);
|
ui->listView->header()->setSectionResizeMode(1, QHeaderView::Stretch);
|
||||||
|
|
||||||
QItemSelectionModel* selectionModel = ui->listView->selectionModel();
|
QItemSelectionModel *selectionModel = ui->listView->selectionModel();
|
||||||
|
|
||||||
connect(selectionModel, &QItemSelectionModel::selectionChanged,
|
connect(selectionModel, &QItemSelectionModel::selectionChanged,
|
||||||
[this] (const QItemSelection& sel, const QItemSelection& dsel) { updateButtonStates(); });
|
[this](const QItemSelection &sel, const QItemSelection &dsel)
|
||||||
|
{ updateButtonStates(); });
|
||||||
|
|
||||||
connect(m_accounts.get(), SIGNAL(listChanged()), SLOT(listChanged()));
|
connect(m_accounts.get(), SIGNAL(listChanged()), SLOT(listChanged()));
|
||||||
connect(m_accounts.get(), SIGNAL(activeAccountChanged()), SLOT(listChanged()));
|
connect(m_accounts.get(), SIGNAL(activeAccountChanged()), SLOT(listChanged()));
|
||||||
@ -68,7 +70,8 @@ void AccountListDialog::listChanged()
|
|||||||
|
|
||||||
void AccountListDialog::on_addAccountBtn_clicked()
|
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()
|
void AccountListDialog::on_rmAccountBtn_clicked()
|
||||||
@ -87,7 +90,8 @@ void AccountListDialog::on_setDefaultBtn_clicked()
|
|||||||
if (selection.size() > 0)
|
if (selection.size() > 0)
|
||||||
{
|
{
|
||||||
QModelIndex selected = selection.first();
|
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());
|
m_accounts->setActiveAccount(account->username());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -113,48 +117,29 @@ void AccountListDialog::updateButtonStates()
|
|||||||
ui->noDefaultBtn->setDown(m_accounts->activeAccount().get() == nullptr);
|
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.
|
// TODO: The login dialog isn't quite done yet
|
||||||
EditAccountDialog loginDialog(errMsg, this, EditAccountDialog::UsernameField | EditAccountDialog::PasswordField);
|
MojangAccountPtr account = LoginDialog::newAccount(this, errMsg);
|
||||||
loginDialog.exec();
|
|
||||||
|
|
||||||
if (loginDialog.result() == QDialog::Accepted)
|
if (account != nullptr)
|
||||||
{
|
{
|
||||||
QString username(loginDialog.username());
|
m_accounts->addAccount(account);
|
||||||
QString password(loginDialog.password());
|
if (m_accounts->count() == 1)
|
||||||
|
m_accounts->setActiveAccount(account->username());
|
||||||
|
|
||||||
MojangAccountPtr account = MojangAccount::createFromUsername(username);
|
// Grab associated player skins
|
||||||
ProgressDialog progDialog(this);
|
auto job = new NetJob("Player skins: " + account->username());
|
||||||
auto task = account->login(nullptr, password);
|
|
||||||
progDialog.exec(task.get());
|
for (AccountProfile profile : account->profiles())
|
||||||
if(task->successful())
|
|
||||||
{
|
{
|
||||||
m_accounts->addAccount(account);
|
auto meta = MMC->metacache()->resolveEntry("skins", profile.name + ".png");
|
||||||
if (m_accounts->count() == 1)
|
auto action = CacheDownload::make(
|
||||||
m_accounts->setActiveAccount(account->username());
|
QUrl("http://" + URLConstants::SKINS_BASE + profile.name + ".png"), meta);
|
||||||
|
job->addNetAction(action);
|
||||||
// Grab associated player skins
|
meta->stale = true;
|
||||||
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;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
job->start();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
152
gui/dialogs/LoginDialog.cpp
Normal file
152
gui/dialogs/LoginDialog.cpp
Normal file
@ -0,0 +1,152 @@
|
|||||||
|
/* Copyright 2014 MultiMC Contributors
|
||||||
|
*
|
||||||
|
* Authors:
|
||||||
|
* Taeyeon Mori <orochimarufan.x3@gmail.com>
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "LoginDialog.h"
|
||||||
|
#include "ui_LoginDialog.h"
|
||||||
|
|
||||||
|
#include "logic/auth/YggdrasilTask.h"
|
||||||
|
|
||||||
|
#include <QtWidgets/QPushButton>
|
||||||
|
|
||||||
|
LoginDialog::LoginDialog(QWidget *parent) : QDialog(parent), ui(new Ui::LoginDialog)
|
||||||
|
{
|
||||||
|
ui->setupUi(this);
|
||||||
|
ui->progressBar->setVisible(false);
|
||||||
|
ui->buttonBox->button(QDialogButtonBox::Ok)->setEnabled(false);
|
||||||
|
|
||||||
|
setAttribute(Qt::WA_ShowModal);
|
||||||
|
|
||||||
|
connect(ui->buttonBox, &QDialogButtonBox::accepted, this, &QDialog::accept);
|
||||||
|
connect(ui->buttonBox, &QDialogButtonBox::rejected, this, &QDialog::reject);
|
||||||
|
}
|
||||||
|
|
||||||
|
LoginDialog::~LoginDialog()
|
||||||
|
{
|
||||||
|
delete ui;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Stage 1: User interaction
|
||||||
|
void LoginDialog::accept()
|
||||||
|
{
|
||||||
|
setResult(Accepted);
|
||||||
|
loop.quit();
|
||||||
|
}
|
||||||
|
|
||||||
|
void LoginDialog::reject()
|
||||||
|
{
|
||||||
|
setResult(Rejected);
|
||||||
|
loop.quit();
|
||||||
|
}
|
||||||
|
|
||||||
|
void LoginDialog::setUserInputsEnabled(bool enable)
|
||||||
|
{
|
||||||
|
ui->userTextBox->setEnabled(enable);
|
||||||
|
ui->passTextBox->setEnabled(enable);
|
||||||
|
ui->buttonBox->setEnabled(enable);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Enable the OK button only when both textboxes contain something.
|
||||||
|
void LoginDialog::on_userTextBox_textEdited(QString newText)
|
||||||
|
{
|
||||||
|
ui->buttonBox->button(QDialogButtonBox::Ok)
|
||||||
|
->setEnabled(!newText.isEmpty() && !ui->passTextBox->text().isEmpty());
|
||||||
|
}
|
||||||
|
|
||||||
|
void LoginDialog::on_passTextBox_textEdited(QString newText)
|
||||||
|
{
|
||||||
|
ui->buttonBox->button(QDialogButtonBox::Ok)
|
||||||
|
->setEnabled(!newText.isEmpty() && !ui->userTextBox->text().isEmpty());
|
||||||
|
}
|
||||||
|
|
||||||
|
// Stage 2: Task interaction
|
||||||
|
void LoginDialog::onTaskFailed(QString failure)
|
||||||
|
{
|
||||||
|
// Set message
|
||||||
|
ui->label->setText("<span style='color:red'>" + failure + "</span>");
|
||||||
|
|
||||||
|
// Return
|
||||||
|
setResult(Rejected);
|
||||||
|
loop.quit();
|
||||||
|
}
|
||||||
|
|
||||||
|
void LoginDialog::onTaskSucceeded()
|
||||||
|
{
|
||||||
|
setResult(Accepted);
|
||||||
|
loop.quit();
|
||||||
|
}
|
||||||
|
|
||||||
|
void LoginDialog::onTaskStatus(QString status)
|
||||||
|
{
|
||||||
|
ui->label->setText(status);
|
||||||
|
}
|
||||||
|
|
||||||
|
void LoginDialog::onTaskProgress(qint64 current, qint64 total)
|
||||||
|
{
|
||||||
|
ui->progressBar->setMaximum(total);
|
||||||
|
ui->progressBar->setValue(current);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Public interface
|
||||||
|
MojangAccountPtr LoginDialog::newAccount(QWidget *parent, QString msg)
|
||||||
|
{
|
||||||
|
LoginDialog dlg(parent);
|
||||||
|
dlg.show();
|
||||||
|
dlg.ui->label->setText(msg);
|
||||||
|
|
||||||
|
while (1)
|
||||||
|
{
|
||||||
|
// Show dialog
|
||||||
|
dlg.loop.exec();
|
||||||
|
|
||||||
|
// Close if cancel was clicked
|
||||||
|
if (dlg.result() == Rejected)
|
||||||
|
return nullptr;
|
||||||
|
|
||||||
|
// Read values
|
||||||
|
QString username(dlg.ui->userTextBox->text());
|
||||||
|
QString password(dlg.ui->passTextBox->text());
|
||||||
|
|
||||||
|
// disable inputs
|
||||||
|
dlg.setUserInputsEnabled(false);
|
||||||
|
dlg.ui->progressBar->setVisible(true);
|
||||||
|
|
||||||
|
// Start login process
|
||||||
|
MojangAccountPtr account = MojangAccount::createFromUsername(username);
|
||||||
|
auto task = account->login(nullptr, password);
|
||||||
|
|
||||||
|
// show progess
|
||||||
|
connect(task.get(), &ProgressProvider::failed, &dlg, &LoginDialog::onTaskFailed);
|
||||||
|
connect(task.get(), &ProgressProvider::succeeded, &dlg, &LoginDialog::onTaskSucceeded);
|
||||||
|
connect(task.get(), &ProgressProvider::status, &dlg, &LoginDialog::onTaskStatus);
|
||||||
|
connect(task.get(), &ProgressProvider::progress, &dlg, &LoginDialog::onTaskProgress);
|
||||||
|
|
||||||
|
// Start task
|
||||||
|
if (!task->isRunning())
|
||||||
|
task->start();
|
||||||
|
if (task->isRunning())
|
||||||
|
dlg.loop.exec();
|
||||||
|
|
||||||
|
// Be done
|
||||||
|
if (dlg.result() == Accepted)
|
||||||
|
return account;
|
||||||
|
|
||||||
|
// Otherwise, re-enable user inputs and begin anew
|
||||||
|
dlg.setUserInputsEnabled(true);
|
||||||
|
dlg.ui->progressBar->setVisible(false);
|
||||||
|
}
|
||||||
|
}
|
61
gui/dialogs/LoginDialog.h
Normal file
61
gui/dialogs/LoginDialog.h
Normal file
@ -0,0 +1,61 @@
|
|||||||
|
/* Copyright 2014 MultiMC Contributors
|
||||||
|
*
|
||||||
|
* Authors:
|
||||||
|
* Taeyeon Mori <orochimarufan.x3@gmail.com>
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <QtWidgets/QDialog>
|
||||||
|
#include <QtCore/QEventLoop>
|
||||||
|
|
||||||
|
#include "logic/auth/MojangAccount.h"
|
||||||
|
|
||||||
|
namespace Ui
|
||||||
|
{
|
||||||
|
class LoginDialog;
|
||||||
|
}
|
||||||
|
|
||||||
|
class LoginDialog : public QDialog
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
|
||||||
|
public:
|
||||||
|
~LoginDialog();
|
||||||
|
|
||||||
|
static MojangAccountPtr newAccount(QWidget *parent, QString message);
|
||||||
|
|
||||||
|
private:
|
||||||
|
explicit LoginDialog(QWidget *parent = 0);
|
||||||
|
|
||||||
|
void setUserInputsEnabled(bool enable);
|
||||||
|
|
||||||
|
protected
|
||||||
|
slots:
|
||||||
|
void accept();
|
||||||
|
void reject();
|
||||||
|
|
||||||
|
void onTaskFailed(QString);
|
||||||
|
void onTaskSucceeded();
|
||||||
|
void onTaskStatus(QString);
|
||||||
|
void onTaskProgress(qint64, qint64);
|
||||||
|
|
||||||
|
void on_userTextBox_textEdited(QString);
|
||||||
|
void on_passTextBox_textEdited(QString);
|
||||||
|
|
||||||
|
private:
|
||||||
|
Ui::LoginDialog *ui;
|
||||||
|
QEventLoop loop;
|
||||||
|
};
|
77
gui/dialogs/LoginDialog.ui
Normal file
77
gui/dialogs/LoginDialog.ui
Normal file
@ -0,0 +1,77 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<ui version="4.0">
|
||||||
|
<class>LoginDialog</class>
|
||||||
|
<widget class="QDialog" name="LoginDialog">
|
||||||
|
<property name="geometry">
|
||||||
|
<rect>
|
||||||
|
<x>0</x>
|
||||||
|
<y>0</y>
|
||||||
|
<width>400</width>
|
||||||
|
<height>162</height>
|
||||||
|
</rect>
|
||||||
|
</property>
|
||||||
|
<property name="sizePolicy">
|
||||||
|
<sizepolicy hsizetype="Fixed" vsizetype="Fixed">
|
||||||
|
<horstretch>0</horstretch>
|
||||||
|
<verstretch>0</verstretch>
|
||||||
|
</sizepolicy>
|
||||||
|
</property>
|
||||||
|
<property name="windowTitle">
|
||||||
|
<string>Add Account</string>
|
||||||
|
</property>
|
||||||
|
<layout class="QVBoxLayout" name="verticalLayout">
|
||||||
|
<item>
|
||||||
|
<widget class="QLabel" name="label">
|
||||||
|
<property name="text">
|
||||||
|
<string>Message label placeholder.</string>
|
||||||
|
</property>
|
||||||
|
<property name="textFormat">
|
||||||
|
<enum>Qt::RichText</enum>
|
||||||
|
</property>
|
||||||
|
<property name="textInteractionFlags">
|
||||||
|
<set>Qt::LinksAccessibleByKeyboard|Qt::LinksAccessibleByMouse|Qt::TextBrowserInteraction|Qt::TextSelectableByKeyboard|Qt::TextSelectableByMouse</set>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<widget class="QLineEdit" name="userTextBox">
|
||||||
|
<property name="placeholderText">
|
||||||
|
<string>Email / Username</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<widget class="QLineEdit" name="passTextBox">
|
||||||
|
<property name="echoMode">
|
||||||
|
<enum>QLineEdit::Password</enum>
|
||||||
|
</property>
|
||||||
|
<property name="placeholderText">
|
||||||
|
<string>Password</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<widget class="QProgressBar" name="progressBar">
|
||||||
|
<property name="value">
|
||||||
|
<number>24</number>
|
||||||
|
</property>
|
||||||
|
<property name="textVisible">
|
||||||
|
<bool>false</bool>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<widget class="QDialogButtonBox" name="buttonBox">
|
||||||
|
<property name="orientation">
|
||||||
|
<enum>Qt::Horizontal</enum>
|
||||||
|
</property>
|
||||||
|
<property name="standardButtons">
|
||||||
|
<set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
</layout>
|
||||||
|
</widget>
|
||||||
|
<resources/>
|
||||||
|
<connections/>
|
||||||
|
</ui>
|
Loading…
Reference in New Issue
Block a user