summaryrefslogtreecommitdiffstats
path: root/gui
diff options
context:
space:
mode:
Diffstat (limited to 'gui')
-rw-r--r--gui/MainWindow.cpp145
-rw-r--r--gui/MainWindow.h8
-rw-r--r--gui/dialogs/AccountListDialog.cpp3
3 files changed, 131 insertions, 25 deletions
diff --git a/gui/MainWindow.cpp b/gui/MainWindow.cpp
index e817d50d..a9f29d86 100644
--- a/gui/MainWindow.cpp
+++ b/gui/MainWindow.cpp
@@ -32,6 +32,7 @@
#include <QFileInfo>
#include <QLabel>
#include <QToolButton>
+#include <QWidgetAction>
#include "osutils.h"
#include "userutils.h"
@@ -172,34 +173,49 @@ MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWi
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);
+ accountMenu = new QMenu(this);
+ manageAccountsAction = new QAction(tr("Manage accounts"), this);
+ manageAccountsAction->setCheckable(false);
+ connect(manageAccountsAction, SIGNAL(triggered(bool)), this, SLOT(on_actionManageAccounts_triggered()));
- MojangAccountPtr account = MMC->accounts()->activeAccount();
- if(account != nullptr)
- {
- auto job = new NetJob("Startup player skins: " + account->username());
+ repopulateAccountsMenu();
+
+ accountMenuButton = new QToolButton(this);
+ accountMenuButton->setText(tr("Accounts"));
+ accountMenuButton->setMenu(accountMenu);
+ accountMenuButton->setPopupMode(QToolButton::InstantPopup);
+ accountMenuButton->setToolButtonStyle(Qt::ToolButtonTextBesideIcon);
+ accountMenuButton->setLayoutDirection(Qt::RightToLeft);
- for(AccountProfile profile : account->profiles())
+ QWidgetAction *accountMenuButtonAction = new QWidgetAction(this);
+ accountMenuButtonAction->setDefaultWidget(accountMenuButton);
+
+ ui->mainToolBar->addAction(accountMenuButtonAction);
+
+ std::shared_ptr<MojangAccountList> accounts = MMC->accounts();
+
+ // TODO: Nicer way to iterate?
+ for(int i = 0; i < accounts->count(); i++)
+ {
+ MojangAccountPtr account = accounts->at(i);
+ if(account != nullptr)
{
- 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;
- }
+ auto job = new NetJob("Startup player skins: " + account->username());
- connect(job, SIGNAL(succeeded()), SLOT(activeAccountChanged()));
- job->start();
- }
+ 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(actionManageAccounts, SIGNAL(clicked()), this, SLOT(on_actionManageAccounts_triggered()));
- ui->mainToolBar->addWidget(actionManageAccounts);
+ connect(job, SIGNAL(succeeded()), SLOT(activeAccountChanged()));
+ job->start();
+ }
+ }
// run the things that load and download other things... FIXME: this is NOT the place
// FIXME: invisible actions in the background = NOPE.
@@ -233,8 +249,86 @@ MainWindow::~MainWindow()
delete assets_downloader;
}
+
+void MainWindow::repopulateAccountsMenu()
+{
+ accountMenu->clear();
+
+ std::shared_ptr<MojangAccountList> accounts = MMC->accounts();
+
+ QString active_username;
+ if(accounts->activeAccount() != nullptr)
+ {
+ active_username = accounts->activeAccount()->username();
+ }
+
+ if(accounts->count() <= 0)
+ {
+ QAction *action = new QAction(tr("No accounts added!"), this);
+ action->setEnabled(false);
+ accountMenu->addAction(action);
+
+ accountMenu->addSeparator();
+ }
+ else
+ {
+ // TODO: Nicer way to iterate?
+ for(int i = 0; i < accounts->count(); i++)
+ {
+ MojangAccountPtr account = accounts->at(i);
+
+ // Styling hack
+ QAction *section = new QAction(account->username(), this);
+ section->setEnabled(false);
+ accountMenu->addAction(section);
+
+ for(AccountProfile profile : account->profiles())
+ {
+ QAction *action = new QAction(profile.name(), this);
+ action->setData(account->username());
+ action->setCheckable(true);
+ if(active_username == account->username())
+ {
+ action->setChecked(true);
+ }
+
+ action->setIcon(SkinUtils::getFaceFromCache(profile.name()));
+ accountMenu->addAction(action);
+ connect(action, SIGNAL(triggered(bool)), SLOT(changeActiveAccount()));
+ }
+
+ accountMenu->addSeparator();
+ }
+ }
+
+ accountMenu->addAction(manageAccountsAction);
+}
+
+/*
+ * Assumes the sender is a QAction
+ */
+void MainWindow::changeActiveAccount()
+{
+ QAction* sAction = (QAction*) sender();
+
+ // Profile's associated Mojang username
+ // Will need to change when profiles are properly implemented
+ if(sAction->data().type() != QVariant::Type::String) return;
+
+ QString id = sAction->data().toString();
+
+ if(id != nullptr && !id.isEmpty())
+ {
+ MMC->accounts()->setActiveAccount(id);
+ }
+
+ activeAccountChanged();
+}
+
void MainWindow::activeAccountChanged()
{
+ repopulateAccountsMenu();
+
MojangAccountPtr account = MMC->accounts()->activeAccount();
if(account != nullptr)
@@ -242,9 +336,12 @@ void MainWindow::activeAccountChanged()
const AccountProfile *profile = account->currentProfile();
if(profile != nullptr)
{
- actionManageAccounts->setIcon(SkinUtils::getFaceFromCache(profile->name()));
+ accountMenuButton->setIcon(SkinUtils::getFaceFromCache(profile->name()));
+ return;
}
}
+
+ accountMenuButton->setIcon(QIcon());
}
bool MainWindow::eventFilter(QObject *obj, QEvent *ev)
diff --git a/gui/MainWindow.h b/gui/MainWindow.h
index 4e20d7cb..4191e590 100644
--- a/gui/MainWindow.h
+++ b/gui/MainWindow.h
@@ -148,6 +148,10 @@ slots:
void activeAccountChanged();
+ void changeActiveAccount();
+
+ void repopulateAccountsMenu();
+
protected:
bool eventFilter(QObject *obj, QEvent *ev);
void setCatBackground(bool enabled);
@@ -170,5 +174,7 @@ private:
QLabel *m_statusLeft;
QLabel *m_statusRight;
- QToolButton *actionManageAccounts;
+ QMenu *accountMenu;
+ QToolButton *accountMenuButton;
+ QAction *manageAccountsAction;
};
diff --git a/gui/dialogs/AccountListDialog.cpp b/gui/dialogs/AccountListDialog.cpp
index 5feed13d..97dc0564 100644
--- a/gui/dialogs/AccountListDialog.cpp
+++ b/gui/dialogs/AccountListDialog.cpp
@@ -138,6 +138,9 @@ void AccountListDialog::onLoginComplete()
// Add the authenticated account to the accounts list.
MojangAccountPtr account = m_authTask->getMojangAccount();
m_accounts->addAccount(account);
+
+ emit activeAccountChanged();
+
//ui->listView->update();
// Grab associated player skins