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),
38 m_updateInterval(DEFAULT_UPDATE_INTERVAL)
40 qDebug() << __PRETTY_FUNCTION__;
42 m_parent = static_cast<GPSPosition*>(parent);
45 bool GPSPositionPrivate::isInitialized()
47 qDebug() << __PRETTY_FUNCTION__;
52 void GPSPositionPrivate::setMode(GPSPosition::Mode mode, const QString &filePath)
54 qDebug() << __PRETTY_FUNCTION__;
58 if (m_liblocationWrapper) {
59 disconnect(m_liblocationWrapper, 0, 0, 0);
60 delete m_liblocationWrapper;
63 if (mode == GPSPosition::Default) {
64 m_liblocationWrapper = new LiblocationWrapper(this);
66 if (!m_liblocationWrapper) {
67 m_initialized = false;
68 emit m_parent->error(123); ///Change to correct error code
73 if (m_liblocationWrapper) {
75 m_liblocationWrapper->init(m_updateInterval);
77 connect(m_liblocationWrapper, SIGNAL(locationChanged(const GeoPositionInfo &)),
78 this, SLOT(positionUpdated(const GeoPositionInfo &)));
79 connect(m_liblocationWrapper, SIGNAL(errorMessage(const QString &)),
80 this, SLOT(locationError(const QString &)));
84 void GPSPositionPrivate::start()
86 qDebug() << __PRETTY_FUNCTION__;
88 if (m_initialized && !isRunning()) {
89 m_liblocationWrapper->startUpdates();
94 void GPSPositionPrivate::stop()
96 qDebug() << __PRETTY_FUNCTION__;
98 if (m_initialized && isRunning()) {
99 m_liblocationWrapper->stopUpdates();
104 bool GPSPositionPrivate::isRunning()
106 qDebug() << __PRETTY_FUNCTION__;
111 QPointF GPSPositionPrivate::lastPosition()
113 qDebug() << __PRETTY_FUNCTION__;
115 GeoPositionInfo positionInfo = m_liblocationWrapper->lastKnownPosition();
117 return QPointF(positionInfo.coordinate().longitude(), positionInfo.coordinate().latitude());
120 void GPSPositionPrivate::requestLastPosition()
122 qDebug() << __PRETTY_FUNCTION__;
124 GeoPositionInfo positionInfo = m_liblocationWrapper->lastKnownPosition();
126 if (positionInfo.isValid()) {
127 GeoCoordinate coordinate = positionInfo.coordinate();
128 emit m_parent->position(QPointF(coordinate.longitude(), coordinate.latitude()),
129 accuracy(positionInfo));
133 void GPSPositionPrivate::positionUpdated(const GeoPositionInfo &positionInfo)
135 qDebug() << __PRETTY_FUNCTION__;
137 if (positionInfo.coordinate().isValid()) {
138 GeoCoordinate coordinate = positionInfo.coordinate();
139 emit m_parent->position(QPointF(coordinate.longitude(), coordinate.latitude()),
140 accuracy(positionInfo));
144 void GPSPositionPrivate::locationError(const QString &errorMessage)
146 qDebug() << __PRETTY_FUNCTION__;
148 Q_UNUSED(errorMessage);
150 emit m_parent->error(123);
153 void GPSPositionPrivate::setUpdateInterval(int interval)
155 qDebug() << __PRETTY_FUNCTION__;
157 if (m_updateInterval != interval) {
158 m_updateInterval = interval;
159 m_liblocationWrapper->init(m_updateInterval);
163 qreal GPSPositionPrivate::accuracy(const GeoPositionInfo &positionInfo)
165 qDebug() << __PRETTY_FUNCTION__;
167 if (!positionInfo.timestamp().isValid())
168 return GPS_ACCURACY_UNDEFINED;
170 if (positionInfo.isAccurate())
171 return positionInfo.accuracy();
173 return GPS_ACCURACY_UNDEFINED;