|
1 /* |
|
2 * Copyright (c) 2009-2010 Nokia Corporation and/or its subsidiary(-ies). |
|
3 * All rights reserved. |
|
4 * This component and the accompanying materials are made available |
|
5 * under the terms of "Eclipse Public License v1.0" |
|
6 * which accompanies this distribution, and is available |
|
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 * |
|
9 * Initial Contributors: |
|
10 * Nokia Corporation - initial contribution. |
|
11 * |
|
12 * Contributors: |
|
13 * |
|
14 * Description: |
|
15 * |
|
16 */ |
|
17 |
|
18 #include <QObject> // For Q_OS_SYMBIAN define |
|
19 #if defined(Q_OS_SYMBIAN) |
|
20 #include <locationtrailpskeys.h> |
|
21 #endif |
|
22 |
|
23 #include "cxutils.h" |
|
24 #include "cxestate.h" |
|
25 #include "cxesettings.h" |
|
26 #include "cxenamespace.h" |
|
27 #include "cxestillcapturecontrol.h" |
|
28 #include "cxevideocapturecontrol.h" |
|
29 #include "cxegeotaggingtrailprivate.h" |
|
30 |
|
31 #include "OstTraceDefinitions.h" |
|
32 #ifdef OST_TRACE_COMPILER_IN_USE |
|
33 #include "cxegeotaggingtrailprivateTraces.h" |
|
34 #endif |
|
35 |
|
36 |
|
37 namespace |
|
38 { |
|
39 // in milliseconds |
|
40 const int STOP_TRAIL_INTERVAL = 10*1000; |
|
41 } |
|
42 |
|
43 |
|
44 /*! |
|
45 * Constructor |
|
46 */ |
|
47 CxeGeoTaggingTrailPrivate::CxeGeoTaggingTrailPrivate(CxeStillCaptureControl &stillControl, |
|
48 CxeVideoCaptureControl &videoControl, |
|
49 CxeSettings &settings) |
|
50 : CxeStateMachine("CxeGeoTaggingTrailPrivate"), |
|
51 mStillCaptureControl(stillControl), |
|
52 mVideoCaptureControl(videoControl), |
|
53 mSettings(settings), |
|
54 mStopLocationTrailTimer(), |
|
55 mPendingStopTrailSession(false) |
|
56 { |
|
57 CX_DEBUG_ENTER_FUNCTION(); |
|
58 |
|
59 qRegisterMetaType<CxeGeoTaggingTrail::State>(); |
|
60 initializeStates(); |
|
61 |
|
62 #if defined(Q_OS_SYMBIAN) |
|
63 |
|
64 QVariant locationTrailState; |
|
65 // Get initial location trail state. |
|
66 mSettings.get(KPSUidLocationTrail.iUid, KLocationTrailState, |
|
67 Cxe::PublishAndSubscribe, locationTrailState); |
|
68 |
|
69 connect(&mSettings, SIGNAL(settingValueChanged(long int, unsigned long int, QVariant)), |
|
70 this, SLOT(handleGeoTaggingPropertyEvent(long int, unsigned long int, QVariant))); |
|
71 |
|
72 #endif |
|
73 |
|
74 connect(&mSettings, SIGNAL(settingValueChanged(const QString&,QVariant)), |
|
75 this, SLOT(handleSettingValueChanged(const QString&,QVariant))); |
|
76 |
|
77 connect(&mStopLocationTrailTimer, SIGNAL(timeout()), |
|
78 this, SLOT(timeout()), Qt::UniqueConnection); |
|
79 |
|
80 CX_DEBUG_EXIT_FUNCTION(); |
|
81 } |
|
82 |
|
83 /*! |
|
84 * Destructor |
|
85 */ |
|
86 CxeGeoTaggingTrailPrivate::~CxeGeoTaggingTrailPrivate() |
|
87 { |
|
88 CX_DEBUG_ENTER_FUNCTION(); |
|
89 |
|
90 // stop trail and close location utility session |
|
91 stop(true); |
|
92 |
|
93 CX_DEBUG_EXIT_FUNCTION(); |
|
94 } |
|
95 |
|
96 |
|
97 /*! |
|
98 * Start location trail. |
|
99 */ |
|
100 void CxeGeoTaggingTrailPrivate::start() |
|
101 { |
|
102 CX_DEBUG_ENTER_FUNCTION(); |
|
103 OstTrace0(camerax_performance, CXEGEOTAGGINGTRAIL_START_1, "msg: e_CX_START_GEOTAGGING 1"); |
|
104 |
|
105 #if defined(Q_OS_SYMBIAN) |
|
106 |
|
107 int err = KErrNone; |
|
108 int settingValue = Cxe::GeoTaggingOff; |
|
109 mSettings.get(CxeSettingIds::GEOTAGGING, settingValue); |
|
110 |
|
111 if (settingValue == Cxe::GeoTaggingOn) { |
|
112 // geotagging setting is ON, trying to start location trail |
|
113 if (state() == CxeGeoTaggingTrail::NotConnected) { |
|
114 err = mLocationTrail.Connect(); |
|
115 if (!err) { |
|
116 CX_DEBUG(("CxeGeoTaggingTrail <> location trail connected")); |
|
117 setState(CxeGeoTaggingTrail::Connected); |
|
118 } |
|
119 } |
|
120 |
|
121 if (state() == CxeGeoTaggingTrail::Connected && !err) { |
|
122 err = mLocationTrail.StartLocationTrail(RLocationTrail::ECaptureAll); |
|
123 if (!err) { |
|
124 CX_DEBUG(("CxeGeoTaggingTrail <> starting location trail")); |
|
125 mStopLocationTrailTimer.stop(); // stop location timer. |
|
126 setState(CxeGeoTaggingTrail::TrailStarted); |
|
127 } |
|
128 } |
|
129 |
|
130 if (err) { |
|
131 CX_DEBUG(("CxeGeoTaggingTrailPrivate::start <> FAILED: error = %d ", err)); |
|
132 stop(true); |
|
133 } |
|
134 } else { |
|
135 // geotagging setting off, do nothing. |
|
136 CX_DEBUG(("CxeGeoTaggingTrail <> start -- Geotagging setting OFF, do nothing..")); |
|
137 } |
|
138 |
|
139 #endif |
|
140 OstTrace0(camerax_performance, CXEGEOTAGGINGTRAIL_START_2, "msg: e_CX_START_GEOTAGGING 0"); |
|
141 |
|
142 CX_DEBUG_EXIT_FUNCTION(); |
|
143 } |
|
144 |
|
145 |
|
146 |
|
147 |
|
148 /*! |
|
149 * Stop location trail. |
|
150 * @ param closeSession, indicates if we are willing to close the location utility session. |
|
151 */ |
|
152 void CxeGeoTaggingTrailPrivate::stop(bool closeSession) |
|
153 { |
|
154 CX_DEBUG_ENTER_FUNCTION(); |
|
155 OstTrace0(camerax_performance, CXEGEOTAGGINGTRAIL_STOP_1, "msg: e_CX_STOP_GEOTAGGING 1"); |
|
156 |
|
157 #if defined(Q_OS_SYMBIAN) |
|
158 |
|
159 bool ok2StopTrail = canStopTrail(); |
|
160 |
|
161 if (ok2StopTrail) { |
|
162 |
|
163 if (state() == CxeGeoTaggingTrail::TrailStarted || |
|
164 state() == CxeGeoTaggingTrail::DataAvailable) { |
|
165 CX_DEBUG(("CxeGeoTaggingTrailPrivate::StopLocationTrail")); |
|
166 // stop location trail timer. |
|
167 mStopLocationTrailTimer.stop(); |
|
168 mLocationTrail.StopLocationTrail(); |
|
169 setState(CxeGeoTaggingTrail::Connected); |
|
170 } |
|
171 |
|
172 if (closeSession && state() == CxeGeoTaggingTrail::Connected) { |
|
173 CX_DEBUG(("CxeGeoTaggingTrailPrivate <> disconnect location trail utility")); |
|
174 mLocationTrail.Close(); |
|
175 setState(CxeGeoTaggingTrail::NotConnected); |
|
176 } |
|
177 } else { |
|
178 // not ready to stop the location trail, TrailStarted the timer. |
|
179 if (!mPendingStopTrailSession) { |
|
180 mPendingStopTrailSession = closeSession; |
|
181 } |
|
182 mStopLocationTrailTimer.start(STOP_TRAIL_INTERVAL); |
|
183 } |
|
184 |
|
185 #endif |
|
186 |
|
187 OstTrace0(camerax_performance, CXEGEOTAGGINGTRAIL_STOP_2, "msg: e_CX_STOP_GEOTAGGING 0"); |
|
188 } |
|
189 |
|
190 |
|
191 |
|
192 /*! |
|
193 * Checking possible stillcapturecontrol/videocapturecontrol states for stopping |
|
194 * location trail. |
|
195 */ |
|
196 bool CxeGeoTaggingTrailPrivate::canStopTrail() const |
|
197 { |
|
198 // checking still capture control states |
|
199 bool ok = mStillCaptureControl.state() != CxeStillCaptureControl::Capturing; |
|
200 |
|
201 // Still side OK, checking video capture control states |
|
202 if (ok) { |
|
203 ok = (mVideoCaptureControl.state() != CxeVideoCaptureControl::Recording && |
|
204 mVideoCaptureControl.state() != CxeVideoCaptureControl::Paused && |
|
205 mVideoCaptureControl.state() != CxeVideoCaptureControl::Stopping); |
|
206 } |
|
207 |
|
208 return ok; |
|
209 } |
|
210 |
|
211 |
|
212 |
|
213 /*! |
|
214 * Slot that is called when timer timeout signal is triggered. We track this to do pending |
|
215 * stopping of location trail. |
|
216 */ |
|
217 void CxeGeoTaggingTrailPrivate::timeout() |
|
218 { |
|
219 CX_DEBUG_ENTER_FUNCTION(); |
|
220 |
|
221 // stop the pending location trail utility |
|
222 stop(mPendingStopTrailSession); |
|
223 |
|
224 CX_DEBUG_EXIT_FUNCTION(); |
|
225 } |
|
226 |
|
227 |
|
228 |
|
229 |
|
230 /*! |
|
231 * Handle new setting value. |
|
232 * Check if the geotagging setting has changed. |
|
233 */ |
|
234 void CxeGeoTaggingTrailPrivate::handleSettingValueChanged(const QString& settingId, QVariant newValue) |
|
235 { |
|
236 CX_DEBUG_ENTER_FUNCTION(); |
|
237 |
|
238 if (settingId == CxeSettingIds::GEOTAGGING) { |
|
239 if (newValue.toInt() == Cxe::GeoTaggingOn) { |
|
240 // setting is turned ON, start location trail |
|
241 start(); |
|
242 } else { |
|
243 // setting is turned OFF, stopping location trail |
|
244 stop(); |
|
245 } |
|
246 } else if (settingId == CxeSettingIds::GEOTAGGING_DISCLAIMER) { |
|
247 if (newValue.toInt() == Cxe::GeoTaggingDisclaimerDisabled) { |
|
248 // geotagging disclaimer is diabled, we can start location trail. |
|
249 start(); |
|
250 } |
|
251 } |
|
252 |
|
253 CX_DEBUG_EXIT_FUNCTION(); |
|
254 } |
|
255 |
|
256 |
|
257 /*! |
|
258 * Handle new setting value. |
|
259 * Check if the geotagging setting has changed. |
|
260 */ |
|
261 void CxeGeoTaggingTrailPrivate::handleGeoTaggingPropertyEvent(long int uid, |
|
262 unsigned long int key, |
|
263 QVariant value) |
|
264 { |
|
265 CX_DEBUG_ENTER_FUNCTION(); |
|
266 |
|
267 #if defined(Q_OS_SYMBIAN) |
|
268 |
|
269 if (uid == KPSUidLocationTrail.iUid && key == KLocationTrailState) { |
|
270 CX_DEBUG(("Location trail: new state = %d ", value.toInt())); |
|
271 |
|
272 RLocationTrail::TTrailState newState = |
|
273 static_cast<RLocationTrail::TTrailState>(value.toInt()); |
|
274 |
|
275 if (newState == RLocationTrail::ETrailStarted) { |
|
276 CX_DEBUG(("CxeGeoTaggingTrail <> location trail started, data available.")); |
|
277 setState(CxeGeoTaggingTrail::DataAvailable); |
|
278 } else { |
|
279 // ignoring all other state changes. |
|
280 } |
|
281 } |
|
282 |
|
283 #endif |
|
284 |
|
285 CX_DEBUG_EXIT_FUNCTION(); |
|
286 } |
|
287 |
|
288 |
|
289 |
|
290 /*! |
|
291 Returns current state of Location trail |
|
292 */ |
|
293 CxeGeoTaggingTrail::State CxeGeoTaggingTrailPrivate::state() const |
|
294 { |
|
295 return static_cast<CxeGeoTaggingTrail::State> (stateId()); |
|
296 } |
|
297 |
|
298 |
|
299 |
|
300 /*! |
|
301 * slot called when state is changed. |
|
302 */ |
|
303 void CxeGeoTaggingTrailPrivate::handleStateChanged(int newStateId, CxeError::Id error) |
|
304 { |
|
305 emit stateChanged(static_cast<CxeGeoTaggingTrail::State> (newStateId), error); |
|
306 |
|
307 } |
|
308 |
|
309 |
|
310 /*! |
|
311 * Initialize states for geotaggingtrail |
|
312 */ |
|
313 void CxeGeoTaggingTrailPrivate::initializeStates() |
|
314 { |
|
315 // addState( id, name, allowed next states ) |
|
316 addState(new CxeState(CxeGeoTaggingTrail::NotConnected, "NotConnected", CxeGeoTaggingTrail::Connected)); |
|
317 |
|
318 addState(new CxeState(CxeGeoTaggingTrail::Connected, "Connected", CxeGeoTaggingTrail::TrailStarted | |
|
319 CxeGeoTaggingTrail::NotConnected)); |
|
320 |
|
321 addState(new CxeState(CxeGeoTaggingTrail::TrailStarted, "TrailStarted", CxeGeoTaggingTrail::DataAvailable | |
|
322 CxeGeoTaggingTrail::Connected | |
|
323 CxeGeoTaggingTrail::NotConnected)); |
|
324 |
|
325 addState(new CxeState(CxeGeoTaggingTrail::DataAvailable, "DataAvailable", CxeGeoTaggingTrail::Connected | |
|
326 CxeGeoTaggingTrail::NotConnected)); |
|
327 |
|
328 |
|
329 setInitialState(CxeGeoTaggingTrail::NotConnected); |
|
330 } |
|
331 |
|
332 // end of file |