39 ** |
39 ** |
40 ****************************************************************************/ |
40 ****************************************************************************/ |
41 |
41 |
42 #include "qgeopositioninfosource_maemo_p.h" |
42 #include "qgeopositioninfosource_maemo_p.h" |
43 #include <iostream> |
43 #include <iostream> |
44 |
44 #include <QDateTime> |
45 #if 0 |
|
46 void dumpQByteArray(const QByteArray &msg) |
|
47 { |
|
48 std::cout << "QByteArray dump:\n"; |
|
49 std::cout << msg.size() << " \n"; |
|
50 int i = msg.size(); |
|
51 for (int k = 0; k < i ;k++) |
|
52 printf("msg[%d]=%2.2x\n", k, (unsigned char)msg[k]); |
|
53 } |
|
54 #endif |
|
55 |
45 |
56 using namespace std; |
46 using namespace std; |
57 |
47 |
58 QTM_BEGIN_NAMESPACE |
48 QTM_BEGIN_NAMESPACE |
59 |
49 |
60 QGeoPositionInfoSourceMaemo::QGeoPositionInfoSourceMaemo(QObject *parent): QGeoPositionInfoSource(parent) |
50 QGeoPositionInfoSourceMaemo::QGeoPositionInfoSourceMaemo(QObject *parent): QGeoPositionInfoSource(parent) |
61 { |
51 { |
62 // default values |
52 time_interval_ = DefaultUpdateInterval; |
63 time_interval_ = 5000; |
|
64 distance_interval_ = 10; |
|
65 registered_ = false; |
|
66 validLastUpdate = false; |
|
67 validLastSatUpdate = false; |
|
68 availableMethods = AllPositioningMethods; |
53 availableMethods = AllPositioningMethods; |
69 } |
54 } |
|
55 |
70 |
56 |
71 int QGeoPositionInfoSourceMaemo::init() |
57 int QGeoPositionInfoSourceMaemo::init() |
72 { |
58 { |
73 int status; |
59 int status; |
74 |
|
75 dbusComm = new DBusComm(); |
60 dbusComm = new DBusComm(); |
76 status = dbusComm->init(); |
61 if ((status = dbusComm->init()) == 0) { |
77 |
62 QObject::connect(dbusComm, SIGNAL(receivedPositionUpdate(const QGeoPositionInfo &)), |
78 QObject::connect(dbusComm, SIGNAL(receivedMessage(const QByteArray &)), |
63 this, SLOT(newPositionUpdate(const QGeoPositionInfo &))); |
79 this, SLOT(dbusMessages(const QByteArray &))); |
64 } |
80 |
|
81 QObject::connect(dbusComm, SIGNAL(receivedPositionUpdate(const QGeoPositionInfo &)), |
|
82 this, SLOT(newPositionUpdate(const QGeoPositionInfo &))); |
|
83 |
|
84 return status; |
65 return status; |
85 } |
|
86 |
|
87 |
|
88 void QGeoPositionInfoSourceMaemo::dbusMessages(const QByteArray &msg) |
|
89 { |
|
90 Q_UNUSED(msg) |
|
91 // stub |
|
92 |
|
93 return; |
|
94 } |
66 } |
95 |
67 |
96 |
68 |
97 void QGeoPositionInfoSourceMaemo::newPositionUpdate(const QGeoPositionInfo &update) |
69 void QGeoPositionInfoSourceMaemo::newPositionUpdate(const QGeoPositionInfo &update) |
98 { |
70 { |
99 lastSatUpdate = update; |
|
100 validLastSatUpdate = true; |
|
101 emit positionUpdated(update); |
71 emit positionUpdated(update); |
102 } |
72 } |
103 |
73 |
104 |
74 |
105 QGeoPositionInfo QGeoPositionInfoSourceMaemo::lastKnownPosition(bool fromSatellitePositioningMethodsOnly) const |
75 QGeoPositionInfo QGeoPositionInfoSourceMaemo::lastKnownPosition(bool fromSatellitePositioningMethodsOnly) const |
106 { |
76 { |
107 if (validLastSatUpdate) |
77 static QGeoPositionInfo lastUpdate; |
108 return lastSatUpdate; |
78 lastUpdate = dbusComm->requestLastKnownPosition(fromSatellitePositioningMethodsOnly); |
109 |
79 |
110 if (!fromSatellitePositioningMethodsOnly) |
80 return lastUpdate; |
111 if (validLastUpdate) |
|
112 return lastUpdate; |
|
113 |
|
114 return QGeoPositionInfo(); |
|
115 } |
81 } |
116 |
82 |
117 |
83 |
118 QGeoPositionInfoSource::PositioningMethods QGeoPositionInfoSourceMaemo::supportedPositioningMethods() const |
84 QGeoPositionInfoSource::PositioningMethods QGeoPositionInfoSourceMaemo::supportedPositioningMethods() const |
119 { |
85 { |
122 |
88 |
123 |
89 |
124 void QGeoPositionInfoSourceMaemo::setUpdateInterval(int msec) |
90 void QGeoPositionInfoSourceMaemo::setUpdateInterval(int msec) |
125 { |
91 { |
126 msec = (msec < MinimumUpdateInterval) ? MinimumUpdateInterval : msec; |
92 msec = (msec < MinimumUpdateInterval) ? MinimumUpdateInterval : msec; |
|
93 QGeoPositionInfoSource::setUpdateInterval(msec); |
127 |
94 |
128 QGeoPositionInfoSource::setUpdateInterval(msec); |
95 dbusComm->sendConfigRequest(dbusComm->CommandSetInterval, 0, msec); |
129 if (registered_ == false) |
|
130 registered_ = dbusComm->sendDBusRegister(); |
|
131 dbusComm->sessionConfigRequest(dbusComm->CmdSetInterval, 0, msec); |
|
132 } |
96 } |
|
97 |
133 |
98 |
134 void QGeoPositionInfoSourceMaemo::setPreferredPositioningMethods(PositioningMethods sources) |
99 void QGeoPositionInfoSourceMaemo::setPreferredPositioningMethods(PositioningMethods sources) |
135 { |
100 { |
136 QGeoPositionInfoSource::setPreferredPositioningMethods(sources); |
101 QGeoPositionInfoSource::setPreferredPositioningMethods(sources); |
137 if (registered_ == false) |
102 dbusComm->sendConfigRequest(dbusComm->CommandSetMethods, sources, 0); |
138 registered_ = dbusComm->sendDBusRegister(); |
|
139 dbusComm->sessionConfigRequest(dbusComm->CmdSetMethods, sources, 0); |
|
140 } |
103 } |
141 |
104 |
142 |
105 |
143 int QGeoPositionInfoSourceMaemo::minimumUpdateInterval() const |
106 int QGeoPositionInfoSourceMaemo::minimumUpdateInterval() const |
144 { |
107 { |
145 return MinimumUpdateInterval; |
108 return MinimumUpdateInterval; |
146 } |
109 } |
147 |
110 |
148 |
111 |
149 // public slots: |
|
150 |
|
151 void QGeoPositionInfoSourceMaemo::startUpdates() |
112 void QGeoPositionInfoSourceMaemo::startUpdates() |
152 { |
113 { |
153 if (registered_ == false) |
114 dbusComm->sendConfigRequest(DBusComm::CommandStart, 0, time_interval_); |
154 registered_ = dbusComm->sendDBusRegister(); |
|
155 |
|
156 int cmd = dbusComm->CmdStart; |
|
157 dbusComm->sessionConfigRequest(cmd, 222, time_interval_); |
|
158 } |
115 } |
159 |
116 |
160 |
117 |
161 void QGeoPositionInfoSourceMaemo::stopUpdates() |
118 void QGeoPositionInfoSourceMaemo::stopUpdates() |
162 { |
119 { |
163 if (registered_ == false) return; // nothing to stop |
120 dbusComm->sendConfigRequest(dbusComm->CommandStop, 0, 0); |
164 dbusComm->sessionConfigRequest(dbusComm->CmdStop, 0, 0); |
|
165 } |
121 } |
166 |
122 |
167 // Stub |
|
168 |
123 |
169 void QGeoPositionInfoSourceMaemo::requestUpdate(int timeout) |
124 void QGeoPositionInfoSourceMaemo::requestUpdate(int timeout) |
170 { |
125 { |
171 if (timeout) {} |
126 dbusComm->sendConfigRequest(dbusComm->CommandOneShot, 0, timeout); |
172 } |
127 } |
173 |
128 |
174 #include "moc_qgeopositioninfosource_maemo_p.cpp" |
129 #include "moc_qgeopositioninfosource_maemo_p.cpp" |
175 QTM_END_NAMESPACE |
130 QTM_END_NAMESPACE |
176 |
131 |