2012-12-08 10:59:13 +00:00
|
|
|
|
|
|
|
#include "tools.hpp"
|
|
|
|
|
|
|
|
#include <QThreadPool>
|
|
|
|
|
2012-12-08 13:44:03 +00:00
|
|
|
#include "../doc/state.hpp"
|
2013-09-14 13:16:31 +00:00
|
|
|
#include "../doc/operation.hpp"
|
2012-12-08 10:59:13 +00:00
|
|
|
|
2012-12-08 22:27:59 +00:00
|
|
|
#include "../world/data.hpp"
|
2012-12-11 14:35:47 +00:00
|
|
|
#include "../world/universalid.hpp"
|
2012-12-08 22:27:59 +00:00
|
|
|
|
2012-12-11 14:35:47 +00:00
|
|
|
#include "reportmodel.hpp"
|
2012-12-08 22:27:59 +00:00
|
|
|
#include "mandatoryid.hpp"
|
2013-03-25 10:07:04 +00:00
|
|
|
#include "skillcheck.hpp"
|
2013-04-04 08:10:26 +00:00
|
|
|
#include "classcheck.hpp"
|
2013-04-04 08:39:43 +00:00
|
|
|
#include "factioncheck.hpp"
|
2013-04-06 15:35:36 +00:00
|
|
|
#include "racecheck.hpp"
|
2013-04-06 19:48:52 +00:00
|
|
|
#include "soundcheck.hpp"
|
2013-04-07 17:39:13 +00:00
|
|
|
#include "regioncheck.hpp"
|
2013-04-07 21:25:35 +00:00
|
|
|
#include "birthsigncheck.hpp"
|
2013-04-09 10:44:49 +00:00
|
|
|
#include "spellcheck.hpp"
|
2013-12-20 19:02:42 +00:00
|
|
|
#include "referenceablecheck.hpp"
|
2012-12-08 22:27:59 +00:00
|
|
|
|
2013-12-30 12:23:16 +00:00
|
|
|
CSMDoc::Operation* CSMTools::Tools::get(int type)
|
2012-12-08 16:00:58 +00:00
|
|
|
{
|
|
|
|
switch (type)
|
|
|
|
{
|
|
|
|
case CSMDoc::State_Verifying: return mVerifier;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2013-12-30 12:23:16 +00:00
|
|
|
const CSMDoc::Operation* CSMTools::Tools::get(int type) const
|
2012-12-08 16:00:58 +00:00
|
|
|
{
|
2013-12-30 12:23:16 +00:00
|
|
|
return const_cast<Tools*>(this)->get(type);
|
2012-12-08 16:00:58 +00:00
|
|
|
}
|
|
|
|
|
2013-12-30 12:23:16 +00:00
|
|
|
CSMDoc::Operation* CSMTools::Tools::getVerifier()
|
2012-12-08 10:59:13 +00:00
|
|
|
{
|
|
|
|
if (!mVerifier)
|
|
|
|
{
|
2013-12-30 12:23:16 +00:00
|
|
|
mVerifier = new CSMDoc::Operation(CSMDoc::State_Verifying, false);
|
2012-12-08 10:59:13 +00:00
|
|
|
|
2013-12-30 12:23:16 +00:00
|
|
|
connect(mVerifier, SIGNAL(progress(int, int, int)), this, SIGNAL(progress(int, int, int)));
|
|
|
|
connect(mVerifier, SIGNAL(done(int)), this, SIGNAL(done(int)));
|
|
|
|
connect(mVerifier, SIGNAL(reportMessage(const QString&, int)),
|
|
|
|
this, SLOT(verifierMessage(const QString&, int)));
|
2012-12-08 22:27:59 +00:00
|
|
|
|
|
|
|
std::vector<std::string> mandatoryIds; // I want C++11, damn it!
|
2013-12-30 12:23:16 +00:00
|
|
|
mandatoryIds.push_back("Day");
|
|
|
|
mandatoryIds.push_back("DaysPassed");
|
|
|
|
mandatoryIds.push_back("GameHour");
|
|
|
|
mandatoryIds.push_back("Month");
|
|
|
|
mandatoryIds.push_back("PCRace");
|
|
|
|
mandatoryIds.push_back("PCVampire");
|
|
|
|
mandatoryIds.push_back("PCWerewolf");
|
|
|
|
mandatoryIds.push_back("PCYear");
|
2012-12-08 22:27:59 +00:00
|
|
|
|
2013-12-30 12:23:16 +00:00
|
|
|
mVerifier->appendStage(new MandatoryIdStage(mData.getGlobals(),
|
|
|
|
CSMWorld::UniversalId(CSMWorld::UniversalId::Type_Globals), mandatoryIds));
|
2013-03-25 10:07:04 +00:00
|
|
|
|
2013-12-30 12:23:16 +00:00
|
|
|
mVerifier->appendStage(new SkillCheckStage(mData.getSkills()));
|
2013-04-04 08:10:26 +00:00
|
|
|
|
2013-12-30 12:23:16 +00:00
|
|
|
mVerifier->appendStage(new ClassCheckStage(mData.getClasses()));
|
2013-04-04 08:39:43 +00:00
|
|
|
|
2013-12-30 12:23:16 +00:00
|
|
|
mVerifier->appendStage(new FactionCheckStage(mData.getFactions()));
|
2013-04-06 15:35:36 +00:00
|
|
|
|
2013-12-30 12:23:16 +00:00
|
|
|
mVerifier->appendStage(new RaceCheckStage(mData.getRaces()));
|
2013-04-06 19:48:52 +00:00
|
|
|
|
2013-12-30 12:23:16 +00:00
|
|
|
mVerifier->appendStage(new SoundCheckStage(mData.getSounds()));
|
2013-04-07 17:39:13 +00:00
|
|
|
|
2013-12-30 12:23:16 +00:00
|
|
|
mVerifier->appendStage(new RegionCheckStage(mData.getRegions()));
|
2013-04-07 21:25:35 +00:00
|
|
|
|
2013-12-30 12:23:16 +00:00
|
|
|
mVerifier->appendStage(new BirthsignCheckStage(mData.getBirthsigns()));
|
2013-04-09 10:44:49 +00:00
|
|
|
|
2013-12-30 12:23:16 +00:00
|
|
|
mVerifier->appendStage(new SpellCheckStage(mData.getSpells()));
|
|
|
|
|
|
|
|
mVerifier->appendStage(new ReferenceableCheckStage(mData.getReferenceables().getDataSet(), mData.getRaces(), mData.getClasses(), mData.getFactions()));
|
2012-12-08 10:59:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return mVerifier;
|
|
|
|
}
|
|
|
|
|
2013-12-30 12:23:16 +00:00
|
|
|
CSMTools::Tools::Tools(CSMWorld::Data& data) : mData(data), mVerifier(0), mNextReportNumber(0)
|
2012-12-08 10:59:13 +00:00
|
|
|
{
|
2013-12-30 12:23:16 +00:00
|
|
|
for (std::map<int, ReportModel*>::iterator iter(mReports.begin()); iter != mReports.end(); ++iter)
|
2012-12-11 14:35:47 +00:00
|
|
|
delete iter->second;
|
2012-12-08 10:59:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
CSMTools::Tools::~Tools()
|
|
|
|
{
|
|
|
|
delete mVerifier;
|
|
|
|
}
|
|
|
|
|
2012-12-11 14:35:47 +00:00
|
|
|
CSMWorld::UniversalId CSMTools::Tools::runVerifier()
|
2012-12-08 10:59:13 +00:00
|
|
|
{
|
2013-12-30 12:23:16 +00:00
|
|
|
mReports.insert(std::make_pair(mNextReportNumber++, new ReportModel));
|
|
|
|
mActiveReports[CSMDoc::State_Verifying] = mNextReportNumber - 1;
|
2012-12-11 14:35:47 +00:00
|
|
|
|
2012-12-08 10:59:13 +00:00
|
|
|
getVerifier()->start();
|
2012-12-11 14:35:47 +00:00
|
|
|
|
2013-12-30 12:23:16 +00:00
|
|
|
return CSMWorld::UniversalId(CSMWorld::UniversalId::Type_VerificationResults, mNextReportNumber - 1);
|
2012-12-08 10:59:13 +00:00
|
|
|
}
|
|
|
|
|
2013-12-30 12:23:16 +00:00
|
|
|
void CSMTools::Tools::abortOperation(int type)
|
2012-12-08 10:59:13 +00:00
|
|
|
{
|
2013-12-30 12:23:16 +00:00
|
|
|
if (CSMDoc::Operation* operation = get(type))
|
2012-12-08 16:00:58 +00:00
|
|
|
operation->abort();
|
|
|
|
}
|
|
|
|
|
|
|
|
int CSMTools::Tools::getRunningOperations() const
|
|
|
|
{
|
|
|
|
static const int sOperations[] =
|
|
|
|
{
|
2013-12-30 12:23:16 +00:00
|
|
|
CSMDoc::State_Verifying,
|
2012-12-08 16:00:58 +00:00
|
|
|
-1
|
|
|
|
};
|
|
|
|
|
|
|
|
int result = 0;
|
|
|
|
|
2013-12-30 12:23:16 +00:00
|
|
|
for (int i = 0; sOperations[i] != -1; ++i)
|
|
|
|
if (const CSMDoc::Operation* operation = get(sOperations[i]))
|
2012-12-08 16:00:58 +00:00
|
|
|
if (operation->isRunning())
|
|
|
|
result |= sOperations[i];
|
2012-12-08 10:59:13 +00:00
|
|
|
|
2012-12-08 16:00:58 +00:00
|
|
|
return result;
|
2012-12-08 10:59:13 +00:00
|
|
|
}
|
|
|
|
|
2013-12-30 12:23:16 +00:00
|
|
|
CSMTools::ReportModel* CSMTools::Tools::getReport(const CSMWorld::UniversalId& id)
|
2012-12-11 14:35:47 +00:00
|
|
|
{
|
2013-12-30 12:23:16 +00:00
|
|
|
if (id.getType() != CSMWorld::UniversalId::Type_VerificationResults)
|
|
|
|
throw std::logic_error("invalid request for report model: " + id.toString());
|
2012-12-11 14:35:47 +00:00
|
|
|
|
2013-12-30 12:23:16 +00:00
|
|
|
return mReports.at(id.getIndex());
|
2012-12-11 14:35:47 +00:00
|
|
|
}
|
|
|
|
|
2013-12-30 12:23:16 +00:00
|
|
|
void CSMTools::Tools::verifierMessage(const QString& message, int type)
|
2012-12-08 17:38:36 +00:00
|
|
|
{
|
2013-12-30 12:23:16 +00:00
|
|
|
std::map<int, int>::iterator iter = mActiveReports.find(type);
|
2012-12-08 17:38:36 +00:00
|
|
|
|
2013-12-30 12:23:16 +00:00
|
|
|
if (iter != mActiveReports.end())
|
|
|
|
mReports[iter->second]->add(message.toStdString());
|
2013-12-20 19:02:42 +00:00
|
|
|
}
|