|
1 /* |
|
2 * Copyright (c) 2002 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: LandmarksUi Content File - |
|
15 * Methods for Landmark editor field array. |
|
16 * |
|
17 */ |
|
18 |
|
19 |
|
20 |
|
21 |
|
22 |
|
23 |
|
24 |
|
25 // INCLUDE FILES |
|
26 #include "CLmkEditorFieldArray.h" // this class |
|
27 #include "MLmkEditorUiBuilder.h" |
|
28 #include "MLmkEditorField.h" |
|
29 #include "LmkEditorFieldFactory.h" |
|
30 #include "CLmkFields.h" |
|
31 #include "landmarks.hrh" |
|
32 #include "CLmkUiUtils.h" |
|
33 #include <bldvariant.hrh> |
|
34 #include <EPos_CPosLandmark.h> |
|
35 // Code added |
|
36 #include <e32math.h> |
|
37 #include <e32des16.h> |
|
38 |
|
39 // CONSTANTS |
|
40 /// Unnamed namespace for local definitions |
|
41 namespace { |
|
42 const TInt KNumberOfFields( 5 ); |
|
43 } // namespace |
|
44 // ================= MEMBER FUNCTIONS ======================= |
|
45 |
|
46 // ---------------------------------------------------- |
|
47 // CLmkEditorFieldArray::CLmkEditorFieldArray |
|
48 // ---------------------------------------------------- |
|
49 // |
|
50 CLmkEditorFieldArray::CLmkEditorFieldArray( CLmkFields& aLmkFields, |
|
51 MLmkEditorUiBuilder& aUiBuilder ) : |
|
52 iLmkFields( aLmkFields ), |
|
53 iUiBuilder( aUiBuilder ), |
|
54 iFieldArray(KNumberOfFields) |
|
55 { |
|
56 } |
|
57 |
|
58 // ---------------------------------------------------- |
|
59 // CLmkEditorFieldArray::ConstructL |
|
60 // ---------------------------------------------------- |
|
61 // |
|
62 void CLmkEditorFieldArray::ConstructL() |
|
63 { |
|
64 iCategoryFlag = EFalse; // Used for showing categories |
|
65 } |
|
66 |
|
67 // ---------------------------------------------------- |
|
68 // CLmkEditorFieldArray::NewL |
|
69 // ---------------------------------------------------- |
|
70 // |
|
71 CLmkEditorFieldArray* CLmkEditorFieldArray::NewL |
|
72 ( CLmkFields& aLmkFields, |
|
73 MLmkEditorUiBuilder& aUiBuilder ) |
|
74 { |
|
75 CLmkEditorFieldArray* dlg = new(ELeave) CLmkEditorFieldArray( aLmkFields, |
|
76 aUiBuilder ); |
|
77 CleanupStack::PushL( dlg ); |
|
78 dlg->ConstructL(); |
|
79 CleanupStack::Pop(); // dlg |
|
80 return dlg; |
|
81 } |
|
82 |
|
83 // ---------------------------------------------------- |
|
84 // CLmkEditorFieldArray::~CLmkEditorFieldArray |
|
85 // ---------------------------------------------------- |
|
86 // |
|
87 CLmkEditorFieldArray::~CLmkEditorFieldArray() |
|
88 { |
|
89 iFieldArray.ResetAndDestroy(); |
|
90 } |
|
91 |
|
92 // ---------------------------------------------------- |
|
93 // CLmkEditorFieldArray::UpdateFieldsL |
|
94 // ---------------------------------------------------- |
|
95 // |
|
96 void CLmkEditorFieldArray::UpdateFieldsL( const TUint16 aFieldType ) |
|
97 { |
|
98 TInt count = iFieldArray.Count(); |
|
99 for ( TInt i=0; i < count; i++ ) |
|
100 { |
|
101 if ( ( iFieldArray[i]->LandmarkItemField().FieldType() == |
|
102 aFieldType ) || ( aFieldType == EAllEditorItems ) ) |
|
103 { |
|
104 iFieldArray[i]->UpdateL(); |
|
105 } |
|
106 } |
|
107 } |
|
108 |
|
109 // ---------------------------------------------------- |
|
110 // CLmkEditorFieldArray::CreateFieldsFromLmkL |
|
111 // ---------------------------------------------------- |
|
112 // |
|
113 void CLmkEditorFieldArray::CreateFieldsFromLmkL() |
|
114 { |
|
115 CArrayPtrFlat<MLmkFieldData>& fields = iLmkFields.Fields(); |
|
116 TInt count = fields.Count(); |
|
117 |
|
118 for ( TInt i = 0; i < count; i++ ) |
|
119 { |
|
120 MLmkFieldData& lmkItemField = *fields[i]; |
|
121 TBool tight = ETrue; |
|
122 if(iUiBuilder.EditMode()) |
|
123 { |
|
124 tight = CheckIfFieldIsEmpty(lmkItemField); |
|
125 } |
|
126 MLmkEditorField* editorField = NULL; |
|
127 if( tight && iCategoryFlag && lmkItemField.EditorType() == EListFieldEditor ) |
|
128 { //if there are |
|
129 editorField = LmkEditorFieldFactory::CreateFieldL( |
|
130 lmkItemField, iUiBuilder,iCategoryName); |
|
131 iCategoryFlag = EFalse; // Safty purpose.... |
|
132 } |
|
133 else if(tight) |
|
134 { |
|
135 editorField = LmkEditorFieldFactory::CreateFieldL( |
|
136 lmkItemField, iUiBuilder ); |
|
137 } |
|
138 CleanupStack::PushL( editorField ); |
|
139 if ( editorField ) |
|
140 { |
|
141 iFieldArray.AppendL( editorField ); |
|
142 } |
|
143 CleanupStack::Pop(); //editorField |
|
144 } |
|
145 } |
|
146 |
|
147 // ---------------------------------------------------- |
|
148 // CLmkEditorFieldArray::AreAllFieldsEmptyL |
|
149 // ---------------------------------------------------- |
|
150 // |
|
151 TBool CLmkEditorFieldArray::AreAllFieldsEmptyL() const |
|
152 { |
|
153 TBool result = ETrue; |
|
154 TReal localVar; |
|
155 |
|
156 const TInt fieldCount = iFieldArray.Count(); |
|
157 for ( TInt i=0; i < fieldCount; i++ ) |
|
158 { |
|
159 switch( iFieldArray[i]->LandmarkItemField().EditorType() ) |
|
160 { |
|
161 //case ETextFieldEditor: |
|
162 case ETextGenericFieldEditor: |
|
163 case ETextPhoneNumberFieldEditor: |
|
164 { |
|
165 HBufC* fieldText = iFieldArray[i]->ControlTextL(); |
|
166 if ( fieldText && fieldText->Length() > 0 ) |
|
167 { |
|
168 //Check if any active character or not |
|
169 TPtr16 ptr = fieldText->Des(); |
|
170 ptr.Trim(); |
|
171 if (ptr.Length() == 0) |
|
172 { |
|
173 result = ETrue; |
|
174 } |
|
175 else |
|
176 { |
|
177 result = EFalse; |
|
178 } |
|
179 } |
|
180 delete fieldText; |
|
181 break; |
|
182 } |
|
183 case ETextUriFieldEditor: |
|
184 { |
|
185 HBufC* fieldText = iFieldArray[i]->ControlTextL(); |
|
186 |
|
187 if( fieldText && fieldText->Length() > 0 ) |
|
188 { |
|
189 //Check if any active character or not |
|
190 TPtr16 ptr = fieldText->Des(); |
|
191 ptr.Trim(); |
|
192 // Checking if the String present is only "http:\\" |
|
193 // If that is the case then the field is still |
|
194 // considered empty |
|
195 if(!CLmkUiUtils::FindIfWebAddrFieldIsEmpty(ptr)) |
|
196 { |
|
197 result = EFalse; |
|
198 } |
|
199 } |
|
200 delete fieldText; |
|
201 break; |
|
202 } |
|
203 case EListFieldEditor: |
|
204 { |
|
205 if ( iFieldArray[i]->LandmarkItemField().Categories().Count() ) |
|
206 { |
|
207 result = EFalse; |
|
208 } |
|
209 break; |
|
210 } |
|
211 case ENumberFieldEditor: |
|
212 { |
|
213 localVar = iFieldArray[i]->FieldValue(); |
|
214 if (!Math::IsNaN(localVar)) |
|
215 result = EFalse; |
|
216 break; |
|
217 } |
|
218 |
|
219 case ECoordinateFieldEditor: |
|
220 { |
|
221 localVar = iFieldArray[i]->FieldValue(); |
|
222 if (!Math::IsNaN(localVar)) |
|
223 result = EFalse; |
|
224 break; |
|
225 } |
|
226 |
|
227 |
|
228 default: |
|
229 { |
|
230 break; |
|
231 } |
|
232 } |
|
233 |
|
234 if ( !result ) |
|
235 { |
|
236 break; |
|
237 } |
|
238 } |
|
239 return result; |
|
240 } |
|
241 |
|
242 // ---------------------------------------------------- |
|
243 // CLmkEditorFieldArray::FieldAt |
|
244 // ---------------------------------------------------- |
|
245 // |
|
246 const MLmkEditorField& CLmkEditorFieldArray::FieldAt |
|
247 ( TInt aFieldIndex ) |
|
248 { |
|
249 return *iFieldArray[aFieldIndex]; |
|
250 } |
|
251 |
|
252 // ---------------------------------------------------- |
|
253 // CLmkEditorFieldArray::Find |
|
254 // ---------------------------------------------------- |
|
255 // |
|
256 MLmkEditorField* CLmkEditorFieldArray::Find( TInt aControlId, TInt* aPos, |
|
257 TInt* aPrevControlId ) const |
|
258 { |
|
259 MLmkEditorField* field = NULL; |
|
260 const TInt count = iFieldArray.Count(); |
|
261 for (TInt i = 0; i < count; ++i) |
|
262 { |
|
263 MLmkEditorField* temp = iFieldArray.At(i); |
|
264 if (temp && temp->ControlId() == aControlId ) |
|
265 { |
|
266 field = temp; |
|
267 if(aPos) |
|
268 { |
|
269 *aPos =i; |
|
270 } |
|
271 break; |
|
272 } |
|
273 if( (temp && aPrevControlId) && temp->ControlId() < aControlId) |
|
274 { |
|
275 *aPrevControlId = temp->ControlId(); |
|
276 } |
|
277 } |
|
278 return field; |
|
279 } |
|
280 |
|
281 // ---------------------------------------------------- |
|
282 // CLmkEditorFieldArray::SaveFieldsL |
|
283 // ---------------------------------------------------- |
|
284 // |
|
285 TBool CLmkEditorFieldArray::SaveFieldsL() |
|
286 { |
|
287 TBool result = EFalse; |
|
288 for ( TInt i(0); i < iFieldArray.Count(); ++i ) |
|
289 { |
|
290 if ( iFieldArray[i]->SaveFieldL() ) |
|
291 { |
|
292 result = ETrue; |
|
293 } |
|
294 } |
|
295 |
|
296 iLmkFields.SaveFieldsL(); |
|
297 return result; |
|
298 } |
|
299 |
|
300 // ---------------------------------------------------- |
|
301 // CLmkEditorFieldArray::SetCategoryName |
|
302 // ---------------------------------------------------- |
|
303 // |
|
304 void CLmkEditorFieldArray::SetCategoryName(const TDesC& aCategoryName) |
|
305 { |
|
306 iCategoryName.Copy(aCategoryName); |
|
307 iCategoryFlag = ETrue; |
|
308 } |
|
309 |
|
310 // ---------------------------------------------------- |
|
311 // CLmkEditorFieldArray::SaveFieldsToBufferL |
|
312 // ---------------------------------------------------- |
|
313 // |
|
314 void CLmkEditorFieldArray::SaveFieldsToBufferL() |
|
315 { |
|
316 for ( TInt i(0); i < iFieldArray.Count(); ++i ) |
|
317 { |
|
318 iFieldArray[i]->SaveFieldL(); |
|
319 } |
|
320 } |
|
321 |
|
322 // ---------------------------------------------------- |
|
323 // CLmkEditorFieldArray::GetFieldArray |
|
324 // ---------------------------------------------------- |
|
325 // |
|
326 CArrayPtrFlat<MLmkEditorField>& CLmkEditorFieldArray::GetFieldArray() |
|
327 { |
|
328 return iFieldArray; |
|
329 } |
|
330 |
|
331 // ---------------------------------------------------- |
|
332 // CLmkEditorFieldArray::CheckIfFieldIsEmpty |
|
333 // ---------------------------------------------------- |
|
334 // |
|
335 TBool CLmkEditorFieldArray::CheckIfFieldIsEmpty(MLmkFieldData& a) |
|
336 { |
|
337 TBool result = EFalse; |
|
338 switch( a.EditorType() ) |
|
339 { |
|
340 //case ETextFieldEditor: |
|
341 case ETextGenericFieldEditor: |
|
342 case ETextPhoneNumberFieldEditor: |
|
343 case ETextUriFieldEditor: |
|
344 { |
|
345 TPtrC buf = a.TextData(); |
|
346 if ( buf.Length() > 0 ) |
|
347 { |
|
348 result = ETrue; |
|
349 } |
|
350 break; |
|
351 } |
|
352 case EListFieldEditor: |
|
353 { |
|
354 RArray<TPosLmItemId>& t = a.Categories(); |
|
355 if ( t.Count() > 0 ) |
|
356 { |
|
357 result = ETrue; |
|
358 } |
|
359 break; |
|
360 } |
|
361 case ENumberFieldEditor: |
|
362 { |
|
363 TReal32 y = a.FloatData(); |
|
364 if(!Math::IsNaN(y)) |
|
365 { |
|
366 result = ETrue; |
|
367 } |
|
368 break; |
|
369 } |
|
370 case ECoordinateFieldEditor: |
|
371 { |
|
372 TReal64 z = a.DoubleData(); |
|
373 if(!Math::IsNaN(z)) |
|
374 { |
|
375 result = ETrue; |
|
376 } |
|
377 break; |
|
378 } |
|
379 } |
|
380 return result; |
|
381 } |
|
382 // End of File |