diff options
author | Aaron McCarthy <aaron.mccarthy@jollamobile.com> | 2013-10-03 16:32:26 +1000 |
---|---|---|
committer | The Qt Project <gerrit-noreply@qt-project.org> | 2013-10-08 08:48:36 +0200 |
commit | 32cb5bcec7a63c9c9f858cca950693b789ddba8c (patch) | |
tree | 0c23a97b213c1f87a53afd8072321049afa0bafe | |
parent | f01f3bc181f579680867b9dd9a71f52f71c8ee83 (diff) |
Emit updates from Geoclue when an update interval is not specified.
An update interval of 0 is valid and means provide position updates as
frequently as the provider can supply them. The state of the update
timer was being used as the check for whether updates should be
provided. This is invalid for the case of a 0 update interval as the
update timer is not started.
Change-Id: I2c9d3fef41abaa21feafd31b232a7053d179ffd6
Reviewed-by: Alex Blasche <alexander.blasche@digia.com>
-rw-r--r-- | src/plugins/position/geoclue/qgeopositioninfosource_geocluemaster.cpp | 32 | ||||
-rw-r--r-- | src/plugins/position/geoclue/qgeopositioninfosource_geocluemaster_p.h | 1 |
2 files changed, 21 insertions, 12 deletions
diff --git a/src/plugins/position/geoclue/qgeopositioninfosource_geocluemaster.cpp b/src/plugins/position/geoclue/qgeopositioninfosource_geocluemaster.cpp index d6269858..b276f2f6 100644 --- a/src/plugins/position/geoclue/qgeopositioninfosource_geocluemaster.cpp +++ b/src/plugins/position/geoclue/qgeopositioninfosource_geocluemaster.cpp @@ -125,7 +125,7 @@ static void position_callback (GeocluePosition *pos, QGeoPositionInfoSourceGeoclueMaster::QGeoPositionInfoSourceGeoclueMaster(QObject *parent) : QGeoPositionInfoSource(parent), QGeoclueMaster(this), m_updateInterval(0), m_pos(0), m_vel(0), m_lastPositionIsFresh(false), m_lastVelocityIsFresh(false), m_lastVelocity(0), - m_lastPositionFromSatellite(false), m_methods(AllPositioningMethods) + m_lastPositionFromSatellite(false), m_methods(AllPositioningMethods), m_running(false) { m_requestTimer.setSingleShot(true); QObject::connect(&m_requestTimer, SIGNAL(timeout()), this, SLOT(requestUpdateTimeout())); @@ -319,23 +319,26 @@ QGeoPositionInfoSourceGeoclueMaster::PositioningMethods QGeoPositionInfoSourceGe void QGeoPositionInfoSourceGeoclueMaster::startUpdates() { - if (m_updateTimer.isActive()) { + if (m_running) { #ifdef Q_LOCATION_GEOCLUE_DEBUG qDebug() << "QGeoPositionInfoSourceGeoclueMaster timer was active, ignoring startUpdates: " << m_updateInterval; #endif return; } - if (!m_pos) { - // May happen if source has been changed unsuccesfully - emit updateTimeout(); - return; - } + + m_running = true; + if (m_updateInterval > 0) { #ifdef Q_LOCATION_GEOCLUE_DEBUG qDebug() << "QGeoPositionInfoSourceGeoclueMaster startUpdates with interval: " << m_updateInterval; #endif m_updateTimer.start(m_updateInterval); } + + // m_pos and m_vel are likely to be invalid until Geoclue master selects a position provider. + if (!m_pos) + return; + g_signal_connect (G_OBJECT (m_pos), "position-changed", G_CALLBACK (position_changed),this); if (m_vel) { @@ -350,13 +353,15 @@ int QGeoPositionInfoSourceGeoclueMaster::minimumUpdateInterval() const { void QGeoPositionInfoSourceGeoclueMaster::stopUpdates() { + if (!m_running) + return; + if (m_updateTimer.isActive()) m_updateTimer.stop(); - if (m_pos) { + if (m_pos) g_signal_handlers_disconnect_by_func(G_OBJECT(m_pos), (void *)position_changed, this); - } if (m_vel) { + if (m_vel) g_signal_handlers_disconnect_by_func(G_OBJECT(m_vel), (void *)velocity_changed, this); - } } void QGeoPositionInfoSourceGeoclueMaster::requestUpdate(int timeout) @@ -411,18 +416,21 @@ void QGeoPositionInfoSourceGeoclueMaster::positionProviderChanged(const QByteArr m_pos = geoclue_position_new(service.constData(), path.constData()); if (m_pos) { - if (m_updateTimer.isActive()) + if (m_running) { g_signal_connect(G_OBJECT(m_pos), "position-changed", G_CALLBACK(position_changed), this); + } // Get the current position immediately. geoclue_position_get_position_async(m_pos, position_callback, this); m_vel = geoclue_velocity_new(service.constData(), path.constData()); - if (m_vel && m_updateTimer.isActive()) + if (m_vel && m_running) { g_signal_connect(G_OBJECT(m_vel), "velocity-changed", G_CALLBACK(velocity_changed), this); + } } else { + m_running = false; m_updateTimer.stop(); m_requestTimer.stop(); emit updateTimeout(); diff --git a/src/plugins/position/geoclue/qgeopositioninfosource_geocluemaster_p.h b/src/plugins/position/geoclue/qgeopositioninfosource_geocluemaster_p.h index ff351b6a..a54bc198 100644 --- a/src/plugins/position/geoclue/qgeopositioninfosource_geocluemaster_p.h +++ b/src/plugins/position/geoclue/qgeopositioninfosource_geocluemaster_p.h @@ -137,6 +137,7 @@ private: bool m_lastPositionFromSatellite; QGeoPositionInfo m_lastPosition; PositioningMethods m_methods; + bool m_running; }; QT_END_NAMESPACE |