summaryrefslogtreecommitdiffstats
path: root/core/gpslocation.cpp
diff options
context:
space:
mode:
authorGravatar Dirk Hohndel <dirk@hohndel.org>2016-04-17 22:41:30 -0700
committerGravatar Dirk Hohndel <dirk@hohndel.org>2016-04-17 22:59:02 -0700
commitb00306f50e489be144c8acec6944c2d4ac0b861c (patch)
tree567549f876e79a6178692b06e106fce2928c6cf9 /core/gpslocation.cpp
parent5e4290996415d5ac927ac108aefad286248ca21d (diff)
downloadsubsurface-b00306f50e489be144c8acec6944c2d4ac0b861c.tar.gz
GPS provider: track tristate information for GPS source
Initially we don't know if we have a source. After that we may think that we have one, or not have one (but that can actually change while the program is running if the user, for example, turns the source off or switches to airplane mode). Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
Diffstat (limited to 'core/gpslocation.cpp')
-rw-r--r--core/gpslocation.cpp26
1 files changed, 16 insertions, 10 deletions
diff --git a/core/gpslocation.cpp b/core/gpslocation.cpp
index b56cb7b8c..3866fdc8a 100644
--- a/core/gpslocation.cpp
+++ b/core/gpslocation.cpp
@@ -21,21 +21,20 @@
GpsLocation *GpsLocation::m_Instance = NULL;
-GpsLocation::GpsLocation(void (*showMsgCB)(const char *), QObject *parent) : QObject(parent)
+GpsLocation::GpsLocation(void (*showMsgCB)(const char *), QObject *parent) :
+ QObject(parent),
+ m_GpsSource(0),
+ waitingForPosition(false),
+ haveSource(UNKNOWN)
{
Q_ASSERT_X(m_Instance == NULL, "GpsLocation", "GpsLocation recreated");
m_Instance = this;
- m_GpsSource = 0;
- waitingForPosition = false;
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(QString("Found GPS with positioning methods %1").arg(QString::number(m_GpsSource->supportedPositioningMethods(), 16)));
-#endif
userAgent = getUserAgent();
+ (void)getGpsSource();
loadFromStorage();
}
@@ -53,9 +52,14 @@ GpsLocation::~GpsLocation()
QGeoPositionInfoSource *GpsLocation::getGpsSource()
{
+ if (haveSource == NOGPS)
+ return 0;
+
if (!m_GpsSource) {
m_GpsSource = QGeoPositionInfoSource::createDefaultSource(this);
if (m_GpsSource != 0) {
+ haveSource = (m_GpsSource->supportedPositioningMethods() & QGeoPositionInfoSource::SatellitePositioningMethods) ? HAVEGPS : NOGPS;
+ emit haveSourceChanged();
#ifndef SUBSURFACE_MOBILE
if (verbose)
#endif
@@ -67,6 +71,8 @@ QGeoPositionInfoSource *GpsLocation::getGpsSource()
#ifdef SUBSURFACE_MOBILE
status("don't have GPS source");
#endif
+ haveSource = NOGPS;
+ emit haveSourceChanged();
}
}
return m_GpsSource;
@@ -74,14 +80,14 @@ QGeoPositionInfoSource *GpsLocation::getGpsSource()
bool GpsLocation::hasLocationsSource()
{
- QGeoPositionInfoSource *gpsSource = getGpsSource();
- return gpsSource != 0 && (gpsSource->supportedPositioningMethods() & QGeoPositionInfoSource::SatellitePositioningMethods);
+ (void)getGpsSource();
+ return haveSource == HAVEGPS;
}
void GpsLocation::serviceEnable(bool toggle)
{
QGeoPositionInfoSource *gpsSource = getGpsSource();
- if (!gpsSource) {
+ if (haveSource != HAVEGPS) {
if (toggle)
status("Can't start location service, no location source available");
return;