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>
29 #include "gpscommon.h"
30 #include "gpsposition.h"
31 #include "gpspositionprivateliblocation.h"
32 #include "liblocationwrapper.h"
34 GPSPositionPrivate::GPSPositionPrivate(QObject *parent)
36 m_liblocationWrapper(0),
38 m_updateInterval(DEFAULT_UPDATE_INTERVAL)
40 qDebug() << __PRETTY_FUNCTION__;
42 m_parent = static_cast<GPSPosition*>(parent);
45 void GPSPositionPrivate::setMode(GPSPosition::Mode mode, const QString &filePath)
47 qDebug() << __PRETTY_FUNCTION__;
51 if (m_liblocationWrapper) {
52 disconnect(m_liblocationWrapper, 0, 0, 0);
53 delete m_liblocationWrapper;
56 if (mode == GPSPosition::Default) {
57 m_liblocationWrapper = new LiblocationWrapper(this);
59 if (!m_liblocationWrapper) {
60 emit m_parent->error(SituareError::GPS_INITIALIZATION_FAILED);
65 if (m_liblocationWrapper) {
66 m_liblocationWrapper->init(m_updateInterval);
68 connect(m_liblocationWrapper, SIGNAL(locationChanged(const GeoPositionInfo &)),
69 this, SLOT(positionUpdated(const GeoPositionInfo &)));
70 connect(m_liblocationWrapper, SIGNAL(errorMessage(const QString &)),
71 this, SLOT(locationError(const QString &)));
75 void GPSPositionPrivate::start()
77 qDebug() << __PRETTY_FUNCTION__;
79 if (m_liblocationWrapper && !isRunning()) {
80 m_liblocationWrapper->startUpdates();
85 void GPSPositionPrivate::stop()
87 qDebug() << __PRETTY_FUNCTION__;
89 if (m_liblocationWrapper && isRunning()) {
90 m_liblocationWrapper->stopUpdates();
95 bool GPSPositionPrivate::isRunning()
97 qDebug() << __PRETTY_FUNCTION__;
102 QPointF GPSPositionPrivate::lastPosition()
104 qDebug() << __PRETTY_FUNCTION__;
106 GeoPositionInfo positionInfo = m_liblocationWrapper->lastKnownPosition();
108 return QPointF(positionInfo.coordinate().longitude(), positionInfo.coordinate().latitude());
111 void GPSPositionPrivate::requestLastPosition()
113 qDebug() << __PRETTY_FUNCTION__;
115 GeoPositionInfo positionInfo = m_liblocationWrapper->lastKnownPosition();
117 if (positionInfo.isValid()) {
118 GeoCoordinate coordinate = positionInfo.coordinate();
119 emit m_parent->position(QPointF(coordinate.longitude(), coordinate.latitude()),
120 accuracy(positionInfo));
124 void GPSPositionPrivate::positionUpdated(const GeoPositionInfo &positionInfo)
126 qDebug() << __PRETTY_FUNCTION__;
128 if (positionInfo.coordinate().isValid()) {
129 GeoCoordinate coordinate = positionInfo.coordinate();
130 emit m_parent->position(QPointF(coordinate.longitude(), coordinate.latitude()),
131 accuracy(positionInfo));
135 void GPSPositionPrivate::locationError(const QString &errorMessage)
137 qDebug() << __PRETTY_FUNCTION__;
139 Q_UNUSED(errorMessage);
141 emit m_parent->error(SituareError::GPS_INITIALIZATION_FAILED);
144 void GPSPositionPrivate::setUpdateInterval(int interval)
146 qDebug() << __PRETTY_FUNCTION__;
148 if (m_updateInterval != interval) {
149 m_updateInterval = interval;
150 m_liblocationWrapper->init(m_updateInterval);
154 qreal GPSPositionPrivate::accuracy(const GeoPositionInfo &positionInfo)
156 qDebug() << __PRETTY_FUNCTION__;
158 if (!positionInfo.timestamp().isValid())
159 return GPS_ACCURACY_UNDEFINED;
161 if (positionInfo.isAccurate())
162 return positionInfo.accuracy();
164 return GPS_ACCURACY_UNDEFINED;