diff --git a/src/modules/locale/LocalePage.cpp b/src/modules/locale/LocalePage.cpp index 041771a3d..93a993cfb 100644 --- a/src/modules/locale/LocalePage.cpp +++ b/src/modules/locale/LocalePage.cpp @@ -122,7 +122,7 @@ LocalePage::LocalePage( QWidget* parent ) void -LocalePage::init() +LocalePage::init( const QString& initialRegion, const QString& initialZone ) { m_regionCombo->blockSignals( true ); m_timezoneCombo->blockSignals( true ); @@ -144,8 +144,26 @@ LocalePage::init() m_regionCombo->currentIndexChanged( m_regionCombo->currentText() ); // Default location - // TODO: make configurable from module.conf - m_tzWidget->setCurrentLocation( "Europe", "Berlin" ); + auto containsLocation = []( const QList< LocaleGlobal::Location >& locations, + const QString& zone ) -> bool + { + foreach ( const LocaleGlobal::Location& location, locations ) + { + if ( location.zone == zone ) + return true; + } + return false; + }; + + if ( keys.contains( initialRegion ) && + containsLocation( regions.value( initialRegion ), initialZone ) ) + { + m_tzWidget->setCurrentLocation( initialRegion, initialZone ); + } + else + { + m_tzWidget->setCurrentLocation( "Europe", "Berlin" ); + } emit m_tzWidget->locationChanged( m_tzWidget->getCurrentLocation() ); } diff --git a/src/modules/locale/LocalePage.h b/src/modules/locale/LocalePage.h index dcd3d6ef8..ee80fe9ca 100644 --- a/src/modules/locale/LocalePage.h +++ b/src/modules/locale/LocalePage.h @@ -30,7 +30,7 @@ class LocalePage : public QWidget public: explicit LocalePage( QWidget* parent = nullptr ); - void init(); + void init( const QString& initialRegion, const QString& initialZone ); QString prettyStatus() const; diff --git a/src/modules/locale/LocaleViewStep.cpp b/src/modules/locale/LocaleViewStep.cpp index 47e3bde75..068eb9fcf 100644 --- a/src/modules/locale/LocaleViewStep.cpp +++ b/src/modules/locale/LocaleViewStep.cpp @@ -74,7 +74,7 @@ LocaleViewStep::LocaleViewStep( QObject* parent ) connect( &m_initWatcher, &QFutureWatcher< void >::finished, [=] { - m_actualWidget->init(); + m_actualWidget->init( m_startingTimezone.first, m_startingTimezone.second ); m_widget->layout()->removeWidget( waitingWidget ); waitingWidget->deleteLater(); m_widget->layout()->addWidget( m_actualWidget ); @@ -163,3 +163,24 @@ LocaleViewStep::onLeave() { m_prettyStatus = m_actualWidget->prettyStatus(); } + + +void +LocaleViewStep::setConfigurationMap( const QVariantMap& configurationMap ) +{ + if ( configurationMap.contains( "region" ) && + configurationMap.value( "region" ).type() == QVariant::String && + !configurationMap.value( "region" ).toString().isEmpty() && + configurationMap.contains( "zone" ) && + configurationMap.value( "zone" ).type() == QVariant::String && + !configurationMap.value( "zone" ).toString().isEmpty() ) + { + m_startingTimezone = qMakePair( configurationMap.value( "region" ).toString(), + configurationMap.value( "zone" ).toString() ); + } + else + { + m_startingTimezone = qMakePair( QStringLiteral( "Europe" ), + QStringLiteral( "Berlin" ) ); + } +} diff --git a/src/modules/locale/LocaleViewStep.h b/src/modules/locale/LocaleViewStep.h index 652cccc5e..0f5cc9a0e 100644 --- a/src/modules/locale/LocaleViewStep.h +++ b/src/modules/locale/LocaleViewStep.h @@ -56,6 +56,8 @@ public: void onLeave() override; + void setConfigurationMap( const QVariantMap& configurationMap ) override; + private: QWidget* m_widget; QFutureWatcher< void > m_initWatcher; @@ -63,6 +65,8 @@ private: LocalePage* m_actualWidget; bool m_nextEnabled; QString m_prettyStatus; + + QPair< QString, QString > m_startingTimezone; }; #endif // LOCALEVIEWSTEP_H