--- /dev/null
+/*
+ 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 <QDateTime>
+
+#include "geopositioninfo.h"
+#include "gpscommon.h"
+
+GeoPositionInfo::GeoPositionInfo()
+{
+}
+
+void GeoPositionInfo::setLatitude(qreal latitude)
+{
+ m_latitude = latitude;
+}
+
+qreal GeoPositionInfo::latitude() const
+{
+ return m_latitude;
+}
+void GeoPositionInfo::setLongitude(qreal longitude)
+{
+ m_longitude = longitude;
+}
+
+qreal GeoPositionInfo::longitude() const
+{
+ return m_longitude;
+}
+
+void GeoPositionInfo::setTimestamp(qreal time)
+{
+ m_timestamp = QDateTime::fromTime_t(time);
+}
+
+QDateTime GeoPositionInfo::timestamp() const
+{
+ return m_timestamp;
+}
+
+bool GeoPositionInfo::isValid() const
+{
+ if ((latitude >= MIN_LATITUDE) && (latitude < MAX_LATITUDE) &&
+ (longitude >= MIN_LONGITUDE) && (longitude < MAX_LONGITUDE))
+
+ return true;
+ else
+ return false;
+}
+
+void GeoPositionInfo::setAttribute(Attribute attribute, qreal value)
+{
+ if (hasAttribute(attribute))
+ m_horizontalAccuracy = value;
+}
+
+qreal GeoPositionInfo::attribute(Attribute attribute)
+{
+ if (attribute == HorizontalAccuracy)
+ return m_horizontalAccuracy;
+ else
+ return GPS_ACCURACY_UNDEFINED;
+}
+
+bool GeoPositionInfo::hasAttribute(Attribute attribute)
+{
+ if (attribute == HorizontalAccuracy)
+ return true;
+ else
+ return false;
+}
--- /dev/null
+/*
+ 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 GEOPOSITIONINFO_H
+#define GEOPOSITIONINFO_H
+
+#include <QObject>
+#include <QDateTime>
+
+class GeoPositionInfo
+{
+public:
+ GeoPositionInfo();
+
+ enum Attribute {HorizontalAccuracy};
+
+ void setLatitude(qreal latitude);
+ qreal latitude() const;
+ void setLongitude(qreal longitude);
+ qreal longitude() const;
+ void setTimestamp(qreal time);
+ QDateTime timestamp() const;
+ bool isValid() const;
+ void setAttribute(Attribute attribute, qreal value);
+ qreal attribute(Attribute attribute);
+ bool hasAttribute(Attribute attribute);
+
+private:
+ QDateTime m_timestamp;
+ qreal m_latitude;
+ qreal m_longitude;
+};
+
+#endif // GEOPOSITIONINFO_H
#ifndef GPSCOMMON_H
#define GPSCOMMON_H
+#include <QObject>
+
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
+
#endif // GPSCOMMON_H
#include "gpscommon.h"
#include "gpsposition.h"
#include "gpspositionprivate.h"
+#include "liblocationwrapper.h"
GPSPositionPrivate::GPSPositionPrivate(QObject *parent)
: QObject(parent),
}
if (mode == GPSPosition::Default) {
- m_gpsSource = QGeoPositionInfoSource::createDefaultSource(this);
+ m_gpsSource = new LiblocationWrapper(this);
if (!m_gpsSource) {
emit m_parent->error(tr("Unable to use GPS"));
}
}
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) {
- connect(m_gpsSource, SIGNAL(positionUpdated(const QGeoPositionInfo &)),
- this, SLOT(positionUpdated(const QGeoPositionInfo &)));
- connect(m_gpsSource, SIGNAL(updateTimeout()), this, SLOT(updateTimeout()));
+ connect(m_gpsSource, SIGNAL(positionUpdated(const GeoPositionInfo &)),
+ this, SLOT(positionUpdated(const GeoPositionInfo &)));
+ //connect(m_gpsSource, SIGNAL(updateTimeout()), this, SLOT(updateTimeout()));
m_gpsSource->setUpdateInterval(m_updateInterval);
}
QPointF GPSPositionPrivate::lastPosition()
{
- QGeoCoordinate coordinate = m_gpsSource->lastKnownPosition().coordinate();
- return QPointF(coordinate.longitude(), coordinate.latitude());
+ GeoPositionInfo positionInfo = m_gpsSource->lastKnownPosition();
+
+ return QPointF(positionInfo.longitude(), positionInfo.latitude());
}
void GPSPositionPrivate::requestLastPosition()
{
qDebug() << __PRETTY_FUNCTION__;
- QGeoCoordinate coordinate = m_gpsSource->lastKnownPosition().coordinate();
+ GeoPositionInfo positionInfo = m_gpsSource->lastKnownPosition();
- if (coordinate.isValid()) {
- emit m_parent->position(QPointF(coordinate.longitude(), coordinate.latitude()),
+ if (positionInfo.isValid()) {
+ emit m_parent->position(QPointF(positionInfo.longitude(), positionInfo.latitude()),
accuracy(m_gpsSource->lastKnownPosition()));
}
}
-void GPSPositionPrivate::positionUpdated(const QGeoPositionInfo &positionInfo)
+void GPSPositionPrivate::positionUpdated(const GeoPositionInfo &positionInfo)
{
qDebug() << __PRETTY_FUNCTION__ << positionInfo;
if (positionInfo.coordinate().isValid()) {
- emit m_parent->position(QPointF(positionInfo.coordinate().longitude(),
- positionInfo.coordinate().latitude()),
+ emit m_parent->position(QPointF(positionInfo.longitude(),
+ positionInfo.latitude()),
accuracy(positionInfo));
}
}
}
}
-qreal GPSPositionPrivate::accuracy(const QGeoPositionInfo &positionInfo)
+qreal GPSPositionPrivate::accuracy(const GeoPositionInfo &positionInfo)
{
qDebug() << __PRETTY_FUNCTION__;
- QDateTime timestamp;
-
- if (!positionInfo.dateTime().isValid())
+ if (!positionInfo.timestamp().isValid())
return GPS_ACCURACY_UNDEFINED;
- if (positionInfo.hasAttribute(QGeoPositionInfo::HorizontalAccuracy))
- return positionInfo.attribute(QGeoPositionInfo::HorizontalAccuracy);
+ if (positionInfo.hasAttribute(GeoPositionInfo::HorizontalAccuracy))
+ return positionInfo.attribute(GeoPositionInfo::HorizontalAccuracy);
else
return GPS_ACCURACY_UNDEFINED;
}
#include <QPointF>
-#include <QGeoPositionInfo>
-#include <QGeoPositionInfoSource>
-#include <QNmeaPositionInfoSource>
+//#include <QGeoPositionInfo>
+//#include <QGeoPositionInfoSource>
+//#include <QNmeaPositionInfoSource>
#include "gpsposition.h"
-QTM_USE_NAMESPACE
+//QTM_USE_NAMESPACE
+
+#include "geopositioninfo.h"
+
+class LiblocationWrapper;
/**
* @brief GPSPositionPrivate class use GPS to receive location information.
* @return accuracy value, -1 if undefined. Returns -1 also is timestamp is not valid
* (when using network positioning)
*/
- qreal accuracy(const QGeoPositionInfo &positionInfo);
+ qreal accuracy(const GeoPositionInfo &positionInfo);
private slots:
*
* @param positionInfo Geo position info.
*/
- void positionUpdated(const QGeoPositionInfo &positionInfo);
+ void positionUpdated(const GeoPositionInfo &positionInfo);
/**
* @brief Slot for update timeout.
* DATA MEMBERS
******************************************************************************/
private:
- QGeoPositionInfoSource *m_gpsSource; ///< GPS position info source
+ //QGeoPositionInfoSource *m_gpsSource; ///< GPS position info source
+ LiblocationWrapper *m_gpsSource; ///< GPS position info source
GPSPosition *m_parent; ///< Parent object
bool m_running; ///< GPS is running
int m_updateInterval; ///< GPS update interval
--- /dev/null
+/*
+ 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 "liblocationwrapper.h"
+#include "geopositioninfo.h"
+
+LiblocationWrapper::LiblocationWrapper(QObject *parent)
+ : QObject(parent)
+{
+ 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));
+}
+
+LiblocationWrapper::~LiblocationWrapper()
+{
+ qDebug() << __PRETTY_FUNCTION__;
+
+ if (m_device)
+ g_object_unref(m_device);
+ if (m_control)
+ g_object_unref(m_control);
+}
+
+LiblocationWrapper::changed(LocationGPSDevice *device, gpointer data)
+{
+ qDebug() << __PRETTY_FUNCTION__;
+
+ if (m_device) {
+ if (m_device->fix) {
+
+ GeoPositionInfo positionInfo;
+
+ if (m_device->fix->fields & LOCATION_GPS_DEVICE_TIME_SET) {
+ qDebug() << __PRETTY_FUNCTION__ << m_device->fix->time;
+
+ positionInfo.setTimestamp(m_device->fix->time);
+ positionInfo.setAttribute(GeoPositionInfo::HorizontalAccuracy, m_device->fix->eph);
+ }
+
+ if (m_device->fix->fields & LOCATION_GPS_DEVICE_LATLONG_SET) {
+ qDebug() << __PRETTY_FUNCTION__ << m_device->fix->latitude << m_device->fix->longitude;
+
+ positionInfo.setLatitude(m_device->fix->latitude);
+ positionInfo.setLongitude(m_device->fix->longitude);
+ }
+ }
+
+ setLastKnownPosition(positionInfo);
+ emit locationChanged(positionInfo);
+ }
+}
+
+GeoPositionInfo LiblocationWrapper::lastKnownPosition() const
+{
+ return m_lastKnownPosition;
+}
+
+void LiblocationWrapper::setLastKnownPosition(const GeoPositionInfo &positionInfo)
+{
+ m_lastKnownPosition = positionInfo;
+}
+
+void LiblocationWrapper::setUpdateInterval(int updateInterval)
+{
+
+}
+
+void LiblocationWrapper::startUpdates()
+{
+ if (!isRunning())
+ location_gpsd_control_start(m_control);
+}
+
+void LiblocationWrapper::stopUpdates()
+{
+ if (isRunning())
+ location_gpsd_control_stop(m_control);
+
+}
+
+bool LiblocationWrapper::isRunning()
+{
+ return m_isRunning();
+}
--- /dev/null
+/*
+ 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 LIBLOCATIONWRAPPER_H
+#define LIBLOCATIONWRAPPER_H
+
+#include <QObject>
+#include "geopositioninfo.h"
+
+extern "C"
+{
+ #include <location/location-gps-device.h>
+ #include <location/location-gpsd-control.h>
+}
+
+class LiblocationWrapper : public QObject
+{
+ Q_OBJECT
+
+public:
+ LiblocationWrapper(QObject *parent = 0);
+ ~LiblocationWrapper();
+
+ GeoPositionInfo lastKnownPosition() const;
+ void setLastKnownPosition(const GeoPositionInfo &positionInfo);
+ void setUpdateInterval(int updateInterval);
+ void startUpdates();
+ void stopUpdates();
+ bool isRunning();
+
+private:
+ static void changed(LocationGPSDevice *device, gpointer data);
+
+signals:
+ void locationChanged(const GeoPositionInfo &positionInfo);
+
+private:
+ LocationGPSDControl *m_control;
+ LocationGPSDevice *m_device;
+
+ GeoPositionInfo m_lastKnownPosition;
+ bool m_isRunning;
+};
+
+#endif // LIBLOCATIONWRAPPER_H
network/networkaccessmanager.cpp \
network/networkhandler.cpp \
network/networkcookiejar.cpp \
- network/networkreply.cpp
+ network/networkreply.cpp \
+ gps/liblocationwrapper.cpp \
+ gps/geopositioninfo.cpp
HEADERS += ui/mainwindow.h \
map/mapengine.h \
map/mapview.h \
network/networkaccessmanager.h \
network/networkhandler.h \
network/networkcookiejar.h \
- network/networkreply.h
+ network/networkreply.h \
+ gps/liblocationwrapper.h \
+ gps/geopositioninfo.h
QT += network \
webkit
DEFINES += QT_NO_DEBUG_OUTPUT
SOURCES += gps/gpspositionprivate.cpp
HEADERS += gps/gpspositionprivate.h
QT += maemo5
- CONFIG += mobility
- MOBILITY = location
+# CONFIG += mobility
+# MOBILITY = location
+ CONFIG += link_pkgconfig
+ 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)