1 /* |
|
2 * Copyright (c) 2006-2007 Nokia Corporation and/or its subsidiary(-ies). |
|
3 * All rights reserved. |
|
4 * This component and the accompanying materials are made available |
|
5 * under the terms of "Eclipse Public License v1.0" |
|
6 * which accompanies this distribution, and is available |
|
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 * |
|
9 * Initial Contributors: |
|
10 * Nokia Corporation - initial contribution. |
|
11 * |
|
12 * Contributors: |
|
13 * |
|
14 * Description: CMnrpNaviModel class implementation |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 #include <coemain.h> |
|
20 #include <aknlists.h> |
|
21 #include <barsread.h> |
|
22 |
|
23 #include <lbs.h> |
|
24 #include <lbsposition.h> |
|
25 #include <lbspositioninfo.h> |
|
26 |
|
27 #include <EPos_CPosLandmark.h> |
|
28 |
|
29 #include "mnrputils.h" |
|
30 #include "mnrpengine.h" |
|
31 #include "mnrpnavimodel.h" |
|
32 |
|
33 const TInt KUpdateInterval = 1 * 1000 * 1000; // 1 sec |
|
34 const TInt KUpdateTimeout = 10 * 1000 * 1000; // 10 sec |
|
35 |
|
36 _LIT( KNotDefined, "<n/a>" ); |
|
37 _LIT( KDestination, "destination" ); |
|
38 _LIT( KPosition, "position" ); |
|
39 _LIT( KDistance, "distance" ); |
|
40 _LIT( KBearing, "bearing" ); |
|
41 _LIT( KDestinationLat, "dest.lat." ); |
|
42 _LIT( KDestinationLon, "dest.lon." ); |
|
43 _LIT( KPositionLat, "pos.lat." ); |
|
44 _LIT( KPositionLon, "pos.lon." ); |
|
45 _LIT( KSpeed, "speed" ); |
|
46 _LIT( KHeading, "heading" ); |
|
47 _LIT( KMagHeading, "m.heading" ); |
|
48 _LIT( KCourse, "course" ); |
|
49 _LIT( KMagCourse, "m.course" ); |
|
50 |
|
51 // ========================== MEMBER CLASS' FUNCTIONS ========================== |
|
52 |
|
53 // ----------------------------------------------------------------------------- |
|
54 // ----------------------------------------------------------------------------- |
|
55 // |
|
56 CMnrpNaviModel::CListItem* CMnrpNaviModel::CListItem::NewL( |
|
57 const TDesC& aItemHeader, |
|
58 const TDesC& aItemValue ) |
|
59 { |
|
60 CListItem* self = new (ELeave) CListItem; |
|
61 CleanupStack::PushL( self ); |
|
62 self->iHeader = aItemHeader.AllocL(); |
|
63 self->iValue = aItemValue.AllocL(); |
|
64 CleanupStack::Pop( self ); |
|
65 return self; |
|
66 } |
|
67 |
|
68 // ----------------------------------------------------------------------------- |
|
69 // ----------------------------------------------------------------------------- |
|
70 // |
|
71 CMnrpNaviModel::CListItem::~CListItem() |
|
72 { |
|
73 delete iHeader; |
|
74 delete iValue; |
|
75 } |
|
76 |
|
77 // ============================ MEMBER FUNCTIONS =============================== |
|
78 |
|
79 // ----------------------------------------------------------------------------- |
|
80 // ----------------------------------------------------------------------------- |
|
81 // |
|
82 CMnrpNaviModel::CMnrpNaviModel( MNaviModelObserver& aObserver, CMnrpEngine& aEngine ) |
|
83 : iEngine( aEngine ), iObserver( aObserver ) |
|
84 { |
|
85 } |
|
86 |
|
87 // ----------------------------------------------------------------------------- |
|
88 // ----------------------------------------------------------------------------- |
|
89 // |
|
90 CMnrpNaviModel::~CMnrpNaviModel() |
|
91 { |
|
92 delete iPositionRequest; |
|
93 delete iDestination; |
|
94 iListItems.ResetAndDestroy(); |
|
95 } |
|
96 |
|
97 // ----------------------------------------------------------------------------- |
|
98 // ----------------------------------------------------------------------------- |
|
99 // |
|
100 CMnrpNaviModel* CMnrpNaviModel::NewL( MNaviModelObserver& aObserver, CMnrpEngine& aEngine ) |
|
101 { |
|
102 CMnrpNaviModel* self = new (ELeave) CMnrpNaviModel( aObserver, aEngine ); |
|
103 CleanupStack::PushL( self ); |
|
104 self->ConstructL(); |
|
105 CleanupStack::Pop( self ); |
|
106 return self; |
|
107 } |
|
108 |
|
109 // ----------------------------------------------------------------------------- |
|
110 // ----------------------------------------------------------------------------- |
|
111 // |
|
112 void CMnrpNaviModel::ConstructL() |
|
113 { |
|
114 _LIT( KRequestorName, "MnRefProvider" ); |
|
115 iPositionRequest = CMnrpPositionRequest::NewL( KRequestorName, *this ); |
|
116 |
|
117 TPositionUpdateOptions options; |
|
118 options.SetUpdateInterval( TTimeIntervalMicroSeconds( KUpdateInterval ) ); |
|
119 options.SetUpdateTimeOut( TTimeIntervalMicroSeconds( KUpdateTimeout ) ); |
|
120 iPositionRequest->SetOptionsL( options ); |
|
121 |
|
122 iPositionRequest->FetchNewPosition(); |
|
123 } |
|
124 |
|
125 // ----------------------------------------------------------------------------- |
|
126 // ----------------------------------------------------------------------------- |
|
127 // |
|
128 void CMnrpNaviModel::SetDestinationL( const CPosLandmark& aNewDestination ) |
|
129 { |
|
130 delete iDestination; |
|
131 iDestination = NULL; |
|
132 iDestination = CPosLandmark::NewL( aNewDestination ); |
|
133 |
|
134 iObserver.HandleModelUpdateL(); |
|
135 } |
|
136 |
|
137 // ----------------------------------------------------------------------------- |
|
138 // ----------------------------------------------------------------------------- |
|
139 // |
|
140 TArray<CMnrpNaviModel::CListItem*> CMnrpNaviModel::ListItemsL() |
|
141 { |
|
142 iListItems.ResetAndDestroy(); |
|
143 |
|
144 TBuf<64> buf; |
|
145 TPosition position; |
|
146 TLocality destination; |
|
147 |
|
148 iPosInfo.GetPosition( position ); |
|
149 |
|
150 if ( !iDestination || iDestination->GetPosition( destination ) ) |
|
151 { |
|
152 iListItems.AppendL( CListItem::NewL( KDestination, KNotDefined ) ); |
|
153 } |
|
154 else |
|
155 { |
|
156 TPtrC name; |
|
157 iDestination->GetLandmarkName( name ); |
|
158 HBufC* printableName = MnrpUtils::PrintableStringLC( name ); |
|
159 iListItems.AppendL( CListItem::NewL( KDestination, *printableName ) ); |
|
160 CleanupStack::PopAndDestroy( printableName ); |
|
161 |
|
162 TBool validPosition = ( !Math::IsNaN( position.Latitude() ) && |
|
163 !Math::IsNaN( position.Longitude() ) ); |
|
164 |
|
165 if ( validPosition ) |
|
166 { |
|
167 TReal32 distance, bearing; |
|
168 if ( position.Distance( destination, distance ) == KErrNone ) |
|
169 { |
|
170 MnrpUtils::DistanceToString( distance, buf ); |
|
171 iListItems.AppendL( CListItem::NewL( KDistance, buf ) ); |
|
172 } |
|
173 else |
|
174 { |
|
175 iListItems.AppendL( CListItem::NewL( KDistance, KNotDefined ) ); |
|
176 } |
|
177 |
|
178 if ( position.BearingTo( destination, bearing ) == KErrNone ) |
|
179 { |
|
180 MnrpUtils::AngleToString( bearing, buf ); |
|
181 iListItems.AppendL( CListItem::NewL( KBearing, buf ) ); |
|
182 } |
|
183 else |
|
184 { |
|
185 iListItems.AppendL( CListItem::NewL( KBearing, KNotDefined ) ); |
|
186 } |
|
187 |
|
188 MnrpUtils::SpeedToString( iPositionRequest->Speed(), buf ); |
|
189 iListItems.AppendL( CListItem::NewL( KSpeed, buf ) ); |
|
190 |
|
191 MnrpUtils::AngleToString( iPositionRequest->Course(), buf ); |
|
192 iListItems.AppendL( CListItem::NewL( KCourse, buf ) ); |
|
193 |
|
194 MnrpUtils::AngleToString( iPositionRequest->Heading(), buf ); |
|
195 iListItems.AppendL( CListItem::NewL( KHeading, buf ) ); |
|
196 |
|
197 MnrpUtils::CoordinateToString( position.Latitude(), buf, ETrue, ETrue ); |
|
198 iListItems.AppendL( CListItem::NewL( KPositionLat, buf ) ); |
|
199 |
|
200 MnrpUtils::CoordinateToString( position.Longitude(), buf, ETrue, ETrue ); |
|
201 iListItems.AppendL( CListItem::NewL( KPositionLon, buf ) ); |
|
202 } |
|
203 else |
|
204 { |
|
205 iListItems.AppendL( CListItem::NewL( KPosition, KNotDefined ) ); |
|
206 } |
|
207 |
|
208 MnrpUtils::CoordinateToString( destination.Latitude(), buf, ETrue, ETrue ); |
|
209 iListItems.AppendL( CListItem::NewL( KDestinationLat, buf ) ); |
|
210 |
|
211 MnrpUtils::CoordinateToString( destination.Longitude(), buf, ETrue, ETrue ); |
|
212 iListItems.AppendL( CListItem::NewL( KDestinationLon, buf ) ); |
|
213 |
|
214 if ( validPosition ) |
|
215 { |
|
216 MnrpUtils::AngleToString( iPositionRequest->MagneticCourse(), buf ); |
|
217 iListItems.AppendL( CListItem::NewL( KMagCourse, buf ) ); |
|
218 |
|
219 MnrpUtils::AngleToString( iPositionRequest->MagneticHeading(), buf ); |
|
220 iListItems.AppendL( CListItem::NewL( KMagHeading, buf ) ); |
|
221 } |
|
222 } |
|
223 |
|
224 return iListItems.Array(); |
|
225 } |
|
226 |
|
227 // ----------------------------------------------------------------------------- |
|
228 // ----------------------------------------------------------------------------- |
|
229 // |
|
230 void CMnrpNaviModel::HandlePositionRequestCompletedL( TInt aError ) |
|
231 { |
|
232 if ( !aError ) |
|
233 { |
|
234 iPositionRequest->GetPosition( iPosInfo ); |
|
235 TPosition position; |
|
236 iPosInfo.GetPosition( position ); |
|
237 |
|
238 iObserver.HandleModelUpdateL(); |
|
239 } |
|
240 iPositionRequest->FetchNewPosition(); |
|
241 } |
|