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