phonebookengines/contactsmodel/src/CNTFIELD.CPP
changeset 0 e686773b3f54
child 24 0ba2181d7c28
equal deleted inserted replaced
-1:000000000000 0:e686773b3f54
       
     1 // Copyright (c) 1997-2009 Nokia Corporation and/or its subsidiary(-ies).
       
     2 // All rights reserved.
       
     3 // This component and the accompanying materials are made available
       
     4 // under the terms of "Eclipse Public License v1.0"
       
     5 // which accompanies this distribution, and is available
       
     6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     7 //
       
     8 // Initial Contributors:
       
     9 // Nokia Corporation - initial contribution.
       
    10 //
       
    11 // Contributors:
       
    12 //
       
    13 // Description:
       
    14 //
       
    15 
       
    16 #include <s32std.h>
       
    17 
       
    18 #include "CNTSTD.H"
       
    19 #include <cntdef.h>
       
    20 #include <cntfield.h>
       
    21 #include <cntfldst.h>
       
    22 
       
    23 #include <cntitem.h>
       
    24 #include <versit.h>
       
    25 #include "CNTPROF.H"
       
    26 #ifdef SYMBIAN_ENABLE_SPLIT_HEADERS
       
    27 #include "cntfieldheader.h"
       
    28 #include "cnthint.h"
       
    29 #include "cntfield_internal.h"
       
    30 #endif
       
    31 
       
    32 //
       
    33 // class TContactFieldAtts
       
    34 //
       
    35 const TUint32 KAttribsMask		    = 0xf0000fff;
       
    36 const TUint32 KExtendedAttribsMask	= 0x000ff000;
       
    37 const TUint32 KStorageTypeMask	    = 0x00f00000;
       
    38 
       
    39 const TUint32 KTypeBitShift		    = 20;
       
    40 const TUint32 KExtendedAttsBitShift = 12;
       
    41 
       
    42 /** Set contact field attributes.
       
    43 
       
    44 @param aAttribs contact field arributes to be set.
       
    45 @internalTechnology
       
    46 */
       
    47 void TContactFieldAtts::SetAttribs(TUint32 aAttribs)
       
    48 	{
       
    49 	iStorage |= aAttribs;
       
    50 	}
       
    51 	
       
    52 /** Set contact field extended arributes.
       
    53 
       
    54 @param aExtendedAttribs contact field extended arributes to be set.
       
    55 @internalTechnology
       
    56 */
       
    57 void TContactFieldAtts::SetExtendedAttribs(TUint32 aExtendedAttribs)
       
    58 	{
       
    59 	iStorage |= aExtendedAttribs << KExtendedAttsBitShift;
       
    60 	}
       
    61 
       
    62 /** Set storage type.
       
    63 
       
    64 @param aType storage type to set.
       
    65 @internalTechnology
       
    66 */
       
    67 void TContactFieldAtts::SetType(TStorageType aType)
       
    68 	{
       
    69 	iStorage |= aType << KTypeBitShift;
       
    70 	}
       
    71 
       
    72 /** Get contact field arributes.
       
    73 
       
    74 @return contact field arributes.
       
    75 @internalTechnology
       
    76 */
       
    77 TUint32 TContactFieldAtts::Attribs() const
       
    78 	{
       
    79 	return (iStorage & KAttribsMask);
       
    80 	}
       
    81 	
       
    82 /** Get contact field extended arributes.
       
    83 
       
    84 @return contact field extended arributes.
       
    85 @internalTechnology
       
    86 */
       
    87 TUint32 TContactFieldAtts::ExtendedAttribs() const
       
    88 	{
       
    89 	return (iStorage & KExtendedAttribsMask) >> KExtendedAttsBitShift;
       
    90 	}
       
    91 	
       
    92 /** Get contact field storage type.
       
    93 
       
    94 @return contact field storage type.
       
    95 @internalTechnology
       
    96 */
       
    97 TStorageType TContactFieldAtts::Type() const
       
    98 	{
       
    99 	return (iStorage & KStorageTypeMask) >> KTypeBitShift;
       
   100 	}
       
   101 	
       
   102 /** Internalize implementation.
       
   103 
       
   104 @internalTechnology
       
   105 */
       
   106 void TContactFieldAtts::InternalizeL(RReadStream& aStream)
       
   107 	{
       
   108 	iStorage=aStream.ReadUint32L();
       
   109 	}
       
   110 	
       
   111 /** Externalize implementation.
       
   112 
       
   113 @internalTechnology
       
   114 */
       
   115 void TContactFieldAtts::ExternalizeL(RWriteStream& aStream) const
       
   116 	{
       
   117 	aStream.WriteUint32L(iStorage);
       
   118 	}
       
   119 
       
   120 
       
   121 //
       
   122 // class CContentType
       
   123 //
       
   124    
       
   125 EXPORT_C CContentType::~CContentType()
       
   126 /** Frees all resources owned by the content type object, prior 
       
   127 to its destruction. */
       
   128     {
       
   129 	delete iFieldTypes;
       
   130 	}
       
   131       
       
   132 CContentType::CContentType()
       
   133     {
       
   134 	}
       
   135       
       
   136 CContentType::CContentType(TUid aMapping) : iMapping(aMapping)
       
   137 	{
       
   138 	}
       
   139 	
       
   140 /** Constructs a new content type based on a RReadStream.
       
   141 
       
   142 @param aStream RReadStream containing object to internalize.
       
   143 @return Pointer to the newly created CContentType. This is left on the cleanup stack. 
       
   144 @internalTechnology
       
   145 */
       
   146 CContentType* CContentType::NewLC(RReadStream& aStream)
       
   147 	{ // static
       
   148 	CContentType* type = NewL();
       
   149 	CleanupStack::PushL(type);
       
   150 	type->InternalizeL(aStream);
       
   151 	
       
   152 	return type;
       
   153 	}		
       
   154 
       
   155 EXPORT_C CContentType* CContentType::NewL()
       
   156 /** Allocates and constructs a new default CContentType.
       
   157 
       
   158 The object has no field types and the mapping is set to KNullUid
       
   159 
       
   160 @return Pointer to the newly created content type object. */
       
   161 	{
       
   162 	CContentType* self=new(ELeave) CContentType(KNullUid);
       
   163 	CleanupStack::PushL(self);
       
   164 	self->ConstructL();
       
   165 	CleanupStack::Pop();	// self
       
   166 	return(self);
       
   167 	}
       
   168 
       
   169 EXPORT_C CContentType* CContentType::NewL(TFieldType aFieldType,TUid aMapping)
       
   170 /** Allocates and constructs a new CContentType with a single field 
       
   171 type and a mapping.
       
   172 
       
   173 @param aFieldType The field type to add to the content type.
       
   174 @param aMapping The mapping.
       
   175 @return Pointer to the newly created content type object. */
       
   176 	{
       
   177 	CContentType* self=new(ELeave) CContentType(aMapping);
       
   178 	CleanupStack::PushL(self);
       
   179 	self->ConstructL();
       
   180 	self->AddFieldTypeL(aFieldType);
       
   181 	CleanupStack::Pop();	// self
       
   182 	return(self);
       
   183 	}
       
   184 
       
   185 EXPORT_C CContentType* CContentType::NewL(const CContentType &aContentType)
       
   186 /** Allocates and constructs a new CContentType based on another one.
       
   187 
       
   188 @param aContentType The CContentType on which to base the new one.
       
   189 @return Pointer to the newly created content type object. */
       
   190 	{ // static
       
   191 	CContentType* self=new(ELeave) CContentType;
       
   192 	CleanupStack::PushL(self);
       
   193 	self->ConstructL();
       
   194 	self->CloneL(aContentType);
       
   195 	CleanupStack::Pop();	// self
       
   196 	return self;
       
   197 	}
       
   198  
       
   199 void CContentType::ConstructL()
       
   200 	{
       
   201 	iFieldTypes=new(ELeave) CArrayFixFlat<TUid>(2);
       
   202 	}
       
   203 
       
   204 EXPORT_C void CContentType::AddFieldTypeL(TFieldType aFieldType)
       
   205 /** Appends a field type to the content type's list of field types.
       
   206 
       
   207 Note that certain combinations of field types are not valid and should not be
       
   208 used.
       
   209 
       
   210 @param aFieldType The field type to append to the list of field types. */
       
   211 	{
       
   212 	const TInt KMaxFieldTypes=15;
       
   213 	if (iFieldTypes->Count()==KMaxFieldTypes)
       
   214 		{
       
   215 		User::Leave(KErrOverflow);
       
   216 		}
       
   217     		
       
   218    	iFieldTypes->AppendL(aFieldType);
       
   219 	}
       
   220 
       
   221 EXPORT_C void CContentType::RemoveFieldType(TFieldType aFieldType)
       
   222 /** Removes a field type from the list of field types.
       
   223 
       
   224 @param aFieldType The field type to remove from the list of field types. */
       
   225 	{
       
   226 	for(TInt loop=0;loop<iFieldTypes->Count();loop++)
       
   227 		if ((*iFieldTypes)[loop]==aFieldType)
       
   228 			{
       
   229 			iFieldTypes->Delete(loop);
       
   230 			break;
       
   231 			}
       
   232 	}
       
   233 
       
   234 EXPORT_C void CContentType::SetMapping(TUid aMapping)
       
   235 /** Sets the vCard mapping.
       
   236 
       
   237 @param aMapping The new vCard mapping for the content type. */
       
   238 	{
       
   239 	iMapping=aMapping;
       
   240 	}
       
   241 
       
   242 void CContentType::CloneL(const CContentType &aContentType)
       
   243 	{
       
   244     iMapping=aContentType.iMapping;
       
   245 	if (aContentType.iFieldTypes)
       
   246 		for(TInt loop=0;loop<aContentType.iFieldTypes->Count();loop++)
       
   247 			AddFieldTypeL((*aContentType.iFieldTypes)[loop]);
       
   248 	}
       
   249 
       
   250 EXPORT_C TInt CContentType::FieldTypeCount() const
       
   251 /** Gets the number of field types in the content type's list of field types.
       
   252 
       
   253 @return The number of field types in the content type. */
       
   254 	{
       
   255 	return(iFieldTypes->Count());
       
   256 	}
       
   257 
       
   258 EXPORT_C TFieldType CContentType::FieldType(TInt aIndex) const
       
   259 /** Gets the indexed field type.
       
   260 
       
   261 @param aIndex Index into the list of field types. The position is relative 
       
   262 to zero; i.e. zero implies the first element in the array. This value must 
       
   263 be non-negative and less than the number of objects currently within the array 
       
   264 otherwise the operator raises a panic.
       
   265 @return The indexed field type. */
       
   266 	{
       
   267 	__ASSERT_DEBUG(aIndex<iFieldTypes->Count(),Panic(ECntPanicFieldTypeIndex));
       
   268 	return((*iFieldTypes)[aIndex]);
       
   269 	}
       
   270 
       
   271 EXPORT_C TUid CContentType::Mapping() const
       
   272 /** Gets the vCard mapping.
       
   273 
       
   274 @return The vCard mapping. */
       
   275 	{
       
   276 	return(iMapping);
       
   277 	}
       
   278 
       
   279 EXPORT_C TBool CContentType::ContainsFieldType(TFieldType aFieldType) const
       
   280 /** Tests whether the content type object contains the specified field type UID 
       
   281 either as the mapping value or in its list of field types.
       
   282 
       
   283 @param aFieldType The field type of interest.
       
   284 @return ETrue if the CContentType contains the specified field type. EFalse 
       
   285 if not. */
       
   286 	{
       
   287 	if (iMapping==aFieldType)
       
   288 		return(ETrue);
       
   289 	for(TInt loop=0;loop<iFieldTypes->Count();loop++)
       
   290 		if ((*iFieldTypes)[loop]==aFieldType)
       
   291 			return(ETrue);
       
   292 	return(EFalse);
       
   293 	}
       
   294 
       
   295 void CContentType::InternalizeAdditionalUidsL(TInt aCount,RReadStream& aStream)
       
   296 	{
       
   297 	for (TInt ii=0;ii<aCount;ii++) 
       
   298 		iFieldTypes->AppendL(TUid::Uid(aStream.ReadInt32L()));
       
   299 	}
       
   300 
       
   301 EXPORT_C TBool CContentType::SupportsMultipleLines() const
       
   302 /** Tests whether the content type supports multiple lines of text. If the content 
       
   303 type object contains a field type which supports this, either in its list 
       
   304 of field types, or as its mapping, the function returns ETrue. Examples of 
       
   305 such field types are address fields (type KUidContactFieldAddress) and note 
       
   306 fields (type KUidContactFieldNote).
       
   307 
       
   308 @return ETrue if the CContentType supports multiple lines of text. EFalse 
       
   309 if not. */
       
   310 	{
       
   311 	return(ContainsFieldType(KUidContactFieldAddress) || ContainsFieldType(KUidContactFieldNote));
       
   312 	}
       
   313 
       
   314 EXPORT_C TBool CContentType::operator==(const CContentType &aType) const
       
   315 /** Compares two content type objects for equality. 
       
   316 Two content type objects are equal according to this method if all following 
       
   317 conditions are met:
       
   318 - vCard property mapping matches
       
   319 - same number of field types
       
   320 - main field type matches
       
   321 - additional field types and vCard property parameter mappings match
       
   322  
       
   323 @param aType The content type to compare with this CContentType.
       
   324 +@return ETrue if aType is equal with current content type. */
       
   325 	{
       
   326 	// Compare vCard property mapping.
       
   327 	if (Mapping() != aType.Mapping())
       
   328 		{
       
   329 		return EFalse;
       
   330 		}
       
   331 	
       
   332 	// Compare field type counts.
       
   333 	const TInt typeCount = FieldTypeCount();
       
   334 	if (typeCount != aType.FieldTypeCount())
       
   335 		{
       
   336 		return EFalse;
       
   337 		}
       
   338 	if (typeCount <= 0)
       
   339 		{
       
   340 		// Nothing more to compare.
       
   341 		return ETrue;
       
   342 		}
       
   343 	
       
   344 	// Compare main field type.
       
   345 	if (FieldType(0) != aType.FieldType(0))
       
   346 		{
       
   347 		return EFalse;
       
   348 		}
       
   349 	
       
   350 	// Compare additional field types and vCard property parameter mappings.
       
   351 	for (TInt lhsIndex = 1; lhsIndex < typeCount; ++lhsIndex)
       
   352 		{
       
   353 		TInt rhsIndex = 1;
       
   354 		for (rhsIndex = 1; rhsIndex < typeCount; ++rhsIndex)
       
   355 			{
       
   356 			if (FieldType(lhsIndex) == aType.FieldType(rhsIndex))
       
   357 			    break;
       
   358 			}
       
   359 		if (rhsIndex == typeCount)
       
   360 			{
       
   361 			// No match found.
       
   362 			return EFalse;
       
   363 			}
       
   364 		}
       
   365 	
       
   366 	return ETrue;
       
   367 	}
       
   368 
       
   369 EXPORT_C TBool CContentType::IsEqual(const CContentType &aType) const
       
   370 /** Compares two content type objects for equality.
       
   371 Two content type objects are equal according to this method if all following 
       
   372 conditions are met:
       
   373 - vCard property mapping matches
       
   374 - same number of field types
       
   375 - main field type matches
       
   376 - additional field types and vCard property parameter mappings match
       
   377  
       
   378 @param aType The content type to compare with this CContentType.
       
   379 @return ETrue if aType is equal with current content type. */
       
   380 	{
       
   381 	// Compare vCard property mapping.
       
   382 	if (iMapping!=aType.iMapping)
       
   383 		{
       
   384 		return(EFalse);	
       
   385 		}
       
   386 	
       
   387 	// Compare field type counts.
       
   388 	const TInt typeCount = aType.FieldTypeCount();
       
   389 	if (FieldTypeCount()!= typeCount)
       
   390 		{
       
   391 		return(EFalse);	
       
   392 		}
       
   393 		
       
   394     if (typeCount <= 0)
       
   395         {
       
   396         // Nothing more to compare.
       
   397         return ETrue;
       
   398         }
       
   399 			
       
   400     // Compare main field type.
       
   401     if (FieldType(0) != aType.FieldType(0))
       
   402         {
       
   403         return EFalse;
       
   404         }
       
   405 
       
   406     // Compare additional field types and vCard property parameter mappings.
       
   407     for (TInt leftIndex = 1; leftIndex < typeCount; ++leftIndex)
       
   408         {
       
   409         TUint rightIndex = 1;
       
   410         for (rightIndex = 1; rightIndex < typeCount; ++rightIndex)
       
   411             {
       
   412             if (FieldType(leftIndex) == aType.FieldType(rightIndex))
       
   413                 break;
       
   414             }
       
   415         if (rightIndex == typeCount)
       
   416             {
       
   417             // No match found.
       
   418             return EFalse;
       
   419             }
       
   420         }
       
   421 
       
   422     return ETrue;
       
   423    	}
       
   424   	
       
   425 void CContentType::Reset()
       
   426 	{
       
   427 	iMapping=TUid::Uid(0);
       
   428 	iFieldTypes->Reset();
       
   429 	}
       
   430 
       
   431 
       
   432 /*
       
   433  * Determine if content types are suitable to match for synchronization purpose. 
       
   434  * Some properties are subject to specific processing depending of the <code>CContentType</code> Mapping. 
       
   435  * Notably: VOICE, PREF, VoiceDial and SpeedDial. 
       
   436  * VOICE is a a default property parameter for all TEL properties.
       
   437  *
       
   438  * @param		"const CContentType& aType"
       
   439  *				The content type to compare with this
       
   440  *				<code>CContentType</code>. Beware, to do a proper comparison,
       
   441  *				the <code>aType</code> parameter must not contains VoiceDial or SpeedDial properties.
       
   442  *				Otherwise the fields will not match.				  
       
   443  *
       
   444  * @return 		"TBool"
       
   445  *				<code>ETrue</code> if <code>aType</code> match this content type.
       
   446  *				Field types do not need to be in the same order in the 
       
   447  *				list of field types for a match to be made.
       
   448  */
       
   449 EXPORT_C TBool CContentType::IsEqualForSyncUpdate(const CContentType& aType) const
       
   450 /** Tests whether the content types are suitable to match for synchronisation purpose. 
       
   451 
       
   452 @param aType The content type to compare with this CContentType.
       
   453 @return ETrue if aType is an identical content type
       
   454  */
       
   455 	{
       
   456 	if (iMapping!=aType.iMapping)
       
   457 		return(EFalse);	
       
   458 
       
   459 	switch (iMapping.iUid)
       
   460 		{
       
   461 	case KIntContactFieldVCardMapTEL:
       
   462 		{
       
   463 		TInt countModifier=0;
       
   464 		TInt loop=0;
       
   465 
       
   466 		if (aType.ContainsFieldType(KUidContactFieldVCardMapVOICE))
       
   467 			{
       
   468 			++countModifier;
       
   469 			}
       
   470 
       
   471 		if (aType.ContainsFieldType(KUidContactFieldVCardMapPREF))
       
   472 			{
       
   473 			++countModifier;
       
   474 			}
       
   475 		
       
   476 		if (ContainsFieldType(KUidContactFieldVCardMapVOICE))
       
   477 			{
       
   478 			--countModifier;
       
   479 			}
       
   480 
       
   481 		if (ContainsFieldType(KUidContactFieldVCardMapPREF))
       
   482 			{
       
   483 			--countModifier;
       
   484 			}
       
   485 
       
   486 		if (ContainsFieldType(KUidContactsVoiceDialField))
       
   487 			{
       
   488 			--countModifier;
       
   489 			}
       
   490 
       
   491 		//look for speed dial property only in db field
       
   492 		for(loop=0;loop<iFieldTypes->Count();loop++)
       
   493 			{
       
   494 			TInt uid = (*iFieldTypes)[loop].iUid;
       
   495 			if (uid >= KUidSpeedDialOneValue && uid <= KUidSpeedDialNineValue)
       
   496 				{
       
   497 				--countModifier;
       
   498 				break; //only one speed dial property allowed for a field
       
   499 				}
       
   500 			}
       
   501 	
       
   502 		//now check for field count	
       
   503 		if ((FieldTypeCount()+countModifier)!=aType.FieldTypeCount())
       
   504 			{
       
   505 			return(EFalse);
       
   506 			}
       
   507 				
       
   508 		//Check that all type from the imported field match a type in this field but VOICE and PREF
       
   509 		for(loop=0;loop<aType.FieldTypeCount();loop++)
       
   510 			{
       
   511 			if (!ContainsFieldType(aType.FieldType(loop)))
       
   512 				{
       
   513 				if (aType.FieldType(loop).iUid==KIntContactFieldVCardMapVOICE || aType.FieldType(loop).iUid==KIntContactFieldVCardMapPREF)
       
   514 					{
       
   515 					continue;
       
   516 					}
       
   517 				return(EFalse);
       
   518 				}
       
   519 			}
       
   520 		return(ETrue);
       
   521 		}
       
   522 
       
   523 	case KIntContactFieldVCardMapEMAILINTERNET:
       
   524 		{
       
   525 		TInt countModifier=0;		
       
   526 
       
   527 		if (aType.ContainsFieldType(KUidContactFieldVCardMapPREF))
       
   528 			{
       
   529 			++countModifier;
       
   530 			}
       
   531 		
       
   532 		if (ContainsFieldType(KUidContactFieldVCardMapPREF))
       
   533 			{
       
   534 			--countModifier;
       
   535 			}
       
   536 	
       
   537 		//now check for field count	
       
   538 		if ((FieldTypeCount()+countModifier)!=aType.FieldTypeCount())
       
   539 			{
       
   540 			return(EFalse);
       
   541 			}
       
   542 				
       
   543 		//Check that all type from the imported field match a type in this field but PREF
       
   544 		for(TInt loop=0;loop<aType.FieldTypeCount();loop++)
       
   545 			{
       
   546 			if (!ContainsFieldType(aType.FieldType(loop)))
       
   547 				{
       
   548 				if (aType.FieldType(loop).iUid==KIntContactFieldVCardMapPREF)
       
   549 					{
       
   550 					continue;
       
   551 					}
       
   552 				return(EFalse);
       
   553 				}
       
   554 			}
       
   555 		return(ETrue);
       
   556 		}
       
   557 	
       
   558 	case KIntContactFieldVCardMapAGENT:
       
   559 		{
       
   560 		return(ETrue);
       
   561 		}	
       
   562 
       
   563 	default:
       
   564 		return *this==aType;
       
   565 		}
       
   566 	}
       
   567 	
       
   568 void CContentType::InternalizeL(RReadStream& aStream)
       
   569 /** Internalises a CContentType object from a read stream. 
       
   570 @param aStream Stream from which the object should be internalised. */
       
   571 	{
       
   572     // TUid iMapping;
       
   573 	iMapping.iUid = aStream.ReadInt32L();
       
   574 	
       
   575 	// CArrayFix<TUid>* iFieldTypes;
       
   576 	const TInt count=aStream.ReadInt32L();
       
   577 
       
   578 	// Allocated in constructor
       
   579 	TUid tempID;
       
   580 	for(TInt index=0; index<count; ++index)
       
   581 		{
       
   582 		
       
   583 		aStream>>tempID;		
       
   584 		iFieldTypes->AppendL(tempID);
       
   585 		}
       
   586 	}
       
   587 
       
   588 void CContentType::ExternalizeL(RWriteStream& aStream) const 
       
   589 /** Externalises a CContentType object to a write stream.
       
   590 @param aStream Stream to which the object should be externalised. */
       
   591 	{
       
   592 	aStream.WriteInt32L(iMapping.iUid);
       
   593 	
       
   594 	const TInt count = iFieldTypes->Count();
       
   595 	aStream.WriteInt32L(count);	
       
   596 	for(TInt index=0; index<count; ++index)
       
   597 		{
       
   598 		aStream<<iFieldTypes->At(index);
       
   599 		}
       
   600 	}		
       
   601 
       
   602 
       
   603 //
       
   604 // class CContactItemField
       
   605 //
       
   606 
       
   607 EXPORT_C CContactItemField* CContactItemField::NewLC()
       
   608 /** Allocates and constructs a new default contact item field. 
       
   609 
       
   610 The field's storage type, content type and label are unspecified. 
       
   611 The ESynchronize attribute is set.
       
   612 
       
   613 @return Pointer to the newly created contact item field. */
       
   614 	{
       
   615     CContactItemField* self=new(ELeave) CContactItemField;
       
   616     CleanupStack::PushL(self);
       
   617 	self->iContentType=CContentType::NewL();
       
   618     return self;
       
   619 	}
       
   620 
       
   621 EXPORT_C CContactItemField* CContactItemField::NewL(TStorageType aType)
       
   622 /** Allocates and constructs a contact item field with a storage type. 
       
   623 
       
   624 The field's label and content type are unspecified.
       
   625 
       
   626 @param aType The field's storage type.
       
   627 @return Pointer to the newly created contact item field. */
       
   628 	{
       
   629     CContactItemField* self=CContactItemField::NewLC(aType);
       
   630     CleanupStack::Pop(); // self
       
   631     return self;
       
   632 	}
       
   633 
       
   634 EXPORT_C CContactItemField* CContactItemField::NewLC(TStorageType aType)
       
   635 /** Allocates and constructs a contact item field with a storage type. 
       
   636 
       
   637 The field's label and content type are unspecified.
       
   638 
       
   639 @param aType The field's storage type.
       
   640 @return Pointer to the newly created contact item field. This is left on 
       
   641 the cleanup stack. */
       
   642 	{
       
   643     CContactItemField* self=new(ELeave) CContactItemField(aType);
       
   644     CleanupStack::PushL(self);
       
   645     self->ConstructStorageL();
       
   646 	self->iContentType=CContentType::NewL();
       
   647     return self;
       
   648 	}
       
   649 
       
   650 EXPORT_C CContactItemField* CContactItemField::NewL(TStorageType aType, TFieldType aFieldType)
       
   651 /** Allocates and constructs a contact item field with a storage type 
       
   652 and a field type.
       
   653 
       
   654 The field's content type is initialised with the field type, 
       
   655 and its vCard mapping is set by default to KNullUid. The field's label is 
       
   656 unspecified.
       
   657 
       
   658 @param aType The field's storage type.
       
   659 @param aFieldType The field type as defined in cntdef.h.
       
   660 @return Pointer to the newly created contact item field. */
       
   661     { // static
       
   662     CContactItemField* self=CContactItemField::NewLC(aType,aFieldType);
       
   663     CleanupStack::Pop(); // self
       
   664     return self;
       
   665     }
       
   666 
       
   667 EXPORT_C CContactItemField* CContactItemField::NewLC(TStorageType aType, TFieldType aFieldType)
       
   668 /** Allocates and constructs a contact item field with a storage type 
       
   669 and a field type.
       
   670 
       
   671 The field's content type is initialised with the field type, 
       
   672 and its vCard mapping is set by default to KNullUid. The field's label is 
       
   673 unspecified.
       
   674 
       
   675 @param aType The field's storage type.
       
   676 @param aFieldType The field type as defined in cntdef.h.
       
   677 @return Pointer to the newly created contact item field. This is left on 
       
   678 the cleanup stack. */
       
   679     { // static
       
   680     CContactItemField* self=new(ELeave) CContactItemField(aType);
       
   681     CleanupStack::PushL(self);
       
   682     self->ConstructStorageL();
       
   683 	self->iContentType=CContentType::NewL(aFieldType);
       
   684     return self;
       
   685     }
       
   686 
       
   687 EXPORT_C CContactItemField* CContactItemField::NewL(const CContactItemField &aField)
       
   688 /** Allocates and constructs a contact item field based on another one.
       
   689 
       
   690 All details (content type, storage type, attributes and label) are copied 
       
   691 from the specified field.
       
   692 
       
   693 @param aField The contact field to copy.
       
   694 @return Pointer to the newly created contact item field. */
       
   695 	{ // static
       
   696 	CContactItemField* self=CContactItemField::NewLC(aField);
       
   697 	CleanupStack::Pop(); // self
       
   698 	return self;
       
   699 	}
       
   700 
       
   701 EXPORT_C CContactItemField* CContactItemField::NewLC(const CContactItemField &aField)
       
   702 /** Allocates and constructs a contact item field based on another one.
       
   703 
       
   704 All details (content type, storage type, attributes and label) are copied 
       
   705 from the specified field.
       
   706 
       
   707 @param aField The contact field to copy.
       
   708 @return Pointer to the newly created contact item field. This is left on 
       
   709 the cleanup stack. */
       
   710 	{ // static
       
   711 	CContactItemField* self=new(ELeave) CContactItemField(aField.StorageType());
       
   712 	CleanupStack::PushL(self);
       
   713 	self->ConstructStorageL();
       
   714 	self->CloneL(aField);
       
   715 	return self;
       
   716 	}
       
   717  
       
   718 EXPORT_C CContactItemField* CContactItemField::NewL(TStorageType aType, const CContentType &aContentType)
       
   719 /** Allocates and constructs a contact item field with a content type 
       
   720 and a storage type. 
       
   721 
       
   722 The field's label is unspecified.
       
   723 
       
   724 @param aType The field's storage type.
       
   725 @param aContentType The field's content type. 
       
   726 @return Pointer to the newly created contact item field. */
       
   727 	{ // static
       
   728 	CContactItemField* self=CContactItemField::NewLC(aType,aContentType);
       
   729 	CleanupStack::Pop(); // self
       
   730 	return self;
       
   731 	}
       
   732 
       
   733 EXPORT_C CContactItemField* CContactItemField::NewLC(TStorageType aType, const CContentType &aContentType)
       
   734 /** Allocates and constructs a contact item field with a content type 
       
   735 and a storage type. 
       
   736 
       
   737 The field's label is unspecified.
       
   738 
       
   739 @param aType The field's storage type.
       
   740 @param aContentType The field's content type. 
       
   741 @return Pointer to the newly created contact item field. This is left on 
       
   742 the cleanup stack. */
       
   743 	{ // static
       
   744 	CContactItemField* self=new(ELeave) CContactItemField(aType);
       
   745 	CleanupStack::PushL(self);
       
   746 	self->ConstructStorageL();
       
   747 	self->iContentType=CContentType::NewL(aContentType);
       
   748 	return self;
       
   749 	}
       
   750  
       
   751 CContactItemField::CContactItemField(TStorageType aType)
       
   752 	: iStorageType(aType), iAttributes(ESynchronize|EOverRidesLabel|ELabelUnspecified),iTemplateFieldId(KNullFieldId)
       
   753     {}
       
   754 
       
   755 CContactItemField::CContactItemField()
       
   756 	: iAttributes(ESynchronize),iTemplateFieldId(KNullFieldId)
       
   757     {}
       
   758 
       
   759 void CContactItemField::ConstructStorageL()
       
   760     {
       
   761 	__ASSERT_DEBUG(iStorage==NULL,Panic(ECntPanicStorageAlreadyAllocated));
       
   762     switch (iStorageType)
       
   763         {
       
   764     case KStorageTypeText:
       
   765         iStorage=new(ELeave) CContactTextField;
       
   766         break;
       
   767     case KStorageTypeStore:
       
   768         iStorage=new(ELeave) CContactStoreField;
       
   769         break;
       
   770     case KStorageTypeDateTime:
       
   771         iStorage=new(ELeave) CContactDateField;
       
   772         break;
       
   773     case KStorageTypeContactItemId:
       
   774         iStorage=new(ELeave) CContactAgentField;
       
   775         break;
       
   776     default:
       
   777     	User::Leave(KErrNotSupported);
       
   778     	break;
       
   779         }
       
   780     }
       
   781 
       
   782 void CContactItemField::CloneL(const CContactItemField &aField)
       
   783 	{
       
   784 	iContentType=CContentType::NewL(aField.ContentType());
       
   785 	if (aField.iLabel)
       
   786 		iLabel=aField.iLabel->AllocL();
       
   787 	iAttributes=aField.iAttributes;
       
   788 	// copy extended attributes as well
       
   789 	iExtendedAttributes=aField.iExtendedAttributes; 
       
   790 	iTemplateFieldId=aField.iTemplateFieldId;
       
   791 	CopyStorageL(aField);
       
   792 	}
       
   793 
       
   794 void CContactItemField::CopyStorageL(const CContactItemField &aField)
       
   795 	{
       
   796 	switch(aField.StorageType())
       
   797 		{
       
   798 		case KStorageTypeText:
       
   799 			TextStorage()->SetTextL(aField.TextStorage()->Text());
       
   800 			break;
       
   801 		case KStorageTypeDateTime:
       
   802 			DateTimeStorage()->SetTime(aField.DateTimeStorage()->Time());
       
   803 			break;
       
   804 		case KStorageTypeContactItemId:
       
   805 			AgentStorage()->SetAgentId(aField.AgentStorage()->Value());
       
   806 			break;
       
   807 		case KStorageTypeStore:
       
   808 			if (aField.StoreStorage()->Thing())
       
   809 				{
       
   810 				StoreStorage()->SetThingL(*aField.StoreStorage()->Thing());
       
   811 				}
       
   812 			break;
       
   813 		}
       
   814 	}
       
   815 
       
   816 EXPORT_C CContactItemField::~CContactItemField()
       
   817 /** Frees all resources owned by the field (the label, the stored 
       
   818 data and the content type), prior to its destruction. */
       
   819     {
       
   820     delete iLabel;
       
   821     delete iStorage;
       
   822 	delete iContentType;
       
   823     }
       
   824 
       
   825 /**
       
   826 @internalTechnology
       
   827   */
       
   828 EXPORT_C void CContactItemField::Reset()
       
   829 	{
       
   830     delete iLabel;
       
   831 	iLabel=NULL;
       
   832     delete iStorage;
       
   833 	iStorage=NULL;
       
   834 	iContentType->Reset();
       
   835 	iStorageType=0;
       
   836 	iId=KNullFieldId	;
       
   837 	iAttributes=ESynchronize;
       
   838 	iExtendedAttributes=0;
       
   839 	iTemplateFieldId=KNullFieldId;
       
   840 	}
       
   841 
       
   842 void CContactItemField::MapHintsToFieldTypesL(THint aHint)
       
   843 	{
       
   844 	if (aHint.IsPhone())
       
   845 		AddFieldTypeL(KUidContactFieldPhoneNumber);
       
   846 	if (aHint.IsMsg())
       
   847 		AddFieldTypeL(KUidContactFieldMsg);
       
   848 	if (aHint.IsCompanyName())
       
   849 		AddFieldTypeL(KUidContactFieldCompanyName);
       
   850 	if (aHint.IsFamilyName())
       
   851 		AddFieldTypeL(KUidContactFieldFamilyName);
       
   852 	if (aHint.IsGivenName())
       
   853 		AddFieldTypeL(KUidContactFieldGivenName);
       
   854 	if (aHint.IsCompanyNamePronunciation())
       
   855 		AddFieldTypeL(KUidContactFieldCompanyNamePronunciation);
       
   856 	if (aHint.IsFamilyNamePronunciation())
       
   857 		AddFieldTypeL(KUidContactFieldFamilyNamePronunciation);
       
   858 	if (aHint.IsGivenNamePronunciation())
       
   859 		AddFieldTypeL(KUidContactFieldGivenNamePronunciation);
       
   860 	if (aHint.IsAddress())
       
   861 		AddFieldTypeL(KUidContactFieldAddress);
       
   862 	if (aHint.IsAdditionalName())
       
   863 		AddFieldTypeL(KUidContactFieldAdditionalName);
       
   864 	if (aHint.IsSuffixName())
       
   865 		AddFieldTypeL(KUidContactFieldSuffixName);
       
   866 	if (aHint.IsPrefixName())
       
   867 		AddFieldTypeL(KUidContactFieldPrefixName);
       
   868 	if (aHint.IsEmail())
       
   869 		AddFieldTypeL(KUidContactFieldEMail);
       
   870 	if (aHint.IsStorageInline())
       
   871 		AddFieldTypeL(KUidContactStorageInline);
       
   872 	}
       
   873 
       
   874 TBool CContactItemField::AddFieldToHint(TFieldType aFieldType, CContactItemField::THint &aHint) const 
       
   875   	{
       
   876 	TBool matchedHint = ETrue;
       
   877 	switch(aFieldType.iUid)
       
   878 		{
       
   879 		case KUidContactFieldAddressValue:
       
   880 			aHint.SetIsAddress();
       
   881 			break;
       
   882 		case KUidContactFieldCompanyNameValue:
       
   883 			aHint.SetIsCompanyName();
       
   884 			break;
       
   885 		case KUidContactFieldPhoneNumberValue:
       
   886 			aHint.SetIsPhone();
       
   887 			break;
       
   888 		case KUidContactFieldGivenNameValue:
       
   889 			aHint.SetIsGivenName();
       
   890 			break;
       
   891 		case KUidContactFieldFamilyNameValue:
       
   892 			aHint.SetIsFamilyName();
       
   893 			break;
       
   894 		case KUidContactFieldCompanyNamePronunciationValue:
       
   895 			aHint.SetIsCompanyNamePronunciation();
       
   896 			break;
       
   897 		case KUidContactFieldGivenNamePronunciationValue:
       
   898 			aHint.SetIsGivenNamePronunciation();
       
   899 			break;
       
   900 		case KUidContactFieldFamilyNamePronunciationValue:
       
   901 			aHint.SetIsFamilyNamePronunciation();
       
   902 			break;
       
   903 		case KUidContactFieldAdditionalNameValue:
       
   904 			aHint.SetIsAdditionalName();
       
   905 			break;
       
   906 		case KUidContactFieldSuffixNameValue:
       
   907 			aHint.SetIsSuffixName();
       
   908 			break;
       
   909 		case KUidContactFieldPrefixNameValue:
       
   910 			aHint.SetIsPrefixName();
       
   911 			break;
       
   912 		case KUidContactFieldEMailValue:
       
   913 			aHint.SetIsEmail();
       
   914 			break;
       
   915 		case KUidContactFieldMsgValue:
       
   916 			aHint.SetIsMsg();
       
   917 			break;
       
   918 		case KUidContactFieldStorageInlineValue:
       
   919 			aHint.SetStorageIsInline();
       
   920 			break;
       
   921 		default:
       
   922 			matchedHint=EFalse;
       
   923 			break;
       
   924 		}
       
   925 	return(matchedHint);
       
   926 	}
       
   927 
       
   928 
       
   929 /**
       
   930 Encode contact field data into stream store.
       
   931 
       
   932 @param aTextStream the text blob stream to export text data.
       
   933 @param aBlobStore the binary blob stream to export binary data.
       
   934 @param aTextFieldIndex the index of text field stored in the storage
       
   935 
       
   936 @return field header which is to be stored into header blob. 
       
   937 @internalTechnology 
       
   938 */
       
   939 TFieldHeader CContactItemField::StoreL(RWriteStream& aTextStream, CStreamStore& aBlobStore, TInt aTextFieldIndex)
       
   940 	{
       
   941 	TStreamId streamId = KNullStreamIdValue;
       
   942 	if (iStorageType == KStorageTypeText)
       
   943 		{
       
   944 		STATIC_CAST(CContactTextField*,iStorage)->ExternalizeL(aTextStream, ETrue, aTextFieldIndex);
       
   945 		}
       
   946 	else
       
   947 	    {
       
   948 		streamId = iStorage->StoreL(aBlobStore);
       
   949 	    }
       
   950 	
       
   951 	TContactFieldAtts atts;
       
   952 	/* sets all attributes of the field:- hidden private etc.. + type (text etc..)
       
   953 	   into TContactFieldAtts which is then stored ahead of the field data */
       
   954 	atts.SetAttribs(iAttributes);
       
   955 	atts.SetExtendedAttribs(iExtendedAttributes);
       
   956 	atts.SetType(iStorageType);
       
   957     return TFieldHeader(atts, iId, streamId);
       
   958 	}
       
   959 
       
   960 
       
   961 /**
       
   962 Decode given blob header stream into contact field relevent data.
       
   963 
       
   964 @param aStream reference to the blob header stream to be decoded.
       
   965 @param aSystemTemplateFields cached template fields.
       
   966 
       
   967 @return the stream id of content data stored in data store 
       
   968 @internalTechnology 
       
   969 */
       
   970 EXPORT_C TStreamId CContactItemField::RestoreFieldTypesL(RReadStream &aStream, const CContactItemFieldSet *aSystemTemplateFields)
       
   971   	{
       
   972 	THint hint;
       
   973 	TStreamId nestedId(KNullStreamIdValue);
       
   974 	TContactFieldAtts fieldAtts;
       
   975 
       
   976 	aStream >> fieldAtts;
       
   977 	
       
   978 	iAttributes = fieldAtts.Attribs();
       
   979 	iExtendedAttributes = fieldAtts.ExtendedAttribs();
       
   980 	iStorageType = fieldAtts.Type();
       
   981 	
       
   982     if(fieldAtts.Type() != KStorageTypeText)
       
   983         {
       
   984    	    //Only import stream id when the storage type is not text
       
   985         aStream >> nestedId;
       
   986         }
       
   987         
       
   988     iId = aStream.ReadUint32L();
       
   989     iTemplateFieldId = aStream.ReadUint32L();
       
   990     
       
   991 	const CContactItemField* templateField = NULL;
       
   992 	
       
   993 	if (UsesTemplateTypes() || !OverRidesLabel())
       
   994 		{
       
   995 		if (aSystemTemplateFields == NULL)
       
   996 		    {
       
   997 			User::Leave(KErrCorrupt);
       
   998 		    }
       
   999 		templateField = aSystemTemplateFields->FindById(iTemplateFieldId);
       
  1000 		}
       
  1001 		
       
  1002 	if (templateField)
       
  1003 		{
       
  1004 		iAttributes |= (templateField->iAttributes&ETemplateMask);
       
  1005 		}
       
  1006 		
       
  1007 	if (UsesTemplateTypes() && templateField)
       
  1008 		{
       
  1009 		CContentType* newContent=CContentType::NewL(templateField->ContentType());
       
  1010 		delete iContentType;
       
  1011 		iContentType = NULL;
       
  1012 		iContentType=newContent;
       
  1013 		}
       
  1014 	else
       
  1015 		{
       
  1016   		hint = aStream.ReadInt32L();
       
  1017   		
       
  1018  		if(hint.HasVCardMappingUid())
       
  1019  		    {
       
  1020         	iContentType->SetMapping(TUid::Uid(aStream.ReadInt32L()));
       
  1021  		    }
       
  1022  		    
       
  1023 		MapHintsToFieldTypesL(hint);
       
  1024  		iContentType->InternalizeAdditionalUidsL(hint.AdditionalUidsNum(),aStream);
       
  1025 		}
       
  1026 		
       
  1027 	ConstructStorageL();
       
  1028 	
       
  1029 	if (OverRidesLabel())
       
  1030 		{
       
  1031 		const TInt length = aStream.ReadInt32L();
       
  1032 		if (length)
       
  1033 		    {
       
  1034 			iLabel = HBufC::NewL(aStream,length);
       
  1035 		    }
       
  1036 		}
       
  1037 	else if(templateField)
       
  1038 	    {
       
  1039 		iLabel = templateField->Label().AllocL();
       
  1040 	    }
       
  1041 		    
       
  1042 	return nestedId;
       
  1043     }
       
  1044 	
       
  1045 
       
  1046 void CContactItemField::RestoreDataL(CStreamStore& aStore,TStreamId aId)
       
  1047     {
       
  1048     RStoreReadStream stream;
       
  1049     stream.OpenLC(aStore,aId);
       
  1050 	iStorage->RestoreL(aStore,stream);
       
  1051 	CleanupStack::PopAndDestroy(); // stream
       
  1052 	}
       
  1053 
       
  1054 /**
       
  1055 @internalTechnology 
       
  1056 */
       
  1057 EXPORT_C void CContactItemField::RestoreTextL(HBufC *aTextStream,TInt aTextFieldIndex)
       
  1058     {
       
  1059 	__ASSERT_ALWAYS(iStorageType==KStorageTypeText,Panic(ECntPanicInvalidStorageType));
       
  1060     STATIC_CAST(CContactTextField*,iStorage)->InternalizeL(aTextStream,aTextFieldIndex);
       
  1061 	}
       
  1062 
       
  1063 /**
       
  1064 @internalTechnology 
       
  1065 */
       
  1066 EXPORT_C TBool CContactItemField::RestoreIfMatchL(RReadStream& aStream,const CContactItemFieldDef *aFieldDef, const CContactItemFieldSet *aSystemTemplateFields,HBufC *aTextStream,TInt aTextIndex)
       
  1067 	{
       
  1068 	TStreamId nestedId;
       
  1069 	nestedId=RestoreFieldTypesL(aStream,aSystemTemplateFields);
       
  1070 	TBool match=EFalse;
       
  1071 	if (aFieldDef==NULL)
       
  1072 		match=ETrue;
       
  1073 	else
       
  1074 		{
       
  1075 		for(TInt loop=0;loop<aFieldDef->Count();loop++)
       
  1076 			{
       
  1077 			TUid fieldType=(*aFieldDef)[loop];
       
  1078 			if (fieldType==KUidContactFieldMatchAll || iContentType->ContainsFieldType(fieldType))
       
  1079 				{
       
  1080 				match=ETrue;
       
  1081 				break;
       
  1082 				}
       
  1083 			}
       
  1084 		}
       
  1085 	if (match && iStorageType==KStorageTypeText)
       
  1086 		RestoreTextL(aTextStream,aTextIndex);
       
  1087 	return match;
       
  1088 	}
       
  1089 	        
       
  1090 TBool CContactItemField::RestoreIfMatchL(RReadStream& aRootStream,TFieldType aFieldType, const CContactItemFieldSet *aSystemTemplateFields,HBufC *aTextStream,TInt aTextIndex)
       
  1091 	{
       
  1092 	CContactItemFieldDef* fieldDef=new(ELeave) CContactItemFieldDef();
       
  1093 	CleanupStack::PushL(fieldDef);
       
  1094 	fieldDef->AppendL(aFieldType);
       
  1095 	TBool ret=RestoreIfMatchL(aRootStream,fieldDef, aSystemTemplateFields,aTextStream,aTextIndex);
       
  1096 	CleanupStack::PopAndDestroy();	// fieldDef
       
  1097 	return(ret);
       
  1098 	}
       
  1099 
       
  1100 EXPORT_C TStorageType CContactItemField::StorageType() const
       
  1101 /** Gets the field's storage type.
       
  1102 
       
  1103 @return The field's storage type. */
       
  1104     {
       
  1105     return iStorageType;
       
  1106     }
       
  1107 
       
  1108 EXPORT_C const CContentType &CContactItemField::ContentType() const
       
  1109 /** Gets the field's content type.
       
  1110 
       
  1111 @return Reference to the field's content type. */
       
  1112     {
       
  1113     return *iContentType;
       
  1114     }
       
  1115 
       
  1116 const CContentType &CContactItemField::TemplateContentType(const CContactItemFieldSet &aSystemTemplateFields) const
       
  1117 	{
       
  1118 	if (UsesTemplateTypes() || OverRidesLabel())
       
  1119 		return(*iContentType);
       
  1120 	const CContactItemField *templateField=aSystemTemplateFields.FindById(iTemplateFieldId);
       
  1121 	if (!templateField)
       
  1122 		return(*iContentType);
       
  1123 	return(templateField->ContentType());
       
  1124 	}
       
  1125 
       
  1126 EXPORT_C TPtrC CContactItemField::Label() const
       
  1127 /** Gets the field's label.
       
  1128 
       
  1129 @return The field label. If no label has been set, its length is zero. */
       
  1130     {
       
  1131     TPtrC label;
       
  1132     if (iLabel)
       
  1133         label.Set(*iLabel);
       
  1134     return label;
       
  1135     }
       
  1136 
       
  1137 EXPORT_C void CContactItemField::ResetStore()
       
  1138 /** Resets the field storage. The field's store is deleted, then re-allocated. */
       
  1139     {
       
  1140     delete iStorage;
       
  1141 	iStorage=NULL;
       
  1142 	ConstructStorageL();
       
  1143 	}
       
  1144 
       
  1145 EXPORT_C CContactFieldStorage *CContactItemField::Storage() const
       
  1146 /** Gets a pointer to the field's base storage.
       
  1147 
       
  1148 Rather than using this function and then casting to a specific storage class, 
       
  1149 one of the following functions should normally be used: TextStorage(), 
       
  1150 StoreStorage(), AgentStorage(), or DateTimeStorage().
       
  1151 
       
  1152 @return The field's base storage type. */
       
  1153     {
       
  1154     return iStorage;
       
  1155     }
       
  1156 
       
  1157 EXPORT_C CContactTextField *CContactItemField::TextStorage() const
       
  1158 /** Gets a pointer to the field's storage as a CContactTextField. 
       
  1159 
       
  1160 If the field's storage type is not KStorageTypeText, this function raises a panic.
       
  1161 
       
  1162 @return The field's storage as a CContactTextField*. */
       
  1163     {
       
  1164 	__ASSERT_ALWAYS(iStorageType==KStorageTypeText,Panic(ECntPanicInvalidStorageType));
       
  1165     return (CContactTextField *)iStorage;
       
  1166 	}
       
  1167 
       
  1168 EXPORT_C CContactStoreField *CContactItemField::StoreStorage() const
       
  1169 /** Gets a pointer to the field's storage as a CContactStoreField. 
       
  1170 
       
  1171 This indicates the field data is stored in a descriptor or descriptor array. 
       
  1172 If the field storage type is not KStorageTypeStore, this function raises a panic.
       
  1173 
       
  1174 @return Field's storage as a CContactStoreField*. */
       
  1175     {
       
  1176 	__ASSERT_ALWAYS(iStorageType==KStorageTypeStore,Panic(ECntPanicInvalidStorageType));
       
  1177     return (CContactStoreField *)iStorage;
       
  1178 	}
       
  1179 
       
  1180 EXPORT_C CContactAgentField *CContactItemField::AgentStorage() const
       
  1181 /** Gets a pointer to the field's storage as a CContactAgentField. 
       
  1182 
       
  1183 An agent is a property in a vCard which contains another person's contact details. 
       
  1184 If the field storage type is not KStorageTypeContactItemId, this function raises 
       
  1185 a panic.
       
  1186 
       
  1187 @return Field's storage as a CContactAgentField*. */
       
  1188     {
       
  1189 	__ASSERT_ALWAYS(iStorageType==KStorageTypeContactItemId,Panic(ECntPanicInvalidStorageType));
       
  1190     return (CContactAgentField *)iStorage;
       
  1191 	}
       
  1192 
       
  1193 EXPORT_C CContactDateField *CContactItemField::DateTimeStorage() const
       
  1194 /** Returns a pointer to the field's storage as a CContactDateField. 
       
  1195 
       
  1196 If the field storage type is not KStorageTypeDateTime, this function raises a panic.
       
  1197 
       
  1198 @return Field's storage as a CContactDateField*. */
       
  1199     {
       
  1200 	__ASSERT_ALWAYS(iStorageType==KStorageTypeDateTime,Panic(ECntPanicInvalidStorageType));
       
  1201     return (CContactDateField *)iStorage;
       
  1202 	}
       
  1203 
       
  1204 EXPORT_C void CContactItemField::AddFieldTypeL(TFieldType aFieldType)
       
  1205 /** Appends a field type to the field's content type.
       
  1206 
       
  1207 Note that certain combinations of field types are not valid and should not be
       
  1208 used.
       
  1209 
       
  1210 @param aFieldType The field type to append to the field's content type. */
       
  1211     {
       
  1212     iContentType->AddFieldTypeL(aFieldType);
       
  1213 	}
       
  1214 
       
  1215 EXPORT_C void CContactItemField::RemoveFieldType(TFieldType aFieldType)
       
  1216 /** Removes a field type from the field's content type.
       
  1217 
       
  1218 @param aFieldType The field type to remove from the field's content type. */
       
  1219 	{
       
  1220     iContentType->RemoveFieldType(aFieldType);
       
  1221 	}
       
  1222 
       
  1223 EXPORT_C void CContactItemField::SetMapping(TUid aMapping)
       
  1224 /** Sets the vCard mapping for the field's content type.
       
  1225 
       
  1226 @param aMapping The new mapping for the field's content type. */
       
  1227     {
       
  1228     iContentType->SetMapping(aMapping);
       
  1229     }
       
  1230 
       
  1231 EXPORT_C void CContactItemField::SetHidden(TBool aHidden)
       
  1232 /** Sets the value of the hidden attribute. 
       
  1233 
       
  1234 If hidden fields are included in the view definition, the field is displayed 
       
  1235 like other fields. If the view definition masks hidden fields, it is not displayed. 
       
  1236 See the TMode enumeration defined in class CContactItemViewDef.
       
  1237 
       
  1238 @param aHidden ETrue for hidden, EFalse for displayed. */
       
  1239     {
       
  1240     if (aHidden)
       
  1241         iAttributes|=EHidden;
       
  1242     else
       
  1243         iAttributes&=~EHidden;
       
  1244     }
       
  1245 
       
  1246 EXPORT_C void CContactItemField::SetReadOnly(TBool aReadOnly)
       
  1247 /** Sets the value of the field's read only attribute.
       
  1248 
       
  1249 @param aReadOnly ETrue to set the field's read only attribute, EFalse to unset 
       
  1250 the attribute. */
       
  1251     {
       
  1252     if (aReadOnly)
       
  1253         iAttributes|=EReadOnly;
       
  1254     else
       
  1255         iAttributes&=~EReadOnly;
       
  1256     }
       
  1257 
       
  1258 EXPORT_C void CContactItemField::SetSynchronize(TBool aSynchronize)
       
  1259 /** Sets the value of the field's synchronise attribute.
       
  1260 
       
  1261 @param aSynchronize ETrue to set synchronise attribute, EFalse to unset it. */
       
  1262     {
       
  1263     if (aSynchronize)
       
  1264         iAttributes|=ESynchronize;
       
  1265     else
       
  1266         iAttributes&=~ESynchronize;
       
  1267     }
       
  1268 
       
  1269 EXPORT_C void CContactItemField::SetDisabled(TBool aDisabled)
       
  1270 /** Sets the value of the disabled attribute.
       
  1271 
       
  1272 @param aDisabled ETrue to set the disabled attribute, EFalse to unset the 
       
  1273 attribute. */
       
  1274     {
       
  1275     if (aDisabled)
       
  1276         iAttributes|=EDisabled;
       
  1277     else
       
  1278         iAttributes&=~EDisabled;
       
  1279     }
       
  1280 
       
  1281 /** 
       
  1282 @internalComponent
       
  1283 */
       
  1284 void CContactItemField::UsesTemplateData(TInt aTemplateFieldId)
       
  1285 	{
       
  1286 	iTemplateFieldId=aTemplateFieldId;
       
  1287 	}
       
  1288 
       
  1289 void CContactItemField::SetLabelUnspecified(TBool aUnspecified)
       
  1290 	{
       
  1291 	if (aUnspecified)
       
  1292 		iAttributes|=ELabelUnspecified;
       
  1293 	else
       
  1294 		iAttributes&=~ELabelUnspecified;
       
  1295 	}
       
  1296 
       
  1297 EXPORT_C void CContactItemField::SetUserAddedField(TBool aUserAddedField)
       
  1298 /** Sets the user added field attribute.
       
  1299 
       
  1300 @param aUserAddedField ETrue to set the field's user added attribute, EFalse 
       
  1301 to unset it. */
       
  1302 	{
       
  1303 	if (aUserAddedField)
       
  1304 		iAttributes|=EUserAddedField;
       
  1305 	else
       
  1306 		iAttributes&=~EUserAddedField;
       
  1307 	}
       
  1308 
       
  1309 EXPORT_C void CContactItemField::SetTemplateField(TBool aTemplateField)
       
  1310 /** Sets whether the field is a template field.
       
  1311 
       
  1312 @param aTemplateField ETrue to set the field's Is template attribute. EFalse 
       
  1313 to unset it. */
       
  1314 	{
       
  1315 	if (aTemplateField)
       
  1316 		iAttributes|=ETemplate;
       
  1317 	else
       
  1318 		iAttributes&=~ETemplate;
       
  1319 	}
       
  1320 
       
  1321 EXPORT_C void CContactItemField::SetPrivate(TBool aPrivateField)
       
  1322 /** Sets the value of the field's private attribute. 
       
  1323 
       
  1324 This is used by the contact database when exporting a contact item as a vCard, 
       
  1325 to identify fields which should not be exported.
       
  1326 
       
  1327 @param aTemplateField ETrue to set the field's private attribute, EFalse to 
       
  1328 unset it. */
       
  1329 	{
       
  1330 	if (aPrivateField)
       
  1331 		iExtendedAttributes|=EPrivate;
       
  1332 	else
       
  1333 		iExtendedAttributes&=~EPrivate;
       
  1334 	}
       
  1335 
       
  1336 EXPORT_C void CContactItemField::SetSpeedDial(TBool aSpeedDialField)
       
  1337 /** Sets the value of the field's speed dial attribute.
       
  1338 
       
  1339 @param aSpeedDialField ETrue if the field should be a speed dial field, EFalse 
       
  1340 if not. */
       
  1341 	{
       
  1342 	if (aSpeedDialField)
       
  1343 		iExtendedAttributes|=ESpeedDial;
       
  1344 	else
       
  1345 		iExtendedAttributes&=~ESpeedDial;
       
  1346 	}
       
  1347 
       
  1348 /**
       
  1349 @internalTechnology 
       
  1350 */
       
  1351 EXPORT_C void CContactItemField::SetCustomFilterable(EContactFieldFlags aContactFilterType)
       
  1352 	{
       
  1353 	if (aContactFilterType == EContactFieldFlagFilterable) 
       
  1354 		{
       
  1355  		iExtendedAttributes |= EUserDefinedFilter;
       
  1356  		}
       
  1357   	else if (aContactFilterType == EContactFieldFlagFilterable1) 
       
  1358  		{
       
  1359  		iExtendedAttributes |= EUserDefinedFilter1;
       
  1360  		}
       
  1361  	else if (aContactFilterType == EContactFieldFlagFilterable2) 
       
  1362  		{
       
  1363  		iExtendedAttributes |= EUserDefinedFilter2;
       
  1364  		}
       
  1365  	else if (aContactFilterType == EContactFieldFlagFilterable3) 
       
  1366  		{
       
  1367  		iExtendedAttributes |= EUserDefinedFilter3;
       
  1368  		}
       
  1369  	else if (aContactFilterType == EContactFieldFlagFilterable4) 
       
  1370  		{
       
  1371  		iExtendedAttributes |= EUserDefinedFilter4;
       
  1372  		}
       
  1373 	}
       
  1374 
       
  1375 /** 
       
  1376 Determine if a custom filter exists. If it does, return the filter type.
       
  1377 
       
  1378 @param aContactFieldFlag The custom filter type if one exists.
       
  1379 @return ETrue if custom filter exists.
       
  1380 @internalTechnology 
       
  1381  */	
       
  1382 EXPORT_C TBool CContactItemField::HasCustomFilter(EContactFieldFlags& aContactFieldFlag) const
       
  1383 	{
       
  1384 	if (iExtendedAttributes & EUserDefinedFilter) 
       
  1385  		{
       
  1386  		aContactFieldFlag = EContactFieldFlagFilterable;
       
  1387  		return ETrue;
       
  1388  		}
       
  1389 	else if (iExtendedAttributes & EUserDefinedFilter1) 
       
  1390  		{
       
  1391  		aContactFieldFlag = EContactFieldFlagFilterable1;
       
  1392  		return ETrue;
       
  1393  		}
       
  1394  	else if (iExtendedAttributes & EUserDefinedFilter2) 
       
  1395  		{
       
  1396  		aContactFieldFlag = EContactFieldFlagFilterable2;
       
  1397  		return ETrue;
       
  1398  		}
       
  1399  	else if (iExtendedAttributes & EUserDefinedFilter3) 
       
  1400  		{
       
  1401  		aContactFieldFlag = EContactFieldFlagFilterable3;
       
  1402  		return ETrue;
       
  1403  		}
       
  1404  	else if (iExtendedAttributes & EUserDefinedFilter4) 
       
  1405  		{
       
  1406  		aContactFieldFlag = EContactFieldFlagFilterable4;
       
  1407  		return ETrue;
       
  1408  		}
       
  1409  		
       
  1410  	return EFalse;
       
  1411   	}
       
  1412   	
       
  1413 
       
  1414 void CContactItemField::UsesTemplateLabel()
       
  1415 	{
       
  1416 	iAttributes&=~EOverRidesLabel;
       
  1417 	SetLabelUnspecified(EFalse);
       
  1418 	}
       
  1419 
       
  1420 void CContactItemField::SetOverRidesLabel(TBool aValue)
       
  1421 	{
       
  1422 	if (aValue)
       
  1423 		{
       
  1424 		iAttributes|=EOverRidesLabel;
       
  1425 		}
       
  1426 	else
       
  1427 		{
       
  1428 		iAttributes&=~EOverRidesLabel;
       
  1429 		}
       
  1430 	}
       
  1431 
       
  1432 void CContactItemField::SetUsesTemplateTypes(TBool aUsesTemplateTypes)
       
  1433 	{
       
  1434 	if (aUsesTemplateTypes)
       
  1435 		iAttributes|=EUsesTemplateData;
       
  1436 	else
       
  1437 		iAttributes&=~EUsesTemplateData;
       
  1438 	}
       
  1439 
       
  1440 EXPORT_C void CContactItemField::SetLabelL(const TDesC& aLabel)
       
  1441 /** Sets the field label. 
       
  1442 
       
  1443 The label is allocated using TDesC::AllocL(), so the function can leave. 
       
  1444 Any existing label is replaced.
       
  1445 
       
  1446 @param aLabel The new field label. */
       
  1447     {
       
  1448 	SetLabel(aLabel.AllocL());
       
  1449     }
       
  1450 
       
  1451 EXPORT_C void CContactItemField::SetLabel(HBufC* aLabel)
       
  1452 /** Sets the field label. 
       
  1453 
       
  1454 The field takes ownership of aLabel so the function cannot leave.
       
  1455 
       
  1456 @param aLabel The new field label. */
       
  1457 	{
       
  1458 	delete iLabel;
       
  1459 	iLabel=aLabel;
       
  1460 	SetLabelUnspecified(EFalse);
       
  1461 	iAttributes|=EOverRidesLabel;
       
  1462 	}
       
  1463 
       
  1464 EXPORT_C void CContactItemField::SetId(TInt aId)
       
  1465 /** Sets the ID which uniquely identifies a field within a field set..
       
  1466 
       
  1467 Note that the field ID value is initialised when the field is added to the 
       
  1468 field set (using CContactItemFieldSet::AddL()). It is equivalent to the field's 
       
  1469 index within the field set array, and should not normally be changed.
       
  1470 
       
  1471 @param aId The new field ID. */
       
  1472 	{
       
  1473 	iId=aId;
       
  1474 	}
       
  1475 
       
  1476 EXPORT_C TInt CContactItemField::Id() const
       
  1477 /** Gets the field ID.
       
  1478 
       
  1479 @return The field ID. */
       
  1480 	{
       
  1481 	return(iId);
       
  1482 	}
       
  1483 
       
  1484 EXPORT_C TUint CContactItemField::UserFlags() const
       
  1485 /** Gets the value of the user flags, as set by SetUserFlags().
       
  1486 
       
  1487 @return The user flags value. */
       
  1488 	{
       
  1489 	return((iAttributes&EUserMask)>>EUserMaskShift);
       
  1490 	}
       
  1491 
       
  1492 EXPORT_C void CContactItemField::SetUserFlags(TUint aFlags)
       
  1493 /** Sets the value of the user flags.
       
  1494 
       
  1495 @param aFlags The user flags value. */
       
  1496 	{
       
  1497 	iAttributes&=~EUserMask;
       
  1498 	iAttributes|=((aFlags<<EUserMaskShift)&EUserMask);
       
  1499 	}
       
  1500 
       
  1501 TInt CContactItemField::TemplateFieldId() const
       
  1502 	{
       
  1503 	return iTemplateFieldId;
       
  1504 	}
       
  1505 
       
  1506 void CContactItemField::SetDeleted(TBool aDeleted)
       
  1507 	{
       
  1508 	if (aDeleted)
       
  1509 		iAttributes|=STATIC_CAST(TUint, EDeleted); 
       
  1510 	else
       
  1511 		iAttributes&=~EDeleted;
       
  1512 	}
       
  1513 
       
  1514 void CContactItemField::UpdateFieldFlags(const CContactItemFieldSet& aTemplateFieldSet)
       
  1515 	{
       
  1516 	TInt templatePosition;
       
  1517 	TBool exactMatch;
       
  1518 
       
  1519 	if (!Storage()->IsFull() && !IsTemplate())
       
  1520 		{
       
  1521 		SetDeleted(ETrue);
       
  1522 		}
       
  1523 	else
       
  1524 		{
       
  1525 		SetDeleted(EFalse);
       
  1526 		templatePosition = aTemplateFieldSet.MatchTemplateField(ContentType(),UserFlags(),exactMatch);
       
  1527 		if (templatePosition != KErrNotFound)
       
  1528 			{
       
  1529 			const CContactItemField& templateField = aTemplateFieldSet[templatePosition];
       
  1530 			UsesTemplateData(templateField.Id());
       
  1531 			SetUsesTemplateTypes(exactMatch);
       
  1532 			if (LabelUnspecified() || templateField.Label().CompareF(Label())==0)
       
  1533 				{
       
  1534 				UsesTemplateLabel();
       
  1535 				}
       
  1536 			}
       
  1537 		}
       
  1538 	SetLabelUnspecified(EFalse);
       
  1539 	}
       
  1540 
       
  1541 /** 
       
  1542 @internalTechnology 
       
  1543  */
       
  1544 EXPORT_C void CContactItemField::GetFieldText(TDes &aText) const 
       
  1545 	{
       
  1546 	if (StorageType()==KStorageTypeText)
       
  1547 		{
       
  1548 		TPtrC text=TextStorage()->Text();
       
  1549 		TInt length=text.Length();
       
  1550 		const TInt carriageReturn=13;
       
  1551 		const TInt lineFeed=10;
       
  1552 		for(TInt loop=0;loop<length;loop++)
       
  1553   			if ((TChar(text[loop])==carriageReturn) || (TChar(text[loop])==lineFeed))
       
  1554 				{
       
  1555 				length=loop;
       
  1556 				break;
       
  1557 				}
       
  1558 		if (length>KTextFieldMinimalLength)
       
  1559 			length=KTextFieldMinimalLength;
       
  1560 		aText.Copy(text.Left(length));
       
  1561 		}
       
  1562 	}
       
  1563 
       
  1564 EXPORT_C TBool CContactItemField::IsValidLabel(const TDesC& aLabel,TInt& aInvalidPos)
       
  1565 /** Tests whether a field label is valid.
       
  1566 
       
  1567 Note: the label is invalid if it contains any of the following characters: 
       
  1568 
       
  1569 [] (left or right square bracket) 
       
  1570 
       
  1571 = (equals sign)
       
  1572 
       
  1573 . (dot) 
       
  1574 
       
  1575 : (colon) 
       
  1576 
       
  1577 , (comma)
       
  1578 
       
  1579 @param aLabel The field label to test.
       
  1580 @param aInvalidPos On return, contains the character position within the label 
       
  1581 of the first invalid character. The first character position is zero.
       
  1582 @return ETrue if valid, EFalse if invalid. */
       
  1583 	{
       
  1584 		return !(((aInvalidPos = aLabel.Locate(KVersitTokenLSquareBracketVal)) != KErrNotFound) ||
       
  1585 		((aInvalidPos = aLabel.Locate(KVersitTokenRSquareBracketVal)) != KErrNotFound) ||
       
  1586 		((aInvalidPos = aLabel.Locate(KVersitTokenEqualsVal)) != KErrNotFound) ||
       
  1587 		((aInvalidPos = aLabel.Locate(KVersitTokenColonVal)) != KErrNotFound) ||
       
  1588 		((aInvalidPos = aLabel.Locate(KVersitTokenPeriodVal)) != KErrNotFound) ||
       
  1589 		((aInvalidPos = aLabel.Locate(KVersitTokenCommaVal)) != KErrNotFound));
       
  1590 	}
       
  1591 
       
  1592 EXPORT_C TBool CContactItemField::IsTemplateLabelField() const
       
  1593 /** Tests whether the field is a template label field (a field which holds 
       
  1594 the label for a contact card template: see class CContactCardTemplate).
       
  1595 
       
  1596 @return ETrue if the field is a template label field, EFalse if not. */
       
  1597 	{
       
  1598 	return (iContentType->ContainsFieldType(KUidContactFieldTemplateLabel));
       
  1599 	}
       
  1600 
       
  1601 
       
  1602 /** 
       
  1603 Part of the system template update implementation. 
       
  1604 This could be used for a generic update method at a later stage.
       
  1605 @internalTechnology
       
  1606 */
       
  1607 void CContactItemField::PopulateStoreL(RStoreWriteStream& aRootStream, TInt aCount, CArrayFix<TFieldHeader>& aFieldHeaderArray) const
       
  1608 	{
       
  1609 	if (!IsDeleted())
       
  1610 		{
       
  1611 		//Store attributes
       
  1612         aRootStream << aFieldHeaderArray[aCount].FieldAtts();
       
  1613         
       
  1614 		// since field is in fullFields it cannot be empty, so there is no need to check
       
  1615         if (StorageType() != KStorageTypeText)
       
  1616             {
       
  1617             aRootStream << aFieldHeaderArray[aCount].StreamId();
       
  1618             }
       
  1619 		
       
  1620 		//Store field id.
       
  1621 		aRootStream.WriteUint32L(iId);
       
  1622 		aRootStream.WriteUint32L(iTemplateFieldId);
       
  1623         
       
  1624 		CContactItemField::THint hint(0);
       
  1625         if(!UsesTemplateTypes())
       
  1626             {
       
  1627 			CArrayFixFlat<TUid>* additionalFields = new(ELeave) CArrayFixFlat<TUid>(5);
       
  1628 			CleanupStack::PushL(additionalFields);
       
  1629 			
       
  1630 			for(TInt loop=0; loop < iContentType->FieldTypeCount(); loop++)
       
  1631 				{
       
  1632 				TFieldType fieldType = iContentType->FieldType(loop);
       
  1633 				if (!AddFieldToHint(fieldType, hint))
       
  1634 				    {
       
  1635 					additionalFields->AppendL(fieldType);
       
  1636 				    }
       
  1637 				}
       
  1638 				
       
  1639 			const TInt KAdditionalUidsCount = additionalFields->Count();
       
  1640 			hint.SetAdditionalUidsNum(KAdditionalUidsCount);
       
  1641 			
       
  1642             if(iContentType->Mapping() != KNullUid)
       
  1643                 {
       
  1644                 //Store vCard mapping uid if there is a one.
       
  1645                 hint.SetHasVCardMappingUid();
       
  1646                 aRootStream.WriteInt32L(hint.iHintValue);
       
  1647     			aRootStream.WriteInt32L(iContentType->Mapping().iUid); // mapping
       
  1648                 }
       
  1649             else
       
  1650                 {
       
  1651                 aRootStream.WriteInt32L(hint.iHintValue);            
       
  1652                 }			
       
  1653 			
       
  1654 			for (TInt ii = 0; ii < KAdditionalUidsCount; ++ii) 
       
  1655 				{
       
  1656 				aRootStream.WriteInt32L((*additionalFields)[ii].iUid); // additional typing uids
       
  1657 				}
       
  1658 			CleanupStack::PopAndDestroy(); // additionalFields
       
  1659             }    
       
  1660 		
       
  1661 		if (OverRidesLabel())
       
  1662 			{ // store label if not inherited from template
       
  1663 			
       
  1664 			TInt length;
       
  1665 			
       
  1666 			if(iLabel)
       
  1667 				{
       
  1668 				length = iLabel->Length();
       
  1669 				}
       
  1670 			else
       
  1671 				{
       
  1672 				length = 0;
       
  1673 				}			
       
  1674 			
       
  1675 			aRootStream.WriteInt32L(length);	
       
  1676 				
       
  1677 			if (length > 0)
       
  1678 			    {
       
  1679 				aRootStream << *(iLabel);
       
  1680 			    }
       
  1681 			}
       
  1682 		} //if (!IsDeleted())
       
  1683 	}
       
  1684 
       
  1685 
       
  1686 /** 
       
  1687 Part of the system template update implementation. 
       
  1688 This could be used for a generic update method at a later stage.
       
  1689 @since 7.0
       
  1690 @internalTechnology
       
  1691 */
       
  1692 void CContactItemField::PrepareFieldAsTemplateL(CContactItemFieldSet& aSystemTemplateFieldSet)
       
  1693 	{
       
  1694 	TInt templatePosition = KErrNotFound;
       
  1695 	TBool exactMatch = EFalse;
       
  1696 	
       
  1697 	if ( !iStorage->IsFull() && !IsTemplate() )
       
  1698 		{
       
  1699 		SetDeleted(ETrue);
       
  1700 		} // if
       
  1701 	else
       
  1702 		{
       
  1703 		SetDeleted(EFalse);
       
  1704 		templatePosition = aSystemTemplateFieldSet.MatchTemplateField(ContentType(), UserFlags(), exactMatch);
       
  1705 		if (templatePosition != KErrNotFound)
       
  1706 			{
       
  1707 			const CContactItemField& systemTemplateField = aSystemTemplateFieldSet[templatePosition];
       
  1708 			UsesTemplateData( systemTemplateField.Id() );
       
  1709 			SetUsesTemplateTypes( exactMatch );
       
  1710 			if( LabelUnspecified() || systemTemplateField.Label().CompareF(Label()) == 0 )
       
  1711 				{
       
  1712 				UsesTemplateLabel();
       
  1713 				} 
       
  1714 			} //if
       
  1715 		} //else
       
  1716 
       
  1717 	SetLabelUnspecified(EFalse);
       
  1718 	}
       
  1719 
       
  1720 void CContactItemField::InternalizeL(RReadStream& aStream)
       
  1721 /** Internalises a CContactItemField object from a read stream. 
       
  1722 @param aStream Stream from which the object should be internalised. */
       
  1723 	{
       
  1724 
       
  1725 	delete iContentType;
       
  1726 	iContentType = NULL;
       
  1727 	iContentType = CContentType::NewL();
       
  1728 	iContentType->InternalizeL(aStream);
       
  1729 	
       
  1730 	iStorageType = aStream.ReadUint32L();
       
  1731 	
       
  1732 	if(iLabel)
       
  1733 		{
       
  1734 		delete iLabel;
       
  1735 		iLabel = NULL;
       
  1736 		}
       
  1737 	const TInt length=aStream.ReadInt32L();
       
  1738 	if (length)
       
  1739 		{
       
  1740 		iLabel=HBufC::NewL(aStream,length);	
       
  1741 		}
       
  1742 
       
  1743 	iId = aStream.ReadInt32L();
       
  1744 	
       
  1745 	iAttributes = aStream.ReadUint32L();
       
  1746 		
       
  1747 	iExtendedAttributes = aStream.ReadUint32L();
       
  1748 	
       
  1749 	delete iStorage;
       
  1750 	iStorage = NULL;
       
  1751 	ConstructStorageL();
       
  1752 	iStorage->InternalizeL(aStream);
       
  1753 	
       
  1754 	iTemplateFieldId = aStream.ReadInt32L();		
       
  1755 
       
  1756 	}
       
  1757 
       
  1758 void CContactItemField::ExternalizeL(RWriteStream& aStream) const 
       
  1759 /** Externalises a CContactItemField object to a write stream.
       
  1760 @param aStream Stream to which the object should be externalised. */
       
  1761 	{
       
  1762 	iContentType->ExternalizeL(aStream);
       
  1763 	
       
  1764 	aStream.WriteUint32L(iStorageType);
       
  1765 	
       
  1766 	if(iLabel)
       
  1767 		{
       
  1768 		
       
  1769 		const TInt length=iLabel->Length();
       
  1770 		aStream.WriteInt32L(length);	
       
  1771 		if (iLabel && length)
       
  1772 			{
       
  1773 			aStream<<*(iLabel);
       
  1774 			}
       
  1775 		}
       
  1776 		
       
  1777 	else
       
  1778 		{
       
  1779 		aStream.WriteInt32L(0);
       
  1780 		}
       
  1781 	
       
  1782 	aStream.WriteInt32L(iId);
       
  1783 	
       
  1784 	aStream.WriteUint32L(iAttributes);
       
  1785 		
       
  1786 	aStream.WriteUint32L(iExtendedAttributes);
       
  1787 	
       
  1788 	iStorage->ExternalizeL(aStream);
       
  1789 	
       
  1790 	aStream.WriteInt32L(iTemplateFieldId);
       
  1791 	}
       
  1792 
       
  1793 
       
  1794 
       
  1795 //
       
  1796 //	class THint
       
  1797 //
       
  1798 CContactItemField::THint::THint() : iHintValue(0)
       
  1799 	{}
       
  1800 
       
  1801 CContactItemField::THint::THint(TInt aValue)
       
  1802 	{
       
  1803 	iHintValue = aValue;
       
  1804 	}
       
  1805 
       
  1806 TBool CContactItemField::THint::operator==(const THint& aHint) const
       
  1807 	{
       
  1808 	return (iHintValue == aHint.iHintValue);
       
  1809 	}
       
  1810 
       
  1811 TBool CContactItemField::THint::operator!=(const THint& aHint) const	
       
  1812 	{
       
  1813 	return (iHintValue != aHint.iHintValue);
       
  1814 	}
       
  1815 
       
  1816 TInt  CContactItemField::THint::HintType() const
       
  1817 	{
       
  1818 	return (iHintValue & KHintTypeMask);
       
  1819 	}
       
  1820 
       
  1821 TInt CContactItemField::THint::TemplateFieldId() const
       
  1822     {
       
  1823     return (iHintValue & KHintTemplateFieldMask);    
       
  1824     }
       
  1825     
       
  1826 void  CContactItemField::THint::SetTemplateFieldId(TInt aTemplateFieldId)
       
  1827     {
       
  1828     iHintValue |= (aTemplateFieldId & KHintTemplateFieldMask);
       
  1829     }
       
  1830 
       
  1831 inline void CContactItemField::THint::SetHasVCardMappingUid()
       
  1832     {
       
  1833     iHintValue |= KHintVCardMappingMask;    
       
  1834     }
       
  1835     
       
  1836 inline TBool CContactItemField::THint::HasVCardMappingUid() const
       
  1837     {
       
  1838     return (iHintValue & KHintVCardMappingMask);    
       
  1839     }
       
  1840 
       
  1841 inline TInt CContactItemField::THint::AdditionalUidsNum() const
       
  1842     {
       
  1843     return ((iHintValue & KHintAdditionalMask) >> KHintAdditionalMaskShift);
       
  1844     }
       
  1845     
       
  1846 inline void CContactItemField::THint::SetAdditionalUidsNum(TInt aNumber)
       
  1847     {
       
  1848     iHintValue |= ((aNumber << KHintAdditionalMaskShift) & KHintAdditionalMask);       
       
  1849     }
       
  1850 #ifdef SYMBIAN_ENABLE_SPLIT_HEADERS	
       
  1851 inline void CContactItemField::THint::SetIsPhone()
       
  1852 	{iHintValue|=KIntContactHintIsPhone;}
       
  1853 inline void CContactItemField::THint::SetIsMsg()
       
  1854 	{iHintValue|=KIntContactHintIsMsg;}
       
  1855 // turn off Pronunciation bit too?
       
  1856 inline void CContactItemField::THint::SetIsCompanyName()
       
  1857 	{iHintValue|=KIntContactHintIsCompanyName;}
       
  1858 inline void CContactItemField::THint::SetIsFamilyName()
       
  1859 	{iHintValue|=KIntContactHintIsFamilyName;}
       
  1860 inline void CContactItemField::THint::SetIsGivenName()
       
  1861 	{iHintValue|=KIntContactHintIsGivenName;}
       
  1862 inline void CContactItemField::THint::SetIsCompanyNamePronunciation()
       
  1863 	{iHintValue|=KIntContactHintIsCompanyName|KIntContactHintIsPronunciation;}
       
  1864 inline void CContactItemField::THint::SetIsFamilyNamePronunciation()
       
  1865 	{iHintValue|=KIntContactHintIsFamilyName|KIntContactHintIsPronunciation;}
       
  1866 inline void CContactItemField::THint::SetIsGivenNamePronunciation()
       
  1867 	{iHintValue|=KIntContactHintIsGivenName|KIntContactHintIsPronunciation;}
       
  1868 inline void CContactItemField::THint::SetIsAddress()
       
  1869 	{iHintValue|=KIntContactHintIsAddress;}
       
  1870 inline void CContactItemField::THint::SetIsAdditionalName()
       
  1871 	{iHintValue|=KIntContactHintIsAdditionalName;}
       
  1872 inline void CContactItemField::THint::SetIsSuffixName()
       
  1873 	{iHintValue|=KIntContactHintIsSuffixName;}
       
  1874 inline void CContactItemField::THint::SetIsPrefixName()
       
  1875 	{iHintValue|=KIntContactHintIsPrefixName;}
       
  1876 inline void CContactItemField::THint::SetStorageIsInline()
       
  1877 	{iHintValue|=KIntContactHintStorageInline;}
       
  1878 inline void CContactItemField::THint::SetIsEmail()
       
  1879 	{iHintValue|=KIntContactHintIsEmail;}
       
  1880 inline TBool CContactItemField::THint::IsPhone() const
       
  1881 	{return (iHintValue&KIntContactHintIsPhone);}
       
  1882 inline TBool CContactItemField::THint::IsMsg() const
       
  1883 	{return (iHintValue&KIntContactHintIsMsg);}
       
  1884 inline TBool CContactItemField::THint::IsCompanyName() const
       
  1885 	{return ((iHintValue&KIntContactHintIsCompanyNamePronunciation) == KIntContactHintIsCompanyName);}
       
  1886 inline TBool CContactItemField::THint::IsFamilyName() const
       
  1887 	{return ((iHintValue&KIntContactHintIsFamilyNamePronunciation)==KIntContactHintIsFamilyName);}
       
  1888 inline TBool CContactItemField::THint::IsGivenName() const
       
  1889 	{return ((iHintValue&KIntContactHintIsGivenNamePronunciation)==KIntContactHintIsGivenName);}
       
  1890 inline TBool CContactItemField::THint::IsCompanyNamePronunciation() const
       
  1891 	{return ((iHintValue&KIntContactHintIsCompanyNamePronunciation) == KIntContactHintIsCompanyNamePronunciation);}
       
  1892 inline TBool CContactItemField::THint::IsFamilyNamePronunciation() const
       
  1893 	{return ((iHintValue&KIntContactHintIsFamilyNamePronunciation)==KIntContactHintIsFamilyNamePronunciation);}
       
  1894 inline TBool CContactItemField::THint::IsGivenNamePronunciation() const
       
  1895 	{return ((iHintValue&KIntContactHintIsGivenNamePronunciation)==KIntContactHintIsGivenNamePronunciation);}
       
  1896 inline TBool CContactItemField::THint::IsAddress() const
       
  1897 	{return (iHintValue&KIntContactHintIsAddress);}
       
  1898 inline TBool CContactItemField::THint::IsAdditionalName() const
       
  1899 	{return (iHintValue&KIntContactHintIsAdditionalName);}
       
  1900 inline TBool CContactItemField::THint::IsSuffixName() const
       
  1901 	{return (iHintValue&KIntContactHintIsSuffixName);}
       
  1902 inline TBool CContactItemField::THint::IsPrefixName() const
       
  1903 	{return (iHintValue&KIntContactHintIsPrefixName);}
       
  1904 inline TBool CContactItemField::THint::IsStorageInline() const
       
  1905 	{return (iHintValue&KIntContactHintStorageInline);}
       
  1906 inline TBool CContactItemField::THint::IsEmail() const
       
  1907 	{return (iHintValue&KIntContactHintIsEmail);}
       
  1908 	
       
  1909 #ifndef __SYMBIAN_CNTMODEL_USE_SQLITE__	
       
  1910 inline void CContactItemField::THint::SetHasAdditionalUids()
       
  1911 	{iHintValue|=KHintAdditionalMask;}
       
  1912 #endif //__SYMBIAN_CNTMODEL_USE_SQLITE__ 
       
  1913 inline TBool CContactItemField::THint::Contains(const THint& aHint) const
       
  1914 	{return (iHintValue&aHint.iHintValue);}
       
  1915 #endif	
       
  1916 //
       
  1917 //	class TFieldHeader
       
  1918 //
       
  1919 
       
  1920 /*
       
  1921  * Default constructor
       
  1922  */
       
  1923 TFieldHeader::TFieldHeader()
       
  1924 : iFieldUid(0),
       
  1925   iStreamId(KNullStreamIdValue)
       
  1926     {
       
  1927     }
       
  1928 
       
  1929 /*
       
  1930  * Overloaded constructor
       
  1931  */
       
  1932 TFieldHeader::TFieldHeader(TContactFieldAtts aAtts, TUint32 aFieldUid, TStreamId aId)
       
  1933 : iAtts(aAtts),
       
  1934   iFieldUid(aFieldUid),
       
  1935   iStreamId(aId)
       
  1936     {
       
  1937     }
       
  1938     
       
  1939 inline TInt TFieldHeader::FieldId() const
       
  1940 	{
       
  1941 	return iFieldUid;
       
  1942 	}
       
  1943 
       
  1944 inline void TFieldHeader::SetFieldId(TInt aId) 
       
  1945 	{
       
  1946     iFieldUid = aId;
       
  1947 	}
       
  1948 
       
  1949 inline TContactFieldAtts TFieldHeader::FieldAtts() const
       
  1950     {
       
  1951     return iAtts;
       
  1952     }
       
  1953     
       
  1954 inline void TFieldHeader::SetFieldAtts(TContactFieldAtts aAtts)
       
  1955     {
       
  1956     iAtts = aAtts; 
       
  1957     }
       
  1958 
       
  1959 inline TStreamId TFieldHeader::StreamId() const
       
  1960     {
       
  1961     return iStreamId;    
       
  1962     }
       
  1963     
       
  1964 inline void TFieldHeader::SetStreamId(TStreamId aId)
       
  1965     {
       
  1966     iStreamId = aId;
       
  1967     }