phonebookui/Phonebook2/UIControls/src/CPbk2FieldAnalyzer.cpp
changeset 0 e686773b3f54
child 68 9da50d567e3c
equal deleted inserted replaced
-1:000000000000 0:e686773b3f54
       
     1 /*
       
     2 * Copyright (c) 2002-2007 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 *       Provides methods for Phonebook 2 field analyzer.
       
    16 *
       
    17 */
       
    18 
       
    19 
       
    20 // INCLUDE FILES
       
    21 #include "CPbk2FieldAnalyzer.h"
       
    22 
       
    23 // Phonebook 2
       
    24 #include <CPbk2PresentationContactField.h>
       
    25 
       
    26 // Virtual Phonebook
       
    27 #include <MVPbkStoreContactField.h>
       
    28 #include <MVPbkContactStoreProperties.h>
       
    29 #include <MVPbkContactStore.h>
       
    30 #include <CVPbkContactManager.h>
       
    31 #include <CVPbkSpeedDialAttribute.h>
       
    32 #include <MVPbkStoreContactFieldCollection.h>
       
    33 #include <VPbkEng.rsg>
       
    34 #include <MVPbkFieldType.h>
       
    35 #include <CVPbkContactFieldIterator.h>
       
    36 #include <MVPbkContactFieldUriData.h>
       
    37 
       
    38 // System
       
    39 #include <featmgr.h>
       
    40 #include <spsettings.h>
       
    41 #include <spentry.h>
       
    42 #include <spproperty.h>
       
    43 #include <crcseprofileregistry.h>
       
    44 
       
    45 namespace   // Unnamed namespace. Used to break down the VoipSupportL method
       
    46 {
       
    47 /*
       
    48 *	Check whether there is any voip capable settings in the 
       
    49 *   phone's Service Provider Settings
       
    50 */
       
    51 
       
    52 void BasicSupportL(TInt& aVoipFlag)
       
    53     {    
       
    54     TBool supported( EFalse );
       
    55     RIdArray idArray;
       
    56     CleanupClosePushL(idArray);
       
    57     CSPSettings* settings = CSPSettings::NewLC();
       
    58     
       
    59     User::LeaveIfError( settings->FindServiceIdsL(idArray) );
       
    60     for (TInt i = 0; !supported && i < idArray.Count(); ++i)
       
    61         {
       
    62         CSPEntry* entry = CSPEntry::NewLC();
       
    63         TServiceId id = idArray[i];
       
    64         User::LeaveIfError( settings->FindEntryL(id, *entry) );
       
    65         const CSPProperty* property = NULL;
       
    66         if (entry->GetProperty(property, ESubPropertyVoIPSettingsId) == KErrNone)
       
    67             {
       
    68             supported = ETrue;
       
    69             }
       
    70 
       
    71         if (entry->GetProperty(property, EPropertyServiceAttributeMask) == KErrNone)
       
    72             {
       
    73             TInt value = 0;
       
    74             property->GetValue(value);
       
    75             supported = value & ESupportsInternetCall; 
       
    76             }
       
    77 
       
    78         CleanupStack::PopAndDestroy(); // entry
       
    79         }
       
    80     
       
    81     if (supported)
       
    82         {
       
    83         aVoipFlag |= MPbk2FieldAnalyzer::EVoIPSupportBasic;
       
    84         }
       
    85 	
       
    86     if( settings->IsFeatureSupported( ESupportCallOutFeature ) )
       
    87         {
       
    88         aVoipFlag |= MPbk2FieldAnalyzer::EVoIPSupportCallout;
       
    89 		}
       
    90     
       
    91     CleanupStack::PopAndDestroy(2); // settings, idArray
       
    92     }
       
    93 /*
       
    94 *	Check whether there is any SIP settings in the phone's Service Provider Settings
       
    95 */
       
    96 
       
    97 void CleanupResetAndDestroy(TAny*  aItem)
       
    98 	{
       
    99 	RPointerArray<CRCSEProfileEntry> *pMyArray = (RPointerArray<CRCSEProfileEntry>*) aItem;
       
   100 	pMyArray->ResetAndDestroy();
       
   101 	pMyArray->Close();
       
   102 	}
       
   103 
       
   104 void SipSupportL(TInt& aVoipFlag)
       
   105     { 
       
   106     TBool found( EFalse );
       
   107     RPointerArray<CRCSEProfileEntry> entries;
       
   108     CleanupStack::PushL( TCleanupItem( CleanupResetAndDestroy, &entries ) );
       
   109         
       
   110     CSPSettings* settings = CSPSettings::NewLC();
       
   111     RIdArray idArray;
       
   112     CleanupClosePushL(idArray);
       
   113         
       
   114     User::LeaveIfError( settings->FindServiceIdsL(idArray) );
       
   115     CRCSEProfileRegistry* profileRegistry = CRCSEProfileRegistry::NewLC();
       
   116 	// Check if we have atleast one SPSetting entry
       
   117 	// Any entry in this array uses SIP protocol for VoIP
       
   118     TInt count = idArray.Count();
       
   119 	for (TInt i = 0; !found && i < count; ++i)
       
   120         {
       
   121         profileRegistry->FindByServiceIdL( idArray[i], entries );
       
   122         if (entries.Count() > 0)
       
   123             {
       
   124             aVoipFlag |= MPbk2FieldAnalyzer::EVoIPSupportSip;
       
   125             found = ETrue;
       
   126             }
       
   127         }       
       
   128     
       
   129     CleanupStack::PopAndDestroy( 4 ); // entries, idArray, settings, profileRegistry
       
   130     }
       
   131 /*
       
   132 *	Check whether the Xsp fields specified in the IMPP field of the contact
       
   133 * 	support voip (not necessarily SIP)
       
   134 */
       
   135 
       
   136 void XspSupportL(CVPbkContactManager& aContactManager, 
       
   137         const MVPbkBaseContactFieldCollection& aFields, TInt& aVoipFlag)
       
   138     {
       
   139     
       
   140     TBool found( EFalse );
       
   141     RIdArray ids;
       
   142     CleanupClosePushL( ids );
       
   143     CSPSettings* settings = CSPSettings::NewLC();
       
   144     
       
   145     CDesCArrayFlat* nameArray = new ( ELeave ) CDesCArrayFlat( 2 );
       
   146     CleanupStack::PushL( nameArray );
       
   147     
       
   148     TInt error = settings->FindServiceIdsL( ids );  
       
   149     User::LeaveIfError( error );     
       
   150     error = settings->FindServiceNamesL( ids, *nameArray );
       
   151 	User::LeaveIfError( error );
       
   152     const TInt count = nameArray->MdcaCount();	
       
   153 
       
   154     const MVPbkFieldType* type = aContactManager.FieldTypes().Find( R_VPBK_FIELD_TYPE_IMPP );
       
   155     CVPbkBaseContactFieldTypeIterator* itr = CVPbkBaseContactFieldTypeIterator::NewLC( *type, aFields );
       
   156     
       
   157     while( itr->HasNext() && !found )
       
   158         {
       
   159         const MVPbkBaseContactField* field = itr->Next();
       
   160         const MVPbkContactFieldUriData& uri = MVPbkContactFieldUriData::Cast( field->FieldData() );
       
   161         TPtrC scheme( uri.Scheme() );
       
   162         
       
   163         for ( TInt i = 0; !found && i < count; i++ )
       
   164             {
       
   165             TPtrC desc = nameArray->MdcaPoint( i );
       
   166             if ( !desc.CompareF( scheme ) )
       
   167                 {
       
   168                 CSPProperty* property = CSPProperty::NewLC();
       
   169                 error = settings->FindPropertyL( ids[i], EPropertyServiceAttributeMask, *property );
       
   170                 if ( KErrNone == error )
       
   171                     {
       
   172                     TInt value = 0; 
       
   173                     property->GetValue( value );                    
       
   174                     if ( value & ESupportsInternetCall )
       
   175                         {
       
   176                         found = ETrue;
       
   177                         aVoipFlag |= MPbk2FieldAnalyzer::EVoIPSupportXspId;                
       
   178                         }
       
   179                     }
       
   180                 CleanupStack::PopAndDestroy();  //property
       
   181                 break;
       
   182                 }
       
   183             }
       
   184         }
       
   185     CleanupStack::PopAndDestroy( 4 );  //nameArray, settings, ids, itr    
       
   186     }
       
   187 }
       
   188 
       
   189 // --------------------------------------------------------------------------
       
   190 // CPbk2FieldAnalyzer::CPbk2FieldAnalyzer
       
   191 // --------------------------------------------------------------------------
       
   192 //
       
   193 CPbk2FieldAnalyzer::CPbk2FieldAnalyzer( 
       
   194         CVPbkContactManager& aContactManager ) : 
       
   195     iContactManager( aContactManager ),
       
   196     iVoiceTaggedFields (NULL)
       
   197 	{
       
   198 	// Do nothing
       
   199 	}
       
   200 
       
   201 // --------------------------------------------------------------------------
       
   202 // CPbk2FieldAnalyzer::NewL
       
   203 // --------------------------------------------------------------------------
       
   204 //
       
   205 CPbk2FieldAnalyzer* CPbk2FieldAnalyzer::NewL( 
       
   206         CVPbkContactManager& aContactManager )
       
   207     {
       
   208     CPbk2FieldAnalyzer* self = new (ELeave) CPbk2FieldAnalyzer( 
       
   209         aContactManager);
       
   210     return self;
       
   211     }
       
   212 
       
   213 // --------------------------------------------------------------------------
       
   214 // CPbk2FieldAnalyzer::~CPbk2FieldAnalyzer
       
   215 // --------------------------------------------------------------------------
       
   216 //
       
   217 CPbk2FieldAnalyzer::~CPbk2FieldAnalyzer()
       
   218     {
       
   219     delete iVoiceTaggedFields;
       
   220     }
       
   221 
       
   222 // --------------------------------------------------------------------------
       
   223 // CPbk2FieldAnalyzer::HasSpeedDialL
       
   224 // --------------------------------------------------------------------------
       
   225 //
       
   226 TBool CPbk2FieldAnalyzer::HasSpeedDialL( 
       
   227         const MVPbkStoreContactField& aField ) const
       
   228     {
       
   229     return iContactManager.ContactAttributeManagerL().HasFieldAttributeL
       
   230            ( CVPbkSpeedDialAttribute::Uid(), aField );
       
   231     }
       
   232 
       
   233 
       
   234 // --------------------------------------------------------------------------
       
   235 // CPbk2FieldAnalyzer::HasVoiceTagL
       
   236 // --------------------------------------------------------------------------
       
   237 //
       
   238 TBool CPbk2FieldAnalyzer::HasVoiceTagL( 
       
   239         const MVPbkStoreContactField& aField ) const
       
   240     {
       
   241     TBool ret = EFalse;
       
   242 
       
   243     if (iVoiceTaggedFields)
       
   244         {
       
   245         // look into voice tag container to see if this field had a voice tag    
       
   246         const TInt count = iVoiceTaggedFields->FieldCount();
       
   247         for ( TInt i = 0; i < count && !ret; ++i )
       
   248             {
       
   249             MVPbkStoreContactField& voiceTagField = iVoiceTaggedFields->FieldAt(i);            
       
   250             if (aField.IsSame(voiceTagField))
       
   251                 {
       
   252                 ret = ETrue;
       
   253                 }
       
   254             }
       
   255         }
       
   256     return ret;    
       
   257     }
       
   258 
       
   259 
       
   260 // --------------------------------------------------------------------------
       
   261 // CPbk2FieldAnalyzer::IsHiddenField
       
   262 // --------------------------------------------------------------------------
       
   263 //
       
   264 TBool CPbk2FieldAnalyzer::IsHiddenField( 
       
   265         const CPbk2PresentationContactField& aField ) const
       
   266     {
       
   267     return !aField.IsVisibleInDetailsView();
       
   268     }
       
   269 
       
   270 // --------------------------------------------------------------------------
       
   271 // CPbk2FieldAnalyzer::SetVoiceTagFields
       
   272 // --------------------------------------------------------------------------
       
   273 //
       
   274 void CPbk2FieldAnalyzer::SetVoiceTagFields(
       
   275         MVPbkStoreContactFieldCollection* aFields)
       
   276     {
       
   277     delete iVoiceTaggedFields;
       
   278     iVoiceTaggedFields = aFields;
       
   279     }
       
   280 
       
   281 const TInt CPbk2FieldAnalyzer::VoipSupportL( const MVPbkBaseContactFieldCollection& aFields ) const
       
   282     {
       
   283     TInt supported( 0 );
       
   284     
       
   285     if ( FeatureManager::FeatureSupported(KFeatureIdCommonVoip) )
       
   286     	{
       
   287         BasicSupportL( supported );
       
   288         SipSupportL( supported );
       
   289         XspSupportL( iContactManager, aFields, supported );
       
   290     	}
       
   291     return supported;    
       
   292     
       
   293     }
       
   294 
       
   295 TBool CPbk2FieldAnalyzer::IsFieldVoipCapable( TInt aVpbkFieldResId, const TInt aVoipFlag ) const
       
   296     {
       
   297     TBool ret( EFalse );
       
   298     
       
   299     if ( FeatureManager::FeatureSupported(KFeatureIdCommonVoip) )
       
   300         {
       
   301         if ( EVoIPSupportBasic & aVoipFlag && 
       
   302            ( R_VPBK_FIELD_TYPE_VOIPGEN == aVpbkFieldResId 
       
   303           || R_VPBK_FIELD_TYPE_VOIPHOME == aVpbkFieldResId
       
   304           || R_VPBK_FIELD_TYPE_VOIPWORK == aVpbkFieldResId
       
   305           || R_VPBK_FIELD_TYPE_POC == aVpbkFieldResId
       
   306           || R_VPBK_FIELD_TYPE_SWIS == aVpbkFieldResId ) )
       
   307             {
       
   308             ret = ETrue;
       
   309             }
       
   310         if ( EVoIPSupportSip & aVoipFlag && 
       
   311           ( R_VPBK_FIELD_TYPE_SIP == aVpbkFieldResId ) )
       
   312             {
       
   313             ret = ETrue;
       
   314             }
       
   315         if ( EVoIPSupportXspId & aVoipFlag && 
       
   316           ( R_VPBK_FIELD_TYPE_IMPP == aVpbkFieldResId  ) )
       
   317             {
       
   318             ret = ETrue;
       
   319             }
       
   320         if ( EVoIPSupportCallout & aVoipFlag && 
       
   321            ( R_VPBK_FIELD_TYPE_MOBILEPHONEGEN == aVpbkFieldResId
       
   322           || R_VPBK_FIELD_TYPE_MOBILEPHONEHOME == aVpbkFieldResId
       
   323           || R_VPBK_FIELD_TYPE_MOBILEPHONEWORK == aVpbkFieldResId
       
   324           || R_VPBK_FIELD_TYPE_LANDPHONEGEN == aVpbkFieldResId
       
   325           || R_VPBK_FIELD_TYPE_LANDPHONEHOME == aVpbkFieldResId
       
   326           || R_VPBK_FIELD_TYPE_LANDPHONEWORK == aVpbkFieldResId
       
   327           || R_VPBK_FIELD_TYPE_ASSTPHONE == aVpbkFieldResId
       
   328           || R_VPBK_FIELD_TYPE_CARPHONE == aVpbkFieldResId ) )
       
   329             {
       
   330             ret = ETrue;
       
   331             }
       
   332         }
       
   333     
       
   334     return ret;
       
   335     }
       
   336 
       
   337 
       
   338 //  End of File