[locale] Add GeoIP settings to Config
- this doesn't do the lookup **yet** - while here, refactor setConfigurationMap so it reads like a story, with chunks bitten out into a handful of static inline void methods.
This commit is contained in:
parent
f64a1eb16a
commit
a25d61077f
@ -327,43 +327,50 @@ Config::currentLCStatus() const
|
||||
.arg( localeLabel( m_selectedLocaleConfiguration.lc_numeric ) );
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
Config::setConfigurationMap( const QVariantMap& configurationMap )
|
||||
static inline void
|
||||
getLocaleGenLines( const QVariantMap& configurationMap, QStringList& localeGenLines )
|
||||
{
|
||||
QString localeGenPath = CalamaresUtils::getString( configurationMap, "localeGenPath" );
|
||||
if ( localeGenPath.isEmpty() )
|
||||
{
|
||||
localeGenPath = QStringLiteral( "/etc/locale.gen" );
|
||||
}
|
||||
m_localeGenLines = loadLocales( localeGenPath );
|
||||
localeGenLines = loadLocales( localeGenPath );
|
||||
}
|
||||
|
||||
m_adjustLiveTimezone
|
||||
static inline void
|
||||
getAdjustLiveTimezone( const QVariantMap& configurationMap, bool& adjustLiveTimezone )
|
||||
{
|
||||
adjustLiveTimezone
|
||||
= CalamaresUtils::getBool( configurationMap, "adjustLiveTimezone", Calamares::Settings::instance()->doChroot() );
|
||||
#ifdef DEBUG_TIMEZONES
|
||||
if ( m_adjustLiveTimezone )
|
||||
{
|
||||
cWarning() << "Turning off live-timezone adjustments because debugging is on.";
|
||||
m_adjustLiveTimezone = false;
|
||||
adjustLiveTimezone = false;
|
||||
}
|
||||
#endif
|
||||
#ifdef __FreeBSD__
|
||||
if ( m_adjustLiveTimezone )
|
||||
if ( adjustLiveTimezone )
|
||||
{
|
||||
cWarning() << "Turning off live-timezone adjustments on FreeBSD.";
|
||||
m_adjustLiveTimezone = false;
|
||||
adjustLiveTimezone = false;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
static inline void
|
||||
getStartingTimezone( const QVariantMap& configurationMap, CalamaresUtils::GeoIP::RegionZonePair& startingTimezone )
|
||||
{
|
||||
QString region = CalamaresUtils::getString( configurationMap, "region" );
|
||||
QString zone = CalamaresUtils::getString( configurationMap, "zone" );
|
||||
if ( !region.isEmpty() && !zone.isEmpty() )
|
||||
{
|
||||
m_startingTimezone = CalamaresUtils::GeoIP::RegionZonePair( region, zone );
|
||||
startingTimezone = CalamaresUtils::GeoIP::RegionZonePair( region, zone );
|
||||
}
|
||||
else
|
||||
{
|
||||
m_startingTimezone
|
||||
startingTimezone
|
||||
= CalamaresUtils::GeoIP::RegionZonePair( QStringLiteral( "America" ), QStringLiteral( "New_York" ) );
|
||||
}
|
||||
|
||||
@ -372,11 +379,40 @@ Config::setConfigurationMap( const QVariantMap& configurationMap )
|
||||
auto systemtz = CalamaresUtils::GeoIP::splitTZString( QTimeZone::systemTimeZoneId() );
|
||||
if ( systemtz.isValid() )
|
||||
{
|
||||
m_startingTimezone = systemtz;
|
||||
cDebug() << "Overriding configured timezone" << startingTimezone << "with system timezone" << systemtz;
|
||||
startingTimezone = systemtz;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static inline void
|
||||
getGeoIP( const QVariantMap& configurationMap, std::unique_ptr< CalamaresUtils::GeoIP::Handler >& geoip )
|
||||
{
|
||||
bool ok = false;
|
||||
QVariantMap map = CalamaresUtils::getSubMap( configurationMap, "geoip", ok );
|
||||
if ( ok )
|
||||
{
|
||||
QString url = CalamaresUtils::getString( map, "url" );
|
||||
QString style = CalamaresUtils::getString( map, "style" );
|
||||
QString selector = CalamaresUtils::getString( map, "selector" );
|
||||
|
||||
geoip = std::make_unique< CalamaresUtils::GeoIP::Handler >( style, url, selector );
|
||||
if ( !geoip->isValid() )
|
||||
{
|
||||
cWarning() << "GeoIP Style" << style << "is not recognized.";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
Config::setConfigurationMap( const QVariantMap& configurationMap )
|
||||
{
|
||||
getLocaleGenLines( configurationMap, m_localeGenLines );
|
||||
getAdjustLiveTimezone( configurationMap, m_adjustLiveTimezone );
|
||||
getStartingTimezone( configurationMap, m_startingTimezone );
|
||||
getGeoIP( configurationMap, m_geoip );
|
||||
}
|
||||
|
||||
Calamares::JobList
|
||||
Config::createJobs()
|
||||
{
|
||||
|
@ -24,6 +24,7 @@
|
||||
#include "LocaleConfiguration.h"
|
||||
|
||||
#include "Job.h"
|
||||
#include "geoip/Handler.h"
|
||||
#include "geoip/Interface.h"
|
||||
#include "locale/TimeZone.h"
|
||||
|
||||
@ -136,8 +137,18 @@ private:
|
||||
bool m_adjustLiveTimezone;
|
||||
|
||||
/** @brief The initial timezone (region, zone) specified in the config.
|
||||
*
|
||||
* This may be overridden by setting *useSystemTimezone* or by
|
||||
* GeoIP settings.
|
||||
*/
|
||||
CalamaresUtils::GeoIP::RegionZonePair m_startingTimezone;
|
||||
|
||||
/** @brief Handler for GeoIP lookup (if configured)
|
||||
*
|
||||
* The GeoIP lookup needs to be started at some suitable time,
|
||||
* by explicitly calling *TODO*
|
||||
*/
|
||||
std::unique_ptr< CalamaresUtils::GeoIP::Handler > m_geoip;
|
||||
};
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user