summaryrefslogtreecommitdiffstats
path: root/subsurface-core/gpslocation.cpp
diff options
context:
space:
mode:
authorGravatar Dirk Hohndel <dirk@hohndel.org>2015-11-30 10:58:18 -0800
committerGravatar Dirk Hohndel <dirk@hohndel.org>2015-11-30 10:58:18 -0800
commit2311bc23787c12b5ce6abe0c995fc23f8d2ddce1 (patch)
tree2da30ea21bf8cc9d3c8e60f8d44a048df9cf4da3 /subsurface-core/gpslocation.cpp
parentf6ae8bf3ea6fee354bd4298fd0ebadd91fb0d36e (diff)
downloadsubsurface-2311bc23787c12b5ce6abe0c995fc23f8d2ddce1.tar.gz
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>
Diffstat (limited to 'subsurface-core/gpslocation.cpp')
-rw-r--r--subsurface-core/gpslocation.cpp32
1 files changed, 23 insertions, 9 deletions
diff --git a/subsurface-core/gpslocation.cpp b/subsurface-core/gpslocation.cpp
index c0d55a0be..e75856a98 100644
--- a/subsurface-core/gpslocation.cpp
+++ b/subsurface-core/gpslocation.cpp
@@ -19,25 +19,39 @@ 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);
- if (gpsSource != 0) {
- 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()));
- gpsSource->setUpdateInterval(5 * 60 * 1000); // 5 minutes so the device doesn't drain the battery
- } else {
- status("don't have GPS source");
- }
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()));
+ gpsSource->setUpdateInterval(5 * 60 * 1000); // 5 minutes so the device doesn't drain the battery
+ } else {
+ status("don't have GPS source");
+ }
+ }
+ 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");