diff --git a/apps/opencs/CMakeLists.txt b/apps/opencs/CMakeLists.txt index 2574eb111..5fbd0c5dd 100644 --- a/apps/opencs/CMakeLists.txt +++ b/apps/opencs/CMakeLists.txt @@ -5,7 +5,7 @@ opencs_units (. editor) set (CMAKE_BUILD_TYPE DEBUG) opencs_units (model/doc - document operation saving documentmanager loader + document operation saving documentmanager loader runner ) opencs_units_noqt (model/doc diff --git a/apps/opencs/model/doc/document.cpp b/apps/opencs/model/doc/document.cpp index c608757e0..f4eb72b6b 100644 --- a/apps/opencs/model/doc/document.cpp +++ b/apps/opencs/model/doc/document.cpp @@ -2367,6 +2367,16 @@ bool CSMDoc::Document::isBlacklisted (const CSMWorld::UniversalId& id) return mBlacklist.isBlacklisted (id); } +void CSMDoc::Document::startRunning (const std::string& profile, + const std::string& startupInstruction) +{ + mRunner.start(); +} + +void CSMDoc::Document::stopRunning() +{ + mRunner.stop(); +} void CSMDoc::Document::progress (int current, int max, int type) { diff --git a/apps/opencs/model/doc/document.hpp b/apps/opencs/model/doc/document.hpp index d0e94d5e0..9efee352d 100644 --- a/apps/opencs/model/doc/document.hpp +++ b/apps/opencs/model/doc/document.hpp @@ -18,6 +18,7 @@ #include "state.hpp" #include "saving.hpp" #include "blacklist.hpp" +#include "runner.hpp" class QAbstractItemModel; @@ -54,6 +55,7 @@ namespace CSMDoc Saving mSaving; boost::filesystem::path mResDir; Blacklist mBlacklist; + Runner mRunner; // It is important that the undo stack is declared last, because on desctruction it fires a signal, that is connected to a slot, that is // using other member variables. Unfortunately this connection is cut only in the QObject destructor, which is way too late. @@ -115,6 +117,11 @@ namespace CSMDoc bool isBlacklisted (const CSMWorld::UniversalId& id) const; + void startRunning (const std::string& profile, + const std::string& startupInstruction = ""); + + void stopRunning(); + signals: void stateChanged (int state, CSMDoc::Document *document); diff --git a/apps/opencs/model/doc/runner.cpp b/apps/opencs/model/doc/runner.cpp new file mode 100644 index 000000000..dd8e745b2 --- /dev/null +++ b/apps/opencs/model/doc/runner.cpp @@ -0,0 +1,35 @@ + +#include "runner.hpp" + + +CSMDoc::Runner::Runner() +{ + connect (&mProcess, SIGNAL (finished (int, QProcess::ExitStatus)), + this, SLOT (finished (int, QProcess::ExitStatus))); +} + +void CSMDoc::Runner::start() +{ + QString path = "openmw"; +#ifdef Q_OS_WIN + path.append(QString(".exe")); +#elif defined(Q_OS_MAC) + QDir dir(QCoreApplication::applicationDirPath()); + path = dir.absoluteFilePath(name); +#else + path.prepend(QString("./")); +#endif + + mProcess.start (path); + emit runStateChanged (true); +} + +void CSMDoc::Runner::stop() +{ + mProcess.kill(); +} + +void CSMDoc::Runner::finished (int exitCode, QProcess::ExitStatus exitStatus) +{ + emit runStateChanged (false); +} diff --git a/apps/opencs/model/doc/runner.hpp b/apps/opencs/model/doc/runner.hpp new file mode 100644 index 000000000..8ab73fcf3 --- /dev/null +++ b/apps/opencs/model/doc/runner.hpp @@ -0,0 +1,33 @@ +#ifndef CSM_DOC_RUNNER_H +#define CSM_DOC_RUNNER_H + +#include +#include + +namespace CSMDoc +{ + class Runner : public QObject + { + Q_OBJECT + + QProcess mProcess; + + public: + + Runner(); + + void start(); + + void stop(); + + signals: + + void runStateChanged (bool running); + + private slots: + + void finished (int exitCode, QProcess::ExitStatus exitStatus); + }; +} + +#endif diff --git a/apps/opencs/view/doc/view.cpp b/apps/opencs/view/doc/view.cpp index acd415034..9d1bb40e8 100644 --- a/apps/opencs/view/doc/view.cpp +++ b/apps/opencs/view/doc/view.cpp @@ -239,6 +239,16 @@ void CSVDoc::View::setupDebugMenu() QAction *profiles = new QAction (tr ("Debug Profiles"), this); connect (profiles, SIGNAL (triggered()), this, SLOT (addDebugProfilesSubView())); debug->addAction (profiles); + + debug->addSeparator(); + + QAction *run = new QAction (tr ("Run OpenMW"), this); + connect (run, SIGNAL (triggered()), this, SLOT (run())); + debug->addAction (run); + + QAction *stop = new QAction (tr ("Shutdown OpenMW"), this); + connect (stop, SIGNAL (triggered()), this, SLOT (stop())); + debug->addAction (stop); } void CSVDoc::View::setupUi() @@ -603,3 +613,13 @@ void CSVDoc::View::loadErrorLog() { addSubView (CSMWorld::UniversalId (CSMWorld::UniversalId::Type_LoadErrorLog, 0)); } + +void CSVDoc::View::run() +{ + mDocument->startRunning ("", ""); +} + +void CSVDoc::View::stop() +{ + mDocument->stopRunning(); +} \ No newline at end of file diff --git a/apps/opencs/view/doc/view.hpp b/apps/opencs/view/doc/view.hpp index a76429315..dca8f4b22 100644 --- a/apps/opencs/view/doc/view.hpp +++ b/apps/opencs/view/doc/view.hpp @@ -201,6 +201,10 @@ namespace CSVDoc void toggleShowStatusBar (bool show); void loadErrorLog(); + + void run(); + + void stop(); }; }