From cf05d3c69f64fef6f82a4570191b3975e0cfded9 Mon Sep 17 00:00:00 2001 From: Marc Zinnschlag Date: Fri, 5 Sep 2014 13:49:34 +0200 Subject: [PATCH] added run log --- apps/opencs/CMakeLists.txt | 2 +- apps/opencs/model/doc/document.cpp | 5 +++++ apps/opencs/model/doc/document.hpp | 2 ++ apps/opencs/model/doc/runner.cpp | 18 ++++++++++++++++++ apps/opencs/model/doc/runner.hpp | 6 ++++++ apps/opencs/model/world/universalid.cpp | 1 + apps/opencs/model/world/universalid.hpp | 3 ++- apps/opencs/view/doc/runlogsubview.cpp | 20 ++++++++++++++++++++ apps/opencs/view/doc/runlogsubview.hpp | 20 ++++++++++++++++++++ apps/opencs/view/doc/view.cpp | 13 +++++++++++++ apps/opencs/view/doc/view.hpp | 2 ++ 11 files changed, 90 insertions(+), 2 deletions(-) create mode 100644 apps/opencs/view/doc/runlogsubview.cpp create mode 100644 apps/opencs/view/doc/runlogsubview.hpp diff --git a/apps/opencs/CMakeLists.txt b/apps/opencs/CMakeLists.txt index c88f791ab..417d57981 100644 --- a/apps/opencs/CMakeLists.txt +++ b/apps/opencs/CMakeLists.txt @@ -44,7 +44,7 @@ opencs_units_noqt (model/tools opencs_units (view/doc viewmanager view operations operation subview startup filedialog newgame - filewidget adjusterwidget loader globaldebugprofilemenu + filewidget adjusterwidget loader globaldebugprofilemenu runlogsubview ) diff --git a/apps/opencs/model/doc/document.cpp b/apps/opencs/model/doc/document.cpp index 17d624be7..8e414fb9c 100644 --- a/apps/opencs/model/doc/document.cpp +++ b/apps/opencs/model/doc/document.cpp @@ -2399,6 +2399,11 @@ void CSMDoc::Document::stopRunning() mRunner.stop(); } +QTextDocument *CSMDoc::Document::getRunLog() +{ + return mRunner.getLog(); +} + void CSMDoc::Document::runStateChanged() { emit stateChanged (getState(), this); diff --git a/apps/opencs/model/doc/document.hpp b/apps/opencs/model/doc/document.hpp index 4fedd8f40..29235e6e4 100644 --- a/apps/opencs/model/doc/document.hpp +++ b/apps/opencs/model/doc/document.hpp @@ -122,6 +122,8 @@ namespace CSMDoc void stopRunning(); + QTextDocument *getRunLog(); + signals: void stateChanged (int state, CSMDoc::Document *document); diff --git a/apps/opencs/model/doc/runner.cpp b/apps/opencs/model/doc/runner.cpp index 67bd5e4d2..295733a5a 100644 --- a/apps/opencs/model/doc/runner.cpp +++ b/apps/opencs/model/doc/runner.cpp @@ -11,6 +11,11 @@ CSMDoc::Runner::Runner() : mRunning (false), mStartup (0) connect (&mProcess, SIGNAL (finished (int, QProcess::ExitStatus)), this, SLOT (finished (int, QProcess::ExitStatus))); + connect (&mProcess, SIGNAL (readyReadStandardOutput()), + this, SLOT (readyReadStandardOutput())); + + mProcess.setProcessChannelMode (QProcess::MergedChannels); + mProfile.blank(); } @@ -34,6 +39,8 @@ void CSMDoc::Runner::start (bool delayed) if (!delayed) { + mLog.clear(); + QString path = "openmw"; #ifdef Q_OS_WIN path.append(QString(".exe")); @@ -107,6 +114,17 @@ void CSMDoc::Runner::finished (int exitCode, QProcess::ExitStatus exitStatus) emit runStateChanged(); } +QTextDocument *CSMDoc::Runner::getLog() +{ + return &mLog; +} + +void CSMDoc::Runner::readyReadStandardOutput() +{ + mLog.setPlainText ( + mLog.toPlainText() + QString::fromUtf8 (mProcess.readAllStandardOutput())); +} + CSMDoc::SaveWatcher::SaveWatcher (Runner *runner, Operation *operation) : QObject (runner), mRunner (runner) diff --git a/apps/opencs/model/doc/runner.hpp b/apps/opencs/model/doc/runner.hpp index f63968e3b..9d0273f3e 100644 --- a/apps/opencs/model/doc/runner.hpp +++ b/apps/opencs/model/doc/runner.hpp @@ -3,6 +3,7 @@ #include #include +#include #include @@ -19,6 +20,7 @@ namespace CSMDoc ESM::DebugProfile mProfile; std::string mStartupInstruction; QTemporaryFile *mStartup; + QTextDocument mLog; public: @@ -39,6 +41,8 @@ namespace CSMDoc void configure (const ESM::DebugProfile& profile, const std::string& startupInstruction); + QTextDocument *getLog(); + signals: void runStateChanged(); @@ -46,6 +50,8 @@ namespace CSMDoc private slots: void finished (int exitCode, QProcess::ExitStatus exitStatus); + + void readyReadStandardOutput(); }; class Operation; diff --git a/apps/opencs/model/world/universalid.cpp b/apps/opencs/model/world/universalid.cpp index 7d2cce0de..d338a4a3b 100644 --- a/apps/opencs/model/world/universalid.cpp +++ b/apps/opencs/model/world/universalid.cpp @@ -51,6 +51,7 @@ namespace { CSMWorld::UniversalId::Class_ResourceList, CSMWorld::UniversalId::Type_Textures, "Textures", 0 }, { CSMWorld::UniversalId::Class_ResourceList, CSMWorld::UniversalId::Type_Videos, "Videos", 0 }, { CSMWorld::UniversalId::Class_RecordList, CSMWorld::UniversalId::Type_DebugProfiles, "Debug Profiles", 0 }, + { CSMWorld::UniversalId::Class_Transient, CSMWorld::UniversalId::Type_RunLog, "Run Log", 0 }, { CSMWorld::UniversalId::Class_None, CSMWorld::UniversalId::Type_None, 0, 0 } // end marker }; diff --git a/apps/opencs/model/world/universalid.hpp b/apps/opencs/model/world/universalid.hpp index 8f3437220..069beed4b 100644 --- a/apps/opencs/model/world/universalid.hpp +++ b/apps/opencs/model/world/universalid.hpp @@ -121,7 +121,8 @@ namespace CSMWorld Type_Videos, Type_Video, Type_DebugProfiles, - Type_DebugProfile + Type_DebugProfile, + Type_RunLog }; enum { NumberOfTypes = Type_DebugProfile+1 }; diff --git a/apps/opencs/view/doc/runlogsubview.cpp b/apps/opencs/view/doc/runlogsubview.cpp new file mode 100644 index 000000000..68e888e8d --- /dev/null +++ b/apps/opencs/view/doc/runlogsubview.cpp @@ -0,0 +1,20 @@ + +#include "runlogsubview.hpp" + +#include + +CSVDoc::RunLogSubView::RunLogSubView (const CSMWorld::UniversalId& id, + CSMDoc::Document& document) +: SubView (id) +{ + QTextEdit *edit = new QTextEdit (this); + edit->setDocument (document.getRunLog()); + edit->setReadOnly (true); + + setWidget (edit); +} + +void CSVDoc::RunLogSubView::setEditLock (bool locked) +{ + // ignored since this SubView does not have editing +} \ No newline at end of file diff --git a/apps/opencs/view/doc/runlogsubview.hpp b/apps/opencs/view/doc/runlogsubview.hpp new file mode 100644 index 000000000..cfb676a37 --- /dev/null +++ b/apps/opencs/view/doc/runlogsubview.hpp @@ -0,0 +1,20 @@ +#ifndef CSV_DOC_RUNLOGSUBVIEW_H +#define CSV_DOC_RUNLOGSUBVIEW_H + +#include "subview.hpp" + +namespace CSVDoc +{ + class RunLogSubView : public SubView + { + Q_OBJECT + + public: + + RunLogSubView (const CSMWorld::UniversalId& id, CSMDoc::Document& document); + + virtual void setEditLock (bool locked); + }; +} + +#endif diff --git a/apps/opencs/view/doc/view.cpp b/apps/opencs/view/doc/view.cpp index 3abde7c77..cf5148391 100644 --- a/apps/opencs/view/doc/view.cpp +++ b/apps/opencs/view/doc/view.cpp @@ -22,6 +22,8 @@ #include "operations.hpp" #include "subview.hpp" #include "globaldebugprofilemenu.hpp" +#include "runlogsubview.hpp" +#include "subviewfactoryimp.hpp" void CSVDoc::View::closeEvent (QCloseEvent *event) { @@ -258,6 +260,10 @@ void CSVDoc::View::setupDebugMenu() mStopDebug = new QAction (tr ("Shutdown OpenMW"), this); connect (mStopDebug, SIGNAL (triggered()), this, SLOT (stop())); debug->addAction (mStopDebug); + + QAction *runLog = new QAction (tr ("Run Log"), this); + connect (runLog, SIGNAL (triggered()), this, SLOT (addRunLogSubView())); + debug->addAction (runLog); } void CSVDoc::View::setupUi() @@ -333,6 +339,8 @@ CSVDoc::View::View (ViewManager& viewManager, CSMDoc::Document *document, int to CSVWorld::addSubViewFactories (mSubViewFactory); CSVTools::addSubViewFactories (mSubViewFactory); + mSubViewFactory.add (CSMWorld::UniversalId::Type_RunLog, new SubViewFactory); + connect (mOperations, SIGNAL (abortOperation (int)), this, SLOT (abortOperation (int))); } @@ -583,6 +591,11 @@ void CSVDoc::View::addDebugProfilesSubView() addSubView (CSMWorld::UniversalId::Type_DebugProfiles); } +void CSVDoc::View::addRunLogSubView() +{ + addSubView (CSMWorld::UniversalId::Type_RunLog); +} + void CSVDoc::View::abortOperation (int type) { mDocument->abortOperation (type); diff --git a/apps/opencs/view/doc/view.hpp b/apps/opencs/view/doc/view.hpp index 23be54302..9b4f2099b 100644 --- a/apps/opencs/view/doc/view.hpp +++ b/apps/opencs/view/doc/view.hpp @@ -201,6 +201,8 @@ namespace CSVDoc void addDebugProfilesSubView(); + void addRunLogSubView(); + void toggleShowStatusBar (bool show); void loadErrorLog();