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(tr("Unable to use GPS"));
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 GeoPositionInfo positionInfo = m_liblocationWrapper->lastKnownPosition();
105 return QPointF(positionInfo.coordinate().longitude(), positionInfo.coordinate().latitude());
108 void GPSPositionPrivate::requestLastPosition()
110 qDebug() << __PRETTY_FUNCTION__;
112 GeoPositionInfo positionInfo = m_liblocationWrapper->lastKnownPosition();
114 if (positionInfo.isValid()) {
115 GeoCoordinate coordinate = positionInfo.coordinate();
116 emit m_parent->position(QPointF(coordinate.longitude(), coordinate.latitude()),
117 accuracy(positionInfo));
121 void GPSPositionPrivate::positionUpdated(const GeoPositionInfo &positionInfo)
123 qDebug() << __PRETTY_FUNCTION__ << positionInfo;
125 if (positionInfo.coordinate().isValid()) {
126 GeoCoordinate coordinate = positionInfo.coordinate();
127 emit m_parent->position(QPointF(coordinate.longitude(), coordinate.latitude()),
128 accuracy(positionInfo));
132 void GPSPositionPrivate::locationError(const QString &errorMessage)
134 qDebug() << __PRETTY_FUNCTION__;
136 emit m_parent->error(errorMessage);
139 void GPSPositionPrivate::setUpdateInterval(int interval)
141 qDebug() << __PRETTY_FUNCTION__;
143 if (m_updateInterval != interval) {
144 m_updateInterval = interval;
145 m_liblocationWrapper->init(m_updateInterval);
149 qreal GPSPositionPrivate::accuracy(const GeoPositionInfo &positionInfo)
151 qDebug() << __PRETTY_FUNCTION__;
153 if (!positionInfo.timestamp().isValid())
154 return GPS_ACCURACY_UNDEFINED;
156 if (positionInfo.isAccurate())
157 return positionInfo.accuracy();
159 return GPS_ACCURACY_UNDEFINED;