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., 59 Temple Place - Suite 330, Boston, MA  02111-1307, 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 
00030 class StelMainScriptAPI;
00031 
00032 #ifdef ENABLE_SCRIPT_CONSOLE
00033 class ScriptConsole;
00034 #endif
00035 
00037 class StelScriptMgr : public QObject
00038 {
00039     Q_OBJECT
00040         
00041 #ifdef ENABLE_SCRIPT_CONSOLE
00042 friend class ScriptConsole;
00043 #endif
00044 
00045 public:
00046     StelScriptMgr(QObject *parent=0);
00047     ~StelScriptMgr();
00048 
00049     QStringList getScriptList();
00050 
00053     bool scriptIsRunning();
00057     QString runningScriptId();
00058     
00059 public slots:
00066     const QString getName(const QString& s);
00067 
00074     const QString getAuthor(const QString& s);
00075 
00082     const QString getLicense(const QString& s);
00083 
00091     const QString getDescription(const QString& s);
00092 
00101     bool runScript(const QString& fileName, const QString& includePath="");
00102 
00105     void stopScript();
00106 
00112     void setScriptRate(float r);
00113     
00116     double getScriptRate();
00117 
00120     void debug(const QString& msg);
00121 
00122 private slots:
00124     void scriptEnded();
00125 
00126 signals:
00128     void scriptRunning();
00130     void scriptStopped();
00132     void scriptDebug(const QString&);
00133 
00134 private:
00135     // Utility functions for preprocessor
00136     QMap<QString, QString> mappify(const QStringList& args, bool lowerKey=false);
00137     bool strToBool(const QString& str);
00138     // Pre-processor functions
00139     bool preprocessScript(QFile& input, QString& output, const QString& scriptDir);
00140 
00141 #ifdef ENABLE_STRATOSCRIPT_COMPAT
00142     bool preprocessStratoScript(QFile& input, QString& output, const QString& scriptDir);
00143 #endif
00144 
00151     const QString getHeaderSingleLineCommentText(const QString& s, const QString& id, const QString& notFoundText="");  
00152     QScriptEngine engine;
00153     
00155     StelMainScriptAPI *mainAPI;
00156 
00157     QString scriptFileName;
00158     
00159 };
00160 
00161 #endif // _STELSCRIPTMGR_HPP_