phoneengine/PhoneCntFinder/ContactService/src/cphcntcontactfieldsresolver.cpp
changeset 0 5f000ab63145
equal deleted inserted replaced
-1:000000000000 0:5f000ab63145
       
     1 /*
       
     2 * Copyright (c) 2006 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:  Resolves contact's fields
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #include <MVPbkContactLink.h>
       
    20 #include <MVPbkStoreContact.h>
       
    21 #include <MPbk2ContactNameFormatter.h>
       
    22 #include <MVPbkStoreContactFieldCollection.h>
       
    23 #include <MVPbkFieldType.h>
       
    24 #include <MVPbkContactFieldData.h>
       
    25 #include <MVPbkContactFieldTextData.h>
       
    26 #include <MVPbkContactFieldUriData.h>
       
    27 #include <TVPbkFieldVersitProperty.h>
       
    28 #include <VPbkEng.rsg>
       
    29 #include <badesca.h>
       
    30 
       
    31 #include "MPhCntContactManager.h"
       
    32 #include "cphcntcontactfieldsresolver.h"
       
    33 
       
    34 
       
    35 // ======== MEMBER FUNCTIONS ========
       
    36 
       
    37 // ---------------------------------------------------------------------------
       
    38 // Constructor
       
    39 // ---------------------------------------------------------------------------
       
    40 //
       
    41 CPhCntContactFieldsResolver::CPhCntContactFieldsResolver(
       
    42     MVPbkContactLink* aContactLink,
       
    43     MVPbkStoreContact* aContact,
       
    44     MPhCntContactManager& aContactManager ) : 
       
    45     iFirstNameResolver( R_VPBK_FIELD_TYPE_FIRSTNAME ),
       
    46     iLastNameResolver(R_VPBK_FIELD_TYPE_LASTNAME),
       
    47     iCompanyNameResolver( R_VPBK_FIELD_TYPE_COMPANYNAME ),
       
    48     iSecondNameResolver( R_VPBK_FIELD_TYPE_SECONDNAME ),
       
    49     iRingingToneResolver( R_VPBK_FIELD_TYPE_RINGTONE ),
       
    50     iFirstNamePronunciationResolver( R_VPBK_FIELD_TYPE_FIRSTNAMEREADING ),
       
    51     iLastNamePronunciationResolver( R_VPBK_FIELD_TYPE_LASTNAMEREADING ),
       
    52     iCompanyNamePronunciationResolver( R_VPBK_FIELD_TYPE_COMPANYNAME ),
       
    53     iCallImageResolver( R_VPBK_FIELD_TYPE_CALLEROBJIMG ),
       
    54     iCallTextResolver( R_VPBK_FIELD_TYPE_CALLEROBJTEXT ),
       
    55     iDtmfResolver( R_VPBK_FIELD_TYPE_DTMFSTRING ),    	    
       
    56 	iContactLink( aContactLink ),
       
    57     iContact( aContact ),    
       
    58     iContactManager( aContactManager ),
       
    59     iNameFormatter( aContactManager.ContactNameFormatter() )
       
    60     {
       
    61    
       
    62     }
       
    63 
       
    64 
       
    65 // ---------------------------------------------------------------------------
       
    66 // Secondphase constructor.
       
    67 // ---------------------------------------------------------------------------
       
    68 //
       
    69 void CPhCntContactFieldsResolver::ConstructL()
       
    70     {
       
    71     iAllDtmfNumbers = new ( ELeave ) CDesCArrayFlat( 2 );
       
    72     // Check if contactlink is pointing directly to some contact field.
       
    73     // If there is pointed field, then it is going to be in resolved contact fields.
       
    74     // For example there migth be many phonenumbers in contact, but the 
       
    75     // we want to have only the pointed number resolved.
       
    76     MVPbkStoreContactField* field = iContact->Fields().
       
    77         RetrieveField( *iContactLink );
       
    78     if( field != NULL ) 
       
    79         {
       
    80         ResolveFieldL( *field, ETrue );
       
    81         }
       
    82     
       
    83     // Go through the contact's field and resolve the fields.              
       
    84     MVPbkStoreContactFieldCollection& fields = iContact->Fields();
       
    85     const TInt fieldCount( fields.FieldCount() );
       
    86     for( TInt i = 0; i < fieldCount; i++ ) 
       
    87         {
       
    88         MVPbkStoreContactField& field = fields.FieldAt( i );
       
    89         ResolveFieldL( field, EFalse );
       
    90         }
       
    91     }
       
    92     
       
    93 // ---------------------------------------------------------------------------
       
    94 // Resolves contact's fields
       
    95 // ---------------------------------------------------------------------------
       
    96 //
       
    97 void CPhCntContactFieldsResolver::ResolveFieldL( 
       
    98     MVPbkStoreContactField& aContactField, 
       
    99     TBool aFieldPointedByContactLink )
       
   100     {
       
   101      MVPbkContactFieldData& fieldData = aContactField.FieldData();
       
   102         
       
   103     const MVPbkFieldType* fieldType = aContactField.BestMatchingFieldType();
       
   104     if( fieldType ) 
       
   105         {
       
   106         const TInt fieldId( fieldType->FieldTypeResId() );
       
   107         if( fieldData.DataType() == EVPbkFieldStorageTypeText )
       
   108             {
       
   109             const TPtrC fieldTextData = 
       
   110                 MVPbkContactFieldTextData::Cast( fieldData ).Text();
       
   111             
       
   112             ResolveFieldDataL( aContactField,
       
   113                                fieldTextData,
       
   114                                aFieldPointedByContactLink );   
       
   115                                        
       
   116             // DTMF field is only used if the contact link was pointing to it.
       
   117             if( aFieldPointedByContactLink )
       
   118                 {
       
   119                 iDtmfResolver.Resolve( 
       
   120                     fieldId, 
       
   121                     fieldTextData, 
       
   122                     aFieldPointedByContactLink );
       
   123                 }
       
   124                 
       
   125              if ( fieldId == R_VPBK_FIELD_TYPE_DTMFSTRING )
       
   126                 {
       
   127                 TRAP_IGNORE( iAllDtmfNumbers->AppendL( fieldTextData ) );
       
   128                 }               
       
   129             }
       
   130         else if ( fieldData.DataType() == EVPbkFieldStorageTypeUri )
       
   131             {
       
   132             MVPbkContactFieldUriData& textData =
       
   133                 MVPbkContactFieldUriData::Cast( fieldData );
       
   134             TPtrC fieldTextData = textData.Text();
       
   135             
       
   136             ResolveFieldDataL( aContactField,
       
   137                                fieldTextData,
       
   138                                aFieldPointedByContactLink );
       
   139                                        
       
   140             }
       
   141             
       
   142         // Check for thumbnail field.
       
   143         if( fieldId == R_VPBK_FIELD_TYPE_THUMBNAILPIC )
       
   144             {
       
   145             iThumbnailField = fieldType;    
       
   146             }
       
   147                 
       
   148         }
       
   149     }
       
   150 
       
   151 // ---------------------------------------------------------------------------
       
   152 // Resolves contact's fields
       
   153 // ---------------------------------------------------------------------------
       
   154 //
       
   155 void CPhCntContactFieldsResolver::ResolveFieldDataL( 
       
   156     MVPbkStoreContactField& aContactField,
       
   157     const TPtrC aFieldTextData,
       
   158     TBool aFieldPointedByContactLink )
       
   159     {
       
   160     MVPbkContactFieldData& fieldData = aContactField.FieldData();
       
   161         
       
   162     const MVPbkFieldType* fieldType = aContactField.BestMatchingFieldType();
       
   163     const TInt fieldId( fieldType->FieldTypeResId() );
       
   164            
       
   165     iPhoneNumberResolver.ResolveL( fieldId, aFieldTextData,
       
   166         aFieldPointedByContactLink, iContactManager, aContactField );
       
   167     iFirstNameResolver.Resolve(  fieldId, aFieldTextData,
       
   168         aFieldPointedByContactLink );
       
   169     iLastNameResolver.Resolve(  fieldId, aFieldTextData,
       
   170         aFieldPointedByContactLink );
       
   171     iCompanyNameResolver.Resolve(  fieldId, aFieldTextData,
       
   172         aFieldPointedByContactLink );
       
   173     iSecondNameResolver.Resolve(  fieldId, aFieldTextData,
       
   174         aFieldPointedByContactLink );
       
   175     iRingingToneResolver.Resolve(  fieldId, aFieldTextData,
       
   176         aFieldPointedByContactLink );
       
   177     iFirstNamePronunciationResolver.Resolve( fieldId, aFieldTextData,
       
   178         aFieldPointedByContactLink );
       
   179     iLastNamePronunciationResolver.Resolve( fieldId, 
       
   180             aFieldTextData, aFieldPointedByContactLink ); 
       
   181     iCompanyNamePronunciationResolver.Resolve( fieldId,
       
   182             aFieldTextData, aFieldPointedByContactLink );
       
   183     
       
   184     iCallImageResolver.Resolve( fieldId, 
       
   185                                 aFieldTextData, 
       
   186                                 aFieldPointedByContactLink ); 
       
   187     
       
   188     iCallTextResolver.Resolve( fieldId, 
       
   189                                aFieldTextData, 
       
   190                                aFieldPointedByContactLink );    
       
   191 
       
   192     }
       
   193 
       
   194 // ---------------------------------------------------------------------------
       
   195 // Constructor
       
   196 // ---------------------------------------------------------------------------
       
   197 //
       
   198 CPhCntContactFieldsResolver* CPhCntContactFieldsResolver::NewL(
       
   199     MVPbkContactLink* aContactLink,
       
   200     MVPbkStoreContact* aContact,
       
   201     MPhCntContactManager& aContactManager )
       
   202     {
       
   203     CPhCntContactFieldsResolver* self = 
       
   204         CPhCntContactFieldsResolver::NewLC(
       
   205             aContactLink, aContact, aContactManager );
       
   206     CleanupStack::Pop( self );
       
   207     return self;
       
   208     }
       
   209 
       
   210 
       
   211 // ---------------------------------------------------------------------------
       
   212 // Static constructor
       
   213 // ---------------------------------------------------------------------------
       
   214 //
       
   215 CPhCntContactFieldsResolver* CPhCntContactFieldsResolver::NewLC(
       
   216     MVPbkContactLink* aContactLink,
       
   217     MVPbkStoreContact* aContact,
       
   218     MPhCntContactManager& aContactManager ) 
       
   219     {
       
   220     CPhCntContactFieldsResolver* self = 
       
   221         new( ELeave ) CPhCntContactFieldsResolver(
       
   222             aContactLink,
       
   223             aContact,
       
   224             aContactManager );
       
   225     CleanupStack::PushL( self );
       
   226     self->ConstructL();
       
   227     return self;
       
   228     }
       
   229 
       
   230 
       
   231 // ---------------------------------------------------------------------------
       
   232 // Destructor
       
   233 // ---------------------------------------------------------------------------
       
   234 //
       
   235 CPhCntContactFieldsResolver::~CPhCntContactFieldsResolver()
       
   236     {
       
   237     delete iContact;
       
   238     delete iContactLink;
       
   239     delete iAllDtmfNumbers;
       
   240     }
       
   241 
       
   242 // ---------------------------------------------------------------------------
       
   243 // From class MPhCntContactFields
       
   244 // ---------------------------------------------------------------------------
       
   245 //
       
   246 MVPbkContactLink* CPhCntContactFieldsResolver::ContactLink() const 
       
   247     {   
       
   248     return iContactLink;
       
   249     }
       
   250   
       
   251 // ---------------------------------------------------------------------------
       
   252 // From class MPhCntContactFields
       
   253 // ---------------------------------------------------------------------------
       
   254 // 
       
   255 MPhCntMatch::TNumberType
       
   256     CPhCntContactFieldsResolver::NumberType() const   
       
   257     {
       
   258     return iPhoneNumberResolver.Number().Type();
       
   259     }    
       
   260 
       
   261 // ---------------------------------------------------------------------------
       
   262 // From class MPhCntContactFields
       
   263 // ---------------------------------------------------------------------------
       
   264 //
       
   265 TPtrC CPhCntContactFieldsResolver::FirstName() const 
       
   266     {
       
   267     return iFirstNameResolver.Data();
       
   268     }
       
   269 
       
   270 // ---------------------------------------------------------------------------
       
   271 // From class MPhCntContactFields
       
   272 // ---------------------------------------------------------------------------
       
   273 //
       
   274 TPtrC CPhCntContactFieldsResolver::LastName() const 
       
   275     {
       
   276     return iLastNameResolver.Data();
       
   277     }
       
   278 
       
   279 // ---------------------------------------------------------------------------
       
   280 // From class MPhCntContactFields
       
   281 // ---------------------------------------------------------------------------
       
   282 //
       
   283 TPtrC CPhCntContactFieldsResolver::CompanyName() const 
       
   284     {
       
   285     return iCompanyNameResolver.Data();
       
   286     }
       
   287 
       
   288 // ---------------------------------------------------------------------------
       
   289 // From class MPhCntContactFields
       
   290 // ---------------------------------------------------------------------------
       
   291 //
       
   292 TPtrC CPhCntContactFieldsResolver::Number() const
       
   293     {
       
   294     return iPhoneNumberResolver.Number().Number();
       
   295     }
       
   296 
       
   297 // ---------------------------------------------------------------------------
       
   298 // From class MPhCntContactFields
       
   299 // ---------------------------------------------------------------------------
       
   300 //   
       
   301 TPtrC CPhCntContactFieldsResolver::Dtmf() const
       
   302     {
       
   303     return iDtmfResolver.Data();
       
   304     }
       
   305 
       
   306 // ---------------------------------------------------------------------------
       
   307 // From class MPhCntContactFields
       
   308 // ---------------------------------------------------------------------------
       
   309 //
       
   310 TPtrC CPhCntContactFieldsResolver::PersonalRingingTone() const 
       
   311     {
       
   312     return iRingingToneResolver.Data();
       
   313     }
       
   314     
       
   315 // ---------------------------------------------------------------------------
       
   316 // From class MPhCntContactFields
       
   317 // ---------------------------------------------------------------------------
       
   318 //
       
   319 TPtrC CPhCntContactFieldsResolver::SecondName() const
       
   320     {
       
   321     return iSecondNameResolver.Data();
       
   322     }
       
   323 
       
   324 // ---------------------------------------------------------------------------
       
   325 // From class MPhCntContactFields
       
   326 // ---------------------------------------------------------------------------
       
   327 //
       
   328 TPtrC CPhCntContactFieldsResolver::FirstNamePronunciation() const
       
   329     {
       
   330     return iFirstNamePronunciationResolver.Data();
       
   331     }
       
   332 
       
   333 // ---------------------------------------------------------------------------
       
   334 // From class MPhCntContactFields
       
   335 // ---------------------------------------------------------------------------
       
   336 //     
       
   337 TPtrC CPhCntContactFieldsResolver::LastNamePronunciation() const
       
   338     {
       
   339     return iLastNamePronunciationResolver.Data();
       
   340     }
       
   341 
       
   342 // ---------------------------------------------------------------------------
       
   343 // From class MPhCntContactFields
       
   344 // ---------------------------------------------------------------------------
       
   345 //    
       
   346 TPtrC CPhCntContactFieldsResolver::CompanyNamePronunciation() const
       
   347     {
       
   348     return iCompanyNamePronunciationResolver.Data();
       
   349     }
       
   350     
       
   351 // ---------------------------------------------------------------------------
       
   352 // From class MPhCntContactFields
       
   353 // ---------------------------------------------------------------------------
       
   354 //
       
   355 HBufC* CPhCntContactFieldsResolver::GetContactTitleL()
       
   356     {
       
   357     return iNameFormatter.GetContactTitleOrNullL(
       
   358         iContact->Fields(), 
       
   359         MPbk2ContactNameFormatter::EPreserveLeadingSpaces | 
       
   360         MPbk2ContactNameFormatter::EUseSeparator |
       
   361         MPbk2ContactNameFormatter::EReplaceNonGraphicChars );
       
   362     }
       
   363 
       
   364 // ---------------------------------------------------------------------------
       
   365 // From class MPhCntContactFields
       
   366 // ---------------------------------------------------------------------------
       
   367 //
       
   368 MVPbkContactLinkArray* CPhCntContactFieldsResolver::ContactGroupsLC() const
       
   369     {
       
   370     return iContact->GroupsJoinedLC();
       
   371     }
       
   372  
       
   373 // ---------------------------------------------------------------------------
       
   374 // From class MPhCntContactFields
       
   375 // ---------------------------------------------------------------------------
       
   376 //   
       
   377  MVPbkStoreContact& CPhCntContactFieldsResolver::StoreContact() const
       
   378     {
       
   379     return *iContact;
       
   380     }
       
   381 
       
   382 // ---------------------------------------------------------------------------
       
   383 // From class MPhCntContactFields
       
   384 // ---------------------------------------------------------------------------
       
   385 //       
       
   386 const MVPbkFieldType* CPhCntContactFieldsResolver::ThumbnailField() const
       
   387     {
       
   388     return iThumbnailField;
       
   389     }
       
   390     
       
   391 // ---------------------------------------------------------------------------
       
   392 // From class MPhCntContactFields
       
   393 // ---------------------------------------------------------------------------
       
   394 // 
       
   395 TPtrC CPhCntContactFieldsResolver::CallImage() const 
       
   396     {
       
   397     return iCallImageResolver.Data();
       
   398     }
       
   399 
       
   400 // ---------------------------------------------------------------------------    
       
   401 // From class MPhCntContactFields
       
   402 // ---------------------------------------------------------------------------
       
   403 //
       
   404 TPtrC CPhCntContactFieldsResolver::CallText() const 
       
   405     {
       
   406     return iCallTextResolver.Data();
       
   407     }
       
   408 
       
   409 // ---------------------------------------------------------------------------    
       
   410 // From class MPhCntContactFields
       
   411 // ---------------------------------------------------------------------------
       
   412 //
       
   413 TBool CPhCntContactFieldsResolver::HasThumbnail() const 
       
   414     {
       
   415     return ( iThumbnailField != NULL );
       
   416     }        
       
   417 
       
   418 // ---------------------------------------------------------------------------    
       
   419 // From class MPhCntContactFields
       
   420 // ---------------------------------------------------------------------------
       
   421 // 
       
   422 const RArray<TPhCntNumber>& CPhCntContactFieldsResolver::AllNumbers() const
       
   423     {
       
   424     return iPhoneNumberResolver.AllNumbers();
       
   425     }
       
   426 
       
   427 // ---------------------------------------------------------------------------    
       
   428 // From class MPhCntContactFields
       
   429 // ---------------------------------------------------------------------------
       
   430 //        
       
   431 CDesCArray* CPhCntContactFieldsResolver::AllDtmfNumbers() const
       
   432     {
       
   433     return iAllDtmfNumbers;
       
   434     }