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() {
|
||||
defaultProfileIndex = settings.value("defaultProfile", 0).toInt();
|
||||
|
||||
auto profiles = settings.childGroups();
|
||||
|
||||
// create the Default profile if it doesnt exist
|
||||
|
@ -252,60 +254,32 @@ LauncherWindow::LauncherWindow(QWidget* parent) :
|
|||
|
||||
auto layout = new QFormLayout();
|
||||
|
||||
auto profileSelect = new QComboBox();
|
||||
profileSelect->addItem("Default");
|
||||
profileSelect = new QComboBox();
|
||||
|
||||
layout->addRow("Profile", profileSelect);
|
||||
|
||||
auto usernameEdit = new QLineEdit();
|
||||
usernameEdit = new QLineEdit();
|
||||
layout->addRow("Username", usernameEdit);
|
||||
|
||||
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());
|
||||
});
|
||||
}
|
||||
|
||||
auto rememberUsernameBox = new QCheckBox();
|
||||
rememberUsernameBox->setChecked(currentProfile().rememberUsername);
|
||||
rememberUsernameBox = new QCheckBox();
|
||||
layout->addRow("Remember Username?", rememberUsernameBox);
|
||||
|
||||
auto passwordEdit = new QLineEdit();
|
||||
passwordEdit = new QLineEdit();
|
||||
passwordEdit->setEchoMode(QLineEdit::EchoMode::Password);
|
||||
layout->addRow("Password", passwordEdit);
|
||||
|
||||
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());
|
||||
});
|
||||
}
|
||||
|
||||
auto rememberPasswordBox = new QCheckBox();
|
||||
rememberPasswordBox->setChecked(currentProfile().rememberPassword);
|
||||
rememberPasswordBox = new QCheckBox();
|
||||
layout->addRow("Remember Password?", rememberPasswordBox);
|
||||
|
||||
auto otpEdit = new QLineEdit();
|
||||
otpEdit = new QLineEdit();
|
||||
layout->addRow("One-Time Password", otpEdit);
|
||||
|
||||
auto loginButton = new QPushButton("Login");
|
||||
layout->addRow(loginButton);
|
||||
|
||||
auto registerButton = new QPushButton("Register");
|
||||
registerButton = new QPushButton("Register");
|
||||
layout->addRow(registerButton);
|
||||
|
||||
const auto refreshControls = [=]() {
|
||||
registerButton->setEnabled(currentProfile().isSapphire);
|
||||
otpEdit->setEnabled(!currentProfile().isSapphire);
|
||||
};
|
||||
refreshControls();
|
||||
|
||||
auto emptyWidget = new QWidget();
|
||||
emptyWidget->setLayout(layout);
|
||||
setCentralWidget(emptyWidget);
|
||||
|
@ -340,16 +314,18 @@ LauncherWindow::LauncherWindow(QWidget* parent) :
|
|||
sapphireLauncher->registerAccount(currentProfile().lobbyURL, info);
|
||||
}
|
||||
});
|
||||
|
||||
reloadControls();
|
||||
}
|
||||
|
||||
LauncherWindow::~LauncherWindow() = default;
|
||||
|
||||
ProfileSettings LauncherWindow::currentProfile() const {
|
||||
return getProfile(currentProfileIndex);
|
||||
return getProfile(profileSelect->currentIndex());
|
||||
}
|
||||
|
||||
ProfileSettings& LauncherWindow::currentProfile() {
|
||||
return getProfile(currentProfileIndex);
|
||||
return getProfile(profileSelect->currentIndex());
|
||||
}
|
||||
|
||||
ProfileSettings LauncherWindow::getProfile(int index) const {
|
||||
|
@ -360,16 +336,6 @@ ProfileSettings& LauncherWindow::getProfile(int 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) {
|
||||
for(int i = 0; i < profileSettings.size(); i++) {
|
||||
if(profileSettings[i].name == name)
|
||||
|
@ -408,3 +374,40 @@ void LauncherWindow::saveSettings() {
|
|||
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 <QFuture>
|
||||
#include <QSettings>
|
||||
#include <QComboBox>
|
||||
#include <QCheckBox>
|
||||
#include <QPushButton>
|
||||
|
||||
class SapphireLauncher;
|
||||
class SquareLauncher;
|
||||
|
@ -52,8 +55,6 @@ public:
|
|||
ProfileSettings getProfile(int index) const;
|
||||
ProfileSettings& getProfile(int index);
|
||||
|
||||
void setProfile(QString name);
|
||||
void setProfile(int index);
|
||||
int getProfileIndex(QString name);
|
||||
QList<QString> profileList() const;
|
||||
int addProfile();
|
||||
|
@ -68,6 +69,9 @@ public:
|
|||
|
||||
QSettings settings;
|
||||
|
||||
public slots:
|
||||
void reloadControls();
|
||||
|
||||
signals:
|
||||
void settingsChanged();
|
||||
|
||||
|
@ -76,6 +80,12 @@ private:
|
|||
SquareBoot* squareBoot;
|
||||
SquareLauncher* squareLauncher;
|
||||
|
||||
QComboBox* profileSelect;
|
||||
QLineEdit* usernameEdit, *passwordEdit;
|
||||
QLineEdit* otpEdit;
|
||||
QCheckBox* rememberUsernameBox, *rememberPasswordBox;
|
||||
QPushButton* registerButton;
|
||||
|
||||
QList<ProfileSettings> profileSettings;
|
||||
int currentProfileIndex = 0;
|
||||
int defaultProfileIndex = 0;
|
||||
};
|
||||
|
|
Loading…
Add table
Reference in a new issue