2 Situare - A location system for Facebook
3 Copyright (C) 2010 Ixonos Plc. Authors:
5 Jussi Laitinen - jussi.laitinen@ixonos.com
7 Situare is free software; you can redistribute it and/or
8 modify it under the terms of the GNU General Public License
9 version 2 as published by the Free Software Foundation.
11 Situare is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with Situare; if not, write to the Free Software
18 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
24 #include <QApplication>
28 #include "gpscommon.h"
29 #include "gpsposition.h"
30 #include "gpspositionprivate.h"
31 #include "liblocationwrapper.h"
33 GPSPositionPrivate::GPSPositionPrivate(QObject *parent)
37 m_updateInterval(DEFAULT_UPDATE_INTERVAL)
39 qDebug() << __PRETTY_FUNCTION__;
41 m_parent = static_cast<GPSPosition*>(parent);
44 void GPSPositionPrivate::setMode(GPSPosition::Mode mode, const QString &filePath)
46 qDebug() << __PRETTY_FUNCTION__;
49 disconnect(m_gpsSource, 0, 0, 0);
53 if (mode == GPSPosition::Default) {
54 m_gpsSource = new LiblocationWrapper(this);
57 emit m_parent->error(tr("Unable to use GPS"));
61 else if (mode == GPSPosition::Simulation) {
62 // QNmeaPositionInfoSource *nmeaSource = new QNmeaPositionInfoSource(
63 // QNmeaPositionInfoSource::SimulationMode, this);
64 // QFile *logFile = new QFile(filePath, this);
66 // nmeaSource->setDevice(logFile);
67 // m_gpsSource = nmeaSource;
71 connect(m_gpsSource, SIGNAL(positionUpdated(const GeoPositionInfo &)),
72 this, SLOT(positionUpdated(const GeoPositionInfo &)));
73 //connect(m_gpsSource, SIGNAL(updateTimeout()), this, SLOT(updateTimeout()));
75 m_gpsSource->setUpdateInterval(m_updateInterval);
79 void GPSPositionPrivate::start()
81 qDebug() << __PRETTY_FUNCTION__;
83 if (m_gpsSource && !isRunning()) {
84 m_gpsSource->startUpdates();
89 void GPSPositionPrivate::stop()
91 qDebug() << __PRETTY_FUNCTION__;
93 if (m_gpsSource && isRunning()) {
94 m_gpsSource->stopUpdates();
99 bool GPSPositionPrivate::isRunning()
101 qDebug() << __PRETTY_FUNCTION__;
106 QPointF GPSPositionPrivate::lastPosition()
108 GeoPositionInfo positionInfo = m_gpsSource->lastKnownPosition();
110 return QPointF(positionInfo.longitude(), positionInfo.latitude());
113 void GPSPositionPrivate::requestLastPosition()
115 qDebug() << __PRETTY_FUNCTION__;
117 GeoPositionInfo positionInfo = m_gpsSource->lastKnownPosition();
119 if (positionInfo.isValid()) {
120 emit m_parent->position(QPointF(positionInfo.longitude(), positionInfo.latitude()),
121 accuracy(m_gpsSource->lastKnownPosition()));
125 void GPSPositionPrivate::positionUpdated(const GeoPositionInfo &positionInfo)
127 qDebug() << __PRETTY_FUNCTION__ << positionInfo;
129 if (positionInfo.coordinate().isValid()) {
130 emit m_parent->position(QPointF(positionInfo.longitude(),
131 positionInfo.latitude()),
132 accuracy(positionInfo));
136 void GPSPositionPrivate::updateTimeout()
138 qDebug() << __PRETTY_FUNCTION__;
140 emit m_parent->timeout();
143 void GPSPositionPrivate::setUpdateInterval(int interval)
145 qDebug() << __PRETTY_FUNCTION__;
147 if (m_updateInterval != interval) {
148 m_updateInterval = interval;
149 m_gpsSource->setUpdateInterval(m_updateInterval);
153 qreal GPSPositionPrivate::accuracy(const GeoPositionInfo &positionInfo)
155 qDebug() << __PRETTY_FUNCTION__;
157 if (!positionInfo.timestamp().isValid())
158 return GPS_ACCURACY_UNDEFINED;
160 if (positionInfo.hasAttribute(GeoPositionInfo::HorizontalAccuracy))
161 return positionInfo.attribute(GeoPositionInfo::HorizontalAccuracy);
163 return GPS_ACCURACY_UNDEFINED;