1 /****************************************************************************
3 ** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
4 ** All rights reserved.
5 ** Contact: Nokia Corporation (qt-info@nokia.com)
7 ** This file is part of the Qt Mobility Components.
9 ** $QT_BEGIN_LICENSE:LGPL$
10 ** GNU Lesser General Public License Usage
11 ** This file may be used under the terms of the GNU Lesser General Public
12 ** License version 2.1 as published by the Free Software Foundation and
13 ** appearing in the file LICENSE.LGPL included in the packaging of this
14 ** file. Please review the following information to ensure the GNU Lesser
15 ** General Public License version 2.1 requirements will be met:
16 ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
18 ** In addition, as a special exception, Nokia gives you certain additional
19 ** rights. These rights are described in the Nokia Qt LGPL Exception
20 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
22 ** GNU General Public License Usage
23 ** Alternatively, this file may be used under the terms of the GNU General
24 ** Public License version 3.0 as published by the Free Software Foundation
25 ** and appearing in the file LICENSE.GPL included in the packaging of this
26 ** file. Please review the following information to ensure the GNU General
27 ** Public License version 3.0 requirements will be met:
28 ** http://www.gnu.org/copyleft/gpl.html.
31 ** Alternatively, this file may be used in accordance with the terms and
32 ** conditions contained in a signed written agreement between you and Nokia.
40 ****************************************************************************/
42 #include "qgeosatelliteinfosource_maemo5_p.h"
43 #include "liblocationwrapper_p.h"
47 QGeoSatelliteInfoSourceMaemo::QGeoSatelliteInfoSourceMaemo(QObject *parent)
48 : QGeoSatelliteInfoSource(parent)
50 qDebug() << "* QGeoSatelliteInfoSourceMaemo Fremantle Backport";
52 timerInterval = DEFAULT_UPDATE_INTERVAL;
53 updateTimer = new QTimer(this);
54 updateTimer->setSingleShot(true);
55 connect(updateTimer, SIGNAL(timeout()), this, SLOT(satelliteStatus()));
57 requestTimer = new QTimer(this);
58 requestTimer->setSingleShot(true);
59 connect(requestTimer, SIGNAL(timeout()), this, SLOT(requestTimeoutElapsed()));
61 satelliteInfoState = QGeoSatelliteInfoSourceMaemo::Undefined;
64 int QGeoSatelliteInfoSourceMaemo::init()
66 if (LiblocationWrapper::instance()->inited())
72 void QGeoSatelliteInfoSourceMaemo::setUpdateInterval(int msec)
74 bool updateTimerInterval = false;
76 if (satelliteInfoState & QGeoSatelliteInfoSourceMaemo::PowersaveActive)
77 if (satelliteInfoState & QGeoSatelliteInfoSourceMaemo::Stopped)
78 updateTimerInterval = true;
80 timerInterval = (msec < MINIMUM_UPDATE_INTERVAL) ? MINIMUM_UPDATE_INTERVAL : msec;
82 if (timerInterval >= POWERSAVE_THRESHOLD)
83 satelliteInfoState |= QGeoSatelliteInfoSourceMaemo::PowersaveActive;
85 satelliteInfoState &= ~QGeoSatelliteInfoSourceMaemo::PowersaveActive;
87 // If powersave has been active when new update interval has been set,
88 // ensure that timer is started.
89 if (updateTimerInterval)
90 startLocationDaemon();
92 // Ensure that new timer interval is taken into use immediately.
96 void QGeoSatelliteInfoSourceMaemo::startUpdates()
98 startLocationDaemon();
100 // Ensure that powersave is selected, if stopUpdates() has been called,
101 // but selected update interval is still greater than POWERSAVE_THRESHOLD.
102 if (timerInterval >= POWERSAVE_THRESHOLD)
103 satelliteInfoState |= QGeoSatelliteInfoSourceMaemo::PowersaveActive;
108 void QGeoSatelliteInfoSourceMaemo::stopUpdates()
110 satelliteInfoState &= ~QGeoSatelliteInfoSourceMaemo::PowersaveActive;
112 if (!(satelliteInfoState & QGeoSatelliteInfoSourceMaemo::RequestActive)) {
114 if (LiblocationWrapper::instance()->isActive())
115 LiblocationWrapper::instance()->stop();
118 satelliteInfoState &= ~QGeoSatelliteInfoSourceMaemo::Started;
119 satelliteInfoState |= QGeoSatelliteInfoSourceMaemo::Stopped;
122 void QGeoSatelliteInfoSourceMaemo::requestUpdate(int timeout)
124 int timeoutForRequest = 0;
127 if (LiblocationWrapper::instance()->isActive())
128 // If GPS is active, assume quick fix.
129 timeoutForRequest = DEFAULT_UPDATE_INTERVAL;
131 // Otherwise reserve longer time to get a fix.
132 timeoutForRequest = POWERSAVE_POWERON_PERIOD;
133 } else if (timeout < MINIMUM_UPDATE_INTERVAL) {
134 if (satelliteInfoState & QGeoSatelliteInfoSourceMaemo::RequestActive)
137 emit requestTimeout();
140 timeoutForRequest = timeout;
143 satelliteInfoState |= QGeoSatelliteInfoSourceMaemo::RequestActive;
145 if (!(LiblocationWrapper::instance()->isActive()))
146 LiblocationWrapper::instance()->start();
149 requestTimer->start(timeoutForRequest);
152 void QGeoSatelliteInfoSourceMaemo::satelliteStatus()
154 QList<QGeoSatelliteInfo> satellitesInView =
155 LiblocationWrapper::instance()->satellitesInView();
156 QList<QGeoSatelliteInfo> satellitesInUse =
157 LiblocationWrapper::instance()->satellitesInUse();
159 if (satelliteInfoState & QGeoSatelliteInfoSourceMaemo::RequestActive) {
160 satelliteInfoState &= ~QGeoSatelliteInfoSourceMaemo::RequestActive;
162 requestTimer->stop();
164 if (satelliteInfoState & QGeoSatelliteInfoSourceMaemo::Stopped) {
165 if (LiblocationWrapper::instance()->isActive()) {
166 LiblocationWrapper::instance()->stop();
170 // Ensure that requested satellite info is emitted even though
171 // powersave is active and GPS would normally be off.
172 if ((satelliteInfoState & QGeoSatelliteInfoSourceMaemo::PowersaveActive) &&
173 (satelliteInfoState & QGeoSatelliteInfoSourceMaemo::Stopped)) {
174 if (satellitesInView.length()) {
175 emit satellitesInViewUpdated(satellitesInView);
176 emit satellitesInUseUpdated(satellitesInUse);
181 // Make sure that if update is triggered when waking up, there
182 // is no false position update.
183 if (!((satelliteInfoState & QGeoSatelliteInfoSourceMaemo::PowersaveActive) &&
184 (satelliteInfoState & QGeoSatelliteInfoSourceMaemo::Stopped))) {
185 if (satellitesInView.length()) {
186 emit satellitesInViewUpdated(satellitesInView);
187 emit satellitesInUseUpdated(satellitesInUse);
194 void QGeoSatelliteInfoSourceMaemo::requestTimeoutElapsed()
197 emit requestTimeout();
199 satelliteInfoState &= ~QGeoSatelliteInfoSourceMaemo::RequestActive;
201 if (satelliteInfoState & QGeoSatelliteInfoSourceMaemo::Stopped)
202 if (LiblocationWrapper::instance()->isActive())
203 LiblocationWrapper::instance()->stop();
208 void QGeoSatelliteInfoSourceMaemo::activateTimer()
210 if (satelliteInfoState & QGeoSatelliteInfoSourceMaemo::RequestActive) {
211 updateTimer->start(MINIMUM_UPDATE_INTERVAL);
215 if (satelliteInfoState & QGeoSatelliteInfoSourceMaemo::PowersaveActive) {
216 if (satelliteInfoState & QGeoSatelliteInfoSourceMaemo::Started) {
217 // Cannot call stopUpdates() here since we want to keep powersave
219 if (LiblocationWrapper::instance()->isActive())
220 LiblocationWrapper::instance()->stop();
221 updateTimer->start(timerInterval - POWERSAVE_POWERON_PERIOD);
223 satelliteInfoState &= ~QGeoSatelliteInfoSourceMaemo::Started;
224 satelliteInfoState |= QGeoSatelliteInfoSourceMaemo::Stopped;
225 } else if (satelliteInfoState & QGeoSatelliteInfoSourceMaemo::Stopped) {
226 startLocationDaemon();
227 updateTimer->start(POWERSAVE_POWERON_PERIOD);
232 if (satelliteInfoState & QGeoSatelliteInfoSourceMaemo::Started)
233 updateTimer->start(timerInterval);
236 void QGeoSatelliteInfoSourceMaemo::startLocationDaemon()
238 if (!(LiblocationWrapper::instance()->isActive()))
239 LiblocationWrapper::instance()->start();
240 satelliteInfoState |= QGeoSatelliteInfoSourceMaemo::Started;
241 satelliteInfoState &= ~QGeoSatelliteInfoSourceMaemo::Stopped;
244 #include "moc_qgeosatelliteinfosource_maemo5_p.cpp"