Added GeoCoordinate, GeoPositionInfo, GpsPositionPrivate (liblocation)
authorJussi Laitinen <jupe@l3l7588.ixonos.local>
Fri, 4 Jun 2010 10:57:33 +0000 (13:57 +0300)
committerJussi Laitinen <jupe@l3l7588.ixonos.local>
Fri, 4 Jun 2010 10:57:33 +0000 (13:57 +0300)
and LiblocationWrapper classes.

13 files changed:
src/gps/geocoordinate.cpp [new file with mode: 0644]
src/gps/geocoordinate.h [new file with mode: 0644]
src/gps/geopositioninfo.cpp
src/gps/geopositioninfo.h
src/gps/gpscommon.h
src/gps/gpsposition.cpp
src/gps/gpspositionprivate.cpp
src/gps/gpspositionprivate.h
src/gps/gpspositionprivateliblocation.cpp [new file with mode: 0644]
src/gps/gpspositionprivateliblocation.h [new file with mode: 0644]
src/gps/liblocationwrapper.cpp
src/gps/liblocationwrapper.h
src/src.pro

diff --git a/src/gps/geocoordinate.cpp b/src/gps/geocoordinate.cpp
new file mode 100644 (file)
index 0000000..f0065c4
--- /dev/null
@@ -0,0 +1,62 @@
+/*
+   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 "geocoordinate.h"
+#include "gpscommon.h"
+
+GeoCoordinate::GeoCoordinate()
+{
+}
+
+GeoCoordinate::GeoCoordinate(double latitude, double longitude)
+{
+    m_latitude = latitude;
+    m_longitude = longitude;
+}
+
+void GeoCoordinate::setLatitude(double latitude)
+{
+    m_latitude = latitude;
+}
+
+double GeoCoordinate::latitude() const
+{
+    return m_latitude;
+}
+void GeoCoordinate::setLongitude(double longitude)
+{
+    m_longitude = longitude;
+}
+
+double GeoCoordinate::longitude() const
+{
+    return m_longitude;
+}
+
+bool GeoCoordinate::isValid()
+{
+    if ((m_latitude >= GPS_MIN_LATITUDE) && (m_latitude < GPS_MAX_LATITUDE) &&
+        (m_longitude >= GPS_MIN_LONGITUDE) && (m_longitude < GPS_MAX_LONGITUDE))
+
+        return true;
+    else
+        return false;
+}
diff --git a/src/gps/geocoordinate.h b/src/gps/geocoordinate.h
new file mode 100644 (file)
index 0000000..72b650a
--- /dev/null
@@ -0,0 +1,90 @@
+/*
+   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 GEOCOORDINATE_H
+#define GEOCOORDINATE_H
+
+/**
+* @brief GeoCoordinate class stores latitude and longitude.
+*/
+class GeoCoordinate
+{
+public:
+    /**
+    * @brief Constructor.
+    */
+    GeoCoordinate();
+
+    /**
+    * @brief Constructor.
+    *
+    * @param latitude latitude value
+    * @param longitude longitude value
+    */
+    GeoCoordinate(double latitude, double longitude);
+
+/******************************************************************************
+* MEMBER FUNCTIONS AND SLOTS
+******************************************************************************/
+    /**
+    * @brief Returns is coordinate valid.
+    *
+    * @return true if coordinate is valid, false otherwise
+    */
+    bool isValid();
+
+    /**
+    * @brief Returns latitude.
+    *
+    * @return latitude value
+    */
+    double latitude() const;
+
+    /**
+    * @brief Returns longitude.
+    *
+    * @return longitude value
+    */
+    double longitude() const;
+
+    /**
+    * @brief Sets latitude.
+    *
+    * @param latitude value
+    */
+    void setLatitude(double latitude);
+
+    /**
+    * @brief Sets longitude.
+    *
+    * @param longitude value
+    */
+    void setLongitude(double longitude);
+
+/******************************************************************************
+* DATA MEMBERS
+******************************************************************************/
+private:
+    double m_latitude;  ///< Latitude value
+    double m_longitude; ///< Longitude value
+};
+
+#endif // GEOCOORDINATE_H
index 96c5544..7709cf8 100644 (file)
 
 #include "geopositioninfo.h"
 #include "gpscommon.h"
+#include "geocoordinate.h"
 
 GeoPositionInfo::GeoPositionInfo()
+    : m_isAccurate(false)
 {
 }
 
-void GeoPositionInfo::setLatitude(qreal latitude)
+QDateTime GeoPositionInfo::timestamp() const
 {
-    m_latitude = latitude;
+    return m_timestamp;
 }
 
-qreal GeoPositionInfo::latitude() const
-{
-    return m_latitude;
-}
-void GeoPositionInfo::setLongitude(qreal longitude)
+void GeoPositionInfo::setTimestamp(qreal time)
 {
-    m_longitude = longitude;
+    m_timestamp = QDateTime::fromTime_t(time);
 }
 
-qreal GeoPositionInfo::longitude() const
+void GeoPositionInfo::setCoordinate(const GeoCoordinate &coordinate)
 {
-    return m_longitude;
+    m_coordinate = coordinate;
 }
 
-void GeoPositionInfo::setTimestamp(qreal time)
+GeoCoordinate GeoPositionInfo::coordinate() const
 {
-    m_timestamp = QDateTime::fromTime_t(time);
+    return m_coordinate;
 }
 
-QDateTime GeoPositionInfo::timestamp() const
+bool GeoPositionInfo::isValid()
 {
-    return m_timestamp;
+   return m_coordinate.isValid();
 }
 
-bool GeoPositionInfo::isValid() const
+void GeoPositionInfo::setAccuracy(bool accurate, qreal accuracy)
 {
-    if ((latitude >= MIN_LATITUDE) && (latitude < MAX_LATITUDE) &&
-        (longitude >= MIN_LONGITUDE) && (longitude < MAX_LONGITUDE))
-
-        return true;
+    if (accuracy < 0)
+        m_horizontalAccuracy = GPS_ACCURACY_UNDEFINED;
     else
-        return false;
-}
+        m_horizontalAccuracy = accuracy;
 
-void GeoPositionInfo::setAttribute(Attribute attribute, qreal value)
-{
-    if (hasAttribute(attribute))
-        m_horizontalAccuracy = value;
+    m_isAccurate = accurate;
 }
 
-qreal GeoPositionInfo::attribute(Attribute attribute)
+qreal GeoPositionInfo::accuracy() const
 {
-    if (attribute == HorizontalAccuracy)
-        return m_horizontalAccuracy;
-    else
-        return GPS_ACCURACY_UNDEFINED;
+    return m_horizontalAccuracy;
 }
 
-bool GeoPositionInfo::hasAttribute(Attribute attribute)
+bool GeoPositionInfo::isAccurate() const
 {
-    if (attribute == HorizontalAccuracy)
-        return true;
-    else
-        return false;
+    return m_isAccurate;
 }
index 9718f52..32e100d 100644 (file)
 #include <QObject>
 #include <QDateTime>
 
+#include "geocoordinate.h"
+
+/**
+* @brief GeoPositionInfo class stores geo position info.
+*/
 class GeoPositionInfo
 {
 public:
+    /**
+    * @brief Constructor.
+    */
     GeoPositionInfo();
 
-    enum Attribute {HorizontalAccuracy};
+/******************************************************************************
+* MEMBER FUNCTIONS AND SLOTS
+******************************************************************************/
+public:
+    /**
+    * @brief Returns accuracy.
+    *
+    * Returns -1 if accuracy is not accurate.
+    *
+    * @return qreal
+    */
+    qreal accuracy() const;
+
+    /**
+    * @brief Returns geo coordinates.
+    *
+    * @return GeoCoordinate
+    */
+    GeoCoordinate coordinate() const;
+
+    /**
+    * @brief Checks if the accuracy is accurate.
+    *
+    * @return true if accurate, false otherwise
+    */
+    bool isAccurate() const;
 
-    void setLatitude(qreal latitude);
-    qreal latitude() const;
-    void setLongitude(qreal longitude);
-    qreal longitude() const;
+    /**
+    * @brief Checks the validity of the GeoPositionInfo.
+    *
+    * Checks coordinate validity.
+    *
+    * @return true if valid, false otherwise
+    */
+    bool isValid();
+
+    /**
+    * @brief Sets accuracy.
+    *
+    * @param accurate true if accuracy is accurate (satellite positioning)
+    * @param accuracy accuracy value
+    */
+    void setAccuracy(bool accurate, qreal accuracy);
+
+    /**
+    * @brief Sets geo coordinates.
+    *
+    * @param coordinate GeoCoordinate
+    */
+    void setCoordinate(const GeoCoordinate &coordinate);
+
+
+    /**
+    * @brief Sets timestamp.
+    *
+    * @param time timestamp in seconds
+    */
     void setTimestamp(qreal time);
+
+    /**
+    * @brief Returns timestamp.
+    *
+    * @return QDateTime
+    */
     QDateTime timestamp() const;
-    bool isValid() const;
-    void setAttribute(Attribute attribute, qreal value);
-    qreal attribute(Attribute attribute);
-    bool hasAttribute(Attribute attribute);
 
+/******************************************************************************
+* DATA MEMBERS
+******************************************************************************/
 private:
-    QDateTime m_timestamp;
-    qreal m_latitude;
-    qreal m_longitude;
+    QDateTime m_timestamp;      ///< Timestamp
+    GeoCoordinate m_coordinate; ///< GeoCoordinate
+    qreal m_horizontalAccuracy; ///< Horizontal accuracy
+    bool m_isAccurate;          ///< Is accurate
 };
 
 #endif // GEOPOSITIONINFO_H
index 40b54da..80f76ba 100644 (file)
@@ -3,6 +3,7 @@
     Copyright (C) 2010  Ixonos Plc. Authors:
 
         Sami Rämö - sami.ramo@ixonos.com
+        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
@@ -19,7 +20,6 @@
     USA.
 */
 
-
 #ifndef GPSCOMMON_H
 #define GPSCOMMON_H
 
@@ -27,9 +27,9 @@
 
 const int GPS_ACCURACY_UNDEFINED = -1; ///< Value used when accuracy is undefined
 
-const qreal MAX_LATITUDE = 85.05112877980659237802;  ///< Maximum latitude value
-const qreal MIN_LATITUDE = -MAX_LATITUDE; ///< Minimum latitude value
-const qreal MIN_LONGITUDE = -180.0;  ///< Minimum longitude value
-const qreal MAX_LONGITUDE = 180.0;  ///< Maximum longitude value
+const qreal GPS_MAX_LATITUDE = 85.05112877980659237802;  ///< Maximum latitude value
+const qreal GPS_MIN_LATITUDE = -GPS_MAX_LATITUDE; ///< Minimum latitude value
+const qreal GPS_MIN_LONGITUDE = -180.0;  ///< Minimum longitude value
+const qreal GPS_MAX_LONGITUDE = 180.0;  ///< Maximum longitude value
 
 #endif // GPSCOMMON_H
index 63b0954..3348ca4 100644 (file)
@@ -24,7 +24,7 @@
 #include "gpsposition.h"
 
 #if defined(Q_WS_MAEMO_5) | defined(Q_WS_SIMULATOR)
-#include "gpspositionprivate.h"
+#include "gpspositionprivateliblocation.h"
 #else
 #include "gpspositionprivatestub.h"
 #endif
index e194f56..956d9e7 100644 (file)
@@ -28,7 +28,6 @@
 #include "gpscommon.h"
 #include "gpsposition.h"
 #include "gpspositionprivate.h"
-#include "liblocationwrapper.h"
 
 GPSPositionPrivate::GPSPositionPrivate(QObject *parent)
     : QObject(parent),
@@ -51,7 +50,7 @@ void GPSPositionPrivate::setMode(GPSPosition::Mode mode, const QString &filePath
     }
 
     if (mode == GPSPosition::Default) {
-        m_gpsSource = new LiblocationWrapper(this);
+        m_gpsSource = new QGeoPositionInfoSource(this);
 
         if (!m_gpsSource) {
             emit m_parent->error(tr("Unable to use GPS"));
@@ -59,12 +58,12 @@ void GPSPositionPrivate::setMode(GPSPosition::Mode mode, const QString &filePath
         }
     }
     else if (mode == GPSPosition::Simulation) {
-//        QNmeaPositionInfoSource *nmeaSource = new QNmeaPositionInfoSource(
-//                QNmeaPositionInfoSource::SimulationMode, this);
-//        QFile *logFile = new QFile(filePath, this);
+        QNmeaPositionInfoSource *nmeaSource = new QNmeaPositionInfoSource(
+                QNmeaPositionInfoSource::SimulationMode, this);
+        QFile *logFile = new QFile(filePath, this);
 
-//        nmeaSource->setDevice(logFile);
-//        m_gpsSource = nmeaSource;
+        nmeaSource->setDevice(logFile);
+        m_gpsSource = nmeaSource;
     }
 
     if (m_gpsSource) {
@@ -107,7 +106,7 @@ QPointF GPSPositionPrivate::lastPosition()
 {
     GeoPositionInfo positionInfo = m_gpsSource->lastKnownPosition();
 
-    return QPointF(positionInfo.longitude(), positionInfo.latitude());
+    return QPointF(positionInfo.coordinate().longitude(), positionInfo.coordinate().latitude());
 }
 
 void GPSPositionPrivate::requestLastPosition()
@@ -117,7 +116,8 @@ void GPSPositionPrivate::requestLastPosition()
     GeoPositionInfo positionInfo = m_gpsSource->lastKnownPosition();
 
     if (positionInfo.isValid()) {
-        emit m_parent->position(QPointF(positionInfo.longitude(), positionInfo.latitude()),
+        GeoCoordinate coordinate = positionInfo.coordinate();
+        emit m_parent->position(QPointF(coordinate.longitude(), coordinate.latitude()),
                       accuracy(m_gpsSource->lastKnownPosition()));
     }
 }
@@ -127,8 +127,8 @@ void GPSPositionPrivate::positionUpdated(const GeoPositionInfo &positionInfo)
     qDebug() << __PRETTY_FUNCTION__ << positionInfo;
 
     if (positionInfo.coordinate().isValid()) {
-        emit m_parent->position(QPointF(positionInfo.longitude(),
-                              positionInfo.latitude()),
+        GeoCoordinate coordinate = positionInfo.coordinate();
+        emit m_parent->position(QPointF(coordinate.longitude(), coordinate.latitude()),
                       accuracy(positionInfo));
     }
 }
index e63720d..c0b0bb5 100644 (file)
 
 #include <QPointF>
 
-//#include <QGeoPositionInfo>
-//#include <QGeoPositionInfoSource>
-//#include <QNmeaPositionInfoSource>
+#include <QGeoPositionInfo>
+#include <QGeoPositionInfoSource>
+#include <QNmeaPositionInfoSource>
 
 #include "gpsposition.h"
 
-//QTM_USE_NAMESPACE
-
-#include "geopositioninfo.h"
-
-class LiblocationWrapper;
+QTM_USE_NAMESPACE
 
 /**
 * @brief GPSPositionPrivate class use GPS to receive location information.
@@ -106,7 +102,7 @@ private:
     * @return accuracy value, -1 if undefined. Returns -1 also is timestamp is not valid
     *         (when using network positioning)
     */
-    qreal accuracy(const GeoPositionInfo &positionInfo);
+    qreal accuracy(const QGeoPositionInfo &positionInfo);
 
 private slots:
 
@@ -115,7 +111,7 @@ private slots:
     *
     * @param positionInfo Geo position info.
     */
-    void positionUpdated(const GeoPositionInfo &positionInfo);
+    void positionUpdated(const QGeoPositionInfo &positionInfo);
 
     /**
     * @brief Slot for update timeout.
@@ -128,8 +124,7 @@ private slots:
  * DATA MEMBERS
  ******************************************************************************/
 private:
-    //QGeoPositionInfoSource *m_gpsSource;        ///< GPS position info source
-    LiblocationWrapper  *m_gpsSource;            ///< GPS position info source
+    QGeoPositionInfoSource *m_gpsSource;        ///< GPS position info source
     GPSPosition *m_parent;                      ///< Parent object
     bool m_running;                             ///< GPS is running
     int m_updateInterval;                       ///< GPS update interval
diff --git a/src/gps/gpspositionprivateliblocation.cpp b/src/gps/gpspositionprivateliblocation.cpp
new file mode 100644 (file)
index 0000000..f9efbd7
--- /dev/null
@@ -0,0 +1,160 @@
+/*
+   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 <QFile>
+#include <QDir>
+#include <QApplication>
+#include <QDebug>
+#include <QTimer>
+
+#include "gpscommon.h"
+#include "gpsposition.h"
+#include "gpspositionprivateliblocation.h"
+#include "liblocationwrapper.h"
+
+GPSPositionPrivate::GPSPositionPrivate(QObject *parent)
+    : QObject(parent),
+      m_liblocationWrapper(0),
+      m_running(false),
+      m_updateInterval(DEFAULT_UPDATE_INTERVAL)
+{
+    qDebug() << __PRETTY_FUNCTION__;
+
+    m_parent = static_cast<GPSPosition*>(parent);
+}
+
+void GPSPositionPrivate::setMode(GPSPosition::Mode mode, const QString &filePath)
+{
+    qDebug() << __PRETTY_FUNCTION__;
+
+    Q_UNUSED(filePath);
+
+    if (m_liblocationWrapper) {
+        disconnect(m_liblocationWrapper, 0, 0, 0);
+        delete m_liblocationWrapper;
+    }
+
+    if (mode == GPSPosition::Default) {
+        m_liblocationWrapper = new LiblocationWrapper(this);
+
+        if (!m_liblocationWrapper) {
+            emit m_parent->error(tr("Unable to use GPS"));
+            return;
+        }
+    }
+
+    if (m_liblocationWrapper) {
+        connect(m_liblocationWrapper, SIGNAL(locationChanged(const GeoPositionInfo &)),
+                this, SLOT(positionUpdated(const GeoPositionInfo &)));
+        connect(m_liblocationWrapper, SIGNAL(locationError(const QString &)),
+                this, SLOT(error(const QString &)));
+
+        m_liblocationWrapper->setUpdateInterval(m_updateInterval);
+    }
+}
+
+void GPSPositionPrivate::start()
+{
+    qDebug() << __PRETTY_FUNCTION__;
+
+    if (m_liblocationWrapper && !isRunning()) {
+        m_liblocationWrapper->startUpdates();
+        m_running = true;
+    }
+}
+
+void GPSPositionPrivate::stop()
+{
+    qDebug() << __PRETTY_FUNCTION__;
+
+    if (m_liblocationWrapper && isRunning()) {
+        m_liblocationWrapper->stopUpdates();
+        m_running = false;
+    }
+}
+
+bool GPSPositionPrivate::isRunning()
+{
+    qDebug() << __PRETTY_FUNCTION__;
+
+    return m_running;
+}
+
+QPointF GPSPositionPrivate::lastPosition()
+{
+    GeoPositionInfo positionInfo =  m_liblocationWrapper->lastKnownPosition();
+
+    return QPointF(positionInfo.coordinate().longitude(), positionInfo.coordinate().latitude());
+}
+
+void GPSPositionPrivate::requestLastPosition()
+{
+    qDebug() << __PRETTY_FUNCTION__;
+
+    GeoPositionInfo positionInfo = m_liblocationWrapper->lastKnownPosition();
+
+    if (positionInfo.isValid()) {
+        GeoCoordinate coordinate = positionInfo.coordinate();
+        emit m_parent->position(QPointF(coordinate.longitude(), coordinate.latitude()),
+                      accuracy(positionInfo));
+    }
+}
+
+void GPSPositionPrivate::positionUpdated(const GeoPositionInfo &positionInfo)
+{
+    qDebug() << __PRETTY_FUNCTION__ << positionInfo;
+
+    if (positionInfo.coordinate().isValid()) {
+        GeoCoordinate coordinate = positionInfo.coordinate();
+        emit m_parent->position(QPointF(coordinate.longitude(), coordinate.latitude()),
+                      accuracy(positionInfo));
+    }
+}
+
+void GPSPositionPrivate::locationError(const QString &errorMessage)
+{
+    qDebug() << __PRETTY_FUNCTION__;
+
+    emit m_parent->error(errorMessage);
+}
+
+void GPSPositionPrivate::setUpdateInterval(int interval)
+{
+    qDebug() << __PRETTY_FUNCTION__;
+
+    if (m_updateInterval != interval) {
+        m_updateInterval = interval;
+        m_liblocationWrapper->setUpdateInterval(m_updateInterval);
+    }
+}
+
+qreal GPSPositionPrivate::accuracy(const GeoPositionInfo &positionInfo)
+{
+    qDebug() << __PRETTY_FUNCTION__;
+
+    if (!positionInfo.timestamp().isValid())
+        return GPS_ACCURACY_UNDEFINED;
+
+    if (positionInfo.isAccurate())
+        return positionInfo.accuracy();
+    else
+        return GPS_ACCURACY_UNDEFINED;
+}
diff --git a/src/gps/gpspositionprivateliblocation.h b/src/gps/gpspositionprivateliblocation.h
new file mode 100644 (file)
index 0000000..e14f5fe
--- /dev/null
@@ -0,0 +1,125 @@
+/*
+   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 GPSPOSITIONPRIVATELIBLOCATION_H
+#define GPSPOSITIONPRIVATELIBLOCATION_H
+
+#include <QPointF>
+
+#include "gpsposition.h"
+#include "geopositioninfo.h"
+
+class LiblocationWrapper;
+
+/**
+* @brief GPSPositionPrivate class use GPS to receive location information.
+*/
+class GPSPositionPrivate : public QObject
+{
+    Q_OBJECT
+
+public:
+    /**
+    * @brief Constructor creates GPS source.
+    *
+    * @param parent QObject
+    */
+    GPSPositionPrivate(QObject *parent);
+
+/******************************************************************************
+* MEMBER FUNCTIONS AND SLOTS
+******************************************************************************/
+public:
+    /**
+    * @brief Checks if GPS is running.
+    *
+    * @return true if GPS running, false otherwise
+    */
+    bool isRunning();
+
+    /**
+    * @brief Return last known position.
+    */
+    QPointF lastPosition();
+
+    /**
+    * @brief Informs gps to emit last known position.
+    */
+    void requestLastPosition();
+
+    /**
+    * @brief Set GPS mode.
+    *
+    * Modes: default and simulation.
+    * @param mode GPS mode
+    * @param filePath file path to NMEA file if simulation mode is used
+    */
+    void setMode(GPSPosition::Mode mode, const QString &filePath = 0);
+
+    /**
+    * @brief Set GPS update interval
+    *
+    * @return interval interval in milliseconds
+    */
+    void setUpdateInterval(int interval);
+
+    /**
+    * @brief Start GPS.
+    */
+    void start();
+
+    /**
+    * @brief Stop GPS.
+    */
+    void stop();
+
+private:
+    qreal accuracy(const GeoPositionInfo &positionInfo);
+
+private slots:
+
+    /**
+    * @brief Slot for received position update.
+    *
+    * @param positionInfo Geo position info.
+    */
+    void positionUpdated(const GeoPositionInfo &positionInfo);
+
+    /**
+    * @brief Slot for location error.
+    *
+    * Called when there is error in GPS.
+    */
+    void locationError(const QString &errorMessage);
+
+/*******************************************************************************
+ * DATA MEMBERS
+ ******************************************************************************/
+private:
+    LiblocationWrapper *m_liblocationWrapper;    ///< Liblocation wrapper object
+    GPSPosition *m_parent;                      ///< Parent object
+    bool m_running;                             ///< GPS is running
+    int m_updateInterval;                       ///< GPS update interval
+};
+
+const int DEFAULT_UPDATE_INTERVAL = 5000;       ///< Default update interval
+
+#endif // GPSPOSITIONPRIVATELIBLOCATION_H
index 6918b6f..7077563 100644 (file)
    USA.
 */
 
+#include <QDebug>
+
 #include "liblocationwrapper.h"
 #include "geopositioninfo.h"
+#include "geocoordinate.h"
 
 LiblocationWrapper::LiblocationWrapper(QObject *parent)
-    : QObject(parent)
+    : QObject(parent),
+      m_control(0),
+      m_device(0),
+      m_state(LiblocationWrapper::Undefined)
 {
     qDebug() << __PRETTY_FUNCTION__;
 
     m_control = location_gpsd_control_get_default();
     m_device = (LocationGPSDevice*)g_object_new(LOCATION_TYPE_GPS_DEVICE, NULL);
 
-    g_object_set(G_OBJECT(m_control),
-            "preferred-method", LOCATION_METHOD_USER_SELECTED,
-            "preferred-interval", LOCATION_INTERVAL_5S,
-            NULL);
-
-    g_signal_connect(G_OBJECT(m_device), "changed", G_CALLBACK(&changed),
-                     static_cast<void*>(this));
+    if (m_control && m_device)
+        setState(LiblocationWrapper::Initialized);
 }
 
 LiblocationWrapper::~LiblocationWrapper()
@@ -49,64 +50,136 @@ LiblocationWrapper::~LiblocationWrapper()
         g_object_unref(m_control);
 }
 
-LiblocationWrapper::changed(LocationGPSDevice *device, gpointer data)
+void LiblocationWrapper::changed(LocationGPSDevice *device, gpointer data)
 {
     qDebug() << __PRETTY_FUNCTION__;
 
-    if (m_device) {
-        if (m_device->fix) {
+    if (!device || !data)
+        return;
 
-        GeoPositionInfo positionInfo;
+    GeoPositionInfo positionInfo;
+    LiblocationWrapper *wrapper;
+    wrapper = (LiblocationWrapper*)data;
 
-            if (m_device->fix->fields & LOCATION_GPS_DEVICE_TIME_SET) {
-                qDebug() <<  __PRETTY_FUNCTION__ << m_device->fix->time;
+    if (device) {
+        if (device->fix) {
 
-                positionInfo.setTimestamp(m_device->fix->time);
-                positionInfo.setAttribute(GeoPositionInfo::HorizontalAccuracy, m_device->fix->eph);
+            if (device->fix->fields & LOCATION_GPS_DEVICE_TIME_SET) {
+                positionInfo.setTimestamp(device->fix->time);
+                positionInfo.setAccuracy(true, device->fix->eph);
+            }
+            else {
+                positionInfo.setAccuracy(false, device->fix->eph);
             }
 
-            if (m_device->fix->fields & LOCATION_GPS_DEVICE_LATLONG_SET) {
-                qDebug() <<  __PRETTY_FUNCTION__ << m_device->fix->latitude << m_device->fix->longitude;
+            if (device->fix->fields & LOCATION_GPS_DEVICE_LATLONG_SET) {
+                GeoCoordinate coordinate;
 
-                positionInfo.setLatitude(m_device->fix->latitude);
-                positionInfo.setLongitude(m_device->fix->longitude);
-            }
+                coordinate.setLatitude(device->fix->latitude);
+                coordinate.setLongitude(device->fix->longitude);
+                positionInfo.setCoordinate(coordinate);
+            }    
         }
-
-        setLastKnownPosition(positionInfo);
-        emit locationChanged(positionInfo);
+        wrapper->setLastKnownPosition(positionInfo);
+        wrapper->locationChanged();
     }
 }
 
+bool LiblocationWrapper::isRunning()
+{
+    qDebug() << __PRETTY_FUNCTION__;
+
+    if (state() == LiblocationWrapper::Running)
+        return true;
+    else
+        return false;
+}
+
 GeoPositionInfo LiblocationWrapper::lastKnownPosition() const
 {
+    qDebug() << __PRETTY_FUNCTION__;
+
     return m_lastKnownPosition;
 }
 
+void LiblocationWrapper::locationChanged()
+{
+    qDebug() << __PRETTY_FUNCTION__;
+
+    emit locationChanged(lastKnownPosition());
+}
+
 void LiblocationWrapper::setLastKnownPosition(const GeoPositionInfo &positionInfo)
 {
+    qDebug() << __PRETTY_FUNCTION__;
+
     m_lastKnownPosition = positionInfo;
 }
 
 void LiblocationWrapper::setUpdateInterval(int updateInterval)
 {
+    qDebug() << __PRETTY_FUNCTION__;
 
+    if (state() == LiblocationWrapper::Initialized) {
+
+        int locationInterval = LOCATION_INTERVAL_DEFAULT;
+
+        if ((updateInterval > 0) && (updateInterval <= 1500))
+            locationInterval = LOCATION_INTERVAL_1S;
+        else if (updateInterval <= 2500)
+            locationInterval = LOCATION_INTERVAL_2S;
+        else if (updateInterval <= 7500)
+            locationInterval = LOCATION_INTERVAL_5S;
+        else if (updateInterval <= 15000)
+            locationInterval = LOCATION_INTERVAL_10S;
+        else if (updateInterval <= 25000)
+            locationInterval = LOCATION_INTERVAL_20S;
+        else if (updateInterval <= 45000)
+            locationInterval = LOCATION_INTERVAL_30S;
+        else if (updateInterval <= 90000)
+            locationInterval = LOCATION_INTERVAL_60S;
+        else if (updateInterval <= 120000)
+            locationInterval = LOCATION_INTERVAL_120S;
+
+
+        g_object_set(G_OBJECT(m_control), "preferred-method", LOCATION_METHOD_USER_SELECTED,
+                "preferred-interval", locationInterval, ((void *)0));
+
+        g_signal_connect(G_OBJECT(m_device), "changed", G_CALLBACK(&changed),
+                         static_cast<void*>(this));
+    }
 }
 
 void LiblocationWrapper::startUpdates()
 {
-    if (!isRunning())
+    qDebug() << __PRETTY_FUNCTION__;
+
+    if (!isRunning()) {
+        setState(LiblocationWrapper::Running);
         location_gpsd_control_start(m_control);
+    }
 }
 
-void LiblocationWrapper::stopUpdates()
+void LiblocationWrapper::setState(int state)
 {
-    if (isRunning())
-        location_gpsd_control_stop(m_control);
+    qDebug() << __PRETTY_FUNCTION__;
 
+    m_state = state;
 }
 
-bool LiblocationWrapper::isRunning()
+int LiblocationWrapper::state()
 {
-    return m_isRunning();
+    qDebug() << __PRETTY_FUNCTION__;
+
+    return m_state;
+}
+
+void LiblocationWrapper::stopUpdates()
+{
+    qDebug() << __PRETTY_FUNCTION__;
+
+    if (isRunning()) {
+        setState(LiblocationWrapper::Initialized);
+        location_gpsd_control_stop(m_control);
+    }
 }
index 6a0f30e..b6f4cae 100644 (file)
@@ -31,33 +31,122 @@ extern "C"
     #include <location/location-gpsd-control.h>
 }
 
+/**
+* @brief LiblocationWrapper class is a wrapper for liblocation library.
+*/
 class LiblocationWrapper : public QObject
 {
     Q_OBJECT
 
 public:
-    LiblocationWrapper(QObject *parent = 0);
+    /**
+    * @brief Constructor.
+    */
+    LiblocationWrapper(QObject *parent);
+
+    /**
+    * @brief Destructor.
+    *
+    * Releases m_control and m_device objects.
+    */
     ~LiblocationWrapper();
 
+    /**
+    * GPS state.
+    */
+    enum State {Undefined, Initialized, Running};
+
+/******************************************************************************
+* MEMBER FUNCTIONS AND SLOTS
+******************************************************************************/
+    /**
+    * @brief Checks if GPS is running.
+    *
+    * @return true if running, false otherwise
+    */
+    bool isRunning();
+
+    /**
+    * @brief Returns last known position.
+    *
+    * @return GeoPositionInfo
+    */
     GeoPositionInfo lastKnownPosition() const;
+
+    /**
+    * @brief Starts GPS updates.
+    */
+    void startUpdates();
+
+    /**
+    * @brief Sets last known position.
+    *
+    * @param positionInfo GeoPositionInfo
+    */
     void setLastKnownPosition(const GeoPositionInfo &positionInfo);
+
+    /**
+    * @brief Sets update interval.
+    *
+    * DOES NOTHING.
+    *
+    * @param updateInterval update interval in milliseconds
+    */
     void setUpdateInterval(int updateInterval);
-    void startUpdates();
+
+    /**
+    * @brief Stops GPS updates.
+    */
     void stopUpdates();
-    bool isRunning();
 
 private:
+    /**
+    * @brief Called when GPS location changes.
+    *
+    * @param device LocationGPSDevice
+    * @param data qpointer
+    */
     static void changed(LocationGPSDevice *device, gpointer data);
 
+    /**
+    * @brief Emits locationChanged signal.
+    */
+    void locationChanged();
+
+    /**
+    * @brief Sets state.
+    *
+    * @param state State
+    */
+    void setState(int state);
+
+    /**
+    * Returns state.
+    *
+    * State state
+    */
+    int state();
+
+/******************************************************************************
+* SIGNALS
+******************************************************************************/
 signals:
+    /**
+    * @brief Signal for location change.
+    *
+    * @param positionInfo GeoPositionInfo
+    */
     void locationChanged(const GeoPositionInfo &positionInfo);
 
-private:
-    LocationGPSDControl *m_control;
-    LocationGPSDevice *m_device;
 
-    GeoPositionInfo m_lastKnownPosition;
-    bool m_isRunning;
+/******************************************************************************
+* DATA MEMBERS
+******************************************************************************/
+private:
+    LocationGPSDControl *m_control;         ///< LocationGPSDControl pointer
+    LocationGPSDevice *m_device;            ///< LocationGPSDevice pointer
+    GeoPositionInfo m_lastKnownPosition;    ///< GeoPositionInfo data
+    int m_state;                            ///< GPS state
 };
 
 #endif // LIBLOCATIONWRAPPER_H
index 1ce1327..87f6238 100644 (file)
@@ -46,9 +46,7 @@ SOURCES += main.cpp \
     network/networkaccessmanager.cpp \
     network/networkhandler.cpp \
     network/networkcookiejar.cpp \
-    network/networkreply.cpp \
-    gps/liblocationwrapper.cpp \
-    gps/geopositioninfo.cpp
+    network/networkreply.cpp
 HEADERS += ui/mainwindow.h \
     map/mapengine.h \
     map/mapview.h \
@@ -96,9 +94,11 @@ HEADERS += ui/mainwindow.h \
     network/networkcookiejar.h \
     network/networkreply.h \
     gps/liblocationwrapper.h \
-    gps/geopositioninfo.h
+    gps/geopositioninfo.h \
+    gps/geocoordinate.h
 QT += network \
     webkit
+
 DEFINES += QT_NO_DEBUG_OUTPUT
 
 maemo5 | simulator {
@@ -113,14 +113,17 @@ maemo5 | simulator {
         SOURCES += network/networkhandlerprivatestub.cpp
         HEADERS += network/networkhandlerprivatestub.h
     }
-    SOURCES += gps/gpspositionprivate.cpp
-    HEADERS += gps/gpspositionprivate.h
+    SOURCES += gps/gpspositionprivateliblocation.cpp \
+               gps/liblocationwrapper.cpp \
+               gps/geopositioninfo.cpp \
+               gps/geocoordinate.cpp
+    HEADERS += gps/gpspositionprivateliblocation.h \
+               gps/liblocationwrapper.h \
+               gps/geopositioninfo.h \
+               gps/geocoordinate.h
     QT += maemo5
-#    CONFIG += mobility
-#    MOBILITY = location
     CONFIG += link_pkgconfig
-    PKGCONFIG += glib-2.0 \
-    liblocation
+    PKGCONFIG += glib-2.0 liblocation
     message([QJson])
     message(Make sure you have QJson development headers installed)
     message(add: deb http://repository.maemo.org/extras-devel fremantle free non-free)