StelScriptMgr.hpp
00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #ifndef _STELSCRIPTMGR_HPP_
00021 #define _STELSCRIPTMGR_HPP_
00022
00023 #include <QObject>
00024 #include <QtScript>
00025 #include <QStringList>
00026 #include <QFile>
00027 #include <QTime>
00028 #include <QTimer>
00029 #include <QScriptEngineAgent>
00030
00031 class StelMainScriptAPI;
00032 class StelScriptEngineAgent;
00033
00034 #ifdef ENABLE_SCRIPT_CONSOLE
00035 class ScriptConsole;
00036 #endif
00037
00039 class StelScriptMgr : public QObject
00040 {
00041 Q_OBJECT
00042
00043 #ifdef ENABLE_SCRIPT_CONSOLE
00044 friend class ScriptConsole;
00045 #endif
00046
00047 public:
00048 StelScriptMgr(QObject *parent=0);
00049 ~StelScriptMgr();
00050
00051 QStringList getScriptList();
00052
00055 bool scriptIsRunning();
00059 QString runningScriptId();
00060
00061
00062 bool preprocessScript(const QString& input, QString& output, const QString& scriptDir);
00063 bool preprocessScript(QFile &input, QString& output, const QString& scriptDir);
00064
00066 void addModules();
00067 public slots:
00074 const QString getName(const QString& s);
00075
00082 const QString getAuthor(const QString& s);
00083
00090 const QString getLicense(const QString& s);
00091
00099 const QString getDescription(const QString& s);
00100
00104 bool runPreprocessedScript(const QString& preprocessedScript);
00105
00114 bool runScript(const QString& fileName, const QString& includePath="");
00115
00118 void stopScript();
00119
00125 void setScriptRate(float r);
00126
00129 double getScriptRate();
00130
00133 void debug(const QString& msg);
00134
00136 void pauseScript();
00137
00139 void resumeScript();
00140
00141 private slots:
00143 void scriptEnded();
00144 signals:
00146 void scriptRunning();
00148 void scriptStopped();
00150 void scriptDebug(const QString&);
00151
00152 private:
00153
00154 QMap<QString, QString> mappify(const QStringList& args, bool lowerKey=false);
00155 bool strToBool(const QString& str);
00156
00157 #ifdef ENABLE_STRATOSCRIPT_COMPAT
00158 bool preprocessStratoScript(QFile& input, QString& output, const QString& scriptDir);
00159 #endif
00160
00167 const QString getHeaderSingleLineCommentText(const QString& s, const QString& id, const QString& notFoundText="");
00168 QScriptEngine engine;
00169
00171 StelMainScriptAPI *mainAPI;
00172
00173 QString scriptFileName;
00174
00175
00176 StelScriptEngineAgent *agent;
00177
00178 };
00179
00180 class StelScriptEngineAgent : public QScriptEngineAgent
00181 {
00182 public:
00183 explicit StelScriptEngineAgent(QScriptEngine *engine);
00184 virtual ~StelScriptEngineAgent() {}
00185
00186 void setPauseScript(bool pause) { isPaused=pause; }
00187 bool getPauseScript() { return isPaused; }
00188
00189 void positionChange(qint64 scriptId, int lineNumber, int columnNumber);
00190
00191 private:
00192 bool isPaused;
00193
00194 };
00195
00196 #endif // _STELSCRIPTMGR_HPP_