summaryrefslogtreecommitdiffstats
path: root/gui
diff options
context:
space:
mode:
authorSky <git@bunnies.cc>2013-11-27 16:56:15 +0000
committerSky <git@bunnies.cc>2013-11-27 16:56:15 +0000
commit7d7579d7f04f88013d7e4d064b2becec28cced61 (patch)
tree9f9181e08b1652a4a84c00ba140ad33462890f8b /gui
parent7024e5a83e543a5e59e0c30ab72fe6ee5c5522f0 (diff)
downloadMultiMC-7d7579d7f04f88013d7e4d064b2becec28cced61.tar
MultiMC-7d7579d7f04f88013d7e4d064b2becec28cced61.tar.gz
MultiMC-7d7579d7f04f88013d7e4d064b2becec28cced61.tar.lz
MultiMC-7d7579d7f04f88013d7e4d064b2becec28cced61.tar.xz
MultiMC-7d7579d7f04f88013d7e4d064b2becec28cced61.zip
Move "manage accounts" to right, use player skin when available
Diffstat (limited to 'gui')
-rw-r--r--gui/MainWindow.cpp31
-rw-r--r--gui/MainWindow.h4
-rw-r--r--gui/MainWindow.ui1
-rw-r--r--gui/dialogs/AccountListDialog.cpp6
-rw-r--r--gui/dialogs/AccountListDialog.h3
-rw-r--r--gui/dialogs/LoginDialog.cpp44
6 files changed, 47 insertions, 42 deletions
diff --git a/gui/MainWindow.cpp b/gui/MainWindow.cpp
index 7a0b5849..dc7a1200 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,24 @@ 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);
+
+ activeAccountChanged();
+
+ 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 +215,16 @@ MainWindow::~MainWindow()
delete assets_downloader;
}
+void MainWindow::activeAccountChanged()
+{
+ MojangAccountPtr account = MMC->accounts()->activeAccount();
+
+ if(account != nullptr)
+ {
+ actionManageAccounts->setIcon(SkinUtils::getFaceFromCache(account->username()));
+ }
+}
+
bool MainWindow::eventFilter(QObject *obj, QEvent *ev)
{
if (obj == view)
@@ -427,6 +456,7 @@ void MainWindow::on_actionSettings_triggered()
void MainWindow::on_actionManageAccounts_triggered()
{
AccountListDialog dialog(this);
+ connect(&dialog, SIGNAL(activeAccountChanged()), SLOT(activeAccountChanged()));
dialog.exec();
}
@@ -624,6 +654,7 @@ void MainWindow::prepareLaunch(BaseInstance* instance, MojangAccountPtr account)
job->addNetAction(action);
meta->stale = true;
+ connect(job, SIGNAL(succeeded()), SLOT(activeAccountChanged()));
job->start();
auto filename = MMC->metacache()->resolveEntry("skins", "skins.json")->getFullPath();
QFile listFile(filename);
diff --git a/gui/MainWindow.h b/gui/MainWindow.h
index 3b8d4668..4e20d7cb 100644
--- a/gui/MainWindow.h
+++ b/gui/MainWindow.h
@@ -146,6 +146,8 @@ slots:
void startTask(Task *task);
+ void activeAccountChanged();
+
protected:
bool eventFilter(QObject *obj, QEvent *ev);
void setCatBackground(bool enabled);
@@ -167,4 +169,6 @@ private:
QLabel *m_statusLeft;
QLabel *m_statusRight;
+
+ QToolButton *actionManageAccounts;
};
diff --git a/gui/MainWindow.ui b/gui/MainWindow.ui
index f76d4d4e..0537d0e5 100644
--- a/gui/MainWindow.ui
+++ b/gui/MainWindow.ui
@@ -70,7 +70,6 @@
<addaction name="separator"/>
<addaction name="actionCheckUpdate"/>
<addaction name="actionSettings"/>
- <addaction name="actionManageAccounts"/>
<addaction name="separator"/>
<addaction name="actionReportBug"/>
<addaction name="actionNews"/>
diff --git a/gui/dialogs/AccountListDialog.cpp b/gui/dialogs/AccountListDialog.cpp
index c685c164..81b39e4c 100644
--- a/gui/dialogs/AccountListDialog.cpp
+++ b/gui/dialogs/AccountListDialog.cpp
@@ -56,6 +56,8 @@ void AccountListDialog::on_rmAccountBtn_clicked()
{
QModelIndex selected = selection.first();
m_accounts->removeAccount(selected);
+
+ emit activeAccountChanged();
}
}
@@ -72,7 +74,9 @@ void AccountListDialog::on_setActiveBtn_clicked()
QModelIndex selected = selection.first();
MojangAccountPtr account = selected.data(MojangAccountList::PointerRole).value<MojangAccountPtr>();
m_accounts->setActiveAccount(account->username());
- }
+
+ emit activeAccountChanged();
+ }
}
void AccountListDialog::on_closeBtnBox_rejected()
diff --git a/gui/dialogs/AccountListDialog.h b/gui/dialogs/AccountListDialog.h
index 17a50bec..52666e3b 100644
--- a/gui/dialogs/AccountListDialog.h
+++ b/gui/dialogs/AccountListDialog.h
@@ -47,6 +47,9 @@ slots:
// This will be sent when the "close" button is clicked.
void on_closeBtnBox_rejected();
+signals:
+ void activeAccountChanged();
+
protected:
std::shared_ptr<MojangAccountList> m_accounts;
diff --git a/gui/dialogs/LoginDialog.cpp b/gui/dialogs/LoginDialog.cpp
index 19c6437d..28bbb1ee 100644
--- a/gui/dialogs/LoginDialog.cpp
+++ b/gui/dialogs/LoginDialog.cpp
@@ -18,6 +18,7 @@
#include "keyring.h"
#include "gui/Platform.h"
#include "MultiMC.h"
+#include "logic/SkinUtils.h"
#include <QFile>
#include <QJsonObject>
@@ -168,47 +169,10 @@ void LoginDialog::userTextChanged(const QString &user)
ui->rememberPasswordCheckbox->setChecked(!passwd.isEmpty());
ui->passwordTextBox->setText(passwd);
- QByteArray data;
- {
- auto filename =
- MMC->metacache()->resolveEntry("skins", "skins.json")->getFullPath();
- QFile listFile(filename);
- if (!listFile.open(QIODevice::ReadOnly))
- return;
- data = listFile.readAll();
- }
-
- QJsonParseError jsonError;
- QJsonDocument jsonDoc = QJsonDocument::fromJson(data, &jsonError);
- QJsonObject root = jsonDoc.object();
- QJsonObject mappings = root.value("mappings").toObject();
+ QPixmap face = SkinUtils::getFaceFromCache(user);
+ gotFace = !face.isNull();
- if (!mappings[user].isUndefined())
- {
- QJsonArray usernames = mappings.value(user).toArray();
- if (!usernames.isEmpty())
- {
- QString mapped_username = usernames[0].toString();
-
- if (!mapped_username.isEmpty())
- {
- QFile fskin(MMC->metacache()
- ->resolveEntry("skins", mapped_username + ".png")
- ->getFullPath());
- if (fskin.exists())
- {
- QPixmap skin(MMC->metacache()
- ->resolveEntry("skins", mapped_username + ".png")
- ->getFullPath());
- QPixmap face =
- skin.copy(8, 8, 8, 8).scaled(48, 48, Qt::KeepAspectRatio);
-
- ui->lblFace->setPixmap(face);
- gotFace = true;
- }
- }
- }
- }
+ if(gotFace) ui->lblFace->setPixmap(face);
}
ui->lblFace->setVisible(gotFace);