creator/engine/src/creator_phonebook.cpp
changeset 31 e7a04a6385be
parent 29 1c71b77fbc93
child 48 da3ec8478e66
equal deleted inserted replaced
30:d8e625c87f33 31:e7a04a6385be
    18 
    18 
    19 #include "engine.h"
    19 #include "engine.h"
    20 #include "enginewrapper.h"
    20 #include "enginewrapper.h"
    21 #include "creator_contactsetcache.h"
    21 #include "creator_contactsetcache.h"
    22 
    22 
    23 #include "creator_phonebook.h" 
    23 #include "creator_phonebook.h"
    24 #include "creator_traces.h"
    24 #include "creator_traces.h"
    25 
    25 
    26 #include <bautils.h> 
    26 #include <bautils.h> 
    27 //#include <qpixmap>
    27 
    28 
       
    29 //#include <QDebug>
       
    30 _LIT(KTempPath, "C:\\Data\\Creator\\");
    28 _LIT(KTempPath, "C:\\Data\\Creator\\");
    31 
    29 
    32 
    30 
    33 typedef struct {
    31 typedef struct {
    34 QString iDetail;
    32 TInt iFieldCode;
    35 QString iFieldContext;
       
    36 QString iFieldString;
       
    37 TInt iRandomType;
    33 TInt iRandomType;
    38 } DetailFieldInfo;
    34 } DetailFieldInfo;
    39 static const TInt RND_TYPE_UNDEF = -99;
    35 static const TInt RND_TYPE_UNDEF = -99;
    40 DetailFieldInfo CreatorPbkMiscTextFields[] = {        
    36 DetailFieldInfo CreatorPbkMiscTextFields[] = {        
    41         { (QContactName::DefinitionName).operator QString(), (QContactDetail::ContextHome).operator QString(), (QContactName::FieldFirstName).operator QString(), (TInt) CCreatorEngine::EFirstName},
    37         {CCreatorPhonebookWrapper::EFirstName, (TInt) CCreatorEngine::EFirstName},
    42         { (QContactName::DefinitionName).operator QString(), (QContactDetail::ContextHome).operator QString(), (QContactName::FieldLastName).operator QString(), (TInt) CCreatorEngine::ESurname},
    38         {CCreatorPhonebookWrapper::EFirstNameReading, (TInt) CCreatorEngine::EFirstName},
    43         { (QContactOrganization::DefinitionName).operator QString(), (QContactDetail::ContextWork).operator QString(), (QContactOrganization::FieldName).operator QString(), (TInt) CCreatorEngine::ECompany},
    39         {CCreatorPhonebookWrapper::ELastName, (TInt) CCreatorEngine::ESurname},
    44         { (QContactOrganization::DefinitionName).operator QString(), (QContactDetail::ContextWork).operator QString(), (QContactOrganization::FieldTitle).operator QString(), (TInt) CCreatorEngine::EJobTitle},
    40         {CCreatorPhonebookWrapper::ELastNameReading, (TInt) CCreatorEngine::ESurname},
    45         { (QContactName::DefinitionName).operator QString(), (QContactDetail::ContextHome).operator QString(), (QContactName::FieldPrefix).operator QString(), (TInt) CCreatorEngine::EPrefix},
    41         {CCreatorPhonebookWrapper::ECompanyName, (TInt) CCreatorEngine::ECompany},
    46         { (QContactName::DefinitionName).operator QString(), (QContactDetail::ContextHome).operator QString(), (QContactName::FieldSuffix).operator QString(), (TInt) CCreatorEngine::ESuffix},
    42         {CCreatorPhonebookWrapper::EJobTitle, (TInt) CCreatorEngine::EJobTitle},
    47         { (QContactName::DefinitionName).operator QString(), (QContactDetail::ContextHome).operator QString(), (QContactName::FieldMiddleName).operator QString(), (TInt) CCreatorEngine::EFirstName},
    43         {CCreatorPhonebookWrapper::EPrefix, (TInt) CCreatorEngine::EPrefix},
    48         { (QContactAddress::DefinitionName).operator QString(), (QContactDetail::ContextHome).operator QString(), (QContactAddress::FieldStreet).operator QString(), (TInt) CCreatorEngine::EAddress},
    44         {CCreatorPhonebookWrapper::ESuffix, (TInt) CCreatorEngine::ESuffix},
    49         { (QContactAddress::DefinitionName).operator QString(), (QContactDetail::ContextHome).operator QString(), (QContactAddress::FieldLocality).operator QString(), (TInt) CCreatorEngine::ECity},
    45         {CCreatorPhonebookWrapper::ESecondName, (TInt) CCreatorEngine::EFirstName},
    50         { (QContactAddress::DefinitionName).operator QString(), (QContactDetail::ContextHome).operator QString(), (QContactAddress::FieldRegion).operator QString(), (TInt) CCreatorEngine::EState},
    46         {CCreatorPhonebookWrapper::EAddrLabelGen, (TInt) CCreatorEngine::EAddress},
    51         { (QContactAddress::DefinitionName).operator QString(), (QContactDetail::ContextHome).operator QString(), (QContactAddress::FieldPostcode).operator QString(), (TInt) CCreatorEngine::EPostcode},
    47         {CCreatorPhonebookWrapper::EAddrPoGen, (TInt) CCreatorEngine::EPobox},
    52         { (QContactAddress::DefinitionName).operator QString(), (QContactDetail::ContextHome).operator QString(), (QContactAddress::FieldCountry).operator QString(), (TInt) CCreatorEngine::ECountry},
    48         {CCreatorPhonebookWrapper::EAddrExtGen, (TInt) CCreatorEngine::EAddress},
    53         { (QContactAddress::DefinitionName).operator QString(), "", (QContactAddress::FieldStreet).operator QString(), (TInt) CCreatorEngine::EAddress},
    49         {CCreatorPhonebookWrapper::EAddrStreetGen, (TInt) CCreatorEngine::EAddress},
    54         { (QContactAddress::DefinitionName).operator QString(), "", (QContactAddress::FieldLocality).operator QString(), (TInt) CCreatorEngine::ECity},
    50         {CCreatorPhonebookWrapper::EAddrLocalGen, (TInt) CCreatorEngine::ECity},
    55         { (QContactAddress::DefinitionName).operator QString(), "", (QContactAddress::FieldRegion).operator QString(), (TInt) CCreatorEngine::EState},
    51         {CCreatorPhonebookWrapper::EAddrRegionGen, (TInt) CCreatorEngine::EState},
    56         { (QContactAddress::DefinitionName).operator QString(), "", (QContactAddress::FieldPostcode).operator QString(), (TInt) CCreatorEngine::EPostcode},
    52         {CCreatorPhonebookWrapper::EAddrPostCodeGen, (TInt) CCreatorEngine::EPostcode},
    57         { (QContactAddress::DefinitionName).operator QString(), "", (QContactAddress::FieldCountry).operator QString(), (TInt) CCreatorEngine::ECountry},
    53         {CCreatorPhonebookWrapper::EAddrCountryGen, (TInt) CCreatorEngine::ECountry},
    58         { (QContactAddress::DefinitionName).operator QString(), (QContactDetail::ContextWork).operator QString(), (QContactAddress::FieldStreet).operator QString(), (TInt) CCreatorEngine::EAddress},
    54         {CCreatorPhonebookWrapper::EAddrLabelHome, (TInt) CCreatorEngine::EAddress},
    59         { (QContactAddress::DefinitionName).operator QString(), (QContactDetail::ContextWork).operator QString(), (QContactAddress::FieldLocality).operator QString(), (TInt) CCreatorEngine::ECity},
    55         {CCreatorPhonebookWrapper::EAddrPoHome, (TInt) CCreatorEngine::EPobox},
    60         { (QContactAddress::DefinitionName).operator QString(), (QContactDetail::ContextWork).operator QString(), (QContactAddress::FieldRegion).operator QString(), (TInt) CCreatorEngine::EState},
    56         {CCreatorPhonebookWrapper::EAddrExtHome, (TInt) CCreatorEngine::EAddress},
    61         { (QContactAddress::DefinitionName).operator QString(), (QContactDetail::ContextWork).operator QString(), (QContactAddress::FieldPostcode).operator QString(), (TInt) CCreatorEngine::EPostcode},
    57         {CCreatorPhonebookWrapper::EAddrStreetHome, (TInt) CCreatorEngine::EAddress},
    62         { (QContactAddress::DefinitionName).operator QString(), (QContactDetail::ContextWork).operator QString(), (QContactAddress::FieldCountry).operator QString(), (TInt) CCreatorEngine::ECountry},
    58         {CCreatorPhonebookWrapper::EAddrLocalHome, (TInt) CCreatorEngine::ECity},
    63         { (QContactPhoneNumber::DefinitionName).operator QString(), (QContactDetail::ContextWork).operator QString(), (QContactPhoneNumber::SubTypeMobile).operator QString(), (TInt) CCreatorEngine::EPhoneNumber},
    59         {CCreatorPhonebookWrapper::EAddrRegionHome, (TInt) CCreatorEngine::EState},
    64         { (QContactPhoneNumber::DefinitionName).operator QString(), (QContactDetail::ContextWork).operator QString(), (QContactPhoneNumber::SubTypeLandline).operator QString(), (TInt) CCreatorEngine::EPhoneNumber},
    60         {CCreatorPhonebookWrapper::EAddrPostCodeHome, (TInt) CCreatorEngine::EPostcode},
    65         { (QContactNote::DefinitionName).operator QString(), (QContactDetail::ContextHome).operator QString(), (QContactNote::FieldNote).operator QString(), (TInt)  CCreatorEngine::EMemoText},
    61         {CCreatorPhonebookWrapper::EAddrCountryHome, (TInt) CCreatorEngine::ECountry},
    66         { (QContactOrganization::DefinitionName).operator QString(), (QContactDetail::ContextWork).operator QString(), (QContactOrganization::FieldDepartment).operator QString(), (TInt) CCreatorEngine::ECompany},
    62         {CCreatorPhonebookWrapper::EAddrLabelWork, (TInt) CCreatorEngine::EAddress},
    67         { (QContactOrganization::DefinitionName).operator QString(), (QContactDetail::ContextWork).operator QString(), (QContactOrganization::FieldAssistantName).operator QString(), (TInt) CCreatorEngine::ECompany},
    63         {CCreatorPhonebookWrapper::EAddrPoWork, (TInt) CCreatorEngine::EPobox},
    68         { (QContactFamily::DefinitionName).operator QString(), (QContactDetail::ContextHome).operator QString(), (QContactFamily::FieldSpouse).operator QString(), (TInt) CCreatorEngine::EFirstName},
    64         {CCreatorPhonebookWrapper::EAddrExtWork, (TInt) CCreatorEngine::EAddress},
    69         { (QContactFamily::DefinitionName).operator QString(), (QContactDetail::ContextHome).operator QString(), (QContactFamily::FieldChildren).operator QString(), (TInt) CCreatorEngine::EFirstName},
    65         {CCreatorPhonebookWrapper::EAddrStreetWork, (TInt) CCreatorEngine::EAddress},
    70         { (QContactName::DefinitionName).operator QString(), (QContactDetail::ContextHome).operator QString(),  (QContactName::FieldCustomLabel).operator QString(), (TInt) CCreatorEngine::EFirstName}
    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}
    71         };
    87         };
    72                   
    88                   
    73 
    89 
    74 typedef struct{
    90 TInt CreatorPbkBinaryFields[] = {
    75 QString iFieldContext;
    91         CCreatorPhonebookWrapper::ECallerObjImg//,
    76 QString iFieldString;
    92         //R_VPBK_FIELD_TYPE_THUMBNAILPATH
    77 }PhoneNumInfo;
    93         };
    78 PhoneNumInfo CreatorPhoneNumberFields[] =
    94 
    79     {
    95 TInt CreatorPbkDateTimeFields[] = {
    80     { "", "Landline"},
    96         CCreatorPhonebookWrapper::EAnniversary
    81     { "Home", "Landline"},
    97         };
    82     { "Work", "Landline"},                        
    98 
    83     { "","Mobile"},
    99 //----------------------------------------------------------------------------
    84     { "Home","Mobile"},
   100 TInt CreatorPbkPhoneNumberFields[] =
    85     { "Work", "Mobile"},
   101     {
    86     { "Home", "Facsimile"},
   102     CCreatorPhonebookWrapper::ELandPhoneGen,
    87     { "Work", "Facsimile"},
   103     CCreatorPhonebookWrapper::ELandPhoneHome,
    88     { "Work", "Pager"},
   104     CCreatorPhonebookWrapper::ELandPhoneWork,                        
    89     { "Home", "Video"},
   105     CCreatorPhonebookWrapper::EMobilePhoneGen,
    90     { "Work", "Video"},   //{ "Home", "Voice" },//{ "Work", "Voice" },
   106     CCreatorPhonebookWrapper::EMobilePhoneHome,
    91     { "Work", "Assistant" },
   107     CCreatorPhonebookWrapper::EMobilePhoneWork,
    92     { "Home",  "Car" }
   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
    93     };
   120     };
    94 
   121 
    95 
   122 TInt CreatorPbkUrlFields[] =
    96 QString CreatorPbkEmailFields[] =
   123     {
    97     {
   124     CCreatorPhonebookWrapper::EUrlGen,
    98     //R_VPBK_FIELD_TYPE_EMAILGEN,
   125     CCreatorPhonebookWrapper::EUrlHome,
    99     (QContactDetail::ContextHome).operator QString(),//"Home",//R_VPBK_FIELD_TYPE_EMAILHOME,
   126     CCreatorPhonebookWrapper::EUrlWork
   100     (QContactDetail::ContextWork).operator QString()//R_VPBK_FIELD_TYPE_EMAILWORK
       
   101     };
   127     };
   102 
   128 
       
   129 TInt CreatorPbkEmailFields[] =
       
   130     {
       
   131     CCreatorPhonebookWrapper::EEmailGen,
       
   132     CCreatorPhonebookWrapper::EEmailHome,
       
   133     CCreatorPhonebookWrapper::EEmailWork
       
   134     };
   103 
   135 
   104 CPhonebookParameters::CPhonebookParameters()
   136 CPhonebookParameters::CPhonebookParameters()
   105     {
   137     {
   106     LOGSTRING("Creator: CVirtualPhonebookParameters::CVirtualPhonebookParameters");
   138     LOGSTRING("Creator: CPhonebookParameters::CVirtualPhonebookParameters");
   107     //iGroupName = HBufC::New(KPhonebookFieldLength);  
   139     iGroupName = HBufC::New(KPhonebookFieldLength);  
   108     }
   140     }
   109 
   141 
   110 CPhonebookParameters::~CPhonebookParameters()
   142 CPhonebookParameters::~CPhonebookParameters()
   111     {
   143     {
   112     LOGSTRING("Creator: CVirtualPhonebookParameters::~CVirtualPhonebookParameters");
   144     LOGSTRING("Creator: CPhonebookParameters::~CPhonebookParameters");
   113 
   145 
   114     //delete iGroupName;   
   146     delete iGroupName;   
   115     //iContactFields.ResetAndDestroy();
   147     for( TCreatorContactFields::iterator it = iContactFields.begin(); it != iContactFields.end(); ++it)
   116     //iContactFields.Close();
   148         {
   117     
   149         HBufC* temp =  (*it).second;
   118     //iLinkIds.clear();
   150         iContactFields.erase(it);
       
   151         delete temp;
       
   152         }
   119     iLinkIds.Reset();
   153     iLinkIds.Reset();
   120     iLinkIds.Close();
   154     iLinkIds.Close();
   121     }
   155     }
   122 
   156 
   123 void CPhonebookParameters::ParseL(CCommandParser* /*parser*/, TParseParams /*aCase = 0*/)
   157 void CPhonebookParameters::ParseL(CCommandParser* /*parser*/, TParseParams /*aCase = 0*/)
   162     {
   196     {
   163     LOGSTRING("Creator: CCreatorPhonebook::ConstructL");
   197     LOGSTRING("Creator: CCreatorPhonebook::ConstructL");
   164 	
   198 	
   165 	iEngine = aEngine;
   199 	iEngine = aEngine;
   166 	
   200 	
   167 	iContactMngr = new QContactManager("symbian");
   201 	iPhonebookWrapper = CCreatorPhonebookWrapper::NewL();
   168 
   202 
   169 	SetDefaultParameters();
   203 	SetDefaultParameters();
   170     }
   204     }
   171 	
   205 	
   172 
   206 
   181     if ( iContactGroupsToDelete.Count() )
   215     if ( iContactGroupsToDelete.Count() )
   182     	{
   216     	{
   183         TRAP_IGNORE( StoreLinksForDeleteL( iContactGroupsToDelete, KUidDictionaryUidContactGroups ) );
   217         TRAP_IGNORE( StoreLinksForDeleteL( iContactGroupsToDelete, KUidDictionaryUidContactGroups ) );
   184         }
   218         }
   185     
   219     
   186 	if( iContactMngr )
   220 	if( iPhonebookWrapper )
   187 		{
   221 		{
   188 		delete iContactMngr;
   222 		delete iPhonebookWrapper;
   189 		}
   223 		}
   190     
   224     
   191     if (iParameters)
   225     if (iParameters)
   192     	{
   226     	{
   193         delete iParameters;
   227         delete iParameters;
   194     	}
   228     	}
       
   229   
   195     }
   230     }
   196 
   231 
   197 //----------------------------------------------------------------------------
   232 //----------------------------------------------------------------------------
   198 
   233 
   199 TInt CCreatorPhonebook::CreateContactEntryL(CCreatorModuleBaseParameters *aParameters)
   234 TInt CCreatorPhonebook::CreateContactEntryL(CCreatorModuleBaseParameters *aParameters)
   200     {
   235     {
   201 	TInt err = KErrNone;
   236 	TInt err = KErrNone;
   202 	delete iParameters;
   237 	delete iParameters;
   203 	    iParameters = 0;
   238 	    iParameters = 0;
   204 	CPhonebookParameters* parameters = 0;
   239 	CPhonebookParameters* parameters = 0;
   205 	//InitializeContactParamsL();
       
   206 	
   240 	
   207 	if( aParameters == 0 )
   241 	if( aParameters == 0 )
   208 	    {
   242 	    {
   209 	    InitializeContactParamsL();
   243 	    InitializeContactParamsL();
   210 	    parameters = iParameters;
   244 	    parameters = iParameters;
   212 	else
   246 	else
   213 	    {
   247 	    {
   214 	    parameters = (CPhonebookParameters*) aParameters;
   248 	    parameters = (CPhonebookParameters*) aParameters;
   215 	    }
   249 	    }
   216 	    
   250 	    
   217 	bool success = false;
   251 	int numberOfFields = parameters->iContactFields.size();
   218 	// create a new contact item
   252 	// create a new contact item
   219 	QContact iStore;
       
   220 	
   253 	
   221 	int numberOfFields = parameters->iContactFields.count();
   254 	TUint32 contactId = iPhonebookWrapper->CreateContactEntryL( parameters->iContactFields ); //wrapper should return contact id to store
   222 	QString phone;
   255 	iContactsToDelete.Append( contactId );
   223 	for(int i=0; i< numberOfFields; i++ )
       
   224 		{
       
   225 		QContactDetail* cntdet = new QContactDetail(parameters->iContactFields.at(i));
       
   226 		success = iStore.saveDetail( cntdet );
       
   227 		delete cntdet;		
       
   228 		}
       
   229 	
   256 	
   230 	iContactMngr->saveContact( &iStore );
   257 
   231 	
       
   232 	iContactsToDelete.Append( (TUint32)iStore.localId() );
       
   233 	
       
   234 	// If this contact has a link id in script (i.e. belongs to a contact-set), we must cache the contact id:
   258 	// If this contact has a link id in script (i.e. belongs to a contact-set), we must cache the contact id:
   235 	    if( parameters->ScriptLinkId() > 0 )
   259 	    if( parameters->ScriptLinkId() > 0 )
   236 	        {                
   260 	        {                
   237 	        RPointerArray<CCreatorContactSet>& contactsets = ContactLinkCache::Instance()->ContactSets();
   261 	        RPointerArray<CCreatorContactSet>& contactsets = ContactLinkCache::Instance()->ContactSets();
   238 	        TBool setFound(EFalse);
   262 	        TBool setFound(EFalse);
   239 	        for(TInt i = 0; i < contactsets.Count(); ++i )
   263 	        for(TInt i = 0; i < contactsets.Count(); ++i )
   240 	            {
   264 	            {
   241 	            if( contactsets[i]->LinkId() == parameters->ScriptLinkId() )
   265 	            if( contactsets[i]->LinkId() == parameters->ScriptLinkId() )
   242 	                {
   266 	                {
   243 	                if( iStore.localId() )
   267 	                if( contactId )
   244 	                    {
   268 	                    {
   245 	                    contactsets[i]->AppendL( iStore.localId() );
   269 	                    contactsets[i]->AppendL( contactId );
   246 	                    iContactLinkArray.AppendL( (TUint32)iStore.localId() );
   270 	                    iContactLinkArray.AppendL( contactId );
   247 	                    }
   271 	                    }
   248 	                setFound = ETrue;
   272 	                setFound = ETrue;
   249 	                break;
   273 	                break;
   250 	                }
   274 	                }
   251 	            }
   275 	            }
   265 
   289 
   266 //----------------------------------------------------------------------------
   290 //----------------------------------------------------------------------------
   267 
   291 
   268 void CCreatorPhonebook::DeleteAllL()
   292 void CCreatorPhonebook::DeleteAllL()
   269     {
   293     {
   270 	QList<QContactLocalId> contacts = iContactMngr->contactIds();
   294 	iPhonebookWrapper->DeleteAllL();
   271 	DeleteContactsL( contacts );
       
   272     }
   295     }
   273 
   296 
   274 //----------------------------------------------------------------------------
   297 //----------------------------------------------------------------------------
   275 void CCreatorPhonebook::DeleteAllCreatedByCreatorL()
   298 void CCreatorPhonebook::DeleteAllCreatedByCreatorL()
   276     {
   299     {
   280 
   303 
   281 //----------------------------------------------------------------------------
   304 //----------------------------------------------------------------------------
   282 void CCreatorPhonebook::DeleteAllGroupsL()
   305 void CCreatorPhonebook::DeleteAllGroupsL()
   283     {
   306     {
   284     LOGSTRING("Creator: CCreatorPhonebook::DeleteAllGroupsL");
   307     LOGSTRING("Creator: CCreatorPhonebook::DeleteAllGroupsL");
   285     
   308     iPhonebookWrapper->DeleteAllGroupsL();
   286     QList<QContactLocalId> contacts = iContactMngr->contactIds();
       
   287     QList<QContactLocalId> groups;
       
   288     for(int i = 0; i < contacts.count(); i++)
       
   289     	{
       
   290 		QContact group = iContactMngr->contact( contacts.at(i) );
       
   291 		if( group.type() == QContactType::TypeGroup )
       
   292 			{
       
   293 			groups.append( group.localId() );
       
   294 			}
       
   295     	}
       
   296     DeleteContactsL( groups );
       
   297 
       
   298     }
   309     }
   299 
   310 
   300 //----------------------------------------------------------------------------
   311 //----------------------------------------------------------------------------
   301 void CCreatorPhonebook::DeleteAllGroupsCreatedByCreatorL()
   312 void CCreatorPhonebook::DeleteAllGroupsCreatedByCreatorL()
   302     {
   313     {
   303     LOGSTRING("Creator: CCreatorPhonebook::DeleteAllGroupsCreatedByCreatorL");
   314     LOGSTRING("Creator: CCreatorPhonebook::DeleteAllGroupsCreatedByCreatorL");
   304     DeleteItemsCreatedWithCreatorL( KUidDictionaryUidContactGroups );
   315     DeleteItemsCreatedWithCreatorL( KUidDictionaryUidContactGroups );
   305     }
   316     }
   306 
   317 
   307 //----------------------------------------------------------------------------
   318 //----------------------------------------------------------------------------
   308 void CCreatorPhonebook::DeleteContactsL( QList<QContactLocalId>& aContacts /*MVPbkContactLinkArray* aContacts, TBool aGroup*/ )
   319 void CCreatorPhonebook::DeleteContactsL( RArray<TUint32>& aContactsToDelete, TUid aStoreUid	)
   309     {
   320     {
   310 	//QList<QContactLocalId> contacts = iContactMngr->contactIds();
   321 	iPhonebookWrapper->DeleteContactsL( aContactsToDelete, aStoreUid );
   311     QMap<int, QContactManager::Error> errorMap;
   322     }
   312 	iContactMngr->removeContacts( aContacts, &errorMap );
   323 
   313     }
   324 //----------------------------------------------------------------------------
   314 
   325 
   315 //----------------------------------------------------------------------------
   326 
   316 void CCreatorPhonebook::DeleteItemsCreatedWithCreatorL( TUid aStoreUid )
   327 void CCreatorPhonebook::DeleteItemsCreatedWithCreatorL( TUid aStoreUid )
   317     {
   328     {
   318 	CDictionaryFileStore* store = iEngine->FileStoreLC();
   329 	CDictionaryFileStore* store = iEngine->FileStoreLC();
   319 	       User::LeaveIfNull( store );
   330     User::LeaveIfNull( store );
   320 	       
   331     
   321 	       QList<QContactLocalId> contacts;
   332     RArray<TUint32> contacts; 
   322 	       // backup previous contact links from store
   333     // backup previous contact links from store
   323 	       // otherwise they would be overwritten when calling out.WriteL
   334     // otherwise they would be overwritten when calling out.WriteL
   324 	       TUint32 creatorLink;
   335     TUint32 creatorLink;
   325 	       if ( store->IsPresentL( aStoreUid ) )
   336     if ( store->IsPresentL( aStoreUid ) )
   326 	           {
   337        {
   327 	           RDictionaryReadStream in;
   338        RDictionaryReadStream in;
   328 	           in.OpenLC( *store, aStoreUid );
   339        in.OpenLC( *store, aStoreUid );
   329 	           TRAP_IGNORE( 
   340        TRAP_IGNORE( 
   330 	               do{ 
   341            do{ 
   331 	                   creatorLink = in.ReadUint32L();
   342                creatorLink = in.ReadUint32L();
   332 	                   QContact contact = iContactMngr->contact( creatorLink );
   343                contacts.AppendL( creatorLink );
   333 	                   if( (contact.type() == QContactType::TypeGroup && aStoreUid == KUidDictionaryUidContactGroups ) ||  (contact.type() != QContactType::TypeGroup && aStoreUid != KUidDictionaryUidContactGroups) )
   344            }while( creatorLink );
   334 	                	   {
   345        );
   335 						   contacts.append( creatorLink );
   346        
   336 	                	   }
   347        CleanupStack::PopAndDestroy(); // in
   337 	               }while( creatorLink );)
   348        }
   338 	           
   349     
   339 	           CleanupStack::PopAndDestroy(); // in
   350     
   340 	           }
   351     iPhonebookWrapper->DeleteContactsL( contacts, aStoreUid );
   341 	       
   352     
   342 	       
   353     store->Remove( aStoreUid );
   343 	       DeleteContactsL( contacts );
   354     store->CommitL();
   344 	       
   355     
   345 	       store->Remove( aStoreUid );
   356     CleanupStack::PopAndDestroy( store );
   346 	       store->CommitL();
       
   347 	       
       
   348 	       CleanupStack::PopAndDestroy( store );
       
   349     }
   357     }
   350 
   358 
   351 //----------------------------------------------------------------------------
   359 //----------------------------------------------------------------------------
   352 void CCreatorPhonebook::DoDeleteItemsCreatedWithCreatorL( TUid /*aStoreUid*/, CDictionaryFileStore* /*aStore*/ )
   360 void CCreatorPhonebook::DoDeleteItemsCreatedWithCreatorL( TUid /*aStoreUid*/, CDictionaryFileStore* /*aStore*/ )
   353     {
   361     {
   354     
   362     
   355     }
   363     }
   356 
   364 
   357 //----------------------------------------------------------------------------
   365 //----------------------------------------------------------------------------
   358 TBool CCreatorPhonebook::HasOtherThanGroupsL( /*MVPbkContactLinkArray* aContacts */)
   366 TBool CCreatorPhonebook::HasOtherThanGroupsL()
   359     {
   367     {
   360     LOGSTRING("Creator: CCreatorPhonebook::HasOtherThanGroupsL");
   368     LOGSTRING("Creator: CCreatorPhonebook::HasOtherThanGroupsL");
   361     TBool result( EFalse );
   369     TBool result( EFalse );
   362     return result;
   370     return result;
   363     }
   371     }
   403        
   411        
   404        // restore previous links
   412        // restore previous links
   405        for ( TInt i = 0; i < iPreviousDeleteLinks.Count(); i++ )
   413        for ( TInt i = 0; i < iPreviousDeleteLinks.Count(); i++ )
   406            {
   414            {
   407            out.WriteUint32L( iPreviousDeleteLinks[i] );
   415            out.WriteUint32L( iPreviousDeleteLinks[i] );
   408            //CleanupStack::PopAndDestroy(); // PackLC            
       
   409            }
   416            }
   410        
   417        
   411        // write new links
   418        // write new links
   412        for(int i=0; i < aLinks.Count(); i++)
   419        for(int i=0; i < aLinks.Count(); i++)
   413     	   {
   420     	   {
   414 		   //TUint32 localId = (TUint32) aLinks[i];
       
   415 		   //out.WriteUint32L( aLinks[i] );
       
   416 		   out.WriteUint32L( aLinks[i] );
   421 		   out.WriteUint32L( aLinks[i] );
   417     	   }
   422     	   }
   418        out.CommitL();
   423        out.CommitL();
   419        //CleanupStack::PopAndDestroy(); // aLinks.PackLC
       
   420        CleanupStack::PopAndDestroy(); // out
   424        CleanupStack::PopAndDestroy(); // out
   421        
   425        
   422        store->CommitL();
   426        store->CommitL();
   423 
   427 
   424        CleanupStack::PopAndDestroy( store );
   428        CleanupStack::PopAndDestroy( store );
   425     }
   429     }
   426 
   430 
   427 //----------------------------------------------------------------------------
   431 //----------------------------------------------------------------------------
   428        
   432 //----------------------------------------------------------------------------
   429 //----------------------------------------------------------------------------
   433 
   430 
   434 void CCreatorPhonebook::InitializeContactParamsL()
   431 void CCreatorPhonebook::InitializeContactParamsL(/*CCreatorModuleBaseParameters* aParameters*/)
       
   432     {
   435     {
   433     LOGSTRING("Creator: CCreatorPhonebook::InitializeContactParamsL");        
   436     LOGSTRING("Creator: CCreatorPhonebook::InitializeContactParamsL");        
   434  
   437  
   435     iParameters = new (ELeave) CPhonebookParameters;
   438     iParameters = new (ELeave) CPhonebookParameters;
   436            
   439            
   437     iParameters->iNumberOfPhoneNumberFields = iNumberOfPhoneNumberFields;
   440     iParameters->iNumberOfPhoneNumberFields = iNumberOfPhoneNumberFields;
   438     iParameters->iNumberOfURLFields = iNumberOfURLFields;
   441     iParameters->iNumberOfURLFields = iNumberOfURLFields;
   439     iParameters->iNumberOfEmailAddressFields = iNumberOfEmailAddressFields;       
   442     iParameters->iNumberOfEmailAddressFields = iNumberOfEmailAddressFields;       
   440     
   443     
   441         
       
   442     QContactName name;
       
   443     
       
   444     TPtrC fname = iEngine->RandomString(CCreatorEngine::EFirstName);
   444     TPtrC fname = iEngine->RandomString(CCreatorEngine::EFirstName);
   445     TPtrC lname = iEngine->RandomString(CCreatorEngine::ESurname);
   445     TPtrC lname = iEngine->RandomString(CCreatorEngine::ESurname);
   446     QString firstname = QString::fromUtf16( fname.Ptr(), fname.Length() ); 
   446     
   447     QString lastname  = QString::fromUtf16( lname.Ptr(), lname.Length() );               
       
   448     
       
   449     name.setFirstName(firstname);
       
   450     name.setLastName(lastname);
       
   451     
   447     
   452     if( iAddAllFields )
   448     if( iAddAllFields )
   453         {
   449         {
   454 		TInt textFieldCount = sizeof(CreatorPbkMiscTextFields) / sizeof(DetailFieldInfo);
   450 		TInt textFieldCount = sizeof(CreatorPbkMiscTextFields) / sizeof(DetailFieldInfo);
   455 		for( TInt tfIndex = 0; tfIndex < textFieldCount; ++tfIndex )
   451 		for( TInt tfIndex = 0; tfIndex < textFieldCount; ++tfIndex )
   456                     { 
   452 			{ 
   457 //    				QContactDetail field = CreateContactDetail( CreatorPbkMiscTextFields[tfIndex].iDetail, CreatorPbkMiscTextFields[tfIndex].iFieldContext, CreatorPbkMiscTextFields[tfIndex].iFieldString, CreatorPbkMiscTextFields[tfIndex].iRandomType );
   453 			CCreatorContactField* field = CCreatorContactField::NewL();
   458     				
   454 			CleanupStack::PushL(field);
   459     				CCreatorContactField* field = CCreatorContactField::NewL();
   455 	        field->AddFieldToParamL( iEngine,iParameters, CreatorPbkMiscTextFields[tfIndex].iFieldCode, CreatorPbkMiscTextFields[tfIndex].iRandomType );
   460 	                CleanupStack::PushL( field );
   456   	        CleanupStack::Pop(field);
   461 	                QContactDetail cntDetail = field->CreateContactDetailL(iEngine,iParameters,CreatorPbkMiscTextFields[tfIndex].iDetail, CreatorPbkMiscTextFields[tfIndex].iFieldContext, CreatorPbkMiscTextFields[tfIndex].iFieldString, CreatorPbkMiscTextFields[tfIndex].iRandomType );
   457             }
   462   	                if(!cntDetail.isEmpty())
   458 		
   463   	                	{
       
   464   						field->AddFieldToParam( iParameters, cntDetail ); //it will do "param->iContactFields.AppendL(field);"
       
   465   	                	}
       
   466   	                CleanupStack::Pop( field );
       
   467                     }
       
   468 		// Add binary fields:
   459 		// Add binary fields:
   469 		TPtrC emptyData;
       
   470 		CCreatorContactField* fieldPicture = CCreatorContactField::NewL();
       
   471 		CleanupStack::PushL( fieldPicture );
       
   472 		QContactDetail cntDetail = fieldPicture->CreateContactDetailL(iEngine,iParameters,QContactAvatar::DefinitionName,"","",emptyData );
       
   473 		if(!cntDetail.isEmpty())
       
   474 		  	{
       
   475 		fieldPicture->AddFieldToParam( iParameters, cntDetail ); //it will do "param->iContactFields.AppendL(field);"
       
   476 		  	}
       
   477 		CleanupStack::Pop( fieldPicture );
       
   478 		
   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);
   479 		// Add date-time fields:
   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  
   480 		CCreatorContactField* fieldAnniv = CCreatorContactField::NewL();
   492 		CCreatorContactField* fieldAnniv = CCreatorContactField::NewL();
   481 		CleanupStack::PushL( fieldAnniv );
   493 		CleanupStack::PushL( fieldAnniv );
   482 		QContactDetail cntDetAnniv = fieldAnniv->CreateContactDetailL(iEngine,iParameters,QContactAnniversary::DefinitionName,"","",emptyData );
   494 		fieldAnniv->AddFieldToParamL(iParameters,CCreatorPhonebookWrapper::EAnniversary, anniv );
   483 		if(!cntDetAnniv .isEmpty())
       
   484 		  	{
       
   485 			fieldAnniv->AddFieldToParam( iParameters, cntDetAnniv ); //it will do "param->iContactFields.AppendL(field);"
       
   486 			}
       
   487 		CleanupStack::Pop( fieldAnniv );
   495 		CleanupStack::Pop( fieldAnniv );
   488 
       
   489     //***************************************************************************
   496     //***************************************************************************
   490     
   497     
   491         }
   498         }
   492     else
   499     else
   493         {    
   500         {
   494 		iParameters->iContactFields.append( name );
   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);
   495         }
   506         }
   496                         
   507                         
   497       // Phone numbers:
   508       // Phone numbers:
   498     TInt phoneFieldCount = sizeof(CreatorPhoneNumberFields) / sizeof(PhoneNumInfo);
   509     TInt phoneFieldCount = sizeof(CreatorPbkPhoneNumberFields) / sizeof(TInt);
   499     
   510     
   500     TInt inc=0;
   511     TInt inc=0;
   501     for( int i=0; i<iNumberOfPhoneNumberFields; i++ )
   512     for( TInt i=0; i<iNumberOfPhoneNumberFields; i++ )
   502     	{
   513     	{
   503     
   514     
   504 		if(inc >= phoneFieldCount )
   515 		if(inc >= phoneFieldCount )
   505         	{
   516         	{
   506     		inc = 0;
   517     		inc = 0;
   507         	}
   518         	}
   508     
       
   509 		QContactPhoneNumber phoneNum;
       
   510 		TPtrC phoneNumber = iEngine->RandomString(CCreatorEngine::EPhoneNumber);
       
   511 		QString phone = QString::fromUtf16( phoneNumber.Ptr(), phoneNumber.Length() );
       
   512 		if(!CreatorPhoneNumberFields[inc].iFieldContext.isEmpty())
       
   513 			{
       
   514 			phoneNum.setContexts(CreatorPhoneNumberFields[inc].iFieldContext);
       
   515 			}
       
   516 		phoneNum.setSubTypes(CreatorPhoneNumberFields[inc].iFieldString);
       
   517 		
   519 		
   518 
   520 		CCreatorContactField* field = CCreatorContactField::NewL();
   519 		phoneNum.setNumber( phone );
   521         CleanupStack::PushL(field);
   520 
   522 		field->AddFieldToParamL(iEngine, iParameters, CreatorPbkPhoneNumberFields[inc] );
   521 		iParameters->iContactFields.append( phoneNum );
   523 		CleanupStack::Pop(field);
       
   524     
   522 		inc++;
   525 		inc++;
   523     	}
   526     	}
   524     
   527     
   525     
   528     
   526     
   529     
   527     // URLs:
   530     // URLs:
   528     for( int i=0; i<iNumberOfURLFields; i++ )
   531     TInt urlFieldCount = sizeof(CreatorPbkUrlFields) / sizeof(TInt);
       
   532     inc = 0;
       
   533     for( TInt i=0; i<iNumberOfURLFields; i++ )
   529         {
   534         {
   530     	CCreatorContactField* fieldUrl = CCreatorContactField::NewL();
   535     
   531     	CleanupStack::PushL( fieldUrl );
   536 		if(inc >= urlFieldCount )
   532     	QContactDetail cntDetUrl = fieldUrl->CreateContactDetailL(iEngine,iParameters,QContactUrl::DefinitionName,"","",KErrNotFound );
   537           	{
   533     	if(!cntDetUrl.isEmpty())
   538         	inc = 0;
   534     	  	{
   539            	}
   535 			fieldUrl->AddFieldToParam( iParameters, cntDetUrl ); //it will do "param->iContactFields.AppendL(field);"
   540     
   536     	  	}
   541 		CCreatorContactField* field = CCreatorContactField::NewL();
   537     	CleanupStack::Pop( fieldUrl );
   542         CleanupStack::PushL(field);
   538 
   543     	field->AddFieldToParamL(iEngine, iParameters, CreatorPbkUrlFields[inc] );
       
   544     	CleanupStack::Pop(field);
       
   545     	inc++;
   539         }
   546         }
   540 
   547 
   541     // EMail addresses:
   548     // EMail addresses:
       
   549     TInt emailFieldCount = sizeof(CreatorPbkEmailFields) / sizeof(TInt);
       
   550     inc = 0;
   542     for( int i=0; i<iNumberOfEmailAddressFields; i++ )
   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)
   543         	{
   575         	{
   544 			CCreatorContactField* fieldEmail = CCreatorContactField::NewL();
   576 			LOGSTRING3("Type: %d Content:%S ", (*it).first, &temp->Des() );
   545         	CleanupStack::PushL( fieldEmail );
       
   546         	QContactDetail cntDetEmail = fieldEmail->CreateContactDetailL(iEngine,iParameters,QContactEmailAddress::DefinitionName,"","",KErrNotFound );
       
   547         	if(!cntDetEmail.isEmpty())
       
   548         	  	{
       
   549 				fieldEmail->AddFieldToParam( iParameters, cntDetEmail ); //it will do "param->iContactFields.AppendL(field);"
       
   550         	  	}
       
   551         	CleanupStack::Pop( fieldEmail );
       
   552         	}
   577         	}
   553     
   578         }
   554     }
   579     }
   555 
       
   556 
       
   557 
   580 
   558 // Checks if the link is a group or not
   581 // Checks if the link is a group or not
   559 TBool CCreatorPhonebook::IsContactGroupL( QContactLocalId& aLink )
   582 TBool CCreatorPhonebook::IsContactGroupL( TUint32& aLink )
   560 	{
   583 	{
   561     QContact group = iContactMngr->contact( aLink );
   584 	//not used right now
   562     if( group.type() == QContactType::TypeGroup )
       
   563         {
       
   564         return ETrue;
       
   565         }
       
   566 	return EFalse;
   585 	return EFalse;
   567 	}
   586 	}
   568 
   587 
       
   588 
   569 TInt CCreatorPhonebook::CreateGroupEntryL(CCreatorModuleBaseParameters *aParameters)
   589 TInt CCreatorPhonebook::CreateGroupEntryL(CCreatorModuleBaseParameters *aParameters)
   570     {
   590     {
   571 	 LOGSTRING("Creator: CCreatorVirtualPhonebook::CreateGroupEntryL");
   591 	 LOGSTRING("Creator: CCreatorPhonebook::CreateGroupEntryL");
       
   592 	 TInt err = KErrNone;
       
   593 	 
   572 	    delete iParameters;
   594 	    delete iParameters;
   573 	    iParameters = 0;
   595 	    iParameters = 0;
   574 	    
   596 	    
   575 	    CPhonebookParameters* parameters = (CPhonebookParameters*) aParameters;
   597 	    CPhonebookParameters* parameters = (CPhonebookParameters*) aParameters;
   576 	    
   598 	    
   577 	    if( !parameters )
   599 	    if( !parameters )
   578 	        {
   600 	       {
   579 	        iParameters = new (ELeave) CPhonebookParameters;
   601 	       iParameters = new (ELeave) CPhonebookParameters;
   580 	        iParameters->iContactsInGroup = iContactsInGroup;
   602 	       iParameters->iContactsInGroup = iContactsInGroup;
   581 	        TPtrC gname = iEngine->RandomString(CCreatorEngine::EGroupName);
   603 	       iParameters->iGroupName->Des().Copy( iEngine->RandomString(CCreatorEngine::EGroupName) );
   582 	        iParameters->iGroupName = QString::fromUtf16( gname.Ptr(),gname.Length() );
   604 	       iParameters->iGroupName->Des().Append( _L(" #") );
   583 	        iParameters->iGroupName += " #";
   605 	       iParameters->iGroupName->Des().AppendNum( iEngine->RandomNumber(1000, 9999) );
   584 	        int rnd = iEngine->RandomNumber(1000, 9999);
   606 	       parameters = iParameters;
   585 	        iParameters->iGroupName += QString::number( rnd, 10 );
   607 	       }
   586 	        parameters = iParameters;
   608 	   
   587 	        }
       
   588 
       
   589 	    TInt err = KErrNone;
       
   590 	 
       
   591 	    // create a new contact group
   609 	    // create a new contact group
   592 	    QContact newGroup;
   610 	    
   593 	    newGroup.setType(QContactType::TypeGroup);
   611 	    TUint32 newGroupId = iPhonebookWrapper->CreateGroupEntryL( parameters->iGroupName );
   594         QContactName newGroupName;
   612 	    
   595         newGroupName.setCustomLabel( parameters->iGroupName );
       
   596         newGroup.saveDetail(&newGroupName);
       
   597         iContactMngr->saveContact(&newGroup);
       
   598         QContactLocalId newGroupId = newGroup.localId();
       
   599 
       
   600 	        
       
   601 	    // define amounts of contacts to be added to the group
   613 	    // define amounts of contacts to be added to the group
   602 	    TInt amountOfContactsToBeAdded = 0;
   614 	    TInt amountOfContactsToBeAdded = 0;
   603 	    if (parameters->iContactsInGroup == KCreateRandomAmountOfGroups)
   615 	    if (parameters->iContactsInGroup == KCreateRandomAmountOfGroups)
   604 	    	{
   616 	    	{
   605 	        amountOfContactsToBeAdded = iEngine->RandomNumber(30);
   617 	        amountOfContactsToBeAdded = iEngine->RandomNumber(30);
   613 	        {
   625 	        {
   614 	        for( TInt i = 0; i < parameters->iLinkIds.Count(); ++i )
   626 	        for( TInt i = 0; i < parameters->iLinkIds.Count(); ++i )
   615 	            {
   627 	            {
   616 	            const CCreatorContactSet& set = ContactLinkCache::Instance()->ContactSet(parameters->iLinkIds[i].iLinkId);
   628 	            const CCreatorContactSet& set = ContactLinkCache::Instance()->ContactSet(parameters->iLinkIds[i].iLinkId);
   617 	          
   629 	          
   618 	            const RArray<QContactLocalId> links = set.ContactLinks();//ContactLinkCache::Instance()->ContactSets();//set.ContactLinks();
   630 	            const RArray<TUint32> links = set.ContactLinks();//ContactLinkCache::Instance()->ContactSets();//set.ContactLinks();
   619 	            TInt numberOfExplicitLinks = links.Count(); // Number of defined contacts in contact-set
   631 	            TInt numberOfExplicitLinks = links.Count(); // Number of defined contacts in contact-set
   620 	            TInt numberOfExistingContacts = set.NumberOfExistingContacts(); // Number of existing contacts in contact-set
   632 	            TInt numberOfExistingContacts = set.NumberOfExistingContacts(); // Number of existing contacts in contact-set
   621 	            TInt maxAmount = numberOfExplicitLinks + numberOfExistingContacts;
   633 	            TInt maxAmount = numberOfExplicitLinks + numberOfExistingContacts;
   622 	            
   634 	            
   623 	            if( parameters->iLinkIds[i].iLinkAmount > 0 )
   635 	            if( parameters->iLinkIds[i].iLinkAmount > 0 )
   625 	            
   637 	            
   626 	            TInt addedMembers = 0;
   638 	            TInt addedMembers = 0;
   627 	            
   639 	            
   628 	            for( TInt j = 0; j < links.Count() && addedMembers < maxAmount; ++j )
   640 	            for( TInt j = 0; j < links.Count() && addedMembers < maxAmount; ++j )
   629 	                {
   641 	                {
   630 	                QContactLocalId link = links[j];
   642 					
   631 	                QContact contactLink = iContactMngr->contact( link );
   643 					addedMembers += iPhonebookWrapper->AddContactToGroup(newGroupId,links[j]);
   632 	                if( link && IsContactGroupL( link ) == EFalse )
   644 	           
   633 	                    {
       
   634                         //QList<QContactRelationship> relationships = contactLink.relationships(QContactRelationship::HasMember);
       
   635 	                    if(/*!relationships.count() && */contactLink.type() == QContactType::TypeContact ) //just for contacts that are not in relationship - not in group yet
       
   636 	                        {
       
   637 	                        QContactRelationship* contactRel = new QContactRelationship();
       
   638 	                        contactRel->setRelationshipType(QContactRelationship::HasMember);
       
   639 	                        contactRel->setFirst(newGroup.id());
       
   640 	                        contactRel->setSecond( contactLink.id() );
       
   641 	                        iContactMngr->saveRelationship( contactRel );
       
   642 	                        delete contactRel;
       
   643 	                        ++addedMembers;
       
   644 	                        }         
       
   645 	                    }
       
   646 	                }
   645 	                }
   647 	            if( addedMembers < maxAmount )
   646 	            if( addedMembers < maxAmount )
   648 	            	{
   647 	            	{
   649 	            	// Add existing contacts, withing the limits set by maxAmount:
   648 	            	// Add existing contacts, withing the limits set by maxAmount:
   650 	            	amountOfContactsToBeAdded += maxAmount - addedMembers;
   649 	            	amountOfContactsToBeAdded += maxAmount - addedMembers;
   651 	            	}
   650 	            	}
   652 	            }
   651 	            }
   653 	        }
   652 	        }
   654 	    if( amountOfContactsToBeAdded > 0 )
   653 	    if( amountOfContactsToBeAdded > 0 )
   655 	        {
   654 	        {
   656 			QList<QContactLocalId> contacts = iContactMngr->contactIds();
   655 			TInt addedContacts = iPhonebookWrapper->AddToGroup(newGroupId, amountOfContactsToBeAdded);
   657 			QContactRelationshipFilter rFilter;
   656 		
   658 			rFilter.setRelationshipType(QContactRelationship::HasMember);
       
   659 			rFilter.setRelatedContactRole(QContactRelationshipFilter::First);
       
   660 			rFilter.setRelatedContactId( newGroup.id() );
       
   661 			
       
   662 			int cnt = 0;
       
   663 			for(int i=0; cnt < amountOfContactsToBeAdded && i < contacts.count() ; i++ )
       
   664 				{
       
   665 				QContact contact = iContactMngr->contact( iContactMngr->contactIds().at(i) );
       
   666 				if( iContactMngr->error() == QContactManager::DoesNotExistError )
       
   667 					{
       
   668 				
       
   669 					}
       
   670 				else
       
   671 					{
       
   672 					QList<QContactRelationship> relationships = contact.relationships(QContactRelationship::HasMember);
       
   673 					if(!relationships.count() && contact.type() == QContactType::TypeContact ) //just for contacts that are not in relationship - not in group yet
       
   674 						{
       
   675 						QContactRelationship* contactRel = new QContactRelationship();
       
   676 						contactRel->setRelationshipType(QContactRelationship::HasMember);
       
   677 						contactRel->setFirst(newGroup.id());
       
   678 						contactRel->setSecond(contact.id());
       
   679 						iContactMngr->saveRelationship( contactRel );
       
   680 						delete contactRel;
       
   681 						cnt++;
       
   682 						}
       
   683 					}
       
   684 				}
       
   685 			
       
   686 	       // group members and their count
       
   687 			QList<QContactLocalId> groupMemberIds = iContactMngr->contactIds( rFilter );
       
   688 			int testcnt = groupMemberIds.count(); 
       
   689 	    
       
   690 	   
       
   691 	        }
   657 	        }
   692 	    
   658 	    
   693 	    // store the link to contact, so that Creator is able to delete
   659 	    // store the link to contact, so that Creator is able to delete
   694 	    // it when user requests deletion of contacts that were created with Creator 
   660 	    // it when user requests deletion of contacts that were created with Creator 
   695 	    iContactGroupsToDelete.Append( (TUint32)newGroupId );
   661 	    iContactGroupsToDelete.Append( newGroupId );
   696 	    
   662 	    
   697 	    return err;
   663 	    return err;
   698     }
   664     }
   699 
   665 
   700 //----------------------------------------------------------------------------
   666 //----------------------------------------------------------------------------
   723     CleanupStack::Pop();
   689     CleanupStack::Pop();
   724     return self;
   690     return self;
   725     }
   691     }
   726 void CCreatorContactField::ConstructL()
   692 void CCreatorContactField::ConstructL()
   727     {
   693     {
   728     //pImpl = CCreatorContactTextField::NewL(aFieldType, aData); 
   694     }
   729     }
   695 
   730 QContactDetail CCreatorContactField::CreateContactDetailL(CCreatorEngine* aEngine,CPhonebookParameters* aParameters,QString aDetail, QString aFieldContext, QString aFieldString, TInt aRand )
   696 
   731     {
   697 void CCreatorContactField::AddFieldToParamL( CCreatorEngine* aEngine, CPhonebookParameters* aParam, TInt aType, TInt aRand )
   732 	QContactDetail emptyDet;
   698     {
   733     TPtrC contentData;
   699     HBufC* content = NULL;
   734     HBufC16* tempData = 0;
   700     if( aRand == KErrNotFound ) 
   735     if(aRand == KErrNotFound)
   701         {
   736     	{
   702         TInt textFieldCount = sizeof(CreatorPbkPhoneNumberFields)/sizeof(TInt);;
   737 		TInt textFieldCount = sizeof(CreatorPbkMiscTextFields) / sizeof(DetailFieldInfo);
   703         for( TInt tfIndex = 0; tfIndex < textFieldCount; ++tfIndex )
   738 		for( TInt tfIndex = 0; tfIndex < textFieldCount; ++tfIndex )
   704             {
   739 			{
   705             if( CreatorPbkPhoneNumberFields[tfIndex] == aType )
   740 			if( CreatorPbkMiscTextFields[tfIndex].iDetail == aDetail && CreatorPbkMiscTextFields[tfIndex].iFieldContext == aFieldContext && CreatorPbkMiscTextFields[tfIndex].iFieldString == aFieldString)
   706                 {
   741 				{
   707                 content = aEngine->RandomString(CCreatorEngine::EPhoneNumber).AllocL();
   742 				aRand = CreatorPbkMiscTextFields[tfIndex].iRandomType;
   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 				}
   743 				}
   744 			}
   744 			}	
   745     	}
   745         }
   746     
   746 
   747     if( aRand != KErrNotFound ) 
   747     if( aRand != KErrNotFound && aRand != RND_TYPE_UNDEF ) 
   748     	{
   748         {
   749 		contentData.Set(aEngine->RandomString((CCreatorEngine::TRandomStringType) aRand));
   749         TInt textFieldCount = sizeof(CreatorPbkMiscTextFields) / sizeof(DetailFieldInfo);
   750     	}
   750         for( TInt tfIndex = 0; tfIndex < textFieldCount; ++tfIndex )
   751     else
       
   752     	{
       
   753 		if( aDetail == QContactPhoneNumber::DefinitionName )
       
   754 			{
       
   755 			contentData.Set(aEngine->RandomString(CCreatorEngine::EPhoneNumber));
       
   756 			}
       
   757 		else if( aDetail == QContactEmailAddress::DefinitionName )
       
   758 			{
       
   759 			tempData = aEngine->CreateEmailAddressLC();
       
   760 			contentData.Set( tempData->Des() );
       
   761 			}
       
   762 		else if( aDetail == QContactUrl::DefinitionName )
       
   763 			{
       
   764 			tempData = aEngine->CreateHTTPUrlLC(); 
       
   765 			contentData.Set( tempData->Des() );
       
   766 			}
       
   767 		else
       
   768 			{
       
   769 			return emptyDet;
       
   770 			}
       
   771     	}
       
   772     emptyDet = CreateContactDetailL( aEngine, aParameters, aDetail, aFieldContext, aFieldString, contentData );
       
   773     if( tempData )
       
   774     	{
       
   775 		CleanupStack::PopAndDestroy( tempData );
       
   776     	}
       
   777     return emptyDet;
       
   778     }
       
   779 
       
   780 QContactDetail CCreatorContactField::CreateContactDetailL(CCreatorEngine* aEngine,CPhonebookParameters* aParameters,QString aDetail, QString aFieldContext, QString aFieldString, TPtrC aData )
       
   781     {
       
   782     QContactDetail contactDetail;
       
   783         
       
   784         if( aDetail == QContactPhoneNumber::DefinitionName)
       
   785             {
   751             {
   786             QContactPhoneNumber phoneNumber;// = contactDetail;
   752             if( CreatorPbkMiscTextFields[tfIndex].iFieldCode == aType )
   787             if(!aFieldContext.isEmpty())
   753                 {
   788             	{
   754                 content = aEngine->RandomString((CCreatorEngine::TRandomStringType) aRand).AllocL();
   789 				phoneNumber.setContexts(aFieldContext);
   755                 }
   790             	}
       
   791             phoneNumber.setSubTypes(aFieldString);
       
   792             QString number = QString::fromUtf16(aData.Ptr(),aData.Length());
       
   793             phoneNumber.setNumber(number);
       
   794             return phoneNumber;
       
   795             }
   756             }
   796         else if( aDetail == QContactName::DefinitionName )          //--Contact NAME-----------------------------
   757         }
   797             {
   758 	
   798             QContactName contactName;
   759 	aParam->iContactFields.insert( TCreatorContactField(aType, content) );
   799             for(int i = 0 ; i < aParameters->iContactFields.count() ; i++ ) //go through all contact details to check if there is already Contact Name to set other details
   760 	}
   800                 {
   761 
   801                 if(aParameters->iContactFields.at(i).definitionName() == QContactName::DefinitionName )
   762 void CCreatorContactField::AddFieldToParamL( CPhonebookParameters* aParam, TInt aType, TPtrC aContent )
   802                     {
   763     {
   803                     contactName = aParameters->iContactFields.at(i);
   764     aParam->iContactFields.insert( TCreatorContactField(aType, aContent.AllocL()) );
   804                     }
   765     }
   805                 }
   766 
   806             QString name = QString::fromUtf16(aData.Ptr(),aData.Length());
   767 //----------------------------------------------------------------------------
   807             if(aFieldString == QContactName::FieldFirstName)
   768 
   808                 {
   769 //----------------------------------------------------------------------------
   809                 if(contactName.firstName().isEmpty())
   770 
   810                     {
       
   811                     contactName.setFirstName( name );
       
   812                     }
       
   813                 }
       
   814             else if(aFieldString == QContactName::FieldLastName)
       
   815                 {
       
   816                 if(contactName.lastName().isEmpty())
       
   817                     {
       
   818                     contactName.setLastName( name );
       
   819                     }
       
   820                 }
       
   821             else if(aFieldString == QContactName::FieldMiddleName)
       
   822                 {
       
   823                 if(contactName.middleName().isEmpty())
       
   824                     {
       
   825                     contactName.setMiddleName( name );
       
   826                     }
       
   827                 }
       
   828             else if(aFieldString == QContactName::FieldPrefix)
       
   829                 {
       
   830                 if(contactName.prefix().isEmpty())
       
   831                     {
       
   832                     contactName.setPrefix( name );
       
   833                     }
       
   834                 }
       
   835             else if(aFieldString == QContactName::FieldSuffix)
       
   836                 {
       
   837                 if(contactName.suffix().isEmpty())
       
   838                     {
       
   839                     contactName.setSuffix( name );
       
   840                     }
       
   841                 }
       
   842             else        //QContactName::FieldCustomLabel:
       
   843                 {
       
   844                 if(contactName.customLabel().isEmpty())
       
   845                     {
       
   846                     contactName.setCustomLabel( name );
       
   847                     }
       
   848                 }
       
   849             return contactName;
       
   850             }
       
   851         else if( aDetail == QContactOrganization::DefinitionName )          //--Contact Company-----------------------------
       
   852             {
       
   853             QContactOrganization contactCompany;
       
   854             
       
   855             for(int i = 0 ; i < aParameters->iContactFields.count() ; i++ ) //go through all contact details to check if there is already Contact Name to set other details
       
   856                 {
       
   857                 if(aParameters->iContactFields.at(i).definitionName() == QContactOrganization::DefinitionName )
       
   858                     {
       
   859                     contactCompany = aParameters->iContactFields.at(i);
       
   860                     }
       
   861                 }
       
   862             
       
   863             QString company = QString::fromUtf16(aData.Ptr(),aData.Length());
       
   864             if(aFieldString == QContactOrganization::FieldName)
       
   865                 {
       
   866                 if(contactCompany.name().isEmpty())
       
   867                     {
       
   868                     contactCompany.setName( company );
       
   869                     }
       
   870                 }
       
   871             if(aFieldString == QContactOrganization::FieldTitle)
       
   872                 {
       
   873                 if(contactCompany.title().isEmpty())
       
   874                     {
       
   875                     contactCompany.setTitle( company );
       
   876                     }
       
   877                 }
       
   878             if(aFieldString == QContactOrganization::FieldDepartment)
       
   879                 {
       
   880                 QStringList depList = contactCompany.department();
       
   881                 depList.append(company);
       
   882                 contactCompany.setDepartment(depList);
       
   883                 }
       
   884             if(aFieldString == QContactOrganization::FieldAssistantName)
       
   885                 {
       
   886                 if(contactCompany.assistantName().isEmpty())
       
   887                     {
       
   888                     contactCompany.setAssistantName( company );
       
   889                     }
       
   890                 }
       
   891             return contactCompany;
       
   892             }
       
   893         else if( aDetail == QContactAddress::DefinitionName )           //--Contact Address-----------------------------
       
   894                 {
       
   895                 QContactAddress contactAddress;
       
   896                 
       
   897                 for(int i = 0 ; i < aParameters->iContactFields.count() ; i++ ) //go through all contact details to check if there is already Contact Name to set other details
       
   898                     {
       
   899                     if(aParameters->iContactFields.at(i).definitionName() == QContactAddress::DefinitionName && aParameters->iContactFields.at(i).value(QContactDetail::FieldContext) == aFieldContext )
       
   900                         {
       
   901                         contactAddress = aParameters->iContactFields.at(i);
       
   902                         }
       
   903                     }
       
   904                 if( !aFieldContext.isEmpty() )
       
   905                     {
       
   906 					contactAddress.setContexts( aFieldContext );
       
   907                     }
       
   908                 QString address = QString::fromUtf16(aData.Ptr(),aData.Length());
       
   909                 if(aFieldString == QContactAddress::FieldStreet )
       
   910                     {
       
   911                     if( contactAddress.street().isEmpty() )
       
   912                         {
       
   913                         contactAddress.setStreet( address );
       
   914                         }
       
   915                     }
       
   916                 else if(aFieldString == QContactAddress::FieldLocality )
       
   917                     {
       
   918                     if( contactAddress.locality().isEmpty() )
       
   919                         {
       
   920                         contactAddress.setLocality( address );
       
   921                         }
       
   922                     }
       
   923                 else if(aFieldString == QContactAddress::FieldRegion )
       
   924                     {
       
   925                     if( contactAddress.region().isEmpty() )
       
   926                         {
       
   927                         contactAddress.setRegion( address );
       
   928                         }
       
   929                     }
       
   930                 else if(aFieldString == QContactAddress::FieldPostcode )
       
   931                     {
       
   932                     if( contactAddress.postcode().isEmpty() )
       
   933                         {
       
   934                         contactAddress.setPostcode( address );
       
   935                         }
       
   936                     }
       
   937                 else if(aFieldString == QContactAddress::FieldCountry )
       
   938                     {
       
   939                     if( contactAddress.country().isEmpty() )
       
   940                         {
       
   941                         contactAddress.setCountry( address );
       
   942                         }
       
   943                     }
       
   944                 else 
       
   945                     {
       
   946                     return contactDetail;
       
   947                     }
       
   948                 return contactAddress;
       
   949                 }
       
   950         else if( aDetail == QContactNote::DefinitionName )          //--Contact Note-----------------------------
       
   951                     {
       
   952                     QContactNote contactNote;
       
   953                     QString note = QString::fromUtf16(aData.Ptr(),aData.Length());
       
   954                     contactNote.setNote(note);
       
   955                     return contactNote;
       
   956                     }
       
   957         else if( aDetail == QContactFamily::DefinitionName )            //--Contact Family-----------------------------
       
   958                     {
       
   959                     QContactFamily contactFamily;
       
   960                     
       
   961                     for(int i = 0 ; i < aParameters->iContactFields.count() ; i++ ) //go through all contact details to check if there is already Contact Name to set other details
       
   962                         {
       
   963                         if(aParameters->iContactFields.at(i).definitionName() == QContactFamily::DefinitionName && aParameters->iContactFields.at(i).value(QContactDetail::FieldContext) == aFieldContext )
       
   964                             {
       
   965                             contactFamily = aParameters->iContactFields.at(i);
       
   966                             }
       
   967                         }
       
   968                    
       
   969                     QString familyData = QString::fromUtf16(aData.Ptr(),aData.Length());
       
   970                     if(aFieldString == QContactFamily::FieldSpouse )
       
   971                         {
       
   972                         if( contactFamily.spouse().isEmpty() )
       
   973                             {
       
   974                             contactFamily.setSpouse( familyData );
       
   975                             }
       
   976                         }
       
   977                     if(aFieldString == QContactFamily::FieldChildren )
       
   978                         {
       
   979                             QStringList children = contactFamily.children();
       
   980                             children.append( familyData );
       
   981                             contactFamily.setChildren( children );
       
   982                         }
       
   983                     
       
   984                     return contactFamily;
       
   985                     }
       
   986         
       
   987         if( aDetail == QContactAvatar::DefinitionName)                      //--Contact Picture-----------------------------
       
   988                 {
       
   989                 RFs& fs = CCoeEnv::Static()->FsSession();
       
   990                 QContactAvatar contactAvatar;
       
   991                 TBuf<KMaxFileName> srcPath;
       
   992                 aEngine->RandomPictureFileL(srcPath);
       
   993                 TBuf<KMaxFileName> destPath(KTempPath);
       
   994                             
       
   995                 if(!BaflUtils::FolderExists( fs, destPath ))
       
   996                     {
       
   997                     BaflUtils::EnsurePathExistsL( fs, destPath );
       
   998                     }
       
   999                 
       
  1000                 TInt err=BaflUtils::CopyFile( fs, srcPath, destPath );
       
  1001 
       
  1002                 TParse temp;
       
  1003                 temp.Set( srcPath,NULL,NULL );
       
  1004                 destPath.Append(temp.NameAndExt());
       
  1005                 
       
  1006                 QString avatarFile = QString::fromUtf16( destPath.Ptr(),destPath.Length() );
       
  1007                 
       
  1008                 //QPixmap avatarPix(avatarFile);
       
  1009 
       
  1010                 QUrl imageUrl;
       
  1011                 imageUrl.setUrl(avatarFile);
       
  1012                 contactAvatar.setImageUrl(imageUrl);
       
  1013                 //contactAvatar.setAvatar(avatarFile); //deprecated
       
  1014                 //contactAvatar.setPixmap(avatarPix);
       
  1015 
       
  1016                 return contactAvatar;
       
  1017                 }
       
  1018         if( aDetail == QContactAnniversary::DefinitionName) //--Anniversary------------------------------
       
  1019                 {
       
  1020                 QContactAnniversary contactAnniversary;
       
  1021                 QDate date;
       
  1022                 TTime datetime = aEngine->RandomDate( CCreatorEngine::EDateFuture );
       
  1023                 date.setDate( datetime.DateTime().Year(),(int) (datetime.DateTime().Month()+1), datetime.DateTime().Day() );
       
  1024                 contactAnniversary.setOriginalDate( date );
       
  1025                 return contactAnniversary;
       
  1026                 }
       
  1027         if( aDetail == QContactEmailAddress::DefinitionName) //--Email------------------------------------
       
  1028             {
       
  1029             QContactEmailAddress email;
       
  1030             QString emailAddr = QString::fromUtf16(aData.Ptr(),aData.Length());
       
  1031             if( !aFieldContext.isEmpty() )
       
  1032             	{
       
  1033 				email.setContexts( aFieldContext );
       
  1034             	}
       
  1035             email.setEmailAddress( emailAddr );
       
  1036             return email;
       
  1037             }
       
  1038         if( aDetail == QContactUrl::DefinitionName )    //--Url-------------------------------------------
       
  1039             {
       
  1040             QContactUrl url;
       
  1041             QString urlStr = QString::fromUtf16(aData.Ptr(),aData.Length());
       
  1042             if( !aFieldContext.isEmpty() )
       
  1043                 {
       
  1044 				url.setContexts( aFieldContext );
       
  1045                 }
       
  1046             url.setUrl(urlStr);
       
  1047             return url;
       
  1048             }
       
  1049         if( aDetail == QContactBirthday::DefinitionName )   //--Birthday-----------------------------------
       
  1050             {
       
  1051             QContactBirthday birthday;
       
  1052             QDate date;
       
  1053             TTime datetime = aEngine->RandomDate( CCreatorEngine::EDatePast );
       
  1054             date.setDate( datetime.DateTime().Year(),(int) (datetime.DateTime().Month()+1), datetime.DateTime().Day() );
       
  1055             birthday.setDate( date );
       
  1056             return birthday;
       
  1057             }
       
  1058                 
       
  1059         return contactDetail;
       
  1060     }
       
  1061 
       
  1062 void CCreatorContactField::AddFieldToParam( CPhonebookParameters* aParam, QContactDetail aDetail)
       
  1063     {
       
  1064      bool replace = false;
       
  1065      for(int i = 0 ; i< aParam->iContactFields.count() ; i++) //go through
       
  1066           {
       
  1067            if( !aDetail.isEmpty() && aDetail.definitionName() == aParam->iContactFields.at(i).definitionName() 
       
  1068         		   && aDetail.definitionName() != QContactPhoneNumber::DefinitionName 
       
  1069         		   && aDetail.definitionName() != QContactEmailAddress::DefinitionName
       
  1070         		   && aDetail.definitionName() != QContactUrl::DefinitionName )
       
  1071                {
       
  1072                QString context = aDetail.value(QContactDetail::FieldContext);
       
  1073                bool isContextEmpty = context.isEmpty();
       
  1074                if( isContextEmpty ||  ( aDetail.value(QContactDetail::FieldContext) == aParam->iContactFields.at(i).value(QContactDetail::FieldContext)) )
       
  1075                    {
       
  1076                    //replace
       
  1077                    aParam->iContactFields.replace(i,aDetail);
       
  1078                    replace = true;
       
  1079                    }
       
  1080                }
       
  1081           }
       
  1082           if(!replace)
       
  1083              {
       
  1084              if(!aDetail.isEmpty())
       
  1085                 {
       
  1086                 aParam->iContactFields.append(aDetail);
       
  1087                 }
       
  1088              }
       
  1089       
       
  1090     }
       
  1091 //----------------------------------------------------------------------------
       
  1092 
       
  1093 //----------------------------------------------------------------------------
       
  1094