Make the locale viewmodule load the initial timezone from config.

This commit is contained in:
Teo Mrnjavac 2014-07-15 11:35:05 +02:00
parent 0a8aa66d58
commit e3741c4d26
4 changed files with 48 additions and 5 deletions

View File

@ -122,7 +122,7 @@ LocalePage::LocalePage( QWidget* parent )
void void
LocalePage::init() LocalePage::init( const QString& initialRegion, const QString& initialZone )
{ {
m_regionCombo->blockSignals( true ); m_regionCombo->blockSignals( true );
m_timezoneCombo->blockSignals( true ); m_timezoneCombo->blockSignals( true );
@ -144,8 +144,26 @@ LocalePage::init()
m_regionCombo->currentIndexChanged( m_regionCombo->currentText() ); m_regionCombo->currentIndexChanged( m_regionCombo->currentText() );
// Default location // Default location
// TODO: make configurable from module.conf auto containsLocation = []( const QList< LocaleGlobal::Location >& locations,
m_tzWidget->setCurrentLocation( "Europe", "Berlin" ); 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() ); emit m_tzWidget->locationChanged( m_tzWidget->getCurrentLocation() );
} }

View File

@ -30,7 +30,7 @@ class LocalePage : public QWidget
public: public:
explicit LocalePage( QWidget* parent = nullptr ); explicit LocalePage( QWidget* parent = nullptr );
void init(); void init( const QString& initialRegion, const QString& initialZone );
QString prettyStatus() const; QString prettyStatus() const;

View File

@ -74,7 +74,7 @@ LocaleViewStep::LocaleViewStep( QObject* parent )
connect( &m_initWatcher, &QFutureWatcher< void >::finished, connect( &m_initWatcher, &QFutureWatcher< void >::finished,
[=] [=]
{ {
m_actualWidget->init(); m_actualWidget->init( m_startingTimezone.first, m_startingTimezone.second );
m_widget->layout()->removeWidget( waitingWidget ); m_widget->layout()->removeWidget( waitingWidget );
waitingWidget->deleteLater(); waitingWidget->deleteLater();
m_widget->layout()->addWidget( m_actualWidget ); m_widget->layout()->addWidget( m_actualWidget );
@ -163,3 +163,24 @@ LocaleViewStep::onLeave()
{ {
m_prettyStatus = m_actualWidget->prettyStatus(); 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" ) );
}
}

View File

@ -56,6 +56,8 @@ public:
void onLeave() override; void onLeave() override;
void setConfigurationMap( const QVariantMap& configurationMap ) override;
private: private:
QWidget* m_widget; QWidget* m_widget;
QFutureWatcher< void > m_initWatcher; QFutureWatcher< void > m_initWatcher;
@ -63,6 +65,8 @@ private:
LocalePage* m_actualWidget; LocalePage* m_actualWidget;
bool m_nextEnabled; bool m_nextEnabled;
QString m_prettyStatus; QString m_prettyStatus;
QPair< QString, QString > m_startingTimezone;
}; };
#endif // LOCALEVIEWSTEP_H #endif // LOCALEVIEWSTEP_H