phonebookui/Phonebook2/UIControls/src/CPbk2FetchDlg.cpp
branchRCL_3
changeset 20 f4a778e096c2
child 21 9da50d567e3c
equal deleted inserted replaced
19:5b6f26637ad3 20:f4a778e096c2
       
     1 /*
       
     2 * Copyright (c) 2005-2007 Nokia Corporation and/or its subsidiary(-ies).
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description:  Phonebook 2 fetch dialog.
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 // INCLUDE FILES
       
    20 #include <CPbk2FetchDlg.h>
       
    21 
       
    22 // Phonebook 2
       
    23 #include "MPbk2FetchDlgPage.h"
       
    24 #include "MPbk2FetchDlgPages.h"
       
    25 #include "Pbk2FetchDlgPageFactory.h"
       
    26 #include "CPbk2FetchResults.h"
       
    27 #include <MPbk2AppUi.h>
       
    28 #include <MPbk2ApplicationServices.h>
       
    29 #include <MPbk2ContactViewSupplier.h>
       
    30 #include <Pbk2UIControls.hrh>
       
    31 #include <MPbk2ContactUiControl.h>
       
    32 #include <MPbk2FetchDlgObserver.h>
       
    33 #include <Pbk2UIControls.rsg>
       
    34 #include <MPbk2ContactLinkIterator.h>
       
    35 #include <CPbk2IconInfoContainer.h>
       
    36 #include <Pbk2UID.h>
       
    37 #include <CPbk2IconFactory.h>
       
    38 #include <TPbk2IconId.h>
       
    39 #include <MPbk2ExitCallback.h>
       
    40 #include <TPbk2DestructionIndicator.h>
       
    41 #include "CPbk2NamesListControl.h"
       
    42 #include <CPbk2AppUiBase.h>
       
    43 #include <MPbk2KeyEventHandler.h>
       
    44 #include <MPbk2AppUi.h>
       
    45 #include <MPbk2ApplicationServices.h>
       
    46 #include <MPbk2ContactViewSupplier.h>
       
    47 
       
    48 // Virtual Phonebook
       
    49 #include <CVPbkContactLinkArray.h>
       
    50 #include <CVPbkContactManager.h>
       
    51 #include <MVPbkContactViewBase.h>
       
    52 #include <MVPbkContactLink.h>
       
    53 #include <MVPbkContactOperationBase.h>
       
    54 #include <MVPbkStoreContact.h>
       
    55 #include <MVPbkContactGroup.h>
       
    56 #include <VPbkContactView.hrh>
       
    57 
       
    58 // System includes
       
    59 #include <barsread.h>
       
    60 #include <avkon.rsg>
       
    61 #include <aknnavide.h>
       
    62 #include <aknappui.h>
       
    63 #include <StringLoader.h>
       
    64 #include <akntabgrp.h>
       
    65 #include <AknsUtils.h>
       
    66 #include <layoutmetadata.cdl.h>
       
    67 
       
    68 // Debugging headers
       
    69 #include <Pbk2Debug.h>
       
    70 
       
    71 
       
    72 /// Unnamed namespace for local definitions
       
    73 namespace {
       
    74 
       
    75 const TInt KPbk2MSKControlId( CEikButtonGroupContainer::EMiddleSoftkeyPosition );
       
    76 const TInt KFirstElement = 0;
       
    77 const TInt KDefaultMinSelection = 1;
       
    78 
       
    79 enum TPanicCode
       
    80     {
       
    81     EPanicInvalidResourceData = 1,
       
    82     EPanicPostCond_PreLayoutDynInitL,
       
    83     EPanicPreCond_ResetWhenDestroyed,
       
    84     };
       
    85 
       
    86 void Panic(TInt aReason)
       
    87     {
       
    88     _LIT(KPanicText, "CPbk2FetchDlg");
       
    89     User::Panic(KPanicText, aReason);
       
    90     }
       
    91 
       
    92 } /// namespace
       
    93 
       
    94 
       
    95 // --------------------------------------------------------------------------
       
    96 // CPbk2FetchDlg::TParams::TParams
       
    97 // --------------------------------------------------------------------------
       
    98 //
       
    99 EXPORT_C CPbk2FetchDlg::TParams::TParams() :
       
   100         iFlags( EFetchSingle ),
       
   101         iResId( R_PBK2_SINGLE_ENTRY_FETCH_DLG ),
       
   102         iMarkedEntries( NULL ),
       
   103         iNamesListView( NULL ),
       
   104         iGroupsListView( NULL ),
       
   105         iCbaId( 0 ),
       
   106         iNaviPaneId( 0 ),
       
   107         iExitCallback( NULL ),
       
   108         iMinSelection( KDefaultMinSelection )
       
   109     {
       
   110     }
       
   111 
       
   112 // --------------------------------------------------------------------------
       
   113 // CPbk2FetchDlg::TParams::TCleanupItem
       
   114 // --------------------------------------------------------------------------
       
   115 //
       
   116 EXPORT_C CPbk2FetchDlg::TParams::operator TCleanupItem()
       
   117     {
       
   118     return TCleanupItem(Cleanup,this);
       
   119     }
       
   120 
       
   121 // --------------------------------------------------------------------------
       
   122 // CPbk2FetchDlg::TParams::Cleanup
       
   123 // --------------------------------------------------------------------------
       
   124 //
       
   125 void CPbk2FetchDlg::TParams::Cleanup(TAny* aPtr)
       
   126     {
       
   127     TParams* self = static_cast<TParams*>(aPtr);
       
   128     delete self->iMarkedEntries;
       
   129     self->iMarkedEntries = NULL;
       
   130     }
       
   131 
       
   132 // --------------------------------------------------------------------------
       
   133 // CPbk2FetchDlg::TResData::ReadFromResource
       
   134 // --------------------------------------------------------------------------
       
   135 //
       
   136 inline void CPbk2FetchDlg::TResData::ReadFromResource
       
   137         ( TResourceReader& aReader )
       
   138     {
       
   139     iDialogId = aReader.ReadInt32();
       
   140     iCbaId = aReader.ReadInt32();
       
   141     iEmptyCbaId = aReader.ReadInt32();
       
   142     iNaviPaneId = aReader.ReadInt32();
       
   143     }
       
   144 
       
   145 // --------------------------------------------------------------------------
       
   146 // CPbk2FetchDlg::CPbk2FetchDlg
       
   147 // --------------------------------------------------------------------------
       
   148 //
       
   149 inline CPbk2FetchDlg::CPbk2FetchDlg
       
   150         ( TParams aParams, MPbk2FetchDlgObserver& aObserver ) :
       
   151             iParams( aParams ),
       
   152             iObserver( aObserver ),
       
   153             iSelectPermitted( ETrue )
       
   154     {
       
   155     }
       
   156 
       
   157 // --------------------------------------------------------------------------
       
   158 // CPbk2FetchDlg::~CPbk2FetchDlg
       
   159 // --------------------------------------------------------------------------
       
   160 //
       
   161 CPbk2FetchDlg::~CPbk2FetchDlg()
       
   162     {
       
   163     if (iDestroyedPtr)
       
   164         {
       
   165         *iDestroyedPtr = ETrue;
       
   166         }
       
   167 
       
   168     if ( iSelfPtr )
       
   169         {
       
   170         *iSelfPtr = NULL;
       
   171         }
       
   172         
       
   173     if ( iStoreConfiguration )
       
   174         {
       
   175         iStoreConfiguration->RemoveObserver( *this );
       
   176         }
       
   177 
       
   178     RemoveCommandFromMSK();
       
   179     delete iTabSkinDelay;
       
   180     delete iSelectionRestorer;
       
   181     delete iPages;
       
   182     delete iNaviDecorator;
       
   183     delete iDialogAccepter;
       
   184     delete iResults;
       
   185     delete iFocusedContactLink;
       
   186     }
       
   187 
       
   188 // --------------------------------------------------------------------------
       
   189 // CPbk2FetchDlg::ConstructL
       
   190 // --------------------------------------------------------------------------
       
   191 //
       
   192 inline void CPbk2FetchDlg::ConstructL()
       
   193     {
       
   194     // Read resources
       
   195     TResourceReader reader;
       
   196     iCoeEnv->CreateResourceReaderLC( reader, iParams.iResId );
       
   197     iResData.ReadFromResource( reader );
       
   198     __ASSERT_ALWAYS( iResData.iDialogId != 0,
       
   199         Panic( EPanicInvalidResourceData ) );
       
   200     __ASSERT_ALWAYS( iResData.iCbaId != 0,
       
   201         Panic( EPanicInvalidResourceData ) );
       
   202     __ASSERT_ALWAYS( iResData.iEmptyCbaId != 0,
       
   203         Panic( EPanicInvalidResourceData ) );
       
   204     CleanupStack::PopAndDestroy(); // reader
       
   205 
       
   206     iExitRecord.ClearAll();
       
   207 
       
   208     CAknDialog::ConstructL( R_AVKON_MENUPANE_EMPTY );
       
   209 
       
   210     TCallBack accepter( TryAcceptSelectionL, this );
       
   211     iDialogAccepter =
       
   212         new (ELeave) CAsyncCallBack( accepter, CActive::EPriorityIdle );
       
   213 
       
   214     // Dialog tabs appear in status pane stack only after dialog is fully
       
   215     // constructed, so we need to delay tab skinning.
       
   216     // Even in PostLayoutDyninit tab group is wrong.
       
   217     // Must use higher priority than user input, so the user
       
   218     // has no chance to write into find box. Tab skinning resets
       
   219     // the find input.
       
   220     iTabSkinDelay = CIdle::NewL( CActive::EPriorityHigh );
       
   221     iTabSkinDelay->Start( TCallBack( DelaySkinning, this ));
       
   222 	
       
   223     // Initialize whether MSK is enabled in current layout.
       
   224     // Currently AknLayoutUtils::MSKEnabled() returns ETrue
       
   225     // if the application supports MSK (constructed with EAknEnableMSK flag).
       
   226     // In addition Layout_Meta_Data::IsMSKEnabled() is expected to be called,
       
   227     // which checks from the layout data whether or not the MSK is supported 
       
   228     // in the current resolution/orientation. 
       
   229     // So if either one returns EFalse, then MSK is not shown.
       
   230     iMSKEnabled = (AknLayoutUtils::MSKEnabled() && Layout_Meta_Data::IsMSKEnabled());
       
   231     
       
   232     // Add the store observer.
       
   233     iStoreConfiguration = &Phonebook2::Pbk2AppUi()->ApplicationServices().StoreConfiguration();
       
   234     iStoreConfiguration->AddObserverL( *this );
       
   235     }
       
   236 
       
   237 // --------------------------------------------------------------------------
       
   238 // CPbk2FetchDlg::NewL
       
   239 // --------------------------------------------------------------------------
       
   240 //
       
   241 EXPORT_C CPbk2FetchDlg* CPbk2FetchDlg::NewL
       
   242         ( TParams aParams, MPbk2FetchDlgObserver& aObserver )
       
   243     {
       
   244     CPbk2FetchDlg* dlg = new ( ELeave ) CPbk2FetchDlg( aParams, aObserver );
       
   245     CleanupStack::PushL( dlg );
       
   246     dlg->ConstructL();
       
   247     CleanupStack::Pop( dlg );
       
   248     return dlg;
       
   249     }
       
   250 
       
   251 // --------------------------------------------------------------------------
       
   252 // CPbk2FetchDlg::AcceptDelayedFetchL
       
   253 // --------------------------------------------------------------------------
       
   254 //
       
   255 EXPORT_C void CPbk2FetchDlg::AcceptDelayedFetchL
       
   256         ( const TDesC8& aContactLink )
       
   257     {
       
   258     CVPbkContactLinkArray* linkArray = CVPbkContactLinkArray::NewLC
       
   259         ( aContactLink, Phonebook2::Pbk2AppUi()->ApplicationServices().
       
   260             ContactManager().ContactStoresL() );
       
   261 
       
   262     // Append the selected contact to results.
       
   263     if ( linkArray->Count() > 0 )
       
   264         {
       
   265         const MVPbkContactLink& link = linkArray->At( KFirstElement );
       
   266         iResults->AppendDelayedL( link );
       
   267         }
       
   268 
       
   269     CleanupStack::PopAndDestroy(); // linkArray
       
   270     }
       
   271 
       
   272 // --------------------------------------------------------------------------
       
   273 // CPbk2FetchDlg::AcceptDelayedFetchL
       
   274 // --------------------------------------------------------------------------
       
   275 //
       
   276 EXPORT_C void CPbk2FetchDlg::DenyDelayedFetchL
       
   277         ( const TDesC8& aContactLink )
       
   278     {
       
   279     CVPbkContactLinkArray* linkArray = CVPbkContactLinkArray::NewLC
       
   280         ( aContactLink, Phonebook2::Pbk2AppUi()->ApplicationServices().
       
   281             ContactManager().ContactStoresL() );
       
   282 
       
   283     // Unmark the selected contact
       
   284     if ( linkArray->Count() > 0 )
       
   285         {
       
   286         const MVPbkContactLink& link = linkArray->At( KFirstElement );
       
   287         iResults->DenyAppendDelayedL( link );
       
   288         iPages->SelectContactL( link, EFalse );
       
   289         }
       
   290 
       
   291     CleanupStack::PopAndDestroy(); // linkArray
       
   292     }
       
   293 
       
   294 // --------------------------------------------------------------------------
       
   295 // CPbk2FetchDlg::ExecuteLD
       
   296 // --------------------------------------------------------------------------
       
   297 //
       
   298 EXPORT_C TInt CPbk2FetchDlg::ExecuteLD()
       
   299     {
       
   300     return CEikDialog::ExecuteLD( iResData.iDialogId );
       
   301     }
       
   302 
       
   303 // --------------------------------------------------------------------------
       
   304 // CPbk2FetchDlg::RequestExitL
       
   305 // --------------------------------------------------------------------------
       
   306 //
       
   307 void CPbk2FetchDlg::RequestExitL( TInt aCommandId )
       
   308     {
       
   309     iExitRecord.Set( EExitApproved );
       
   310     TryExitL( aCommandId );
       
   311     }
       
   312 
       
   313 // --------------------------------------------------------------------------
       
   314 // CPbk2FetchDlg::ForceExit
       
   315 // --------------------------------------------------------------------------
       
   316 //
       
   317 void CPbk2FetchDlg::ForceExit()
       
   318     {
       
   319     iExitRecord.Set( EExitApproved );
       
   320     iExitRecord.Set( EExitOrdered );
       
   321 
       
   322     TRAPD( err, TryExitL( EAknSoftkeyBack ) );
       
   323     if ( err != KErrNone )
       
   324         {
       
   325         // If not nicely then use the force
       
   326         delete this;
       
   327         }
       
   328     }
       
   329 
       
   330 // --------------------------------------------------------------------------
       
   331 // CPbk2FetchDlg::ResetWhenDestroyed
       
   332 // --------------------------------------------------------------------------
       
   333 //
       
   334 void CPbk2FetchDlg::ResetWhenDestroyed( MPbk2DialogEliminator** aSelfPtr )
       
   335     {
       
   336     __ASSERT_DEBUG(!aSelfPtr || *aSelfPtr == this,
       
   337         Panic(EPanicPreCond_ResetWhenDestroyed));
       
   338 
       
   339     iSelfPtr = aSelfPtr;
       
   340     }
       
   341 
       
   342 // --------------------------------------------------------------------------
       
   343 // CPbk2FetchDlg::CreateCustomControlL
       
   344 // --------------------------------------------------------------------------
       
   345 //
       
   346 SEikControlInfo CPbk2FetchDlg::CreateCustomControlL( TInt aControlType )
       
   347     {
       
   348     SEikControlInfo ctrl;
       
   349     ctrl.iControl = NULL;
       
   350     ctrl.iTrailerTextId = 0;
       
   351     ctrl.iFlags = 0;
       
   352     ctrl.iControl = Pbk2FetchDlgPageFactory::CreateCustomControlL
       
   353         ( aControlType, this, *this );
       
   354     
       
   355     if ( aControlType == EPbk2CtNamesContactViewList )
       
   356         {
       
   357         iNamesListControl = static_cast<CPbk2NamesListControl*>(ctrl.iControl);
       
   358         }
       
   359     else if ( aControlType == EPbk2CtGroupsContactViewList )
       
   360         {
       
   361         iGroupListControl = static_cast<CPbk2NamesListControl*>(ctrl.iControl);
       
   362         }
       
   363     
       
   364     return ctrl;
       
   365     }
       
   366 
       
   367 // --------------------------------------------------------------------------
       
   368 // CPbk2FetchDlg::PreLayoutDynInitL
       
   369 // --------------------------------------------------------------------------
       
   370 //
       
   371 void CPbk2FetchDlg::PreLayoutDynInitL()
       
   372     {
       
   373     CAknDialog::PreLayoutDynInitL();
       
   374 
       
   375     SetupStatusPaneL();
       
   376 
       
   377     iPages = Pbk2FetchDlgPageFactory::CreatePagesL
       
   378         ( *this, Phonebook2::Pbk2AppUi()->ApplicationServices().
       
   379             ContactManager() );
       
   380     iPages->ActiveFirstPageL();
       
   381 
       
   382     iResults = CPbk2FetchResults::NewL( Phonebook2::Pbk2AppUi()->
       
   383         ApplicationServices().ContactManager(),
       
   384         *this, *iPages, iObserver, *this );
       
   385 
       
   386     // Use the current page view because we know the first page is
       
   387     // names list view that contains all contacts that can be marked
       
   388     PageChangedL(iPages->CurrentPage().FetchDlgPageId());
       
   389 
       
   390     __ASSERT_DEBUG(iPages, Panic(EPanicPostCond_PreLayoutDynInitL));
       
   391     }
       
   392 
       
   393 // --------------------------------------------------------------------------
       
   394 // CPbk2FetchDlg::OkToExitL
       
   395 // --------------------------------------------------------------------------
       
   396 //
       
   397 TBool CPbk2FetchDlg::OkToExitL( TInt aButtonId )
       
   398     {
       
   399     TBool okToExit = ETrue;
       
   400     TBool canceled = Canceled( aButtonId );
       
   401     TBool aborted = ( aButtonId == EEikBidCancel );
       
   402 
       
   403     if ( iExitRecord.IsSet( EExitApproved ) )
       
   404         {
       
   405         okToExit = ETrue;
       
   406         }
       
   407     else
       
   408         {
       
   409         if ( !canceled )
       
   410             {
       
   411             okToExit = CheckIsOkToExitL( aButtonId );
       
   412             }
       
   413         }
       
   414 
       
   415     // Only multiple fetch needs to wait buffered operations finished
       
   416     if ( !canceled && ( iParams.iFlags & EFetchMultiple ) )
       
   417         {
       
   418         iResults->WaitOperationsCompleteL();
       
   419         }
       
   420     
       
   421     // Notify observer
       
   422     if ( canceled )
       
   423         {
       
   424         iObserver.FetchCanceled();
       
   425         }
       
   426     else if ( okToExit && aborted )
       
   427         {
       
   428         // End key exit aborts the fetch
       
   429         iObserver.FetchAborted();
       
   430         ExitApplication( EAknCmdExit );
       
   431         }
       
   432     else if ( okToExit && !iExitRecord.IsSet( EExitApproved ) )
       
   433         {
       
   434         // Do not announce fetch completion if exit has already
       
   435         // been approved by the client
       
   436         TBool thisDestroyed = EFalse;
       
   437         iDestroyedPtr = &thisDestroyed;
       
   438         TPbk2DestructionIndicator indicator
       
   439             ( &thisDestroyed, iDestroyedPtr );
       
   440 
       
   441 
       
   442         iObserver.FetchCompletedL( &FetchDlgSelection() );
       
   443 
       
   444         if ( thisDestroyed )
       
   445             {
       
   446             // If this has been destroyed, don't return ok since
       
   447             // returning ETrue would make the base class to
       
   448             // commence more prosessing with already deleted objects
       
   449             okToExit = EFalse;
       
   450             }
       
   451         }
       
   452 
       
   453     // Client can prevent the exit here at the last step. This query
       
   454     // has to be done after the client has been told about fetch
       
   455     // completion/cancellation. If client has already approved
       
   456     // exit, do not query this.
       
   457     if ( okToExit && !iExitRecord.IsSet( EExitApproved ) &&
       
   458          !iObserver.FetchOkToExit() )
       
   459         {
       
   460         okToExit = EFalse;
       
   461         }
       
   462 
       
   463     if ( okToExit )
       
   464         {
       
   465         // Reset results
       
   466         iResults->ResetAndDestroy();
       
   467         }
       
   468     else
       
   469         {
       
   470         // Permit selection again
       
   471         iSelectPermitted = ETrue;
       
   472         }
       
   473     
       
   474     iExitRecord.Set( EExitOrdered );    // exit is now ordered and
       
   475                                         // when client later requests
       
   476                                         // exit, the ordered exit
       
   477                                         // becomes approved exit
       
   478 
       
   479     return okToExit;
       
   480     }
       
   481 
       
   482 // --------------------------------------------------------------------------
       
   483 // CPbk2FetchDlg::PageChangedL
       
   484 // --------------------------------------------------------------------------
       
   485 //
       
   486 void CPbk2FetchDlg::PageChangedL( TInt aPageId )
       
   487     {
       
   488     iPages->HandlePageChangedL( aPageId );
       
   489     UpdateCbasL();
       
   490     }
       
   491 
       
   492 // --------------------------------------------------------------------------
       
   493 // CPbk2FetchDlg::OfferKeyEventL
       
   494 // --------------------------------------------------------------------------
       
   495 //
       
   496 TKeyResponse CPbk2FetchDlg::OfferKeyEventL
       
   497         ( const TKeyEvent& aKeyEvent, TEventCode aType )
       
   498     {
       
   499     TKeyResponse result = EKeyWasNotConsumed;
       
   500 
       
   501     TBool selectContact = EFalse;
       
   502     if ( aKeyEvent.iCode == EKeyOK &&
       
   503             ( iParams.iFlags & EFetchSingle ) )
       
   504         {
       
   505         selectContact = ETrue;
       
   506         }
       
   507     else if ( aKeyEvent.iCode == EKeyPhoneSend )
       
   508         {
       
   509         if ( iParams.iFlags & EFetchCallItem ) 
       
   510             {
       
   511             // Send key is used to select the contact, but only when
       
   512             // operating in 'call item fetch' mode
       
   513             // As the call item fetch is a single fetch, fetch dialog
       
   514             // needs to be exited after item fetched.
       
   515             TryExitL( EAknSoftkeySelect );
       
   516             }
       
   517         else if ( iParams.iFlags & EFetchMultiple || 
       
   518                     ( ( iParams.iFlags & EFetchSingle ) && 
       
   519                         ( EStdKeyYes == aKeyEvent.iScanCode ) ) )
       
   520             {
       
   521             // Call key is inactive when operating in 'multifetch' mode
       
   522             // and 'single item fetch' mode. 
       
   523             // Call key should be active when operating in 'single item 
       
   524             // call fetch' mode
       
   525             return EKeyWasConsumed;
       
   526             }
       
   527         }
       
   528     else if ( aKeyEvent.iCode == EKeyEnter &&
       
   529                 ( iParams.iFlags & EFetchSingle ) )
       
   530         {
       
   531         // Single item fetch selects the highlighted contact and exits
       
   532         // dialog.
       
   533         // Enter key is handled similarly to MSK event, which is
       
   534         // received and handled by CBA (CBA's observer uses TryExitL).
       
   535         TryExitL( EAknSoftkeySelect );
       
   536         }
       
   537 
       
   538     if ( selectContact )
       
   539         {
       
   540         const MVPbkBaseContact* focusedContact =
       
   541             iPages->FocusedContactL();
       
   542         if ( focusedContact )
       
   543             {
       
   544             if ( !( iParams.iFlags & EFetchMultiple ) )
       
   545                 {
       
   546                 delete iFocusedContactLink;
       
   547                 iFocusedContactLink = NULL;
       
   548                 iFocusedContactLink = focusedContact->CreateLinkLC();
       
   549                 CleanupStack::Pop(); // iFocusedContactLink
       
   550                 }
       
   551             MVPbkContactLink* link = focusedContact->CreateLinkLC();
       
   552             SelectContactL( *link, selectContact );
       
   553             CleanupStack::PopAndDestroy(); // link
       
   554             result = EKeyWasConsumed;
       
   555             }
       
   556         else
       
   557             {
       
   558             result = CEikDialog::OfferKeyEventL( aKeyEvent, aType );
       
   559             }
       
   560         }
       
   561     else
       
   562         {
       
   563         // EKeyApplicationF means left softkey is pressed
       
   564         if ( EKeyApplicationF == aKeyEvent.iCode && 
       
   565                 ( iParams.iFlags & EFetchMultiple ) )
       
   566             {
       
   567             iSelectPermitted = EFalse;
       
   568             }
       
   569         if( !Phonebook2::Pbk2AppUi()->KeyEventHandler().Pbk2ProcessKeyEventL( aKeyEvent, aType ) )
       
   570             {
       
   571             
       
   572             if( iNamesListControl && iNamesListControl->IsVisible() 
       
   573                 && aKeyEvent.iCode != EKeyLeftArrow
       
   574                 && aKeyEvent.iCode != EKeyRightArrow 
       
   575                 && aKeyEvent.iCode != EKeyEscape )
       
   576                 {
       
   577                 result = iNamesListControl->OfferKeyEventL( aKeyEvent, aType );
       
   578                 }
       
   579             else if( iGroupListControl && iGroupListControl->IsVisible() 
       
   580                      && aKeyEvent.iCode != EKeyLeftArrow
       
   581                      && aKeyEvent.iCode != EKeyRightArrow 
       
   582                      && aKeyEvent.iCode != EKeyEscape )
       
   583                 {
       
   584                 result = iGroupListControl->OfferKeyEventL( aKeyEvent, aType );
       
   585                 }
       
   586             if( result == EKeyWasNotConsumed )
       
   587                 {
       
   588                 result = CEikDialog::OfferKeyEventL( aKeyEvent, aType );
       
   589                 }
       
   590             }
       
   591         }
       
   592 
       
   593     return result;
       
   594     }
       
   595 
       
   596 // --------------------------------------------------------------------------
       
   597 // CPbk2FetchDlg::HandleResourceChange
       
   598 // --------------------------------------------------------------------------
       
   599 //
       
   600 void CPbk2FetchDlg::HandleResourceChange( TInt aType )
       
   601     {
       
   602     if( aType == KEikDynamicLayoutVariantSwitch )
       
   603         {
       
   604         // Update iMSKEnabled value
       
   605         iMSKEnabled = AknLayoutUtils::MSKEnabled();
       
   606         
       
   607         CEikStatusPane* statusPane = iAvkonAppUi->StatusPane();
       
   608         if (statusPane)
       
   609             {
       
   610             TInt currentStatusPaneResId = statusPane->CurrentLayoutResId();
       
   611             // Make the statusPane update when it was already set to EMPTY status,
       
   612             // in other case it'll update itself automaticlly
       
   613             if( currentStatusPaneResId == R_AVKON_STATUS_PANE_LAYOUT_EMPTY )
       
   614                 {
       
   615                 statusPane->SwitchLayoutL( R_AVKON_STATUS_PANE_LAYOUT_USUAL );
       
   616                 statusPane->HandleResourceChange(aType);                
       
   617                 }
       
   618             }
       
   619             
       
   620         if ( iPages )
       
   621             {
       
   622             // Handle resouce change for all pages 
       
   623             for (TInt i = 0; i < iPages->DlgPageCount() ; i++ )
       
   624                 {
       
   625                 iPages->DlgPageAt( i ).HandleResourceChange( aType );
       
   626                 }
       
   627             }
       
   628         }
       
   629     else if ( aType == KAknsMessageSkinChange )
       
   630         {
       
   631         // Just visual effect, no need to handle error
       
   632         TRAP_IGNORE( SkinTabsL() );
       
   633         }
       
   634 
       
   635     CAknDialog::HandleResourceChange(aType);
       
   636     }
       
   637 
       
   638 // --------------------------------------------------------------------------
       
   639 // CPbk2FetchDlg::LineChangedL
       
   640 // --------------------------------------------------------------------------
       
   641 //
       
   642 void CPbk2FetchDlg::LineChangedL( TInt /*aControlId*/ )
       
   643     {
       
   644     UpdateCbasL();
       
   645     }
       
   646 
       
   647 // --------------------------------------------------------------------------
       
   648 // CPbk2FetchDlg::FetchDlgControl
       
   649 // --------------------------------------------------------------------------
       
   650 //
       
   651 CCoeControl* CPbk2FetchDlg::FetchDlgControl( TInt aCtrlId ) const
       
   652     {
       
   653     return ControlOrNull( aCtrlId );
       
   654     }
       
   655 
       
   656 // --------------------------------------------------------------------------
       
   657 // CPbk2FetchDlg::FetchDlgViewL
       
   658 // --------------------------------------------------------------------------
       
   659 //
       
   660 MVPbkContactViewBase& CPbk2FetchDlg::FetchDlgViewL( TInt aControlId ) const
       
   661     {
       
   662     MVPbkContactViewBase* view = NULL;
       
   663 
       
   664     if ( iPages )
       
   665         {
       
   666         // Return page's view
       
   667         MPbk2FetchDlgPage* page = iPages->DlgPageWithId( aControlId );
       
   668         if ( page )
       
   669             {
       
   670             MVPbkContactViewBase& pageView = page->View();
       
   671             view = &pageView;
       
   672             }
       
   673         }
       
   674 
       
   675     if ( !view )
       
   676         {
       
   677         if ( aControlId == ECtrlFetchNamesList )
       
   678             {
       
   679             if ( iParams.iNamesListView )
       
   680                 {
       
   681                 // Use view given as parameter
       
   682                 view = iParams.iNamesListView;
       
   683                 }
       
   684             else
       
   685                 {
       
   686                 // If there is no view given, we use all contacts view
       
   687                 view = Phonebook2::Pbk2AppUi()->ApplicationServices().
       
   688                     ViewSupplier().AllContactsViewL();
       
   689                 }
       
   690             }
       
   691         else if (aControlId == ECtrlFetchGroupsList)
       
   692             {
       
   693             if ( iParams.iGroupsListView )
       
   694                 {
       
   695                 // Use view given as parameter
       
   696                 view = iParams.iGroupsListView;
       
   697                 }
       
   698             else
       
   699                 {
       
   700                 // If there is no view given, we use all groups view
       
   701                 view = Phonebook2::Pbk2AppUi()->ApplicationServices().
       
   702                     ViewSupplier().AllGroupsViewL();
       
   703                 }
       
   704             }
       
   705 
       
   706         }
       
   707 
       
   708     return *view;
       
   709     }
       
   710 
       
   711 // --------------------------------------------------------------------------
       
   712 // CPbk2FetchDlg::SetFetchDlgViewL
       
   713 // --------------------------------------------------------------------------
       
   714 //
       
   715 void CPbk2FetchDlg::SetFetchDlgViewL
       
   716         ( TInt aControlId, MVPbkContactViewBase& aView )
       
   717     {
       
   718     MPbk2FetchDlgPage* page = iPages->DlgPageWithId( aControlId );
       
   719 
       
   720     if ( page )
       
   721         {
       
   722         page->SetViewL( aView );
       
   723         }
       
   724     }
       
   725 
       
   726 // --------------------------------------------------------------------------
       
   727 // CPbk2FetchDlg::FetchDlgSelection
       
   728 // --------------------------------------------------------------------------
       
   729 //
       
   730 MVPbkContactLinkArray& CPbk2FetchDlg::FetchDlgSelection()
       
   731     {
       
   732     return *iResults;
       
   733     }
       
   734 
       
   735 // --------------------------------------------------------------------------
       
   736 // CPbk2FetchDlg::FetchDlgHandleError
       
   737 // --------------------------------------------------------------------------
       
   738 //
       
   739 void CPbk2FetchDlg::FetchDlgHandleError( TInt aError )
       
   740     {
       
   741     iEikonEnv->HandleError( aError );
       
   742     }
       
   743 
       
   744 // --------------------------------------------------------------------------
       
   745 // CPbk2FetchDlg::FetchDlgClientRect
       
   746 // --------------------------------------------------------------------------
       
   747 //
       
   748 TRect CPbk2FetchDlg::FetchDlgClientRect() const
       
   749     {
       
   750     TRect appRect = iAvkonAppUi->ApplicationRect();
       
   751     TAknLayoutRect mainPane;
       
   752     mainPane.LayoutRect( appRect,
       
   753         AKN_LAYOUT_WINDOW_main_pane( appRect, 0, 1, 1 ) );
       
   754     return mainPane.Rect();
       
   755     }
       
   756 
       
   757 // --------------------------------------------------------------------------
       
   758 // CPbk2FetchDlg::FetchDlgPageChangedL
       
   759 // --------------------------------------------------------------------------
       
   760 //
       
   761 void CPbk2FetchDlg::FetchDlgPageChangedL( MPbk2FetchDlgPage& aPage )
       
   762     {
       
   763     delete iSelectionRestorer;
       
   764     iSelectionRestorer = NULL;
       
   765 
       
   766     if ( aPage.DlgPageReady() )
       
   767         {
       
   768         // An view event burst from VPbk results this function being called
       
   769         // several times a row. It is not meaningful to restore selections
       
   770         // every time, but inste ad wait for a while and restore the selections
       
   771         // after all events have been received. Hence the idle object is used.
       
   772         iSelectionRestorer = CIdle::NewL( CActive::EPriorityIdle );
       
   773         iSelectionRestorer->Start( TCallBack( RestoreSelections, this ));
       
   774         }
       
   775     }
       
   776 
       
   777 // --------------------------------------------------------------------------
       
   778 // CPbk2FetchDlg::FetchDlgObserver
       
   779 // --------------------------------------------------------------------------
       
   780 //
       
   781 MPbk2FetchDlgObserver& CPbk2FetchDlg::FetchDlgObserver() const
       
   782     {
       
   783     return iObserver;
       
   784     }
       
   785 
       
   786 // --------------------------------------------------------------------------
       
   787 // CPbk2FetchDlg::SelectContactL
       
   788 // --------------------------------------------------------------------------
       
   789 //
       
   790 void CPbk2FetchDlg::SelectContactL
       
   791         ( const MVPbkContactLink& aLink, TBool aSelected )
       
   792     {
       
   793     if ( iParams.iFlags & EFetchSingle )
       
   794         {
       
   795          // Clean result if this is single fetch.
       
   796          iResults->ResetAndDestroy();
       
   797         }
       
   798     if ( aSelected )
       
   799         {
       
   800         iResults->AppendL( aLink );
       
   801 
       
   802         MVPbkContactLink* link = iPages->CurrentPage().Control().
       
   803             FocusedContactL()->CreateLinkLC();
       
   804 
       
   805         if ( link->IsSame( aLink ) )
       
   806             {
       
   807             UpdateMultiSelectionMSKL( ETrue );
       
   808             }
       
   809 
       
   810         CleanupStack::PopAndDestroy( ); // link
       
   811         }
       
   812     else
       
   813         {
       
   814         iResults->RemoveL( aLink );
       
   815         
       
   816 
       
   817         // Names list control always delegates its behavior to the associated state, when 
       
   818         // the names list control is in empty state, then it may return NULL here;
       
   819 
       
   820         const MVPbkBaseContact* focusedContact = iPages->CurrentPage().Control().FocusedContactL();
       
   821         if ( focusedContact )
       
   822         	{  
       
   823         	MVPbkContactLink* link = focusedContact->CreateLinkLC();
       
   824             if ( link->IsSame( aLink ) )
       
   825                 {
       
   826                 UpdateMultiSelectionMSKL( EFalse );
       
   827                 }    
       
   828             CleanupStack::PopAndDestroy( ); // link
       
   829         	}
       
   830         }
       
   831     }
       
   832 // --------------------------------------------------------------------------
       
   833 // CPbk2FetchDlg::IsSelectPermitted
       
   834 // --------------------------------------------------------------------------
       
   835 //
       
   836 TBool CPbk2FetchDlg::IsSelectPermitted()
       
   837     {
       
   838     return iSelectPermitted;
       
   839     }
       
   840 
       
   841 // --------------------------------------------------------------------------
       
   842 // CPbk2FetchDlg::HandleControlEventL
       
   843 // --------------------------------------------------------------------------
       
   844 //
       
   845 void CPbk2FetchDlg::HandleControlEventL
       
   846         ( MPbk2ContactUiControl& /*aControl*/,
       
   847           const TPbk2ControlEvent& aEvent )
       
   848     {
       
   849     switch ( aEvent.iEventType )
       
   850         {
       
   851         case TPbk2ControlEvent::EContactDoubleTapped:
       
   852             {
       
   853             if ( !(iParams.iFlags & EFetchMultiple) )
       
   854                 {
       
   855                 // Single item fetch dialog double tap
       
   856                 // -> try to accept the dialog
       
   857                 iDialogAccepter->Cancel();
       
   858                 iDialogAccepter->CallBack();
       
   859                 }
       
   860             break;
       
   861             }
       
   862 
       
   863         case TPbk2ControlEvent::EContactSetChanged:     // FALLTHROUGH
       
   864         case TPbk2ControlEvent::EControlStateChanged:
       
   865             {
       
   866             // Find pane events are handled here
       
   867             UpdateCbasL();
       
   868             break;
       
   869             }
       
   870             
       
   871         case TPbk2ControlEvent::EReady:
       
   872             {
       
   873             MVPbkContactLinkArray* markedEntries = iParams.iMarkedEntries;
       
   874         
       
   875             if ( markedEntries && iPages && iResults)
       
   876                 {
       
   877                 const TInt markedEntriesCount = markedEntries->Count();
       
   878                 for ( TInt i = 0; i < markedEntriesCount; i ++ )
       
   879                     {
       
   880                     const MVPbkContactLink& link = markedEntries->At(i);
       
   881                     iPages->SelectContactL( link, ETrue );
       
   882                     iResults->AppendToResultsL( link );
       
   883                     }
       
   884                 }
       
   885             break;
       
   886             }
       
   887 
       
   888         default:
       
   889             {
       
   890             // Do nothing
       
   891             break;
       
   892             }
       
   893         }
       
   894     }
       
   895 
       
   896 // --------------------------------------------------------------------------
       
   897 // CPbk2FetchDlg::ContactSelected
       
   898 // --------------------------------------------------------------------------
       
   899 //
       
   900 void CPbk2FetchDlg::ContactSelected
       
   901         ( const MVPbkContactLink& aLink, TBool aSelected )
       
   902     {
       
   903     if ( aSelected && iFocusedContactLink && iFocusedContactLink->IsSame( aLink ) )
       
   904         {
       
   905         // Deleting focused contact link that next time single fetch
       
   906         // also fetches the contact.
       
   907         delete iFocusedContactLink;
       
   908         iFocusedContactLink = NULL;
       
   909 
       
   910         TRAPD( err, TryExitL( EEikBidOk ) );
       
   911         if ( err != KErrNone )
       
   912             {
       
   913             // If not nicely then use the force
       
   914             delete this;
       
   915             }
       
   916         }
       
   917     else
       
   918         {
       
   919         TRAP_IGNORE( UpdateCbasL() );
       
   920         }
       
   921     }
       
   922 
       
   923 // --------------------------------------------------------------------------
       
   924 // CPbk2FetchDlg::ContactSelectionFailed
       
   925 // --------------------------------------------------------------------------
       
   926 //
       
   927 void CPbk2FetchDlg::ContactSelectionFailed()
       
   928     {
       
   929     // Delete the focused link so that the exit procedure can be tried again
       
   930     delete iFocusedContactLink;
       
   931     iFocusedContactLink = NULL;
       
   932     }
       
   933 
       
   934 // --------------------------------------------------------------------------
       
   935 // CPbk2FetchDlg::SetCbaCommandSetL
       
   936 // --------------------------------------------------------------------------
       
   937 //
       
   938 void CPbk2FetchDlg::SetCbaCommandSetL( TInt aResourceId )
       
   939     {
       
   940     // Only need to call SetCommandSetL for the CBA if the resource actually changes.
       
   941     // And also, unnecessary to call the DrawDeferred since the CBA SetCommandSetL
       
   942     // does a redraw on the CBA.
       
   943     if( iCbaCommandSet != aResourceId )
       
   944         {
       
   945         CEikButtonGroupContainer& cba = ButtonGroupContainer();
       
   946         cba.SetCommandSetL( aResourceId );
       
   947         iCbaCommandSet = aResourceId;
       
   948         }
       
   949     }
       
   950 
       
   951 // --------------------------------------------------------------------------
       
   952 // CPbk2FetchDlg::SetupStatusPaneL
       
   953 // --------------------------------------------------------------------------
       
   954 //
       
   955 void CPbk2FetchDlg::SetupStatusPaneL()
       
   956     {
       
   957     delete iNaviDecorator;
       
   958     iNaviDecorator = NULL;
       
   959 
       
   960     TInt navipaneResId = KErrNone;
       
   961 
       
   962     CEikStatusPane* statusPane = iAvkonAppUi->StatusPane();
       
   963     if (statusPane)
       
   964         {
       
   965         // Switch to Phonebook's status pane layout. Calling app has to
       
   966         // restore the layout if different
       
   967         statusPane->SwitchLayoutL( R_AVKON_STATUS_PANE_LAYOUT_USUAL );
       
   968 
       
   969         // First test if there was a navi pane parameter
       
   970         if ( iParams.iNaviPaneId > 0 )
       
   971             {
       
   972             navipaneResId = iParams.iNaviPaneId;
       
   973             }
       
   974         // If no parameter was found, test is navi pane defined in resources
       
   975         else if ( iResData.iNaviPaneId > 0 )
       
   976             {
       
   977             navipaneResId = iResData.iNaviPaneId;
       
   978             }
       
   979 
       
   980         // Setup navi pane if defined in resources
       
   981         if ( navipaneResId &&
       
   982             statusPane->PaneCapabilities
       
   983             (TUid::Uid(EEikStatusPaneUidNavi)).IsPresent())
       
   984             {
       
   985             CAknNavigationControlContainer* naviPane =
       
   986                 static_cast<CAknNavigationControlContainer*>
       
   987                 (statusPane->ControlL(TUid::Uid(EEikStatusPaneUidNavi)));
       
   988             TResourceReader reader;
       
   989             iCoeEnv->CreateResourceReaderLC( reader, navipaneResId );
       
   990             iNaviDecorator =
       
   991                 naviPane->ConstructNavigationDecoratorFromResourceL
       
   992                     ( reader );
       
   993             naviPane->PushL(*iNaviDecorator);
       
   994             CleanupStack::PopAndDestroy();  // reader
       
   995             }
       
   996         }
       
   997     }
       
   998 
       
   999 // --------------------------------------------------------------------------
       
  1000 // CPbk2FetchDlg::UpdateCbasL
       
  1001 // --------------------------------------------------------------------------
       
  1002 //
       
  1003 void CPbk2FetchDlg::UpdateCbasL()
       
  1004     {
       
  1005     if ( iResults && iPages &&  iPages->CurrentPage().DlgPageReady() &&
       
  1006          !iPages->CurrentPage().DlgPageEmpty() )
       
  1007         {
       
  1008         // Use user defined CBA parameter if exist
       
  1009         if ( iParams.iCbaId )
       
  1010             {
       
  1011             SetCbaCommandSetL( iParams.iCbaId );
       
  1012             }
       
  1013         // Use CBA resources if exist
       
  1014         else if ( iResData.iCbaId )
       
  1015             {
       
  1016             SetCbaCommandSetL( iResData.iCbaId );
       
  1017             }
       
  1018         // Resources for single fetch
       
  1019         else if ( iParams.iFlags & EFetchSingle )
       
  1020             {
       
  1021             SetCbaCommandSetL( R_PBK2_SOFTKEYS_OK_BACK_OK );
       
  1022             }
       
  1023     
       
  1024         if ( iParams.iFlags & EFetchMultiple )
       
  1025             {
       
  1026             CEikButtonGroupContainer& cba = ButtonGroupContainer();
       
  1027             if ( iResults->Count() < iParams.iMinSelection )
       
  1028                 {
       
  1029                 cba.MakeCommandVisibleByPosition
       
  1030                     ( CEikButtonGroupContainer::ELeftSoftkeyPosition, EFalse );
       
  1031                 }
       
  1032             else
       
  1033                 {
       
  1034                 cba.MakeCommandVisibleByPosition
       
  1035                     ( CEikButtonGroupContainer::ELeftSoftkeyPosition, ETrue );
       
  1036                 }
       
  1037             }
       
  1038         
       
  1039         MVPbkContactLink* link = NULL;
       
  1040         TBool contactSelected = EFalse;
       
  1041         //Used the TRAPD to catch the exception when the contact can't be found in DB. 
       
  1042         TRAPD( err,
       
  1043                 {link=iPages->CurrentPage().Control().FocusedContactL()->CreateLinkLC();CleanupStack::Pop();});
       
  1044         TInt findResult = KErrNotFound;
       
  1045         if ( KErrNone == err )
       
  1046             {
       
  1047             findResult = iResults->Find( *link );
       
  1048             delete link;
       
  1049             }
       
  1050         else
       
  1051             {
       
  1052             // ignore KErrNotFound  as it will cause dead loop in CPbk2PredictiveViewStack::Reset.
       
  1053             if ( KErrNotFound != err )
       
  1054                 {
       
  1055                 User::LeaveIfError( err );
       
  1056                 }
       
  1057             }
       
  1058 
       
  1059         if ( findResult != KErrNotFound )
       
  1060             {
       
  1061             User::LeaveIfError( findResult );
       
  1062             contactSelected = ETrue;
       
  1063             }
       
  1064 
       
  1065         UpdateMultiSelectionMSKL( contactSelected );
       
  1066 
       
  1067         }
       
  1068     else
       
  1069         {
       
  1070         if ( iResData.iEmptyCbaId )
       
  1071             {
       
  1072             SetCbaCommandSetL( iResData.iEmptyCbaId );
       
  1073             }
       
  1074         else
       
  1075             {
       
  1076             SetCbaCommandSetL( R_PBK2_SOFTKEYS_EMPTY_BACK_EMPTY );
       
  1077             }
       
  1078         }
       
  1079     }
       
  1080 
       
  1081 // --------------------------------------------------------------------------
       
  1082 // CPbk2FetchDlg::UpdateMultiSelectionMSKL
       
  1083 // --------------------------------------------------------------------------
       
  1084 //
       
  1085 void CPbk2FetchDlg::UpdateMultiSelectionMSKL( TBool aContactSelected )
       
  1086     {
       
  1087     if ( iMSKEnabled && iParams.iFlags & EFetchMultiple )
       
  1088         {
       
  1089         RemoveCommandFromMSK();
       
  1090 
       
  1091         if ( aContactSelected )
       
  1092             {
       
  1093             SetMiddleSoftKeyLabelL
       
  1094                 ( R_QTN_MSK_UNMARK, EAknSoftkeyUnmark );
       
  1095             }
       
  1096         else
       
  1097             {
       
  1098             SetMiddleSoftKeyLabelL( R_QTN_MSK_MARK, EAknSoftkeyMark );
       
  1099             }
       
  1100         }
       
  1101     }
       
  1102 
       
  1103 // --------------------------------------------------------------------------
       
  1104 // CPbk2FetchDlg::RemoveCommandFromMSK
       
  1105 // --------------------------------------------------------------------------
       
  1106 //
       
  1107 void CPbk2FetchDlg::RemoveCommandFromMSK()
       
  1108     {
       
  1109     ButtonGroupContainer().
       
  1110         RemoveCommandFromStack( KPbk2MSKControlId, EAknSoftkeyMark );
       
  1111     ButtonGroupContainer().
       
  1112         RemoveCommandFromStack( KPbk2MSKControlId, EAknSoftkeyUnmark );
       
  1113     }
       
  1114 
       
  1115 // --------------------------------------------------------------------------
       
  1116 // CPbk2FetchDlg::SetMiddleSoftKeyLabelL
       
  1117 // --------------------------------------------------------------------------
       
  1118 //
       
  1119 void CPbk2FetchDlg::SetMiddleSoftKeyLabelL
       
  1120         ( const TInt aResourceId, const TInt aCommandId )
       
  1121     {
       
  1122     CEikButtonGroupContainer& cbaGroup = ButtonGroupContainer();
       
  1123     HBufC* middleSKText = StringLoader::LoadLC( aResourceId );
       
  1124     TPtr mskPtr = middleSKText->Des();
       
  1125     cbaGroup.AddCommandToStackL(
       
  1126         KPbk2MSKControlId,
       
  1127         aCommandId,
       
  1128         mskPtr );
       
  1129     CleanupStack::PopAndDestroy( middleSKText );
       
  1130     }
       
  1131 
       
  1132 // --------------------------------------------------------------------------
       
  1133 // CPbk2FetchDlg::TryAcceptSelectionL
       
  1134 // --------------------------------------------------------------------------
       
  1135 //
       
  1136 TInt CPbk2FetchDlg::TryAcceptSelectionL( TAny* aSelf )
       
  1137     {
       
  1138     static_cast< CPbk2FetchDlg* >( aSelf )->TryExitL( EAknSoftkeySelect );
       
  1139     return KErrNone;
       
  1140     }
       
  1141 
       
  1142 // --------------------------------------------------------------------------
       
  1143 // CPbk2FetchDlg::CheckIsOkToExitL
       
  1144 // --------------------------------------------------------------------------
       
  1145 //
       
  1146 inline TBool CPbk2FetchDlg::CheckIsOkToExitL( TInt aButtonId )
       
  1147     {
       
  1148     TBool ret = ETrue;
       
  1149 
       
  1150     switch ( aButtonId )
       
  1151         {
       
  1152         case EAknSoftkeyMark:
       
  1153             {
       
  1154             iPages->CurrentPage().Control().
       
  1155                 ProcessCommandL( EAknCmdMark );
       
  1156             // Not ok to exit
       
  1157             ret = EFalse;
       
  1158             break;
       
  1159             }
       
  1160 
       
  1161         case EAknSoftkeyUnmark:
       
  1162             {
       
  1163             iPages->CurrentPage().Control().
       
  1164                 ProcessCommandL( EAknCmdUnmark );
       
  1165             // Not ok to exit
       
  1166             ret = EFalse;
       
  1167             break;
       
  1168             }
       
  1169 
       
  1170         case EEikBidCancel:
       
  1171             {
       
  1172             // End key pressed, query permission for application exit
       
  1173             if ( !OkToExitApplicationL( EEikBidCancel ) )
       
  1174                 {
       
  1175                 ret = EFalse;
       
  1176                 }
       
  1177             break;
       
  1178             }
       
  1179         }
       
  1180 
       
  1181     if ( ret && aButtonId != EEikBidCancel )
       
  1182         {
       
  1183         // Focused contact must be returned if no contacts yet selected,
       
  1184         // and the focused contact selection is not already on its way
       
  1185         if ( FetchDlgSelection().Count() == 0 && !( iParams.iFlags & EFetchMultiple ) )
       
  1186             {
       
  1187             const MVPbkBaseContact* focusedContact = iPages->FocusedContactL();    
       
  1188             if ( focusedContact )
       
  1189                 {
       
  1190                 delete iFocusedContactLink;
       
  1191                 iFocusedContactLink = NULL;
       
  1192                 iFocusedContactLink = focusedContact->CreateLinkLC();
       
  1193                 CleanupStack::Pop(); // iFocusedContactLink
       
  1194                 if ( iParams.iFlags & EFetchSingle )
       
  1195                     {
       
  1196                     // Clean result if this is single fetch.
       
  1197                     iResults->ResetAndDestroy();
       
  1198                     }
       
  1199                 SelectContactL( *iFocusedContactLink, ETrue );
       
  1200                 }
       
  1201 
       
  1202             // Not ok to to exit, since contact selection is asynchronous
       
  1203             ret = EFalse;
       
  1204             }
       
  1205         }
       
  1206     return ret;
       
  1207     }
       
  1208 
       
  1209 // --------------------------------------------------------------------------
       
  1210 // CPbk2FetchDlg::Canceled
       
  1211 // EEikBidCancel is omitted on purpose. End key sends EEikBidCancel,
       
  1212 // and it indicates abortion, not cancellation.
       
  1213 // --------------------------------------------------------------------------
       
  1214 //
       
  1215 inline TBool CPbk2FetchDlg::Canceled( TInt aButtonId )
       
  1216     {
       
  1217     TBool canceled = EFalse;
       
  1218 
       
  1219     switch ( aButtonId )
       
  1220         {
       
  1221         case EAknSoftkeyBack:       // FALLTHROUGH
       
  1222         case EAknSoftkeyClose:      // FALLTHROUGH
       
  1223         case EAknSoftkeyNo:         // FALLTHROUGH
       
  1224         case EAknSoftkeyExit:
       
  1225             {
       
  1226             canceled = ETrue;
       
  1227             break;
       
  1228             }
       
  1229         }
       
  1230 
       
  1231     return canceled;
       
  1232     }
       
  1233 
       
  1234 // --------------------------------------------------------------------------
       
  1235 // CPbk2FetchDlg::SkinTabsL
       
  1236 // --------------------------------------------------------------------------
       
  1237 //
       
  1238 void CPbk2FetchDlg::SkinTabsL()
       
  1239     {
       
  1240     PBK2_DEBUG_PRINT(PBK2_DEBUG_STRING("SkinTabsL start"));
       
  1241     CEikStatusPane* statusPane = iAvkonAppUi->StatusPane();
       
  1242 
       
  1243     if (statusPane && statusPane->PaneCapabilities
       
  1244         (TUid::Uid(EEikStatusPaneUidNavi)).IsPresent())
       
  1245         {
       
  1246         CAknNavigationControlContainer* naviPane =
       
  1247             static_cast<CAknNavigationControlContainer*>
       
  1248             (statusPane->ControlL(TUid::Uid(EEikStatusPaneUidNavi)));
       
  1249         CAknNavigationDecorator* naviDeco = naviPane->Top();
       
  1250 
       
  1251         if ( naviDeco )
       
  1252             {
       
  1253             PBK2_DEBUG_PRINT(PBK2_DEBUG_STRING("SkinTabsL naviDeco"));
       
  1254             if ( naviDeco->ControlType() ==
       
  1255                     CAknNavigationDecorator::ETabGroup )
       
  1256                 {
       
  1257                 MAknsSkinInstance* skin = AknsUtils::SkinInstance();
       
  1258 
       
  1259                 PBK2_DEBUG_PRINT(PBK2_DEBUG_STRING("SkinTabsL ETabGroup"));
       
  1260                 CPbk2IconInfoContainer* tabIcons =
       
  1261                     CPbk2IconInfoContainer::NewL
       
  1262                         ( R_PBK2_FETCH_TAB_ICON_INFO_ARRAY );
       
  1263                 CleanupStack::PushL( tabIcons );
       
  1264 
       
  1265                 CAknTabGroup* tabGroup =
       
  1266                     static_cast<CAknTabGroup*>(naviDeco->DecoratedControl());
       
  1267 
       
  1268                 const TInt count = tabGroup->TabCount();
       
  1269                 PBK2_DEBUG_PRINT(PBK2_DEBUG_STRING
       
  1270                     ("SkinTabsL TabCount = %d"), count);
       
  1271                 for (TInt i = 0; i < count; ++i)
       
  1272                     {
       
  1273                     TInt tabId = tabGroup->TabIdFromIndex(i);
       
  1274                     // tabId is used as icon id
       
  1275                     TPbk2IconId iconId( TUid::Uid(KPbk2UID3), tabId );
       
  1276                     const CPbk2IconInfo* iconInfo = tabIcons->Find(iconId);
       
  1277                     if (iconInfo)
       
  1278                         {
       
  1279                         CFbsBitmap* bitmap = NULL;
       
  1280                         CFbsBitmap* mask = NULL;
       
  1281 
       
  1282                         CPbk2IconFactory* factory =
       
  1283                             CPbk2IconFactory::NewLC( *tabIcons );
       
  1284                         factory->CreateIconLC(iconId, *skin, bitmap, mask);
       
  1285                         tabGroup->ReplaceTabL(tabId, bitmap, mask);
       
  1286                         CleanupStack::Pop(2); // mask, bitmap
       
  1287                         CleanupStack::PopAndDestroy(factory);
       
  1288                         }
       
  1289                     }
       
  1290                 CleanupStack::PopAndDestroy( tabIcons );
       
  1291                 }
       
  1292             }
       
  1293         }
       
  1294     PBK2_DEBUG_PRINT(PBK2_DEBUG_STRING("SkinTabsL end"));
       
  1295     }
       
  1296 
       
  1297 // --------------------------------------------------------------------------
       
  1298 // CPbk2FetchDlg::DelaySkinning
       
  1299 // --------------------------------------------------------------------------
       
  1300 //
       
  1301 TInt CPbk2FetchDlg::DelaySkinning( TAny* aFetchDlg )
       
  1302     {
       
  1303     // Tab skinning is just visual effect, no need to handle error
       
  1304     TRAP_IGNORE( ( (CPbk2FetchDlg*)aFetchDlg)->SkinTabsL() );
       
  1305     return 0; // one time only
       
  1306     }
       
  1307 
       
  1308 // --------------------------------------------------------------------------
       
  1309 // CPbk2FetchDlg::RestoreSelections
       
  1310 // --------------------------------------------------------------------------
       
  1311 //
       
  1312 TInt CPbk2FetchDlg::RestoreSelections( TAny* aFetchDlg )
       
  1313     {
       
  1314     CPbk2FetchDlg* self = static_cast<CPbk2FetchDlg*> ( aFetchDlg );
       
  1315     TRAPD( err, self->RestoreSelectionsL() );
       
  1316     if ( err != KErrNone )
       
  1317     	{
       
  1318     	self->FetchDlgHandleError( err );
       
  1319     	}
       
  1320 
       
  1321     return 0; // one time only
       
  1322     }
       
  1323 
       
  1324 // --------------------------------------------------------------------------
       
  1325 // CPbk2FetchDlg::RestoreSelectionsL
       
  1326 // --------------------------------------------------------------------------
       
  1327 //
       
  1328 void CPbk2FetchDlg::RestoreSelectionsL()
       
  1329     {
       
  1330     if ( iResults )
       
  1331         {
       
  1332         for ( TInt i = 0; i < iResults->Count(); ++i )
       
  1333             {
       
  1334             iPages->SelectContactL( iResults->At( i ), ETrue );
       
  1335             }
       
  1336         }
       
  1337     
       
  1338     UpdateCbasL();
       
  1339     }
       
  1340 
       
  1341 // --------------------------------------------------------------------------
       
  1342 // CPbk2FetchDlg::OkToExitApplicationL
       
  1343 // --------------------------------------------------------------------------
       
  1344 //
       
  1345 TBool CPbk2FetchDlg::OkToExitApplicationL( TInt aCommandId )
       
  1346     {
       
  1347     TBool okToExit = ETrue;
       
  1348 
       
  1349     // If exit callback returned EFalse, the exit is cancelled
       
  1350     if ( iParams.iExitCallback &&
       
  1351          !iParams.iExitCallback->OkToExitL( aCommandId ) )
       
  1352         {
       
  1353         okToExit = EFalse;
       
  1354         }
       
  1355 
       
  1356     if ( !okToExit )
       
  1357         {
       
  1358         iExitRecord.Clear( EExitApproved );
       
  1359         }
       
  1360 
       
  1361     return okToExit;
       
  1362     }
       
  1363 
       
  1364 // --------------------------------------------------------------------------
       
  1365 // CPbk2FetchDlg::ExitApplication
       
  1366 // --------------------------------------------------------------------------
       
  1367 //
       
  1368 void CPbk2FetchDlg::ExitApplication( TInt aCommandId )
       
  1369     {
       
  1370     if ( iExitRecord.IsSet( EExitOrdered ) &&
       
  1371          iExitRecord.IsSet( EExitApproved ) )
       
  1372         {
       
  1373         CEikAppUi* appUi = iEikonEnv->EikAppUi();
       
  1374         MEikCommandObserver* cmdObs =
       
  1375             static_cast<MEikCommandObserver*>( appUi );
       
  1376 
       
  1377         // Dialog is closed so there is nothing to do if
       
  1378         // ProcessCommandL leaves. Of course it shouldn't leave in
       
  1379         // practice because it's exit command.
       
  1380         TRAP_IGNORE( cmdObs->ProcessCommandL( aCommandId ) );
       
  1381         }
       
  1382     }
       
  1383 
       
  1384 
       
  1385 // --------------------------------------------------------------------------
       
  1386 // CPbk2FetchDlg::ConfigurationChanged
       
  1387 // --------------------------------------------------------------------------
       
  1388 //
       
  1389 void CPbk2FetchDlg::ConfigurationChanged()
       
  1390     {
       
  1391     // Do nothing.
       
  1392     }
       
  1393 
       
  1394 // --------------------------------------------------------------------------
       
  1395 // CPbk2FetchDlg::ConfigurationChangedComplete
       
  1396 // --------------------------------------------------------------------------
       
  1397 //
       
  1398 void CPbk2FetchDlg::ConfigurationChangedComplete()
       
  1399     {
       
  1400     // When changing the setting in phonebook.
       
  1401     // Fetch dialog will exit and return back to the last view.
       
  1402     // For example:
       
  1403     // Speeddial: back to its main view.
       
  1404     // Message:   back to its editor view.
       
  1405     TryExitL( EAknSoftkeyBack );
       
  1406     }
       
  1407 // End of File