|
S60 3rd Edition SDK for Symbian OS Example Applications Guide |
00001 /* 00002 * ============================================================================== 00003 * Name : LandmarksEditDialog.cpp 00004 * Part of : Landmark Reference Application 00005 * Interface : - 00006 * Description : Implements the CLandmarksEditDialog class 00007 * Version : 1.0 00008 * 00009 * Copyright (c) 2004-2006 Nokia Corporation. 00010 * This material, including documentation and any related 00011 * computer programs, is protected by copyright controlled by 00012 * Nokia Corporation. 00013 * ============================================================================== 00014 */ 00015 00016 // INCLUDE FILES 00017 #include <eikmenub.h> 00018 #include <akntitle.h> 00019 #include <aknnotewrappers.h> 00020 #include <aknappui.h> 00021 #include <e32math.h> 00022 #include <eikcapc.h> 00023 #include <aknselectionlist.h> 00024 00025 #include <LbsPosition.h> 00026 #include <EPos_CPosLandmark.h> 00027 #include <EPos_CPosLandmarkCategory.h> 00028 00029 #include "LmRefApp.hrh" 00030 #include <LmRefApp.rsg> 00031 00032 #include "LandmarksUtils.h" 00033 #include "LandmarksCommonData.h" 00034 #include "LandmarksEditDialog.h" 00035 #include "LandmarksCategoriesDialog.h" 00036 #include "LandmarksPositionRequest.h" 00037 #include "LandmarksApplicationEngine.h" 00038 #include "LandmarksLmCategoriesModel.h" 00039 00040 // ============================ MEMBER FUNCTIONS =============================== 00041 00042 // ----------------------------------------------------------------------------- 00043 // CLandmarksEditDialog::CLandmarksEditDialog 00044 // C++ constructor can NOT contain any code, that 00045 // might leave. 00046 // ----------------------------------------------------------------------------- 00047 // 00048 CLandmarksEditDialog::CLandmarksEditDialog( 00049 CPosLandmark& aLandmark, 00050 TBool aUseCurrentLocation, 00051 TBool& aEdited, 00052 CLandmarksApplicationEngine& aEngine, 00053 TInt aInitialFocusFieldId) 00054 : iLandmark(&aLandmark), 00055 iUseCurrentLocation(aUseCurrentLocation), 00056 iEdited(aEdited), 00057 iEngine(aEngine), 00058 iInitialFocusFieldId(aInitialFocusFieldId) 00059 { 00060 iEdited = EFalse; 00061 00062 // Configure real format 00063 const TChar KDecimalChar = '.'; 00064 iRealFormat.iPlaces = KNrOfDecimals; 00065 iRealFormat.iPoint = KDecimalChar; 00066 iRealFormat.iTriLen = 0; 00067 iRealFormat.iWidth = KPosLmMaxTextFieldLength; 00068 iRealFormat.iType = KRealFormatFixed; 00069 } 00070 00071 // ----------------------------------------------------------------------------- 00072 // CLandmarksEditDialog::ConstructL 00073 // Symbian 2nd phase constructor can leave. 00074 // ----------------------------------------------------------------------------- 00075 // 00076 void CLandmarksEditDialog::ConstructL() 00077 { 00078 CAknForm::ConstructL(R_LMREFAPP_EDIT_MENU_BAR); 00079 00080 // Save original title 00081 CEikStatusPane* statusPane = iAvkonAppUi->StatusPane(); 00082 iTitlePane = (CAknTitlePane*) statusPane->ControlL( 00083 TUid::Uid(EEikStatusPaneUidTitle)); 00084 iOriginalTitle = iTitlePane->Text()->AllocL(); 00085 00086 // Create iPositionRequest 00087 HBufC* appName = iCoeEnv->AllocReadResourceAsDes16LC(R_LMREFAPP_APP_TITLE); 00088 iPositionRequest = CLandmarksPositionRequest::NewL(*appName, this); 00089 CleanupStack::PopAndDestroy(appName); 00090 00091 // Initialize iCategoryIds 00092 iLandmark->GetCategoriesL(iCategoryIds); 00093 00094 iLmCategoriesModel = 00095 CLandmarksLmCategoriesModel::NewL(iEngine, iCategoryIds); 00096 00097 // Initialise states of real value editors 00098 for (TInt i = ELatitudeEditor; i <= ERadiusEditor; i++) 00099 { 00100 User::LeaveIfError(iIsRealValueEdited.Append(EFalse)); 00101 } 00102 } 00103 00104 // ----------------------------------------------------------------------------- 00105 // CLandmarksEditDialog::NewLC 00106 // Two-phased constructor. 00107 // ----------------------------------------------------------------------------- 00108 // 00109 CLandmarksEditDialog* CLandmarksEditDialog::NewLC( 00110 CPosLandmark& aLandmark, 00111 TBool aUseCurrentLocation, 00112 TBool& aEdited, 00113 CLandmarksApplicationEngine& aEngine, 00114 TInt aInitialFocusFieldId) 00115 { 00116 CLandmarksEditDialog* self = new (ELeave) CLandmarksEditDialog( 00117 aLandmark, aUseCurrentLocation, aEdited, aEngine, aInitialFocusFieldId); 00118 CleanupStack::PushL(self); 00119 self->ConstructL(); 00120 return self; 00121 } 00122 00123 // Destructor 00124 CLandmarksEditDialog::~CLandmarksEditDialog() 00125 { 00126 delete iAppName; 00127 delete iPositionRequest; 00128 iCategoryIds.Close(); 00129 iIsRealValueEdited.Close(); 00130 delete iLmCategoriesModel; 00131 00132 // Restore title pane. Ownership of iTitlePane transferred. 00133 if (iTitlePane && iOriginalTitle) 00134 { 00135 iTitlePane->SetText(iOriginalTitle); 00136 } 00137 } 00138 00139 // ----------------------------------------------------------------------------- 00140 // CLandmarksEditDialog::DynInitMenuPaneL 00141 // 00142 // (other items were commented in a header). 00143 // ----------------------------------------------------------------------------- 00144 // 00145 void CLandmarksEditDialog::DynInitMenuPaneL( 00146 TInt aResourceId, 00147 CEikMenuPane* aMenuPane) 00148 { 00149 CAknForm::DynInitMenuPaneL(aResourceId, aMenuPane); 00150 if (aResourceId == R_AVKON_FORM_MENUPANE) 00151 { 00152 // We do not want to allow the user to modify our Form therefore 00153 // Disable the Label, Add, Delete, and Save Field 00154 aMenuPane->SetItemDimmed(EAknFormCmdLabel, ETrue); 00155 aMenuPane->SetItemDimmed(EAknFormCmdAdd, ETrue); 00156 aMenuPane->SetItemDimmed(EAknFormCmdDelete, ETrue); 00157 aMenuPane->SetItemDimmed(EAknFormCmdSave, ETrue); 00158 00159 aMenuPane->SetItemDimmed(ELandmarksUpdateToCurrentLocation, 00160 Control(ELandmarkCategoryField)->IsFocused()); 00161 aMenuPane->SetItemDimmed(ELandmarksEditCategories, 00162 !Control(ELandmarkCategoryField)->IsFocused()); 00163 } 00164 } 00165 00166 // ----------------------------------------------------------------------------- 00167 // CLandmarksEditDialog::ProcessCommandL 00168 // 00169 // (other items were commented in a header). 00170 // ----------------------------------------------------------------------------- 00171 // 00172 void CLandmarksEditDialog::ProcessCommandL(TInt aCommandId) 00173 { 00174 switch (aCommandId) 00175 { 00176 case ELandmarksUpdateToCurrentLocation: 00177 UpdateToCurrentLocationL(); 00178 break; 00179 00180 case ELandmarksEditCategories: 00181 EditCategoriesL(); 00182 break; 00183 00184 default: 00185 break; 00186 } 00187 00188 CAknForm::ProcessCommandL(aCommandId); 00189 } 00190 00191 // ----------------------------------------------------------------------------- 00192 // CLandmarksEditDialog::NotifyOperationProgressL 00193 // 00194 // (other items were commented in a header). 00195 // ----------------------------------------------------------------------------- 00196 // 00197 void CLandmarksEditDialog::NotifyOperationProgressL( 00198 TOperation aOperation, 00199 TInt /*aProgress*/, 00200 TInt aErrorCode) 00201 { 00202 if (aErrorCode == KErrNone && 00203 aOperation == EAcquiringLocation) 00204 { 00205 // Update location fields with new location 00206 TPosition position; 00207 iPositionInfo.GetPosition(position); 00208 ConfigureLocationFieldsL(position); 00209 SetChangesPending(ETrue); 00210 00211 // Indicate that editors have been updated 00212 for (TInt i = ELatitudeEditor; i <= EVerticalAccEditor; i++) 00213 { 00214 iIsRealValueEdited[i] = ETrue; 00215 } 00216 } 00217 } 00218 00219 // ----------------------------------------------------------------------------- 00220 // CLandmarksEditDialog::OkToExitL 00221 // 00222 // (other items were commented in a header). 00223 // ----------------------------------------------------------------------------- 00224 // 00225 TBool CLandmarksEditDialog::OkToExitL(TInt aButtonId) 00226 { 00227 if (aButtonId == EAknSoftkeyDone) 00228 { 00229 // exit from CAknForm's "edit" mode 00230 return CAknForm::OkToExitL(EAknSoftkeyBack); 00231 } 00232 else 00233 { 00234 return CAknForm::OkToExitL(aButtonId); 00235 } 00236 } 00237 00238 // ----------------------------------------------------------------------------- 00239 // CLandmarksEditDialog::PreLayoutDynInitL 00240 // 00241 // (other items were commented in a header). 00242 // ----------------------------------------------------------------------------- 00243 // 00244 void CLandmarksEditDialog::PreLayoutDynInitL() 00245 { 00246 SetEditableL(ETrue); 00247 ConfigureFieldsL(); 00248 ConfigureCategoryFieldL(); 00249 } 00250 00251 // ----------------------------------------------------------------------------- 00252 // CLandmarksEditDialog::PostLayoutDynInitL 00253 // 00254 // (other items were commented in a header). 00255 // ----------------------------------------------------------------------------- 00256 // 00257 void CLandmarksEditDialog::PostLayoutDynInitL() 00258 { 00259 SetChangesPending(ETrue); 00260 00261 UpdateTitleBarL(); 00262 CAknForm::PostLayoutDynInitL(); 00263 00264 if (iUseCurrentLocation) 00265 { 00266 UpdateToCurrentLocationL(); 00267 } 00268 } 00269 00270 // ----------------------------------------------------------------------------- 00271 // CLandmarksEditDialog::SetInitialCurrentLine 00272 // 00273 // (other items were commented in a header). 00274 // ----------------------------------------------------------------------------- 00275 // 00276 void CLandmarksEditDialog::SetInitialCurrentLine() 00277 { 00278 CAknForm::SetInitialCurrentLine(); 00279 00280 if (iInitialFocusFieldId >= ELandmarkNameField && 00281 iInitialFocusFieldId <= ELandmarkCountryField) 00282 { 00283 TInt err = KErrNone; 00284 TRAP(err, TryChangeFocusToL(iInitialFocusFieldId)); 00285 } 00286 } 00287 00288 // ----------------------------------------------------------------------------- 00289 // CLandmarksEditDialog::HandleControlEventL 00290 // 00291 // (other items were commented in a header). 00292 // ----------------------------------------------------------------------------- 00293 // 00294 void CLandmarksEditDialog::HandleControlEventL( 00295 CCoeControl* aControl, 00296 TCoeEvent aEventType) 00297 { 00298 CAknForm::HandleControlEventL(aControl, aEventType); 00299 00300 if (aEventType == EEventStateChanged) 00301 { 00302 if (aControl == ControlOrNull(ELandmarkLatitudeField)) 00303 { 00304 iIsRealValueEdited[ELatitudeEditor] = ETrue; 00305 } 00306 else if (aControl == ControlOrNull(ELandmarkLongitudeField)) 00307 { 00308 iIsRealValueEdited[ELongitudeEditor] = ETrue; 00309 } 00310 else if (aControl == ControlOrNull(ELandmarkAltitudeField)) 00311 { 00312 iIsRealValueEdited[EAltitudeEditor] = ETrue; 00313 } 00314 else if (aControl == ControlOrNull(ELandmarkHorAccField)) 00315 { 00316 iIsRealValueEdited[EHorizontalAccEditor] = ETrue; 00317 } 00318 else if (aControl == ControlOrNull(ELandmarkVerAccField)) 00319 { 00320 iIsRealValueEdited[EVerticalAccEditor] = ETrue; 00321 } 00322 else if (aControl == ControlOrNull(ELandmarkRadiusField)) 00323 { 00324 iIsRealValueEdited[ERadiusEditor] = ETrue; 00325 } 00326 else if (aControl == ControlOrNull(ELandmarkNameField)) 00327 { 00328 UpdateTitleBarL(ETrue); // get it from name field 00329 } 00330 } 00331 } 00332 00333 // ----------------------------------------------------------------------------- 00334 // CLandmarksEditDialog::SaveFormDataL 00335 // 00336 // (other items were commented in a header). 00337 // ----------------------------------------------------------------------------- 00338 // 00339 TBool CLandmarksEditDialog::SaveFormDataL() 00340 { 00341 CEikEdwin* editor = NULL; 00342 00343 // Fetch name 00344 TBuf<KPosLmMaxTextFieldLength> name; 00345 editor = static_cast <CEikEdwin*> (Control(ELandmarkNameField)); 00346 editor->GetText(name); 00347 00348 // Fetch description 00349 HBufC* descBuf = HBufC::NewLC(KPosLmMaxDescriptionLength); 00350 TPtr desc = descBuf->Des(); 00351 editor = static_cast <CEikEdwin*> (Control(ELandmarkDescField)); 00352 editor->GetText(desc); 00353 00354 // Fetch existing location 00355 TLocality existingLocation; 00356 TBool locationExists = 00357 (iLandmark->GetPosition(existingLocation) == KErrNone); 00358 TRealX floatFieldValue; 00359 00360 // Fetch Latitude 00361 TReal latitude = existingLocation.Latitude(); 00362 if (iIsRealValueEdited[ELatitudeEditor] || !locationExists) 00363 { 00364 FetchFloatL(floatFieldValue, ELandmarkLatitudeField, 00365 R_LMREFAPP_LATITUDE_ERROR); 00366 floatFieldValue.GetTReal(latitude); 00367 } 00368 00369 // Fetch Longitude 00370 TReal longitude = existingLocation.Longitude(); 00371 if (iIsRealValueEdited[ELongitudeEditor] || !locationExists) 00372 { 00373 FetchFloatL(floatFieldValue, ELandmarkLongitudeField, 00374 R_LMREFAPP_LONGITUDE_ERROR); 00375 floatFieldValue.GetTReal(longitude); 00376 } 00377 00378 // Fetch Altitude 00379 TReal32 altitude = existingLocation.Altitude(); 00380 if (iIsRealValueEdited[EAltitudeEditor] || !locationExists) 00381 { 00382 FetchFloatL(floatFieldValue, ELandmarkAltitudeField, 00383 R_LMREFAPP_ALTITUDE_ERROR); 00384 floatFieldValue.GetTReal(altitude); 00385 } 00386 00387 // Fetch horizontal accuracy 00388 TReal32 horAcc = existingLocation.HorizontalAccuracy(); 00389 if (iIsRealValueEdited[EHorizontalAccEditor] || !locationExists) 00390 { 00391 FetchFloatL(floatFieldValue, ELandmarkHorAccField, 00392 R_LMREFAPP_HOR_ACC_ERROR); 00393 floatFieldValue.GetTReal(horAcc); 00394 } 00395 00396 // Fetch vertical accuracy 00397 TReal32 verAcc = existingLocation.VerticalAccuracy(); 00398 if (iIsRealValueEdited[EVerticalAccEditor] || !locationExists) 00399 { 00400 FetchFloatL(floatFieldValue, ELandmarkVerAccField, 00401 R_LMREFAPP_VER_ACC_ERROR); 00402 floatFieldValue.GetTReal(verAcc); 00403 } 00404 00405 // Fetch Coverage Radius 00406 TReal32 radius; 00407 TInt radiusExists = (iLandmark->GetCoverageRadius(radius) == KErrNone); 00408 if (iIsRealValueEdited[ERadiusEditor] || !radiusExists) 00409 { 00410 FetchFloatL(floatFieldValue, ELandmarkRadiusField, 00411 R_LMREFAPP_RADIUS_ERROR); 00412 floatFieldValue.GetTReal(radius); 00413 } 00414 00415 // Fetch street 00416 TBuf<KPosLmMaxTextFieldLength> street; 00417 editor = 00418 static_cast <CEikEdwin*> (Control(ELandmarkStreetField)); 00419 editor->GetText(street); 00420 00421 // Fetch postal code 00422 TBuf<KPosLmMaxTextFieldLength> postalCode; 00423 editor = 00424 static_cast <CEikEdwin*> (Control(ELandmarkPostalField)); 00425 editor->GetText(postalCode); 00426 00427 // Fetch city 00428 TBuf<KPosLmMaxTextFieldLength> city; 00429 editor = static_cast <CEikEdwin*> (Control(ELandmarkCityField)); 00430 editor->GetText(city); 00431 00432 // Fetch country 00433 TBuf<KPosLmMaxTextFieldLength> country; 00434 editor = 00435 static_cast <CEikEdwin*> (Control(ELandmarkCountryField)); 00436 editor->GetText(country); 00437 00438 // Update category 00439 iLandmark->RemoveLandmarkAttributes(CPosLandmark::ECategoryInfo); 00440 for (TInt i = 0; i < iCategoryIds.Count(); i++) 00441 { 00442 iLandmark->AddCategoryL(iCategoryIds[i]); 00443 } 00444 // Check that at least some data is entered 00445 if (!name.Length() && !desc.Length() && 00446 !street.Length() && !city.Length() && 00447 !country.Length() && !postalCode.Length() && 00448 !iCategoryIds.Count() && 00449 Math::IsNaN(latitude) && Math::IsNaN(longitude) && 00450 Math::IsNaN(altitude) && Math::IsNaN(radius) && 00451 Math::IsNaN(horAcc) && Math::IsNaN(verAcc)) 00452 { 00453 NotifyErrorToUserL(R_LMREFAPP_EMPTY_LANDMARK); 00454 } 00455 00456 // Update name 00457 iLandmark->SetLandmarkNameL(name); 00458 00459 // Update description 00460 iLandmark->SetLandmarkDescriptionL(desc); 00461 CleanupStack::PopAndDestroy(descBuf); 00462 00463 // Update coverage radius 00464 if (!Math::IsNaN(radius) && radius < 0) 00465 { 00466 NotifyErrorToUserL(R_LMREFAPP_RADIUS_ERROR); 00467 } 00468 iLandmark->SetCoverageRadius(radius); 00469 00470 // Update street 00471 iLandmark->SetPositionFieldL(EPositionFieldStreet, street); 00472 00473 // Update postal code 00474 iLandmark->SetPositionFieldL(EPositionFieldPostalCode, postalCode); 00475 00476 // Update city 00477 iLandmark->SetPositionFieldL(EPositionFieldCity, city); 00478 00479 // Update country 00480 iLandmark->SetPositionFieldL(EPositionFieldCountry, country); 00481 00482 // Update location. There are some rules specified by TLocality and 00483 // TCoordinate how to update a location. These rules are taken into 00484 // account below when validating the location data. 00485 if (Math::IsNaN(latitude) && Math::IsNaN(longitude)) 00486 { 00487 // If lat long are undefined, then alt and hAcc 00488 // must be undefined 00489 if (!Math::IsNaN(horAcc)) 00490 { 00491 NotifyErrorToUserL(R_LMREFAPP_HACC_LAT_LONG_ERROR); 00492 } 00493 else if (!Math::IsNaN(altitude)) 00494 { 00495 NotifyErrorToUserL(R_LMREFAPP_ALT_LAT_LONG_ERROR); 00496 } 00497 else if (!Math::IsNaN(verAcc)) 00498 { 00499 NotifyErrorToUserL(R_LMREFAPP_VACC_ALT_ERROR); 00500 } 00501 else 00502 { 00503 // None position fields are set, Remove position info. 00504 iLandmark->RemoveLandmarkAttributes(CPosLandmark::EPosition); 00505 } 00506 } 00507 else if (!Math::IsNaN(latitude) && !Math::IsNaN(longitude)) 00508 { 00509 // If lat long are defined, hAcc must be positive if defined 00510 if (!Math::IsNaN(horAcc) && horAcc < 0) 00511 { 00512 NotifyErrorToUserL(R_LMREFAPP_HOR_ACC_ERROR); 00513 } 00514 00515 // if altitude is undefined, then vertical accuracy 00516 // must be undefined 00517 if (Math::IsNaN(altitude) && !Math::IsNaN(verAcc)) 00518 { 00519 NotifyErrorToUserL(R_LMREFAPP_VACC_ALT_ERROR); 00520 } 00521 00522 // vertical accuracy must be positive if defined 00523 if (!Math::IsNaN(verAcc) && verAcc < 0) 00524 { 00525 NotifyErrorToUserL(R_LMREFAPP_VER_ACC_ERROR); 00526 } 00527 00528 // We are allowed to set the new locality 00529 TCoordinate coordinate(latitude, longitude, altitude); 00530 TLocality newLocation(coordinate, horAcc, verAcc); 00531 iLandmark->SetPositionL(newLocation); 00532 } 00533 else 00534 { 00535 // Inform user that no valid lat/long has been entered 00536 NotifyErrorToUserL(R_LMREFAPP_LAT_LONG_ERROR); 00537 } 00538 00539 iEdited = ETrue; 00540 return ETrue; 00541 } 00542 00543 // ----------------------------------------------------------------------------- 00544 // CLandmarksEditDialog::ConfigureFieldsL 00545 // 00546 // (other items were commented in a header). 00547 // ----------------------------------------------------------------------------- 00548 // 00549 void CLandmarksEditDialog::ConfigureFieldsL() 00550 { 00551 TPtrC textFieldValue; 00552 00553 // Configure landmark name 00554 textFieldValue.Set(KNullDesC); 00555 iLandmark->GetLandmarkName(textFieldValue); 00556 00557 ConfigureTextFieldL(ELandmarkNameField, textFieldValue); 00558 00559 // Configure description 00560 textFieldValue.Set(KNullDesC); 00561 iLandmark->GetLandmarkDescription(textFieldValue); 00562 00563 ConfigureTextFieldL(ELandmarkDescField, textFieldValue); 00564 00565 // Configure street; 00566 textFieldValue.Set(KNullDesC); 00567 iLandmark->GetPositionField(EPositionFieldStreet, textFieldValue); 00568 00569 ConfigureTextFieldL(ELandmarkStreetField, textFieldValue); 00570 00571 // Configure postalCode; 00572 textFieldValue.Set(KNullDesC); 00573 iLandmark->GetPositionField(EPositionFieldPostalCode, textFieldValue); 00574 00575 ConfigureTextFieldL(ELandmarkPostalField, textFieldValue); 00576 00577 // Configure city; 00578 textFieldValue.Set(KNullDesC); 00579 iLandmark->GetPositionField(EPositionFieldCity, textFieldValue); 00580 00581 ConfigureTextFieldL(ELandmarkCityField, textFieldValue); 00582 00583 // Configure country 00584 textFieldValue.Set(KNullDesC); 00585 iLandmark->GetPositionField(EPositionFieldCountry, textFieldValue); 00586 00587 ConfigureTextFieldL(ELandmarkCountryField, textFieldValue); 00588 00589 // Configure location fields 00590 TLocality location; 00591 iLandmark->GetPosition(location); 00592 ConfigureLocationFieldsL(location); 00593 00594 // Configure coverage Radius 00595 TReal32 coverageRadius; 00596 TBuf<KPosLmMaxTextFieldLength> radiusBuf; 00597 TInt res = iLandmark->GetCoverageRadius(coverageRadius); 00598 if (res != KErrNotFound) 00599 { 00600 radiusBuf.AppendNum(coverageRadius, iRealFormat); 00601 } 00602 00603 ConfigureTextFieldL(ELandmarkRadiusField, radiusBuf); 00604 } 00605 00606 // ----------------------------------------------------------------------------- 00607 // CLandmarksEditDialog::ConfigureLocationFieldsL 00608 // 00609 // (other items were commented in a header). 00610 // ----------------------------------------------------------------------------- 00611 // 00612 void CLandmarksEditDialog::ConfigureLocationFieldsL(TLocality& aLocation) 00613 { 00614 TBuf<KPosLmMaxTextFieldLength> textFieldValue; 00615 00616 // Configure latitude in float format 00617 LandmarksUtils::LatLongToDes(aLocation.Latitude(), textFieldValue); 00618 ConfigureTextFieldL(ELandmarkLatitudeField, textFieldValue); 00619 00620 // Configure longitude in float format 00621 LandmarksUtils::LatLongToDes(aLocation.Longitude(), textFieldValue); 00622 ConfigureTextFieldL(ELandmarkLongitudeField, textFieldValue); 00623 00624 // Configure altitude 00625 LandmarksUtils::FloatToDesL(aLocation.Altitude(), textFieldValue, iRealFormat); 00626 ConfigureTextFieldL(ELandmarkAltitudeField, textFieldValue); 00627 00628 // Configure horizontal accuracy 00629 LandmarksUtils::FloatToDesL(aLocation.HorizontalAccuracy(), textFieldValue, iRealFormat); 00630 ConfigureTextFieldL(ELandmarkHorAccField, textFieldValue); 00631 00632 // Configure vertical accuracy 00633 LandmarksUtils::FloatToDesL(aLocation.VerticalAccuracy(), textFieldValue, iRealFormat); 00634 ConfigureTextFieldL(ELandmarkVerAccField, textFieldValue); 00635 } 00636 00637 // ----------------------------------------------------------------------------- 00638 // CLandmarksEditDialog::ConfigureCategoryFieldL 00639 // 00640 // (other items were commented in a header). 00641 // ----------------------------------------------------------------------------- 00642 // 00643 void CLandmarksEditDialog::ConfigureCategoryFieldL() 00644 { 00645 TInt nrOfCategories = iCategoryIds.Count(); 00646 const TInt KExtraChars = 2; // CRLF 00647 00648 HBufC* lmCategoriesBuf = HBufC::NewLC( 00649 (KPosLmMaxTextFieldLength + KExtraChars) * nrOfCategories); 00650 00651 TPtr lmCategories = lmCategoriesBuf->Des(); 00652 for (TInt i = 0; i < nrOfCategories; i++) 00653 { 00654 if (i > 0) 00655 { 00656 lmCategories.Append(CEditableText::ELineBreak); 00657 } 00658 00659 CPosLandmarkCategory* category = iEngine.CategoryLC(iCategoryIds[i]); 00660 TPtrC categoryName; 00661 category->GetCategoryName(categoryName); 00662 lmCategories.Append(categoryName); 00663 CleanupStack::PopAndDestroy(category); 00664 } 00665 00666 ConfigureTextFieldL(ELandmarkCategoryField, *lmCategoriesBuf); 00667 00668 CleanupStack::PopAndDestroy(lmCategoriesBuf); 00669 } 00670 00671 void CLandmarksEditDialog::ConfigureTextFieldL(TInt aId, const TDesC& aText) 00672 { 00673 CEikEdwin* editor = static_cast<CEikEdwin*>(Control(aId)); 00674 editor->SetTextL(&aText); 00675 } 00676 00677 // ----------------------------------------------------------------------------- 00678 // CLandmarksEditDialog::UpdateTitleBarL 00679 // 00680 // (other items were commented in a header). 00681 // ----------------------------------------------------------------------------- 00682 // 00683 void CLandmarksEditDialog::UpdateTitleBarL(TBool aFromField) 00684 { 00685 if (aFromField) 00686 { 00687 TBuf<KPosLmMaxTextFieldLength> name; 00688 00689 CEikEdwin* nameEditor = 00690 static_cast<CEikEdwin*>(Control(ELandmarkNameField)); 00691 nameEditor->GetText(name); 00692 iTitlePane->SetTextL(name); 00693 } 00694 else 00695 { 00696 TPtrC ptr; 00697 iLandmark->GetLandmarkName(ptr); 00698 iTitlePane->SetTextL(ptr); 00699 } 00700 } 00701 00702 // ----------------------------------------------------------------------------- 00703 // CLandmarksEditDialog::FetchFloatL 00704 // 00705 // (other items were commented in a header). 00706 // ----------------------------------------------------------------------------- 00707 // 00708 void CLandmarksEditDialog::FetchFloatL( 00709 TRealX& aFloat, 00710 TInt aEditorResourceId, 00711 TInt aErrorResourceId) 00712 { 00713 const TChar KDecimalPoint = '.'; 00714 TBuf<KPosLmMaxTextFieldLength> textFieldValue; 00715 TLex fieldLex; 00716 TInt result(KErrNone); 00717 CEikEdwin* editor = static_cast <CEikEdwin*> (Control(aEditorResourceId)); 00718 00719 editor->GetText(textFieldValue); 00720 if (textFieldValue == KNullDesC) 00721 { 00722 // User has indicated that he/she wants this value to be undefined. 00723 aFloat.SetNaN(); 00724 } 00725 else 00726 { 00727 // Try to extract value 00728 fieldLex = textFieldValue; 00729 TReal floatValue(0); 00730 result = fieldLex.Val(floatValue, KDecimalPoint); 00731 if (result != KErrNone) 00732 { 00733 NotifyErrorToUserL(aErrorResourceId); 00734 } 00735 00736 // Update output parameter 00737 User::LeaveIfError(aFloat.Set(floatValue)); 00738 } 00739 } 00740 00741 // ----------------------------------------------------------------------------- 00742 // CLandmarksEditDialog::NotifyErrorToUserL 00743 // 00744 // (other items were commented in a header). 00745 // ----------------------------------------------------------------------------- 00746 // 00747 void CLandmarksEditDialog::NotifyErrorToUserL(TInt aResourceId) 00748 { 00749 HBufC* msg = iCoeEnv->AllocReadResourceLC(aResourceId); 00750 CAknErrorNote* errorNote = new (ELeave) CAknErrorNote(ETrue); 00751 errorNote->ExecuteLD(*msg); 00752 CleanupStack::PopAndDestroy(msg); 00753 00754 // Leave to interrupt saving of data. Other error codes than KErrNone 00755 // results in an additional error dialog. 00756 User::Leave(KErrNone); 00757 } 00758 00759 // ----------------------------------------------------------------------------- 00760 // CLandmarksEditDialog::EditCategoriesL 00761 // 00762 // (other items were commented in a header). 00763 // ----------------------------------------------------------------------------- 00764 // 00765 void CLandmarksEditDialog::EditCategoriesL() 00766 { 00767 TInt res = CLandmarksCategoriesDialog::RunDialogL(*iLmCategoriesModel); 00768 if (res) 00769 { 00770 ConfigureCategoryFieldL(); 00771 DrawDeferred(); 00772 SetChangesPending(ETrue); 00773 } 00774 } 00775 00776 // ----------------------------------------------------------------------------- 00777 // CLandmarksEditDialog::UpdateToCurrentLocationL 00778 // 00779 // (other items were commented in a header). 00780 // ----------------------------------------------------------------------------- 00781 // 00782 void CLandmarksEditDialog::UpdateToCurrentLocationL() 00783 { 00784 // Update location fields to current location 00785 HBufC* title = 00786 iCoeEnv->AllocReadResourceAsDes16LC(R_LMREFAPP_ACQUIRING_LOC); 00787 iPositionRequest->FetchPositionInfoL(*title, iPositionInfo); 00788 CleanupStack::PopAndDestroy(title); 00789 } 00790 00791 // End of File 00792
|
© Nokia 2006 |