LocationService.cpp   LocationService.cpp 
skipping to change at line 38 skipping to change at line 38
#include "StelTranslator.hpp" #include "StelTranslator.hpp"
#include "SolarSystem.hpp" #include "SolarSystem.hpp"
#include <QFileInfo> #include <QFileInfo>
#include <QMimeDatabase> #include <QMimeDatabase>
#include <QJsonArray> #include <QJsonArray>
#include <QJsonDocument> #include <QJsonDocument>
#include <QJsonObject> #include <QJsonObject>
#include <QStringListModel> #include <QStringListModel>
LocationService::LocationService(const QByteArray &serviceName, QObject *pa rent) : AbstractAPIService(serviceName,parent) LocationService::LocationService(QObject *parent) : AbstractAPIService(pare nt)
{ {
//this is run in the main thread //this is run in the main thread
core = StelApp::getInstance().getCore(); core = StelApp::getInstance().getCore();
locMgr = &StelApp::getInstance().getLocationMgr(); locMgr = &StelApp::getInstance().getLocationMgr();
ssys = GETSTELMODULE(SolarSystem); ssys = GETSTELMODULE(SolarSystem);
} }
void LocationService::getImpl(const QByteArray& operation, const APIParamet ers &parameters, APIServiceResponse &response) void LocationService::get(const QByteArray& operation, const APIParameters &parameters, APIServiceResponse &response)
{ {
if(operation=="list") if(operation=="list")
{ {
//for now, this does not return location objects (which woul d require a much larger data transfer), but only the location strings //for now, this does not return location objects (which woul d require a much larger data transfer), but only the location strings
//same as in the LocationDialog list //same as in the LocationDialog list
//TODO not fully thread safe //TODO not fully thread safe
QJsonArray list = QJsonArray::fromStringList(QStringList(loc Mgr->getAllMap().keys())); QJsonArray list = QJsonArray::fromStringList(QStringList(loc Mgr->getAllMap().keys()));
response.writeJSON(QJsonDocument(list)); response.writeJSON(QJsonDocument(list));
skipping to change at line 108 skipping to change at line 108
{ {
response.writeRequestError("requires 'planet' parame ter"); response.writeRequestError("requires 'planet' parame ter");
return; return;
} }
SolarSystem* ssm = GETSTELMODULE(SolarSystem); SolarSystem* ssm = GETSTELMODULE(SolarSystem);
PlanetP p = ssm->searchByEnglishName(planet); PlanetP p = ssm->searchByEnglishName(planet);
if (p) if (p)
{ {
QString path = StelFileMgr::findFile("textures/"+p-> getTextMapName()); QString path = StelFileMgr::findFile("textures/"+p-> getTextMapName());
QFile file(path); response.writeFile(path, true);
if (path.isEmpty() || !file.exists())
{
response.setStatus(404,"not found");
response.setData("planet image not available
");
qWarning() << "ERROR - could not find planet
map for " << planet;
return;
}
QMimeType mime = QMimeDatabase().mimeTypeForFile(pat
h);
if(file.open(QIODevice::ReadOnly))
{
//allow the image to be cached by browser (1
hour)
response.setHeader("Cache-Control","max-age=
"+QByteArray::number(60*60));
//response.setHeader("Content-Length",static
_cast<int>(file.size()));
if(!mime.isDefault())
{
response.setHeader("Content-Type", m
ime.name().toLatin1());
}
//load and write data
response.setData(file.readAll());
}
else
{
response.setStatus(500,"internal server erro
r");
response.setData("could not open image file"
);
}
} }
else else
{ {
response.setStatus(404,"not found"); response.setStatus(404,"not found");
response.setData("planet id not found"); response.setData("planet id not found");
qWarning() << "ERROR - could not find planet " << pl anet; qWarning() << "ERROR - could not find planet " << pl anet;
return; return;
} }
} }
else else
{ {
//TODO some sort of service description? //TODO some sort of service description?
response.writeRequestError("unsupported operation. GET: list , countrylist, planetlist, planetimage"); response.writeRequestError("unsupported operation. GET: list , countrylist, planetlist, planetimage");
} }
} }
void LocationService::postImpl(const QByteArray& operation, const APIParame ters &parameters, const QByteArray &data, APIServiceResponse &response) void LocationService::post(const QByteArray& operation, const APIParameters &parameters, const QByteArray &data, APIServiceResponse &response)
{ {
Q_UNUSED(data); Q_UNUSED(data);
if (operation == "setlocationfields") if (operation == "setlocationfields")
{ {
QString id = QString::fromUtf8(parameters.value("id")); QString id = QString::fromUtf8(parameters.value("id"));
StelLocation loc; StelLocation loc;
if(!id.isEmpty()) if(!id.isEmpty())
{ {
 End of changes. 4 change blocks. 
41 lines changed or deleted 4 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/