From 15a8d629864d3de473b02b59fd6dec30b14a88db Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Thu, 6 Aug 2020 12:40:24 +0200 Subject: [PATCH] [locale] Add a 'current timezone' strings to Config - status is a longer phrase - name is a short human-readable name - code is the internal code Code that writes its own "Timezone set to" messages can use the name, rather than the status. --- src/modules/locale/Config.cpp | 25 +++++++++++++++++++++++++ src/modules/locale/Config.h | 9 +++++++++ 2 files changed, 34 insertions(+) diff --git a/src/modules/locale/Config.cpp b/src/modules/locale/Config.cpp index a6d3e5222..228f863e5 100644 --- a/src/modules/locale/Config.cpp +++ b/src/modules/locale/Config.cpp @@ -192,6 +192,9 @@ Config::Config( QObject* parent ) QProcess::execute( "timedatectl", // depends on systemd { "set-timezone", location->region() + '/' + location->zone() } ); } + + emit currentTimezoneCodeChanged( currentTimezoneCode() ); + emit currentTimezoneNameChanged( currentTimezoneName() ); } ); auto prettyStatusNotify = [&]() { emit prettyStatusChanged( prettyStatus() ); }; @@ -265,6 +268,7 @@ Config::setCurrentLocation( const CalamaresUtils::Locale::TimeZoneData* location emit currentLCStatusChanged( currentLCStatus() ); } emit currentLocationChanged( m_currentLocation ); + // Other signals come from the LocationChanged signal } } @@ -323,6 +327,27 @@ Config::currentLocationStatus() const m_currentLocation ? m_currentLocation->zone() : QString() ); } +QString +Config::currentTimezoneCode() const +{ + if ( m_currentLocation ) + { + return m_currentLocation->region() + '/' + m_currentLocation->zone(); + } + return QString(); +} + +QString +Config::currentTimezoneName() const +{ + if ( m_currentLocation ) + { + return m_regionModel->tr( m_currentLocation->region() ) + '/' + m_currentLocation->tr(); + } + return QString(); +} + + static inline QString localeLabel( const QString& s ) { diff --git a/src/modules/locale/Config.h b/src/modules/locale/Config.h index fccd3822e..5754cde8d 100644 --- a/src/modules/locale/Config.h +++ b/src/modules/locale/Config.h @@ -48,7 +48,12 @@ class Config : public QObject Q_PROPERTY( QString currentLocationStatus READ currentLocationStatus NOTIFY currentLanguageStatusChanged ) Q_PROPERTY( QString currentLanguageStatus READ currentLanguageStatus NOTIFY currentLanguageStatusChanged ) Q_PROPERTY( QString currentLCStatus READ currentLCStatus NOTIFY currentLCStatusChanged ) + // Name are shorter human-readable names + // .. main difference is that status is a full sentence, like "Timezone is America/New York" + // while name is just "America/New York" (and the code, below, is "America/New_York") + Q_PROPERTY( QString currentTimezoneName READ currentTimezoneName NOTIFY currentTimezoneNameChanged ) // Code are internal identifiers, like "en_US.UTF-8" + Q_PROPERTY( QString currentTimezoneCode READ currentTimezoneCode NOTIFY currentTimezoneCodeChanged ) Q_PROPERTY( QString currentLanguageCode READ currentLanguageCode WRITE setLanguageExplicitly NOTIFY currentLanguageCodeChanged ) Q_PROPERTY( QString currentLCCode READ currentLCCode WRITE setLCLocaleExplicitly NOTIFY currentLCCodeChanged ) @@ -119,6 +124,8 @@ public Q_SLOTS: QString currentLanguageCode() const { return localeConfiguration().language(); } QString currentLCCode() const { return localeConfiguration().lc_numeric; } + QString currentTimezoneName() const; // human-readable + QString currentTimezoneCode() const; signals: void currentLocationChanged( const CalamaresUtils::Locale::TimeZoneData* location ) const; @@ -128,6 +135,8 @@ signals: void prettyStatusChanged( const QString& ) const; void currentLanguageCodeChanged( const QString& ) const; void currentLCCodeChanged( const QString& ) const; + void currentTimezoneCodeChanged( const QString& ) const; + void currentTimezoneNameChanged( const QString& ) const; private: /// A list of supported locale identifiers (e.g. "en_US.UTF-8")