emailcontacts/remotecontactlookup/engine/src/cpbkxrclsearchresultdlg.cpp
branchRCL_3
changeset 12 4ce476e64c59
parent 11 0396474f30f5
child 13 8592a65ad3fb
equal deleted inserted replaced
11:0396474f30f5 12:4ce476e64c59
     1 /*
       
     2 * Copyright (c) 2008 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:  Definition of the class CPbkxRclSearchResultDlg.
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #include "emailtrace.h"
       
    20 #include <pbkxrclengine.rsg>
       
    21 #include <eikmover.h>
       
    22 #include <coemain.h>
       
    23 #include <aknnavi.h>
       
    24 #include <aknnavide.h>
       
    25 #include <aknappui.h>
       
    26 #include <AknIconUtils.h>
       
    27 #include <cntitem.h>
       
    28 #include <badesca.h>
       
    29 #include <StringLoader.h>
       
    30 #include <CPbkContactEngine.h>
       
    31 #include <CPbkContactItem.h>
       
    32 #include <gulicon.h>
       
    33 #include <avkon.mbg>
       
    34 #include <pbkxrclengine.mbg>
       
    35 //<cmail>
       
    36 #include "cfsccontactactionmenu.h"  
       
    37 #include "mfsccontactactionmenumodel.h"
       
    38 #include "mfsccontactaction.h"
       
    39 #include "cfsccontactactionmenuitem.h"
       
    40 #include "fsccontactactionservicedefines.h"
       
    41 #include "fsccontactactionmenudefines.h"
       
    42 //</cmail>
       
    43 
       
    44 #include <data_caging_path_literals.hrh>
       
    45 #include <AknsUtils.h>
       
    46 #include <eikclb.h>
       
    47 #include <eikclbd.h>
       
    48 #include <eiklbo.h>                 // MEikListBoxObserver
       
    49 
       
    50 #include <csxhelp/cmail.hlp.hrh>
       
    51 
       
    52 #include "cpbkxrclsearchresultdlg.h"
       
    53 #include "pbkxremotecontactlookuppanic.h"
       
    54 #include "engine.hrh"
       
    55 #include "pbkxrclutils.h"
       
    56 #include "cpbkxrclvcardsender.h"
       
    57 #include "cpbkxrclactionservicewrapper.h"
       
    58 
       
    59 // list box field formats
       
    60 _LIT( KFieldFormat, "\t%S %S" );
       
    61 _LIT( KFieldFormatWithIcon, "\t%S %S\t%d" );
       
    62 
       
    63 _LIT( KFieldFormatDispName, "\t%S" );
       
    64 _LIT( KFieldFormatDispNameWithIcon, "\t%S\t%d" );
       
    65 
       
    66 // Constant to measure when user is scrolling.
       
    67 const TInt KKeyScrolling = 1;
       
    68 // <cmail> S60 UID update
       
    69 const TInt KPbkxRemoteContactLookupServiceImplImpUid = 0x2001FE0D;
       
    70 // </cmail> S60 UID update
       
    71 
       
    72 
       
    73 // ======== MEMBER FUNCTIONS ========
       
    74 
       
    75 // ---------------------------------------------------------------------------
       
    76 // CPbkxRclSearchResultDlg::NewL
       
    77 // ---------------------------------------------------------------------------
       
    78 //
       
    79 CPbkxRclSearchResultDlg* CPbkxRclSearchResultDlg::NewL(
       
    80     TInt& aIndex,
       
    81     CDesCArray* aArray,
       
    82     MEikCommandObserver* aCommand,
       
    83     RPointerArray<CContactCard>& aContactItems,
       
    84     CPbkContactEngine& aContactEngine,
       
    85     CPbkxRclActionServiceWrapper& aActionService,
       
    86     TBool aContactSelectorEnabled )
       
    87     {
       
    88     FUNC_LOG;
       
    89     CPbkxRclSearchResultDlg* dialog = new ( ELeave ) CPbkxRclSearchResultDlg(
       
    90         aIndex, 
       
    91         aArray,
       
    92         aCommand,
       
    93         aContactItems,
       
    94         aContactEngine,
       
    95         aActionService,
       
    96         aContactSelectorEnabled );
       
    97 
       
    98     CleanupStack::PushL( dialog );
       
    99     dialog->ConstructL();
       
   100     CleanupStack::Pop( dialog );
       
   101     return dialog;
       
   102     }
       
   103 
       
   104 // ---------------------------------------------------------------------------
       
   105 // CPbkxRclSearchResultDlg::CPbkxRclSearchResultDlg
       
   106 // ---------------------------------------------------------------------------
       
   107 //
       
   108 CPbkxRclSearchResultDlg::CPbkxRclSearchResultDlg(
       
   109     TInt& aIndex,
       
   110     CDesCArray* aArray,
       
   111     MEikCommandObserver* aCommand,
       
   112     RPointerArray<CContactCard>& aContactItems,
       
   113     CPbkContactEngine& aContactEngine,
       
   114     CPbkxRclActionServiceWrapper& aActionService,
       
   115     TBool aContactSelectorEnabled ) :
       
   116     CPbkxRclBaseDlg( aIndex, aArray, aCommand, ETrue ), 
       
   117     iContactEngine( aContactEngine ),
       
   118     iContactActionService( aActionService ),
       
   119     iItems( aArray ), iContactItems( aContactItems ), 
       
   120     iContactSelectorEnabled( aContactSelectorEnabled ), 
       
   121     iSelectedItemIndex( aIndex ), 
       
   122     iIsInfoDlgVisible( EFalse )
       
   123     {
       
   124     FUNC_LOG;
       
   125     }
       
   126 
       
   127 // ---------------------------------------------------------------------------
       
   128 // CPbkxRclSearchResultDlg::ConstructL
       
   129 // ---------------------------------------------------------------------------
       
   130 //
       
   131 void CPbkxRclSearchResultDlg::ConstructL()
       
   132     {
       
   133     FUNC_LOG;
       
   134     CPbkxRclBaseDlg::ConstructL( R_RCL_SEARCH_RESULT_DIALOG_MENU_BAR );
       
   135     LoadNaviTextL();
       
   136 
       
   137     // add foreground observer
       
   138     CCoeEnv::Static()->AddForegroundObserverL( *this );
       
   139     }
       
   140 
       
   141 // ---------------------------------------------------------------------------
       
   142 // CPbkxRclSearchResultDlg::~CPbkxRclSearchResultDlg
       
   143 // ---------------------------------------------------------------------------
       
   144 //
       
   145 CPbkxRclSearchResultDlg::~CPbkxRclSearchResultDlg()
       
   146     {
       
   147     FUNC_LOG;
       
   148     CCoeEnv::Static()->RemoveForegroundObserver( *this );
       
   149     ResetStatusPane();
       
   150     iNaviText.Close();
       
   151     delete iAddRecipientIcon;
       
   152 
       
   153     iContactActionService.CancelQuery();
       
   154     if ( iActionMenu )
       
   155     	{
       
   156      	delete iActionMenu;
       
   157     	iActionMenu = NULL;
       
   158     	}
       
   159     }
       
   160 
       
   161 // ---------------------------------------------------------------------------
       
   162 // CPbkxRclSearchResultDlg::ExecuteLD
       
   163 // ---------------------------------------------------------------------------
       
   164 //
       
   165 void CPbkxRclSearchResultDlg::ExecuteLD()
       
   166     {
       
   167     FUNC_LOG;
       
   168 
       
   169     PrepareLC( R_RCL_SEARCH_RESULT_DIALOG );
       
   170 
       
   171     UpdateGraphics();
       
   172     UpdateColors();
       
   173 
       
   174     HBufC* noItemText = StringLoader::LoadLC( R_QTN_RCL_NO_RESULTS );
       
   175     ListBox()->View()->SetListEmptyTextL( *noItemText );
       
   176     CleanupStack::PopAndDestroy( noItemText );
       
   177 
       
   178     CreateListBoxIconsL();
       
   179 
       
   180     InitializeActionMenuL();
       
   181 
       
   182     SetupStatusPaneL();
       
   183     CreateListBoxEntriesL();
       
   184     
       
   185     if ( iContactItems.Count() == 0 )
       
   186       {
       
   187       ConstructMenuBarL( R_RCL_OPTIONS_BACK_CONTEXTMENU );
       
   188       }
       
   189 
       
   190     CAknSelectionListDialog::RunLD();
       
   191     }
       
   192 
       
   193 // ---------------------------------------------------------------------------
       
   194 // CPbkxRclSearchResultDlg::CurrentItemIndex
       
   195 // ---------------------------------------------------------------------------
       
   196 //
       
   197 TInt CPbkxRclSearchResultDlg::CurrentItemIndex() const
       
   198     {
       
   199     FUNC_LOG;
       
   200     return ListBox()->CurrentItemIndex();
       
   201     }
       
   202 
       
   203 // ---------------------------------------------------------------------------
       
   204 // CPbkxRclSearchResultDlg::SetCurrentItemIndex
       
   205 // ---------------------------------------------------------------------------
       
   206 //
       
   207 void CPbkxRclSearchResultDlg::SetCurrentItemIndexL( TInt aIndex )
       
   208     {
       
   209     FUNC_LOG;
       
   210     if ( aIndex >= 0 && aIndex < iContactItems.Count() )
       
   211         {
       
   212         // update list box entrys first
       
   213         TInt oldIndex = iSelectedItemIndex;
       
   214         
       
   215         ListBox()->SetCurrentItemIndex( aIndex );
       
   216         iSelectedItemIndex = aIndex;
       
   217         
       
   218         UpdateListBoxEntryL( iSelectedItemIndex );
       
   219         UpdateListBoxEntryL( oldIndex );
       
   220         }
       
   221     }
       
   222 
       
   223 // ---------------------------------------------------------------------------
       
   224 // CPbkxRclSearchResultDlg::Close
       
   225 // ---------------------------------------------------------------------------
       
   226 //
       
   227 void CPbkxRclSearchResultDlg::Close()
       
   228     {
       
   229     FUNC_LOG;
       
   230     // this will not leave, because TryExitL doesn't call leaving methods
       
   231     // when EAknSoftkeyCancel is used
       
   232     iExit = ETrue;
       
   233     TRAP_IGNORE( TryExitL( EAknSoftkeyCancel ) ); // <cmail>
       
   234     }
       
   235 
       
   236 // ---------------------------------------------------------------------------
       
   237 // CPbkxRclSearchResultDlg::UpdateDialogL
       
   238 // ---------------------------------------------------------------------------
       
   239 //
       
   240 void CPbkxRclSearchResultDlg::UpdateDialogL()
       
   241     {
       
   242     FUNC_LOG;
       
   243     LoadNaviTextL();
       
   244     CreateListBoxEntriesL();
       
   245     UpdateStatusPaneL();
       
   246     
       
   247     if ( iContactItems.Count() == 0 )
       
   248         {
       
   249         ConstructMenuBarL( R_RCL_OPTIONS_BACK_CONTEXTMENU );
       
   250         }
       
   251     else
       
   252         {
       
   253         ConstructMenuBarL( R_RCL_OPTIONS_BACK_OPEN );
       
   254         }
       
   255     }
       
   256 
       
   257 // ---------------------------------------------------------------------------
       
   258 // CPbkxRclSearchResultDlg::SendBusinessCardL
       
   259 // ---------------------------------------------------------------------------
       
   260 //
       
   261 void CPbkxRclSearchResultDlg::SendBusinessCardL()
       
   262     {
       
   263     FUNC_LOG;
       
   264     CPbkxRclvCardSender* sender = CPbkxRclvCardSender::NewLC( iContactEngine );
       
   265 
       
   266     TInt curIndex = CurrentItemIndex();
       
   267 
       
   268 
       
   269     CContactCard* current = iContactItems[curIndex];
       
   270    
       
   271     CPbkContactItem* contactItem = PbkxRclUtils::CreateContactItemL(
       
   272         current,
       
   273         iContactEngine );
       
   274     CleanupStack::PushL( contactItem );
       
   275     
       
   276     sender->SendvCardL( *contactItem, *(iContactActionService.ContactConverter()) );
       
   277 
       
   278     CleanupStack::PopAndDestroy( contactItem );
       
   279     CleanupStack::PopAndDestroy( sender );
       
   280     
       
   281     }
       
   282 
       
   283 // ---------------------------------------------------------------------------
       
   284 // CPbkxRclSearchResultDlg::DynInitMenuPaneL
       
   285 // ---------------------------------------------------------------------------
       
   286 //
       
   287 void CPbkxRclSearchResultDlg::DynInitMenuPaneL( 
       
   288     TInt aResourceId, 
       
   289     CEikMenuPane* aMenuPane )
       
   290     {
       
   291     FUNC_LOG;
       
   292     if ( aResourceId == R_RCL_SEARCH_RESULT_DIALOG_MENU_PANE )
       
   293         {
       
   294 
       
   295         if ( iContactItems.Count() == 0 )
       
   296             {
       
   297             // when there are 0 results, only new search option is available
       
   298             aMenuPane->SetItemDimmed( ERclCmdViewDetails, ETrue );
       
   299             aMenuPane->SetItemDimmed( ERclCmdAddAsRecipient, ETrue );
       
   300             aMenuPane->SetItemDimmed( ERclCmdSaveToContacts, ETrue );
       
   301             aMenuPane->SetItemDimmed( ERclCmdCall, ETrue );
       
   302             aMenuPane->SetItemDimmed( ERclCmdSend, ETrue );
       
   303             }
       
   304         else
       
   305             {
       
   306             if ( !iContactSelectorEnabled )
       
   307                 {
       
   308                 
       
   309                 aMenuPane->SetItemDimmed( ERclCmdAddAsRecipient, ETrue );
       
   310                 
       
   311                 aMenuPane->SetItemDimmed(
       
   312                     ERclCmdCall,
       
   313                     !CallActionsAvailable() );
       
   314                 
       
   315                 // send menu is always visible, since business card can 
       
   316                 // always be sent
       
   317                 }
       
   318             else
       
   319                 {
       
   320                 aMenuPane->SetItemDimmed( ERclCmdCall, ETrue );
       
   321                 aMenuPane->SetItemDimmed( ERclCmdSend, ETrue );
       
   322                 }
       
   323             
       
   324             aMenuPane->SetItemDimmed(
       
   325                 ERclCmdSaveToContacts,
       
   326                 !iContactActionService.IsActionEnabled( KFscAtManSaveAs ) );
       
   327             }
       
   328         }
       
   329     else if ( aResourceId == R_RCL_CALL_MENU_PANE )
       
   330         {
       
   331         
       
   332         aMenuPane->SetItemDimmed( 
       
   333             ERclCmdVoiceCall,
       
   334             !iContactActionService.IsActionEnabled( KFscAtComCallGSM ) );
       
   335 
       
   336         aMenuPane->SetItemDimmed(
       
   337             ERclCmdVideoCall,
       
   338             !iContactActionService.IsActionEnabled( KFscAtComCallVideo ) );
       
   339 
       
   340         aMenuPane->SetItemDimmed(
       
   341             ERclCmdVoip,
       
   342             !iContactActionService.IsActionEnabled( KFscAtComCallVoip ) );
       
   343         
       
   344         }
       
   345     else if ( aResourceId == R_RCL_SEND_MENU_PANE )
       
   346         {       
       
   347         aMenuPane->SetItemDimmed( 
       
   348             ERclCmdSendMsg, 
       
   349             !iContactActionService.IsActionEnabled( KFscAtComSendMsg ) );
       
   350        
       
   351         aMenuPane->SetItemDimmed( 
       
   352             ERclCmdSendEmail, 
       
   353             !iContactActionService.IsActionEnabled( KFscAtComSendEmail ) );
       
   354       
       
   355         aMenuPane->SetItemDimmed( 
       
   356             ERclCmdSendMeetingReq, 
       
   357             ETrue /*!iContactActionService.IsActionEnabled( KFscAtComSendCalReq )*/ );
       
   358             // "Send meeting request" option should not be available
       
   359                 
       
   360         aMenuPane->SetItemDimmed( 
       
   361             ERclCmdSendAudioMsg, 
       
   362             !iContactActionService.IsActionEnabled( KFscAtComSendAudio ) );
       
   363         
       
   364         }
       
   365     }
       
   366 
       
   367 // ---------------------------------------------------------------------------
       
   368 // CPbkxRclSearchResultDlg::GetHelpContext
       
   369 // ---------------------------------------------------------------------------
       
   370 //
       
   371 void CPbkxRclSearchResultDlg::GetHelpContext( TCoeHelpContext& aContext ) const
       
   372     {
       
   373     FUNC_LOG;
       
   374 
       
   375     if ( !iIsInfoDlgVisible )
       
   376         {
       
   377         aContext.iMajor = TUid::Uid( KPbkxRemoteContactLookupServiceImplImpUid );
       
   378         aContext.iContext = KRLOOK_HLP_RESULT_VIEW;
       
   379         }
       
   380     }
       
   381 
       
   382 // ---------------------------------------------------------------------------
       
   383 // CPbkxRclSearchResultDlg::HandleGainingForeground
       
   384 // ---------------------------------------------------------------------------
       
   385 //
       
   386 void CPbkxRclSearchResultDlg::HandleGainingForeground()
       
   387     {
       
   388     FUNC_LOG;
       
   389     }
       
   390 
       
   391 // ---------------------------------------------------------------------------
       
   392 // CPbkxRclSearchResultDlg::HandleLosingForeground
       
   393 // ---------------------------------------------------------------------------
       
   394 //
       
   395 void CPbkxRclSearchResultDlg::HandleLosingForeground()
       
   396     {
       
   397     FUNC_LOG;
       
   398     if ( ScrollingInProgress() )
       
   399         {
       
   400         // scrolling was in progress
       
   401         TRAP_IGNORE( ScrollingStoppedL() );
       
   402         iKeyDown = EFalse;
       
   403         iKeyCounter = 0;
       
   404         }
       
   405     }
       
   406 
       
   407 // ----------------------------------------------------------------------------
       
   408 // CPbkxRclSearchResultDlg::HandleListBoxEventL()
       
   409 // ----------------------------------------------------------------------------
       
   410 //
       
   411 void CPbkxRclSearchResultDlg::HandleListBoxEventL(
       
   412     CEikListBox* /* aListBox */,
       
   413     TListBoxEvent aEventType )
       
   414     {
       
   415     FUNC_LOG;
       
   416     switch ( aEventType )
       
   417         {
       
   418         case EEventEnterKeyPressed:
       
   419         case EEventItemClicked:
       
   420         	{
       
   421         	if ( iContactItems.Count() > 0 )
       
   422                 {
       
   423                 TInt oldIndex = iSelectedItemIndex;
       
   424                 iSelectedItemIndex = CurrentItemIndex();
       
   425                 if ( oldIndex != iSelectedItemIndex )
       
   426                     {
       
   427                     UpdateListBoxEntryL( oldIndex );
       
   428                     // update listbox entry if we are not yet fast scrolling
       
   429                     if ( !ScrollingInProgress() )
       
   430                         {
       
   431                         SetCurrentContactToActionServiceL();
       
   432                         UpdateListBoxEntryL( iSelectedItemIndex );
       
   433                         }
       
   434                     }
       
   435                 }
       
   436         	break;
       
   437         	}
       
   438         case EEventItemActioned:
       
   439             {
       
   440             break;
       
   441             }
       
   442             
       
   443         case EEventItemDoubleClicked:
       
   444         	{
       
   445             ProcessCommandL( ERclCmdViewDetails );
       
   446         	break;
       
   447         	}
       
   448         	
       
   449         default:
       
   450             {
       
   451             break;
       
   452             }
       
   453         }
       
   454     }
       
   455 
       
   456 // ---------------------------------------------------------------------------
       
   457 // CPbkxRclSearchResultDlg::OfferKeyEventL
       
   458 // ---------------------------------------------------------------------------
       
   459 //
       
   460 TKeyResponse CPbkxRclSearchResultDlg::OfferKeyEventL( 
       
   461     const TKeyEvent& aKeyEvent, 
       
   462     TEventCode aType )
       
   463     {
       
   464     FUNC_LOG;
       
   465 
       
   466     // if there are no items, don't handle key presses
       
   467     TInt count = iContactItems.Count();
       
   468 
       
   469     if ( iExit || aType != EEventKey )
       
   470         {
       
   471         if ( aType == EEventKeyUp )
       
   472             {
       
   473             // added count condition
       
   474             if ( count && ScrollingInProgress() && !iIsScrollLaunched )
       
   475                 {
       
   476                 // scrolling ended
       
   477                 iIsScrollLaunched = ETrue;
       
   478                 ScrollingStoppedL();
       
   479                 }
       
   480             iKeyCounter = 0;
       
   481             iKeyDown = EFalse;
       
   482             }
       
   483         
       
   484         return EKeyWasConsumed;
       
   485         }
       
   486     
       
   487     if ( aKeyEvent.iCode == EKeyUpArrow || 
       
   488          aKeyEvent.iCode == EKeyDownArrow )
       
   489         {
       
   490         iKeyDown = ETrue;
       
   491         iKeyCounter++;
       
   492         }
       
   493     else
       
   494         {
       
   495         // make sure that if we were scrolling we stop it now
       
   496         if ( ScrollingInProgress() )
       
   497             {
       
   498             ScrollingStoppedL();
       
   499             }
       
   500         iKeyDown = EFalse;
       
   501         iKeyCounter = 0;
       
   502         }
       
   503     
       
   504     switch ( aKeyEvent.iCode )
       
   505         {
       
   506         case EKeyPhoneSend:
       
   507             {
       
   508             ProcessCommandL( ERclCmdVoiceCall );
       
   509             break;
       
   510             }
       
   511         case EKeyOK:
       
   512             {
       
   513             if ( count > 0 )
       
   514                 {
       
   515                 // opens result information view
       
   516                 ProcessCommandL( ERclCmdViewDetails );
       
   517                 }
       
   518             }
       
   519             break;
       
   520         case EKeyUpArrow: // fall through, same functionality with these two
       
   521         case EKeyDownArrow:
       
   522             {
       
   523             if ( count > 0 )
       
   524                 {
       
   525                 TInt oldIndex = iSelectedItemIndex;
       
   526                 CAknSelectionListDialog::OfferKeyEventL( aKeyEvent, aType );
       
   527                 iSelectedItemIndex = CurrentItemIndex();
       
   528                 if ( oldIndex != iSelectedItemIndex )
       
   529                     {
       
   530                     UpdateListBoxEntryL( oldIndex );
       
   531                     // update listbox entry if we are not yet fast scrolling
       
   532                     if ( !ScrollingInProgress() )
       
   533                         {
       
   534                         SetCurrentContactToActionServiceL();
       
   535                         UpdateListBoxEntryL( iSelectedItemIndex );
       
   536                         }
       
   537                     }
       
   538                 }
       
   539             }
       
   540             break;
       
   541         case EKeyRightArrow:
       
   542             {
       
   543             if ( !AknLayoutUtils::LayoutMirrored() && ActionMenuAvailable() )
       
   544                 {
       
   545                 // opens action menu
       
   546                 ShowActionMenuL();
       
   547                 }
       
   548             }
       
   549             break;
       
   550         case EKeyLeftArrow:
       
   551             {
       
   552             if ( AknLayoutUtils::LayoutMirrored() && ActionMenuAvailable() )
       
   553                 {
       
   554                 ShowActionMenuL();
       
   555                 }
       
   556             }
       
   557             break;
       
   558         case EKeyEscape:
       
   559             {
       
   560             // exit application
       
   561             iExit = ETrue;
       
   562             ProcessCommandL( EAknCmdExit );
       
   563             }
       
   564             break;
       
   565         default:
       
   566             break;
       
   567         }
       
   568     return EKeyWasConsumed;
       
   569     }
       
   570 
       
   571 // ---------------------------------------------------------------------------
       
   572 // CPbkxRclSearchResultDlg::OkToExitL
       
   573 // ---------------------------------------------------------------------------
       
   574 //
       
   575 TBool CPbkxRclSearchResultDlg::OkToExitL( TInt aButtonId )
       
   576 	{
       
   577     FUNC_LOG;
       
   578 	if( aButtonId == EAknSoftkeyOpen )
       
   579 		{
       
   580 		ProcessCommandL( ERclCmdViewDetails );
       
   581 		return EFalse;
       
   582 		}
       
   583 	else if ( aButtonId == EAknSoftkeyContextOptions )
       
   584 	    {
       
   585 	    iMenuBar->TryDisplayMenuBarL();
       
   586         return EFalse;
       
   587 	    }
       
   588 	else
       
   589 		{
       
   590 		return CAknDialog::OkToExitL( aButtonId );
       
   591 		}
       
   592 	}
       
   593 
       
   594 // ---------------------------------------------------------------------------
       
   595 // CPbkxRclSearchResultDlg::SetupStatusPaneL
       
   596 // ---------------------------------------------------------------------------
       
   597 //
       
   598 void CPbkxRclSearchResultDlg::SetupStatusPaneL()
       
   599     {
       
   600     FUNC_LOG;
       
   601     CAknAppUi* appUi = static_cast<CAknAppUi*>( CCoeEnv::Static()->AppUi() );
       
   602     CEikStatusPane* statusPane = appUi->StatusPane();
       
   603     iNaviPane = reinterpret_cast<CAknNavigationControlContainer*>(
       
   604         statusPane->ControlL( TUid::Uid( EEikStatusPaneUidNavi ) ) );
       
   605     
       
   606     iNaviDecorator = iNaviPane->CreateNavigationLabelL( iNaviText );
       
   607     
       
   608     iNaviPane->PushL( *iNaviDecorator );
       
   609     }
       
   610 
       
   611 // ---------------------------------------------------------------------------
       
   612 // CPbkxRclSearchResultDlg::UpdateStatusPaneL
       
   613 // ---------------------------------------------------------------------------
       
   614 //
       
   615 void CPbkxRclSearchResultDlg::UpdateStatusPaneL()
       
   616     {
       
   617     FUNC_LOG;
       
   618     
       
   619     ResetStatusPane();
       
   620     iNaviDecorator = iNaviPane->CreateNavigationLabelL( iNaviText );
       
   621     iNaviPane->PushL( *iNaviDecorator );
       
   622     }
       
   623 
       
   624 // ---------------------------------------------------------------------------
       
   625 // CPbkxRclSearchResultDlg::ResetStatusPane
       
   626 // ---------------------------------------------------------------------------
       
   627 //
       
   628 void CPbkxRclSearchResultDlg::ResetStatusPane()
       
   629     {
       
   630     FUNC_LOG;
       
   631     // navi pane and navi decorator may be null if dialog construction
       
   632     // failed
       
   633     if ( iNaviPane != NULL && iNaviDecorator != NULL )
       
   634         {
       
   635         iNaviPane->Pop( iNaviDecorator );
       
   636         delete iNaviDecorator;
       
   637         iNaviDecorator = NULL;
       
   638         }
       
   639     }
       
   640 
       
   641 // ---------------------------------------------------------------------------
       
   642 // CPbkxRclSearchResultDlg::CreateListBoxEntriesL
       
   643 // ---------------------------------------------------------------------------
       
   644 //
       
   645 void CPbkxRclSearchResultDlg::CreateListBoxEntriesL()
       
   646     {
       
   647     FUNC_LOG;
       
   648     iItems->Delete( 0, iItems->Count() );
       
   649     TInt count = iContactItems.Count();
       
   650     
       
   651     if ( count > 0 )
       
   652         {
       
   653         iSelectedItemIndex = 0;
       
   654         }
       
   655     
       
   656     SetCurrentContactToActionServiceL();
       
   657 
       
   658     for ( TInt i = 0; i < count; i++ )
       
   659         {
       
   660         CreateListBoxEntryL( i );
       
   661         }
       
   662     
       
   663     CEikListBox* listBox = ListBox();
       
   664 
       
   665     if ( count > 0 )
       
   666         {
       
   667         listBox->SetTopItemIndex( 0 );
       
   668         listBox->SetCurrentItemIndex( 0 );
       
   669         }
       
   670 
       
   671     listBox->HandleItemAdditionL();
       
   672     }
       
   673 
       
   674 // ---------------------------------------------------------------------------
       
   675 // CPbkxRclSearchResultDlg::CreateListBoxIconsL
       
   676 // ---------------------------------------------------------------------------
       
   677 //
       
   678 void CPbkxRclSearchResultDlg::CreateListBoxIconsL()
       
   679     {
       
   680     FUNC_LOG;
       
   681     CFbsBitmap* bitmap = NULL;
       
   682     CFbsBitmap* mask = NULL;
       
   683 
       
   684     TFileName dllFileName; 
       
   685     Dll::FileName( dllFileName );
       
   686     TParse parse;
       
   687     parse.Set( KEngineIconFile, &KDC_APP_RESOURCE_DIR, &dllFileName );
       
   688 
       
   689 // <cmail> icons changed
       
   690     if ( iContactSelectorEnabled )
       
   691         {
       
   692         // add as recipient icon
       
   693         AknsUtils::CreateIconL(
       
   694             AknsUtils::SkinInstance(),
       
   695             KAknsIIDQgnFsRclActionRecipient,
       
   696             bitmap,
       
   697             mask,
       
   698             parse.FullName(),
       
   699             EMbmPbkxrclengineQgn_prop_cmail_contacts_group,
       
   700             EMbmPbkxrclengineQgn_prop_cmail_contacts_group_mask );
       
   701         
       
   702         CleanupStack::PushL( bitmap );
       
   703         CleanupStack::PushL( mask );
       
   704         
       
   705         iAddRecipientIcon = CGulIcon::NewL( bitmap, mask );
       
   706         
       
   707         CleanupStack::Pop( mask );
       
   708         CleanupStack::Pop( bitmap );
       
   709         }
       
   710     
       
   711     // action menu icon
       
   712     AknsUtils::CreateIconL(
       
   713         AknsUtils::SkinInstance(),
       
   714         KAknsIIDQgnFsHscrActionArrowRight,
       
   715         bitmap,
       
   716         mask,
       
   717         parse.FullName(),
       
   718         EMbmPbkxrclengineQgn_indi_cmail_action_arrow_right,
       
   719         EMbmPbkxrclengineQgn_indi_cmail_action_arrow_right_mask );
       
   720 // </cmail>    
       
   721     CleanupStack::PushL( bitmap );
       
   722     CleanupStack::PushL( mask );
       
   723     
       
   724     CGulIcon* icon = CGulIcon::NewL( bitmap, mask );
       
   725     CleanupStack::PushL( icon );
       
   726 
       
   727     CArrayPtr<CGulIcon>* iconArray = 
       
   728         new ( ELeave ) CArrayPtrFlat<CGulIcon>( KArrayGranularity );
       
   729     CleanupStack::PushL( iconArray );
       
   730     iconArray->AppendL( icon );
       
   731 
       
   732     SetIconArrayL( iconArray );
       
   733 
       
   734     CleanupStack::Pop( iconArray );
       
   735 
       
   736     CleanupStack::Pop( icon );
       
   737     CleanupStack::Pop( mask );
       
   738     CleanupStack::Pop( bitmap );
       
   739         
       
   740     }
       
   741 
       
   742 // ---------------------------------------------------------------------------
       
   743 // CPbkxRclSearchResultDlg::CreateListBoxEntryL
       
   744 // ---------------------------------------------------------------------------
       
   745 //
       
   746 void CPbkxRclSearchResultDlg::CreateListBoxEntryL( TInt aIndex )
       
   747     {
       
   748     FUNC_LOG;
       
   749      
       
   750     CContactCard* card = iContactItems[aIndex];
       
   751     TPtrC dispName = PbkxRclUtils::FieldText( card, KUidContactFieldDefinedText );
       
   752     TPtrC firstName = PbkxRclUtils::FieldText( card, KUidContactFieldGivenName );
       
   753     TPtrC lastName = PbkxRclUtils::FieldText( card, KUidContactFieldFamilyName );
       
   754     
       
   755     RBuf entry;
       
   756     TPtrC entryFirstName;
       
   757 
       
   758     if ( dispName.Length() != 0 )
       
   759         {
       
   760         entryFirstName.Set(dispName);
       
   761         entry.CreateL( entryFirstName.Length() + KExtraSpaceInListboxEntry );
       
   762         }
       
   763     else
       
   764         {
       
   765         entryFirstName.Set(firstName);
       
   766         entry.CreateL( firstName.Length() + lastName.Length() + KExtraSpaceInListboxEntry );
       
   767         }
       
   768     
       
   769     CleanupClosePushL( entry );
       
   770     if ( dispName.Length() != 0 )
       
   771         {
       
   772         if ( aIndex == iSelectedItemIndex && ActionMenuAvailable() )
       
   773             {
       
   774             entry.Format( 
       
   775                 KFieldFormatDispNameWithIcon, 
       
   776                 &entryFirstName, 
       
   777                 EActionMenuEnabled );
       
   778             }
       
   779         else
       
   780             {
       
   781             entry.Format( KFieldFormatDispName, &entryFirstName );
       
   782             }
       
   783         }
       
   784     else
       
   785         {
       
   786         if ( aIndex == iSelectedItemIndex && ActionMenuAvailable() )
       
   787             {
       
   788             entry.Format( 
       
   789                 KFieldFormatWithIcon, 
       
   790                 &firstName, 
       
   791                 &lastName, 
       
   792                 EActionMenuEnabled );
       
   793             }
       
   794         else
       
   795             {
       
   796             entry.Format( KFieldFormat, &firstName, &lastName );
       
   797             }
       
   798         }
       
   799     iItems->InsertL( aIndex, entry );
       
   800     CleanupStack::PopAndDestroy( &entry );
       
   801     }
       
   802 
       
   803 // ---------------------------------------------------------------------------
       
   804 // CPbkxRclSearchResultDlg::UpdateListBoxEntryL
       
   805 // ---------------------------------------------------------------------------
       
   806 //
       
   807 void CPbkxRclSearchResultDlg::UpdateListBoxEntryL( TInt aIndex )
       
   808     {
       
   809     FUNC_LOG;
       
   810     iItems->Delete( aIndex );
       
   811     CreateListBoxEntryL( aIndex );
       
   812     ListBox()->DrawItem( aIndex );
       
   813     }
       
   814 
       
   815 // ---------------------------------------------------------------------------
       
   816 // CPbkxRclSearchResultDlg::SetCurrentContactToActionServiceL
       
   817 // ---------------------------------------------------------------------------
       
   818 //
       
   819 void CPbkxRclSearchResultDlg::SetCurrentContactToActionServiceL()
       
   820     {
       
   821     FUNC_LOG;
       
   822    
       
   823     if ( iActionMenu )
       
   824     	{
       
   825         if ( iContactItems.Count() > 0 )
       
   826             {
       
   827             // set current contact to action service
       
   828         
       
   829             CPbkContactItem* currentContact = PbkxRclUtils::CreateContactItemL(
       
   830                 iContactItems[iSelectedItemIndex],
       
   831                 iContactEngine );
       
   832             CleanupStack::PushL( currentContact );
       
   833     
       
   834             iContactActionService.SetCurrentContactL( 
       
   835                 currentContact );
       
   836         
       
   837             CleanupStack::PopAndDestroy( currentContact );
       
   838         
       
   839             }
       
   840         else
       
   841             {
       
   842             iContactActionService.SetCurrentContactL( NULL );
       
   843             }
       
   844     
       
   845     	if ( iActionMenu )
       
   846 			{
       
   847             // update action menu
       
   848             iActionMenu->Model().AddPreQueriedCasItemsL();
       
   849             // save as contact not added for this contact
       
   850             iSaveAsAdded = EFalse;
       
   851             }
       
   852     	} 
       
   853     iIsScrollLaunched = EFalse;
       
   854     }
       
   855 
       
   856 // ---------------------------------------------------------------------------
       
   857 // CPbkxRclSearchResultDlg::LoadNaviTextL
       
   858 // ---------------------------------------------------------------------------
       
   859 //
       
   860 void CPbkxRclSearchResultDlg::LoadNaviTextL()
       
   861     {
       
   862     FUNC_LOG;
       
   863     iNaviText.Close();
       
   864     HBufC* naviText = NULL;
       
   865     if ( iContactItems.Count() == 1 )
       
   866         {
       
   867         naviText = StringLoader::LoadLC( R_QTN_RCL_ONE_RESULT_NAVI );
       
   868         }
       
   869     else if ( iContactItems.Count() == 0 )
       
   870         {
       
   871         naviText = NULL;
       
   872         }
       
   873     else
       
   874         {
       
   875         naviText = StringLoader::LoadLC( 
       
   876             R_QTN_RCL_RESULT_NAVI,
       
   877             iContactItems.Count() );
       
   878         }
       
   879     
       
   880     if (naviText)
       
   881         {
       
   882         iNaviText.CreateL( *naviText );
       
   883         CleanupStack::PopAndDestroy( naviText );
       
   884         }
       
   885     else
       
   886         {
       
   887         iNaviText = KNullDesC;
       
   888         }
       
   889     }
       
   890 
       
   891 // ---------------------------------------------------------------------------
       
   892 // CPbkxRclSearchResultDlg::CallActionsAvailable
       
   893 // ---------------------------------------------------------------------------
       
   894 //
       
   895 TBool CPbkxRclSearchResultDlg::CallActionsAvailable() const
       
   896     {
       
   897     FUNC_LOG;
       
   898     return iContactActionService.IsActionEnabled( KFscAtComCallGSM ) ||
       
   899         iContactActionService.IsActionEnabled( KFscAtComCallVideo );
       
   900     }
       
   901 
       
   902 // ---------------------------------------------------------------------------
       
   903 // CPbkxRclSearchResultDlg::InitializeActionMenuL
       
   904 // ---------------------------------------------------------------------------
       
   905 //
       
   906 void CPbkxRclSearchResultDlg::InitializeActionMenuL()
       
   907     {
       
   908     FUNC_LOG;
       
   909     
       
   910     iActionMenu = CFscContactActionMenu::NewL( 
       
   911         *(iContactActionService.ActionService()) );
       
   912 
       
   913     MFscContactActionMenuModel& model = iActionMenu->Model();
       
   914 
       
   915     if ( iContactSelectorEnabled && iContactItems.Count() > 0 )
       
   916         {
       
   917 
       
   918         // add static custom item
       
   919         HBufC* menuText = StringLoader::LoadLC( 
       
   920             R_QTN_RCL_ADD_RECIPIENT_ACTION_MENU_TEXT );
       
   921         
       
   922         CFscContactActionMenuItem* item = model.NewMenuItemL(
       
   923             *menuText,
       
   924             iAddRecipientIcon,
       
   925             KPbkxRclAddRecipientPriority,
       
   926             ETrue,
       
   927             KPbkxRclAddRecipientActionUid );
       
   928         
       
   929         CleanupStack::PushL( item );
       
   930         
       
   931         model.AddItemL( item );
       
   932         
       
   933         CleanupStack::Pop( item );
       
   934         CleanupStack::PopAndDestroy( menuText );
       
   935         }
       
   936     }
       
   937 
       
   938 // ---------------------------------------------------------------------------
       
   939 // CPbkxRclSearchResultDlg::ShowActionMenuL
       
   940 // ---------------------------------------------------------------------------
       
   941 //
       
   942 void CPbkxRclSearchResultDlg::ShowActionMenuL()
       
   943     {
       
   944     FUNC_LOG;
       
   945 
       
   946     CreateAndAddSaveAsContactActionL();
       
   947     
       
   948     TFscContactActionMenuPosition pos = GetActionMenuPosition();
       
   949     TFscActionMenuResult result = iActionMenu->ExecuteL( pos );
       
   950 
       
   951     // if custom item was selected, it was our add to recipient or
       
   952     // save as contact
       
   953     if ( result == EFscCustomItemSelected )
       
   954         {
       
   955         const TFscContactActionQueryResult* saveAsContact = 
       
   956             iContactActionService.GetResult( KFscAtManSaveAs );
       
   957         TInt itemIndex = iActionMenu->FocusedItemIndex();
       
   958         CFscContactActionMenuItem& item = 
       
   959             iActionMenu->Model().ItemL( itemIndex );
       
   960         
       
   961         if ( item.ImplementationUid() == KPbkxRclAddRecipientActionUid )
       
   962             {
       
   963             ProcessCommandL( ERclCmdAddAsRecipient );
       
   964             }
       
   965         else if ( saveAsContact != NULL &&
       
   966                   item.ImplementationUid() == saveAsContact->iAction->Uid() ) 
       
   967             {
       
   968             ProcessCommandL( ERclCmdSaveToContacts );
       
   969             }
       
   970         }
       
   971     }
       
   972 
       
   973 // ---------------------------------------------------------------------------
       
   974 // CPbkxRclSearchResultDlg::GetActionMenuPosition
       
   975 // ---------------------------------------------------------------------------
       
   976 //
       
   977 TFscContactActionMenuPosition CPbkxRclSearchResultDlg::GetActionMenuPosition()
       
   978     {
       
   979     FUNC_LOG;
       
   980     const TInt KNumberOfMenuPositions = 3;
       
   981 
       
   982     CEikListBox* listBox = ListBox();
       
   983     TInt itemsInView = listBox->View()->NumberOfItemsThatFitInRect( Rect() );
       
   984 
       
   985     TInt topIndex = listBox->TopItemIndex();
       
   986     TInt curIndex = listBox->CurrentItemIndex();
       
   987 
       
   988     TInt normalizedIndex = curIndex - topIndex;
       
   989     
       
   990     TInt segmentSize = itemsInView / KNumberOfMenuPositions;
       
   991 
       
   992     if ( normalizedIndex < segmentSize )
       
   993         {
       
   994         return EFscTop;
       
   995         }
       
   996     else if ( normalizedIndex < ( 2 * segmentSize) )
       
   997         {
       
   998         return EFscCenter;
       
   999         }
       
  1000     else
       
  1001         {
       
  1002         return EFscBottom;
       
  1003         }
       
  1004     }
       
  1005 
       
  1006 // ---------------------------------------------------------------------------
       
  1007 // CPbkxRclSearchResultDlg::ActionMenuAvailable
       
  1008 // ---------------------------------------------------------------------------
       
  1009 //
       
  1010 TBool CPbkxRclSearchResultDlg::ActionMenuAvailable() const
       
  1011     {
       
  1012     FUNC_LOG;
       
  1013     TInt count = iActionMenu->Model().ItemCount() > 0;
       
  1014     if ( !iSaveAsAdded )
       
  1015         {
       
  1016         if ( iContactActionService.IsActionEnabled( KFscAtManSaveAs ) )
       
  1017             {
       
  1018             count++;
       
  1019             }
       
  1020         }
       
  1021     
       
  1022     return count > 0;
       
  1023     }
       
  1024 
       
  1025 // ---------------------------------------------------------------------------
       
  1026 // CPbkxRclSearchResultDlg::CreateAndAddSaveAsContactActionL
       
  1027 // ---------------------------------------------------------------------------
       
  1028 //
       
  1029 void CPbkxRclSearchResultDlg::CreateAndAddSaveAsContactActionL()
       
  1030     {
       
  1031     FUNC_LOG;
       
  1032     if ( !iSaveAsAdded )
       
  1033         {
       
  1034         const TFscContactActionQueryResult* saveAsContact = 
       
  1035             iContactActionService.GetResult( KFscAtManSaveAs );
       
  1036         if ( saveAsContact != NULL )
       
  1037             {
       
  1038             MFscContactActionMenuModel& model = iActionMenu->Model();
       
  1039             
       
  1040             const MFscContactAction* action = saveAsContact->iAction;
       
  1041             
       
  1042             CFscContactActionMenuItem* item = model.NewMenuItemL(
       
  1043                 action->ActionMenuText(),
       
  1044                 action->Icon(),
       
  1045                 saveAsContact->iPriority,
       
  1046                 EFalse,
       
  1047                 action->Uid() );
       
  1048             
       
  1049             CleanupStack::PushL( item );
       
  1050             
       
  1051             model.AddItemL( item );
       
  1052             
       
  1053             iSaveAsAdded = ETrue;
       
  1054 
       
  1055             CleanupStack::Pop( item );
       
  1056             }
       
  1057         }
       
  1058     }
       
  1059 
       
  1060 
       
  1061 // ---------------------------------------------------------------------------
       
  1062 // CPbkxRclSearchResultDlg::ScrollingInProgress
       
  1063 // ---------------------------------------------------------------------------
       
  1064 //
       
  1065 TBool CPbkxRclSearchResultDlg::ScrollingInProgress() const
       
  1066     {
       
  1067     FUNC_LOG;
       
  1068     return iKeyDown && iKeyCounter > KKeyScrolling;
       
  1069     }
       
  1070 
       
  1071 // ---------------------------------------------------------------------------
       
  1072 // CPbkxRclSearchResultDlg::ScrollingStopped
       
  1073 // ---------------------------------------------------------------------------
       
  1074 //
       
  1075 void CPbkxRclSearchResultDlg::ScrollingStoppedL()
       
  1076     {
       
  1077     FUNC_LOG;
       
  1078     SetCurrentContactToActionServiceL();
       
  1079     UpdateListBoxEntryL( iSelectedItemIndex ); 
       
  1080     }
       
  1081 
       
  1082 // ---------------------------------------------------------------------------
       
  1083 // CPbkxRclSearchResultDlg::ConstructContextMenuL
       
  1084 // ---------------------------------------------------------------------------
       
  1085 //
       
  1086 void CPbkxRclSearchResultDlg::ConstructMenuBarL( TInt aResourceId )
       
  1087     {
       
  1088     FUNC_LOG;
       
  1089     CEikButtonGroupContainer& butContainer = ButtonGroupContainer();
       
  1090     butContainer.SetCommandSetL( aResourceId );
       
  1091     butContainer.DrawNow();
       
  1092     }
       
  1093 
       
  1094 // ---------------------------------------------------------------------------
       
  1095 // CPbkxRclSearchResultDlg::InfoDlgVisible
       
  1096 // ---------------------------------------------------------------------------
       
  1097 //
       
  1098 void CPbkxRclSearchResultDlg::InfoDlgVisible( TBool aVisible )
       
  1099     {
       
  1100     FUNC_LOG;
       
  1101     iIsInfoDlgVisible = aVisible;
       
  1102     }