StelLocationMgr.cpp   StelLocationMgr.cpp 
skipping to change at line 25 skipping to change at line 25
* along with this program; if not, write to the Free Software * along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA. * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA.
*/ */
#include "StelApp.hpp" #include "StelApp.hpp"
#include "StelCore.hpp" #include "StelCore.hpp"
#include "StelFileMgr.hpp" #include "StelFileMgr.hpp"
#include "StelLocationMgr.hpp" #include "StelLocationMgr.hpp"
#include "StelUtils.hpp" #include "StelUtils.hpp"
#include "StelJsonParser.hpp" #include "StelJsonParser.hpp"
#include "StelLocaleMgr.hpp"
#include <QStringListModel> #include <QStringListModel>
#include <QDebug> #include <QDebug>
#include <QFile> #include <QFile>
#include <QDir> #include <QDir>
#include <QtNetwork/QNetworkInterface> #include <QNetworkInterface>
#include <QtNetwork/QNetworkAccessManager> #include <QNetworkAccessManager>
#include <QNetworkRequest> #include <QNetworkRequest>
#include <QNetworkReply> #include <QNetworkReply>
#include <QUrl> #include <QUrl>
#include <QUrlQuery> #include <QUrlQuery>
#include <QSettings> #include <QSettings>
#include <QTimeZone>
TimezoneNameMap StelLocationMgr::locationDBToIANAtranslations;
StelLocationMgr::StelLocationMgr() StelLocationMgr::StelLocationMgr()
{ {
// initialize the static QMap first if necessary.
if (locationDBToIANAtranslations.count()==0)
{
// Missing on Qt5.7/Win10 as of 2017-03-18.
locationDBToIANAtranslations.insert("Europe/Astrakhan", "UTC
+04:00");
locationDBToIANAtranslations.insert("Europe/Ulyanovsk", "UTC
+04:00");
locationDBToIANAtranslations.insert("Europe/Kirov", "UTC
+03:00");
locationDBToIANAtranslations.insert("Asia/Hebron", "Asi
a/Jerusalem");
locationDBToIANAtranslations.insert("Asia/Gaza", "Asi
a/Jerusalem"); // or use UTC+2:00? (political issue...)
locationDBToIANAtranslations.insert("Asia/Kolkata", "Asi
a/Calcutta");
locationDBToIANAtranslations.insert("Asia/Kathmandu", "Asi
a/Katmandu");
locationDBToIANAtranslations.insert("Asia/Tomsk", "Asi
a/Novosibirsk");
locationDBToIANAtranslations.insert("Asia/Barnaul", "UTC
+07:00");
locationDBToIANAtranslations.insert("Asia/Ho_Chi_Minh", "Asi
a/Saigon");
locationDBToIANAtranslations.insert("Asia/Hovd", "UTC
+07:00");
locationDBToIANAtranslations.insert("America/Argentina/Bueno
s_Aires", "America/Buenos_Aires");
locationDBToIANAtranslations.insert("America/Argentina/Jujuy
", "America/Jujuy");
locationDBToIANAtranslations.insert("America/Argentina/Mendo
za", "America/Mendoza");
locationDBToIANAtranslations.insert("America/Argentina/Catam
arca", "America/Catamarca");
locationDBToIANAtranslations.insert("America/Argentina/Cordo
ba", "America/Cordoba");
locationDBToIANAtranslations.insert("America/Indiana/Indiana
polis", "America/Indianapolis");
locationDBToIANAtranslations.insert("America/Kentucky/Louisv
ille", "America/Louisville");
locationDBToIANAtranslations.insert("America/Miquelon",
"UTC-03:00"); // Small Canadian island.
locationDBToIANAtranslations.insert("Africa/Asmara", "Af
rica/Asmera");
locationDBToIANAtranslations.insert("Atlantic/Faroe", "At
lantic/Faeroe");
locationDBToIANAtranslations.insert("Pacific/Pohnpei", "Pa
cific/Ponape");
locationDBToIANAtranslations.insert("Pacific/Norfolk", "UT
C+11:00");
locationDBToIANAtranslations.insert("Pacific/Pitcairn", "UT
C-08:00");
// Missing on Qt5.5.1/Ubuntu 16.04.1 LTE as of 2017-03-18
locationDBToIANAtranslations.insert("Asia/Rangoon", "As
ia/Yangon"); // UTC+6:30 Missing on Ubuntu/Qt5.5.1.
locationDBToIANAtranslations.insert( "", "UTC");
// N.B. Further missing TZ names will be printed out in the
log.txt. Resolve these by adding into this list.
// TODO later: create a text file in user data directory.
}
QSettings* conf = StelApp::getInstance().getSettings(); QSettings* conf = StelApp::getInstance().getSettings();
// The line below allows to re-generate the location file, you still need to gunzip it manually afterward. // The line below allows to re-generate the location file, you still need to gunzip it manually afterward.
if (conf->value("devel/convert_locations_list", false).toBool()) if (conf->value("devel/convert_locations_list", false).toBool())
generateBinaryLocationFile("data/base_locations.txt", false, "data/base_locations.bin"); generateBinaryLocationFile("data/base_locations.txt", false, "data/base_locations.bin");
locations = loadCitiesBin("data/base_locations.bin.gz"); locations = loadCitiesBin("data/base_locations.bin.gz");
locations.unite(loadCities("data/user_locations.txt", true)); locations.unite(loadCities("data/user_locations.txt", true));
// Init to Paris France because it's the center of the world. // Init to Paris France because it's the center of the world.
skipping to change at line 105 skipping to change at line 145
{ {
qWarning() << "ERROR: Could not open location data file: " < < QDir::toNativeSeparators(cityDataPath); qWarning() << "ERROR: Could not open location data file: " < < QDir::toNativeSeparators(cityDataPath);
return res; return res;
} }
if (fileName.endsWith(".gz")) if (fileName.endsWith(".gz"))
{ {
QDataStream in(StelUtils::uncompress(sourcefile.readAll())); QDataStream in(StelUtils::uncompress(sourcefile.readAll()));
in.setVersion(QDataStream::Qt_5_2); in.setVersion(QDataStream::Qt_5_2);
in >> res; in >> res;
return res;
} }
else else
{ {
QDataStream in(&sourcefile); QDataStream in(&sourcefile);
in.setVersion(QDataStream::Qt_5_2); in.setVersion(QDataStream::Qt_5_2);
in >> res; in >> res;
return res;
} }
// Now res has all location data. However, some timezone names are n
ot available in various versions of Qt.
// Sanity checks: It seems we must translate timezone names. Quite a
number on Windows, but also still some on Linux.
QList<QByteArray> availableTimeZoneList=QTimeZone::availableTimeZone
Ids();
QStringList unknownTZlist;
QMap<QString, StelLocation>::iterator i=res.begin();
while (i!=res.end())
{
StelLocation loc=i.value();
if ((loc.ianaTimeZone!="LMST") && (loc.ianaTimeZone!="LTST"
) && ( ! availableTimeZoneList.contains(loc.ianaTimeZone.toUtf8())) )
{
// TZ name which is currently unknown to Qt detected
. See if we can translate it, if not: complain to qDebug().
QString fixTZname=sanitizeTimezoneStringFromLocation
DB(loc.ianaTimeZone);
if (availableTimeZoneList.contains(fixTZname.toUtf8(
)))
{
loc.ianaTimeZone=fixTZname;
i.value() = loc;
}
else
{
qDebug() << "StelLocationMgr::loadCitiesBin(
): TimeZone for " << loc.name << " not found: " << loc.ianaTimeZone;
unknownTZlist.append(loc.ianaTimeZone);
}
}
++i;
}
if (unknownTZlist.length()>0)
{
unknownTZlist.removeDuplicates();
qDebug() << "StelLocationMgr::loadCitiesBin(): Summary of un
known TimeZones:";
QStringList::const_iterator t=unknownTZlist.begin();
while (t!=unknownTZlist.end())
{
qDebug() << *t;
++t;
}
qDebug() << "Please report these timezone names (this logfil
e) to the Stellarium developers.";
// Note to developers: Fill those names and replacements to
the map above.
}
return res;
} }
// Done in the following: TZ name sanitizing also for text file!
LocationMap StelLocationMgr::loadCities(const QString& fileName, bool isUse rLocation) LocationMap StelLocationMgr::loadCities(const QString& fileName, bool isUse rLocation)
{ {
// Load the cities from data file // Load the cities from data file
QMap<QString, StelLocation> locations; QMap<QString, StelLocation> locations;
QString cityDataPath = StelFileMgr::findFile(fileName); QString cityDataPath = StelFileMgr::findFile(fileName);
if (cityDataPath.isEmpty()) if (cityDataPath.isEmpty())
{ {
// Note it is quite normal not to have a user locations file (e.g. first run) // Note it is quite normal not to have a user locations file (e.g. first run)
if (!isUserLocation) if (!isUserLocation)
qWarning() << "WARNING: Failed to locate location da ta file: " << QDir::toNativeSeparators(fileName); qWarning() << "WARNING: Failed to locate location da ta file: " << QDir::toNativeSeparators(fileName);
skipping to change at line 440 skipping to change at line 519
{ {
iter.next(); iter.next();
const StelLocation *loc=&iter.value(); const StelLocation *loc=&iter.value();
if (loc->country == country) if (loc->country == country)
{ {
results.insert(iter.key(), iter.value()); results.insert(iter.key(), iter.value());
} }
} }
return results; return results;
} }
// Check timezone string and return either the same or the corresponding st
ring that we use in the Stellarium location database.
// If timezone name starts with "UTC", always return unchanged.
// This is required to store timezone names exactly as we know them, and no
t mix ours and corrent-iana spelling flavour.
// In practice, reverse lookup to locationDBToIANAtranslations
QString StelLocationMgr::sanitizeTimezoneStringForLocationDB(QString tzStri
ng)
{
if (tzString.startsWith("UTC"))
return tzString;
QByteArray res=locationDBToIANAtranslations.key(tzString.toUtf8(), "
---");
if ( res != "---")
return QString(res);
return tzString;
}
// Attempt to translate a timezone name from those used in Stellarium's loc
ation database to a name which is valid
// as ckeckable by QTimeZone::availableTimeZoneIds(). That list may be upda
ted anytime and is known to differ
// between OSes. Some spellings may be different, or in some cases some nam
es get simply translated to "UTC+HH:MM" style.
// The empty string gets translated to "UTC".
QString StelLocationMgr::sanitizeTimezoneStringFromLocationDB(QString dbStr
ing)
{
if (dbString.startsWith("UTC"))
return dbString;
// Maybe silences a debug later:
if (dbString=="")
return "UTC";
QByteArray res=locationDBToIANAtranslations.value(dbString.toUtf8(),
"---");
if ( res != "---")
return QString(res);
return dbString;
}
 End of changes. 9 change blocks. 
4 lines changed or deleted 120 lines changed or added

This html diff was produced by rfcdiff 1.41. The latest version is available from http://tools.ietf.org/tools/rfcdiff/