ScriptService.cpp   ScriptService.cpp 
skipping to change at line 31 skipping to change at line 31
#include "StelApp.hpp" #include "StelApp.hpp"
#include "StelScriptMgr.hpp" #include "StelScriptMgr.hpp"
#include "StelTranslator.hpp" #include "StelTranslator.hpp"
#include <QJsonDocument> #include <QJsonDocument>
#include <QJsonObject> #include <QJsonObject>
#include <QJsonArray> #include <QJsonArray>
#include <QVariant> #include <QVariant>
ScriptService::ScriptService(const QByteArray &serviceName, QObject *parent ) : AbstractAPIService(serviceName,parent) ScriptService::ScriptService(QObject *parent) : AbstractAPIService(parent)
{ {
//this is run in the main thread //this is run in the main thread
scriptMgr = &StelApp::getInstance().getScriptMgr(); scriptMgr = &StelApp::getInstance().getScriptMgr();
} }
void ScriptService::getImpl(const QByteArray& operation, const APIParameter s &parameters, APIServiceResponse &response) void ScriptService::get(const QByteArray& operation, const APIParameters &p arameters, APIServiceResponse &response)
{ {
if(operation=="list") if(operation=="list")
{ {
//list all scripts, this should be thread safe //list all scripts, this should be thread safe
QStringList allScripts = scriptMgr->getScriptList(); QStringList allScripts = scriptMgr->getScriptList();
response.writeJSON(QJsonDocument(QJsonArray::fromStringList( allScripts))); response.writeJSON(QJsonDocument(QJsonArray::fromStringList( allScripts)));
} }
else if (operation == "info") else if (operation == "info")
{ {
if(parameters.contains("id")) if(parameters.contains("id"))
{ {
//retrieve detail about a single script //retrieve detail about a single script
QString scriptId = QString::fromUtf8(parameters.valu e("id")); QString scriptId = QString::fromUtf8(parameters.valu e("id"));
if(parameters.contains("html")) if(parameters.contains("html"))
{ {
QString html = scriptMgr->getHtmlDescription (scriptId, false); QString html = scriptMgr->getHtmlDescription (scriptId, false);
response.setHeader("Content-Type","text/html response.writeWrappedHTML(html, scriptId);
; charset=UTF-8");
response.setData(wrapHtml(html, scriptId).to
Utf8());
return; return;
} }
QJsonObject obj; QJsonObject obj;
//if the script name is wrong, this will return empt y strings //if the script name is wrong, this will return empt y strings
obj.insert("id",scriptId); obj.insert("id",scriptId);
QString d = scriptMgr->getName(scriptId).trimmed(); QString d = scriptMgr->getName(scriptId).trimmed();
obj.insert("name",d); obj.insert("name",d);
obj.insert("name_localized", StelTranslator::globalT ranslator->qtranslate(d)); obj.insert("name_localized", StelTranslator::globalT ranslator->qtranslate(d));
d = scriptMgr->getDescription(scriptId).trimmed(); d = scriptMgr->getDescription(scriptId).trimmed();
obj.insert("description",d); obj.insert("description",d);
obj.insert("description_localized", StelTranslator:: globalTranslator->qtranslate(d)); obj.insert("description_localized", StelTranslator:: globalTranslator->qtranslate(d));
obj.insert("author",scriptMgr->getAuthor(scriptId).t rimmed()); obj.insert("author",scriptMgr->getAuthor(scriptId).t rimmed());
obj.insert("license",scriptMgr->getLicense(scriptId) .trimmed()); obj.insert("license",scriptMgr->getLicense(scriptId) .trimmed());
obj.insert("version",scriptMgr->getVersion(scriptId) .trimmed());
//shortcut often causes a large delay because the wh ole file gets searched, and it is usually missing, so we ignore it //shortcut often causes a large delay because the wh ole file gets searched, and it is usually missing, so we ignore it
//obj.insert("shortcut",scriptMgr->getShortcut(scrip tId)); //obj.insert("shortcut",scriptMgr->getShortcut(scrip tId));
response.writeJSON(QJsonDocument(obj)); response.writeJSON(QJsonDocument(obj));
} }
else else
{ {
response.writeRequestError("need parameter: id"); response.writeRequestError("need parameter: id");
} }
} }
skipping to change at line 98 skipping to change at line 98
response.writeJSON(QJsonDocument(obj)); response.writeJSON(QJsonDocument(obj));
} }
else else
{ {
//TODO some sort of service description? //TODO some sort of service description?
response.writeRequestError("unsupported operation. GET: list ,info,status POST: run,stop"); response.writeRequestError("unsupported operation. GET: list ,info,status POST: run,stop");
} }
} }
void ScriptService::postImpl(const QByteArray& operation, const APIParamete rs &parameters, const QByteArray &data, APIServiceResponse &response) void ScriptService::post(const QByteArray& operation, const APIParameters & parameters, const QByteArray &data, APIServiceResponse &response)
{ {
Q_UNUSED(data); Q_UNUSED(data);
if(operation=="run") if(operation=="run")
{ {
//retrieve detail about a single script //retrieve detail about a single script
QString scriptId = QString::fromUtf8(parameters.value("id")) ; QString scriptId = QString::fromUtf8(parameters.value("id")) ;
if(scriptMgr->scriptIsRunning()) if(scriptMgr->scriptIsRunning())
{ {
 End of changes. 5 change blocks. 
7 lines changed or deleted 5 lines changed or added

This html diff was produced by rfcdiff 1.41. The latest version is available from http://tools.ietf.org/tools/rfcdiff/