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