diff options
author | Sky <git@bunnies.cc> | 2013-10-21 21:25:50 +0100 |
---|---|---|
committer | Sky <git@bunnies.cc> | 2013-10-21 21:25:50 +0100 |
commit | 003fedde018c399a148b1e5caae34350d720024e (patch) | |
tree | 53b932e45df59f423187399fee79beae39ce909c /gui | |
parent | 11813a0621dd7b500c2d7966a2671c0ab93be692 (diff) | |
download | MultiMC-003fedde018c399a148b1e5caae34350d720024e.tar MultiMC-003fedde018c399a148b1e5caae34350d720024e.tar.gz MultiMC-003fedde018c399a148b1e5caae34350d720024e.tar.lz MultiMC-003fedde018c399a148b1e5caae34350d720024e.tar.xz MultiMC-003fedde018c399a148b1e5caae34350d720024e.zip |
Implement auto login
Diffstat (limited to 'gui')
-rw-r--r-- | gui/mainwindow.cpp | 78 | ||||
-rw-r--r-- | gui/mainwindow.h | 2 |
2 files changed, 61 insertions, 19 deletions
diff --git a/gui/mainwindow.cpp b/gui/mainwindow.cpp index ab718f98..d602efcf 100644 --- a/gui/mainwindow.cpp +++ b/gui/mainwindow.cpp @@ -20,6 +20,7 @@ #include "mainwindow.h" #include "ui_mainwindow.h" +#include "keyring.h" #include <QMenu> #include <QMessageBox> @@ -235,15 +236,6 @@ void MainWindow::setCatBackground(bool enabled) } } -void MainWindow::instanceActivated(QModelIndex index) -{ - if (!index.isValid()) - return; - BaseInstance *inst = - (BaseInstance *)index.data(InstanceList::InstancePointerRole).value<void *>(); - doLogin(); -} - void MainWindow::on_actionAddInstance_triggered() { if (!MMC->minecraftlist()->isLoaded() && m_versionLoadTask && @@ -453,14 +445,70 @@ void MainWindow::on_instanceView_customContextMenuRequested(const QPoint &pos) instContextMenu->exec(view->mapToGlobal(pos)); } */ +void MainWindow::instanceActivated(QModelIndex index) +{ + if (!index.isValid()) + return; + BaseInstance *inst = + (BaseInstance *)index.data(InstanceList::InstancePointerRole).value<void *>(); + + bool autoLogin = MMC->settings()->get("AutoLogin").toBool(); + if(autoLogin) doAutoLogin(); + else doLogin(); +} + void MainWindow::on_actionLaunchInstance_triggered() { if (m_selectedInstance) { - doLogin(); + bool autoLogin = MMC->settings()->get("AutoLogin").toBool(); + if(autoLogin) doAutoLogin(); + else doLogin(); } } +void MainWindow::doAutoLogin() +{ + Keyring * k = Keyring::instance(); + QStringList accounts = k->getStoredAccounts("minecraft"); + + if(!accounts.isEmpty()) + { + QString username = accounts[0]; + QString password = k->getPassword("minecraft", username); + + if(!password.isEmpty()) + { + QLOG_INFO() << "Automatically logging in with stored account: " << username; + 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.")); + } + } + else + { + QLOG_ERROR() << "Auto login set but no accounts were stored."; + doLogin(tr("Auto login attempted, but no accounts are stored.")); + } +} + +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) @@ -475,16 +523,8 @@ void MainWindow::doLogin(const QString &errorMsg) { if (loginDlg->isOnline()) { - UserInfo uInfo{loginDlg->getUsername(), loginDlg->getPassword()}; - - 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); m_activeInst = m_selectedInstance; - tDialog->exec(loginTask); + doLogin(loginDlg->getUsername(), loginDlg->getPassword()); } else { diff --git a/gui/mainwindow.h b/gui/mainwindow.h index dbf7c4c3..4490d474 100644 --- a/gui/mainwindow.h +++ b/gui/mainwindow.h @@ -99,6 +99,8 @@ private slots: void on_actionEditInstNotes_triggered(); void doLogin(const QString &errorMsg = ""); + void doLogin(QString username, QString password); + void doAutoLogin(); void onLoginComplete(); |