Make the locale viewmodule load the initial timezone from config.

main
Teo Mrnjavac 11 years ago
parent 0a8aa66d58
commit e3741c4d26

@ -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() );
}

@ -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;

@ -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" ) );
}
}

@ -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

Loading…
Cancel
Save