From b607cf3f98c1cad911d84ebff116c37d97123834 Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Wed, 22 Jul 2020 01:26:15 +0200 Subject: [PATCH] [locale] Get starting TZ in Config - read the *region* and *zone* settings; this duplicates what the ViewStep does and is currently unused, but .. - add new support for using the system's TZ (rather than the fixed values from *region* and *zone*). This complements GeoIP lookup. This is the actual feature that started the long rewrite of the Config object (so that all the business logic would be in one place, usable for both widgets and QML). FIXES #1381 --- src/modules/locale/Config.cpp | 26 ++++++++++++++++++++++++-- src/modules/locale/Config.h | 5 +++++ src/modules/locale/locale.conf | 12 ++++++++++++ src/modules/locale/locale.schema.yaml | 1 + 4 files changed, 42 insertions(+), 2 deletions(-) diff --git a/src/modules/locale/Config.cpp b/src/modules/locale/Config.cpp index 0898a77f2..0ecd7e049 100644 --- a/src/modules/locale/Config.cpp +++ b/src/modules/locale/Config.cpp @@ -31,6 +31,7 @@ #include #include +#include /** @brief Load supported locale keys * @@ -342,17 +343,38 @@ Config::setConfigurationMap( const QVariantMap& configurationMap ) #ifdef DEBUG_TIMEZONES if ( m_adjustLiveTimezone ) { - cDebug() << "Turning off live-timezone adjustments because debugging is on."; + cWarning() << "Turning off live-timezone adjustments because debugging is on."; m_adjustLiveTimezone = false; } #endif #ifdef __FreeBSD__ if ( m_adjustLiveTimezone ) { - cDebug() << "Turning off live-timezone adjustments on FreeBSD."; + cWarning() << "Turning off live-timezone adjustments on FreeBSD."; m_adjustLiveTimezone = false; } #endif + + QString region = CalamaresUtils::getString( configurationMap, "region" ); + QString zone = CalamaresUtils::getString( configurationMap, "zone" ); + if ( !region.isEmpty() && !zone.isEmpty() ) + { + m_startingTimezone = CalamaresUtils::GeoIP::RegionZonePair( region, zone ); + } + else + { + m_startingTimezone + = CalamaresUtils::GeoIP::RegionZonePair( QStringLiteral( "America" ), QStringLiteral( "New_York" ) ); + } + + if ( CalamaresUtils::getBool( configurationMap, "useSystemTimezone", false ) ) + { + auto systemtz = CalamaresUtils::GeoIP::splitTZString( QTimeZone::systemTimeZoneId() ); + if ( systemtz.isValid() ) + { + m_startingTimezone = systemtz; + } + } } Calamares::JobList diff --git a/src/modules/locale/Config.h b/src/modules/locale/Config.h index c8710f4a9..7e634a4a8 100644 --- a/src/modules/locale/Config.h +++ b/src/modules/locale/Config.h @@ -24,6 +24,7 @@ #include "LocaleConfiguration.h" #include "Job.h" +#include "geoip/Interface.h" #include "locale/TimeZone.h" #include @@ -133,6 +134,10 @@ private: * timezone, and the live system can be made to follow that. */ bool m_adjustLiveTimezone; + + /** @brief The initial timezone (region, zone) specified in the config. + */ + CalamaresUtils::GeoIP::RegionZonePair m_startingTimezone; }; diff --git a/src/modules/locale/locale.conf b/src/modules/locale/locale.conf index 572326f0b..8236a879b 100644 --- a/src/modules/locale/locale.conf +++ b/src/modules/locale/locale.conf @@ -11,9 +11,21 @@ # the locale page can be set through keys *region* and *zone*. # If either is not set, defaults to America/New_York. # +# Note that useSystemTimezone and GeoIP settings can change the +# starting time zone. +# region: "America" zone: "New_York" +# Instead of using *region* and *zone* specified above, +# you can use the system's notion of the timezone, instead. +# This can help if your system is automatically configured with +# a sensible TZ rather than chasing a fixed default. +# +# The default is false. +# +# useSystemTimezone: true + # Should changing the system location (e.g. clicking around on the timezone # map) immediately reflect the changed timezone in the live system? # By default, installers (with a target system) do, and setup (e.g. OEM diff --git a/src/modules/locale/locale.schema.yaml b/src/modules/locale/locale.schema.yaml index 6eadb5c85..d6c35020f 100644 --- a/src/modules/locale/locale.schema.yaml +++ b/src/modules/locale/locale.schema.yaml @@ -19,6 +19,7 @@ properties: ] } zone: { type: string } + useSystemTimezone: { type: boolean, default: false } adjustLiveTimezone: { type: boolean, default: true }