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>
This commit is contained in:
Dirk Hohndel 2015-11-11 15:19:09 -08:00
parent cd7d6ae6e5
commit 62f7ec11d7
4 changed files with 22 additions and 14 deletions

View file

@ -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()