creator/engine/src/creator_noteelement.cpp
branchRCL_3
changeset 22 fad26422216a
parent 21 b3cee849fa46
child 23 f8280f3bfeb7
equal deleted inserted replaced
21:b3cee849fa46 22: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_noteelement.h"
       
    21 #include "creator_traces.h"
       
    22 #include "creator_note.h"
       
    23 
       
    24 using namespace creatornote;
       
    25 
       
    26 /*
       
    27  * 
       
    28  */
       
    29 CCreatorNoteElement* CCreatorNoteElement::NewL(CCreatorEngine* aEngine, const TDesC& aName, const TDesC& aContext )
       
    30     {
       
    31     CCreatorNoteElement* self = new (ELeave) CCreatorNoteElement(aEngine);
       
    32     CleanupStack::PushL(self);
       
    33     self->ConstructL(aName, aContext);
       
    34     CleanupStack::Pop(self);
       
    35     return self;
       
    36     }
       
    37 /*
       
    38  * 
       
    39  */
       
    40 CCreatorNoteElement::CCreatorNoteElement(CCreatorEngine* aEngine) 
       
    41 : 
       
    42 CCreatorScriptElement(aEngine)
       
    43     {
       
    44     iIsCommandElement = ETrue;
       
    45     }
       
    46 
       
    47 void CCreatorNoteElement::ExecuteCommandL()
       
    48     {
       
    49     const CCreatorScriptAttribute* amountAttr = FindAttributeByName(KAmount);
       
    50     TInt noteAmount = 1;    
       
    51     if( amountAttr )
       
    52         {
       
    53         noteAmount = 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 < noteAmount; ++cI )
       
    63             {            
       
    64             CNotepadParameters* param = new (ELeave) CNotepadParameters;
       
    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 useMax = EFalse;
       
    74                 if( randomAttr && randomAttr->Value() == KMax )
       
    75                     {
       
    76                     useMax = ETrue;
       
    77                     }
       
    78                 
       
    79                 if( elemName == KText )
       
    80                     {
       
    81                     if( randomAttr || elemContent.Length() == 0 )
       
    82                         {
       
    83                         if( useMax )
       
    84                             {
       
    85                             TDesC* temp = iEngine->CreateRandomStringLC(KNotepadFieldLength);                            
       
    86                             SetContentToTextParamL(param->iNoteText, *temp);
       
    87                             CleanupStack::PopAndDestroy(); // temp
       
    88                             }
       
    89                         else
       
    90                             {
       
    91                             SetContentToTextParamL(param->iNoteText, iEngine->RandomString(CCreatorEngine::EMessageText));
       
    92                             }
       
    93                         }
       
    94                     else
       
    95                         {
       
    96                         SetContentToTextParamL(param->iNoteText, elemContent);
       
    97                         }
       
    98                     }
       
    99                 }
       
   100             iEngine->AppendToCommandArrayL(ECmdCreateMiscEntryNotes, param);
       
   101             CleanupStack::Pop(); // param
       
   102             }
       
   103         }
       
   104     else
       
   105     	{
       
   106     	iEngine->AppendToCommandArrayL(ECmdCreateMiscEntryNotes, 0, noteAmount);
       
   107     	}
       
   108     }