dom/system/qt/QTMLocationProvider.cpp

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

michael@0 1 /* -*- Mode: c++; c-basic-offset: 4; tab-width: 20; indent-tabs-mode: nil; -*-
michael@0 2 * This Source Code Form is subject to the terms of the Mozilla Public
michael@0 3 * License, v. 2.0. If a copy of the MPL was not distributed with this
michael@0 4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
michael@0 5
michael@0 6 #include "QTMLocationProvider.h"
michael@0 7 #include "nsGeoPosition.h"
michael@0 8
michael@0 9 using namespace mozilla;
michael@0 10
michael@0 11 NS_IMPL_ISUPPORTS(QTMLocationProvider, nsIGeolocationProvider)
michael@0 12
michael@0 13 QTMLocationProvider::QTMLocationProvider()
michael@0 14 {
michael@0 15 if (QMetaType::type("QGeoPositionInfo") == QMetaType::UnknownType) {
michael@0 16 qRegisterMetaType<QGeoPositionInfo>("QGeoPositionInfo");
michael@0 17 }
michael@0 18 mLocation = QGeoPositionInfoSource::createDefaultSource(this);
michael@0 19 if (mLocation)
michael@0 20 connect(mLocation, SIGNAL(positionUpdated(QGeoPositionInfo)), this, SLOT(positionUpdated(QGeoPositionInfo)));
michael@0 21 }
michael@0 22
michael@0 23 QTMLocationProvider::~QTMLocationProvider()
michael@0 24 {
michael@0 25 delete mLocation;
michael@0 26 }
michael@0 27
michael@0 28 void
michael@0 29 QTMLocationProvider::positionUpdated(const QGeoPositionInfo &geoPosition)
michael@0 30 {
michael@0 31 if (!geoPosition.isValid()) {
michael@0 32 NS_WARNING("Invalida geoposition received");
michael@0 33 return;
michael@0 34 }
michael@0 35
michael@0 36 QGeoCoordinate coord = geoPosition.coordinate();
michael@0 37 double latitude = coord.latitude();
michael@0 38 double longitude = coord.longitude();
michael@0 39 double altitude = coord.altitude();
michael@0 40 double accuracy = geoPosition.attribute(QGeoPositionInfo::HorizontalAccuracy);
michael@0 41 double altitudeAccuracy = geoPosition.attribute(QGeoPositionInfo::VerticalAccuracy);
michael@0 42 double heading = geoPosition.attribute(QGeoPositionInfo::Direction);
michael@0 43
michael@0 44 bool providesSpeed = geoPosition.hasAttribute(QGeoPositionInfo::GroundSpeed);
michael@0 45 double speed = geoPosition.attribute(QGeoPositionInfo::GroundSpeed);
michael@0 46
michael@0 47 nsRefPtr<nsGeoPosition> p =
michael@0 48 new nsGeoPosition(latitude, longitude,
michael@0 49 altitude, accuracy,
michael@0 50 altitudeAccuracy, heading,
michael@0 51 speed, geoPosition.timestamp().toTime_t());
michael@0 52 if (mCallback) {
michael@0 53 mCallback->Update(p);
michael@0 54 }
michael@0 55 }
michael@0 56
michael@0 57 NS_IMETHODIMP
michael@0 58 QTMLocationProvider::Startup()
michael@0 59 {
michael@0 60 if (!mLocation)
michael@0 61 return NS_ERROR_NOT_IMPLEMENTED;
michael@0 62
michael@0 63 // Not all versions of qt5positioning set default prefered method
michael@0 64 // thus this workaround initializing QGeoPositionSource explicitly
michael@0 65 SetHighAccuracy(false);
michael@0 66 mLocation->startUpdates();
michael@0 67
michael@0 68 return NS_OK;
michael@0 69 }
michael@0 70
michael@0 71 NS_IMETHODIMP
michael@0 72 QTMLocationProvider::Watch(nsIGeolocationUpdate* aCallback)
michael@0 73 {
michael@0 74 mCallback = aCallback;
michael@0 75
michael@0 76 return NS_OK;
michael@0 77 }
michael@0 78
michael@0 79 NS_IMETHODIMP
michael@0 80 QTMLocationProvider::Shutdown()
michael@0 81 {
michael@0 82 if (!mLocation)
michael@0 83 return NS_ERROR_NOT_IMPLEMENTED;
michael@0 84
michael@0 85 mLocation->stopUpdates();
michael@0 86 mCallback = nullptr;
michael@0 87
michael@0 88 return NS_OK;
michael@0 89 }
michael@0 90
michael@0 91 NS_IMETHODIMP
michael@0 92 QTMLocationProvider::SetHighAccuracy(bool aHigh)
michael@0 93 {
michael@0 94 if (!mLocation)
michael@0 95 return NS_ERROR_NOT_IMPLEMENTED;
michael@0 96
michael@0 97 mLocation->setPreferredPositioningMethods(aHigh ?
michael@0 98 QGeoPositionInfoSource::SatellitePositioningMethods :
michael@0 99 QGeoPositionInfoSource::AllPositioningMethods);
michael@0 100 return NS_OK;
michael@0 101 }

mercurial