Bug 679236 Add Maemo6 geolocation provider (Qt Mobility based). r=dougt
authorOleg Romashin <romaxa@gmail.com>
Mon, 15 Aug 2011 20:25:43 -0400
changeset 76802 690b443ea6891026d87aff42f4e71539033cfb6a
parent 76801 a67e4bd575b4dd74f1956567595cd32ca6b1e76d
child 76803 58b7de3f9b79b713d74504e922c4bae8511cc34c
push id78
push userclegnitto@mozilla.com
push dateFri, 16 Dec 2011 17:32:24 +0000
treeherdermozilla-release@79d24e644fdd [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersdougt
bugs679236
milestone9.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 679236 Add Maemo6 geolocation provider (Qt Mobility based). r=dougt
configure.in
dom/src/geolocation/Makefile.in
dom/src/geolocation/nsGeolocation.cpp
dom/system/unix/Makefile.in
dom/system/unix/QTMLocationProvider.cpp
dom/system/unix/QTMLocationProvider.h
mobile/installer/debian/fennec.aegis.in
--- a/configure.in
+++ b/configure.in
@@ -5141,30 +5141,31 @@ incorrect])
                       MOZ_ENABLE_QTNETWORK=)
 
     if test "$MOZ_ENABLE_QTNETWORK"; then
       MOZ_ENABLE_QTNETWORK=1
       AC_DEFINE(MOZ_ENABLE_QTNETWORK)
     fi
 
     MOZ_ENABLE_QTMOBILITY=
-    PKG_CHECK_MODULES(_QTMOBILITY, QtSensors QtFeedback,
+    PKG_CHECK_MODULES(_QTMOBILITY, QtSensors QtFeedback QtLocation,
                       MOZ_ENABLE_QTMOBILITY=1,
                       MOZ_ENABLE_QTMOBILITY=)
     if test "$MOZ_ENABLE_QTMOBILITY"; then
        MOZ_ENABLE_QTMOBILITY=1
        MOZ_QT_CFLAGS="$MOZ_QT_CFLAGS $_QTMOBILITY_CFLAGS"
        MOZ_QT_LIBS="$MOZ_QT_LIBS $_QTMOBILITY_LIBS"
     else
-       AC_CHECK_LIB(QtSensors QtFeedback, main, [
+       AC_CHECK_LIB(QtSensors QtFeedback QtLocation, main, [
           MOZ_ENABLE_QTMOBILITY=1
           MOZ_QT_CFLAGS="$MOZ_QT_CFLAGS -I/usr/include/qt4/QtMobility"
           MOZ_QT_CFLAGS="$MOZ_QT_CFLAGS -I/usr/include/qt4/QtSensors"
           MOZ_QT_CFLAGS="$MOZ_QT_CFLAGS -I/usr/include/qt4/QtFeedback"
-          MOZ_QT_LIBS="$MOZ_QT_LIBS -lQtSensors -lQtFeedback"
+          MOZ_QT_CFLAGS="$MOZ_QT_CFLAGS -I/usr/include/qt4/QtLocation"
+          MOZ_QT_LIBS="$MOZ_QT_LIBS -lQtSensors -lQtFeedback -lQtLocation"
        ])
     fi
     if test "$MOZ_ENABLE_QTMOBILITY"; then
        AC_DEFINE(MOZ_ENABLE_QTMOBILITY)
     fi
 fi
 
 AC_SUBST(GTK_CONFIG)
--- a/dom/src/geolocation/Makefile.in
+++ b/dom/src/geolocation/Makefile.in
@@ -63,16 +63,21 @@ LOCAL_INCLUDES = \
 
 EXPORTS        = nsGeoPosition.h
 
 ifdef MOZ_MAEMO_LIBLOCATION
 LOCAL_INCLUDES  += $(MOZ_PLATFORM_MAEMO_CFLAGS) \
                    -I$(topsrcdir)/dom/system/unix \
                    $(NULL)
 endif
+ifdef MOZ_ENABLE_QTMOBILITY
+LOCAL_INCLUDES  += $(MOZ_QT_CFLAGS) \
+                   -I$(topsrcdir)/dom/system/unix \
+                   $(NULL)
+endif
 
 ifeq ($(MOZ_WIDGET_TOOLKIT),android)
 LOCAL_INCLUDES  += -I$(topsrcdir)/dom/system/android \
                    $(NULL)
 endif
 
 EXPORTS         += nsGeoPositionIPCSerialiser.h
 
--- a/dom/src/geolocation/nsGeolocation.cpp
+++ b/dom/src/geolocation/nsGeolocation.cpp
@@ -75,16 +75,20 @@
 #include "mozilla/Preferences.h"
 
 #include <math.h>
 
 #ifdef MOZ_MAEMO_LIBLOCATION
 #include "MaemoLocationProvider.h"
 #endif
 
+#ifdef MOZ_ENABLE_QTMOBILITY
+#include "QTMLocationProvider.h"
+#endif
+
 #ifdef ANDROID
 #include "AndroidLocationProvider.h"
 #endif
 
 #include "nsIDOMDocument.h"
 #include "nsIDocument.h"
 
 // Some limit to the number of get or watch geolocation requests
@@ -573,16 +577,22 @@ nsresult nsGeolocationService::Init()
   // we should move these providers outside of this file! dft
 
 #ifdef MOZ_MAEMO_LIBLOCATION
   provider = new MaemoLocationProvider();
   if (provider)
     mProviders.AppendObject(provider);
 #endif
 
+#ifdef MOZ_ENABLE_QTMOBILITY
+  provider = new QTMLocationProvider();
+  if (provider)
+    mProviders.AppendObject(provider);
+#endif
+
 #ifdef ANDROID
   provider = new AndroidLocationProvider();
   if (provider)
     mProviders.AppendObject(provider);
 #endif
   return NS_OK;
 }
 
--- a/dom/system/unix/Makefile.in
+++ b/dom/system/unix/Makefile.in
@@ -45,16 +45,18 @@ MODULE      = dom
 LIBRARY_NAME    = domsystemunix_s
 
 # we don't want the shared lib, but we want to force the creation of a static lib.
 LIBXUL_LIBRARY   = 1
 FORCE_STATIC_LIB = 1
 EXPORT_LIBRARY = 1
 
 include $(topsrcdir)/config/config.mk
+include $(topsrcdir)/ipc/chromium/chromium-config.mk
+
 
 CPPSRCS     = \
         nsDeviceMotionSystem.cpp \
         $(NULL)
 
 ifdef MOZ_MAEMO_LIBLOCATION
         CPPSRCS         += MaemoLocationProvider.cpp
         LOCAL_INCLUDES  += $(MOZ_PLATFORM_MAEMO_CFLAGS) \
@@ -62,14 +64,19 @@ ifdef MOZ_MAEMO_LIBLOCATION
                            $(NULL)
 endif
 
 ifdef MOZ_PLATFORM_MAEMO
 CPPSRCS += nsHapticFeedback.cpp
 LOCAL_INCLUDES  += $(MOZ_DBUS_CFLAGS) \
                    $(NULL)
 ifdef MOZ_ENABLE_QTMOBILITY
+MOCSRCS         += moc_QTMLocationProvider.cpp
+CPPSRCS         += $(MOCSRCS) \
+                   QTMLocationProvider.cpp \
+                   $(NULL)
 LOCAL_INCLUDES  += $(MOZ_QT_CFLAGS) \
+                   -I$(topsrcdir)/dom/src/geolocation \
                    $(NULL)
 endif
 endif
 
 include $(topsrcdir)/config/rules.mk
new file mode 100644
--- /dev/null
+++ b/dom/system/unix/QTMLocationProvider.cpp
@@ -0,0 +1,118 @@
+/* -*- Mode: c++; c-basic-offset: 4; tab-width: 20; indent-tabs-mode: nil; -*-
+ * ***** BEGIN LICENSE BLOCK *****
+ * Version: MPL 1.1/GPL 2.0/LGPL 2.1
+ *
+ * The contents of this file are subject to the Mozilla Public License Version
+ * 1.1 (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ * http://www.mozilla.org/MPL/
+ *
+ * Software distributed under the License is distributed on an "AS IS" basis,
+ * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
+ * for the specific language governing rights and limitations under the
+ * License.
+ *
+ * The Original Code is Mozilla Qt code.
+ *
+ * The Initial Developer of the Original Code is Mozilla Foundation.
+ * Portions created by the Initial Developer are Copyright (C) 2011
+ * the Initial Developer. All Rights Reserved.
+ *
+ * Contributor(s):
+ *   Oleg Romashin <romaxa@gmail.com>
+ *
+ * Alternatively, the contents of this file may be used under the terms of
+ * either the GNU General Public License Version 2 or later (the "GPL"), or
+ * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
+ * in which case the provisions of the GPL or the LGPL are applicable instead
+ * of those above. If you wish to allow use of your version of this file only
+ * under the terms of either the GPL or the LGPL, and not to allow others to
+ * use your version of this file under the terms of the MPL, indicate your
+ * decision by deleting the provisions above and replace them with the notice
+ * and other provisions required by the GPL or the LGPL. If you do not delete
+ * the provisions above, a recipient may use your version of this file under
+ * the terms of any one of the MPL, the GPL or the LGPL.
+ *
+ * ***** END LICENSE BLOCK ***** */
+
+#include "QTMLocationProvider.h"
+#include "nsGeoPosition.h"
+#include <QFeedbackEffect>
+using namespace QtMobility;
+
+using namespace mozilla;
+
+NS_IMPL_ISUPPORTS1(QTMLocationProvider, nsIGeolocationProvider)
+
+QTMLocationProvider::QTMLocationProvider()
+{
+    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);
+
+    nsRefPtr<nsGeoPosition> p =
+        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;
+
+    mLocation->startUpdates();
+
+    return NS_OK;
+}
+
+NS_IMETHODIMP
+QTMLocationProvider::Watch(nsIGeolocationUpdate* aCallback)
+{
+    mCallback = aCallback;
+
+    return NS_OK;
+}
+
+NS_IMETHODIMP
+QTMLocationProvider::Shutdown()
+{
+    if (!mLocation)
+        return NS_ERROR_NOT_IMPLEMENTED;
+
+    mLocation->stopUpdates();
+    mCallback = nsnull;
+
+    return NS_OK;
+}
+
new file mode 100644
--- /dev/null
+++ b/dom/system/unix/QTMLocationProvider.h
@@ -0,0 +1,69 @@
+/* ***** BEGIN LICENSE BLOCK *****
+ * Version: MPL 1.1/GPL 2.0/LGPL 2.1
+ *
+ * The contents of this file are subject to the Mozilla Public License Version
+ * 1.1 (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ * http://www.mozilla.org/MPL/
+ *
+ * Software distributed under the License is distributed on an "AS IS" basis,
+ * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
+ * for the specific language governing rights and limitations under the
+ * License.
+ *
+ * The Original Code is Mozilla Qt code.
+ *
+ * The Initial Developer of the Original Code is Mozilla Foundation.
+ * Portions created by the Initial Developer are Copyright (C) 2011
+ * the Initial Developer. All Rights Reserved.
+ *
+ * Contributor(s):
+ *   Oleg Romashin <romaxa@gmail.com>
+ *
+ * Alternatively, the contents of this file may be used under the terms of
+ * either the GNU General Public License Version 2 or later (the "GPL"), or
+ * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
+ * in which case the provisions of the GPL or the LGPL are applicable instead
+ * of those above. If you wish to allow use of your version of this file only
+ * under the terms of either the GPL or the LGPL, and not to allow others to
+ * use your version of this file under the terms of the MPL, indicate your
+ * decision by deleting the provisions above and replace them with the notice
+ * and other provisions required by the GPL or the LGPL. If you do not delete
+ * the provisions above, a recipient may use your version of this file under
+ * the terms of any one of the MPL, the GPL or the LGPL.
+ *
+ * ***** END LICENSE BLOCK ***** */
+
+#ifndef QTMLocationProvider_h
+#define QTMLocationProvider_h
+
+#include <QGeoPositionInfoSource>
+#include "nsGeolocation.h"
+#include "nsIGeolocationProvider.h"
+#include "nsCOMPtr.h"
+
+using namespace QtMobility;
+
+class QTMLocationProvider : public QObject,
+                            public nsIGeolocationProvider
+{
+    Q_OBJECT
+
+public:
+    NS_DECL_ISUPPORTS
+    NS_DECL_NSIGEOLOCATIONPROVIDER
+
+    QTMLocationProvider();
+
+public Q_SLOTS:
+    // QGeoPositionInfoSource
+    void positionUpdated(const QGeoPositionInfo&);
+
+private:
+    ~QTMLocationProvider();
+
+    QtMobility::QGeoPositionInfoSource* mLocation;
+    nsCOMPtr<nsIGeolocationUpdate> mCallback;
+};
+
+#endif /* QTMLocationProvider_h */
--- a/mobile/installer/debian/fennec.aegis.in
+++ b/mobile/installer/debian/fennec.aegis.in
@@ -1,7 +1,10 @@
 <aegis>
   <request>
     <credential name="TrackerReadAccess" />
     <credential name="TrackerWriteAccess" />
+    <credential name="Location" />
+    <for path="@installdir@/@MOZ_APP_NAME@" />
+    <for path="@installdir@/plugin-container" />
   </request>
 </aegis>