javaextensions/pim/cntadapter/inc.s60/cpimcontactitemadapter.h
changeset 21 2a9601315dfc
equal deleted inserted replaced
18:e8e63152f320 21:2a9601315dfc
       
     1 /*
       
     2 * Copyright (c) 2008 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:  Handles conversion between PIM API Contact Items and Contacts
       
    15  *                Model Contact Cards.
       
    16  *
       
    17 */
       
    18 
       
    19 
       
    20 #ifndef CPIMCONTACTITEMADAPTER_H
       
    21 #define CPIMCONTACTITEMADAPTER_H
       
    22 
       
    23 // INTERNAL INCLUDES
       
    24 #include "pimcommon.h"
       
    25 #include "pimcontact.h"
       
    26 
       
    27 // EXTERNAL INCLUDES
       
    28 #include <e32base.h>
       
    29 #include <badesca.h>
       
    30 #include <cntdef.h>
       
    31 
       
    32 // CONSTANTS
       
    33 
       
    34 /** Maximum lengths of address elements in S60 */
       
    35 const TInt KContactAddrElemMaxLengths[EPIMContactAddrNumElements] =
       
    36 {
       
    37     20, // P.O.Box
       
    38     50, // Extra/Extension
       
    39     50, // Street
       
    40     50, // City
       
    41     50, // State/Region
       
    42     20, // Postal code
       
    43     50 // Country
       
    44 };
       
    45 
       
    46 /** Maximum lengths of name elements in S60 */
       
    47 const TInt KContactNameElemMaxLengths[EPIMContactNameNumElements] =
       
    48 {
       
    49     50, // Family/surname
       
    50     50, // Given/First name
       
    51     50, // Other
       
    52     10, // Prefix
       
    53     10, // Suffix
       
    54     50, // Family name reading
       
    55     50 // Given name reading
       
    56 };
       
    57 
       
    58 /**
       
    59  * Maximum lengths of standard string field values in S60.
       
    60  * An offset to the table is found by substracting
       
    61  * KContactStringMaxLengthsOffset from a field id.
       
    62  */
       
    63 const TInt KContactStringMaxLengths[] =
       
    64 {
       
    65     KErrNotFound, // EPIMContactAddr
       
    66     KErrNotFound, // EPIMContactBirthday
       
    67     KErrNotFound, // EPIMContactClass
       
    68     150, // EPIMContactEmail
       
    69     KErrNotSupported, // EPIMContactFormattedAddr
       
    70     KErrNotSupported, // EPIMContactFormattedName
       
    71     KErrNotFound, // EPIMContactName
       
    72     50, // EPIMContactNickname
       
    73     1000, // EPIMContactNote
       
    74     50, // EPIMContactOrg
       
    75     KErrNotFound, // EPIMContactPhoto
       
    76     KErrNotFound, // EPIMContactPhotoUrl
       
    77     KErrNotSupported, // EPIMContactPublicKey
       
    78     KErrNotSupported, // EPIMContactPublicKeyString
       
    79     KErrNotFound, // EPIMContactRevision
       
    80     48, // EPIMContactTel
       
    81     50, // EPIMContactTitle
       
    82     KErrNotFound, // EPIMContactUid
       
    83     1000 // EPIMContactUrl
       
    84 };
       
    85 
       
    86 const TInt KContactStringMaxLengthsOffset = 100;
       
    87 const TInt KContactStringMaxLengthsLen = sizeof(KContactStringMaxLengths)
       
    88         / sizeof(TInt);
       
    89 
       
    90 /**
       
    91  * Maximum lengths of extended string field values in S60.
       
    92  */
       
    93 const TInt KContactExtStringMaxLengths[] =
       
    94 {
       
    95     50, // Extended WV user ID
       
    96     100, // Extended SIP
       
    97     60, // Extended DTFM
       
    98     50, // Extended Department
       
    99     50, // Extended Assistant name
       
   100     50, // Extended Children
       
   101     50, // Extended Spouse
       
   102     KErrNotFound, // Extended Anniversary
       
   103     100, // Extended VOIP
       
   104     100, // Extended PTT
       
   105     100 // Extended SWIS
       
   106 };
       
   107 
       
   108 const TInt KContactExtStringMaxLengthOffset = 0x1005001;
       
   109 const TInt KContactExtStringMaxLengthsLen = sizeof(KContactExtStringMaxLengths)
       
   110         / sizeof(TInt);
       
   111 
       
   112 // FORWARD DECLARATIONS
       
   113 class CPIMContactCategoryManager;
       
   114 class CContactCard;
       
   115 class CViewContact;
       
   116 class RContactViewSortOrder;
       
   117 class MPIMContactItem;
       
   118 class MPIMItemData;
       
   119 class CContentType;
       
   120 class CContactItemField;
       
   121 class CPIMImageScaler;
       
   122 class CPIMContactFieldInfo;
       
   123 
       
   124 // CLASS DECLARATION
       
   125 
       
   126 /**
       
   127  * Contact Item Adapter
       
   128  * Converts Contact Items from PIM representation to Contacts Model
       
   129  * representation and vice versa.
       
   130  */
       
   131 NONSHARABLE_CLASS(CPIMContactItemAdapter): public CBase
       
   132 {
       
   133 public: // Constructor and destructor
       
   134     /**
       
   135      * Two-phased constructor.
       
   136      */
       
   137     static CPIMContactItemAdapter* NewL(
       
   138         CPIMContactCategoryManager& aCategoryManager);
       
   139 
       
   140     /**
       
   141      * Destructor.
       
   142      */
       
   143     ~CPIMContactItemAdapter();
       
   144 
       
   145 public: // new methods
       
   146     /**
       
   147      * Converts from a PIM item data to a Contacts Model contact card.
       
   148      *
       
   149      * @param aItem The item to convert
       
   150      *
       
   151      * @return A contact card with the same information as given in
       
   152      *         the parameter item. The \b ownership of the card is
       
   153      *         transferred to the caller.
       
   154      *
       
   155      * @par Leaving:
       
   156      * This leaves on an error with system wide error codes.
       
   157      * @par NOTE!
       
   158      * The debug version of this method panics if the item contains
       
   159      * unsupported fields!
       
   160      */
       
   161     CContactCard* CardL(const MPIMContactItem& aItem);
       
   162 
       
   163     /**
       
   164      * Converts from a Contacts Model contact card to the PIM
       
   165      * representation.
       
   166      *
       
   167      * @param aItem Item data container to fill with the data
       
   168      * @param aCard Contact card to convert
       
   169      *
       
   170      * @par Leaving:
       
   171      *  - KErrNotFound: The contact belongs to a group which either does not
       
   172      *                  exist, or does not have a label. In other words, the
       
   173      *                  database has been corrupted.
       
   174      *  - This method may also leave with other system wide error codes.
       
   175      */
       
   176     void FillItemL(MPIMContactItem& aItem, const CContactCard& aCard);
       
   177 
       
   178 
       
   179     /**
       
   180      * Updates the data in the Contacts Model contact card to match
       
   181      * the data in the PIM item data container.
       
   182      *
       
   183      * @param aItem Item from which the data is read
       
   184      * @param aCard The card which is updated
       
   185      *
       
   186      * @par Leaving:
       
   187      * This leaves on an error with system wide error codes.
       
   188      * @par NOTE!
       
   189      * The debug version of this method panics if the item contains
       
   190      * unsupported fields!
       
   191      */
       
   192     void UpdateCardL(const MPIMContactItem& aItem,
       
   193                      CContactCard& aCard);
       
   194 
       
   195     /**
       
   196      * Updates the category information in the database.
       
   197      *
       
   198      * @param aItem Item which contains the category information which
       
   199      *              is used in the update.
       
   200      * @param aCard the card which is updated.
       
   201      *
       
   202      * @par Leaving:
       
   203      *  - KErrNotFound: There is something fishy about the groups in the
       
   204      *                  database.
       
   205      */
       
   206     void UpdateCategoriesL(const MPIMContactItem& aItem,
       
   207                            const CContactCard& aCard);
       
   208 
       
   209     /**
       
   210      * Returns Contacts model field which is mapped to the PIM contact
       
   211      * field. Ownership of the returned array is transferred to the caller
       
   212      *
       
   213      * @return Mapped Contacts Model fields
       
   214      */
       
   215     CArrayFix< TInt>* ContactsModelFieldTypeL(
       
   216         TPIMContactField aContactField) const;
       
   217 
       
   218 private:
       
   219     /**
       
   220      * C++ constructor.
       
   221      */
       
   222     CPIMContactItemAdapter(CPIMContactCategoryManager& aCategoryManager);
       
   223 
       
   224     /**
       
   225      * Symbian 2nd phase constructor.
       
   226      */
       
   227     void ConstructL();
       
   228 
       
   229     /**
       
   230      * Deletes all the supported fields from the contact card.
       
   231      * Those fields which are not supported are left as is.
       
   232      *
       
   233      * @param aCard The card which is cleaned
       
   234      *
       
   235      */
       
   236     void CleanCard(CContactCard& aCard);
       
   237 
       
   238     /**
       
   239      * Checks if we support this particular contact field.
       
   240      *
       
   241      * @param aField The field which is checked
       
   242      *
       
   243      * @return ETrue if the field is supported, EFalse otherwise
       
   244      *
       
   245      */
       
   246     TBool IsSupportedField(CContactItemField& aField);
       
   247 
       
   248     /**
       
   249      * Converts a field from a PIM Item to a Contact Card.
       
   250      *
       
   251      * @param aItem item to read the field from
       
   252      * @param aCard card to write the field to
       
   253      * @param aField field to convert
       
   254      *
       
   255      * @par Leaving:
       
   256      * This method leaves on error with system wide error codes.
       
   257      * @par NOTE!
       
   258      * The debug version of this method panics if the field is unsupported!
       
   259      */
       
   260     void ConvertFieldL(const MPIMContactItem& aItem,
       
   261                        CContactCard& aCard,
       
   262                        TPIMContactField aField);
       
   263 
       
   264     /**
       
   265      * Converts a field from a Contact Card to a PIM Item
       
   266      *
       
   267      * @param aField field to read the data from
       
   268      * @param aItem item to write the data to
       
   269      *
       
   270      * @par Leaving:
       
   271      * This method leaves on an error with system wide error codes.
       
   272      */
       
   273     void ConvertFieldL(const CContactItemField& aField,
       
   274                        MPIMContactItem& aItem);
       
   275 
       
   276     /**
       
   277      * Converts a text field from a Contact Card to a PIM Item
       
   278      *
       
   279      * @param aField field to read the data from
       
   280      * @param aItem item to write the data to
       
   281      *
       
   282      * @par Leaving:
       
   283      * This method leaves on error with system wide error codes
       
   284      */
       
   285     void ConvertTextFieldL(const CContactItemField& aField,
       
   286                            MPIMContactItem& aItem);
       
   287 
       
   288     /**
       
   289      * Adds a string field to the item, and optionally sets the
       
   290      * fields label.
       
   291      *
       
   292      * @param aItem item to which the string field is added
       
   293      * @param aField field type
       
   294      * @param aAttributes attributes of the field to be added
       
   295      * @param aInternalAttributes Internal attributes of the field
       
   296      * @param aValue value to be added. Ownership gets transferred
       
   297      *        to the item.
       
   298      * @param aLabel label to be set. NULL if default label is to
       
   299      * be used. Ownership gets transferred.
       
   300      */
       
   301     void AddStringFieldWithLabelL(
       
   302         MPIMItemData& aItem,
       
   303         TPIMField aField,
       
   304         TPIMAttribute aAttributes,
       
   305         CArrayFix< TUid>* aInternalAttributes,
       
   306         const TPtrC aValue,
       
   307         const TPtrC aLabel);
       
   308 
       
   309     /**
       
   310      * Converts a date field from a Contact Card to a PIM Item
       
   311      *
       
   312      * @param aField field to read the data from
       
   313      * @param aItem item to write the data to
       
   314      *
       
   315      * @par Leaving:
       
   316      * This method leaves on error with system wide error codes
       
   317      */
       
   318     void ConvertDateFieldL(const CContactItemField& aField,
       
   319                            MPIMContactItem& aItem);
       
   320 
       
   321     /**
       
   322      * Converts a store field from a Contact Card to a PIM Item
       
   323      *
       
   324      * @param aField field to read the data from
       
   325      * @param aItem item to write the data to
       
   326      *
       
   327      * @par Leaving:
       
   328      * This method leaves on error with system wide error codes
       
   329      */
       
   330     void ConvertStoreFieldL(const CContactItemField& aField,
       
   331                             MPIMContactItem& aItem);
       
   332 
       
   333     /**
       
   334      * Adds a name field to a PIM Item
       
   335      *
       
   336      * @param aText text to add
       
   337      * @param aItem item to add the field to
       
   338      * @param aElement element which is added
       
   339      * @param aLabel lable to be set
       
   340      *
       
   341      * @par Leaving:
       
   342      * This method leaves on an error with system wide error codes.
       
   343      */
       
   344     void AddNameFieldToItemL(
       
   345         TPtrC aText,
       
   346         MPIMContactItem& aItem,
       
   347         TPIMContactNameElement aElement,
       
   348         TPtrC aLabel);
       
   349 
       
   350     /**
       
   351      * Adds an addres field to a PIM Item
       
   352      *
       
   353      * @param aText text to add
       
   354      * @param aItem item to add the field to
       
   355      * @param aElement element which is added
       
   356      * @param aAttributes attributes of the address field
       
   357      * @param aLabel label to be set
       
   358      *
       
   359      * @par Leaving:
       
   360      * This method leaves on an error with system wide error codes.
       
   361      */
       
   362     void AddAddressFieldToItemL(
       
   363         TPtrC aText,
       
   364         MPIMContactItem& aItem,
       
   365         TPIMContactAddrElement aElement,
       
   366         TPIMAttribute aAttributes,
       
   367         TPtrC aLabel);
       
   368 
       
   369     /**
       
   370      * Converts an address field from a PIM Item to a Contact Card.
       
   371      *
       
   372      * @param aItem item to read the field from
       
   373      * @param aCard card to write the field to
       
   374      * @param aField field to convert
       
   375      * @param aIndex index to the field to convert
       
   376      * @param aAttributes attributes of the field to convert
       
   377      *
       
   378      * @par Leaving:
       
   379      * This method leaves on an error with system wide error codes.
       
   380      */
       
   381     void ConvertAddressFieldL(
       
   382         const MPIMItemData& aItem,
       
   383         CContactCard& aCard,
       
   384         TPIMContactField aField,
       
   385         TInt aIndex,
       
   386         TPIMAttribute aAttributes);
       
   387 
       
   388     /**
       
   389      * Converts a name field from a PIM Item to a Contact Card.
       
   390      *
       
   391      * @param aItem item to read the field from
       
   392      * @param aCard card to write the field to
       
   393      * @param aField field to convert
       
   394      * @param aIndex index to the field to convert
       
   395      *
       
   396      * @par Leaving:
       
   397      * This method leaves on an error with system wide error codes.
       
   398      */
       
   399     void ConvertNameFieldL(
       
   400         const MPIMItemData& aItem,
       
   401         CContactCard& aCard,
       
   402         TPIMContactField aField,
       
   403         TInt aIndex);
       
   404 
       
   405     /**
       
   406      * Converts a date field from a PIM Item to a Contact Card.
       
   407      *
       
   408      * @param aItem item to read the field from
       
   409      * @param aCard card to write the field to
       
   410      * @param aField field to convert
       
   411      * @param aIndex index to the field to convert
       
   412      *
       
   413      * @par Leaving:
       
   414      * This method leaves on an error with system wide error codes.
       
   415      * @par NOTE!
       
   416      * The debug version of this method panics if the date is not a birthday!
       
   417      */
       
   418     void ConvertDateFieldL(
       
   419         const MPIMItemData& aItem,
       
   420         CContactCard& aCard,
       
   421         TPIMContactField aField,
       
   422         TInt aIndex);
       
   423 
       
   424     /**
       
   425      * Converts a string field from a PIM Item to a Contact Card.
       
   426      *
       
   427      * @param aItem item to read the field from
       
   428      * @param aCard card to write the field to
       
   429      * @param aField field to convert
       
   430      * @param aIndex index to the field to convert
       
   431      *
       
   432      * @par Leaving:
       
   433      * This method leaves on an error with system wide error codes.
       
   434      */
       
   435     void ConvertStringFieldL(
       
   436         const MPIMItemData& aItem,
       
   437         CContactCard& aCard,
       
   438         TPIMContactField aField,
       
   439         TInt aIndex);
       
   440 
       
   441     /**
       
   442      * Converts a photo field from a PIM Item to a Contact Card.
       
   443      *
       
   444      * @param aItem item to read the field from
       
   445      * @param aCard card to write the field to
       
   446      * @param aField field to convert
       
   447      * @param aIndex index to the field to convert
       
   448      *
       
   449      * @par Leaving:
       
   450      * This method may leave.
       
   451      */
       
   452     void ConvertPhotoFieldL(
       
   453         const MPIMItemData& aItem,
       
   454         CContactCard& aCard,
       
   455         TPIMContactField aField,
       
   456         TInt aIndex);
       
   457 
       
   458     /**
       
   459      * Converts a class field from a PIM Item to a Contact Card.
       
   460      *
       
   461      * @param aItemData item to read the field from
       
   462      * @param aCard card to write the field to
       
   463      * @param aField field to convert
       
   464      * @param aIndex index to the field to convert
       
   465      *
       
   466      * @par Leaving:
       
   467      * This method may leave.
       
   468      */
       
   469     void ConvertClassFieldL(
       
   470         const MPIMItemData& aItemData,
       
   471         CContactCard& aCard,
       
   472         TPIMContactField aField,
       
   473         TInt aIndex);
       
   474 
       
   475     /**
       
   476      * Converts a class field from a Contact Card to PIM item
       
   477      *
       
   478      * @param aItemData Item to add the field
       
   479      * @param aClassDesValue Pointer descriptor to the native value
       
   480      * @param aLabel Label for the field
       
   481      *
       
   482      * @par Leaving
       
   483      * This method may leve
       
   484      */
       
   485     void AddClassFieldToItemL(
       
   486         MPIMItemData& aItemData,
       
   487         TPtrC& aClassDesValue,
       
   488         TPtrC aLabel);
       
   489 
       
   490     /**
       
   491      * Checks the attributes in the address values in the given
       
   492      * item, and finds out optimal values for address index
       
   493      * members.
       
   494      * @param aItem item which is checked
       
   495      * @param aPlainAddressIndex the index of address without
       
   496      * attributes is placed here
       
   497      * @param aHomeAddressIndex the index of address with home
       
   498      * attribute is placed here
       
   499      * @param aWorkAddressIndex the index of address with work
       
   500      * attribute is placed here
       
   501      */
       
   502     void AddressAttributesL(const MPIMItemData& aItem,
       
   503                             TInt& aPlainAddressIndex,
       
   504                             TInt& aHomeAddressIndex,
       
   505                             TInt& aWorkAddressIndex);
       
   506 
       
   507     /**
       
   508      * Checks that given string value does not exceed the limit
       
   509      * specified for the given field.
       
   510      */
       
   511     void EnsureValidStringValueLengthL(
       
   512         TPIMContactField aField,
       
   513         const TDesC& aValue);
       
   514 
       
   515     /**
       
   516      * Checks that given address array element does not exceed
       
   517      * a predefined length limit.
       
   518      */
       
   519     void EnsureValidAddrElemLengthL(
       
   520         TPIMContactAddrElement aElemIndex,
       
   521         const TDesC& aElemValue);
       
   522 
       
   523     /**
       
   524      * Checks that given name array element does not exceed
       
   525      * a predefined length limit.
       
   526      */
       
   527     void EnsureValidNameElemLengthL(
       
   528         TPIMContactNameElement aElemIndex,
       
   529         const TDesC& aElemValue);
       
   530 
       
   531 private: // members
       
   532 
       
   533     // Handles categories
       
   534     CPIMContactCategoryManager& iCategoryManager;
       
   535 
       
   536     // Scales bitmaps, owned.
       
   537     CPIMImageScaler* iImageScaler;
       
   538 
       
   539     // Matches Contacts Model fields to PIM contact fields
       
   540     CPIMContactFieldInfo* iFieldInfo;
       
   541 
       
   542 };
       
   543 
       
   544 #endif // CPIMCONTACTITEMADAPTER_H
       
   545 // End of file