StelLocationMgr.cpp   StelLocationMgr.cpp 
skipping to change at line 19 skipping to change at line 19
* This program is distributed in the hope that it will be useful, * This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of * but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details. * GNU General Public License for more details.
* *
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* 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 "StelLocationMgr.hpp"
#include "StelLocationMgr_p.hpp"
#include "StelApp.hpp" #include "StelApp.hpp"
#include "StelCore.hpp" #include "StelCore.hpp"
#include "StelFileMgr.hpp" #include "StelFileMgr.hpp"
#include "StelLocationMgr.hpp"
#include "StelUtils.hpp" #include "StelUtils.hpp"
#include "StelJsonParser.hpp" #include "StelJsonParser.hpp"
#include "StelLocaleMgr.hpp" #include "StelLocaleMgr.hpp"
#include <QStringListModel> #include <QStringListModel>
#include <QDebug> #include <QDebug>
#include <QFile> #include <QFile>
#include <QDir> #include <QDir>
#include <QNetworkInterface> #include <QNetworkInterface>
#include <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> #include <QTimeZone>
TimezoneNameMap StelLocationMgr::locationDBToIANAtranslations; TimezoneNameMap StelLocationMgr::locationDBToIANAtranslations;
StelLocationMgr::StelLocationMgr() #ifdef ENABLE_GPS
#ifdef ENABLE_LIBGPS
LibGPSLookupHelper::LibGPSLookupHelper(QObject *parent)
: GPSLookupHelper(parent), ready(false)
{
QSettings* conf = StelApp::getInstance().getSettings();
QString gpsdHostname=conf->value("gui/gpsd_hostname", "localhost").t
oString();
QString gpsdPort=conf->value("gui/gpsd_port", DEFAULT_GPSD_PORT).toS
tring();
// Example almost straight from http://www.catb.org/gpsd/client-howt
o.html
gps_rec = new gpsmm(gpsdHostname.toUtf8(), gpsdPort.toUtf8());
if(gps_rec->is_open())
{
ready = gps_rec->stream(WATCH_ENABLE|WATCH_JSON);
}
if(!ready)
qDebug()<<"libGPS lookup not ready, GPSD probably not runnin
g";
}
LibGPSLookupHelper::~LibGPSLookupHelper()
{ {
delete gps_rec;
}
bool LibGPSLookupHelper::isReady()
{
return ready;
}
void LibGPSLookupHelper::query()
{
if(!ready)
{
emit queryError("GPSD helper not ready");
return;
}
StelLocation loc;
int tries=0;
int fixmode=0;
while (tries<10)
{
tries++;
if (!gps_rec->waiting(750000)) // argument usec. wait 0.75 s
ec. (example had 50s)
{
//qDebug() << " - waiting timed out after 0.75sec.";
continue;
}
struct gps_data_t* newdata;
if ((newdata = gps_rec->read()) == Q_NULLPTR)
{
emit queryError("GPSD query: Read error.");
return;
}
else
{
// It is unclear why some data elements seem to be not filled by gps_rec.re
ad().
// if (newdata->status==0) // no fix?
// {
// // This can happen indoors.
// qDebug() << "GPS has no fix.";
// emit gpsResult(false);
// return;
// }
if (newdata->online==0) // no device?
{
// This can happen when unplugging the GPS w
hile running Stellarium,
// or running gpsd with no GPS receiver.
emit queryError("GPS seems offline. No fix."
);
return;
}
fixmode=newdata->fix.mode; // 0:not_seen, 1:no_fix,
2:2Dfix(no alt), 3:3Dfix(perfect)
loc.longitude=newdata->fix.longitude;
loc.latitude=newdata->fix.latitude;
// Frequently hdop, vdop and satellite counts are Na
N. Sometimes they show OK. This is minor issue.
if (fixmode<3)
{
qDebug() << "GPSDfix " << fixmode << ": Loca
tion" << QString("lat %1, long %2, alt %3").arg(loc.latitude).arg(loc.longi
tude).arg(loc.altitude);
qDebug() << " Estimated HDOP " << newdata
->dop.hdop << "m from " << newdata->satellites_used << "(of" << newdata->sa
tellites_visible << "visible) satellites";
}
else
{
loc.altitude=newdata->fix.altitude;
qDebug() << "GPSDfix " << fixmode << ": Loca
tion" << QString("lat %1, long %2, alt %3").arg(loc.latitude).arg(loc.longi
tude).arg(loc.altitude);
qDebug() << " Estimated HDOP " << newdata
->dop.hdop << "m, VDOP " << newdata->dop.vdop << "m from " << newdata->sat
ellites_used << "(of" << newdata->satellites_visible << "visible) satellit
es";
break; // escape from the tries loop
}
}
}
if (fixmode <2)
{
emit queryError("GPSD: Could not get valid position.");
return;
}
if (fixmode<3)
{
qDebug() << "Fix only quality " << fixmode << " after " << t
ries << " tries";
}
qDebug() << "GPSD location" << QString("lat %1, long %2, alt %3").ar
g(loc.latitude).arg(loc.longitude).arg(loc.altitude);
loc.bortleScaleIndex=StelLocation::DEFAULT_BORTLE_SCALE_INDEX;
// Usually you don't leave your time zone with GPS.
loc.ianaTimeZone=StelApp::getInstance().getCore()->getCurrentTimeZon
e();
loc.isUserLocation=true;
loc.planetName="Earth";
loc.name=QString("GPS %1%2 %3%4")
.arg(loc.longitude<0?"W":"E").arg(floor(loc.longitud
e))
.arg(loc.latitude<0?"S":"N").arg(floor(loc.latitude)
);
emit queryFinished(loc);
}
#endif
NMEALookupHelper::NMEALookupHelper(QObject *parent)
: GPSLookupHelper(parent), serial(Q_NULLPTR), nmea(Q_NULLPTR)
{
//use RAII
// Getting a list of ports may enable auto-detection!
QList<QSerialPortInfo> portInfoList=QSerialPortInfo::availablePorts(
);
if (portInfoList.size()==0)
{
qDebug() << "No connected devices found. NMEA GPS lookup fai
led.";
return;
}
QSettings* conf = StelApp::getInstance().getSettings();
// As long as we only have one, this is OK. Else we must do somethin
g about COM3, COM4 etc.
QSerialPortInfo portInfo;
if (portInfoList.size()==1)
{
portInfo=portInfoList.at(0);
}
else
{
#ifdef Q_OS_WIN
QString portName=conf->value("gui/gps_interface", "COM3").to
String();
#else
QString portName=conf->value("gui/gps_interface", "ttyUSB0")
.toString();
#endif
bool portFound=false;
for (int i=0; i<portInfoList.size(); ++i)
{
QSerialPortInfo pi=portInfoList.at(i);
qDebug() << "Serial port list. Make sure you are usi
ng the right configuration.";
qDebug() << "Port: " << pi.portName();
qDebug() << " SystemLocation:" << pi.systemLocation
();
qDebug() << " Description:" << pi.description();
qDebug() << " Manufacturer:" << pi.manufacturer()
;
qDebug() << " VendorID:" << pi.vendorIdentifi
er();
qDebug() << " ProductID:" << pi.productIdentif
ier();
qDebug() << " SerialNumber:" << pi.serialNumber()
;
qDebug() << " Busy:" << pi.isBusy();
qDebug() << " Valid:" << pi.isValid();
qDebug() << " Null:" << pi.isNull();
if (pi.portName()==portName)
{
portInfo=pi;
portFound=true;
}
}
if (!portFound)
{
qDebug() << "Configured port" << portName << "not fo
und. No GPS query.";
return;
}
}
// NMEA-0183 specifies device sends at 4800bps, 8N1. Some devices ho
wever send at 9600, allow this.
// baudrate is configurable via config
qint32 baudrate=conf->value("gui/gps_baudrate", 4800).toInt();
nmea=new QNmeaPositionInfoSource(QNmeaPositionInfoSource::RealTimeMo
de,this);
serial = new QSerialPort(portInfo, nmea);
serial->setBaudRate(baudrate);
serial->setDataBits(QSerialPort::Data8);
serial->setParity(QSerialPort::NoParity);
serial->setStopBits(QSerialPort::OneStop);
serial->setFlowControl(QSerialPort::NoFlowControl);
//serial->open(QIODevice::ReadOnly); // automatic by setDevice below
.
nmea->setDevice(serial);
// TODO Find out what happens if some other serial device is connect
ed? Just timeout/error?
qDebug() << "Query GPS NMEA device at port " << serial->portName();
connect(nmea, SIGNAL(error(QGeoPositionInfoSource::Error)), this, SL
OT(nmeaError(QGeoPositionInfoSource::Error)));
connect(nmea, SIGNAL(positionUpdated(const QGeoPositionInfo)),this,S
LOT(nmeaUpdated(const QGeoPositionInfo)));
connect(nmea, SIGNAL(updateTimeout()),this,SLOT(nmeaTimeout()));
}
void NMEALookupHelper::query()
{
if(isReady())
{
//kick off a update request
nmea->requestUpdate(3000);
}
else
emit queryError("NMEA helper not ready");
}
void NMEALookupHelper::nmeaUpdated(const QGeoPositionInfo &update)
{
qDebug() << "NMEA updated";
QGeoCoordinate coord=update.coordinate();
QDateTime timestamp=update.timestamp();
qDebug() << " - time: " << timestamp.toString();
qDebug() << " - location: Long=" << coord.longitude() << " Lat=" <<
coord.latitude() << " Alt=" << coord.altitude();
if (update.isValid())
{
StelCore *core=StelApp::getInstance().getCore();
StelLocation loc;
loc.longitude=coord.longitude();
loc.latitude=coord.latitude();
// 2D fix may have only long/lat, invalid altitude.
loc.altitude=( qIsNaN(coord.altitude()) ? 0 : (int) floor(co
ord.altitude()));
loc.bortleScaleIndex=StelLocation::DEFAULT_BORTLE_SCALE_INDE
X;
// Usually you don't leave your time zone with GPS.
loc.ianaTimeZone=core->getCurrentTimeZone();
loc.isUserLocation=true;
loc.planetName="Earth";
loc.name=QString("GPS %1%2 %3%4")
.arg(loc.longitude<0?"W":"E").arg(floor(loc.
longitude))
.arg(loc.latitude<0?"S":"N").arg(floor(loc.l
atitude));
emit queryFinished(loc);
}
else
{
emit queryError("NMEA update: invalid package");
}
}
void NMEALookupHelper::nmeaError(QGeoPositionInfoSource::Error error)
{
emit queryError(QString("NMEA general error: %1").arg(error));
}
void NMEALookupHelper::nmeaTimeout()
{
emit queryError("NMEA timeout");
}
#endif
StelLocationMgr::StelLocationMgr()
: nmeaHelper(Q_NULLPTR), libGpsHelper(Q_NULLPTR)
{
// initialize the static QMap first if necessary. // initialize the static QMap first if necessary.
if (locationDBToIANAtranslations.count()==0) if (locationDBToIANAtranslations.count()==0)
{ {
// reported in SF forum on 2017-03-27
locationDBToIANAtranslations.insert("Europe/Minsk", "UTC
+03:00");
locationDBToIANAtranslations.insert("Europe/Samara", "UTC
+04:00");
locationDBToIANAtranslations.insert("America/Cancun", "UTC
-05:00");
locationDBToIANAtranslations.insert("Asia/Kamchatka", "UTC
+12:00");
// Missing on Qt5.7/Win10 as of 2017-03-18. // Missing on Qt5.7/Win10 as of 2017-03-18.
locationDBToIANAtranslations.insert("Europe/Astrakhan", "UTC +04:00"); locationDBToIANAtranslations.insert("Europe/Astrakhan", "UTC +04:00");
locationDBToIANAtranslations.insert("Europe/Ulyanovsk", "UTC +04:00"); locationDBToIANAtranslations.insert("Europe/Ulyanovsk", "UTC +04:00");
locationDBToIANAtranslations.insert("Europe/Kirov", "UTC +03:00"); locationDBToIANAtranslations.insert("Europe/Kirov", "UTC +03:00");
locationDBToIANAtranslations.insert("Asia/Hebron", "Asi a/Jerusalem"); locationDBToIANAtranslations.insert("Asia/Hebron", "Asi a/Jerusalem");
locationDBToIANAtranslations.insert("Asia/Gaza", "Asi a/Jerusalem"); // or use UTC+2:00? (political issue...) locationDBToIANAtranslations.insert("Asia/Gaza", "Asi a/Jerusalem"); // or use UTC+2:00? (political issue...)
locationDBToIANAtranslations.insert("Asia/Kolkata", "Asi a/Calcutta"); locationDBToIANAtranslations.insert("Asia/Kolkata", "Asi a/Calcutta");
locationDBToIANAtranslations.insert("Asia/Kathmandu", "Asi a/Katmandu"); locationDBToIANAtranslations.insert("Asia/Kathmandu", "Asi a/Katmandu");
locationDBToIANAtranslations.insert("Asia/Tomsk", "Asi a/Novosibirsk"); locationDBToIANAtranslations.insert("Asia/Tomsk", "Asi a/Novosibirsk");
locationDBToIANAtranslations.insert("Asia/Barnaul", "UTC +07:00"); locationDBToIANAtranslations.insert("Asia/Barnaul", "UTC +07:00");
skipping to change at line 73 skipping to change at line 334
locationDBToIANAtranslations.insert("America/Argentina/Catam arca", "America/Catamarca"); locationDBToIANAtranslations.insert("America/Argentina/Catam arca", "America/Catamarca");
locationDBToIANAtranslations.insert("America/Argentina/Cordo ba", "America/Cordoba"); locationDBToIANAtranslations.insert("America/Argentina/Cordo ba", "America/Cordoba");
locationDBToIANAtranslations.insert("America/Indiana/Indiana polis", "America/Indianapolis"); locationDBToIANAtranslations.insert("America/Indiana/Indiana polis", "America/Indianapolis");
locationDBToIANAtranslations.insert("America/Kentucky/Louisv ille", "America/Louisville"); locationDBToIANAtranslations.insert("America/Kentucky/Louisv ille", "America/Louisville");
locationDBToIANAtranslations.insert("America/Miquelon", "UTC-03:00"); // Small Canadian island. locationDBToIANAtranslations.insert("America/Miquelon", "UTC-03:00"); // Small Canadian island.
locationDBToIANAtranslations.insert("Africa/Asmara", "Af rica/Asmera"); locationDBToIANAtranslations.insert("Africa/Asmara", "Af rica/Asmera");
locationDBToIANAtranslations.insert("Atlantic/Faroe", "At lantic/Faeroe"); locationDBToIANAtranslations.insert("Atlantic/Faroe", "At lantic/Faeroe");
locationDBToIANAtranslations.insert("Pacific/Pohnpei", "Pa cific/Ponape"); locationDBToIANAtranslations.insert("Pacific/Pohnpei", "Pa cific/Ponape");
locationDBToIANAtranslations.insert("Pacific/Norfolk", "UT C+11:00"); locationDBToIANAtranslations.insert("Pacific/Norfolk", "UT C+11:00");
locationDBToIANAtranslations.insert("Pacific/Pitcairn", "UT C-08:00"); locationDBToIANAtranslations.insert("Pacific/Pitcairn", "UT C-08:00");
// Missing on Qt5.5.1/Ubuntu 16.04.1 LTE as of 2017-03-18 // Missing on Qt5.5.1/Ubuntu 16.04.1 LTE as of 2017-03-18:
locationDBToIANAtranslations.insert("Asia/Rangoon", "As // NOTE: We must add these following zones for lookup in bot
ia/Yangon"); // UTC+6:30 Missing on Ubuntu/Qt5.5.1. h ways: When the binary file is being created for publication on Linux, Ran
goon/Yangon is being translated.
locationDBToIANAtranslations.insert("Asia/Rangoon", "As
ia/Yangon"); // UTC+6:30 Yangon missing on Ubuntu/Qt5.5.1.
locationDBToIANAtranslations.insert("Asia/Yangon", "As
ia/Rangoon"); // This can translate from the binary location file back to t
he zone name as known on Windows.
locationDBToIANAtranslations.insert( "", "UTC"); locationDBToIANAtranslations.insert( "", "UTC");
// N.B. Further missing TZ names will be printed out in the log.txt. Resolve these by adding into this list. // 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. // TODO later: create a text file in user data directory, an d auto-update it weekly.
} }
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.
lastResortLocation = locationForString(conf->value("init_location/la st_location", "Paris, France").toString()); lastResortLocation = locationForString(conf->value("init_location/la st_location", "Paris, France").toString());
} }
StelLocationMgr::~StelLocationMgr()
{
}
StelLocationMgr::StelLocationMgr(const LocationList &locations) StelLocationMgr::StelLocationMgr(const LocationList &locations)
: nmeaHelper(Q_NULLPTR), libGpsHelper(Q_NULLPTR)
{ {
setLocations(locations); setLocations(locations);
QSettings* conf = StelApp::getInstance().getSettings(); QSettings* conf = StelApp::getInstance().getSettings();
// Init to Paris France because it's the center of the world. // Init to Paris France because it's the center of the world.
lastResortLocation = locationForString(conf->value("init_location/la st_location", "Paris, France").toString()); lastResortLocation = locationForString(conf->value("init_location/la st_location", "Paris, France").toString());
} }
void StelLocationMgr::setLocations(const LocationList &locations) void StelLocationMgr::setLocations(const LocationList &locations)
{ {
skipping to change at line 443 skipping to change at line 712
// lookup location from IP address. // lookup location from IP address.
void StelLocationMgr::locationFromIP() void StelLocationMgr::locationFromIP()
{ {
QNetworkRequest req( QUrl( QString("http://freegeoip.net/json/") ) ) ; QNetworkRequest req( QUrl( QString("http://freegeoip.net/json/") ) ) ;
req.setAttribute(QNetworkRequest::CacheLoadControlAttribute, QNetwor kRequest::PreferCache); req.setAttribute(QNetworkRequest::CacheLoadControlAttribute, QNetwor kRequest::PreferCache);
req.setRawHeader("User-Agent", StelUtils::getUserAgentString().toLat in1()); req.setRawHeader("User-Agent", StelUtils::getUserAgentString().toLat in1());
QNetworkReply* networkReply=StelApp::getInstance().getNetworkAccessM anager()->get(req); QNetworkReply* networkReply=StelApp::getInstance().getNetworkAccessM anager()->get(req);
connect(networkReply, SIGNAL(finished()), this, SLOT(changeLocationF romNetworkLookup())); connect(networkReply, SIGNAL(finished()), this, SLOT(changeLocationF romNetworkLookup()));
} }
#ifdef ENABLE_GPS
bool StelLocationMgr::locationFromGPS()
{
#ifdef ENABLE_LIBGPS
if(!libGpsHelper)
{
libGpsHelper = new LibGPSLookupHelper(this);
connect(libGpsHelper, SIGNAL(queryFinished(StelLocation)), t
his, SLOT(changeLocationFromGPSQuery(StelLocation)));
connect(libGpsHelper, SIGNAL(queryError(QString)), this, SLO
T(gpsQueryError(QString)));
}
if(libGpsHelper->isReady())
{
libGpsHelper->query();
return true;
}
#endif
if(!nmeaHelper)
{
nmeaHelper = new NMEALookupHelper(this);
connect(nmeaHelper, SIGNAL(queryFinished(StelLocation)), thi
s, SLOT(changeLocationFromGPSQuery(StelLocation)));
connect(nmeaHelper, SIGNAL(queryError(QString)), this, SLOT(
gpsQueryError(QString)));
}
if(nmeaHelper->isReady())
{
nmeaHelper->query();
return true;
}
emit gpsQueryFinished(false);
return false;
}
void StelLocationMgr::changeLocationFromGPSQuery(const StelLocation &loc)
{
StelApp::getInstance().getCore()->moveObserverTo(loc, 0.0f, 0.0f);
emit gpsQueryFinished(true);
}
void StelLocationMgr::gpsQueryError(const QString &err)
{
qWarning()<<err;
emit gpsQueryFinished(false);
}
#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()
{ {
StelLocation location;
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) { if (networkReply->error() == QNetworkReply::NoError) {
//success //success
QVariantMap locMap = StelJsonParser::parse(networkReply->rea dAll()).toMap(); QVariantMap locMap = StelJsonParser::parse(networkReply->rea dAll()).toMap();
QString ipRegion = locMap.value("region_name").toString(); QString ipRegion = locMap.value("region_name").toString();
QString ipCity = locMap.value("city").toString(); QString ipCity = locMap.value("city").toString();
QString ipCountry = locMap.value("country_name").toString(); // NOTE: Got a short name of country QString ipCountry = locMap.value("country_name").toString(); // NOTE: Got a short name of country
QString ipCountryCode = locMap.value("country_code").toStrin g(); QString ipCountryCode = locMap.value("country_code").toStrin g();
QString ipTimeZone = locMap.value("time_zone").toString(); QString ipTimeZone = locMap.value("time_zone").toString();
float latitude=locMap.value("latitude").toFloat(); float latitude=locMap.value("latitude").toFloat();
float longitude=locMap.value("longitude").toFloat(); float longitude=locMap.value("longitude").toFloat();
qDebug() << "Got location" << QString("%1, %2, %3 (%4, %5; % 6)").arg(ipCity).arg(ipRegion).arg(ipCountry).arg(latitude).arg(longitude). arg(ipTimeZone) << "for IP" << locMap.value("ip").toString(); qDebug() << "Got location" << QString("%1, %2, %3 (%4, %5; % 6)").arg(ipCity).arg(ipRegion).arg(ipCountry).arg(latitude).arg(longitude). arg(ipTimeZone) << "for IP" << locMap.value("ip").toString();
QString locLine= // we re-pack into a new line that will be StelLocation loc;
parsed back by StelLocation... loc.name = (ipCity.isEmpty() ? QString("%1, %2").arg(lati
QString("%1\t%2\t%3\tX\t0\t%4\t%5\t0\t\t%6") tude).arg(longitude) : ipCity);
.arg(ipCity.isEmpty() ? QString("%1, %2").ar loc.state = (ipRegion.isEmpty() ? "IPregion" : ipRegion);
g(latitude).arg(longitude) : ipCity) loc.country = StelLocaleMgr::countryCodeToString(ipCountryCo
.arg(ipRegion.isEmpty() ? "IPregion" : ipRe de.isEmpty() ? "" : ipCountryCode.toLower());
gion) loc.role = QChar(0x0058); // char 'X'
.arg(ipCountryCode.isEmpty() ? "" : ipCountr loc.population = 0;
yCode.toLower()) loc.latitude = latitude;
.arg(latitude<0 ? QString("%1S").arg(-latitu loc.longitude = longitude;
de, 0, 'f', 6) : QString("%1N").arg(latitude, 0, 'f', 6)) loc.altitude = 0;
.arg(longitude<0 ? QString("%1W").arg(-longi loc.bortleScaleIndex = StelLocation::DEFAULT_BORTLE_SCALE_IN
tude, 0, 'f', 6) : QString("%1E").arg(longitude, 0, 'f', 6)) DEX;
.arg(ipTimeZone.isEmpty() ? "" : ipTimeZone) loc.ianaTimeZone = (ipTimeZone.isEmpty() ? "" : ipTimeZone);
; loc.planetName = "Earth";
location=StelLocation::createFromLine(locLine); // in lack o loc.landscapeKey = "";
f a regular constructor ;-)
core->setCurrentTimeZone(ipTimeZone.isEmpty() ? "LMST" : ipT imeZone); core->setCurrentTimeZone(ipTimeZone.isEmpty() ? "LMST" : ipT imeZone);
core->moveObserverTo(location, 0.0f, 0.0f); core->moveObserverTo(loc, 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();
// 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();
 End of changes. 14 change blocks. 
25 lines changed or deleted 397 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/