[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 "GlobalStorage.h"
|
||||||
#include "JobQueue.h"
|
#include "JobQueue.h"
|
||||||
|
|
||||||
#include "geoip/Interface.h"
|
#include "geoip/Handler.h"
|
||||||
#include "geoip/GeoIPJSON.h"
|
|
||||||
#ifdef QT_XML_LIB
|
|
||||||
#include "geoip/GeoIPXML.h"
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#include "utils/CalamaresUtilsGui.h"
|
#include "utils/CalamaresUtilsGui.h"
|
||||||
#include "utils/Logger.h"
|
#include "utils/Logger.h"
|
||||||
@ -117,56 +113,16 @@ LocaleViewStep::setUpPage()
|
|||||||
void
|
void
|
||||||
LocaleViewStep::fetchGeoIpTimezone()
|
LocaleViewStep::fetchGeoIpTimezone()
|
||||||
{
|
{
|
||||||
using namespace CalamaresUtils::GeoIP;
|
CalamaresUtils::GeoIP::Handler h( m_geoipStyle, m_geoipUrl, m_geoipSelector );
|
||||||
|
if ( h.isValid() )
|
||||||
QString actualUrl( m_geoipUrl );
|
|
||||||
Interface* handler = nullptr;
|
|
||||||
|
|
||||||
if ( m_geoipStyle.isEmpty() || m_geoipStyle == "legacy" )
|
|
||||||
{
|
{
|
||||||
actualUrl.append( "/json/" );
|
m_startingTimezone = h.get();
|
||||||
handler = new GeoIPJSON( m_geoipSelector );
|
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
|
else
|
||||||
{
|
|
||||||
cWarning() << "GeoIP Style" << m_geoipStyle << "is not recognized.";
|
cWarning() << "GeoIP Style" << m_geoipStyle << "is not recognized.";
|
||||||
setUpPage();
|
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
|
void
|
||||||
LocaleViewStep::setConfigurationMap( const QVariantMap& configurationMap )
|
LocaleViewStep::setConfigurationMap( const QVariantMap& configurationMap )
|
||||||
{
|
{
|
||||||
if ( configurationMap.contains( "region" ) &&
|
QString region = CalamaresUtils::getString( configurationMap, "region" );
|
||||||
configurationMap.value( "region" ).type() == QVariant::String &&
|
QString zone = CalamaresUtils::getString( configurationMap, "zone" );
|
||||||
!configurationMap.value( "region" ).toString().isEmpty() &&
|
if ( !region.isEmpty() && !zone.isEmpty() )
|
||||||
configurationMap.contains( "zone" ) &&
|
|
||||||
configurationMap.value( "zone" ).type() == QVariant::String &&
|
|
||||||
!configurationMap.value( "zone" ).toString().isEmpty() )
|
|
||||||
{
|
{
|
||||||
m_startingTimezone = qMakePair( configurationMap.value( "region" ).toString(),
|
m_startingTimezone = CalamaresUtils::GeoIP::RegionZonePair( region, zone );
|
||||||
configurationMap.value( "zone" ).toString() );
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
m_startingTimezone = qMakePair( QStringLiteral( "America" ),
|
m_startingTimezone = CalamaresUtils::GeoIP::RegionZonePair( QStringLiteral( "America" ), QStringLiteral( "New_York" ) );
|
||||||
QStringLiteral( "New_York" ) );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( configurationMap.contains( "localeGenPath" ) &&
|
m_localeGenPath = CalamaresUtils::getString( configurationMap, "localeGenPath" );
|
||||||
configurationMap.value( "localeGenPath" ).type() == QVariant::String &&
|
if ( m_localeGenPath.isEmpty() )
|
||||||
!configurationMap.value( "localeGenPath" ).toString().isEmpty() )
|
|
||||||
{
|
|
||||||
m_localeGenPath = configurationMap.value( "localeGenPath" ).toString();
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
m_localeGenPath = QStringLiteral( "/etc/locale.gen" );
|
m_localeGenPath = QStringLiteral( "/etc/locale.gen" );
|
||||||
}
|
|
||||||
|
|
||||||
// Optional
|
// Optional
|
||||||
m_geoipUrl = CalamaresUtils::getString( configurationMap, "geoipUrl" );
|
m_geoipUrl = CalamaresUtils::getString( configurationMap, "geoipUrl" );
|
||||||
m_geoipStyle = CalamaresUtils::getString( configurationMap, "geoipStyle" );
|
m_geoipStyle = CalamaresUtils::getString( configurationMap, "geoipStyle" );
|
||||||
m_geoipSelector = CalamaresUtils::getString( configurationMap, "geoipSelector" );
|
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
|
#ifndef LOCALEVIEWSTEP_H
|
||||||
#define LOCALEVIEWSTEP_H
|
#define LOCALEVIEWSTEP_H
|
||||||
|
|
||||||
#include <QObject>
|
#include "geoip/Interface.h"
|
||||||
|
#include "utils/PluginFactory.h"
|
||||||
|
#include "viewpages/ViewStep.h"
|
||||||
|
|
||||||
#include <utils/PluginFactory.h>
|
#include "PluginDllMacro.h"
|
||||||
#include <viewpages/ViewStep.h>
|
|
||||||
|
|
||||||
#include <PluginDllMacro.h>
|
|
||||||
|
|
||||||
#include <QFutureWatcher>
|
#include <QFutureWatcher>
|
||||||
|
#include <QObject>
|
||||||
|
|
||||||
class LocalePage;
|
class LocalePage;
|
||||||
class WaitingWidget;
|
class WaitingWidget;
|
||||||
@ -71,7 +71,7 @@ private:
|
|||||||
bool m_nextEnabled;
|
bool m_nextEnabled;
|
||||||
QString m_prettyStatus;
|
QString m_prettyStatus;
|
||||||
|
|
||||||
QPair< QString, QString > m_startingTimezone;
|
CalamaresUtils::GeoIP::RegionZonePair m_startingTimezone;
|
||||||
QString m_localeGenPath;
|
QString m_localeGenPath;
|
||||||
|
|
||||||
QString m_geoipUrl; // The URL, depening on style might be modified on lookup
|
QString m_geoipUrl; // The URL, depening on style might be modified on lookup
|
||||||
|
Loading…
Reference in New Issue
Block a user