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),
39 m_updateInterval(DEFAULT_UPDATE_INTERVAL)
41 qDebug() << __PRETTY_FUNCTION__;
43 m_parent = static_cast<GPSPosition*>(parent);
46 bool GPSPositionPrivate::isInitialized()
48 qDebug() << __PRETTY_FUNCTION__;
53 void GPSPositionPrivate::setMode(GPSPosition::Mode mode, const QString &filePath)
55 qDebug() << __PRETTY_FUNCTION__;
59 if (m_liblocationWrapper) {
60 disconnect(m_liblocationWrapper, 0, 0, 0);
61 delete m_liblocationWrapper;
64 if (mode == GPSPosition::Default) {
65 m_liblocationWrapper = new LiblocationWrapper(this);
67 if (!m_liblocationWrapper) {
68 m_initialized = false;
69 emit m_parent->error(SituareError::GPS_INITIALIZATION_FAILED);
74 if (m_liblocationWrapper) {
76 m_liblocationWrapper->init(m_updateInterval);
78 connect(m_liblocationWrapper, SIGNAL(locationChanged(const GeoPositionInfo &)),
79 this, SLOT(positionUpdated(const GeoPositionInfo &)));
80 connect(m_liblocationWrapper, SIGNAL(errorMessage(const QString &)),
81 this, SLOT(locationError(const QString &)));
85 void GPSPositionPrivate::start()
87 qDebug() << __PRETTY_FUNCTION__;
89 if (m_initialized && !isRunning()) {
90 m_liblocationWrapper->startUpdates();
95 void GPSPositionPrivate::stop()
97 qDebug() << __PRETTY_FUNCTION__;
99 if (m_initialized && isRunning()) {
100 m_liblocationWrapper->stopUpdates();
105 bool GPSPositionPrivate::isRunning()
107 qDebug() << __PRETTY_FUNCTION__;
112 QPointF GPSPositionPrivate::lastPosition()
114 qDebug() << __PRETTY_FUNCTION__;
116 GeoPositionInfo positionInfo = m_liblocationWrapper->lastKnownPosition();
118 return QPointF(positionInfo.coordinate().longitude(), positionInfo.coordinate().latitude());
121 void GPSPositionPrivate::requestLastPosition()
123 qDebug() << __PRETTY_FUNCTION__;
125 GeoPositionInfo positionInfo = m_liblocationWrapper->lastKnownPosition();
127 if (positionInfo.isValid()) {
128 GeoCoordinate coordinate = positionInfo.coordinate();
129 emit m_parent->position(QPointF(coordinate.longitude(), coordinate.latitude()),
130 accuracy(positionInfo));
134 void GPSPositionPrivate::positionUpdated(const GeoPositionInfo &positionInfo)
136 qDebug() << __PRETTY_FUNCTION__;
138 if (positionInfo.coordinate().isValid()) {
139 GeoCoordinate coordinate = positionInfo.coordinate();
140 emit m_parent->position(QPointF(coordinate.longitude(), coordinate.latitude()),
141 accuracy(positionInfo));
145 void GPSPositionPrivate::locationError(const QString &errorMessage)
147 qDebug() << __PRETTY_FUNCTION__;
149 Q_UNUSED(errorMessage);
151 emit m_parent->error(SituareError::GPS_INITIALIZATION_FAILED);
154 void GPSPositionPrivate::setUpdateInterval(int interval)
156 qDebug() << __PRETTY_FUNCTION__;
158 if (m_updateInterval != interval) {
159 m_updateInterval = interval;
160 m_liblocationWrapper->init(m_updateInterval);
164 qreal GPSPositionPrivate::accuracy(const GeoPositionInfo &positionInfo)
166 qDebug() << __PRETTY_FUNCTION__;
168 if (positionInfo.isAccurate())
169 return positionInfo.accuracy();
171 return GPS_ACCURACY_UNDEFINED;