From a2eb3e02665ae4dd2d6029142ac28d27f1cef361 Mon Sep 17 00:00:00 2001 From: LostDragonist Date: Sun, 19 Aug 2018 13:02:30 -0500 Subject: Prevent user from deleting currently active profile --- src/profilesdialog.cpp | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) (limited to 'src/profilesdialog.cpp') diff --git a/src/profilesdialog.cpp b/src/profilesdialog.cpp index 04c1876d..f0bbe6ed 100644 --- a/src/profilesdialog.cpp +++ b/src/profilesdialog.cpp @@ -53,6 +53,7 @@ ProfilesDialog::ProfilesDialog(const QString &profileName, MOBase::IPluginGame c , ui(new Ui::ProfilesDialog) , m_FailState(false) , m_Game(game) + , m_ActiveProfileName("") { ui->setupUi(this); @@ -66,6 +67,7 @@ ProfilesDialog::ProfilesDialog(const QString &profileName, MOBase::IPluginGame c QListWidgetItem *item = addItem(profileIter.filePath()); if (profileName == profileIter.fileName()) { ui->profilesList->setCurrentItem(item); + m_ActiveProfileName = profileName; } } @@ -182,13 +184,19 @@ void ProfilesDialog::on_copyProfileButton_clicked() void ProfilesDialog::on_removeProfileButton_clicked() { + Profile::Ptr profileToDelete = ui->profilesList->currentItem()->data(Qt::UserRole).value(); + if (profileToDelete->name() == m_ActiveProfileName) { + QMessageBox::warning(this, tr("Deleting active profile"), + tr("Unable to delete active profile. Please change to a different profile first.")); + return; + } + QMessageBox confirmBox(QMessageBox::Question, tr("Confirm"), tr("Are you sure you want to remove this profile (including local savegames if any)?"), QMessageBox::Yes | QMessageBox::No); if (confirmBox.exec() == QMessageBox::Yes) { - Profile::Ptr currentProfile = ui->profilesList->currentItem()->data(Qt::UserRole).value(); QString profilePath; - if (currentProfile.get() == nullptr) { + if (profileToDelete.get() == nullptr) { profilePath = Settings::instance().getProfileDirectory() + "/" + ui->profilesList->currentItem()->text(); if (QMessageBox::question(this, tr("Profile broken"), @@ -199,7 +207,7 @@ void ProfilesDialog::on_removeProfileButton_clicked() } else { // on destruction, the profile object would write the profile.ini file again, so // we have to get rid of the it before deleting the directory - profilePath = currentProfile->absolutePath(); + profilePath = profileToDelete->absolutePath(); } QListWidgetItem* item = ui->profilesList->takeItem(ui->profilesList->currentRow()); if (item != nullptr) { -- cgit v1.3.1