|
1 /* |
|
2 * Copyright (c) 2009 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: A class responsible for geotagging of media files in background. |
|
15 * |
|
16 */ |
|
17 |
|
18 #include <e32cmn.h> |
|
19 #include <lbserrors.h> |
|
20 #include <lbssatellite.h> |
|
21 #include <ecom.h> |
|
22 |
|
23 #include "locationmanagerdebug.h" |
|
24 #include "mdeconstants.h" |
|
25 #include "mdesession.h" |
|
26 #include "cinternalgeotagger.h" |
|
27 #include "reversegeocoderplugin.h" |
|
28 |
|
29 using namespace MdeConstants; |
|
30 |
|
31 _LIT ( KCountry, "country:"); // country:india |
|
32 const TUid KReverseGeoCodeUid = {0x2002DD12}; |
|
33 |
|
34 // -------------------------------------------------------------------------- |
|
35 // CInternalGeoTagger::NewL |
|
36 // -------------------------------------------------------------------------- |
|
37 // |
|
38 EXPORT_C CInternalGeoTagger* CInternalGeoTagger::NewL( CMdESession* aMdeSession, |
|
39 MGeoTaggerObserver* aObserver ) |
|
40 { |
|
41 CInternalGeoTagger* self = |
|
42 new (ELeave) CInternalGeoTagger( aMdeSession, aObserver ); |
|
43 CleanupStack::PushL( self ); |
|
44 self->ConstructL(); |
|
45 CleanupStack::Pop( self ); |
|
46 return self; |
|
47 } |
|
48 |
|
49 // -------------------------------------------------------------------------- |
|
50 // CInternalGeoTagger::CInternalGeoTagger |
|
51 // -------------------------------------------------------------------------- |
|
52 // |
|
53 CInternalGeoTagger::CInternalGeoTagger( CMdESession* aMdeSession, |
|
54 MGeoTaggerObserver* aObserver ) |
|
55 : iMdeSession(aMdeSession), |
|
56 iLocationQuery(NULL), |
|
57 iRelationQuery(NULL), |
|
58 iTagQuery(NULL), |
|
59 iIndex(0), |
|
60 iSessionReady( EFalse ), |
|
61 iObserver( aObserver ), |
|
62 iTagCreator(NULL), |
|
63 iASW(NULL), |
|
64 iTagPendingHandlerFlag(EFalse), |
|
65 iRevGeocoderPlugin(NULL) |
|
66 #ifdef LOC_GEOTAGGING_CELLID |
|
67 ,iGeoConverter(NULL) |
|
68 #endif |
|
69 { |
|
70 iMdeSessionOwnFlag = (iMdeSession == NULL); |
|
71 } |
|
72 |
|
73 // -------------------------------------------------------------------------- |
|
74 // CInternalGeoTagger::ConstructL |
|
75 // -------------------------------------------------------------------------- |
|
76 // |
|
77 void CInternalGeoTagger::ConstructL() |
|
78 { |
|
79 LOG("CInternalGeoTagger::ConstructL ,begin"); |
|
80 if(iMdeSession != NULL) |
|
81 { |
|
82 LOG("Not owning mds session"); |
|
83 iMdeSessionOwnFlag = EFalse; |
|
84 //object is not owning iMdeSession |
|
85 iTagCreator = CTagCreator::NewL(); |
|
86 iSessionReady = ETrue; |
|
87 |
|
88 iTagCreator->SetSession( iMdeSession ); |
|
89 } |
|
90 else |
|
91 { |
|
92 iMdeSessionOwnFlag = ETrue; |
|
93 iASW = new (ELeave) CActiveSchedulerWait(); |
|
94 iMdeSession = CMdESession::NewL( *this ); |
|
95 //for creating tags |
|
96 iTagCreator = CTagCreator::NewL(); |
|
97 |
|
98 iASW->Start(); |
|
99 delete iASW; |
|
100 iASW = NULL; |
|
101 } |
|
102 |
|
103 //for reverse geocoding (geo-tagging) |
|
104 |
|
105 if (!iRevGeocoderPlugin) |
|
106 { |
|
107 |
|
108 TRAP_IGNORE( |
|
109 iRevGeocoderPlugin = reinterpret_cast<CReverseGeoCoderPlugin*>( |
|
110 REComSession::CreateImplementationL(KReverseGeoCodeUid, iDtorKey));) |
|
111 |
|
112 if(iRevGeocoderPlugin) |
|
113 { |
|
114 iRevGeocoderPlugin->AddObserverL(*this); |
|
115 |
|
116 } |
|
117 |
|
118 } |
|
119 |
|
120 LOG("CInternalGeoTagger::ConstructL ,end"); |
|
121 } |
|
122 |
|
123 // -------------------------------------------------------------------------- |
|
124 // CInternalGeoTagger::~CInternalGeoTagger |
|
125 // -------------------------------------------------------------------------- |
|
126 // |
|
127 CInternalGeoTagger::~CInternalGeoTagger() |
|
128 { |
|
129 LOG("CInternalGeoTagger::~CInternalGeoTagger ,begin"); |
|
130 #ifdef LOC_GEOTAGGING_CELLID |
|
131 if(iGeoConverter) |
|
132 { |
|
133 delete iGeoConverter; |
|
134 iGeoConverter = NULL; |
|
135 } |
|
136 #endif |
|
137 if(iRelationQuery) |
|
138 { |
|
139 iRelationQuery->RemoveObserver(*this); |
|
140 iRelationQuery->Cancel(); |
|
141 delete iRelationQuery; |
|
142 } |
|
143 if(iLocationQuery) |
|
144 { |
|
145 iLocationQuery->RemoveObserver(*this); |
|
146 iLocationQuery->Cancel(); |
|
147 delete iLocationQuery; |
|
148 } |
|
149 if(iTagQuery) |
|
150 { |
|
151 iTagQuery->RemoveObserver(*this); |
|
152 iTagQuery->Cancel(); |
|
153 delete iTagQuery; |
|
154 } |
|
155 delete iRevGeocoderPlugin; |
|
156 iRevGeocoderPlugin = NULL; |
|
157 REComSession::DestroyedImplementation(iDtorKey); |
|
158 if(iMdeSessionOwnFlag) |
|
159 { |
|
160 delete iMdeSession; |
|
161 delete iASW; |
|
162 } |
|
163 LOG("CInternalGeoTagger::~CInternalGeoTagger ,end"); |
|
164 } |
|
165 |
|
166 // -------------------------------------------------------------------------- |
|
167 // CInternalGeoTagger::CreateGeoTags |
|
168 // -------------------------------------------------------------------------- |
|
169 // |
|
170 void CInternalGeoTagger::CreateGeoTagsL( const TConnectionOption aOption ) |
|
171 { |
|
172 LOG("CInternalGeoTagger::CreateGeoTagsL ,begin"); |
|
173 if ( !IsSessionReady() ) |
|
174 { |
|
175 User::Leave( KErrNotReady ); |
|
176 } |
|
177 |
|
178 iConnectionOption = aOption; |
|
179 iIndex = 0; |
|
180 GetAllLocationsL(); |
|
181 |
|
182 LOG("CInternalGeoTagger::CreateGeoTagsL ,end"); |
|
183 } |
|
184 |
|
185 // -------------------------------------------------------------------------- |
|
186 // CInternalGeoTagger::HandleSessionOpened |
|
187 // -------------------------------------------------------------------------- |
|
188 // |
|
189 void CInternalGeoTagger::HandleSessionOpened(CMdESession& /*aSession*/, TInt aError) |
|
190 { |
|
191 LOG("CInternalGeoTagger::HandleSessionOpened ,begin"); |
|
192 if ( iMdeSessionOwnFlag && iASW && iASW->IsStarted() ) |
|
193 { |
|
194 iASW->AsyncStop(); |
|
195 } |
|
196 |
|
197 if ( KErrNone == aError ) |
|
198 { |
|
199 iSessionReady = ETrue; |
|
200 |
|
201 iTagCreator->SetSession( iMdeSession ); |
|
202 } |
|
203 else if(iMdeSessionOwnFlag) |
|
204 { |
|
205 delete iMdeSession; |
|
206 iMdeSession = NULL; |
|
207 } |
|
208 LOG("CInternalGeoTagger::HandleSessionOpened ,end"); |
|
209 } |
|
210 |
|
211 // -------------------------------------------------------------------------- |
|
212 // CInternalGeoTagger::HandleSessionError |
|
213 // -------------------------------------------------------------------------- |
|
214 // |
|
215 void CInternalGeoTagger::HandleSessionError(CMdESession& /*aSession*/, TInt /*aError*/) |
|
216 { |
|
217 LOG("CInternalGeoTagger::HandleSessionError ,begin"); |
|
218 if ( iMdeSessionOwnFlag && iASW && iASW->IsStarted() ) |
|
219 { |
|
220 iASW->AsyncStop(); |
|
221 } |
|
222 iSessionReady = EFalse; |
|
223 if(iMdeSessionOwnFlag) |
|
224 { |
|
225 delete iMdeSession; |
|
226 iMdeSession = NULL; |
|
227 } |
|
228 LOG("CInternalGeoTagger::HandleSessionError ,end"); |
|
229 } |
|
230 |
|
231 // -------------------------------------------------------------------------- |
|
232 // CInternalGeoTagger::IsSessionReady |
|
233 // -------------------------------------------------------------------------- |
|
234 // |
|
235 TBool CInternalGeoTagger::IsSessionReady() |
|
236 { |
|
237 return iSessionReady; |
|
238 } |
|
239 |
|
240 |
|
241 // -------------------------------------------------------------------------- |
|
242 // CInternalGeoTagger::GetRelationObjectsL() |
|
243 // -------------------------------------------------------------------------- |
|
244 // |
|
245 void CInternalGeoTagger::GetRelationObjectsL(TItemId aLocID) |
|
246 { |
|
247 LOG("CInternalGeoTagger::GetRelationObjectsL ,begin"); |
|
248 CMdENamespaceDef& namespaceDef = iMdeSession->GetDefaultNamespaceDefL(); |
|
249 CMdEObjectDef& imageObjDef = namespaceDef.GetObjectDefL( Image::KImageObject ); |
|
250 |
|
251 if(iRelationQuery) |
|
252 { |
|
253 iRelationQuery->RemoveObserver(*this); |
|
254 iRelationQuery->Cancel(); |
|
255 delete iRelationQuery; |
|
256 iRelationQuery = NULL; |
|
257 } |
|
258 |
|
259 iRelationQuery = iMdeSession->NewRelationQueryL( namespaceDef, this ); |
|
260 User::LeaveIfNull( iRelationQuery ); |
|
261 |
|
262 iRelationQuery->SetResultMode( EQueryResultModeItem ); |
|
263 |
|
264 // both left and right condition must match |
|
265 CMdERelationCondition& filterCond = iRelationQuery->Conditions(). |
|
266 AddRelationConditionL( ERelationConditionSideRight ); |
|
267 |
|
268 // left one must be any image object. |
|
269 filterCond.LeftL().AddObjectConditionL( imageObjDef ); |
|
270 |
|
271 // right one must be this location object |
|
272 filterCond.RightL().AddObjectConditionL( aLocID ); |
|
273 |
|
274 iRelationQuery->FindL(); // results to a call to HandleQueryCompleted() |
|
275 LOG("CInternalGeoTagger::GetRelationObjectsL ,end"); |
|
276 } |
|
277 |
|
278 // -------------------------------------------------------------------------- |
|
279 // CInternalGeoTagger::HandleQueryNewResults() |
|
280 // -------------------------------------------------------------------------- |
|
281 // |
|
282 void CInternalGeoTagger::HandleQueryNewResults(CMdEQuery& /*aQuery*/, TInt /*aFirstNewItemIndex*/, |
|
283 TInt /*aNewItemCount*/) |
|
284 { |
|
285 LOG("CInternalGeoTagger::HandleQueryNewResults ,begin"); |
|
286 } |
|
287 |
|
288 // -------------------------------------------------------------------------- |
|
289 // CInternalGeoTagger::HandleQueryCompleted() |
|
290 // -------------------------------------------------------------------------- |
|
291 // |
|
292 void CInternalGeoTagger::HandleQueryCompleted(CMdEQuery& aQuery, TInt aError) |
|
293 { |
|
294 LOG("CInternalGeoTagger::HandleQueryCompleted ,begin"); |
|
295 |
|
296 TInt count = aQuery.Count(); |
|
297 LOG1("CInternalGeoTagger::HandleQueryCompleted count: %d", count); |
|
298 |
|
299 if ( &aQuery == iLocationQuery ) |
|
300 { |
|
301 if ( count ) |
|
302 { |
|
303 iLocationId = iLocationQuery->ResultId( iIndex++ ); |
|
304 TRAP_IGNORE( GetRelationObjectsL( iLocationId ) ); |
|
305 } |
|
306 else |
|
307 { |
|
308 iIndex = 0; |
|
309 iObserver->GeoTaggingCompleted( aError ); |
|
310 if(iTagPendingHandlerFlag) |
|
311 { |
|
312 iTagPendingHandlerFlag = EFalse; |
|
313 iObserver->PendingGeoTagReqComplete(KErrNone); |
|
314 } |
|
315 } |
|
316 } |
|
317 else if ( &aQuery == iRelationQuery ) |
|
318 { |
|
319 //if it is a relation query, then update gps info of location object. |
|
320 |
|
321 if ( iRelationQuery->Count() ) |
|
322 { |
|
323 TInt err = KErrNone; |
|
324 TRAP(err, StartGeoTaggingL( ) ); |
|
325 if(err != KErrNone) |
|
326 { |
|
327 IterateNextLocation(); |
|
328 } |
|
329 } |
|
330 else |
|
331 { |
|
332 IterateNextLocation(); |
|
333 } |
|
334 |
|
335 } |
|
336 |
|
337 else if ( &aQuery == iTagQuery ) |
|
338 { |
|
339 |
|
340 if ( LocationTagExists() ) //nothing to do for this location |
|
341 { |
|
342 IterateNextLocation(); //Go through next location |
|
343 } |
|
344 else //do reverse geocoding |
|
345 { |
|
346 if(iTagPendingHandlerFlag) |
|
347 { |
|
348 iIndex = 0; |
|
349 iTagPendingHandlerFlag = EFalse; |
|
350 iObserver->PendingGeoTagReqComplete(KErrNotFound); |
|
351 return; |
|
352 } |
|
353 |
|
354 //Find the address for this geo-coordinate |
|
355 if(GPSInfoExists()) |
|
356 { |
|
357 // GPS info exist go for reverse geo coding. |
|
358 if(iRevGeocoderPlugin) |
|
359 { |
|
360 TRAP_IGNORE( |
|
361 iRevGeocoderPlugin->GetAddressByCoordinateL |
|
362 ( iLocationData.iPosition, iConnectionOption ) ); |
|
363 } |
|
364 else |
|
365 { |
|
366 IterateNextLocation(); //Go through next location |
|
367 } |
|
368 } |
|
369 else |
|
370 { |
|
371 if ( iLocationData.iNetworkInfo.iCellId > 0 && |
|
372 iLocationData.iNetworkInfo.iLocationAreaCode > 0 && |
|
373 iLocationData.iNetworkInfo.iCountryCode.Length() > 0 && |
|
374 iLocationData.iNetworkInfo.iNetworkId.Length() > 0 ) |
|
375 { |
|
376 // valid n/w information.. go for cell id based geo coding. |
|
377 #ifdef LOC_GEOTAGGING_CELLID |
|
378 TInt err = KErrNone; |
|
379 if(iGeoConverter == NULL) |
|
380 { |
|
381 TRAP(err, iGeoConverter = CGeoConverter::NewL(*this)); |
|
382 } |
|
383 |
|
384 if(err == KErrNone && iGeoConverter != NULL) |
|
385 { |
|
386 TRAP(err, iGeoConverter->ConvertL(iLocationData.iNetworkInfo);) |
|
387 } |
|
388 if(err != KErrNone) |
|
389 { |
|
390 HandleConversionError(err); |
|
391 } |
|
392 #else |
|
393 IterateNextLocation(); //Go through next location |
|
394 #endif |
|
395 } |
|
396 else |
|
397 { |
|
398 IterateNextLocation(); //Go through next location |
|
399 } |
|
400 } |
|
401 } |
|
402 |
|
403 } |
|
404 |
|
405 LOG("CInternalGeoTagger::HandleQueryCompleted ,end"); |
|
406 } |
|
407 |
|
408 |
|
409 // -------------------------------------------------------------------------- |
|
410 // CInternalGeoTagger::GPSInfoExists() |
|
411 // -------------------------------------------------------------------------- |
|
412 // |
|
413 TBool CInternalGeoTagger::GPSInfoExists() |
|
414 { |
|
415 LOG("CInternalGeoTagger::GPSInfoExists"); |
|
416 TBool gpsInfoExists = EFalse; |
|
417 if ( !Math::IsNaN( iLocationData.iPosition.Latitude() ) && |
|
418 !Math::IsNaN( iLocationData.iPosition.Longitude() )) //lat, long is there |
|
419 { |
|
420 |
|
421 LOG("Valid lat/lon\n"); |
|
422 gpsInfoExists = ETrue; |
|
423 } |
|
424 return gpsInfoExists; |
|
425 } |
|
426 |
|
427 // -------------------------------------------------------------------------- |
|
428 // CInternalGeoTagger::StartGeoTagging() |
|
429 // -------------------------------------------------------------------------- |
|
430 // |
|
431 void CInternalGeoTagger::StartGeoTaggingL( ) |
|
432 { |
|
433 LOG("CInternalGeoTagger::StartGeoTaggingL ,start"); |
|
434 GetLocationInfoL(); |
|
435 |
|
436 CMdERelation& relation = iRelationQuery->Result( 0 ); |
|
437 |
|
438 GetTagsL( relation.LeftObjectId() ); |
|
439 |
|
440 LOG("CInternalGeoTagger::StartGeoTaggingL ,end"); |
|
441 } |
|
442 // -------------------------------------------------------------------------- |
|
443 // CInternalGeoTagger::GetLocationInfoL() |
|
444 // -------------------------------------------------------------------------- |
|
445 // |
|
446 void CInternalGeoTagger::GetLocationInfoL() |
|
447 { |
|
448 LOG("CInternalGeoTagger::GetLocationInfoL, begin"); |
|
449 |
|
450 CMdENamespaceDef& namespaceDef = iMdeSession->GetDefaultNamespaceDefL(); |
|
451 |
|
452 CMdEObjectDef& locationObjectDef = namespaceDef.GetObjectDefL( Location::KLocationObject ); |
|
453 |
|
454 CMdEPropertyDef& latitudeDef = locationObjectDef.GetPropertyDefL( |
|
455 Location::KLatitudeProperty ); |
|
456 CMdEPropertyDef& longitudeDef = locationObjectDef.GetPropertyDefL( |
|
457 Location::KLongitudeProperty ); |
|
458 CMdEPropertyDef& cellIdDef = locationObjectDef.GetPropertyDefL( |
|
459 Location::KCellIdProperty ); |
|
460 CMdEPropertyDef& lacCodeDef = locationObjectDef.GetPropertyDefL( |
|
461 Location::KLocationAreaCodeProperty ); |
|
462 CMdEPropertyDef& countryCodeDef = locationObjectDef.GetPropertyDefL( |
|
463 Location::KCountryCodeProperty ); |
|
464 CMdEPropertyDef& networkCodeDef = locationObjectDef.GetPropertyDefL( |
|
465 Location::KNetworkCodeProperty ); |
|
466 |
|
467 CMdEObject* locationObject = NULL; |
|
468 CMdEProperty* latProp = NULL; |
|
469 CMdEProperty* lonProp = NULL; |
|
470 CMdEProperty* cellProp = NULL; |
|
471 CMdEProperty* lacProp = NULL; |
|
472 CMdEProperty* countryProp = NULL; |
|
473 CMdEProperty* networkProp = NULL; |
|
474 |
|
475 locationObject = iMdeSession->GetObjectL( iLocationId, locationObjectDef ); |
|
476 |
|
477 locationObject->Property( latitudeDef, latProp, 0 ); |
|
478 locationObject->Property( longitudeDef, lonProp, 0 ); |
|
479 if ( latProp && lonProp ) |
|
480 { |
|
481 iLocationData.iPosition.SetCoordinate( latProp->Real64ValueL(), |
|
482 lonProp->Real64ValueL() ); |
|
483 } |
|
484 |
|
485 locationObject->Property( cellIdDef, cellProp, 0 ); |
|
486 locationObject->Property( lacCodeDef, lacProp, 0 ); |
|
487 locationObject->Property( countryCodeDef, countryProp, 0 ); |
|
488 locationObject->Property( networkCodeDef, networkProp, 0 ); |
|
489 if ( cellProp && lacProp && countryProp && networkProp) |
|
490 { |
|
491 iLocationData.iNetworkInfo.iCellId = cellProp->Uint32ValueL(); |
|
492 iLocationData.iNetworkInfo.iLocationAreaCode = lacProp->Uint32ValueL(); |
|
493 iLocationData.iNetworkInfo.iCountryCode = countryProp->TextValueL(); |
|
494 iLocationData.iNetworkInfo.iNetworkId = networkProp->TextValueL(); |
|
495 |
|
496 } |
|
497 |
|
498 LOG("CInternalGeoTagger::GetLocationInfoL ,end"); |
|
499 } |
|
500 |
|
501 // -------------------------------------------------------------------------- |
|
502 // CInternalGeoTagger::LocationTagExists() |
|
503 // -------------------------------------------------------------------------- |
|
504 // |
|
505 TBool CInternalGeoTagger::LocationTagExists() |
|
506 { |
|
507 LOG("CInternalGeoTagger::LocationTagExists ,begin"); |
|
508 |
|
509 TBool tagFound = EFalse; |
|
510 TInt error = KErrNone; |
|
511 const TInt count = iTagQuery->Count(); |
|
512 |
|
513 for ( TInt i = 0; i < count; i++ ) |
|
514 { |
|
515 CMdERelation& relation = static_cast<CMdERelation&>( iTagQuery->ResultItem( i ) ); |
|
516 |
|
517 TItemId tagId = relation.RightObjectId(); |
|
518 CMdEObject* object = NULL; |
|
519 TRAP_IGNORE( object = iMdeSession->GetObjectL( tagId ) ); |
|
520 |
|
521 error = object->Uri().Find( KCountry ); |
|
522 if ( error == KErrNone ) |
|
523 { |
|
524 i = count; |
|
525 tagFound = ETrue; |
|
526 } |
|
527 } |
|
528 |
|
529 |
|
530 LOG("CInternalGeoTagger::LocationTagExists ,end"); |
|
531 return tagFound; |
|
532 |
|
533 } |
|
534 |
|
535 // -------------------------------------------------------------------------- |
|
536 // CInternalGeoTagger::AddressInfo() |
|
537 // -------------------------------------------------------------------------- |
|
538 // |
|
539 void CInternalGeoTagger::AddressInfoL( const TItemId aCountryTagId, const TItemId aCityTagId ) |
|
540 { |
|
541 LOG("CInternalGeoTagger::AddressInfoL ,begin"); |
|
542 |
|
543 const TInt count = iRelationQuery->Count(); |
|
544 |
|
545 for ( TInt i = 0; i < count; i++ ) |
|
546 { |
|
547 CMdERelation& relation = iRelationQuery->Result( i ); |
|
548 TItemId imageId = relation.LeftObjectId(); |
|
549 |
|
550 if ( !GPSInfoExists() ) //to update EXIF |
|
551 { |
|
552 // update relation timestamp, composer will then update exif data |
|
553 TTime timestamp( 0 ); |
|
554 timestamp.UniversalTime(); |
|
555 relation.SetLastModifiedDate( timestamp ); |
|
556 iMdeSession->UpdateRelationL( relation ); |
|
557 } |
|
558 |
|
559 iTagCreator->AttachTagsL( imageId, aCountryTagId, aCityTagId ); |
|
560 } |
|
561 |
|
562 LOG("CInternalGeoTagger::AddressInfoL ,end"); |
|
563 } |
|
564 |
|
565 |
|
566 // -------------------------------------------------------------------------- |
|
567 // CInternalGeoTagger::IterateNextLocation() |
|
568 // -------------------------------------------------------------------------- |
|
569 // |
|
570 void CInternalGeoTagger::IterateNextLocation() |
|
571 { |
|
572 LOG("CInternalGeoTagger::IterateNextLocation ,begin"); |
|
573 |
|
574 if (iIndex < iLocationQuery->Count()) |
|
575 { |
|
576 iLocationId = iLocationQuery->ResultId( iIndex++ ); |
|
577 TRAP_IGNORE( GetRelationObjectsL( iLocationId ) ); |
|
578 } |
|
579 else |
|
580 { |
|
581 if ( iObserver ) |
|
582 { |
|
583 iIndex = 0; |
|
584 TInt error = KErrNone; |
|
585 iObserver->GeoTaggingCompleted( error ); |
|
586 if(iTagPendingHandlerFlag) |
|
587 { |
|
588 iTagPendingHandlerFlag = EFalse; |
|
589 iObserver->PendingGeoTagReqComplete(KErrNone); |
|
590 } |
|
591 } |
|
592 } |
|
593 LOG("CInternalGeoTagger::IterateNextLocation ,end"); |
|
594 } |
|
595 |
|
596 // -------------------------------------------------------------------------- |
|
597 // CInternalGeoTagger::GetAllLocationsL() |
|
598 // -------------------------------------------------------------------------- |
|
599 // |
|
600 void CInternalGeoTagger::GetAllLocationsL() |
|
601 { |
|
602 LOG("CInternalGeoTagger::GetAllLocationsL ,begin"); |
|
603 |
|
604 CMdENamespaceDef& defaultNamespaceDef = iMdeSession->GetDefaultNamespaceDefL(); |
|
605 CMdEObjectDef& locObjDef = defaultNamespaceDef.GetObjectDefL( |
|
606 MdeConstants::Location::KLocationObject ); |
|
607 CMdEPropertyDef& cellIdPropDef = locObjDef.GetPropertyDefL( |
|
608 MdeConstants::Location::KCellIdProperty ); |
|
609 |
|
610 if(iLocationQuery) |
|
611 { |
|
612 iLocationQuery->RemoveObserver(*this); |
|
613 iLocationQuery->Cancel(); |
|
614 delete iLocationQuery; |
|
615 iLocationQuery = NULL; |
|
616 } |
|
617 // query objects with object definition "Image" |
|
618 iLocationQuery = iMdeSession->NewObjectQueryL( defaultNamespaceDef, locObjDef, this ); |
|
619 |
|
620 //Define the result order |
|
621 iLocationQuery->AppendOrderRuleL(TMdEOrderRule(cellIdPropDef, ESortAscending)); |
|
622 |
|
623 iLocationQuery->SetResultMode( EQueryResultModeId ); |
|
624 iLocationQuery->FindL(); |
|
625 |
|
626 LOG("CInternalGeoTagger::GetAllLocationsL ,end"); |
|
627 } |
|
628 |
|
629 // -------------------------------------------------------------------------- |
|
630 // CInternalGeoTagger::ReverseGeocodeComplete() |
|
631 // Get address details like street, city, state, etc. |
|
632 // -------------------------------------------------------------------------- |
|
633 // |
|
634 void CInternalGeoTagger::ReverseGeocodeComplete( TInt& aErrorcode, MAddressInfo& aAddressInfo ) |
|
635 { |
|
636 LOG("CInternalGeoTagger::ReverseGeocodeComplete ,begin"); |
|
637 TItemId countryTagId(0); |
|
638 TItemId cityTagId(0); |
|
639 |
|
640 // create country and city tags |
|
641 if( aErrorcode == KErrNone ) |
|
642 { |
|
643 TPtrC countryPtr( aAddressInfo.GetCountryName() ); |
|
644 TPtrC cityPtr( aAddressInfo.GetCity() ); |
|
645 |
|
646 TRAP_IGNORE( iTagCreator->CreateLocationTagsL( countryPtr, countryTagId, cityPtr, cityTagId ) ); |
|
647 |
|
648 TRAP_IGNORE(AddressInfoL( countryTagId, cityTagId )); |
|
649 |
|
650 IterateNextLocation(); |
|
651 } |
|
652 else |
|
653 { |
|
654 //handle error |
|
655 if ( iObserver ) |
|
656 { |
|
657 iIndex = 0; |
|
658 iObserver->GeoTaggingCompleted( aErrorcode ); |
|
659 } |
|
660 } |
|
661 |
|
662 |
|
663 LOG("CInternalGeoTagger::ReverseGeocodeComplete ,end"); |
|
664 } |
|
665 |
|
666 // -------------------------------------------------------------------------- |
|
667 // CInternalGeoTagger::GetTagsL() |
|
668 // Get tags related to this image/video object |
|
669 // -------------------------------------------------------------------------- |
|
670 // |
|
671 void CInternalGeoTagger::GetTagsL( TItemId aImageID ) |
|
672 { |
|
673 LOG("CInternalGeoTagger::GetTagsL ,begin"); |
|
674 CMdENamespaceDef& namespaceDef = iMdeSession->GetDefaultNamespaceDefL(); |
|
675 CMdEObjectDef& tagObjectDef = namespaceDef.GetObjectDefL( Tag::KTagObject ); |
|
676 |
|
677 if(iTagQuery) |
|
678 { |
|
679 iTagQuery->RemoveObserver(*this); |
|
680 iTagQuery->Cancel(); |
|
681 delete iTagQuery; |
|
682 iTagQuery = NULL; |
|
683 } |
|
684 |
|
685 iTagQuery = iMdeSession->NewRelationQueryL( namespaceDef, this ); |
|
686 User::LeaveIfNull( iTagQuery ); |
|
687 |
|
688 iTagQuery->SetResultMode( EQueryResultModeItem ); |
|
689 |
|
690 // both left and right condition must match |
|
691 CMdERelationCondition& filterCond = iTagQuery->Conditions(). |
|
692 AddRelationConditionL( ERelationConditionSideRight ); |
|
693 |
|
694 // left one must be this image object. |
|
695 filterCond.LeftL().AddObjectConditionL( aImageID ); |
|
696 |
|
697 // right one must be tag object |
|
698 filterCond.RightL().AddObjectConditionL( tagObjectDef ); |
|
699 |
|
700 iTagQuery->FindL(); // results to a call to HandleQueryCompleted() |
|
701 LOG("CInternalGeoTagger::GetTagsL ,end"); |
|
702 } |
|
703 |
|
704 #ifdef LOC_GEOTAGGING_CELLID |
|
705 // -------------------------------------------------------------------------- |
|
706 // CInternalGeoTagger::ConversionCompletedL() |
|
707 // -------------------------------------------------------------------------- |
|
708 // |
|
709 |
|
710 void CInternalGeoTagger::ConversionCompletedL( const TInt aError, |
|
711 TLocality& aPosition ) |
|
712 { |
|
713 LOG1("CInternalGeoTagger::ConversionCompletedL, begin. Error - %d", aError); |
|
714 if(aError == KErrNone) |
|
715 { |
|
716 iLocationData.iPosition.SetCoordinate |
|
717 ( aPosition.Latitude(), aPosition.Longitude()); |
|
718 if(iRevGeocoderPlugin) |
|
719 { |
|
720 iRevGeocoderPlugin->GetAddressByCoordinateL |
|
721 ( iLocationData.iPosition, iConnectionOption ) ; |
|
722 } |
|
723 else |
|
724 { |
|
725 IterateNextLocation(); //Go through next location |
|
726 } |
|
727 } |
|
728 else |
|
729 { |
|
730 IterateNextLocation(); //Go through next location |
|
731 } |
|
732 LOG("CInternalGeoTagger::ConversionCompletedL, end"); |
|
733 } |
|
734 |
|
735 |
|
736 //----------------------------------------------------------------- |
|
737 // CInternalGeoTagger::HandleConversionError |
|
738 //------------------------------------------------------------------ |
|
739 // |
|
740 void CInternalGeoTagger::HandleConversionError(TInt aError) |
|
741 { |
|
742 LOG("CInternalGeoTagger::HandleConversionError, begin"); |
|
743 ARG_USED(aError); |
|
744 IterateNextLocation(); //Go through next location |
|
745 LOG("CInternalGeoTagger::HandleConversionError, end"); |
|
746 } |
|
747 |
|
748 #endif |
|
749 |
|
750 // -------------------------------------------------------------------------- |
|
751 // CInternalGeoTagger::PendingGeoTagsL() |
|
752 // Is there any untagged photos with location info?. |
|
753 // -------------------------------------------------------------------------- |
|
754 // |
|
755 void CInternalGeoTagger::PendingGeoTagsL( TBool aTagInProgress ) |
|
756 { |
|
757 LOG("CInternalGeoTagger::PendingGeoTagsL ,begin"); |
|
758 iIndex = 0; |
|
759 if ( aTagInProgress ) |
|
760 { |
|
761 //Tagging is going through location trail, so photo does not need to do tagging now |
|
762 LOG("Geo tagging in progress.\n"); |
|
763 iObserver->PendingGeoTagReqComplete( KErrInUse ); |
|
764 } |
|
765 else |
|
766 { |
|
767 if(!iTagPendingHandlerFlag) |
|
768 { |
|
769 LOG("Processing the request.\n"); |
|
770 // tag pending request is not going on |
|
771 iTagPendingHandlerFlag = ETrue; |
|
772 CreateGeoTagsL(); |
|
773 } |
|
774 else |
|
775 { |
|
776 // req osn progress, don't do anything. |
|
777 LOG("Request in progress.\n"); |
|
778 iObserver->PendingGeoTagReqComplete( KErrInUse ); |
|
779 } |
|
780 } |
|
781 LOG("CInternalGeoTagger::PendingGeoTagsL ,end"); |
|
782 } |
|
783 |
|
784 // ---------------------------------------------------------------------------- |
|
785 // CInternalGeoTagger::GetCurrentRegisterNw() |
|
786 // ---------------------------------------------------------------------------- |
|
787 RMobilePhone::TMobilePhoneNetworkInfoV2& CInternalGeoTagger::GetCurrentRegisterNw() |
|
788 { |
|
789 LOG( "CInternalGeoTagger::GetCurrentRegisterNw ,begin" ); |
|
790 return iObserver->GetCurrentRegisterNw(); |
|
791 } |
|
792 |
|
793 // ---------------------------------------------------------------------------- |
|
794 // CInternalGeoTagger::IsRegisteredAtHomeNetwork() |
|
795 // ---------------------------------------------------------------------------- |
|
796 TBool CInternalGeoTagger::IsRegisteredAtHomeNetwork() |
|
797 { |
|
798 LOG( "CInternalGeoTagger::IsRegisteredAtHomeNetwork" ); |
|
799 return iObserver->IsRegisteredAtHomeNetwork(); |
|
800 } |
|
801 |
|
802 // ---------------------------------------------------------------------------- |
|
803 // CInternalGeoTagger::GetHomeNetworkInfo() |
|
804 // ---------------------------------------------------------------------------- |
|
805 const RMobilePhone::TMobilePhoneNetworkInfoV1& |
|
806 CInternalGeoTagger::GetHomeNetworkInfo(TBool& aHomeNwInfoAvailableFlag) |
|
807 { |
|
808 LOG( "CInternalReverseGeocode::GetHomeNetworkInfo" ); |
|
809 return iObserver->GetHomeNetworkInfo(aHomeNwInfoAvailableFlag); |
|
810 } |
|
811 |
|
812 // End of file |
|
813 |