|
1 /**************************************************************************** |
|
2 ** |
|
3 ** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). |
|
4 ** All rights reserved. |
|
5 ** Contact: Nokia Corporation (qt-info@nokia.com) |
|
6 ** |
|
7 ** This file is part of the Qt Mobility Components. |
|
8 ** |
|
9 ** $QT_BEGIN_LICENSE:LGPL$ |
|
10 ** No Commercial Usage |
|
11 ** This file contains pre-release code and may not be distributed. |
|
12 ** You may use this file in accordance with the terms and conditions |
|
13 ** contained in the Technology Preview License Agreement accompanying |
|
14 ** this package. |
|
15 ** |
|
16 ** GNU Lesser General Public License Usage |
|
17 ** Alternatively, this file may be used under the terms of the GNU Lesser |
|
18 ** General Public License version 2.1 as published by the Free Software |
|
19 ** Foundation and appearing in the file LICENSE.LGPL included in the |
|
20 ** packaging of this file. Please review the following information to |
|
21 ** ensure the GNU Lesser General Public License version 2.1 requirements |
|
22 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. |
|
23 ** |
|
24 ** In addition, as a special exception, Nokia gives you certain additional |
|
25 ** rights. These rights are described in the Nokia Qt LGPL Exception |
|
26 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. |
|
27 ** |
|
28 ** If you have questions regarding the use of this file, please contact |
|
29 ** Nokia at qt-info@nokia.com. |
|
30 ** |
|
31 ** |
|
32 ** |
|
33 ** |
|
34 ** |
|
35 ** |
|
36 ** |
|
37 ** |
|
38 ** $QT_END_LICENSE$ |
|
39 ** |
|
40 ****************************************************************************/ |
|
41 |
|
42 #include "qgeopositioninfosource_maemo_p.h" |
|
43 #include <iostream> |
|
44 #include <QDateTime> |
|
45 |
|
46 using namespace std; |
|
47 |
|
48 QTM_BEGIN_NAMESPACE |
|
49 |
|
50 QGeoPositionInfoSourceMaemo::QGeoPositionInfoSourceMaemo(QObject *parent): QGeoPositionInfoSource(parent) |
|
51 { |
|
52 requestTimer = new QTimer(this); |
|
53 QObject::connect(requestTimer, SIGNAL(timeout()), this, SLOT(requestTimerExpired())); |
|
54 locationOngoing = false; |
|
55 } |
|
56 |
|
57 |
|
58 int QGeoPositionInfoSourceMaemo::init() |
|
59 { |
|
60 dbusComm = new DBusComm(this); |
|
61 int status = dbusComm->init(); |
|
62 |
|
63 if (status == 0) { |
|
64 QObject::connect(dbusComm, SIGNAL(receivedPositionUpdate(const QGeoPositionInfo &)), |
|
65 this, SLOT(newPositionUpdate(const QGeoPositionInfo &))); |
|
66 QObject::connect(dbusComm, SIGNAL(serviceConnected()), |
|
67 this, SLOT(onServiceConnect())); |
|
68 QObject::connect(dbusComm, SIGNAL(serviceDisconnected()), |
|
69 this, SLOT(onServiceDisconnect())); |
|
70 } |
|
71 return status; |
|
72 } |
|
73 |
|
74 void QGeoPositionInfoSourceMaemo::onServiceDisconnect() |
|
75 { |
|
76 // |
|
77 } |
|
78 |
|
79 |
|
80 void QGeoPositionInfoSourceMaemo::onServiceConnect() |
|
81 { |
|
82 DBusComm::Command command = (DBusComm::Command)( int(DBusComm::CommandStart) |
|
83 | int(DBusComm::CommandSetInterval) |
|
84 | int(DBusComm::CommandSetMethods) ); |
|
85 int interval = QGeoPositionInfoSource::updateInterval(); |
|
86 QGeoPositionInfoSource::PositioningMethods method; |
|
87 method = QGeoPositionInfoSource::preferredPositioningMethods(); |
|
88 |
|
89 if (locationOngoing) { |
|
90 dbusComm->sendConfigRequest(command, method, interval); |
|
91 } |
|
92 } |
|
93 |
|
94 void QGeoPositionInfoSourceMaemo::newPositionUpdate(const QGeoPositionInfo &update) |
|
95 { |
|
96 if(update.isValid()) { |
|
97 emit positionUpdated(update); |
|
98 if ( requestTimer->isActive() ) |
|
99 shutdownRequestSession(); |
|
100 } else { |
|
101 if ( !requestTimer->isActive() ) |
|
102 emit updateTimeout(); |
|
103 } |
|
104 } |
|
105 |
|
106 |
|
107 QGeoPositionInfo QGeoPositionInfoSourceMaemo::lastKnownPosition(bool fromSatellitePositioningMethodsOnly) const |
|
108 { |
|
109 QGeoPositionInfo update = dbusComm->requestLastKnownPosition(fromSatellitePositioningMethodsOnly); |
|
110 |
|
111 return update; |
|
112 } |
|
113 |
|
114 |
|
115 QGeoPositionInfoSource::PositioningMethods QGeoPositionInfoSourceMaemo::supportedPositioningMethods() const |
|
116 { |
|
117 return dbusComm->availableMethods(); |
|
118 } |
|
119 |
|
120 |
|
121 void QGeoPositionInfoSourceMaemo::setUpdateInterval(int msec) |
|
122 { |
|
123 qint32 min = dbusComm->minimumInterval(); |
|
124 msec = (msec < min) ? min : msec; |
|
125 QGeoPositionInfoSource::setUpdateInterval(msec); |
|
126 |
|
127 dbusComm->sendConfigRequest(dbusComm->CommandSetInterval, 0, msec); |
|
128 } |
|
129 |
|
130 |
|
131 void QGeoPositionInfoSourceMaemo::setPreferredPositioningMethods(PositioningMethods sources) |
|
132 { |
|
133 QGeoPositionInfoSource::setPreferredPositioningMethods(sources); |
|
134 dbusComm->sendConfigRequest(dbusComm->CommandSetMethods, sources, 0); |
|
135 } |
|
136 |
|
137 |
|
138 int QGeoPositionInfoSourceMaemo::minimumUpdateInterval() const |
|
139 { |
|
140 return dbusComm->minimumInterval(); |
|
141 } |
|
142 |
|
143 |
|
144 void QGeoPositionInfoSourceMaemo::startUpdates() |
|
145 { |
|
146 locationOngoing = true; |
|
147 if ( !requestTimer->isActive() ) |
|
148 dbusComm->sendConfigRequest(DBusComm::CommandStart, 0, 0); |
|
149 } |
|
150 |
|
151 |
|
152 void QGeoPositionInfoSourceMaemo::stopUpdates() |
|
153 { |
|
154 locationOngoing = false; |
|
155 if ( !requestTimer->isActive() ) |
|
156 dbusComm->sendConfigRequest(dbusComm->CommandStop, 0, 0); |
|
157 } |
|
158 |
|
159 |
|
160 void QGeoPositionInfoSourceMaemo::requestUpdate(int timeout) |
|
161 { |
|
162 if ( QGeoPositionInfoSource::updateInterval() != |
|
163 dbusComm->minimumInterval() ) |
|
164 dbusComm->sendConfigRequest(dbusComm->CommandSetInterval, 0, |
|
165 dbusComm->minimumInterval()); |
|
166 |
|
167 if ( !QGeoPositionInfoSource::preferredPositioningMethods().testFlag(QGeoPositionInfoSource::AllPositioningMethods) ) |
|
168 dbusComm->sendConfigRequest(dbusComm->CommandSetMethods, |
|
169 QGeoPositionInfoSource::AllPositioningMethods, 0); |
|
170 |
|
171 if ( !locationOngoing ) |
|
172 dbusComm->sendConfigRequest(dbusComm->CommandStart, 0, 0); |
|
173 |
|
174 requestTimer->start(timeout); |
|
175 } |
|
176 |
|
177 void QGeoPositionInfoSourceMaemo::requestTimerExpired() |
|
178 { |
|
179 emit updateTimeout(); |
|
180 shutdownRequestSession(); |
|
181 } |
|
182 |
|
183 void QGeoPositionInfoSourceMaemo::shutdownRequestSession() |
|
184 { |
|
185 requestTimer->stop(); |
|
186 |
|
187 if ( !locationOngoing ) |
|
188 dbusComm->sendConfigRequest(dbusComm->CommandStop, 0, 0); |
|
189 |
|
190 if ( QGeoPositionInfoSource::updateInterval() != |
|
191 dbusComm->minimumInterval() ) |
|
192 dbusComm->sendConfigRequest(dbusComm->CommandSetInterval, 0, |
|
193 QGeoPositionInfoSource::updateInterval()); |
|
194 |
|
195 if ( !QGeoPositionInfoSource::preferredPositioningMethods().testFlag(QGeoPositionInfoSource::AllPositioningMethods) ) |
|
196 dbusComm->sendConfigRequest(dbusComm->CommandSetMethods, |
|
197 QGeoPositionInfoSource::preferredPositioningMethods(), 0); |
|
198 } |
|
199 |
|
200 #include "moc_qgeopositioninfosource_maemo_p.cpp" |
|
201 QTM_END_NAMESPACE |
|
202 |