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