mirror of https://github.com/cutefishos/calamares
Merge branch 'issue-1374'
SEE #1374 This isn't a fix, it just adds a test that demonstrates the scope of the problem.main
commit
da440256d9
@ -0,0 +1,205 @@
|
||||
/* === This file is part of Calamares - <https://github.com/calamares> ===
|
||||
*
|
||||
* Copyright 2020, Adriaan de Groot <groot@kde.org>
|
||||
*
|
||||
* Calamares is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Calamares is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with Calamares. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "TimeZoneImage.h"
|
||||
|
||||
#include "utils/Logger.h"
|
||||
|
||||
#include <QDir>
|
||||
|
||||
static const char* zoneNames[]
|
||||
= { "0.0", "1.0", "2.0", "3.0", "3.5", "4.0", "4.5", "5.0", "5.5", "5.75", "6.0", "6.5", "7.0",
|
||||
"8.0", "9.0", "9.5", "10.0", "10.5", "11.0", "11.5", "12.0", "12.75", "13.0", "-1.0", "-2.0", "-3.0",
|
||||
"-3.5", "-4.0", "-4.5", "-5.0", "-5.5", "-6.0", "-7.0", "-8.0", "-9.0", "-9.5", "-10.0", "-11.0" };
|
||||
static_assert( TimeZoneImageList::zoneCount == ( sizeof( zoneNames ) / sizeof( zoneNames[ 0 ] ) ),
|
||||
"Incorrect number of zones" );
|
||||
|
||||
#define ZONE_NAME QStringLiteral( "zone" )
|
||||
|
||||
TimeZoneImageList::TimeZoneImageList() {}
|
||||
|
||||
TimeZoneImageList
|
||||
TimeZoneImageList::fromQRC()
|
||||
{
|
||||
TimeZoneImageList l;
|
||||
for ( const auto* zoneName : zoneNames )
|
||||
{
|
||||
l.append( QImage( QStringLiteral( ":/images/timezone_" ) + zoneName + ".png" ) );
|
||||
l.last().setText( ZONE_NAME, zoneName );
|
||||
}
|
||||
|
||||
return l;
|
||||
}
|
||||
|
||||
TimeZoneImageList
|
||||
TimeZoneImageList::fromDirectory( const QString& dirName )
|
||||
{
|
||||
TimeZoneImageList l;
|
||||
QDir dir( dirName );
|
||||
if ( !dir.exists() )
|
||||
{
|
||||
cWarning() << "TimeZone images directory" << dirName << "does not exist.";
|
||||
return l;
|
||||
}
|
||||
|
||||
for ( const auto* zoneName : zoneNames )
|
||||
{
|
||||
l.append( QImage( dir.filePath( QStringLiteral( "timezone_" ) + zoneName + ".png" ) ) );
|
||||
l.last().setText( ZONE_NAME, zoneName );
|
||||
}
|
||||
|
||||
return l;
|
||||
}
|
||||
|
||||
QPoint
|
||||
TimeZoneImageList::getLocationPosition( double longitude, double latitude )
|
||||
{
|
||||
constexpr double MAP_Y_OFFSET = 0.125;
|
||||
constexpr double MAP_X_OFFSET = -0.0370;
|
||||
constexpr double MATH_PI = 3.14159265;
|
||||
|
||||
const int width = imageSize.width();
|
||||
const int height = imageSize.height();
|
||||
|
||||
double x = ( width / 2.0 + ( width / 2.0 ) * longitude / 180.0 ) + MAP_X_OFFSET * width;
|
||||
double y = ( height / 2.0 - ( height / 2.0 ) * latitude / 90.0 ) + MAP_Y_OFFSET * height;
|
||||
|
||||
// Far north, the MAP_Y_OFFSET no longer holds, cancel the Y offset; it's noticeable
|
||||
// from 62 degrees north, so scale those 28 degrees as if the world is flat south
|
||||
// of there, and we have a funny "rounded" top of the world. In practice the locations
|
||||
// of the different cities / regions looks ok -- at least Thule ends up in the right
|
||||
// country, and Inuvik isn't in the ocean.
|
||||
if ( latitude > 70.0 )
|
||||
{
|
||||
y -= sin( MATH_PI * ( latitude - 70.0 ) / 56.0 ) * MAP_Y_OFFSET * height * 0.8;
|
||||
}
|
||||
if ( latitude > 74.0 )
|
||||
{
|
||||
y += 4;
|
||||
}
|
||||
if ( latitude > 69.0 )
|
||||
{
|
||||
y -= 2;
|
||||
}
|
||||
if ( latitude > 59.0 )
|
||||
{
|
||||
y -= 4 * int( ( latitude - 54.0 ) / 5.0 );
|
||||
}
|
||||
if ( latitude > 54.0 )
|
||||
{
|
||||
y -= 2;
|
||||
}
|
||||
if ( latitude > 49.0 )
|
||||
{
|
||||
y -= int( ( latitude - 44.0 ) / 5.0 );
|
||||
}
|
||||
// Far south, some stretching occurs as well, but it is less pronounced.
|
||||
// Move down by 1 pixel per 5 degrees past 10 south
|
||||
if ( latitude < 0 )
|
||||
{
|
||||
y += int( ( -latitude ) / 5.0 );
|
||||
}
|
||||
// Antarctica isn't shown on the map, but you could try clicking there
|
||||
if ( latitude < -60 )
|
||||
{
|
||||
y = height - 1;
|
||||
}
|
||||
|
||||
if ( x < 0 )
|
||||
{
|
||||
x = width + x;
|
||||
}
|
||||
if ( x >= width )
|
||||
{
|
||||
x -= width;
|
||||
}
|
||||
if ( y < 0 )
|
||||
{
|
||||
y = height + y;
|
||||
}
|
||||
if ( y >= height )
|
||||
{
|
||||
y -= height;
|
||||
}
|
||||
|
||||
return QPoint( int( x ), int( y ) );
|
||||
}
|
||||
|
||||
// Pixel value indicating that a spot is outside of a zone
|
||||
static constexpr const int RGB_TRANSPARENT = 0;
|
||||
|
||||
int
|
||||
TimeZoneImageList::index( QPoint pos, int& count ) const
|
||||
{
|
||||
count = 0;
|
||||
|
||||
#ifdef DEBUG_TIMEZONES
|
||||
for ( int i = 0; i < size(); ++i )
|
||||
{
|
||||
const QImage& zone = at( i );
|
||||
|
||||
// If not transparent set as current
|
||||
if ( zone.pixel( pos ) != RGB_TRANSPARENT )
|
||||
{
|
||||
// Log *all* the zones that contain this point,
|
||||
// but only pick the first.
|
||||
if ( !count )
|
||||
{
|
||||
cDebug() << Logger::SubEntry << "First zone found" << i << zone.text( ZONE_NAME );
|
||||
}
|
||||
else
|
||||
{
|
||||
cDebug() << Logger::SubEntry << "Also in zone" << i << zone.text( ZONE_NAME );
|
||||
}
|
||||
count++;
|
||||
}
|
||||
}
|
||||
if ( !count )
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
#endif
|
||||
return index( pos );
|
||||
}
|
||||
|
||||
int
|
||||
TimeZoneImageList::index( QPoint pos ) const
|
||||
{
|
||||
for ( int i = 0; i < size(); ++i )
|
||||
{
|
||||
const QImage& zone = at( i );
|
||||
|
||||
// If not transparent set as current
|
||||
if ( zone.pixel( pos ) != RGB_TRANSPARENT )
|
||||
{
|
||||
return i;
|
||||
}
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
QImage
|
||||
TimeZoneImageList::find( QPoint p ) const
|
||||
{
|
||||
int i = index( p );
|
||||
if ( i < 0 || size() <= i )
|
||||
{
|
||||
return QImage();
|
||||
}
|
||||
return at( i );
|
||||
}
|
@ -0,0 +1,85 @@
|
||||
/* === This file is part of Calamares - <https://github.com/calamares> ===
|
||||
*
|
||||
* Copyright 2020, Adriaan de Groot <groot@kde.org>
|
||||
*
|
||||
* Calamares is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Calamares is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with Calamares. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef TIMEZONEIMAGE_H
|
||||
#define TIMEZONEIMAGE_H
|
||||
|
||||
#include <QImage>
|
||||
#include <QList>
|
||||
|
||||
using TimeZoneImage = QImage;
|
||||
|
||||
/** @brief All the timezone images
|
||||
*
|
||||
* There's one fixed list of timezone images that can be loaded
|
||||
* from the QRC, or from the source directory.
|
||||
*/
|
||||
class TimeZoneImageList : public QList< TimeZoneImage >
|
||||
{
|
||||
private:
|
||||
TimeZoneImageList();
|
||||
|
||||
public:
|
||||
/** @brief loads all the images from QRC.
|
||||
*
|
||||
* The images are assumed to be compiled into the Qt resource
|
||||
* system and are loaded from there.
|
||||
*/
|
||||
static TimeZoneImageList fromQRC();
|
||||
/** @brief loads all the images from a specified directory.
|
||||
*
|
||||
* No error is returned if files are missing.
|
||||
*/
|
||||
static TimeZoneImageList fromDirectory( const QString& dirName );
|
||||
|
||||
/** @brief Map longitude and latitude to pixel positions
|
||||
*
|
||||
* The image is flat, and stretched at the poles and generally
|
||||
* a bit weird, so this maps the global coordinates (as found in
|
||||
* the zones table as a floating-point longitude and latitude value)
|
||||
* to an x,y position.
|
||||
*/
|
||||
static QPoint getLocationPosition( double longitude, double latitude );
|
||||
|
||||
/** @brief Find the index of the image claiming point @p p
|
||||
*
|
||||
* This maps a point (presumably from getLocationPosition(), so
|
||||
* originating from a longitude and latitude) to a specific zone
|
||||
* image index. Returns -1 if no image claims the point (e.g. if
|
||||
* it is out of bounds).
|
||||
*/
|
||||
int index( QPoint p ) const;
|
||||
/** @brief Find the index of the image claiming point @p p
|
||||
*
|
||||
* As `index(p)`, but also fills in @p count with the number of
|
||||
* zones that claim the point.
|
||||
*/
|
||||
int index( QPoint p, int& count ) const;
|
||||
/** @brief Get image of the zone claiming @p p
|
||||
*
|
||||
* Can return a null image, if the point is unclaimed or invalid.
|
||||
*/
|
||||
QImage find( QPoint p ) const;
|
||||
|
||||
/// @brief The **expected** number of zones in the list.
|
||||
static constexpr const int zoneCount = 38;
|
||||
/// @brief The expected size of each zone image.
|
||||
static constexpr const QSize imageSize = QSize( 780, 340 );
|
||||
};
|
||||
|
||||
#endif
|
@ -1,126 +0,0 @@
|
||||
/* === This file is part of Calamares - <https://github.com/calamares> ===
|
||||
*
|
||||
* Copyright 2014-2016, Teo Mrnjavac <teo@kde.org>
|
||||
*
|
||||
* Originally from the Manjaro Installation Framework
|
||||
* by Roland Singer <roland@manjaro.org>
|
||||
* Copyright (C) 2007 Free Software Foundation, Inc.
|
||||
*
|
||||
* Calamares is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Calamares is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with Calamares. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "localeglobal.h"
|
||||
|
||||
#include "locale/TimeZone.h"
|
||||
|
||||
#include <QTimeZone>
|
||||
|
||||
//###
|
||||
//### Private variables
|
||||
//###
|
||||
|
||||
QHash< QString, QHash< QString, QList< LocaleGlobal::Locale > > > LocaleGlobal::locales;
|
||||
|
||||
|
||||
//###
|
||||
//### Public methods
|
||||
//###
|
||||
|
||||
|
||||
void
|
||||
LocaleGlobal::init()
|
||||
{
|
||||
// TODO: Error handling
|
||||
initLocales();
|
||||
}
|
||||
|
||||
|
||||
QHash< QString, QHash< QString, QList< LocaleGlobal::Locale > > >
|
||||
LocaleGlobal::getLocales()
|
||||
{
|
||||
return locales;
|
||||
}
|
||||
|
||||
|
||||
//###
|
||||
//### Private methods
|
||||
//###
|
||||
|
||||
|
||||
void
|
||||
LocaleGlobal::initLocales()
|
||||
{
|
||||
static const char LOCALESDIR[] = "/usr/share/i18n/locales";
|
||||
|
||||
locales.clear();
|
||||
|
||||
QStringList files = QDir( LOCALESDIR ).entryList( QDir::Files, QDir::Name );
|
||||
|
||||
for ( int i = 0; i < files.size(); ++i )
|
||||
{
|
||||
QString filename = files.at( i );
|
||||
QFile file( QString( LOCALESDIR ) + "/" + filename );
|
||||
if ( !file.open( QIODevice::ReadOnly | QIODevice::Text ) )
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
QTextStream in( &file );
|
||||
QString commentChar = "%";
|
||||
Locale locale;
|
||||
QString lang, territory;
|
||||
|
||||
locale.locale = filename;
|
||||
|
||||
while ( !in.atEnd() )
|
||||
{
|
||||
QString line = in.readLine().trimmed();
|
||||
QStringList split = line.split( commentChar, QString::KeepEmptyParts )
|
||||
.first()
|
||||
.split( QRegExp( " (?=[^\"]*(\"[^\"]*\"[^\"]*)*$)" ), QString::SkipEmptyParts );
|
||||
|
||||
if ( split.size() < 2 )
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
QString sub1 = QString( split.at( 0 ) ).remove( "\"" );
|
||||
QString sub2 = QString( split.at( 1 ) ).remove( "\"" );
|
||||
|
||||
if ( sub1 == "comment_char" )
|
||||
{
|
||||
commentChar = sub2;
|
||||
}
|
||||
else if ( sub1 == "title" )
|
||||
{
|
||||
locale.description = sub2;
|
||||
}
|
||||
else if ( sub1 == "territory" )
|
||||
{
|
||||
territory = sub2;
|
||||
}
|
||||
else if ( sub1 == "language" )
|
||||
{
|
||||
lang = sub2;
|
||||
}
|
||||
}
|
||||
|
||||
if ( lang.isEmpty() || territory.isEmpty() )
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
locales[ lang ][ territory ].append( locale );
|
||||
}
|
||||
}
|
@ -1,63 +0,0 @@
|
||||
/* === This file is part of Calamares - <https://github.com/calamares> ===
|
||||
*
|
||||
* Copyright 2014-2016, Teo Mrnjavac <teo@kde.org>
|
||||
* Copyright 2019, Adriaan de Groot <groot@kde.org>
|
||||
*
|
||||
* Originally from the Manjaro Installation Framework
|
||||
* by Roland Singer <roland@manjaro.org>
|
||||
* Copyright (C) 2007 Free Software Foundation, Inc.
|
||||
*
|
||||
* Calamares is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Calamares is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with Calamares. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef LOCALEGLOBAL_H
|
||||
#define LOCALEGLOBAL_H
|
||||
|
||||
#include <QDebug>
|
||||
#include <QDir>
|
||||
#include <QFile>
|
||||
#include <QHash>
|
||||
#include <QList>
|
||||
#include <QMap>
|
||||
#include <QRegExp>
|
||||
#include <QString>
|
||||
#include <QStringList>
|
||||
#include <QTextStream>
|
||||
|
||||
namespace CalamaresUtils
|
||||
{
|
||||
namespace Locale
|
||||
{
|
||||
class TZZone;
|
||||
}
|
||||
} // namespace CalamaresUtils
|
||||
|
||||
class LocaleGlobal
|
||||
{
|
||||
public:
|
||||
struct Locale
|
||||
{
|
||||
QString description, locale;
|
||||
};
|
||||
|
||||
static void init();
|
||||
static QHash< QString, QHash< QString, QList< LocaleGlobal::Locale > > > getLocales();
|
||||
|
||||
private:
|
||||
static QHash< QString, QHash< QString, QList< LocaleGlobal::Locale > > > locales;
|
||||
|
||||
static void initLocales();
|
||||
};
|
||||
|
||||
#endif // LOCALEGLOBAL_H
|
Loading…
Reference in New Issue