From cdca53013990ac85967394529476712e6695bbf9 Mon Sep 17 00:00:00 2001 From: Andrew Date: Mon, 18 Nov 2013 12:05:35 -0600 Subject: Implement account list and account list dialog --- gui/dialogs/AccountListDialog.cpp | 90 +++++++++++++++++++++++++++++++++++++++ gui/dialogs/AccountListDialog.h | 60 ++++++++++++++++++++++++++ gui/dialogs/AccountListDialog.ui | 83 ++++++++++++++++++++++++++++++++++++ 3 files changed, 233 insertions(+) create mode 100644 gui/dialogs/AccountListDialog.cpp create mode 100644 gui/dialogs/AccountListDialog.h create mode 100644 gui/dialogs/AccountListDialog.ui (limited to 'gui') diff --git a/gui/dialogs/AccountListDialog.cpp b/gui/dialogs/AccountListDialog.cpp new file mode 100644 index 00000000..86d34de8 --- /dev/null +++ b/gui/dialogs/AccountListDialog.cpp @@ -0,0 +1,90 @@ +/* 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 "AccountListDialog.h" +#include "ui_AccountListDialog.h" + +#include + +#include + +#include +#include + +AccountListDialog::AccountListDialog(QWidget *parent) : + QDialog(parent), + ui(new Ui::AccountListDialog) +{ + ui->setupUi(this); + + ui->listView->setModel(&m_accounts); +} + +AccountListDialog::~AccountListDialog() +{ + delete ui; +} + + +void AccountListDialog::on_addAccountBtn_clicked() +{ + doLogin("Please log in to add your account."); +} + +void AccountListDialog::on_rmAccountBtn_clicked() +{ + // TODO +} + +void AccountListDialog::on_editAccountBtn_clicked() +{ + // TODO +} + +void AccountListDialog::on_closedBtnBox_rejected() +{ + close(); +} + +void AccountListDialog::doLogin(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); + loginDialog.exec(); + + if (loginDialog.result() == QDialog::Accepted) + { + QString username(loginDialog.getUsername()); + QString password(loginDialog.getPassword()); + + 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() +{ + // Add the authenticated account to the accounts list. + MojangAccountPtr account = m_authTask->getMojangAccount(); + m_accounts.addAccount(account); + //ui->listView->update(); +} + diff --git a/gui/dialogs/AccountListDialog.h b/gui/dialogs/AccountListDialog.h new file mode 100644 index 00000000..442834ef --- /dev/null +++ b/gui/dialogs/AccountListDialog.h @@ -0,0 +1,60 @@ +/* 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 + +#include "logic/lists/MojangAccountList.h" + +namespace Ui { +class AccountListDialog; +} + +class AuthenticateTask; + +class AccountListDialog : public QDialog +{ +Q_OBJECT +public: + explicit AccountListDialog(QWidget *parent = 0); + ~AccountListDialog(); + +public +slots: + void on_addAccountBtn_clicked(); + + void on_rmAccountBtn_clicked(); + + void on_editAccountBtn_clicked(); + + // This will be sent when the "close" button is clicked. + void on_closedBtnBox_rejected(); + +protected: + // Temporarily putting this here... + MojangAccountList m_accounts; + + AuthenticateTask* m_authTask; + +protected +slots: + void doLogin(const QString& errMsg=""); + void onLoginComplete(); + +private: + Ui::AccountListDialog *ui; +}; + diff --git a/gui/dialogs/AccountListDialog.ui b/gui/dialogs/AccountListDialog.ui new file mode 100644 index 00000000..034985a9 --- /dev/null +++ b/gui/dialogs/AccountListDialog.ui @@ -0,0 +1,83 @@ + + + AccountListDialog + + + + 0 + 0 + 400 + 300 + + + + Dialog + + + + + + <html><head/><body><p>Welcome! If you're new here, you can click the &quot;Add&quot; button to add your Mojang or Minecraft account.</p></body></html> + + + true + + + + + + + + + + + + + + &Add + + + + + + + &Edit + + + + + + + &Remove + + + + + + + Qt::Vertical + + + + 20 + 40 + + + + + + + + + + + + QDialogButtonBox::Close + + + + + + + + -- cgit v1.2.3 From a9a0b65358b3799746fa9c8e1aa879e0b59ef526 Mon Sep 17 00:00:00 2001 From: Andrew Date: Mon, 18 Nov 2013 12:58:03 -0600 Subject: Implement loading accounts from list. --- gui/dialogs/AccountListDialog.cpp | 7 +++++-- gui/dialogs/AccountListDialog.h | 5 +++-- 2 files changed, 8 insertions(+), 4 deletions(-) (limited to 'gui') diff --git a/gui/dialogs/AccountListDialog.cpp b/gui/dialogs/AccountListDialog.cpp index 86d34de8..5a73cb18 100644 --- a/gui/dialogs/AccountListDialog.cpp +++ b/gui/dialogs/AccountListDialog.cpp @@ -23,13 +23,16 @@ #include #include +#include + AccountListDialog::AccountListDialog(QWidget *parent) : QDialog(parent), ui(new Ui::AccountListDialog) { ui->setupUi(this); - ui->listView->setModel(&m_accounts); + m_accounts = MMC->accounts(); + ui->listView->setModel(m_accounts.get()); } AccountListDialog::~AccountListDialog() @@ -84,7 +87,7 @@ void AccountListDialog::onLoginComplete() { // Add the authenticated account to the accounts list. MojangAccountPtr account = m_authTask->getMojangAccount(); - m_accounts.addAccount(account); + m_accounts->addAccount(account); //ui->listView->update(); } diff --git a/gui/dialogs/AccountListDialog.h b/gui/dialogs/AccountListDialog.h index 442834ef..57c8b460 100644 --- a/gui/dialogs/AccountListDialog.h +++ b/gui/dialogs/AccountListDialog.h @@ -17,6 +17,8 @@ #include +#include + #include "logic/lists/MojangAccountList.h" namespace Ui { @@ -44,8 +46,7 @@ slots: void on_closedBtnBox_rejected(); protected: - // Temporarily putting this here... - MojangAccountList m_accounts; + std::shared_ptr m_accounts; AuthenticateTask* m_authTask; -- cgit v1.2.3 From 03652b01d2ec8a7c54fb39dd8ed660f0bbc2fa2a Mon Sep 17 00:00:00 2001 From: Andrew Date: Wed, 20 Nov 2013 12:20:35 -0600 Subject: Add a button to open the account list. Also fix the account list dialog's close button. --- gui/MainWindow.cpp | 7 +++++++ gui/MainWindow.h | 2 ++ gui/MainWindow.ui | 9 +++++++++ gui/dialogs/AccountListDialog.cpp | 2 +- gui/dialogs/AccountListDialog.h | 2 +- 5 files changed, 20 insertions(+), 2 deletions(-) (limited to 'gui') diff --git a/gui/MainWindow.cpp b/gui/MainWindow.cpp index 62ae195b..3bf248f9 100644 --- a/gui/MainWindow.cpp +++ b/gui/MainWindow.cpp @@ -57,6 +57,7 @@ #include "gui/dialogs/IconPickerDialog.h" #include "gui/dialogs/EditNotesDialog.h" #include "gui/dialogs/CopyInstanceDialog.h" +#include "gui/dialogs/AccountListDialog.h" #include "gui/ConsoleWindow.h" @@ -427,6 +428,12 @@ void MainWindow::on_actionSettings_triggered() proxymodel->sort(0); } +void MainWindow::on_actionManageAccounts_triggered() +{ + AccountListDialog dialog(this); + dialog.exec(); +} + void MainWindow::on_actionReportBug_triggered() { openWebPage(QUrl("http://multimc.myjetbrains.com/youtrack/dashboard#newissue=yes")); diff --git a/gui/MainWindow.h b/gui/MainWindow.h index 97aa0d9f..b89aab7c 100644 --- a/gui/MainWindow.h +++ b/gui/MainWindow.h @@ -79,6 +79,8 @@ slots: void on_actionSettings_triggered(); + void on_actionManageAccounts_triggered(); + void on_actionReportBug_triggered(); void on_actionNews_triggered(); diff --git a/gui/MainWindow.ui b/gui/MainWindow.ui index 6f70fc98..f76d4d4e 100644 --- a/gui/MainWindow.ui +++ b/gui/MainWindow.ui @@ -70,6 +70,7 @@ + @@ -465,6 +466,14 @@ Add a new instance. + + + Manage Accounts + + + Manage your Mojang or Minecraft accounts. + + diff --git a/gui/dialogs/AccountListDialog.cpp b/gui/dialogs/AccountListDialog.cpp index 5a73cb18..af074514 100644 --- a/gui/dialogs/AccountListDialog.cpp +++ b/gui/dialogs/AccountListDialog.cpp @@ -56,7 +56,7 @@ void AccountListDialog::on_editAccountBtn_clicked() // TODO } -void AccountListDialog::on_closedBtnBox_rejected() +void AccountListDialog::on_closeBtnBox_rejected() { close(); } diff --git a/gui/dialogs/AccountListDialog.h b/gui/dialogs/AccountListDialog.h index 57c8b460..99dee639 100644 --- a/gui/dialogs/AccountListDialog.h +++ b/gui/dialogs/AccountListDialog.h @@ -43,7 +43,7 @@ slots: void on_editAccountBtn_clicked(); // This will be sent when the "close" button is clicked. - void on_closedBtnBox_rejected(); + void on_closeBtnBox_rejected(); protected: std::shared_ptr m_accounts; -- cgit v1.2.3 From abf8408911c057d8aafe90790f5d2f5de0e1d97c Mon Sep 17 00:00:00 2001 From: Andrew Date: Wed, 20 Nov 2013 18:31:15 -0600 Subject: Nuke and pave the old login system Also, account list now saves profile lists. --- gui/MainWindow.cpp | 134 ++++++++++++++++++++++------------------------------- gui/MainWindow.h | 12 +++-- 2 files changed, 63 insertions(+), 83 deletions(-) (limited to 'gui') diff --git a/gui/MainWindow.cpp b/gui/MainWindow.cpp index 3bf248f9..734ed3b4 100644 --- a/gui/MainWindow.cpp +++ b/gui/MainWindow.cpp @@ -544,11 +544,7 @@ void MainWindow::instanceActivated(QModelIndex index) NagUtils::checkJVMArgs(inst->settings().get("JvmArgs").toString(), this); - bool autoLogin = inst->settings().get("AutoLogin").toBool(); - if (autoLogin) - doAutoLogin(); - else - doLogin(); + doLogin(); } void MainWindow::on_actionLaunchInstance_triggered() @@ -560,56 +556,34 @@ void MainWindow::on_actionLaunchInstance_triggered() } } -void MainWindow::doAutoLogin() +void MainWindow::doLogin(const QString &errorMsg) { if (!m_selectedInstance) return; - Keyring *k = Keyring::instance(); - QStringList accounts = k->getStoredAccounts("minecraft"); - - if (!accounts.isEmpty()) + // Find an account to use. + std::shared_ptr accounts = MMC->accounts(); + MojangAccountPtr account; + if (accounts->count() <= 0) { - QString username = accounts[0]; - QString password = k->getPassword("minecraft", username); - - if (!password.isEmpty()) - { - QLOG_INFO() << "Automatically logging in with stored account: " << username; - m_activeInst = m_selectedInstance; - doLogin(username, password); - } - else - { - QLOG_ERROR() << "Auto login set for account, but no password was found: " - << username; - doLogin(tr("Auto login attempted, but no password is stored.")); - } + // Tell the user they need to log in at least one account in order to play. + CustomMessageBox::selectable(this, tr("No Accounts"), + tr("In order to play Minecraft, you must have at least one Mojang or Minecraft account logged in to MultiMC. Please add an account."), + QMessageBox::Warning)->show(); } else { - QLOG_ERROR() << "Auto login set but no accounts were stored."; - doLogin(tr("Auto login attempted, but no accounts are stored.")); + // TODO: Allow user to select different accounts. + // For now, we'll just use the first one in the list until I get arround to implementing that. + account = accounts->at(0); } -} - -void MainWindow::doLogin(QString username, QString password) -{ - UserInfo uInfo{username, password}; - - ProgressDialog *tDialog = new ProgressDialog(this); - LoginTask *loginTask = new LoginTask(uInfo, tDialog); - connect(loginTask, SIGNAL(succeeded()), SLOT(onLoginComplete()), Qt::QueuedConnection); - connect(loginTask, SIGNAL(failed(QString)), SLOT(doLogin(QString)), Qt::QueuedConnection); - - tDialog->exec(loginTask); -} -void MainWindow::doLogin(const QString &errorMsg) -{ - if (!m_selectedInstance) - return; + // We'll need to validate the access token to make sure the account is still logged in. + // TODO: Do that ^ + + launchInstance(m_selectedInstance, account); + /* LoginDialog *loginDlg = new LoginDialog(this, errorMsg); if (!m_selectedInstance->lastLaunch()) loginDlg->forceOnline(); @@ -632,6 +606,41 @@ void MainWindow::doLogin(const QString &errorMsg) launchInstance(m_activeInst, m_activeLogin); } } + */ +} + +void MainWindow::launchInstance(BaseInstance *instance, MojangAccountPtr account) +{ + Q_ASSERT_X(instance != NULL, "launchInstance", "instance is NULL"); + + proc = instance->prepareForLaunch(account); + if (!proc) + return; + + // Prepare GUI: If it shall stay open disable the required parts + if (MMC->settings()->get("NoHide").toBool()) + { + ui->actionLaunchInstance->setEnabled(false); + } + else + { + this->hide(); + } + + console = new ConsoleWindow(proc); + + connect(proc, SIGNAL(log(QString, MessageLevel::Enum)), console, + SLOT(write(QString, MessageLevel::Enum))); + connect(proc, SIGNAL(ended(BaseInstance *)), this, SLOT(instanceEnded(BaseInstance *))); + + if (instance->settings().get("ShowConsole").toBool()) + { + console->show(); + } + + // I think this will work... + proc->setLogin(account->username(), account->accessToken()); + proc->launch(); } void MainWindow::onLoginComplete() @@ -644,7 +653,7 @@ void MainWindow::onLoginComplete() BaseUpdate *updateTask = m_activeInst->doUpdate(); if (!updateTask) { - launchInstance(m_activeInst, m_activeLogin); + //launchInstance(m_activeInst, m_activeLogin); } else { @@ -701,7 +710,7 @@ void MainWindow::onLoginComplete() void MainWindow::onGameUpdateComplete() { - launchInstance(m_activeInst, m_activeLogin); + //launchInstance(m_activeInst, m_activeLogin); } void MainWindow::onGameUpdateError(QString error) @@ -710,39 +719,6 @@ void MainWindow::onGameUpdateError(QString error) QMessageBox::Warning)->show(); } -void MainWindow::launchInstance(BaseInstance *instance, LoginResponse response) -{ - Q_ASSERT_X(instance != NULL, "launchInstance", "instance is NULL"); - - proc = instance->prepareForLaunch(response); - if (!proc) - return; - - // Prepare GUI: If it shall stay open disable the required parts - if (MMC->settings()->get("NoHide").toBool()) - { - ui->actionLaunchInstance->setEnabled(false); - } - else - { - this->hide(); - } - - console = new ConsoleWindow(proc); - - connect(proc, SIGNAL(log(QString, MessageLevel::Enum)), console, - SLOT(write(QString, MessageLevel::Enum))); - connect(proc, SIGNAL(ended(BaseInstance *)), this, SLOT(instanceEnded(BaseInstance *))); - - if (instance->settings().get("ShowConsole").toBool()) - { - console->show(); - } - - proc->setLogin(response.username, response.session_id); - proc->launch(); -} - void MainWindow::taskStart() { // Nothing to do here yet. diff --git a/gui/MainWindow.h b/gui/MainWindow.h index b89aab7c..c0fcc385 100644 --- a/gui/MainWindow.h +++ b/gui/MainWindow.h @@ -21,6 +21,8 @@ #include "logic/net/LoginTask.h" #include "logic/BaseInstance.h" +#include "logic/auth/MojangAccount.h" + class QToolButton; class LabeledToolButton; class QLabel; @@ -104,8 +106,12 @@ slots: void on_actionEditInstNotes_triggered(); void doLogin(const QString &errorMsg = ""); - void doLogin(QString username, QString password); - void doAutoLogin(); + + /*! + * Launches the given instance with the given account. + * This function assumes that the given account has a valid, usable access token. + */ + void launchInstance(BaseInstance* instance, MojangAccountPtr account); void onLoginComplete(); @@ -137,8 +143,6 @@ slots: void startTask(Task *task); - void launchInstance(BaseInstance *inst, LoginResponse response); - protected: bool eventFilter(QObject *obj, QEvent *ev); void setCatBackground(bool enabled); -- cgit v1.2.3 From a332e0d7b15a05d7a611624ef59c0604e74b5ae4 Mon Sep 17 00:00:00 2001 From: Andrew Date: Fri, 22 Nov 2013 09:53:27 -0600 Subject: Fix crashing when there are no accounts added The warning message actually displays now when there are no Mojang accounts to log in with, rather than simply crashing MultiMC. --- gui/MainWindow.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'gui') diff --git a/gui/MainWindow.cpp b/gui/MainWindow.cpp index 734ed3b4..3279661f 100644 --- a/gui/MainWindow.cpp +++ b/gui/MainWindow.cpp @@ -569,7 +569,8 @@ void MainWindow::doLogin(const QString &errorMsg) // Tell the user they need to log in at least one account in order to play. CustomMessageBox::selectable(this, tr("No Accounts"), tr("In order to play Minecraft, you must have at least one Mojang or Minecraft account logged in to MultiMC. Please add an account."), - QMessageBox::Warning)->show(); + QMessageBox::Information)->exec(); + return; } else { @@ -612,6 +613,7 @@ void MainWindow::doLogin(const QString &errorMsg) void MainWindow::launchInstance(BaseInstance *instance, MojangAccountPtr account) { Q_ASSERT_X(instance != NULL, "launchInstance", "instance is NULL"); + Q_ASSERT_X(account.get() != nullptr, "launchInstance", "account is NULL"); proc = instance->prepareForLaunch(account); if (!proc) -- cgit v1.2.3 From 69ac3e5a86d2a5602abc6e74904f29475b99a63c Mon Sep 17 00:00:00 2001 From: Andrew Date: Fri, 22 Nov 2013 10:12:16 -0600 Subject: Tweak the "no accounts" warning a bit. It now asks users if they want to open the manage accounts dialog to add their accounts. --- gui/MainWindow.cpp | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) (limited to 'gui') diff --git a/gui/MainWindow.cpp b/gui/MainWindow.cpp index 3279661f..9824d52f 100644 --- a/gui/MainWindow.cpp +++ b/gui/MainWindow.cpp @@ -567,9 +567,16 @@ void MainWindow::doLogin(const QString &errorMsg) if (accounts->count() <= 0) { // Tell the user they need to log in at least one account in order to play. - CustomMessageBox::selectable(this, tr("No Accounts"), - tr("In order to play Minecraft, you must have at least one Mojang or Minecraft account logged in to MultiMC. Please add an account."), - QMessageBox::Information)->exec(); + auto reply = CustomMessageBox::selectable(this, tr("No Accounts"), + tr("In order to play Minecraft, you must have at least one Mojang or Minecraft account logged in to MultiMC." + "Would you like to open the account manager to add an account now?"), + QMessageBox::Information, QMessageBox::Yes | QMessageBox::No)->exec(); + + if (reply == QMessageBox::Yes) + { + // Open the account manager. + on_actionManageAccounts_triggered(); + } return; } else -- cgit v1.2.3 From 23bc195b3c8558cb997789ca8772342612716993 Mon Sep 17 00:00:00 2001 From: Andrew Date: Fri, 22 Nov 2013 10:54:52 -0600 Subject: Implement removing accounts. --- gui/dialogs/AccountListDialog.cpp | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) (limited to 'gui') diff --git a/gui/dialogs/AccountListDialog.cpp b/gui/dialogs/AccountListDialog.cpp index af074514..838bef7f 100644 --- a/gui/dialogs/AccountListDialog.cpp +++ b/gui/dialogs/AccountListDialog.cpp @@ -16,6 +16,8 @@ #include "AccountListDialog.h" #include "ui_AccountListDialog.h" +#include + #include #include @@ -48,7 +50,12 @@ void AccountListDialog::on_addAccountBtn_clicked() void AccountListDialog::on_rmAccountBtn_clicked() { - // TODO + QModelIndexList selection = ui->listView->selectionModel()->selectedIndexes(); + if (selection.size() > 0) + { + QModelIndex selected = selection.first(); + m_accounts->removeAccount(selected); + } } void AccountListDialog::on_editAccountBtn_clicked() -- cgit v1.2.3 From 75e7932607bdd84d2867765eb6f07dcec95ee193 Mon Sep 17 00:00:00 2001 From: Andrew Date: Fri, 22 Nov 2013 12:47:39 -0600 Subject: Properly implement launching and downloading Also added a system to select an active account to log in with. --- gui/MainWindow.cpp | 147 +++++++++++++++----------------------- gui/MainWindow.h | 12 ++-- gui/dialogs/AccountListDialog.cpp | 12 ++++ gui/dialogs/AccountListDialog.h | 2 + gui/dialogs/AccountListDialog.ui | 12 +++- 5 files changed, 88 insertions(+), 97 deletions(-) (limited to 'gui') diff --git a/gui/MainWindow.cpp b/gui/MainWindow.cpp index 9824d52f..7ea67764 100644 --- a/gui/MainWindow.cpp +++ b/gui/MainWindow.cpp @@ -85,11 +85,6 @@ MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWi ui->setupUi(this); setWindowTitle(QString("MultiMC %1").arg(MMC->version().toString())); - // Set the selected instance to null - m_selectedInstance = nullptr; - // Set active instance to null. - m_activeInst = nullptr; - // OSX magic. setUnifiedTitleAndToolBarOnMac(true); @@ -563,7 +558,7 @@ void MainWindow::doLogin(const QString &errorMsg) // Find an account to use. std::shared_ptr accounts = MMC->accounts(); - MojangAccountPtr account; + MojangAccountPtr account = accounts->activeAccount(); if (accounts->count() <= 0) { // Tell the user they need to log in at least one account in order to play. @@ -577,107 +572,53 @@ void MainWindow::doLogin(const QString &errorMsg) // Open the account manager. on_actionManageAccounts_triggered(); } - return; } - else + else if (account.get() == nullptr) { - // TODO: Allow user to select different accounts. - // For now, we'll just use the first one in the list until I get arround to implementing that. - account = accounts->at(0); - } - - // We'll need to validate the access token to make sure the account is still logged in. - // TODO: Do that ^ - - launchInstance(m_selectedInstance, account); - - /* - LoginDialog *loginDlg = new LoginDialog(this, errorMsg); - if (!m_selectedInstance->lastLaunch()) - loginDlg->forceOnline(); + // Tell the user they need to log in at least one account in order to play. + auto reply = CustomMessageBox::selectable(this, tr("No Account Selected"), + tr("You don't have an account selected as an active account." + "Would you like to open the account manager to select one now?"), + QMessageBox::Information, QMessageBox::Yes | QMessageBox::No)->exec(); - loginDlg->exec(); - if (loginDlg->result() == QDialog::Accepted) - { - if (loginDlg->isOnline()) - { - m_activeInst = m_selectedInstance; - doLogin(loginDlg->getUsername(), loginDlg->getPassword()); - } - else + if (reply == QMessageBox::Yes) { - QString user = loginDlg->getUsername(); - if (user.length() == 0) - user = QString("Player"); - m_activeLogin = {user, QString("Offline"), user, QString()}; - m_activeInst = m_selectedInstance; - launchInstance(m_activeInst, m_activeLogin); + // Open the account manager. + on_actionManageAccounts_triggered(); } } - */ -} - -void MainWindow::launchInstance(BaseInstance *instance, MojangAccountPtr account) -{ - Q_ASSERT_X(instance != NULL, "launchInstance", "instance is NULL"); - Q_ASSERT_X(account.get() != nullptr, "launchInstance", "account is NULL"); - - proc = instance->prepareForLaunch(account); - if (!proc) - return; - - // Prepare GUI: If it shall stay open disable the required parts - if (MMC->settings()->get("NoHide").toBool()) - { - ui->actionLaunchInstance->setEnabled(false); - } else { - this->hide(); + // We'll need to validate the access token to make sure the account is still logged in. + // TODO: Do that ^ + + prepareLaunch(m_selectedInstance, account); } - - console = new ConsoleWindow(proc); - - connect(proc, SIGNAL(log(QString, MessageLevel::Enum)), console, - SLOT(write(QString, MessageLevel::Enum))); - connect(proc, SIGNAL(ended(BaseInstance *)), this, SLOT(instanceEnded(BaseInstance *))); - - if (instance->settings().get("ShowConsole").toBool()) - { - console->show(); - } - - // I think this will work... - proc->setLogin(account->username(), account->accessToken()); - proc->launch(); } -void MainWindow::onLoginComplete() +void MainWindow::prepareLaunch(BaseInstance* instance, MojangAccountPtr account) { - if (!m_activeInst) - return; - LoginTask *task = (LoginTask *)QObject::sender(); - m_activeLogin = task->getResult(); - - BaseUpdate *updateTask = m_activeInst->doUpdate(); + BaseUpdate *updateTask = instance->doUpdate(); if (!updateTask) { - //launchInstance(m_activeInst, m_activeLogin); + launchInstance(instance, account); } else { ProgressDialog tDialog(this); - connect(updateTask, SIGNAL(succeeded()), SLOT(onGameUpdateComplete())); + connect(updateTask, &BaseUpdate::succeeded, [this, instance, account] { launchInstance(instance, account); }); connect(updateTask, SIGNAL(failed(QString)), SLOT(onGameUpdateError(QString))); tDialog.exec(updateTask); delete updateTask; } - auto job = new NetJob("Player skin: " + m_activeLogin.player_name); + QString playerName = account->currentProfile()->name(); + + auto job = new NetJob("Player skin: " + playerName); - auto meta = MMC->metacache()->resolveEntry("skins", m_activeLogin.player_name + ".png"); + auto meta = MMC->metacache()->resolveEntry("skins", playerName + ".png"); auto action = CacheDownload::make( - QUrl("http://skins.minecraft.net/MinecraftSkins/" + m_activeLogin.player_name + ".png"), + QUrl("http://skins.minecraft.net/MinecraftSkins/" + playerName + ".png"), meta); job->addNetAction(action); meta->stale = true; @@ -702,12 +643,12 @@ void MainWindow::onLoginComplete() QJsonDocument jsonDoc = QJsonDocument::fromJson(data, &jsonError); QJsonObject root = jsonDoc.object(); QJsonObject mappings = root.value("mappings").toObject(); - QJsonArray usernames = mappings.value(m_activeLogin.username).toArray(); + QJsonArray usernames = mappings.value(account->username()).toArray(); - if (!usernames.contains(m_activeLogin.player_name)) + if (!usernames.contains(playerName)) { - usernames.prepend(m_activeLogin.player_name); - mappings[m_activeLogin.username] = usernames; + usernames.prepend(playerName); + mappings[account->username()] = usernames; root["mappings"] = mappings; jsonDoc.setObject(root); @@ -717,9 +658,39 @@ void MainWindow::onLoginComplete() } } -void MainWindow::onGameUpdateComplete() +void MainWindow::launchInstance(BaseInstance *instance, MojangAccountPtr account) { - //launchInstance(m_activeInst, m_activeLogin); + Q_ASSERT_X(instance != NULL, "launchInstance", "instance is NULL"); + Q_ASSERT_X(account.get() != nullptr, "launchInstance", "account is NULL"); + + proc = instance->prepareForLaunch(account); + if (!proc) + return; + + // Prepare GUI: If it shall stay open disable the required parts + if (MMC->settings()->get("NoHide").toBool()) + { + ui->actionLaunchInstance->setEnabled(false); + } + else + { + this->hide(); + } + + console = new ConsoleWindow(proc); + + connect(proc, SIGNAL(log(QString, MessageLevel::Enum)), console, + SLOT(write(QString, MessageLevel::Enum))); + connect(proc, SIGNAL(ended(BaseInstance *)), this, SLOT(instanceEnded(BaseInstance *))); + + if (instance->settings().get("ShowConsole").toBool()) + { + console->show(); + } + + // I think this will work... + proc->setLogin(account->username(), account->accessToken()); + proc->launch(); } void MainWindow::onGameUpdateError(QString error) diff --git a/gui/MainWindow.h b/gui/MainWindow.h index c0fcc385..f88905bf 100644 --- a/gui/MainWindow.h +++ b/gui/MainWindow.h @@ -113,9 +113,11 @@ slots: */ void launchInstance(BaseInstance* instance, MojangAccountPtr account); - void onLoginComplete(); + /*! + * Prepares the given instance for launch with the given account. + */ + void prepareLaunch(BaseInstance* instance, MojangAccountPtr account); - void onGameUpdateComplete(); void onGameUpdateError(QString error); void taskStart(); @@ -160,12 +162,6 @@ private: BaseInstance *m_selectedInstance; - // A pointer to the instance we are actively doing stuff with. - // This is set when the user launches an instance and is used to refer to that - // instance throughout the launching process. - BaseInstance *m_activeInst; - LoginResponse m_activeLogin; - Task *m_versionLoadTask; QLabel *m_statusLeft; diff --git a/gui/dialogs/AccountListDialog.cpp b/gui/dialogs/AccountListDialog.cpp index 838bef7f..c685c164 100644 --- a/gui/dialogs/AccountListDialog.cpp +++ b/gui/dialogs/AccountListDialog.cpp @@ -34,6 +34,7 @@ AccountListDialog::AccountListDialog(QWidget *parent) : ui->setupUi(this); m_accounts = MMC->accounts(); + // TODO: Make the "Active?" column show checkboxes or radio buttons. ui->listView->setModel(m_accounts.get()); } @@ -63,6 +64,17 @@ void AccountListDialog::on_editAccountBtn_clicked() // TODO } +void AccountListDialog::on_setActiveBtn_clicked() +{ + QModelIndexList selection = ui->listView->selectionModel()->selectedIndexes(); + if (selection.size() > 0) + { + QModelIndex selected = selection.first(); + MojangAccountPtr account = selected.data(MojangAccountList::PointerRole).value(); + m_accounts->setActiveAccount(account->username()); + } +} + void AccountListDialog::on_closeBtnBox_rejected() { close(); diff --git a/gui/dialogs/AccountListDialog.h b/gui/dialogs/AccountListDialog.h index 99dee639..17a50bec 100644 --- a/gui/dialogs/AccountListDialog.h +++ b/gui/dialogs/AccountListDialog.h @@ -42,6 +42,8 @@ slots: void on_editAccountBtn_clicked(); + void on_setActiveBtn_clicked(); + // This will be sent when the "close" button is clicked. void on_closeBtnBox_rejected(); diff --git a/gui/dialogs/AccountListDialog.ui b/gui/dialogs/AccountListDialog.ui index 034985a9..2872b368 100644 --- a/gui/dialogs/AccountListDialog.ui +++ b/gui/dialogs/AccountListDialog.ui @@ -27,7 +27,7 @@ - + @@ -65,6 +65,16 @@ + + + + <html><head/><body><p>Set the currently selected account as the active account. The active account is the account that is used to log in (unless it is overridden in an instance-specific setting).</p></body></html> + + + &Set Active + + + -- cgit v1.2.3