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.
This commit is contained in:
parent
bfc9e1e5d5
commit
f3a9dde52e
@ -217,8 +217,8 @@ gui/dialogs/EditNotesDialog.h
|
||||
gui/dialogs/EditNotesDialog.cpp
|
||||
gui/dialogs/CustomMessageBox.h
|
||||
gui/dialogs/CustomMessageBox.cpp
|
||||
gui/dialogs/PasswordDialog.h
|
||||
gui/dialogs/PasswordDialog.cpp
|
||||
gui/dialogs/EditAccountDialog.h
|
||||
gui/dialogs/EditAccountDialog.cpp
|
||||
gui/dialogs/AccountListDialog.h
|
||||
gui/dialogs/AccountListDialog.cpp
|
||||
gui/dialogs/AccountSelectDialog.h
|
||||
@ -370,7 +370,6 @@ gui/dialogs/SettingsDialog.ui
|
||||
gui/dialogs/CopyInstanceDialog.ui
|
||||
gui/dialogs/NewInstanceDialog.ui
|
||||
gui/dialogs/LoginDialog.ui
|
||||
gui/dialogs/PasswordDialog.ui
|
||||
gui/dialogs/AboutDialog.ui
|
||||
gui/dialogs/VersionSelectDialog.ui
|
||||
gui/dialogs/LwjglSelectDialog.ui
|
||||
@ -382,6 +381,7 @@ gui/dialogs/OneSixModEditDialog.ui
|
||||
gui/dialogs/EditNotesDialog.ui
|
||||
gui/dialogs/AccountListDialog.ui
|
||||
gui/dialogs/AccountSelectDialog.ui
|
||||
gui/dialogs/EditAccountDialog.ui
|
||||
|
||||
# Widgets/other
|
||||
gui/widgets/MCModInfoFrame.ui
|
||||
|
@ -60,7 +60,7 @@
|
||||
#include "gui/dialogs/CopyInstanceDialog.h"
|
||||
#include "gui/dialogs/AccountListDialog.h"
|
||||
#include "gui/dialogs/AccountSelectDialog.h"
|
||||
#include "gui/dialogs/PasswordDialog.h"
|
||||
#include "gui/dialogs/EditAccountDialog.h"
|
||||
|
||||
#include "gui/ConsoleWindow.h"
|
||||
|
||||
@ -599,7 +599,6 @@ void MainWindow::on_actionSettings_triggered()
|
||||
void MainWindow::on_actionManageAccounts_triggered()
|
||||
{
|
||||
AccountListDialog dialog(this);
|
||||
connect(&dialog, SIGNAL(activeAccountChanged()), SLOT(activeAccountChanged()));
|
||||
dialog.exec();
|
||||
}
|
||||
|
||||
@ -812,7 +811,7 @@ void MainWindow::doLaunchInst(BaseInstance* instance, MojangAccountPtr account)
|
||||
|
||||
bool MainWindow::doRefreshToken(MojangAccountPtr account, const QString& errorMsg)
|
||||
{
|
||||
PasswordDialog passDialog(errorMsg, this);
|
||||
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.
|
||||
|
@ -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,44 +103,32 @@ 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;
|
||||
}
|
||||
}
|
||||
|
||||
void AccountListDialog::onLoginComplete()
|
||||
{
|
||||
ProgressDialog progDialog(this);
|
||||
AuthenticateTask authTask(account, password, &progDialog);
|
||||
if (progDialog.exec(&authTask))
|
||||
{
|
||||
// Add the authenticated account to the accounts list.
|
||||
MojangAccountPtr account = m_authTask->getMojangAccount();
|
||||
MojangAccountPtr account = authTask.getMojangAccount();
|
||||
m_accounts->addAccount(account);
|
||||
|
||||
emit activeAccountChanged();
|
||||
|
||||
//ui->listView->update();
|
||||
|
||||
// Grab associated player skins
|
||||
auto job = new NetJob("Player skins: " + account->username());
|
||||
|
||||
@ -158,7 +142,8 @@ void AccountListDialog::onLoginComplete()
|
||||
meta->stale = true;
|
||||
}
|
||||
|
||||
connect(job, SIGNAL(succeeded()), SIGNAL(activeAccountChanged()));
|
||||
job->start();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -40,8 +40,6 @@ slots:
|
||||
|
||||
void on_rmAccountBtn_clicked();
|
||||
|
||||
void on_editAccountBtn_clicked();
|
||||
|
||||
void on_setDefaultBtn_clicked();
|
||||
|
||||
void on_noDefaultBtn_clicked();
|
||||
@ -49,21 +47,17 @@ slots:
|
||||
// This will be sent when the "close" button is clicked.
|
||||
void on_closeBtnBox_rejected();
|
||||
|
||||
void listChanged();
|
||||
|
||||
//! Updates the states of the dialog's buttons.
|
||||
void updateButtonStates();
|
||||
|
||||
signals:
|
||||
void activeAccountChanged();
|
||||
|
||||
protected:
|
||||
std::shared_ptr<MojangAccountList> m_accounts;
|
||||
|
||||
AuthenticateTask* m_authTask;
|
||||
|
||||
protected
|
||||
slots:
|
||||
void doLogin(const QString& errMsg="");
|
||||
void onLoginComplete();
|
||||
void addAccount(const QString& errMsg="");
|
||||
|
||||
private:
|
||||
Ui::AccountListDialog *ui;
|
||||
|
@ -38,13 +38,6 @@
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QPushButton" name="editAccountBtn">
|
||||
<property name="text">
|
||||
<string>&Edit</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QPushButton" name="rmAccountBtn">
|
||||
<property name="text">
|
||||
|
@ -13,25 +13,33 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include "PasswordDialog.h"
|
||||
#include "ui_PasswordDialog.h"
|
||||
#include "EditAccountDialog.h"
|
||||
#include "ui_EditAccountDialog.h"
|
||||
|
||||
PasswordDialog::PasswordDialog(const QString& errorMsg, QWidget *parent) :
|
||||
EditAccountDialog::EditAccountDialog(const QString& text, QWidget *parent, int flags) :
|
||||
QDialog(parent),
|
||||
ui(new Ui::PasswordDialog)
|
||||
ui(new Ui::EditAccountDialog)
|
||||
{
|
||||
ui->setupUi(this);
|
||||
|
||||
ui->errorLabel->setText(errorMsg);
|
||||
ui->errorLabel->setVisible(!errorMsg.isEmpty());
|
||||
ui->label->setText(text);
|
||||
ui->label->setVisible(!text.isEmpty());
|
||||
|
||||
ui->userTextBox->setVisible(flags & UsernameField);
|
||||
ui->passTextBox->setVisible(flags & PasswordField);
|
||||
}
|
||||
|
||||
PasswordDialog::~PasswordDialog()
|
||||
EditAccountDialog::~EditAccountDialog()
|
||||
{
|
||||
delete ui;
|
||||
}
|
||||
|
||||
QString PasswordDialog::password() const
|
||||
QString EditAccountDialog::username() const
|
||||
{
|
||||
return ui->userTextBox->text();
|
||||
}
|
||||
|
||||
QString EditAccountDialog::password() const
|
||||
{
|
||||
return ui->passTextBox->text();
|
||||
}
|
@ -18,23 +18,39 @@
|
||||
#include <QDialog>
|
||||
|
||||
namespace Ui {
|
||||
class PasswordDialog;
|
||||
class EditAccountDialog;
|
||||
}
|
||||
|
||||
class PasswordDialog : public QDialog
|
||||
class EditAccountDialog : public QDialog
|
||||
{
|
||||
Q_OBJECT
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit PasswordDialog(const QString& errorMsg="", QWidget *parent = 0);
|
||||
~PasswordDialog();
|
||||
explicit EditAccountDialog(const QString& text="", QWidget *parent = 0, int flags=UsernameField | PasswordField);
|
||||
~EditAccountDialog();
|
||||
|
||||
/*!
|
||||
* Gets the text entered in the dialog's username field.
|
||||
*/
|
||||
QString username() const;
|
||||
|
||||
/*!
|
||||
* Gets the text entered in the dialog's password field.
|
||||
*/
|
||||
QString password() const;
|
||||
|
||||
enum Flags
|
||||
{
|
||||
NoFlags=0,
|
||||
|
||||
//! Specifies that the dialog should have a username field.
|
||||
UsernameField,
|
||||
|
||||
//! Specifies that the dialog should have a password field.
|
||||
PasswordField,
|
||||
};
|
||||
|
||||
private:
|
||||
Ui::PasswordDialog *ui;
|
||||
Ui::EditAccountDialog *ui;
|
||||
};
|
||||
|
@ -1,13 +1,13 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<ui version="4.0">
|
||||
<class>PasswordDialog</class>
|
||||
<widget class="QDialog" name="PasswordDialog">
|
||||
<class>EditAccountDialog</class>
|
||||
<widget class="QDialog" name="EditAccountDialog">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>400</width>
|
||||
<height>94</height>
|
||||
<height>128</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="windowTitle">
|
||||
@ -15,9 +15,16 @@
|
||||
</property>
|
||||
<layout class="QVBoxLayout" name="verticalLayout">
|
||||
<item>
|
||||
<widget class="QLabel" name="errorLabel">
|
||||
<widget class="QLabel" name="label">
|
||||
<property name="text">
|
||||
<string>Error message here...</string>
|
||||
<string>Message label placeholder.</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QLineEdit" name="userTextBox">
|
||||
<property name="placeholderText">
|
||||
<string>Email / Username</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
@ -26,6 +33,9 @@
|
||||
<property name="echoMode">
|
||||
<enum>QLineEdit::Password</enum>
|
||||
</property>
|
||||
<property name="placeholderText">
|
||||
<string>Password</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
@ -45,7 +55,7 @@
|
||||
<connection>
|
||||
<sender>buttonBox</sender>
|
||||
<signal>accepted()</signal>
|
||||
<receiver>PasswordDialog</receiver>
|
||||
<receiver>EditAccountDialog</receiver>
|
||||
<slot>accept()</slot>
|
||||
<hints>
|
||||
<hint type="sourcelabel">
|
||||
@ -61,7 +71,7 @@
|
||||
<connection>
|
||||
<sender>buttonBox</sender>
|
||||
<signal>rejected()</signal>
|
||||
<receiver>PasswordDialog</receiver>
|
||||
<receiver>EditAccountDialog</receiver>
|
||||
<slot>reject()</slot>
|
||||
<hints>
|
||||
<hint type="sourcelabel">
|
Loading…
Reference in New Issue
Block a user