StelLocationMgr.cpp   StelLocationMgr.cpp 
skipping to change at line 764 skipping to change at line 764
} }
#endif #endif
// slot that receives IP-based location data from the network. // slot that receives IP-based location data from the network.
void StelLocationMgr::changeLocationFromNetworkLookup() void StelLocationMgr::changeLocationFromNetworkLookup()
{ {
StelCore *core=StelApp::getInstance().getCore(); StelCore *core=StelApp::getInstance().getCore();
QNetworkReply* networkReply = qobject_cast<QNetworkReply*>(sender()) ; QNetworkReply* networkReply = qobject_cast<QNetworkReply*>(sender()) ;
if (!networkReply) if (!networkReply)
return; return;
if (networkReply->error() == QNetworkReply::NoError) {
//success if (networkReply->error() == QNetworkReply::NoError && networkReply-
>bytesAvailable()>0)
{
// success
QVariantMap locMap = StelJsonParser::parse(networkReply->rea dAll()).toMap(); QVariantMap locMap = StelJsonParser::parse(networkReply->rea dAll()).toMap();
QString ipRegion = locMap.value("region_name").toString(); if (!locMap.isEmpty())
QString ipCity = locMap.value("city").toString(); {
QString ipCountry = locMap.value("country_name").toString(); QString ipRegion = locMap.value("region_name").toStr
// NOTE: Got a short name of country ing();
QString ipCountryCode = locMap.value("country_code").toStrin QString ipCity = locMap.value("city").toString();
g(); QString ipCountry = locMap.value("country_name").toS
QString ipTimeZone = locMap.value("time_zone").toString(); tring(); // NOTE: Got a short name of country
float latitude=locMap.value("latitude").toFloat(); QString ipCountryCode = locMap.value("country_code")
float longitude=locMap.value("longitude").toFloat(); .toString();
QString ipTimeZone = locMap.value("time_zone").toStr
qDebug() << "Got location" << QString("%1, %2, %3 (%4, %5; % ing();
6)").arg(ipCity).arg(ipRegion).arg(ipCountry).arg(latitude).arg(longitude). float latitude=locMap.value("latitude").toFloat();
arg(ipTimeZone) << "for IP" << locMap.value("ip").toString(); float longitude=locMap.value("longitude").toFloat();
StelLocation loc; qDebug() << "Got location" << QString("%1, %2, %3 (%
loc.name = (ipCity.isEmpty() ? QString("%1, %2").arg(lati 4, %5; %6)").arg(ipCity).arg(ipRegion).arg(ipCountry).arg(latitude).arg(lon
tude).arg(longitude) : ipCity); gitude).arg(ipTimeZone) << "for IP" << locMap.value("ip").toString();
loc.state = (ipRegion.isEmpty() ? "IPregion" : ipRegion);
loc.country = StelLocaleMgr::countryCodeToString(ipCountryCo StelLocation loc;
de.isEmpty() ? "" : ipCountryCode.toLower()); loc.name = (ipCity.isEmpty() ? QString("%1, %2").
loc.role = QChar(0x0058); // char 'X' arg(latitude).arg(longitude) : ipCity);
loc.population = 0; loc.state = (ipRegion.isEmpty() ? "IPregion" : ip
loc.latitude = latitude; Region);
loc.longitude = longitude; loc.country = StelLocaleMgr::countryCodeToString(ipC
loc.altitude = 0; ountryCode.isEmpty() ? "" : ipCountryCode.toLower());
loc.bortleScaleIndex = StelLocation::DEFAULT_BORTLE_SCALE_IN loc.role = QChar(0x0058); // char 'X'
DEX; loc.population = 0;
loc.ianaTimeZone = (ipTimeZone.isEmpty() ? "" : ipTimeZone); loc.latitude = latitude;
loc.planetName = "Earth"; loc.longitude = longitude;
loc.landscapeKey = ""; loc.altitude = 0;
loc.bortleScaleIndex = StelLocation::DEFAULT_BORTLE_
core->setCurrentTimeZone(ipTimeZone.isEmpty() ? "LMST" : ipT SCALE_INDEX;
imeZone); loc.ianaTimeZone = (ipTimeZone.isEmpty() ? "" : ipTi
core->moveObserverTo(loc, 0.0f, 0.0f); meZone);
QSettings* conf = StelApp::getInstance().getSettings(); loc.planetName = "Earth";
conf->setValue("init_location/last_location", QString("%1,%2 loc.landscapeKey = "";
").arg(latitude).arg(longitude));
core->setCurrentTimeZone(ipTimeZone.isEmpty() ? "LMS
T" : ipTimeZone);
core->moveObserverTo(loc, 0.0f, 0.0f);
QSettings* conf = StelApp::getInstance().getSettings
();
conf->setValue("init_location/last_location", QStrin
g("%1,%2").arg(latitude).arg(longitude));
}
else
{
qDebug() << "Failure getting IP-based location: answ
er is in not acceptable format! Let's use Paris, France as default location
...";
core->moveObserverTo(getLastResortLocation(), 0.0f,
0.0f); // Answer is not in JSON format! A possible block by DNS server or f
irewall
}
} }
else else
{ {
qDebug() << "Failure getting IP-based location: \n\t" <<netw orkReply->errorString(); qDebug() << "Failure getting IP-based location: \n\t" << net workReply->errorString();
// If there is a problem, this must not change to some other location! // If there is a problem, this must not change to some other location!
//core->moveObserverTo(lastResortLocation, 0.0f, 0.0f); //core->moveObserverTo(lastResortLocation, 0.0f, 0.0f);
} }
networkReply->deleteLater(); networkReply->deleteLater();
} }
LocationMap StelLocationMgr::pickLocationsNearby(const QString planetName, const float longitude, const float latitude, const float radiusDegrees) LocationMap StelLocationMgr::pickLocationsNearby(const QString planetName, const float longitude, const float latitude, const float radiusDegrees)
{ {
QMap<QString, StelLocation> results; QMap<QString, StelLocation> results;
QMapIterator<QString, StelLocation> iter(locations); QMapIterator<QString, StelLocation> iter(locations);
 End of changes. 3 change blocks. 
40 lines changed or deleted 60 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/