MultiLevelJsonBase.cpp   MultiLevelJsonBase.cpp 
skipping to change at line 25 skipping to change at line 25
* along with this program; if not, write to the Free Software * along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA. * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA.
*/ */
#include "MultiLevelJsonBase.hpp" #include "MultiLevelJsonBase.hpp"
#include "StelJsonParser.hpp" #include "StelJsonParser.hpp"
#include "StelApp.hpp" #include "StelApp.hpp"
#include "StelFileMgr.hpp" #include "StelFileMgr.hpp"
#include "StelProjector.hpp" #include "StelProjector.hpp"
#include "StelCore.hpp" #include "StelCore.hpp"
#include "kfilterdev.h"
#include "StelUtils.hpp" #include "StelUtils.hpp"
#include <QDebug> #include <QDebug>
#include <QFile> #include <QFile>
#include <QFileInfo> #include <QFileInfo>
#include <QHttp>
#include <QUrl> #include <QUrl>
#include <QDir> #include <QDir>
#include <QBuffer> #include <QBuffer>
#include <QThread> #include <QThread>
#include <QNetworkAccessManager> #include <QNetworkAccessManager>
#include <QNetworkRequest> #include <QNetworkRequest>
#include <QNetworkReply> #include <QNetworkReply>
#include <stdexcept> #include <stdexcept>
#include <stdio.h>
// #include <QNetworkDiskCache> // #include <QNetworkDiskCache>
// Init statics // Init statics
QNetworkAccessManager* MultiLevelJsonBase::networkAccessManager = NULL; QNetworkAccessManager* MultiLevelJsonBase::networkAccessManager = NULL;
QNetworkAccessManager& MultiLevelJsonBase::getNetworkAccessManager() QNetworkAccessManager& MultiLevelJsonBase::getNetworkAccessManager()
{ {
if (networkAccessManager==NULL) if (networkAccessManager==NULL)
{ {
skipping to change at line 118 skipping to change at line 117
} }
} }
void MultiLevelJsonBase::initFromUrl(const QString& url) void MultiLevelJsonBase::initFromUrl(const QString& url)
{ {
const MultiLevelJsonBase* parent = qobject_cast<MultiLevelJsonBase*> (QObject::parent()); const MultiLevelJsonBase* parent = qobject_cast<MultiLevelJsonBase*> (QObject::parent());
contructorUrl = url; contructorUrl = url;
if (!url.startsWith("http://") && (parent==NULL || !parent->getBaseU rl().startsWith("http://"))) if (!url.startsWith("http://") && (parent==NULL || !parent->getBaseU rl().startsWith("http://")))
{ {
// Assume a local file // Assume a local file
QString fileName; QString fileName = StelFileMgr::findFile(url);
try if (fileName.isEmpty())
{ {
fileName = StelFileMgr::findFile(url); if (parent==NULL)
}
catch (std::runtime_error e)
{
try
{ {
if (parent==NULL) qWarning() << "NULL parent";
throw std::runtime_error("NULL paren errorOccured = true;
t"); return;
fileName = StelFileMgr::findFile(parent->get
BaseUrl()+url);
} }
catch (std::runtime_error e) fileName = StelFileMgr::findFile(parent->getBaseUrl(
)+url);
if (fileName.isEmpty())
{ {
qWarning() << "WARNING : Can't find JSON des cription: " << url << ": " << e.what(); qWarning() << "WARNING : Can't find JSON des cription: " << url;
errorOccured = true; errorOccured = true;
return; return;
} }
} }
QFileInfo finf(fileName); QFileInfo finf(fileName);
baseUrl = finf.absolutePath()+'/'; baseUrl = finf.absolutePath()+'/';
QFile f(fileName); QFile f(fileName);
f.open(QIODevice::ReadOnly); if(f.open(QIODevice::ReadOnly))
const bool compressed = fileName.endsWith(".qZ");
const bool gzCompressed = fileName.endsWith(".gz");
try
{
loadFromQVariantMap(loadFromJSON(f, compressed, gzCo
mpressed));
}
catch (std::runtime_error e)
{ {
qWarning() << "WARNING : Can't parse JSON descriptio const bool compressed = fileName.endsWith(".qZ");
n: " << QDir::toNativeSeparators(fileName) << ": " << e.what(); const bool gzCompressed = fileName.endsWith(".gz");
errorOccured = true; try
{
loadFromQVariantMap(loadFromJSON(f, compress
ed, gzCompressed));
}
catch (std::runtime_error e)
{
qWarning() << "WARNING : Can't parse JSON de
scription: " << QDir::toNativeSeparators(fileName) << ": " << e.what();
errorOccured = true;
f.close();
return;
}
f.close(); f.close();
return;
} }
f.close();
} }
else else
{ {
// Use a very short deletion delay to ensure that tile which are outside screen are discared before they are even downloaded // Use a very short deletion delay to ensure that tile which are outside screen are discared before they are even downloaded
// This is useful to reduce bandwidth when the user moves ra pidely // This is useful to reduce bandwidth when the user moves ra pidely
deletionDelay = 0.001; deletionDelay = 0.001;
QUrl qurl; QUrl qurl;
if (url.startsWith("http://")) if (url.startsWith("http://"))
{ {
qurl.setUrl(url); qurl.setUrl(url);
} }
else else
{ {
Q_ASSERT(parent->getBaseUrl().startsWith("http://")) ; Q_ASSERT(parent->getBaseUrl().startsWith("http://")) ;
qurl.setUrl(parent->getBaseUrl()+url); qurl.setUrl(parent->getBaseUrl()+url);
} }
Q_ASSERT(httpReply==NULL); Q_ASSERT(httpReply==NULL);
QNetworkRequest req(qurl); QNetworkRequest req(qurl);
req.setRawHeader("User-Agent", StelUtils::getApplicationName ().toAscii()); req.setRawHeader("User-Agent", StelUtils::getApplicationName ().toLatin1());
httpReply = getNetworkAccessManager().get(req); httpReply = getNetworkAccessManager().get(req);
//qDebug() << "Started downloading " << httpReply->request() .url().path(); //qDebug() << "Started downloading " << httpReply->request() .url().path();
Q_ASSERT(httpReply->error()==QNetworkReply::NoError); Q_ASSERT(httpReply->error()==QNetworkReply::NoError);
//qDebug() << httpReply->attribute(QNetworkRequest::SourceIs FromCacheAttribute).toBool(); //qDebug() << httpReply->attribute(QNetworkRequest::SourceIs FromCacheAttribute).toBool();
connect(httpReply, SIGNAL(finished()), this, SLOT(downloadFi nished())); connect(httpReply, SIGNAL(finished()), this, SLOT(downloadFi nished()));
//connect(httpReply, SIGNAL(error(QNetworkReply::NetworkErro r)), this, SLOT(downloadError(QNetworkReply::NetworkError))); //connect(httpReply, SIGNAL(error(QNetworkReply::NetworkErro r)), this, SLOT(downloadError(QNetworkReply::NetworkError)));
//connect(httpReply, SIGNAL(destroyed()), this, SLOT(replyDe stroyed())); //connect(httpReply, SIGNAL(destroyed()), this, SLOT(replyDe stroyed()));
downloading = true; downloading = true;
QString turl = qurl.toString(); QString turl = qurl.toString();
baseUrl = turl.left(turl.lastIndexOf('/')+1); baseUrl = turl.left(turl.lastIndexOf('/')+1);
skipping to change at line 277 skipping to change at line 275
{ {
QByteArray ar = qUncompress(input.readAll()); QByteArray ar = qUncompress(input.readAll());
input.close(); input.close();
QBuffer buf(&ar); QBuffer buf(&ar);
buf.open(QIODevice::ReadOnly); buf.open(QIODevice::ReadOnly);
map = parser.parse(&buf).toMap(); map = parser.parse(&buf).toMap();
buf.close(); buf.close();
} }
else if (gzCompressed) else if (gzCompressed)
{ {
QIODevice* d = KFilterDev::device(&input, "application/x-gzi QByteArray ar = StelUtils::uncompress(input.readAll());
p", false); input.close();
d->open(QIODevice::ReadOnly); map = parser.parse(ar).toMap();
map = parser.parse(d).toMap();
d->close();
delete d;
} }
else else
{ {
map = parser.parse(&input).toMap(); map = parser.parse(&input).toMap();
} }
if (map.isEmpty()) if (map.isEmpty())
throw std::runtime_error("empty JSON file, cannot load"); throw std::runtime_error("empty JSON file, cannot load");
return map; return map;
} }
 End of changes. 14 change blocks. 
37 lines changed or deleted 31 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/