1
0
mirror of https://github.com/qTox/qTox.git synced 2024-03-22 14:00:36 +08:00

Merge pull request #3560

Diadlo (3):
      fix(toxsave, profileimporter): Added `remove` function call before overwrite file
      refactor(profileimporter): Removed extra spaces
      refactor(toxsave, profileimporter): Removed code duplication
This commit is contained in:
sudden6 2016-08-01 21:35:32 +02:00
commit eedc2a961f
No known key found for this signature in database
GPG Key ID: 279509B499E032B9
3 changed files with 41 additions and 56 deletions

View File

@ -21,6 +21,7 @@
#include "src/widget/gui.h"
#include "src/core/core.h"
#include "src/persistence/settings.h"
#include "src/widget/tool/profileimporter.h"
#include <QCoreApplication>
#include <QFileInfo>
@ -52,28 +53,6 @@ bool handleToxSave(const QString& path)
while (!core->isReady())
qApp->processEvents();
QFileInfo info(path);
if (!info.exists())
return false;
QString profile = info.completeBaseName();
if (info.suffix() != "tox")
{
GUI::showWarning(QObject::tr("Ignoring non-Tox file", "popup title"),
QObject::tr("Warning: you've chosen a file that is not a Tox save file; ignoring.", "popup text"));
return false;
}
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;
QFile::copy(path, profilePath);
// no good way to update the ui from here... maybe we need a Widget:refreshUi() function...
// such a thing would simplify other code as well I believe
GUI::showInfo(QObject::tr("Profile imported"), QObject::tr("%1.tox was successfully imported").arg(profile));
return true;
ProfileImporter importer(GUI::getMainWidget());
return importer.importProfile(path);
}

View File

@ -42,45 +42,50 @@ bool ProfileImporter::importProfile()
tr("Tox save file (*.tox)", "import dialog filter"),
0,
QFileDialog::DontUseNativeDialog);
importProfile(path);
}
bool ProfileImporter::importProfile(const QString &path)
{
if (path.isEmpty())
return false;
QFileInfo info(path);
QString profile = info.completeBaseName();
QFileInfo info(path);
if (!info.exists())
{
GUI::showWarning(tr("File doesn't exist"),
tr("Profile doesn't exist"));
return false;
}
if (info.suffix() != "tox")
{
QMessageBox::warning( this,
tr("Ignoring non-Tox file", "popup title"),
tr("Warning: You have chosen a file that is not a Tox save file; ignoring.", "popup text"),
QMessageBox::Ok);
return false; //ingore importing non-tox file
}
QString profile = info.completeBaseName();
QString profilePath = QDir(Settings::getInstance().getSettingsDirPath()).filePath(profile + Core::TOX_EXT);
if (info.suffix() != "tox")
{
GUI::showWarning(tr("Ignoring non-Tox file", "popup title"),
tr("Warning: You have chosen a file that is not a Tox save file; ignoring.", "popup text"));
return false; //ingore importing non-tox file
}
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);
QString profilePath = QDir(Settings::getInstance().getSettingsDirPath()).filePath(profile + Core::TOX_EXT);
if (reply == QMessageBox::Yes)
{
QFile::copy(path, profilePath);
return true; //import successfull
}
else
{
if (QFileInfo(profilePath).exists())
{
QString title = tr("Profile already exists", "import confirm title");
QString message = 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
}
}
else
{
QFile::copy(path, profilePath);
return true; //import successfull
}
QFile(profilePath).remove();
}
QFile::copy(path, profilePath);
// no good way to update the ui from here... maybe we need a Widget:refreshUi() function...
// such a thing would simplify other code as well I believe
GUI::showInfo(tr("Profile imported"),
tr("%1.tox was successfully imported").arg(profile));
return true; //import successfull
}

View File

@ -28,6 +28,7 @@ class ProfileImporter : public QWidget
public:
explicit ProfileImporter(QWidget *parent = 0);
bool importProfile(const QString &path);
bool importProfile();
signals: