Stellarium 0.11.4
Home · All Namespaces · All Classes · Functions · Coding Style · Scripting · Plugins · File Structure

scripting/StelScriptMgr.hpp

00001 /*
00002  * Stellarium
00003  * Copyright (C) 2007 Fabien Chereau, 2009 Matthew Gates
00004  *
00005  * This program is free software; you can redistribute it and/or
00006  * modify it under the terms of the GNU General Public License
00007  * as published by the Free Software Foundation; either version 2
00008  * of the License, or (at your option) any later version.
00009  *
00010  * This program is distributed in the hope that it will be useful,
00011  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00012  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00013  * GNU General Public License for more details.
00014  *
00015  * You should have received a copy of the GNU General Public License
00016  * along with this program; if not, write to the Free Software
00017  * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA  02110-1335, USA.
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 public slots:
00068     const QString getName(const QString& s);
00069 
00076     const QString getAuthor(const QString& s);
00077 
00084     const QString getLicense(const QString& s);
00085 
00093     const QString getDescription(const QString& s);
00094 
00103     bool runScript(const QString& fileName, const QString& includePath="");
00104 
00107     void stopScript();
00108 
00114     void setScriptRate(float r);
00115     
00118     double getScriptRate();
00119 
00122     void debug(const QString& msg);
00123 
00125     void pauseScript();
00126 
00128     void resumeScript();
00129 
00130 private slots:
00132     void scriptEnded();
00133 signals:
00135     void scriptRunning();
00137     void scriptStopped();
00139     void scriptDebug(const QString&);
00140 
00141 private:
00142     // Utility functions for preprocessor
00143     QMap<QString, QString> mappify(const QStringList& args, bool lowerKey=false);
00144     bool strToBool(const QString& str);
00145     // Pre-processor functions
00146     bool preprocessScript(QFile& input, QString& output, const QString& scriptDir);
00147 
00148 #ifdef ENABLE_STRATOSCRIPT_COMPAT
00149     bool preprocessStratoScript(QFile& input, QString& output, const QString& scriptDir);
00150 #endif
00151 
00158     const QString getHeaderSingleLineCommentText(const QString& s, const QString& id, const QString& notFoundText="");  
00159     QScriptEngine engine;
00160     
00162     StelMainScriptAPI *mainAPI;
00163 
00164     QString scriptFileName;
00165     
00166     //Script engine agent
00167     StelScriptEngineAgent *agent;
00168     
00169 };
00170 
00171 class StelScriptEngineAgent : public QScriptEngineAgent
00172 {
00173 public:
00174     explicit StelScriptEngineAgent(QScriptEngine *engine);
00175     virtual ~StelScriptEngineAgent() {}
00176 
00177     void setPauseScript(bool pause) { isPaused=pause; }
00178     bool getPauseScript() { return isPaused; }
00179 
00180     void positionChange(qint64 scriptId, int lineNumber, int columnNumber);
00181     
00182 private:
00183     bool isPaused;
00184 
00185 };
00186 
00187 #endif // _STELSCRIPTMGR_HPP_
Generated on Sat Aug 25 22:13:30 2012 for Stellarium by  doxygen 1.6.3