mirror of
https://github.com/parchlinux/calamares.git
synced 2025-02-24 19:05:46 -05:00
[locale] Move current-location to Config
This commit is contained in:
parent
5a6a9a0d45
commit
726f882185
5 changed files with 63 additions and 40 deletions
|
@ -163,6 +163,31 @@ Config::timezoneData() const
|
||||||
return ::timezoneData();
|
return ::timezoneData();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
Config::setCurrentLocation( const QString& regionName, const QString& zoneName )
|
||||||
|
{
|
||||||
|
using namespace CalamaresUtils::Locale;
|
||||||
|
auto* region = timezoneData().find< TZRegion >( regionName );
|
||||||
|
auto* zone = region ? region->zones().find< TZZone >( zoneName ) : nullptr;
|
||||||
|
if ( zone )
|
||||||
|
{
|
||||||
|
setCurrentLocation( zone );
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
setCurrentLocation( QStringLiteral("America"), QStringLiteral("New_York") );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
Config::setCurrentLocation( const CalamaresUtils::Locale::TZZone* location )
|
||||||
|
{
|
||||||
|
if ( location != m_currentLocation )
|
||||||
|
{
|
||||||
|
m_currentLocation = location;
|
||||||
|
emit currentLocationChanged( m_currentLocation );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
Config::setConfigurationMap( const QVariantMap& configurationMap )
|
Config::setConfigurationMap( const QVariantMap& configurationMap )
|
||||||
|
|
|
@ -35,6 +35,7 @@ class Config : public QObject
|
||||||
Q_PROPERTY( CalamaresUtils::Locale::CStringListModel* zonesModel READ zonesModel CONSTANT FINAL )
|
Q_PROPERTY( CalamaresUtils::Locale::CStringListModel* zonesModel READ zonesModel CONSTANT FINAL )
|
||||||
Q_PROPERTY( CalamaresUtils::Locale::CStringListModel* regionModel READ regionModel CONSTANT FINAL )
|
Q_PROPERTY( CalamaresUtils::Locale::CStringListModel* regionModel READ regionModel CONSTANT FINAL )
|
||||||
Q_PROPERTY( const CalamaresUtils::Locale::CStringPairList& timezoneData READ timezoneData CONSTANT FINAL )
|
Q_PROPERTY( const CalamaresUtils::Locale::CStringPairList& timezoneData READ timezoneData CONSTANT FINAL )
|
||||||
|
Q_PROPERTY( const CalamaresUtils::Locale::TZZone* currentLocation READ currentLocation WRITE setCurrentLocation NOTIFY currentLocationChanged )
|
||||||
|
|
||||||
public:
|
public:
|
||||||
Config( QObject* parent = nullptr );
|
Config( QObject* parent = nullptr );
|
||||||
|
@ -50,6 +51,23 @@ public Q_SLOTS:
|
||||||
// Underlying data for the models
|
// Underlying data for the models
|
||||||
const CalamaresUtils::Locale::CStringPairList& timezoneData() const;
|
const CalamaresUtils::Locale::CStringPairList& timezoneData() const;
|
||||||
|
|
||||||
|
/** @brief Sets a location by name
|
||||||
|
*
|
||||||
|
* @p region should be "America" or the like, while @p zone
|
||||||
|
* names a zone within that region.
|
||||||
|
*/
|
||||||
|
void setCurrentLocation( const QString& region, const QString& zone );
|
||||||
|
/** @brief Sets a location by pointer
|
||||||
|
*
|
||||||
|
* Pointer should be within the same model as the widget uses.
|
||||||
|
*/
|
||||||
|
void setCurrentLocation( const CalamaresUtils::Locale::TZZone* location );
|
||||||
|
|
||||||
|
const CalamaresUtils::Locale::TZZone* currentLocation() const { return m_currentLocation; }
|
||||||
|
|
||||||
|
signals:
|
||||||
|
void currentLocationChanged( const CalamaresUtils::Locale::TZZone* location );
|
||||||
|
|
||||||
private:
|
private:
|
||||||
/// A list of supported locale identifiers (e.g. "en_US.UTF-8")
|
/// A list of supported locale identifiers (e.g. "en_US.UTF-8")
|
||||||
QStringList m_localeGenLines;
|
QStringList m_localeGenLines;
|
||||||
|
@ -58,6 +76,10 @@ private:
|
||||||
std::unique_ptr< CalamaresUtils::Locale::CStringListModel > m_regionModel;
|
std::unique_ptr< CalamaresUtils::Locale::CStringListModel > m_regionModel;
|
||||||
/// The zones for the current region (e.g. America/New_York)
|
/// The zones for the current region (e.g. America/New_York)
|
||||||
std::unique_ptr< CalamaresUtils::Locale::CStringListModel > m_zonesModel;
|
std::unique_ptr< CalamaresUtils::Locale::CStringListModel > m_zonesModel;
|
||||||
|
|
||||||
|
/// The location, points into the timezone data
|
||||||
|
const CalamaresUtils::Locale::TZZone* m_currentLocation = nullptr;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -104,9 +104,13 @@ LocalePage::LocalePage( Config* config, QWidget* parent )
|
||||||
setMinimumWidth( m_tzWidget->width() );
|
setMinimumWidth( m_tzWidget->width() );
|
||||||
setLayout( mainLayout );
|
setLayout( mainLayout );
|
||||||
|
|
||||||
|
connect( config, &Config::currentLocationChanged, m_tzWidget, &TimeZoneWidget::setCurrentLocation );
|
||||||
|
connect( config, &Config::currentLocationChanged, this, &LocalePage::locationChanged );
|
||||||
|
connect( m_tzWidget, &TimeZoneWidget::locationChanged, config, QOverload< const CalamaresUtils::Locale::TZZone* >::of( &Config::setCurrentLocation ) );
|
||||||
|
|
||||||
connect( m_regionCombo, QOverload< int >::of( &QComboBox::currentIndexChanged ), this, &LocalePage::regionChanged );
|
connect( m_regionCombo, QOverload< int >::of( &QComboBox::currentIndexChanged ), this, &LocalePage::regionChanged );
|
||||||
connect( m_zoneCombo, QOverload< int >::of( &QComboBox::currentIndexChanged ), this, &LocalePage::zoneChanged );
|
connect( m_zoneCombo, QOverload< int >::of( &QComboBox::currentIndexChanged ), this, &LocalePage::zoneChanged );
|
||||||
connect( m_tzWidget, &TimeZoneWidget::locationChanged, this, &LocalePage::locationChanged );
|
|
||||||
connect( m_localeChangeButton, &QPushButton::clicked, this, &LocalePage::changeLocale );
|
connect( m_localeChangeButton, &QPushButton::clicked, this, &LocalePage::changeLocale );
|
||||||
connect( m_formatsChangeButton, &QPushButton::clicked, this, &LocalePage::changeFormats );
|
connect( m_formatsChangeButton, &QPushButton::clicked, this, &LocalePage::changeFormats );
|
||||||
|
|
||||||
|
@ -140,16 +144,7 @@ LocalePage::init( const QString& initialRegion, const QString& initialZone )
|
||||||
m_regionCombo->setModel( m_config->regionModel() );
|
m_regionCombo->setModel( m_config->regionModel() );
|
||||||
m_regionCombo->currentIndexChanged( m_regionCombo->currentIndex() );
|
m_regionCombo->currentIndexChanged( m_regionCombo->currentIndex() );
|
||||||
|
|
||||||
auto* region = CalamaresUtils::Locale::TZRegion::fromZoneTab().find< TZRegion >( initialRegion );
|
m_config->setCurrentLocation( initialRegion, initialZone );
|
||||||
if ( region && region->zones().find< TZZone >( initialZone ) )
|
|
||||||
{
|
|
||||||
m_tzWidget->setCurrentLocation( initialRegion, initialZone );
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
m_tzWidget->setCurrentLocation( "America", "New_York" );
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
updateGlobalStorage();
|
updateGlobalStorage();
|
||||||
}
|
}
|
||||||
|
@ -209,7 +204,7 @@ LocaleConfiguration
|
||||||
LocalePage::guessLocaleConfiguration() const
|
LocalePage::guessLocaleConfiguration() const
|
||||||
{
|
{
|
||||||
return LocaleConfiguration::fromLanguageAndLocation(
|
return LocaleConfiguration::fromLanguageAndLocation(
|
||||||
QLocale().name(), m_config->supportedLocales(), m_tzWidget->currentLocation()->country() );
|
QLocale().name(), m_config->supportedLocales(), m_config->currentLocation()->country() );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -227,7 +222,7 @@ LocalePage::updateGlobalStorage()
|
||||||
{
|
{
|
||||||
auto* gs = Calamares::JobQueue::instance()->globalStorage();
|
auto* gs = Calamares::JobQueue::instance()->globalStorage();
|
||||||
|
|
||||||
const auto* location = m_tzWidget->currentLocation();
|
const auto* location = m_config->currentLocation();
|
||||||
bool locationChanged = ( location->region() != gs->value( "locationRegion" ) )
|
bool locationChanged = ( location->region() != gs->value( "locationRegion" ) )
|
||||||
|| ( location->zone() != gs->value( "locationZone" ) );
|
|| ( location->zone() != gs->value( "locationZone" ) );
|
||||||
|
|
||||||
|
@ -296,9 +291,10 @@ LocalePage::zoneChanged( int currentIndex )
|
||||||
{
|
{
|
||||||
Q_UNUSED( currentIndex )
|
Q_UNUSED( currentIndex )
|
||||||
if ( !m_blockTzWidgetSet )
|
if ( !m_blockTzWidgetSet )
|
||||||
m_tzWidget->setCurrentLocation( m_regionCombo->currentData().toString(),
|
{
|
||||||
|
m_config->setCurrentLocation( m_regionCombo->currentData().toString(),
|
||||||
m_zoneCombo->currentData().toString() );
|
m_zoneCombo->currentData().toString() );
|
||||||
|
}
|
||||||
updateGlobalStorage();
|
updateGlobalStorage();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -65,26 +65,13 @@ TimeZoneWidget::TimeZoneWidget( const CalamaresUtils::Locale::CStringPairList& z
|
||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
TimeZoneWidget::setCurrentLocation( QString regionName, QString zoneName )
|
TimeZoneWidget::setCurrentLocation( const CalamaresUtils::Locale::TZZone* location )
|
||||||
{
|
{
|
||||||
using namespace CalamaresUtils::Locale;
|
if ( location == m_currentLocation )
|
||||||
auto* region = m_zonesData.find< TZRegion >( regionName );
|
|
||||||
if ( !region )
|
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
auto* zone = region->zones().find< TZZone >( zoneName );
|
|
||||||
if ( zone )
|
|
||||||
{
|
|
||||||
setCurrentLocation( zone );
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void
|
|
||||||
TimeZoneWidget::setCurrentLocation( const CalamaresUtils::Locale::TZZone* location )
|
|
||||||
{
|
|
||||||
m_currentLocation = location;
|
m_currentLocation = location;
|
||||||
|
|
||||||
// Set zone
|
// Set zone
|
||||||
|
@ -100,7 +87,6 @@ TimeZoneWidget::setCurrentLocation( const CalamaresUtils::Locale::TZZone* locati
|
||||||
|
|
||||||
// Repaint widget
|
// Repaint widget
|
||||||
repaint();
|
repaint();
|
||||||
emit locationChanged( m_currentLocation );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -229,6 +215,6 @@ TimeZoneWidget::mousePressEvent( QMouseEvent* event )
|
||||||
// Set zone image and repaint widget
|
// Set zone image and repaint widget
|
||||||
setCurrentLocation( closest );
|
setCurrentLocation( closest );
|
||||||
// Emit signal
|
// Emit signal
|
||||||
emit locationChanged( m_currentLocation );
|
emit locationChanged( closest );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -55,21 +55,15 @@ public:
|
||||||
|
|
||||||
explicit TimeZoneWidget( const CalamaresUtils::Locale::CStringPairList& zones, QWidget* parent = nullptr );
|
explicit TimeZoneWidget( const CalamaresUtils::Locale::CStringPairList& zones, QWidget* parent = nullptr );
|
||||||
|
|
||||||
/** @brief Sets a location by name
|
public Q_SLOTS:
|
||||||
*
|
|
||||||
* @p region should be "America" or the like, while @p zone
|
|
||||||
* names a zone within that region.
|
|
||||||
*/
|
|
||||||
void setCurrentLocation( QString region, QString zone );
|
|
||||||
/** @brief Sets a location by pointer
|
/** @brief Sets a location by pointer
|
||||||
*
|
*
|
||||||
* Pointer should be within the same model as the widget uses.
|
* Pointer should be within the same model as the widget uses.
|
||||||
*/
|
*/
|
||||||
void setCurrentLocation( const TZZone* location );
|
void setCurrentLocation( const TZZone* location );
|
||||||
|
|
||||||
const TZZone* currentLocation() { return m_currentLocation; }
|
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
|
/** @brief The location has changed by mouse click */
|
||||||
void locationChanged( const TZZone* location );
|
void locationChanged( const TZZone* location );
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
Loading…
Add table
Reference in a new issue