serviceproviders/sapi_contacts_vpbk/contactservice/src/singlecontact.cpp
changeset 22 fc9cf246af83
parent 19 989d2f495d90
child 24 f4292e0e20df
equal deleted inserted replaced
19:989d2f495d90 22:fc9cf246af83
    27 #include <MVPbkContactFieldTextData.h>					     
    27 #include <MVPbkContactFieldTextData.h>					     
    28 #include <MVPbkContactFieldData.h>
    28 #include <MVPbkContactFieldData.h>
    29 #include <MVPbkContactFieldBinaryData.h>
    29 #include <MVPbkContactFieldBinaryData.h>
    30 #include <MVPbkContactFieldDateTimeData.h>			      
    30 #include <MVPbkContactFieldDateTimeData.h>			      
    31 #include <MVPbkStoreContactField.h>
    31 #include <MVPbkStoreContactField.h>
       
    32 #include <MVPbkContactFieldUriData.h>
       
    33 _LIT8(KXSPID,"IMPP");
       
    34 _LIT(KXSPIDLabel,"IMPP");
    32 
    35 
    33 #include "singlecontact.h"
    36 #include "singlecontact.h"
    34 
    37 
    35 //NewL method for CSingleContact class. It holds MVPbkStoreContact variable as its member
    38 //NewL method for CSingleContact class. It holds MVPbkStoreContact variable as its member
    36 CSingleContact* CSingleContact::NewL(MVPbkStoreContact* aSingleContact, Ttype aIndicator)
    39 CSingleContact* CSingleContact::NewL(MVPbkStoreContact* aSingleContact, Ttype aIndicator)
    67 	ConvertContactToFieldListL(aSingleContact);
    70 	ConvertContactToFieldListL(aSingleContact);
    68     }
    71     }
    69 
    72 
    70 void CSingleContact::ConvertContactToFieldListL(MVPbkStoreContact* aSingleContact)
    73 void CSingleContact::ConvertContactToFieldListL(MVPbkStoreContact* aSingleContact)
    71     {
    74     {
       
    75     TBool XSPID = EFalse;
    72 
    76 
    73 	if(aSingleContact)
    77 	if(aSingleContact)
    74 	{
    78 	{
    75 	TInt fieldCount = aSingleContact->Fields().FieldCount();	
    79 	TInt fieldCount = aSingleContact->Fields().FieldCount();	
    76 	CSingleContactField* field = NULL;
    80 	CSingleContactField* field = NULL;
    77 	for(TInt fieldIndex = 0; fieldIndex < fieldCount ; fieldIndex++)
    81 	for(TInt fieldIndex = 0; fieldIndex < fieldCount ; fieldIndex++)
       
    82 		{
       
    83 		TPtrC8 fieldKey;
       
    84 		if(XSPID == EFalse)
       
    85 		    {
       
    86 		MVPbkStoreContactField& fieldval = aSingleContact->Fields().FieldAt(fieldIndex);
       
    87 		        
       
    88 		//Get the fieldKey of the field 
       
    89 		fieldKey.Set(CSearchFields::GetFieldKeyFromId(fieldval.BestMatchingFieldType()->FieldTypeResId()));
       
    90 		
       
    91 		    }
       
    92 		else
       
    93 		    {
       
    94 		    fieldIndex--;
       
    95 		    MVPbkStoreContactField& fieldval = aSingleContact->Fields().FieldAt(fieldIndex);
       
    96 		                    
       
    97 		            //Get the fieldKey of the field 
       
    98             fieldKey.Set(CSearchFields::GetFieldKeyFromId(fieldval.BestMatchingFieldType()->FieldTypeResId()));
       
    99             XSPID = EFalse;
       
   100 		    }
       
   101 		
       
   102 		if(fieldKey.Compare(KXSPID) == 0)
       
   103 		    {
       
   104 		    XSPID = ETrue;
       
   105 		    field = GetXSPIDFieldL(aSingleContact, fieldIndex);
       
   106 		    if(field != NULL)
       
   107 		        {
       
   108 		        iFields.Append(field);
       
   109 		        }
       
   110 		    }
       
   111 		else
    78 		{
   112 		{
    79 		field = NextFieldL(aSingleContact, fieldIndex);
   113 		field = NextFieldL(aSingleContact, fieldIndex);
    80 		if(field !=NULL)
   114 		if(field !=NULL)
    81 			{
   115 			{
    82 			iFields.AppendL(field);	
   116 			iFields.AppendL(field);	
    83 			}
   117 			}
    84 		}
   118 		}
    85 	}
   119 	}
       
   120 	}
    86 		delete aSingleContact;
   121 		delete aSingleContact;
    87 
   122 
       
   123     }
       
   124 CSingleContactField* CSingleContact::GetXSPIDFieldL(MVPbkStoreContact* aSingleContact, TInt& aIndex)
       
   125     {
       
   126     CSingleContactField* contactField = CSingleContactField::NewL();
       
   127     CleanupStack::PushL(contactField);
       
   128     TPtrC uri;
       
   129     if(iIndicator == EContacts)
       
   130             {
       
   131                 MVPbkStoreContactField& field = aSingleContact->Fields().FieldAt(aIndex);
       
   132                     
       
   133                 //Get the fieldKey of the field 
       
   134                 TPtrC8 fieldKeyXspid = CSearchFields::GetFieldKeyFromId(field.BestMatchingFieldType()->FieldTypeResId());
       
   135                 if(fieldKeyXspid.Compare(KNullDesC8) == 0)
       
   136                     {
       
   137                     CleanupStack::PopAndDestroy(contactField);      
       
   138                     return NULL;
       
   139                     }
       
   140                 
       
   141                 RPointerArray<HBufC> xspidArray;
       
   142                 
       
   143                 while(fieldKeyXspid.Compare(KXSPID) == 0)
       
   144                     {
       
   145                     TPtrC label(field.FieldLabel());
       
   146                 
       
   147                       TVPbkFieldStorageType storageType = field.FieldData().DataType();
       
   148                                    
       
   149                       if(EVPbkFieldStorageTypeUri == storageType )
       
   150                           {
       
   151                           //TDesC val = label.Alloc();
       
   152                           uri.Set((MVPbkContactFieldUriData::Cast(field.FieldData())).Uri());
       
   153                    /*       TBuf<10> bufVal1;
       
   154                           bufVal1.Copy(label);
       
   155                           TBuf<100> bufVal2;
       
   156                           bufVal2.Copy(uri);
       
   157                           bufVal1.Append(_L(":"));
       
   158                           bufVal1.Append(bufVal2);
       
   159                           HBufC* xspidVal = bufVal1.AllocLC();*/
       
   160                           xspidArray.AppendL(uri.AllocL());
       
   161                           }
       
   162                       aIndex++;
       
   163                       MVPbkStoreContactField& field = aSingleContact->Fields().FieldAt(aIndex);
       
   164                       
       
   165                       fieldKeyXspid.Set(CSearchFields::GetFieldKeyFromId(field.BestMatchingFieldType()->FieldTypeResId()));
       
   166                 
       
   167                     }
       
   168                 
       
   169                     contactField->SetUriFieldParamsL(KXSPID,KXSPIDLabel,xspidArray);
       
   170                     CleanupStack::Pop(contactField);    
       
   171                     return contactField;
       
   172             }
       
   173         return NULL;
    88     }
   174     }
    89 //Returns the Next field in the contact if any, otherwise returns NULL
   175 //Returns the Next field in the contact if any, otherwise returns NULL
    90 CSingleContactField* CSingleContact::NextFieldL(MVPbkStoreContact* aSingleContact, TInt aIndex)
   176 CSingleContactField* CSingleContact::NextFieldL(MVPbkStoreContact* aSingleContact, TInt aIndex)
    91 	{
   177 	{
    92     TPtrC text(KNullDesC);
   178     TPtrC text(KNullDesC);