creator/engine/src/creator_browserelement.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 
       
    21 #include "creator_browserelement.h"
       
    22 #include "creator_traces.h"
       
    23 #include "creator_browser.h"
       
    24 
       
    25 using namespace creatorbrowser;
       
    26 
       
    27 /*
       
    28  * 
       
    29  */
       
    30 CCreatorBrowserElement* CCreatorBrowserElement::NewL(CCreatorEngine* aEngine, const TDesC& aName, const TDesC& aContext )
       
    31     {
       
    32     CCreatorBrowserElement* self = new (ELeave) CCreatorBrowserElement(aEngine);
       
    33     CleanupStack::PushL(self);
       
    34     self->ConstructL(aName, aContext);
       
    35     CleanupStack::Pop(self);
       
    36     return self;
       
    37     }
       
    38 /*
       
    39  * 
       
    40  */
       
    41 CCreatorBrowserElement::CCreatorBrowserElement(CCreatorEngine* aEngine) 
       
    42 : 
       
    43 CCreatorScriptElement(aEngine)
       
    44     {
       
    45     iIsCommandElement = ETrue;
       
    46     }
       
    47 
       
    48 
       
    49 /*
       
    50  * 
       
    51  */
       
    52 void CCreatorBrowserElement::ExecuteCommandL()
       
    53     {
       
    54     const CCreatorScriptAttribute* amountAttr = FindAttributeByName(KAmount);
       
    55     TInt entryAmount = 1;
       
    56     TBool addAll = EFalse;
       
    57     if( amountAttr )
       
    58         {
       
    59         entryAmount = ConvertStrToIntL(amountAttr->Value());
       
    60         }
       
    61     // Get 'fields' element 
       
    62     CCreatorScriptElement* fieldsElement = FindSubElement(KFields);
       
    63     if( fieldsElement )
       
    64         {
       
    65         // Get sub-elements
       
    66         const RPointerArray<CCreatorScriptElement>& fields = fieldsElement->SubElements();
       
    67         // Create browser entries, the amount of entries is defined by entryAmount:
       
    68         for( TInt cI = 0; cI < entryAmount; ++cI )
       
    69             {
       
    70             CBrowserParameters* param = 0;
       
    71             
       
    72             if( fields.Count() > 0 )
       
    73             	param = new (ELeave) CBrowserParameters;
       
    74             else
       
    75             	{
       
    76             	// No fields defined --> Add all fields with random values:
       
    77             	addAll = ETrue;
       
    78             	break;
       
    79             	}
       
    80             
       
    81             CleanupStack::PushL(param);
       
    82             
       
    83             for( TInt i = 0; i < fields.Count(); ++i )
       
    84                 {
       
    85                 CCreatorScriptElement* field = fields[i];
       
    86                 TPtrC elemName = field->Name();                
       
    87                 TPtrC elemContent = field->Content();
       
    88                 const CCreatorScriptAttribute* randomAttr = fields[i]->FindAttributeByName(KRandomLength);
       
    89                 if( elemName == KName )
       
    90                     {
       
    91                     if( randomAttr || elemContent.Length() == 0)
       
    92                         {
       
    93                         elemContent.Set(iEngine->RandomString(CCreatorEngine::ECompany));
       
    94                         }
       
    95                     if( iName->Des() == KBookmark )
       
    96                         {
       
    97                         SetContentToTextParamL(param->iBookmarkName, elemContent);                        
       
    98                         }
       
    99                     else if( iName->Des() == KBookmarkFolder )
       
   100                         {
       
   101                         SetContentToTextParamL(param->iBookmarkFolderName, elemContent);
       
   102                         }
       
   103                     else if( iName->Des() == KSavedPage )
       
   104                         {
       
   105                         SetContentToTextParamL(param->iSavedDeckLinkName, elemContent);
       
   106                         }
       
   107                     else if( iName->Des() == KSavedPageFolder )
       
   108                         {
       
   109                         SetContentToTextParamL(param->iSavedDeckFolderName, elemContent);
       
   110                         }
       
   111                     }
       
   112                 
       
   113                 else if( elemName == KPath )
       
   114                     {                    
       
   115                     if( randomAttr || elemContent.Length() == 0)
       
   116                         {
       
   117                         SetContentToTextParamL(param->iSavedDeckLocalAddress, iEngine->TestDataPathL(CCreatorEngine::ESavedDeck_1kB));
       
   118                         }
       
   119                     else
       
   120                         {
       
   121                         SetContentToTextParamL(param->iSavedDeckLocalAddress, elemContent);
       
   122                         }
       
   123                     }
       
   124                 else if( elemName == KUsername )
       
   125                     {
       
   126                     if( randomAttr || elemContent.Length() == 0)
       
   127                         {
       
   128                         // Set username and password to same string
       
   129                         if( param->iBookmarkPassword && param->iBookmarkPassword->Length() > 0 )
       
   130                             {
       
   131                             SetContentToTextParamL(param->iBookmarkUsername, param->iBookmarkPassword->Des());
       
   132                             }
       
   133                         else
       
   134                             {
       
   135                             SetContentToTextParamL(param->iBookmarkUsername, iEngine->RandomString(CCreatorEngine::EFirstName));
       
   136                             }
       
   137                         }
       
   138                     else
       
   139                         {
       
   140                         SetContentToTextParamL(param->iBookmarkUsername, elemContent);
       
   141                         }
       
   142                     }
       
   143                 else if( elemName == KPassword )
       
   144                     {
       
   145                     if( randomAttr || elemContent.Length() == 0)
       
   146                         {
       
   147                         // Set username and password to same string
       
   148                         if( param->iBookmarkUsername && param->iBookmarkUsername->Length() > 0 )
       
   149                             {
       
   150                             SetContentToTextParamL(param->iBookmarkPassword, param->iBookmarkUsername->Des());
       
   151                             }
       
   152                         else
       
   153                             {
       
   154                             SetContentToTextParamL(param->iBookmarkPassword, iEngine->RandomString(CCreatorEngine::EFirstName));                                                    
       
   155                             }
       
   156                         }
       
   157                     else
       
   158                         {
       
   159                         SetContentToTextParamL(param->iBookmarkPassword, elemContent);
       
   160                         }
       
   161                     }
       
   162                 else if( elemName == KUrl )
       
   163                     {
       
   164                     if( randomAttr || elemContent.Length() == 0)
       
   165                         {
       
   166                         TDesC* tmpUrl = iEngine->CreateHTTPUrlLC();
       
   167                         if( tmpUrl )
       
   168                             {
       
   169                             SetContentToTextParamL(param->iBookmarkAddress, *tmpUrl );
       
   170                             }
       
   171                         CleanupStack::PopAndDestroy(); // tmpUrl                        
       
   172                         }
       
   173                     else
       
   174                         {
       
   175                         SetContentToTextParamL(param->iBookmarkAddress, elemContent);
       
   176                         }
       
   177                     }
       
   178                 }
       
   179             iEngine->AppendToCommandArrayL(GetBrowserCommandL(), param);
       
   180             CleanupStack::Pop(); // param
       
   181             }
       
   182         }
       
   183     else
       
   184     	{
       
   185     	addAll = ETrue;
       
   186     	}
       
   187     
       
   188     if( addAll )
       
   189     	{
       
   190     	iEngine->AppendToCommandArrayL(GetBrowserCommandL(), 0, entryAmount);
       
   191     	}
       
   192     }
       
   193 
       
   194 TInt CCreatorBrowserElement::GetBrowserCommandL() const
       
   195     {
       
   196     if( iName->Des() == KBookmark )
       
   197         {
       
   198         return ECmdCreateBrowserBookmarkEntries;
       
   199         }
       
   200     else if( iName->Des() == KBookmarkFolder )
       
   201         {
       
   202         return ECmdCreateBrowserBookmarkFolderEntries;
       
   203         }
       
   204     else if( iName->Des() == KSavedPage )
       
   205         {
       
   206         return ECmdCreateBrowserSavedPageEntries;
       
   207         }
       
   208     else if( iName->Des() == KSavedPageFolder )
       
   209         {
       
   210         return ECmdCreateBrowserSavedPageFolderEntries;
       
   211         }
       
   212     
       
   213     LOGSTRING("CCreatorFileElement::GetBrowserCommandL: Unknown browser entry");
       
   214     User::Leave(KErrGeneral);
       
   215     return 0; // Not reached, but disables compiler warning...
       
   216     }