[locale] Use GeoIP Handler instead of own implementation
This commit is contained in:
parent
2f2adb3623
commit
25d97efe48
@ -26,11 +26,7 @@
|
||||
#include "GlobalStorage.h"
|
||||
#include "JobQueue.h"
|
||||
|
||||
#include "geoip/Interface.h"
|
||||
#include "geoip/GeoIPJSON.h"
|
||||
#ifdef QT_XML_LIB
|
||||
#include "geoip/GeoIPXML.h"
|
||||
#endif
|
||||
#include "geoip/Handler.h"
|
||||
|
||||
#include "utils/CalamaresUtilsGui.h"
|
||||
#include "utils/Logger.h"
|
||||
@ -117,56 +113,16 @@ LocaleViewStep::setUpPage()
|
||||
void
|
||||
LocaleViewStep::fetchGeoIpTimezone()
|
||||
{
|
||||
using namespace CalamaresUtils::GeoIP;
|
||||
|
||||
QString actualUrl( m_geoipUrl );
|
||||
Interface* handler = nullptr;
|
||||
|
||||
if ( m_geoipStyle.isEmpty() || m_geoipStyle == "legacy" )
|
||||
CalamaresUtils::GeoIP::Handler h( m_geoipStyle, m_geoipUrl, m_geoipSelector );
|
||||
if ( h.isValid() )
|
||||
{
|
||||
actualUrl.append( "/json/" );
|
||||
handler = new GeoIPJSON( m_geoipSelector );
|
||||
m_startingTimezone = h.get();
|
||||
if ( !m_startingTimezone.isValid() )
|
||||
cWarning() << "GeoIP lookup at" << m_geoipUrl << "failed.";
|
||||
}
|
||||
else if ( m_geoipStyle == "json" )
|
||||
{
|
||||
handler = new GeoIPJSON( m_geoipSelector );
|
||||
}
|
||||
#if defined(QT_XML_LIB)
|
||||
else if ( m_geoipStyle == "xml" )
|
||||
{
|
||||
handler = new GeoIPXML( m_geoipSelector );
|
||||
}
|
||||
#endif
|
||||
else
|
||||
{
|
||||
cWarning() << "GeoIP Style" << m_geoipStyle << "is not recognized.";
|
||||
setUpPage();
|
||||
return;
|
||||
}
|
||||
cDebug() << "Fetching GeoIP data from" << actualUrl;
|
||||
|
||||
QNetworkAccessManager *manager = new QNetworkAccessManager( this );
|
||||
connect( manager, &QNetworkAccessManager::finished,
|
||||
[=]( QNetworkReply* reply )
|
||||
{
|
||||
if ( reply->error() == QNetworkReply::NoError )
|
||||
{
|
||||
auto tz = handler->processReply( reply->readAll() );
|
||||
if ( !tz.first.isEmpty() )
|
||||
m_startingTimezone = tz;
|
||||
else
|
||||
cWarning() << "GeoIP lookup at" << reply->url() << "failed.";
|
||||
}
|
||||
delete handler;
|
||||
reply->deleteLater();
|
||||
manager->deleteLater();
|
||||
setUpPage();
|
||||
} );
|
||||
|
||||
QNetworkRequest request;
|
||||
request.setUrl( QUrl::fromUserInput( actualUrl ) );
|
||||
request.setAttribute( QNetworkRequest::FollowRedirectsAttribute, true );
|
||||
manager->get( request );
|
||||
}
|
||||
|
||||
|
||||
@ -254,35 +210,29 @@ LocaleViewStep::onLeave()
|
||||
void
|
||||
LocaleViewStep::setConfigurationMap( const QVariantMap& configurationMap )
|
||||
{
|
||||
if ( configurationMap.contains( "region" ) &&
|
||||
configurationMap.value( "region" ).type() == QVariant::String &&
|
||||
!configurationMap.value( "region" ).toString().isEmpty() &&
|
||||
configurationMap.contains( "zone" ) &&
|
||||
configurationMap.value( "zone" ).type() == QVariant::String &&
|
||||
!configurationMap.value( "zone" ).toString().isEmpty() )
|
||||
QString region = CalamaresUtils::getString( configurationMap, "region" );
|
||||
QString zone = CalamaresUtils::getString( configurationMap, "zone" );
|
||||
if ( !region.isEmpty() && !zone.isEmpty() )
|
||||
{
|
||||
m_startingTimezone = qMakePair( configurationMap.value( "region" ).toString(),
|
||||
configurationMap.value( "zone" ).toString() );
|
||||
m_startingTimezone = CalamaresUtils::GeoIP::RegionZonePair( region, zone );
|
||||
}
|
||||
else
|
||||
{
|
||||
m_startingTimezone = qMakePair( QStringLiteral( "America" ),
|
||||
QStringLiteral( "New_York" ) );
|
||||
m_startingTimezone = CalamaresUtils::GeoIP::RegionZonePair( QStringLiteral( "America" ), QStringLiteral( "New_York" ) );
|
||||
}
|
||||
|
||||
if ( configurationMap.contains( "localeGenPath" ) &&
|
||||
configurationMap.value( "localeGenPath" ).type() == QVariant::String &&
|
||||
!configurationMap.value( "localeGenPath" ).toString().isEmpty() )
|
||||
{
|
||||
m_localeGenPath = configurationMap.value( "localeGenPath" ).toString();
|
||||
}
|
||||
else
|
||||
{
|
||||
m_localeGenPath = CalamaresUtils::getString( configurationMap, "localeGenPath" );
|
||||
if ( m_localeGenPath.isEmpty() )
|
||||
m_localeGenPath = QStringLiteral( "/etc/locale.gen" );
|
||||
}
|
||||
|
||||
// Optional
|
||||
m_geoipUrl = CalamaresUtils::getString( configurationMap, "geoipUrl" );
|
||||
m_geoipStyle = CalamaresUtils::getString( configurationMap, "geoipStyle" );
|
||||
m_geoipSelector = CalamaresUtils::getString( configurationMap, "geoipSelector" );
|
||||
|
||||
if ( !m_geoipUrl.isEmpty() && ( m_geoipStyle.isEmpty() || m_geoipStyle == "legacy" ) )
|
||||
{
|
||||
m_geoipStyle = "json";
|
||||
m_geoipUrl.append( "/json/" );
|
||||
}
|
||||
}
|
||||
|
@ -20,14 +20,14 @@
|
||||
#ifndef LOCALEVIEWSTEP_H
|
||||
#define LOCALEVIEWSTEP_H
|
||||
|
||||
#include <QObject>
|
||||
#include "geoip/Interface.h"
|
||||
#include "utils/PluginFactory.h"
|
||||
#include "viewpages/ViewStep.h"
|
||||
|
||||
#include <utils/PluginFactory.h>
|
||||
#include <viewpages/ViewStep.h>
|
||||
|
||||
#include <PluginDllMacro.h>
|
||||
#include "PluginDllMacro.h"
|
||||
|
||||
#include <QFutureWatcher>
|
||||
#include <QObject>
|
||||
|
||||
class LocalePage;
|
||||
class WaitingWidget;
|
||||
@ -71,7 +71,7 @@ private:
|
||||
bool m_nextEnabled;
|
||||
QString m_prettyStatus;
|
||||
|
||||
QPair< QString, QString > m_startingTimezone;
|
||||
CalamaresUtils::GeoIP::RegionZonePair m_startingTimezone;
|
||||
QString m_localeGenPath;
|
||||
|
||||
QString m_geoipUrl; // The URL, depening on style might be modified on lookup
|
||||
|
Loading…
Reference in New Issue
Block a user