summaryrefslogtreecommitdiff
path: root/src/profilesdialog.cpp
diff options
context:
space:
mode:
authorTannin <devnull@localhost>2014-04-05 15:36:42 +0200
committerTannin <devnull@localhost>2014-04-05 15:36:42 +0200
commitcabed9b268c9f095d5e3b98a6797b0bcdcd38b1f (patch)
tree454b03b0c5664e90fe586e7b39603e34a526d35b /src/profilesdialog.cpp
parent98e5e57a845541acddf519a81957261f58008cb9 (diff)
parentc017f4a0d50b67a44e276bd5ae8929ed3990c62c (diff)
Merge with branch1.1
Diffstat (limited to 'src/profilesdialog.cpp')
-rw-r--r--src/profilesdialog.cpp45
1 files changed, 32 insertions, 13 deletions
diff --git a/src/profilesdialog.cpp b/src/profilesdialog.cpp
index 9955ecd2..69872a24 100644
--- a/src/profilesdialog.cpp
+++ b/src/profilesdialog.cpp
@@ -150,36 +150,55 @@ void ProfilesDialog::on_copyProfileButton_clicked()
{
bool okClicked;
QString name = QInputDialog::getText(this, tr("Name"), tr("Please enter a name for the new profile"), QLineEdit::Normal, QString(), &okClicked);
- if (okClicked && (name.size() > 0)) {
- QListWidget *profilesList = findChild<QListWidget*>("profilesList");
+ fixDirectoryName(name);
+ if (okClicked) {
+ if (name.size() > 0) {
+ QListWidget *profilesList = findChild<QListWidget*>("profilesList");
- try {
- const Profile::Ptr currentProfile = profilesList->currentItem()->data(Qt::UserRole).value<Profile::Ptr>();
- createProfile(name, *currentProfile);
- } catch (const std::exception &e) {
- reportError(tr("failed to copy profile: %1").arg(e.what()));
+ try {
+ const Profile::Ptr currentProfile = profilesList->currentItem()->data(Qt::UserRole).value<Profile::Ptr>();
+ createProfile(name, *currentProfile);
+ } catch (const std::exception &e) {
+ reportError(tr("failed to copy profile: %1").arg(e.what()));
+ }
+ } else {
+ QMessageBox::warning(this, tr("Invalid name"), tr("Invalid profile name"));
}
}
}
void ProfilesDialog::on_removeProfileButton_clicked()
{
- QMessageBox confirmBox(QMessageBox::Question, tr("Confirm"), tr("Are you sure you want to remove this profile?"),
+ 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) {
QListWidget *profilesList = findChild<QListWidget*>("profilesList");
Profile::Ptr currentProfile = profilesList->currentItem()->data(Qt::UserRole).value<Profile::Ptr>();
-
- // 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
- QString profilePath = currentProfile->getPath();
+ QString profilePath;
+ if (currentProfile.get() == NULL) {
+ profilePath = QDir::fromNativeSeparators(ToQString(GameInfo::instance().getProfilesDir())) + "/" + profilesList->currentItem()->text();
+ if (QMessageBox::question(this, tr("Profile broken"),
+ tr("This profile you're about to delete seems to be broken or the path is invalid. "
+ "I'm about to delete the following folder: \"%1\". Proceed?").arg(profilePath), QMessageBox::Yes | QMessageBox::No) == QMessageBox::No) {
+ return;
+ }
+ } 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->getPath();
+ }
QListWidgetItem* item = profilesList->takeItem(profilesList->currentRow());
if (item != NULL) {
delete item;
}
- shellDelete(QStringList(profilePath));
+ if (!shellDelete(QStringList(profilePath))) {
+ qWarning("Failed to shell-delete \"%s\" (errorcode %lu), trying regular delete", qPrintable(profilePath), ::GetLastError());
+ if (!removeDir(profilePath)) {
+ qWarning("regular delete failed too");
+ }
+ }
}
}