--- Vago/trunk/Vago/converter.cpp 2013/03/31 19:02:16 771 +++ Vago/trunk/Vago/converter.cpp 2014/01/08 11:32:55 897 @@ -1,18 +1,22 @@ #include "converter.h" -Converter::Converter(Logger *myLogger, QStringList *myData) +Converter::Converter(QString AppDir, Logger *myLogger, QStringList *myData) { + this->AppDir=AppDir; this->myLogger=myLogger; this->myData=myData; } void Converter::run() { - QProcess *myProcess = new QProcess(); + this->processHasKilled=false; + this->myProcess = new QProcess(); QString result = QString(); QString errorMessage = ""; int numErrors=0; + myProcess->setWorkingDirectory(this->AppDir); // Set working directory (for work with AEI2/Mac OS) + if(this->myData->size()!=1){ emit setupPB(this->myData->size()); } @@ -20,8 +24,6 @@ void Converter::run() emit setupPB(0); //Intermitent bar, we don't have any estimation when the task is done } - //myProcess->setProcessChannelMode(QProcess::MergedChannels); //we want both stdout and stderr - for(int i=0; imyData->size(); i++){ QString commands=this->myData->at(i); @@ -33,9 +35,17 @@ void Converter::run() nextIndex=commands.indexOf(GlobalVars::OniSplitProcSeparator,currentIndex+1); commandToExec=commands.mid(currentIndex,(nextIndex-currentIndex)); - myProcess->start(GlobalVars::OniSplitExeName+" "+commandToExec); - myProcess->waitForFinished(-1); - result=myProcess->readAllStandardError(); + this->myProcess->start(GlobalVars::OniSplitExeName+" "+commandToExec); + this->myProcess->waitForFinished(-1); + + if(this->processHasKilled){ // If the process has killed there's no need to proceed with reading output or process more commands + delete this->myProcess; //delete object and make pointer invalid + this->myData->clear(); //clean list + emit conversionAborted(); + return; + } + + result=this->myProcess->readAllStandardError(); if(!result.isEmpty()){ //if(!result.startsWith("Importing",Qt::CaseSensitive) && !result.startsWith("Importing",Qt::CaseSensitive)){ //case sensitive is faster //catch exception @@ -53,7 +63,7 @@ void Converter::run() emit taskDone(); } - delete myProcess; //delete object and make pointer invalid + delete this->myProcess; //delete object and make pointer invalid this->myData->clear(); //clean list //let's cut it a bit, complete error is in log file. @@ -67,3 +77,9 @@ void Converter::run() emit resultConversion(errorMessage,numErrors); } +// Kill the process if requested +void Converter::terminateCurrProcess(){ + this->myProcess->kill(); + this->processHasKilled=true; + this->myLogger->writeString("Received signal to kill current OniSplit operation (user requested)."); +}