diff --git a/src/settingswindow.cpp b/src/settingswindow.cpp index 1632e08..3a79c94 100644 --- a/src/settingswindow.cpp +++ b/src/settingswindow.cpp @@ -30,9 +30,19 @@ SettingsWindow::SettingsWindow(LauncherWindow& window, QWidget* parent) : window auto addProfileButton = new QPushButton("Add Profile"); connect(addProfileButton, &QPushButton::pressed, [=] { - profileWidget->setCurrentRow(this->window.addProfile()); + 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); diff --git a/src/settingswindow.h b/src/settingswindow.h index 8f9ce23..5f7d101 100644 --- a/src/settingswindow.h +++ b/src/settingswindow.h @@ -23,6 +23,7 @@ private: ProfileSettings& getCurrentProfile(); QListWidget* profileWidget = nullptr; + QPushButton* deleteProfileButton = nullptr; // game QLineEdit* nameEdit = nullptr; diff --git a/src/xivlauncher.cpp b/src/xivlauncher.cpp index e15065c..cd1f9e3 100755 --- a/src/xivlauncher.cpp +++ b/src/xivlauncher.cpp @@ -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); diff --git a/src/xivlauncher.h b/src/xivlauncher.h index a9a676f..4f4f18f 100755 --- a/src/xivlauncher.h +++ b/src/xivlauncher.h @@ -65,6 +65,7 @@ public: int getProfileIndex(QString name); QList profileList() const; int addProfile(); + int deleteProfile(QString name); void launchGame(const LoginAuth auth); void launchExecutable(const QStringList args);