Skip to content
This repository has been archived by the owner on Feb 12, 2023. It is now read-only.

Commit

Permalink
fix(toxsave, profileimporter): Added remove function call before ov…
Browse files Browse the repository at this point in the history
…erwrite file

Fix #3558.
  • Loading branch information
Diadlo committed Aug 1, 2016
1 parent a163d18 commit 58ea0af
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 23 deletions.
13 changes: 10 additions & 3 deletions src/persistence/toxsave.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -67,9 +67,16 @@ bool handleToxSave(const QString& path)

QString profilePath = Settings::getInstance().getSettingsDirPath() + profile + Core::TOX_EXT;

if (QFileInfo(profilePath).exists() && !GUI::askQuestion(QObject::tr("Profile already exists", "import confirm title"),
QObject::tr("A profile named \"%1\" already exists. Do you want to erase it?", "import confirm text").arg(profile)))
return false;
if (QFileInfo(profilePath).exists())
{
QString title = QObject::tr("Profile already exists", "import confirm title");
QString message = QObject::tr("A profile named \"%1\" already exists. Do you want to erase it?", "import confirm text").arg(profile);
bool erase = GUI::askQuestion(title, message);
if (!erase)
return false;

QFile(profilePath).remove();
}

QFile::copy(path, profilePath);
// no good way to update the ui from here... maybe we need a Widget:refreshUi() function...
Expand Down
31 changes: 11 additions & 20 deletions src/widget/tool/profileimporter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,26 +61,17 @@ bool ProfileImporter::importProfile()

if (QFileInfo(profilePath).exists())
{
QMessageBox::StandardButton reply;
reply = QMessageBox::warning( this,
tr("Profile already exists", "import confirm title"),
tr("A profile named \"%1\" already exists. Do you want to erase it?", "import confirm text").arg(profile),
QMessageBox::Yes | QMessageBox::No);

if (reply == QMessageBox::Yes)
{
QFile::copy(path, profilePath);
return true; //import successfull
}
else
{
return false; //import canelled
}
}
else
{
QFile::copy(path, profilePath);
return true; //import successfull
QString title = QObject::tr("Profile already exists", "import confirm title");
QString message = QObject::tr("A profile named \"%1\" already exists. Do you want to erase it?", "import confirm text").arg(profile);
bool erase = GUI::askQuestion(title, message);

if (!erase)
return false; //import canelled

QFile(profilePath).remove();
}

QFile::copy(path, profilePath);
return true; //import successfull

}

0 comments on commit 58ea0af

Please sign in to comment.