aboutsummaryrefslogtreecommitdiff
path: root/launcher/pages/global
diff options
context:
space:
mode:
authorPetr Mrázek <peterix@gmail.com>2021-07-26 21:44:11 +0200
committerPetr Mrázek <peterix@gmail.com>2021-08-15 23:18:50 +0200
commit3a53349e332599221bc325f7fac9dc7927194bc2 (patch)
tree2ee40fa6044c241b3b7db27fe0b83931b453c2b2 /launcher/pages/global
parentfca2e9e44cb44004eec7f47c03b186bd5e44dc32 (diff)
downloadPrismLauncher-3a53349e332599221bc325f7fac9dc7927194bc2.tar.gz
PrismLauncher-3a53349e332599221bc325f7fac9dc7927194bc2.tar.bz2
PrismLauncher-3a53349e332599221bc325f7fac9dc7927194bc2.zip
GH-3392 dirty initial MSA support that shares logic with Mojang flows
Both act as the first step of AuthContext.
Diffstat (limited to 'launcher/pages/global')
-rw-r--r--launcher/pages/global/AccountListPage.cpp80
-rw-r--r--launcher/pages/global/AccountListPage.h8
-rw-r--r--launcher/pages/global/AccountListPage.ui30
3 files changed, 71 insertions, 47 deletions
diff --git a/launcher/pages/global/AccountListPage.cpp b/launcher/pages/global/AccountListPage.cpp
index ff3736ed..a3cd86a4 100644
--- a/launcher/pages/global/AccountListPage.cpp
+++ b/launcher/pages/global/AccountListPage.cpp
@@ -29,12 +29,13 @@
#include "dialogs/CustomMessageBox.h"
#include "dialogs/SkinUploadDialog.h"
#include "tasks/Task.h"
-#include "minecraft/auth/YggdrasilTask.h"
+#include "minecraft/auth/AccountTask.h"
#include "minecraft/services/SkinDelete.h"
#include "MultiMC.h"
#include "BuildConfig.h"
+#include <dialogs/MSALoginDialog.h>
AccountListPage::AccountListPage(QWidget *parent)
: QMainWindow(parent), ui(new Ui::AccountListPage)
@@ -50,11 +51,12 @@ AccountListPage::AccountListPage(QWidget *parent)
m_accounts = MMC->accounts();
ui->listView->setModel(m_accounts.get());
- ui->listView->header()->setSectionResizeMode(QHeaderView::ResizeToContents);
+ ui->listView->header()->setSectionResizeMode(0, QHeaderView::Stretch);
+ ui->listView->header()->setSectionResizeMode(1, QHeaderView::Stretch);
+ ui->listView->header()->setSectionResizeMode(2, QHeaderView::ResizeToContents);
ui->listView->setSelectionMode(QAbstractItemView::SingleSelection);
// Expand the account column
- ui->listView->header()->setSectionResizeMode(1, QHeaderView::Stretch);
QItemSelectionModel *selectionModel = ui->listView->selectionModel();
@@ -63,8 +65,8 @@ AccountListPage::AccountListPage(QWidget *parent)
});
connect(ui->listView, &VersionListView::customContextMenuRequested, this, &AccountListPage::ShowContextMenu);
- connect(m_accounts.get(), SIGNAL(listChanged()), SLOT(listChanged()));
- connect(m_accounts.get(), SIGNAL(activeAccountChanged()), SLOT(listChanged()));
+ connect(m_accounts.get(), &AccountList::listChanged, this, &AccountListPage::listChanged);
+ connect(m_accounts.get(), &AccountList::activeAccountChanged, this, &AccountListPage::listChanged);
updateButtonStates();
}
@@ -103,9 +105,36 @@ void AccountListPage::listChanged()
updateButtonStates();
}
-void AccountListPage::on_actionAdd_triggered()
+void AccountListPage::on_actionAddMojang_triggered()
{
- addAccount(tr("Please enter your Minecraft account email and password to add your account."));
+ MinecraftAccountPtr account = LoginDialog::newAccount(
+ this,
+ tr("Please enter your Mojang account email and password to add your account.")
+ );
+
+ if (account != nullptr)
+ {
+ m_accounts->addAccount(account);
+ if (m_accounts->count() == 1) {
+ m_accounts->setActiveAccount(account->profileId());
+ }
+ }
+}
+
+void AccountListPage::on_actionAddMicrosoft_triggered()
+{
+ MinecraftAccountPtr account = MSALoginDialog::newAccount(
+ this,
+ tr("Please enter your Mojang account email and password to add your account.")
+ );
+
+ if (account != nullptr)
+ {
+ m_accounts->addAccount(account);
+ if (m_accounts->count() == 1) {
+ m_accounts->setActiveAccount(account->profileId());
+ }
+ }
}
void AccountListPage::on_actionRemove_triggered()
@@ -124,9 +153,8 @@ void AccountListPage::on_actionSetDefault_triggered()
if (selection.size() > 0)
{
QModelIndex selected = selection.first();
- MojangAccountPtr account =
- selected.data(MojangAccountList::PointerRole).value<MojangAccountPtr>();
- m_accounts->setActiveAccount(account->username());
+ MinecraftAccountPtr account = selected.data(AccountList::PointerRole).value<MinecraftAccountPtr>();
+ m_accounts->setActiveAccount(account->profileId());
}
}
@@ -156,39 +184,13 @@ void AccountListPage::updateButtonStates()
}
-void AccountListPage::addAccount(const QString &errMsg)
-{
- // TODO: The login dialog isn't quite done yet
- MojangAccountPtr account = LoginDialog::newAccount(this, errMsg);
-
- if (account != nullptr)
- {
- m_accounts->addAccount(account);
- if (m_accounts->count() == 1)
- m_accounts->setActiveAccount(account->username());
-
- // Grab associated player skins
- auto job = new NetJob("Player skins: " + account->username());
-
- for (AccountProfile 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);
- job->addNetAction(action);
- meta->setStale(true);
- }
-
- job->start();
- }
-}
-
void AccountListPage::on_actionUploadSkin_triggered()
{
QModelIndexList selection = ui->listView->selectionModel()->selectedIndexes();
if (selection.size() > 0)
{
QModelIndex selected = selection.first();
- MojangAccountPtr account = selected.data(MojangAccountList::PointerRole).value<MojangAccountPtr>();
+ MinecraftAccountPtr account = selected.data(AccountList::PointerRole).value<MinecraftAccountPtr>();
SkinUploadDialog dialog(account, this);
dialog.exec();
}
@@ -202,8 +204,8 @@ void AccountListPage::on_actionDeleteSkin_triggered()
QModelIndex selected = selection.first();
AuthSessionPtr session = std::make_shared<AuthSession>();
- MojangAccountPtr account = selected.data(MojangAccountList::PointerRole).value<MojangAccountPtr>();
- auto login = account->login(session);
+ MinecraftAccountPtr account = selected.data(AccountList::PointerRole).value<MinecraftAccountPtr>();
+ auto login = account->refresh(session);
ProgressDialog prog(this);
if (prog.execWithTask((Task*)login.get()) != QDialog::Accepted) {
CustomMessageBox::selectable(this, tr("Skin Delete"), tr("Failed to login!"), QMessageBox::Warning)->exec();
diff --git a/launcher/pages/global/AccountListPage.h b/launcher/pages/global/AccountListPage.h
index fba1833f..24bb96da 100644
--- a/launcher/pages/global/AccountListPage.h
+++ b/launcher/pages/global/AccountListPage.h
@@ -20,7 +20,7 @@
#include "pages/BasePage.h"
-#include "minecraft/auth/MojangAccountList.h"
+#include "minecraft/auth/AccountList.h"
#include "MultiMC.h"
namespace Ui
@@ -60,7 +60,8 @@ public:
}
public slots:
- void on_actionAdd_triggered();
+ void on_actionAddMojang_triggered();
+ void on_actionAddMicrosoft_triggered();
void on_actionRemove_triggered();
void on_actionSetDefault_triggered();
void on_actionNoDefault_triggered();
@@ -74,11 +75,10 @@ public slots:
protected slots:
void ShowContextMenu(const QPoint &pos);
- void addAccount(const QString& errMsg="");
private:
void changeEvent(QEvent * event) override;
QMenu * createPopupMenu() override;
- std::shared_ptr<MojangAccountList> m_accounts;
+ std::shared_ptr<AccountList> m_accounts;
Ui::AccountListPage *ui;
};
diff --git a/launcher/pages/global/AccountListPage.ui b/launcher/pages/global/AccountListPage.ui
index 71647db3..887c3d48 100644
--- a/launcher/pages/global/AccountListPage.ui
+++ b/launcher/pages/global/AccountListPage.ui
@@ -25,7 +25,23 @@
<number>0</number>
</property>
<item>
- <widget class="VersionListView" name="listView"/>
+ <widget class="VersionListView" name="listView">
+ <property name="alternatingRowColors">
+ <bool>true</bool>
+ </property>
+ <property name="rootIsDecorated">
+ <bool>false</bool>
+ </property>
+ <property name="itemsExpandable">
+ <bool>false</bool>
+ </property>
+ <property name="allColumnsShowFocus">
+ <bool>true</bool>
+ </property>
+ <attribute name="headerStretchLastSection">
+ <bool>false</bool>
+ </attribute>
+ </widget>
</item>
</layout>
</widget>
@@ -36,7 +52,8 @@
<attribute name="toolBarBreak">
<bool>false</bool>
</attribute>
- <addaction name="actionAdd"/>
+ <addaction name="actionAddMicrosoft"/>
+ <addaction name="actionAddMojang"/>
<addaction name="actionRemove"/>
<addaction name="actionSetDefault"/>
<addaction name="actionNoDefault"/>
@@ -44,9 +61,9 @@
<addaction name="actionUploadSkin"/>
<addaction name="actionDeleteSkin"/>
</widget>
- <action name="actionAdd">
+ <action name="actionAddMojang">
<property name="text">
- <string>Add</string>
+ <string>Add Mojang</string>
</property>
</action>
<action name="actionRemove">
@@ -80,6 +97,11 @@
<string>Delete the currently active skin and go back to the default one</string>
</property>
</action>
+ <action name="actionAddMicrosoft">
+ <property name="text">
+ <string>Add Microsoft</string>
+ </property>
+ </action>
</widget>
<customwidgets>
<customwidget>