author | Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com> |
Wed, 13 Oct 2010 14:24:28 +0300 | |
branch | RCL_3 |
changeset 44 | 5033d469f7c9 |
parent 37 | 870918037e16 |
permissions | -rw-r--r-- |
37 | 1 |
/* |
2 |
* Copyright (c) 2004-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: Implements the CLandmarksInfoModel class |
|
15 |
* |
|
16 |
*/ |
|
17 |
||
18 |
||
19 |
||
20 |
#include <eikenv.h> |
|
21 |
#include <gulicon.h> |
|
22 |
#include <AknsUtils.h> |
|
23 |
#include <AknsItemID.h> |
|
24 |
#include <aknlocationed.h> |
|
25 |
||
26 |
#include <lbsposition.h> |
|
27 |
#include <EPos_CPosLandmark.h> |
|
28 |
#include <EPos_CPosLandmarkCategory.h> |
|
29 |
||
44
5033d469f7c9
Revision: 201038
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
37
diff
changeset
|
30 |
#include <LmRefApp.rsg> |
37 | 31 |
#include "LmRefApp.hrh" |
32 |
#include "LandmarksInfoModel.h" |
|
33 |
#include "LandmarksUtils.h" |
|
34 |
#include "LandmarksCommonData.h" |
|
35 |
#include "LandmarksApplicationEngine.h" |
|
36 |
||
37 |
const TInt KFieldCaptions[] = |
|
38 |
{ |
|
39 |
0, // this slot is not used |
|
40 |
R_LMREFAPP_LMNAME_LABEL_SHORT, // ELandmarkNameField |
|
41 |
R_LMREFAPP_DESCRIPTION_LABEL_SHORT, // ELandmarkDescField |
|
42 |
R_LMREFAPP_CATEGORY_LABEL_SHORT, // ELandmarkCategoryField |
|
43 |
R_LMREFAPP_LAT_LABEL_SHORT, // ELandmarkLatitudeField |
|
44 |
R_LMREFAPP_LON_LABEL_SHORT, // ELandmarkLongitudeField |
|
45 |
R_LMREFAPP_ALT_LABEL_SHORT, // ELandmarkAltitudeField |
|
46 |
R_LMREFAPP_HOR_ACC_LABEL_SHORT, // ELandmarkHorAccField |
|
47 |
R_LMREFAPP_VER_ACC_LABEL_SHORT, // ELandmarkVerAccField |
|
48 |
R_LMREFAPP_RADIUS_LABEL_SHORT, // ELandmarkRadiusField |
|
49 |
R_LMREFAPP_STREET_LABEL_SHORT, // ELandmarkStreetField |
|
50 |
R_LMREFAPP_POSTAL_LABEL_SHORT, // ELandmarkPostalField |
|
51 |
R_LMREFAPP_CITY_LABEL_SHORT, // ELandmarkCityField |
|
52 |
R_LMREFAPP_COUNTRY_LABEL_SHORT, // ELandmarkCountryField |
|
53 |
}; |
|
54 |
||
55 |
// ============================ MEMBER FUNCTIONS =============================== |
|
56 |
||
57 |
// ----------------------------------------------------------------------------- |
|
58 |
// ----------------------------------------------------------------------------- |
|
59 |
// |
|
60 |
CLandmarksInfoModel::CLandmarksInfoModel( |
|
61 |
CLandmarksApplicationEngine& aEngine) |
|
62 |
: iEngine(aEngine) |
|
63 |
{ |
|
64 |
// Configure real format |
|
65 |
const TChar KDecimalChar = '.'; |
|
66 |
iRealFormat.iPlaces = KNrOfDecimals; |
|
67 |
iRealFormat.iPoint = KDecimalChar; |
|
68 |
iRealFormat.iTriLen = 0; |
|
69 |
iRealFormat.iWidth = KPosLmMaxTextFieldLength; |
|
70 |
iRealFormat.iType = KRealFormatFixed; |
|
71 |
} |
|
72 |
||
73 |
// ----------------------------------------------------------------------------- |
|
74 |
// ----------------------------------------------------------------------------- |
|
75 |
// |
|
76 |
CLandmarksInfoModel::~CLandmarksInfoModel() |
|
77 |
{ |
|
78 |
} |
|
79 |
||
80 |
// ----------------------------------------------------------------------------- |
|
81 |
// ----------------------------------------------------------------------------- |
|
82 |
// |
|
83 |
CDesCArray* CLandmarksInfoModel::GetLandmarkInfoL( |
|
84 |
CPosLandmark& aLandmark, |
|
85 |
RArray<TInt>& aFieldIds) |
|
86 |
{ |
|
87 |
TPtrC fieldValue; |
|
88 |
aFieldIds.Reset(); |
|
89 |
||
90 |
const TInt KInfoArrayGranularity = 16; |
|
91 |
CDesCArray* infoArray = new (ELeave) CDesCArrayFlat(KInfoArrayGranularity); |
|
92 |
||
93 |
// Format landmark name |
|
94 |
fieldValue.Set(KNullDesC); |
|
95 |
aLandmark.GetLandmarkName(fieldValue); |
|
96 |
||
97 |
AddTextFieldL(ELandmarkNameField, fieldValue, *infoArray, aFieldIds); |
|
98 |
||
99 |
// Format description |
|
100 |
fieldValue.Set(KNullDesC); |
|
101 |
aLandmark.GetLandmarkDescription(fieldValue); |
|
102 |
||
103 |
AddTextFieldL(ELandmarkDescField, fieldValue, *infoArray, aFieldIds); |
|
104 |
||
105 |
// Format categories |
|
106 |
AddCategoryFieldsL(aLandmark, *infoArray, aFieldIds); |
|
107 |
||
108 |
// Format location fields |
|
109 |
TLocality location; |
|
110 |
aLandmark.GetPosition(location); |
|
111 |
AddLocationFieldsL(location, *infoArray, aFieldIds); |
|
112 |
||
113 |
// Format coverage Radius |
|
114 |
TReal32 coverageRadius; |
|
115 |
TBuf<KPosLmMaxTextFieldLength> radiusBuf; |
|
116 |
TInt res = aLandmark.GetCoverageRadius(coverageRadius); |
|
117 |
if (res != KErrNotFound) |
|
118 |
{ |
|
119 |
radiusBuf.AppendNum(coverageRadius, iRealFormat); |
|
120 |
} |
|
121 |
||
122 |
AddTextFieldL(ELandmarkRadiusField, radiusBuf, *infoArray, aFieldIds); |
|
123 |
||
124 |
// Format street; |
|
125 |
fieldValue.Set(KNullDesC); |
|
126 |
aLandmark.GetPositionField(EPositionFieldStreet, fieldValue); |
|
127 |
||
128 |
AddTextFieldL(ELandmarkStreetField, fieldValue, *infoArray, aFieldIds); |
|
129 |
||
130 |
// Format postalCode; |
|
131 |
fieldValue.Set(KNullDesC); |
|
132 |
aLandmark.GetPositionField(EPositionFieldPostalCode, fieldValue); |
|
133 |
||
134 |
AddTextFieldL(ELandmarkPostalField, fieldValue, *infoArray, aFieldIds); |
|
135 |
||
136 |
// Format city; |
|
137 |
fieldValue.Set(KNullDesC); |
|
138 |
aLandmark.GetPositionField(EPositionFieldCity, fieldValue); |
|
139 |
||
140 |
AddTextFieldL(ELandmarkCityField, fieldValue, *infoArray, aFieldIds); |
|
141 |
||
142 |
// Format country |
|
143 |
fieldValue.Set(KNullDesC); |
|
144 |
aLandmark.GetPositionField(EPositionFieldCountry, fieldValue); |
|
145 |
||
146 |
AddTextFieldL(ELandmarkCountryField, fieldValue, *infoArray, aFieldIds); |
|
147 |
||
148 |
return infoArray; |
|
149 |
} |
|
150 |
||
151 |
// ----------------------------------------------------------------------------- |
|
152 |
// ----------------------------------------------------------------------------- |
|
153 |
// |
|
154 |
void CLandmarksInfoModel::AddTextFieldL( |
|
155 |
TInt aFieldId, |
|
156 |
TDesC& aText, |
|
157 |
CDesCArray& aArray, |
|
158 |
RArray<TInt>& aFieldIds) |
|
159 |
{ |
|
160 |
if (aText.Length()) |
|
161 |
{ |
|
162 |
HBufC* caption = CCoeEnv::Static()-> |
|
163 |
AllocReadResourceAsDes16LC(KFieldCaptions[aFieldId]); |
|
164 |
||
165 |
const TInt KNumTabsAndOther = 10; |
|
166 |
HBufC* item = HBufC::NewLC( |
|
167 |
caption->Length() + aText.Length() + KNumTabsAndOther); |
|
168 |
||
169 |
_LIT(KItemFormat, "%S\t%S\t\t"); |
|
170 |
item->Des().Format(KItemFormat, caption, &aText); |
|
171 |
||
172 |
// append new item to the list |
|
173 |
aFieldIds.AppendL(aFieldId); |
|
174 |
aArray.AppendL(*item); |
|
175 |
CleanupStack::PopAndDestroy(2, caption); |
|
176 |
} |
|
177 |
} |
|
178 |
||
179 |
// ----------------------------------------------------------------------------- |
|
180 |
// ----------------------------------------------------------------------------- |
|
181 |
// |
|
182 |
void CLandmarksInfoModel::AddLocationFieldsL( |
|
183 |
TLocality& aLocation, |
|
184 |
CDesCArray& aArray, |
|
185 |
RArray<TInt>& aFieldIds) |
|
186 |
{ |
|
187 |
TBuf<KPosLmMaxTextFieldLength> fieldValue; |
|
188 |
||
189 |
TPosition pos( aLocation, TTime(0) ); |
|
190 |
||
191 |
// Format latitude in system format |
|
192 |
HBufC* latStr = CAknLocationEditor::DisplayableLocationL( |
|
193 |
pos, CAknLocationEditor::ELatitudeOnly ); |
|
194 |
CleanupStack::PushL( latStr ); |
|
195 |
AddTextFieldL( ELandmarkLatitudeField, *latStr, aArray, aFieldIds ); |
|
196 |
CleanupStack::PopAndDestroy( latStr ); |
|
197 |
||
198 |
// Format longitude in system format |
|
199 |
HBufC* lonStr = CAknLocationEditor::DisplayableLocationL( |
|
200 |
pos, CAknLocationEditor::ELongitudeOnly ); |
|
201 |
CleanupStack::PushL( lonStr ); |
|
202 |
AddTextFieldL( ELandmarkLongitudeField, *lonStr, aArray, aFieldIds ); |
|
203 |
CleanupStack::PopAndDestroy( lonStr ); |
|
204 |
||
205 |
// Format altitude |
|
206 |
LandmarksUtils::FloatToDes(aLocation.Altitude(), fieldValue, iRealFormat); |
|
207 |
AddTextFieldL(ELandmarkAltitudeField, fieldValue, aArray, aFieldIds); |
|
208 |
||
209 |
// Format horizontal accuracy |
|
210 |
LandmarksUtils::FloatToDes(aLocation.HorizontalAccuracy(), fieldValue, iRealFormat); |
|
211 |
AddTextFieldL(ELandmarkHorAccField, fieldValue, aArray, aFieldIds); |
|
212 |
||
213 |
// Format vertical accuracy |
|
214 |
LandmarksUtils::FloatToDes(aLocation.VerticalAccuracy(), fieldValue, iRealFormat); |
|
215 |
AddTextFieldL(ELandmarkVerAccField, fieldValue, aArray, aFieldIds); |
|
216 |
} |
|
217 |
||
218 |
// ----------------------------------------------------------------------------- |
|
219 |
// ----------------------------------------------------------------------------- |
|
220 |
// |
|
221 |
void CLandmarksInfoModel::AddCategoryFieldsL( |
|
222 |
CPosLandmark& aLandmark, |
|
223 |
CDesCArray& aArray, |
|
224 |
RArray<TInt>& aFieldIds) |
|
225 |
{ |
|
226 |
RArray< TPosLmItemId > categories; |
|
227 |
CleanupClosePushL(categories); |
|
228 |
aLandmark.GetCategoriesL(categories); |
|
229 |
TInt nrOfCategories = categories.Count(); |
|
230 |
||
231 |
for (TInt i = 0; i < nrOfCategories; i++) |
|
232 |
{ |
|
233 |
TPtrC categoryName; |
|
234 |
CPosLandmarkCategory* category = iEngine.CategoryLC(categories[i]); |
|
235 |
category->GetCategoryName(categoryName); |
|
236 |
||
237 |
AddTextFieldL(ELandmarkCategoryField, categoryName, aArray, aFieldIds); |
|
238 |
||
239 |
CleanupStack::PopAndDestroy(category); |
|
240 |
} |
|
241 |
||
242 |
CleanupStack::PopAndDestroy(&categories); |
|
243 |
} |
|
244 |
||
245 |
||
246 |