mirror of
https://github.com/subsurface/subsurface.git
synced 2024-11-28 13:10:19 +00:00
cd7d6ae6e5
That way we don't track the user's location until explicitly asked to do so. Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
55 lines
1.4 KiB
C++
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));
|
|
}
|