summaryrefslogtreecommitdiffstats
path: root/gui
diff options
context:
space:
mode:
authorAndrew <forkk@forkk.net>2013-11-20 18:31:15 -0600
committerAndrew <forkk@forkk.net>2013-11-20 18:31:15 -0600
commitabf8408911c057d8aafe90790f5d2f5de0e1d97c (patch)
treeb6b77a485702c0a7ac45b5b96d6b8b0f41c14af7 /gui
parent03652b01d2ec8a7c54fb39dd8ed660f0bbc2fa2a (diff)
downloadMultiMC-abf8408911c057d8aafe90790f5d2f5de0e1d97c.tar
MultiMC-abf8408911c057d8aafe90790f5d2f5de0e1d97c.tar.gz
MultiMC-abf8408911c057d8aafe90790f5d2f5de0e1d97c.tar.lz
MultiMC-abf8408911c057d8aafe90790f5d2f5de0e1d97c.tar.xz
MultiMC-abf8408911c057d8aafe90790f5d2f5de0e1d97c.zip
Nuke and pave the old login system
Also, account list now saves profile lists.
Diffstat (limited to 'gui')
-rw-r--r--gui/MainWindow.cpp134
-rw-r--r--gui/MainWindow.h12
2 files changed, 63 insertions, 83 deletions
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<MojangAccountList> 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);