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 // close the location utility session |
|
78 mLocationTrail.Close(); |
|
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 mLocationTrail.Close(); |
|
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 */ |
|
129 void CxeGeoTaggingTrailPrivate::stop() |
|
130 { |
|
131 CX_DEBUG_ENTER_FUNCTION(); |
|
132 |
|
133 bool ok2StopTrail = canStopTrail(); |
|
134 |
|
135 if (ok2StopTrail) { |
|
136 |
|
137 if (state() == CxeGeoTaggingTrail::TrailStarted || |
|
138 state() == CxeGeoTaggingTrail::DataAvailable) { |
|
139 CX_DEBUG(("CxeGeoTaggingTrailPrivate::StopLocationTrail")); |
|
140 // stop location trail timer. |
|
141 mStopLocationTrailTimer.stop(); |
|
142 mLocationTrail.StopLocationTrail(); |
|
143 setState(CxeGeoTaggingTrail::Connected); |
|
144 } |
|
145 |
|
146 } else { |
|
147 // not ready to stop the location trail, TrailStarted the timer. |
|
148 mStopLocationTrailTimer.start(STOP_TRAIL_INTERVAL); |
|
149 } |
|
150 |
|
151 CX_DEBUG_EXIT_FUNCTION(); |
|
152 } |
|
153 |
|
154 /*! |
|
155 * Checking possible stillcapturecontrol/videocapturecontrol states for stopping |
|
156 * location trail. |
|
157 */ |
|
158 bool CxeGeoTaggingTrailPrivate::canStopTrail() const |
|
159 { |
|
160 // checking still capture control states |
|
161 bool ok = mStillCaptureControl.state() != CxeStillCaptureControl::Capturing; |
|
162 |
|
163 // Still side OK, checking video capture control states |
|
164 if (ok) { |
|
165 ok = (mVideoCaptureControl.state() != CxeVideoCaptureControl::Recording && |
|
166 mVideoCaptureControl.state() != CxeVideoCaptureControl::Paused && |
|
167 mVideoCaptureControl.state() != CxeVideoCaptureControl::Stopping); |
|
168 } |
|
169 |
|
170 return ok; |
|
171 } |
|
172 |
|
173 /*! |
|
174 * Slot that is called when timer timeout signal is triggered. We track this to do pending |
|
175 * stopping of location trail. |
|
176 */ |
|
177 void CxeGeoTaggingTrailPrivate::timeout() |
|
178 { |
|
179 CX_DEBUG_ENTER_FUNCTION(); |
|
180 |
|
181 // stop the pending location trail utility |
|
182 stop(); |
|
183 |
|
184 CX_DEBUG_EXIT_FUNCTION(); |
|
185 } |
|
186 |
|
187 /*! |
|
188 * Handle new setting value. |
|
189 * Check if the geotagging setting has changed. |
|
190 */ |
|
191 void CxeGeoTaggingTrailPrivate::handleSettingValueChanged(const QString& settingId, QVariant newValue) |
|
192 { |
|
193 CX_DEBUG_ENTER_FUNCTION(); |
|
194 |
|
195 if (settingId == CxeSettingIds::GEOTAGGING) { |
|
196 if (newValue.toInt() == Cxe::GeoTaggingOn) { |
|
197 // setting is turned ON, start location trail |
|
198 start(); |
|
199 } else { |
|
200 // setting is turned OFF, stopping location trail |
|
201 stop(); |
|
202 } |
|
203 } else if (settingId == CxeSettingIds::GEOTAGGING_DISCLAIMER) { |
|
204 if (newValue.toInt() == Cxe::GeoTaggingDisclaimerDisabled) { |
|
205 // geotagging disclaimer is diabled, we can start location trail. |
|
206 start(); |
|
207 } |
|
208 } |
|
209 |
|
210 CX_DEBUG_EXIT_FUNCTION(); |
|
211 } |
|
212 |
|
213 /*! |
|
214 * Handle new setting value. |
|
215 * Check if the geotagging setting has changed. |
|
216 */ |
|
217 void CxeGeoTaggingTrailPrivate::handleGeoTaggingPropertyEvent(long int uid, |
|
218 unsigned long int key, |
|
219 QVariant value) |
|
220 { |
|
221 CX_DEBUG_ENTER_FUNCTION(); |
|
222 bool stateOk = (state() == CxeGeoTaggingTrail::DataAvailable || state() == CxeGeoTaggingTrail::TrailStarted); |
|
223 if (uid == KPSUidLocationTrail.iUid && key == KLocationTrailState && stateOk) { |
|
224 CX_DEBUG(("Location trail: new state = %d ", value.toInt())); |
|
225 |
|
226 RLocationTrail::TTrailState newState = |
|
227 static_cast<RLocationTrail::TTrailState>(value.toInt()); |
|
228 |
|
229 if (newState == RLocationTrail::ETrailStarted) { |
|
230 CX_DEBUG(("CxeGeoTaggingTrail <> location trail started, data available.")); |
|
231 setState(CxeGeoTaggingTrail::DataAvailable); |
|
232 } else { |
|
233 // ignoring all other state changes. |
|
234 } |
|
235 } |
|
236 |
|
237 CX_DEBUG_EXIT_FUNCTION(); |
|
238 } |
|
239 |
|
240 /*! |
|
241 Returns current state of Location trail |
|
242 */ |
|
243 CxeGeoTaggingTrail::State CxeGeoTaggingTrailPrivate::state() const |
|
244 { |
|
245 return static_cast<CxeGeoTaggingTrail::State> (stateId()); |
|
246 } |
|
247 |
|
248 /*! |
|
249 * slot called when state is changed. |
|
250 */ |
|
251 void CxeGeoTaggingTrailPrivate::handleStateChanged(int newStateId, CxeError::Id error) |
|
252 { |
|
253 emit stateChanged(static_cast<CxeGeoTaggingTrail::State> (newStateId), error); |
|
254 |
|
255 } |
|
256 |
|
257 /*! |
|
258 * Initialize states for geotaggingtrail |
|
259 */ |
|
260 void CxeGeoTaggingTrailPrivate::initializeStates() |
|
261 { |
|
262 // addState( id, name, allowed next states ) |
|
263 addState(new CxeState(CxeGeoTaggingTrail::NotConnected, "NotConnected", CxeGeoTaggingTrail::Connected)); |
|
264 |
|
265 addState(new CxeState(CxeGeoTaggingTrail::Connected, "Connected", CxeGeoTaggingTrail::TrailStarted | |
|
266 CxeGeoTaggingTrail::NotConnected)); |
|
267 |
|
268 addState(new CxeState(CxeGeoTaggingTrail::TrailStarted, "TrailStarted", CxeGeoTaggingTrail::DataAvailable | |
|
269 CxeGeoTaggingTrail::Connected | |
|
270 CxeGeoTaggingTrail::NotConnected)); |
|
271 |
|
272 addState(new CxeState(CxeGeoTaggingTrail::DataAvailable, "DataAvailable", CxeGeoTaggingTrail::Connected | |
|
273 CxeGeoTaggingTrail::NotConnected)); |
|
274 |
|
275 |
|
276 setInitialState(CxeGeoTaggingTrail::NotConnected); |
|
277 } |
|
278 |
|
279 // end of file |
|