From 242b79e2e1292a6f926229c29063473fb94a11fc Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Wed, 11 Dec 2019 08:36:23 -0500 Subject: [PATCH] [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 --- src/modules/locale/LocalePage.cpp | 38 ++++++------------- src/modules/locale/LocalePage.h | 2 +- .../locale/timezonewidget/localeglobal.cpp | 26 ------------- .../locale/timezonewidget/localeglobal.h | 16 -------- .../locale/timezonewidget/timezonewidget.cpp | 13 ++++--- .../locale/timezonewidget/timezonewidget.h | 16 ++++---- 6 files changed, 28 insertions(+), 83 deletions(-) diff --git a/src/modules/locale/LocalePage.cpp b/src/modules/locale/LocalePage.cpp index ecdfb1935..4e43fc177 100644 --- a/src/modules/locale/LocalePage.cpp +++ b/src/modules/locale/LocalePage.cpp @@ -133,19 +133,6 @@ LocalePage::updateLocaleLabels() 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 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" ); } - emit m_tzWidget->locationChanged( m_tzWidget->getCurrentLocation() ); // 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 @@ -298,9 +284,9 @@ Calamares::JobList LocalePage::createJobs() { 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 ) ); return list; @@ -333,7 +319,7 @@ LocaleConfiguration LocalePage::guessLocaleConfiguration() const { 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(); - LocaleGlobal::Location location = m_tzWidget->getCurrentLocation(); - bool locationChanged - = ( location.region != gs->value( "locationRegion" ) ) || ( location.zone != gs->value( "locationZone" ) ); + const auto* location = m_tzWidget->currentLocation(); + bool locationChanged = ( location->region() != gs->value( "locationRegion" ) ) + || ( location->zone() != gs->value( "locationZone" ) ); - gs->insert( "locationRegion", location.region ); - gs->insert( "locationZone", location.zone ); + gs->insert( "locationRegion", location->region() ); + gs->insert( "locationZone", location->zone() ); updateGlobalLocale(); @@ -366,7 +352,7 @@ LocalePage::updateGlobalStorage() if ( locationChanged && Calamares::Settings::instance()->doChroot() ) { QProcess::execute( "timedatectl", // depends on systemd - { "set-timezone", location.region + '/' + location.zone } ); + { "set-timezone", location->region() + '/' + location->zone() } ); } #endif @@ -427,12 +413,12 @@ LocalePage::zoneChanged( int currentIndex ) } void -LocalePage::locationChanged( LocaleGlobal::Location location ) +LocalePage::locationChanged( const CalamaresUtils::Locale::TZZone* location ) { m_blockTzWidgetSet = true; // Set region index - int index = m_regionCombo->findData( location.region ); + int index = m_regionCombo->findData( location->region() ); if ( index < 0 ) { return; @@ -441,7 +427,7 @@ LocalePage::locationChanged( LocaleGlobal::Location location ) m_regionCombo->setCurrentIndex( index ); // Set zone index - index = m_zoneCombo->findData( location.zone ); + index = m_zoneCombo->findData( location->zone() ); if ( index < 0 ) { return; diff --git a/src/modules/locale/LocalePage.h b/src/modules/locale/LocalePage.h index 7c2eba253..d6aaa6de8 100644 --- a/src/modules/locale/LocalePage.h +++ b/src/modules/locale/LocalePage.h @@ -70,7 +70,7 @@ private: void regionChanged( int currentIndex ); void zoneChanged( int currentIndex ); - void locationChanged( LocaleGlobal::Location location ); + void locationChanged( const CalamaresUtils::Locale::TZZone* location ); void changeLocale(); void changeFormats(); diff --git a/src/modules/locale/timezonewidget/localeglobal.cpp b/src/modules/locale/timezonewidget/localeglobal.cpp index 593de5cab..d0e889148 100644 --- a/src/modules/locale/timezonewidget/localeglobal.cpp +++ b/src/modules/locale/timezonewidget/localeglobal.cpp @@ -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 LocaleGlobal::init() { diff --git a/src/modules/locale/timezonewidget/localeglobal.h b/src/modules/locale/timezonewidget/localeglobal.h index b5e175c7c..1dc9548d0 100644 --- a/src/modules/locale/timezonewidget/localeglobal.h +++ b/src/modules/locale/timezonewidget/localeglobal.h @@ -51,16 +51,6 @@ public: 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 QHash< QString, QHash< QString, QList< LocaleGlobal::Locale > > > getLocales(); @@ -70,10 +60,4 @@ private: 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 diff --git a/src/modules/locale/timezonewidget/timezonewidget.cpp b/src/modules/locale/timezonewidget/timezonewidget.cpp index 41b5b1980..926226f8c 100644 --- a/src/modules/locale/timezonewidget/timezonewidget.cpp +++ b/src/modules/locale/timezonewidget/timezonewidget.cpp @@ -105,10 +105,10 @@ TimeZoneWidget::setCurrentLocation( QString regionName, QString zoneName ) void TimeZoneWidget::setCurrentLocation( const CalamaresUtils::Locale::TZZone* location ) { - currentLocation = *location; + m_currentLocation = location; // Set zone - QPoint pos = getLocationPosition( currentLocation.longitude, currentLocation.latitude ); + QPoint pos = getLocationPosition( location ); #ifdef DEBUG_TIMEZONES cDebug() << "Setting location" << location->region() << *location; @@ -147,6 +147,7 @@ TimeZoneWidget::setCurrentLocation( const CalamaresUtils::Locale::TZZone* locati // Repaint widget repaint(); + emit locationChanged( m_currentLocation ); } @@ -265,12 +266,12 @@ TimeZoneWidget::paintEvent( QPaintEvent* ) painter.drawPoint( point ); #else // 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 ); // 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(); 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.drawRoundedRect( rect, 3, 3 ); 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 painter.end(); @@ -345,6 +346,6 @@ TimeZoneWidget::mousePressEvent( QMouseEvent* event ) // Set zone image and repaint widget setCurrentLocation( closest ); // Emit signal - emit locationChanged( currentLocation ); + emit locationChanged( m_currentLocation ); } } diff --git a/src/modules/locale/timezonewidget/timezonewidget.h b/src/modules/locale/timezonewidget/timezonewidget.h index 7a3572f10..d91c5cf27 100644 --- a/src/modules/locale/timezonewidget/timezonewidget.h +++ b/src/modules/locale/timezonewidget/timezonewidget.h @@ -43,25 +43,25 @@ class TimeZoneWidget : public QWidget { Q_OBJECT public: + using TZZone = CalamaresUtils::Locale::TZZone; + explicit TimeZoneWidget( QWidget* parent = nullptr ); - LocaleGlobal::Location getCurrentLocation() { return currentLocation; } 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: - void locationChanged( LocaleGlobal::Location location ); + void locationChanged( const TZZone* location ); private: QFont font; QImage background, pin, currentZoneImage; QList< QImage > timeZoneImages; - LocaleGlobal::Location currentLocation; + const TZZone* m_currentLocation = nullptr; // Not owned by me - QPoint getLocationPosition( const LocaleGlobal::Location& l ) - { - return getLocationPosition( l.longitude, l.latitude ); - } + QPoint getLocationPosition( const TZZone* l ) { return getLocationPosition( l->longitude(), l->latitude() ); } QPoint getLocationPosition( double longitude, double latitude ); void paintEvent( QPaintEvent* event );