epoc32/include/app/CPbkContactItem.h
author William Roberts <williamr@symbian.org>
Wed, 31 Mar 2010 12:33:34 +0100
branchSymbian3
changeset 4 837f303aceeb
permissions -rw-r--r--
Current Symbian^3 public API header files (from PDK 3.0.h)
This is the epoc32/include tree with the "platform" subtrees removed, and
all but a selected few mbg and rsg files removed.
     1 /*
     2 * Copyright (c) 2002 Nokia Corporation and/or its subsidiary(-ies).
     3 * All rights reserved.
     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".
     8 *
     9 * Initial Contributors:
    10 * Nokia Corporation - initial contribution.
    11 *
    12 * Contributors:
    13 *
    14 * Description: 
    15 *     Phonebook Contact item class.
    16 *
    17 */
    18 
    19 
    20 #ifndef __CPbkContactItem_H__
    21 #define __CPbkContactItem_H__
    22 
    23 //  INCLUDES
    24 #include <e32base.h>        // CBase, CArrayFixFlat
    25 #include "MPbkFieldData.h"  // MPbkFieldDataArray
    26 #include "PbkFields.hrh"    // TPbkFieldId
    27 #include "TPbkContactItemField.h"
    28 
    29 // FORWARD DECLARATIONS
    30 class CPbkFieldsInfo;
    31 class CPbkFieldInfo;
    32 class CContactItemField;
    33 class CContactItem;
    34 class MPbkContactNameFormat;
    35 
    36 
    37 // CLASS DECLARATION
    38 
    39 /**
    40  * Array of TPbkContactItemField instances.
    41  */
    42 class CPbkFieldArray : public CArrayFixFlat<TPbkContactItemField>
    43     {
    44     public:
    45         enum
    46             {
    47             /// Default array reallocation granularity
    48             KDefaultGranularity = 8
    49             };
    50 
    51         /** 
    52          * Constructor.
    53          */
    54         inline CPbkFieldArray() 
    55             : CArrayFixFlat<TPbkContactItemField>(KDefaultGranularity)
    56             {
    57             }
    58 
    59         /**
    60          * Constructor.
    61          * @param aGranularity  Reallocation granularity of this array.
    62          */
    63         inline CPbkFieldArray(TInt aGranurality) 
    64             : CArrayFixFlat<TPbkContactItemField>(aGranurality)
    65             {
    66             }
    67     };
    68 
    69 
    70 /**
    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.
    75  */
    76 class CPbkContactItem : 
    77         public CBase, public MPbkFieldDataArray
    78     {
    79     public:  // Constructor and destructor
    80         /**
    81          * Creates an instance of this class.
    82          *
    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.
    89          */
    90         IMPORT_C static CPbkContactItem* NewL(
    91                 CContactItem* aItem, 
    92                 const CPbkFieldsInfo& aFieldsInfo, 
    93                 MPbkContactNameFormat& aNameFormat);
    94 
    95         /**
    96          * Destructor.
    97          */
    98         ~CPbkContactItem();
    99 
   100     public: // CContactItem functions
   101         /**
   102          * Returns this contact item's id.
   103          * @see CContactItem::Id()
   104          */
   105         IMPORT_C TContactItemId Id() const;
   106         
   107         /**
   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()
   112          */
   113         IMPORT_C TUid Type() const;
   114 
   115         /**
   116          * Gets the groups this contact belongs to.
   117          * @return Array of group ids. Caller owns the array.
   118          * @see CContactItem::GroupsJoinedLC()
   119          */
   120         IMPORT_C CContactIdArray* GroupsJoinedLC() const;
   121 
   122         /**
   123          * Converts this object to a CContactItem. Use only if this class's API
   124          * is not enough.
   125          * @return  The underlying Symbian Contacts model contact item object.
   126          */
   127         IMPORT_C CContactItem& ContactItem();
   128 
   129         /**
   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.
   133          */
   134         IMPORT_C const CContactItem& ContactItem() const;
   135 
   136     public:  // Field set operations
   137         /**
   138          * Returns the field set of this contact item.
   139          * @return  Field array of this contact item.
   140          */
   141         IMPORT_C CPbkFieldArray& CardFields() const;
   142 
   143         /**
   144          * Creates a new field based on aFieldInfo and adds it to this contact.
   145          *
   146          * @param aFieldInfo    Type of field to create.
   147          * @return The created field.
   148          */
   149       	IMPORT_C TPbkContactItemField& AddFieldL(CPbkFieldInfo& aFieldInfo);
   150 
   151         /**
   152          * Returns ETrue if data of type aFieldInfo can be added to this 
   153          * contact.
   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
   156          *          otherwise.
   157          */
   158         IMPORT_C TBool CanAcceptDataOfType(CPbkFieldInfo& aFieldInfo) const;
   159 
   160         /**
   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.
   166          *
   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.
   172          */
   173       	IMPORT_C TPbkContactItemField* AddOrReturnUnusedFieldL
   174             (CPbkFieldInfo& aFieldInfo);
   175 
   176         /**
   177          * Deletes field at aIndex.
   178          * @param aIndex    Field index to delete from the contact item.
   179          */
   180         IMPORT_C void RemoveField(TInt aIndex);
   181 
   182         /**
   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.
   189          */
   190         IMPORT_C void UpdateFieldSetL(const CPbkFieldsInfo& aFieldsInfo);
   191 
   192     public:  // Field searching
   193         /**
   194          * Returns first field matching aFieldId.
   195          *
   196          * @param aFieldId  Field id to search.
   197          * @return First field matching aFieldId, NULL if none found.
   198          */
   199         IMPORT_C TPbkContactItemField* FindField(TPbkFieldId aFieldId) const;
   200 
   201         /**
   202          * Returns first field matching aFieldId starting from aIndex.
   203          *
   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.
   208          */
   209         IMPORT_C TPbkContactItemField* FindField
   210             (TPbkFieldId aFieldId, TInt& aIndex) const;
   211 
   212         /**
   213          * Returns first field matching aFieldInfo.
   214          *
   215          * @param aFieldInfo    Field type to find from the contact.
   216          * @return First field matching aFieldInfo, NULL if none found.
   217          */
   218         IMPORT_C TPbkContactItemField* FindField(const CPbkFieldInfo& aFieldInfo) const;
   219 
   220         /**
   221          * Returns first field matching aFieldInfo starting from aIndex.
   222          *
   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.
   227          */
   228         IMPORT_C TPbkContactItemField* FindField
   229             (const CPbkFieldInfo& aFieldInfo, TInt& aIndex) const;
   230 
   231         /**
   232          * Returns aField's index from this contact item.
   233          *
   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
   239          */
   240         IMPORT_C TInt FindFieldIndex(const TPbkContactItemField& aField) const;
   241 
   242         /**
   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.
   247          */
   248         IMPORT_C TInt FindContactItemFieldIndex(const CContactItemField& aField) const;
   249 
   250         /**
   251          * Searches phone number fields of this contact for a match.
   252          * Uses PbkEngUtils::ContainSameDigits to perform the matching.
   253          *
   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
   257          *                          performed if 0.
   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
   262          */
   263         IMPORT_C TPbkContactItemField* FindNextFieldWithPhoneNumber
   264             (const TDesC& aNumber,
   265             TInt aNumberOfDigits,
   266             TInt &aIndex) const;
   267 
   268         /**
   269          * Searches for a text in this contact's fields. Uses TDesC::FindF()
   270          * search the text from the fields.
   271          *
   272          * @param aIndex    Input: field index from where to start the search,
   273          *                  Output: index of the found field or KErrNotFound 
   274          *                  if not found.
   275          * @return The matching field, NULL if not found.
   276          * @see TDesC::FindF
   277          */
   278         IMPORT_C TPbkContactItemField* FindNextFieldWithText
   279             (const TDesC& aText,
   280             TInt& aIndex) const;
   281 
   282         /**
   283          * Returns field matching aField from this contact item's field set, NULL if
   284          * not found.
   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)
   288          */
   289         IMPORT_C TPbkContactItemField* FindSameField
   290             (const TPbkContactItemField& aField) const;
   291 
   292     public: // Contact presentation
   293         /**
   294          * Gets a title text for this contact or localized unnamed text.
   295          *
   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.
   299          */
   300         IMPORT_C HBufC* GetContactTitleL() const;
   301 
   302         /**
   303          * Gets a title text for this contact.
   304          *
   305          * @return  A buffer containing the title text, NULL if title is empty.
   306          *          Caller is responsible for deleting the returned buffer.
   307          */
   308         IMPORT_C HBufC* GetContactTitleOrNullL() const;
   309 
   310         /**
   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.
   313          *
   314          * @return  Icon index for this contact, EPbkNullIconId for no icon.
   315          */
   316         IMPORT_C TPbkIconId ContactIconIdL() const;
   317 
   318     public:  // Defaults
   319         /**
   320          * Returns the default phone number field of this contact.
   321          *
   322          * @return  Default phone number field of this contact, 
   323          *          NULL if no default set.
   324          */
   325         IMPORT_C TPbkContactItemField* DefaultPhoneNumberField() const;
   326 
   327         /**
   328          * Sets this contact's default phone number field to aField.
   329          *
   330          * @param aField    Field to set as default, if NULL phone number
   331          *                  default is removed. Guaranteed not to leave if
   332          *                  aField is NULL.
   333          * @exception KErrNotFound  If aField is not this contact's field.
   334          * @exception KErrNotSupported  If aField is not a phone number field.
   335          */
   336         IMPORT_C void SetDefaultPhoneNumberFieldL
   337             (TPbkContactItemField* aField);
   338 
   339         /**
   340          * Removes phone number default from this contact.
   341          *
   342          * @postcond DefaultPhoneNumberField()==NULL.
   343          */
   344         IMPORT_C void RemoveDefaultPhoneNumberField();
   345 
   346         /**
   347          * Returns the default video number field of this contact.
   348          *
   349          * @return  Default video number field of this contact, 
   350          *          NULL if no default set.
   351          */
   352         IMPORT_C TPbkContactItemField* DefaultVideoNumberField() const;
   353 
   354         /**
   355          * Sets this contact's default video number field to aField.
   356          *
   357          * @param aField    Field to set as default, if NULL video number
   358          *                  default is removed. Guaranteed not to leave if
   359          *                  aField is NULL.
   360          * @exception KErrNotFound  if aField is not this contact's field.
   361          * @exception KErrNotSupported  if aField is not a phone number field.
   362          */
   363         IMPORT_C void SetDefaultVideoNumberFieldL
   364             (TPbkContactItemField* aField);
   365 
   366         /**
   367          * Removes video number default from this contact.
   368          *
   369          * @postcond DefaultVideoNumberField()==NULL.
   370          */
   371         IMPORT_C void RemoveDefaultVideoNumberField();
   372 
   373         /**
   374          * Returns the default SMS field of this contact.
   375          *
   376          * @return  Default SMS field of this contact, 
   377          *          NULL if no default set.
   378          */
   379         IMPORT_C TPbkContactItemField* DefaultSmsField() const;
   380 
   381         /**
   382          * Sets this contact's default SMS field to aField.
   383          *
   384          * @param aField    Field to set as default, if NULL SMS
   385          *                  default is removed. Guaranteed not to leave if
   386          *                  aField is NULL.
   387          * @exception KErrNotFound  if aField is not this contact's field.
   388          * @exception KErrNotSupported  if aField is not a phone number field.
   389          */
   390         IMPORT_C void SetDefaultSmsFieldL(TPbkContactItemField* aField);
   391 
   392         /**
   393          * Removes SMS field default from this contact.
   394          *
   395          * @postcond DefaultSmsField()==NULL.
   396          */
   397         IMPORT_C void RemoveDefaultSmsField();
   398 
   399         /**
   400          * Returns the default email field of this contact.
   401          *
   402          * @return  Default email field of this contact, 
   403          *          NULL if no default set.
   404          */
   405         IMPORT_C TPbkContactItemField* DefaultEmailField() const;
   406 
   407         /**
   408          * Sets this contact's default email address field to aField.
   409          *
   410          * @param aField    Field to set as default, if NULL email 
   411          *                  default is removed. Guaranteed not to leave if
   412          *                  aField is NULL.
   413          * @exception KErrNotFound  If aField is not this contact's field.
   414          * @exception KErrNotSupported  If aField is not an email field.
   415          */
   416         IMPORT_C void SetDefaultEmailFieldL(TPbkContactItemField* aField);
   417 
   418         /**
   419          * Removes email field default from this contact.
   420          *
   421          * @postcond DefaultEmailField()==NULL.
   422          */
   423         IMPORT_C void RemoveDefaultEmailField();
   424 
   425         /**
   426          * Returns the default Mms field of this contact.
   427          *
   428          * @return  Default Mms field of this contact, 
   429          *          NULL if no default set.
   430          */
   431         IMPORT_C TPbkContactItemField* DefaultMmsField() const;
   432 
   433         /**
   434          * Sets this contact's default MMS address field to aField.
   435          *
   436          * @param aField    Field to set as default, if NULL MMS 
   437          *                  default is removed. Guaranteed not to leave if
   438          *                  aField is NULL.
   439          * @exception KErrNotFound  If aField is not this contact's field.
   440          * @exception KErrNotSupported  If aField is not an email field.
   441          */
   442         IMPORT_C void SetDefaultMmsFieldL(TPbkContactItemField* aField);
   443 
   444         /**
   445          * Removes MMS field default from this contact.
   446          *
   447          * @postcond DefaultMmsField()==NULL.
   448          */
   449         IMPORT_C void RemoveDefaultMmsField();
   450 
   451         /**
   452          * Returns the default Poc field of this contact.
   453          *
   454          * @return  Default Poc field of this contact, 
   455          *          NULL if no default set.
   456          */
   457         IMPORT_C TPbkContactItemField* DefaultPocField() const;
   458 
   459         /**
   460          * Sets this contact's default POC address field to aField.
   461          *
   462          * @param aField    Field to set as default, if NULL POC 
   463          *                  default is removed. Guaranteed not to leave if
   464          *                  aField is NULL.
   465          * @exception KErrNotFound  If aField is not this contact's field.
   466          * @exception KErrNotSupported  If aField is not an email field.
   467          */
   468         IMPORT_C void SetDefaultPocFieldL(TPbkContactItemField* aField);
   469 
   470         /**
   471          * Removes POC field default from this contact.
   472          *
   473          * @postcond DefaultPocField()==NULL.
   474          */
   475         IMPORT_C void RemoveDefaultPocField();
   476         
   477         /**
   478          * Returns the default VOIP field of this contact.
   479          *
   480          * @return  Default VOIP field of this contact, 
   481          *          NULL if no default set.
   482          */
   483         IMPORT_C TPbkContactItemField* DefaultVoipField() const;
   484 
   485         /**
   486          * Sets this contact's default VOIP address field to aField.
   487          *
   488          * @param aField    Field to set as default, if NULL VOIP 
   489          *                  default is removed. Guaranteed not to leave if
   490          *                  aField is NULL.
   491          * @exception KErrNotFound  If aField is not this contact's field.
   492          * @exception KErrNotSupported  If aField is not an email field.
   493          */
   494         IMPORT_C void SetDefaultVoipFieldL(TPbkContactItemField* aField);
   495 
   496         /**
   497          * Removes VOIP field default from this contact.
   498          *
   499          * @postcond DefaultVoipField()==NULL.
   500          */
   501         IMPORT_C void RemoveDefaultVoipField();
   502         
   503         /**
   504          * Returns the default EmailOverSms field of this contact.
   505          *
   506          * @return  Default EmailOverSms field of this contact, 
   507          *          NULL if no default set.
   508          */
   509         IMPORT_C TPbkContactItemField* DefaultEmailOverSmsField() const;
   510         
   511         /**
   512          * Sets this contact's default Sms With Email address field to aField.
   513          *
   514          * @param aField    Field to set as default, if NULL Sms With Email 
   515          *                  default is removed. Guaranteed not to leave if
   516          *                  aField is NULL.
   517          * @exception KErrNotFound  If aField is not this contact's field.
   518          * @exception KErrNotSupported  If aField is not an email field.
   519          */
   520         IMPORT_C void SetDefaultEmailOverSmsFieldL(TPbkContactItemField* aField);
   521         
   522         /**
   523          * Removes EmailOverSms field default from this contact.
   524          *
   525          * @postcond DefaultEmailOverSmsField()==NULL.
   526          */
   527         IMPORT_C void RemoveDefaultEmailOverSmsField();
   528 
   529     public:  // Voice tags
   530         /**
   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 
   534          * return null.
   535          *
   536          * @return  Voice tag field of this contact, 
   537          *          NULL if no voice tag set.
   538          * @deprecated
   539          */
   540         IMPORT_C TPbkContactItemField* VoiceTagField() const;
   541 
   542         /**
   543          * Sets this contact's voice tag field to aField.
   544          *
   545          * @param aField    Field to set as default, if NULL voice tag mark
   546          *                  is removed. Guaranteed not to leave if
   547          *                  aField is NULL.
   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())
   551          * @deprecated
   552          */
   553         IMPORT_C void SetVoiceTagFieldL(TPbkContactItemField* aField);
   554 
   555         /**
   556          * Removes any voice tag mark from this contact.
   557          *
   558          * @postcond VoiceTagField()==NULL.
   559          * @deprecated
   560          */
   561         IMPORT_C void RemoveVoiceTagField();
   562 
   563     public:  // from MPbkFieldDataArray
   564         TInt PbkFieldCount() const;
   565         MPbkFieldData& PbkFieldAt(TInt aIndex);
   566         const MPbkFieldData& PbkFieldAt(TInt aIndex) const;
   567 
   568     public: // Phonebook internal functions, do not call
   569         /**
   570          * @internal
   571          * Prepares this contact for saving into the contact database.
   572          * @see PrepareAfterLoad
   573          * @deprecated
   574          */
   575         void PrepareForSaveL();
   576 
   577         /**
   578          * @internal
   579          * Prepares this contact after loading it from the contact database.
   580          * @see PrepareForSaveL
   581          * @deprecated
   582          */
   583         void PrepareAfterLoadL();
   584         
   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;
   590         __DECLARE_TEST;
   591         typedef CPbkContactItem SelfType;
   592 
   593     private:    // Data
   594         /// Own: Embedded contact item.
   595         CContactItem* iItem;
   596         /// Own: array of phonebook contact item fields
   597         CPbkFieldArray iFields;
   598         /// Ref: Contact name formatting API
   599         MPbkContactNameFormat& iNameFormat;
   600 
   601     private:  // Friend declarations
   602         friend IMPORT_C TBool operator==
   603             (const CPbkContactItem& aLeft, const CPbkContactItem& aRight);
   604     };
   605 
   606 
   607 // FUNCTION DECLARATIONS
   608 
   609 /**
   610  * Returns ETrue if aLeft and aRight contents are the same.
   611  */
   612 IMPORT_C TBool operator==
   613     (const CPbkContactItem& aLeft, const CPbkContactItem& aRight);
   614 
   615 /**
   616  * Returns ETrue if aLeft and aRight contents differ.
   617  */
   618 inline TBool operator!=
   619     (const CPbkContactItem& aLeft, const CPbkContactItem& aRight)
   620     {
   621     return !(aLeft==aRight);
   622     }
   623 
   624 
   625 #endif // __CPbkContactItem_H__
   626             
   627 // End of File