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