|
|
|
@ -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" )
|
|
|
|
|
{
|
|
|
|
|
actualUrl.append( "/json/" );
|
|
|
|
|
handler = new GeoIPJSON( m_geoipSelector );
|
|
|
|
|
}
|
|
|
|
|
else if ( m_geoipStyle == "json" )
|
|
|
|
|
{
|
|
|
|
|
handler = new GeoIPJSON( m_geoipSelector );
|
|
|
|
|
}
|
|
|
|
|
#if defined(QT_XML_LIB)
|
|
|
|
|
else if ( m_geoipStyle == "xml" )
|
|
|
|
|
CalamaresUtils::GeoIP::Handler h( m_geoipStyle, m_geoipUrl, m_geoipSelector );
|
|
|
|
|
if ( h.isValid() )
|
|
|
|
|
{
|
|
|
|
|
handler = new GeoIPXML( m_geoipSelector );
|
|
|
|
|
m_startingTimezone = h.get();
|
|
|
|
|
if ( !m_startingTimezone.isValid() )
|
|
|
|
|
cWarning() << "GeoIP lookup at" << m_geoipUrl << "failed.";
|
|
|
|
|
}
|
|
|
|
|
#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 );
|
|
|
|
|
setUpPage();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -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/" );
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|