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();
|
||||
}
|
||||
|
||||
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
|
||||
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* regionModel READ regionModel 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:
|
||||
Config( QObject* parent = nullptr );
|
||||
|
@ -50,6 +51,23 @@ public Q_SLOTS:
|
|||
// Underlying data for the models
|
||||
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:
|
||||
/// A list of supported locale identifiers (e.g. "en_US.UTF-8")
|
||||
QStringList m_localeGenLines;
|
||||
|
@ -58,6 +76,10 @@ private:
|
|||
std::unique_ptr< CalamaresUtils::Locale::CStringListModel > m_regionModel;
|
||||
/// The zones for the current region (e.g. America/New_York)
|
||||
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() );
|
||||
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_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_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->currentIndexChanged( m_regionCombo->currentIndex() );
|
||||
|
||||
auto* region = CalamaresUtils::Locale::TZRegion::fromZoneTab().find< TZRegion >( initialRegion );
|
||||
if ( region && region->zones().find< TZZone >( initialZone ) )
|
||||
{
|
||||
m_tzWidget->setCurrentLocation( initialRegion, initialZone );
|
||||
}
|
||||
else
|
||||
{
|
||||
m_tzWidget->setCurrentLocation( "America", "New_York" );
|
||||
}
|
||||
|
||||
m_config->setCurrentLocation( initialRegion, initialZone );
|
||||
|
||||
updateGlobalStorage();
|
||||
}
|
||||
|
@ -209,7 +204,7 @@ LocaleConfiguration
|
|||
LocalePage::guessLocaleConfiguration() const
|
||||
{
|
||||
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();
|
||||
|
||||
const auto* location = m_tzWidget->currentLocation();
|
||||
const auto* location = m_config->currentLocation();
|
||||
bool locationChanged = ( location->region() != gs->value( "locationRegion" ) )
|
||||
|| ( location->zone() != gs->value( "locationZone" ) );
|
||||
|
||||
|
@ -296,9 +291,10 @@ LocalePage::zoneChanged( int currentIndex )
|
|||
{
|
||||
Q_UNUSED( currentIndex )
|
||||
if ( !m_blockTzWidgetSet )
|
||||
m_tzWidget->setCurrentLocation( m_regionCombo->currentData().toString(),
|
||||
{
|
||||
m_config->setCurrentLocation( m_regionCombo->currentData().toString(),
|
||||
m_zoneCombo->currentData().toString() );
|
||||
|
||||
}
|
||||
updateGlobalStorage();
|
||||
}
|
||||
|
||||
|
|
|
@ -65,26 +65,13 @@ TimeZoneWidget::TimeZoneWidget( const CalamaresUtils::Locale::CStringPairList& z
|
|||
|
||||
|
||||
void
|
||||
TimeZoneWidget::setCurrentLocation( QString regionName, QString zoneName )
|
||||
TimeZoneWidget::setCurrentLocation( const CalamaresUtils::Locale::TZZone* location )
|
||||
{
|
||||
using namespace CalamaresUtils::Locale;
|
||||
auto* region = m_zonesData.find< TZRegion >( regionName );
|
||||
if ( !region )
|
||||
if ( location == m_currentLocation )
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
auto* zone = region->zones().find< TZZone >( zoneName );
|
||||
if ( zone )
|
||||
{
|
||||
setCurrentLocation( zone );
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
TimeZoneWidget::setCurrentLocation( const CalamaresUtils::Locale::TZZone* location )
|
||||
{
|
||||
m_currentLocation = location;
|
||||
|
||||
// Set zone
|
||||
|
@ -100,7 +87,6 @@ TimeZoneWidget::setCurrentLocation( const CalamaresUtils::Locale::TZZone* locati
|
|||
|
||||
// Repaint widget
|
||||
repaint();
|
||||
emit locationChanged( m_currentLocation );
|
||||
}
|
||||
|
||||
|
||||
|
@ -229,6 +215,6 @@ TimeZoneWidget::mousePressEvent( QMouseEvent* event )
|
|||
// Set zone image and repaint widget
|
||||
setCurrentLocation( closest );
|
||||
// Emit signal
|
||||
emit locationChanged( m_currentLocation );
|
||||
emit locationChanged( closest );
|
||||
}
|
||||
}
|
||||
|
|
|
@ -55,21 +55,15 @@ public:
|
|||
|
||||
explicit TimeZoneWidget( const CalamaresUtils::Locale::CStringPairList& zones, QWidget* parent = nullptr );
|
||||
|
||||
/** @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( QString region, QString zone );
|
||||
public Q_SLOTS:
|
||||
/** @brief Sets a location by pointer
|
||||
*
|
||||
* Pointer should be within the same model as the widget uses.
|
||||
*/
|
||||
void setCurrentLocation( const TZZone* location );
|
||||
|
||||
const TZZone* currentLocation() { return m_currentLocation; }
|
||||
|
||||
signals:
|
||||
/** @brief The location has changed by mouse click */
|
||||
void locationChanged( const TZZone* location );
|
||||
|
||||
private:
|
||||
|
|
Loading…
Add table
Reference in a new issue