Commit 24ca1226 authored by Bernhard Beschow's avatar Bernhard Beschow
Browse files

Revert "remove workaround for bug 257376"

This reverts commit ce74cf20.

BUG: 257376
parent 6eafb31f
......@@ -29,7 +29,7 @@ HostipRunner::HostipRunner( QObject *parent ) :
m_networkAccessManager( new QNetworkAccessManager( this ) )
{
connect( m_networkAccessManager, SIGNAL( finished( QNetworkReply* ) ),
this, SLOT( slotRequestFinished( QNetworkReply* ) ) );
this, SLOT( slotRequestFinished( QNetworkReply* ) ), Qt::DirectConnection );
}
HostipRunner::~HostipRunner()
......@@ -72,17 +72,22 @@ void HostipRunner::slotLookupFinished(const QHostInfo &info)
m_hostInfo = info;
QString hostAddress = info.addresses().first().toString();
QString query = QString( "http://api.hostip.info/get_html.php?ip=%1&position=true" ).arg( hostAddress );
m_request.setUrl( QUrl( query ) );
QNetworkRequest request = QNetworkRequest( QUrl( query ) );
QNetworkReply *reply = m_networkAccessManager->get( request );
connect( reply, SIGNAL( error( QNetworkReply::NetworkError ) ),
this, SLOT( slotNoResults() ) );
// @todo FIXME Must currently be done in the main thread, see bug 257376
QTimer::singleShot( 0, this, SLOT( get() ) );
}
else
slotNoResults();
}
void HostipRunner::get()
{
QNetworkReply *reply = m_networkAccessManager->get( m_request );
connect( reply, SIGNAL( error( QNetworkReply::NetworkError ) ),
this, SLOT( slotNoResults() ), Qt::DirectConnection );
}
void HostipRunner::slotRequestFinished( QNetworkReply* reply )
{
double lon(0.0), lat(0.0);
......
......@@ -14,6 +14,7 @@
#include <QtCore/QString>
#include <QtNetwork/QHostInfo>
#include <QtNetwork/QNetworkRequest>
class QNetworkAccessManager;
class QNetworkReply;
......@@ -33,6 +34,8 @@ public:
GeoDataFeature::GeoDataVisualCategory category() const;
private Q_SLOTS:
void get();
// Http request with hostip.info done
void slotRequestFinished( QNetworkReply* );
......@@ -48,6 +51,8 @@ private:
QHostInfo m_hostInfo;
QNetworkAccessManager *const m_networkAccessManager;
QNetworkRequest m_request;
};
}
......
......@@ -62,19 +62,17 @@ void OsmNominatimRunner::search( const QString &searchTerm )
QString query = "q=%1&format=xml&addressdetails=1&accept-language=%2";
QString url = QString(base + query).arg(searchTerm).arg(MarbleLocale::languageCode());
QNetworkRequest networkRequest;
networkRequest.setUrl(QUrl(url));
networkRequest.setRawHeader("User-Agent", TinyWebBrowser::userAgent("Browser", "OsmNominatimRunner") );
QNetworkReply *reply = m_manager->get( networkRequest );
connect( reply, SIGNAL( error( QNetworkReply::NetworkError ) ),
this, SLOT( returnNoResults() ) );
m_request.setUrl(QUrl(url));
m_request.setRawHeader("User-Agent", TinyWebBrowser::userAgent("Browser", "OsmNominatimRunner") );
QEventLoop eventLoop;
connect( this, SIGNAL( searchFinished( QVector<GeoDataPlacemark*> ) ),
&eventLoop, SLOT( quit() ) );
// @todo FIXME Must currently be done in the main thread, see bug 257376
QTimer::singleShot( 0, this, SLOT( startSearch() ) );
eventLoop.exec();
}
......@@ -88,22 +86,34 @@ void OsmNominatimRunner::reverseGeocoding( const GeoDataCoordinates &coordinates
double lat = coordinates.latitude( GeoDataCoordinates::Degree );
QString url = QString( base + query ).arg( lon ).arg( lat ).arg( MarbleLocale::languageCode() );
QNetworkRequest networkRequest;
networkRequest.setUrl(QUrl(url));
networkRequest.setRawHeader("User-Agent", TinyWebBrowser::userAgent("Browser", "OsmNominatimRunner") );
QNetworkReply *reply = m_manager->get( networkRequest );
connect( reply, SIGNAL( error( QNetworkReply::NetworkError ) ),
this, SLOT( returnNoReverseGeocodingResult() ) );
m_request.setUrl(QUrl(url));
m_request.setRawHeader("User-Agent", TinyWebBrowser::userAgent("Browser", "OsmNominatimRunner") );
QEventLoop eventLoop;
connect( this, SIGNAL( reverseGeocodingFinished( GeoDataCoordinates, GeoDataPlacemark ) ),
&eventLoop, SLOT( quit() ) );
// @todo FIXME Must currently be done in the main thread, see bug 257376
QTimer::singleShot( 0, this, SLOT( startReverseGeocoding() ) );
eventLoop.exec();
}
void OsmNominatimRunner::startSearch()
{
QNetworkReply *reply = m_manager->get( m_request );
connect(reply, SIGNAL(error(QNetworkReply::NetworkError)),
this, SLOT(returnNoResults()));
}
void OsmNominatimRunner::startReverseGeocoding()
{
QNetworkReply *reply = m_manager->get( m_request );
connect(reply, SIGNAL(error(QNetworkReply::NetworkError)),
this, SLOT(returnNoReverseGeocodingResult()));
}
void OsmNominatimRunner::handleResult( QNetworkReply* reply )
{
bool const isSearch = reply->url().path().endsWith( "search" );
......
......@@ -56,11 +56,17 @@ private Q_SLOTS:
void returnNoReverseGeocodingResult();
void startSearch();
void startReverseGeocoding();
private:
void addData( const QDomNodeList &node, const QString &key, GeoDataExtendedData *extendedData );
QNetworkAccessManager* m_manager;
QNetworkRequest m_request;
GeoDataCoordinates m_coordinates;
};
......
......@@ -85,24 +85,28 @@ void OpenRouteServiceRunner::retrieveRoute( const RouteRequest *route )
// Please refrain from making this URI public. To use it outside the scope
// of marble you need permission from the openrouteservice.org team.
QUrl url = QUrl( "http://openls.geog.uni-heidelberg.de/osm/eu/routing" );
QNetworkRequest networkRequest = QNetworkRequest( url );
networkRequest.setHeader( QNetworkRequest::ContentTypeHeader, "application/xml" );
QByteArray requestData = request.toLatin1();
QNetworkReply *reply = m_networkAccessManager->post( networkRequest, requestData );
connect( reply, SIGNAL( error( QNetworkReply::NetworkError ) ),
this, SLOT( handleError( QNetworkReply::NetworkError ) ) );
m_request = QNetworkRequest( url );
m_request.setHeader( QNetworkRequest::ContentTypeHeader, "application/xml" );
m_requestData = request.toLatin1();
QEventLoop eventLoop;
connect( this, SIGNAL( routeCalculated( GeoDataDocument* ) ),
&eventLoop, SLOT( quit() ) );
// @todo FIXME Must currently be done in the main thread, see bug 257376
QTimer::singleShot( 0, this, SLOT( get() ) );
eventLoop.exec();
}
void OpenRouteServiceRunner::get()
{
QNetworkReply *reply = m_networkAccessManager->post( m_request, m_requestData );
connect( reply, SIGNAL( error( QNetworkReply::NetworkError ) ),
this, SLOT( handleError( QNetworkReply::NetworkError ) ), Qt::DirectConnection );
}
void OpenRouteServiceRunner::retrieveData( QNetworkReply *reply )
{
if ( reply->isFinished() ) {
......
......@@ -17,6 +17,7 @@
#include <QtCore/QString>
#include <QtNetwork/QNetworkReply>
#include <QtNetwork/QHostInfo>
class QNetworkAccessManager;
......@@ -51,6 +52,8 @@ private Q_SLOTS:
/** A network error occurred */
void handleError( QNetworkReply::NetworkError );
void get();
private:
/** Builds the xml request header. */
QString xmlHeader() const;
......@@ -70,6 +73,10 @@ private:
GeoDataDocument* parse( const QByteArray &input ) const;
QNetworkAccessManager *m_networkAccessManager;
QNetworkRequest m_request;
QByteArray m_requestData;
};
}
......
......@@ -73,20 +73,26 @@ void YoursRunner::retrieveRoute( const RouteRequest *route )
QString request = base + args + preferences;
// mDebug() << "GET: " << request;
QNetworkRequest networkRequest = QNetworkRequest( QUrl( request ) );
QNetworkReply *reply = m_networkAccessManager->get( networkRequest );
connect( reply, SIGNAL( error( QNetworkReply::NetworkError ) ),
this, SLOT( handleError( QNetworkReply::NetworkError ) ) );
m_request = QNetworkRequest( QUrl( request ) );
QEventLoop eventLoop;
connect( this, SIGNAL( routeCalculated( GeoDataDocument* ) ),
&eventLoop, SLOT( quit() ) );
// @todo FIXME Must currently be done in the main thread, see bug 257376
QTimer::singleShot( 0, this, SLOT( get() ) );
eventLoop.exec();
}
void YoursRunner::get()
{
QNetworkReply *reply = m_networkAccessManager->get( m_request );
connect( reply, SIGNAL( error( QNetworkReply::NetworkError ) ),
this, SLOT( handleError( QNetworkReply::NetworkError ) ) );
}
void YoursRunner::retrieveData( QNetworkReply *reply )
{
if ( reply->isFinished() ) {
......
......@@ -44,12 +44,16 @@ private Q_SLOTS:
/** A network error occurred */
void handleError( QNetworkReply::NetworkError );
void get();
private:
GeoDataDocument* parse( const QByteArray &input ) const;
qreal distance( const GeoDataDocument* document ) const;
QNetworkAccessManager *m_networkAccessManager;
QNetworkRequest m_request;
};
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment