StelLocationMgr.cpp   StelLocationMgr.cpp 
skipping to change at line 85 skipping to change at line 85
QFile sourcefile(cityDataPath); QFile sourcefile(cityDataPath);
if (!sourcefile.open(QIODevice::ReadOnly)) if (!sourcefile.open(QIODevice::ReadOnly))
{ {
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"))
{ {
// FIXME: This code doesn't work with MSVC2012 -- need fix! --AW
QDataStream in(StelUtils::uncompress(sourcefile.readAll())); QDataStream in(StelUtils::uncompress(sourcefile.readAll()));
in.setVersion(QDataStream::Qt_4_6); in.setVersion(QDataStream::Qt_4_6);
in >> res; in >> res;
return res; return res;
} }
else else
{ {
QDataStream in(&sourcefile); QDataStream in(&sourcefile);
in.setVersion(QDataStream::Qt_4_6); in.setVersion(QDataStream::Qt_4_6);
in >> res; in >> res;
skipping to change at line 212 skipping to change at line 211
ret.longitude = parseAngle(reg.capturedTexts()[3].trimmed(), &ok); ret.longitude = parseAngle(reg.capturedTexts()[3].trimmed(), &ok);
if (!ok) ret.role = '!'; if (!ok) ret.role = '!';
ret.name = reg.capturedTexts()[1].trimmed(); ret.name = reg.capturedTexts()[1].trimmed();
ret.planetName = "Earth"; ret.planetName = "Earth";
return ret; return ret;
} }
ret.role = '!'; ret.role = '!';
return ret; return ret;
} }
const StelLocation StelLocationMgr::locationFromCLI() const
{
StelLocation ret;
QSettings* conf = StelApp::getInstance().getSettings();
bool ok;
conf->beginGroup("location_run_once");
ret.latitude = parseAngle(StelUtils::radToDmsStr(conf->value("latitu
de").toFloat(), true), &ok);
if (!ok) ret.role = '!';
ret.longitude = parseAngle(StelUtils::radToDmsStr(conf->value("longi
tude").toFloat(), true), &ok);
if (!ok) ret.role = '!';
ret.altitude = conf->value("altitude", 0).toInt(&ok);
ret.planetName = conf->value("home_planet", "Earth").toString();
ret.landscapeKey = conf->value("landscape_name", "guereins").toStrin
g();
conf->endGroup();
conf->remove("location_run_once");
return ret;
}
// Get whether a location can be permanently added to the list of user loca tions // Get whether a location can be permanently added to the list of user loca tions
bool StelLocationMgr::canSaveUserLocation(const StelLocation& loc) const bool StelLocationMgr::canSaveUserLocation(const StelLocation& loc) const
{ {
return loc.isValid() && locations.find(loc.getID())==locations.end() ; return loc.isValid() && locations.find(loc.getID())==locations.end() ;
} }
// Add permanently a location to the list of user locations // Add permanently a location to the list of user locations
bool StelLocationMgr::saveUserLocation(const StelLocation& loc) bool StelLocationMgr::saveUserLocation(const StelLocation& loc)
{ {
if (!canSaveUserLocation(loc)) if (!canSaveUserLocation(loc))
skipping to change at line 344 skipping to change at line 361
// 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()
{ {
StelLocation location; StelLocation location;
StelCore *core=StelApp::getInstance().getCore(); StelCore *core=StelApp::getInstance().getCore();
if (networkReply->error() == QNetworkReply::NoError) { if (networkReply->error() == QNetworkReply::NoError) {
//success //success
// Tested with and without working network connection. // Tested with and without working network connection.
QByteArray answer=networkReply->readAll(); QByteArray answer=networkReply->readAll();
// answer/splitline example: "222.222.222.222","AT","Austria qDebug() << "IP answer:" << answer;
","","","","","47.3333","13.3333","","" // answer/splitline example: "222.222.222.222","AT","Aus
tria","","","","","47.3333","13.3333","",""
// The parts from freegeoip are: ip,country_code,country_nam e,region_code,region_name,city,zipcode,latitude,longitude,metro_code,area_c ode // The parts from freegeoip are: ip,country_code,country_nam e,region_code,region_name,city,zipcode,latitude,longitude,metro_code,area_c ode
// Changed before 2014-11-21 to: 222.222.222.222,AT,Austria,
"","","","",Europe/Vienna,47.33,13.33,0<CR><LF> (i.e., only empty strings h
ave "")
// Now: ip,country_code,country_nam
e,region_code,region_name,city,zipcode,Timezone_name,latitude,longitude,met
ro_code
// longitude and latitude should always be filled. // longitude and latitude should always be filled.
// A few tests: // A few tests:
if ((answer.count('"') != 22 ) || (answer.count(',') != 10 ) ) if (answer.count(',') != 10 )
{ {
qDebug() << "StelLocationMgr: Malformatted answer in IP-based location lookup: \n\t" << answer; qDebug() << "StelLocationMgr: Malformatted answer in IP-based location lookup: \n\t" << answer;
qDebug() << "StelLocationMgr: Will not change locati on."; qDebug() << "StelLocationMgr: Will not change locati on.";
networkReply->deleteLater(); networkReply->deleteLater();
return; return;
} }
const QStringList& splitline = QString(answer).split(","); const QStringList& splitline = QString(answer).split(",");
if (splitline.count() != 11 ) if (splitline.count() != 11 )
{ {
qDebug() << "StelLocationMgr: Unexpected answer in I P-based location lookup: \n\t" << answer; qDebug() << "StelLocationMgr: Unexpected answer in I P-based location lookup: \n\t" << answer;
qDebug() << "StelLocationMgr: Will not change locati on."; qDebug() << "StelLocationMgr: Will not change locati on.";
networkReply->deleteLater(); networkReply->deleteLater();
return; return;
} }
if ((splitline.at(7)=="\"\"") || (splitline.at(8)=="\"\"")) // KEEP FOR DEBUGGING:
// empty coordinates? //for (int i=0; i<splitline.count(); ++i)
// qDebug() << "Component" << i << "length:" << splitli
ne.at(i).length() << ":" << splitline.at(i);
if ((splitline.at(8)=="\"\"") || (splitline.at(9)=="\"\""))
// empty coordinates?
{ {
qDebug() << "StelLocationMgr: Invalid coordinates fr om IP-based lookup. Ignoring: \n\t" << answer; qDebug() << "StelLocationMgr: Invalid coordinates fr om IP-based lookup. Ignoring: \n\t" << answer;
networkReply->deleteLater(); networkReply->deleteLater();
return; return;
} }
float latitude=splitline.at(7).mid(1, splitline.at(7).length float latitude=splitline.at(8).toFloat();
()-2).toFloat(); float longitude=splitline.at(9).toFloat();
float longitude=splitline.at(8).mid(1, splitline.at(8).lengt
h()-2).toFloat();
QString locLine= // we re-pack into a new line that will be parsed back by StelLocation... QString locLine= // we re-pack into a new line that will be parsed back by StelLocation...
QString("%1\t%2\t%3\t%4\t%5\t%6\t%7\t0") QString("%1\t%2\t%3\t%4\t%5\t%6\t%7\t0")
.arg(splitline.at(5).length()>2 ? splitline. .arg(splitline.at(5) == "\"\"" ? QString("%1
at(5).mid(1, splitline.at(5).length()-2) : QString("IP%1").arg(splitline.a , %2").arg(latitude).arg(longitude) : splitline.at(5))
t(0).mid(1, splitline.at(0).length()-2))) .arg(splitline.at(4) == "\"\"" ? "IPregion"
.arg(splitline.at(4).length()>2 ? splitline. : splitline.at(4))
at(4).mid(1, splitline.at(4).length()-2) : "IPregion") .arg(splitline.at(2) == "\"\"" ? "IPcountry"
.arg(splitline.at(2).length()>2 ? splitline. : splitline.at(2)) // countryCode
at(2).mid(1, splitline.at(2).length()-2) : "IPcountry") // country
.arg("X") // role: X=user-defined .arg("X") // role: X=user-defined
.arg(0) // population: unknown .arg(0) // population: unknown
.arg(latitude<0 ? QString("%1S").arg(-latitu de, 0, 'f', 6) : QString("%1N").arg(latitude, 0, 'f', 6)) .arg(latitude<0 ? QString("%1S").arg(-latitu de, 0, 'f', 6) : QString("%1N").arg(latitude, 0, 'f', 6))
.arg(longitude<0 ? QString("%1W").arg(-longi tude, 0, 'f', 6) : QString("%1E").arg(longitude, 0, 'f', 6)); .arg(longitude<0 ? QString("%1W").arg(-longi tude, 0, 'f', 6) : QString("%1E").arg(longitude, 0, 'f', 6));
location=StelLocation::createFromLine(locLine); // in lack o f a regular constructor ;-) location=StelLocation::createFromLine(locLine); // in lack o f a regular constructor ;-)
core->moveObserverTo(location, 0.0f, 0.0f); core->moveObserverTo(location, 0.0f, 0.0f);
QSettings* conf = StelApp::getInstance().getSettings(); QSettings* conf = StelApp::getInstance().getSettings();
conf->setValue("init_location/last_location", QString("%1, % 2").arg(latitude).arg(longitude)); conf->setValue("init_location/last_location", QString("%1,%2 ").arg(latitude).arg(longitude));
} }
else else
{ {
qDebug() << "Failure getting IP-based location: \n\t" <<netw orkReply->errorString(); qDebug() << "Failure getting IP-based location: \n\t" <<netw orkReply->errorString();
core->moveObserverTo(lastResortLocation, 0.0f, 0.0f); // If there is a problem, this must not change to some other
location!
//core->moveObserverTo(lastResortLocation, 0.0f, 0.0f);
} }
networkReply->deleteLater(); networkReply->deleteLater();
} }
void StelLocationMgr::pickLocationsNearby(const QString planetName, const f loat longitude, const float latitude, const float radiusDegrees) void StelLocationMgr::pickLocationsNearby(const QString planetName, const f loat longitude, const float latitude, const float radiusDegrees)
{ {
pickedLocations.clear(); pickedLocations.clear();
QMapIterator<QString, StelLocation> iter(locations); QMapIterator<QString, StelLocation> iter(locations);
while (iter.hasNext()) while (iter.hasNext())
{ {
 End of changes. 10 change blocks. 
19 lines changed or deleted 49 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/