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