1
0
Fork 1
mirror of https://github.com/TES3MP/openmw-tes3mp.git synced 2025-01-16 05:49:56 +00:00
openmw-tes3mp/apps/opencs/model/doc/runner.cpp

81 lines
1.5 KiB
C++
Raw Normal View History

2014-09-02 08:21:17 +00:00
#include "runner.hpp"
#include "operation.hpp"
2014-09-02 08:21:17 +00:00
CSMDoc::Runner::Runner() : mRunning (false)
2014-09-02 08:21:17 +00:00
{
connect (&mProcess, SIGNAL (finished (int, QProcess::ExitStatus)),
this, SLOT (finished (int, QProcess::ExitStatus)));
}
CSMDoc::Runner::~Runner()
{
if (mRunning)
{
disconnect (&mProcess, 0, this, 0);
mProcess.kill();
mProcess.waitForFinished();
}
}
void CSMDoc::Runner::start (bool delayed)
2014-09-02 08:21:17 +00:00
{
if (!delayed)
{
QString path = "openmw";
2014-09-02 08:21:17 +00:00
#ifdef Q_OS_WIN
path.append(QString(".exe"));
2014-09-02 08:21:17 +00:00
#elif defined(Q_OS_MAC)
QDir dir(QCoreApplication::applicationDirPath());
path = dir.absoluteFilePath(name);
2014-09-02 08:21:17 +00:00
#else
path.prepend(QString("./"));
2014-09-02 08:21:17 +00:00
#endif
mProcess.start (path);
}
mRunning = true;
emit runStateChanged();
2014-09-02 08:21:17 +00:00
}
void CSMDoc::Runner::stop()
{
if (mProcess.state()==QProcess::NotRunning)
{
mRunning = false;
emit runStateChanged();
}
else
mProcess.kill();
2014-09-02 08:21:17 +00:00
}
bool CSMDoc::Runner::isRunning() const
{
return mRunning;
}
2014-09-02 08:21:17 +00:00
void CSMDoc::Runner::finished (int exitCode, QProcess::ExitStatus exitStatus)
{
mRunning = false;
emit runStateChanged();
2014-09-02 08:21:17 +00:00
}
CSMDoc::SaveWatcher::SaveWatcher (Runner *runner, Operation *operation)
: QObject (runner), mRunner (runner)
{
connect (operation, SIGNAL (done (int, bool)), this, SLOT (saveDone (int, bool)));
}
void CSMDoc::SaveWatcher::saveDone (int type, bool failed)
{
if (failed)
mRunner->stop();
else
mRunner->start();
deleteLater();
}