mirror of
https://github.com/redstrate/Astra.git
synced 2025-04-20 11:47:46 +00:00
Add delete profile button
This commit is contained in:
parent
ecd43301b7
commit
516b47a541
4 changed files with 34 additions and 2 deletions
|
@ -31,8 +31,18 @@ SettingsWindow::SettingsWindow(LauncherWindow& window, QWidget* parent) : window
|
|||
auto addProfileButton = new QPushButton("Add Profile");
|
||||
connect(addProfileButton, &QPushButton::pressed, [=] {
|
||||
profileWidget->setCurrentRow(this->window.addProfile());
|
||||
|
||||
this->window.saveSettings();
|
||||
});
|
||||
mainLayout->addWidget(addProfileButton, 3, 0);
|
||||
mainLayout->addWidget(addProfileButton, 2, 0);
|
||||
|
||||
deleteProfileButton = new QPushButton("Delete Profile");
|
||||
connect(deleteProfileButton, &QPushButton::pressed, [=] {
|
||||
profileWidget->setCurrentRow(this->window.deleteProfile(getCurrentProfile().name));
|
||||
|
||||
this->window.saveSettings();
|
||||
});
|
||||
mainLayout->addWidget(deleteProfileButton, 3, 0);
|
||||
|
||||
nameEdit = new QLineEdit();
|
||||
connect(nameEdit, &QLineEdit::editingFinished, [=] {
|
||||
|
@ -268,6 +278,9 @@ void SettingsWindow::reloadControls() {
|
|||
}
|
||||
profileWidget->setCurrentRow(oldRow);
|
||||
|
||||
// deleting the main profile is unsupported behavior
|
||||
deleteProfileButton->setEnabled(window.profileList().size() > 1);
|
||||
|
||||
ProfileSettings& profile = window.getProfile(profileWidget->currentRow());
|
||||
nameEdit->setText(profile.name);
|
||||
|
||||
|
|
|
@ -23,6 +23,7 @@ private:
|
|||
ProfileSettings& getCurrentProfile();
|
||||
|
||||
QListWidget* profileWidget = nullptr;
|
||||
QPushButton* deleteProfileButton = nullptr;
|
||||
|
||||
// game
|
||||
QLineEdit* nameEdit = nullptr;
|
||||
|
|
|
@ -392,6 +392,23 @@ int LauncherWindow::addProfile() {
|
|||
return profileSettings.size() - 1;
|
||||
}
|
||||
|
||||
int LauncherWindow::deleteProfile(QString name) {
|
||||
int index = 0;
|
||||
for(int i = 0; i < profileSettings.size(); i++) {
|
||||
if(profileSettings[i].name == name)
|
||||
index = i;
|
||||
}
|
||||
|
||||
// remove group so it doesnt stay
|
||||
settings.beginGroup(profileSettings[index].uuid.toString(QUuid::StringFormat::WithoutBraces));
|
||||
settings.remove("");
|
||||
settings.endGroup();
|
||||
|
||||
profileSettings.removeAt(index);
|
||||
|
||||
return index - 1;
|
||||
}
|
||||
|
||||
void LauncherWindow::saveSettings() {
|
||||
settings.setValue("defaultProfile", defaultProfileIndex);
|
||||
|
||||
|
|
|
@ -65,6 +65,7 @@ public:
|
|||
int getProfileIndex(QString name);
|
||||
QList<QString> profileList() const;
|
||||
int addProfile();
|
||||
int deleteProfile(QString name);
|
||||
|
||||
void launchGame(const LoginAuth auth);
|
||||
void launchExecutable(const QStringList args);
|
||||
|
|
Loading…
Add table
Reference in a new issue