summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar Dirk Hohndel <dirk@hohndel.org>2015-11-11 15:19:09 -0800
committerGravatar Dirk Hohndel <dirk@hohndel.org>2015-11-11 15:28:10 -0800
commit62f7ec11d72aeb4edbf4d6063ed3059912c7545a (patch)
treece80e830b90477cb9b3a4e13af2d6dfce268c42f
parentcd7d6ae6e51a8422a141fc389b2eca232b7e93c5 (diff)
downloadsubsurface-62f7ec11d72aeb4edbf4d6063ed3059912c7545a.tar.gz
Location service: store locations in settings
This is rather simplistic and will clutter the settings. I'm not convinced this is the BEST way to do this, but it's a rather straight forward way to get persistant storage of the location fixes. Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
-rw-r--r--qt-mobile/gpslocation.cpp27
-rw-r--r--qt-mobile/gpslocation.h3
-rw-r--r--qt-mobile/qml/main.qml2
-rw-r--r--qt-mobile/qmlmanager.cpp4
4 files changed, 22 insertions, 14 deletions
diff --git a/qt-mobile/gpslocation.cpp b/qt-mobile/gpslocation.cpp
index d1c5c4588..eb0f15292 100644
--- a/qt-mobile/gpslocation.cpp
+++ b/qt-mobile/gpslocation.cpp
@@ -1,23 +1,19 @@
#include "qt-mobile/gpslocation.h"
#include "qt-mobile/qmlmanager.h"
+#include "pref.h"
+#include "dive.h"
+#include <time.h>
#include <QDebug>
-
+#include <QVariant>
GpsLocation::GpsLocation(QObject *parent)
{
+ QSettings *geoSettings = new QSettings();
gpsSource = QGeoPositionInfoSource::createDefaultSource(parent);
if (gpsSource != 0) {
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()));
- lastPos = gpsSource->lastKnownPosition();
- gpsSource->startUpdates();
- QGeoCoordinate lastCoord = lastPos.coordinate();
- if (lastCoord.isValid()) {
- status(msg + lastCoord.toString());
- } else {
- status(msg + "invalid last position");
- }
} else {
status("don't have GPS source");
}
@@ -25,9 +21,11 @@ GpsLocation::GpsLocation(QObject *parent)
void GpsLocation::serviceEnable(bool toggle)
{
- if (!gpsSource)
+ if (!gpsSource) {
+ if (toggle)
+ status("Can't start location service, no location source available");
return;
-
+ }
if (toggle) {
gpsSource->startUpdates();
status("Starting Subsurface GPS service");
@@ -41,6 +39,13 @@ void GpsLocation::newPosition(QGeoPositionInfo pos)
{
QString msg("received new position %1");
status(qPrintable(msg.arg(pos.coordinate().toString())));
+ geoSettings.beginGroup("locations");
+ int nr = geoSettings.value("count", 0).toInt();
+ geoSettings.setValue("count", nr + 1);
+ geoSettings.setValue(QString("gpsFix%1_time").arg(nr), pos.timestamp().toTime_t());
+ geoSettings.setValue(QString("gpsFix%1_lat").arg(nr), rint(pos.coordinate().latitude() * 1000000));
+ geoSettings.setValue(QString("gpsFix%1_lon").arg(nr), rint(pos.coordinate().longitude() * 1000000));
+ geoSettings.sync();
}
void GpsLocation::updateTimeout()
diff --git a/qt-mobile/gpslocation.h b/qt-mobile/gpslocation.h
index b140f705e..f4a2fc737 100644
--- a/qt-mobile/gpslocation.h
+++ b/qt-mobile/gpslocation.h
@@ -1,10 +1,12 @@
#ifndef GPSLOCATION_H
#define GPSLOCATION_H
+#include "units.h"
#include <QObject>
#include <QGeoCoordinate>
#include <QGeoPositionInfoSource>
#include <QGeoPositionInfo>
+#include <QSettings>
class GpsLocation : QObject
{
@@ -16,6 +18,7 @@ private:
QGeoPositionInfo lastPos;
QGeoPositionInfoSource *gpsSource;
void status(QString msg);
+ QSettings geoSettings;
signals:
diff --git a/qt-mobile/qml/main.qml b/qt-mobile/qml/main.qml
index 2a4b8f432..bbb0806da 100644
--- a/qt-mobile/qml/main.qml
+++ b/qt-mobile/qml/main.qml
@@ -74,7 +74,7 @@ ApplicationWindow {
checkable: true
checked: manager.locationServiceEnabled
onToggled: {
- manager.setLocationServiceEnabled(checked);
+ manager.locationServiceEnabled = checked;
}
}
diff --git a/qt-mobile/qmlmanager.cpp b/qt-mobile/qmlmanager.cpp
index 1f2dd4c98..ad8f1e259 100644
--- a/qt-mobile/qmlmanager.cpp
+++ b/qt-mobile/qmlmanager.cpp
@@ -15,11 +15,11 @@ void qmlUiShowMessage(const char *errorString)
qDebug() << "couldn't set property messageText to" << errorString;
}
-QMLManager::QMLManager()
+QMLManager::QMLManager() :
+ m_locationServiceEnabled(false)
{
// create location manager service
locationProvider = new GpsLocation(this);
- setLocationServiceEnabled(false);
// Initialize cloud credentials.
setCloudUserName(prefs.cloud_storage_email);