diff --git a/src/modules/locale/CMakeLists.txt b/src/modules/locale/CMakeLists.txt index 442ca0d18..376c19b00 100644 --- a/src/modules/locale/CMakeLists.txt +++ b/src/modules/locale/CMakeLists.txt @@ -7,6 +7,7 @@ find_package(Qt5 COMPONENTS Xml) if( Qt5Xml_FOUND ) list( APPEND geoip_src GeoIPXML.cpp ) list( APPEND geoip_libs Qt5::Xml ) + add_definitions( -DHAVE_XML ) endif() calamares_add_plugin( locale diff --git a/src/modules/locale/LocaleViewStep.cpp b/src/modules/locale/LocaleViewStep.cpp index 04870ff76..09589a732 100644 --- a/src/modules/locale/LocaleViewStep.cpp +++ b/src/modules/locale/LocaleViewStep.cpp @@ -21,6 +21,9 @@ #include "GeoIP.h" #include "GeoIPFreeGeoIP.h" +#ifdef HAVE_XML +#include "GeoIPXML.h" +#endif #include "GlobalStorage.h" #include "JobQueue.h" #include "LocalePage.h" @@ -114,9 +117,32 @@ LocaleViewStep::setUpPage() void LocaleViewStep::fetchGeoIpTimezone() { - QNetworkAccessManager *manager = new QNetworkAccessManager( this ); - GeoIP *handler = new FreeGeoIP; + QString actualUrl( m_geoipUrl ); + GeoIP *handler = nullptr; + if ( m_geoipStyle.isEmpty() || m_geoipStyle == "legacy" ) + { + actualUrl.append( "/json" ); + handler = new FreeGeoIP; + } + else if ( m_geoipStyle == "json" ) + { + handler = new FreeGeoIP; + } +#if defined(HAVE_XML) + else if ( m_geoipStyle == "xml" ) + { + handler = new XMLGeoIP; + } +#endif + else + { + cDebug() << "WARNING: GeoIP Style" << m_geoipStyle << "is not recognized."; + setUpPage(); + return; + } + + QNetworkAccessManager *manager = new QNetworkAccessManager( this ); connect( manager, &QNetworkAccessManager::finished, [=]( QNetworkReply* reply ) { @@ -269,4 +295,10 @@ LocaleViewStep::setConfigurationMap( const QVariantMap& configurationMap ) { m_geoipUrl = configurationMap.value( "geoipUrl" ).toString(); } + if ( configurationMap.contains( "geoipStyle" ) && + configurationMap.value( "geoipStyle" ).type() == QVariant::String && + !configurationMap.value( "geoipStyle" ).toString().isEmpty() ) + { + m_geoipStyle = configurationMap.value( "geoipStyle" ).toString(); + } } diff --git a/src/modules/locale/LocaleViewStep.h b/src/modules/locale/LocaleViewStep.h index 402fb7ce9..e6983ef15 100644 --- a/src/modules/locale/LocaleViewStep.h +++ b/src/modules/locale/LocaleViewStep.h @@ -76,6 +76,7 @@ private: QPair< QString, QString > m_startingTimezone; QString m_localeGenPath; QString m_geoipUrl; + QString m_geoipStyle; QList< Calamares::job_ptr > m_jobs; }; diff --git a/src/modules/locale/locale.conf b/src/modules/locale/locale.conf index c51a5d1bc..54a7b584c 100644 --- a/src/modules/locale/locale.conf +++ b/src/modules/locale/locale.conf @@ -19,8 +19,8 @@ zone: "New_York" # GeoIP settings. Leave commented out to disable GeoIP. # -# An HTTP request is made to *geoipUrl* -- prior to Calamares 3.1.13, -# an implicit "/json" was added at the end.. The request must return +# An HTTP request is made to *geoipUrl* -- depending on the geoipStyle, +# the URL may be modified before use. The request must return # valid JSON data in the FreeGeoIP format; there should # be an attribute *time_zone*, with a string value set to the # timezone, in / format. @@ -34,3 +34,19 @@ zone: "New_York" # ``` # #geoipUrl: "freegeoip.net/json" + +# GeoIP style. Leave commented out for the "legacy" interpretation. +# This setting only makes sense if geoipUrl is set, enabliing geoIP. +# +# Possible values are: +# unset same as "legacy" +# blank same as "legacy" +# "legacy" appends "/json" to geoipUrl, above, and uses JSON format +# (which is what freegeoip.net provides there). +# "json" URL is not modified, uses JSON format. +# "xml" URL is not modified, uses XML format. +# +# The JSON format is provided by freegeoip.net, but that service is +# shutting down in June 2018. There are other providers with the same +# format. XML format is provided for Ubiquity. +#geoipStyle: "legacy"