[locale] Make the style of GeoIP retrieval selectable
- Unchanged config files will continue to use the weird addition of /json, and interpret JSON data. - Allow to specify full URL with data format through one of geoipStyle: json geoipStyle: xml - XML support is optional
This commit is contained in:
parent
5b98e58ae7
commit
6b7c8a694a
@ -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
|
||||
|
@ -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();
|
||||
}
|
||||
}
|
||||
|
@ -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;
|
||||
};
|
||||
|
@ -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 <region>/<zone> 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"
|
||||
|
Loading…
Reference in New Issue
Block a user