2011-08-16 00:25:43 +00:00
|
|
|
/* -*- Mode: c++; c-basic-offset: 4; tab-width: 20; indent-tabs-mode: nil; -*-
|
2012-05-21 11:12:37 +00:00
|
|
|
* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
2011-08-16 00:25:43 +00:00
|
|
|
|
|
|
|
#include "QTMLocationProvider.h"
|
|
|
|
#include "nsGeoPosition.h"
|
2011-08-23 16:45:10 +00:00
|
|
|
|
2011-08-16 00:25:43 +00:00
|
|
|
using namespace mozilla;
|
|
|
|
|
2014-04-27 07:06:00 +00:00
|
|
|
NS_IMPL_ISUPPORTS(QTMLocationProvider, nsIGeolocationProvider)
|
2011-08-16 00:25:43 +00:00
|
|
|
|
|
|
|
QTMLocationProvider::QTMLocationProvider()
|
|
|
|
{
|
2014-02-21 02:09:02 +00:00
|
|
|
if (QMetaType::type("QGeoPositionInfo") == QMetaType::UnknownType) {
|
|
|
|
qRegisterMetaType<QGeoPositionInfo>("QGeoPositionInfo");
|
|
|
|
}
|
2011-08-16 00:25:43 +00:00
|
|
|
mLocation = QGeoPositionInfoSource::createDefaultSource(this);
|
|
|
|
if (mLocation)
|
|
|
|
connect(mLocation, SIGNAL(positionUpdated(QGeoPositionInfo)), this, SLOT(positionUpdated(QGeoPositionInfo)));
|
|
|
|
}
|
|
|
|
|
|
|
|
QTMLocationProvider::~QTMLocationProvider()
|
|
|
|
{
|
|
|
|
delete mLocation;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
QTMLocationProvider::positionUpdated(const QGeoPositionInfo &geoPosition)
|
|
|
|
{
|
|
|
|
if (!geoPosition.isValid()) {
|
|
|
|
NS_WARNING("Invalida geoposition received");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
QGeoCoordinate coord = geoPosition.coordinate();
|
|
|
|
double latitude = coord.latitude();
|
|
|
|
double longitude = coord.longitude();
|
|
|
|
double altitude = coord.altitude();
|
|
|
|
double accuracy = geoPosition.attribute(QGeoPositionInfo::HorizontalAccuracy);
|
|
|
|
double altitudeAccuracy = geoPosition.attribute(QGeoPositionInfo::VerticalAccuracy);
|
|
|
|
double heading = geoPosition.attribute(QGeoPositionInfo::Direction);
|
|
|
|
|
|
|
|
bool providesSpeed = geoPosition.hasAttribute(QGeoPositionInfo::GroundSpeed);
|
|
|
|
double speed = geoPosition.attribute(QGeoPositionInfo::GroundSpeed);
|
|
|
|
|
2015-10-18 05:24:48 +00:00
|
|
|
RefPtr<nsGeoPosition> p =
|
2011-08-16 00:25:43 +00:00
|
|
|
new nsGeoPosition(latitude, longitude,
|
|
|
|
altitude, accuracy,
|
|
|
|
altitudeAccuracy, heading,
|
|
|
|
speed, geoPosition.timestamp().toTime_t());
|
|
|
|
if (mCallback) {
|
|
|
|
mCallback->Update(p);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
QTMLocationProvider::Startup()
|
|
|
|
{
|
|
|
|
if (!mLocation)
|
|
|
|
return NS_ERROR_NOT_IMPLEMENTED;
|
|
|
|
|
2014-02-21 02:09:02 +00:00
|
|
|
// Not all versions of qt5positioning set default prefered method
|
|
|
|
// thus this workaround initializing QGeoPositionSource explicitly
|
|
|
|
SetHighAccuracy(false);
|
2011-08-16 00:25:43 +00:00
|
|
|
mLocation->startUpdates();
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2013-06-13 02:20:07 +00:00
|
|
|
QTMLocationProvider::Watch(nsIGeolocationUpdate* aCallback)
|
2011-08-16 00:25:43 +00:00
|
|
|
{
|
|
|
|
mCallback = aCallback;
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
QTMLocationProvider::Shutdown()
|
|
|
|
{
|
|
|
|
if (!mLocation)
|
|
|
|
return NS_ERROR_NOT_IMPLEMENTED;
|
|
|
|
|
|
|
|
mLocation->stopUpdates();
|
2012-07-30 14:20:58 +00:00
|
|
|
mCallback = nullptr;
|
2011-08-16 00:25:43 +00:00
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2012-03-22 20:24:51 +00:00
|
|
|
NS_IMETHODIMP
|
2014-02-21 02:09:02 +00:00
|
|
|
QTMLocationProvider::SetHighAccuracy(bool aHigh)
|
2012-03-22 20:24:51 +00:00
|
|
|
{
|
2014-02-21 02:09:02 +00:00
|
|
|
if (!mLocation)
|
|
|
|
return NS_ERROR_NOT_IMPLEMENTED;
|
|
|
|
|
|
|
|
mLocation->setPreferredPositioningMethods(aHigh ?
|
|
|
|
QGeoPositionInfoSource::SatellitePositioningMethods :
|
|
|
|
QGeoPositionInfoSource::AllPositioningMethods);
|
|
|
|
return NS_OK;
|
2012-03-22 20:24:51 +00:00
|
|
|
}
|