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