Subsurface-mobile: don't create the GPS source until it is needed

This should accelerate the startup of the UI a little more.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
This commit is contained in:
Dirk Hohndel 2015-11-30 10:58:18 -08:00
parent f6ae8bf3ea
commit 2311bc2378
2 changed files with 24 additions and 10 deletions

View file

@ -19,8 +19,19 @@ GpsLocation::GpsLocation(void (*showMsgCB)(const char *), QObject *parent)
// create a QSettings object that's separate from the main application settings
geoSettings = new QSettings(QSettings::NativeFormat, QSettings::UserScope,
QString("org.subsurfacedivelog"), QString("subsurfacelocation"), this);
gpsSource = QGeoPositionInfoSource::createDefaultSource(parent);
userAgent = getUserAgent();
}
QGeoPositionInfoSource *GpsLocation::getGpsSource()
{
static QGeoPositionInfoSource *gpsSource = NULL;
static bool initGpsSource = false;
if (!initGpsSource) {
gpsSource = QGeoPositionInfoSource::createDefaultSource(this);
initGpsSource = true;
if (gpsSource != 0) {
status("created GPS source");
QString msg = QString("have position source %1").arg(gpsSource->sourceName());
connect(gpsSource, SIGNAL(positionUpdated(QGeoPositionInfo)), this, SLOT(newPosition(QGeoPositionInfo)));
connect(gpsSource, SIGNAL(updateTimeout()), this, SLOT(updateTimeout()));
@ -28,16 +39,19 @@ GpsLocation::GpsLocation(void (*showMsgCB)(const char *), QObject *parent)
} else {
status("don't have GPS source");
}
userAgent = getUserAgent();
}
return gpsSource;
}
bool GpsLocation::hasLocationsSource()
{
QGeoPositionInfoSource *gpsSource = getGpsSource();
return gpsSource != 0 && (gpsSource->supportedPositioningMethods() & QGeoPositionInfoSource::SatellitePositioningMethods);
}
void GpsLocation::serviceEnable(bool toggle)
{
QGeoPositionInfoSource *gpsSource = getGpsSource();
if (!gpsSource) {
if (toggle)
status("Can't start location service, no location source available");

View file

@ -21,7 +21,7 @@ public:
private:
QGeoPositionInfo lastPos;
QGeoPositionInfoSource *gpsSource;
QGeoPositionInfoSource *getGpsSource();
void status(QString msg);
QSettings *geoSettings;
QNetworkReply *reply;