[locale] Refactor GeoIP handlers

- Read the data in the caller of the handler, instead of in the callers
main
Adriaan de Groot 7 years ago
parent 939cdff93b
commit 5b98e58ae7

@ -23,7 +23,7 @@
#include <QString>
#include <QUrl>
class QNetworkReply;
class QByteArray;
/**
* @brief Interface for GeoIP retrievers.
@ -47,7 +47,7 @@ struct GeoIP
* likes. On error, returns a RegionZonePair with empty
* strings (e.g. ( "", "" ) ).
*/
virtual RegionZonePair processReply( QNetworkReply* ) = 0;
virtual RegionZonePair processReply( const QByteArray& ) = 0;
/** @brief Splits a region/zone string into a pair. */
static RegionZonePair splitTZString( const QString& s );

@ -22,15 +22,13 @@
#include "utils/Logger.h"
#include "utils/YamlUtils.h"
#include <QNetworkReply>
#include <QByteArray>
#include <yaml-cpp/yaml.h>
GeoIP::RegionZonePair
FreeGeoIP::processReply( QNetworkReply* reply )
FreeGeoIP::processReply( const QByteArray& data )
{
QByteArray data = reply->readAll();
try
{
YAML::Node doc = YAML::Load( data );

@ -31,7 +31,7 @@
*/
struct FreeGeoIP : public GeoIP
{
virtual RegionZonePair processReply( QNetworkReply* );
virtual RegionZonePair processReply( const QByteArray& );
} ;
#endif

@ -24,13 +24,13 @@
#include <QtXml/QDomDocument>
GeoIP::RegionZonePair
XMLGeoIP::processReply( QNetworkReply* reply )
XMLGeoIP::processReply( const QByteArray& data )
{
QString domError;
int errorLine, errorColumn;
QDomDocument doc;
if ( doc.setContent( reply->readAll(), false, &domError, &errorLine, &errorColumn ) )
if ( doc.setContent( data, false, &domError, &errorLine, &errorColumn ) )
{
const auto tzElements = doc.elementsByTagName( "TimeZone" );
cDebug() << "GeoIP found" << tzElements.length() << "elements";

@ -30,7 +30,7 @@
*/
struct XMLGeoIP : public GeoIP
{
virtual RegionZonePair processReply( QNetworkReply* );
virtual RegionZonePair processReply( const QByteArray& );
} ;
#endif

@ -122,7 +122,7 @@ LocaleViewStep::fetchGeoIpTimezone()
{
if ( reply->error() == QNetworkReply::NoError )
{
auto tz = handler->processReply( reply );
auto tz = handler->processReply( reply->readAll() );
if ( !tz.first.isEmpty() )
m_startingTimezone = tz;
}

Loading…
Cancel
Save