1 /* |
|
2 * Copyright (c) 2008 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: |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 #include "creator_landmarkelement.h" |
|
20 #include "creator_traces.h" |
|
21 #include "creator_landmark.h" |
|
22 |
|
23 using namespace creatorlandmark; |
|
24 |
|
25 /* |
|
26 * |
|
27 */ |
|
28 CCreatorLandmarkElement* CCreatorLandmarkElement::NewL(CCreatorEngine* aEngine, const TDesC& aName, const TDesC& aContext ) |
|
29 { |
|
30 CCreatorLandmarkElement* self = new (ELeave) CCreatorLandmarkElement(aEngine); |
|
31 CleanupStack::PushL(self); |
|
32 self->ConstructL(aName, aContext); |
|
33 CleanupStack::Pop(self); |
|
34 return self; |
|
35 } |
|
36 /* |
|
37 * |
|
38 */ |
|
39 CCreatorLandmarkElement::CCreatorLandmarkElement(CCreatorEngine* aEngine) |
|
40 : |
|
41 CCreatorScriptElement(aEngine) |
|
42 { |
|
43 iIsCommandElement = ETrue; |
|
44 } |
|
45 |
|
46 void CCreatorLandmarkElement::ExecuteCommandL() |
|
47 { |
|
48 const CCreatorScriptAttribute* amountAttr = FindAttributeByName(KAmount); |
|
49 TInt lmAmount = 1; |
|
50 if( amountAttr ) |
|
51 { |
|
52 lmAmount = ConvertStrToIntL(amountAttr->Value()); |
|
53 } |
|
54 // Get 'fields' element |
|
55 CCreatorScriptElement* fieldsElement = FindSubElement(KFields); |
|
56 if( fieldsElement && fieldsElement->SubElements().Count() > 0 ) |
|
57 { |
|
58 // Get sub-elements |
|
59 const RPointerArray<CCreatorScriptElement>& fields = fieldsElement->SubElements(); |
|
60 // Create note entries, the amount of entries is defined by noteAmount: |
|
61 for( TInt cI = 0; cI < lmAmount; ++cI ) |
|
62 { |
|
63 CLandmarkParameters* param = new (ELeave) CLandmarkParameters; |
|
64 CleanupStack::PushL(param); |
|
65 |
|
66 for( TInt i = 0; i < fields.Count(); ++i ) |
|
67 { |
|
68 CCreatorScriptElement* field = fields[i]; |
|
69 TPtrC elemName = field->Name(); |
|
70 TPtrC elemContent = field->Content(); |
|
71 const CCreatorScriptAttribute* randomAttr = fields[i]->FindAttributeByName(KRandomLength); |
|
72 TBool useRandom = EFalse; |
|
73 if( randomAttr || elemContent.Length() == 0 ) |
|
74 { |
|
75 useRandom = ETrue; |
|
76 } |
|
77 |
|
78 if( elemName == KName ) |
|
79 { |
|
80 if( useRandom ) |
|
81 { |
|
82 param->SetRandomNameL(*iEngine); |
|
83 } |
|
84 else |
|
85 { |
|
86 SetContentToTextParamL(param->iName, elemContent); |
|
87 } |
|
88 } |
|
89 else if( elemName == KCategory ) |
|
90 { |
|
91 if( useRandom ) |
|
92 { |
|
93 param->AddRandomCategoryL(*iEngine); |
|
94 } |
|
95 else |
|
96 { |
|
97 TPosLmItemId categoryId = CCreatorLandmarks::GetCategoryIdL(elemContent); |
|
98 if( categoryId > 0 ) |
|
99 { |
|
100 param->iCategories.AppendL(categoryId); |
|
101 } |
|
102 } |
|
103 } |
|
104 else if( elemName == KDescription ) |
|
105 { |
|
106 if( useRandom ) |
|
107 { |
|
108 param->SetRandomDescriptionL(*iEngine); |
|
109 } |
|
110 else |
|
111 { |
|
112 SetContentToTextParamL(param->iDescription, elemContent); |
|
113 } |
|
114 } |
|
115 else if( elemName == KStreet ) |
|
116 { |
|
117 if( useRandom ) |
|
118 { |
|
119 param->SetRandomStreetL(*iEngine); |
|
120 } |
|
121 else |
|
122 { |
|
123 SetContentToTextParamL(param->iStreet, elemContent); |
|
124 } |
|
125 } |
|
126 else if( elemName == KPostalcode ) |
|
127 { |
|
128 if( useRandom ) |
|
129 { |
|
130 param->SetRandomPostCodeL(*iEngine); |
|
131 } |
|
132 else |
|
133 { |
|
134 SetContentToTextParamL(param->iPostCode, elemContent); |
|
135 } |
|
136 } |
|
137 else if( elemName == KCity ) |
|
138 { |
|
139 if( useRandom ) |
|
140 { |
|
141 param->SetRandomCityL(*iEngine); |
|
142 } |
|
143 else |
|
144 { |
|
145 SetContentToTextParamL(param->iCity, elemContent); |
|
146 } |
|
147 } |
|
148 else if( elemName == KState ) |
|
149 { |
|
150 if( useRandom ) |
|
151 { |
|
152 param->SetRandomStateL(*iEngine); |
|
153 } |
|
154 else |
|
155 { |
|
156 SetContentToTextParamL(param->iState, elemContent); |
|
157 } |
|
158 } |
|
159 else if( elemName == KCountry ) |
|
160 { |
|
161 if( useRandom ) |
|
162 { |
|
163 param->SetRandomCountryL(*iEngine); |
|
164 } |
|
165 else |
|
166 { |
|
167 SetContentToTextParamL(param->iCountry, elemContent); |
|
168 } |
|
169 } |
|
170 else if( elemName == KPhonenumber ) |
|
171 { |
|
172 if( useRandom ) |
|
173 { |
|
174 param->SetRandomPhoneNumberL(*iEngine); |
|
175 } |
|
176 else |
|
177 { |
|
178 SetContentToTextParamL(param->iPhonenumber, elemContent); |
|
179 } |
|
180 } |
|
181 else if( elemName == KUrl ) |
|
182 { |
|
183 if( useRandom ) |
|
184 { |
|
185 param->SetRandomUrlL(*iEngine); |
|
186 } |
|
187 else |
|
188 { |
|
189 SetContentToTextParamL(param->iUrl, elemContent); |
|
190 } |
|
191 } |
|
192 else if( elemName == KLatitude ) |
|
193 { |
|
194 if( useRandom ) |
|
195 { |
|
196 param->SetRandomLatitudeL(*iEngine); |
|
197 } |
|
198 else |
|
199 { |
|
200 ConvertStrToReal64L(elemContent, param->iLatitude); |
|
201 } |
|
202 } |
|
203 else if( elemName == KLongitude ) |
|
204 { |
|
205 if( useRandom ) |
|
206 { |
|
207 param->SetRandomLongitudeL(*iEngine); |
|
208 } |
|
209 else |
|
210 { |
|
211 ConvertStrToReal64L(elemContent, param->iLongitude); |
|
212 } |
|
213 } |
|
214 else if( elemName == KPositionaccuracy ) |
|
215 { |
|
216 if( useRandom ) |
|
217 { |
|
218 param->SetRandomPositionAccuracyL(*iEngine); |
|
219 } |
|
220 else |
|
221 { |
|
222 param->iPositionAccuracy = ConvertStrToIntL(elemContent); |
|
223 } |
|
224 } |
|
225 else if( elemName == KAltitude ) |
|
226 { |
|
227 if( useRandom ) |
|
228 { |
|
229 param->SetRandomAltitudeL(*iEngine); |
|
230 } |
|
231 else |
|
232 { |
|
233 ConvertStrToReal32L(elemContent, param->iAltitude); |
|
234 } |
|
235 } |
|
236 else if( elemName == KAltitudeaccuracy ) |
|
237 { |
|
238 if( useRandom ) |
|
239 { |
|
240 param->SetRandomAltitudeAccuracyL(*iEngine); |
|
241 } |
|
242 else |
|
243 { |
|
244 param->iAltitudeAccuracy = ConvertStrToIntL(elemContent); |
|
245 } |
|
246 } |
|
247 } |
|
248 iEngine->AppendToCommandArrayL(ECmdCreateMiscEntryLandmarks, param); |
|
249 CleanupStack::Pop(); // param |
|
250 } |
|
251 } |
|
252 else |
|
253 { |
|
254 iEngine->AppendToCommandArrayL(ECmdCreateMiscEntryLandmarks, 0, lmAmount); |
|
255 } |
|
256 } |
|