|
|
|
@ -18,8 +18,14 @@
|
|
|
|
|
|
|
|
|
|
#include "TimeZone.h"
|
|
|
|
|
|
|
|
|
|
#include <QFile>
|
|
|
|
|
#include <QStringList>
|
|
|
|
|
#include <QTextStream>
|
|
|
|
|
|
|
|
|
|
#include <cstring>
|
|
|
|
|
|
|
|
|
|
static const char TZ_DATA_FILE[] = "/usr/share/zoneinfo/zone.tab";
|
|
|
|
|
|
|
|
|
|
namespace CalamaresUtils
|
|
|
|
|
{
|
|
|
|
|
namespace Locale
|
|
|
|
@ -27,6 +33,8 @@ namespace Locale
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
CStringPair::CStringPair( CStringPair&& t )
|
|
|
|
|
: m_human( nullptr )
|
|
|
|
|
, m_key( nullptr )
|
|
|
|
|
{
|
|
|
|
|
// My pointers are initialized to nullptr
|
|
|
|
|
std::swap( m_human, t.m_human );
|
|
|
|
@ -94,5 +102,83 @@ TZZone::tr() const
|
|
|
|
|
return QObject::tr( m_human, "tz_names" );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TZRegionModel::TZRegionModel()
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
QFile file( TZ_DATA_FILE );
|
|
|
|
|
if ( !file.open( QIODevice::ReadOnly | QIODevice::Text ) )
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QStringList regions;
|
|
|
|
|
|
|
|
|
|
QTextStream in( &file );
|
|
|
|
|
while ( !in.atEnd() )
|
|
|
|
|
{
|
|
|
|
|
QString line = in.readLine().trimmed().split( '#', QString::KeepEmptyParts ).first().trimmed();
|
|
|
|
|
if ( line.isEmpty() )
|
|
|
|
|
{
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QStringList list = line.split( QRegExp( "[\t ]" ), QString::SkipEmptyParts );
|
|
|
|
|
if ( list.size() < 3 )
|
|
|
|
|
{
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QStringList timezoneParts = list.at( 2 ).split( '/', QString::SkipEmptyParts );
|
|
|
|
|
if ( timezoneParts.size() < 2 )
|
|
|
|
|
{
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QString region = timezoneParts.first().trimmed();
|
|
|
|
|
;
|
|
|
|
|
if ( region.isEmpty() )
|
|
|
|
|
{
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if ( !regions.contains( region ) )
|
|
|
|
|
{
|
|
|
|
|
regions.append( region );
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
m_regions.reserve( regions.length() );
|
|
|
|
|
for ( int i = 0; i < regions.length(); ++i )
|
|
|
|
|
{
|
|
|
|
|
m_regions.append( TZRegion( regions[ i ].toUtf8().data() ) );
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TZRegionModel::~TZRegionModel() {}
|
|
|
|
|
|
|
|
|
|
int
|
|
|
|
|
TZRegionModel::rowCount( const QModelIndex& parent ) const
|
|
|
|
|
{
|
|
|
|
|
return m_regions.count();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QVariant
|
|
|
|
|
TZRegionModel::data( const QModelIndex& index, int role ) const
|
|
|
|
|
{
|
|
|
|
|
if ( role != LabelRole )
|
|
|
|
|
{
|
|
|
|
|
return QVariant();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if ( !index.isValid() )
|
|
|
|
|
{
|
|
|
|
|
return QVariant();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const TZRegion& region = m_regions.at( index.row() );
|
|
|
|
|
return region.tr();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} // namespace Locale
|
|
|
|
|
} // namespace CalamaresUtils
|
|
|
|
|