creator/engine/src/creator_phonebook.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 #include "engine.h"
       
    20 #include "enginewrapper.h"
       
    21 #include "creator_contactsetcache.h"
       
    22 
       
    23 #include "creator_phonebook.h"
       
    24 #include "creator_traces.h"
       
    25 
       
    26 #include <bautils.h> 
       
    27 
       
    28 _LIT(KTempPath, "C:\\Data\\Creator\\");
       
    29 
       
    30 
       
    31 typedef struct {
       
    32 TInt iFieldCode;
       
    33 TInt iRandomType;
       
    34 } DetailFieldInfo;
       
    35 static const TInt RND_TYPE_UNDEF = -99;
       
    36 DetailFieldInfo CreatorPbkMiscTextFields[] = {        
       
    37         {CCreatorPhonebookWrapper::EFirstName, (TInt) CCreatorEngine::EFirstName},
       
    38         {CCreatorPhonebookWrapper::EFirstNameReading, (TInt) CCreatorEngine::EFirstName},
       
    39         {CCreatorPhonebookWrapper::ELastName, (TInt) CCreatorEngine::ESurname},
       
    40         {CCreatorPhonebookWrapper::ELastNameReading, (TInt) CCreatorEngine::ESurname},
       
    41         {CCreatorPhonebookWrapper::ECompanyName, (TInt) CCreatorEngine::ECompany},
       
    42         {CCreatorPhonebookWrapper::EJobTitle, (TInt) CCreatorEngine::EJobTitle},
       
    43         {CCreatorPhonebookWrapper::EPrefix, (TInt) CCreatorEngine::EPrefix},
       
    44         {CCreatorPhonebookWrapper::ESuffix, (TInt) CCreatorEngine::ESuffix},
       
    45         {CCreatorPhonebookWrapper::ESecondName, (TInt) CCreatorEngine::EFirstName},
       
    46         {CCreatorPhonebookWrapper::EAddrLabelGen, (TInt) CCreatorEngine::EAddress},
       
    47         {CCreatorPhonebookWrapper::EAddrPoGen, (TInt) CCreatorEngine::EPobox},
       
    48         {CCreatorPhonebookWrapper::EAddrExtGen, (TInt) CCreatorEngine::EAddress},
       
    49         {CCreatorPhonebookWrapper::EAddrStreetGen, (TInt) CCreatorEngine::EAddress},
       
    50         {CCreatorPhonebookWrapper::EAddrLocalGen, (TInt) CCreatorEngine::ECity},
       
    51         {CCreatorPhonebookWrapper::EAddrRegionGen, (TInt) CCreatorEngine::EState},
       
    52         {CCreatorPhonebookWrapper::EAddrPostCodeGen, (TInt) CCreatorEngine::EPostcode},
       
    53         {CCreatorPhonebookWrapper::EAddrCountryGen, (TInt) CCreatorEngine::ECountry},
       
    54         {CCreatorPhonebookWrapper::EAddrLabelHome, (TInt) CCreatorEngine::EAddress},
       
    55         {CCreatorPhonebookWrapper::EAddrPoHome, (TInt) CCreatorEngine::EPobox},
       
    56         {CCreatorPhonebookWrapper::EAddrExtHome, (TInt) CCreatorEngine::EAddress},
       
    57         {CCreatorPhonebookWrapper::EAddrStreetHome, (TInt) CCreatorEngine::EAddress},
       
    58         {CCreatorPhonebookWrapper::EAddrLocalHome, (TInt) CCreatorEngine::ECity},
       
    59         {CCreatorPhonebookWrapper::EAddrRegionHome, (TInt) CCreatorEngine::EState},
       
    60         {CCreatorPhonebookWrapper::EAddrPostCodeHome, (TInt) CCreatorEngine::EPostcode},
       
    61         {CCreatorPhonebookWrapper::EAddrCountryHome, (TInt) CCreatorEngine::ECountry},
       
    62         {CCreatorPhonebookWrapper::EAddrLabelWork, (TInt) CCreatorEngine::EAddress},
       
    63         {CCreatorPhonebookWrapper::EAddrPoWork, (TInt) CCreatorEngine::EPobox},
       
    64         {CCreatorPhonebookWrapper::EAddrExtWork, (TInt) CCreatorEngine::EAddress},
       
    65         {CCreatorPhonebookWrapper::EAddrStreetWork, (TInt) CCreatorEngine::EAddress},
       
    66         {CCreatorPhonebookWrapper::EAddrLocalWork, (TInt) CCreatorEngine::ECity},
       
    67         {CCreatorPhonebookWrapper::EAddrRegionWork, (TInt) CCreatorEngine::EState},
       
    68         {CCreatorPhonebookWrapper::EAddrPostCodeWork, (TInt) CCreatorEngine::EPostcode},
       
    69         {CCreatorPhonebookWrapper::EAddrCountryWork, (TInt) CCreatorEngine::ECountry},
       
    70         {CCreatorPhonebookWrapper::EPoc, (TInt) CCreatorEngine::EPhoneNumber},
       
    71         {CCreatorPhonebookWrapper::ESwis, (TInt) CCreatorEngine::EPhoneNumber},
       
    72         {CCreatorPhonebookWrapper::ESip, (TInt) CCreatorEngine::EPhoneNumber},
       
    73         {CCreatorPhonebookWrapper::EDtmfString, (TInt) CCreatorEngine::EFirstName},
       
    74         {CCreatorPhonebookWrapper::ENote,(TInt)  CCreatorEngine::EMemoText},
       
    75         {CCreatorPhonebookWrapper::EMiddleName, (TInt) CCreatorEngine::EFirstName},
       
    76         {CCreatorPhonebookWrapper::EDepartment, (TInt) CCreatorEngine::ECompany},
       
    77         {CCreatorPhonebookWrapper::EAsstName, (TInt) CCreatorEngine::EFirstName},
       
    78         {CCreatorPhonebookWrapper::ESpouse, (TInt) CCreatorEngine::EFirstName},
       
    79         {CCreatorPhonebookWrapper::EChildren, (TInt) CCreatorEngine::EFirstName},
       
    80         {CCreatorPhonebookWrapper::ESyncClass, RND_TYPE_UNDEF},
       
    81         {CCreatorPhonebookWrapper::ELocPrivacy, RND_TYPE_UNDEF},
       
    82         {CCreatorPhonebookWrapper::EGenLabel, (TInt) CCreatorEngine::EFirstName},
       
    83         {CCreatorPhonebookWrapper::EWVAddress, (TInt) CCreatorEngine::EPhoneNumber},
       
    84         {CCreatorPhonebookWrapper::ERingTone, RND_TYPE_UNDEF},
       
    85         {CCreatorPhonebookWrapper::EThumbnailPic, RND_TYPE_UNDEF},
       
    86         {CCreatorPhonebookWrapper::ECallerObjText, (TInt) CCreatorEngine::EFirstName}
       
    87         };
       
    88                   
       
    89 
       
    90 TInt CreatorPbkBinaryFields[] = {
       
    91         CCreatorPhonebookWrapper::ECallerObjImg//,
       
    92         //R_VPBK_FIELD_TYPE_THUMBNAILPATH
       
    93         };
       
    94 
       
    95 TInt CreatorPbkDateTimeFields[] = {
       
    96         CCreatorPhonebookWrapper::EAnniversary
       
    97         };
       
    98 
       
    99 //----------------------------------------------------------------------------
       
   100 TInt CreatorPbkPhoneNumberFields[] =
       
   101     {
       
   102     CCreatorPhonebookWrapper::ELandPhoneGen,
       
   103     CCreatorPhonebookWrapper::ELandPhoneHome,
       
   104     CCreatorPhonebookWrapper::ELandPhoneWork,                        
       
   105     CCreatorPhonebookWrapper::EMobilePhoneGen,
       
   106     CCreatorPhonebookWrapper::EMobilePhoneHome,
       
   107     CCreatorPhonebookWrapper::EMobilePhoneWork,
       
   108     CCreatorPhonebookWrapper::EFaxNumberGen,
       
   109     CCreatorPhonebookWrapper::EFaxNumberHome,
       
   110     CCreatorPhonebookWrapper::EFaxNumberWork,
       
   111     CCreatorPhonebookWrapper::EPagerNumber,           
       
   112     CCreatorPhonebookWrapper::EVideoNumberGen,
       
   113     CCreatorPhonebookWrapper::EVideoNumberHome,
       
   114     CCreatorPhonebookWrapper::EVideoNumberWork,
       
   115     CCreatorPhonebookWrapper::EVoipGen,
       
   116     CCreatorPhonebookWrapper::EVoipHome,
       
   117     CCreatorPhonebookWrapper::EVoipWork,
       
   118     CCreatorPhonebookWrapper::EAsstPhone,
       
   119     CCreatorPhonebookWrapper::ECarPhone
       
   120     };
       
   121 
       
   122 TInt CreatorPbkUrlFields[] =
       
   123     {
       
   124     CCreatorPhonebookWrapper::EUrlGen,
       
   125     CCreatorPhonebookWrapper::EUrlHome,
       
   126     CCreatorPhonebookWrapper::EUrlWork
       
   127     };
       
   128 
       
   129 TInt CreatorPbkEmailFields[] =
       
   130     {
       
   131     CCreatorPhonebookWrapper::EEmailGen,
       
   132     CCreatorPhonebookWrapper::EEmailHome,
       
   133     CCreatorPhonebookWrapper::EEmailWork
       
   134     };
       
   135 
       
   136 CPhonebookParameters::CPhonebookParameters()
       
   137     {
       
   138     LOGSTRING("Creator: CPhonebookParameters::CVirtualPhonebookParameters");
       
   139     iGroupName = HBufC::New(KPhonebookFieldLength);  
       
   140     }
       
   141 
       
   142 CPhonebookParameters::~CPhonebookParameters()
       
   143     {
       
   144     LOGSTRING("Creator: CPhonebookParameters::~CPhonebookParameters");
       
   145 
       
   146     delete iGroupName;   
       
   147     for( TCreatorContactFields::iterator it = iContactFields.begin(); it != iContactFields.end(); ++it)
       
   148         {
       
   149         HBufC* temp =  (*it).second;
       
   150         iContactFields.erase(it);
       
   151         delete temp;
       
   152         }
       
   153     iLinkIds.Reset();
       
   154     iLinkIds.Close();
       
   155     }
       
   156 
       
   157 void CPhonebookParameters::ParseL(CCommandParser* /*parser*/, TParseParams /*aCase = 0*/)
       
   158 	{
       
   159 	}
       
   160 
       
   161 TInt CPhonebookParameters::ScriptLinkId() const
       
   162     {
       
   163     return iLinkId;
       
   164     }
       
   165 
       
   166 void CPhonebookParameters::SetScriptLinkId(TInt aLinkId)
       
   167     {
       
   168     iLinkId = aLinkId;
       
   169     }
       
   170 
       
   171 
       
   172 //----------------------------------------------------------------------------
       
   173 
       
   174 CCreatorPhonebook* CCreatorPhonebook::NewL(CCreatorEngine* aEngine)
       
   175     {
       
   176     CCreatorPhonebook* self = CCreatorPhonebook::NewLC(aEngine);
       
   177     CleanupStack::Pop(self);
       
   178     return self;
       
   179     }
       
   180 
       
   181 CCreatorPhonebook* CCreatorPhonebook::NewLC(CCreatorEngine* aEngine)
       
   182     {
       
   183     CCreatorPhonebook* self = new (ELeave) CCreatorPhonebook();
       
   184     CleanupStack::PushL(self);
       
   185     self->ConstructL(aEngine);
       
   186     return self;
       
   187     }
       
   188 
       
   189 
       
   190 CCreatorPhonebook::CCreatorPhonebook() 
       
   191     {
       
   192     iAddAllFields = EFalse;
       
   193     }
       
   194 
       
   195 void CCreatorPhonebook::ConstructL(CCreatorEngine* aEngine)
       
   196     {
       
   197     LOGSTRING("Creator: CCreatorPhonebook::ConstructL");
       
   198 	
       
   199 	iEngine = aEngine;
       
   200 	
       
   201 	iPhonebookWrapper = CCreatorPhonebookWrapper::NewL();
       
   202 
       
   203 	SetDefaultParameters();
       
   204     }
       
   205 	
       
   206 
       
   207 CCreatorPhonebook::~CCreatorPhonebook()
       
   208     {
       
   209     LOGSTRING("Creator: CCreatorPhonebook::~CCreatorPhonebook");
       
   210  
       
   211     if ( iContactsToDelete.Count() )
       
   212     	{
       
   213         TRAP_IGNORE( StoreLinksForDeleteL( iContactsToDelete, KUidDictionaryUidContacts ) );
       
   214         }
       
   215     if ( iContactGroupsToDelete.Count() )
       
   216     	{
       
   217         TRAP_IGNORE( StoreLinksForDeleteL( iContactGroupsToDelete, KUidDictionaryUidContactGroups ) );
       
   218         }
       
   219     
       
   220 	if( iPhonebookWrapper )
       
   221 		{
       
   222 		delete iPhonebookWrapper;
       
   223 		}
       
   224     
       
   225     if (iParameters)
       
   226     	{
       
   227         delete iParameters;
       
   228     	}
       
   229   
       
   230     }
       
   231 
       
   232 //----------------------------------------------------------------------------
       
   233 
       
   234 TInt CCreatorPhonebook::CreateContactEntryL(CCreatorModuleBaseParameters *aParameters)
       
   235     {
       
   236 	TInt err = KErrNone;
       
   237 	delete iParameters;
       
   238 	    iParameters = 0;
       
   239 	CPhonebookParameters* parameters = 0;
       
   240 	
       
   241 	if( aParameters == 0 )
       
   242 	    {
       
   243 	    InitializeContactParamsL();
       
   244 	    parameters = iParameters;
       
   245 	    }
       
   246 	else
       
   247 	    {
       
   248 	    parameters = (CPhonebookParameters*) aParameters;
       
   249 	    }
       
   250 	    
       
   251 	int numberOfFields = parameters->iContactFields.size();
       
   252 	// create a new contact item
       
   253 	
       
   254 	TUint32 contactId = iPhonebookWrapper->CreateContactEntryL( parameters->iContactFields ); //wrapper should return contact id to store
       
   255 	iContactsToDelete.Append( contactId );
       
   256 	
       
   257 
       
   258 	// If this contact has a link id in script (i.e. belongs to a contact-set), we must cache the contact id:
       
   259 	    if( parameters->ScriptLinkId() > 0 )
       
   260 	        {                
       
   261 	        RPointerArray<CCreatorContactSet>& contactsets = ContactLinkCache::Instance()->ContactSets();
       
   262 	        TBool setFound(EFalse);
       
   263 	        for(TInt i = 0; i < contactsets.Count(); ++i )
       
   264 	            {
       
   265 	            if( contactsets[i]->LinkId() == parameters->ScriptLinkId() )
       
   266 	                {
       
   267 	                if( contactId )
       
   268 	                    {
       
   269 	                    contactsets[i]->AppendL( contactId );
       
   270 	                    iContactLinkArray.AppendL( contactId );
       
   271 	                    }
       
   272 	                setFound = ETrue;
       
   273 	                break;
       
   274 	                }
       
   275 	            }
       
   276 	        if( !setFound )
       
   277 	            {
       
   278 	            LOGSTRING2("Error: Contact set id %d not found.", parameters->ScriptLinkId());
       
   279 	            }
       
   280 	        }
       
   281 	    
       
   282     return err;
       
   283     }
       
   284 
       
   285 
       
   286 //----------------------------------------------------------------------------
       
   287 
       
   288 
       
   289 
       
   290 //----------------------------------------------------------------------------
       
   291 
       
   292 void CCreatorPhonebook::DeleteAllL()
       
   293     {
       
   294 	iPhonebookWrapper->DeleteAllL();
       
   295     }
       
   296 
       
   297 //----------------------------------------------------------------------------
       
   298 void CCreatorPhonebook::DeleteAllCreatedByCreatorL()
       
   299     {
       
   300     LOGSTRING("Creator: CCreatorPhonebook::DeleteAllCreatedByCreatorL");
       
   301     DeleteItemsCreatedWithCreatorL( KUidDictionaryUidContacts );
       
   302     }
       
   303 
       
   304 //----------------------------------------------------------------------------
       
   305 void CCreatorPhonebook::DeleteAllGroupsL()
       
   306     {
       
   307     LOGSTRING("Creator: CCreatorPhonebook::DeleteAllGroupsL");
       
   308     iPhonebookWrapper->DeleteAllGroupsL();
       
   309     }
       
   310 
       
   311 //----------------------------------------------------------------------------
       
   312 void CCreatorPhonebook::DeleteAllGroupsCreatedByCreatorL()
       
   313     {
       
   314     LOGSTRING("Creator: CCreatorPhonebook::DeleteAllGroupsCreatedByCreatorL");
       
   315     DeleteItemsCreatedWithCreatorL( KUidDictionaryUidContactGroups );
       
   316     }
       
   317 
       
   318 //----------------------------------------------------------------------------
       
   319 void CCreatorPhonebook::DeleteContactsL( RArray<TUint32>& aContactsToDelete, TUid aStoreUid	)
       
   320     {
       
   321 	iPhonebookWrapper->DeleteContactsL( aContactsToDelete, aStoreUid );
       
   322     }
       
   323 
       
   324 //----------------------------------------------------------------------------
       
   325 
       
   326 
       
   327 void CCreatorPhonebook::DeleteItemsCreatedWithCreatorL( TUid aStoreUid )
       
   328     {
       
   329 	CDictionaryFileStore* store = iEngine->FileStoreLC();
       
   330     User::LeaveIfNull( store );
       
   331     
       
   332     RArray<TUint32> contacts; 
       
   333     // backup previous contact links from store
       
   334     // otherwise they would be overwritten when calling out.WriteL
       
   335     TUint32 creatorLink;
       
   336     if ( store->IsPresentL( aStoreUid ) )
       
   337        {
       
   338        RDictionaryReadStream in;
       
   339        in.OpenLC( *store, aStoreUid );
       
   340        TRAP_IGNORE( 
       
   341            do{ 
       
   342                creatorLink = in.ReadUint32L();
       
   343                contacts.AppendL( creatorLink );
       
   344            }while( creatorLink );
       
   345        );
       
   346        
       
   347        CleanupStack::PopAndDestroy(); // in
       
   348        }
       
   349     
       
   350     
       
   351     iPhonebookWrapper->DeleteContactsL( contacts, aStoreUid );
       
   352     
       
   353     store->Remove( aStoreUid );
       
   354     store->CommitL();
       
   355     
       
   356     CleanupStack::PopAndDestroy( store );
       
   357     }
       
   358 
       
   359 //----------------------------------------------------------------------------
       
   360 void CCreatorPhonebook::DoDeleteItemsCreatedWithCreatorL( TUid /*aStoreUid*/, CDictionaryFileStore* /*aStore*/ )
       
   361     {
       
   362     
       
   363     }
       
   364 
       
   365 //----------------------------------------------------------------------------
       
   366 TBool CCreatorPhonebook::HasOtherThanGroupsL()
       
   367     {
       
   368     LOGSTRING("Creator: CCreatorPhonebook::HasOtherThanGroupsL");
       
   369     TBool result( EFalse );
       
   370     return result;
       
   371     }
       
   372 
       
   373 
       
   374 //----------------------------------------------------------------------------
       
   375 
       
   376 
       
   377 //----------------------------------------------------------------------------
       
   378 void CCreatorPhonebook::StoreLinksForDeleteL( RArray<TUint32>& aLinks, TUid aStoreUid )
       
   379     {
       
   380     LOGSTRING("Creator: CCreatorPhonebook::StoreLinksForDeleteL");
       
   381     CDictionaryFileStore* store = iEngine->FileStoreLC();
       
   382        User::LeaveIfNull( store );
       
   383        
       
   384        // backup previous contact links from store
       
   385        // otherwise they would be overwritten when calling out.WriteL
       
   386        TUint32 previousLink;
       
   387        if ( store->IsPresentL( aStoreUid ) )
       
   388            {
       
   389            RDictionaryReadStream in;
       
   390            in.OpenLC( *store, aStoreUid );
       
   391            bool r = false;
       
   392            TRAP_IGNORE( 
       
   393                do{ //iContactMngr->CreateLinksLC( in )) != NULL ) // will leave with KErrEof
       
   394                    previousLink = in.ReadUint32L();
       
   395                    iPreviousDeleteLinks.Append( previousLink );
       
   396                    if(previousLink)
       
   397                 	   {
       
   398 					   r=true;
       
   399                 	   }
       
   400                    else
       
   401                 	   {
       
   402 					   r=false;
       
   403                 	   }
       
   404                }while(r==true); );
       
   405            
       
   406            CleanupStack::PopAndDestroy(); // in
       
   407            }
       
   408 
       
   409        RDictionaryWriteStream out;       
       
   410        out.AssignLC( *store, aStoreUid );
       
   411        
       
   412        // restore previous links
       
   413        for ( TInt i = 0; i < iPreviousDeleteLinks.Count(); i++ )
       
   414            {
       
   415            out.WriteUint32L( iPreviousDeleteLinks[i] );
       
   416            }
       
   417        
       
   418        // write new links
       
   419        for(int i=0; i < aLinks.Count(); i++)
       
   420     	   {
       
   421 		   out.WriteUint32L( aLinks[i] );
       
   422     	   }
       
   423        out.CommitL();
       
   424        CleanupStack::PopAndDestroy(); // out
       
   425        
       
   426        store->CommitL();
       
   427 
       
   428        CleanupStack::PopAndDestroy( store );
       
   429     }
       
   430 
       
   431 //----------------------------------------------------------------------------
       
   432 //----------------------------------------------------------------------------
       
   433 
       
   434 void CCreatorPhonebook::InitializeContactParamsL()
       
   435     {
       
   436     LOGSTRING("Creator: CCreatorPhonebook::InitializeContactParamsL");        
       
   437  
       
   438     iParameters = new (ELeave) CPhonebookParameters;
       
   439            
       
   440     iParameters->iNumberOfPhoneNumberFields = iNumberOfPhoneNumberFields;
       
   441     iParameters->iNumberOfURLFields = iNumberOfURLFields;
       
   442     iParameters->iNumberOfEmailAddressFields = iNumberOfEmailAddressFields;       
       
   443     
       
   444     TPtrC fname = iEngine->RandomString(CCreatorEngine::EFirstName);
       
   445     TPtrC lname = iEngine->RandomString(CCreatorEngine::ESurname);
       
   446     
       
   447     
       
   448     if( iAddAllFields )
       
   449         {
       
   450 		TInt textFieldCount = sizeof(CreatorPbkMiscTextFields) / sizeof(DetailFieldInfo);
       
   451 		for( TInt tfIndex = 0; tfIndex < textFieldCount; ++tfIndex )
       
   452 			{ 
       
   453 			CCreatorContactField* field = CCreatorContactField::NewL();
       
   454 			CleanupStack::PushL(field);
       
   455 	        field->AddFieldToParamL( iEngine,iParameters, CreatorPbkMiscTextFields[tfIndex].iFieldCode, CreatorPbkMiscTextFields[tfIndex].iRandomType );
       
   456   	        CleanupStack::Pop(field);
       
   457             }
       
   458 		
       
   459 		// Add binary fields:
       
   460 		
       
   461 		RFs& fs = CCoeEnv::Static()->FsSession();
       
   462 		      
       
   463         TBuf<KMaxFileName> srcPath;
       
   464 		iEngine->RandomPictureFileL(srcPath);
       
   465 		TBuf<KMaxFileName> destPath(KTempPath);
       
   466 		                            
       
   467 		if(!BaflUtils::FolderExists( fs, destPath ))
       
   468 			{
       
   469 		    BaflUtils::EnsurePathExistsL( fs, destPath );
       
   470 		    }
       
   471 		                
       
   472 		TInt err=BaflUtils::CopyFile( fs, srcPath, destPath );
       
   473 
       
   474 		TParse temp;
       
   475 		temp.Set( srcPath,NULL,NULL );
       
   476 		destPath.Append(temp.NameAndExt());
       
   477 		TPtrC picture;
       
   478 		picture.Set(destPath);
       
   479 		CCreatorContactField* picturefield = CCreatorContactField::NewL();
       
   480 		CleanupStack::PushL(picturefield);
       
   481 		picturefield->AddFieldToParamL( iParameters, CCreatorPhonebookWrapper::EThumbnailPic, picture );
       
   482 		CleanupStack::Pop(picturefield);
       
   483 		// Add date-time fields:
       
   484 		TPtrC anniv;
       
   485 		TBuf<20> timeString;
       
   486 		TTime datetime = iEngine->RandomDate( CCreatorEngine::EDateFuture );
       
   487 		_LIT(KDateString,"%D%M%Y%/0%1%/1%2%/2%3%/3");
       
   488 		TRAP_IGNORE( datetime.FormatL(timeString, KDateString) );
       
   489 		
       
   490 		anniv.Set(timeString);
       
   491  
       
   492 		CCreatorContactField* fieldAnniv = CCreatorContactField::NewL();
       
   493 		CleanupStack::PushL( fieldAnniv );
       
   494 		fieldAnniv->AddFieldToParamL(iParameters,CCreatorPhonebookWrapper::EAnniversary, anniv );
       
   495 		CleanupStack::Pop( fieldAnniv );
       
   496     //***************************************************************************
       
   497     
       
   498         }
       
   499     else
       
   500         {
       
   501 		CCreatorContactField* field = CCreatorContactField::NewL();
       
   502     	CleanupStack::PushL(field);
       
   503     	field->AddFieldToParamL( iParameters, CCreatorPhonebookWrapper::EFirstName, fname );
       
   504 		field->AddFieldToParamL( iParameters, CCreatorPhonebookWrapper::ELastName, lname );
       
   505 		CleanupStack::Pop(field);
       
   506         }
       
   507                         
       
   508       // Phone numbers:
       
   509     TInt phoneFieldCount = sizeof(CreatorPbkPhoneNumberFields) / sizeof(TInt);
       
   510     
       
   511     TInt inc=0;
       
   512     for( TInt i=0; i<iNumberOfPhoneNumberFields; i++ )
       
   513     	{
       
   514     
       
   515 		if(inc >= phoneFieldCount )
       
   516         	{
       
   517     		inc = 0;
       
   518         	}
       
   519 		
       
   520 		CCreatorContactField* field = CCreatorContactField::NewL();
       
   521         CleanupStack::PushL(field);
       
   522 		field->AddFieldToParamL(iEngine, iParameters, CreatorPbkPhoneNumberFields[inc] );
       
   523 		CleanupStack::Pop(field);
       
   524     
       
   525 		inc++;
       
   526     	}
       
   527     
       
   528     
       
   529     
       
   530     // URLs:
       
   531     TInt urlFieldCount = sizeof(CreatorPbkUrlFields) / sizeof(TInt);
       
   532     inc = 0;
       
   533     for( TInt i=0; i<iNumberOfURLFields; i++ )
       
   534         {
       
   535     
       
   536 		if(inc >= urlFieldCount )
       
   537           	{
       
   538         	inc = 0;
       
   539            	}
       
   540     
       
   541 		CCreatorContactField* field = CCreatorContactField::NewL();
       
   542         CleanupStack::PushL(field);
       
   543     	field->AddFieldToParamL(iEngine, iParameters, CreatorPbkUrlFields[inc] );
       
   544     	CleanupStack::Pop(field);
       
   545     	inc++;
       
   546         }
       
   547 
       
   548     // EMail addresses:
       
   549     TInt emailFieldCount = sizeof(CreatorPbkEmailFields) / sizeof(TInt);
       
   550     inc = 0;
       
   551     for( int i=0; i<iNumberOfEmailAddressFields; i++ )
       
   552     	{
       
   553 		if(inc >= emailFieldCount )
       
   554            	{
       
   555           	inc = 0;
       
   556            	}
       
   557         CCreatorContactField* field = CCreatorContactField::NewL();
       
   558         CleanupStack::PushL(field);
       
   559         field->AddFieldToParamL(iEngine, iParameters, CreatorPbkEmailFields[inc] );
       
   560         CleanupStack::Pop(field);
       
   561         inc++;
       
   562     	}
       
   563     
       
   564     TestPrintOut(iParameters);
       
   565     
       
   566    }
       
   567 
       
   568 void CCreatorPhonebook::TestPrintOut(CPhonebookParameters* aParam)
       
   569 	{
       
   570 	LOGSTRING("Creator: CCreatorPhonebook::TestPrintOut");
       
   571 	for( TCreatorContactFields::iterator it = aParam->iContactFields.begin(); it != aParam->iContactFields.end(); ++it)
       
   572         {
       
   573         HBufC* temp = (*it).second;
       
   574         if(temp)
       
   575         	{
       
   576 			LOGSTRING3("Type: %d Content:%S ", (*it).first, &temp->Des() );
       
   577         	}
       
   578         }
       
   579     }
       
   580 
       
   581 // Checks if the link is a group or not
       
   582 TBool CCreatorPhonebook::IsContactGroupL( TUint32& aLink )
       
   583 	{
       
   584 	//not used right now
       
   585 	return EFalse;
       
   586 	}
       
   587 
       
   588 
       
   589 TInt CCreatorPhonebook::CreateGroupEntryL(CCreatorModuleBaseParameters *aParameters)
       
   590     {
       
   591 	 LOGSTRING("Creator: CCreatorPhonebook::CreateGroupEntryL");
       
   592 	 TInt err = KErrNone;
       
   593 	 
       
   594 	    delete iParameters;
       
   595 	    iParameters = 0;
       
   596 	    
       
   597 	    CPhonebookParameters* parameters = (CPhonebookParameters*) aParameters;
       
   598 	    
       
   599 	    if( !parameters )
       
   600 	       {
       
   601 	       iParameters = new (ELeave) CPhonebookParameters;
       
   602 	       iParameters->iContactsInGroup = iContactsInGroup;
       
   603 	       iParameters->iGroupName->Des().Copy( iEngine->RandomString(CCreatorEngine::EGroupName) );
       
   604 	       iParameters->iGroupName->Des().Append( _L(" #") );
       
   605 	       iParameters->iGroupName->Des().AppendNum( iEngine->RandomNumber(1000, 9999) );
       
   606 	       parameters = iParameters;
       
   607 	       }
       
   608 	   
       
   609 	    // create a new contact group
       
   610 	    
       
   611 	    TUint32 newGroupId = iPhonebookWrapper->CreateGroupEntryL( parameters->iGroupName );
       
   612 	    
       
   613 	    // define amounts of contacts to be added to the group
       
   614 	    TInt amountOfContactsToBeAdded = 0;
       
   615 	    if (parameters->iContactsInGroup == KCreateRandomAmountOfGroups)
       
   616 	    	{
       
   617 	        amountOfContactsToBeAdded = iEngine->RandomNumber(30);
       
   618 	    	}
       
   619 	    else 
       
   620 	    	{
       
   621 	        amountOfContactsToBeAdded = parameters->iContactsInGroup;
       
   622 	    	}
       
   623 	    
       
   624 	    if( parameters->iLinkIds.Count() > 0 )
       
   625 	        {
       
   626 	        for( TInt i = 0; i < parameters->iLinkIds.Count(); ++i )
       
   627 	            {
       
   628 	            const CCreatorContactSet& set = ContactLinkCache::Instance()->ContactSet(parameters->iLinkIds[i].iLinkId);
       
   629 	          
       
   630 	            const RArray<TUint32> links = set.ContactLinks();//ContactLinkCache::Instance()->ContactSets();//set.ContactLinks();
       
   631 	            TInt numberOfExplicitLinks = links.Count(); // Number of defined contacts in contact-set
       
   632 	            TInt numberOfExistingContacts = set.NumberOfExistingContacts(); // Number of existing contacts in contact-set
       
   633 	            TInt maxAmount = numberOfExplicitLinks + numberOfExistingContacts;
       
   634 	            
       
   635 	            if( parameters->iLinkIds[i].iLinkAmount > 0 )
       
   636 	                maxAmount = parameters->iLinkIds[i].iLinkAmount; // Max amount is limited
       
   637 	            
       
   638 	            TInt addedMembers = 0;
       
   639 	            
       
   640 	            for( TInt j = 0; j < links.Count() && addedMembers < maxAmount; ++j )
       
   641 	                {
       
   642 					
       
   643 					addedMembers += iPhonebookWrapper->AddContactToGroup(newGroupId,links[j]);
       
   644 	           
       
   645 	                }
       
   646 	            if( addedMembers < maxAmount )
       
   647 	            	{
       
   648 	            	// Add existing contacts, withing the limits set by maxAmount:
       
   649 	            	amountOfContactsToBeAdded += maxAmount - addedMembers;
       
   650 	            	}
       
   651 	            }
       
   652 	        }
       
   653 	    if( amountOfContactsToBeAdded > 0 )
       
   654 	        {
       
   655 			TInt addedContacts = iPhonebookWrapper->AddToGroup(newGroupId, amountOfContactsToBeAdded);
       
   656 		
       
   657 	        }
       
   658 	    
       
   659 	    // store the link to contact, so that Creator is able to delete
       
   660 	    // it when user requests deletion of contacts that were created with Creator 
       
   661 	    iContactGroupsToDelete.Append( newGroupId );
       
   662 	    
       
   663 	    return err;
       
   664     }
       
   665 
       
   666 //----------------------------------------------------------------------------
       
   667 
       
   668 TInt CCreatorPhonebook::CreateSubscribedContactEntryL(CCreatorModuleBaseParameters* /*aParameters*/)
       
   669     {
       
   670     LOGSTRING("Creator: CCreatorPhonebook::CreateSubscribedContactEntryL");
       
   671 
       
   672     return KErrNotSupported;
       
   673     }
       
   674 
       
   675 //----------------------------------------------------------------------------
       
   676 
       
   677 CCreatorContactField::CCreatorContactField()
       
   678     {
       
   679     }
       
   680 CCreatorContactField::~CCreatorContactField()
       
   681     {
       
   682     }
       
   683 
       
   684 CCreatorContactField* CCreatorContactField::NewL()
       
   685     {
       
   686     CCreatorContactField* self = new (ELeave) CCreatorContactField();
       
   687     CleanupStack::PushL(self);
       
   688     self->ConstructL();
       
   689     CleanupStack::Pop();
       
   690     return self;
       
   691     }
       
   692 void CCreatorContactField::ConstructL()
       
   693     {
       
   694     }
       
   695 
       
   696 
       
   697 void CCreatorContactField::AddFieldToParamL( CCreatorEngine* aEngine, CPhonebookParameters* aParam, TInt aType, TInt aRand )
       
   698     {
       
   699     HBufC* content = NULL;
       
   700     if( aRand == KErrNotFound ) 
       
   701         {
       
   702         TInt textFieldCount = sizeof(CreatorPbkPhoneNumberFields)/sizeof(TInt);;
       
   703         for( TInt tfIndex = 0; tfIndex < textFieldCount; ++tfIndex )
       
   704             {
       
   705             if( CreatorPbkPhoneNumberFields[tfIndex] == aType )
       
   706                 {
       
   707                 content = aEngine->RandomString(CCreatorEngine::EPhoneNumber).AllocL();
       
   708                 break;
       
   709                 }
       
   710             }
       
   711     
       
   712         textFieldCount = sizeof(CreatorPbkUrlFields)/sizeof(TInt);;
       
   713         for( TInt tfIndex = 0; tfIndex < textFieldCount; ++tfIndex )
       
   714             {
       
   715             if( CreatorPbkUrlFields[tfIndex] == aType )
       
   716                 {
       
   717                 content = aEngine->CreateHTTPUrlLC(); 
       
   718                 CleanupStack::Pop();
       
   719                 break;
       
   720                 }
       
   721             }
       
   722         textFieldCount = sizeof(CreatorPbkEmailFields)/sizeof(TInt);;
       
   723         for( TInt tfIndex = 0; tfIndex < textFieldCount; ++tfIndex )
       
   724             {
       
   725             if( CreatorPbkEmailFields[tfIndex] == aType )
       
   726                 {
       
   727                 content = aEngine->CreateEmailAddressLC();
       
   728                 CleanupStack::Pop();
       
   729                 break;
       
   730                 }
       
   731             }
       
   732         
       
   733     
       
   734         //if there is textfield without specified random number
       
   735         textFieldCount = sizeof(CreatorPbkMiscTextFields) / sizeof(DetailFieldInfo);
       
   736         for( TInt tfIndex = 0; tfIndex < textFieldCount; ++tfIndex )
       
   737             {
       
   738 			if( CreatorPbkMiscTextFields[tfIndex].iFieldCode == aType && CreatorPbkMiscTextFields[tfIndex].iRandomType != RND_TYPE_UNDEF )
       
   739             	{
       
   740 				TInt rand =  CreatorPbkMiscTextFields[tfIndex].iRandomType;
       
   741 				content = aEngine->RandomString((CCreatorEngine::TRandomStringType) rand).AllocL();
       
   742 				break;
       
   743 				}
       
   744 			}	
       
   745         }
       
   746 
       
   747     if( aRand != KErrNotFound && aRand != RND_TYPE_UNDEF ) 
       
   748         {
       
   749         TInt textFieldCount = sizeof(CreatorPbkMiscTextFields) / sizeof(DetailFieldInfo);
       
   750         for( TInt tfIndex = 0; tfIndex < textFieldCount; ++tfIndex )
       
   751             {
       
   752             if( CreatorPbkMiscTextFields[tfIndex].iFieldCode == aType )
       
   753                 {
       
   754                 content = aEngine->RandomString((CCreatorEngine::TRandomStringType) aRand).AllocL();
       
   755                 }
       
   756             }
       
   757         }
       
   758 	
       
   759 	aParam->iContactFields.insert( TCreatorContactField(aType, content) );
       
   760 	}
       
   761 
       
   762 void CCreatorContactField::AddFieldToParamL( CPhonebookParameters* aParam, TInt aType, TPtrC aContent )
       
   763     {
       
   764     aParam->iContactFields.insert( TCreatorContactField(aType, aContent.AllocL()) );
       
   765     }
       
   766 
       
   767 //----------------------------------------------------------------------------
       
   768 
       
   769 //----------------------------------------------------------------------------
       
   770