creator/src/creator_contactelement.cpp
branchRCL_3
changeset 60 6646c35e558c
parent 50 9b2cffad4b5e
equal deleted inserted replaced
50:9b2cffad4b5e 60:6646c35e558c
   169     { 
   169     { 
   170     iIsCommandElement = ETrue;
   170     iIsCommandElement = ETrue;
   171     }
   171     }
   172 
   172 
   173 #if(!defined __SERIES60_30__ && !defined __SERIES60_31__)
   173 #if(!defined __SERIES60_30__ && !defined __SERIES60_31__)
   174 void CCreatorContactElement::AsyncExecuteCommandL()
       
   175     {    
       
   176     LOGSTRING("Creator: CCreatorContactElement::AsyncExecuteCommandL");
       
   177     // Find out how many contacts should we create:
       
   178     const CCreatorScriptAttribute* contactAmountAttr = this->FindAttributeByName(KAmount);    
       
   179     TInt contactAmount = 1;    
       
   180     if( contactAmountAttr )
       
   181         {
       
   182         contactAmount = ConvertStrToIntL(contactAmountAttr->Value());
       
   183         }
       
   184     CCreatorScriptElement* fieldsElement = FindSubElement(KFields);
       
   185     TInt fieldMappingTblSize = sizeof(fieldMappingTbl)/sizeof(FieldMapping);
       
   186     if( iLoopIndex < contactAmount )
       
   187         {
       
   188         CVirtualPhonebookParameters* param = (CVirtualPhonebookParameters*) TCreatorFactory::CreatePhoneBookParametersL();
       
   189         CleanupStack::PushL(param);
       
   190         // Loop all the field elements
       
   191         if( fieldsElement && fieldsElement->SubElements().Count() > 0 )
       
   192             {
       
   193             
       
   194             const RPointerArray<CCreatorScriptElement>& fieldList = fieldsElement->SubElements();
       
   195             
       
   196             if( fieldList.Count() == 0 )
       
   197                 {
       
   198                 
       
   199                 }
       
   200             for( TInt i = 0; i < fieldList.Count(); ++i )
       
   201                 {
       
   202                 TPtrC fieldName = fieldList[i]->Name();
       
   203                 const CCreatorScriptAttribute* amountAttr = fieldList[i]->FindAttributeByName(KAmount);
       
   204                 const CCreatorScriptAttribute* rndLenAttr = fieldList[i]->FindAttributeByName(KRandomLength);
       
   205                 const CCreatorScriptAttribute* increaseAttr = fieldList[i]->FindAttributeByName(KIncrease);
       
   206                 TBool increase( EFalse );
       
   207                 if ( increaseAttr )
       
   208                     {
       
   209                     increase = ConvertStrToBooleanL( increaseAttr->Value() );
       
   210                     }
       
   211                 CCreatorContactField* field = 0;
       
   212                 for( TInt j = 0; j < fieldMappingTblSize; ++j )
       
   213                     {
       
   214                     const FieldMapping& mapping = fieldMappingTbl[j];
       
   215                     if( fieldName == mapping.iElementName )
       
   216                         {
       
   217                         TInt rndLen = 0;
       
   218                         TPtrC content = fieldList[i]->Content();
       
   219                                                                         
       
   220                         MCreatorRandomDataField::TRandomLengthType randomLenType = MCreatorRandomDataField::ERandomLengthUndefined;
       
   221                     
       
   222                         if( content == TPtrC(KEmpty) || content == TPtrC(KNullDesC) )
       
   223                             {
       
   224                             if( rndLenAttr == 0 )
       
   225                                 {
       
   226                                 randomLenType = MCreatorRandomDataField::ERandomLengthDefault;
       
   227                                 }
       
   228                             else
       
   229                                 {
       
   230                                 randomLenType = ResolveRandomDataTypeL(*rndLenAttr, rndLen);
       
   231                                 }
       
   232                             }
       
   233                         else
       
   234                             {
       
   235                             // Special handling for file id content:
       
   236                             if( fieldName == KThumbnailId )
       
   237                                 {
       
   238                                 // Thumbnail data is copied to the contact entry, so we can use temporary file:
       
   239                                 CCreatorEngine::TTestDataPath id = (CCreatorEngine::TTestDataPath) iEngine->GetAttachmentIdL(content);
       
   240                                 content.Set(iEngine->TestDataPathL(id));
       
   241                                 }
       
   242                             else if( fieldName == KRingToneId )
       
   243                                 {
       
   244                                 // Contact entry contains just a link to the sound file, so we must 
       
   245                                 // copy the temporary file to a permanent location:
       
   246                                 CCreatorEngine::TTestDataPath id = (CCreatorEngine::TTestDataPath) iEngine->GetAttachmentIdL(content);
       
   247                                 TPtrC fullTargetPath(iEngine->CreateSoundFileL(id));                            
       
   248                                 content.Set(fullTargetPath);
       
   249                                 }
       
   250                             }
       
   251                         TInt amountValue = 1;
       
   252                         if( amountAttr )
       
   253                             {                        
       
   254                             amountValue = ConvertStrToIntL(amountAttr->Value());
       
   255                             }
       
   256                         for( TInt k = 0; k < amountValue; ++k )
       
   257                             {
       
   258                             if ( increase &&
       
   259                                  ( fieldName.FindF( _L("number") ) > KErrNotFound ||
       
   260                                  fieldName.FindF( _L("phone") ) > KErrNotFound ) )
       
   261                                 {
       
   262                                 // increase phonenumber for each copy
       
   263                                 HBufC* incNum = HBufC::NewLC( content.Length() + 3 );
       
   264                                 if ( amountValue > 1 )
       
   265                                     {
       
   266                                     // amount defined in number field level
       
   267                                     IncreasePhoneNumL( content, k, incNum );
       
   268                                     }
       
   269                                 else
       
   270                                     {
       
   271                                     // amount defined in contact field level
       
   272                                     IncreasePhoneNumL( content, iLoopIndex, incNum );
       
   273                                     }
       
   274                                 field = CCreatorContactField::NewL( mapping.iFieldCode, *incNum );
       
   275                                 CleanupStack::PushL( field );
       
   276                                 field->SetRandomParametersL( randomLenType, rndLen );
       
   277                                 param->iContactFields.AppendL( field );
       
   278                                 CleanupStack::Pop( field );
       
   279                                 CleanupStack::PopAndDestroy( incNum );
       
   280                                 }
       
   281                             else
       
   282                                 {
       
   283                                 field = CCreatorContactField::NewL(mapping.iFieldCode, content);
       
   284                                 CleanupStack::PushL(field);
       
   285                                 field->SetRandomParametersL(randomLenType, rndLen);
       
   286                                 param->iContactFields.AppendL(field);
       
   287                                 CleanupStack::Pop(field);                                
       
   288                                 }
       
   289                             }
       
   290                         break;
       
   291                         }
       
   292                     }
       
   293                 }
       
   294             } 
       
   295         else
       
   296             {
       
   297             // No fields specified, so add all fields with random content:
       
   298             for( TInt i = 0; i < fieldMappingTblSize; ++i )
       
   299                 {
       
   300                 if( fieldMappingTbl[i].iElementName == KThumbnailId || 
       
   301                     fieldMappingTbl[i].iElementName == KRingToneId )
       
   302                     {
       
   303                     // Skip thumbnail and ringtone IDs, since they are duplicates with thumbnailpath and ringtonepath
       
   304                     continue;
       
   305                     }
       
   306                 CCreatorContactField* field = 0;
       
   307                 if(fieldMappingTbl[i].iDataType == EDataTypeText )
       
   308                     {
       
   309                     field = CCreatorContactField::NewL(fieldMappingTbl[i].iFieldCode, KNullDesC);
       
   310                     }
       
   311                 else if( fieldMappingTbl[i].iDataType == EDataTypeBinary )
       
   312                     {
       
   313                     field = CCreatorContactField::NewL(fieldMappingTbl[i].iFieldCode, KNullDesC8);
       
   314                     }
       
   315                 else if( fieldMappingTbl[i].iDataType == EDataTypeDateTime )
       
   316                     {                       
       
   317                     TDateTime dateTime(Time::NullTTime().DateTime());
       
   318                     field = CCreatorContactField::NewL(fieldMappingTbl[i].iFieldCode, dateTime);
       
   319                     }
       
   320                 if( field )
       
   321                     {
       
   322                     CleanupStack::PushL(field);
       
   323                     field->SetRandomParametersL(MCreatorRandomDataField::ERandomLengthDefault, 0);
       
   324                     param->iContactFields.AppendL(field);
       
   325                     CleanupStack::Pop(field);
       
   326                     }
       
   327                 }
       
   328             }
       
   329         iEngine->AppendToCommandArrayL(ECmdCreatePhoneBookEntryContacts, param);
       
   330         iParameters.AppendL(param); // Save the pointer to the parametes. 
       
   331         CleanupStack::Pop(param);
       
   332         StartNextLoop();
       
   333         }
       
   334     else
       
   335         {
       
   336         // stop loop and signal end of the executing command
       
   337         AsyncCommandFinished();
       
   338         }
       
   339     }
       
   340 
       
   341 void CCreatorContactElement::ExecuteCommandL()
   174 void CCreatorContactElement::ExecuteCommandL()
   342     {    
   175     {    
   343     LOGSTRING("Creator: CCreatorContactElement::ExecuteCommandL");
   176     LOGSTRING("Creator: CCreatorContactElement::ExecuteCommandL");
   344     // Find out how many contacts should we create:
   177     // Find out how many contacts should we create:
   345     const CCreatorScriptAttribute* contactAmountAttr = this->FindAttributeByName(KAmount);    
   178     const CCreatorScriptAttribute* contactAmountAttr = this->FindAttributeByName(KAmount);    
   515 CCreatorContactSetElement::CCreatorContactSetElement(CCreatorEngine* aEngine) 
   348 CCreatorContactSetElement::CCreatorContactSetElement(CCreatorEngine* aEngine) 
   516 : 
   349 : 
   517 CCreatorContactElementBase(aEngine)
   350 CCreatorContactElementBase(aEngine)
   518     { }
   351     { }
   519 
   352 
   520 void CCreatorContactSetElement::AsyncExecuteCommand()
       
   521     { 
       
   522     AsyncCommandFinished();
       
   523     }
       
   524 
       
   525 void CCreatorContactSetElement::ExecuteCommandL()
   353 void CCreatorContactSetElement::ExecuteCommandL()
   526     { }
   354     { }
   527 
   355 
   528 void CCreatorContactSetElement::AddToCacheL()
   356 void CCreatorContactSetElement::AddToCacheL()
   529     {    
   357     {    
   576     { 
   404     { 
   577     iIsCommandElement = ETrue;
   405     iIsCommandElement = ETrue;
   578     }
   406     }
   579 
   407 
   580 #if(!defined __SERIES60_30__ && !defined __SERIES60_31__ )
   408 #if(!defined __SERIES60_30__ && !defined __SERIES60_31__ )
   581 void CCreatorContactGroupElement::AsyncExecuteCommandL()
       
   582     {
       
   583     LOGSTRING("Creator: CCreatorContactGroupElement::AsyncExecuteCommandL");
       
   584     // Get attributes (amount and name)
       
   585     const CCreatorScriptAttribute* groupAmountAttr = this->FindAttributeByName(KAmount);        
       
   586     const CCreatorScriptAttribute* groupNameAttr = this->FindAttributeByName(KName);
       
   587     // How many groups to create:
       
   588     TInt groupAmount = 1;        
       
   589     if( groupAmountAttr )
       
   590         {
       
   591         groupAmount = ConvertStrToIntL(groupAmountAttr->Value());
       
   592         }
       
   593     
       
   594     if( iLoopIndex <  groupAmount )
       
   595         {        
       
   596         CCreatorScriptElement* membersElement = FindSubElement(KMembers);
       
   597         
       
   598         if( membersElement )
       
   599             {    
       
   600             CVirtualPhonebookParameters* param = (CVirtualPhonebookParameters*) TCreatorFactory::CreatePhoneBookParametersL();            
       
   601             CleanupStack::PushL(param);
       
   602             
       
   603             // Links to contact-sets:
       
   604             const RPointerArray<CCreatorScriptElement>& linkList = membersElement->SubElements();
       
   605             if( linkList.Count() > 0 )
       
   606                 {
       
   607                 for( TInt i = 0; i < linkList.Count(); ++i )
       
   608                     {
       
   609                     AppendContactSetReferenceL(*linkList[i], param->iLinkIds);
       
   610                     }                
       
   611                 }
       
   612             
       
   613             if( groupNameAttr )
       
   614                 {
       
   615                 param->iGroupName->Des().Copy( groupNameAttr->Value() );
       
   616                 }
       
   617             else
       
   618                 {
       
   619                 param->iGroupName->Des().Copy( iEngine->RandomString(CCreatorEngine::EGroupName) );
       
   620                 }                
       
   621             iEngine->AppendToCommandArrayL(ECmdCreatePhoneBookEntryGroups, param);
       
   622             CleanupStack::Pop(param);
       
   623             }
       
   624         StartNextLoop();
       
   625         }
       
   626     else
       
   627         {
       
   628         // stop loop and signal end of the executing command
       
   629         AsyncCommandFinished();        
       
   630         }
       
   631     }
       
   632 
       
   633 void CCreatorContactGroupElement::ExecuteCommandL()
   409 void CCreatorContactGroupElement::ExecuteCommandL()
   634     {
   410     {
   635     LOGSTRING("Creator: CCreatorContactGroupElement::ExecuteCommandL");
   411     LOGSTRING("Creator: CCreatorContactGroupElement::ExecuteCommandL");
   636     // Get attributes (amount and name)
   412     // Get attributes (amount and name)
   637     const CCreatorScriptAttribute* groupAmountAttr = this->FindAttributeByName(KAmount);        
   413     const CCreatorScriptAttribute* groupAmountAttr = this->FindAttributeByName(KAmount);