16 */ |
16 */ |
17 |
17 |
18 #include <e32cmn.h> |
18 #include <e32cmn.h> |
19 #include <lbserrors.h> |
19 #include <lbserrors.h> |
20 #include <lbssatellite.h> |
20 #include <lbssatellite.h> |
|
21 #include <ecom.h> |
|
22 #include <centralrepository.h> |
|
23 #include <hwrmpowerstatesdkpskeys.h> |
21 |
24 |
22 #include "rlocationtrail.h" |
25 #include "rlocationtrail.h" |
23 #include "clocationrecord.h" |
26 #include "clocationrecord.h" |
24 #include "cnetworkinfo.h" |
27 #include "cnetworkinfo.h" |
25 #include "locationmanagerdebug.h" |
28 #include "locationmanagerdebug.h" |
26 #include "locationtraildefs.h" |
29 #include "locationtraildefs.h" |
27 #include "locationtrailpskeys.h" |
30 #include "locationtrailpskeys.h" |
28 #include "mdeconstants.h" |
31 #include "mdeconstants.h" |
29 #include <centralrepository.h> |
32 #ifdef LOC_REVERSEGEOCODE |
30 #include <hwrmpowerstatesdkpskeys.h> |
33 #include "reversegeocoderplugin.h" |
|
34 const TUid KReverseGeoCodeUid = {0x2002DD12}; |
|
35 #endif |
31 |
36 |
32 |
37 |
33 using namespace MdeConstants; |
38 using namespace MdeConstants; |
34 |
39 |
|
40 const TUint KNetQueryBit = 1; // 1 bit |
|
41 const TUint KDownloadMediaFile = 2; // 2 bit |
|
42 const TUint KSnapMediaFile = 4; // 3 bit |
|
43 const TUint KLocationQueryInProgress = 1; // 1 bit |
|
44 #ifdef LOC_REVERSEGEOCODE |
|
45 const TUint KReverseGeoCodingInProgress = 2; // 2 bit |
|
46 _LIT ( KCountry, "country:"); // country:india |
|
47 _LIT ( KCity, "city:"); // city:bangalore|country:india |
|
48 #endif |
|
49 const TUint KSnapGeoConvertInProgress = 4; // 3 bit |
|
50 #ifdef LOC_GEOTAGGING_CELLID |
|
51 const TUint KSnapGeoConvertInPendingState = 8; // 4 bit |
|
52 #endif |
|
53 |
|
54 |
|
55 |
35 // -------------------------------------------------------------------------- |
56 // -------------------------------------------------------------------------- |
36 // CLocationRecord::NewL |
57 // CLocationRecord::NewL |
37 // -------------------------------------------------------------------------- |
58 // -------------------------------------------------------------------------- |
38 // |
59 // |
39 EXPORT_C CLocationRecord* CLocationRecord::NewL() |
60 EXPORT_C CLocationRecord* CLocationRecord::NewL(MGeoTaggerObserver& aGeoTaggerObserver, |
40 { |
61 RMobilePhone& aPhone) |
41 CLocationRecord* self = new (ELeave) CLocationRecord(); |
62 { |
|
63 CLocationRecord* self = new (ELeave) CLocationRecord(aGeoTaggerObserver, aPhone); |
42 CleanupStack::PushL( self ); |
64 CleanupStack::PushL( self ); |
43 self->ConstructL(); |
65 self->ConstructL(); |
44 CleanupStack::Pop( self ); |
66 CleanupStack::Pop( self ); |
45 return self; |
67 return self; |
46 } |
68 } |
47 |
69 |
48 // -------------------------------------------------------------------------- |
70 // -------------------------------------------------------------------------- |
49 // CLocationRecord::CLocationRecord |
71 // CLocationRecord::CLocationRecord |
50 // -------------------------------------------------------------------------- |
72 // -------------------------------------------------------------------------- |
51 // |
73 // |
52 CLocationRecord::CLocationRecord() |
74 CLocationRecord::CLocationRecord(MGeoTaggerObserver& aGeoTaggerObserver, |
|
75 RMobilePhone& aPhone) |
53 : iNetworkInfoTimer( NULL ), |
76 : iNetworkInfoTimer( NULL ), |
54 iState( RLocationTrail::ETrailStopped ), |
77 iState( RLocationTrail::ETrailStopped ), |
55 iTrailCaptureSetting( RLocationTrail::ECaptureAll ), |
78 iTrailCaptureSetting( RLocationTrail::ECaptureAll ), |
56 iLocationCounter( 0 ), |
79 iLocationCounter( 0 ), |
57 iRequestCurrentLoc( EFalse ), |
80 iRequestCurrentLoc( EFalse ), |
58 iTrailStarted( EFalse ), |
81 iTrailStarted( EFalse ), |
59 iLastGPSFixState( EFalse ), |
82 iLastGPSFixState( EFalse ), |
60 iLastLocationId( 0 ) |
83 iLocationQuery(NULL), |
|
84 iNetLocationQuery(NULL), |
|
85 iRemapState( ERemapProgressNone), |
|
86 iNamespaceDef(NULL), |
|
87 iLocationObjectDef(NULL), |
|
88 iLatitudeDef(NULL), |
|
89 iLongitudeDef(NULL), |
|
90 iAltitudeDef(NULL), |
|
91 iMediaHandlingFlag(0), |
|
92 iPhone(aPhone), |
|
93 iGpsDataAvailableFlag(EFalse), |
|
94 iGeoTaggerObserver(aGeoTaggerObserver) |
|
95 #ifdef LOC_GEOTAGGING_CELLID |
|
96 ,iGeoConverter(NULL) |
|
97 , iConvertRetry(ETrue) |
|
98 #endif |
|
99 #ifdef LOC_REVERSEGEOCODE |
|
100 ,iConnectionOption(ESilent) |
|
101 ,iImageQuery(NULL) |
|
102 ,iTagQuery(NULL) |
|
103 ,iTagCreator( NULL ) |
|
104 ,iRevGeocoderPlugin( NULL ) |
|
105 #endif |
61 { |
106 { |
62 iMaxTrailSize = KMaxTrailLength / KUpdateInterval; |
107 iMaxTrailSize = KMaxTrailLength / KUpdateInterval; |
63 } |
108 } |
64 |
109 |
65 // -------------------------------------------------------------------------- |
110 // -------------------------------------------------------------------------- |
66 // CLocationRecord::ConstructL |
111 // CLocationRecord::ConstructL |
67 // -------------------------------------------------------------------------- |
112 // -------------------------------------------------------------------------- |
68 // |
113 // |
69 void CLocationRecord::ConstructL() |
114 void CLocationRecord::ConstructL() |
70 { |
115 { |
|
116 LOG( "CLocationRecord::ConstructL(), begin" ); |
71 const TInt KMillion = 1000000; |
117 const TInt KMillion = 1000000; |
72 TInt err = iProperty.Define( KPSUidLocationTrail, KLocationTrailState, RProperty::EInt ); |
118 TInt err = iProperty.Define( KPSUidLocationTrail, KLocationTrailState, RProperty::EInt ); |
73 if ( err != KErrNone && err != KErrAlreadyExists ) |
119 if ( err != KErrNone && err != KErrAlreadyExists ) |
74 { |
120 { |
75 User::Leave( err ); |
121 User::Leave( err ); |
76 } |
122 } |
77 User::LeaveIfError( iProperty.Set( KPSUidLocationTrail, |
123 User::LeaveIfError( iProperty.Set( KPSUidLocationTrail, |
78 KLocationTrailState, (TInt) RLocationTrail::ETrailStopped ) ); |
124 KLocationTrailState, (TInt) RLocationTrail::ETrailStopped ) ); |
79 |
125 |
80 iNetworkInfo = CNetworkInfo::NewL( this ); |
126 |
|
127 iNetworkInfoChangeListener = CNetworkInfo::NewL( this ); |
81 iPositionInfo = CPositionInfo::NewL( this ); |
128 iPositionInfo = CPositionInfo::NewL( this ); |
82 iRemapper = CLocationRemappingAO::NewL(); |
129 iRemapper = CLocationRemappingAO::NewL(); |
83 iNetworkInfoTimer = CPeriodic::NewL( CActive::EPriorityStandard ); |
130 iNetworkInfoTimer = CPeriodic::NewL( CActive::EPriorityStandard ); |
84 |
131 |
|
132 #ifdef LOC_REVERSEGEOCODE |
|
133 iTagCreator = CTagCreator::NewL(); |
|
134 |
|
135 |
|
136 if (!iRevGeocoderPlugin) |
|
137 { |
|
138 iRevGeocoderPlugin = reinterpret_cast<CReverseGeoCoderPlugin*>( |
|
139 REComSession::CreateImplementationL(KReverseGeoCodeUid,iDtorKey)); |
|
140 if(iRevGeocoderPlugin) |
|
141 { |
|
142 iRevGeocoderPlugin->AddObserverL(*this); |
|
143 } |
|
144 } |
|
145 |
|
146 #endif |
|
147 |
|
148 |
85 TInt interval( 0 ); |
149 TInt interval( 0 ); |
86 TRAP(err, ReadCenRepValueL(KIntervalKey, interval)); |
150 TRAP(err, ReadCenRepValueL(KIntervalKey, interval)); |
87 LOG1("CLocationManagerServer::ConstructL, cenrep interval value:%d", interval); |
151 LOG1("Cenrep interval value:%d", interval); |
88 |
152 |
89 if (interval == 0 || err != KErrNone ) |
153 if (interval == 0 || err != KErrNone ) |
90 { |
154 { |
91 LOG1("CLocationManagerServer::ConstructL, cenrep interval err:%d", err); |
155 LOG1("Cenrep interval err:%d", err); |
92 iInterval = KUpdateInterval; |
156 iInterval = KUpdateInterval; |
93 } |
157 } |
94 else |
158 else |
95 { |
159 { |
96 iInterval = interval * KMillion; |
160 iInterval = interval * KMillion; |
97 } |
161 } |
98 |
162 |
99 TRAP(err, ReadCenRepValueL(KLocationDeltaKey, iLocationDelta)); |
163 TRAP(err, ReadCenRepValueL(KLocationDeltaKey, iLocationDelta)); |
100 LOG1("CLocationManagerServer::ConstructL, location delta value:%d", iLocationDelta); |
164 LOG1("Location delta value:%d", iLocationDelta); |
101 |
165 |
102 if (iLocationDelta == 0) |
166 if (iLocationDelta == 0) |
103 { |
167 { |
104 LOG1("CLocationManagerServer::ConstructL, location delta err:%d", err); |
168 LOG1("Location delta err:%d", err); |
105 iLocationDelta = KLocationDelta; |
169 iLocationDelta = KLocationDelta; |
106 } |
170 } |
107 |
171 iLastMediaItem.iFlag = 0; |
|
172 iLastMediaItem.iLocationId = 0; |
|
173 #ifdef LOC_REVERSEGEOCODE |
|
174 iLastMediaItem.iCityTagId= 0; |
|
175 iLastMediaItem.iCountryTagId = 0; |
|
176 |
|
177 iLastLocationItem.iFlag = 0; |
|
178 iLastLocationItem.iCityTagId= 0; |
|
179 iLastLocationItem.iCountryTagId = 0; |
|
180 iLastLocationItem.iLocationId = 0; |
|
181 #endif |
|
182 LOG( "CLocationRecord::ConstructL(), end" ); |
108 } |
183 } |
109 |
184 |
110 // -------------------------------------------------------------------------- |
185 // -------------------------------------------------------------------------- |
111 // CLocationRecord::~CLocationRecord |
186 // CLocationRecord::~CLocationRecord |
112 // -------------------------------------------------------------------------- |
187 // -------------------------------------------------------------------------- |
113 // |
188 // |
114 EXPORT_C CLocationRecord::~CLocationRecord() |
189 EXPORT_C CLocationRecord::~CLocationRecord() |
115 { |
190 { |
|
191 LOG( "CLocationRecord::~CLocationRecord(), begin" ); |
116 Stop(); |
192 Stop(); |
117 iProperty.Delete( KPSUidLocationTrail, KLocationTrailState ); |
193 iProperty.Delete( KPSUidLocationTrail, KLocationTrailState ); |
118 iProperty.Close(); |
194 iProperty.Close(); |
|
195 iTrail.ResetAndDestroy(); |
119 iTrail.Close(); |
196 iTrail.Close(); |
120 |
197 iMediaItems.ResetAndDestroy(); |
121 delete iNetworkInfo; |
198 iMediaItems.Close(); |
|
199 #ifdef LOC_REVERSEGEOCODE |
|
200 iLocationItems.ResetAndDestroy(); |
|
201 iLocationItems.Close(); |
|
202 #endif |
|
203 delete iNetworkInfoChangeListener; |
122 delete iPositionInfo; |
204 delete iPositionInfo; |
123 delete iNetworkInfoTimer; |
205 delete iNetworkInfoTimer; |
124 if (iRemapper) |
206 #ifdef LOC_GEOTAGGING_CELLID |
|
207 if(iGeoConverter) |
|
208 { |
|
209 delete iGeoConverter; |
|
210 iGeoConverter = NULL; |
|
211 } |
|
212 #endif |
|
213 if (iRemapper) |
125 { |
214 { |
126 iRemapper->StopRemapping(); |
215 iRemapper->StopRemapping(); |
127 delete iRemapper; |
216 delete iRemapper; |
128 } |
217 } |
|
218 if(iLocationQuery) |
|
219 { |
|
220 iLocationQuery->RemoveObserver(*this); |
|
221 iLocationQuery->Cancel(); |
|
222 delete iLocationQuery; |
|
223 iLocationQuery = NULL; |
|
224 } |
|
225 |
|
226 if(iNetLocationQuery) |
|
227 { |
|
228 iNetLocationQuery->RemoveObserver(*this); |
|
229 iNetLocationQuery->Cancel(); |
|
230 delete iNetLocationQuery; |
|
231 iNetLocationQuery = NULL; |
|
232 } |
|
233 |
|
234 |
|
235 #ifdef LOC_REVERSEGEOCODE |
|
236 if(iImageQuery) |
|
237 { |
|
238 iImageQuery->RemoveObserver(*this); |
|
239 iImageQuery->Cancel(); |
|
240 delete iImageQuery; |
|
241 iImageQuery = NULL; |
|
242 } |
|
243 if(iTagQuery) |
|
244 { |
|
245 iTagQuery->RemoveObserver(*this); |
|
246 iTagQuery->Cancel(); |
|
247 delete iTagQuery; |
|
248 iTagQuery = NULL; |
|
249 } |
|
250 delete iTagCreator; |
|
251 // set the pointer to NULL, ECOM will destroy object. |
|
252 delete iRevGeocoderPlugin; |
|
253 iRevGeocoderPlugin = NULL; |
|
254 REComSession::DestroyedImplementation(iDtorKey); |
|
255 #endif |
|
256 LOG( "CLocationRecord::~CLocationRecord(), end" ); |
129 } |
257 } |
130 |
258 |
131 // -------------------------------------------------------------------------- |
259 // -------------------------------------------------------------------------- |
132 // CLocationRecord::CurrentState |
260 // CLocationRecord::CurrentState |
133 // -------------------------------------------------------------------------- |
261 // -------------------------------------------------------------------------- |
349 // -------------------------------------------------------------------------- |
488 // -------------------------------------------------------------------------- |
350 // |
489 // |
351 void CLocationRecord::Position( const TPositionInfo& aPositionInfo, |
490 void CLocationRecord::Position( const TPositionInfo& aPositionInfo, |
352 const TInt aError ) |
491 const TInt aError ) |
353 { |
492 { |
|
493 LOG( "CLocationRecord::Position(), begin" ); |
354 const TPositionSatelliteInfo& positionSatelliteInfo = |
494 const TPositionSatelliteInfo& positionSatelliteInfo = |
355 static_cast<const TPositionSatelliteInfo&>(aPositionInfo); |
495 static_cast<const TPositionSatelliteInfo&>(aPositionInfo); |
356 |
496 |
357 if ( iRequestCurrentLoc ) |
497 if ( iRequestCurrentLoc ) |
358 { |
498 { |
359 HandleLocationRequest( positionSatelliteInfo, aError ); |
499 HandleLocationRequest( positionSatelliteInfo, aError ); |
360 } |
500 } |
361 if( iState == RLocationTrail::ETrailStopped ) |
501 |
362 { |
502 iGpsDataAvailableFlag = EFalse; |
363 LOG("CLocationRecord::Position - trail stopped"); |
503 |
364 return; |
504 if ( !iTrailStarted || iState == RLocationTrail::ETrailStopped) |
365 } |
505 { |
366 |
506 LOG("trail not started/stopped"); |
367 if ( !iTrailStarted ) |
507 iPositionInfo->Stop(); |
368 { |
|
369 iPositionInfo->NextPosition(); |
|
370 return; |
508 return; |
|
509 } |
|
510 // all cases store the location.. |
|
511 StoreLocation( positionSatelliteInfo ); |
|
512 |
|
513 if ( RemappingNeeded() ) |
|
514 { |
|
515 //either network or gps signal is available |
|
516 if ( ( iNetwork.iCellId != 0 && |
|
517 iNetwork.iCountryCode.Length() != 0 && |
|
518 iNetwork.iNetworkId.Length() != 0 ) || ( aError == KErrNone ) ) |
|
519 { |
|
520 //no error means gps info available |
|
521 TRAP_IGNORE( RemapObjectsL( aError == KErrNone ) ); |
|
522 } |
371 } |
523 } |
372 switch ( aError ) |
524 switch ( aError ) |
373 { |
525 { |
374 case KPositionPartialUpdate: // fall through |
526 case KPositionPartialUpdate: // fall through |
375 case KPositionQualityLoss: |
527 case KPositionQualityLoss: |
376 { |
528 { |
377 // Location is stored, even if it may not be valid. |
529 // Location is stored, even if it may not be valid. |
378 StoreLocation( positionSatelliteInfo ); |
530 LOG("Partial update"); |
379 LOG("CLocationRecord::Position - partial update"); |
|
380 if ( iState != RLocationTrail::EWaitingGPSData && |
531 if ( iState != RLocationTrail::EWaitingGPSData && |
381 iState != RLocationTrail::ETrailStopping ) |
532 iState != RLocationTrail::ETrailStopping ) |
382 { |
533 { |
383 SetCurrentState( RLocationTrail::EWaitingGPSData ); |
534 SetCurrentState( RLocationTrail::EWaitingGPSData ); |
384 LOG("CLocationRecord::Position trail waiting for gps"); |
535 LOG("Trail waiting for gps"); |
385 } |
536 } |
386 break; |
537 break; |
387 } |
538 } |
388 case KErrNone: |
539 case KErrNone: |
389 { |
540 { |
390 StoreLocation( positionSatelliteInfo ); |
541 LOG("Good GPS coordinates"); |
391 LOG("CLocationRecord::Position - good GPS coordinates"); |
542 iGpsDataAvailableFlag = ETrue; |
392 if ( iState != RLocationTrail::ETrailStarted ) |
543 if ( iState != RLocationTrail::ETrailStarted ) |
393 { |
544 { |
394 if ( iRemapper ) |
545 if ( iRemapper ) |
395 { |
546 { |
396 LOG("CLocationRecord::Position start remapping"); |
547 LOG("Start remapping"); |
397 iLastLocationId = 0; |
|
398 TBool createLocation = iRemapper->CheckQueue(); |
|
399 if( createLocation ) |
|
400 { |
|
401 TRAP_IGNORE( |
|
402 TItemId locationId = DoCreateLocationL( iNewItem.iLocationData ); |
|
403 iRemapper->UpdateRelationsL( locationId ); |
|
404 ) |
|
405 } |
|
406 iRemapper->StartRemappingObjects( iNewItem.iLocationData ); |
548 iRemapper->StartRemappingObjects( iNewItem.iLocationData ); |
407 |
549 |
408 if( iObserver->WaitForPositioningStopTimeout() && !RemappingNeeded() ) |
550 if( iObserver->WaitForPositioningStopTimeout() && !RemappingNeeded() ) |
409 { |
551 { |
410 iObserver->RemapedCompleted(); |
552 iObserver->RemapedCompleted(); |
|
553 iPositionInfo->HandleRemapComplete(); |
411 return; |
554 return; |
412 } |
555 } |
413 |
556 |
414 } |
557 } |
415 if ( iState != RLocationTrail::ETrailStopping ) |
558 if ( iState != RLocationTrail::ETrailStopping ) |
416 { |
559 { |
417 SetCurrentState( RLocationTrail::ETrailStarted ); |
560 SetCurrentState( RLocationTrail::ETrailStarted ); |
418 LOG("CLocationRecord::Position trail started"); |
561 LOG("Trail started"); |
419 } |
562 } |
420 } |
563 } |
421 break; |
564 break; |
422 } |
565 } |
423 default: |
566 default: |
424 { |
567 { |
425 StoreLocation( positionSatelliteInfo ); |
568 LOG1("Searching GPS, aError %d", aError ); |
426 LOG1("CLocationRecord::Position - searching GPS, aError %d", aError ); |
|
427 if ( iState != RLocationTrail::ESearchingGPS && |
569 if ( iState != RLocationTrail::ESearchingGPS && |
428 iState != RLocationTrail::ETrailStopping ) |
570 iState != RLocationTrail::ETrailStopping ) |
429 { |
571 { |
430 SetCurrentState( RLocationTrail::ESearchingGPS ); |
572 SetCurrentState( RLocationTrail::ESearchingGPS ); |
431 LOG("CLocationRecord::Position trail searching gps"); |
573 LOG("Trail searching gps"); |
432 } |
574 } |
433 break; |
575 break; |
434 } |
576 } |
435 } |
577 } |
436 TBool fixState = CheckGPSFix( positionSatelliteInfo ); |
578 TBool fixState = CheckGPSFix( positionSatelliteInfo ); |
437 LOG1( "CLocationRecord::Position fixState %d", fixState ); |
579 LOG1( "fixState %d", fixState ); |
438 LOG1( "CLocationRecord::Position iLastGPSFixState %d", iLastGPSFixState ); |
580 LOG1( "iLastGPSFixState %d", iLastGPSFixState ); |
439 |
581 |
440 if ( iObserver && iLastGPSFixState != fixState ) |
582 if ( iObserver && iLastGPSFixState != fixState ) |
441 { |
583 { |
442 LOG("CLocationRecord::Position quality changed"); |
584 LOG("Quality changed"); |
443 iObserver->GPSSignalQualityChanged( positionSatelliteInfo ); |
585 iObserver->GPSSignalQualityChanged( positionSatelliteInfo ); |
444 } |
586 } |
445 |
587 |
446 iLastGPSFixState = fixState; |
588 iLastGPSFixState = fixState; |
447 |
589 |
448 iPositionInfo->NextPosition(); |
590 LOG( "CLocationRecord::Position(), end" ); |
|
591 } |
|
592 |
|
593 |
|
594 // -------------------------------------------------------------------------- |
|
595 // CLocationRecord::RemapObjectsL |
|
596 // Remaps the location objects when GPS is available |
|
597 // -------------------------------------------------------------------------- |
|
598 // |
|
599 void CLocationRecord::RemapObjectsL( TBool aGPSInfoAvailable ) |
|
600 { |
|
601 LOG( "CLocationRecord::RemapObjectsL(), begin" ); |
|
602 TBool createLocation = EFalse; |
|
603 |
|
604 if (iRemapper) |
|
605 { |
|
606 createLocation = iRemapper->CheckQueue(); |
|
607 } |
|
608 |
|
609 if ( !createLocation || iRemapper == NULL) |
|
610 { |
|
611 return; |
|
612 } |
|
613 |
|
614 |
|
615 if ( aGPSInfoAvailable ) |
|
616 { |
|
617 TItemId locationId = DoCreateLocationL( iNewItem.iLocationData ); |
|
618 iRemapper->UpdateRelationsL( locationId ); |
|
619 #ifdef LOC_REVERSEGEOCODE |
|
620 if(!(iMediaHandlingFlag & KReverseGeoCodingInProgress)) |
|
621 { |
|
622 iRemapState = ERemapRevGeoCodeInProgress; |
|
623 //Find the address by coordinate, results a call to ReverseGeocodeComplete() |
|
624 iMediaHandlingFlag |= KReverseGeoCodingInProgress; |
|
625 |
|
626 if(iRevGeocoderPlugin) |
|
627 { |
|
628 iRevGeocoderPlugin->GetAddressByCoordinateL( iNewItem.iLocationData.iPosition, iConnectionOption ); |
|
629 } |
|
630 } |
|
631 else |
|
632 { |
|
633 // make this as pending state so that on rev geo code complete |
|
634 // it will take the priority over the next item within the location |
|
635 // item in location queue. |
|
636 iRemapState = ERemapRevGeoCodePending; |
|
637 } |
|
638 #endif //LOC_REVERSEGEOCODE |
|
639 } |
|
640 else |
|
641 { |
|
642 //call location m/w API to convert cell ID to lat, long |
|
643 #ifdef LOC_GEOTAGGING_CELLID |
|
644 if((iMediaHandlingFlag & KSnapGeoConvertInProgress) > 0) |
|
645 { |
|
646 iRemapState = ERemapNwGeoConverterPending; |
|
647 } |
|
648 else |
|
649 { |
|
650 // go for cell id based geo coding. |
|
651 iRemapState = ERemapNwGeoConverterInProgress; |
|
652 if(iGeoConverter == NULL) |
|
653 { |
|
654 iGeoConverter = CGeoConverter::NewL(*this); |
|
655 } |
|
656 iGeoConverter->ConvertL(iNewItem.iLocationData.iNetworkInfo); |
|
657 iMediaHandlingFlag |= KSnapGeoConvertInProgress; |
|
658 } |
|
659 #endif |
|
660 } |
|
661 #ifdef LOC_REVERSEGEOCODE |
|
662 if((iMediaHandlingFlag & KSnapGeoConvertInProgress) > 0 || |
|
663 (iMediaHandlingFlag & KReverseGeoCodingInProgress) > 0) |
|
664 #else |
|
665 if((iMediaHandlingFlag & KSnapGeoConvertInProgress) > 0 ) |
|
666 #endif //LOC_REVERSEGEOCODE |
|
667 { |
|
668 // stop n/w info change listener, since device may connect to n/w |
|
669 // and local trail will receive so many call backs on current n/w info change. |
|
670 iNetworkInfoChangeListener->StopNwInfoChangeNotifier(); |
|
671 } |
|
672 else |
|
673 { |
|
674 iNetworkInfoChangeListener->StartNwInfoChangeNotifier(); |
|
675 } |
|
676 LOG( "CLocationRecord::RemapObjectsL(), end" ); |
|
677 |
449 } |
678 } |
450 |
679 |
451 TBool CLocationRecord::CheckGPSFix( const TPositionSatelliteInfo& aSatelliteInfo ) |
680 TBool CLocationRecord::CheckGPSFix( const TPositionSatelliteInfo& aSatelliteInfo ) |
452 { |
681 { |
|
682 LOG("CLocationRecord::CheckGPSFix, begin"); |
453 TPosition position; |
683 TPosition position; |
454 aSatelliteInfo.GetPosition( position ); |
684 aSatelliteInfo.GetPosition( position ); |
455 LOG1( "CLocationRecord::CheckGPSFix latitude %f", position.Latitude() ); |
685 LOG1( "latitude %f", position.Latitude() ); |
456 LOG1( "CLocationRecord::CheckGPSFix longitude %f", position.Longitude() ); |
686 LOG1( "longitude %f", position.Longitude() ); |
457 TBool ret = ( Math::IsNaN(position.Latitude()) || Math::IsNaN(position.Longitude()) ) |
687 TBool ret = ( Math::IsNaN(position.Latitude()) || Math::IsNaN(position.Longitude()) ) |
458 ? EFalse : ETrue; |
688 ? EFalse : ETrue; |
|
689 LOG1("CLocationRecord::CheckGPSFix, end. Ret - %d", ret); |
459 return ret; |
690 return ret; |
460 } |
691 } |
461 |
692 |
462 // -------------------------------------------------------------------------- |
693 // -------------------------------------------------------------------------- |
463 // From MPositionerObserver. |
694 // From MPositionerObserver. |
593 |
881 |
594 |
882 |
595 EXPORT_C void CLocationRecord::CreateLocationObjectL( const TLocationData& aLocationData, |
883 EXPORT_C void CLocationRecord::CreateLocationObjectL( const TLocationData& aLocationData, |
596 const TUint& aObjectId ) |
884 const TUint& aObjectId ) |
597 { |
885 { |
598 TItemId locationId = DoCreateLocationL( aLocationData ); |
886 LOG( "CLocationRecord::CreateLocationObjectL(), begin" ); |
599 CreateRelationL( aObjectId, locationId ); |
887 TLocationSnapshotItem* newItem = new (ELeave) TLocationSnapshotItem; |
|
888 newItem->iObjectId = aObjectId; |
|
889 newItem->iLocationData = aLocationData; |
|
890 |
|
891 // for downloaded files, network informations are not valid. |
|
892 // Do location handling only based on lat/lon |
|
893 // all all n/w information to invalid value. |
|
894 newItem->iLocationData.iNetworkInfo.iCellId = 0; |
|
895 newItem->iLocationData.iNetworkInfo.iAccess = CTelephony::ENetworkAccessUnknown; |
|
896 newItem->iLocationData.iNetworkInfo.iLocationAreaCode = 0; |
|
897 newItem->iLocationData.iNetworkInfo.iCountryCode.Zero(); |
|
898 newItem->iLocationData.iNetworkInfo.iNetworkId.Zero(); |
|
899 newItem->iFlag = KDownloadMediaFile; |
|
900 |
|
901 iMediaItems.Append( newItem ); |
|
902 FindLocationFromDBL(); |
|
903 GeoTaggingCompleted(); |
|
904 LOG( "CLocationRecord::CreateLocationObjectL(), end" ); |
|
905 |
600 } |
906 } |
601 |
907 |
602 |
908 // -------------------------------------------------------------------------- |
|
909 // CLocationRecord::LocationSnapshotL |
|
910 // -------------------------------------------------------------------------- |
|
911 // |
603 EXPORT_C void CLocationRecord::LocationSnapshotL( const TUint& aObjectId ) |
912 EXPORT_C void CLocationRecord::LocationSnapshotL( const TUint& aObjectId ) |
604 { |
913 { |
605 LOG("CLocationRecord::LocationSnapshotL"); |
914 LOG( "CLocationRecord::LocationSnapshotL(), begin" ); |
606 |
|
607 TBool previousMatch = EFalse; |
915 TBool previousMatch = EFalse; |
608 CMdENamespaceDef& namespaceDef = iMdeSession->GetDefaultNamespaceDefL(); |
|
609 |
916 |
610 // get locationdata from trail with object time |
917 // get locationdata from trail with object time |
611 TTime timestamp = GetMdeObjectTimeL( aObjectId ); |
918 TTime timestamp = GetMdeObjectTimeL( aObjectId ); |
612 TLocationData locationData; |
919 TLocationData locationData; |
613 TLocTrailState state; |
920 TLocTrailState state; |
614 GetLocationByTimeL( timestamp, locationData, state ); |
921 TRAPD(err, GetLocationByTimeL( timestamp, locationData, state )); |
615 |
922 if(err != KErrNone && iTrailStarted) |
616 iObjectId = aObjectId; |
923 { |
617 iLocationData = locationData; |
924 // Execution shouldn't come over here. |
618 |
925 // Handling error case in worst sceenario.. |
|
926 StartL(iTrailCaptureSetting); |
|
927 // this case may apprear, when cache data is not within the delta limit because someone call stop trail. |
|
928 // sceenario, take photograph, then stop taking for sometime, again take photograph. |
|
929 // during this time, if there is no change in position (because someone stop trail) and n/w, then cache has old value. |
|
930 // go with the n/w based. |
|
931 LOG( "Old trail cache. go for n/w based." ); |
|
932 UpdateNetworkInfo( this ); |
|
933 // again read the location. |
|
934 GetLocationByTimeL( timestamp, locationData, state ); |
|
935 } |
|
936 TLocationSnapshotItem* newItem = new (ELeave) TLocationSnapshotItem; |
|
937 newItem->iObjectId = aObjectId; |
|
938 newItem->iLocationData = locationData; |
|
939 newItem->iFlag = KSnapMediaFile; |
|
940 |
|
941 iMediaItems.Append( newItem ); |
|
942 |
|
943 TItemId lastLocationId = 0; |
|
944 if ( (iLastMediaItem.iFlag & KSnapMediaFile) > 0) |
|
945 { |
|
946 lastLocationId = iLastMediaItem.iLocationId; |
|
947 } |
|
948 |
|
949 CTelephony::TNetworkInfoV1* net = &locationData.iNetworkInfo; |
619 // capture only network data |
950 // capture only network data |
620 if ( iTrailCaptureSetting == RLocationTrail::ECaptureNetworkInfo ) |
951 if ( iTrailCaptureSetting == RLocationTrail::ECaptureNetworkInfo ) |
621 { |
952 { |
622 CTelephony::TNetworkInfoV1* net = &locationData.iNetworkInfo; |
953 if ( net->iCellId == 0 && |
|
954 net->iLocationAreaCode == 0 && |
|
955 net->iCountryCode.Length() == 0 && |
|
956 net->iNetworkId.Length() == 0 ) |
|
957 { |
|
958 // no n/w info... put it into remap. |
|
959 // remove the last appended element. |
|
960 LOG("No network info (offline mode + no GPS fix), keep for remapping"); |
|
961 TRemapItem remapItem; |
|
962 remapItem.iObjectId = aObjectId; |
|
963 remapItem.iTime = timestamp; |
|
964 iRemapper->Append( remapItem ); |
623 |
965 |
|
966 TLocationSnapshotItem* firstPtr = iMediaItems[iMediaItems.Count() - 1]; |
|
967 iMediaItems.Remove(iMediaItems.Count() - 1); |
|
968 iMediaItems.Compress(); |
|
969 delete firstPtr; |
|
970 } |
|
971 else |
|
972 { |
|
973 // n/w info available |
|
974 NetworkInfoSnapshotL(); |
|
975 } |
|
976 } |
|
977 else if ( Math::IsNaN( locationData.iPosition.Latitude() ) && |
|
978 Math::IsNaN( locationData.iPosition.Longitude() )) |
|
979 { |
|
980 // coordinates empty, with or without cellular info |
|
981 |
624 if ( net->iCellId == 0 && |
982 if ( net->iCellId == 0 && |
625 net->iLocationAreaCode == 0 && |
983 net->iLocationAreaCode == 0 && |
626 net->iCountryCode.Length() == 0 && |
984 net->iCountryCode.Length() == 0 && |
627 net->iNetworkId.Length() == 0 ) |
985 net->iNetworkId.Length() == 0 ) |
628 { |
986 { |
629 // nothing to do |
987 LOG("No network info (offline mode + no GPS fix), keep for remapping"); |
630 LOG("CLocationRecord::LocationSnapshotL - no network info available"); |
988 TRemapItem remapItem; |
631 } |
989 remapItem.iObjectId = aObjectId; |
632 else if ( iLastLocationId != 0 ) |
990 remapItem.iTime = timestamp; |
633 { |
991 iRemapper->Append( remapItem ); |
634 CTelephony::TNetworkInfoV1* lastnet = &iLastLocation.iNetworkInfo; |
|
635 |
|
636 // compare to previous network info |
|
637 TItemId locationId = iLastLocationId; |
|
638 if ( lastnet->iCellId != net->iCellId || |
|
639 lastnet->iLocationAreaCode != net->iLocationAreaCode || |
|
640 lastnet->iCountryCode != net->iCountryCode || |
|
641 lastnet->iNetworkId != net->iNetworkId ) |
|
642 { |
|
643 LOG("CLocationRecord::LocationSnapshotL - network info changed"); |
|
644 locationId = DoCreateLocationL( locationData ); |
|
645 } |
|
646 CreateRelationL( aObjectId, locationId ); |
|
647 } |
|
648 else |
|
649 { |
|
650 // new location |
|
651 TItemId locationId = DoCreateLocationL( locationData ); |
|
652 CreateRelationL( aObjectId, locationId ); |
|
653 } |
|
654 return; |
|
655 } |
|
656 |
|
657 // coordinates empty (will be remapped) |
|
658 if ( Math::IsNaN( locationData.iPosition.Latitude() ) && |
|
659 Math::IsNaN( locationData.iPosition.Longitude() )) |
|
660 { |
|
661 TRemapItem remapItem; |
|
662 remapItem.iObjectId = aObjectId; |
|
663 remapItem.iTime = timestamp; |
|
664 |
992 |
665 CTelephony::TNetworkInfoV1* net = &locationData.iNetworkInfo; |
993 TLocationSnapshotItem* firstPtr = iMediaItems[iMediaItems.Count() - 1]; |
666 |
994 iMediaItems.Remove(iMediaItems.Count() - 1); |
667 // no network info (offline mode + no GPS fix) |
995 iMediaItems.Compress(); |
668 if ( net->iCellId == 0 && |
996 delete firstPtr; |
669 net->iLocationAreaCode == 0 && |
|
670 net->iCountryCode.Length() == 0 && |
|
671 net->iNetworkId.Length() == 0 ) |
|
672 { |
|
673 LOG("CLocationRecord::LocationSnapshotL - empty remap item created"); |
|
674 } |
997 } |
675 // check match for last created locationobject |
998 // check match for last created locationobject |
676 else if ( iLastLocationId != 0 ) |
999 #ifdef LOC_REVERSEGEOCODE |
|
1000 else if ( (iLastMediaItem.iFlag & KSnapMediaFile) > 0 && |
|
1001 iLastMediaItem.iCountryTagId > 0) |
|
1002 #else |
|
1003 else if ( (iLastMediaItem.iFlag & KSnapMediaFile) > 0) |
|
1004 #endif //LOC_REVERSEGEOCODE |
677 { |
1005 { |
678 TItemId locationId; |
1006 TLocationData lastLocationData = iLastMediaItem.iLocationData; |
679 CTelephony::TNetworkInfoV1* lastnet = &iLastLocation.iNetworkInfo; |
1007 CTelephony::TNetworkInfoV1* lastnet = &lastLocationData.iNetworkInfo; |
680 |
1008 |
681 // networkinfo changed from last location |
1009 // networkinfo changed from last location |
682 if ( lastnet->iCellId != net->iCellId || |
1010 if ( lastnet->iCellId == net->iCellId && |
683 lastnet->iLocationAreaCode != net->iLocationAreaCode || |
1011 lastnet->iLocationAreaCode == net->iLocationAreaCode && |
684 lastnet->iCountryCode != net->iCountryCode || |
1012 lastnet->iCountryCode == net->iCountryCode && |
685 lastnet->iNetworkId != net->iNetworkId ) |
1013 lastnet->iNetworkId == net->iNetworkId ) |
686 { |
1014 { |
687 LOG("CLocationRecord::LocationSnapshotL - remap with new network info"); |
1015 // same network. |
688 locationId = DoCreateLocationL( locationData ); |
1016 previousMatch = ETrue; |
689 } |
1017 CreateRelationL( aObjectId, lastLocationId ); |
690 else |
1018 // attach same tags associated to last location |
691 { |
1019 #ifdef LOC_REVERSEGEOCODE |
692 LOG("CLocationRecord::LocationSnapshotL - remap with previous network info"); |
1020 if ( iLastMediaItem.iCountryTagId ) //found from DB last time |
693 locationId = iLastLocationId; |
1021 { |
|
1022 iTagCreator->AttachTagsL( aObjectId, |
|
1023 iLastMediaItem.iCountryTagId, iLastMediaItem.iCityTagId ); |
|
1024 } |
|
1025 #endif //LOC_REVERSEGEOCODE |
|
1026 // remove the current item. |
|
1027 TLocationSnapshotItem* firstPtr = iMediaItems[iMediaItems.Count() - 1]; |
|
1028 iMediaItems.Remove(iMediaItems.Count() - 1); |
|
1029 iMediaItems.Compress(); |
|
1030 delete firstPtr; |
694 } |
1031 } |
695 TItemId relationId = CreateRelationL( aObjectId, locationId ); |
|
696 remapItem.iLocationId = locationId; |
|
697 remapItem.iRelationId = relationId; |
|
698 } |
1032 } |
699 else |
1033 |
700 { |
1034 if ( !previousMatch ) |
701 // new location with only network data |
1035 { |
702 TItemId locationId = DoCreateLocationL( locationData ); |
1036 // go for n/w based |
703 TItemId relationId = CreateRelationL( aObjectId, locationId ); |
1037 newItem->iFlag |= KNetQueryBit; |
704 remapItem.iLocationId = locationId; |
1038 } |
705 remapItem.iRelationId = relationId; |
|
706 } |
|
707 iRemapper->Append( remapItem ); |
|
708 return; |
|
709 } |
1039 } |
710 |
1040 |
711 // valid coordinates found |
1041 // valid coordinates found |
712 if ( iLastLocationId != 0 ) |
1042 else if ( lastLocationId != 0 && |
|
1043 ((iLastMediaItem.iFlag & KSnapMediaFile) > 0)) |
713 { |
1044 { |
714 CTelephony::TNetworkInfoV1* net = &locationData.iNetworkInfo; |
1045 TLocationData lastLocationData = iLastMediaItem.iLocationData; |
715 CTelephony::TNetworkInfoV1* lastnet = &iLastLocation.iNetworkInfo; |
1046 CTelephony::TNetworkInfoV1* lastnet = &lastLocationData.iNetworkInfo; |
716 |
1047 |
717 // first check if networkinfo matches last created location |
1048 // first check if networkinfo matches last created location |
718 if ( lastnet->iCellId == net->iCellId && |
1049 if ( lastnet->iCellId == net->iCellId && |
719 lastnet->iLocationAreaCode == net->iLocationAreaCode && |
1050 lastnet->iLocationAreaCode == net->iLocationAreaCode && |
720 lastnet->iCountryCode == net->iCountryCode && |
1051 lastnet->iCountryCode == net->iCountryCode && |
721 lastnet->iNetworkId == net->iNetworkId ) |
1052 lastnet->iNetworkId == net->iNetworkId ) |
722 { |
1053 { |
723 LOG("CLocationRecord::LocationSnapshotL - network info matches"); |
|
724 |
1054 |
725 // if both locations have valid coordinates, calculate distance between points |
1055 // if both locations have valid coordinates, calculate distance between points |
726 if ( !Math::IsNaN( iLastLocation.iPosition.Latitude() ) && |
1056 if ( !Math::IsNaN( lastLocationData.iPosition.Latitude() ) && |
727 !Math::IsNaN( iLastLocation.iPosition.Longitude() ) && |
1057 !Math::IsNaN( lastLocationData.iPosition.Longitude() ) && |
728 !Math::IsNaN( locationData.iPosition.Latitude() ) && |
1058 !Math::IsNaN( locationData.iPosition.Latitude() ) && |
729 !Math::IsNaN( locationData.iPosition.Longitude() )) |
1059 !Math::IsNaN( locationData.iPosition.Longitude() )) |
730 { |
1060 { |
731 TReal32 distance; |
1061 TReal32 distance; |
732 TInt err = locationData.iPosition.Distance(iLastLocation.iPosition, distance); |
1062 TInt err = locationData.iPosition.Distance(lastLocationData.iPosition, distance); |
733 |
1063 |
734 if ( distance < iLocationDelta ) |
1064 if ( distance < iLocationDelta ) |
735 { |
1065 { |
736 LOG("CLocationRecord::LocationSnapshotL - location close to the previous one"); |
1066 LOG("location close to the previous one"); |
737 previousMatch = ETrue; |
1067 previousMatch = ETrue; |
738 CreateRelationL( aObjectId, iLastLocationId ); |
1068 CreateRelationL( aObjectId, lastLocationId ); |
739 LOG("CLocationRecord::CreateLocationObjectL - last location matched"); |
1069 |
|
1070 #ifdef LOC_REVERSEGEOCODE |
|
1071 // attach same tags associated to last location |
|
1072 if ( iLastMediaItem.iCountryTagId ) |
|
1073 { |
|
1074 iTagCreator->AttachTagsL( |
|
1075 aObjectId, iLastMediaItem.iCountryTagId, iLastMediaItem.iCityTagId ); |
|
1076 TLocationSnapshotItem* firstPtr = iMediaItems[iMediaItems.Count() - 1]; |
|
1077 iMediaItems.Remove(iMediaItems.Count() - 1); |
|
1078 iMediaItems.Compress(); |
|
1079 delete firstPtr; |
|
1080 } |
|
1081 else |
|
1082 { |
|
1083 // country tag not found.. go for reverse geocoding.. |
|
1084 newItem->iLocationId = lastLocationId; |
|
1085 iLocationItems.Append( newItem ); |
|
1086 iMediaItems.Remove(iMediaItems.Count() - 1); |
|
1087 iMediaItems.Compress(); |
|
1088 |
|
1089 if(!(iMediaHandlingFlag & KReverseGeoCodingInProgress)) |
|
1090 { |
|
1091 iMediaHandlingFlag |= KReverseGeoCodingInProgress; |
|
1092 if(iRevGeocoderPlugin) |
|
1093 { |
|
1094 iRevGeocoderPlugin->GetAddressByCoordinateL |
|
1095 ( iLocationItems[0]->iLocationData.iPosition, |
|
1096 iConnectionOption); |
|
1097 } |
|
1098 } |
|
1099 } |
|
1100 #else |
|
1101 // remove from the queue |
|
1102 TLocationSnapshotItem* firstPtr = iMediaItems[iMediaItems.Count() - 1]; |
|
1103 iMediaItems.Remove(iMediaItems.Count() - 1); |
|
1104 iMediaItems.Compress(); |
|
1105 delete firstPtr; |
|
1106 |
|
1107 #endif //LOC_REVERSEGEOCODE |
740 } |
1108 } |
741 } |
1109 } |
742 } |
1110 } |
743 } |
1111 } |
744 |
1112 |
745 // last location did not match, find existing one from DB |
1113 // last location did not match, find existing one from DB |
746 if( !previousMatch ) |
1114 if( !previousMatch ) |
747 { |
1115 { |
748 LOG("CLocationRecord::LocationSnapshotL - query location"); |
1116 FindLocationFromDBL(); |
749 const TReal64 KMeterInDegrees = 0.000009; |
|
750 const TReal64 KPi = 3.14159265358979; |
|
751 const TReal32 K180Degrees = 180.0; |
|
752 |
|
753 TReal64 latitude = locationData.iPosition.Latitude(); |
|
754 TReal64 longitude = locationData.iPosition.Longitude(); |
|
755 // calculate distance in degrees |
|
756 TReal64 cosine; |
|
757 Math::Cos(cosine, locationData.iPosition.Latitude() * KPi / K180Degrees ); |
|
758 TReal64 latDelta = iLocationDelta * KMeterInDegrees; |
|
759 TReal64 lonDelta = latDelta * cosine; |
|
760 |
|
761 CMdEObjectDef& locationObjectDef = namespaceDef.GetObjectDefL( Location::KLocationObject ); |
|
762 |
|
763 CMdEPropertyDef& latitudeDef = locationObjectDef.GetPropertyDefL( |
|
764 Location::KLatitudeProperty ); |
|
765 CMdEPropertyDef& longitudeDef = locationObjectDef.GetPropertyDefL( |
|
766 Location::KLongitudeProperty ); |
|
767 CMdEPropertyDef& cellIdDef = locationObjectDef.GetPropertyDefL( |
|
768 Location::KCellIdProperty ); |
|
769 CMdEPropertyDef& locationCodeDef = locationObjectDef.GetPropertyDefL( |
|
770 Location::KLocationAreaCodeProperty ); |
|
771 CMdEPropertyDef& countryCodeDef = locationObjectDef.GetPropertyDefL( |
|
772 Location::KCountryCodeProperty ); |
|
773 CMdEPropertyDef& networkCodeDef = locationObjectDef.GetPropertyDefL( |
|
774 Location::KNetworkCodeProperty ); |
|
775 |
|
776 iLocationQuery = iMdeSession->NewObjectQueryL( namespaceDef, locationObjectDef, this ); |
|
777 CMdELogicCondition& cond = iLocationQuery->Conditions(); |
|
778 cond.SetOperator( ELogicConditionOperatorAnd ); |
|
779 |
|
780 LOG1( "CLocationRecord::LocationSnapshotL latitude: %f", latitude); |
|
781 LOG1( "CLocationRecord::LocationSnapshotL latdelta: %f", latDelta); |
|
782 LOG1( "CLocationRecord::LocationSnapshotL longitude: %f", longitude); |
|
783 LOG1( "CLocationRecord::LocationSnapshotL londelta: %f", lonDelta); |
|
784 |
|
785 cond.AddPropertyConditionL( latitudeDef, |
|
786 TMdERealBetween( latitude - latDelta, latitude + latDelta )); |
|
787 cond.AddPropertyConditionL( longitudeDef, |
|
788 TMdERealBetween( longitude - lonDelta, longitude + lonDelta )); |
|
789 cond.AddPropertyConditionL( cellIdDef, |
|
790 TMdEUintEqual( locationData.iNetworkInfo.iCellId) ); |
|
791 cond.AddPropertyConditionL( locationCodeDef, |
|
792 TMdEUintEqual( locationData.iNetworkInfo.iLocationAreaCode) ); |
|
793 cond.AddPropertyConditionL( countryCodeDef, ETextPropertyConditionCompareEquals, |
|
794 locationData.iNetworkInfo.iCountryCode ); |
|
795 cond.AddPropertyConditionL( networkCodeDef, ETextPropertyConditionCompareEquals, |
|
796 locationData.iNetworkInfo.iNetworkId ); |
|
797 |
|
798 iLocationQuery->FindL(); |
|
799 } |
1117 } |
|
1118 LOG( "CLocationRecord::LocationSnapshotL(), end" ); |
800 } |
1119 } |
801 |
1120 |
802 |
1121 |
803 TItemId CLocationRecord::DoCreateLocationL( const TLocationData& aLocationData ) |
1122 // -------------------------------------------------------------------------- |
|
1123 // CLocationRecord::NetworkInfoSnapshotL |
|
1124 // -------------------------------------------------------------------------- |
|
1125 // |
|
1126 void CLocationRecord::NetworkInfoSnapshotL() |
|
1127 { |
|
1128 LOG( "CLocationRecord::NetworkInfoSnapshotL(), begin" ); |
|
1129 // n/w info available.. always act on last element within the queue |
|
1130 TInt lastItemIndex = iMediaItems.Count() - 1; |
|
1131 if ( lastItemIndex >= 0 && |
|
1132 (iMediaItems[lastItemIndex]->iFlag & KSnapMediaFile) > 0 ) |
|
1133 { |
|
1134 CTelephony::TNetworkInfoV1* net = &iMediaItems[lastItemIndex]->iLocationData.iNetworkInfo; |
|
1135 //only for snap item. |
|
1136 if ( (iLastMediaItem.iFlag & KSnapMediaFile) > 0 ) |
|
1137 { |
|
1138 CTelephony::TNetworkInfoV1* lastnet = &iLastMediaItem.iLocationData.iNetworkInfo; |
|
1139 |
|
1140 // compare to previous network info |
|
1141 TItemId locationId = iLastMediaItem.iLocationId; |
|
1142 if ( lastnet->iCellId != net->iCellId || |
|
1143 lastnet->iLocationAreaCode != net->iLocationAreaCode || |
|
1144 lastnet->iCountryCode != net->iCountryCode || |
|
1145 lastnet->iNetworkId != net->iNetworkId ) |
|
1146 { |
|
1147 // last one is not matching. |
|
1148 // let's check the database of any existing etry. |
|
1149 iMediaItems[lastItemIndex]->iFlag |= KNetQueryBit; |
|
1150 } |
|
1151 else |
|
1152 { |
|
1153 // matching with the last entry. Just create a relation. |
|
1154 CreateRelationL( iMediaItems[lastItemIndex]->iObjectId, locationId ); |
|
1155 TLocationSnapshotItem* firstPtr = iMediaItems[lastItemIndex]; |
|
1156 iMediaItems.Remove(lastItemIndex); |
|
1157 delete firstPtr; |
|
1158 } |
|
1159 } |
|
1160 else |
|
1161 { |
|
1162 // let's check the database of any existing etry. |
|
1163 iMediaItems[lastItemIndex]->iFlag |= KNetQueryBit; |
|
1164 } |
|
1165 } |
|
1166 LOG( "CLocationRecord::NetworkInfoSnapshotL(), end" ); |
|
1167 } |
|
1168 |
|
1169 |
|
1170 // -------------------------------------------------------------------------- |
|
1171 // CLocationRecord::FindLocationFromDBL |
|
1172 // -------------------------------------------------------------------------- |
|
1173 // |
|
1174 void CLocationRecord::FindLocationFromDBL() |
|
1175 { |
|
1176 LOG( "CLocationRecord::FindLocationFromDBL(), begin" ); |
|
1177 if(((iMediaHandlingFlag & KLocationQueryInProgress)> 0) |
|
1178 || (iMediaItems.Count() <= 0)) |
|
1179 { |
|
1180 // query is in progress or queue is empty |
|
1181 LOG1( "query is in progress or queue is empty. Count - %d", iMediaItems.Count() ); |
|
1182 return; |
|
1183 } |
|
1184 if ( (iMediaItems[0]->iFlag & KNetQueryBit) > 0 ) |
|
1185 { |
|
1186 // n/w based. |
|
1187 FindLocationWithSameNetInfoL(); |
|
1188 return; |
|
1189 } |
|
1190 |
|
1191 const TReal64 KMeterInDegrees = 0.000009; |
|
1192 const TReal64 KPi = 3.14159265358979; |
|
1193 const TReal32 K180Degrees = 180.0; |
|
1194 |
|
1195 //TLocationData locationData = iMediaItems[0].iLocationData; |
|
1196 |
|
1197 TReal64 latitude = iMediaItems[0]->iLocationData.iPosition.Latitude(); |
|
1198 TReal64 longitude = iMediaItems[0]->iLocationData.iPosition.Longitude(); |
|
1199 // calculate distance in degrees |
|
1200 TReal64 cosine; |
|
1201 Math::Cos(cosine, latitude * KPi / K180Degrees ); |
|
1202 TReal64 latDelta = iLocationDelta * KMeterInDegrees; |
|
1203 TReal64 lonDelta = latDelta * cosine; |
|
1204 |
|
1205 //get network related defs |
|
1206 CMdEPropertyDef& cellIdDef = iLocationObjectDef->GetPropertyDefL( |
|
1207 Location::KCellIdProperty ); |
|
1208 CMdEPropertyDef& locationCodeDef = iLocationObjectDef->GetPropertyDefL( |
|
1209 Location::KLocationAreaCodeProperty ); |
|
1210 CMdEPropertyDef& countryCodeDef = iLocationObjectDef->GetPropertyDefL( |
|
1211 Location::KCountryCodeProperty ); |
|
1212 CMdEPropertyDef& networkCodeDef = iLocationObjectDef->GetPropertyDefL( |
|
1213 Location::KNetworkCodeProperty ); |
|
1214 if(iLocationQuery) |
|
1215 { |
|
1216 iLocationQuery->RemoveObserver(*this); |
|
1217 iLocationQuery->Cancel(); |
|
1218 delete iLocationQuery; |
|
1219 iLocationQuery = NULL; |
|
1220 } |
|
1221 iLocationQuery = iMdeSession->NewObjectQueryL( *iNamespaceDef, *iLocationObjectDef, this ); |
|
1222 |
|
1223 CMdELogicCondition& cond = iLocationQuery->Conditions(); |
|
1224 cond.SetOperator( ELogicConditionOperatorAnd ); |
|
1225 |
|
1226 LOG1( "latitude: %f", latitude); |
|
1227 LOG1( "latdelta: %f", latDelta); |
|
1228 LOG1( "longitude: %f", longitude); |
|
1229 LOG1( "londelta: %f", lonDelta); |
|
1230 |
|
1231 cond.AddPropertyConditionL( *iLatitudeDef, |
|
1232 TMdERealBetween( latitude - latDelta, latitude + latDelta )); |
|
1233 cond.AddPropertyConditionL( *iLongitudeDef, |
|
1234 TMdERealBetween( longitude - lonDelta, longitude + lonDelta )); |
|
1235 |
|
1236 if ( iMediaItems[0]->iLocationData.iNetworkInfo.iCellId > 0 ) |
|
1237 { |
|
1238 cond.AddPropertyConditionL( cellIdDef, |
|
1239 TMdEUintEqual( iMediaItems[0]->iLocationData.iNetworkInfo.iCellId) ); |
|
1240 } |
|
1241 if ( iMediaItems[0]->iLocationData.iNetworkInfo.iLocationAreaCode > 0 ) |
|
1242 { |
|
1243 cond.AddPropertyConditionL( locationCodeDef, |
|
1244 TMdEUintEqual( iMediaItems[0]->iLocationData.iNetworkInfo.iLocationAreaCode) ); |
|
1245 } |
|
1246 if ( iMediaItems[0]->iLocationData.iNetworkInfo.iCountryCode.Length() > 0 ) |
|
1247 { |
|
1248 cond.AddPropertyConditionL( countryCodeDef, ETextPropertyConditionCompareEquals, |
|
1249 iMediaItems[0]->iLocationData.iNetworkInfo.iCountryCode ); |
|
1250 } |
|
1251 if ( iMediaItems[0]->iLocationData.iNetworkInfo.iNetworkId.Length() > 0 ) |
|
1252 { |
|
1253 cond.AddPropertyConditionL( networkCodeDef, ETextPropertyConditionCompareEquals, |
|
1254 iMediaItems[0]->iLocationData.iNetworkInfo.iNetworkId ); |
|
1255 } |
|
1256 iMediaHandlingFlag |= KLocationQueryInProgress; |
|
1257 iLocationQuery->FindL(); |
|
1258 |
|
1259 LOG( "CLocationRecord::FindLocationFromDBL(), end" ); |
|
1260 } |
|
1261 |
|
1262 |
|
1263 // -------------------------------------------------------------------------- |
|
1264 // CLocationRecord::DoCreateLocationL |
|
1265 // -------------------------------------------------------------------------- |
|
1266 // |
|
1267 TItemId CLocationRecord::DoCreateLocationL( const TLocationData& aLocationData ) |
804 { |
1268 { |
805 LOG("CLocationRecord::DoCreateLocationL - start"); |
1269 LOG( "CLocationRecord::DoCreateLocationL(), begin" ); |
806 TItemId locationObjectId; |
1270 TItemId locationObjectId; |
807 |
1271 |
808 CMdENamespaceDef& namespaceDef = iMdeSession->GetDefaultNamespaceDefL(); |
|
809 |
|
810 CMdEObjectDef& locationObjectDef = namespaceDef.GetObjectDefL( Location::KLocationObject ); |
|
811 |
|
812 // required object properties |
1272 // required object properties |
813 CMdEPropertyDef& creationDef = locationObjectDef.GetPropertyDefL( |
1273 CMdEPropertyDef& creationDef = iLocationObjectDef->GetPropertyDefL( |
814 Object::KCreationDateProperty ); |
1274 Object::KCreationDateProperty ); |
815 CMdEPropertyDef& modifiedDef = locationObjectDef.GetPropertyDefL( |
1275 CMdEPropertyDef& modifiedDef = iLocationObjectDef->GetPropertyDefL( |
816 Object::KLastModifiedDateProperty ); |
1276 Object::KLastModifiedDateProperty ); |
817 CMdEPropertyDef& sizeDef = locationObjectDef.GetPropertyDefL( |
1277 CMdEPropertyDef& sizeDef = iLocationObjectDef->GetPropertyDefL( |
818 Object::KSizeProperty ); |
1278 Object::KSizeProperty ); |
819 CMdEPropertyDef& itemTypeDef = locationObjectDef.GetPropertyDefL( |
1279 CMdEPropertyDef& itemTypeDef = iLocationObjectDef->GetPropertyDefL( |
820 Object::KItemTypeProperty ); |
1280 Object::KItemTypeProperty ); |
821 CMdEPropertyDef& offSetDef = locationObjectDef.GetPropertyDefL( |
1281 CMdEPropertyDef& offSetDef = iLocationObjectDef->GetPropertyDefL( |
822 Object::KTimeOffsetProperty ); |
1282 Object::KTimeOffsetProperty ); |
823 |
1283 |
824 // location related properties |
1284 // location related properties |
825 CMdEPropertyDef& cellIdDef = locationObjectDef.GetPropertyDefL( |
1285 CMdEPropertyDef& cellIdDef = iLocationObjectDef->GetPropertyDefL( |
826 Location::KCellIdProperty ); |
1286 Location::KCellIdProperty ); |
827 CMdEPropertyDef& latitudeDef = locationObjectDef.GetPropertyDefL( |
1287 CMdEPropertyDef& directionDef = iLocationObjectDef->GetPropertyDefL( |
828 Location::KLatitudeProperty ); |
|
829 CMdEPropertyDef& longitudeDef = locationObjectDef.GetPropertyDefL( |
|
830 Location::KLongitudeProperty ); |
|
831 CMdEPropertyDef& altitudeDef = locationObjectDef.GetPropertyDefL( |
|
832 Location::KAltitudeProperty ); |
|
833 |
|
834 CMdEPropertyDef& directionDef = locationObjectDef.GetPropertyDefL( |
|
835 Location::KDirectionProperty ); |
1288 Location::KDirectionProperty ); |
836 CMdEPropertyDef& speedDef = locationObjectDef.GetPropertyDefL( |
1289 CMdEPropertyDef& speedDef = iLocationObjectDef->GetPropertyDefL( |
837 Location::KSpeedProperty ); |
1290 Location::KSpeedProperty ); |
838 CMdEPropertyDef& locationCodeDef = locationObjectDef.GetPropertyDefL( |
1291 CMdEPropertyDef& locationCodeDef = iLocationObjectDef->GetPropertyDefL( |
839 Location::KLocationAreaCodeProperty ); |
1292 Location::KLocationAreaCodeProperty ); |
840 CMdEPropertyDef& countryCodeDef = locationObjectDef.GetPropertyDefL( |
1293 CMdEPropertyDef& countryCodeDef = iLocationObjectDef->GetPropertyDefL( |
841 Location::KCountryCodeProperty ); |
1294 Location::KCountryCodeProperty ); |
842 CMdEPropertyDef& networkCodeDef = locationObjectDef.GetPropertyDefL( |
1295 CMdEPropertyDef& networkCodeDef = iLocationObjectDef->GetPropertyDefL( |
843 Location::KNetworkCodeProperty ); |
1296 Location::KNetworkCodeProperty ); |
844 CMdEPropertyDef& qualityDef = locationObjectDef.GetPropertyDefL( |
1297 CMdEPropertyDef& qualityDef = iLocationObjectDef->GetPropertyDefL( |
845 Location::KQualityProperty ); |
1298 Location::KQualityProperty ); |
846 |
1299 |
847 // location object |
1300 // location object |
848 CMdEObject* locationObject = NULL; |
1301 CMdEObject* locationObject = NULL; |
849 |
1302 |
850 locationObject = iMdeSession->NewObjectL( locationObjectDef, Object::KAutomaticUri ); |
1303 locationObject = iMdeSession->NewObjectL( *iLocationObjectDef, Object::KAutomaticUri ); |
851 CleanupStack::PushL( locationObject ); |
1304 CleanupStack::PushL( locationObject ); |
852 |
1305 |
853 TTime timestamp( 0 ); |
1306 TTime timestamp( 0 ); |
854 timestamp.UniversalTime(); |
1307 timestamp.UniversalTime(); |
855 |
1308 |
966 User::LeaveIfError(repository->Get( aKey, aValue)); |
1419 User::LeaveIfError(repository->Get( aKey, aValue)); |
967 CleanupStack::PopAndDestroy(repository); |
1420 CleanupStack::PopAndDestroy(repository); |
968 LOG( "CLocationRecord::::ReadCenRepValueL(), end" ); |
1421 LOG( "CLocationRecord::::ReadCenRepValueL(), end" ); |
969 } |
1422 } |
970 |
1423 |
|
1424 |
|
1425 // -------------------------------------------------------------------------- |
|
1426 // CLocationRecord::HandleQueryNewResults |
|
1427 // -------------------------------------------------------------------------- |
|
1428 // |
971 void CLocationRecord::HandleQueryNewResults(CMdEQuery& /*aQuery*/, TInt /*aFirstNewItemIndex*/, |
1429 void CLocationRecord::HandleQueryNewResults(CMdEQuery& /*aQuery*/, TInt /*aFirstNewItemIndex*/, |
972 TInt /*aNewItemCount*/) |
1430 TInt /*aNewItemCount*/) |
973 { |
1431 { |
974 } |
1432 } |
975 |
1433 |
|
1434 |
|
1435 // -------------------------------------------------------------------------- |
|
1436 // CLocationRecord::HandleQueryCompleted |
|
1437 // -------------------------------------------------------------------------- |
|
1438 // |
976 void CLocationRecord::HandleQueryCompleted(CMdEQuery& aQuery, TInt aError) |
1439 void CLocationRecord::HandleQueryCompleted(CMdEQuery& aQuery, TInt aError) |
977 { |
1440 { |
978 LOG("CLocationRecord::HandleQueryCompleted - start"); |
1441 LOG("CLocationRecord::HandleQueryCompleted - start"); |
979 const TInt count = aQuery.Count(); |
1442 const TInt count = aQuery.Count(); |
980 LOG1("CLocationRecord::HandleQueryCompleted count: %d", count); |
1443 LOG1("CLocationRecord::HandleQueryCompleted count: %d", count); |
981 |
1444 |
982 CMdENamespaceDef* namespaceDef = NULL; |
1445 if ( aError != KErrNone ) |
983 |
1446 { |
984 TRAP_IGNORE( namespaceDef = &iMdeSession->GetDefaultNamespaceDefL() ); |
1447 HandleQueryFailure(); |
985 if ( namespaceDef ) |
1448 } |
986 { |
1449 |
987 CMdEObjectDef* locationObjectDef = NULL; |
1450 else if ( &aQuery == iLocationQuery ) |
988 |
1451 { |
989 TRAP_IGNORE( locationObjectDef = &namespaceDef->GetObjectDefL( Location::KLocationObject ) ); |
1452 |
990 if ( locationObjectDef ) |
1453 TRAPD(err,HandleLocationQueryL( aQuery )); |
991 { |
1454 if(err != KErrNone) |
992 CMdEPropertyDef* latitudeDef = NULL; |
1455 { |
993 CMdEPropertyDef* longitudeDef = NULL; |
1456 // unable to process the first node.. |
994 CMdEPropertyDef* altitudeDef = NULL; |
1457 // remove this and process the next. |
995 |
1458 |
996 TRAP_IGNORE( |
1459 // reset the flag |
997 latitudeDef = &locationObjectDef->GetPropertyDefL( |
1460 HandleQueryFailure(); |
998 Location::KLatitudeProperty ); |
1461 } |
999 longitudeDef = &locationObjectDef->GetPropertyDefL( |
1462 |
1000 Location::KLongitudeProperty ); |
1463 } |
1001 altitudeDef = &locationObjectDef->GetPropertyDefL( |
1464 else if ( &aQuery == iNetLocationQuery ) |
1002 Location::KAltitudeProperty ); |
1465 { |
1003 ); |
1466 TRAPD(err,HandleNetLocationQueryL( aQuery )); |
1004 |
1467 if(err != KErrNone) |
1005 if( latitudeDef && longitudeDef && altitudeDef ) |
1468 { |
1006 { |
1469 // unable to process the first node.. |
1007 TBool created = EFalse; |
1470 // remove this and process the next. |
1008 for ( TInt i = 0; i < count; i++ ) |
1471 HandleQueryFailure(); |
1009 { |
1472 } |
1010 LOG1("CLocationRecord::HandleQueryCompleted check item: %d", i); |
1473 |
1011 CMdEItem& item = aQuery.ResultItem(i); |
1474 } |
1012 CMdEObject& locationObject = static_cast<CMdEObject&>(item); |
1475 |
1013 |
1476 #ifdef LOC_REVERSEGEOCODE |
1014 CMdEProperty* latProp = NULL; |
1477 else if ( &aQuery == iImageQuery ) |
1015 CMdEProperty* lonProp = NULL; |
1478 { |
1016 CMdEProperty* altProp = NULL; |
1479 if(aQuery.Count() > 0) |
1017 |
1480 { |
1018 locationObject.Property( *latitudeDef, latProp, 0 ); |
1481 |
1019 locationObject.Property( *longitudeDef, lonProp, 0 ); |
1482 CMdERelation& relation = static_cast<CMdERelation&>( aQuery.ResultItem( 0 ) ); |
1020 locationObject.Property( *altitudeDef, altProp, 0 ); |
1483 |
1021 |
1484 TItemId imageId = relation.LeftObjectId(); |
1022 if ( latProp && lonProp ) |
1485 |
1023 { |
1486 TRAPD(err, GetTagsL( imageId ) ); |
1024 TReal32 distance; |
1487 if(err != KErrNone) |
1025 TCoordinate newCoords; |
1488 { |
1026 if ( altProp ) |
1489 // unable to process the first node.. |
1027 { |
1490 // remove this and process the next. |
1028 TRAP_IGNORE( newCoords = TCoordinate( latProp->Real64ValueL(), lonProp->Real64ValueL(), (TReal32)altProp->Real64ValueL() ) ); |
1491 |
1029 } |
1492 // reset the flag |
1030 else |
1493 HandleQueryFailure(); |
1031 { |
1494 } |
1032 TRAP_IGNORE( newCoords = TCoordinate( latProp->Real64ValueL(), lonProp->Real64ValueL() ) ); |
1495 } |
1033 } |
1496 else |
1034 |
1497 { |
1035 const TInt err = iLocationData.iPosition.Distance(newCoords, distance); |
1498 HandleQueryFailure(); |
1036 |
1499 } |
1037 if ( distance < iLocationDelta ) |
1500 } |
1038 { |
1501 |
1039 LOG("CLocationRecord::HandleQueryCompleted - match found in db"); |
1502 else if ( &aQuery == iTagQuery ) |
1040 TRAPD( err, CreateRelationL( iObjectId, locationObject.Id() ) ); |
1503 { |
1041 if( err == KErrNone) |
1504 TRAPD(err, HandleTagQueryL( aQuery ) ); |
1042 { |
1505 |
1043 created = ETrue; |
1506 GeoTaggingCompleted(); |
1044 i = count; |
1507 if(err != KErrNone) |
1045 } |
1508 { |
1046 else |
1509 // unable to process the first node.. |
1047 { |
1510 // remove this and process the next. |
1048 aError = err; |
1511 |
1049 } |
1512 // reset the flag |
1050 } |
1513 HandleQueryFailure(); |
1051 } |
1514 } |
1052 } |
1515 } |
1053 |
1516 #endif //LOC_REVERSEGEOCODE |
1054 if ( !created && aError == KErrNone ) |
1517 else |
1055 { |
1518 { |
1056 LOG("CLocationRecord::HandleQueryCompleted - no match found in db, create new"); |
1519 // execution should not come over here...still take recovery action. |
1057 TInt locationId( 0 ); |
1520 HandleQueryFailure(); |
1058 TRAPD( err, locationId = DoCreateLocationL( iLocationData ) ); |
1521 } |
1059 LOG1("CLocationRecord::HandleQueryCompleted - DoCreateLocationL err: %d", err); |
1522 GeoTaggingCompleted(); |
1060 if( err == KErrNone ) |
1523 LOG( "CLocationRecord::HandleQueryCompleted(), end" ); |
1061 { |
1524 } |
1062 TRAP( err, CreateRelationL( iObjectId, locationId )); |
1525 |
1063 LOG1("CLocationRecord::HandleQueryCompleted - CreateRelationL err: %d", err); |
1526 // -------------------------------------------------------------------------- |
1064 } |
1527 // CLocationRecord::HandleQueryFailure() |
1065 } |
1528 // handle MDS query sceenario |
1066 } |
1529 // -------------------------------------------------------------------------- |
1067 } |
1530 // |
1068 } |
1531 void CLocationRecord::HandleQueryFailure() |
1069 |
1532 { |
1070 LOG("CLocationRecord::HandleQueryCompleted - end"); |
1533 LOG( "CLocationRecord::HandleQueryFailure(), begin" ); |
1071 } |
1534 iMediaHandlingFlag &= ~KLocationQueryInProgress; |
1072 |
1535 if ( iMediaItems.Count() > 0 ) |
|
1536 { |
|
1537 TLocationSnapshotItem* firstPtr = iMediaItems[0]; |
|
1538 iMediaItems.Remove(0); |
|
1539 delete firstPtr; |
|
1540 iMediaItems.Compress(); |
|
1541 HandleFindLocationFromDB(); |
|
1542 } |
|
1543 LOG( "CLocationRecord::HandleQueryFailure(), end" ); |
|
1544 } |
|
1545 |
|
1546 // -------------------------------------------------------------------------- |
|
1547 // CLocationRecord::HandleFindLocationFromDB() |
|
1548 // handle find location from DB within the non leaving method |
|
1549 // -------------------------------------------------------------------------- |
|
1550 // |
|
1551 void CLocationRecord::HandleFindLocationFromDB() |
|
1552 { |
|
1553 LOG( "CLocationRecord::HandleFindLocationFromDB(), begin" ); |
|
1554 if ( iMediaItems.Count() > 0 ) |
|
1555 { |
|
1556 //TODO: by module owner |
|
1557 TInt trapErr = KErrNone; |
|
1558 TRAP(trapErr,FindLocationFromDBL()); |
|
1559 // no memory, don't proceed further |
|
1560 // other error sceenario, we can move the node to the end and process the next |
|
1561 if(trapErr != KErrNoMemory && trapErr != KErrNone) |
|
1562 { |
|
1563 // other than no memory |
|
1564 TInt numberOfNodes = iMediaItems.Count(); |
|
1565 LOG1("media count - %d\n", numberOfNodes); |
|
1566 while(--numberOfNodes >= 0 && |
|
1567 trapErr != KErrNoMemory && |
|
1568 trapErr != KErrNone) |
|
1569 { |
|
1570 // first remove the node |
|
1571 TLocationSnapshotItem* firstPtr = iMediaItems[0]; |
|
1572 iMediaItems.Remove(0); |
|
1573 // move this to last |
|
1574 iMediaItems.Append(firstPtr); |
|
1575 iMediaItems.Compress(); |
|
1576 trapErr = KErrNone; |
|
1577 // process for the next till we reached the last node. |
|
1578 TRAP(trapErr,FindLocationFromDBL()); |
|
1579 } |
|
1580 } |
|
1581 } |
|
1582 LOG( "CLocationRecord::HandleFindLocationFromDB(), end" ); |
|
1583 } |
|
1584 |
|
1585 |
|
1586 // -------------------------------------------------------------------------- |
|
1587 // CLocationRecord::HandleLocationQuery() |
|
1588 // handle if only gps info available |
|
1589 // -------------------------------------------------------------------------- |
|
1590 // |
|
1591 void CLocationRecord::HandleLocationQueryL( CMdEQuery& aQuery ) |
|
1592 { |
|
1593 LOG( "CLocationRecord::HandleLocationQueryL(), begin" ); |
|
1594 TInt error = KErrNone; |
|
1595 TUint locationId( 0 ); |
|
1596 if ( iMediaItems.Count() <= 0 ) |
|
1597 { |
|
1598 LOG("CLocationRecord::HandleLocationQueryL. No media items to process"); |
|
1599 return; |
|
1600 } |
|
1601 |
|
1602 TLocationData locationData = iMediaItems[0]->iLocationData; |
|
1603 |
|
1604 const TInt count = aQuery.Count(); |
|
1605 //find any location matches |
|
1606 for ( TInt i = 0; i < count; i++ ) |
|
1607 { |
|
1608 LOG1("CLocationRecord::HandleLocationQueryL check item: %d", i); |
|
1609 CMdEItem& item = aQuery.ResultItem(i); |
|
1610 CMdEObject& locationObject = static_cast<CMdEObject&>(item); |
|
1611 |
|
1612 CMdEProperty* latProp = NULL; |
|
1613 CMdEProperty* lonProp = NULL; |
|
1614 CMdEProperty* altProp = NULL; |
|
1615 |
|
1616 locationObject.Property( *iLatitudeDef, latProp, 0 ); |
|
1617 locationObject.Property( *iLongitudeDef, lonProp, 0 ); |
|
1618 locationObject.Property( *iAltitudeDef, altProp, 0 ); |
|
1619 |
|
1620 if ( latProp && lonProp ) |
|
1621 { |
|
1622 TReal32 distance; |
|
1623 TCoordinate newCoords; |
|
1624 |
|
1625 TReal64 lat = latProp->Real64ValueL(); |
|
1626 TReal64 lon = lonProp->Real64ValueL(); |
|
1627 if ( altProp ) |
|
1628 { |
|
1629 TReal32 alt = (TReal32)altProp->Real64ValueL(); |
|
1630 newCoords = TCoordinate( lat, lon, alt ); |
|
1631 } |
|
1632 else |
|
1633 { |
|
1634 newCoords = TCoordinate( lat, lon ); |
|
1635 } |
|
1636 |
|
1637 locationData.iPosition.Distance(newCoords, distance); |
|
1638 |
|
1639 if ( distance < iLocationDelta ) |
|
1640 { |
|
1641 i = count; |
|
1642 locationId = locationObject.Id(); |
|
1643 iMediaItems[0]->iLocationId = locationId; |
|
1644 break; |
|
1645 } |
|
1646 } |
|
1647 } |
|
1648 |
|
1649 |
|
1650 if ( locationId ) |
|
1651 { |
|
1652 TRAP( error, CreateRelationL( iMediaItems[0]->iObjectId, locationId ) ); |
|
1653 |
|
1654 #ifdef LOC_REVERSEGEOCODE |
|
1655 if( error == KErrNone) |
|
1656 { |
|
1657 //find out if image for this location is tagged already |
|
1658 GetRelatedImageL( locationId ); |
|
1659 } |
|
1660 #else |
|
1661 TLocationSnapshotItem* firstPtr = iMediaItems[0]; |
|
1662 iMediaItems.Remove(0); |
|
1663 delete firstPtr; |
|
1664 iMediaItems.Compress(); |
|
1665 iMediaHandlingFlag &= ~KLocationQueryInProgress; |
|
1666 if ( iMediaItems.Count() > 0 ) |
|
1667 { |
|
1668 FindLocationFromDBL(); |
|
1669 } |
|
1670 #endif //LOC_REVERSEGEOCODE |
|
1671 } |
|
1672 else |
|
1673 { |
|
1674 |
|
1675 if((iMediaItems[0]->iFlag & KDownloadMediaFile) > 0) |
|
1676 { |
|
1677 locationData.iNetworkInfo.iCellId = 0; |
|
1678 locationData.iNetworkInfo.iAccess = CTelephony::ENetworkAccessUnknown; |
|
1679 locationData.iNetworkInfo.iLocationAreaCode = 0; |
|
1680 locationData.iNetworkInfo.iCountryCode.Zero(); |
|
1681 locationData.iNetworkInfo.iNetworkId.Zero(); |
|
1682 } |
|
1683 TRAP( error, locationId = DoCreateLocationL( locationData ) ); |
|
1684 |
|
1685 if ( error == KErrNone ) |
|
1686 { |
|
1687 iMediaItems[0]->iLocationId = locationId; |
|
1688 TRAP( error, CreateRelationL( iMediaItems[0]->iObjectId, locationId )); |
|
1689 } |
|
1690 |
|
1691 TLocationSnapshotItem* item = iMediaItems[0]; |
|
1692 if((iMediaItems[0]->iFlag & KSnapMediaFile) > 0) |
|
1693 { |
|
1694 iLastMediaItem = *(iMediaItems[0]); |
|
1695 } |
|
1696 iMediaItems.Remove(0); |
|
1697 iMediaItems.Compress(); |
|
1698 iMediaHandlingFlag &= ~KLocationQueryInProgress; |
|
1699 if ( error == KErrNone ) |
|
1700 { |
|
1701 //Find the address by coordinate, results a call to ReverseGeocodeComplete() |
|
1702 #ifdef LOC_REVERSEGEOCODE |
|
1703 iLocationItems.Append( item ); |
|
1704 if(!(iMediaHandlingFlag & KReverseGeoCodingInProgress)) |
|
1705 { |
|
1706 iMediaHandlingFlag |= KReverseGeoCodingInProgress; |
|
1707 |
|
1708 if(iRevGeocoderPlugin) |
|
1709 { |
|
1710 iRevGeocoderPlugin->GetAddressByCoordinateL |
|
1711 ( iLocationItems[0]->iLocationData.iPosition, |
|
1712 iConnectionOption); |
|
1713 } |
|
1714 } |
|
1715 #else |
|
1716 // free resources |
|
1717 delete item; |
|
1718 #endif //LOC_REVERSEGEOCODE |
|
1719 } |
|
1720 else |
|
1721 { |
|
1722 // free resources |
|
1723 delete item; |
|
1724 } |
|
1725 |
|
1726 if ( iMediaItems.Count() > 0 ) |
|
1727 { |
|
1728 FindLocationFromDBL(); |
|
1729 } |
|
1730 } |
|
1731 LOG( "CLocationRecord::HandleLocationQueryL(), end" ); |
|
1732 |
|
1733 } |
|
1734 |
|
1735 // -------------------------------------------------------------------------- |
|
1736 // CLocationRecord::HandleNetLocationQuery() |
|
1737 // handle if only network info available |
|
1738 // -------------------------------------------------------------------------- |
|
1739 // |
|
1740 void CLocationRecord::HandleNetLocationQueryL( CMdEQuery& aQuery ) |
|
1741 { |
|
1742 LOG( "CLocationRecord::HandleNetLocationQueryL(), begin" ); |
|
1743 TInt error = KErrNone; |
|
1744 TUint locationId( 0 ); |
|
1745 if ( iMediaItems.Count() <= 0 ) |
|
1746 { |
|
1747 LOG("CLocationRecord::HandleNetLocationQueryL(), End. No media items to process\n"); |
|
1748 return; |
|
1749 } |
|
1750 if( aQuery.Count() ) |
|
1751 { |
|
1752 CMdEItem& item = aQuery.ResultItem(0); |
|
1753 CMdEObject& locationObject = static_cast<CMdEObject&>(item); |
|
1754 locationId = locationObject.Id(); |
|
1755 |
|
1756 TRAP( error, CreateRelationL( iMediaItems[0]->iObjectId, locationId ) ); |
|
1757 #ifdef LOC_REVERSEGEOCODE |
|
1758 //check if found location object has lat, long |
|
1759 CMdEProperty* latProp = NULL; |
|
1760 CMdEProperty* lonProp = NULL; |
|
1761 CMdEProperty* cellIdProp = NULL; |
|
1762 CMdEProperty* areadCodeProp = NULL; |
|
1763 CMdEProperty* countryProp = NULL; |
|
1764 CMdEProperty* networkCodeProp = NULL; |
|
1765 if ( error == KErrNone ) |
|
1766 { |
|
1767 |
|
1768 CMdEPropertyDef& cellIdDef = iLocationObjectDef->GetPropertyDefL( |
|
1769 Location::KCellIdProperty ); |
|
1770 CMdEPropertyDef& locationAreadCodeDef = iLocationObjectDef->GetPropertyDefL( |
|
1771 Location::KLocationAreaCodeProperty ); |
|
1772 CMdEPropertyDef& countryCodeDef = iLocationObjectDef->GetPropertyDefL( |
|
1773 Location::KCountryCodeProperty ); |
|
1774 CMdEPropertyDef& networkCodeDef = iLocationObjectDef->GetPropertyDefL( |
|
1775 Location::KNetworkCodeProperty ); |
|
1776 |
|
1777 locationObject.Property( *iLatitudeDef, latProp, 0 ); |
|
1778 locationObject.Property( *iLongitudeDef, lonProp, 0 ); |
|
1779 |
|
1780 locationObject.Property( cellIdDef, cellIdProp, 0 ); |
|
1781 locationObject.Property( locationAreadCodeDef, areadCodeProp, 0 ); |
|
1782 locationObject.Property( countryCodeDef, countryProp, 0 ); |
|
1783 locationObject.Property( networkCodeDef, networkCodeProp, 0 ); |
|
1784 } |
|
1785 |
|
1786 if( (latProp && lonProp) |
|
1787 || (cellIdProp && areadCodeProp && countryProp && networkCodeProp) ) |
|
1788 { |
|
1789 //find out if image for this location is tagged already |
|
1790 GetRelatedImageL( locationId ); |
|
1791 } |
|
1792 else |
|
1793 #endif //LOC_REVERSEGEOCODE |
|
1794 { |
|
1795 // no geo info.. remove the item and proceed for the next. |
|
1796 TLocationSnapshotItem* firstPtr = iMediaItems[0]; |
|
1797 iMediaItems.Remove(0); |
|
1798 delete firstPtr; |
|
1799 iMediaItems.Compress(); |
|
1800 iMediaHandlingFlag &= ~KLocationQueryInProgress; |
|
1801 if ( iMediaItems.Count() > 0 ) |
|
1802 { |
|
1803 FindLocationFromDBL(); |
|
1804 } |
|
1805 } |
|
1806 } |
|
1807 else |
|
1808 { |
|
1809 #ifdef LOC_GEOTAGGING_CELLID |
|
1810 LOG1("Media handling flag = %d", iMediaHandlingFlag); |
|
1811 if((iMediaHandlingFlag & KSnapGeoConvertInProgress) > 0) |
|
1812 { |
|
1813 iMediaHandlingFlag |= KSnapGeoConvertInPendingState; |
|
1814 } |
|
1815 else |
|
1816 { |
|
1817 // go for cell id based geo coding. |
|
1818 if(iGeoConverter == NULL) |
|
1819 { |
|
1820 iGeoConverter = CGeoConverter::NewL(*this); |
|
1821 } |
|
1822 iGeoConverter->ConvertL(iMediaItems[0]->iLocationData.iNetworkInfo); |
|
1823 iMediaHandlingFlag |= KSnapGeoConvertInProgress; |
|
1824 iMediaHandlingFlag &= ~KSnapGeoConvertInPendingState; |
|
1825 } |
|
1826 #else |
|
1827 locationId = DoCreateLocationL( iMediaItems[0]->iLocationData ); |
|
1828 iMediaItems[0]->iLocationId = locationId; |
|
1829 CreateRelationL( iMediaItems[0]->iObjectId, locationId ); |
|
1830 TLocationSnapshotItem* firstPtr = iMediaItems[0]; |
|
1831 iMediaItems.Remove(0); |
|
1832 delete firstPtr; |
|
1833 iMediaItems.Compress(); |
|
1834 iMediaHandlingFlag &= ~KLocationQueryInProgress; |
|
1835 if ( iMediaItems.Count() > 0 ) |
|
1836 { |
|
1837 FindLocationFromDBL(); |
|
1838 } |
|
1839 #endif |
|
1840 } |
|
1841 #ifdef LOC_REVERSEGEOCODE |
|
1842 if((iMediaHandlingFlag & KSnapGeoConvertInProgress) > 0 || |
|
1843 (iMediaHandlingFlag & KReverseGeoCodingInProgress) > 0) |
|
1844 #else |
|
1845 if((iMediaHandlingFlag & KSnapGeoConvertInProgress) > 0) |
|
1846 #endif //LOC_REVERSEGEOCODE |
|
1847 { |
|
1848 // stop n/w info change listener, since device may connect to n/w |
|
1849 // and local trail will receive so many call backs on current n/w info change. |
|
1850 iNetworkInfoChangeListener->StopNwInfoChangeNotifier(); |
|
1851 } |
|
1852 else |
|
1853 { |
|
1854 iNetworkInfoChangeListener->StartNwInfoChangeNotifier(); |
|
1855 } |
|
1856 LOG( "CLocationRecord::HandleNetLocationQueryL(), end" ); |
|
1857 |
|
1858 } |
|
1859 |
|
1860 |
|
1861 #ifdef LOC_GEOTAGGING_CELLID |
|
1862 // -------------------------------------------------------------------------- |
|
1863 // CLocationRecord::ConversionCompletedL() |
|
1864 // -------------------------------------------------------------------------- |
|
1865 // |
|
1866 void CLocationRecord::ConversionCompletedL( const TInt aError, TLocality& aPosition ) |
|
1867 { |
|
1868 |
|
1869 LOG1("CLocationRecord::ConversionCompletedL, begin. Error - %d", aError); |
|
1870 // reset the flag first |
|
1871 iMediaHandlingFlag &= ~KSnapGeoConvertInProgress; |
|
1872 LOG1("iRemapState - %d", iRemapState); |
|
1873 if(aError == KErrNone) |
|
1874 { |
|
1875 iConvertRetry = ETrue; |
|
1876 LOG("Conversion completed successfully"); |
|
1877 if(iRemapState == ERemapNwGeoConverterInProgress) |
|
1878 { |
|
1879 iNewItem.iLocationData.iPosition.SetCoordinate |
|
1880 ( aPosition.Latitude(), aPosition.Longitude(), aPosition.Altitude()); |
|
1881 iNewItem.iLocationData.iQuality = aPosition.HorizontalAccuracy(); |
|
1882 TItemId locationId = DoCreateLocationL( iNewItem.iLocationData ); |
|
1883 iRemapper->UpdateRelationsL( locationId ); |
|
1884 // TODO: remap. |
|
1885 #ifdef LOC_REVERSEGEOCODE |
|
1886 if(!(iMediaHandlingFlag & KReverseGeoCodingInProgress)) |
|
1887 { |
|
1888 iRemapState = ERemapRevGeoCodeInProgress; |
|
1889 //Find the address by coordinate, results a call to ReverseGeocodeComplete() |
|
1890 iMediaHandlingFlag |= KReverseGeoCodingInProgress; |
|
1891 |
|
1892 if(iRevGeocoderPlugin) |
|
1893 { |
|
1894 iRevGeocoderPlugin->GetAddressByCoordinateL |
|
1895 ( iNewItem.iLocationData.iPosition, iConnectionOption ); |
|
1896 } |
|
1897 } |
|
1898 else |
|
1899 { |
|
1900 // remap in reverse geocoding pending state. |
|
1901 iRemapState = ERemapRevGeoCodePending; |
|
1902 } |
|
1903 #endif //LOC_REVERSEGEOCODE |
|
1904 } |
|
1905 else if ( iMediaItems.Count() > 0 ) |
|
1906 { |
|
1907 |
|
1908 iMediaItems[0]->iLocationData.iPosition.SetCoordinate |
|
1909 ( aPosition.Latitude(), aPosition.Longitude(), aPosition.Altitude()); |
|
1910 iMediaItems[0]->iLocationData.iQuality = aPosition.HorizontalAccuracy(); |
|
1911 TLocationSnapshotItem* item = iMediaItems[0]; |
|
1912 TItemId locationId = DoCreateLocationL( iMediaItems[0]->iLocationData ); |
|
1913 iMediaItems[0]->iLocationId = locationId; |
|
1914 CreateRelationL( iMediaItems[0]->iObjectId, locationId ); |
|
1915 if((iMediaItems[0]->iFlag & KSnapMediaFile) > 0) |
|
1916 { |
|
1917 iLastMediaItem = *(iMediaItems[0]); |
|
1918 } |
|
1919 iMediaItems.Remove(0); |
|
1920 iMediaItems.Compress(); |
|
1921 iMediaHandlingFlag &= ~KLocationQueryInProgress; |
|
1922 #ifdef LOC_REVERSEGEOCODE |
|
1923 iLocationItems.Append( item ); |
|
1924 #else |
|
1925 // free resource |
|
1926 delete item; |
|
1927 #endif |
|
1928 } |
|
1929 } |
|
1930 else |
|
1931 { |
|
1932 LOG1("Conversion error - %d", aError); |
|
1933 if(iConvertRetry) |
|
1934 { |
|
1935 LOG("Retry once"); |
|
1936 iConvertRetry = EFalse; |
|
1937 if(iRemapState == ERemapNwGeoConverterInProgress) |
|
1938 { |
|
1939 iRemapState = ERemapNwGeoConverterPending; |
|
1940 } |
|
1941 else if ( iMediaItems.Count() > 0 ) |
|
1942 { |
|
1943 iMediaHandlingFlag |= KSnapGeoConvertInPendingState; |
|
1944 } |
|
1945 } |
|
1946 else |
|
1947 { |
|
1948 if(iRemapState == ERemapNwGeoConverterInProgress) |
|
1949 { |
|
1950 iRemapState = ERemapProgressNone; |
|
1951 } |
|
1952 else if ( iMediaItems.Count() > 0 ) |
|
1953 { |
|
1954 TLocationSnapshotItem* item = iMediaItems[0]; |
|
1955 iMediaItems.Remove(0); |
|
1956 iMediaItems.Compress(); |
|
1957 iMediaHandlingFlag &= ~KLocationQueryInProgress; |
|
1958 delete item; |
|
1959 } |
|
1960 } |
|
1961 |
|
1962 } |
|
1963 |
|
1964 // check the remap item first. |
|
1965 if(iRemapState == ERemapNwGeoConverterPending) |
|
1966 { |
|
1967 // go for cell id based geo coding. |
|
1968 iRemapState = ERemapNwGeoConverterInProgress; |
|
1969 iGeoConverter->ConvertL(iNewItem.iLocationData.iNetworkInfo); |
|
1970 iMediaHandlingFlag |= KSnapGeoConvertInProgress; |
|
1971 } |
|
1972 //check for media queue pending request. |
|
1973 else if((iMediaHandlingFlag & KSnapGeoConvertInPendingState) > 0) |
|
1974 { |
|
1975 // previous media queue geo convert is in pending state. |
|
1976 // go for cell id based geo coding. |
|
1977 iGeoConverter->ConvertL(iMediaItems[0]->iLocationData.iNetworkInfo); |
|
1978 iMediaHandlingFlag |= KSnapGeoConvertInProgress; |
|
1979 iMediaHandlingFlag &= ~KSnapGeoConvertInPendingState; |
|
1980 } |
|
1981 // let's not use multiple access point. |
|
1982 #ifdef LOC_REVERSEGEOCODE |
|
1983 else if(!(iMediaHandlingFlag & KReverseGeoCodingInProgress) && |
|
1984 iLocationItems.Count() > 0) |
|
1985 { |
|
1986 iMediaHandlingFlag |= KReverseGeoCodingInProgress; |
|
1987 |
|
1988 if(iRevGeocoderPlugin) |
|
1989 { |
|
1990 iRevGeocoderPlugin->GetAddressByCoordinateL |
|
1991 ( iLocationItems[0]->iLocationData.iPosition, |
|
1992 iConnectionOption); |
|
1993 } |
|
1994 } |
|
1995 if((iMediaHandlingFlag & KSnapGeoConvertInProgress) > 0 || |
|
1996 (iMediaHandlingFlag & KReverseGeoCodingInProgress) > 0) |
|
1997 #else |
|
1998 if((iMediaHandlingFlag & KSnapGeoConvertInProgress) > 0) |
|
1999 #endif //LOC_REVERSEGEOCODE |
|
2000 { |
|
2001 // stop n/w info change listener, since device may connect to n/w |
|
2002 // and local trail will receive so many call backs on current n/w info change. |
|
2003 iNetworkInfoChangeListener->StopNwInfoChangeNotifier(); |
|
2004 } |
|
2005 else |
|
2006 { |
|
2007 iNetworkInfoChangeListener->StartNwInfoChangeNotifier(); |
|
2008 } |
|
2009 FindLocationFromDBL(); |
|
2010 GeoTaggingCompleted(); |
|
2011 LOG("CLocationRecord::ConversionCompletedL, end"); |
|
2012 } |
|
2013 |
|
2014 |
|
2015 //------------------------------------------------------------------------ |
|
2016 // CLocationRecord::HandleConversionError |
|
2017 //------------------------------------------------------------------------ |
|
2018 // |
|
2019 void CLocationRecord::HandleConversionError(TInt aError) |
|
2020 { |
|
2021 LOG( "CLocationRecord::HandleConversionError(), begin" ); |
|
2022 ARG_USED(aError); |
|
2023 if(iRemapState == ERemapNwGeoConverterInProgress) |
|
2024 { |
|
2025 iRemapState = ERemapProgressNone; |
|
2026 } |
|
2027 else if ( iMediaItems.Count() > 0 ) |
|
2028 { |
|
2029 TLocationSnapshotItem* item = iMediaItems[0]; |
|
2030 iMediaItems.Remove(0); |
|
2031 iMediaItems.Compress(); |
|
2032 iMediaHandlingFlag &= ~KLocationQueryInProgress; |
|
2033 delete item; |
|
2034 } |
|
2035 // let's not use multiple access point. |
|
2036 #ifdef LOC_REVERSEGEOCODE |
|
2037 if(!(iMediaHandlingFlag & KReverseGeoCodingInProgress) && |
|
2038 iLocationItems.Count() > 0) |
|
2039 { |
|
2040 iMediaHandlingFlag |= KReverseGeoCodingInProgress; |
|
2041 |
|
2042 if(iRevGeocoderPlugin) |
|
2043 { |
|
2044 TRAP_IGNORE(iRevGeocoderPlugin->GetAddressByCoordinateL |
|
2045 ( iLocationItems[0]->iLocationData.iPosition, |
|
2046 iConnectionOption)); |
|
2047 } |
|
2048 } |
|
2049 if((iMediaHandlingFlag & KSnapGeoConvertInProgress) > 0 || |
|
2050 (iMediaHandlingFlag & KReverseGeoCodingInProgress) > 0) |
|
2051 #else |
|
2052 if((iMediaHandlingFlag & KSnapGeoConvertInProgress) > 0) |
|
2053 #endif //LOC_REVERSEGEOCODE |
|
2054 { |
|
2055 // stop n/w info change listener, since device may connect to n/w |
|
2056 // and local trail will receive so many call backs on current n/w info change. |
|
2057 iNetworkInfoChangeListener->StopNwInfoChangeNotifier(); |
|
2058 } |
|
2059 else |
|
2060 { |
|
2061 iNetworkInfoChangeListener->StartNwInfoChangeNotifier(); |
|
2062 } |
|
2063 TRAP_IGNORE(FindLocationFromDBL()); |
|
2064 GeoTaggingCompleted(); |
|
2065 LOG( "CLocationRecord::HandleConversionError(), end" ); |
|
2066 } |
|
2067 |
|
2068 #endif // LOC_GEOTAGGING_CELLID |
|
2069 |
|
2070 // -------------------------------------------------------------------------- |
|
2071 // CLocationRecord::SetMdeSession |
|
2072 // -------------------------------------------------------------------------- |
|
2073 // |
1073 EXPORT_C void CLocationRecord::SetMdeSession( CMdESession* aSession ) |
2074 EXPORT_C void CLocationRecord::SetMdeSession( CMdESession* aSession ) |
1074 { |
2075 { |
|
2076 LOG( "CLocationRecord::SetMdeSession(), begin" ); |
1075 iMdeSession = aSession; |
2077 iMdeSession = aSession; |
|
2078 #ifdef LOC_REVERSEGEOCODE |
|
2079 iTagCreator->SetSession( aSession ); |
|
2080 #endif |
1076 TRAPD(err, iRemapper->InitialiseL( aSession )); |
2081 TRAPD(err, iRemapper->InitialiseL( aSession )); |
1077 if( err != KErrNone ) |
2082 if( err != KErrNone ) |
1078 { |
2083 { |
1079 delete iRemapper; |
2084 delete iRemapper; |
1080 iRemapper = NULL; |
2085 iRemapper = NULL; |
1081 } |
2086 } |
|
2087 TRAP(err, InitialiseL() ); |
|
2088 LOG( "CLocationRecord::SetMdeSession(), end" ); |
1082 } |
2089 } |
1083 |
2090 |
|
2091 // -------------------------------------------------------------------------- |
|
2092 // CLocationRecord::InitialiseL |
|
2093 // -------------------------------------------------------------------------- |
|
2094 // |
|
2095 void CLocationRecord::InitialiseL() |
|
2096 { |
|
2097 LOG( "CLocationRecord::InitialiseL(), begin" ); |
|
2098 // namespace defaults |
|
2099 iNamespaceDef = &iMdeSession->GetDefaultNamespaceDefL(); |
|
2100 |
|
2101 // location object definitions |
|
2102 iLocationObjectDef = &iNamespaceDef->GetObjectDefL( Location::KLocationObject ); |
|
2103 iLatitudeDef = &iLocationObjectDef->GetPropertyDefL( Location::KLatitudeProperty ); |
|
2104 iLongitudeDef = &iLocationObjectDef->GetPropertyDefL( Location::KLongitudeProperty ); |
|
2105 iAltitudeDef = &iLocationObjectDef->GetPropertyDefL( Location::KAltitudeProperty ); |
|
2106 LOG( "CLocationRecord::InitialiseL(), end" ); |
|
2107 } |
|
2108 |
|
2109 |
|
2110 // -------------------------------------------------------------------------- |
|
2111 // CLocationRecord::StartTimerL |
|
2112 // -------------------------------------------------------------------------- |
|
2113 // |
1084 void CLocationRecord::StartTimerL() |
2114 void CLocationRecord::StartTimerL() |
1085 { |
2115 { |
1086 LOG("CLocationRecord::StartTimerL"); |
2116 LOG("CLocationRecord::StartTimerL,begin"); |
1087 |
2117 |
1088 if( !iNetworkInfoTimer->IsActive() ) |
2118 if( !iNetworkInfoTimer->IsActive() ) |
1089 { |
2119 { |
1090 iNetworkInfoTimer->Start( iInterval, iInterval, TCallBack( UpdateNetworkInfo, this ) ); |
2120 iNetworkInfoTimer->Start( iInterval, iInterval, TCallBack( UpdateNetworkInfo, this ) ); |
1091 } |
2121 } |
|
2122 LOG( "CLocationRecord::StartL(), end" ); |
1092 } |
2123 } |
1093 |
2124 |
|
2125 |
|
2126 // -------------------------------------------------------------------------- |
|
2127 // CLocationRecord::GetMdeObjectTimeL |
|
2128 // -------------------------------------------------------------------------- |
|
2129 // |
1094 TTime CLocationRecord::GetMdeObjectTimeL( TItemId aObjectId ) |
2130 TTime CLocationRecord::GetMdeObjectTimeL( TItemId aObjectId ) |
1095 { |
2131 { |
|
2132 LOG( "CLocationRecord::GetMdeObjectTimeL(), begin" ); |
1096 CMdENamespaceDef& namespaceDef = iMdeSession->GetDefaultNamespaceDefL(); |
2133 CMdENamespaceDef& namespaceDef = iMdeSession->GetDefaultNamespaceDefL(); |
1097 |
2134 |
1098 CMdEObjectDef& objectDef = namespaceDef.GetObjectDefL( Object::KBaseObject ); |
2135 CMdEObjectDef& objectDef = namespaceDef.GetObjectDefL( Object::KBaseObject ); |
1099 CMdEPropertyDef& timeDef = objectDef.GetPropertyDefL( Object::KLastModifiedDateProperty ); |
2136 CMdEPropertyDef& timeDef = objectDef.GetPropertyDefL( Object::KLastModifiedDateProperty ); |
1100 |
2137 |
1133 } |
2238 } |
1134 else |
2239 else |
1135 { |
2240 { |
1136 return ETrue; |
2241 return ETrue; |
1137 } |
2242 } |
1138 |
2243 } |
1139 } |
2244 |
|
2245 // -------------------------------------------------------------------------- |
|
2246 // CLocationRecord::GeoTaggingCompleted |
|
2247 // -------------------------------------------------------------------------- |
|
2248 // |
|
2249 void CLocationRecord::GeoTaggingCompleted() |
|
2250 { |
|
2251 LOG( "CLocationRecord::GeoTaggingCompleted(), begin" ); |
|
2252 if((iMediaItems.Count() == 0) |
|
2253 #ifdef LOC_REVERSEGEOCODE |
|
2254 && (iLocationItems.Count() == 0) |
|
2255 #endif //LOC_REVERSEGEOCODE |
|
2256 ) |
|
2257 { |
|
2258 LOG("Geo tagging completed"); |
|
2259 iGeoTaggerObserver.GeoTaggingCompleted(KErrNone); |
|
2260 // fallback to silent |
|
2261 #ifdef LOC_REVERSEGEOCODE |
|
2262 iConnectionOption = ESilent; |
|
2263 #endif //LOC_REVERSEGEOCODE |
|
2264 } |
|
2265 LOG( "CLocationRecord::GeoTaggingCompleted(), end" ); |
|
2266 } |
|
2267 |
|
2268 |
|
2269 |
|
2270 |
|
2271 // -------------------------------------------------------------------------- |
|
2272 // CLocationRecord::TaggingInProgress |
|
2273 // -------------------------------------------------------------------------- |
|
2274 // |
|
2275 EXPORT_C TBool CLocationRecord::TaggingInProgress() |
|
2276 { |
|
2277 LOG( "CLocationRecord::TaggingInProgress(), begin" ); |
|
2278 TBool retVal = EFalse; |
|
2279 #ifdef LOC_REVERSEGEOCODE |
|
2280 if( ((iMediaItems.Count() > 0) || (iLocationItems.Count() > 0) ) |
|
2281 && (iRevGeocoderPlugin && iRevGeocoderPlugin->SilentConnectionAllowed())) |
|
2282 #else |
|
2283 if( iMediaItems.Count() > 0 ) |
|
2284 |
|
2285 #endif //LOC_REVERSEGEOCODE |
|
2286 { |
|
2287 #ifdef LOC_REVERSEGEOCODE |
|
2288 if(!(iMediaHandlingFlag & KReverseGeoCodingInProgress)) |
|
2289 { |
|
2290 // start geocoding |
|
2291 |
|
2292 if (iLocationItems.Count() > 0 ) |
|
2293 { |
|
2294 iMediaHandlingFlag |= KReverseGeoCodingInProgress; |
|
2295 |
|
2296 TRAP_IGNORE( iRevGeocoderPlugin->GetAddressByCoordinateL( |
|
2297 iLocationItems[0]->iLocationData.iPosition, |
|
2298 iConnectionOption) ); |
|
2299 |
|
2300 retVal = ETrue; |
|
2301 } |
|
2302 } |
|
2303 else |
|
2304 { |
|
2305 retVal = ETrue; |
|
2306 } |
|
2307 #endif //LOC_REVERSEGEOCODE |
|
2308 if(!(iMediaHandlingFlag & KLocationQueryInProgress)) |
|
2309 { |
|
2310 if(iMediaItems.Count() > 0) |
|
2311 { |
|
2312 HandleFindLocationFromDB(); |
|
2313 retVal = ETrue; |
|
2314 } |
|
2315 } |
|
2316 else |
|
2317 { |
|
2318 retVal = ETrue; |
|
2319 } |
|
2320 } |
|
2321 else |
|
2322 { |
|
2323 // Flash the array to avoid double tagging by photos & localrail. |
|
2324 } |
|
2325 LOG( "CLocationRecord::TaggingInProgress(), end" ); |
|
2326 return retVal; |
|
2327 } |
|
2328 |
|
2329 |
|
2330 // ---------------------------------------------------------------------------- |
|
2331 // CLocationRecord::GetCurrentRegisteredNw() |
|
2332 // ---------------------------------------------------------------------------- |
|
2333 EXPORT_C RMobilePhone::TMobilePhoneNetworkInfoV2& CLocationRecord::GetCurrentRegisteredNw() |
|
2334 { |
|
2335 LOG( "CLocationRecord::GetCurrentRegisteredNw ,begin" ); |
|
2336 return iNetworkInfoChangeListener->GetCurrentRegisterNw(); |
|
2337 } |
|
2338 |
|
2339 // -------------------------------------------------------------------------- |
|
2340 // CLocationRecord::StartGeoTagging |
|
2341 // -------------------------------------------------------------------------- |
|
2342 // |
|
2343 EXPORT_C TBool CLocationRecord::StartGeoTagging(const TConnectionOption aConnectionOption) |
|
2344 { |
|
2345 LOG( "CLocationRecord::StartGeoTagging(), begin" ); |
|
2346 TBool retVal = EFalse; |
|
2347 ARG_USED(aConnectionOption); |
|
2348 if((iMediaItems.Count() > 0) |
|
2349 #ifdef LOC_REVERSEGEOCODE |
|
2350 || (iLocationItems.Count() > 0) |
|
2351 #endif //LOC_REVERSEGEOCODE |
|
2352 ) |
|
2353 { |
|
2354 #ifdef LOC_REVERSEGEOCODE |
|
2355 iConnectionOption = aConnectionOption; |
|
2356 if(!(iMediaHandlingFlag & KReverseGeoCodingInProgress)) |
|
2357 { |
|
2358 // start geocoding |
|
2359 if (iLocationItems.Count() > 0 ) |
|
2360 { |
|
2361 iMediaHandlingFlag |= KReverseGeoCodingInProgress; |
|
2362 if(iRevGeocoderPlugin) |
|
2363 { |
|
2364 TRAP_IGNORE( iRevGeocoderPlugin->GetAddressByCoordinateL( |
|
2365 iLocationItems[0]->iLocationData.iPosition, |
|
2366 iConnectionOption) ); |
|
2367 } |
|
2368 retVal = ETrue; |
|
2369 } |
|
2370 } |
|
2371 else |
|
2372 { |
|
2373 retVal = ETrue; |
|
2374 } |
|
2375 #endif //LOC_REVERSEGEOCODE |
|
2376 if(!(iMediaHandlingFlag & KLocationQueryInProgress)) |
|
2377 { |
|
2378 if(iMediaItems.Count() > 0) |
|
2379 { |
|
2380 HandleFindLocationFromDB(); |
|
2381 retVal = ETrue; |
|
2382 } |
|
2383 } |
|
2384 else |
|
2385 { |
|
2386 retVal = ETrue; |
|
2387 } |
|
2388 } |
|
2389 LOG( "CLocationRecord::StartGeoTagging(), end" ); |
|
2390 return retVal; |
|
2391 } |
|
2392 |
|
2393 |
|
2394 // -------------------------------------------------------------------------- |
|
2395 // CLocationRecord::CancelGeoTagging |
|
2396 // -------------------------------------------------------------------------- |
|
2397 // |
|
2398 EXPORT_C void CLocationRecord::CancelGeoTagging() |
|
2399 { |
|
2400 #ifdef LOC_REVERSEGEOCODE |
|
2401 LOG1( "CLocationRecord::CancelGeoTagging(), Connetion opt - %d", |
|
2402 iConnectionOption ); |
|
2403 // set this to default connection. |
|
2404 iConnectionOption = ESilent; |
|
2405 #endif //LOC_REVERSEGEOCODE |
|
2406 } |
|
2407 |
|
2408 |
|
2409 #ifdef LOC_REVERSEGEOCODE |
|
2410 |
|
2411 // -------------------------------------------------------------------------- |
|
2412 // CLocationManagerServer::GetRelatedImages() |
|
2413 // Find any image, already related to this location object |
|
2414 // -------------------------------------------------------------------------- |
|
2415 // |
|
2416 void CLocationRecord::GetRelatedImageL(TItemId aLocID) |
|
2417 { |
|
2418 LOG( "CLocationRecord::GetRelatedImageL(), begin" ); |
|
2419 CMdEObjectDef& imageObjDef = iNamespaceDef->GetObjectDefL( Image::KImageObject ); |
|
2420 |
|
2421 if(iImageQuery) |
|
2422 { |
|
2423 iImageQuery->RemoveObserver(*this); |
|
2424 iImageQuery->Cancel(); |
|
2425 delete iImageQuery; |
|
2426 iImageQuery = NULL; |
|
2427 } |
|
2428 |
|
2429 iImageQuery = iMdeSession->NewRelationQueryL( *iNamespaceDef, this ); |
|
2430 User::LeaveIfNull( iImageQuery ); |
|
2431 |
|
2432 iImageQuery->SetResultMode( EQueryResultModeItem ); |
|
2433 |
|
2434 // both left and right condition must match |
|
2435 CMdERelationCondition& filterCond = iImageQuery->Conditions(). |
|
2436 AddRelationConditionL( ERelationConditionSideRight ); |
|
2437 |
|
2438 // left one must be any image object. |
|
2439 filterCond.LeftL().AddObjectConditionL( imageObjDef ); |
|
2440 |
|
2441 // right one must be this location object |
|
2442 filterCond.RightL().AddObjectConditionL( aLocID ); |
|
2443 |
|
2444 iImageQuery->FindL(1, 1); // results to a call to HandleQueryCompleted() |
|
2445 LOG( "CLocationRecord::GetRelatedImageL(), end" ); |
|
2446 } |
|
2447 |
|
2448 |
|
2449 |
|
2450 // -------------------------------------------------------------------------- |
|
2451 // CLocationRecord::ReverseGeocodeComplete() |
|
2452 // Get address details like country, city.. |
|
2453 // Create country and city tags and attach to the current image/video object |
|
2454 // -------------------------------------------------------------------------- |
|
2455 // |
|
2456 void CLocationRecord::ReverseGeocodeComplete( TInt& aErrorcode, MAddressInfo& aAddressInfo ) |
|
2457 { |
|
2458 LOG( "CLocationRecord::ReverseGeocodeComplete(), begin" ); |
|
2459 TItemId countryTagId(0); |
|
2460 TItemId cityTagId(0); |
|
2461 |
|
2462 iMediaHandlingFlag &= (~KReverseGeoCodingInProgress); |
|
2463 TLocationSnapshotItem* snapshotItem = NULL; |
|
2464 if( aErrorcode == KErrNone ) |
|
2465 { |
|
2466 TPtrC countryPtr( aAddressInfo.GetCountryName() ); |
|
2467 TPtrC cityPtr( aAddressInfo.GetCity() ); |
|
2468 TRAP_IGNORE( iTagCreator->CreateLocationTagsL( countryPtr, countryTagId, |
|
2469 cityPtr, cityTagId ) ); |
|
2470 if ( iRemapState == ERemapRevGeoCodeInProgress) |
|
2471 { |
|
2472 TRAP_IGNORE( iRemapper->AttachGeoTagsL( iTagCreator, countryTagId, cityTagId ) ); |
|
2473 iRemapState = ERemapProgressNone; |
|
2474 } |
|
2475 else |
|
2476 { |
|
2477 if(iLocationItems.Count() > 0) |
|
2478 { |
|
2479 iLocationItems[0]->iCountryTagId = countryTagId; |
|
2480 iLocationItems[0]->iCityTagId = cityTagId; |
|
2481 iLastLocationItem = (*iLocationItems[0]); |
|
2482 |
|
2483 TRAP_IGNORE( iTagCreator->AttachTagsL( |
|
2484 iLocationItems[0]->iObjectId, countryTagId, cityTagId ) ); |
|
2485 } |
|
2486 } |
|
2487 if(iLastMediaItem.iFlag == 0) |
|
2488 { |
|
2489 LOG("Last media item is null\n"); |
|
2490 } |
|
2491 if ( iLastMediaItem.iFlag > 0 && iLastMediaItem.iLocationId == iLastLocationItem.iLocationId ) |
|
2492 { |
|
2493 LOG("Updating country/city\n"); |
|
2494 iLastMediaItem.iCountryTagId = countryTagId; |
|
2495 iLastMediaItem.iCityTagId = cityTagId; |
|
2496 } |
|
2497 |
|
2498 //check other items in the array has same location |
|
2499 for ( TInt index = iLocationItems.Count() - 1; index > 0; index--) |
|
2500 { |
|
2501 if ( iLocationItems[index]->iLocationId == iLastLocationItem.iLocationId ) |
|
2502 { |
|
2503 LOG1("Attached tags in for - %d\n", index); |
|
2504 TRAP_IGNORE( iTagCreator->AttachTagsL( |
|
2505 iLocationItems[index]->iObjectId, countryTagId, cityTagId ) ); |
|
2506 snapshotItem = iLocationItems[index]; |
|
2507 iLocationItems.Remove(index); |
|
2508 delete snapshotItem; |
|
2509 } |
|
2510 } |
|
2511 } |
|
2512 else |
|
2513 { |
|
2514 //handle error |
|
2515 } |
|
2516 |
|
2517 //irrespective of error or not, remove current(first) item to proceed further |
|
2518 if ( iLocationItems.Count() > 0 ) |
|
2519 { |
|
2520 snapshotItem = iLocationItems[0]; |
|
2521 iLocationItems.Remove(0); |
|
2522 delete snapshotItem; |
|
2523 iLocationItems.Compress(); |
|
2524 } |
|
2525 if (aErrorcode == KErrNone) |
|
2526 { |
|
2527 if(iRemapState == ERemapRevGeoCodePending) |
|
2528 { |
|
2529 if(iRevGeocoderPlugin) |
|
2530 { |
|
2531 TRAPD(err, iRevGeocoderPlugin->GetAddressByCoordinateL( iNewItem.iLocationData.iPosition, iConnectionOption );) |
|
2532 if(err == KErrNone) |
|
2533 { |
|
2534 // Remap geo coding in pending state |
|
2535 iRemapState = ERemapRevGeoCodeInProgress; |
|
2536 //Find the address by coordinate, results a call to ReverseGeocodeComplete() |
|
2537 iMediaHandlingFlag |= KReverseGeoCodingInProgress; |
|
2538 } |
|
2539 } |
|
2540 } |
|
2541 else if(iLocationItems.Count() > 0) |
|
2542 { |
|
2543 if(iRevGeocoderPlugin) |
|
2544 { |
|
2545 TRAPD(err, iRevGeocoderPlugin->GetAddressByCoordinateL( |
|
2546 iLocationItems[0]->iLocationData.iPosition, |
|
2547 iConnectionOption) ); |
|
2548 if(err == KErrNone) |
|
2549 { |
|
2550 // queue is not empty process the next. |
|
2551 iMediaHandlingFlag |= KReverseGeoCodingInProgress; |
|
2552 } |
|
2553 } |
|
2554 } |
|
2555 } |
|
2556 |
|
2557 GeoTaggingCompleted(); |
|
2558 if((iMediaHandlingFlag & KSnapGeoConvertInProgress) > 0 || |
|
2559 (iMediaHandlingFlag & KReverseGeoCodingInProgress) > 0) |
|
2560 { |
|
2561 // stop n/w info change listener, since device may connect to n/w |
|
2562 // and local trail will receive so many call backs on current n/w info change. |
|
2563 iNetworkInfoChangeListener->StopNwInfoChangeNotifier(); |
|
2564 } |
|
2565 else |
|
2566 { |
|
2567 iNetworkInfoChangeListener->StartNwInfoChangeNotifier(); |
|
2568 } |
|
2569 LOG( "CLocationRecord::ReverseGeocodeComplete(), end" ); |
|
2570 } |
|
2571 |
|
2572 |
|
2573 // ---------------------------------------------------------------------------- |
|
2574 // CLocationRecord::IsRegisteredAtHomeNetwork() |
|
2575 // ---------------------------------------------------------------------------- |
|
2576 TBool CLocationRecord::IsRegisteredAtHomeNetwork() |
|
2577 { |
|
2578 LOG( "CLocationRecord::IsRegisteredAtHomeNetwork" ); |
|
2579 return iGeoTaggerObserver.IsRegisteredAtHomeNetwork(); |
|
2580 } |
|
2581 |
|
2582 // ---------------------------------------------------------------------------- |
|
2583 // CLocationRecord::GetHomeNetworkInfo() |
|
2584 // ---------------------------------------------------------------------------- |
|
2585 const RMobilePhone::TMobilePhoneNetworkInfoV1& |
|
2586 CLocationRecord::GetHomeNetworkInfo(TBool& aHomeNwInfoAvailableFlag) |
|
2587 { |
|
2588 LOG( "CLocationRecord::GetHomeNetworkInfo" ); |
|
2589 return iGeoTaggerObserver.GetHomeNetworkInfo(aHomeNwInfoAvailableFlag); |
|
2590 } |
|
2591 |
|
2592 // ---------------------------------------------------------------------------- |
|
2593 // CLocationRecord::GetCurrentRegisterNw() |
|
2594 // ---------------------------------------------------------------------------- |
|
2595 RMobilePhone::TMobilePhoneNetworkInfoV2& CLocationRecord::GetCurrentRegisterNw() |
|
2596 { |
|
2597 LOG( "CLocationRecord::GetCurrentRegisterNw ,begin" ); |
|
2598 return GetCurrentRegisteredNw(); |
|
2599 } |
|
2600 |
|
2601 |
|
2602 // -------------------------------------------------------------------------- |
|
2603 // CLocationRecord::HandleTagQuery() |
|
2604 // handle if only gps info available |
|
2605 // -------------------------------------------------------------------------- |
|
2606 // |
|
2607 void CLocationRecord::HandleTagQueryL( CMdEQuery& aQuery ) |
|
2608 { |
|
2609 LOG( "CLocationRecord::HandleTagQueryL(), begin" ); |
|
2610 TItemId countryTagId = 0; |
|
2611 TItemId cityTagId = 0; |
|
2612 TRAPD( error, FindCountryAndCityTagL( aQuery, countryTagId, cityTagId ) ); |
|
2613 if ( error == KErrNone ) |
|
2614 { |
|
2615 LOG1("Media count - %d\n", iMediaItems.Count()); |
|
2616 if ( !countryTagId && !cityTagId ) |
|
2617 { |
|
2618 if ( iMediaItems.Count() > 0 ) |
|
2619 { |
|
2620 iLocationItems.Append( iMediaItems[0] ); |
|
2621 if((iMediaItems[0]->iFlag & KSnapMediaFile) > 0) |
|
2622 { |
|
2623 iLastMediaItem = *(iMediaItems[0]); |
|
2624 } |
|
2625 iMediaItems.Remove(0); |
|
2626 iMediaItems.Compress(); |
|
2627 iMediaHandlingFlag &= ~KLocationQueryInProgress; |
|
2628 } |
|
2629 |
|
2630 #ifdef LOC_REVERSEGEOCODE |
|
2631 if(!(iMediaHandlingFlag & KReverseGeoCodingInProgress) && |
|
2632 iLocationItems.Count() > 0) |
|
2633 { |
|
2634 iMediaHandlingFlag |= KReverseGeoCodingInProgress; |
|
2635 if(iRevGeocoderPlugin) |
|
2636 { |
|
2637 iRevGeocoderPlugin->GetAddressByCoordinateL |
|
2638 ( iLocationItems[0]->iLocationData.iPosition, |
|
2639 iConnectionOption); |
|
2640 } |
|
2641 } |
|
2642 #endif //LOC_REVERSEGEOCODE |
|
2643 } |
|
2644 else |
|
2645 { |
|
2646 |
|
2647 iTagCreator->AttachTagsL( iMediaItems[0]->iObjectId, countryTagId, cityTagId ); |
|
2648 if ( iMediaItems.Count() > 0 ) |
|
2649 { |
|
2650 iMediaItems[0]->iCountryTagId = countryTagId; |
|
2651 iMediaItems[0]->iCityTagId = cityTagId; |
|
2652 TLocationSnapshotItem* item = iMediaItems[0]; |
|
2653 if((iMediaItems[0]->iFlag & KSnapMediaFile) > 0) |
|
2654 { |
|
2655 iLastMediaItem = *item; |
|
2656 } |
|
2657 iMediaItems.Remove(0); |
|
2658 iMediaItems.Compress(); |
|
2659 iMediaHandlingFlag &= ~KLocationQueryInProgress; |
|
2660 delete item; |
|
2661 } |
|
2662 } |
|
2663 |
|
2664 } |
|
2665 if ( iMediaItems.Count() > 0 ) |
|
2666 { |
|
2667 FindLocationFromDBL(); |
|
2668 } |
|
2669 LOG( "CLocationRecord::HandleTagQueryL(), end" ); |
|
2670 } |
|
2671 |
|
2672 |
|
2673 // -------------------------------------------------------------------------- |
|
2674 // CLocationRecord::FindCountryAndCityTagL() |
|
2675 // Go through all attached tags to get location tags only |
|
2676 // -------------------------------------------------------------------------- |
|
2677 // |
|
2678 void CLocationRecord::FindCountryAndCityTagL( CMdEQuery& aQuery, |
|
2679 TItemId& aCountryTagId, TItemId& aCityTagId ) |
|
2680 { |
|
2681 LOG( "CLocationRecord::FindCountryAndCityTagL(), begin" ); |
|
2682 TItemId tagId = 0; |
|
2683 CMdEObject* object = NULL; |
|
2684 TInt error = KErrNone; |
|
2685 |
|
2686 const TInt count = aQuery.Count(); |
|
2687 |
|
2688 for ( TInt i = 0; i < count; i++ ) |
|
2689 { |
|
2690 CMdERelation& relation = static_cast<CMdERelation&>( aQuery.ResultItem( i ) ); |
|
2691 |
|
2692 tagId = relation.RightObjectId(); |
|
2693 TRAP_IGNORE( object = iMdeSession->GetObjectL( tagId ) ); |
|
2694 |
|
2695 if ( !aCountryTagId ) |
|
2696 { |
|
2697 error = object->Uri().Find( KCountry ); |
|
2698 //just make sure 'country' appears first in the tag uri |
|
2699 if ( error == KErrNone ) |
|
2700 { |
|
2701 aCountryTagId = tagId; |
|
2702 continue; |
|
2703 } |
|
2704 } |
|
2705 |
|
2706 if ( !aCityTagId ) |
|
2707 { |
|
2708 error = object->Uri().Find( KCity ); |
|
2709 if ( error == KErrNone ) |
|
2710 { |
|
2711 aCityTagId = tagId; |
|
2712 } |
|
2713 } |
|
2714 |
|
2715 if ( aCountryTagId && aCityTagId ) |
|
2716 { |
|
2717 i = count; |
|
2718 } |
|
2719 } |
|
2720 LOG( "CLocationRecord::FindCountryAndCityTagL(), end" ); |
|
2721 |
|
2722 } |
|
2723 |
|
2724 // -------------------------------------------------------------------------- |
|
2725 // CLocationRecord::GetTagsL() |
|
2726 // -------------------------------------------------------------------------- |
|
2727 // |
|
2728 void CLocationRecord::GetTagsL( TItemId aImageID ) |
|
2729 { |
|
2730 LOG( "CLocationRecord::GetTagsL(), begin" ); |
|
2731 CMdEObjectDef& tagObjectDef = iNamespaceDef->GetObjectDefL( Tag::KTagObject ); |
|
2732 |
|
2733 if(iTagQuery) |
|
2734 { |
|
2735 iTagQuery->RemoveObserver(*this); |
|
2736 iTagQuery->Cancel(); |
|
2737 delete iTagQuery; |
|
2738 iTagQuery = NULL; |
|
2739 } |
|
2740 |
|
2741 iTagQuery = iMdeSession->NewRelationQueryL( *iNamespaceDef, this ); |
|
2742 User::LeaveIfNull( iTagQuery ); |
|
2743 |
|
2744 iTagQuery->SetResultMode( EQueryResultModeItem ); |
|
2745 |
|
2746 // both left and right condition must match |
|
2747 CMdERelationCondition& filterCond = iTagQuery->Conditions(). |
|
2748 AddRelationConditionL( ERelationConditionSideRight ); |
|
2749 |
|
2750 // left one must be this image object. |
|
2751 filterCond.LeftL().AddObjectConditionL( aImageID ); |
|
2752 |
|
2753 // right one must be tag object |
|
2754 filterCond.RightL().AddObjectConditionL( tagObjectDef ); |
|
2755 |
|
2756 iTagQuery->FindL(); // results to a call to HandleQueryCompleted() |
|
2757 LOG( "CLocationRecord::GetTagsL(), end" ); |
|
2758 } |
|
2759 |
|
2760 |
|
2761 #endif //LOC_REVERSEGEOCODE |
1140 |
2762 |
1141 // End of file |
2763 // End of file |
|
2764 |
|
2765 |