[locale] Remove old Location information
- all the TZ location information now lives in the Calamares locale service and the TZ list - replace the Location class that was local to the timezone widget by the TZZone class - chase a bunch of small API changes that this needs
This commit is contained in:
parent
4945408911
commit
242b79e2e1
@ -133,19 +133,6 @@ LocalePage::updateLocaleLabels()
|
|||||||
m_formatsLabel->setText( labels.second );
|
m_formatsLabel->setText( labels.second );
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline bool
|
|
||||||
containsLocation( const QList< LocaleGlobal::Location >& locations, const QString& zone )
|
|
||||||
{
|
|
||||||
for ( const LocaleGlobal::Location& location : locations )
|
|
||||||
{
|
|
||||||
if ( location.zone == zone )
|
|
||||||
{
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
void
|
void
|
||||||
LocalePage::init( const QString& initialRegion, const QString& initialZone, const QString& localeGenPath )
|
LocalePage::init( const QString& initialRegion, const QString& initialZone, const QString& localeGenPath )
|
||||||
{
|
{
|
||||||
@ -163,7 +150,6 @@ LocalePage::init( const QString& initialRegion, const QString& initialZone, cons
|
|||||||
{
|
{
|
||||||
m_tzWidget->setCurrentLocation( "America", "New_York" );
|
m_tzWidget->setCurrentLocation( "America", "New_York" );
|
||||||
}
|
}
|
||||||
emit m_tzWidget->locationChanged( m_tzWidget->getCurrentLocation() );
|
|
||||||
|
|
||||||
// Some distros come with a meaningfully commented and easy to parse locale.gen,
|
// Some distros come with a meaningfully commented and easy to parse locale.gen,
|
||||||
// and others ship a separate file /usr/share/i18n/SUPPORTED with a clean list of
|
// and others ship a separate file /usr/share/i18n/SUPPORTED with a clean list of
|
||||||
@ -298,9 +284,9 @@ Calamares::JobList
|
|||||||
LocalePage::createJobs()
|
LocalePage::createJobs()
|
||||||
{
|
{
|
||||||
QList< Calamares::job_ptr > list;
|
QList< Calamares::job_ptr > list;
|
||||||
LocaleGlobal::Location location = m_tzWidget->getCurrentLocation();
|
const CalamaresUtils::Locale::TZZone* location = m_tzWidget->currentLocation();
|
||||||
|
|
||||||
Calamares::Job* j = new SetTimezoneJob( location.region, location.zone );
|
Calamares::Job* j = new SetTimezoneJob( location->region(), location->zone() );
|
||||||
list.append( Calamares::job_ptr( j ) );
|
list.append( Calamares::job_ptr( j ) );
|
||||||
|
|
||||||
return list;
|
return list;
|
||||||
@ -333,7 +319,7 @@ LocaleConfiguration
|
|||||||
LocalePage::guessLocaleConfiguration() const
|
LocalePage::guessLocaleConfiguration() const
|
||||||
{
|
{
|
||||||
return LocaleConfiguration::fromLanguageAndLocation(
|
return LocaleConfiguration::fromLanguageAndLocation(
|
||||||
QLocale().name(), m_localeGenLines, m_tzWidget->getCurrentLocation().country );
|
QLocale().name(), m_localeGenLines, m_tzWidget->currentLocation()->country() );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -351,12 +337,12 @@ LocalePage::updateGlobalStorage()
|
|||||||
{
|
{
|
||||||
auto* gs = Calamares::JobQueue::instance()->globalStorage();
|
auto* gs = Calamares::JobQueue::instance()->globalStorage();
|
||||||
|
|
||||||
LocaleGlobal::Location location = m_tzWidget->getCurrentLocation();
|
const auto* location = m_tzWidget->currentLocation();
|
||||||
bool locationChanged
|
bool locationChanged = ( location->region() != gs->value( "locationRegion" ) )
|
||||||
= ( location.region != gs->value( "locationRegion" ) ) || ( location.zone != gs->value( "locationZone" ) );
|
|| ( location->zone() != gs->value( "locationZone" ) );
|
||||||
|
|
||||||
gs->insert( "locationRegion", location.region );
|
gs->insert( "locationRegion", location->region() );
|
||||||
gs->insert( "locationZone", location.zone );
|
gs->insert( "locationZone", location->zone() );
|
||||||
|
|
||||||
updateGlobalLocale();
|
updateGlobalLocale();
|
||||||
|
|
||||||
@ -366,7 +352,7 @@ LocalePage::updateGlobalStorage()
|
|||||||
if ( locationChanged && Calamares::Settings::instance()->doChroot() )
|
if ( locationChanged && Calamares::Settings::instance()->doChroot() )
|
||||||
{
|
{
|
||||||
QProcess::execute( "timedatectl", // depends on systemd
|
QProcess::execute( "timedatectl", // depends on systemd
|
||||||
{ "set-timezone", location.region + '/' + location.zone } );
|
{ "set-timezone", location->region() + '/' + location->zone() } );
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
@ -427,12 +413,12 @@ LocalePage::zoneChanged( int currentIndex )
|
|||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
LocalePage::locationChanged( LocaleGlobal::Location location )
|
LocalePage::locationChanged( const CalamaresUtils::Locale::TZZone* location )
|
||||||
{
|
{
|
||||||
m_blockTzWidgetSet = true;
|
m_blockTzWidgetSet = true;
|
||||||
|
|
||||||
// Set region index
|
// Set region index
|
||||||
int index = m_regionCombo->findData( location.region );
|
int index = m_regionCombo->findData( location->region() );
|
||||||
if ( index < 0 )
|
if ( index < 0 )
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
@ -441,7 +427,7 @@ LocalePage::locationChanged( LocaleGlobal::Location location )
|
|||||||
m_regionCombo->setCurrentIndex( index );
|
m_regionCombo->setCurrentIndex( index );
|
||||||
|
|
||||||
// Set zone index
|
// Set zone index
|
||||||
index = m_zoneCombo->findData( location.zone );
|
index = m_zoneCombo->findData( location->zone() );
|
||||||
if ( index < 0 )
|
if ( index < 0 )
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
|
@ -70,7 +70,7 @@ private:
|
|||||||
|
|
||||||
void regionChanged( int currentIndex );
|
void regionChanged( int currentIndex );
|
||||||
void zoneChanged( int currentIndex );
|
void zoneChanged( int currentIndex );
|
||||||
void locationChanged( LocaleGlobal::Location location );
|
void locationChanged( const CalamaresUtils::Locale::TZZone* location );
|
||||||
void changeLocale();
|
void changeLocale();
|
||||||
void changeFormats();
|
void changeFormats();
|
||||||
|
|
||||||
|
@ -38,32 +38,6 @@ QHash< QString, QHash< QString, QList< LocaleGlobal::Locale > > > LocaleGlobal::
|
|||||||
//###
|
//###
|
||||||
|
|
||||||
|
|
||||||
QString
|
|
||||||
LocaleGlobal::Location::pretty( const QString& s )
|
|
||||||
{
|
|
||||||
return QString( s ).replace( '_', ' ' ).simplified();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
QString
|
|
||||||
LocaleGlobal::Location::comment() const
|
|
||||||
{
|
|
||||||
QTimeZone qtz = QTimeZone( QString( "%1/%2" ).arg( region ).arg( zone ).toLatin1() );
|
|
||||||
return qtz.comment();
|
|
||||||
}
|
|
||||||
|
|
||||||
LocaleGlobal::Location&
|
|
||||||
LocaleGlobal::Location::operator=( const CalamaresUtils::Locale::TZZone& location )
|
|
||||||
{
|
|
||||||
region = location.region();
|
|
||||||
zone = location.key();
|
|
||||||
country = location.country();
|
|
||||||
latitude = location.latitude();
|
|
||||||
longitude = location.longitude();
|
|
||||||
return *this;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
LocaleGlobal::init()
|
LocaleGlobal::init()
|
||||||
{
|
{
|
||||||
|
@ -51,16 +51,6 @@ public:
|
|||||||
QString description, locale;
|
QString description, locale;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct Location
|
|
||||||
{
|
|
||||||
QString region, zone, country;
|
|
||||||
double latitude, longitude;
|
|
||||||
static QString pretty( const QString& s );
|
|
||||||
QString comment() const;
|
|
||||||
|
|
||||||
Location& operator=( const CalamaresUtils::Locale::TZZone& );
|
|
||||||
};
|
|
||||||
|
|
||||||
static void init();
|
static void init();
|
||||||
static QHash< QString, QHash< QString, QList< LocaleGlobal::Locale > > > getLocales();
|
static QHash< QString, QHash< QString, QList< LocaleGlobal::Locale > > > getLocales();
|
||||||
|
|
||||||
@ -70,10 +60,4 @@ private:
|
|||||||
static void initLocales();
|
static void initLocales();
|
||||||
};
|
};
|
||||||
|
|
||||||
inline QDebug&
|
|
||||||
operator<<( QDebug& s, const LocaleGlobal::Location& l )
|
|
||||||
{
|
|
||||||
return s << l.region << '/' << l.zone << '(' << l.country << ") @N" << l.latitude << 'E' << l.longitude;
|
|
||||||
}
|
|
||||||
|
|
||||||
#endif // LOCALEGLOBAL_H
|
#endif // LOCALEGLOBAL_H
|
||||||
|
@ -105,10 +105,10 @@ TimeZoneWidget::setCurrentLocation( QString regionName, QString zoneName )
|
|||||||
void
|
void
|
||||||
TimeZoneWidget::setCurrentLocation( const CalamaresUtils::Locale::TZZone* location )
|
TimeZoneWidget::setCurrentLocation( const CalamaresUtils::Locale::TZZone* location )
|
||||||
{
|
{
|
||||||
currentLocation = *location;
|
m_currentLocation = location;
|
||||||
|
|
||||||
// Set zone
|
// Set zone
|
||||||
QPoint pos = getLocationPosition( currentLocation.longitude, currentLocation.latitude );
|
QPoint pos = getLocationPosition( location );
|
||||||
|
|
||||||
#ifdef DEBUG_TIMEZONES
|
#ifdef DEBUG_TIMEZONES
|
||||||
cDebug() << "Setting location" << location->region() << *location;
|
cDebug() << "Setting location" << location->region() << *location;
|
||||||
@ -147,6 +147,7 @@ TimeZoneWidget::setCurrentLocation( const CalamaresUtils::Locale::TZZone* locati
|
|||||||
|
|
||||||
// Repaint widget
|
// Repaint widget
|
||||||
repaint();
|
repaint();
|
||||||
|
emit locationChanged( m_currentLocation );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -265,12 +266,12 @@ TimeZoneWidget::paintEvent( QPaintEvent* )
|
|||||||
painter.drawPoint( point );
|
painter.drawPoint( point );
|
||||||
#else
|
#else
|
||||||
// Draw pin at current location
|
// Draw pin at current location
|
||||||
QPoint point = getLocationPosition( currentLocation.longitude, currentLocation.latitude );
|
QPoint point = getLocationPosition( m_currentLocation );
|
||||||
|
|
||||||
painter.drawImage( point.x() - pin.width() / 2, point.y() - pin.height() / 2, pin );
|
painter.drawImage( point.x() - pin.width() / 2, point.y() - pin.height() / 2, pin );
|
||||||
|
|
||||||
// Draw text and box
|
// Draw text and box
|
||||||
const int textWidth = fontMetrics.horizontalAdvance( LocaleGlobal::Location::pretty( currentLocation.zone ) );
|
const int textWidth = fontMetrics.horizontalAdvance( m_currentLocation ? m_currentLocation->tr() : QString() );
|
||||||
const int textHeight = fontMetrics.height();
|
const int textHeight = fontMetrics.height();
|
||||||
|
|
||||||
QRect rect = QRect( point.x() - textWidth / 2 - 5, point.y() - textHeight - 8, textWidth + 10, textHeight - 2 );
|
QRect rect = QRect( point.x() - textWidth / 2 - 5, point.y() - textHeight - 8, textWidth + 10, textHeight - 2 );
|
||||||
@ -296,7 +297,7 @@ TimeZoneWidget::paintEvent( QPaintEvent* )
|
|||||||
painter.setBrush( QColor( 40, 40, 40 ) );
|
painter.setBrush( QColor( 40, 40, 40 ) );
|
||||||
painter.drawRoundedRect( rect, 3, 3 );
|
painter.drawRoundedRect( rect, 3, 3 );
|
||||||
painter.setPen( Qt::white );
|
painter.setPen( Qt::white );
|
||||||
painter.drawText( rect.x() + 5, rect.bottom() - 4, LocaleGlobal::Location::pretty( currentLocation.zone ) );
|
painter.drawText( rect.x() + 5, rect.bottom() - 4, m_currentLocation ? m_currentLocation->tr() : QString() );
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
painter.end();
|
painter.end();
|
||||||
@ -345,6 +346,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( currentLocation );
|
emit locationChanged( m_currentLocation );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -43,25 +43,25 @@ class TimeZoneWidget : public QWidget
|
|||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
public:
|
public:
|
||||||
|
using TZZone = CalamaresUtils::Locale::TZZone;
|
||||||
|
|
||||||
explicit TimeZoneWidget( QWidget* parent = nullptr );
|
explicit TimeZoneWidget( QWidget* parent = nullptr );
|
||||||
|
|
||||||
LocaleGlobal::Location getCurrentLocation() { return currentLocation; }
|
|
||||||
void setCurrentLocation( QString region, QString zone );
|
void setCurrentLocation( QString region, QString zone );
|
||||||
void setCurrentLocation( const CalamaresUtils::Locale::TZZone* location );
|
void setCurrentLocation( const TZZone* location );
|
||||||
|
const TZZone* currentLocation() { return m_currentLocation; }
|
||||||
|
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
void locationChanged( LocaleGlobal::Location location );
|
void locationChanged( const TZZone* location );
|
||||||
|
|
||||||
private:
|
private:
|
||||||
QFont font;
|
QFont font;
|
||||||
QImage background, pin, currentZoneImage;
|
QImage background, pin, currentZoneImage;
|
||||||
QList< QImage > timeZoneImages;
|
QList< QImage > timeZoneImages;
|
||||||
LocaleGlobal::Location currentLocation;
|
const TZZone* m_currentLocation = nullptr; // Not owned by me
|
||||||
|
|
||||||
QPoint getLocationPosition( const LocaleGlobal::Location& l )
|
QPoint getLocationPosition( const TZZone* l ) { return getLocationPosition( l->longitude(), l->latitude() ); }
|
||||||
{
|
|
||||||
return getLocationPosition( l.longitude, l.latitude );
|
|
||||||
}
|
|
||||||
QPoint getLocationPosition( double longitude, double latitude );
|
QPoint getLocationPosition( double longitude, double latitude );
|
||||||
|
|
||||||
void paintEvent( QPaintEvent* event );
|
void paintEvent( QPaintEvent* event );
|
||||||
|
Loading…
Reference in New Issue
Block a user