ViewService.cpp   ViewService.cpp 
skipping to change at line 35 skipping to change at line 35
#include "StelModuleMgr.hpp" #include "StelModuleMgr.hpp"
#include "StelSkyCultureMgr.hpp" #include "StelSkyCultureMgr.hpp"
#include "StelTranslator.hpp" #include "StelTranslator.hpp"
#include "LandscapeMgr.hpp" #include "LandscapeMgr.hpp"
#include <QFile> #include <QFile>
#include <QMimeDatabase> #include <QMimeDatabase>
#include <QJsonArray> #include <QJsonArray>
#include <QJsonDocument> #include <QJsonDocument>
ViewService::ViewService(const QByteArray &serviceName, QObject *parent) : AbstractAPIService(serviceName,parent) ViewService::ViewService(QObject *parent) : AbstractAPIService(parent)
{ {
core = StelApp::getInstance().getCore(); core = StelApp::getInstance().getCore();
lsMgr = GETSTELMODULE(LandscapeMgr); lsMgr = GETSTELMODULE(LandscapeMgr);
skyCulMgr = &StelApp::getInstance().getSkyCultureMgr(); skyCulMgr = &StelApp::getInstance().getSkyCultureMgr();
} }
void ViewService::getImpl(const QByteArray &operation, const APIParameters &parameters, APIServiceResponse &response) void ViewService::get(const QByteArray &operation, const APIParameters &par ameters, APIServiceResponse &response)
{ {
Q_UNUSED(parameters); Q_UNUSED(parameters);
if(operation=="listlandscape") if(operation=="listlandscape")
{ {
//list all installed landscapes //list all installed landscapes
QMap<QString,QString> map = lsMgr->getNameToDirMap(); QMap<QString,QString> map = lsMgr->getNameToDirMap();
QJsonObject obj; QJsonObject obj;
skipping to change at line 73 skipping to change at line 73
else if (operation.startsWith("landscapedescription/")) else if (operation.startsWith("landscapedescription/"))
{ {
int startidx = operation.indexOf('/'); int startidx = operation.indexOf('/');
//get the path after the name and map it to the landscapes' directory //get the path after the name and map it to the landscapes' directory
QByteArray path = operation.mid(startidx+1); QByteArray path = operation.mid(startidx+1);
if(path.isEmpty()) if(path.isEmpty())
{ {
//return the HTML description of the current landsca pe //return the HTML description of the current landsca pe
QString str = lsMgr->getCurrentLandscapeHtmlDescript ion(); QString str = lsMgr->getCurrentLandscapeHtmlDescript ion();
response.setHeader("Content-Type","text/html; charse response.writeWrappedHTML(str, lsMgr->getCurrentLand
t=UTF-8"); scapeName());
response.setData(wrapHtml(str, lsMgr->getCurrentLand
scapeName()).toUtf8());
} }
else else
{ {
//map path to landscape dir and return files //map path to landscape dir and return files
QString baseFolder = StelFileMgr::findFile("landscap es/" + lsMgr->getCurrentLandscapeID()); QString baseFolder = StelFileMgr::findFile("landscap es/" + lsMgr->getCurrentLandscapeID());
QString pathString = baseFolder + '/' + QString::fro mUtf8(path); QString pathString = baseFolder + '/' + QString::fro mUtf8(path);
QFile file(pathString); response.writeFile(pathString);
if (pathString.isEmpty() || !file.exists())
{
response.setStatus(404,"not found");
response.setData("requested landscape resour
ce not found");
return;
}
QMimeType mime = QMimeDatabase().mimeTypeForFile(pat
hString);
if(file.open(QIODevice::ReadOnly))
{
//reply with correct mime type if possible
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 resource fi
le");
}
} }
} }
else if (operation=="listskyculture") else if (operation=="listskyculture")
{ {
//list installed skycultures //list installed skycultures
QMap<QString, StelSkyCulture> map = skyCulMgr->getDirToNameM ap(); QMap<QString, StelSkyCulture> map = skyCulMgr->getDirToNameM ap();
QJsonObject obj; QJsonObject obj;
QMapIterator<QString,StelSkyCulture> it(map); QMapIterator<QString,StelSkyCulture> it(map);
while(it.hasNext()) while(it.hasNext())
skipping to change at line 136 skipping to change at line 109
else if (operation.startsWith("skyculturedescription/")) else if (operation.startsWith("skyculturedescription/"))
{ {
int startidx = operation.indexOf('/'); int startidx = operation.indexOf('/');
//get the path after the name and map it to the sky cultures ' directory //get the path after the name and map it to the sky cultures ' directory
QByteArray path = operation.mid(startidx+1); QByteArray path = operation.mid(startidx+1);
if(path.isEmpty()) if(path.isEmpty())
{ {
//return the HTML description of the current landsca pe //return the HTML description of the current landsca pe
QString str = skyCulMgr->getCurrentSkyCultureHtmlDes cription(); QString str = skyCulMgr->getCurrentSkyCultureHtmlDes cription();
response.setHeader("Content-Type","text/html; charse response.writeWrappedHTML(str, skyCulMgr->getCurrent
t=UTF-8"); SkyCultureNameI18());
response.setData(wrapHtml(str, skyCulMgr->getCurrent
SkyCultureNameI18()).toUtf8());
} }
else else
{ {
//map path to sky cultures dir and return files //map path to sky cultures dir and return files
QString baseFolder = StelFileMgr::findFile("skycultu res/" + skyCulMgr->getCurrentSkyCultureID()); QString baseFolder = StelFileMgr::findFile("skycultu res/" + skyCulMgr->getCurrentSkyCultureID());
QString pathString = baseFolder + '/' + QString::fro mUtf8(path); QString pathString = baseFolder + '/' + QString::fro mUtf8(path);
QFile file(pathString); response.writeFile(pathString);
if (pathString.isEmpty() || !file.exists())
{
response.setStatus(404,"not found");
response.setData("requested skyculture resou
rce not found");
return;
}
QMimeType mime = QMimeDatabase().mimeTypeForFile(pat
hString);
if(file.open(QIODevice::ReadOnly))
{
//reply with correct mime type if possible
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 resource fi
le");
}
} }
} }
else if (operation=="listprojection") else if (operation=="listprojection")
{ {
//list projection types //list projection types
QStringList keys = core->getAllProjectionTypeKeys(); QStringList keys = core->getAllProjectionTypeKeys();
QJsonObject obj; QJsonObject obj;
foreach(QString str,keys) foreach(QString str,keys)
skipping to change at line 193 skipping to change at line 139
QString name = core->projectionTypeKeyToNameI18n(str ); QString name = core->projectionTypeKeyToNameI18n(str );
obj.insert(str,name); obj.insert(str,name);
} }
response.writeJSON(QJsonDocument(obj)); response.writeJSON(QJsonDocument(obj));
} }
else if (operation=="projectiondescription") else if (operation=="projectiondescription")
{ {
//returns the description of the current projection //returns the description of the current projection
QString str = core->getProjection(StelCore::FrameJ2000)->get HtmlSummary(); QString str = core->getProjection(StelCore::FrameJ2000)->get HtmlSummary();
response.setHeader("Content-Type","text/html; charset=UTF-8" response.writeWrappedHTML(str, core->getCurrentProjectionNam
); eI18n());
response.setData(wrapHtml(str, core->getCurrentProjectionNam
eI18n()).toUtf8());
} }
else else
{ {
//TODO some sort of service description? //TODO some sort of service description?
response.writeRequestError("unsupported operation. GET: list landscape,landscapedescription/,listskyculture,skyculturedescription/,listp rojection,projectiondescription"); response.writeRequestError("unsupported operation. GET: list landscape,landscapedescription/,listskyculture,skyculturedescription/,listp rojection,projectiondescription");
} }
} }
 End of changes. 7 change blocks. 
78 lines changed or deleted 10 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/