diff options
author | Andrew <forkk@forkk.net> | 2013-11-27 14:20:42 -0600 |
---|---|---|
committer | Andrew <forkk@forkk.net> | 2013-11-27 14:20:42 -0600 |
commit | d794a4d0bfac0341c15bd5273e8dc81fe82531ef (patch) | |
tree | 23cdea484bd18b7abee2ce0e6e61e5ff03cb1214 /gui/MainWindow.cpp | |
parent | 7e87278da9fa8afcaab53a00e2d670371a4ab52d (diff) | |
parent | 38732636d3c1f1563c2dceeae723fd51f7b5fda6 (diff) | |
download | MultiMC-d794a4d0bfac0341c15bd5273e8dc81fe82531ef.tar MultiMC-d794a4d0bfac0341c15bd5273e8dc81fe82531ef.tar.gz MultiMC-d794a4d0bfac0341c15bd5273e8dc81fe82531ef.tar.lz MultiMC-d794a4d0bfac0341c15bd5273e8dc81fe82531ef.tar.xz MultiMC-d794a4d0bfac0341c15bd5273e8dc81fe82531ef.zip |
Merge branch 'develop' of github.com:MultiMC/MultiMC5 into develop
Diffstat (limited to 'gui/MainWindow.cpp')
-rw-r--r-- | gui/MainWindow.cpp | 96 |
1 files changed, 51 insertions, 45 deletions
diff --git a/gui/MainWindow.cpp b/gui/MainWindow.cpp index 7a0b5849..3fdbed44 100644 --- a/gui/MainWindow.cpp +++ b/gui/MainWindow.cpp @@ -76,6 +76,7 @@ #include "logic/OneSixUpdate.h" #include "logic/JavaUtils.h" #include "logic/NagUtils.h" +#include "logic/SkinUtils.h" #include "logic/LegacyInstance.h" @@ -164,6 +165,41 @@ MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWi statusBar()->addPermanentWidget(m_statusLeft, 1); statusBar()->addPermanentWidget(m_statusRight, 0); + // Add "manage accounts" button, right align + + QWidget* spacer = new QWidget(); + spacer->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding); + ui->mainToolBar->addWidget(spacer); + + actionManageAccounts = new QToolButton(this); + actionManageAccounts->setToolTip(tr("Manage your Mojang or Minecraft accounts.")); + actionManageAccounts->setObjectName("actionManageAccounts"); + actionManageAccounts->setText(tr("Manage accounts")); + actionManageAccounts->setToolButtonStyle(Qt::ToolButtonTextBesideIcon); + actionManageAccounts->setLayoutDirection(Qt::RightToLeft); + + MojangAccountPtr account = MMC->accounts()->activeAccount(); + if(account != nullptr) + { + auto job = new NetJob("Startup 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()), SLOT(activeAccountChanged())); + job->start(); + } + + connect(actionManageAccounts, SIGNAL(clicked()), this, SLOT(on_actionManageAccounts_triggered())); + ui->mainToolBar->addWidget(actionManageAccounts); + // run the things that load and download other things... FIXME: this is NOT the place // FIXME: invisible actions in the background = NOPE. { @@ -196,6 +232,20 @@ MainWindow::~MainWindow() delete assets_downloader; } +void MainWindow::activeAccountChanged() +{ + MojangAccountPtr account = MMC->accounts()->activeAccount(); + + if(account != nullptr) + { + const AccountProfile *profile = account->currentProfile(); + if(profile != nullptr) + { + actionManageAccounts->setIcon(SkinUtils::getFaceFromCache(profile->name())); + } + } +} + bool MainWindow::eventFilter(QObject *obj, QEvent *ev) { if (obj == view) @@ -427,6 +477,7 @@ void MainWindow::on_actionSettings_triggered() void MainWindow::on_actionManageAccounts_triggered() { AccountListDialog dialog(this); + connect(&dialog, SIGNAL(activeAccountChanged()), SLOT(activeAccountChanged())); dialog.exec(); } @@ -612,51 +663,6 @@ void MainWindow::prepareLaunch(BaseInstance* instance, MojangAccountPtr account) tDialog.exec(updateTask); delete updateTask; } - - QString playerName = account->currentProfile()->name(); - - auto job = new NetJob("Player skin: " + playerName); - - auto meta = MMC->metacache()->resolveEntry("skins", playerName + ".png"); - auto action = CacheDownload::make( - QUrl("http://skins.minecraft.net/MinecraftSkins/" + playerName + ".png"), - meta); - job->addNetAction(action); - meta->stale = true; - - job->start(); - auto filename = MMC->metacache()->resolveEntry("skins", "skins.json")->getFullPath(); - QFile listFile(filename); - - // Add skin mapping - QByteArray data; - { - if (!listFile.open(QIODevice::ReadWrite)) - { - QLOG_ERROR() << "Failed to open/make skins list JSON"; - return; - } - - data = listFile.readAll(); - } - - QJsonParseError jsonError; - QJsonDocument jsonDoc = QJsonDocument::fromJson(data, &jsonError); - QJsonObject root = jsonDoc.object(); - QJsonObject mappings = root.value("mappings").toObject(); - QJsonArray usernames = mappings.value(account->username()).toArray(); - - if (!usernames.contains(playerName)) - { - usernames.prepend(playerName); - mappings[account->username()] = usernames; - root["mappings"] = mappings; - jsonDoc.setObject(root); - - // QJson hack - shouldn't have to clear the file every time a save happens - listFile.resize(0); - listFile.write(jsonDoc.toJson()); - } } void MainWindow::launchInstance(BaseInstance *instance, MojangAccountPtr account) |