Added GPSPosition class.
authorJussi Laitinen <jupe@l3l7588.ixonos.local>
Thu, 6 May 2010 13:00:49 +0000 (16:00 +0300)
committerJussi Laitinen <jupe@l3l7588.ixonos.local>
Thu, 6 May 2010 13:00:49 +0000 (16:00 +0300)
src/gps/README.txt [deleted file]
src/gps/gpsposition.cpp [new file with mode: 0644]
src/gps/gpsposition.h [new file with mode: 0644]
src/map/mapengine.cpp
src/map/mapengine.h
src/src.pro

diff --git a/src/gps/README.txt b/src/gps/README.txt
deleted file mode 100644 (file)
index e69de29..0000000
diff --git a/src/gps/gpsposition.cpp b/src/gps/gpsposition.cpp
new file mode 100644 (file)
index 0000000..510e42a
--- /dev/null
@@ -0,0 +1,67 @@
+/*
+   Situare - A location system for Facebook
+   Copyright (C) 2010  Ixonos Plc. Authors:
+
+       Jussi Laitinen - jussi.laitinen@ixonos.com
+
+   Situare is free software; you can redistribute it and/or
+   modify it under the terms of the GNU General Public License
+   version 2 as published by the Free Software Foundation.
+
+   Situare is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
+
+   You should have received a copy of the GNU General Public License
+   along with Situare; if not, write to the Free Software
+   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301,
+   USA.
+*/
+
+#include <QGeoPositionInfoSource>
+#include <QDebug>
+
+#include "gpsposition.h"
+
+GPSPosition::GPSPosition(QObject *parent)
+    : QObject(parent)
+{
+    m_gpsSource = QGeoPositionInfoSource::createDefaultSource(this);
+
+    if (m_gpsSource)
+        m_gpsSource->setUpdateInterval(10000);
+
+    connect(m_gpsSource, SIGNAL(positionUpdated(QGeoPositionInfo)),
+            this, SLOT(positionUpdated(QGeoPositionInfo)));
+}
+
+GPSPosition::~GPSPosition()
+{
+    stop();
+}
+
+void GPSPosition::start()
+{
+    if (m_gpsSource)
+        m_gpsSource->startUpdates();
+}
+
+void GPSPosition::stop()
+{
+    if (m_gpsSource)
+        m_gpsSource->stopUpdates();
+}
+
+void GPSPosition::requestUpdate()
+{
+
+}
+
+void GPSPosition::positionUpdated(QGeoPositionInfo positionInfo)
+{
+    qDebug() << positionInfo;
+
+    emit position(QPointF(positionInfo.coordinate().longitude(),
+                          positionInfo.coordinate().latitude()));
+}
diff --git a/src/gps/gpsposition.h b/src/gps/gpsposition.h
new file mode 100644 (file)
index 0000000..da1ba59
--- /dev/null
@@ -0,0 +1,53 @@
+/*
+   Situare - A location system for Facebook
+   Copyright (C) 2010  Ixonos Plc. Authors:
+
+       Jussi Laitinen - jussi.laitinen@ixonos.com
+
+   Situare is free software; you can redistribute it and/or
+   modify it under the terms of the GNU General Public License
+   version 2 as published by the Free Software Foundation.
+
+   Situare is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
+
+   You should have received a copy of the GNU General Public License
+   along with Situare; if not, write to the Free Software
+   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301,
+   USA.
+*/
+
+#ifndef GPSPOSITION_H
+#define GPSPOSITION_H
+
+#include <QGeoPositionInfoSource>
+#include <QPointF>
+
+// Use the QtMobility namespace
+QTM_USE_NAMESPACE
+
+class GPSPosition : public QObject
+{
+    Q_OBJECT
+
+public:
+    GPSPosition(QObject *parent = 0);
+    ~GPSPosition();
+
+    void start();
+    void stop();
+
+private slots:
+    void requestUpdate();
+    void positionUpdated(QGeoPositionInfo positionInfo);
+
+signals:
+    void position(QPointF latLonCoordinate);
+
+private:
+    QGeoPositionInfoSource *m_gpsSource;
+};
+
+#endif // GPSPOSITION_H
index b109797..5671a11 100644 (file)
@@ -34,6 +34,8 @@
 #include "mapengine.h"
 #include "maptile.h"
 
+#include "gps/gpsposition.h"
+
 MapEngine::MapEngine(QObject *parent)
     : QObject(parent)
     , m_centerTile(QPoint(UNDEFINED, UNDEFINED))
@@ -57,6 +59,11 @@ MapEngine::MapEngine(QObject *parent)
     connect(m_mapZoomPanel, SIGNAL(zoomOutPressed()), this, SLOT(zoomOut()));
 
    m_ownLocation = new OwnLocationItem(QPointF());
+
+   //GPS
+    m_gps = new GPSPosition(this);
+    m_gps->start();
+    connect(m_gps, SIGNAL(position(QPointF)), this, SLOT(positionReceived(QPointF)));
 }
 
 MapEngine::~MapEngine()
@@ -414,3 +421,10 @@ void MapEngine::cleanOldFriendData(const QList<User *> &friendsList)
         friendGone = true;
     }
 }
+
+void MapEngine::positionReceived(QPointF position)
+{
+    qDebug() << __PRETTY_FUNCTION__;
+
+    setViewLocation(position);
+}
index 60814d0..6c8a9d2 100644 (file)
@@ -36,6 +36,8 @@
 #include "friendlocationitem.h"
 #include "user/user.h"
 
+class GPSPosition;
+
 /**
 * @brief Map engine
 *
@@ -257,6 +259,8 @@ private slots:
     */
     void zoomOut();
 
+    void positionReceived(QPointF position);
+
 /*******************************************************************************
  * SIGNALS
  ******************************************************************************/
@@ -299,6 +303,8 @@ private:
     bool m_zoomedIn; ///< Flag for checking if zoomed in when zoom is finished
     int m_zoomLevel; ///< Current zoom level
     QList<FriendLocationItem *> m_friendItems; ///< List of friendLocationItems
+
+    GPSPosition *m_gps;
 };
 
 #endif // MAPENGINE_H
index 21d8e09..ed0af64 100644 (file)
@@ -36,7 +36,8 @@ SOURCES += main.cpp \
     ui/situareuser.cpp \
     engine/engine.cpp \
     ui/settingsdialog.cpp \
-    map/maptilerequest.cpp
+    map/maptilerequest.cpp \
+    gps/gpsposition.cpp
 HEADERS += ui/mainwindow.h \
     ui/mapviewscreen.h \
     ui/listviewscreen.h \
@@ -69,9 +70,12 @@ HEADERS += ui/mainwindow.h \
     ui/situareuser.h \
     engine/engine.h \
     ui/settingsdialog.h \
-    map/maptilerequest.h
+    map/maptilerequest.h \
+    gps/gpsposition.h
 QT += network \
     webkit
+CONFIG += mobility
+MOBILITY = location
 #DEFINES += QT_NO_DEBUG_OUTPUT
 !maemo5 { 
     message(QJson built in)