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 "gpspositionprivateliblocation.h"
31 #include "liblocationwrapper.h"
33 GPSPositionPrivate::GPSPositionPrivate(QObject *parent)
35 m_liblocationWrapper(0),
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__;
50 if (m_liblocationWrapper) {
51 disconnect(m_liblocationWrapper, 0, 0, 0);
52 delete m_liblocationWrapper;
55 if (mode == GPSPosition::Default) {
56 m_liblocationWrapper = new LiblocationWrapper(this);
58 if (!m_liblocationWrapper) {
59 emit m_parent->error(123); ///Change to correct error code
64 if (m_liblocationWrapper) {
65 m_liblocationWrapper->init(m_updateInterval);
67 connect(m_liblocationWrapper, SIGNAL(locationChanged(const GeoPositionInfo &)),
68 this, SLOT(positionUpdated(const GeoPositionInfo &)));
69 connect(m_liblocationWrapper, SIGNAL(errorMessage(const QString &)),
70 this, SLOT(locationError(const QString &)));
74 void GPSPositionPrivate::start()
76 qDebug() << __PRETTY_FUNCTION__;
78 if (m_liblocationWrapper && !isRunning()) {
79 m_liblocationWrapper->startUpdates();
84 void GPSPositionPrivate::stop()
86 qDebug() << __PRETTY_FUNCTION__;
88 if (m_liblocationWrapper && isRunning()) {
89 m_liblocationWrapper->stopUpdates();
94 bool GPSPositionPrivate::isRunning()
96 qDebug() << __PRETTY_FUNCTION__;
101 QPointF GPSPositionPrivate::lastPosition()
103 qDebug() << __PRETTY_FUNCTION__;
105 GeoPositionInfo positionInfo = m_liblocationWrapper->lastKnownPosition();
107 return QPointF(positionInfo.coordinate().longitude(), positionInfo.coordinate().latitude());
110 void GPSPositionPrivate::requestLastPosition()
112 qDebug() << __PRETTY_FUNCTION__;
114 GeoPositionInfo positionInfo = m_liblocationWrapper->lastKnownPosition();
116 if (positionInfo.isValid()) {
117 GeoCoordinate coordinate = positionInfo.coordinate();
118 emit m_parent->position(QPointF(coordinate.longitude(), coordinate.latitude()),
119 accuracy(positionInfo));
123 void GPSPositionPrivate::positionUpdated(const GeoPositionInfo &positionInfo)
125 qDebug() << __PRETTY_FUNCTION__;
127 if (positionInfo.coordinate().isValid()) {
128 GeoCoordinate coordinate = positionInfo.coordinate();
129 emit m_parent->position(QPointF(coordinate.longitude(), coordinate.latitude()),
130 accuracy(positionInfo));
134 void GPSPositionPrivate::locationError(const QString &errorMessage)
136 qDebug() << __PRETTY_FUNCTION__;
138 Q_UNUSED(errorMessage);
140 emit m_parent->error(123);
143 void GPSPositionPrivate::setUpdateInterval(int interval)
145 qDebug() << __PRETTY_FUNCTION__;
147 if (m_updateInterval != interval) {
148 m_updateInterval = interval;
149 m_liblocationWrapper->init(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.isAccurate())
161 return positionInfo.accuracy();
163 return GPS_ACCURACY_UNDEFINED;