Fix profile deletion bug

This commit is contained in:
Mark Watkins 2018-06-06 08:16:37 +10:00
parent 2ab65bc85b
commit 0e1df59cd3

View File

@ -350,7 +350,7 @@ void ProfileSelector::on_buttonDestroyProfile_clicked()
Profile * profile = Profiles::profiles[name]; Profile * profile = Profiles::profiles[name];
QString path = profile->Get(PrefMacro(STR_GEN_DataFolder)); QString path = profile->Get(PrefMacro(STR_GEN_DataFolder));
bool reallydelete = false; bool verified = true;
if (profile->user->hasPassword()) { if (profile->user->hasPassword()) {
QDialog dialog(this, Qt::Dialog); QDialog dialog(this, Qt::Dialog);
QLineEdit *e = new QLineEdit(&dialog); QLineEdit *e = new QLineEdit(&dialog);
@ -371,19 +371,19 @@ void ProfileSelector::on_buttonDestroyProfile_clicked()
tries++; tries++;
if (profile->user->checkPassword(e->text())) { if (profile->user->checkPassword(e->text())) {
reallydelete = true; verified = true;
break; break;
} else { } else {
if (tries < 3) { if (tries < 3) {
QMessageBox::warning(this, STR_MessageBox_Error, tr("You entered an incorrect password"), QMessageBox::Ok); QMessageBox::warning(this, STR_MessageBox_Error, tr("You entered an incorrect password"), QMessageBox::Ok);
} else { } else {
QMessageBox::warning(this, STR_MessageBox_Error, QMessageBox::warning(this, STR_MessageBox_Error,
tr("If you're trying to delete because you forgot the password, you need to delete it manually."), tr("If you're trying to delete because you forgot the password, you need to either reset it or delete the profile folder manually."),
QMessageBox::Ok); QMessageBox::Ok);
} }
} }
} while (tries < 3); } while (tries < 3);
if (!reallydelete) return; if (!verified) return;
} }
QDialog confirmdlg; QDialog confirmdlg;
@ -410,27 +410,25 @@ void ProfileSelector::on_buttonDestroyProfile_clicked()
QMessageBox::information(NULL, tr("Sorry"), tr("You need to enter DELETE in capital letters."), QMessageBox::Ok); QMessageBox::information(NULL, tr("Sorry"), tr("You need to enter DELETE in capital letters."), QMessageBox::Ok);
return; return;
} }
qDebug() << "Deleting Profile" << name;
if (reallydelete) { if (profile == p_profile) {
qDebug() << "Deleting Profile" << name; // Shut down if active
if (profile == p_profile) { mainwin->CloseProfile();
// Shut down if active
mainwin->CloseProfile();
}
Profiles::profiles.remove(name);
if (!path.isEmpty()) {
if (!removeDir(path)) {
QMessageBox::information(this, STR_MessageBox_Error,
tr("There was an error deleting the profile directory, you need to manually remove it.")+QString("\n\n%1").arg(path),
QMessageBox::Ok);
}
qDebug() << "Delete" << path;
QMessageBox::information(this, STR_MessageBox_Information, QString(tr("Profile '%1' was succesfully deleted").arg(name)),QMessageBox::Ok);
}
updateProfileList();
} }
Profiles::profiles.remove(name);
if (!path.isEmpty()) {
if (!removeDir(path)) {
QMessageBox::information(this, STR_MessageBox_Error,
tr("There was an error deleting the profile directory, you need to manually remove it.")+QString("\n\n%1").arg(path),
QMessageBox::Ok);
}
qDebug() << "Delete" << path;
QMessageBox::information(this, STR_MessageBox_Information, QString(tr("Profile '%1' was succesfully deleted").arg(name)),QMessageBox::Ok);
}
updateProfileList();
} }
} }