From f3a9dde52e99385eba01c9356ed8ef9548833e34 Mon Sep 17 00:00:00 2001 From: Andrew Date: Thu, 28 Nov 2013 21:40:40 -0600 Subject: 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. --- gui/MainWindow.cpp | 5 +-- gui/dialogs/AccountListDialog.cpp | 91 ++++++++++++++++----------------------- gui/dialogs/AccountListDialog.h | 12 ++---- gui/dialogs/AccountListDialog.ui | 7 --- gui/dialogs/EditAccountDialog.cpp | 46 ++++++++++++++++++++ gui/dialogs/EditAccountDialog.h | 56 ++++++++++++++++++++++++ gui/dialogs/EditAccountDialog.ui | 88 +++++++++++++++++++++++++++++++++++++ gui/dialogs/PasswordDialog.cpp | 38 ---------------- gui/dialogs/PasswordDialog.h | 40 ----------------- gui/dialogs/PasswordDialog.ui | 78 --------------------------------- 10 files changed, 233 insertions(+), 228 deletions(-) create mode 100644 gui/dialogs/EditAccountDialog.cpp create mode 100644 gui/dialogs/EditAccountDialog.h create mode 100644 gui/dialogs/EditAccountDialog.ui delete mode 100644 gui/dialogs/PasswordDialog.cpp delete mode 100644 gui/dialogs/PasswordDialog.h delete mode 100644 gui/dialogs/PasswordDialog.ui (limited to 'gui') diff --git a/gui/MainWindow.cpp b/gui/MainWindow.cpp index 72e754ee..65d9f4cc 100644 --- a/gui/MainWindow.cpp +++ b/gui/MainWindow.cpp @@ -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. 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 #include -#include +#include #include #include @@ -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(); 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(); -} - diff --git a/gui/dialogs/AccountListDialog.h b/gui/dialogs/AccountListDialog.h index 63720f58..634d944a 100644 --- a/gui/dialogs/AccountListDialog.h +++ b/gui/dialogs/AccountListDialog.h @@ -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 m_accounts; - AuthenticateTask* m_authTask; - protected slots: - void doLogin(const QString& errMsg=""); - void onLoginComplete(); + void addAccount(const QString& errMsg=""); private: Ui::AccountListDialog *ui; diff --git a/gui/dialogs/AccountListDialog.ui b/gui/dialogs/AccountListDialog.ui index b4baf3f9..571f9be7 100644 --- a/gui/dialogs/AccountListDialog.ui +++ b/gui/dialogs/AccountListDialog.ui @@ -38,13 +38,6 @@ - - - - &Edit - - - diff --git a/gui/dialogs/EditAccountDialog.cpp b/gui/dialogs/EditAccountDialog.cpp new file mode 100644 index 00000000..d28336f7 --- /dev/null +++ b/gui/dialogs/EditAccountDialog.cpp @@ -0,0 +1,46 @@ +/* Copyright 2013 MultiMC Contributors + * + * 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 "EditAccountDialog.h" +#include "ui_EditAccountDialog.h" + +EditAccountDialog::EditAccountDialog(const QString& text, QWidget *parent, int flags) : + QDialog(parent), + ui(new Ui::EditAccountDialog) +{ + ui->setupUi(this); + + ui->label->setText(text); + ui->label->setVisible(!text.isEmpty()); + + ui->userTextBox->setVisible(flags & UsernameField); + ui->passTextBox->setVisible(flags & PasswordField); +} + +EditAccountDialog::~EditAccountDialog() +{ + delete ui; +} + +QString EditAccountDialog::username() const +{ + return ui->userTextBox->text(); +} + +QString EditAccountDialog::password() const +{ + return ui->passTextBox->text(); +} + diff --git a/gui/dialogs/EditAccountDialog.h b/gui/dialogs/EditAccountDialog.h new file mode 100644 index 00000000..847c3be5 --- /dev/null +++ b/gui/dialogs/EditAccountDialog.h @@ -0,0 +1,56 @@ +/* Copyright 2013 MultiMC Contributors + * + * 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 + +namespace Ui { +class EditAccountDialog; +} + +class EditAccountDialog : public QDialog +{ +Q_OBJECT + +public: + 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::EditAccountDialog *ui; +}; + diff --git a/gui/dialogs/EditAccountDialog.ui b/gui/dialogs/EditAccountDialog.ui new file mode 100644 index 00000000..15d371ee --- /dev/null +++ b/gui/dialogs/EditAccountDialog.ui @@ -0,0 +1,88 @@ + + + EditAccountDialog + + + + 0 + 0 + 400 + 128 + + + + Dialog + + + + + + Message label placeholder. + + + + + + + Email / Username + + + + + + + QLineEdit::Password + + + Password + + + + + + + Qt::Horizontal + + + QDialogButtonBox::Cancel|QDialogButtonBox::Ok + + + + + + + + + buttonBox + accepted() + EditAccountDialog + accept() + + + 248 + 254 + + + 157 + 274 + + + + + buttonBox + rejected() + EditAccountDialog + reject() + + + 316 + 260 + + + 286 + 274 + + + + + diff --git a/gui/dialogs/PasswordDialog.cpp b/gui/dialogs/PasswordDialog.cpp deleted file mode 100644 index c67fc6a2..00000000 --- a/gui/dialogs/PasswordDialog.cpp +++ /dev/null @@ -1,38 +0,0 @@ -/* Copyright 2013 MultiMC Contributors - * - * 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 "PasswordDialog.h" -#include "ui_PasswordDialog.h" - -PasswordDialog::PasswordDialog(const QString& errorMsg, QWidget *parent) : - QDialog(parent), - ui(new Ui::PasswordDialog) -{ - ui->setupUi(this); - - ui->errorLabel->setText(errorMsg); - ui->errorLabel->setVisible(!errorMsg.isEmpty()); -} - -PasswordDialog::~PasswordDialog() -{ - delete ui; -} - -QString PasswordDialog::password() const -{ - return ui->passTextBox->text(); -} - diff --git a/gui/dialogs/PasswordDialog.h b/gui/dialogs/PasswordDialog.h deleted file mode 100644 index 0919e6e4..00000000 --- a/gui/dialogs/PasswordDialog.h +++ /dev/null @@ -1,40 +0,0 @@ -/* Copyright 2013 MultiMC Contributors - * - * 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 - -namespace Ui { -class PasswordDialog; -} - -class PasswordDialog : public QDialog -{ - Q_OBJECT - -public: - explicit PasswordDialog(const QString& errorMsg="", QWidget *parent = 0); - ~PasswordDialog(); - - /*! - * Gets the text entered in the dialog's password field. - */ - QString password() const; - -private: - Ui::PasswordDialog *ui; -}; - diff --git a/gui/dialogs/PasswordDialog.ui b/gui/dialogs/PasswordDialog.ui deleted file mode 100644 index 6c70b033..00000000 --- a/gui/dialogs/PasswordDialog.ui +++ /dev/null @@ -1,78 +0,0 @@ - - - PasswordDialog - - - - 0 - 0 - 400 - 94 - - - - Dialog - - - - - - Error message here... - - - - - - - QLineEdit::Password - - - - - - - Qt::Horizontal - - - QDialogButtonBox::Cancel|QDialogButtonBox::Ok - - - - - - - - - buttonBox - accepted() - PasswordDialog - accept() - - - 248 - 254 - - - 157 - 274 - - - - - buttonBox - rejected() - PasswordDialog - reject() - - - 316 - 260 - - - 286 - 274 - - - - - -- cgit v1.2.3