subsurface/qt-mobile/gpslocation.cpp
Dirk Hohndel cd7d6ae6e5 Location service: toggle the service from the main menu
That way we don't track the user's location until explicitly asked to do
so.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2015-11-11 15:28:10 -08:00

55 lines
1.4 KiB
C++

#include "qt-mobile/gpslocation.h"
#include "qt-mobile/qmlmanager.h"
#include <QDebug>
GpsLocation::GpsLocation(QObject *parent)
{
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");
}
}
void GpsLocation::serviceEnable(bool toggle)
{
if (!gpsSource)
return;
if (toggle) {
gpsSource->startUpdates();
status("Starting Subsurface GPS service");
} else {
gpsSource->stopUpdates();
status("Stopping Subsurface GPS service");
}
}
void GpsLocation::newPosition(QGeoPositionInfo pos)
{
QString msg("received new position %1");
status(qPrintable(msg.arg(pos.coordinate().toString())));
}
void GpsLocation::updateTimeout()
{
status("request to get new position timed out");
}
void GpsLocation::status(QString msg)
{
qDebug() << msg;
qmlUiShowMessage(qPrintable(msg));
}