phonebookui/Phonebook2/Commands/src/CPbk2CommandHandler.cpp
changeset 0 e686773b3f54
child 12 4ae315f230bc
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 command handler.
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 // INCLUDE FILES
       
    20 #include "CPbk2CommandHandler.h"
       
    21 
       
    22 // Phonebook 2
       
    23 #include "CPbk2CommandFactory.h"
       
    24 #include "CPbk2CommandStore.h"
       
    25 #include "CPbk2AiwInterestArray.h"
       
    26 #include <MPbk2ViewExplorer.h>
       
    27 #include <CPbk2AppViewBase.h>
       
    28 #include <CPbk2AppUiBase.h>
       
    29 #include <CPbk2UIExtensionManager.h>
       
    30 #include <MPbk2Command.h>
       
    31 #include <Pbk2Commands.rsg>
       
    32 #include <Pbk2UIControls.rsg>
       
    33 #include <CPbk2ViewState.h>
       
    34 #include <CPbk2PhonebookInfoDlg.h>
       
    35 #include <TPbk2StoreContactAnalyzer.h>
       
    36 #include <MPbk2ContactNameFormatter.h>
       
    37 #include <CPbk2StoreProperty.h>
       
    38 #include <CPbk2StorePropertyArray.h>
       
    39 #include <CPbk2ContactRelocator.h>
       
    40 #include <MPbk2ContactLinkIterator.h>
       
    41 #include <CPbk2PresentationContact.h>
       
    42 #include <CPbk2PresentationContactFieldCollection.h>
       
    43 #include <CPbk2FieldPropertyArray.h>
       
    44 #include <cpbk2commandactivator.h>
       
    45 #include <CPbk2ApplicationServices.h>
       
    46 #include <MPbk2AppUi.h>
       
    47 
       
    48 // Virtual Phonebook
       
    49 #include <CVPbkContactManager.h>
       
    50 #include <MVPbkStoreContactField.h>
       
    51 #include <MVPbkStoreContact.h>
       
    52 #include <MVPbkContactStore.h>
       
    53 #include <MVPbkContactStoreProperties.h>
       
    54 #include <MVPbkContactAttributeManager.h>
       
    55 #include <MVPbkContactLinkArray.h>
       
    56 #include <MVPbkContactLink.h>
       
    57 #include <CVPbkSpeedDialAttribute.h>
       
    58 #include <MVPbkStoreContact.h>
       
    59 #include <VPbkContactStoreUris.h>
       
    60 
       
    61 // System includes
       
    62 #include <avkon.hrh>
       
    63 #include <eikmenup.h>
       
    64 #include <featmgr.h>
       
    65 #include <hlplch.h>
       
    66 #include <akntoolbar.h>
       
    67 #include <eikmenub.h>
       
    68 
       
    69 
       
    70 /// Unnamed namespace for local definitions
       
    71 namespace {
       
    72 
       
    73 #ifdef _DEBUG
       
    74 enum TPanicCode
       
    75     {
       
    76     EPanicPreCond_CmdOpenMeViewsL = 1,
       
    77     EPanicPreCond_CmdOpenSettingsViewL,
       
    78     EPanicPreCond_CmdOpenPreviousViewL,
       
    79     EPanicPreCond_CmdOpenHelpL,
       
    80     EPanicLogic_FocusedFieldMatchesFieldTypeL,
       
    81     EPanicLogic_FocusedContactHasFieldTypeL
       
    82     };
       
    83 
       
    84 void Panic(TPanicCode aReason)
       
    85     {
       
    86     _LIT(KPanicText, "CPbk2CommandHandler");
       
    87     User::Panic(KPanicText, aReason);
       
    88     }
       
    89 #endif //_DEBUG
       
    90 
       
    91 /**
       
    92  * Checks if focused field is of given field type.
       
    93  *
       
    94  * @param aUiControl        UI control.
       
    95  * @param aSelectorResId    Selector resource id.
       
    96  * @param aContactManager   Virtual Phonebook contact manager.
       
    97  * @return  ETrue if field type matches with given types.
       
    98  */
       
    99 TBool FocusedFieldMatchesFieldTypeL(
       
   100         MPbk2ContactUiControl& aUiControl,
       
   101         TInt aSelectorResId,
       
   102         CVPbkContactManager& aContactManager )
       
   103     {
       
   104     const MVPbkStoreContact* contact = aUiControl.FocusedStoreContact();
       
   105     __ASSERT_DEBUG(contact, Panic
       
   106             ( EPanicLogic_FocusedFieldMatchesFieldTypeL ) );
       
   107 
       
   108     TPbk2StoreContactAnalyzer analyzer( aContactManager, NULL );
       
   109     const MVPbkBaseContactField* field = aUiControl.FocusedField();
       
   110     return field &&
       
   111         analyzer.IsFieldTypeIncludedL( *field, aSelectorResId );
       
   112     }
       
   113 
       
   114 /**
       
   115  * Checks if the focused contact have a given field type.
       
   116  *
       
   117  * @param aUiControl        UI control
       
   118  * @param aSelectorResId    Selector resource id.
       
   119  * @param aContactManager   Virtual Phonebook contact manager.
       
   120  * @return  Index of the field having the type, KErrNotFound if
       
   121  *          the contact does not have the field type.
       
   122  */
       
   123  TInt FocusedContactHasFieldTypeL(
       
   124         MPbk2ContactUiControl& aUiControl,
       
   125         TInt aSelectorResId,
       
   126         CVPbkContactManager& aContactManager )
       
   127     {
       
   128     TInt ret = KErrNotFound;
       
   129     const MVPbkStoreContact* contact = aUiControl.FocusedStoreContact();
       
   130     __ASSERT_DEBUG( contact,
       
   131         Panic( EPanicLogic_FocusedContactHasFieldTypeL ) );
       
   132 
       
   133     TPbk2StoreContactAnalyzer analyzer( aContactManager, contact );
       
   134     ret = analyzer.HasFieldL( aSelectorResId );
       
   135     return ret;
       
   136     }
       
   137 
       
   138 /**
       
   139  * Checks if command is 'exit' command.
       
   140  *
       
   141  * @param aCommandId    The command to check.
       
   142  * @return  ETrue if command is an exit command, EFalse otherwise.
       
   143  */
       
   144 TBool IsExitCommand( TInt aCommandId )
       
   145     {
       
   146     TBool ret = EFalse;
       
   147 
       
   148     if ( EEikCmdExit == aCommandId || EAknSoftkeyExit == aCommandId ||
       
   149          EAknCmdExit == aCommandId || EPbk2CmdExit == aCommandId )
       
   150         {
       
   151         ret = ETrue;
       
   152         }
       
   153 
       
   154     return ret;
       
   155     }
       
   156 
       
   157 } /// namespace
       
   158 
       
   159 
       
   160 // --------------------------------------------------------------------------
       
   161 // CPbk2CommandHandler::CPbk2CommandHandler
       
   162 // --------------------------------------------------------------------------
       
   163 //
       
   164 inline CPbk2CommandHandler::CPbk2CommandHandler()
       
   165     {
       
   166     }
       
   167 
       
   168 // --------------------------------------------------------------------------
       
   169 // CPbk2CommandHandler::~CPbk2CommandHandler
       
   170 // --------------------------------------------------------------------------
       
   171 //
       
   172 CPbk2CommandHandler::~CPbk2CommandHandler()
       
   173     {
       
   174     delete iAiwInterestArray;
       
   175     delete iCommandStore;
       
   176     delete iCommandFactory;
       
   177     delete iContactRelocator;
       
   178     Release(iExtensionManager);
       
   179     Release(iAppServices);
       
   180     FeatureManager::UnInitializeLib();
       
   181     }
       
   182 
       
   183 // --------------------------------------------------------------------------
       
   184 // CPbk2CommandHandler::NewL
       
   185 // --------------------------------------------------------------------------
       
   186 //
       
   187 EXPORT_C CPbk2CommandHandler* CPbk2CommandHandler::NewL()
       
   188     {
       
   189     CPbk2CommandHandler* self = new(ELeave) CPbk2CommandHandler();
       
   190     CleanupStack::PushL(self);
       
   191     self->ConstructL();
       
   192     CleanupStack::Pop(self);
       
   193     return self;
       
   194     }
       
   195 
       
   196 // --------------------------------------------------------------------------
       
   197 // CPbk2CommandHandler::ConstructL
       
   198 // --------------------------------------------------------------------------
       
   199 //
       
   200 inline void CPbk2CommandHandler::ConstructL()
       
   201     {
       
   202     iCommandFactory = CPbk2CommandFactory::NewL();
       
   203     iCommandStore = CPbk2CommandStore::NewL();
       
   204     iAiwInterestArray = CPbk2AiwInterestArray::NewL();
       
   205     iExtensionManager = CPbk2UIExtensionManager::InstanceL();
       
   206     iContactRelocator = CPbk2ContactRelocator::NewL();
       
   207     iAppServices = CPbk2ApplicationServices::InstanceL();
       
   208 
       
   209     // Initialize feature manager
       
   210     FeatureManager::InitializeLibL();
       
   211     }
       
   212 
       
   213 // --------------------------------------------------------------------------
       
   214 // CPbk2CommandHandler::HandleCommandL
       
   215 // --------------------------------------------------------------------------
       
   216 //
       
   217 TBool CPbk2CommandHandler::HandleCommandL
       
   218         ( const TInt aCommandId, MPbk2ContactUiControl& aControl,
       
   219           const CPbk2AppViewBase* aAppView )
       
   220     {
       
   221     TBool ret = ETrue;
       
   222 
       
   223     // Exit commands are forwarded right away to appui
       
   224     // Otherwise there is possibility that
       
   225     // 'exit' command is not handled in low memory situations
       
   226     if ( IsExitCommand( aCommandId ) )
       
   227         {
       
   228         ret = EFalse;
       
   229         }
       
   230 
       
   231     // Offer the command to AIW unless it is exit command
       
   232     if ( ret && !iAiwInterestArray->HandleCommandL
       
   233             ( aCommandId, aControl, KNullHandle ) )
       
   234         {
       
   235         // Try generic command, this can also be a command from an extension
       
   236         ret = CmdGenericCommandL( TPbk2CommandId( aCommandId ), aControl );
       
   237         if ( !ret )
       
   238             {
       
   239             ret = ETrue;
       
   240             switch ( aCommandId )
       
   241                 {
       
   242                 case EAknSoftkeyBack:               // FALLTHROUGH
       
   243                 case EPbk2CmdOpenPreviousView:
       
   244                     {
       
   245                     CmdOpenPreviousViewL( aControl, aAppView );
       
   246                     break;
       
   247                     }
       
   248                 case EPbk2CmdSettings:
       
   249                     {
       
   250                     CmdOpenSettingsViewL( aControl, aAppView,
       
   251                         Phonebook2::KPbk2SettingsViewUid );
       
   252                     break;
       
   253                     }
       
   254                 case EAknCmdHelp:
       
   255                     {
       
   256                     CmdOpenHelpL( aControl, aAppView );
       
   257                     break;
       
   258                     }
       
   259                 default:
       
   260                     {
       
   261                     ret = EFalse;
       
   262                     break;
       
   263                     }
       
   264                 }
       
   265             }
       
   266         }
       
   267     return ret;
       
   268     }
       
   269 
       
   270 // --------------------------------------------------------------------------
       
   271 // CPbk2CommandHandler::DynInitMenuPaneL
       
   272 // --------------------------------------------------------------------------
       
   273 //
       
   274 void CPbk2CommandHandler::DynInitMenuPaneL(
       
   275         TInt aResourceId,
       
   276         CEikMenuPane* aMenuPane,
       
   277         CPbk2AppViewBase& aViewBase,
       
   278         MPbk2ContactUiControl& aControl )
       
   279     {
       
   280     // First, delegate to AIW interests.
       
   281     // If the menu initialization is handled there,
       
   282     // there's no need to continue here
       
   283     if ( !iAiwInterestArray->DynInitMenuPaneL
       
   284             ( aResourceId, *aMenuPane, aControl ) )
       
   285         {
       
   286         // Then call extensions
       
   287         iExtensionManager->DynInitMenuPaneL( aResourceId, aMenuPane,
       
   288             aViewBase, aControl );
       
   289 
       
   290         // First perform standard menu filtering
       
   291         PerformStandardMenuFilteringL( aResourceId, aMenuPane, aControl );
       
   292 
       
   293         // Then perform field type based filtering
       
   294         PerformFieldTypeBasedFilteringL( aResourceId, aMenuPane, aControl );
       
   295 
       
   296         // Finally perform store specific filtering
       
   297         PerformStoreSpecificFilteringL( aResourceId, aMenuPane, aControl );
       
   298         }
       
   299     }
       
   300 
       
   301 // --------------------------------------------------------------------------
       
   302 // CPbk2CommandHandler::RegisterAiwInterestL
       
   303 // --------------------------------------------------------------------------
       
   304 //
       
   305 void CPbk2CommandHandler::RegisterAiwInterestL(
       
   306         const TInt aInterestId,
       
   307         const TInt aMenuResourceId,
       
   308         const TInt aInterestResourceId,
       
   309         const TBool aAttachBaseService)
       
   310     {
       
   311     iAiwInterestArray->QueueInterestL(aInterestId,
       
   312         aMenuResourceId, aInterestResourceId, aAttachBaseService);
       
   313     }
       
   314 
       
   315 // --------------------------------------------------------------------------
       
   316 // CPbk2CommandHandler::ServiceCmdByMenuCmd
       
   317 // --------------------------------------------------------------------------
       
   318 //
       
   319 TInt CPbk2CommandHandler::ServiceCmdByMenuCmd(
       
   320         TInt aMenuCmdId ) const
       
   321     {
       
   322     return iAiwInterestArray->ServiceCmdByMenuCmd( aMenuCmdId );
       
   323     }
       
   324 
       
   325 // --------------------------------------------------------------------------
       
   326 // CPbk2CommandHandler::AddAndExecuteCommandL
       
   327 // --------------------------------------------------------------------------
       
   328 //
       
   329 void CPbk2CommandHandler::AddAndExecuteCommandL(
       
   330         MPbk2Command* aCommand)
       
   331     {
       
   332     iCommandStore->AddAndExecuteCommandL(aCommand);
       
   333     }
       
   334 
       
   335 // --------------------------------------------------------------------------
       
   336 // CPbk2CommandHandler::AddMenuCommandObserver
       
   337 // --------------------------------------------------------------------------
       
   338 //
       
   339 void CPbk2CommandHandler::AddMenuCommandObserver(
       
   340         MPbk2MenuCommandObserver& aObserver)
       
   341     {
       
   342     iCommandStore->AddMenuCommandObserver(aObserver);
       
   343     }
       
   344 
       
   345 // --------------------------------------------------------------------------
       
   346 // CPbk2CommandHandler::RemoveMenuCommandObserver
       
   347 // --------------------------------------------------------------------------
       
   348 //
       
   349 void CPbk2CommandHandler::RemoveMenuCommandObserver(
       
   350         MPbk2MenuCommandObserver& aObserver)
       
   351     {
       
   352     iCommandStore->RemoveMenuCommandObserver(aObserver);
       
   353     }
       
   354 
       
   355 // --------------------------------------------------------------------------
       
   356 // CPbk2CommandHandler::DynInitToolbarL
       
   357 // --------------------------------------------------------------------------
       
   358 //
       
   359 void CPbk2CommandHandler::DynInitToolbarL
       
   360         ( TInt aResourceId, CAknToolbar* aToolbar,
       
   361           const CPbk2AppViewBase& /*aAppView*/,
       
   362           MPbk2ContactUiControl& aControl )
       
   363     {
       
   364     switch ( aResourceId )
       
   365         {
       
   366         case R_PBK2_NAMESLIST_TOOLBAR:
       
   367             {
       
   368             if ( aControl.FocusedContactIndex() == KErrNotFound )
       
   369                 {
       
   370                 // If there is not focused contact (empty list or otherwise no
       
   371                 // focus) then disable calling and message writing
       
   372                 aToolbar->SetItemDimmed( EPbk2CmdCall, ETrue, ETrue );
       
   373                 aToolbar->SetItemDimmed( EPbk2CmdWriteNoQuery, ETrue, ETrue );
       
   374                 }
       
   375             else if ( aControl.ContactsMarked() )
       
   376                 {
       
   377                 // Disable calling to many contacts
       
   378                 aToolbar->SetItemDimmed( EPbk2CmdCall, ETrue, ETrue );
       
   379                 }
       
   380             break;
       
   381             }
       
   382         }
       
   383     }
       
   384 
       
   385 // --------------------------------------------------------------------------
       
   386 // CPbk2CommandHandler::OfferToolbarEventL
       
   387 // --------------------------------------------------------------------------
       
   388 //
       
   389 void CPbk2CommandHandler::OfferToolbarEventL
       
   390         ( TInt aCommand, MPbk2ContactUiControl& aControl,
       
   391           const CPbk2AppViewBase* aAppView )
       
   392     {
       
   393     if ( aAppView )
       
   394         {
       
   395     HandleCommandL( aCommand, aControl, aAppView );
       
   396         }
       
   397     }
       
   398 
       
   399 // --------------------------------------------------------------------------
       
   400 // CPbk2CommandHandler::CmdOpenSettingsViewL
       
   401 // --------------------------------------------------------------------------
       
   402 //
       
   403 void CPbk2CommandHandler::CmdOpenSettingsViewL
       
   404         ( MPbk2ContactUiControl& aControl,
       
   405           const CPbk2AppViewBase* aAppView, TUid aViewId )
       
   406     {
       
   407     if (aAppView)
       
   408         {
       
   409         // Phonebook 2 view explorer for view switching
       
   410         MPbk2ViewExplorer* viewExplorer = Phonebook2::Pbk2AppUi()->Pbk2ViewExplorer();
       
   411 
       
   412         __ASSERT_DEBUG( viewExplorer,
       
   413             Panic( EPanicPreCond_CmdOpenSettingsViewL ) );
       
   414 
       
   415         CPbk2ViewState* state = aAppView->ViewStateLC();
       
   416         viewExplorer->ActivatePhonebook2ViewL
       
   417             ( aViewId, state );
       
   418         CleanupStack::PopAndDestroy( state );
       
   419         aControl.UpdateAfterCommandExecution();
       
   420         }
       
   421     }
       
   422 
       
   423 // --------------------------------------------------------------------------
       
   424 // CPbk2CommandHandler::CmdOpenPreviousViewL
       
   425 // --------------------------------------------------------------------------
       
   426 //
       
   427 void CPbk2CommandHandler::CmdOpenPreviousViewL
       
   428         ( MPbk2ContactUiControl& /*aControl*/,
       
   429           const CPbk2AppViewBase* aAppView )
       
   430     {
       
   431     if (aAppView)
       
   432         {
       
   433         // Phonebook 2 view explorer for view switching
       
   434         MPbk2ViewExplorer* viewExplorer = Phonebook2::Pbk2AppUi()->Pbk2ViewExplorer();
       
   435 
       
   436         CPbk2ViewState* state = aAppView->ViewStateLC();
       
   437         viewExplorer->ActivatePreviousViewL( state );
       
   438         CleanupStack::PopAndDestroy( state );
       
   439         }
       
   440     }
       
   441 
       
   442 // --------------------------------------------------------------------------
       
   443 // CPbk2CommandHandler::CmdOpenHelpL
       
   444 // --------------------------------------------------------------------------
       
   445 //
       
   446 void CPbk2CommandHandler::CmdOpenHelpL
       
   447         ( MPbk2ContactUiControl& aControl,
       
   448           const CPbk2AppViewBase* aAppView )
       
   449     {
       
   450     if ( aAppView )
       
   451         {
       
   452     TCoeHelpContext helpContext;
       
   453     if ( iExtensionManager->GetHelpContextL
       
   454             ( helpContext, *aAppView, aControl) )
       
   455         {
       
   456         CArrayFix<TCoeHelpContext>* helpContextArray =
       
   457                 new (ELeave) CArrayFixFlat<TCoeHelpContext>( 1 );
       
   458         CleanupStack::PushL( helpContextArray );
       
   459         helpContextArray->AppendL( helpContext );
       
   460 
       
   461         // HlpLauncher destroys the help context array
       
   462         CleanupStack::Pop( helpContextArray );
       
   463         HlpLauncher::LaunchHelpApplicationL
       
   464             ( CCoeEnv::Static()->WsSession(), helpContextArray );
       
   465         }
       
   466     else
       
   467         {
       
   468         HlpLauncher::LaunchHelpApplicationL
       
   469             ( CCoeEnv::Static()->WsSession(),
       
   470               CEikonEnv::Static()->EikAppUi()->AppHelpContextL() );
       
   471             }
       
   472         }
       
   473     }
       
   474 
       
   475 // --------------------------------------------------------------------------
       
   476 // CPbk2CommandHandler::CmdGenericCommandL
       
   477 // --------------------------------------------------------------------------
       
   478 //
       
   479 TBool CPbk2CommandHandler::CmdGenericCommandL(
       
   480         TPbk2CommandId aCommandId,
       
   481         MPbk2ContactUiControl& aControl)
       
   482     {
       
   483     // Create the command object
       
   484     TBool result = EFalse;
       
   485     MPbk2Command* cmd = iCommandFactory->CreateCommandForIdL(
       
   486             aCommandId, aControl);
       
   487     if (cmd)
       
   488         {
       
   489         // If command factory was able to create the command,
       
   490         // add it to the command store and execute it
       
   491         iCommandStore->AddAndExecuteCommandL(cmd);
       
   492         result = ETrue;
       
   493         }
       
   494     return result;
       
   495     }
       
   496 
       
   497 // --------------------------------------------------------------------------
       
   498 // CPbk2CommandHandler::PerformStandardMenuFilteringL
       
   499 // --------------------------------------------------------------------------
       
   500 //
       
   501 inline void CPbk2CommandHandler::PerformStandardMenuFilteringL(
       
   502         TInt aResourceId,
       
   503         CEikMenuPane* aMenuPane,
       
   504         MPbk2ContactUiControl& aControl )
       
   505     {
       
   506     switch (aResourceId)
       
   507         {
       
   508         case R_PHONEBOOK2_NAMESLIST_DELETE_MENU:
       
   509             {
       
   510             if ( aControl.NumberOfContacts() == 0 )
       
   511                 {
       
   512                 aMenuPane->SetItemDimmed( EPbk2CmdDeleteMe, ETrue );
       
   513                 }
       
   514             if ( aControl.ContactsMarked() )
       
   515                 {
       
   516                 aMenuPane->SetItemSpecific( EPbk2CmdDeleteMe, EFalse );
       
   517                 }
       
   518             break;
       
   519             }
       
   520 
       
   521         case R_PHONEBOOK2_NAMELIST_CALL_CONTACT_MENU:
       
   522             {
       
   523             // Weed out commands not meant to be used with marked items
       
   524             if ( aControl.ContactsMarked() )
       
   525                 {
       
   526                 aMenuPane->SetItemDimmed( EPbk2CmdCall, ETrue );
       
   527                 }
       
   528             break;
       
   529             }
       
   530 
       
   531         case R_PHONEBOOK2_NAMESLIST_CREATE_MENU:
       
   532             {
       
   533             // Weed out commands not meant to be used with marked items
       
   534             if ( aControl.ContactsMarked() )
       
   535                 {
       
   536                 aMenuPane->SetItemDimmed( EPbk2CmdCreateNew, ETrue );
       
   537                 }
       
   538             break;
       
   539             }
       
   540 
       
   541         case R_PHONEBOOK2_NAMESLIST_SEND_URL_MENU:
       
   542             {
       
   543             // Weed out commands not meant to be used with empty list
       
   544             if ( aControl.NumberOfContacts() == 0 )
       
   545                 {
       
   546                 aMenuPane->SetItemDimmed( EPbk2CmdGoToURL, ETrue );
       
   547                 }
       
   548 
       
   549             if ( aControl.ContactsMarked() )
       
   550                 {
       
   551                 aMenuPane->SetItemDimmed( EPbk2CmdSend, ETrue );
       
   552                 aMenuPane->SetItemDimmed( EPbk2CmdGoToURL, ETrue );
       
   553                 }
       
   554             break;
       
   555             }
       
   556 
       
   557         case R_PHONEBOOK2_NAMESLIST_COPY_MENU:          // FALLTHROUGH
       
   558         case R_PHONEBOOK2_NAMESLIST_COPY_CONTEXT_MENU:
       
   559             {
       
   560             // The copy menu is not shown if there are no contacts
       
   561             TBool itemSpecCommEnabled = Phonebook2::Pbk2AppUi()->ActiveView()->MenuBar()->ItemSpecificCommandsEnabled();
       
   562             if ( aControl.NumberOfContacts() == 0 || 
       
   563                     ( !aControl.ContactsMarked() && !itemSpecCommEnabled ) ||
       
   564                     ( !aControl.FocusedContactL() && itemSpecCommEnabled && 
       
   565                             !aControl.ContactsMarked() ) )
       
   566                 {
       
   567                 aMenuPane->SetItemDimmed( EPbk2CmdCopy, ETrue );
       
   568                 }
       
   569             break;
       
   570             }
       
   571 
       
   572         case R_PHONEBOOK2_CONTACTINFO_EDIT_MENU:
       
   573             {
       
   574             // Weed out commands not meant to be used with empty contact
       
   575             if ( aControl.NumberOfContactFields() == 0 )
       
   576                 {
       
   577                 aMenuPane->SetItemDimmed( EPbk2CmdWrite, ETrue );
       
   578                 aMenuPane->SetItemDimmed( EPbk2CmdGoToURL, ETrue );
       
   579                 aMenuPane->SetItemDimmed( EPbk2CmdDefaultSettings, ETrue );
       
   580                 }
       
   581             break;
       
   582             }
       
   583 
       
   584         case R_PHONEBOOK2_CONTACTINFO_EXTENDED_MENU:
       
   585             {
       
   586             CVPbkContactManager& manager = iAppServices->ContactManager();
       
   587 
       
   588             // Always dim thumbnail if image/text supported or vice versa
       
   589             if ( FeatureManager::FeatureSupported
       
   590                     ( KFeatureIdCallImagetext ) )
       
   591                 {
       
   592                 aMenuPane->SetItemDimmed( EPbk2CmdFetchThumbnail, ETrue );
       
   593                 aMenuPane->SetItemDimmed( EPbk2CmdRemoveThumbnail, ETrue );
       
   594                 }
       
   595             else
       
   596                 {
       
   597                 aMenuPane->SetItemDimmed( EPbk2CmdAddImage, ETrue );
       
   598                 aMenuPane->SetItemDimmed( EPbk2CmdImage, ETrue );
       
   599                 }
       
   600 
       
   601             // Weed out commands not meant to be used with empty contact
       
   602             if ( aControl.NumberOfContactFields() == 0 )
       
   603                 {
       
   604                 aMenuPane->SetItemDimmed( EPbk2CmdSend, ETrue );
       
   605                 aMenuPane->SetItemDimmed( EPbk2CmdAssignSpeedDial, ETrue);
       
   606                 aMenuPane->SetItemDimmed( EPbk2CmdRemoveSpeedDial, ETrue );
       
   607                 aMenuPane->SetItemDimmed
       
   608                     ( EPbk2CmdPersonalRingingTone, ETrue );
       
   609                 aMenuPane->SetItemDimmed( EPbk2CmdCopy, ETrue );
       
   610 
       
   611                 if ( !FeatureManager::FeatureSupported
       
   612                         ( KFeatureIdCallImagetext ) )
       
   613                     {
       
   614                     aMenuPane->SetItemDimmed
       
   615                         ( EPbk2CmdFetchThumbnail, ETrue );
       
   616                     aMenuPane->SetItemDimmed
       
   617                         ( EPbk2CmdRemoveThumbnail, ETrue );
       
   618                     }
       
   619                 else
       
   620                     {
       
   621                     aMenuPane->SetItemDimmed( EPbk2CmdAddImage, ETrue );
       
   622                     aMenuPane->SetItemDimmed( EPbk2CmdImage, ETrue );
       
   623                     }
       
   624                 }
       
   625             else
       
   626                 {
       
   627                 // Utilise attribute manager to find out if
       
   628                 // the contact have a speed dial defined
       
   629                 TBool hasSpeedDial = HasSpeedDialL( aControl );
       
   630 
       
   631                 // Filtering is based on the speed dial existence
       
   632                 if ( !hasSpeedDial )
       
   633                     {
       
   634                     aMenuPane->SetItemDimmed
       
   635                         ( EPbk2CmdRemoveSpeedDial, ETrue );
       
   636                     }
       
   637                 else
       
   638                     {
       
   639                     aMenuPane->SetItemDimmed
       
   640                         ( EPbk2CmdAssignSpeedDial, ETrue );
       
   641                     }
       
   642                 }
       
   643             break;
       
   644             }
       
   645 
       
   646         case R_PHONEBOOK2_CONTACTINFO_CONTEXT_MENU:
       
   647             {
       
   648             // Weed out commands not meant to be used with empty contact
       
   649             if ( aControl.NumberOfContactFields() == 0 )
       
   650                 {
       
   651                 aMenuPane->SetItemDimmed( EPbk2CmdWrite, ETrue );
       
   652                 aMenuPane->SetItemDimmed( EPbk2CmdGoToURL, ETrue );
       
   653                 aMenuPane->SetItemDimmed( EPbk2CmdPersonalRingingTone, ETrue );
       
   654                 aMenuPane->SetItemDimmed( EPbk2CmdUseNumber, ETrue );
       
   655                 aMenuPane->SetItemDimmed( EPbk2CmdImage, ETrue );
       
   656                 }
       
   657             break;
       
   658             }
       
   659 
       
   660         case R_PHONEBOOK2_INFO_MENU:
       
   661             {
       
   662             // Filter memory info items when list box is empty
       
   663             // or items are marked
       
   664             if ( aControl.NumberOfContacts() == 0 ||
       
   665                  aControl.ContactsMarked() )
       
   666                 {
       
   667                 aMenuPane->SetItemDimmed( EPbk2CmdPhonebook2Info, ETrue );
       
   668                 }
       
   669             break;
       
   670             }
       
   671 
       
   672         case R_PHONEBOOK2_SYSTEM_MENU:
       
   673             {
       
   674             if ( !FeatureManager::FeatureSupported( KFeatureIdHelp ) )
       
   675                 {
       
   676                 // Remove non-supported help from menu
       
   677                 aMenuPane->SetItemDimmed( EAknCmdHelp, ETrue );
       
   678                 }
       
   679             break;
       
   680             }
       
   681         case R_PHONEBOOK2_MERGE_CONTACTS:
       
   682             {
       
   683             TBool supported = FeatureManager::FeatureSupported( KFeatureIdFfContactsMerge );
       
   684                        
       
   685             if ( !supported || aControl.ContactsMarked() )
       
   686                 {
       
   687                 aMenuPane->SetItemDimmed( EPbk2CmdMergeContacts, ETrue );
       
   688                 }
       
   689             break;
       
   690             }
       
   691         default:
       
   692             {
       
   693             // Do nothing
       
   694             break;
       
   695             }
       
   696         }
       
   697     }
       
   698 
       
   699 // --------------------------------------------------------------------------
       
   700 // CPbk2CommandHandler::PerformStoreSpecificFiltering
       
   701 // --------------------------------------------------------------------------
       
   702 //
       
   703 inline void CPbk2CommandHandler::PerformStoreSpecificFilteringL(
       
   704             TInt aResourceId,
       
   705             CEikMenuPane* aMenuPane,
       
   706             MPbk2ContactUiControl& aControl )
       
   707     {
       
   708     // ETrue if all selected contacts are read-only
       
   709     TBool readOnly = AreSelectedContactsFromReadOnlyStoreL( aControl );
       
   710 
       
   711     switch (aResourceId)
       
   712         {
       
   713         case R_PHONEBOOK2_NAMESLIST_CONTEXT_MENU_MARKED_ITEMS: // FALLTHROUGH
       
   714         case R_PHONEBOOK2_NAMESLIST_DELETE_MENU:
       
   715             {
       
   716             // Weed out commands not meant to be used with read only stores
       
   717             if (readOnly)
       
   718                 {
       
   719                 aMenuPane->SetItemDimmed(EPbk2CmdDeleteMe, ETrue);
       
   720                 }
       
   721             break;
       
   722             }
       
   723 
       
   724         case R_PHONEBOOK2_CONTACTINFO_EDIT_MENU:
       
   725             {
       
   726             TBool phoneMemoryInConfiguration =
       
   727                     iContactRelocator->IsPhoneMemoryInConfigurationL();
       
   728 
       
   729             // Weed out commands not meant to be used with read only stores
       
   730             if (readOnly)
       
   731                 {
       
   732                 aMenuPane->SetItemDimmed(EPbk2CmdDeleteMe, ETrue);
       
   733                 aMenuPane->SetItemDimmed(EPbk2CmdEditMe, ETrue);
       
   734                 }
       
   735 
       
   736             // Weed out phone memory specific commands, if there is no
       
   737             // phone memory in configuration
       
   738             if (!phoneMemoryInConfiguration)
       
   739                 {
       
   740                 aMenuPane->SetItemDimmed(EPbk2CmdDefaultSettings, ETrue);
       
   741                 }
       
   742             break;
       
   743             }
       
   744 
       
   745         case R_PHONEBOOK2_CONTACTINFO_EXTENDED_MENU:
       
   746             {
       
   747             TBool phoneMemoryInConfiguration =
       
   748                     iContactRelocator->IsPhoneMemoryInConfigurationL();
       
   749 
       
   750             // Weed out phone memory specific commands, if there is no
       
   751             // phone memory in configuration
       
   752             if (!phoneMemoryInConfiguration)
       
   753                 {
       
   754                 aMenuPane->SetItemDimmed(EPbk2CmdAssignSpeedDial, ETrue);
       
   755                 if (!FeatureManager::FeatureSupported(KFeatureIdCallImagetext))
       
   756                     {
       
   757                     aMenuPane->SetItemDimmed(EPbk2CmdFetchThumbnail, ETrue);
       
   758                     }
       
   759                 else
       
   760                     {
       
   761                     aMenuPane->SetItemDimmed(EPbk2CmdAddImage, ETrue);
       
   762                     aMenuPane->SetItemDimmed(EPbk2CmdImage, ETrue);
       
   763                     }
       
   764                 aMenuPane->SetItemDimmed(EPbk2CmdPersonalRingingTone, ETrue);
       
   765                 }
       
   766 
       
   767             break;
       
   768             }
       
   769 
       
   770         case R_PHONEBOOK2_CONTACTINFO_CONTEXT_MENU:
       
   771             {
       
   772             // Weed out commands not meant to be used with read only stores
       
   773             if (readOnly)
       
   774                 {
       
   775                 aMenuPane->SetItemDimmed(EPbk2CmdEditMe, ETrue);
       
   776                 }
       
   777             break;
       
   778             }
       
   779         case R_PHONEBOOK2_MERGE_CONTACTS:
       
   780             {
       
   781             TBool phoneMemoryInConfiguration =
       
   782                     iContactRelocator->IsPhoneMemoryInConfigurationL();
       
   783             
       
   784             if( !phoneMemoryInConfiguration ) 
       
   785                 {
       
   786                 aMenuPane->SetItemDimmed( EPbk2CmdMergeContacts, ETrue );
       
   787                 }
       
   788             break;
       
   789             }
       
   790         default:
       
   791             {
       
   792             // Do nothing
       
   793             break;
       
   794             }
       
   795         }
       
   796     }
       
   797 
       
   798 // --------------------------------------------------------------------------
       
   799 // CPbk2CommandHandler::PerformFieldTypeBasedFilteringL
       
   800 // --------------------------------------------------------------------------
       
   801 //
       
   802 inline void CPbk2CommandHandler::PerformFieldTypeBasedFilteringL(
       
   803             TInt aResourceId,
       
   804             CEikMenuPane* aMenuPane,
       
   805             MPbk2ContactUiControl& aControl )
       
   806     {
       
   807     CVPbkContactManager& manager = iAppServices->ContactManager();
       
   808 
       
   809     switch (aResourceId)
       
   810         {
       
   811         case R_PHONEBOOK2_CONTACTINFO_EDIT_MENU:
       
   812             {
       
   813             // Weed out commands which are not shown if currently focused field is
       
   814             // not phone number
       
   815             if (!FocusedFieldMatchesFieldTypeL(aControl,
       
   816                     R_PHONEBOOK2_PHONENUMBER_SELECTOR, manager))
       
   817                 {
       
   818                 aMenuPane->SetItemDimmed(EPbk2CmdUseNumber, ETrue);
       
   819                 }
       
   820 
       
   821             // If the contact does not have URL field, there is no
       
   822             // "Go To URL" option available
       
   823             if (FocusedContactHasFieldTypeL(aControl,
       
   824                     R_PHONEBOOK2_URL_SELECTOR, manager) < 0)
       
   825                 {
       
   826                 aMenuPane->SetItemDimmed(EPbk2CmdGoToURL, ETrue);
       
   827                 }
       
   828             break;
       
   829             }
       
   830 
       
   831         case R_PHONEBOOK2_CONTACTINFO_EXTENDED_MENU:
       
   832             {
       
   833             // Speed dial menus are variated based on VoIP support
       
   834             if( FeatureManager::FeatureSupported( KFeatureIdCommonVoip ) )
       
   835                 {
       
   836                 // Weed out commands which are not shown if currently focused field is
       
   837                 // neither phone number nor VoIP field
       
   838                 if( !FocusedFieldMatchesFieldTypeL( aControl,
       
   839                         R_PHONEBOOK2_SIP_MSISDN_SELECTOR, manager ) )
       
   840                     {
       
   841                     aMenuPane->SetItemDimmed( EPbk2CmdAssignSpeedDial, ETrue );
       
   842                     aMenuPane->SetItemDimmed( EPbk2CmdRemoveSpeedDial, ETrue );
       
   843                     }
       
   844                 }
       
   845             else
       
   846                 {
       
   847                 // Weed out commands which are not shown if currently focused field is
       
   848                 // not phone number
       
   849                 if( !FocusedFieldMatchesFieldTypeL( aControl,
       
   850                         R_PHONEBOOK2_PHONENUMBER_SELECTOR, manager ) )
       
   851                     {
       
   852                     aMenuPane->SetItemDimmed( EPbk2CmdAssignSpeedDial, ETrue );
       
   853                     aMenuPane->SetItemDimmed( EPbk2CmdRemoveSpeedDial, ETrue );
       
   854                     }
       
   855                 }
       
   856 
       
   857             // Alternate Thumbnail/Call object menus based on whether data
       
   858             // has been added or not
       
   859             if (!FeatureManager::FeatureSupported(KFeatureIdCallImagetext))
       
   860                 {
       
   861                 // Weed out command Remove Thumbnail if contact does not have one
       
   862                 if (FocusedContactHasFieldTypeL(aControl,
       
   863                         R_PHONEBOOK2_THUMBNAIL_SELECTOR, manager) < 0)
       
   864                     {
       
   865                     aMenuPane->SetItemDimmed(EPbk2CmdRemoveThumbnail, ETrue);
       
   866                     }
       
   867                 }
       
   868             else
       
   869                 {
       
   870                 if ((FocusedContactHasFieldTypeL(aControl,
       
   871                         R_PHONEBOOK2_IMAGE_SELECTOR, manager) < 0) &&
       
   872                     (FocusedContactHasFieldTypeL(aControl,
       
   873                         R_PHONEBOOK2_THUMBNAIL_SELECTOR, manager) < 0))
       
   874                     {
       
   875                     // Weed out Image submenu if contact does not have image
       
   876                     aMenuPane->SetItemDimmed(EPbk2CmdImage, ETrue);
       
   877                     }
       
   878                 else
       
   879                     {
       
   880                     // Weed out command Add Image if contact already has one
       
   881                     aMenuPane->SetItemDimmed(EPbk2CmdAddImage, ETrue);
       
   882                     }
       
   883                 }
       
   884             break;
       
   885             }
       
   886 
       
   887         case R_PHONEBOOK2_CONTACTINFO_CONTEXT_MENU:
       
   888             {
       
   889             TBool filtered = EFalse;
       
   890 
       
   891             // Telephone field
       
   892             if (FocusedFieldMatchesFieldTypeL(aControl,
       
   893                     R_PHONEBOOK2_PHONENUMBER_SELECTOR, manager))
       
   894                 {
       
   895                 aMenuPane->SetItemDimmed(EPbk2CmdGoToURL, ETrue);
       
   896                 aMenuPane->SetItemDimmed(EPbk2CmdPersonalRingingTone, ETrue);
       
   897                 aMenuPane->SetItemDimmed(EPbk2CmdImage, ETrue);
       
   898                 filtered = ETrue;
       
   899 
       
   900                 // Further filtering of phone number fields
       
   901                 // Pager field
       
   902                 // Pager returns a match for R_PHONEBOOK2_PHONENUMBER_SELECTOR
       
   903                 // too, but it requires further filtering, which is handled here
       
   904                 if (FocusedFieldMatchesFieldTypeL(aControl,
       
   905                         R_PHONEBOOK2_PAGER_SELECTOR, manager))
       
   906                     {
       
   907                     aMenuPane->SetItemDimmed(EPbk2CmdWrite, ETrue);
       
   908                     aMenuPane->SetItemDimmed(EPbk2CmdUseNumber, ETrue );
       
   909                     }
       
   910 
       
   911                 // VoIP
       
   912                 // VoIP returns a match for R_PHONEBOOK2_PHONENUMBER_SELECTOR
       
   913                 // too, but it requires further filtering, which is handled here
       
   914                 if (FocusedFieldMatchesFieldTypeL(aControl,
       
   915                         R_PHONEBOOK2_VOIP_SELECTOR, manager))
       
   916                     {
       
   917                     aMenuPane->SetItemDimmed(EPbk2CmdWrite, ETrue);
       
   918                     aMenuPane->SetItemDimmed(EPbk2CmdUseNumber, ETrue );
       
   919                     }
       
   920                 } // further filtering
       
   921 
       
   922             // Email field
       
   923             if (FocusedFieldMatchesFieldTypeL(aControl,
       
   924                     R_PHONEBOOK2_EMAIL_SELECTOR, manager))
       
   925                 {
       
   926                 aMenuPane->SetItemDimmed(EPbk2CmdGoToURL, ETrue);
       
   927                 aMenuPane->SetItemDimmed(EPbk2CmdUseNumber, ETrue );
       
   928                 aMenuPane->SetItemDimmed(EPbk2CmdPersonalRingingTone, ETrue);
       
   929                 aMenuPane->SetItemDimmed(EPbk2CmdImage, ETrue);
       
   930                 filtered = ETrue;
       
   931                 }
       
   932 
       
   933             // URL field
       
   934             if (FocusedFieldMatchesFieldTypeL(aControl,
       
   935                     R_PHONEBOOK2_URL_SELECTOR, manager))
       
   936                 {
       
   937                 aMenuPane->SetItemDimmed(EPbk2CmdWrite, ETrue);
       
   938                 aMenuPane->SetItemDimmed(EPbk2CmdUseNumber, ETrue );
       
   939                 aMenuPane->SetItemDimmed(EPbk2CmdPersonalRingingTone, ETrue);
       
   940                 aMenuPane->SetItemDimmed(EPbk2CmdImage, ETrue);
       
   941                 filtered = ETrue;
       
   942                 }
       
   943 
       
   944             // Ringing tone field
       
   945             if (FocusedFieldMatchesFieldTypeL(aControl,
       
   946                     R_PHONEBOOK2_RINGTONE_SELECTOR, manager))
       
   947                 {
       
   948                 aMenuPane->SetItemDimmed(EPbk2CmdWrite, ETrue);
       
   949                 aMenuPane->SetItemDimmed(EPbk2CmdGoToURL, ETrue);
       
   950                 aMenuPane->SetItemDimmed(EPbk2CmdEditMe, ETrue);
       
   951                 aMenuPane->SetItemDimmed(EPbk2CmdUseNumber, ETrue );
       
   952                 aMenuPane->SetItemDimmed(EPbk2CmdImage, ETrue);
       
   953                 filtered = ETrue;
       
   954                 }
       
   955 
       
   956             // Image/text context submenus
       
   957             if( FocusedFieldMatchesFieldTypeL(aControl,
       
   958                     R_PHONEBOOK2_IMAGE_SELECTOR, manager))
       
   959                 {
       
   960                 aMenuPane->SetItemDimmed(EPbk2CmdWrite, ETrue);
       
   961                 aMenuPane->SetItemDimmed(EPbk2CmdGoToURL, ETrue);
       
   962                 aMenuPane->SetItemDimmed(EPbk2CmdUseNumber, ETrue );
       
   963                 aMenuPane->SetItemDimmed(EPbk2CmdPersonalRingingTone, ETrue);
       
   964                 filtered = ETrue;
       
   965                 }
       
   966 
       
   967             if (!filtered)
       
   968                 {
       
   969                 // Default filtering leaves only edit option in the menu
       
   970                 aMenuPane->SetItemDimmed(EPbk2CmdWrite, ETrue);
       
   971                 aMenuPane->SetItemDimmed(EPbk2CmdGoToURL, ETrue);
       
   972                 aMenuPane->SetItemDimmed(EPbk2CmdUseNumber, ETrue );
       
   973                 aMenuPane->SetItemDimmed(EPbk2CmdPersonalRingingTone, ETrue);
       
   974                 aMenuPane->SetItemDimmed(EPbk2CmdImage, ETrue);
       
   975                 }
       
   976             break;
       
   977             }
       
   978 
       
   979         case R_PHONEBOOK2_IMAGE_SUBMENU:
       
   980             {
       
   981             if (FeatureManager::FeatureSupported(KFeatureIdCallImagetext))
       
   982                 {
       
   983                 if (FocusedContactHasFieldTypeL(aControl,
       
   984                         R_PHONEBOOK2_IMAGE_SELECTOR, manager) < 0)
       
   985                     {
       
   986                     // Weed out Image View command if contact has no image
       
   987                     // (it might have thumbnail from e.g. business card and
       
   988                     // and thus other image submenu options)
       
   989                     aMenuPane->SetItemDimmed(EPbk2CmdViewImage, ETrue);
       
   990                     }
       
   991                 }
       
   992             break;
       
   993             }
       
   994 
       
   995         default:
       
   996             {
       
   997             // AIW provider menus are filtered in the corresponding
       
   998             // interest item, for example R_PHONEBOOK2_CALL_CONTEXT_MENU
       
   999             // is filtered in CPbk2AiwInterestItemCall
       
  1000             break;
       
  1001             }
       
  1002         }
       
  1003     }
       
  1004 
       
  1005 // --------------------------------------------------------------------------
       
  1006 // CPbk2CommandHandler::AreSelectedContactsFromReadOnlyStoreL
       
  1007 // Returns ETrue if all selected contacts are read-only.
       
  1008 // --------------------------------------------------------------------------
       
  1009 //
       
  1010 inline TBool CPbk2CommandHandler::AreSelectedContactsFromReadOnlyStoreL(
       
  1011             MPbk2ContactUiControl& aControl)
       
  1012     {
       
  1013     // Default behavior is that selection is read-only, e.g
       
  1014     // a link can not be created for folding contact in which case
       
  1015     // the folding contact cannot be destroyed
       
  1016     TBool ret = ETrue;
       
  1017 
       
  1018     MPbk2ContactLinkIterator* iterator =
       
  1019         aControl.SelectedContactsIteratorL();
       
  1020     if ( iterator )
       
  1021         {
       
  1022         CleanupDeletePushL( iterator );
       
  1023 
       
  1024         while( iterator->HasNext() && ret )
       
  1025             {
       
  1026             MVPbkContactLink* link = iterator->NextL();
       
  1027 
       
  1028             if ( link && !IsFromReadOnlyStore( *link ) )
       
  1029                 {
       
  1030                 ret = EFalse;
       
  1031                 }
       
  1032 
       
  1033             delete link;
       
  1034             link = NULL;
       
  1035             }
       
  1036 
       
  1037         CleanupStack::PopAndDestroy(); // iterator
       
  1038         }
       
  1039     else
       
  1040         {
       
  1041         // There was no iterator so there are no selected contacts,
       
  1042         // this means we are operating with the focused contact
       
  1043         const MVPbkBaseContact* focusedContact =
       
  1044             aControl.FocusedContactL();
       
  1045         if ( focusedContact )
       
  1046             {
       
  1047             MVPbkContactLink* link = focusedContact->CreateLinkLC();
       
  1048             if ( link && !IsFromReadOnlyStore( *link ) )
       
  1049                 {
       
  1050                 ret = EFalse;
       
  1051                 }
       
  1052             CleanupStack::PopAndDestroy(); // link
       
  1053             }
       
  1054         }
       
  1055 
       
  1056     return ret;
       
  1057     }
       
  1058 
       
  1059 // --------------------------------------------------------------------------
       
  1060 // CPbk2CommandHandler::IsFromReadOnlyStore
       
  1061 // --------------------------------------------------------------------------
       
  1062 //
       
  1063 TBool CPbk2CommandHandler::IsFromReadOnlyStore(
       
  1064         const MVPbkContactLink& aContactLink ) const
       
  1065     {
       
  1066     TBool ret = EFalse;
       
  1067 
       
  1068     const MVPbkContactStore& store = aContactLink.ContactStore();
       
  1069     if ( store.StoreProperties().ReadOnly() )
       
  1070         {
       
  1071         ret = ETrue;
       
  1072         }
       
  1073 
       
  1074     return ret;
       
  1075     }
       
  1076 
       
  1077 // --------------------------------------------------------------------------
       
  1078 // CPbk2CommandHandler::HasSpeedDialL
       
  1079 // --------------------------------------------------------------------------
       
  1080 //
       
  1081 TBool CPbk2CommandHandler::HasSpeedDialL(
       
  1082         MPbk2ContactUiControl& aControl )
       
  1083     {
       
  1084     TBool hasAttribute(EFalse);
       
  1085 
       
  1086     const MVPbkStoreContact* storeContact =
       
  1087             aControl.FocusedStoreContact();
       
  1088 
       
  1089     // Convert presentation index to store index.
       
  1090     TInt index( ToStoreFieldIndexL(
       
  1091                     aControl.FocusedFieldIndex(),
       
  1092                     storeContact ) );
       
  1093 
       
  1094     if ( index != KErrNotFound )
       
  1095         {
       
  1096         const MVPbkStoreContactField& field =
       
  1097             storeContact->Fields().FieldAt( index );
       
  1098 
       
  1099 
       
  1100         hasAttribute =
       
  1101             iAppServices->ContactManager().ContactAttributeManagerL().
       
  1102             HasFieldAttributeL(
       
  1103                 CVPbkSpeedDialAttribute::Uid(),
       
  1104                 field );
       
  1105         }
       
  1106     return hasAttribute;
       
  1107     }
       
  1108 
       
  1109 // --------------------------------------------------------------------------
       
  1110 // CPbk2CommandHandler::ToStoreFieldIndexL
       
  1111 // --------------------------------------------------------------------------
       
  1112 //
       
  1113 TInt CPbk2CommandHandler::ToStoreFieldIndexL(
       
  1114         TInt aPresIndex,
       
  1115         const MVPbkStoreContact* aStoreContact )
       
  1116     {
       
  1117     // It is ok to remove const, we don't make any changes
       
  1118     MVPbkStoreContact* storeContact =
       
  1119         const_cast<MVPbkStoreContact*>( aStoreContact );
       
  1120 
       
  1121     TInt index( KErrNotFound );
       
  1122     if ( aPresIndex >= 0 )
       
  1123         {
       
  1124         CPbk2PresentationContact* presentationContact =
       
  1125             CPbk2PresentationContact::NewL(
       
  1126                 *storeContact,
       
  1127                 iAppServices->FieldProperties() );
       
  1128         CleanupStack::PushL( presentationContact );
       
  1129 
       
  1130         index = presentationContact->PresentationFields().
       
  1131                     StoreIndexOfField( aPresIndex );
       
  1132 
       
  1133         CleanupStack::PopAndDestroy( presentationContact );
       
  1134         }
       
  1135     return index;
       
  1136     }
       
  1137 
       
  1138 // End of File