From b00306f50e489be144c8acec6944c2d4ac0b861c Mon Sep 17 00:00:00 2001 From: Dirk Hohndel Date: Sun, 17 Apr 2016 22:41:30 -0700 Subject: 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 --- core/gpslocation.cpp | 26 ++++++++++++++++---------- core/gpslocation.h | 4 ++++ 2 files changed, 20 insertions(+), 10 deletions(-) (limited to 'core') 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; diff --git a/core/gpslocation.h b/core/gpslocation.h index e1b485832..c6e4a7912 100644 --- a/core/gpslocation.h +++ b/core/gpslocation.h @@ -52,6 +52,10 @@ private: void replaceFixToStorage(gpsTracker >); void deleteFixFromStorage(gpsTracker >); void deleteFixesFromServer(); + enum { UNKNOWN, NOGPS, HAVEGPS } haveSource; + +signals: + void haveSourceChanged(); public slots: void serviceEnable(bool toggle); -- cgit v1.2.3-70-g09d2