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