mirror of
https://github.com/redstrate/Astra.git
synced 2025-04-20 11:47:46 +00:00
Properly reload controls on LauncherWindow on profile change
This commit is contained in:
parent
30fed295e4
commit
221fda6e95
2 changed files with 64 additions and 51 deletions
|
@ -116,6 +116,8 @@ QString LauncherWindow::readVersion(QString path) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void LauncherWindow::readInitialInformation() {
|
void LauncherWindow::readInitialInformation() {
|
||||||
|
defaultProfileIndex = settings.value("defaultProfile", 0).toInt();
|
||||||
|
|
||||||
auto profiles = settings.childGroups();
|
auto profiles = settings.childGroups();
|
||||||
|
|
||||||
// create the Default profile if it doesnt exist
|
// create the Default profile if it doesnt exist
|
||||||
|
@ -252,60 +254,32 @@ LauncherWindow::LauncherWindow(QWidget* parent) :
|
||||||
|
|
||||||
auto layout = new QFormLayout();
|
auto layout = new QFormLayout();
|
||||||
|
|
||||||
auto profileSelect = new QComboBox();
|
profileSelect = new QComboBox();
|
||||||
profileSelect->addItem("Default");
|
|
||||||
layout->addRow("Profile", profileSelect);
|
layout->addRow("Profile", profileSelect);
|
||||||
|
|
||||||
auto usernameEdit = new QLineEdit();
|
usernameEdit = new QLineEdit();
|
||||||
layout->addRow("Username", usernameEdit);
|
layout->addRow("Username", usernameEdit);
|
||||||
|
|
||||||
if(currentProfile().rememberUsername) {
|
rememberUsernameBox = new QCheckBox();
|
||||||
auto job = new QKeychain::ReadPasswordJob("LauncherWindow");
|
|
||||||
job->setKey("username");
|
|
||||||
job->start();
|
|
||||||
|
|
||||||
connect(job, &QKeychain::ReadPasswordJob::finished, [=](QKeychain::Job* j) {
|
|
||||||
usernameEdit->setText(job->textData());
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
auto rememberUsernameBox = new QCheckBox();
|
|
||||||
rememberUsernameBox->setChecked(currentProfile().rememberUsername);
|
|
||||||
layout->addRow("Remember Username?", rememberUsernameBox);
|
layout->addRow("Remember Username?", rememberUsernameBox);
|
||||||
|
|
||||||
auto passwordEdit = new QLineEdit();
|
passwordEdit = new QLineEdit();
|
||||||
passwordEdit->setEchoMode(QLineEdit::EchoMode::Password);
|
passwordEdit->setEchoMode(QLineEdit::EchoMode::Password);
|
||||||
layout->addRow("Password", passwordEdit);
|
layout->addRow("Password", passwordEdit);
|
||||||
|
|
||||||
if(currentProfile().rememberPassword) {
|
rememberPasswordBox = new QCheckBox();
|
||||||
auto job = new QKeychain::ReadPasswordJob("LauncherWindow");
|
|
||||||
job->setKey("password");
|
|
||||||
job->start();
|
|
||||||
|
|
||||||
connect(job, &QKeychain::ReadPasswordJob::finished, [=](QKeychain::Job* j) {
|
|
||||||
passwordEdit->setText(job->textData());
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
auto rememberPasswordBox = new QCheckBox();
|
|
||||||
rememberPasswordBox->setChecked(currentProfile().rememberPassword);
|
|
||||||
layout->addRow("Remember Password?", rememberPasswordBox);
|
layout->addRow("Remember Password?", rememberPasswordBox);
|
||||||
|
|
||||||
auto otpEdit = new QLineEdit();
|
otpEdit = new QLineEdit();
|
||||||
layout->addRow("One-Time Password", otpEdit);
|
layout->addRow("One-Time Password", otpEdit);
|
||||||
|
|
||||||
auto loginButton = new QPushButton("Login");
|
auto loginButton = new QPushButton("Login");
|
||||||
layout->addRow(loginButton);
|
layout->addRow(loginButton);
|
||||||
|
|
||||||
auto registerButton = new QPushButton("Register");
|
registerButton = new QPushButton("Register");
|
||||||
layout->addRow(registerButton);
|
layout->addRow(registerButton);
|
||||||
|
|
||||||
const auto refreshControls = [=]() {
|
|
||||||
registerButton->setEnabled(currentProfile().isSapphire);
|
|
||||||
otpEdit->setEnabled(!currentProfile().isSapphire);
|
|
||||||
};
|
|
||||||
refreshControls();
|
|
||||||
|
|
||||||
auto emptyWidget = new QWidget();
|
auto emptyWidget = new QWidget();
|
||||||
emptyWidget->setLayout(layout);
|
emptyWidget->setLayout(layout);
|
||||||
setCentralWidget(emptyWidget);
|
setCentralWidget(emptyWidget);
|
||||||
|
@ -340,16 +314,18 @@ LauncherWindow::LauncherWindow(QWidget* parent) :
|
||||||
sapphireLauncher->registerAccount(currentProfile().lobbyURL, info);
|
sapphireLauncher->registerAccount(currentProfile().lobbyURL, info);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
reloadControls();
|
||||||
}
|
}
|
||||||
|
|
||||||
LauncherWindow::~LauncherWindow() = default;
|
LauncherWindow::~LauncherWindow() = default;
|
||||||
|
|
||||||
ProfileSettings LauncherWindow::currentProfile() const {
|
ProfileSettings LauncherWindow::currentProfile() const {
|
||||||
return getProfile(currentProfileIndex);
|
return getProfile(profileSelect->currentIndex());
|
||||||
}
|
}
|
||||||
|
|
||||||
ProfileSettings& LauncherWindow::currentProfile() {
|
ProfileSettings& LauncherWindow::currentProfile() {
|
||||||
return getProfile(currentProfileIndex);
|
return getProfile(profileSelect->currentIndex());
|
||||||
}
|
}
|
||||||
|
|
||||||
ProfileSettings LauncherWindow::getProfile(int index) const {
|
ProfileSettings LauncherWindow::getProfile(int index) const {
|
||||||
|
@ -360,16 +336,6 @@ ProfileSettings& LauncherWindow::getProfile(int index) {
|
||||||
return profileSettings[index];
|
return profileSettings[index];
|
||||||
}
|
}
|
||||||
|
|
||||||
void LauncherWindow::setProfile(QString name) {
|
|
||||||
currentProfileIndex = getProfileIndex(name);
|
|
||||||
settingsChanged();
|
|
||||||
}
|
|
||||||
|
|
||||||
void LauncherWindow::setProfile(int index) {
|
|
||||||
currentProfileIndex = index;
|
|
||||||
settingsChanged();
|
|
||||||
}
|
|
||||||
|
|
||||||
int LauncherWindow::getProfileIndex(QString name) {
|
int LauncherWindow::getProfileIndex(QString name) {
|
||||||
for(int i = 0; i < profileSettings.size(); i++) {
|
for(int i = 0; i < profileSettings.size(); i++) {
|
||||||
if(profileSettings[i].name == name)
|
if(profileSettings[i].name == name)
|
||||||
|
@ -407,4 +373,41 @@ void LauncherWindow::saveSettings() {
|
||||||
|
|
||||||
settings.endGroup();
|
settings.endGroup();
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void LauncherWindow::reloadControls() {
|
||||||
|
profileSelect->clear();
|
||||||
|
|
||||||
|
for(const auto& profile : profileList()) {
|
||||||
|
profileSelect->addItem(profile);
|
||||||
|
}
|
||||||
|
|
||||||
|
if(profileSelect->currentIndex() == -1) {
|
||||||
|
profileSelect->setCurrentIndex(defaultProfileIndex);
|
||||||
|
}
|
||||||
|
|
||||||
|
rememberUsernameBox->setChecked(currentProfile().rememberUsername);
|
||||||
|
if(currentProfile().rememberUsername) {
|
||||||
|
auto job = new QKeychain::ReadPasswordJob("LauncherWindow");
|
||||||
|
job->setKey("username");
|
||||||
|
job->start();
|
||||||
|
|
||||||
|
connect(job, &QKeychain::ReadPasswordJob::finished, [=](QKeychain::Job* j) {
|
||||||
|
usernameEdit->setText(job->textData());
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
rememberPasswordBox->setChecked(currentProfile().rememberPassword);
|
||||||
|
if(currentProfile().rememberPassword) {
|
||||||
|
auto job = new QKeychain::ReadPasswordJob("LauncherWindow");
|
||||||
|
job->setKey("password");
|
||||||
|
job->start();
|
||||||
|
|
||||||
|
connect(job, &QKeychain::ReadPasswordJob::finished, [=](QKeychain::Job* j) {
|
||||||
|
passwordEdit->setText(job->textData());
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
registerButton->setEnabled(currentProfile().isSapphire);
|
||||||
|
otpEdit->setEnabled(!currentProfile().isSapphire);
|
||||||
}
|
}
|
|
@ -4,6 +4,9 @@
|
||||||
#include <QNetworkAccessManager>
|
#include <QNetworkAccessManager>
|
||||||
#include <QFuture>
|
#include <QFuture>
|
||||||
#include <QSettings>
|
#include <QSettings>
|
||||||
|
#include <QComboBox>
|
||||||
|
#include <QCheckBox>
|
||||||
|
#include <QPushButton>
|
||||||
|
|
||||||
class SapphireLauncher;
|
class SapphireLauncher;
|
||||||
class SquareLauncher;
|
class SquareLauncher;
|
||||||
|
@ -52,8 +55,6 @@ public:
|
||||||
ProfileSettings getProfile(int index) const;
|
ProfileSettings getProfile(int index) const;
|
||||||
ProfileSettings& getProfile(int index);
|
ProfileSettings& getProfile(int index);
|
||||||
|
|
||||||
void setProfile(QString name);
|
|
||||||
void setProfile(int index);
|
|
||||||
int getProfileIndex(QString name);
|
int getProfileIndex(QString name);
|
||||||
QList<QString> profileList() const;
|
QList<QString> profileList() const;
|
||||||
int addProfile();
|
int addProfile();
|
||||||
|
@ -68,6 +69,9 @@ public:
|
||||||
|
|
||||||
QSettings settings;
|
QSettings settings;
|
||||||
|
|
||||||
|
public slots:
|
||||||
|
void reloadControls();
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
void settingsChanged();
|
void settingsChanged();
|
||||||
|
|
||||||
|
@ -76,6 +80,12 @@ private:
|
||||||
SquareBoot* squareBoot;
|
SquareBoot* squareBoot;
|
||||||
SquareLauncher* squareLauncher;
|
SquareLauncher* squareLauncher;
|
||||||
|
|
||||||
|
QComboBox* profileSelect;
|
||||||
|
QLineEdit* usernameEdit, *passwordEdit;
|
||||||
|
QLineEdit* otpEdit;
|
||||||
|
QCheckBox* rememberUsernameBox, *rememberPasswordBox;
|
||||||
|
QPushButton* registerButton;
|
||||||
|
|
||||||
QList<ProfileSettings> profileSettings;
|
QList<ProfileSettings> profileSettings;
|
||||||
int currentProfileIndex = 0;
|
int defaultProfileIndex = 0;
|
||||||
};
|
};
|
||||||
|
|
Loading…
Add table
Reference in a new issue