2 * Copyright (c) 2002 Nokia Corporation and/or its subsidiary(-ies).
4 * This component and the accompanying materials are made available
5 * under the terms of "Eclipse Public License v1.0"
6 * which accompanies this distribution, and is available
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
9 * Initial Contributors:
10 * Nokia Corporation - initial contribution.
15 * Phonebook Contact item class.
20 #ifndef __CPbkContactItem_H__
21 #define __CPbkContactItem_H__
24 #include <e32base.h> // CBase, CArrayFixFlat
25 #include "MPbkFieldData.h" // MPbkFieldDataArray
26 #include "PbkFields.hrh" // TPbkFieldId
27 #include "TPbkContactItemField.h"
29 // FORWARD DECLARATIONS
32 class CContactItemField;
34 class MPbkContactNameFormat;
40 * Array of TPbkContactItemField instances.
42 class CPbkFieldArray : public CArrayFixFlat<TPbkContactItemField>
47 /// Default array reallocation granularity
48 KDefaultGranularity = 8
54 inline CPbkFieldArray()
55 : CArrayFixFlat<TPbkContactItemField>(KDefaultGranularity)
61 * @param aGranularity Reallocation granularity of this array.
63 inline CPbkFieldArray(TInt aGranurality)
64 : CArrayFixFlat<TPbkContactItemField>(aGranurality)
71 * Phonebook Contact item class. Contact items can be read from the contact
72 * database by using the Phonebook engine, @see CPbkContactEngine.
73 * This class extends Symbian Contacts model class CContactItem capabilities
74 * to better suit Phonebook application's needs.
76 class CPbkContactItem :
77 public CBase, public MPbkFieldDataArray
79 public: // Constructor and destructor
81 * Creates an instance of this class.
83 * @param aItem Contact item this object wraps. This object
84 * takes ownership of aItem. If this function
85 * leaves, ownership is not taken.
86 * @param aFieldsInfo Collection of Phonebook field types.
87 * @param aNameFormat Contact name formatter.
88 * @return A new instance of this class.
90 IMPORT_C static CPbkContactItem* NewL(
92 const CPbkFieldsInfo& aFieldsInfo,
93 MPbkContactNameFormat& aNameFormat);
100 public: // CContactItem functions
102 * Returns this contact item's id.
103 * @see CContactItem::Id()
105 IMPORT_C TContactItemId Id() const;
108 * Returns type of this contact item. The contact types are documented in
109 * the Symbian Contacts model CContactItem::Type().
110 * @return Contact type.
111 * @see CContactItem::Type()
113 IMPORT_C TUid Type() const;
116 * Gets the groups this contact belongs to.
117 * @return Array of group ids. Caller owns the array.
118 * @see CContactItem::GroupsJoinedLC()
120 IMPORT_C CContactIdArray* GroupsJoinedLC() const;
123 * Converts this object to a CContactItem. Use only if this class's API
125 * @return The underlying Symbian Contacts model contact item object.
127 IMPORT_C CContactItem& ContactItem();
130 * Converts this object to a const CContactItem. Use only if this
131 * class's API is not enough.
132 * @return The underlying Symbian Contacts model contact item object.
134 IMPORT_C const CContactItem& ContactItem() const;
136 public: // Field set operations
138 * Returns the field set of this contact item.
139 * @return Field array of this contact item.
141 IMPORT_C CPbkFieldArray& CardFields() const;
144 * Creates a new field based on aFieldInfo and adds it to this contact.
146 * @param aFieldInfo Type of field to create.
147 * @return The created field.
149 IMPORT_C TPbkContactItemField& AddFieldL(CPbkFieldInfo& aFieldInfo);
152 * Returns ETrue if data of type aFieldInfo can be added to this
154 * @param aFieldInfo The field type that we are trying to add.
155 * @return ETrue if the contact can accept this type of data, EFalse
158 IMPORT_C TBool CanAcceptDataOfType(CPbkFieldInfo& aFieldInfo) const;
161 * Finds an unused or creates a new field based on aFieldInfo. An
162 * unused field is a field that is in the contact template, but
163 * doesnt contain any data, in other words it is empty. So a unused
164 * field is preferred ad the next field to add user data before
165 * adding a new field to the contact.
167 * @param aFieldInfo Type of field to search or create.
168 * @return Pointer to the found or created field. NULL only if<br>
169 * field exists AND <br>
170 * field is nonempty AND <br>
171 * aFieldInfo.Multiplicity()==EPbkFieldMultiplicityOne.
173 IMPORT_C TPbkContactItemField* AddOrReturnUnusedFieldL
174 (CPbkFieldInfo& aFieldInfo);
177 * Deletes field at aIndex.
178 * @param aIndex Field index to delete from the contact item.
180 IMPORT_C void RemoveField(TInt aIndex);
183 * Updates this contacts field set to match the field set of
184 * the owned CContactItem. No need to call unless contact item's
185 * field set has been manipulated directly. In other words
186 * remaps the field types of this contact item from the underlying
187 * Symbian Contacts model contact item.
188 * @param aFieldsInfo The new fields set for this contact.
190 IMPORT_C void UpdateFieldSetL(const CPbkFieldsInfo& aFieldsInfo);
192 public: // Field searching
194 * Returns first field matching aFieldId.
196 * @param aFieldId Field id to search.
197 * @return First field matching aFieldId, NULL if none found.
199 IMPORT_C TPbkContactItemField* FindField(TPbkFieldId aFieldId) const;
202 * Returns first field matching aFieldId starting from aIndex.
204 * @param aFieldId Field id to search.
205 * @param aIndex Input: field index where to start the search from,
206 * output: index of the found field or -1 if not found.
207 * @return Field matching aFieldId, NULL if none found.
209 IMPORT_C TPbkContactItemField* FindField
210 (TPbkFieldId aFieldId, TInt& aIndex) const;
213 * Returns first field matching aFieldInfo.
215 * @param aFieldInfo Field type to find from the contact.
216 * @return First field matching aFieldInfo, NULL if none found.
218 IMPORT_C TPbkContactItemField* FindField(const CPbkFieldInfo& aFieldInfo) const;
221 * Returns first field matching aFieldInfo starting from aIndex.
223 * @param aFieldInfo Field type to find from the contact.
224 * @param aIndex Input: field index where to start the search from,
225 * output: index of the found field or -1 if not found.
226 * @return Field matching aFieldInfo, NULL if none found.
228 IMPORT_C TPbkContactItemField* FindField
229 (const CPbkFieldInfo& aFieldInfo, TInt& aIndex) const;
232 * Returns aField's index from this contact item.
234 * @param aField Field to search for. Field is matched with
235 * TPbkContactItemField::IsSame -function.
236 * @return Index of aField in this contact item's field set,
237 * KErrNotFound if not found.
238 * @see TPbkContactItemField::IsSame
240 IMPORT_C TInt FindFieldIndex(const TPbkContactItemField& aField) const;
243 * Returns aField's index from ContactItem()'s CardFields() or
244 * KErrNotFound if not found.
245 * @param aField The field which index we are querying.
246 * @return The fields index in this contact item, KErrNotFound is not found.
248 IMPORT_C TInt FindContactItemFieldIndex(const CContactItemField& aField) const;
251 * Searches phone number fields of this contact for a match.
252 * Uses PbkEngUtils::ContainSameDigits to perform the matching.
254 * @param aNumber Phone number to match to.
255 * @param aNumberOfDigits Number of digits to compare from the end
256 * of the phone numbers. Full comparison
258 * @param aIndex Input: field index where to start the search from,
259 * output: index of the found field or KErrNotFound if not found.
260 * @return The matching field, NULL if not found.
261 * @see PbkEngUtils::ContainSameDigits
263 IMPORT_C TPbkContactItemField* FindNextFieldWithPhoneNumber
264 (const TDesC& aNumber,
265 TInt aNumberOfDigits,
269 * Searches for a text in this contact's fields. Uses TDesC::FindF()
270 * search the text from the fields.
272 * @param aIndex Input: field index from where to start the search,
273 * Output: index of the found field or KErrNotFound
275 * @return The matching field, NULL if not found.
278 IMPORT_C TPbkContactItemField* FindNextFieldWithText
283 * Returns field matching aField from this contact item's field set, NULL if
285 * @param aField The field that we a mathing.
286 * @return Matching field or NULL if not found.
287 * @postcond !FindSameField(field) || FindSameField(field)->IsSame(field)
289 IMPORT_C TPbkContactItemField* FindSameField
290 (const TPbkContactItemField& aField) const;
292 public: // Contact presentation
294 * Gets a title text for this contact or localized unnamed text.
296 * @return A buffer containing the title or localized unnamed text if no
297 * title can be generated. Caller is responsible for deleting
298 * the returned buffer.
300 IMPORT_C HBufC* GetContactTitleL() const;
303 * Gets a title text for this contact.
305 * @return A buffer containing the title text, NULL if title is empty.
306 * Caller is responsible for deleting the returned buffer.
308 IMPORT_C HBufC* GetContactTitleOrNullL() const;
311 * Returns an Phonebook icon id for a contact. This icon id is the icon
312 * of the field that is set as the default number to call.
314 * @return Icon index for this contact, EPbkNullIconId for no icon.
316 IMPORT_C TPbkIconId ContactIconIdL() const;
320 * Returns the default phone number field of this contact.
322 * @return Default phone number field of this contact,
323 * NULL if no default set.
325 IMPORT_C TPbkContactItemField* DefaultPhoneNumberField() const;
328 * Sets this contact's default phone number field to aField.
330 * @param aField Field to set as default, if NULL phone number
331 * default is removed. Guaranteed not to leave if
333 * @exception KErrNotFound If aField is not this contact's field.
334 * @exception KErrNotSupported If aField is not a phone number field.
336 IMPORT_C void SetDefaultPhoneNumberFieldL
337 (TPbkContactItemField* aField);
340 * Removes phone number default from this contact.
342 * @postcond DefaultPhoneNumberField()==NULL.
344 IMPORT_C void RemoveDefaultPhoneNumberField();
347 * Returns the default video number field of this contact.
349 * @return Default video number field of this contact,
350 * NULL if no default set.
352 IMPORT_C TPbkContactItemField* DefaultVideoNumberField() const;
355 * Sets this contact's default video number field to aField.
357 * @param aField Field to set as default, if NULL video number
358 * default is removed. Guaranteed not to leave if
360 * @exception KErrNotFound if aField is not this contact's field.
361 * @exception KErrNotSupported if aField is not a phone number field.
363 IMPORT_C void SetDefaultVideoNumberFieldL
364 (TPbkContactItemField* aField);
367 * Removes video number default from this contact.
369 * @postcond DefaultVideoNumberField()==NULL.
371 IMPORT_C void RemoveDefaultVideoNumberField();
374 * Returns the default SMS field of this contact.
376 * @return Default SMS field of this contact,
377 * NULL if no default set.
379 IMPORT_C TPbkContactItemField* DefaultSmsField() const;
382 * Sets this contact's default SMS field to aField.
384 * @param aField Field to set as default, if NULL SMS
385 * default is removed. Guaranteed not to leave if
387 * @exception KErrNotFound if aField is not this contact's field.
388 * @exception KErrNotSupported if aField is not a phone number field.
390 IMPORT_C void SetDefaultSmsFieldL(TPbkContactItemField* aField);
393 * Removes SMS field default from this contact.
395 * @postcond DefaultSmsField()==NULL.
397 IMPORT_C void RemoveDefaultSmsField();
400 * Returns the default email field of this contact.
402 * @return Default email field of this contact,
403 * NULL if no default set.
405 IMPORT_C TPbkContactItemField* DefaultEmailField() const;
408 * Sets this contact's default email address field to aField.
410 * @param aField Field to set as default, if NULL email
411 * default is removed. Guaranteed not to leave if
413 * @exception KErrNotFound If aField is not this contact's field.
414 * @exception KErrNotSupported If aField is not an email field.
416 IMPORT_C void SetDefaultEmailFieldL(TPbkContactItemField* aField);
419 * Removes email field default from this contact.
421 * @postcond DefaultEmailField()==NULL.
423 IMPORT_C void RemoveDefaultEmailField();
426 * Returns the default Mms field of this contact.
428 * @return Default Mms field of this contact,
429 * NULL if no default set.
431 IMPORT_C TPbkContactItemField* DefaultMmsField() const;
434 * Sets this contact's default MMS address field to aField.
436 * @param aField Field to set as default, if NULL MMS
437 * default is removed. Guaranteed not to leave if
439 * @exception KErrNotFound If aField is not this contact's field.
440 * @exception KErrNotSupported If aField is not an email field.
442 IMPORT_C void SetDefaultMmsFieldL(TPbkContactItemField* aField);
445 * Removes MMS field default from this contact.
447 * @postcond DefaultMmsField()==NULL.
449 IMPORT_C void RemoveDefaultMmsField();
452 * Returns the default Poc field of this contact.
454 * @return Default Poc field of this contact,
455 * NULL if no default set.
457 IMPORT_C TPbkContactItemField* DefaultPocField() const;
460 * Sets this contact's default POC address field to aField.
462 * @param aField Field to set as default, if NULL POC
463 * default is removed. Guaranteed not to leave if
465 * @exception KErrNotFound If aField is not this contact's field.
466 * @exception KErrNotSupported If aField is not an email field.
468 IMPORT_C void SetDefaultPocFieldL(TPbkContactItemField* aField);
471 * Removes POC field default from this contact.
473 * @postcond DefaultPocField()==NULL.
475 IMPORT_C void RemoveDefaultPocField();
478 * Returns the default VOIP field of this contact.
480 * @return Default VOIP field of this contact,
481 * NULL if no default set.
483 IMPORT_C TPbkContactItemField* DefaultVoipField() const;
486 * Sets this contact's default VOIP address field to aField.
488 * @param aField Field to set as default, if NULL VOIP
489 * default is removed. Guaranteed not to leave if
491 * @exception KErrNotFound If aField is not this contact's field.
492 * @exception KErrNotSupported If aField is not an email field.
494 IMPORT_C void SetDefaultVoipFieldL(TPbkContactItemField* aField);
497 * Removes VOIP field default from this contact.
499 * @postcond DefaultVoipField()==NULL.
501 IMPORT_C void RemoveDefaultVoipField();
504 * Returns the default EmailOverSms field of this contact.
506 * @return Default EmailOverSms field of this contact,
507 * NULL if no default set.
509 IMPORT_C TPbkContactItemField* DefaultEmailOverSmsField() const;
512 * Sets this contact's default Sms With Email address field to aField.
514 * @param aField Field to set as default, if NULL Sms With Email
515 * default is removed. Guaranteed not to leave if
517 * @exception KErrNotFound If aField is not this contact's field.
518 * @exception KErrNotSupported If aField is not an email field.
520 IMPORT_C void SetDefaultEmailOverSmsFieldL(TPbkContactItemField* aField);
523 * Removes EmailOverSms field default from this contact.
525 * @postcond DefaultEmailOverSmsField()==NULL.
527 IMPORT_C void RemoveDefaultEmailOverSmsField();
529 public: // Voice tags
531 * Returns the voice tag field of this contact.
532 * NOTE: If this function is unable to make a connection to
533 * the voice tag handling system for some reason, this function will
536 * @return Voice tag field of this contact,
537 * NULL if no voice tag set.
540 IMPORT_C TPbkContactItemField* VoiceTagField() const;
543 * Sets this contact's voice tag field to aField.
545 * @param aField Field to set as default, if NULL voice tag mark
546 * is removed. Guaranteed not to leave if
548 * @exception KErrNotFound If aField is not this contact's field.
549 * @exception KErrNotSupported If aField is not a phone number field.
550 * @postcond (aField && VoiceTagField()->IsSame(*aField)) || (!aField && !VoiceTagField())
553 IMPORT_C void SetVoiceTagFieldL(TPbkContactItemField* aField);
556 * Removes any voice tag mark from this contact.
558 * @postcond VoiceTagField()==NULL.
561 IMPORT_C void RemoveVoiceTagField();
563 public: // from MPbkFieldDataArray
564 TInt PbkFieldCount() const;
565 MPbkFieldData& PbkFieldAt(TInt aIndex);
566 const MPbkFieldData& PbkFieldAt(TInt aIndex) const;
568 public: // Phonebook internal functions, do not call
571 * Prepares this contact for saving into the contact database.
572 * @see PrepareAfterLoad
575 void PrepareForSaveL();
579 * Prepares this contact after loading it from the contact database.
580 * @see PrepareForSaveL
583 void PrepareAfterLoadL();
585 private: // Implementation
586 CPbkContactItem(MPbkContactNameFormat& aNameFormat);
587 void ConstructL(CContactItem* aItem, const CPbkFieldsInfo& aFieldsInfo);
588 void CreateFieldArrayL(CContactItem& aContactItem, const CPbkFieldsInfo& aFieldsInfo);
589 TInt InsertionPos(const TPbkContactItemField& aField) const;
591 typedef CPbkContactItem SelfType;
594 /// Own: Embedded contact item.
596 /// Own: array of phonebook contact item fields
597 CPbkFieldArray iFields;
598 /// Ref: Contact name formatting API
599 MPbkContactNameFormat& iNameFormat;
601 private: // Friend declarations
602 friend IMPORT_C TBool operator==
603 (const CPbkContactItem& aLeft, const CPbkContactItem& aRight);
607 // FUNCTION DECLARATIONS
610 * Returns ETrue if aLeft and aRight contents are the same.
612 IMPORT_C TBool operator==
613 (const CPbkContactItem& aLeft, const CPbkContactItem& aRight);
616 * Returns ETrue if aLeft and aRight contents differ.
618 inline TBool operator!=
619 (const CPbkContactItem& aLeft, const CPbkContactItem& aRight)
621 return !(aLeft==aRight);
625 #endif // __CPbkContactItem_H__