phonebookui/Phonebook/View/src/CPbkFetchDlg.cpp
changeset 0 e686773b3f54
child 68 9da50d567e3c
equal deleted inserted replaced
-1:000000000000 0:e686773b3f54
       
     1 /*
       
     2 * Copyright (c) 2002 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: 
       
    15 *       Provides methods for Fetch dialog for Phonebook.
       
    16 *
       
    17 */
       
    18 
       
    19 
       
    20 // INCLUDE FILES
       
    21 #include "CPbkFetchDlg.h"   // This class
       
    22 #include <barsread.h>       // TResourceReader
       
    23 #include <avkon.rsg>        // AVKON resource IDs
       
    24 #include <aknnavide.h>      // CAknNavigationDecorator
       
    25 #include <aknappui.h>       // CEikAppUi
       
    26 #include <PbkView.rsg>              // Phonebook view dll resource IDs
       
    27 #include <AknUtils.h> 
       
    28 #include <CPbkContactIdSet.h>
       
    29 #include <TPbkContactViewIterator.h>
       
    30 #include <CPbkExtGlobals.h>
       
    31 
       
    32 #include <PbkView.hrh>              // Phonebook view dll resource constants
       
    33 #include "CPbkContextPaneIcon.h"
       
    34 #include "MPbkFetchDlgPage.h"
       
    35 #include "PbkFetchDlgPageFactory.h"
       
    36 #include "MPbkFetchCallbacks.h"
       
    37 #include "MPbkFetchDlgSelection.h"
       
    38 #include <CPbkContactViewListControl.h>
       
    39 #include <PbkIconInfo.h>
       
    40 #include <akntabgrp.h>					// CAknTabGroup
       
    41 #include <AknsUtils.h>
       
    42 #include <PbkDebug.h>
       
    43 
       
    44 
       
    45 
       
    46 /// Unnamed namespace for local definitions
       
    47 namespace {
       
    48 
       
    49 // LOCAL CONSTANTS AND MACROS
       
    50 enum TPanicCode
       
    51     {
       
    52     EPanicNullContactView = 1,
       
    53     EPanicPreCond_ConstructL,
       
    54     EPanicInvalidResourceData,
       
    55     EPanicPreCond_PreLayoutDynInitL,
       
    56     EPanicPostCond_PreLayoutDynInitL,
       
    57     EPanicPreCond_ResetWhenDestroyed,
       
    58     };
       
    59 
       
    60 
       
    61 // ==================== LOCAL FUNCTIONS ====================
       
    62 
       
    63 void Panic(TInt aReason)
       
    64     {
       
    65     _LIT(KPanicText, "CPbkFetchDlg");
       
    66     User::Panic(KPanicText, aReason);
       
    67     }
       
    68 
       
    69 /**
       
    70  * Returns ETrue if all dialog pages in aPages are ready.
       
    71  */
       
    72 TBool AllPagesReady(const MPbkFetchDlgPages& aPages)
       
    73     {
       
    74     const TInt count = aPages.DlgPageCount();
       
    75     for (TInt i=0; i < count; ++i)
       
    76         {
       
    77         if (!aPages.DlgPageAt(i).DlgPageReady())
       
    78             {
       
    79             return EFalse;
       
    80             }
       
    81         }
       
    82     return ETrue;
       
    83     }
       
    84 
       
    85 }  // namespace
       
    86 
       
    87 
       
    88 // ================= MEMBER FUNCTIONS =======================
       
    89 
       
    90 // CPbkFetchDlg::TParams
       
    91 CPbkFetchDlg::TParams::TParams() :
       
    92     iFlags(FETCH_FOCUSED),
       
    93     iResId(R_PBK_SINGLE_ENTRY_FETCH_DLG),
       
    94     iContactView(NULL),
       
    95     iKeyCallback(NULL),
       
    96     iAcceptCallback(NULL),
       
    97     iFetchSelection(NULL),                    
       
    98     iCbaId(0),    
       
    99     iFocusedEntry(KNullContactId),
       
   100     iMarkedEntries(NULL)
       
   101     {
       
   102     }
       
   103 
       
   104 CPbkFetchDlg::TParams::operator TCleanupItem()
       
   105     {
       
   106     return TCleanupItem(Cleanup,this);
       
   107     }
       
   108 
       
   109 void CPbkFetchDlg::TParams::Cleanup(TAny* aPtr)
       
   110     {
       
   111     TParams* self = static_cast<TParams*>(aPtr);
       
   112     self->iFocusedEntry = KNullContactId;
       
   113     delete self->iMarkedEntries;
       
   114     self->iMarkedEntries = NULL;
       
   115     }
       
   116 
       
   117 
       
   118 // CPbkFetchDlg::TResData
       
   119 inline void CPbkFetchDlg::TResData::ReadFromResource(TResourceReader& aReader)
       
   120     {
       
   121     iDialogId   = aReader.ReadInt32();
       
   122     iCbaId      = aReader.ReadInt32();
       
   123     iEmptyCbaId = aReader.ReadInt32();
       
   124     iNaviPaneId = aReader.ReadInt32();
       
   125     }
       
   126 
       
   127 
       
   128 // CPbkFetchDlg
       
   129 inline CPbkFetchDlg::CPbkFetchDlg
       
   130         (TParams& aParams, 
       
   131         CPbkContactEngine& aEngine) :
       
   132     iParams(aParams),
       
   133     iEngine(aEngine),
       
   134     iPreviousStatusPaneLayout(KErrNotFound)
       
   135     {
       
   136     // CBase::operator new(TLeave) resets other member data
       
   137     }
       
   138 
       
   139 CPbkFetchDlg* CPbkFetchDlg::NewL
       
   140         (TParams& aParams, 
       
   141         CPbkContactEngine& aEngine)
       
   142     {
       
   143     // PreCond
       
   144     __ASSERT_ALWAYS(aParams.iContactView, Panic(EPanicNullContactView));
       
   145 
       
   146     CPbkFetchDlg* dlg = new(ELeave) CPbkFetchDlg(aParams, aEngine);
       
   147     CleanupStack::PushL(dlg);
       
   148     dlg->ConstructL();
       
   149     CleanupStack::Pop(dlg);
       
   150     return dlg;
       
   151     }
       
   152 
       
   153 CPbkFetchDlg::~CPbkFetchDlg()
       
   154     {
       
   155     delete iTabSkinDelay;
       
   156     if (iSelfPtr)
       
   157         {
       
   158         *iSelfPtr = NULL;
       
   159         }
       
   160     Release(iExtGlobals);
       
   161     delete iPages;
       
   162     delete iNaviDecorator;
       
   163     delete iContextPaneIcon;
       
   164     delete iSelectedIdSet;
       
   165     delete iDialogAccepter;
       
   166     }
       
   167 
       
   168 void CPbkFetchDlg::ResetWhenDestroyed(CPbkFetchDlg** aSelfPtr)
       
   169     {
       
   170     __ASSERT_DEBUG(!aSelfPtr || *aSelfPtr == this, 
       
   171             Panic(EPanicPreCond_ResetWhenDestroyed));
       
   172 
       
   173     iSelfPtr = aSelfPtr;
       
   174     }
       
   175 
       
   176 TInt CPbkFetchDlg::ExecuteLD()
       
   177     {
       
   178     TBool canceled = EFalse;
       
   179     iCanceledPtr = &canceled;
       
   180     iContextPaneIcon = CPbkContextPaneIcon::NewL(*iEikonEnv);
       
   181     
       
   182     // Status pane layout switching made.
       
   183     // Otherwise status pane layout problems could occur 
       
   184     // e.g. when no contacts in fetch dialog.
       
   185     // Calling app has to restore the layout if different.
       
   186     CEikStatusPane* statusPane = iAvkonAppUi->StatusPane();
       
   187     TInt statusPaneLayout = KErrNotFound;
       
   188     if (statusPane)
       
   189         {
       
   190         statusPaneLayout = statusPane->CurrentLayoutResId();
       
   191         statusPane->SwitchLayoutL(R_AVKON_STATUS_PANE_LAYOUT_USUAL);
       
   192         }
       
   193     TInt res = CEikDialog::ExecuteLD(iResData.iDialogId);
       
   194 
       
   195     if (statusPane && (statusPaneLayout != KErrNotFound))
       
   196         {
       
   197         statusPane->SwitchLayoutL(statusPaneLayout);
       
   198         }
       
   199 
       
   200     return canceled ? 0 : res;
       
   201     }
       
   202 
       
   203 void CPbkFetchDlg::ConstructL()
       
   204     {
       
   205     __ASSERT_DEBUG(iParams.iContactView, Panic(EPanicPreCond_ConstructL));
       
   206 
       
   207     // Read resources
       
   208     TResourceReader reader;
       
   209     iCoeEnv->CreateResourceReaderLC(reader, iParams.iResId);
       
   210     iResData.ReadFromResource(reader);
       
   211     __ASSERT_ALWAYS(iResData.iDialogId != 0, Panic(EPanicInvalidResourceData));
       
   212     __ASSERT_ALWAYS(iResData.iCbaId != 0, Panic(EPanicInvalidResourceData));
       
   213     __ASSERT_ALWAYS(iResData.iEmptyCbaId != 0, Panic(EPanicInvalidResourceData));
       
   214     CleanupStack::PopAndDestroy();  // reader
       
   215 
       
   216     iSelectedIdSet = CPbkContactIdSet::NewL();
       
   217 
       
   218     // Keep a handle to the UI extension factory in this dialog to prevent 
       
   219     // multiple inits of the factory by this dialog's subobjects
       
   220     iExtGlobals = CPbkExtGlobals::InstanceL();
       
   221     
       
   222     TCallBack accepter( TryAcceptSelectionL, this );
       
   223     iDialogAccepter =
       
   224         new (ELeave) CAsyncCallBack( accepter, CActive::EPriorityStandard );
       
   225 
       
   226     CAknDialog::ConstructL(R_PBK_EMPTY_MENU_PANE);
       
   227 
       
   228     // dialog tabs appears status pane stack only after dialog is fully
       
   229     // constructed, so we need to delay tab skinning. Even in PostLayoutDyninit
       
   230     // tab group is wrong
       
   231     iTabSkinDelay = CIdle::NewL( CActive::EPriorityLow );
       
   232     iTabSkinDelay->Start( TCallBack( DelaySkinning, this ));
       
   233     }
       
   234 
       
   235 SEikControlInfo CPbkFetchDlg::CreateCustomControlL(TInt aControlType)
       
   236     {
       
   237     SEikControlInfo ctrl;
       
   238     ctrl.iControl = NULL;
       
   239     ctrl.iTrailerTextId = 0;
       
   240     ctrl.iFlags = 0;
       
   241     ctrl.iControl = PbkFetchDlgPageFactory::CreateCustomControlL(aControlType);
       
   242     return ctrl;
       
   243     }
       
   244 
       
   245 void CPbkFetchDlg::PreLayoutDynInitL()
       
   246     {
       
   247     // PreCond
       
   248     __ASSERT_DEBUG(iParams.iContactView, Panic(EPanicPreCond_PreLayoutDynInitL));
       
   249 
       
   250     CEikDialog::PreLayoutDynInitL();
       
   251 
       
   252     SetupStatusPaneL();
       
   253 
       
   254     iPages = PbkFetchDlgPageFactory::CreatePagesL(*this);
       
   255     if (iParams.iFetchSelection)
       
   256 	    {
       
   257 	    iPages->DlgPageWithId(ECtrlFetchNamesList)->
       
   258 	    	SetMPbkFetchDlgSelection(iParams.iFetchSelection);
       
   259 	    iPages->DlgPageWithId(ECtrlFetchGroupsList)->
       
   260 	    	SetMPbkFetchDlgSelection(iParams.iFetchSelection);
       
   261 	    }
       
   262     iCurrentPage = iPages->DlgPageWithId(ECtrlFetchNamesList);
       
   263     iCurrentPage->ActivateFetchDlgPageL();
       
   264 
       
   265     if ( AknLayoutUtils::MSKEnabled() )
       
   266         {
       
   267         // Set this as MSK observer to be able to receive MSK events.       
       
   268         CEikButtonGroupContainer& bgc = ButtonGroupContainer();            
       
   269         CEikCba* cba;
       
   270         cba = ( static_cast<CEikCba*>( bgc.ButtonGroup() ) ); // downcast from MEikButtonGroup
       
   271         cba->SetMSKCommandObserver(this);    
       
   272         }
       
   273         
       
   274     if ( AknLayoutUtils::PenEnabled() )
       
   275         {
       
   276         // Add observer for contact item double tap events
       
   277         const TInt count = iPages->DlgPageCount();
       
   278         for ( TInt i = 0; i < count; ++i )
       
   279             {
       
   280             iPages->DlgPageAt(i).Control().AddObserverL(*this);
       
   281             }
       
   282         }
       
   283     
       
   284     __ASSERT_DEBUG(iPages && iCurrentPage, Panic(EPanicPostCond_PreLayoutDynInitL));
       
   285     }
       
   286     
       
   287 void CPbkFetchDlg::ProcessCommandL(TInt aCommandId)
       
   288     {
       
   289     // This method gets called if CPbkFetckDlg has been set as
       
   290     // MSK observer. 
       
   291     
       
   292     // close the menu, otherwise problems with FEP
       
   293     HideMenu();
       
   294     
       
   295     if (!iCurrentPage->IsFetchDlgPageEmpty() &&
       
   296         iCurrentPage->ProcessSoftkeyMarkCommandL(aCommandId))
       
   297         {        
       
   298         if ( aCommandId == EAknSoftkeyMark )
       
   299             {
       
   300             iCurrentPage->Control().MarkItemL(iCurrentPage->FocusedContactIdL(), ETrue);
       
   301             }
       
   302         else if ( aCommandId == EAknSoftkeyUnmark )
       
   303             {
       
   304             iCurrentPage->Control().MarkItemL(iCurrentPage->FocusedContactIdL(), EFalse);
       
   305             }
       
   306         // update the label of MSK
       
   307         UpdateMSKL( iCurrentPage->Control().CurrentItemIndex() );
       
   308         }
       
   309     }
       
   310 
       
   311 TBool CPbkFetchDlg::OkToExitL(TInt aButtonId)
       
   312     {    
       
   313     // normally OkToExitL -method is called when we are really
       
   314     // exiting this dialog, but since the MSK came to the 
       
   315     // picture, all the MSK related softkeys are handled here.
       
   316     // so, we're not going to exit the dialog, just ignore all
       
   317     // softkey events related to MSK, those are handled in ProcessCommandL.
       
   318     if ( aButtonId == EAknSoftkeyMark ||
       
   319          aButtonId == EAknSoftkeyUnmark ||
       
   320          aButtonId == EAknSoftkeyEmpty )
       
   321         {                    
       
   322         return EFalse;        
       
   323         }       
       
   324     
       
   325     // Reset return values
       
   326     TBool result = ETrue;
       
   327     iParams.iFocusedEntry = KNullContactId;
       
   328     iParams.iMarkedEntries = NULL;
       
   329     
       
   330 	
       
   331 
       
   332     if (iParams.iFlags & FETCH_FOCUSED)
       
   333         {
       
   334         const TContactItemId focusId = 
       
   335             iPages->DlgPageWithId(ECtrlFetchNamesList)->FocusedContactIdL();
       
   336         if (focusId != KNullContactId)
       
   337             {
       
   338             iParams.iFocusedEntry = focusId;
       
   339             }
       
   340         else
       
   341             {
       
   342             if (!(iParams.iFlags & FETCH_MARKED))
       
   343                 {
       
   344                 // Don't close the dialog if there is no focus, probably
       
   345                 // the focus is missing because find text has filtered
       
   346                 // the list box empty.
       
   347                 result = EFalse;
       
   348                 }
       
   349             }
       
   350         }
       
   351 
       
   352     if (iParams.iFlags & FETCH_MARKED)
       
   353         {
       
   354         // Copy marked entries set to iParams.iMarkedEntries in the same order
       
   355         // they appear in iParams.iContactView        
       
   356         TPbkContactViewIterator iter(*iParams.iContactView);
       
   357         TContactItemId contactId;
       
   358 
       
   359         delete iParams.iMarkedEntries;
       
   360         iParams.iMarkedEntries = NULL;
       
   361         iParams.iMarkedEntries = CContactIdArray::NewLC();
       
   362         
       
   363         while ((contactId = iter.NextL()) != KNullContactId)
       
   364             {
       
   365             if (iSelectedIdSet->Find(contactId))
       
   366                 {
       
   367                 iParams.iMarkedEntries->AddL(contactId);
       
   368                 }
       
   369             }
       
   370         
       
   371         // Can't destroy the iMarkedEntries, these entries need to return to client as
       
   372         // the fetch datum.
       
   373         CleanupStack::Pop(iParams.iMarkedEntries);
       
   374         }
       
   375 
       
   376     // Run accept callback if specified and this dialog is being accepted
       
   377     if (result && iParams.iAcceptCallback)
       
   378         {
       
   379         MPbkFetchDlgAccept::TPbkFetchAccepted res = 
       
   380             iParams.iAcceptCallback->PbkFetchAcceptedL(iParams.iFocusedEntry, iParams.iMarkedEntries);
       
   381         switch (res)
       
   382             {
       
   383             case MPbkFetchDlgAccept::KFetchYes:
       
   384                 {
       
   385                 result = ETrue;
       
   386                 break;
       
   387                 }
       
   388             case MPbkFetchDlgAccept::KFetchCanceled:
       
   389                 {
       
   390                 iParams.iFocusedEntry = KNullContactId;
       
   391                 delete iParams.iMarkedEntries;
       
   392                 iParams.iMarkedEntries = NULL;
       
   393                 result = ETrue;
       
   394                 if (iCanceledPtr) 
       
   395                     {
       
   396                     *iCanceledPtr = ETrue;
       
   397                     }
       
   398                 break;
       
   399                 }
       
   400             case MPbkFetchDlgAccept::KFetchNo:
       
   401                 {
       
   402                 result = EFalse;
       
   403                 break;
       
   404                 }
       
   405             }
       
   406         }
       
   407 
       
   408     switch (aButtonId)
       
   409         {
       
   410         case EAknSoftkeyBack:       // FALLTHROUGH
       
   411         case EAknSoftkeyCancel:     // FALLTHROUGH
       
   412         case EAknSoftkeyClose:      // FALLTHROUGH
       
   413         case EAknSoftkeyNo:         // FALLTHROUGH
       
   414         case EAknSoftkeyExit:
       
   415             {
       
   416             if (iCanceledPtr) 
       
   417                 {
       
   418                 *iCanceledPtr = ETrue;
       
   419                 }
       
   420             break;
       
   421             }
       
   422 
       
   423         case EAknSoftkeyOk:
       
   424             {
       
   425             // Markable list -dialog shouldn't be closed if there are no marked
       
   426             // items in current page. This happens if a selection accepter
       
   427             // didn't accept the selection of focused item when EAknSoftkeyOk
       
   428             // was pressed. If we close the dialog the User might think that
       
   429             // selection succeeded. Now we stay in the dialog and give the
       
   430             // selection accepter a change to show some error message about
       
   431             // failed selection
       
   432             if ( result && (iParams.iFlags & FETCH_MARKED) && 
       
   433                 iCurrentPage && !iCurrentPage->ItemsMarked())
       
   434                 {
       
   435                 result = EFalse;
       
   436                 }
       
   437             break;
       
   438             } 
       
   439         }
       
   440 
       
   441     return result;
       
   442     }
       
   443 
       
   444 void CPbkFetchDlg::PageChangedL(TInt aPageId)
       
   445     {
       
   446     MPbkFetchDlgPage* newPage = iPages->DlgPageWithId(aPageId);
       
   447     if (newPage)
       
   448         {
       
   449         newPage->ActivateFetchDlgPageL();
       
   450         if (iCurrentPage)
       
   451             {
       
   452             iCurrentPage->DeactivateFetchDlgPage();
       
   453             }
       
   454         iCurrentPage = newPage;
       
   455         	    
       
   456 	    if ( iParams.iFlags & FETCH_FOCUSED )
       
   457 	        {
       
   458 	        // this is for single fetch	                  	    
       
   459 	        UpdateCbasL();	        
       
   460 	        }
       
   461 	    else
       
   462 	        {	        
       
   463             // for multiple fetch and MSK
       
   464             // first update the CBA set
       
   465             UpdateCbasL();
       
   466 	        TInt index = iCurrentPage->Control().CurrentItemIndex();
       
   467 	        if ( index != KErrNotFound && AknLayoutUtils::MSKEnabled())
       
   468                 {	            
       
   469 	            // if MSK enable, update it.
       
   470 	            UpdateMSKL(index);
       
   471 	            }
       
   472             
       
   473             }
       
   474         }
       
   475     }
       
   476     
       
   477 void CPbkFetchDlg::UpdateMSKL( TInt aIndex )
       
   478     {    
       
   479 	// do not update MSK for single fetch dialog
       
   480     if ( !(iParams.iFlags & FETCH_FOCUSED) )                
       
   481         {
       
   482         
       
   483         TBool hasSelected (iCurrentPage->Control().ItemMarked(aIndex));
       
   484         
       
   485         if ( hasSelected )
       
   486             {
       
   487             CEikButtonGroupContainer& cba = ButtonGroupContainer();
       
   488             cba.SetCommandL(3,R_AVKON_SOFTKEY_UNMARK);
       
   489             cba.DrawDeferred();
       
   490             }        
       
   491         else
       
   492             {
       
   493             CEikButtonGroupContainer& cba = ButtonGroupContainer();            
       
   494             cba.SetCommandL(3,R_AVKON_SOFTKEY_MARK);
       
   495             cba.DrawDeferred();        
       
   496             }
       
   497         }   
       
   498     }
       
   499 
       
   500 void CPbkFetchDlg::HandleContactViewListControlEventL(
       
   501         CPbkContactViewListControl& /*aControl*/,
       
   502         const TPbkContactViewListControlEvent& aEvent)
       
   503     {
       
   504     switch ( aEvent.iEventType )
       
   505         {
       
   506         case TPbkContactViewListControlEvent::EContactDoubleTapped:
       
   507             {
       
   508             if ( iParams.iFlags & FETCH_FOCUSED )
       
   509                 {
       
   510                 // Single item/entry fetch, try to accept the dialog
       
   511                 iDialogAccepter->Cancel();
       
   512                 iDialogAccepter->CallBack();
       
   513                 break;
       
   514                 }
       
   515             // else fallthrough
       
   516             }
       
   517         case TPbkContactViewListControlEvent::EContactTapped:   // fallthrough
       
   518         case TPbkContactViewListControlEvent::EContactSelected: // fallthrough
       
   519         case TPbkContactViewListControlEvent::EContactUnselected:
       
   520             {
       
   521             UpdateMSKL( iCurrentPage->Control().CurrentItemIndex() );
       
   522             break;
       
   523             }
       
   524         default:;
       
   525         }
       
   526     
       
   527     if ( aEvent.iEventType ==
       
   528             TPbkContactViewListControlEvent::EContactDoubleTapped ||
       
   529          aEvent.iEventType ==
       
   530             TPbkContactViewListControlEvent::EContactTapped )
       
   531         {
       
   532         if ( iCurrentPage->Control().ItemMarked(
       
   533                 iCurrentPage->Control().CurrentItemIndex() ) )
       
   534             {
       
   535             iCurrentPage->ProcessSoftkeyMarkCommandL( EAknSoftkeyMark );
       
   536             }
       
   537         else
       
   538             {
       
   539             iCurrentPage->ProcessSoftkeyMarkCommandL( EAknSoftkeyUnmark );
       
   540             }
       
   541         }
       
   542     }        
       
   543 
       
   544 TInt CPbkFetchDlg::TryAcceptSelectionL( TAny* aSelf )
       
   545     {
       
   546     static_cast<CPbkFetchDlg*>( aSelf )->TryExitL( EEikBidOk );
       
   547     return KErrNone;
       
   548     }
       
   549 
       
   550 TKeyResponse CPbkFetchDlg::OfferKeyEventL
       
   551         (const TKeyEvent& aKeyEvent,
       
   552         TEventCode aType)
       
   553     {
       
   554     // if the MSK is enabled, multiple dialog needs to know
       
   555     // which contact is going to be focused and set the 
       
   556     // label of MSK referring is the certain contact marked
       
   557     // or not, or has limited multiple fetch count already
       
   558     // achieved.
       
   559     if ( AknLayoutUtils::MSKEnabled() )
       
   560         {
       
   561         if ( !iCurrentPage->IsFetchDlgPageEmpty() )
       
   562             {
       
   563             if ( ( aKeyEvent.iCode == EKeyUpArrow || aKeyEvent.iCode == EKeyDownArrow ) &&
       
   564                  aType == EEventKey )
       
   565                 {        
       
   566                 TInt index = iCurrentPage->Control().CurrentItemIndex();                            
       
   567                 
       
   568                 if ( aKeyEvent.iCode == EKeyUpArrow )
       
   569                     {
       
   570                     index--;
       
   571                     if (index < 0)
       
   572                         {
       
   573                         // set the index to the last in the list
       
   574                         index = iCurrentPage->Control().ItemCount() - 1;                    
       
   575                         }     
       
   576                     }
       
   577                 if ( aKeyEvent.iCode == EKeyDownArrow )
       
   578                     {
       
   579                     index++;
       
   580                     if (index >= iCurrentPage->Control().ItemCount() )
       
   581                         {
       
   582                         // set the index to first in the list
       
   583                         index = 0;
       
   584                         }     
       
   585                     }                                       
       
   586                 UpdateCbasL();       
       
   587                 UpdateMSKL( index );
       
   588                 }
       
   589             }
       
   590         }
       
   591 
       
   592     if (iParams.iKeyCallback)
       
   593         {
       
   594         MPbkFetchKeyCallback::TResult result = 
       
   595             iParams.iKeyCallback->PbkFetchKeyCallbackL(aKeyEvent, aType);
       
   596         
       
   597         switch (result)
       
   598             {
       
   599             case MPbkFetchKeyCallback::EKeyWasNotConsumed:
       
   600                 {
       
   601                 break;
       
   602                 }
       
   603             case MPbkFetchKeyCallback::EKeyWasConsumed:
       
   604                 {
       
   605                 return EKeyWasConsumed;
       
   606                 }
       
   607             case MPbkFetchKeyCallback::EAccept:
       
   608                 {
       
   609                 TryExitL(EEikBidOk);
       
   610                 return EKeyWasConsumed;
       
   611                 }
       
   612             case MPbkFetchKeyCallback::ECancel:
       
   613                 {
       
   614                 TryExitL(EEikBidCancel);
       
   615                 return EKeyWasConsumed;
       
   616                 }
       
   617 			default:
       
   618 				{
       
   619 				break;
       
   620 				}
       
   621             }
       
   622         }
       
   623     return CEikDialog::OfferKeyEventL(aKeyEvent, aType);
       
   624     }
       
   625 
       
   626 CCoeControl* CPbkFetchDlg::FetchDlgControl(TInt aCtrlId) const
       
   627     {
       
   628     return ControlOrNull(aCtrlId);
       
   629     }
       
   630 
       
   631 CContactViewBase& CPbkFetchDlg::FetchDlgNamesView() const
       
   632     {
       
   633     return *iParams.iContactView;
       
   634     }
       
   635 
       
   636 CPbkContactIdSet& CPbkFetchDlg::FetchDlgSelection()
       
   637     {
       
   638     return *iSelectedIdSet;
       
   639     }
       
   640 
       
   641 void CPbkFetchDlg::FetchDlgHandleError(TInt aError)
       
   642     {
       
   643     iEikonEnv->HandleError(aError);
       
   644     }
       
   645 
       
   646 TRect CPbkFetchDlg::FetchDlgClientRect() const
       
   647     {
       
   648     TRect appRect = iAvkonAppUi->ApplicationRect();
       
   649     TAknLayoutRect mainPane;
       
   650     mainPane.LayoutRect(appRect, AKN_LAYOUT_WINDOW_main_pane(appRect,0,1,1));
       
   651     return mainPane.Rect();    
       
   652     }
       
   653 
       
   654 CPbkContactEngine& CPbkFetchDlg::PbkEngine()
       
   655     {
       
   656     return iEngine;
       
   657     }
       
   658 
       
   659 void CPbkFetchDlg::FetchDlgPageChangedL(MPbkFetchDlgPage& /*aPage*/)
       
   660     {
       
   661     if ( iParams.iFlags & FETCH_FOCUSED )
       
   662         {
       
   663         UpdateCbasL();	        
       
   664         }
       
   665     else
       
   666         {
       
   667         UpdateCbasL();
       
   668         if ( AknLayoutUtils::MSKEnabled() )
       
   669             {
       
   670             // update also the MSK
       
   671             TInt index = iCurrentPage->Control().CurrentItemIndex();
       
   672 	        if ( index != KErrNotFound )
       
   673 	            {                
       
   674                 UpdateMSKL(index);
       
   675                 }
       
   676             }        
       
   677         }
       
   678     }
       
   679 
       
   680 void CPbkFetchDlg::SetCbaCommandSetL(TInt aResourceId)
       
   681     {
       
   682     if (aResourceId != iCbaCommandSet)
       
   683         {
       
   684         CEikButtonGroupContainer& cba = ButtonGroupContainer();
       
   685         cba.SetCommandSetL(aResourceId);
       
   686         iCbaCommandSet = aResourceId;
       
   687         cba.DrawDeferred();
       
   688         }
       
   689     }
       
   690 
       
   691 void CPbkFetchDlg::SetupStatusPaneL()
       
   692     {
       
   693     delete iNaviDecorator;
       
   694     iNaviDecorator = NULL;
       
   695     
       
   696     CEikStatusPane* statusPane = iAvkonAppUi->StatusPane();
       
   697     if (statusPane)
       
   698         {
       
   699         // Setup navi pane if defined in resources
       
   700         if (iResData.iNaviPaneId && 
       
   701             statusPane->PaneCapabilities
       
   702             (TUid::Uid(EEikStatusPaneUidNavi)).IsPresent())
       
   703             {
       
   704             CAknNavigationControlContainer* naviPane = 
       
   705                 static_cast<CAknNavigationControlContainer*> 
       
   706                 (statusPane->ControlL(TUid::Uid(EEikStatusPaneUidNavi)));
       
   707             TResourceReader reader;
       
   708             iCoeEnv->CreateResourceReaderLC(reader, iResData.iNaviPaneId);
       
   709             iNaviDecorator =
       
   710                 naviPane->ConstructNavigationDecoratorFromResourceL(reader);
       
   711             naviPane->PushL(*iNaviDecorator);
       
   712             CleanupStack::PopAndDestroy();  // reader
       
   713             }
       
   714         }
       
   715     }
       
   716 
       
   717 void CPbkFetchDlg::HandleResourceChange(TInt aType)
       
   718     {    
       
   719     CEikStatusPane* statusPane = iAvkonAppUi->StatusPane();
       
   720     if (aType == KEikDynamicLayoutVariantSwitch)
       
   721         {
       
   722         // Layout dialog itself
       
   723         SetRect( iAvkonAppUi->ClientRect() );
       
   724         // Layout dialog page controls
       
   725         const TInt count(iPages->DlgPageCount());
       
   726         for (TInt i = 0; i < count; ++i)
       
   727             {
       
   728             iPages->DlgPageAt(i).LayoutContents();
       
   729             }
       
   730         // If the fetch dialog has been launched in landscape mode, 
       
   731         // and then later changed to the portrait mode, the icon has to 
       
   732         // be set again, otherwise there will be shown the icon of
       
   733         // the "parent" -application.
       
   734         delete iContextPaneIcon;            
       
   735         iContextPaneIcon = NULL;        
       
   736         TRAP_IGNORE(iContextPaneIcon = CPbkContextPaneIcon::NewL(*iEikonEnv));
       
   737 
       
   738         if (statusPane)
       
   739             {
       
   740             TRAP_IGNORE(statusPane->SwitchLayoutL(
       
   741                 R_AVKON_STATUS_PANE_LAYOUT_USUAL));
       
   742             }
       
   743         }
       
   744     else if (aType == KAknsMessageSkinChange)
       
   745         {
       
   746         // Just visual effect, no need to handle error
       
   747         TRAP_IGNORE( SkinTabsL() );
       
   748         }
       
   749         
       
   750     if (statusPane)
       
   751 		{
       
   752 		statusPane->HandleResourceChange(aType);
       
   753 		}    
       
   754 		
       
   755 	CAknDialog::HandleResourceChange(aType);
       
   756     }
       
   757     
       
   758 // --------------------------------------------------------------------------
       
   759 // CPbkFetchDlg::LineChangedL
       
   760 // --------------------------------------------------------------------------
       
   761 //
       
   762 void CPbkFetchDlg::LineChangedL(TInt /*aControlId*/)
       
   763     {
       
   764     // never gets called
       
   765     }
       
   766 
       
   767 // --------------------------------------------------------------------------
       
   768 // CPbkFetchDlg::UpdateCbasL
       
   769 // --------------------------------------------------------------------------
       
   770 //
       
   771 void CPbkFetchDlg::UpdateCbasL()
       
   772     {
       
   773     if ( AllPagesReady(*iPages) && 
       
   774     		iCurrentPage && !iCurrentPage->IsFetchDlgPageEmpty() )
       
   775     	{       		        	
       
   776     	// Use user defined cba resources if exist
       
   777 	    if (iParams.iCbaId)
       
   778 	        {
       
   779 	        SetCbaCommandSetL(iParams.iCbaId);
       
   780 	        }    	        
       
   781 	    else if ( iResData.iCbaId )
       
   782 	        {
       
   783 	        SetCbaCommandSetL( iResData.iCbaId );
       
   784 	        }
       
   785 	    
       
   786 	    // Resources for single fetch
       
   787 	    else if ( iParams.iFlags & FETCH_FOCUSED )
       
   788 	    	{
       
   789 	    	SetCbaCommandSetL( R_PBK_SOFTKEYS_OK_BACK_OK );
       
   790 	    	} 
       
   791 	    // Resources for multiple fetch
       
   792 	    else
       
   793 	        {
       
   794 	        SetCbaCommandSetL(R_PBK_SOFTKEYS_OK_BACK_MARK);	  
       
   795 	        }
       
   796     	}
       
   797     else
       
   798     	{    	
       
   799     	SetCbaCommandSetL(iResData.iEmptyCbaId);
       
   800     	}
       
   801     }    
       
   802 
       
   803 // --------------------------------------------------------------------------
       
   804 // CPbkFetchDlg::SkinTabsL
       
   805 // --------------------------------------------------------------------------
       
   806 //
       
   807 void CPbkFetchDlg::SkinTabsL()
       
   808     {
       
   809     PBK_DEBUG_PRINT(PBK_DEBUG_STRING("SkinTabsL start"));
       
   810     CEikStatusPane* statusPane = iAvkonAppUi->StatusPane();
       
   811 
       
   812     if (statusPane && statusPane->PaneCapabilities
       
   813 		(TUid::Uid(EEikStatusPaneUidNavi)).IsPresent())
       
   814         {
       
   815         CAknNavigationControlContainer* naviPane =
       
   816 			static_cast<CAknNavigationControlContainer*>
       
   817 			(statusPane->ControlL(TUid::Uid(EEikStatusPaneUidNavi)));
       
   818         CAknNavigationDecorator* naviDeco = naviPane->Top();
       
   819 
       
   820         if ( naviDeco )
       
   821             {
       
   822             PBK_DEBUG_PRINT(PBK_DEBUG_STRING("SkinTabsL naviDeco"));
       
   823             if ( naviDeco->ControlType() == CAknNavigationDecorator::ETabGroup )
       
   824                 {
       
   825                 PBK_DEBUG_PRINT(PBK_DEBUG_STRING("SkinTabsL ETabGroup"));
       
   826                 CPbkIconInfoContainer* iconInfoContainer = 
       
   827                     CPbkIconInfoContainer::NewL( R_PBK_FETCH_TAB_ICON_INFO_ARRAY );
       
   828                 CleanupStack::PushL(iconInfoContainer);
       
   829 
       
   830                 MAknsSkinInstance* skin = AknsUtils::SkinInstance();
       
   831                 CAknTabGroup* tabGroup = 
       
   832                     static_cast<CAknTabGroup*>(naviDeco->DecoratedControl());
       
   833                                 
       
   834                 const TInt count = tabGroup->TabCount();
       
   835                 PBK_DEBUG_PRINT(PBK_DEBUG_STRING("SkinTabsL TabCount = %d"), count);
       
   836                 for (TInt i = 0; i < count; ++i)
       
   837                     {
       
   838                     TInt tabId = tabGroup->TabIdFromIndex(i);
       
   839                     // tabId is used as icon id
       
   840                     const TPbkIconInfo* iconInfo = 
       
   841                         iconInfoContainer->Find(TPbkIconId(tabId));
       
   842                     if (iconInfo)
       
   843                         {
       
   844                         CFbsBitmap* bitmap = NULL;
       
   845                         CFbsBitmap* mask = NULL;
       
   846                         PbkIconUtils::CreateIconLC(
       
   847                             skin, bitmap, mask, *iconInfo);
       
   848 
       
   849                         PBK_DEBUG_PRINT(PBK_DEBUG_STRING("SkinTabsL ReplaceTabL %d"), tabId);
       
   850                         tabGroup->ReplaceTabL(tabId, bitmap, mask);
       
   851 
       
   852                         CleanupStack::Pop(2); // mask, bitmap
       
   853                         }
       
   854                     }
       
   855                 CleanupStack::PopAndDestroy( iconInfoContainer );
       
   856                 }
       
   857             }
       
   858         }
       
   859     PBK_DEBUG_PRINT(PBK_DEBUG_STRING("SkinTabsL end"));
       
   860     }
       
   861 
       
   862 // --------------------------------------------------------------------------
       
   863 // CPbkFetchDlg::SkinTabsL
       
   864 // --------------------------------------------------------------------------
       
   865 //
       
   866 TInt CPbkFetchDlg::DelaySkinning( TAny* aFetchDlg )
       
   867     {
       
   868     // Tab skinning is just visual effect, no need to handle error
       
   869     TRAP_IGNORE( ( (CPbkFetchDlg*)aFetchDlg)->SkinTabsL() );
       
   870     return EFalse; // one time only
       
   871     }
       
   872 
       
   873 //  End of File