1
Fork 0
mirror of https://github.com/redstrate/Astra.git synced 2025-04-21 20:27:45 +00:00

Add currentProfile property to LauncherCore

This commit is contained in:
Joshua Goins 2023-09-16 20:12:01 -04:00
parent c4d870ea0a
commit e211c95e21
4 changed files with 55 additions and 27 deletions

View file

@ -73,6 +73,7 @@ class LauncherCore : public QObject
Q_PROPERTY(QString squareEnixServer READ squareEnixServer WRITE setSquareEnixServer NOTIFY squareEnixServerChanged)
Q_PROPERTY(QString squareEnixLoginServer READ squareEnixLoginServer WRITE setSquareEnixLoginServer NOTIFY squareEnixLoginServerChanged)
Q_PROPERTY(Headline *headline READ headline NOTIFY newsChanged)
Q_PROPERTY(Profile *currentProfile READ currentProfile WRITE setCurrentProfile NOTIFY currentProfileChanged)
public:
LauncherCore();
@ -165,6 +166,9 @@ public:
Q_INVOKABLE void openSystemInfo(Profile *profile);
Q_INVOKABLE void openConfigBackup(Profile *profile);
Profile *currentProfile() const;
void setCurrentProfile(Profile *profile);
signals:
void loadingFinished();
void gameInstallationChanged();
@ -184,6 +188,7 @@ signals:
void stageIndeterminate();
void stageDeterminate(int min, int max, int value);
void newsChanged();
void currentProfileChanged();
private:
/*
@ -219,4 +224,6 @@ private:
AccountManager *m_accountManager = nullptr;
Headline *m_headline = nullptr;
int m_currentProfileIndex = 0;
};

View file

@ -714,3 +714,17 @@ void LauncherCore::setIsSteam(bool isSteam)
{
m_isSteam = isSteam;
}
Profile *LauncherCore::currentProfile() const
{
return m_profileManager->getProfile(m_currentProfileIndex);
}
void LauncherCore::setCurrentProfile(Profile *profile)
{
const int newIndex = m_profileManager->getProfileIndex(profile->name());
if (newIndex != m_currentProfileIndex) {
m_currentProfileIndex = newIndex;
Q_EMIT currentProfileChanged();
}
}

View file

@ -22,8 +22,6 @@ Kirigami.ApplicationWindow {
visible: true
title: LauncherCore.isSteam ? "Astra (Steam)" : "Astra"
property var currentSetupProfile: LauncherCore.profileManager.getProfile(0)
pageStack.initialPage: Kirigami.Page {
Kirigami.LoadingPlaceholder {
anchors.centerIn: parent
@ -37,15 +35,15 @@ Kirigami.ApplicationWindow {
pageStack.layers.clear()
if (!currentSetupProfile.isGameInstalled) {
if (!LauncherCore.currentProfile.isGameInstalled) {
// User must set up the profile
pageStack.layers.replace(Qt.createComponent("zone.xiv.astra", "SetupPage"), {
profile: currentSetupProfile
profile: LauncherCore.currentProfile
})
} else if (!currentSetupProfile.account) {
} else if (!LauncherCore.currentProfile.account) {
// User must select an account for the profile
pageStack.layers.replace(Qt.createComponent("zone.xiv.astra", "AccountSetup"), {
profile: currentSetupProfile
profile: LauncherCore.currentProfile
})
} else {
pageStack.layers.replace(Qt.createComponent("zone.xiv.astra", "MainPage"))
@ -98,6 +96,10 @@ Kirigami.ApplicationWindow {
// TODO: see if this changed in Qt6
pageStack.layers.replace(Qt.createComponent("zone.xiv.astra", "MainPage"))
}
function onCurrentProfileChanged() {
checkSetup();
}
}
Component.onCompleted: checkSetup()

View file

@ -14,9 +14,8 @@ import zone.xiv.astra
QQC2.Control {
id: page
property var profile: LauncherCore.profileManager.getProfile(0)
readonly property bool isLoginValid: {
if (!profile.account) {
if (!LauncherCore.currentProfile.account) {
return false
}
@ -24,11 +23,11 @@ QQC2.Control {
return false
}
if (!profile.account.rememberPassword && passwordField.text.length === 0) {
if (!LauncherCore.currentProfile.account.rememberPassword && passwordField.text.length === 0) {
return false
}
if (profile.account.useOTP && !profile.account.rememberOTP && otpField.text.length === 0) {
if (LauncherCore.currentProfile.account.useOTP && !LauncherCore.currentProfile.account.rememberOTP && otpField.text.length === 0) {
return false
}
@ -36,21 +35,27 @@ QQC2.Control {
}
function updateFields() {
usernameField.text = profile.account.name
passwordField.text = profile.account.rememberPassword ? profile.account.getPassword() : ""
usernameField.text = LauncherCore.currentProfile.account.name
passwordField.text = LauncherCore.currentProfile.account.rememberPassword ? LauncherCore.currentProfile.account.getPassword() : ""
otpField.text = ""
}
Connections {
target: profile
target: LauncherCore
function onCurrentProfileChanged() {
updateFields();
}
}
Connections {
target: LauncherCore.currentProfile
function onAccountChanged() {
updateFields()
}
}
onProfileChanged: updateFields()
contentItem: ColumnLayout {
width: parent.width
@ -59,7 +64,7 @@ QQC2.Control {
FormCard.FormButtonDelegate {
text: i18n("Current Profile")
description: page.profile.name
description: LauncherCore.currentProfile.name
QQC2.Menu {
id: profileMenu
@ -74,7 +79,7 @@ QQC2.Control {
text: profile.name
onClicked: {
page.profile = profile
LauncherCore.currentProfile = profile
profileMenu.close()
}
}
@ -91,11 +96,11 @@ QQC2.Control {
FormCard.FormButtonDelegate {
text: i18n("Current Account")
description: page.profile.account.name
description: LauncherCore.currentProfile.account.name
leading: Components.Avatar
{
source: page.profile.account.avatarUrl
source: LauncherCore.currentProfile.account.avatarUrl
}
leadingPadding: Kirigami.Units.largeSpacing * 2
@ -115,7 +120,7 @@ QQC2.Control {
icon.source: account.avatarUrl
onClicked: {
page.profile.account = account
LauncherCore.currentProfile.account = account
accountMenu.close()
}
}
@ -131,8 +136,8 @@ QQC2.Control {
FormCard.FormTextFieldDelegate {
id: usernameField
label: page.profile.account.isSapphire ? i18n("Username") : i18n("Square Enix ID")
text: page.profile.account.name
label: LauncherCore.currentProfile.account.isSapphire ? i18n("Username") : i18n("Square Enix ID")
text: LauncherCore.currentProfile.account.name
enabled: false
}
@ -141,7 +146,7 @@ QQC2.Control {
FormCard.FormTextFieldDelegate {
id: passwordField
label: page.profile.account.isSapphire ? i18n("Password") : i18n("Square Enix Password")
label: LauncherCore.currentProfile.account.isSapphire ? i18n("Password") : i18n("Square Enix Password")
echoMode: TextInput.Password
focus: true
onAccepted: {
@ -151,7 +156,7 @@ QQC2.Control {
loginButton.clicked();
}
}
text: page.profile.account.rememberPassword ? "abcdefg" : ""
text: LauncherCore.currentProfile.account.rememberPassword ? LauncherCore.currentProfile.account.getPassword() : ""
}
FormCard.FormDelegateSeparator {
@ -160,7 +165,7 @@ QQC2.Control {
FormCard.FormTextFieldDelegate {
id: otpField
label: i18n("One-time Password")
visible: page.profile.account.useOTP
visible: LauncherCore.currentProfile.account.useOTP
onAccepted: loginButton.clicked()
}
@ -173,7 +178,7 @@ QQC2.Control {
icon.name: "unlock"
enabled: page.isLoginValid
onClicked: {
LauncherCore.login(page.profile, usernameField.text, passwordField.text, otpField.text)
LauncherCore.login(LauncherCore.currentProfile, usernameField.text, passwordField.text, otpField.text)
pageStack.layers.push(Qt.createComponent("zone.xiv.astra", "StatusPage"))
}
}
@ -187,7 +192,7 @@ QQC2.Control {
text: i18n("Forgot ID or Password")
icon.name: "dialog-password"
visible: !page.profile.account.isSapphire
visible: !LauncherCore.currentProfile.account.isSapphire
onClicked: applicationWindow().openUrl('https://secure.square-enix.com/account/app/svc/reminder')
}
}