summaryrefslogtreecommitdiffstats
path: root/subsurface-core/gpslocation.cpp
diff options
context:
space:
mode:
authorGravatar Dirk Hohndel <dirk@hohndel.org>2016-01-01 17:19:28 -0800
committerGravatar Dirk Hohndel <dirk@hohndel.org>2016-01-01 17:26:09 -0800
commita611bb22f7dedd0377397c2e42a2bb9d6e1a4110 (patch)
treed28c28f48720a2e7f7eecad453300f085f6a2732 /subsurface-core/gpslocation.cpp
parent87fc84a5eee6f6dbdfc2269b7ddf27324473d94e (diff)
downloadsubsurface-a611bb22f7dedd0377397c2e42a2bb9d6e1a4110.tar.gz
Location service: restructure the way GpsSource is managed
It makes much more sense to have this as a private member of the class instead of a static in one of the functions. Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
Diffstat (limited to 'subsurface-core/gpslocation.cpp')
-rw-r--r--subsurface-core/gpslocation.cpp25
1 files changed, 13 insertions, 12 deletions
diff --git a/subsurface-core/gpslocation.cpp b/subsurface-core/gpslocation.cpp
index fd6b43049..5790bc2d8 100644
--- a/subsurface-core/gpslocation.cpp
+++ b/subsurface-core/gpslocation.cpp
@@ -19,10 +19,15 @@ GpsLocation::GpsLocation(void (*showMsgCB)(const char *), QObject *parent)
{
Q_ASSERT_X(m_Instance == NULL, "GpsLocation", "GpsLocation recreated");
m_Instance = this;
+ m_GpsSource = 0;
showMessageCB = showMsgCB;
// 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);
+#ifdef SUBSURFACE_MOBILE
+ if (hasLocationsSource())
+ status("Found GPS");
+#endif
userAgent = getUserAgent();
}
@@ -40,28 +45,24 @@ GpsLocation::~GpsLocation()
QGeoPositionInfoSource *GpsLocation::getGpsSource()
{
- static QGeoPositionInfoSource *gpsSource = NULL;
- static bool initGpsSource = false;
-
- if (!initGpsSource) {
- gpsSource = QGeoPositionInfoSource::createDefaultSource(this);
- initGpsSource = true;
- if (gpsSource != 0) {
+ if (!m_GpsSource) {
+ m_GpsSource = QGeoPositionInfoSource::createDefaultSource(this);
+ if (m_GpsSource != 0) {
#ifndef SUBSURFACE_MOBILE
if (verbose)
#endif
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
+ QString msg = QString("have position source %1").arg(m_GpsSource->sourceName());
+ connect(m_GpsSource, SIGNAL(positionUpdated(QGeoPositionInfo)), this, SLOT(newPosition(QGeoPositionInfo)));
+ connect(m_GpsSource, SIGNAL(updateTimeout()), this, SLOT(updateTimeout()));
+ m_GpsSource->setUpdateInterval(5 * 60 * 1000); // 5 minutes so the device doesn't drain the battery
} else {
#ifdef SUBSURFACE_MOBILE
status("don't have GPS source");
#endif
}
}
- return gpsSource;
+ return m_GpsSource;
}
bool GpsLocation::hasLocationsSource()