phonebookui/Phonebook2/NamesListExtension/src/NamesListExView.cpp
changeset 0 e686773b3f54
child 3 04ab22b956c2
equal deleted inserted replaced
-1:000000000000 0:e686773b3f54
       
     1 /*
       
     2 * Copyright (c) 2009 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 names list extension view.
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 // INCLUDE FILES
       
    20 #include "Pbk2NamesListExView.h"
       
    21 #include "CPbk2CmdItemAddTop.h"
       
    22 #include "CPbk2CmdItemRemoteContactLookup.h"
       
    23 #include <cpbk2remotecontactlookupaccounts.h>
       
    24 #include <Pbk2ExNamesListRes.rsg>
       
    25 #include "Pbk2NlxMenuFiltering.h"
       
    26 #include "cpbk2cmditemmycard.h"
       
    27 #include "cpbk2mycard.h"
       
    28 #include "Pbk2NamesListEx.hrh"
       
    29 #include "cpbk2contextlaunch.h"
       
    30 
       
    31 #include "CPbk2ThumbnailManager.h"
       
    32 #include <spbcontentprovider.h>
       
    33 
       
    34 // Phonebook 2
       
    35 #include <CPbk2UIExtensionView.h>
       
    36 #include <MPbk2AppUi.h>
       
    37 #include <MPbk2ViewExplorer.h>
       
    38 #include "CPbk2ViewState.h"
       
    39 #include <MPbk2StartupMonitor.h>
       
    40 #include <Phonebook2.rsg>
       
    41 #include <Pbk2Commands.rsg>
       
    42 #include <Pbk2UIControls.rsg>
       
    43 #include <Pbk2CommonUi.rsg>
       
    44 #include <CPbk2ControlContainer.h>
       
    45 #include <CPbk2NamesListControl.h>
       
    46 #include <MPbk2CommandHandler.h>
       
    47 #include <Pbk2Commands.hrh>
       
    48 #include <MPbk2ViewActivationTransaction.h>
       
    49 #include <CPbk2ViewStateTransformer.h>
       
    50 #include <csxhelp/phob.hlp.hrh>
       
    51 #include <Pbk2UID.h>
       
    52 #include <MPbk2PointerEventInspector.h>
       
    53 #include <Phonebook2PrivateCRKeys.h>
       
    54 #include <CPbk2IconFactory.h>
       
    55 #include <TPbk2IconId.h>
       
    56 #include <CPbk2IconInfoContainer.h>
       
    57 #include <MPbk2ApplicationServices.h>
       
    58 #include <MPbk2ContactViewSupplier.h>
       
    59 #include <CPbk2StoreConfiguration.h>
       
    60 #include <Pbk2IconId.hrh>
       
    61 #include "Pbk2ContactUiControlProxy.h"
       
    62 #include <MPbk2UiControlCmdItem.h>
       
    63 #include <pbk2mapcommands.hrh>
       
    64 #include "Pbk2InternalCommands.hrh"
       
    65 
       
    66 #include "CVPbkContactManager.h"
       
    67 #include "MVPbkContactStoreList.h"
       
    68 #include "VPbkContactStoreUris.h"
       
    69 #include "TVPbkContactStoreUriPtr.h"
       
    70 
       
    71 //Cca
       
    72 #ifdef RD_PBK2_USE_CCA
       
    73     #include <MVPbkBaseContact.h>
       
    74     #include <mccaparameter.h>
       
    75     #include <mccaconnection.h>
       
    76     #include <ccafactory.h>
       
    77 //    #include <ccaerrors.h>
       
    78 #endif
       
    79 #include <ccafactory.h>
       
    80 #include <mccaconnection.h>
       
    81 
       
    82 // System includes
       
    83 #include <StringLoader.h>
       
    84 #include <centralrepository.h>
       
    85 #include <AiwCommon.hrh>
       
    86 #include <eikbtgpc.h>
       
    87 #include <avkon.rsg>
       
    88 #include <eikmenub.h>
       
    89 #include <AknUtils.h>
       
    90 #include <akntoolbar.h>
       
    91 #include <akntouchpane.h>
       
    92 #include <gulicon.h>
       
    93 #include <AknsUtils.h>
       
    94 #include <aknbutton.h>
       
    95 #include <eikcolib.h>
       
    96 #include <eiklbx.h>
       
    97 #include <touchfeedback.h>
       
    98 #include <aknstyluspopupmenu.h>
       
    99 #include <Pbk2Config.hrh>
       
   100 #include <layoutmetadata.cdl.h>
       
   101 #include <featmgr.h>
       
   102 #include <ecom.h>
       
   103 
       
   104 // Debugging headers
       
   105 #include <Pbk2Debug.h>
       
   106 #include <Pbk2Profile.h>
       
   107 
       
   108 //Phone memory checking
       
   109 #include <CPbk2ApplicationServices.h>
       
   110 #include <CVPbkContactStoreUriArray.h>
       
   111 #include <CPbk2StoreConfiguration.h>
       
   112 #include <VPbkContactStoreUris.h>
       
   113 #include <TVPbkContactStoreUriPtr.h>
       
   114 
       
   115 /// Unnamed namespace for local definitions
       
   116 namespace {
       
   117 
       
   118 #ifdef _DEBUG
       
   119 enum TPanicCode
       
   120     {
       
   121     EPanicPreCond_ConstructL = 1,
       
   122     EPanicPostCond_ConstructL,
       
   123     EPanicPostCond_DoActivateL,
       
   124     EPanicPreCond_HandleCommandL,
       
   125     EPanicLogic_DoTransformLegacyViewStateToPbk2ViewStateLC
       
   126     };
       
   127 
       
   128 void Panic(TPanicCode aReason)
       
   129     {
       
   130     _LIT( KPanicText, "CPbk2NamesListExView" );
       
   131     User::Panic( KPanicText, aReason );
       
   132     }
       
   133 #endif // _DEBUG
       
   134 
       
   135 
       
   136 /**
       
   137  * Returns ETrue if shift is depressed in aKeyEvent.
       
   138  *
       
   139  * @param aKeyEvent Key event.
       
   140  * @return  ETrue if shift is down.
       
   141  */
       
   142 inline TBool ShiftDown
       
   143         ( const TKeyEvent& aKeyEvent )
       
   144     {
       
   145     return ( aKeyEvent.iModifiers &
       
   146         ( EModifierShift | EModifierLeftShift | EModifierRightShift ) ) != 0;
       
   147     }
       
   148 
       
   149 /**
       
   150  * Returns ETrue if either Shift or Control key is depressed.
       
   151  *
       
   152  * @param aKeyEvent Key event.
       
   153  * @return  ETrue if shift or control is down.
       
   154  */
       
   155 inline TBool IsShiftOrControlDown( const TKeyEvent& aKeyEvent )
       
   156     {
       
   157     return ( aKeyEvent.iModifiers &
       
   158         ( EModifierShift | EModifierLeftShift | EModifierRightShift |
       
   159           EModifierCtrl | EModifierLeftCtrl | EModifierRightCtrl ) ) != 0;
       
   160     }
       
   161 
       
   162 /**
       
   163  * Creates a toolbar button with a skinnable icon
       
   164  *
       
   165  * @param aIconFactory  Icon factory that must contain the toolbar
       
   166  *                      button icon.
       
   167  * @param aPbk2IconId   Id for Phonebook2 icon for all button states.
       
   168  * @return  CAknButton instance.
       
   169  */
       
   170 CAknButton* CreateToolbarButtonLC
       
   171         ( CPbk2IconFactory& aIconFactory, TInt aPbk2IconId, TInt aHelpTextResId )
       
   172     {
       
   173     TPbk2IconId iconId( TUid::Uid(KPbk2UID3), aPbk2IconId );
       
   174     CGulIcon* icon = aIconFactory.CreateIconLC( iconId );
       
   175 
       
   176     HBufC* helpText = CCoeEnv::Static()->AllocReadResourceLC( aHelpTextResId );
       
   177 
       
   178     CAknButton* button = CAknButton::NewL( icon, NULL, NULL, NULL,
       
   179         KNullDesC, *helpText, KAknButtonSizeFitText, 0 );
       
   180 
       
   181     CleanupStack::PopAndDestroy();//helpText
       
   182 
       
   183     CleanupStack::Pop( icon );
       
   184     CleanupStack::PushL( button );
       
   185     return button;
       
   186     }
       
   187 
       
   188 }  /// namespace
       
   189 
       
   190 // --------------------------------------------------------------------------
       
   191 // CPbk2NamesListExView::CPbk2NamesListExView
       
   192 // --------------------------------------------------------------------------
       
   193 //
       
   194 CPbk2NamesListExView::CPbk2NamesListExView
       
   195         ( CPbk2UIExtensionView& aView,
       
   196           CSpbContentProvider& aStatusProvider,
       
   197           MCCAConnection*& aCCAConnection ) :
       
   198         iView( aView ),
       
   199         iCommandState( ETrue ),
       
   200         iCurrentCommandId( KErrNotFound ),
       
   201         iCtrlVisibleStateBeforeLosingForground( ETrue ),
       
   202         iFirstTimeActivated( ETrue ),
       
   203         iContentProvider( aStatusProvider ),
       
   204         iCCAConnection( aCCAConnection )
       
   205     {
       
   206     }
       
   207 
       
   208 // --------------------------------------------------------------------------
       
   209 // CPbk2NamesListAppView::~CPbk2NamesListAppView
       
   210 // --------------------------------------------------------------------------
       
   211 //
       
   212 CPbk2NamesListExView::~CPbk2NamesListExView()
       
   213     {
       
   214     PBK2_DEBUG_PRINT(PBK2_DEBUG_STRING
       
   215         ("CPbk2NamesListExView(%x)::~CPbk2NamesListExView()"), this);
       
   216 
       
   217     if ( iStoreConfiguration )
       
   218         {
       
   219         iStoreConfiguration->RemoveObserver( *this );
       
   220         }
       
   221 
       
   222     delete iControlState;
       
   223     delete iIdleToolbarWarden;
       
   224     delete iToolbarIcons;
       
   225     if ( iToolbar )
       
   226         {
       
   227         iToolbar->SetToolbarObserver( NULL );
       
   228         }
       
   229 
       
   230     if (iContainer)
       
   231         {
       
   232         iContainer->RemoveForegroundObserver();
       
   233         CCoeEnv::Static()->AppUi()->RemoveFromStack(iContainer);
       
   234         delete iContainer;
       
   235         }
       
   236 
       
   237     delete iIdleTexter;
       
   238     delete iControlProxy;
       
   239 
       
   240     delete iMyCard;
       
   241     CCoeEnv::Static()->RemoveForegroundObserver( *this );
       
   242 
       
   243 
       
   244     delete iThumbManager;
       
   245     delete iContextLauncher;
       
   246     FeatureManager::UnInitializeLib();
       
   247     }
       
   248 
       
   249 // --------------------------------------------------------------------------
       
   250 // CPbk2NamesListExView::NewL
       
   251 // --------------------------------------------------------------------------
       
   252 //
       
   253 CPbk2NamesListExView* CPbk2NamesListExView::NewL
       
   254         ( CPbk2UIExtensionView& aView,
       
   255           CSpbContentProvider& aStatusProvider,
       
   256           MCCAConnection*& aCCAConnection )
       
   257     {
       
   258     CPbk2NamesListExView* self = new ( ELeave ) CPbk2NamesListExView
       
   259         ( aView, aStatusProvider, aCCAConnection );
       
   260     CleanupStack::PushL( self );
       
   261     self->ConstructL();
       
   262     CleanupStack::Pop( self );
       
   263     return self;
       
   264     }
       
   265 
       
   266 // --------------------------------------------------------------------------
       
   267 // CPbk2NamesListExView::ConstructL
       
   268 // --------------------------------------------------------------------------
       
   269 //
       
   270 inline void CPbk2NamesListExView::ConstructL()
       
   271     {
       
   272     FeatureManager::InitializeLibL();
       
   273 
       
   274     // PreCond
       
   275     __ASSERT_DEBUG(!iContainer, Panic(EPanicPreCond_ConstructL));
       
   276     PBK2_PROFILE_START(Pbk2Profile::ENamesListExViewConstruction);
       
   277     CCoeEnv::Static()->AddForegroundObserverL(*this);
       
   278 
       
   279     iContactManager = &(Phonebook2::Pbk2AppUi()->ApplicationServices().ContactManager());
       
   280     iNameFormatter = &(Phonebook2::Pbk2AppUi()->ApplicationServices().NameFormatter());
       
   281 
       
   282     PBK2_PROFILE_START(Pbk2Profile::ENamesListGetCommandHandler);
       
   283     iCommandHandler = Phonebook2::Pbk2AppUi()->ApplicationServices().CommandHandlerL();
       
   284     PBK2_PROFILE_END(Pbk2Profile::ENamesListGetCommandHandler);
       
   285 
       
   286     // Register this view as a store configuration observer
       
   287     PBK2_PROFILE_START(Pbk2Profile::ENamesListRegisterStoreConfiguration);
       
   288     iStoreConfiguration = &Phonebook2::Pbk2AppUi()->ApplicationServices().StoreConfiguration();
       
   289     iStoreConfiguration->AddObserverL( *this );
       
   290     PBK2_PROFILE_END(Pbk2Profile::ENamesListRegisterStoreConfiguration);
       
   291     
       
   292     iControlProxy = new( ELeave )CPbk2ContactUiControlProxy;
       
   293 
       
   294     iThumbManager = CPbk2ThumbnailManager::NewL( *iContactManager );
       
   295     iContextLauncher = new(ELeave) CPbk2ContextLaunch( iCCAConnection );
       
   296 
       
   297     PBK2_PROFILE_END(Pbk2Profile::ENamesListPenSupportConstruction);
       
   298 
       
   299     if( FeatureManager::FeatureSupported( KFeatureIdffContactsMycard ) )
       
   300         {
       
   301         // Get the phoneStore for MyCard
       
   302         MVPbkContactStore* phoneStore = iContactManager->ContactStoresL()
       
   303             .Find(VPbkContactStoreUris::DefaultCntDbUri());
       
   304     
       
   305         if(phoneStore)
       
   306             {
       
   307             iMyCard = CPbk2MyCard::NewL( *phoneStore );
       
   308             }
       
   309         }
       
   310     
       
   311     // Attach AIW providers
       
   312     AttachAIWProvidersL();
       
   313 
       
   314     // Do not create the container control here: defer creation to first
       
   315     // activation of the view (first DoActivateL call). This saves a lot
       
   316     // of memory and application starting time, because all the application
       
   317     // views (classes like this) must be created at startup. Controls will
       
   318     // be created on-demand as the views are accessed.
       
   319 
       
   320     PBK2_PROFILE_END(Pbk2Profile::ENamesListExViewConstruction);
       
   321     // PostCond
       
   322     __ASSERT_DEBUG(!iContainer, Panic(EPanicPostCond_ConstructL));
       
   323     }
       
   324 
       
   325 // --------------------------------------------------------------------------
       
   326 // CPbk2NamesListExView::ConstructToolbarL
       
   327 // --------------------------------------------------------------------------
       
   328 //
       
   329 void CPbk2NamesListExView::ConstructToolbarL()
       
   330     {
       
   331     if ( AknLayoutUtils::PenEnabled() )
       
   332         {
       
   333         iToolbar = iView.Toolbar();
       
   334         if ( iToolbar )
       
   335             {
       
   336             // Take toolbar control event handling from touch pane.
       
   337             // Events need to be forwarded to touch pane manually.
       
   338             iToolbar->SetObserver( this );
       
   339             iToolbar->SetToolbarObserver( this );
       
   340 
       
   341             // Add toolbar buttons with skinnable icons
       
   342             iToolbarIcons = CPbk2IconInfoContainer::NewL(
       
   343                 R_PBK2_NAMESLIST_TOOLBAR_ICON_INFO_ARRAY );
       
   344             CPbk2IconFactory* factory =
       
   345                 CPbk2IconFactory::NewLC( *iToolbarIcons );
       
   346 
       
   347             // Button 1: Call
       
   348             CAknButton* button = CreateToolbarButtonLC(
       
   349                 *factory, EPbk2qgn_indi_tb_call, R_PHOB_TB_CALL );
       
   350             iToolbar->AddItemL(
       
   351                 button, EAknCtButton, EPbk2CmdCall, 0, 0 );
       
   352             CleanupStack::Pop( button );
       
   353 
       
   354             // Button 2: Write message
       
   355             button = CreateToolbarButtonLC(
       
   356                 *factory, EPbk2qgn_indi_tb_mce, R_PHOB_TB_CREATE_MSG );
       
   357             iToolbar->AddItemL(
       
   358                 button, EAknCtButton, EPbk2CmdWriteNoQuery, 0, 1 );
       
   359             CleanupStack::Pop( button );
       
   360 
       
   361             // Button 3: Create new contact
       
   362             button = CreateToolbarButtonLC(
       
   363                 *factory, EPbk2qgn_indi_tb_avail_contacts, R_PHOB_TB_NEW_CONTACT );
       
   364             iToolbar->AddItemL(
       
   365                 button, EAknCtButton, EPbk2CmdCreateNew, 0, 2 );
       
   366             CleanupStack::Pop( button );
       
   367 
       
   368             CleanupStack::PopAndDestroy( factory );
       
   369 
       
   370             // Load the previously saved toolbar state
       
   371             CRepository* cenrep =
       
   372                 CRepository::NewLC( TUid::Uid( KCRUidPhonebook ) );
       
   373             User::LeaveIfError(
       
   374                 cenrep->Get( KPhonebookNamesListToolbarVisibility,
       
   375                              iToolbarVisible ) );
       
   376             CleanupStack::PopAndDestroy( cenrep );
       
   377 
       
   378             // FIXME: toolbar is now always on after fixed toolbar is taken to use.
       
   379             // so the toolbar visibility storing and handling code including the cenrep key
       
   380             // could probably be removed now
       
   381             iToolbar->SetToolbarVisibility(ETrue, EFalse);
       
   382             }
       
   383         }
       
   384     }
       
   385 
       
   386 // --------------------------------------------------------------------------
       
   387 // CPbk2NamesListExView::HandleCommandL
       
   388 // --------------------------------------------------------------------------
       
   389 //
       
   390 void CPbk2NamesListExView::HandleCommandL(TInt aCommandId)
       
   391     {
       
   392     // If this view has already been deactivated, just return.
       
   393     if ( Phonebook2::Pbk2AppUi()->ActiveView()->Id() != Phonebook2::KPbk2NamesListViewUid )
       
   394         {
       
   395         return;
       
   396         }
       
   397 
       
   398     // In case "open" is chosen and a command item is highlighted, need to remap
       
   399     // cmd ID from openCca to the correct cmd ID. For command items "select" is used.
       
   400     // Not very elegant. Another way would be to dynamically change the OK cmd assignment
       
   401     // all the time as UI state changes.
       
   402     if ( iControl->FocusedCommandItem() &&
       
   403         !iControl->ContactsMarked() &&
       
   404         (aCommandId == EPbk2CmdOpenCca || aCommandId == EAknSoftkeySelect ) )
       
   405         {
       
   406         aCommandId = iControl->FocusedCommandItem()->CommandId();
       
   407         }
       
   408 
       
   409     if ( iControl->FocusedCommandItem() &&
       
   410         !iControl->ContactsMarked() &&
       
   411         aCommandId == EPbk2CmdSelectRclCmdItem )
       
   412         {
       
   413         aCommandId = EPbk2CmdRcl;
       
   414         }    
       
   415 
       
   416     if ( EAknCmdHideInBackground != aCommandId )
       
   417         {
       
   418         iCurrentCommandId = aCommandId;
       
   419         }
       
   420 
       
   421     // No command handling in this class, forward to Commands
       
   422     if (!iCommandHandler->HandleCommandL( aCommandId, *iControlProxy, &iView ))
       
   423         {
       
   424         iControl->ProcessCommandL(aCommandId);
       
   425         // Command was not handled in Pbk2Commands, forward it to AppUi
       
   426         Phonebook2::Pbk2AppUi()->HandleCommandL(aCommandId);
       
   427 
       
   428         // Update CBAs, if command handler is consuming the command
       
   429         // postcommandexecution is updating CBAs
       
   430         UpdateCbasL();
       
   431         }
       
   432     }
       
   433 
       
   434 // --------------------------------------------------------------------------
       
   435 // CPbk2NamesListExView::Id
       
   436 // --------------------------------------------------------------------------
       
   437 //
       
   438 TUid CPbk2NamesListExView::Id() const
       
   439     {
       
   440     return Phonebook2::KPbk2NamesListViewUid;
       
   441     }
       
   442 
       
   443 // --------------------------------------------------------------------------
       
   444 // CPbk2NamesListExView::HandleStatusPaneSizeChange
       
   445 // --------------------------------------------------------------------------
       
   446 //
       
   447 void CPbk2NamesListExView::HandleStatusPaneSizeChange()
       
   448     {
       
   449     // Resize the container to fill the client rectangle
       
   450     if (iContainer)
       
   451         {
       
   452         iContainer->SetRect(iView.ClientRect());
       
   453         }
       
   454     if ( iToolbar && NeedToHideToolbar(iCurrentCommandId) )
       
   455         {
       
   456         // If Command is is executing (iCommandState:0)
       
   457         // Ordinal priority of iToolbar is set to ECoeWinPriorityLow.
       
   458         iToolbar->DrawableWindow()->SetOrdinalPosition
       
   459             ( 0, iCommandState ? ECoeWinPriorityNormal : ECoeWinPriorityLow );
       
   460         }
       
   461     }
       
   462 
       
   463 // --------------------------------------------------------------------------
       
   464 // CPbk2NamesListExView::DoActivateL
       
   465 // --------------------------------------------------------------------------
       
   466 //
       
   467 void CPbk2NamesListExView::DoActivateL
       
   468         ( const TVwsViewId& aPrevViewId, TUid aCustomMessageId,
       
   469          const TDesC8& aCustomMessage )
       
   470     {
       
   471     /// Notice that when "always on" feature is used this is called second
       
   472     /// time without calling DoDeactivate, when exit is done.
       
   473     /// This function must not do any duplicate resource allocation.
       
   474 
       
   475     PBK2_DEBUG_PRINT(PBK2_DEBUG_STRING
       
   476         ("CPbk2NamesListExView(%x)::DoActivateL()"), this);
       
   477 
       
   478     PBK2_PROFILE_START(Pbk2Profile::ENamesListViewDoActivateL);
       
   479 
       
   480     PBK2_PROFILE_START
       
   481         ( Pbk2Profile::ENamesListViewDoActivateAddMenuCommandObserver );
       
   482     // Do not add duplicate if DoActivateL is called due to Exit in
       
   483     // always on mode.
       
   484     iCommandHandler->RemoveMenuCommandObserver( *this );
       
   485     // Add this view to observ command events
       
   486     iCommandHandler->AddMenuCommandObserver(*this);
       
   487     PBK2_PROFILE_END
       
   488         ( Pbk2Profile::ENamesListViewDoActivateAddMenuCommandObserver );
       
   489 
       
   490     PBK2_PROFILE_START(Pbk2Profile::ENamesListViewDoActivateLoadTitle);
       
   491     HBufC* title = StringLoader::LoadLC(R_QTN_PHOB_TITLE);
       
   492     PBK2_PROFILE_END(Pbk2Profile::ENamesListViewDoActivateLoadTitle);
       
   493 
       
   494     PBK2_PROFILE_START
       
   495         ( Pbk2Profile::ENamesListViewDoActivateHandleViewActivation );
       
   496     MPbk2ViewActivationTransaction* viewActivationTransaction =
       
   497         Phonebook2::Pbk2AppUi()->Pbk2ViewExplorer()->HandleViewActivationLC
       
   498             ( Id(), aPrevViewId, title, NULL,
       
   499               Phonebook2::EUpdateNaviPane | Phonebook2::EUpdateTitlePane |
       
   500               Phonebook2::EUpdateContextPane );
       
   501     PBK2_PROFILE_END
       
   502         ( Pbk2Profile::ENamesListViewDoActivateHandleViewActivation );
       
   503 
       
   504     // Create control and activate it.
       
   505     PBK2_PROFILE_START(Pbk2Profile::ENamesListViewDoActivateActivateControl);
       
   506     CreateControlsL();
       
   507     iContainer->ActivateL();
       
   508     PBK2_PROFILE_END(Pbk2Profile::ENamesListViewDoActivateActivateControl);
       
   509 
       
   510     // Check activation parameters
       
   511     PBK2_PROFILE_START(Pbk2Profile::ENamesListViewDoActivateParamHandling);
       
   512     delete iParamState;
       
   513     iParamState = NULL;
       
   514     if( aCustomMessageId == CPbk2ContextLaunch::Uid() )
       
   515         {
       
   516         // Close up any open CCA instances
       
   517         if( iCCAConnection )
       
   518             {
       
   519             iCCAConnection->Close();
       
   520             iCCAConnection = NULL;
       
   521             }
       
   522         
       
   523         // Handle context launch request
       
   524         if( iContextLauncher )
       
   525             {
       
   526             iContextLauncher->HandleMessageL( aCustomMessage );
       
   527             }
       
   528         }
       
   529     else if (aCustomMessageId == CPbk2ViewState::Uid())
       
   530         {
       
   531         // Restore state when TPbk2ControlEvent::EReady comes.
       
   532         iParamState = CPbk2ViewState::NewL(aCustomMessage);
       
   533         }
       
   534     else if (aCustomMessageId == TUid::Uid(KPbkViewStateUid))
       
   535         {
       
   536         // Handle legacy view state
       
   537         CPbk2ViewStateTransformer* transformer =
       
   538             CPbk2ViewStateTransformer::NewLC( *iContactManager );
       
   539         // Restore state when TPbk2ControlEvent::EReady comes.
       
   540         iParamState = transformer->
       
   541             TransformLegacyViewStateToPbk2ViewStateLC
       
   542                 ( aCustomMessage );
       
   543         CleanupStack::Pop(iParamState);
       
   544         CleanupStack::PopAndDestroy(transformer);
       
   545         }
       
   546     PBK2_PROFILE_END(Pbk2Profile::ENamesListViewDoActivateParamHandling);
       
   547 
       
   548     viewActivationTransaction->Commit();
       
   549     CleanupStack::PopAndDestroy(2,title); // viewActivationTransaction, title
       
   550 
       
   551     // The application is set here to background if application exit occurs
       
   552     PBK2_PROFILE_START
       
   553         ( Pbk2Profile::ENamesListViewDoActivateNotifyViewActivatation );
       
   554 
       
   555     // The application is set here to background if application exit occurs
       
   556     // When the device is powered on, Phonebook will start up automatically and
       
   557     // hide itself in the background. At the first time of names list view activation,
       
   558     // event is generated, the notification needs to be sent to Startup Monitor
       
   559     // so that making UI controls displaying properly.
       
   560     // At the first time of the activation, since all controls are brand new so
       
   561     // the iControl->Reset() needn’t to be called.
       
   562     if ( iParamState && iParamState->Flags() &
       
   563          CPbk2ViewState::ESendToBackground && !iFirstTimeActivated)
       
   564         {
       
   565         // AppUi will send the application to background.
       
   566 
       
   567         // Because the control is not destroyed it must be reset so that
       
   568         // when the view comes foreground again it will look like a fresh
       
   569         // and brand new control.
       
   570         iControl->Reset();
       
   571         }
       
   572     else if (Phonebook2::Pbk2AppUi()->Pbk2StartupMonitor())
       
   573         {
       
   574         // We are not going to background. Notify the start-up monitor that
       
   575         // will need to know the when the first view is activated.
       
   576         Phonebook2::Pbk2AppUi()->Pbk2StartupMonitor()->NotifyViewActivationL(Id());
       
   577 
       
   578         // Reset flag
       
   579         iFirstTimeActivated = EFalse;
       
   580         }
       
   581     PBK2_PROFILE_END
       
   582         ( Pbk2Profile::ENamesListViewDoActivateNotifyViewActivatation );
       
   583 
       
   584     PBK2_PROFILE_END(Pbk2Profile::ENamesListViewDoActivateL);
       
   585 
       
   586     CCoeControl* ctrl=iControl->ComponentControl(0);
       
   587     CEikListBox* listbox=static_cast <CEikListBox*> (ctrl);
       
   588     listbox->SetListBoxObserver( this );
       
   589 
       
   590     // iCtrlVisibleStateBeforeLosingForground records the names list control states before
       
   591     // losing foreground during a command execution. Set the iCtrlVisibleStateBeforeLosingForground
       
   592     // flag as ETrue as the control should be visible when active a view.
       
   593     iCtrlVisibleStateBeforeLosingForground = ETrue;
       
   594 
       
   595     // PostCond:
       
   596     __ASSERT_DEBUG(iContainer, Panic(EPanicPostCond_DoActivateL));
       
   597     }
       
   598 
       
   599 // --------------------------------------------------------------------------
       
   600 // CPbk2NamesListExView::AddCommandItemsToContainerL
       
   601 // --------------------------------------------------------------------------
       
   602 //
       
   603 void CPbk2NamesListExView::AddCommandItemsToContainerL()
       
   604     {
       
   605     // get command item count
       
   606     TInt commandCount = iControl->CommandItemCount();
       
   607        
       
   608     // Check if there is need to create MyCard
       
   609     if( !iMyCard && IsPhoneMemoryUsedL() ) 
       
   610     	{				
       
   611 		// Get the phoneStore for MyCard
       
   612 		MVPbkContactStore* phoneStore = iContactManager->ContactStoresL()
       
   613     		.Find(VPbkContactStoreUris::DefaultCntDbUri() );
       
   614 		
       
   615 		if( phoneStore )
       
   616 			{
       
   617 			// Create MyCard if not already exist and the phone memory selected
       
   618 			iMyCard = CPbk2MyCard::NewL( *phoneStore );
       
   619 			}
       
   620     	}
       
   621     
       
   622     // Add the MyCard item to the top of the list
       
   623     if( iMyCard && IsPhoneMemoryUsedL() )
       
   624         {
       
   625         CPbk2CmdItemMyCard* cmd = 
       
   626             CPbk2CmdItemMyCard::NewLC( *iMyCard, iContentProvider );
       
   627         iControl->AddCommandItemL( cmd, commandCount ); // ownership transferred
       
   628         CleanupStack::Pop( cmd );
       
   629         commandCount++;
       
   630         }
       
   631 
       
   632     CPbk2CmdItemAddTop* listCmd = CPbk2CmdItemAddTop::NewLC();
       
   633     // Add the command item to the bottom of the command list
       
   634     iControl->AddCommandItemL( listCmd, commandCount ); // ownership transferred
       
   635     CleanupStack::Pop( listCmd );
       
   636     commandCount++;
       
   637     
       
   638 
       
   639    // promotion item disabled until we can support command items at the bottom of the list
       
   640    // if ( IsRclOnL() )  
       
   641     if( 0 )
       
   642 	    {
       
   643         CPbk2CmdItemRemoteContactLookup* rclCmd = CPbk2CmdItemRemoteContactLookup::NewLC();
       
   644         // Add the command item to the bottom of the command list
       
   645         iControl->AddCommandItemL( rclCmd, commandCount ); // ownership transferred
       
   646         CleanupStack::Pop( rclCmd );
       
   647         commandCount++;
       
   648 	    }
       
   649     }
       
   650 
       
   651 // --------------------------------------------------------------------------
       
   652 // CPbk2NamesListExView::IsRclOnL
       
   653 // --------------------------------------------------------------------------
       
   654 //
       
   655 TBool CPbk2NamesListExView::IsRclOnL()
       
   656     {
       
   657     TBool ret(EFalse);
       
   658 
       
   659     if( FeatureManager::FeatureSupported( KFeatureIdFfContactsRemoteLookup ))
       
   660         {
       
   661         //1. Get default protocol account
       
   662         TPbkxRemoteContactLookupProtocolAccountId accountID =
       
   663         CPbk2RemoteContactLookupAccounts::DefaultAccountIdL();
       
   664         
       
   665         //2. Check that there really are implementation and account corresponding to 
       
   666         //repository's value
       
   667         // If the iProtocolUid is NULL, then a default account has not been set.
       
   668         if ( accountID.iProtocolUid.iUid )
       
   669             {
       
   670             CPbkxRemoteContactLookupProtocolAccount* account = NULL;
       
   671             // Returns NULL if account or plugin doesn't exist
       
   672             account = CPbk2RemoteContactLookupAccounts::GetAccountL( accountID );
       
   673             if ( account )
       
   674                 {
       
   675                 ret = ETrue;
       
   676                 delete account;
       
   677                 }
       
   678             }            
       
   679         }
       
   680     return ret;
       
   681     }
       
   682 
       
   683 // --------------------------------------------------------------------------
       
   684 // CPbk2NamesListExView::MyCard
       
   685 // --------------------------------------------------------------------------
       
   686 //
       
   687 CPbk2MyCard* CPbk2NamesListExView::MyCard() const
       
   688     {			
       
   689 	TBool phoneMemory = EFalse;
       
   690 	
       
   691 	TRAP_IGNORE( phoneMemory = IsPhoneMemoryUsedL() );
       
   692 	
       
   693 	if( phoneMemory )
       
   694 		{
       
   695 		return iMyCard;
       
   696 		}
       
   697 	
       
   698 	return NULL;
       
   699     }
       
   700 
       
   701 // --------------------------------------------------------------------------
       
   702 // CPbk2NamesListExView::DoDeactivate
       
   703 // --------------------------------------------------------------------------
       
   704 //
       
   705 void CPbk2NamesListExView::DoDeactivate()
       
   706     {
       
   707     PBK2_DEBUG_PRINT(PBK2_DEBUG_STRING
       
   708         ("CPbk2NamesListExView(%x)::DoDeactivate()"), this);
       
   709 
       
   710     if ( iCommandHandler )
       
   711         {
       
   712         iCommandHandler->RemoveMenuCommandObserver( *this );
       
   713         }
       
   714 
       
   715     // Cancel toolbar warden to prevent further state saving
       
   716     if( iIdleToolbarWarden )
       
   717         {
       
   718         iIdleToolbarWarden->Cancel();
       
   719         }
       
   720 
       
   721     // Disable focus of toobar, so that it can't steal it from other views
       
   722     if( iToolbar )
       
   723         {
       
   724         iToolbar->SetFocusing( EFalse );
       
   725         }
       
   726 
       
   727     if( iIdleTexter )
       
   728         {
       
   729         iIdleTexter->Cancel();
       
   730         }
       
   731 
       
   732     // Trash the old states
       
   733     delete iParamState;
       
   734     iParamState = NULL;
       
   735     delete iControlState;
       
   736     iControlState = NULL;
       
   737     
       
   738     if (iContainer)
       
   739         {
       
   740         CCoeEnv::Static()->AppUi()->RemoveFromStack(iContainer);
       
   741         // Store current state, safe to ignore. There's no real harm,
       
   742         // if theres no stored state when activating this view again
       
   743         TRAP_IGNORE(StoreStateL());
       
   744         iControl->SetObserver(NULL);
       
   745         delete iContainer;
       
   746         iContainer = NULL;
       
   747         // Reset also the reference to the control
       
   748         iControl = NULL;
       
   749         iControlProxy->SetControl( NULL );
       
   750         }
       
   751     }
       
   752 
       
   753 // --------------------------------------------------------------------------
       
   754 // CPbk2NamesListExView::DynInitMenuPaneL
       
   755 // --------------------------------------------------------------------------
       
   756 //
       
   757 void CPbk2NamesListExView::DynInitMenuPaneL
       
   758         ( TInt aResourceId, CEikMenuPane* aMenuPane )
       
   759     {
       
   760     // Ask the control to do control specific filtering
       
   761     // (for example call HandleMarkableListDynInitMenuPane if needed)
       
   762     iControl->DynInitMenuPaneL(aResourceId, aMenuPane);
       
   763 
       
   764     // Phonebook 2 menu filtering happens in Commands
       
   765     iCommandHandler->DynInitMenuPaneL(
       
   766         aResourceId, aMenuPane, iView, *iControl);
       
   767 
       
   768     //This is called after CPbk2CommandHandler::PerformStandardMenuFilteringL
       
   769     //so we can safely remove here anything that may already also be removed
       
   770     //there.
       
   771     switch (aResourceId)
       
   772         {
       
   773         case R_PHONEBOOK2_NAMESLIST_SEND_URL_MENU:
       
   774             {
       
   775             DimItem( aMenuPane, EPbk2CmdGoToURL );
       
   776             break;
       
   777             }
       
   778         case R_PHONEBOOK2_NAMELIST_CREATE_MESSAGE_MENU:
       
   779             {
       
   780             TInt pos;
       
   781             if ( aMenuPane->MenuItemExists( EPbk2CmdWriteNoQuery, pos ) )
       
   782                 {
       
   783                 aMenuPane->SetItemSpecific( EPbk2CmdWriteNoQuery, !iControl->ContactsMarked() );
       
   784                 }
       
   785             break;
       
   786             }
       
   787         default:
       
   788             {
       
   789             break;
       
   790             }
       
   791         }
       
   792     }
       
   793 
       
   794 // --------------------------------------------------------------------------
       
   795 // CPbk2NamesListAppView::DimItem
       
   796 // --------------------------------------------------------------------------
       
   797 //
       
   798 void CPbk2NamesListExView::DimItem( CEikMenuPane* aMenuPane, TInt aCmd )
       
   799     {
       
   800     TInt pos;
       
   801     if ( aMenuPane->MenuItemExists( aCmd, pos ) )
       
   802         {
       
   803         aMenuPane->SetItemDimmed( aCmd, ETrue );
       
   804         }
       
   805     }
       
   806 
       
   807 // --------------------------------------------------------------------------
       
   808 // CPbk2NamesListExView::HandleForegroundEventL
       
   809 // --------------------------------------------------------------------------
       
   810 //
       
   811 void CPbk2NamesListExView::HandleForegroundEventL( TBool aForeground )
       
   812     {
       
   813     // CPbk2AppView::HandleForegroundEventL( aForeground );
       
   814 
       
   815     // If this view is gaining foreground, then make sure that thumbnail
       
   816     // gets drawn
       
   817     if ( aForeground && iControl )
       
   818         {
       
   819         if ( iControl->IsVisible() )
       
   820             {
       
   821             iControl->ShowThumbnail();
       
   822             }
       
   823         }
       
   824     }
       
   825 
       
   826 // --------------------------------------------------------------------------
       
   827 // CPbk2NamesListExView::ViewStateLC
       
   828 // --------------------------------------------------------------------------
       
   829 //
       
   830 CPbk2ViewState* CPbk2NamesListExView::ViewStateLC() const
       
   831     {
       
   832     CPbk2ViewState* state = NULL;
       
   833     if (iControl)
       
   834         {
       
   835         state = iControl->ControlStateL();
       
   836         }
       
   837     CleanupStack::PushL(state);
       
   838     return state;
       
   839     }
       
   840 
       
   841 // --------------------------------------------------------------------------
       
   842 // CPbk2NamesListExView::HandleCommandKeyL
       
   843 // --------------------------------------------------------------------------
       
   844 //
       
   845 TBool CPbk2NamesListExView::HandleCommandKeyL
       
   846         ( const TKeyEvent& aKeyEvent, TEventCode aType )
       
   847     {
       
   848     // re-initialized the findbox focus if the application is back in the
       
   849     // foreground.
       
   850     if ( iNeedSetFocus  && iView.IsForeground() )
       
   851         {
       
   852         iNeedSetFocus = EFalse;
       
   853         iControl->FocusChanged( EDrawNow );
       
   854         }
       
   855 
       
   856     /* Uncomment this code if it is necessary to enable navigation hardware keys
       
   857      * on devices which have these keys (its Map Extension feature)
       
   858     if( aKeyEvent.iScanCode == EStdKeyApplicationD && aType == EEventKeyUp )
       
   859         {
       
   860         HandleCommandL( EPbk2ExtensionAssignFromMap );
       
   861         return ETrue;
       
   862         }
       
   863 
       
   864     if( aKeyEvent.iScanCode == EStdKeyApplicationE && aType == EEventKeyUp )
       
   865         {
       
   866         HandleCommandL( EPbk2ExtensionShowOnMap );
       
   867         return ETrue;
       
   868         }*/
       
   869     TBool itemSpecEnabled = iView.MenuBar()->ItemSpecificCommandsEnabled();
       
   870     
       
   871     TBool result = EFalse;
       
   872     if (aType == EEventKey)
       
   873         {
       
   874         switch (aKeyEvent.iCode)
       
   875             {
       
   876             case EKeyPhoneSend:
       
   877                 {
       
   878                 if ( itemSpecEnabled && iControl->NumberOfContacts() > 0 &&
       
   879                      !iControl->ContactsMarked() )
       
   880                     {
       
   881                     // Do not handle the call command if there is a dialog displayed
       
   882                     if ( !(CEikonEnv::Static()->EikAppUi()->IsDisplayingDialog()) )
       
   883                         {
       
   884                         // Use the EPbk2CmdCall id to identify that
       
   885                         // call is being launched with send key
       
   886                         HandleCommandL(EPbk2CmdCall);
       
   887                         }
       
   888                     result = ETrue;
       
   889                     }
       
   890                 break;
       
   891                 }
       
   892             case EKeyPoC:
       
   893                 {
       
   894                 // Use the EPbk2CmdPoC id to identify that
       
   895                 // call is being launched with PoC key
       
   896                 HandleCommandL( EPbk2CmdPoC );
       
   897                 result = ETrue;
       
   898                 break;
       
   899                 }
       
   900             case EKeyBackspace:
       
   901                 {
       
   902                 if ( (itemSpecEnabled && (iControl->NumberOfContacts() > 0))
       
   903                     || iControl->ContactsMarked() )
       
   904                     {
       
   905                     if (iControl->FindTextL() == KNullDesC)
       
   906                         {
       
   907                         HandleCommandL(EPbk2CmdDeleteMe);
       
   908                         result = ETrue;
       
   909                         }
       
   910                     }
       
   911                 break;
       
   912                 }
       
   913 
       
   914             case EKeyEnter: // FALLTHROUGH
       
   915             case EKeyOK:
       
   916                 {
       
   917                 if ( !ShiftDown(aKeyEvent) ) // pure OK key
       
   918 					{
       
   919 					if ( iControl->ContactsMarked() && itemSpecEnabled )					
       
   920 					    {
       
   921                         iView.LaunchPopupMenuL(
       
   922                             R_PHONEBOOK2_NAMESLIST_CONTEXT_MENUBAR_ITEMS_MARKED);
       
   923                         result = ETrue;
       
   924 					    }
       
   925 					else if ( iControl->NumberOfContacts() == 0 )
       
   926 					    {
       
   927                         result = ETrue;
       
   928 					    }
       
   929 					}
       
   930                 break;
       
   931                 }
       
   932             default:
       
   933                 {
       
   934                 break;
       
   935                 }
       
   936             }
       
   937         }
       
   938 
       
   939     // Update selection modifier key state
       
   940     iSelectionModifierUsed = IsShiftOrControlDown( aKeyEvent ) ||
       
   941         ( (aType == EEventKeyDown) && (aKeyEvent.iCode == EStdKeyHash) );
       
   942 
       
   943     return result;
       
   944     }
       
   945 
       
   946 
       
   947 // ----------------------------------------------------------------------------
       
   948 // CLogsBaseView::HandleListBoxEventL
       
   949 // ----------------------------------------------------------------------------
       
   950 //
       
   951 void CPbk2NamesListExView::HandleListBoxEventL(
       
   952     CEikListBox* aListBox,
       
   953     TListBoxEvent aEventType)
       
   954     {
       
   955     if( AknLayoutUtils::PenEnabled() )
       
   956         {
       
   957         switch ( aEventType )
       
   958             {
       
   959             case EEventItemSingleClicked:
       
   960             	{
       
   961                 ShowContextMenuL();
       
   962                 break;
       
   963                 }
       
   964             case EEventItemClicked: //Happens after focus changed
       
   965             break;
       
   966 
       
   967             case EEventPanningStarted:
       
   968             case EEventFlickStarted:
       
   969             case EEventPanningStopped:
       
   970             case EEventFlickStopped:
       
   971                 {
       
   972                 iControl->HandleListBoxEventL( aListBox, aEventType );
       
   973                 break;
       
   974                 }
       
   975             case EEventEnterKeyPressed:
       
   976                 {
       
   977                 if ( iControl->FocusedCommandItem() &&
       
   978                     !iControl->ContactsMarked() )
       
   979                     {
       
   980                     HandleCommandL(iControl->FocusedCommandItem()->CommandId() );
       
   981                     }
       
   982                 else if (iControl->NumberOfContacts() > 0 &&
       
   983                     !iControl->ContactsMarked())
       
   984                     {
       
   985                     // Select key is mapped to "Open Contact" command
       
   986                     HandleCommandL(EPbk2CmdOpenCca);
       
   987                     }
       
   988                 else if (iControl->ContactsMarked())
       
   989             		{
       
   990                 	iView.LaunchPopupMenuL(
       
   991                     	R_PHONEBOOK2_NAMESLIST_CONTEXT_MENUBAR_ITEMS_MARKED);
       
   992                     }
       
   993                 break;
       
   994                 }
       
   995             default:
       
   996                break;
       
   997             }
       
   998           }
       
   999     }
       
  1000 
       
  1001 // --------------------------------------------------------------------------
       
  1002 // CPbk2NamesListExView::HandlePointerEventL
       
  1003 // --------------------------------------------------------------------------
       
  1004 //
       
  1005 void CPbk2NamesListExView::HandlePointerEventL(
       
  1006         const TPointerEvent& aPointerEvent )
       
  1007     {
       
  1008     // re-initialized the findbox focus when the application is back in the
       
  1009     // foreground.
       
  1010     if ( iNeedSetFocus )
       
  1011         {
       
  1012         iNeedSetFocus = EFalse;
       
  1013         iControl->FocusChanged( EDrawNow );
       
  1014         }
       
  1015 
       
  1016     if ( AknLayoutUtils::PenEnabled() )
       
  1017         {
       
  1018         if ( iContainer && !iControl->ContactsMarked() && iPointerEventInspector->FocusableItemPointed() )
       
  1019             {
       
  1020             iContainer->LongTapDetectorL().PointerEventL( aPointerEvent );
       
  1021             }
       
  1022 // ece has stylus menu for empty state, no need to initiate touch feedback
       
  1023 // context menu disabled as well
       
  1024 #if 0
       
  1025         if ( iControl->NumberOfContacts()==0)
       
  1026             {
       
  1027             if ( aPointerEvent.iType == TPointerEvent::EButton1Down )
       
  1028                 {
       
  1029                 MTouchFeedback* feedback = MTouchFeedback::Instance();
       
  1030                 if ( feedback )
       
  1031                        {
       
  1032                        feedback->InstantFeedback( ETouchFeedbackBasic );
       
  1033                        }
       
  1034                 }
       
  1035             else if ( ( aPointerEvent.iType == TPointerEvent::EButton1Up ) && iCommandState)
       
  1036                 {
       
  1037                 ShowContextMenuL();
       
  1038                 }
       
  1039             }
       
  1040 #endif
       
  1041         }
       
  1042 
       
  1043     }
       
  1044 
       
  1045 // --------------------------------------------------------------------------
       
  1046 // CPbk2NamesListExView::ShowContextMenuL
       
  1047 // --------------------------------------------------------------------------
       
  1048 //
       
  1049 void CPbk2NamesListExView::ShowContextMenuL()
       
  1050     {
       
  1051 
       
  1052     if ( iStylusPopupMenuLaunched )
       
  1053          {
       
  1054          // Absorb EButton1Up event if we already launched the stylus
       
  1055          // popup menu
       
  1056          iStylusPopupMenuLaunched = EFalse;
       
  1057          }
       
  1058     else if ( !iPointerEventInspector->SearchFieldPointed() &&
       
  1059               !iSelectionModifierUsed )
       
  1060         {
       
  1061         if ( iControl->NumberOfContacts() > 0 || iControl->CommandItemCount() > 0) 
       
  1062             {
       
  1063             if ( iPointerEventInspector->FocusedItemPointed() )
       
  1064                 {
       
  1065                 if ( iControl->ContactsMarked() )
       
  1066                     {
       
  1067                     // Display marked items context menu
       
  1068                     iView.LaunchPopupMenuL
       
  1069                         ( R_PHONEBOOK2_NAMESLIST_CONTEXT_MENUBAR_ITEMS_MARKED );
       
  1070                     }
       
  1071                 else
       
  1072                     {
       
  1073                     // cancel the long tap animation with pointer up event
       
  1074                     TPointerEvent event;
       
  1075                     event.iType = TPointerEvent::EButton1Up;
       
  1076                     iContainer->LongTapDetectorL().PointerEventL( event );
       
  1077 
       
  1078                     // Open contact
       
  1079                     HandleCommandL( EPbk2CmdOpenCca );
       
  1080                     }
       
  1081                 }
       
  1082             }
       
  1083         else
       
  1084             {
       
  1085 #ifndef ECE_DISABLE_CONTEXT_MENU
       
  1086             // Display regular context menu
       
  1087             iView.LaunchPopupMenuL
       
  1088                 ( R_PHONEBOOK2_NAMESLIST_CONTEXT_MENUBAR );
       
  1089 #endif
       
  1090             }
       
  1091         }
       
  1092     }
       
  1093 
       
  1094 // --------------------------------------------------------------------------
       
  1095 // CPbk2NamesListExView::GetViewSpecificMenuFilteringFlagsL
       
  1096 // --------------------------------------------------------------------------
       
  1097 //
       
  1098 TInt CPbk2NamesListExView::GetViewSpecificMenuFilteringFlagsL() const
       
  1099     {
       
  1100     TInt flags(0);
       
  1101 
       
  1102     flags |= iControl->GetMenuFilteringFlagsL();
       
  1103 
       
  1104     return flags;
       
  1105     }
       
  1106 
       
  1107 // --------------------------------------------------------------------------
       
  1108 // CPbk2NamesListExView::HandleControlEventL
       
  1109 // --------------------------------------------------------------------------
       
  1110 //
       
  1111 void CPbk2NamesListExView::HandleControlEventL
       
  1112         ( MPbk2ContactUiControl& /*aControl*/,
       
  1113           const TPbk2ControlEvent& aEvent )
       
  1114     {
       
  1115     switch (aEvent.iEventType)
       
  1116         {
       
  1117         case TPbk2ControlEvent::EUnavailable: // FALLTHROUGH
       
  1118         case TPbk2ControlEvent::EReady:
       
  1119             {
       
  1120             DynInitToolbarL( R_PBK2_NAMESLIST_TOOLBAR, iToolbar );
       
  1121 
       
  1122             // Restore control state
       
  1123             RestoreStateL();
       
  1124             if ( iControl )
       
  1125                 {
       
  1126                 iControl->ShowThumbnail();
       
  1127                 iControl->DrawDeferred();
       
  1128                 }
       
  1129             // Restore control's state before updating cbas to get right state.
       
  1130             UpdateCbasL();
       
  1131             PBK2_PROFILE_END(Pbk2Profile::EFullStartup);
       
  1132             break;
       
  1133             }
       
  1134 
       
  1135         case TPbk2ControlEvent::EContactSetChanged:
       
  1136             {
       
  1137             UpdateCbasL();
       
  1138             DynInitToolbarL( R_PBK2_NAMESLIST_TOOLBAR, iToolbar );
       
  1139             iControl->ShowThumbnail();
       
  1140             break;
       
  1141             }
       
  1142 
       
  1143         case TPbk2ControlEvent::EContactSelected:   // FALLTHROUGH
       
  1144         case TPbk2ControlEvent::EContactUnselected: // FALLTHROUGH
       
  1145         case TPbk2ControlEvent::EContactUnselectedAll:
       
  1146             {
       
  1147             // Do not UpdateCbasL here because control handles itself
       
  1148             // the MSK when it goes to selection mode.
       
  1149             DynInitToolbarL( R_PBK2_NAMESLIST_TOOLBAR, iToolbar );
       
  1150             UpdateCbasL();
       
  1151             break;
       
  1152             }
       
  1153         case TPbk2ControlEvent::EControlLeavesSelectionMode:
       
  1154             {
       
  1155             // Update CBAs because the control doesn't know should
       
  1156             // the MSK be Open or Context menu when control leaves
       
  1157             // the selection mode.
       
  1158             UpdateCbasL();
       
  1159             break;
       
  1160             }
       
  1161 
       
  1162         case TPbk2ControlEvent::EControlStateChanged:
       
  1163             {
       
  1164             UpdateCbasL();
       
  1165             DynInitToolbarL( R_PBK2_NAMESLIST_TOOLBAR, iToolbar );
       
  1166             UpdateListEmptyTextL( aEvent.iInt );
       
  1167             iControl->DrawDeferred();
       
  1168             break;
       
  1169             }
       
  1170 
       
  1171         case TPbk2ControlEvent::EControlFocusChanged:
       
  1172             {
       
  1173             DynInitToolbarL( R_PBK2_NAMESLIST_TOOLBAR, iToolbar );
       
  1174             UpdateCbasL();
       
  1175             break;
       
  1176             }
       
  1177 
       
  1178         default:
       
  1179             {
       
  1180             // Do nothing
       
  1181             break;
       
  1182             }
       
  1183         }
       
  1184     }
       
  1185 
       
  1186 // --------------------------------------------------------------------------
       
  1187 // CPbk2NamesListExView::ConfigurationChanged
       
  1188 // --------------------------------------------------------------------------
       
  1189 //
       
  1190 void CPbk2NamesListExView::ConfigurationChanged()
       
  1191     {
       
  1192     MVPbkContactStore* phoneStore = NULL;
       
  1193     
       
  1194     Reset();
       
  1195            
       
  1196     if( iMyCard )
       
  1197     	{
       
  1198 		return;
       
  1199     	}
       
  1200        
       
  1201     if( FeatureManager::FeatureSupported( KFeatureIdffContactsMycard ) )
       
  1202 	   {    				
       
  1203 		// Get the phoneStore for MyCard
       
  1204 		TRAP_IGNORE( phoneStore = iContactManager->ContactStoresL().
       
  1205 			Find( VPbkContactStoreUris::DefaultCntDbUri() ) );    		
       
  1206 	   }
       
  1207                
       
  1208     if( !phoneStore )
       
  1209     	{
       
  1210 		iContactManager->LoadContactStoreL( VPbkContactStoreUris::DefaultCntDbUri() );
       
  1211     	}
       
  1212     }
       
  1213 
       
  1214 // --------------------------------------------------------------------------
       
  1215 // CPbk2NamesListExView::ConfigurationChangedComplete
       
  1216 // --------------------------------------------------------------------------
       
  1217 //
       
  1218 void CPbk2NamesListExView::ConfigurationChangedComplete()
       
  1219     {
       
  1220     if ( iControl )
       
  1221         {
       
  1222         MVPbkContactViewBase* allContactsView = NULL;
       
  1223 
       
  1224         TRAPD( res, allContactsView = Phonebook2::Pbk2AppUi()->
       
  1225             ApplicationServices().ViewSupplier().AllContactsViewL() );
       
  1226 
       
  1227         if ( res == KErrNone )
       
  1228             {
       
  1229             TRAP( res, iControl->SetViewL( *allContactsView ) );
       
  1230             iControl->DrawNow();
       
  1231             }
       
  1232 
       
  1233         if ( res != KErrNone )
       
  1234             {
       
  1235             CCoeEnv::Static()->HandleError( res );
       
  1236             iControl->Reset();
       
  1237             }
       
  1238         }
       
  1239     }
       
  1240 
       
  1241 // --------------------------------------------------------------------------
       
  1242 // CPbk2NamesListExView::PreCommandExecutionL
       
  1243 // --------------------------------------------------------------------------
       
  1244 //
       
  1245 void CPbk2NamesListExView::PreCommandExecutionL
       
  1246         ( const MPbk2Command& /*aCommand*/ )
       
  1247     {
       
  1248     iControl->AllowPointerEvents( EFalse );
       
  1249     iCommandState = EFalse;
       
  1250 
       
  1251     if ( iControl )
       
  1252         {
       
  1253         // Note: PostCommandExecutionL() must match this if()
       
  1254         if ( iToolbar && NeedToHideToolbar(iCurrentCommandId) )
       
  1255             {
       
  1256             iToolbarVisible = iToolbar->IsShown();
       
  1257 
       
  1258             // First hide the other components (FindBox etc.)
       
  1259             // No need to hide listbox and findbox for EPbk2CmdWriteNoQuery as
       
  1260             // it will go to Message view
       
  1261             if ( iCurrentCommandId != EPbk2CmdWriteNoQuery )
       
  1262                 {
       
  1263                 iControl->MakeVisible( EFalse );
       
  1264                 }
       
  1265             // Now hide toolbar items during the command execution...
       
  1266             iToolbar->HideItemsAndDrawOnlyBackground( ETrue );
       
  1267 
       
  1268             // ..but don't save the state change
       
  1269             iIdleToolbarWarden->Cancel();
       
  1270             }
       
  1271 
       
  1272         iControl->HideThumbnail();
       
  1273         }
       
  1274     }
       
  1275 
       
  1276 // --------------------------------------------------------------------------
       
  1277 // CPbk2NamesListExView::PostCommandExecutionL
       
  1278 // --------------------------------------------------------------------------
       
  1279 //
       
  1280 void CPbk2NamesListExView::PostCommandExecutionL
       
  1281         ( const MPbk2Command& /*aCommand*/ )
       
  1282     {
       
  1283     iCommandState = ETrue;
       
  1284 
       
  1285     if ( iControl )
       
  1286         {
       
  1287         // There are some special cases that the names list view would be hide in backgroud
       
  1288         // before one command is executing, and then get foreground later after the command
       
  1289         // finished, which would cause the control to be set invisible. So reset the flag
       
  1290         // after a command is finished.
       
  1291         iCtrlVisibleStateBeforeLosingForground = ETrue;
       
  1292 
       
  1293         iControl->AllowPointerEvents( ETrue );
       
  1294         iControl->ShowThumbnail();
       
  1295 
       
  1296         TBool drawToolbar( EFalse );
       
  1297         // Check the orientation of the screen.
       
  1298         const TBool isPortrait( Layout_Meta_Data::IsLandscapeOrientation() ? EFalse : ETrue );
       
  1299         if ( isPortrait )
       
  1300             {
       
  1301             // If there is a menu shown do not draw the tool bar. It will be drawn
       
  1302             // once the dialog or menu disappears and an event is received from
       
  1303             // the control environment
       
  1304             CCoeAppUi* appUi = CCoeEnv::Static()->AppUi();
       
  1305 
       
  1306             if ( NeedToHideToolbar(iCurrentCommandId) &&
       
  1307                 appUi && !appUi->IsDisplayingMenuOrDialog() )
       
  1308                 {
       
  1309                 drawToolbar = ETrue;
       
  1310                 }
       
  1311             }
       
  1312         else
       
  1313             {
       
  1314             // The orientation is landscape
       
  1315             drawToolbar = ETrue;
       
  1316             }
       
  1317         if ( iToolbar && drawToolbar )
       
  1318             {
       
  1319             // First show toolbar items
       
  1320             iToolbar->HideItemsAndDrawOnlyBackground( EFalse );
       
  1321 
       
  1322             // Now show the other components (FindBox etc.)
       
  1323             // No need set the flag as it is not hidden.
       
  1324             if ( iCurrentCommandId != EPbk2CmdWriteNoQuery )
       
  1325                 {
       
  1326                 iControl->MakeVisible( ETrue );
       
  1327                 }
       
  1328             // Without the below lines the Toolbar is drawn
       
  1329             // above the Find box
       
  1330             iContainer->SetRect(iView.ClientRect());
       
  1331             iControl->DrawNow();
       
  1332             }
       
  1333         }
       
  1334     iCurrentCommandId = KErrNotFound;
       
  1335     UpdateCbasL();
       
  1336     }
       
  1337 
       
  1338 // --------------------------------------------------------------------------
       
  1339 // CPbk2NamesListExView::DynInitToolbarL
       
  1340 // --------------------------------------------------------------------------
       
  1341 //
       
  1342 void CPbk2NamesListExView::DynInitToolbarL
       
  1343         ( TInt aResourceId, CAknToolbar* aToolbar )
       
  1344     {
       
  1345     if ( aToolbar )
       
  1346         {
       
  1347         if ( iControl )
       
  1348             {
       
  1349             PBK2_DEBUG_PRINT(PBK2_DEBUG_STRING
       
  1350                     ("CPbk2NamesListExView::DynInitToolbarL(0x%x) enable everything"), this);
       
  1351             // By default enable everything
       
  1352             aToolbar->SetItemDimmed( EPbk2CmdCall, EFalse, ETrue );
       
  1353             aToolbar->SetItemDimmed( EPbk2CmdWriteNoQuery, EFalse, ETrue );
       
  1354             aToolbar->SetItemDimmed( EPbk2CmdCreateNew, EFalse, ETrue );
       
  1355 
       
  1356             // Forward to command handler
       
  1357             iCommandHandler->DynInitToolbarL
       
  1358                 ( aResourceId, aToolbar, iView, *iControl );
       
  1359             }
       
  1360         else
       
  1361             {
       
  1362             PBK2_DEBUG_PRINT(PBK2_DEBUG_STRING
       
  1363                     ("CPbk2NamesListExView::DynInitToolbarL(0x%x) Disable all buttons"), this);
       
  1364 
       
  1365             // Disable all buttons if control has not yet been created
       
  1366             aToolbar->SetItemDimmed( EPbk2CmdCall, ETrue, ETrue );
       
  1367             aToolbar->SetItemDimmed( EPbk2CmdWriteNoQuery, ETrue, ETrue );
       
  1368             aToolbar->SetItemDimmed( EPbk2CmdCreateNew, ETrue, ETrue );
       
  1369             }
       
  1370         }
       
  1371     }
       
  1372 
       
  1373 // --------------------------------------------------------------------------
       
  1374 // CPbk2NamesListExView::OfferToolbarEventL
       
  1375 // --------------------------------------------------------------------------
       
  1376 //
       
  1377 void CPbk2NamesListExView::OfferToolbarEventL
       
  1378         ( TInt aCommand )
       
  1379     {
       
  1380     iCurrentCommandId = aCommand;
       
  1381 
       
  1382     if ( iControl )
       
  1383         {
       
  1384         // Forward to command handler
       
  1385         iCommandHandler->HandleCommandL( aCommand, *iControl, &iView );
       
  1386         }
       
  1387     }
       
  1388 
       
  1389 // --------------------------------------------------------------------------
       
  1390 // CPbk2NamesListExView::HandleControlEventL
       
  1391 // --------------------------------------------------------------------------
       
  1392 //
       
  1393 void CPbk2NamesListExView::HandleControlEventL(
       
  1394         CCoeControl* aControl,
       
  1395         TCoeEvent aEventType )
       
  1396     {
       
  1397     if ( aControl == iToolbar )
       
  1398         {
       
  1399         // Forward control event to touch pane
       
  1400         CEikAppUiFactory* factory = new(ELeave) CEikAppUiFactory;
       
  1401         CleanupStack::PushL(factory);
       
  1402         CAknTouchPane* pane = factory->TouchPane();
       
  1403         CleanupStack::PopAndDestroy(factory);
       
  1404 
       
  1405         if ( pane )
       
  1406             {
       
  1407             pane->HandleControlEventL( aControl, aEventType );
       
  1408             if (!aControl->IsVisible() && iControl )
       
  1409                 {
       
  1410                 iControl->DrawDeferred();
       
  1411                 }
       
  1412             }
       
  1413 
       
  1414         if ( iControl )
       
  1415             {
       
  1416             // Forward event to view's control
       
  1417             iControl->HandleControlEventL( aControl, aEventType );
       
  1418             }
       
  1419 
       
  1420         if ( aEventType == EEventStateChanged )
       
  1421             {
       
  1422             // Save state from idle callback. This gives possibility
       
  1423             // to prevent save if we are e.g. existing the view or just
       
  1424             // disabling the toolbar temporarily.
       
  1425             iIdleToolbarWarden->Cancel();
       
  1426             iIdleToolbarWarden->Start( TCallBack(
       
  1427                 ( &CPbk2NamesListExView::IdleSaveToolbarStateL ), this ) );
       
  1428             }
       
  1429         }
       
  1430     if ( aControl ==iControl &&
       
  1431             aEventType == MCoeControlObserver::EEventStateChanged &&
       
  1432             iCommandState )
       
  1433         {
       
  1434         // If the toolbar is not drawn for some reason, draw it here once
       
  1435         // view's control sends an event after updating itself
       
  1436         if ( iToolbar && !iToolbar->IsShown() )
       
  1437             {
       
  1438             // First show toolbar items
       
  1439             iToolbar->HideItemsAndDrawOnlyBackground( EFalse );
       
  1440 
       
  1441             // Now show the other components (FindBox etc.)
       
  1442             // No need set the flag as it is not hide.
       
  1443             if ( iCurrentCommandId != EPbk2CmdWriteNoQuery )
       
  1444                 {
       
  1445                 iControl->MakeVisible( ETrue );
       
  1446                 }
       
  1447 
       
  1448             // Without the below lines the Toolbar is drawn
       
  1449             // above the Find box
       
  1450             iContainer->SetRect(iView.ClientRect());
       
  1451             iControl->DrawNow();
       
  1452             }
       
  1453         }
       
  1454     }
       
  1455 
       
  1456 //---------------------------------------------------------------------------
       
  1457 // CPbk2NamesListExView::CreateControlsL
       
  1458 // --------------------------------------------------------------------------
       
  1459 //
       
  1460 inline void CPbk2NamesListExView::CreateControlsL()
       
  1461     {
       
  1462 	
       
  1463     if (!iContainer)
       
  1464         {
       
  1465         PBK2_PROFILE_START(Pbk2Profile::ENamesListViewCreateControls);
       
  1466         // Create the container and control
       
  1467         PBK2_PROFILE_START(Pbk2Profile::ENamesListViewCreateContainer);
       
  1468         CContainer* container = CContainer::NewLC( &iView, &iView, iView );
       
  1469         PBK2_PROFILE_END(Pbk2Profile::ENamesListViewCreateContainer);
       
  1470 
       
  1471         PBK2_PROFILE_START(Pbk2Profile::ENamesListViewSetHelpContext);
       
  1472         container->SetHelpContext( TCoeHelpContext( iView.ApplicationUid(),
       
  1473             KPHOB_HLP_NAME_LIST ));
       
  1474         PBK2_PROFILE_END(Pbk2Profile::ENamesListViewSetHelpContext);
       
  1475 
       
  1476         PBK2_PROFILE_START
       
  1477             ( Pbk2Profile::ENamesListViewCreateNamesListControl );
       
  1478         CPbk2NamesListControl* control = CPbk2NamesListControl::NewL(
       
  1479                 R_PBK2_SPB_NAMES_LIST_EXTENSION_CONTROL,
       
  1480                 container,
       
  1481                 *iContactManager,
       
  1482                 *Phonebook2::Pbk2AppUi()->ApplicationServices().
       
  1483                     ViewSupplier().AllContactsViewL(),
       
  1484                 *iNameFormatter,
       
  1485                 Phonebook2::Pbk2AppUi()->ApplicationServices().StoreProperties(),
       
  1486                 iThumbManager );
       
  1487 
       
  1488         PBK2_PROFILE_END
       
  1489             ( Pbk2Profile::ENamesListViewCreateNamesListControl );
       
  1490 
       
  1491         PBK2_PROFILE_START(Pbk2Profile::ENamesListViewSetControl);
       
  1492         container->SetControl(control, iView.ClientRect()); // takes ownership
       
  1493         container->AddForegroundObserver( control );
       
  1494         control->AddObserverL(*this);
       
  1495         PBK2_PROFILE_END(Pbk2Profile::ENamesListViewSetControl);
       
  1496 
       
  1497         PBK2_PROFILE_START(Pbk2Profile::ENamesListViewAddToStack);
       
  1498         CCoeEnv::Static()->AppUi()->AddToStackL(iView, container);
       
  1499         PBK2_PROFILE_END(Pbk2Profile::ENamesListViewAddToStack);
       
  1500         CleanupStack::Pop(container);
       
  1501         iContainer = container;
       
  1502         iControl = control;
       
  1503         iControl->SetObserver(this);
       
  1504         iControlProxy->SetControl( iControl );
       
  1505         iPointerEventInspector = control;
       
  1506         
       
  1507         // Add command item to container
       
  1508         AddCommandItemsToContainerL();
       
  1509         PBK2_PROFILE_END(Pbk2Profile::ENamesListViewCreateControls);
       
  1510         }
       
  1511     }
       
  1512 
       
  1513 // --------------------------------------------------------------------------
       
  1514 // CPbk2NamesListExView::StoreStateL
       
  1515 // --------------------------------------------------------------------------
       
  1516 //
       
  1517 void CPbk2NamesListExView::StoreStateL()
       
  1518     {
       
  1519     CPbk2ViewState* state = ViewStateLC();
       
  1520     CleanupStack::Pop(state);
       
  1521     delete iControlState;
       
  1522     iControlState = state;
       
  1523     }
       
  1524 
       
  1525 // --------------------------------------------------------------------------
       
  1526 // CPbk2NamesListExView::RestoreStateL
       
  1527 // --------------------------------------------------------------------------
       
  1528 //
       
  1529 void CPbk2NamesListExView::RestoreStateL()
       
  1530     {
       
  1531     iControl->RestoreControlStateL(iControlState);
       
  1532     // Parameter state overrides stored state
       
  1533     iControl->RestoreControlStateL(iParamState);
       
  1534     delete iControlState;
       
  1535     iControlState = NULL;
       
  1536     delete iParamState;
       
  1537     iParamState = NULL;
       
  1538     }
       
  1539 
       
  1540 // --------------------------------------------------------------------------
       
  1541 // CPbk2NamesListExView::UpdateCbasL
       
  1542 // --------------------------------------------------------------------------
       
  1543 //
       
  1544 void CPbk2NamesListExView::UpdateCbasL()
       
  1545     {
       
  1546     if ( iControl )
       
  1547         {
       
  1548         TBool listContainsContacts = ( iControl->NumberOfContacts() > 0 );
       
  1549         listContainsContacts = listContainsContacts || (iControl->CommandItemCount() > 0); 
       
  1550         TBool contactsMarked = iControl->ContactsMarked();
       
  1551 
       
  1552         if ( listContainsContacts && !contactsMarked )
       
  1553             {
       
  1554             //For command items msk is select
       
  1555             if( iControl->FocusedContactIndex() == KErrNotFound )
       
  1556                 {
       
  1557                 // Set middle softkey as select.
       
  1558                 iView.Cba()->SetCommandSetL( R_PBK2_SOFTKEYS_OPTIONS_EXIT_SELECT );
       
  1559                 }
       
  1560             else
       
  1561                 {
       
  1562                 // Set middle softkey as open cca.
       
  1563                 iView.Cba()->SetCommandSetL( R_PBK2_SOFTKEYS_OPTIONS_EXIT_CONNECT );
       
  1564                 }
       
  1565             }
       
  1566         else if ( listContainsContacts && contactsMarked )
       
  1567             {
       
  1568             // Set middle softkey as Context Icon
       
  1569             iView.Cba()->SetCommandSetL( R_PBK2_SOFTKEYS_OPTIONS_EXIT_CONTEXT );
       
  1570             // Change context menu when marked items
       
  1571             iView.MenuBar()->SetContextMenuTitleResourceId
       
  1572                 ( R_PHONEBOOK2_NAMESLIST_CONTEXT_MENUBAR_ITEMS_MARKED );
       
  1573             }
       
  1574         else // not listContainsContacts && not contactsMarked
       
  1575             {
       
  1576 #ifndef ECE_DISABLE_CONTEXT_MENU
       
  1577             // Set middle softkey as Context Icon.
       
  1578             iView.Cba()->SetCommandSetL( R_PBK2_SOFTKEYS_OPTIONS_EXIT_CONTEXT );
       
  1579             // Change context menu when nameslist is empty
       
  1580             iView.MenuBar()->SetContextMenuTitleResourceId
       
  1581                 ( R_PHONEBOOK2_NAMESLIST_CONTEXT_MENUBAR );
       
  1582 #else
       
  1583             iView.Cba()->SetCommandSetL( R_PBK2_SOFTKEYS_OPTIONS_EXIT_EMPTY );
       
  1584 #endif
       
  1585             }
       
  1586         iView.Cba()->DrawDeferred();
       
  1587         }
       
  1588 
       
  1589     }
       
  1590 
       
  1591 // --------------------------------------------------------------------------
       
  1592 // CPbk2NamesListExView::IdleSaveToolbarState
       
  1593 // --------------------------------------------------------------------------
       
  1594 //
       
  1595 TInt CPbk2NamesListExView::IdleSaveToolbarStateL( TAny* aSelf )
       
  1596     {
       
  1597     CPbk2NamesListExView* self =
       
  1598         static_cast<CPbk2NamesListExView*>( aSelf );
       
  1599     if ( AknLayoutUtils::PenEnabled() && self && self->iToolbar )
       
  1600         {
       
  1601         TBool shown = self->iToolbar->IsShown();
       
  1602         self->ShowToolbarOnViewActivation( shown );
       
  1603 
       
  1604         // Save state to central repository
       
  1605         CRepository* cenrep =
       
  1606             CRepository::NewLC( TUid::Uid( KCRUidPhonebook ) );
       
  1607         User::LeaveIfError(
       
  1608             cenrep->Set( KPhonebookNamesListToolbarVisibility, shown ) );
       
  1609         CleanupStack::PopAndDestroy( cenrep );
       
  1610         }
       
  1611     return EFalse; // don't call again
       
  1612     }
       
  1613 
       
  1614 void CPbk2NamesListExView::ShowToolbarOnViewActivation(TBool aShown)
       
  1615     {
       
  1616     iView.ShowToolbarOnViewActivation(aShown);
       
  1617     }
       
  1618 // --------------------------------------------------------------------------
       
  1619 // CPbk2NamesListExView::AttachAIWProvidersL
       
  1620 // --------------------------------------------------------------------------
       
  1621 //
       
  1622 inline void CPbk2NamesListExView::AttachAIWProvidersL()
       
  1623     {
       
  1624     PBK2_PROFILE_START( Pbk2Profile::ENamesListAIWRegisterInterestCall );
       
  1625     iCommandHandler->RegisterAiwInterestL
       
  1626         ( KAiwCmdCall, R_PHONEBOOK2_CALL_MENU,
       
  1627         R_PHONEBOOK2_CALLUI_AIW_INTEREST, ETrue );
       
  1628     PBK2_PROFILE_END( Pbk2Profile::ENamesListAIWRegisterInterestCall );
       
  1629     
       
  1630     iCommandHandler->RegisterAiwInterestL
       
  1631         ( KAiwCmdCall, R_PHONEBOOK2_STYLUS_CALL_MENU,
       
  1632         R_PHONEBOOK2_CALLUI_AIW_INTEREST, EFalse );
       
  1633 
       
  1634     PBK2_PROFILE_START( Pbk2Profile::ENamesListAIWRegisterInterestPOC );
       
  1635     iCommandHandler->RegisterAiwInterestL
       
  1636         ( KAiwCmdPoC, R_PHONEBOOK2_POC_MENU,
       
  1637         R_PHONEBOOK2_POCUI_AIW_INTEREST, ETrue );
       
  1638     PBK2_PROFILE_END( Pbk2Profile::ENamesListAIWRegisterInterestPOC );
       
  1639 
       
  1640     PBK2_PROFILE_START( Pbk2Profile::ENamesListAIWRegisterInterestSyncML );
       
  1641     iCommandHandler->RegisterAiwInterestL
       
  1642         ( KAiwCmdSynchronize, R_PHONEBOOK2_SYNCML_MENU,
       
  1643         R_PHONEBOOK2_SYNCML_AIW_INTEREST, EFalse );
       
  1644     PBK2_PROFILE_END( Pbk2Profile::ENamesListAIWRegisterInterestSyncML );
       
  1645     iCommandHandler->RegisterAiwInterestL
       
  1646         ( KOtasAiwCmdSynchronize, R_PHONEBOOK2_OVISYNC_MENU,
       
  1647         R_PHONEBOOK2_OVISYNC_AIW_INTEREST, ETrue );
       
  1648     }
       
  1649 
       
  1650 // --------------------------------------------------------------------------
       
  1651 // CPbk2NamesListExView::UpdateListEmptyTextL
       
  1652 // --------------------------------------------------------------------------
       
  1653 //
       
  1654 void CPbk2NamesListExView::UpdateListEmptyTextL(
       
  1655         TInt aListState )
       
  1656     {
       
  1657     iListState = aListState;
       
  1658 
       
  1659     if ( !iIdleTexter )
       
  1660         {
       
  1661         iIdleTexter = CIdle::NewL( CActive::EPriorityStandard );
       
  1662         }
       
  1663 
       
  1664     iIdleTexter->Cancel();
       
  1665     iIdleTexter->Start( TCallBack(
       
  1666         ( &CPbk2NamesListExView::IdleSetEmptyTextL ), this ) );
       
  1667     }
       
  1668 
       
  1669 // --------------------------------------------------------------------------
       
  1670 // CPbk2NamesListExView::HandleLongTapEventL
       
  1671 // --------------------------------------------------------------------------
       
  1672 //
       
  1673 void CPbk2NamesListExView::HandleLongTapEventL(
       
  1674         const TPoint& /*aPenEventLocation*/,
       
  1675         const TPoint& /*aPenEventScreenLocation*/ )
       
  1676     {
       
  1677 //no implementation needed for single tap
       
  1678     }
       
  1679 
       
  1680 // --------------------------------------------------------------------------
       
  1681 // CPbk2NamesListExView::Reset
       
  1682 // --------------------------------------------------------------------------
       
  1683 //
       
  1684 void CPbk2NamesListExView::Reset()
       
  1685     {
       
  1686     if ( iControl )
       
  1687         {
       
  1688         iControl->Reset();
       
  1689         }
       
  1690 
       
  1691     delete iControlState;
       
  1692     iControlState = NULL;
       
  1693     delete iParamState;
       
  1694     iParamState = NULL;
       
  1695     }
       
  1696 
       
  1697 // --------------------------------------------------------------------------
       
  1698 // CPbk2NamesListExView::IdleSetEmptyTextL
       
  1699 // --------------------------------------------------------------------------
       
  1700 //
       
  1701 TInt CPbk2NamesListExView::IdleSetEmptyTextL( TAny* aSelf  )
       
  1702     {
       
  1703     CPbk2NamesListExView* self =
       
  1704         static_cast<CPbk2NamesListExView*>( aSelf );
       
  1705 
       
  1706     HBufC* text = NULL;
       
  1707     switch ( self->iListState )
       
  1708         {
       
  1709         case CPbk2NamesListControl::EStateEmpty:
       
  1710         case CPbk2NamesListControl::EStateNotReady:
       
  1711             {
       
  1712             text = StringLoader::LoadLC( R_QTN_PHOB_NO_ENTRIES_LONG );
       
  1713 
       
  1714             // Append secondary text
       
  1715             TInt secondaryTextId = R_QTN_PHOB_NO_ENTRIES_LONGER;
       
  1716             if ( self->iListState == CPbk2NamesListControl::EStateNotReady )
       
  1717                 {
       
  1718                 secondaryTextId = R_QTN_PHOB_STORES_NA;
       
  1719                 }
       
  1720             _LIT( KNewline, "\n" );
       
  1721             HBufC* secondaryText = StringLoader::LoadLC( secondaryTextId );
       
  1722             TInt newLength = text->Length()
       
  1723                            + KNewline().Length()
       
  1724                            + secondaryText->Length();
       
  1725             text = text->ReAllocL( newLength );
       
  1726             TPtr ptr = text->Des();
       
  1727             ptr.Append( KNewline );
       
  1728             ptr.Append( *secondaryText );
       
  1729             CleanupStack::PopAndDestroy( secondaryText );
       
  1730 
       
  1731             // Fix text ptr in cleanup stack, see ReAllocL above
       
  1732             CleanupStack::Pop(); // text
       
  1733             CleanupStack::PushL( text );
       
  1734             break;
       
  1735             }
       
  1736         case CPbk2NamesListControl::EStateReady: // FALLTHROUGH
       
  1737         case CPbk2NamesListControl::EStateFiltered:
       
  1738             {
       
  1739             text = StringLoader::LoadLC( R_PBK2_FIND_NO_MATCHES );
       
  1740 
       
  1741             if (self->iListState == CPbk2NamesListControl::EStateFiltered &&
       
  1742                 self->iControl->NumberOfContacts() == 0 &&
       
  1743                 self->iStylusPopupMenuLaunched
       
  1744                 )
       
  1745                 {
       
  1746                 self->iPopupMenu->RemoveMenuItem(EPbk2CmdAddToTopContacts);
       
  1747                 self->iPopupMenu->RemoveMenuItem(EPbk2CmdRemoveFromTopContacts);
       
  1748                 self->iPopupMenu->RemoveMenuItem(EPbk2CmdEditMe);
       
  1749                 self->iPopupMenu->RemoveMenuItem(EPbk2CmdSend);
       
  1750                 }
       
  1751             break;
       
  1752             }
       
  1753         default:
       
  1754             {
       
  1755             text = KNullDesC().AllocLC();
       
  1756             break;
       
  1757             }
       
  1758         }
       
  1759     if ( text )
       
  1760         {
       
  1761         self->iControl->SetTextL( *text );
       
  1762         CleanupStack::PopAndDestroy( text );
       
  1763         self->iControl->DrawDeferred();
       
  1764         }
       
  1765 
       
  1766     return EFalse; // don't call again
       
  1767     }
       
  1768 
       
  1769 // --------------------------------------------------------------------------
       
  1770 // CPbk2NamesListExView::NeedToHideToolbar
       
  1771 // --------------------------------------------------------------------------
       
  1772 //
       
  1773 TBool CPbk2NamesListExView::NeedToHideToolbar(TInt aCurrentCommand)
       
  1774     {
       
  1775     // before show new dialog or pop-up list, etc for the below commands, it is
       
  1776     // required to hide the toolbar, and retrieve it after command complete
       
  1777     if ( aCurrentCommand == EPbk2CmdCreateNew ||
       
  1778          aCurrentCommand == EPbk2CmdWrite ||
       
  1779          aCurrentCommand == EPbk2CmdAddFavourites ||
       
  1780          aCurrentCommand == EPbk2CmdRcl ||    
       
  1781          aCurrentCommand == EPbk2CmdMoveInTopContactsList ||
       
  1782          aCurrentCommand == EPbk2CmdEditMe ||
       
  1783          aCurrentCommand == EPbk2CmdWriteNoQuery )
       
  1784         {
       
  1785         return ETrue;
       
  1786         }
       
  1787     else
       
  1788         {
       
  1789         return EFalse;
       
  1790         }
       
  1791     }
       
  1792 
       
  1793 // --------------------------------------------------------------------------
       
  1794 // CPbk2NamesListExView::IsPhoneMemoryUsedL
       
  1795 // --------------------------------------------------------------------------
       
  1796 //
       
  1797 TBool CPbk2NamesListExView::IsPhoneMemoryUsedL() const
       
  1798 	{
       
  1799 	CPbk2ApplicationServices* appServices = CPbk2ApplicationServices::InstanceL();
       
  1800 			
       
  1801 	// Get current configuration
       
  1802 	CPbk2StoreConfiguration& storeConfig = appServices->StoreConfiguration();
       
  1803 	
       
  1804 	CVPbkContactStoreUriArray* uriArray = storeConfig.CurrentConfigurationL();
       
  1805 			
       
  1806 	TVPbkContactStoreUriPtr contactUri( VPbkContactStoreUris::DefaultCntDbUri() );		
       
  1807 			
       
  1808 	// Check is phone memory included
       
  1809 	TBool phoneMemory = uriArray->IsIncluded( contactUri );
       
  1810 	
       
  1811 	delete uriArray;		
       
  1812 	Release( appServices );
       
  1813 	
       
  1814 	return phoneMemory;
       
  1815 	}
       
  1816 	
       
  1817 // --------------------------------------------------------------------------
       
  1818 // CPbk2NamesListExView::HandleGainingForeground
       
  1819 // --------------------------------------------------------------------------
       
  1820 //
       
  1821 void CPbk2NamesListExView::HandleGainingForeground()
       
  1822     {
       
  1823     // If the control state is not the same as the state before losing forground
       
  1824     // set it back to the state before losing forground.
       
  1825     if( iControl && ( ( iControl->IsVisible() && !iCtrlVisibleStateBeforeLosingForground ) ||
       
  1826                      ( !iControl->IsVisible() && iCtrlVisibleStateBeforeLosingForground ) ) )
       
  1827         {
       
  1828         iControl->MakeVisible( iCtrlVisibleStateBeforeLosingForground );
       
  1829         }
       
  1830 
       
  1831     // This flag is used to force the find box to be re-initialized when the application
       
  1832     // is back in the foreground.
       
  1833     iNeedSetFocus = ETrue;
       
  1834     }
       
  1835 
       
  1836 // --------------------------------------------------------------------------
       
  1837 // CPbk2NamesListExView::HandleLosingForeground
       
  1838 // --------------------------------------------------------------------------
       
  1839 //
       
  1840 void CPbk2NamesListExView::HandleLosingForeground()
       
  1841     {
       
  1842     // If some command is executing now and control state is invisible. Set the control
       
  1843     // visible before it hide in background.
       
  1844     // To do this is because some special states, like creating new contact or
       
  1845     // creating new message, the iControl will be set invisible (In the function the control
       
  1846     // set invisible in the function PreCommandExecutionL which is to avoid  displaying two
       
  1847     // find boxes after press the create new contact button). And during the command
       
  1848     // executing, set the control visible before it is hided into background.This is make
       
  1849     // sure that the control should be updated after it set foreground again.
       
  1850     if( iControl )
       
  1851         {
       
  1852         iCtrlVisibleStateBeforeLosingForground = iControl->IsVisible();
       
  1853         if( !iCommandState && !iCtrlVisibleStateBeforeLosingForground )
       
  1854             {
       
  1855             iControl->MakeVisible( ETrue );
       
  1856             }
       
  1857         }
       
  1858 
       
  1859     // This flag is used to force the find box to be re-initialized when the application
       
  1860     // is back in the foreground.
       
  1861     iNeedSetFocus = EFalse;
       
  1862     }
       
  1863 //  End of File