aboutsummaryrefslogtreecommitdiff
path: root/launcher/MainWindow.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'launcher/MainWindow.cpp')
-rw-r--r--launcher/MainWindow.cpp158
1 files changed, 66 insertions, 92 deletions
diff --git a/launcher/MainWindow.cpp b/launcher/MainWindow.cpp
index 9225193e..182b22e9 100644
--- a/launcher/MainWindow.cpp
+++ b/launcher/MainWindow.cpp
@@ -54,7 +54,7 @@
#include <java/JavaUtils.h>
#include <java/JavaInstallList.h>
#include <launch/LaunchTask.h>
-#include <minecraft/auth/MojangAccountList.h>
+#include <minecraft/auth/AccountList.h>
#include <SkinUtils.h>
#include <BuildConfig.h>
#include <net/NetJob.h>
@@ -90,6 +90,20 @@
#include "KonamiCode.h"
#include <InstanceCopyTask.h>
+namespace {
+QString profileInUseFilter(const QString & profile, bool used)
+{
+ if(used)
+ {
+ return QObject::tr("%1 (in use)").arg(profile);
+ }
+ else
+ {
+ return profile;
+ }
+}
+}
+
// WHY: to hold the pre-translation strings together with the T pointer, so it can be retranslated without a lot of ugly code
template <typename T>
class Translated
@@ -753,49 +767,27 @@ MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new MainWindow
// Update the menu when the active account changes.
// Shouldn't have to use lambdas here like this, but if I don't, the compiler throws a fit.
// Template hell sucks...
- connect(MMC->accounts().get(), &MojangAccountList::activeAccountChanged, [this]
- {
- activeAccountChanged();
- });
- connect(MMC->accounts().get(), &MojangAccountList::listChanged, [this]
- {
- repopulateAccountsMenu();
- });
+ connect(
+ MMC->accounts().get(),
+ &AccountList::activeAccountChanged,
+ [this] {
+ activeAccountChanged();
+ }
+ );
+ connect(
+ MMC->accounts().get(),
+ &AccountList::listChanged,
+ [this]
+ {
+ repopulateAccountsMenu();
+ }
+ );
// Show initial account
activeAccountChanged();
- auto accounts = MMC->accounts();
-
- QList<Net::Download::Ptr> skin_dls;
- for (int i = 0; i < accounts->count(); i++)
- {
- auto account = accounts->at(i);
- if (!account)
- {
- qWarning() << "Null account at index" << i;
- continue;
- }
- for (auto profile : account->profiles())
- {
- auto meta = Env::getInstance().metacache()->resolveEntry("skins", profile.id + ".png");
- auto action = Net::Download::makeCached(QUrl(BuildConfig.SKINS_BASE + profile.id + ".png"), meta);
- skin_dls.append(action);
- meta->setStale(true);
- }
- }
- if (!skin_dls.isEmpty())
- {
- auto job = new NetJob("Startup player skins download");
- connect(job, &NetJob::succeeded, this, &MainWindow::skinJobFinished);
- connect(job, &NetJob::failed, this, &MainWindow::skinJobFinished);
- for (auto action : skin_dls)
- {
- job->addNetAction(action);
- }
- skin_download_job.reset(job);
- job->start();
- }
+ // TODO: refresh accounts here?
+ // auto accounts = MMC->accounts();
// load the news
{
@@ -844,7 +836,15 @@ MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new MainWindow
void MainWindow::retranslateUi()
{
- accountMenuButton->setText(tr("Profiles"));
+ std::shared_ptr<AccountList> accounts = MMC->accounts();
+ MinecraftAccountPtr active_account = accounts->activeAccount();
+ if(active_account) {
+ auto profileLabel = profileInUseFilter(active_account->profileName(), active_account->isInUse());
+ accountMenuButton->setText(profileLabel);
+ }
+ else {
+ accountMenuButton->setText(tr("Profiles"));
+ }
if (m_selectedInstance) {
m_statusLeft->setText(m_selectedInstance->getStatusbarDescription());
@@ -872,12 +872,6 @@ void MainWindow::konamiTriggered()
qDebug() << "Super Secret Mode ACTIVATED!";
}
-void MainWindow::skinJobFinished()
-{
- activeAccountChanged();
- skin_download_job.reset();
-}
-
void MainWindow::showInstanceContextMenu(const QPoint &pos)
{
QList<QAction *> actions;
@@ -1018,34 +1012,21 @@ void MainWindow::updateToolsMenu()
ui->actionLaunchInstanceOffline->setMenu(launchOfflineMenu);
}
-QString profileInUseFilter(const QString & profile, bool used)
-{
- if(used)
- {
- return profile + QObject::tr(" (in use)");
- }
- else
- {
- return profile;
- }
-}
-
void MainWindow::repopulateAccountsMenu()
{
accountMenu->clear();
- std::shared_ptr<MojangAccountList> accounts = MMC->accounts();
- MojangAccountPtr active_account = accounts->activeAccount();
+ std::shared_ptr<AccountList> accounts = MMC->accounts();
+ MinecraftAccountPtr active_account = accounts->activeAccount();
- QString active_username = "";
+ QString active_profileId = "";
if (active_account != nullptr)
{
- active_username = active_account->username();
- const AccountProfile *profile = active_account->currentProfile();
+ active_profileId = active_account->profileId();
// this can be called before accountMenuButton exists
- if (profile != nullptr && accountMenuButton)
+ if (accountMenuButton)
{
- auto profileLabel = profileInUseFilter(profile->name, active_account->isInUse());
+ auto profileLabel = profileInUseFilter(active_account->profileName(), active_account->isInUse());
accountMenuButton->setText(profileLabel);
}
}
@@ -1061,22 +1042,19 @@ void MainWindow::repopulateAccountsMenu()
// TODO: Nicer way to iterate?
for (int i = 0; i < accounts->count(); i++)
{
- MojangAccountPtr account = accounts->at(i);
- for (auto profile : account->profiles())
+ MinecraftAccountPtr account = accounts->at(i);
+ auto profileLabel = profileInUseFilter(account->profileName(), account->isInUse());
+ QAction *action = new QAction(profileLabel, this);
+ action->setData(account->profileId());
+ action->setCheckable(true);
+ if (active_profileId == account->profileId())
{
- auto profileLabel = profileInUseFilter(profile.name, account->isInUse());
- QAction *action = new QAction(profileLabel, this);
- action->setData(account->username());
- action->setCheckable(true);
- if (active_username == account->username())
- {
- action->setChecked(true);
- }
-
- action->setIcon(SkinUtils::getFaceFromCache(profile.id));
- accountMenu->addAction(action);
- connect(action, SIGNAL(triggered(bool)), SLOT(changeActiveAccount()));
+ action->setChecked(true);
}
+
+ action->setIcon(account->getFace());
+ accountMenu->addAction(action);
+ connect(action, SIGNAL(triggered(bool)), SLOT(changeActiveAccount()));
}
}
@@ -1086,8 +1064,7 @@ void MainWindow::repopulateAccountsMenu()
action->setCheckable(true);
action->setIcon(MMC->getThemedIcon("noaccount"));
action->setData("");
- if (active_username.isEmpty())
- {
+ if (active_profileId.isEmpty()) {
action->setChecked(true);
}
@@ -1134,18 +1111,15 @@ void MainWindow::activeAccountChanged()
{
repopulateAccountsMenu();
- MojangAccountPtr account = MMC->accounts()->activeAccount();
+ MinecraftAccountPtr account = MMC->accounts()->activeAccount();
- if (account != nullptr && account->username() != "")
+ // FIXME: this needs adjustment for MSA
+ if (account != nullptr && account->profileName() != "")
{
- const AccountProfile *profile = account->currentProfile();
- if (profile != nullptr)
- {
- auto profileLabel = profileInUseFilter(profile->name, account->isInUse());
- accountMenuButton->setIcon(SkinUtils::getFaceFromCache(profile->id));
- accountMenuButton->setText(profileLabel);
- return;
- }
+ auto profileLabel = profileInUseFilter(account->profileName(), account->isInUse());
+ accountMenuButton->setText(profileLabel);
+ accountMenuButton->setIcon(account->getFace());
+ return;
}
// Set the icon to the "no account" icon.