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".
8 // Initial Contributors:
9 // Nokia Corporation - initial contribution.
14 // Persistence layer exports
18 #if !defined(__CNTITEM_H__)
21 #if !defined(__E32BASE_H__)
25 #if !defined(__CNTDEF_H__)
29 #if !defined(__CNTFIELD_H__)
35 /** Maximum length of UID string.
39 const TInt KUidStringLength =244;
41 /** UID string separator character
45 #define KUidStringSeparator '-'
47 #ifndef SYMBIAN_ENABLE_SPLIT_HEADERS
48 /** Constant used by vCard import/export.
51 #define KContactMaxFieldNumber 32
54 class CContactItemField;
55 class CContactItemViewDef;
58 /** Constant to indicate that all fields in the fieldset should be searched.
62 const TInt KContactFieldSetSearchAll=-1;
64 class CContactItemFieldSet : public CBase
65 /** A contact item's field set. The field set owns an array of contact item fields
66 (CContactItemFields). The field set is owned by a contact item, and can be
67 retrieved using CContactItem::CardFields(). Use functions in class
68 CContactItem to add and remove fields to/from the field set.
70 A field set can contain more than one field of the same type, but this is
71 not advisable as it may cause problems when synchronising the contacts database.
76 friend class CContactItemField;
77 friend class CContactDatabase;
78 friend class CContactTables;
79 friend class RPplContactTable;
80 friend class TCntPersistenceUtility;
83 IMPORT_C static CContactItemFieldSet* NewL();
84 IMPORT_C static CContactItemFieldSet* NewLC();
85 IMPORT_C ~CContactItemFieldSet();
86 inline const CContactItemField& operator[](TInt aIndex) const;
87 inline CContactItemField& operator[](TInt aIndex);
88 inline TInt Find(TFieldType aFieldType) const; // will only find the first such occurence
89 inline TInt Find(TFieldType aFieldType,TUid aMapping) const;
90 IMPORT_C TInt FindNext(TFieldType aFieldType,TInt aStartPos=KContactFieldSetSearchAll) const;
91 IMPORT_C TInt FindNext(TFieldType aFieldType,TUid aMapping,TInt aStartPos=KContactFieldSetSearchAll) const;
92 inline TInt Count() const;
94 IMPORT_C void UpdateFieldL(const CContactItemField& aField, TInt aMatchCount);
95 IMPORT_C void UpdateFieldSyncL(const CContactItemField& aField, TInt aMatchCount);
96 IMPORT_C CContactItemFieldSet& AddL(CContactItemField& aField);
97 IMPORT_C void Remove(TInt aIndex);
98 IMPORT_C void InsertL(TInt aIndex,CContactItemField& aField);
99 IMPORT_C void Move(TInt aFrom, TInt aTo);
100 IMPORT_C TStreamId StoreL(CStreamStore& aStore,RWriteStream& aTextStream,CStreamStore& aBlobStore);
101 TStreamId StoreL(CStreamStore& aStore,RWriteStream& aTextStream,CStreamStore& aBlobStore,CContactTables* aTables);
102 IMPORT_C void RestoreL(CStreamStore& aStore, TStreamId anId,CStreamStore* aBlobStore,const CContactItemViewDef& aViewDef,RReadStream& aReadStream);
103 IMPORT_C void RestoreL(CStreamStore& aStore, TStreamId anId,CStreamStore* aBlobStore,const CContactItemViewDef& aViewDef,const CContactItem* aTemplate, HBufC* aTextBuf);
104 TInt FieldText(TFieldType aFieldType, TDes &aText, TInt aStartPosition) const;
105 CArrayFix<TFieldHeader>* ConstructFieldHeaderArrayLC(RWriteStream& aTextStream, CStreamStore& aBlobStore);
106 TInt FieldTypeCount(const CContactItemFieldSet& aSystemTemplateFields, TInt aStartIndex, const CContactItemField& aField) const;
107 TBool ContainsFieldTypeMapping(const CContentType& aBaseFieldContentType, const TFieldType& aContactFieldType) const;
108 void ExternalizeL(RWriteStream& aStream) const;
109 void InternalizeL(RReadStream& aStream);
112 CContactItemFieldSet();
114 void SetFieldId(CContactItemField& aField);
115 const CContactItemField* FindById(TInt aId) const;
116 IMPORT_C TStreamId StoreL(CStreamStore& aStore,const CContactItem* aTemplate,RWriteStream& aStream,CStreamStore& aBlobStore,CContactTables* aTables);
117 void RestoreL(CStreamStore& aStore, TStreamId anId, CStreamStore* aBlobStore,const CContactItemViewDef& aViewDef,const CContactItem* aTemplate,RReadStream& aReadStream,CContactTables* aContactsTable, RArray<TInt>* aEmailIdArray);
118 void RestoreAndAddTemplateL(CStreamStore& aStore, TStreamId aId,CStreamStore* aBlobStore,const CContactItemViewDef& aViewDef,const CContactItem* aTemplate, RReadStream& aReadStream,CContactTables* aContactsTable,RArray<TInt>* aEmailIdArray);
119 TInt MatchTemplateField(const CContentType& aContentType,TUint aUserFlags,TBool &aExactMatch) const;
120 static HBufC* LoadTextStreamLC(RReadStream& aStream);
121 void NonZeroFieldText(TFieldType aFieldType, TDes &aText) const;
124 CArrayPtr<CContactItemField>* iFields;
127 class CContactDatabase;
129 class CContactItem : public CBase
130 /** The abstract base class for contact cards, templates and groups. All contact
131 items are identified by a contact ID, (TContactItemId), have a last modified
132 date/time and own one or more fields (the field set). Contact items also
133 have an access count and attributes (e.g. hidden). Note that fields in a contact
134 item also have attributes. Attribute values specified in the contact item
135 override those in the contained fields. The access count is a record of the
136 number of objects referencing a contact item. A contact item cannot be fully
137 deleted until its access count is zero.
142 friend class CContactCardTemplate;
143 friend class CContactItemPlusGroup;
144 friend class CContactCard;
145 friend class CContactTemplate;
146 friend class CContactGroup;
147 friend class CContactOwnCard;
148 friend class CVCardToContactsAppConverter;
149 friend class CContactICCEntry;
150 friend class RPplContactTable;
151 friend class RPplIdentityTable;
152 friend class RPplPreferencesTable;
153 friend class CPackagerTests; //Comparison test
154 friend class CPackagerCntComparator;
155 friend class CContactDatabase;
156 friend class CPplContactItemManager;
158 IMPORT_C ~CContactItem();
159 /** Gets the contact item's type.
161 @return The contact item's type. */
162 virtual TUid Type() const=0;
163 static CContactItem* NewLC(RReadStream& aStream);
164 IMPORT_C static CContactItem* NewLC(TUid aType);
165 IMPORT_C TContactItemId Id() const;
166 IMPORT_C TContactItemId TemplateRefId() const;
167 IMPORT_C TTime LastModified() const;
168 IMPORT_C void SetLastModified(const TTime& aLastModified);
169 IMPORT_C void AddFieldL(CContactItemField& aField);
170 IMPORT_C void RemoveField(TInt aFieldPos);
171 IMPORT_C void InsertFieldL(CContactItemField& aField,TInt aFieldPos);
172 IMPORT_C CContactItemFieldSet& CardFields() const;
173 IMPORT_C void SetHidden(TBool aHidden);
174 IMPORT_C void SetSystem(TBool aSystem);
175 IMPORT_C TBool IsHidden();
176 IMPORT_C TBool IsSystem();
177 IMPORT_C void UpdateFieldSet(CContactItemFieldSet* aNewFieldSet);
178 IMPORT_C void SetDeleted(TBool aDeleted);
179 IMPORT_C TBool IsDeleted() const;
180 IMPORT_C void SetTemplateRefId(TContactItemId aUid);
181 TContactItemId Agent();
182 inline TBool IsDeletable();
183 inline void IncAccessCount();
184 inline void DecAccessCount();
185 inline TInt AccessCount() const;
186 IMPORT_C void SetUidStringL(TDesC& aString);
187 IMPORT_C TPtrC UidStringL(TInt64 aMachineUniqueId) const;
188 TStreamId PopulateStoreL(CStreamStore& aStore, CArrayFix<TFieldHeader>& aFieldHeaderArray) const;
189 void AddLabelFieldL();
190 IMPORT_C void RestoreTemplateFieldsL(const CContactItemFieldSet& aSystemTemplateFields, const CContactItemFieldSet& aTemplateFields, const CContactItemViewDef& aViewDef);
191 void ClearFieldContent();
193 virtual void ExternalizeL(RWriteStream& aStream) const;
194 virtual void InternalizeL(RReadStream& aStream);
196 IMPORT_C void SetId(TContactItemId aId);
197 IMPORT_C TUint32 Attributes() const;
198 IMPORT_C void SetAttributes(TUint32 aAttributes);
199 IMPORT_C void SetAccessCount(TUint32 aAccessCount);
200 IMPORT_C void SetCreationDate(const TTime& aTime);
203 /** Contact item's attribute flags
205 These flags can be used to set the various attributes of a contact item. */
208 /** To set the contact item's system attribute. */
210 /** To set the contact item's hidden attribute. */
212 /** To set the contact item's hidden attribute. */
213 ECompressedGuid=0x04,
214 /** To set the contact item's Is deleted attribute. */
221 void ConstructL(const CContactItem *aTemplate);
222 void MakeUidStringL(TInt64 aMachineUniqueId);
223 IMPORT_C void SetHasCompressedGuid(TBool aCompressed);
224 TBool GuidIsCompressed() const;
225 TInt NumberOfFieldsToStore() const;
228 CContactItemFieldSet* iFieldSet;
231 TContactItemId iTemplateRefId;
234 TUint32 iAccessCount;
238 class CContactItemPlusGroup : public CContactItem
239 /** Abstract base class for CContactGroup, CContactCard and CContactOwnCard.
241 The purpose of this class is to avoid duplication of group functionality
242 in its derived classes.
248 IMPORT_C const CContactIdArray* GroupsJoined() const;
249 IMPORT_C CContactIdArray* GroupsJoinedLC() const;
251 CContactItemPlusGroup();
252 IMPORT_C ~CContactItemPlusGroup();
254 virtual void ExternalizeL(RWriteStream& aStream) const;
255 virtual void InternalizeL(RReadStream& aStream);
257 IMPORT_C void ResetGroups();
258 IMPORT_C void SetGroups(CContactIdArray* aGroups);
261 CContactIdArray* iGroups;
262 friend class CContactDatabase;
263 friend class RPplLookupGroupsTable;
264 friend class RPplGroupMembershipTable;
267 class CContactGroup : public CContactItemPlusGroup
270 A contact group is a contact item which holds a set of associated contact
271 item IDs. The members of the group may be contact cards, own cards, or even
272 other groups. The group has a label which identifies the group to users, e.g.
273 "family", or "colleagues". The type of a contact group is KUidContactGroup,
274 as returned by Type().
276 Objects of this class are constructed using CContactDatabase::CreateContactGroupL()
277 or CreateContactGroupLC(). These functions create the group, optionally with
278 a label, add it to the database, and return a pointer to it.
280 To create an association between a card and a group, use CContactDatabase::AddContactToGroupL()
281 and to remove the association, use RemoveContactFromGroupL(). To find out
282 which groups a card belongs to, use CContactCard::GroupsJoinedLC() or CContactOwnCard::GroupsJoinedLC().
284 The function CContactDatabase::GetGroupIdListL() may be used to retrieve a
285 list of IDs for all groups in the database.
291 IMPORT_C static CContactGroup* NewL();
292 IMPORT_C static CContactGroup* NewLC();
293 IMPORT_C ~CContactGroup();
294 public: // from CContactItem
295 IMPORT_C TUid Type() const;
297 // default sorted item array is ascending
298 IMPORT_C CContactIdArray* ItemsContainedLC() const;
299 IMPORT_C const CContactIdArray* ItemsContained() const;
300 IMPORT_C TBool IsSystem() const;
301 IMPORT_C void SetSystem(TBool aSystem);
302 IMPORT_C TBool ContainsItem(TContactItemId aContactId);
303 IMPORT_C void SetGroupLabelL(const TDesC& aLabel);
304 IMPORT_C TPtrC GetGroupLabelL();
305 IMPORT_C TBool HasItemLabelField();
306 IMPORT_C CContactIdArray* GroupsJoinedLC() const;
308 IMPORT_C void AddContactL(TContactItemId aContactId);
309 IMPORT_C void RemoveContactL(TContactItemId aContactId);
310 virtual void ExternalizeL(RWriteStream& aStream) const;
311 virtual void InternalizeL(RReadStream& aStream);
313 IMPORT_C void ResetItems();
314 IMPORT_C void SetItems(CContactIdArray* aItems);
320 CContactIdArray* iItems;
321 friend class CContactDatabase;
322 friend class RPplGroupMembershipTable;
325 class CContactCardTemplate : public CContactItem
326 /** A contact card template.
328 This is a contact item containing a set of fields on which new contact items can
329 be based. Templates have a label which is a string which identifies the template
330 to a user. For instance, 'work template' could indicate a template used
331 to create contact cards in the style of a work colleague. Contact card templates
332 have a type of KUidContactCardTemplate, as returned by Type().
334 Objects of this class cannot be constructed directly because its constructors
335 are protected. Instead, use either CContactDatabase::CreateContactCardTemplateL()
336 or CreateContactCardTemplateLC(). These functions create a contact card template,
337 add it to the database, and return a pointer to it.
339 The function CContactDatabase::GetCardTemplateIdListL() gets a list of the
340 IDs of all contact card templates in the database.
345 friend class CContactDatabase;
346 friend class CContactTables;
347 friend class RPplContactTable;
348 friend class CContactItem;
350 IMPORT_C void SetTemplateLabelL(const TDesC& aLabel);
351 IMPORT_C TPtrC GetTemplateLabelL();
353 IMPORT_C static CContactCardTemplate* NewL();
354 IMPORT_C static CContactCardTemplate* NewLC();
355 IMPORT_C static CContactCardTemplate* NewL(const CContactItem *aTemplate);
356 IMPORT_C static CContactCardTemplate* NewLC(const CContactItem *aTemplate);
357 IMPORT_C TBool HasItemLabelField();
359 /** Intended usage: Reserved to preserve future BC */
360 IMPORT_C void ReservedFunction1();
361 /** Intended usage: Reserved to preserve future BC */
362 IMPORT_C void ReservedFunction2();
364 protected: // from CContactItem
365 IMPORT_C TUid Type() const;
368 CContactCardTemplate();
371 class CContactCard : public CContactItemPlusGroup
374 Implements the Type() function declared in class CContactItem.
375 Contact cards may optionally be constructed from a template.
381 IMPORT_C ~CContactCard();
382 IMPORT_C static CContactCard* NewL();
383 IMPORT_C static CContactCard* NewLC();
384 IMPORT_C static CContactCard* NewL(const CContactItem *aTemplate);
385 IMPORT_C static CContactCard* NewLC(const CContactItem *aTemplate);
386 public: // from CContactItem
387 IMPORT_C TUid Type() const;
389 IMPORT_C CContactIdArray* GroupsJoinedLC() const;
393 friend class CContactDatabase;
396 class CContactOwnCard : public CContactItemPlusGroup
399 An own card is a contact card which contains information about the device's
400 owner. This can be sent to another compatible electronic device as a vCard.
401 The contact database recognises a single own card, referred to as the
402 current own card; its ID is returned by CContactDatabase::OwnCardId(). Like
403 a contact card, an own card can be a member of one or more contact card groups.
404 The own card type is identified by a UID of KUidContactOwnCard.
406 Own cards can be constructed using either CContactDatabase::CreateOwnCardLC()
407 or CreateOwnCardL(). These functions create an own card, based on the system
408 template, add it to the database, set it as the database's current own card
409 and return a pointer to it. To change the database's current own card, use
410 CContactDatabase::SetOwnCardL().
416 IMPORT_C ~CContactOwnCard();
417 IMPORT_C static CContactOwnCard* NewL();
418 IMPORT_C static CContactOwnCard* NewLC();
419 IMPORT_C static CContactOwnCard* NewL(const CContactItem *aTemplate);
420 IMPORT_C static CContactOwnCard* NewLC(const CContactItem *aTemplate);
421 public: // from CContactItem
422 IMPORT_C TUid Type() const;
424 IMPORT_C CContactIdArray* GroupsJoinedLC() const;
428 friend class CContactDatabase;
431 class CContactTemplate : public CContactItem
432 /** A contact item template.
434 This is a contact item which is used to seed the initial field set for
437 Non-system (i.e. user-defined) templates are implemented
438 by the CContactCardTemplate class. CContactCardTemplate should be
439 used in preference to CContactTemplate.
445 IMPORT_C static CContactTemplate* NewL();
446 IMPORT_C static CContactTemplate* NewLC();
447 IMPORT_C static CContactTemplate* NewL(const CContactItem *aTemplate);
448 IMPORT_C static CContactTemplate* NewLC(const CContactItem *aTemplate);
449 public: // from CContactItem
450 IMPORT_C TUid Type() const;
456 class CContactICCEntry : public CContactItemPlusGroup
457 /** A contact ICC entry.
463 IMPORT_C ~CContactICCEntry();
464 IMPORT_C static CContactICCEntry* NewL(const CContactItem& aTemplate);
465 static CContactICCEntry* NewL();
466 public: //from CContactItem
474 /** A globally unique identifier enquiry utility.
476 Each contact item has a unique identifier, stored as a descriptor. It is
477 referred to as the 'UID string'. This is a combination of the unique
478 identifier of the database in which the contact item was created, the
479 contact item ID and the date/time of the contact item's creation. ContactGuid
480 provides a single static exported function to enquire whether an item was
481 created in a specified database.
487 IMPORT_C static TContactItemId IsLocalContactUidString(const TDesC& aString, TInt64 aMachineUniqueId);
488 IMPORT_C static TBool GetCreationDate(TDes& aString, TInt64 aMachineUniqueId);
489 static HBufC* CreateGuidLC(const TDesC& aCreationDate,TContactItemId aId, TInt64 aMachineUniqueId);
490 static HBufC* CreateGuidLC(const TTime& aCreationDate,TContactItemId aId, TInt64 aMachineUniqueId);
491 static HBufC* CreateGuidLC(TContactItemId aId, TInt64 aMachineUniqueId);
494 inline const CContactItemField& CContactItemFieldSet::operator[](TInt aIndex) const
495 /** Gets the field located at a specified position in the field set.
497 @param aIndex The position of the field in the field set. This is relative to zero.
498 It must be non-negative and less than the number of objects in the array, otherwise
499 the operator raises a panic.
501 @return A const reference to an element in the array. */
502 { return *(*iFields)[aIndex]; }
504 inline CContactItemField& CContactItemFieldSet::operator[](TInt aIndex)
505 /** Gets the field located at a specified position in the field set.
507 @param aIndex The position of the field in the field set. This is relative to zero.
508 It must be non-negative and less than the number of objects in the array, otherwise
509 the operator raises a panic.
511 @return A non-const reference to an element in the array. */
512 { return *(*iFields)[aIndex]; }
514 inline TInt CContactItemFieldSet::Find(TFieldType aFieldType) const
515 /** Finds the first field in the field set with the specified field type.
517 @param aFieldType The field type of interest.
518 @return If found, the index of the field within the field set, or KErrNotFound
520 { return FindNext(aFieldType,KContactFieldSetSearchAll); }
522 inline TInt CContactItemFieldSet::Find(TFieldType aFieldType,TUid aMapping) const
523 /** Finds the first field in the field set containing both the content type mapping
524 and the field type specified.
526 @param aFieldType The field type of interest.
527 @param aMapping The content type mapping of interest.
528 @return If found, the index of the field within the field set, or KErrNotFound
530 { return FindNext(aFieldType,aMapping,KContactFieldSetSearchAll); }
532 inline TInt CContactItemFieldSet::Count() const
533 /** Gets the number of fields in the field set.
535 @return The number of fields in the field set. */
536 { return iFields->Count(); }
538 inline void CContactItemFieldSet::Reset()
539 /** Deletes all fields in the field set. */
540 { iFields->ResetAndDestroy(); }
542 inline TBool CContactItem::IsDeletable()
543 /** Tests whether the contact item is deletable.
545 This is true if the item's access count is zero.
547 @return ETrue if deletable, EFalse if not deletable. */
548 {return (iAccessCount == 0);}
550 inline void CContactItem::IncAccessCount()
551 /** Increments the contact item's access count. */
554 inline void CContactItem::DecAccessCount()
555 /** Decrements the contact item's access count. */
556 {if(iAccessCount) iAccessCount--;}
558 inline TInt CContactItem::AccessCount() const
559 /** Gets the contact item's access count.
561 @return The item's access count. */
562 {return(iAccessCount);}
564 inline TPtrC CContactItem::Guid()
565 /** Accessor function for Contact Guid.
566 * This is used to cache contact items that are added during a sync.
568 { return iGuid ? *iGuid : TPtrC(KNullDesC); }