summaryrefslogtreecommitdiffstats
path: root/subsurface-core
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
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')
-rw-r--r--subsurface-core/gpslocation.cpp32
-rw-r--r--subsurface-core/gpslocation.h2
2 files changed, 24 insertions, 10 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");
diff --git a/subsurface-core/gpslocation.h b/subsurface-core/gpslocation.h
index 8796b3100..e0e825cb1 100644
--- a/subsurface-core/gpslocation.h
+++ b/subsurface-core/gpslocation.h
@@ -21,7 +21,7 @@ public:
private:
QGeoPositionInfo lastPos;
- QGeoPositionInfoSource *gpsSource;
+ QGeoPositionInfoSource *getGpsSource();
void status(QString msg);
QSettings *geoSettings;
QNetworkReply *reply;