|
1 /* |
|
2 * Copyright (c) 2002-2006 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 - This file has implementation methods for Landmarks |
|
15 * individual fields. |
|
16 * |
|
17 */ |
|
18 |
|
19 |
|
20 |
|
21 |
|
22 |
|
23 |
|
24 |
|
25 // INCLUDE FILES |
|
26 #include <sysutil.h> |
|
27 #include <e32math.h> |
|
28 #include <EPos_CPosLandmarkDatabase.h> |
|
29 #include <AknUtils.h> |
|
30 #include "landmarks.hrh" |
|
31 #include "LmkConsts.h" |
|
32 #include "CLmkDbUtils.h" |
|
33 #include "CLmkFieldData.h" |
|
34 #include "CLmkFields.h" |
|
35 |
|
36 // CONSTANTS |
|
37 const TInt KMaxFieldLength50( 50 ); |
|
38 const TInt KMaxFieldLength20( 20 ); |
|
39 const TInt KMaxFieldLength10( 10 ); |
|
40 //const TInt KParaChar( 0x2029 ); |
|
41 |
|
42 |
|
43 // ============================ MEMBER FUNCTIONS ============================== |
|
44 // ---------------------------------------------------------------------------- |
|
45 // CLmkFields::CLmkFields |
|
46 // C++ default constructor can NOT contain any code, that |
|
47 // might leave. |
|
48 // ---------------------------------------------------------------------------- |
|
49 // |
|
50 |
|
51 CLmkFields::CLmkFields( |
|
52 RPointerArray<HBufC>& aLabelArray, |
|
53 CPosLandmarkDatabase& aDb, |
|
54 TLmkEditorAttributes aAttributes, |
|
55 TPosLmItemId aLandmarkId, |
|
56 CPosLandmark* aLandmark, |
|
57 TBool aJapaneseInputMode) |
|
58 : iDb( aDb ), |
|
59 iAttributes( aAttributes ), |
|
60 iLandmarkId( aLandmarkId ), |
|
61 iLandmark( aLandmark ), |
|
62 iFieldsArray(5), |
|
63 iLabelArray( &aLabelArray ), |
|
64 iJapaneseMode( aJapaneseInputMode ) |
|
65 { |
|
66 } |
|
67 |
|
68 // ---------------------------------------------------------------------------- |
|
69 // CLmkFields::ConstructL |
|
70 // Symbian 2nd phase constructor can leave. |
|
71 // ---------------------------------------------------------------------------- |
|
72 // |
|
73 void CLmkFields::ConstructL() |
|
74 { |
|
75 iNewLandmark = EFalse; |
|
76 if ( !iLandmark ) |
|
77 { |
|
78 if ( iLandmarkId != KPosLmNullItemId ) |
|
79 { |
|
80 iLandmark = iDb.ReadLandmarkLC(iLandmarkId); |
|
81 iNewLandmark = ETrue; |
|
82 CleanupStack::Pop(); //landmark |
|
83 } |
|
84 else |
|
85 { |
|
86 //create new empty landmark |
|
87 iLandmark = CPosLandmark::NewL(); |
|
88 iNewLandmark = ETrue; |
|
89 } |
|
90 } |
|
91 |
|
92 TRealX nan; |
|
93 nan.SetNaN(); |
|
94 |
|
95 iLocationData.iLatitude =nan; |
|
96 iLocationData.iLongitude =nan; |
|
97 iLocationData.iAltitude =nan; |
|
98 iLocationData.iVerticalAccuracy =nan; |
|
99 iLocationData.iHorizontalAccuracy =nan; |
|
100 |
|
101 CreateLmkFieldsL(); |
|
102 } |
|
103 |
|
104 // ---------------------------------------------------------------------------- |
|
105 // CLmkFields::NewL |
|
106 // Two-phased constructor. |
|
107 // ---------------------------------------------------------------------------- |
|
108 // |
|
109 EXPORT_C CLmkFields* CLmkFields::NewL( RPointerArray<HBufC>& aLabelArray, |
|
110 CPosLandmarkDatabase& aDb, |
|
111 TLmkEditorAttributes aAttributes, |
|
112 TPosLmItemId aLandmarkId, |
|
113 CPosLandmark* aLandmark, |
|
114 TBool aJapaneseInputMode ) |
|
115 |
|
116 { |
|
117 |
|
118 CLmkFields* self = new ( ELeave ) CLmkFields( aLabelArray, |
|
119 aDb, |
|
120 aAttributes, |
|
121 aLandmarkId, |
|
122 aLandmark, |
|
123 aJapaneseInputMode ); |
|
124 CleanupStack::PushL( self ); |
|
125 self->ConstructL(); |
|
126 CleanupStack::Pop(); |
|
127 return self; |
|
128 } |
|
129 |
|
130 // ---------------------------------------------------------------------------- |
|
131 // CLmkFields::~CLmkFields |
|
132 // ---------------------------------------------------------------------------- |
|
133 // |
|
134 EXPORT_C CLmkFields::~CLmkFields() |
|
135 { |
|
136 if ( iNewLandmark ) |
|
137 { |
|
138 delete iLandmark; |
|
139 } |
|
140 iFieldsArray.ResetAndDestroy(); |
|
141 } |
|
142 |
|
143 // ---------------------------------------------------------------------------- |
|
144 // CLmkFields::Fields |
|
145 // ---------------------------------------------------------------------------- |
|
146 // |
|
147 EXPORT_C CArrayPtrFlat<MLmkFieldData>& CLmkFields::Fields() |
|
148 { |
|
149 return iFieldsArray; |
|
150 } |
|
151 |
|
152 // ---------------------------------------------------------------------------- |
|
153 // CLmkFields::SaveFieldsL |
|
154 // ---------------------------------------------------------------------------- |
|
155 // |
|
156 EXPORT_C void CLmkFields::SaveFieldsL() |
|
157 { |
|
158 |
|
159 TInt count(iFieldsArray.Count()); |
|
160 TBool isPosFieldPresent = EFalse; |
|
161 |
|
162 for ( TInt i = 0; i < count; i++ ) |
|
163 { |
|
164 switch( iFieldsArray[i]->FieldType() ) |
|
165 { |
|
166 case EName: |
|
167 { |
|
168 iLandmark->SetLandmarkNameL( iFieldsArray[i]->TextData() ); |
|
169 HBufC* path = iFieldsArray[i]->IconPath(); |
|
170 if ( path && path->Length() > 0 && |
|
171 iFieldsArray[i]->IconId() != KErrNotFound ) |
|
172 { |
|
173 // Get the default Mask index |
|
174 iLandmark->SetIconL( *path, iFieldsArray[i]->IconId() , KLmkDefaultId+1); |
|
175 } |
|
176 |
|
177 break; |
|
178 } |
|
179 case ECategory: |
|
180 case ECategories: |
|
181 { |
|
182 //Add categories to landmark |
|
183 RArray<TPosLmItemId>& categories = |
|
184 iFieldsArray[i]->Categories(); |
|
185 TInt Tcount( categories.Count() ); |
|
186 for ( TInt j=0; j < Tcount; j++ ) |
|
187 { |
|
188 iLandmark->AddCategoryL( categories[j] ); |
|
189 } |
|
190 break; |
|
191 } |
|
192 case EDescription: |
|
193 { |
|
194 iLandmark->SetLandmarkDescriptionL( iFieldsArray[i]->TextData() ); |
|
195 break; |
|
196 } |
|
197 //these all are same |
|
198 case EStreet: |
|
199 case EPostCode: |
|
200 case ECity: |
|
201 case EStateProvince: |
|
202 case ECountry: |
|
203 case EPhoneNumber: |
|
204 case EWebAddress: |
|
205 { |
|
206 iLandmark->SetPositionFieldL( |
|
207 iFieldsArray[i]->PositionFieldId(), |
|
208 iFieldsArray[i]->TextData() ); |
|
209 break; |
|
210 } |
|
211 case ELatitude: |
|
212 { |
|
213 isPosFieldPresent = ETrue; |
|
214 iLocationData.iLatitude = iFieldsArray[i]->DoubleData(); |
|
215 break; |
|
216 } |
|
217 case ELongitude: |
|
218 { |
|
219 isPosFieldPresent = ETrue; |
|
220 iLocationData.iLongitude = iFieldsArray[i]->DoubleData(); |
|
221 break; |
|
222 } |
|
223 case EPositionAccuracy: |
|
224 { |
|
225 iLocationData.iHorizontalAccuracy = |
|
226 iFieldsArray[i]->FloatData(); |
|
227 break; |
|
228 } |
|
229 case EAltitude: |
|
230 { |
|
231 iLocationData.iAltitude = iFieldsArray[i]->FloatData(); |
|
232 break; |
|
233 } |
|
234 case EAltitudeAccuracy: |
|
235 { |
|
236 iLocationData.iVerticalAccuracy = iFieldsArray[i]->FloatData(); |
|
237 break; |
|
238 } |
|
239 default: |
|
240 { |
|
241 break; |
|
242 } |
|
243 } |
|
244 } |
|
245 |
|
246 //Position data |
|
247 iLocality = TLocality(); // empty locality |
|
248 |
|
249 if( isPosFieldPresent ) |
|
250 { |
|
251 // remove the old values to set new values |
|
252 iLandmark->RemoveLandmarkAttributes(CPosLandmark::EPosition); |
|
253 |
|
254 if ( !Math::IsNaN(iLocationData.iLatitude) && !Math::IsNaN(iLocationData.iLongitude) ) |
|
255 { |
|
256 if (!Math::IsNaN(iLocationData.iAltitude)) |
|
257 { |
|
258 iLocality.SetCoordinate( |
|
259 iLocationData.iLatitude, |
|
260 iLocationData.iLongitude, |
|
261 iLocationData.iAltitude); |
|
262 |
|
263 if (!Math::IsNaN(iLocationData.iVerticalAccuracy)) |
|
264 { |
|
265 if( iLocationData.iVerticalAccuracy > 0 ) |
|
266 iLocality.SetVerticalAccuracy(iLocationData.iVerticalAccuracy); |
|
267 } |
|
268 } |
|
269 else |
|
270 { |
|
271 iLocality.SetCoordinate( |
|
272 iLocationData.iLatitude, |
|
273 iLocationData.iLongitude); |
|
274 } |
|
275 |
|
276 if (!Math::IsNaN(iLocationData.iHorizontalAccuracy)) |
|
277 { |
|
278 if( iLocationData.iHorizontalAccuracy > 0 ) |
|
279 iLocality.SetHorizontalAccuracy(iLocationData.iHorizontalAccuracy); |
|
280 } |
|
281 // save position if at least lat/lon are entered |
|
282 iLandmark->SetPositionL(iLocality); |
|
283 } |
|
284 } |
|
285 |
|
286 /* |
|
287 * Check if this landmark still exists in database |
|
288 * (could have been potentially deleted some other app) |
|
289 * It it doesn't, then create a new landmark and add it to database |
|
290 */ |
|
291 |
|
292 TBool isLmPresent = ETrue; |
|
293 CPosLandmark *landmark = NULL; |
|
294 TPosLmItemId lmId = iLandmark->LandmarkId(); |
|
295 |
|
296 TRAPD(err, landmark = iDb.ReadLandmarkLC(lmId); |
|
297 CleanupStack::PopAndDestroy(landmark); |
|
298 ) |
|
299 |
|
300 if (err == KErrNotFound) // Landmark deleted already |
|
301 { |
|
302 isLmPresent = EFalse; |
|
303 } |
|
304 |
|
305 if ( (isLmPresent) && |
|
306 (iLandmark->LandmarkId() != KPosLmNullItemId) ) // Landmark exists in db |
|
307 { |
|
308 iDb.UpdateLandmarkL( *iLandmark ); |
|
309 } |
|
310 else // Lm does not exist in db |
|
311 { |
|
312 iLandmarkId = iDb.AddLandmarkL( *iLandmark ); |
|
313 } |
|
314 } |
|
315 |
|
316 // ---------------------------------------------------------------------------- |
|
317 // CLmkFields::DeleteLandmarkL |
|
318 // ---------------------------------------------------------------------------- |
|
319 // |
|
320 EXPORT_C void CLmkFields::DeleteLandmarkL() |
|
321 { |
|
322 if ( iLandmark ) |
|
323 { |
|
324 CLmkDbUtils::DeleteLandmarkL( iLandmark->LandmarkId(), iDb ); |
|
325 } |
|
326 } |
|
327 |
|
328 // ---------------------------------------------------------------------------- |
|
329 // CLmkFields::GetField |
|
330 // ---------------------------------------------------------------------------- |
|
331 // |
|
332 EXPORT_C MLmkFieldData* CLmkFields::GetField( TUint16 aFieldType ) |
|
333 { |
|
334 TInt count( iFieldsArray.Count() ); |
|
335 |
|
336 for ( TInt i=0; i<count; i++ ) |
|
337 { |
|
338 if ( iFieldsArray[i]->FieldType() == aFieldType ) |
|
339 { |
|
340 return iFieldsArray[i]; |
|
341 } |
|
342 } |
|
343 return NULL; |
|
344 } |
|
345 |
|
346 // ---------------------------------------------------------------------------- |
|
347 // CLmkFields::CreateLmkFieldsL |
|
348 // ---------------------------------------------------------------------------- |
|
349 // |
|
350 EXPORT_C TPosLmItemId CLmkFields::LandmarkId() const |
|
351 { |
|
352 return iLandmarkId; |
|
353 } |
|
354 |
|
355 // ---------------------------------------------------------------------------- |
|
356 // CLmkFields::CreateLmkFieldsL |
|
357 // ---------------------------------------------------------------------------- |
|
358 // |
|
359 void CLmkFields::CreateLmkFieldsL() |
|
360 { |
|
361 if ( iJapaneseMode ) // Japanese mode |
|
362 { |
|
363 CreateLmkFieldsInJapaneseModeL(); |
|
364 } |
|
365 else |
|
366 { |
|
367 CreateLmkFieldsInNormalModeL(); |
|
368 } |
|
369 } |
|
370 // ---------------------------------------------------------------------------- |
|
371 // CLmkFields::CreateLmkFieldsInJapaneseModeL() |
|
372 // ---------------------------------------------------------------------------- |
|
373 // |
|
374 void CLmkFields::CreateLmkFieldsInJapaneseModeL() |
|
375 { |
|
376 // Japanese address fields format |
|
377 //get location position |
|
378 iLandmark->GetPosition( iLocality ); |
|
379 CreateNameFieldL( ENameJapaneseMode ); // name field is always shown |
|
380 |
|
381 if ( ( iAttributes & CLmkEditorDlg::ELmkCategory ) != 0 ) |
|
382 { |
|
383 CreateCategoryFieldL(); |
|
384 } |
|
385 if ( ( iAttributes & CLmkEditorDlg::ELmkDescription ) != 0 ) |
|
386 { |
|
387 CreateDescriptionFieldL( EDescriptionJapaneseMode ); |
|
388 } |
|
389 if ( ( iAttributes & CLmkEditorDlg::ELmkPostalZIP ) != 0 ) |
|
390 { |
|
391 CreatePostCodeFieldL( EPostCodeJapaneseMode ); |
|
392 } |
|
393 if ( ( iAttributes & CLmkEditorDlg::ELmkStateProvince ) != 0 ) |
|
394 { |
|
395 CreateStateProvinceFieldL( EStateProvinceJapaneseMode ); |
|
396 } |
|
397 if ( ( iAttributes & CLmkEditorDlg::ELmkCity ) != 0 ) |
|
398 { |
|
399 CreateCityFieldL( ECityJapaneseMode ); |
|
400 } |
|
401 if ( ( iAttributes & CLmkEditorDlg::ELmkStreet ) != 0 ) |
|
402 { |
|
403 CreateStreetFieldL( EStreetJapaneseMode ); |
|
404 } |
|
405 if ( ( iAttributes & CLmkEditorDlg::ELmkCountry ) != 0 ) |
|
406 { |
|
407 CreateCountryFieldL( ECountryJapaneseMode ); |
|
408 } |
|
409 if ( ( iAttributes & CLmkEditorDlg::ELmkPhoneNumber ) != 0 ) |
|
410 { |
|
411 CreatePhoneNumberFieldL( EPhoneNumberJapaneseMode ); |
|
412 } |
|
413 if ( ( iAttributes & CLmkEditorDlg::ELmkWebAddress ) != 0 ) |
|
414 { |
|
415 CreateWebAddressFieldL( EWebAddressJapaneseMode ); |
|
416 } |
|
417 if ( ( iAttributes & CLmkEditorDlg::ELmkLatitude ) != 0 ) |
|
418 { |
|
419 CreateLatitudeFieldsL( ELatitudeJapaneseMode ); |
|
420 } |
|
421 if ( ( iAttributes & CLmkEditorDlg::ELmkLongitude ) != 0 ) |
|
422 { |
|
423 CreateLongitudeFieldsL( ELongitudeJapaneseMode ); |
|
424 } |
|
425 if ( ( iAttributes & CLmkEditorDlg::ELmkPositionAccuracy ) != 0 ) |
|
426 { |
|
427 CreatePositionAccuracyFieldL( EPositionAccuracyJapaneseMode ); |
|
428 } |
|
429 if ( ( iAttributes & CLmkEditorDlg::ELmkAltitude ) != 0 ) |
|
430 { |
|
431 CreateAltitudeFieldL( EAltitudeJapaneseMode ); |
|
432 } |
|
433 if ( ( iAttributes & CLmkEditorDlg::ELmkAltitudeAccuracy ) != 0 ) |
|
434 { |
|
435 CreateAltitudeAccuracyFieldL( EAltitudeAccuracyJapaneseMode ); |
|
436 } |
|
437 } |
|
438 |
|
439 // ---------------------------------------------------------------------------- |
|
440 // CLmkFields::CreateLmkFieldsInNormalModeL() |
|
441 // ---------------------------------------------------------------------------- |
|
442 // |
|
443 void CLmkFields::CreateLmkFieldsInNormalModeL() |
|
444 { |
|
445 //get location position |
|
446 iLandmark->GetPosition( iLocality ); |
|
447 CreateNameFieldL( EName ); // name field is always shown |
|
448 |
|
449 if ( ( iAttributes & CLmkEditorDlg::ELmkCategory ) != 0 ) |
|
450 { |
|
451 CreateCategoryFieldL( ); |
|
452 } |
|
453 if ( ( iAttributes & CLmkEditorDlg::ELmkDescription ) != 0 ) |
|
454 { |
|
455 CreateDescriptionFieldL( EDescription ); |
|
456 } |
|
457 if ( ( iAttributes & CLmkEditorDlg::ELmkStreet ) != 0 ) |
|
458 { |
|
459 CreateStreetFieldL( EStreet ); |
|
460 } |
|
461 if ( ( iAttributes & CLmkEditorDlg::ELmkPostalZIP ) != 0 ) |
|
462 { |
|
463 CreatePostCodeFieldL( EPostCode ); |
|
464 } |
|
465 if ( ( iAttributes & CLmkEditorDlg::ELmkCity ) != 0 ) |
|
466 { |
|
467 CreateCityFieldL( ECity ); |
|
468 } |
|
469 if ( ( iAttributes & CLmkEditorDlg::ELmkStateProvince ) != 0 ) |
|
470 { |
|
471 CreateStateProvinceFieldL( EStateProvince ); |
|
472 } |
|
473 if ( ( iAttributes & CLmkEditorDlg::ELmkCountry ) != 0 ) |
|
474 { |
|
475 CreateCountryFieldL( ECountry ); |
|
476 } |
|
477 if ( ( iAttributes & CLmkEditorDlg::ELmkPhoneNumber ) != 0 ) |
|
478 { |
|
479 CreatePhoneNumberFieldL( EPhoneNumberJapaneseMode ); |
|
480 } |
|
481 if ( ( iAttributes & CLmkEditorDlg::ELmkWebAddress ) != 0 ) |
|
482 { |
|
483 CreateWebAddressFieldL( EWebAddressJapaneseMode ); |
|
484 } |
|
485 if ( ( iAttributes & CLmkEditorDlg::ELmkLatitude ) != 0 ) |
|
486 { |
|
487 CreateLatitudeFieldsL( ELatitude ); |
|
488 } |
|
489 if ( ( iAttributes & CLmkEditorDlg::ELmkLongitude ) != 0 ) |
|
490 { |
|
491 CreateLongitudeFieldsL( ELongitude ); |
|
492 } |
|
493 if ( ( iAttributes & CLmkEditorDlg::ELmkPositionAccuracy ) != 0 ) |
|
494 { |
|
495 CreatePositionAccuracyFieldL( EPositionAccuracy ); |
|
496 } |
|
497 if ( ( iAttributes & CLmkEditorDlg::ELmkAltitude ) != 0 ) |
|
498 { |
|
499 CreateAltitudeFieldL( EAltitude ); |
|
500 } |
|
501 if ( ( iAttributes & CLmkEditorDlg::ELmkAltitudeAccuracy ) != 0 ) |
|
502 { |
|
503 CreateAltitudeAccuracyFieldL( EAltitudeAccuracy ); |
|
504 } |
|
505 } |
|
506 |
|
507 // ---------------------------------------------------------------------------- |
|
508 // CLmkFields::CreateNameFieldL |
|
509 // ---------------------------------------------------------------------------- |
|
510 // |
|
511 void CLmkFields::CreateNameFieldL( TInt aPos ) |
|
512 { |
|
513 // Landmark name field includes also icon id and path |
|
514 |
|
515 MLmkFieldData* field = CLmkFieldData::NewL( |
|
516 iLabelArray->operator[]( aPos ) ); |
|
517 CleanupStack::PushL(field); |
|
518 |
|
519 TPtrC lmkName; |
|
520 if ( iLandmark->GetLandmarkName( lmkName ) == KErrNone ) |
|
521 { |
|
522 field->SetTextL( lmkName ); |
|
523 field->SetFieldType( EName ); |
|
524 } |
|
525 |
|
526 TPtrC iconPath; |
|
527 TInt iconId; |
|
528 TInt iconMaskIndex; |
|
529 |
|
530 |
|
531 if ( iLandmark->GetIcon(iconPath,iconId, iconMaskIndex) == KErrNone ) |
|
532 { |
|
533 field->SetIconId( iconId ); |
|
534 field->SetIconPathL( iconPath ); |
|
535 } |
|
536 else |
|
537 { |
|
538 field->SetIconId( KErrNotFound ); |
|
539 } |
|
540 |
|
541 field->SetPositionFieldId( EPositionFieldNone ); |
|
542 field->SetEditorType( ETextGenericFieldEditor ); |
|
543 field->SetFieldLength( KMaxFieldLength50 ); |
|
544 field->SetTitleField( ETrue ); |
|
545 iFieldsArray.AppendL(field); |
|
546 |
|
547 CleanupStack::Pop(); //field |
|
548 |
|
549 } |
|
550 |
|
551 // ---------------------------------------------------------------------------- |
|
552 // CLmkFields::CreateCategoryFieldL |
|
553 // ---------------------------------------------------------------------------- |
|
554 // |
|
555 void CLmkFields::CreateCategoryFieldL() |
|
556 { |
|
557 TInt catLabelPos(0); |
|
558 if ( iJapaneseMode ) |
|
559 { |
|
560 catLabelPos = ECategoryJapaneseMode; |
|
561 } |
|
562 else |
|
563 { |
|
564 catLabelPos = ECategoryJapaneseMode; |
|
565 } |
|
566 |
|
567 MLmkFieldData* field = CLmkFieldData::NewL( |
|
568 iLabelArray->operator[](catLabelPos) ); |
|
569 CleanupStack::PushL(field); |
|
570 |
|
571 RArray<TPosLmItemId>& categories = field->Categories(); |
|
572 iLandmark->GetCategoriesL(categories); |
|
573 |
|
574 field->SetPositionFieldId( EPositionFieldNone ); |
|
575 if ( categories.Count() <= 1 ) |
|
576 { |
|
577 field->SetFieldType( ECategory ); |
|
578 } |
|
579 else |
|
580 { |
|
581 field->SetFieldType( ECategories ); |
|
582 if ( iJapaneseMode ) |
|
583 { |
|
584 field->SetLabel( iLabelArray->operator[]( ECategoriesJapaneseMode ) ); |
|
585 } |
|
586 else |
|
587 { |
|
588 field->SetLabel( iLabelArray->operator[]( ECategories ) ); |
|
589 } |
|
590 } |
|
591 field->SetEditorType( EListFieldEditor ); |
|
592 iFieldsArray.AppendL(field); |
|
593 CleanupStack::Pop(); //field |
|
594 |
|
595 //Remove all categories from landmark |
|
596 TInt count( categories.Count() ); |
|
597 for ( TInt i=0; i < count; i++ ) |
|
598 { |
|
599 iLandmark->RemoveCategory( categories[i] ); |
|
600 } |
|
601 } |
|
602 |
|
603 // ---------------------------------------------------------------------------- |
|
604 // CLmkFields::CreateStreetFieldL |
|
605 // ---------------------------------------------------------------------------- |
|
606 // |
|
607 void CLmkFields::CreateStreetFieldL( TInt aPos ) |
|
608 { |
|
609 MLmkFieldData* field = CLmkFieldData::NewL( |
|
610 iLabelArray->operator[]( aPos ) ); |
|
611 CleanupStack::PushL(field); |
|
612 |
|
613 TPtrC street; |
|
614 if ( iLandmark->GetPositionField( |
|
615 EPositionFieldStreet, street ) == KErrNone ) |
|
616 { |
|
617 field->SetTextL( street ); |
|
618 } |
|
619 |
|
620 field->SetFieldType( EStreet ); |
|
621 field->SetPositionFieldId( EPositionFieldStreet ); |
|
622 field->SetEditorType( ETextGenericFieldEditor ); |
|
623 field->SetFieldLength( KMaxFieldLength50 ); |
|
624 iFieldsArray.AppendL(field); |
|
625 |
|
626 CleanupStack::Pop(); //field |
|
627 } |
|
628 |
|
629 // ---------------------------------------------------------------------------- |
|
630 // CLmkFields::CreateCityFieldL |
|
631 // ---------------------------------------------------------------------------- |
|
632 // |
|
633 void CLmkFields::CreateCityFieldL( TInt aPos ) |
|
634 { |
|
635 MLmkFieldData* field = CLmkFieldData::NewL( |
|
636 iLabelArray->operator[]( aPos ) ); |
|
637 CleanupStack::PushL(field); |
|
638 |
|
639 TPtrC city; |
|
640 if ( iLandmark->GetPositionField( EPositionFieldCity, city ) == KErrNone ) |
|
641 { |
|
642 field->SetTextL( city ); |
|
643 } |
|
644 |
|
645 field->SetFieldType( ECity ); |
|
646 field->SetPositionFieldId( EPositionFieldCity ); |
|
647 field->SetEditorType( ETextGenericFieldEditor ); |
|
648 field->SetFieldLength( KMaxFieldLength50 ); |
|
649 iFieldsArray.AppendL(field); |
|
650 |
|
651 CleanupStack::Pop(); //field |
|
652 } |
|
653 |
|
654 // ---------------------------------------------------------------------------- |
|
655 // CLmkFields::CreateStateProvinceFieldL |
|
656 // ---------------------------------------------------------------------------- |
|
657 // |
|
658 void CLmkFields::CreateStateProvinceFieldL( TInt aPos ) |
|
659 { |
|
660 MLmkFieldData* field = CLmkFieldData::NewL( |
|
661 iLabelArray->operator[]( aPos ) ); |
|
662 CleanupStack::PushL(field); |
|
663 |
|
664 TPtrC stateProvince; |
|
665 if ( iLandmark->GetPositionField( |
|
666 EPositionFieldState, stateProvince ) == KErrNone ) |
|
667 { |
|
668 field->SetTextL( stateProvince ); |
|
669 } |
|
670 |
|
671 field->SetFieldType( EStateProvince ); |
|
672 field->SetPositionFieldId( EPositionFieldState ); |
|
673 field->SetEditorType( ETextGenericFieldEditor ); |
|
674 field->SetFieldLength( KMaxFieldLength50 ); |
|
675 iFieldsArray.AppendL(field); |
|
676 |
|
677 CleanupStack::Pop(); //field |
|
678 } |
|
679 |
|
680 // ---------------------------------------------------------------------------- |
|
681 // CLmkFields::CreateCountryFieldL |
|
682 // ---------------------------------------------------------------------------- |
|
683 // |
|
684 void CLmkFields::CreateCountryFieldL( TInt aPos ) |
|
685 { |
|
686 MLmkFieldData* field = CLmkFieldData::NewL( |
|
687 iLabelArray->operator[]( aPos ) ); |
|
688 CleanupStack::PushL(field); |
|
689 |
|
690 TPtrC country; |
|
691 if ( iLandmark->GetPositionField( |
|
692 EPositionFieldCountry, country ) == KErrNone ) |
|
693 { |
|
694 field->SetTextL( country ); |
|
695 } |
|
696 |
|
697 field->SetFieldType( ECountry ); |
|
698 field->SetPositionFieldId( EPositionFieldCountry ); |
|
699 field->SetEditorType( ETextGenericFieldEditor ); |
|
700 field->SetFieldLength( KMaxFieldLength50 ); |
|
701 iFieldsArray.AppendL(field); |
|
702 |
|
703 CleanupStack::Pop(); //field |
|
704 } |
|
705 |
|
706 // ---------------------------------------------------------------------------- |
|
707 // CLmkFields::CreatePostCodeFieldL |
|
708 // ---------------------------------------------------------------------------- |
|
709 // |
|
710 void CLmkFields::CreatePostCodeFieldL( TInt aPos ) |
|
711 { |
|
712 MLmkFieldData* field = CLmkFieldData::NewL( |
|
713 iLabelArray->operator[]( aPos) ); |
|
714 CleanupStack::PushL(field); |
|
715 |
|
716 TPtrC postcode; |
|
717 if ( iLandmark->GetPositionField( |
|
718 EPositionFieldPostalCode, postcode ) == KErrNone ) |
|
719 { |
|
720 field->SetTextL( postcode ); |
|
721 } |
|
722 |
|
723 field->SetFieldType( EPostCode ); |
|
724 field->SetPositionFieldId( EPositionFieldPostalCode ); |
|
725 field->SetEditorType( ETextGenericFieldEditor ); |
|
726 field->SetFieldLength( KMaxFieldLength20 ); |
|
727 iFieldsArray.AppendL(field); |
|
728 |
|
729 CleanupStack::Pop(); //field |
|
730 } |
|
731 |
|
732 // ---------------------------------------------------------------------------- |
|
733 // CLmkFields::CreateLatitudeFieldsL |
|
734 // ---------------------------------------------------------------------------- |
|
735 // |
|
736 void CLmkFields::CreateLatitudeFieldsL( TInt aPos ) |
|
737 { |
|
738 MLmkFieldData* field = CLmkFieldData::NewL( |
|
739 iLabelArray->operator[]( aPos ) ); |
|
740 CleanupStack::PushL(field); |
|
741 |
|
742 field->SetFieldType( ELatitude ); |
|
743 field->SetPositionFieldId( EPositionFieldNone ); |
|
744 field->SetEditorType( ECoordinateFieldEditor ); |
|
745 field->SetFieldLength( KMaxFieldLength10 ); |
|
746 field->SetTReal( iLocality.Latitude() ); |
|
747 iFieldsArray.AppendL(field); |
|
748 |
|
749 CleanupStack::Pop(); //field |
|
750 } |
|
751 |
|
752 // ---------------------------------------------------------------------------- |
|
753 // CLmkFields::CreateLongitudeFieldsL |
|
754 // ---------------------------------------------------------------------------- |
|
755 // |
|
756 void CLmkFields::CreateLongitudeFieldsL( TInt aPos ) |
|
757 { |
|
758 MLmkFieldData* field = CLmkFieldData::NewL( |
|
759 iLabelArray->operator[]( aPos ) ); |
|
760 CleanupStack::PushL(field); |
|
761 |
|
762 field->SetFieldType( ELongitude ); |
|
763 field->SetPositionFieldId( EPositionFieldNone ); |
|
764 field->SetEditorType( ECoordinateFieldEditor ); |
|
765 field->SetFieldLength( KMaxFieldLength10 ); |
|
766 field->SetTReal( iLocality.Longitude() ); |
|
767 iFieldsArray.AppendL(field); |
|
768 |
|
769 CleanupStack::Pop(); //field |
|
770 } |
|
771 // ---------------------------------------------------------------------------- |
|
772 // CLmkFields::CreatePositionAccuracyFieldL |
|
773 // ---------------------------------------------------------------------------- |
|
774 // |
|
775 void CLmkFields::CreatePositionAccuracyFieldL( TInt aPos ) |
|
776 { |
|
777 MLmkFieldData* field = CLmkFieldData::NewL( |
|
778 iLabelArray->operator[]( aPos ) ); |
|
779 CleanupStack::PushL(field); |
|
780 |
|
781 field->SetFieldType( EPositionAccuracy ); |
|
782 field->SetPositionFieldId( EPositionFieldNone ); |
|
783 field->SetEditorType( ENumberFieldEditor ); |
|
784 field->SetFieldLength( KMaxFieldLength10 ); |
|
785 field->SetTReal( iLocality.HorizontalAccuracy() ); |
|
786 iFieldsArray.AppendL(field); |
|
787 |
|
788 CleanupStack::Pop(); //field |
|
789 } |
|
790 |
|
791 // ---------------------------------------------------------------------------- |
|
792 // CLmkFields::CreateAltitudeFieldL |
|
793 // ---------------------------------------------------------------------------- |
|
794 // |
|
795 void CLmkFields::CreateAltitudeFieldL( TInt aPos ) |
|
796 { |
|
797 MLmkFieldData* field = CLmkFieldData::NewL( |
|
798 iLabelArray->operator[]( aPos ) ); |
|
799 CleanupStack::PushL(field); |
|
800 |
|
801 field->SetFieldType( EAltitude ); |
|
802 field->SetPositionFieldId( EPositionFieldNone ); |
|
803 field->SetEditorType( ENumberFieldEditor ); |
|
804 field->SetFieldLength( KMaxFieldLength10 ); |
|
805 field->SetTReal( iLocality.Altitude() ); |
|
806 iFieldsArray.AppendL(field); |
|
807 |
|
808 CleanupStack::Pop(); //field |
|
809 } |
|
810 |
|
811 // ---------------------------------------------------------------------------- |
|
812 // CLmkFields::CreateAltitudeAccuracyFieldL |
|
813 // ---------------------------------------------------------------------------- |
|
814 // |
|
815 void CLmkFields::CreateAltitudeAccuracyFieldL( TInt aPos ) |
|
816 { |
|
817 MLmkFieldData* field = CLmkFieldData::NewL( |
|
818 iLabelArray->operator[]( aPos ) ); |
|
819 CleanupStack::PushL(field); |
|
820 |
|
821 field->SetFieldType( EAltitudeAccuracy ); |
|
822 field->SetPositionFieldId( EPositionFieldNone ); |
|
823 field->SetEditorType( ENumberFieldEditor ); |
|
824 field->SetFieldLength( KMaxFieldLength10 ); |
|
825 field->SetTReal( iLocality.VerticalAccuracy() ); |
|
826 iFieldsArray.AppendL(field); |
|
827 |
|
828 CleanupStack::Pop(); //field |
|
829 } |
|
830 |
|
831 // ---------------------------------------------------------------------------- |
|
832 // CLmkFields::CreateDescriptionFieldL |
|
833 // ---------------------------------------------------------------------------- |
|
834 // |
|
835 void CLmkFields::CreateDescriptionFieldL( TInt aPos ) |
|
836 { |
|
837 MLmkFieldData* field = CLmkFieldData::NewL( |
|
838 iLabelArray->operator[]( aPos ) ); |
|
839 CleanupStack::PushL(field); |
|
840 |
|
841 TPtrC lmkDescription; |
|
842 |
|
843 // Get the description field info |
|
844 if ( iLandmark->GetLandmarkDescription( lmkDescription ) == KErrNone ) |
|
845 { |
|
846 field->SetTextL( lmkDescription ); |
|
847 field->SetFieldType( EDescription ); |
|
848 } |
|
849 |
|
850 field->SetFieldType( EDescription ); |
|
851 field->SetPositionFieldId( EPositionFieldNone ); |
|
852 field->SetEditorType( ETextGenericFieldEditor ); |
|
853 field->SetFieldLength( KMaxDescriptionFieldLen ); |
|
854 iFieldsArray.AppendL(field); |
|
855 CleanupStack::Pop(); //field |
|
856 } |
|
857 |
|
858 // ---------------------------------------------------------------------------- |
|
859 // CLmkFields::CreatePhoneNumberFieldL |
|
860 // ---------------------------------------------------------------------------- |
|
861 // |
|
862 void CLmkFields::CreatePhoneNumberFieldL( TInt aPos ) |
|
863 { |
|
864 MLmkFieldData* field = CLmkFieldData::NewL( |
|
865 iLabelArray->operator[]( aPos ) ); |
|
866 CleanupStack::PushL(field); |
|
867 |
|
868 TPtrC phoneNumber; |
|
869 if ( iLandmark->GetPositionField( |
|
870 ELmkPositionFieldPhoneNumber, phoneNumber ) == KErrNone ) |
|
871 { |
|
872 field->SetTextL( phoneNumber ); |
|
873 } |
|
874 |
|
875 field->SetFieldType( EPhoneNumber ); |
|
876 field->SetPositionFieldId( ELmkPositionFieldPhoneNumber ); |
|
877 field->SetEditorType( ETextPhoneNumberFieldEditor ); |
|
878 field->SetFieldLength( KMaxPhoneNumberFieldLen ); |
|
879 iFieldsArray.AppendL(field); |
|
880 |
|
881 CleanupStack::Pop(); //field |
|
882 } |
|
883 |
|
884 // ---------------------------------------------------------------------------- |
|
885 // CLmkFields::CreateWebAddressFieldL |
|
886 // ---------------------------------------------------------------------------- |
|
887 // |
|
888 void CLmkFields::CreateWebAddressFieldL( TInt aPos ) |
|
889 { |
|
890 MLmkFieldData* field = CLmkFieldData::NewL( iLabelArray->operator[]( aPos ) ); |
|
891 CleanupStack::PushL(field); |
|
892 |
|
893 TPtrC webAddress; |
|
894 if ( iLandmark->GetPositionField( |
|
895 ELmkPositionFieldWebAddress, webAddress ) == KErrNone ) |
|
896 { |
|
897 field->SetTextL( webAddress ); |
|
898 } |
|
899 |
|
900 /* |
|
901 * Web Address field is one of the data part of whole media link info |
|
902 * Media link -- name + Mime Info/format + URL |
|
903 * Right now Mime info not supported. |
|
904 * landmark's media link info containing '//' indicates a empty mime info |
|
905 * and remove the same before saving the received landmark to database |
|
906 */ |
|
907 |
|
908 HBufC* lmkField = HBufC::NewL( 256); |
|
909 CleanupStack::PushL( lmkField ); |
|
910 lmkField->Des().Copy( field->TextData() ); |
|
911 TPtr a = lmkField->Des(); |
|
912 CLmkDbUtils::RemoveDefaultProtocolL(a); |
|
913 field->SetTextL( lmkField->Des()); |
|
914 CleanupStack::PopAndDestroy( lmkField ); |
|
915 |
|
916 field->SetFieldType( EWebAddress); |
|
917 field->SetPositionFieldId( ELmkPositionFieldWebAddress); |
|
918 field->SetEditorType( ETextUriFieldEditor ); |
|
919 field->SetFieldLength( KMaxUrlFieldLen); |
|
920 iFieldsArray.AppendL(field); |
|
921 |
|
922 CleanupStack::Pop(); //field |
|
923 } |
|
924 //---------------------------------------------------------------------------- |
|
925 // CLmkFields::CheckDiscSpace() |
|
926 // ---------------------------------------------------------------------------- |
|
927 // |
|
928 EXPORT_C TInt CLmkFields::CheckDiscSpaceL() |
|
929 { |
|
930 RFs fs; |
|
931 User::LeaveIfError(fs.Connect()); |
|
932 CleanupClosePushL( fs ); |
|
933 if ( SysUtil::DiskSpaceBelowCriticalLevelL( &fs, sizeof( CPosLandmark ), EDriveC ) ) |
|
934 { |
|
935 CleanupStack::PopAndDestroy(); // fs |
|
936 return KErrDiskFull; |
|
937 } |
|
938 CleanupStack::PopAndDestroy(); // fs |
|
939 return KErrNone; |
|
940 } |
|
941 //---------------------------------------------------------------------------- |
|
942 // CLmkFields::RemoveEnterCharacter() |
|
943 // ---------------------------------------------------------------------------- |
|
944 // |
|
945 EXPORT_C TPtr CLmkFields::RemoveEnterCharacter( TPtrC aText ) |
|
946 { |
|
947 _LIT( KReplaceWhitespaceChars, "\x0009\x000A\x000B\x000C\x000D\x2028\x2029" ); |
|
948 _LIT(KSpace," "); |
|
949 TUint16* data = const_cast<TUint16*>(aText.Ptr()); |
|
950 TPtr des1(data,aText.Length()); |
|
951 des1.Copy(aText); |
|
952 AknTextUtils::ReplaceCharacters(des1,KReplaceWhitespaceChars,TChar(' ')); |
|
953 AknTextUtils::PackWhiteSpaces(des1, KSpace); |
|
954 return des1; |
|
955 } |
|
956 // End of File |