creator/src/creator_noteelement.cpp
branchRCL_3
changeset 60 6646c35e558c
parent 50 9b2cffad4b5e
equal deleted inserted replaced
50:9b2cffad4b5e 60:6646c35e558c
    39 CCreatorNoteElement::CCreatorNoteElement(CCreatorEngine* aEngine) 
    39 CCreatorNoteElement::CCreatorNoteElement(CCreatorEngine* aEngine) 
    40 : 
    40 : 
    41 CCreatorScriptElement(aEngine)
    41 CCreatorScriptElement(aEngine)
    42     {
    42     {
    43     iIsCommandElement = ETrue;
    43     iIsCommandElement = ETrue;
    44     }
       
    45 
       
    46 void CCreatorNoteElement::AsyncExecuteCommandL()
       
    47     {
       
    48     const CCreatorScriptAttribute* amountAttr = FindAttributeByName(KAmount);
       
    49     TInt noteAmount = 1;    
       
    50     if( amountAttr )
       
    51         {
       
    52         noteAmount = 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         if( iLoopIndex < noteAmount )
       
    62             {            
       
    63             CNotepadParameters* param = new (ELeave) CNotepadParameters;
       
    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 useMax = EFalse;
       
    73                 if( randomAttr && randomAttr->Value() == KMax )
       
    74                     {
       
    75                     useMax = ETrue;
       
    76                     }
       
    77                 
       
    78                 if( elemName == KText )
       
    79                     {
       
    80                     if( randomAttr || elemContent.Length() == 0 )
       
    81                         {
       
    82                         if( useMax )
       
    83                             {
       
    84                             TDesC* temp = iEngine->CreateRandomStringLC(KNotepadFieldLength);                            
       
    85                             SetContentToTextParamL(param->iNoteText, *temp);
       
    86                             CleanupStack::PopAndDestroy(); // temp
       
    87                             }
       
    88                         else
       
    89                             {
       
    90                             SetContentToTextParamL(param->iNoteText, iEngine->RandomString(CCreatorEngine::EMessageText));
       
    91                             }
       
    92                         }
       
    93                     else
       
    94                         {
       
    95                         SetContentToTextParamL(param->iNoteText, elemContent);
       
    96                         }
       
    97                     }
       
    98                 }
       
    99             iEngine->AppendToCommandArrayL(ECmdCreateMiscEntryNotes, param);
       
   100             CleanupStack::Pop(); // param
       
   101             StartNextLoop();
       
   102             }
       
   103         else
       
   104             {
       
   105             AsyncCommandFinished();
       
   106             }
       
   107         }
       
   108     else
       
   109         {
       
   110         iEngine->AppendToCommandArrayL(ECmdCreateMiscEntryNotes, 0, noteAmount);
       
   111         // signal end of the executing command
       
   112         AsyncCommandFinished();
       
   113         }
       
   114     }
    44     }
   115 
    45 
   116 void CCreatorNoteElement::ExecuteCommandL()
    46 void CCreatorNoteElement::ExecuteCommandL()
   117     {
    47     {
   118     const CCreatorScriptAttribute* amountAttr = FindAttributeByName(KAmount);
    48     const CCreatorScriptAttribute* amountAttr = FindAttributeByName(KAmount);