phonebookui/Phonebook2/UIControls/src/CPbk2MemoryEntryDefaultsDlg.cpp
branchRCL_3
changeset 63 f4a778e096c2
child 64 c1e8ba0c2b16
child 68 9da50d567e3c
equal deleted inserted replaced
62:5b6f26637ad3 63:f4a778e096c2
       
     1 /*
       
     2 * Copyright (c) 2005-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:  Phonebook 2 memory entry defaults dialog.
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 // INCLUDE FILES
       
    20 #include "CPbk2MemoryEntryDefaultsDlg.h"
       
    21 
       
    22 // Phonebook 2
       
    23 #include "CPbk2FieldListBoxModel.h"
       
    24 #include "CPbk2DefaultAttributeProcess.h"
       
    25 #include "CPbk2FieldSelector.h"
       
    26 #include <CPbk2MemoryEntryDefaultsAssignDlg.h>
       
    27 #include <CPbk2IconArray.h>
       
    28 #include <Pbk2UIControls.rsg>
       
    29 #include <CPbk2PresentationContact.h>
       
    30 #include <CPbk2PresentationContactField.h>
       
    31 #include <CPbk2PresentationContactFieldCollection.h>
       
    32 #include <CPbk2FieldPropertyArray.h>
       
    33 #include <CPbk2StorePropertyArray.h>
       
    34 #include <Phonebook2PrivateCRKeys.h>
       
    35 #include <TPbk2DestructionIndicator.h>
       
    36 #include <phonebook2ece.mbg>
       
    37 #include <CPbk2ApplicationServices.h>
       
    38 #include <CPbk2ServiceManager.h>
       
    39 #include <MPbk2ApplicationServices.h>
       
    40 #include <ccappcommlauncherpluginrsc.rsg>
       
    41 
       
    42 // Virtual Phonebook
       
    43 #include <CVPbkContactManager.h>
       
    44 #include <CVPbkDefaultAttribute.h>
       
    45 #include <CVPbkFieldFilter.h>
       
    46 #include <CVPbkFieldTypeSelector.h>
       
    47 #include <MVPbkContactFieldData.h>
       
    48 #include <MVPbkContactOperationBase.h>
       
    49 #include <MVPbkFieldType.h>
       
    50 #include <VPbkFieldType.hrh>
       
    51 #include <TVPbkStoreContactAnalyzer.h>
       
    52 #include <VPbkVariant.hrh>
       
    53 
       
    54 // System includes
       
    55 #include <aknlists.h>   // EikControlFactory
       
    56 #include <barsread.h>
       
    57 #include <StringLoader.h>
       
    58 #include <featmgr.h>
       
    59 #include <centralrepository.h>
       
    60 #include <gulicon.h>
       
    61 #include <AknIconArray.h>
       
    62 #include <eikclbd.h>
       
    63 #include <aknlists.h>
       
    64 #include <aknPopup.h>
       
    65 #include <aknlayoutscalable_avkon.cdl.h>
       
    66 
       
    67 //SpSettings
       
    68 #include <spsettings.h>
       
    69 #include <spentry.h>
       
    70 #include <spproperty.h>
       
    71 
       
    72 
       
    73 // For checking mailbox accounts
       
    74 #include <emailinterfacefactory.h>
       
    75 #include <memailmailbox.h>
       
    76 
       
    77 // Debugging headers
       
    78 #include <Pbk2Debug.h>
       
    79 
       
    80 // LOCAL CONSTANTS AND MACROS
       
    81 
       
    82 const TInt KGranularity = 4;
       
    83 
       
    84 const TUid KCRUidCCACommLauncher = {0x20019548};
       
    85 const TInt KCommunicationMethodOrder  = 0x00000001;
       
    86 const TInt KCCAppCommLauncherMaxOrderBufLength = 128;
       
    87 
       
    88 _LIT( KPbk2ECEIconFileName, "\\resource\\apps\\phonebook2ece.mif" );
       
    89 
       
    90 #ifdef _DEBUG
       
    91 enum TPanicCode
       
    92     {
       
    93     EPanicPostCond_Constructor = 1,
       
    94     EPanicPostCond_ConstructL,
       
    95     EPanicPreCond_FixIndex,
       
    96     EPanicPostCond_FixIndex,
       
    97     EPanicLogic_DefaultFieldL
       
    98     };
       
    99 
       
   100 static void Panic(TPanicCode aReason)
       
   101     {
       
   102     _LIT(KPanicText, "CPbk2MemoryEntryDefaultsDlg");
       
   103     User::Panic(KPanicText, aReason);
       
   104     }
       
   105 #endif // _DEBUG
       
   106 
       
   107 // Defaults settings map
       
   108 struct TDefaultsItem
       
   109     {
       
   110     VPbkFieldTypeSelectorFactory::TVPbkContactActionTypeSelector selectorId;
       
   111     TInt titleResId;
       
   112     TInt iconId;
       
   113     TInt iconMaskId;
       
   114     };
       
   115 
       
   116 /**
       
   117  * Defines Defaults appearance.
       
   118  */
       
   119 const TDefaultsItem KDefaultsSettingsTable[] = {
       
   120     { VPbkFieldTypeSelectorFactory::EVoiceCallSelector, R_QTN_PHOB_SETI_CALL_DEFAULT,
       
   121     EMbmPhonebook2eceQgn_prop_pb_comm_call_large, EMbmPhonebook2eceQgn_prop_pb_comm_call_large_mask },
       
   122     { VPbkFieldTypeSelectorFactory::EEmailEditorSelector, R_QTN_PHOB_SETI_EMAIL_DEFAULT, 
       
   123     EMbmPhonebook2eceQgn_prop_pb_comm_email_large, EMbmPhonebook2eceQgn_prop_pb_comm_email_large_mask },
       
   124     { VPbkFieldTypeSelectorFactory::EInstantMessagingSelector, R_QTN_PHOB_SETI_CHAT_DEFAULT,
       
   125     EMbmPhonebook2eceQgn_prop_pb_comm_chat_large, EMbmPhonebook2eceQgn_prop_pb_comm_chat_large_mask },
       
   126     { VPbkFieldTypeSelectorFactory::EVOIPCallSelector, R_QTN_PHOB_SETI_VOIP_DEFAULT,
       
   127     EMbmPhonebook2eceQgn_prop_pb_comm_voip_large, EMbmPhonebook2eceQgn_prop_pb_comm_voip_large_mask},
       
   128     { VPbkFieldTypeSelectorFactory::EURLSelector, R_QTN_PHOB_SETI_OPENLINK_DEFAULT, 
       
   129     EMbmPhonebook2eceQgn_prop_pb_comm_url_large, EMbmPhonebook2eceQgn_prop_pb_comm_url_large_mask },
       
   130     { VPbkFieldTypeSelectorFactory::EVideoCallSelector, R_QTN_PHOB_SETI_VIDEO_DEFAULT, 
       
   131     EMbmPhonebook2eceQgn_prop_pb_comm_vcall_large, EMbmPhonebook2eceQgn_prop_pb_comm_vcall_large_mask },
       
   132     { VPbkFieldTypeSelectorFactory::EPocSelector, R_QTN_PHOB_SETI_POC_DEFAULT,
       
   133             EMbmPhonebook2eceQgn_prop_nrtyp_poc, EMbmPhonebook2eceQgn_prop_nrtyp_poc_mask },
       
   134     { VPbkFieldTypeSelectorFactory::EUniEditorSelector, R_QTN_PHOB_SETI_MESSAGE_DEFAULT,
       
   135     EMbmPhonebook2eceQgn_prop_pb_comm_message_large, EMbmPhonebook2eceQgn_prop_pb_comm_message_large_mask}
       
   136     };
       
   137 
       
   138 const TInt KDefaultsSettingsTableLength = sizeof( KDefaultsSettingsTable ) / sizeof( TDefaultsItem );
       
   139 
       
   140 // LOCAL FUNCTIONS
       
   141 
       
   142 /**
       
   143  * Returns the default property at given selector id.
       
   144  *
       
   145  * @param aSelectorID           The selector id of the used default.
       
   146  * @param aDefaultProperties    Array of properties at given index on return.
       
   147  */
       
   148 void PropertiesAtIndexL( const VPbkFieldTypeSelectorFactory::TVPbkContactActionTypeSelector aSelectorID,
       
   149         CArrayFixFlat<TVPbkDefaultType>& aDefaultProperties )
       
   150     {
       
   151     switch ( aSelectorID )
       
   152         {
       
   153         case VPbkFieldTypeSelectorFactory::EVoiceCallSelector:
       
   154             {
       
   155             aDefaultProperties.AppendL( EVPbkDefaultTypePhoneNumber );
       
   156             break;
       
   157             }
       
   158         case VPbkFieldTypeSelectorFactory::EVideoCallSelector:
       
   159             {
       
   160             aDefaultProperties.AppendL( EVPbkDefaultTypeVideoNumber );
       
   161             break;
       
   162             }
       
   163         case VPbkFieldTypeSelectorFactory::EUniEditorSelector:
       
   164             {
       
   165             if (FeatureManager::FeatureSupported(KFeatureIdMMS))
       
   166                 {
       
   167                 aDefaultProperties.AppendL( EVPbkDefaultTypeMms );
       
   168                 }
       
   169             else if (FeatureManager::FeatureSupported(KFeatureIdEmailOverSms))
       
   170                 {
       
   171                 aDefaultProperties.AppendL( EVPbkDefaultTypeEmailOverSms );
       
   172                 }
       
   173             else
       
   174                 {
       
   175                 aDefaultProperties.AppendL( EVPbkDefaultTypeSms );
       
   176                 }
       
   177             break;
       
   178             }
       
   179         case VPbkFieldTypeSelectorFactory::EEmailEditorSelector:
       
   180             {
       
   181             aDefaultProperties.AppendL( EVPbkDefaultTypeEmail );
       
   182             break;
       
   183             }
       
   184         case VPbkFieldTypeSelectorFactory::EVOIPCallSelector:
       
   185             {
       
   186             aDefaultProperties.AppendL( EVPbkDefaultTypeVoIP );
       
   187             break;
       
   188             }
       
   189         case VPbkFieldTypeSelectorFactory::EPocSelector:
       
   190             {
       
   191             aDefaultProperties.AppendL( EVPbkDefaultTypePOC );
       
   192             break;
       
   193             }
       
   194         case VPbkFieldTypeSelectorFactory::EInstantMessagingSelector:
       
   195             {
       
   196             aDefaultProperties.AppendL( EVPbkDefaultTypeChat );
       
   197             break;
       
   198             }
       
   199         case VPbkFieldTypeSelectorFactory::EURLSelector:
       
   200             {
       
   201             aDefaultProperties.AppendL( EVPbkDefaultTypeOpenLink );
       
   202             break;
       
   203             }
       
   204         default:
       
   205             {
       
   206             User::Leave( KErrNotFound );
       
   207             break;
       
   208             }
       
   209         }
       
   210     }
       
   211 
       
   212 /**
       
   213  * Returns field selector.
       
   214  * 
       
   215  * @param aFieldTypes       Fieldtype list to use in selectors
       
   216  * @param aDefaultIndex     The index of the default to use.
       
   217  * @return  Field selector which is left to cleanupstack.
       
   218  */
       
   219 CPbk2FieldSelector* ConstructFieldSelectorLC( 
       
   220         const MVPbkFieldTypeList& aFieldTypes,
       
   221         const VPbkFieldTypeSelectorFactory::TVPbkContactActionTypeSelector aSelectorID )
       
   222     {
       
   223      // Create composite field selector
       
   224     CPbk2FieldSelector* selector = CPbk2FieldSelector::NewLC();        
       
   225 
       
   226     // Construct a filtered store contact field collection
       
   227     CVPbkFieldTypeSelector* fieldTypeSelector = 
       
   228         VPbkFieldTypeSelectorFactory::BuildContactActionTypeSelectorL( aSelectorID , aFieldTypes );
       
   229 
       
   230     // takes ownership, no need to push to cleanupstack
       
   231     selector->AddIncludedSelector( fieldTypeSelector );
       
   232         
       
   233     return selector;
       
   234     }
       
   235 
       
   236 /**
       
   237  * Creates a filed filter.
       
   238  * 
       
   239  * @param aFieldsCollection A collection of fields.
       
   240  * @param aSelectorID       The selector id of the current default.
       
   241  * @param aManager          Reference to contact manager.
       
   242  * @return  Returns a field filter.
       
   243  */
       
   244 CVPbkFieldFilter* CreateFilterL
       
   245         ( MVPbkStoreContactFieldCollection& aFieldsCollection,
       
   246           const VPbkFieldTypeSelectorFactory::TVPbkContactActionTypeSelector aSelectorID,
       
   247           const CVPbkContactManager& aManager )
       
   248     {
       
   249     CPbk2FieldSelector* selector = ConstructFieldSelectorLC( 
       
   250             aManager.FieldTypes(), 
       
   251             aSelectorID );
       
   252 
       
   253     const CVPbkFieldFilter::TConfig config
       
   254         ( const_cast<MVPbkStoreContactFieldCollection&>
       
   255             ( aFieldsCollection ), selector, NULL );
       
   256     CVPbkFieldFilter* fieldFilter = CVPbkFieldFilter::NewL( config );
       
   257 
       
   258     CleanupStack::PopAndDestroy( selector );
       
   259 
       
   260     return fieldFilter;
       
   261     }
       
   262     
       
   263 /**
       
   264  * Returns fields applicable to be set as the selected default.
       
   265  * 
       
   266  * @param aContact          The contact whose fields to show.
       
   267  * @param aSelectorId       The selector id of the default to use.
       
   268  * @param aManager          Reference to contact manager.
       
   269  * @return  Collection of fields applicable to use as default.
       
   270  *          Leaves two objects on to cleanup stack. 
       
   271  */
       
   272 CPbk2PresentationContactFieldCollection* ApplicableFieldsCXL
       
   273         ( CPbk2PresentationContact& aContact,
       
   274           VPbkFieldTypeSelectorFactory::TVPbkContactActionTypeSelector aSelectorId,
       
   275           const CVPbkContactManager& aManager )
       
   276     {
       
   277     CVPbkFieldFilter* fieldFilter = 
       
   278             CreateFilterL( aContact.Fields(),
       
   279                            aSelectorId, aManager );
       
   280 
       
   281     CleanupStack::PushL( fieldFilter );
       
   282 
       
   283     CPbk2PresentationContactFieldCollection* fields =
       
   284         CPbk2PresentationContactFieldCollection::NewL
       
   285             ( aContact.PresentationFields().FieldProperties(),
       
   286               *fieldFilter, aContact );
       
   287 
       
   288     CleanupStack::PushL( fields );
       
   289     return fields;
       
   290     }
       
   291 
       
   292 /**
       
   293  * Checks whether the passed contact field candidate is of
       
   294  * correct field type and has the correct attribute assigned.
       
   295  *
       
   296  * @param aCandidate        Contact field candidate.
       
   297  * @param aSelectorId       Selector id.
       
   298  * @param aAttribute        Contact attribute.
       
   299  * @param aManager          Virtual Phonebook contact manager.
       
   300  * @return  ETrue if the candidate fulfills all the requirements.
       
   301  */
       
   302 TBool CandidateApprovedL( MVPbkStoreContactField& aCandidate,
       
   303         VPbkFieldTypeSelectorFactory::TVPbkContactActionTypeSelector aSelectorId,
       
   304         CVPbkDefaultAttribute& aAttribute,
       
   305         CVPbkContactManager& aManager )
       
   306     {
       
   307     TBool ret = EFalse;
       
   308     
       
   309     // Verify the field is of correct type
       
   310     TVPbkStoreContactAnalyzer analyzer( aManager, NULL );
       
   311     if ( analyzer.IsFieldTypeIncludedL( aCandidate, aSelectorId ) )
       
   312         {
       
   313         // Check if field has default attribute defaultType
       
   314         if ( aManager.ContactAttributeManagerL().
       
   315              HasFieldAttributeL( aAttribute, aCandidate ) )
       
   316             {
       
   317             ret = ETrue;
       
   318             }
       
   319         }
       
   320 
       
   321     return ret;
       
   322     }
       
   323 
       
   324 /**
       
   325  * Finds default field identified by given index.
       
   326  *
       
   327  * @param aContact      The contact where to find the default from.
       
   328  * @param aSelectorId   The selector id of the default to use.
       
   329  * @param aManager      A reference to contact manager.
       
   330  * @return  Store contact field which has the appropriate default assigned,
       
   331  *          or NULL if not found.
       
   332  */
       
   333 MVPbkStoreContactField* FindDefaultFieldL
       
   334         ( MVPbkStoreContact& aContact,
       
   335           const VPbkFieldTypeSelectorFactory::TVPbkContactActionTypeSelector aSelectorId,
       
   336           CVPbkContactManager& aManager )
       
   337     {
       
   338     MVPbkStoreContactField* field = NULL;
       
   339 
       
   340     // First find all the default properties matching the default type
       
   341     CArrayFixFlat<TVPbkDefaultType>* defaultProperties =
       
   342         new( ELeave ) CArrayFixFlat<TVPbkDefaultType>( KGranularity );
       
   343     CleanupStack::PushL( defaultProperties );
       
   344     PropertiesAtIndexL
       
   345         ( aSelectorId, *defaultProperties );
       
   346 
       
   347     // Check if the contact has any of the default properties defined
       
   348     for ( TInt i = 0; i < defaultProperties->Count() && !field; ++i )
       
   349         {
       
   350         // Loop through contact's fields and find the specified field
       
   351         CVPbkDefaultAttribute* attr =
       
   352             CVPbkDefaultAttribute::NewL( defaultProperties->At( i ) );
       
   353         CleanupStack::PushL( attr );
       
   354 
       
   355         const TInt fieldCount = aContact.Fields().FieldCount();
       
   356         for ( TInt j = 0; j < fieldCount && !field ; ++j )
       
   357             {
       
   358             MVPbkStoreContactField* candidate =
       
   359                 aContact.Fields().FieldAtLC( j );
       
   360 
       
   361             if ( CandidateApprovedL
       
   362                 ( *candidate, aSelectorId, *attr, aManager ) )
       
   363                 {
       
   364                 field = candidate;
       
   365                 CleanupStack::Pop(); // candidate
       
   366                 }
       
   367             else
       
   368                 {
       
   369                 CleanupStack::PopAndDestroy(); // candidate
       
   370                 }
       
   371             }
       
   372 
       
   373         CleanupStack::PopAndDestroy ( attr );
       
   374         }
       
   375 
       
   376     CleanupStack::PopAndDestroy( defaultProperties );
       
   377 
       
   378     return field;
       
   379     }
       
   380 
       
   381 /**
       
   382  * Returns default field identified by aDefaultIndex from aContact
       
   383  * or NULL if the default is not set.
       
   384  *
       
   385  * @param aContact          Reference to a contact.
       
   386  * @param aSelectorId       The selector id of the default to use.
       
   387  * @param aManager          Reference to contact manager.
       
   388  * @return  The correct default field.
       
   389  */
       
   390 CPbk2PresentationContactField* DefaultFieldL
       
   391         ( CPbk2PresentationContact& aContact,
       
   392           const VPbkFieldTypeSelectorFactory::TVPbkContactActionTypeSelector aSelectorId,
       
   393           CVPbkContactManager& aManager )
       
   394     {
       
   395     CPbk2PresentationContactField* result = NULL;
       
   396 
       
   397     // Find the correct default field
       
   398     MVPbkStoreContactField* defaultField = FindDefaultFieldL
       
   399         ( aContact.StoreContact(), aSelectorId, aManager );
       
   400 
       
   401     if ( defaultField )
       
   402         {
       
   403         // Find the corresponding presentation field
       
   404         CPbk2PresentationContactFieldCollection& presentationFields =
       
   405             aContact.PresentationFields();
       
   406 
       
   407         for (TInt i = 0; i < presentationFields.FieldCount(); ++i)
       
   408             {
       
   409             CPbk2PresentationContactField& victim =
       
   410                 presentationFields.At( i );
       
   411             if ( victim.IsSame( *defaultField ) )
       
   412                 {
       
   413                 result = &victim;    // temporary reference is ok
       
   414                 break;
       
   415                 }
       
   416             }
       
   417         }
       
   418     delete defaultField;
       
   419 
       
   420     return result;
       
   421     }
       
   422 
       
   423 /**
       
   424  * Returns the default UI text for default field identified by aDefaultIndex.
       
   425  *
       
   426  * @param aSelectorId   Selector id of the default.
       
   427  * @return  Text for the default.
       
   428  */
       
   429 HBufC* DefaultFieldTextLC( const VPbkFieldTypeSelectorFactory::TVPbkContactActionTypeSelector aSelectorId )
       
   430     {
       
   431     for( TInt idx = 0; idx < KDefaultsSettingsTableLength; idx++ )
       
   432         {
       
   433         TDefaultsItem tmpItem = KDefaultsSettingsTable[ idx ];
       
   434         if( tmpItem.selectorId == aSelectorId )
       
   435             {
       
   436             return StringLoader::LoadLC( tmpItem.titleResId );
       
   437             }
       
   438         }
       
   439     
       
   440     User::Leave(KErrNotFound);
       
   441     return NULL;
       
   442     } 
       
   443 
       
   444 /**
       
   445  * Loads and creates an icon from given indexes.
       
   446  *
       
   447  * @param aBmpId    Index of icon.
       
   448  * @param aMaskId   Index of icon mask.
       
   449  * @return          An icon.
       
   450  */   
       
   451 CGulIcon* LoadIconLC( TInt aBmpId, TInt aMaskId )
       
   452     {
       
   453     CFbsBitmap* bmp = NULL;
       
   454     CFbsBitmap* mask = NULL;
       
   455     CGulIcon* icon = CGulIcon::NewLC();
       
   456     
       
   457     AknIconUtils::CreateIconLC( 
       
   458         bmp, mask, KPbk2ECEIconFileName, aBmpId, aMaskId );
       
   459                                
       
   460     icon->SetBitmap( bmp );
       
   461     icon->SetMask( mask );
       
   462     CleanupStack::Pop( 2 ); // bmp, mask
       
   463 
       
   464     return icon;
       
   465     }
       
   466 
       
   467 /**
       
   468  * Loads and creates an icon from given indexes.
       
   469  *
       
   470  * @param aBmpId    Index of icon.
       
   471  * @param aMaskId   Index of icon mask.
       
   472  * @return          An icon.
       
   473  */   
       
   474 CGulIcon* MapSelectorId2IconLC( const VPbkFieldTypeSelectorFactory::TVPbkContactActionTypeSelector aSelectorId )
       
   475     {
       
   476     for( TInt idx = 0; idx < KDefaultsSettingsTableLength; idx++ )
       
   477         {
       
   478         TDefaultsItem tmpItem = KDefaultsSettingsTable[ idx ];
       
   479         if( tmpItem.selectorId == aSelectorId )
       
   480             {
       
   481             return LoadIconLC( tmpItem.iconId, tmpItem.iconMaskId );
       
   482             }
       
   483         }
       
   484         
       
   485     User::Leave( KErrNotFound );
       
   486     return NULL;
       
   487     }
       
   488 
       
   489 // --------------------------------------------------------------------------
       
   490 // CPbk2MemoryEntryDefaultsDlg::CPbk2MemoryEntryDefaultsDlg
       
   491 // --------------------------------------------------------------------------
       
   492 //
       
   493 inline CPbk2MemoryEntryDefaultsDlg::CPbk2MemoryEntryDefaultsDlg
       
   494         ( CPbk2PresentationContact& aContact,
       
   495           CVPbkContactManager& aManager ):
       
   496             iContact( aContact ), iManager( aManager ), iLVFlags( 0 ), iServiceName( NULL )
       
   497     {
       
   498     // Do nothing
       
   499     }
       
   500 
       
   501 // --------------------------------------------------------------------------
       
   502 // CPbk2MemoryEntryDefaultsDlg::~CPbk2MemoryEntryDefaultsDlg
       
   503 // --------------------------------------------------------------------------
       
   504 //
       
   505 CPbk2MemoryEntryDefaultsDlg::~CPbk2MemoryEntryDefaultsDlg()
       
   506     {
       
   507     PBK2_DEBUG_PRINT(PBK2_DEBUG_STRING
       
   508         ("CPbk2MemoryEntryDefaultsDlg destructor start"));
       
   509     if (iDestroyedPtr)
       
   510         {
       
   511         *iDestroyedPtr = ETrue;
       
   512         }
       
   513     delete iListBox;
       
   514     delete iAttributeProcess;
       
   515     delete iDefaultsTable;
       
   516     delete iServiceName;
       
   517 
       
   518     FeatureManager::UnInitializeLib();
       
   519 
       
   520     PBK2_DEBUG_PRINT(PBK2_DEBUG_STRING
       
   521         ("CPbk2MemoryEntryDefaultsDlg destructor end"));
       
   522     }
       
   523 
       
   524 // --------------------------------------------------------------------------
       
   525 // CPbk2MemoryEntryDefaultsDlg::NewL
       
   526 // --------------------------------------------------------------------------
       
   527 //
       
   528 EXPORT_C CPbk2MemoryEntryDefaultsDlg* CPbk2MemoryEntryDefaultsDlg::NewL
       
   529         ( CPbk2PresentationContact& aContact, CVPbkContactManager& aManager )
       
   530     {
       
   531     CPbk2MemoryEntryDefaultsDlg* self = new(ELeave)
       
   532         CPbk2MemoryEntryDefaultsDlg(aContact, aManager);
       
   533     CleanupStack::PushL(self);
       
   534     self->ConstructL();
       
   535     CleanupStack::Pop(self);
       
   536     return self;
       
   537     }
       
   538 
       
   539 // --------------------------------------------------------------------------
       
   540 // CPbk2MemoryEntryDefaultsDlg::ConstructL
       
   541 // --------------------------------------------------------------------------
       
   542 //
       
   543 inline void CPbk2MemoryEntryDefaultsDlg::ConstructL()
       
   544     {
       
   545     // Initialize feature manager
       
   546     FeatureManager::InitializeLibL();
       
   547 
       
   548     // Read local variation flags
       
   549     CRepository* key = CRepository::NewL(TUid::Uid(KCRUidPhonebook));
       
   550     TInt err = key->Get(KPhonebookLocalVariationFlags, iLVFlags);
       
   551     if (err != KErrNone)
       
   552         {
       
   553         // If there were problems reading the flags, assume everything is off
       
   554         iLVFlags = 0;
       
   555         }
       
   556     delete key;
       
   557 
       
   558     // Create a list box
       
   559     iListBox = static_cast<CEikFormattedCellListBox*>
       
   560         (EikControlFactory::CreateByTypeL
       
   561                 (EAknCtDoubleLargeGraphicPopupMenuListBox).iControl);
       
   562 
       
   563 
       
   564 	CAknPopupList::ConstructL
       
   565 		(iListBox, R_PBK2_SOFTKEYS_OK_BACK_OK,
       
   566 		AknPopupLayouts::EMenuDoubleLargeGraphicWindow);
       
   567       
       
   568     // Init list box
       
   569     iListBox->ConstructL( this, CEikListBox::ELeftDownInViewRect );
       
   570     iListBox->CreateScrollBarFrameL( ETrue );
       
   571     iListBox->ScrollBarFrame()->SetScrollBarVisibilityL
       
   572         ( CEikScrollBarFrame::EOff, CEikScrollBarFrame::EAuto );
       
   573     
       
   574     // Set title of pop up list
       
   575     HBufC* heading = StringLoader::LoadLC
       
   576         ( R_QTN_PHOB_TITLE_DEFAULT_SETTINGS );
       
   577     SetTitleL( *heading );
       
   578     CleanupStack::PopAndDestroy( heading );
       
   579     
       
   580     iDefaultsTable 
       
   581        = new (ELeave) CArrayFixFlat<VPbkFieldTypeSelectorFactory::TVPbkContactActionTypeSelector>( KGranularity );
       
   582         
       
   583     CreateTableOfDefaultsL();
       
   584     
       
   585     CreateLinesL();
       
   586 
       
   587     __ASSERT_DEBUG(iListBox && !iDestroyedPtr,
       
   588         Panic(EPanicPostCond_ConstructL));
       
   589     }
       
   590 
       
   591 // --------------------------------------------------------------------------
       
   592 // CPbk2MemoryEntryDefaultsDlg::ExecuteLD
       
   593 // --------------------------------------------------------------------------
       
   594 //
       
   595 EXPORT_C void CPbk2MemoryEntryDefaultsDlg::ExecuteLD()
       
   596     {
       
   597     CAknPopupList::ExecuteLD();
       
   598     }
       
   599 
       
   600 // --------------------------------------------------------------------------
       
   601 // CPbk2MemoryEntryDefaultsDlg::ProcessCommandL
       
   602 // --------------------------------------------------------------------------
       
   603 //
       
   604 void CPbk2MemoryEntryDefaultsDlg::ProcessCommandL( TInt aCommandId )
       
   605     {
       
   606     PBK2_DEBUG_PRINT(PBK2_DEBUG_STRING
       
   607         ("CPbk2MemoryEntryDefaultsDlg::ProcessCommandL start"));
       
   608 
       
   609     switch ( aCommandId )
       
   610         {
       
   611         case EAknSoftkeyOk:
       
   612             {
       
   613             // Equal item order in iDefaultsTable and iListBox
       
   614             TInt currentItemIndex( iListBox->CurrentItemIndex() );
       
   615             // iListBox and iDefaultsTable have the same lenght. But its
       
   616             // possible that further changes could break that assumption.
       
   617             if( currentItemIndex < iDefaultsTable->Count() )
       
   618                 DefaultsAssignPopupL( iDefaultsTable->At( currentItemIndex ) );
       
   619             break;
       
   620             }
       
   621 
       
   622         default:
       
   623             {
       
   624             PBK2_DEBUG_PRINT(PBK2_DEBUG_STRING
       
   625                 ("About to call CAknPopupList::ProcessCommandL"));
       
   626             CAknPopupList::ProcessCommandL( aCommandId );
       
   627             PBK2_DEBUG_PRINT(PBK2_DEBUG_STRING
       
   628                 ("Called CAknPopupList::ProcessCommandL"));
       
   629             break;
       
   630             }
       
   631         }
       
   632     PBK2_DEBUG_PRINT(PBK2_DEBUG_STRING
       
   633         ("CPbk2MemoryEntryDefaultsDlg::ProcessCommandL end"));
       
   634     }
       
   635 
       
   636 // --------------------------------------------------------------------------
       
   637 // CPbk2MemoryEntryDefaultsDlg::HandleListBoxEventL
       
   638 // --------------------------------------------------------------------------
       
   639 //
       
   640 void CPbk2MemoryEntryDefaultsDlg::HandleListBoxEventL
       
   641         ( CEikListBox* aListBox, TListBoxEvent aEventType )
       
   642     {
       
   643     // Respond to events from listbox item
       
   644     if ( aListBox == iListBox )
       
   645         {
       
   646         // Handle pointer events - copied source from 
       
   647         // CCCAppCommLauncherContainer::HandleListBoxEventL 
       
   648         TBool executeContactAction = EFalse;
       
   649         if ( aEventType == EEventItemDraggingActioned )
       
   650             {
       
   651             iHasBeenDragged = ETrue;
       
   652             }
       
   653 
       
   654         else if ( aEventType == EEventItemSingleClicked )
       
   655 
       
   656         	{
       
   657             if (!iHasBeenDragged)
       
   658                 {
       
   659                 executeContactAction = ETrue;
       
   660                 }
       
   661             else
       
   662                 {
       
   663                 iHasBeenDragged = EFalse;
       
   664                 }
       
   665             }
       
   666         else if ( aEventType == EEventEnterKeyPressed)
       
   667             {
       
   668             executeContactAction = ETrue;
       
   669             iHasBeenDragged = EFalse;
       
   670             }
       
   671         
       
   672         if ( executeContactAction )
       
   673             {
       
   674             ProcessCommandL( EAknSoftkeyOk );     
       
   675             }
       
   676         }
       
   677     }
       
   678 
       
   679 // --------------------------------------------------------------------------
       
   680 // CPbk2MemoryEntryDefaultsDlg::AttributeProcessCompleted
       
   681 // --------------------------------------------------------------------------
       
   682 //
       
   683 void CPbk2MemoryEntryDefaultsDlg::AttributeProcessCompleted()
       
   684     {
       
   685     delete iField;
       
   686     iField = NULL;
       
   687 
       
   688     // Redraw
       
   689     TRAP_IGNORE( CreateLinesL() );
       
   690     iListBox->DrawDeferred();
       
   691     DrawDeferred();
       
   692     }
       
   693 
       
   694 // --------------------------------------------------------------------------
       
   695 // CPbk2MemoryEntryDefaultsDlg::AttributeProcessFailed
       
   696 // --------------------------------------------------------------------------
       
   697 //
       
   698 void CPbk2MemoryEntryDefaultsDlg::AttributeProcessFailed( TInt aErrorCode )
       
   699     {
       
   700     delete iField;
       
   701     iField = NULL;
       
   702 
       
   703     iCoeEnv->HandleError( aErrorCode );
       
   704     }
       
   705 
       
   706 // --------------------------------------------------------------------------
       
   707 // CPbk2MemoryEntryDefaultsDlg::CreateLinesL
       
   708 // --------------------------------------------------------------------------
       
   709 //
       
   710 void CPbk2MemoryEntryDefaultsDlg::CreateLinesL() const
       
   711     {
       
   712     CDesCArray* lines = static_cast<CDesCArray*>
       
   713         (iListBox->Model()->ItemTextArray());
       
   714     lines->Reset();
       
   715 
       
   716     // int = icon id, string = first text, string = second text
       
   717     _LIT(KFormat, "%d\t%S\t%S\t" );
       
   718     HBufC* noDefault = StringLoader::LoadLC( R_QTN_PHOB_SETI_NO_DEFAULT );
       
   719     
       
   720     for ( TInt idx = 0; idx < iDefaultsTable->Count(); ++idx )
       
   721         {
       
   722         HBufC* defaultFieldText = DefaultFieldTextLC( iDefaultsTable->At(idx) );
       
   723         const CPbk2PresentationContactField* field =
       
   724             DefaultFieldL( iContact, iDefaultsTable->At(idx), iManager );
       
   725         TPtrC label;
       
   726         if( field )
       
   727             {
       
   728             label.Set( field->FieldLabel() );
       
   729             }
       
   730         else
       
   731             {
       
   732             label.Set( *noDefault );
       
   733             }
       
   734 
       
   735         // Allocate and format the listbox line
       
   736         HBufC* lineBuf = NULL;
       
   737         // If only one Voip service avaliable, use voip service name on internet call item
       
   738         if ( iServiceName && 
       
   739         		( iDefaultsTable->At( idx ) == VPbkFieldTypeSelectorFactory::EVOIPCallSelector ) )
       
   740         	{
       
   741         	// Use Voip service name
       
   742             HBufC* str = StringLoader::LoadLC( R_QTN_CCA_VOIP_CALL_WITH_SERVICENAME, 
       
   743                         *iServiceName,             
       
   744                         iCoeEnv );
       
   745         	lineBuf = HBufC::NewLC( KFormat().Length()
       
   746         	            + str->Length() + label.Length() );
       
   747         	TPtr line( lineBuf->Des() );
       
   748         	line.Format( KFormat, idx, str, &label);
       
   749         	lines->AppendL( line ) ;
       
   750         	CleanupStack::PopAndDestroy(2); // lineBuf, str
       
   751         	}
       
   752         else
       
   753         	{
       
   754         	// Use default text
       
   755         	lineBuf = HBufC::NewLC( KFormat().Length()
       
   756         	            + defaultFieldText->Length() + label.Length() );
       
   757         	TPtr line( lineBuf->Des() );
       
   758         	line.Format( KFormat, idx, defaultFieldText, &label);
       
   759         	lines->AppendL( line ) ;
       
   760         	CleanupStack::PopAndDestroy(); // lineBuf
       
   761         	}
       
   762         
       
   763         // Cleanup
       
   764         CleanupStack::PopAndDestroy(); // defaultFieldText        
       
   765         }
       
   766    
       
   767     CleanupStack::PopAndDestroy(); // noDefault
       
   768     }
       
   769 
       
   770 // --------------------------------------------------------------------------
       
   771 // CPbk2MemoryEntryDefaultsDlg::DefaultsAssignPopupL
       
   772 // --------------------------------------------------------------------------
       
   773 //
       
   774 TBool CPbk2MemoryEntryDefaultsDlg::DefaultsAssignPopupL
       
   775         ( VPbkFieldTypeSelectorFactory::TVPbkContactActionTypeSelector aSelectorID )
       
   776     {
       
   777     TBool thisDestroyed = EFalse;
       
   778     iDestroyedPtr = &thisDestroyed;
       
   779     TPbk2DestructionIndicator indicator
       
   780         ( &thisDestroyed, iDestroyedPtr );
       
   781 
       
   782     TBool result = EFalse;
       
   783 
       
   784     // Construct a presentation contact field collection,
       
   785     // containing fields that apply to the field type requirements
       
   786     // of the chosen default
       
   787     CPbk2PresentationContactFieldCollection* fields =
       
   788         ApplicableFieldsCXL( iContact, aSelectorID, iManager );
       
   789 
       
   790     // Construct and launch the assign dialog
       
   791     CPbk2MemoryEntryDefaultsAssignDlg* assignDlg =
       
   792         CPbk2MemoryEntryDefaultsAssignDlg::NewL();
       
   793    const TInt index = assignDlg->ExecuteLD(*fields, iManager,
       
   794           iContact.PresentationFields().FieldProperties(), aSelectorID);
       
   795 
       
   796     if (!thisDestroyed)
       
   797         {
       
   798         // Next find the field index is referencing
       
   799         MVPbkStoreContactField* field = NULL;
       
   800         const TInt fieldCount = fields->FieldCount();
       
   801         // Notice that the last index of the listbox
       
   802         // is bound to 'no default' selection, hence the index
       
   803         // must be smaller than field count.
       
   804         if (index > KErrNotFound && index < fieldCount)
       
   805             {
       
   806             // Set the new default
       
   807             field = &fields->At(index);
       
   808             if (field)
       
   809                 {
       
   810                 SetDefaultL(aSelectorID, *field);
       
   811                 }
       
   812             }
       
   813 
       
   814         else if (index == fieldCount)
       
   815             {
       
   816             // User selected the 'no default' option
       
   817             RemoveDefaultL( aSelectorID );
       
   818             }
       
   819         }
       
   820 
       
   821     CleanupStack::PopAndDestroy( 2 ); // ApplicableFieldsLCX
       
   822     return result;
       
   823     }
       
   824 
       
   825 // --------------------------------------------------------------------------
       
   826 // CPbk2MemoryEntryDefaultsDlg::IsSupported
       
   827 // --------------------------------------------------------------------------
       
   828 //
       
   829 TBool CPbk2MemoryEntryDefaultsDlg::IsSupported
       
   830         ( const VPbkFieldTypeSelectorFactory::TVPbkContactActionTypeSelector aSelectorID ) const
       
   831     {
       
   832     TBool ret(ETrue);
       
   833 
       
   834     // Skip the line if Email field not supported or having no mailbox
       
   835     if ( aSelectorID == VPbkFieldTypeSelectorFactory::EEmailEditorSelector )
       
   836         {
       
   837         if ( !FeatureManager::FeatureSupported( KFeatureIdEmailUi ) )
       
   838         	{
       
   839         	ret = EFalse;
       
   840         	}
       
   841         }
       
   842     // Do not add video fields if they are not enabled
       
   843     else if ( ( aSelectorID == VPbkFieldTypeSelectorFactory::EVideoCallSelector ) &&
       
   844               !( iLVFlags & EVPbkLVAddVideoTelephonyFields ) )
       
   845         {
       
   846         ret = EFalse;
       
   847         }
       
   848     // Do not add Voip fields if they are not enabled
       
   849     else if ( aSelectorID == VPbkFieldTypeSelectorFactory::EVOIPCallSelector &&
       
   850               !FeatureManager::FeatureSupported( KFeatureIdCommonVoip ) )
       
   851         {
       
   852         ret = EFalse;
       
   853         }
       
   854     // Do not add POC fields if they are not enabled
       
   855     else if ( ( aSelectorID == VPbkFieldTypeSelectorFactory::EPocSelector ) &&
       
   856               !( iLVFlags & EVPbkLVPOC ) )
       
   857         {
       
   858         ret = EFalse;
       
   859         }
       
   860 
       
   861     return ret;
       
   862     }
       
   863 
       
   864 // --------------------------------------------------------------------------
       
   865 // CPbk2MemoryEntryDefaultsDlg::HasMailboxAccountsL
       
   866 // --------------------------------------------------------------------------
       
   867 //
       
   868 TBool CPbk2MemoryEntryDefaultsDlg::HasMailboxAccountsL() const
       
   869 	{
       
   870 	using namespace EmailInterface;
       
   871 
       
   872 	TBool result = EFalse;
       
   873 	CEmailInterfaceFactory* factory = CEmailInterfaceFactory::NewL();
       
   874 	CleanupStack::PushL( factory );
       
   875 	MEmailInterface* ifPtr = factory->InterfaceL( KEmailClientApiInterface );
       
   876 	MEmailClientApi* clientApi = static_cast<MEmailClientApi*>( ifPtr );
       
   877 	CleanupReleasePushL( *clientApi );
       
   878 	
       
   879 	// Get mailboxs
       
   880 	RMailboxPtrArray mailboxes;
       
   881 	clientApi->GetMailboxesL( mailboxes );
       
   882 	TInt count = mailboxes.Count();	
       
   883 	if ( count > 0 )
       
   884 		{
       
   885 		result = ETrue;
       
   886 		}
       
   887 	
       
   888 	// Release mailboxs before releasing clientapi
       
   889 	for ( TInt i=0; i<count; i++ )
       
   890 		{
       
   891 		MEmailMailbox* mailbox = mailboxes[i];
       
   892 		mailbox->Release();
       
   893 		}	
       
   894 	mailboxes.Close();	
       
   895 	CleanupStack::PopAndDestroy( 2 ); // clientApi and factory
       
   896 	
       
   897 	return result;
       
   898 	}
       
   899 // --------------------------------------------------------------------------
       
   900 // CPbk2MemoryEntryDefaultsDlg::IsAvailable
       
   901 // --------------------------------------------------------------------------
       
   902 //
       
   903 TBool CPbk2MemoryEntryDefaultsDlg::IsAvailableL
       
   904         ( const VPbkFieldTypeSelectorFactory::TVPbkContactActionTypeSelector aSelectorID ) const
       
   905     {
       
   906     CVPbkFieldFilter* filter = CreateFilterL(
       
   907               iContact.Fields(), aSelectorID, iManager );
       
   908   
       
   909     TInt nbrOfEntries = filter->FieldCount();
       
   910     
       
   911     delete filter;
       
   912     
       
   913     return ( 0 < nbrOfEntries );
       
   914     }
       
   915 
       
   916 void CPbk2MemoryEntryDefaultsDlg::CreateTableOfDefaultsL()
       
   917     {
       
   918     TRAPD( err, ReadDefaultsFromRepositoryL() )
       
   919     if( err != KErrNone )
       
   920         {
       
   921         //add defaults without order
       
   922         iDefaultsTable->Reset();
       
   923         iDefaultsTable->AppendL( VPbkFieldTypeSelectorFactory::EVoiceCallSelector );
       
   924         iDefaultsTable->AppendL( VPbkFieldTypeSelectorFactory::EVOIPCallSelector );
       
   925         iDefaultsTable->AppendL( VPbkFieldTypeSelectorFactory::EUniEditorSelector );
       
   926         iDefaultsTable->AppendL( VPbkFieldTypeSelectorFactory::EEmailEditorSelector );
       
   927         iDefaultsTable->AppendL( VPbkFieldTypeSelectorFactory::EInstantMessagingSelector );
       
   928         iDefaultsTable->AppendL( VPbkFieldTypeSelectorFactory::EURLSelector );
       
   929         iDefaultsTable->AppendL( VPbkFieldTypeSelectorFactory::EVideoCallSelector );
       
   930         }
       
   931     
       
   932     TInt idx;
       
   933     
       
   934     // Filter services
       
   935     // Only show supported and contact-related items
       
   936     for( idx = 0; idx < iDefaultsTable->Count(); idx++ )
       
   937         {        
       
   938         if( !IsSupported( iDefaultsTable->At( idx ) ) ||
       
   939             !IsAvailableL( iDefaultsTable->At( idx ) ) 
       
   940           )
       
   941             {
       
   942             // remove item at current position from array
       
   943             iDefaultsTable->Delete( idx, 1 );
       
   944             idx--;
       
   945             }
       
   946         }
       
   947     
       
   948     // Load icon of each RELEVANT communication 
       
   949     // methode and add it to the listbox.
       
   950     CAknIconArray* iconArray = new (ELeave) CAknIconArray( KGranularity );
       
   951     CleanupStack::PushL( iconArray );
       
   952     for( idx = 0; idx < iDefaultsTable->Count(); idx++ )
       
   953         { 
       
   954         CGulIcon* icon = MapSelectorId2IconLC( iDefaultsTable->At( idx ) );
       
   955         
       
   956         // Important: iconArray positions matchs
       
   957         // with iDefaultsTable positions
       
   958         iconArray->AppendL( icon );
       
   959         
       
   960         // If only one Voip service avaliable, use brand icon on internet call item
       
   961         TServiceId serviceId;
       
   962         if ( ( iDefaultsTable->At( idx ) == VPbkFieldTypeSelectorFactory::EVOIPCallSelector ) &&
       
   963         		( SupportedVOIPServicesL( serviceId ) == 1 ) )
       
   964         	{
       
   965             CFbsBitmap* bitmap (NULL);
       
   966             CFbsBitmap* mask (NULL);
       
   967 
       
   968             // Load Voip brand bitmap and mask              
       
   969             LoadVoipServiceInfoL( serviceId, bitmap, mask );
       
   970             
       
   971             if ( bitmap || mask )
       
   972                 {          
       
   973                 iconArray->At(idx)->SetBitmap(bitmap);
       
   974                 iconArray->At(idx)->SetMask(mask);
       
   975                 }
       
   976         	}
       
   977         
       
   978         CleanupStack::Pop(1); // icon
       
   979         }  
       
   980     // iListBox takes ownership of iconArray
       
   981     iListBox->ItemDrawer()->ColumnData()->SetIconArray( iconArray );
       
   982     CleanupStack::Pop(1); // iconArray
       
   983     }
       
   984 
       
   985 // --------------------------------------------------------------------------
       
   986 // CPbk2MemoryEntryDefaultsDlg::ReadDefaultsFromRepositoryL
       
   987 // --------------------------------------------------------------------------
       
   988 //
       
   989 void CPbk2MemoryEntryDefaultsDlg::ReadDefaultsFromRepositoryL()
       
   990     {
       
   991     //*** read item order out of repository ***
       
   992     CRepository* repository = CRepository::NewLC( KCRUidCCACommLauncher );
       
   993     TBuf<KCCAppCommLauncherMaxOrderBufLength> orderBuf;
       
   994     TInt error = repository->Get( KCommunicationMethodOrder, orderBuf );
       
   995     CleanupStack::PopAndDestroy( repository );
       
   996     
       
   997     TLex orderLex( orderBuf );
       
   998     TPtrC numToken;
       
   999     TLex numLex;
       
  1000     TInt commMethodType;
       
  1001     const TInt bufLength = orderBuf.Length() - 1;
       
  1002 
       
  1003     while ( orderLex.Offset() < bufLength )
       
  1004         {
       
  1005         numToken.Set( orderLex.NextToken() );
       
  1006         numLex.Assign( numToken );
       
  1007         // if defined value is string instead of a number,
       
  1008         // use the default array
       
  1009         User::LeaveIfError( numLex.Val( commMethodType ));
       
  1010         // if defined value is outside of the possible comm method
       
  1011         // values, use the default array
       
  1012         TBool validMethod(EFalse);    
       
  1013         for( TInt idx = 0; idx < KDefaultsSettingsTableLength; idx++ )
       
  1014             {
       
  1015             if( KDefaultsSettingsTable[ idx ].selectorId == commMethodType )
       
  1016                 {
       
  1017                 validMethod = ETrue;
       
  1018                 break;
       
  1019                 }
       
  1020             }
       
  1021         User::LeaveIfError( !validMethod ? KErrArgument : 0 );
       
  1022         
       
  1023         // If commMethodType invalid, function leaves with KErrNotFound
       
  1024         VPbkFieldTypeSelectorFactory::TVPbkContactActionTypeSelector selectorID =
       
  1025         VPbkFieldTypeSelectorFactory::CreateActionTypeSelectorIdL( commMethodType );
       
  1026  
       
  1027         iDefaultsTable->AppendL( selectorID );  
       
  1028         }    
       
  1029 
       
  1030     // if no comm methods defined, use the default array
       
  1031     User::LeaveIfError( iDefaultsTable->Count() ? 0 : KErrNotFound );
       
  1032     }
       
  1033 
       
  1034 // --------------------------------------------------------------------------
       
  1035 // CPbk2MemoryEntryDefaultsDlg::SetDefaultL
       
  1036 // Sets aField as the default (identified by aDefaultIndex) field
       
  1037 // for the contact.
       
  1038 // --------------------------------------------------------------------------
       
  1039 //
       
  1040 void CPbk2MemoryEntryDefaultsDlg::SetDefaultL
       
  1041         ( const VPbkFieldTypeSelectorFactory::TVPbkContactActionTypeSelector aSelectorID,
       
  1042           MVPbkStoreContactField& aField )
       
  1043     {
       
  1044     delete iField;
       
  1045     iField = NULL;
       
  1046 
       
  1047     // Find actual store contact field from presentation
       
  1048     // contact's store contact
       
  1049     for (TInt i = 0; i < iContact.StoreContact().Fields().FieldCount(); ++i)
       
  1050         {
       
  1051         MVPbkStoreContactField* actualField =
       
  1052             iContact.StoreContact().Fields().FieldAtLC( i );
       
  1053         if ( aField.IsSame( *actualField ) )
       
  1054             {
       
  1055             iField = actualField;
       
  1056             CleanupStack::Pop(); // actualField
       
  1057             break;
       
  1058             }
       
  1059         else
       
  1060             {
       
  1061             CleanupStack::PopAndDestroy(); // actualField
       
  1062             }
       
  1063         }
       
  1064 
       
  1065     if ( iField )
       
  1066         {
       
  1067         // Init attribute set/remove process object
       
  1068         delete iAttributeProcess;
       
  1069         iAttributeProcess = NULL;
       
  1070         iAttributeProcess = CPbk2DefaultAttributeProcess::NewL
       
  1071             ( iManager, iContact.StoreContact(), *this );
       
  1072 
       
  1073         CArrayFixFlat<TVPbkDefaultType>* defaultProperties =
       
  1074             new( ELeave ) CArrayFixFlat<TVPbkDefaultType>( KGranularity );
       
  1075         CleanupStack::PushL( defaultProperties );
       
  1076         PropertiesAtIndexL
       
  1077             ( aSelectorID, *defaultProperties );
       
  1078         CleanupStack::Pop( defaultProperties );
       
  1079         iAttributeProcess->SetDefaultsL( defaultProperties, *iField );
       
  1080         }
       
  1081     }
       
  1082 
       
  1083 // --------------------------------------------------------------------------
       
  1084 // CPbk2MemoryEntryDefaultsDlg::RemoveDefaultL
       
  1085 // Removes default (identified by aDefaultIndex) from aContact.
       
  1086 // --------------------------------------------------------------------------
       
  1087 //
       
  1088 void CPbk2MemoryEntryDefaultsDlg::RemoveDefaultL
       
  1089         ( const VPbkFieldTypeSelectorFactory::TVPbkContactActionTypeSelector aSelectorID )
       
  1090     {
       
  1091     delete iAttributeProcess;
       
  1092     iAttributeProcess = NULL;
       
  1093     iAttributeProcess = CPbk2DefaultAttributeProcess::NewL
       
  1094         ( iManager, iContact.StoreContact(), *this );
       
  1095 
       
  1096     CArrayFixFlat<TVPbkDefaultType>* defaultProperties =
       
  1097         new( ELeave ) CArrayFixFlat<TVPbkDefaultType>( KGranularity );
       
  1098     CleanupStack::PushL( defaultProperties );
       
  1099     PropertiesAtIndexL
       
  1100         ( aSelectorID, *defaultProperties );
       
  1101     CleanupStack::Pop( defaultProperties );
       
  1102     iAttributeProcess->RemoveDefaultsL( defaultProperties );
       
  1103     }
       
  1104 
       
  1105 // --------------------------------------------------------------------------
       
  1106 // CPbk2MemoryEntryDefaultsDlg::SupportedVOIPServicesL
       
  1107 // Get supported Voip services
       
  1108 // --------------------------------------------------------------------------
       
  1109 //
       
  1110 TInt CPbk2MemoryEntryDefaultsDlg::SupportedVOIPServicesL( TServiceId& aServiceId )
       
  1111     {   
       
  1112     TInt availableVoipService = 0;    
       
  1113     RIdArray idArray;
       
  1114     CleanupClosePushL(idArray);
       
  1115     
       
  1116     CSPSettings* settings = CSPSettings::NewL();
       
  1117     CleanupStack::PushL( settings );
       
  1118     
       
  1119     User::LeaveIfError( settings->FindServiceIdsL(idArray) ); 
       
  1120     
       
  1121     const TInt count = idArray.Count();   
       
  1122     for (TInt i = 0; i < count; ++i)
       
  1123         {
       
  1124         TBool supported( EFalse );
       
  1125         CSPEntry* entry = CSPEntry::NewLC();
       
  1126         TServiceId id = idArray[i];
       
  1127         User::LeaveIfError( settings->FindEntryL(id, *entry) );
       
  1128         const CSPProperty* property = NULL;
       
  1129         
       
  1130         if (entry->GetProperty(property, EPropertyServiceAttributeMask) == KErrNone)
       
  1131             {
       
  1132             TInt value = 0;
       
  1133             property->GetValue(value);
       
  1134             supported = value & ESupportsInternetCall; 
       
  1135             }
       
  1136         
       
  1137         if ( supported )
       
  1138             {
       
  1139             availableVoipService++;            
       
  1140             aServiceId = id;
       
  1141             }
       
  1142         CleanupStack::PopAndDestroy(); // entry
       
  1143         }
       
  1144     CleanupStack::PopAndDestroy(2); // settings, idArray    
       
  1145     
       
  1146     return availableVoipService;
       
  1147     }
       
  1148 
       
  1149 // ---------------------------------------------------------------------------
       
  1150 // CPbk2MemoryEntryDefaultsDlg::LoadVoipServiceInfoL
       
  1151 // Load Voip service info
       
  1152 // ---------------------------------------------------------------------------
       
  1153 //
       
  1154 void CPbk2MemoryEntryDefaultsDlg::LoadVoipServiceInfoL( 
       
  1155             TServiceId aServiceId,
       
  1156             CFbsBitmap*& aBitmap, CFbsBitmap*& aMask )
       
  1157     {   
       
  1158     CPbk2ApplicationServices* appServices =
       
  1159         CPbk2ApplicationServices::InstanceLC();
       
  1160     
       
  1161     CPbk2ServiceManager& servMan = appServices->ServiceManager();
       
  1162     const CPbk2ServiceManager::RServicesArray& services = servMan.Services();
       
  1163     
       
  1164     const TInt count = services.Count();   
       
  1165     for ( TInt i = 0; i < count; i++ )
       
  1166         {
       
  1167         const CPbk2ServiceManager::TService& service = services[i];
       
  1168 
       
  1169         if ( service.iServiceId == aServiceId )
       
  1170             {
       
  1171             // Calculate preferred size for xsp service icon 
       
  1172             TRect mainPane;
       
  1173             AknLayoutUtils::LayoutMetricsRect(
       
  1174                 AknLayoutUtils::EMainPane, mainPane );
       
  1175             TAknLayoutRect listLayoutRect;
       
  1176             listLayoutRect.LayoutRect(
       
  1177                 mainPane,
       
  1178                 AknLayoutScalable_Avkon::list_double_large_graphic_pane_g1(0).LayoutLine() );
       
  1179             TSize size(listLayoutRect.Rect().Size());
       
  1180             
       
  1181             AknIconUtils::SetSize(
       
  1182                     service.iBitmap,
       
  1183                     size );
       
  1184             AknIconUtils::SetSize(
       
  1185                     service.iMask,
       
  1186                     size );                               
       
  1187     		
       
  1188             aBitmap = new (ELeave) CFbsBitmap;
       
  1189             CleanupStack::PushL( aBitmap );
       
  1190             aBitmap->Duplicate( service.iBitmap->Handle() );
       
  1191             
       
  1192             aMask = new (ELeave) CFbsBitmap;
       
  1193             CleanupStack::PushL( aMask );
       
  1194             aMask->Duplicate( service.iMask->Handle() );                    
       
  1195                      
       
  1196             iServiceName = service.iDisplayName.AllocL();
       
  1197             CleanupStack::Pop( 2 ); // aMask, aBitmap
       
  1198             
       
  1199             break;
       
  1200             }
       
  1201         }
       
  1202     CleanupStack::PopAndDestroy(); // appServices
       
  1203     }
       
  1204 
       
  1205 //  End of File