summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAaron McCarthy <aaron.mccarthy@jollamobile.com>2013-10-17 14:19:34 +1000
committerThe Qt Project <gerrit-noreply@qt-project.org>2013-10-18 05:20:06 +0200
commit654b01af941ec620ca8a9b98be8542dda862d4a8 (patch)
treee40c5cca5957b22e857386913da77d2a9afa986e
parent9f8ab3c280c53bba273cea32fdb5c7801949c344 (diff)
downloadqtlocation-654b01af941ec620ca8a9b98be8542dda862d4a8.tar.gz
Save and restore the last known position.v5.2.0-beta1
Saves the last known location on destruction. Change-Id: Id3c45bed4e94c9e44656d96a8dffc576c7e26a48 Reviewed-by: Alex Blasche <alexander.blasche@digia.com>
-rw-r--r--src/plugins/position/geoclue/qgeopositioninfosource_geocluemaster.cpp28
1 files changed, 27 insertions, 1 deletions
diff --git a/src/plugins/position/geoclue/qgeopositioninfosource_geocluemaster.cpp b/src/plugins/position/geoclue/qgeopositioninfosource_geocluemaster.cpp
index 995ffa38..1a062431 100644
--- a/src/plugins/position/geoclue/qgeopositioninfosource_geocluemaster.cpp
+++ b/src/plugins/position/geoclue/qgeopositioninfosource_geocluemaster.cpp
@@ -43,7 +43,10 @@
#include "qgeopositioninfosource_geocluemaster_p.h"
-#include <QtCore>
+#include <QtCore/QDateTime>
+#include <QtCore/QFile>
+#include <QtCore/QSaveFile>
+#include <QtCore/QStandardPaths>
#ifdef Q_LOCATION_GEOCLUE_DEBUG
#include <QDebug>
@@ -127,6 +130,16 @@ QGeoPositionInfoSourceGeoclueMaster::QGeoPositionInfoSourceGeoclueMaster(QObject
m_lastPositionIsFresh(false), m_lastVelocityIsFresh(false), m_lastVelocity(0),
m_lastPositionFromSatellite(false), m_methods(AllPositioningMethods), m_running(false)
{
+#ifndef QT_NO_DATASTREAM
+ // Load the last known location
+ QFile file(QStandardPaths::writableLocation(QStandardPaths::GenericDataLocation) +
+ QStringLiteral("/qtposition-geoclue"));
+ if (file.open(QIODevice::ReadOnly)) {
+ QDataStream out(&file);
+ out >> m_lastPosition;
+ }
+#endif
+
m_requestTimer.setSingleShot(true);
QObject::connect(&m_requestTimer, SIGNAL(timeout()), this, SLOT(requestUpdateTimeout()));
QObject::connect(&m_updateTimer, SIGNAL(timeout()), this, SLOT(startUpdatesTimeout()));
@@ -134,6 +147,19 @@ QGeoPositionInfoSourceGeoclueMaster::QGeoPositionInfoSourceGeoclueMaster(QObject
QGeoPositionInfoSourceGeoclueMaster::~QGeoPositionInfoSourceGeoclueMaster()
{
+#ifndef QT_NO_DATASTREAM
+ if (m_lastPosition.isValid()) {
+ QSaveFile file(QStandardPaths::writableLocation(QStandardPaths::GenericDataLocation) +
+ QStringLiteral("/qtposition-geoclue"));
+ if (file.open(QIODevice::WriteOnly | QIODevice::Truncate)) {
+ QDataStream out(&file);
+ // Only save position and timestamp.
+ out << QGeoPositionInfo(m_lastPosition.coordinate(), m_lastPosition.timestamp());
+ file.commit();
+ }
+ }
+#endif
+
if (m_pos)
g_object_unref (m_pos);
if (m_vel)