diff --git a/src/libcalamares/locale/TimeZone.cpp b/src/libcalamares/locale/TimeZone.cpp index 4bf23150a..dd8ffbf41 100644 --- a/src/libcalamares/locale/TimeZone.cpp +++ b/src/libcalamares/locale/TimeZone.cpp @@ -147,8 +147,7 @@ TZRegion::fromFile( const char* fileName ) return model; } - QStringList regions; - + TZRegion* thisRegion = nullptr; QTextStream in( &file ); while ( !in.atEnd() ) { @@ -177,10 +176,16 @@ TZRegion::fromFile( const char* fileName ) continue; } - if ( !regions.contains( region ) ) + auto it + = std::find_if( model.begin(), model.end(), [®ion]( const TZRegion* r ) { return r->m_key == region; } ); + if ( it != model.end() ) + { + thisRegion = *it; + } + else { - regions.append( region ); - model.append( new TZRegion( region.toUtf8().data() ) ); + thisRegion = new TZRegion( region.toUtf8().data() ); + model.append( thisRegion ); } QString countryCode = list.at( 0 ).trimmed(); @@ -190,11 +195,15 @@ TZRegion::fromFile( const char* fileName ) } timezoneParts.removeFirst(); - TZZone z( timezoneParts.join( '/' ).toUtf8().constData(), countryCode, list.at( 1 ) ); - cDebug() << "Region" << region << z; + thisRegion->m_zones.append( new TZZone( timezoneParts.join( '/' ).toUtf8().constData(), countryCode, list.at( 1 ) ) ); } std::sort( model.begin(), model.end(), []( const TZRegion* l, const TZRegion* r ) { return *l < *r; } ); + for ( auto& r : model ) + { + std::sort( r->m_zones.begin(), r->m_zones.end(), []( const TZZone* l, const TZZone* r ) { return *l < *r; } ); + } + return model; } diff --git a/src/libcalamares/locale/TimeZone.h b/src/libcalamares/locale/TimeZone.h index 6e4ba062d..896661b99 100644 --- a/src/libcalamares/locale/TimeZone.h +++ b/src/libcalamares/locale/TimeZone.h @@ -60,6 +60,8 @@ public: QString key() const { return m_key; } + bool operator<( const CStringPair& other ) const { return m_key < other.m_key; } + protected: char* m_human = nullptr; QString m_key; @@ -78,8 +80,6 @@ public: virtual ~TZRegion(); QString tr() const override; - bool operator<( const TZRegion& other ) const { return m_key < other.m_key; } - /** @brief Create model from a zone.tab-like file * * Returns a list of all the regions; each region has a list