111 lines
3.7 KiB
C++
111 lines
3.7 KiB
C++
#include "wizardpagepresentor.h"
|
||
#include "wizardpagemodel.h"
|
||
#include "wizardpageactivity.h"
|
||
#include "formatconverter.h"
|
||
#include "settingsrepository.h"
|
||
#include "wizardpageactivity.h"
|
||
#include "QDir"
|
||
|
||
WizardPagePresentor::WizardPagePresentor( WizardPageActivity * activity,QObject *parent)
|
||
: QObject{parent}, activity(activity)
|
||
{
|
||
model = new WizardPageModel();
|
||
init();
|
||
}
|
||
|
||
void WizardPagePresentor::init()
|
||
{
|
||
model->setStage(WizardPageModel::ChooseFiles);
|
||
activity->setModel(model);
|
||
connect(activity, &WizardPageActivity::startTranslate, this, &WizardPagePresentor::transform);
|
||
connect(activity, &WizardPageActivity::cancelTranslate, this, &WizardPagePresentor::cancelTransform);
|
||
}
|
||
|
||
void WizardPagePresentor::transform() {
|
||
qDebug() << "transform clicked";
|
||
if (formatConverter == 0) {
|
||
formatConverter = new FormatConverter();
|
||
connect(formatConverter,&FormatConverter::convertedFinished, this,&WizardPagePresentor::transformFinished);
|
||
connect(formatConverter,&FormatConverter::convertedFinishedWithError, this,&WizardPagePresentor::transformFinishedWithError);
|
||
connect(formatConverter, &FormatConverter::percentCompetedChanged, this, &WizardPagePresentor::percentCompetedChanged);
|
||
}
|
||
|
||
QStringList stringList = model->getListSelectedFiles();
|
||
|
||
QString projectName = model->getProjectName();
|
||
QString projectPath = SettingsRepository::instance().defaultProjectDirectory() +"\\" + projectName;
|
||
QDir projectDir(SettingsRepository::instance().defaultProjectDirectory());
|
||
|
||
if (projectDir.exists(projectPath) == false) {
|
||
projectDir.mkdir(projectPath);
|
||
projectDir.setPath(projectPath);
|
||
projectPath = projectDir.absolutePath();
|
||
model->setProjectPath(projectPath);
|
||
|
||
model->setIsTranslating(true);
|
||
formatConverter->convert(stringList, projectPath);
|
||
} else {
|
||
// Дирректория уже существаует, спрашиваем перезаписать её.
|
||
projectDir.setPath(projectPath);
|
||
|
||
projectPath = projectDir.absolutePath();
|
||
|
||
doActionOnSuccessReplaceProject = [this, projectPath,stringList] {
|
||
model->setProjectPath(projectPath);
|
||
model->setIsTranslating(true);
|
||
formatConverter->convert(stringList, projectPath);
|
||
};
|
||
|
||
doActionOnFailedReplaceProject = [this, projectPath] {
|
||
activity->previosStage();
|
||
};
|
||
|
||
QString header = "Подтверждение перезаписи";
|
||
QString content = "Проект уже существует. Вы точно хотите его перезаписать?";
|
||
emit setTextReplaceProject(header,content);
|
||
emit showDialogReplaceProject(doActionOnSuccessReplaceProject, doActionOnFailedReplaceProject);
|
||
}
|
||
}
|
||
|
||
void WizardPagePresentor::cancelTransform()
|
||
{
|
||
if(formatConverter) formatConverter->stopAllConverting();
|
||
model->setPercentCompete(0);
|
||
model->setIsTranslating(false);
|
||
}
|
||
|
||
void WizardPagePresentor::percentCompetedChanged(double percent)
|
||
{
|
||
model->setPercentCompete(percent);
|
||
}
|
||
|
||
void WizardPagePresentor::showDialogMessage()
|
||
{
|
||
|
||
}
|
||
|
||
void WizardPagePresentor::transformFinished()
|
||
{
|
||
emit projectAddedSuccessful(model->getProjectPath());
|
||
model->setIsTranslating(false);
|
||
activity->nextStage();
|
||
}
|
||
|
||
void WizardPagePresentor::transformFinishedWithError(QStringList listErrorFilesPath, QString pathLog)
|
||
{
|
||
model->setIsTranslating(false);
|
||
|
||
QString errorMsg = R"(
|
||
Невозможно преобразовать следующие файлы:
|
||
)";
|
||
for(const auto &filePath: listErrorFilesPath){
|
||
errorMsg += filePath + "\n";
|
||
}
|
||
|
||
emit showCustomMessage(errorMsg,pathLog);
|
||
}
|
||
|
||
|
||
|
||
|