phonebookui/Phonebook2/USIMExtension/src/CPsu2FixedDialingInfoView.cpp
changeset 0 e686773b3f54
child 68 9da50d567e3c
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 USIM UI Extension FDN contact info view.
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 // INCLUDE FILES
       
    20 #include "CPsu2FixedDialingInfoView.h"
       
    21 
       
    22 // Phonebook 2
       
    23 #include "CPsu2ViewManager.h"
       
    24 #include "CPsu2FixedDialingCall.h"
       
    25 #include "CPsu2SecUi.h"
       
    26 #include <CPbk2UIExtensionView.h>
       
    27 #include <MPbk2ViewActivationTransaction.h>
       
    28 #include <CPbk2AppUiBase.h>
       
    29 #include <MPbk2ViewExplorer.h>
       
    30 #include <Pbk2USimUIRes.rsg>
       
    31 #include <CPbk2ViewState.h>
       
    32 #include <MPbk2ContactUiControl.h>
       
    33 #include <Pbk2UIControls.rsg>
       
    34 #include <MPbk2CommandHandler.h>
       
    35 #include <MPbk2ApplicationServices.h>
       
    36 #include <TPbk2ContactEditorParams.h>
       
    37 #include <CPbk2ContactEditorDlg.h>
       
    38 #include <Pbk2UID.h>
       
    39 #include <csxhelp/phob.hlp.hrh>
       
    40 #include <CPbk2PresentationContact.h>
       
    41 #include <CPbk2FieldPropertyArray.h>
       
    42 #include <CPbk2PresentationContactFieldCollection.h>
       
    43 #include <MPbk2PointerEventInspector.h>
       
    44 
       
    45 // Virtual Phonebook
       
    46 #include <MVPbkSimPhone.h>
       
    47 #include <MVPbkBaseContact.h>
       
    48 #include <MVPbkContactLink.h>
       
    49 #include <MVPbkStoreContact.h>
       
    50 #include <CVPbkContactManager.h>
       
    51 #include <MVPbkContactOperationBase.h>
       
    52 
       
    53 // System includes
       
    54 #include <StringLoader.h>
       
    55 #include <AknUtils.h>
       
    56 #include <AiwCommon.hrh>
       
    57 
       
    58 // Debugging headers
       
    59 #include <Pbk2Debug.h>
       
    60 
       
    61 // --------------------------------------------------------------------------
       
    62 // CPsu2FixedDialingInfoView::CPsu2FixedDialingInfoView
       
    63 // --------------------------------------------------------------------------
       
    64 //
       
    65 CPsu2FixedDialingInfoView::CPsu2FixedDialingInfoView
       
    66         ( CPbk2UIExtensionView& aExtensionView,
       
    67           CPsu2ViewManager& aViewManager ) :
       
    68             CPsu2InfoViewBase( aExtensionView, aViewManager )
       
    69     {
       
    70     }
       
    71 
       
    72 // --------------------------------------------------------------------------
       
    73 // CPsu2FixedDialingInfoView::~CPsu2FixedDialingInfoView
       
    74 // --------------------------------------------------------------------------
       
    75 //
       
    76 CPsu2FixedDialingInfoView::~CPsu2FixedDialingInfoView()
       
    77     {
       
    78     delete iFdnCall;
       
    79     delete iContactLink;
       
    80     delete iContact;
       
    81     delete iContactRetriever;
       
    82     }
       
    83 
       
    84 // --------------------------------------------------------------------------
       
    85 // CPsu2FixedDialingInfoView::NewL
       
    86 // --------------------------------------------------------------------------
       
    87 //
       
    88 CPsu2FixedDialingInfoView* CPsu2FixedDialingInfoView::NewL
       
    89         ( CPbk2UIExtensionView& aExtensionView,
       
    90           CPsu2ViewManager& aViewManager )
       
    91     {
       
    92     CPsu2FixedDialingInfoView* self =
       
    93         new ( ELeave ) CPsu2FixedDialingInfoView
       
    94             ( aExtensionView, aViewManager );
       
    95     CleanupStack::PushL( self );
       
    96     self->ConstructL();
       
    97     CleanupStack::Pop( self );
       
    98     return self;
       
    99     }
       
   100 
       
   101 // --------------------------------------------------------------------------
       
   102 // CPsu2FixedDialingInfoView::ConstructL
       
   103 // --------------------------------------------------------------------------
       
   104 //
       
   105 void CPsu2FixedDialingInfoView::ConstructL()
       
   106     {
       
   107     BaseConstructL();
       
   108     }
       
   109 
       
   110 // --------------------------------------------------------------------------
       
   111 // CPsu2FixedDialingInfoView::DoActivateL
       
   112 // --------------------------------------------------------------------------
       
   113 //
       
   114 void CPsu2FixedDialingInfoView::DoActivateL
       
   115         ( const TVwsViewId& aPrevViewId, TUid aCustomMessageId,
       
   116           const TDesC8& aCustomMessage)
       
   117     {
       
   118     // Set up view
       
   119     delete iViewActivationTransaction;
       
   120     iViewActivationTransaction = NULL;
       
   121     iViewActivationTransaction =
       
   122         Phonebook2::Pbk2AppUi()->Pbk2ViewExplorer()->
       
   123             HandleViewActivationLC( iExtensionView.Id(), aPrevViewId,
       
   124                 NULL, NULL, Phonebook2::EUpdateNaviPane );
       
   125     CleanupStack::Pop(); //iViewActivationTransaction
       
   126 
       
   127     // Call base class
       
   128     CPsu2InfoViewBase::DoActivateL
       
   129         ( aPrevViewId, aCustomMessageId, aCustomMessage );
       
   130     }
       
   131 
       
   132 // --------------------------------------------------------------------------
       
   133 // CPsu2FixedDialingInfoView::DoDeactivate
       
   134 // --------------------------------------------------------------------------
       
   135 //
       
   136 void CPsu2FixedDialingInfoView::DoDeactivate()
       
   137     {
       
   138     CPsu2InfoViewBase::DoDeactivate();
       
   139     }
       
   140 
       
   141 // --------------------------------------------------------------------------
       
   142 // CPsu2FixedDialingInfoView::HandleCommandKeyL
       
   143 // --------------------------------------------------------------------------
       
   144 //
       
   145 TBool CPsu2FixedDialingInfoView::HandleCommandKeyL
       
   146         ( const TKeyEvent& aKeyEvent, TEventCode aType )
       
   147     {
       
   148     TBool ret = EFalse;
       
   149 
       
   150     if ( aType == EEventKey )
       
   151         {
       
   152         if( aKeyEvent.iCode == EKeyPhoneSend )
       
   153             {
       
   154             CreateCallL( EPbk2CmdCall );
       
   155             ret = ETrue;
       
   156             }
       
   157         else if( aKeyEvent.iCode == EKeyBackspace )
       
   158             {
       
   159             HandleCommandL( EPbk2CmdDeleteMe );
       
   160             ret = ETrue;
       
   161             }
       
   162         else
       
   163             {
       
   164             if ( aKeyEvent.iScanCode == EStdKeyNo )
       
   165                 {
       
   166                 // 'Red' button pressed, clear PIN2 query info
       
   167                 iViewManager.SecUi().Reset();
       
   168                 }
       
   169             }            
       
   170         }
       
   171     else
       
   172         {
       
   173         ret = CPsu2InfoViewBase::HandleCommandKeyL( aKeyEvent, aType );        
       
   174         }
       
   175 
       
   176     return ret;
       
   177     }
       
   178 
       
   179 // --------------------------------------------------------------------------
       
   180 // CPsu2FixedDialingInfoView::HandleCommandL
       
   181 // --------------------------------------------------------------------------
       
   182 //
       
   183 void CPsu2FixedDialingInfoView::HandleCommandL( TInt aCommand )
       
   184     {
       
   185     if ( Phonebook2::Pbk2AppUi()->ApplicationServices().CommandHandlerL()->
       
   186             ServiceCmdByMenuCmd( aCommand ) == KAiwCmdCall )
       
   187         {
       
   188         if ( iViewManager.StoreAvailableL() )
       
   189             {
       
   190             CreateCallL( aCommand );
       
   191             }
       
   192         }
       
   193     else
       
   194         {
       
   195         switch( aCommand )
       
   196             {
       
   197             case EPbk2CmdEditMe:
       
   198                 {
       
   199                 if ( iViewManager.SecUi().ConfirmPin2L() )
       
   200                     {     
       
   201                     delete iContactLink;
       
   202                     iContactLink = NULL;               
       
   203                     iContactLink = iControl->FocusedContactL()->CreateLinkLC();
       
   204                     CleanupStack::Pop();
       
   205                     iContactRetriever = 
       
   206                         Phonebook2::Pbk2AppUi()->ApplicationServices().
       
   207                             ContactManager().RetrieveContactL(
       
   208                                 *iContactLink, *this );
       
   209                     }
       
   210                 break;
       
   211                 }
       
   212             case EPbk2CmdDeleteMe:
       
   213                 {
       
   214                 if ( iViewManager.SecUi().ConfirmPin2L() )
       
   215                     {
       
   216                     CPsu2InfoViewBase::HandleCommandL( aCommand );
       
   217                     }
       
   218                 break;
       
   219                 }
       
   220             case EPbk2CmdExit:
       
   221             case EAknCmdHideInBackground:
       
   222                 {
       
   223                 if ( aCommand == EAknCmdHideInBackground && iDlgEliminator )
       
   224                     {
       
   225                     iDlgEliminator->RequestExitL( EKeyEscape );
       
   226                     }
       
   227 
       
   228                 // Clear PIN2 query info
       
   229                 iViewManager.SecUi().Reset();
       
   230                 CPsu2InfoViewBase::HandleCommandL( aCommand );
       
   231                 break;
       
   232                 }
       
   233             default:
       
   234                 {
       
   235                 CPsu2InfoViewBase::HandleCommandL( aCommand );
       
   236                 break;
       
   237                 }
       
   238             };
       
   239         }
       
   240     }
       
   241 
       
   242 // --------------------------------------------------------------------------
       
   243 // CPsu2FixedDialingInfoView::DynInitMenuPaneL
       
   244 // --------------------------------------------------------------------------
       
   245 //
       
   246 void CPsu2FixedDialingInfoView::DynInitMenuPaneL(
       
   247         TInt aResourceId,
       
   248         CEikMenuPane* aMenuPane )
       
   249     {
       
   250     switch( aResourceId )
       
   251         {
       
   252         case R_PSU2_FIXED_DIALING_INFO_COPY_MENUPANE:
       
   253             {
       
   254             break;
       
   255             }
       
   256         case R_PSU2_FIXED_DIALING_INFO_MENUPANE:
       
   257             {
       
   258             break;
       
   259             }
       
   260         default:
       
   261             {
       
   262             CPsu2InfoViewBase::DynInitMenuPaneL( aResourceId, aMenuPane );
       
   263             break;
       
   264             }
       
   265         }
       
   266     }
       
   267 
       
   268 
       
   269 // --------------------------------------------------------------------------
       
   270 // CPsu2FixedDialingInfoView::NameListControlResourceId
       
   271 // --------------------------------------------------------------------------
       
   272 //
       
   273 TInt CPsu2FixedDialingInfoView::NameListControlResourceId() const
       
   274     {
       
   275     return 0;
       
   276     }
       
   277 
       
   278 // --------------------------------------------------------------------------
       
   279 // CPsu2FixedDialingInfoView::NaviPaneLabelL
       
   280 // --------------------------------------------------------------------------
       
   281 //
       
   282 HBufC* CPsu2FixedDialingInfoView::NaviPaneLabelL() const
       
   283     {
       
   284     HBufC* text = NULL;
       
   285     if ( iViewManager.SecUi().IsFDNActive() )
       
   286         {
       
   287         text = StringLoader::LoadLC( R_QTN_FDN_ACTIVE );
       
   288         }
       
   289     else
       
   290         {
       
   291         text = StringLoader::LoadLC( R_QTN_FDN_DEACTIVE );
       
   292         }
       
   293 
       
   294     CleanupStack::Pop(); // text
       
   295     return text;
       
   296     }
       
   297 
       
   298 // --------------------------------------------------------------------------
       
   299 // CPsu2FixedDialingInfoView::UpdateCbasL
       
   300 // --------------------------------------------------------------------------
       
   301 //
       
   302 void CPsu2FixedDialingInfoView::UpdateCbasL()
       
   303     {
       
   304     // Set cba command set "Options - Context Menu - Back"
       
   305     iExtensionView.Cba()->SetCommandSetL
       
   306         ( R_PBK2_SOFTKEYS_OPTIONS_BACK_CONTEXT );
       
   307     iExtensionView.Cba()->DrawDeferred();
       
   308     // Set context menu
       
   309     iExtensionView.MenuBar()->SetContextMenuTitleResourceId
       
   310         ( R_PSU2_FIXED_DIALING_INFO_CONTEXT_MENUBAR );
       
   311     }
       
   312 
       
   313 // --------------------------------------------------------------------------
       
   314 // CPsu2FixedDialingInfoView::VPbkSingleContactOperationComplete
       
   315 // --------------------------------------------------------------------------
       
   316 //    
       
   317 void CPsu2FixedDialingInfoView::VPbkSingleContactOperationComplete(
       
   318         MVPbkContactOperationBase& aOperation,
       
   319         MVPbkStoreContact* aContact )
       
   320     {
       
   321     
       
   322     if ( iContactRetriever == &aOperation && aContact)
       
   323         {
       
   324         delete iContactRetriever;
       
   325         iContactRetriever = NULL;
       
   326         
       
   327         delete iContact;    
       
   328         iContact = aContact;     
       
   329                
       
   330         TRAPD( error, iContact->LockL(*this) );
       
   331         if ( error != KErrNone )
       
   332             {
       
   333             CCoeEnv::Static()->HandleError(error);
       
   334             } 
       
   335         }      
       
   336     }
       
   337         
       
   338 // --------------------------------------------------------------------------
       
   339 // CPsu2FixedDialingInfoView::VPbkSingleContactOperationFailed
       
   340 // --------------------------------------------------------------------------
       
   341 //        
       
   342 void CPsu2FixedDialingInfoView::VPbkSingleContactOperationFailed(
       
   343         MVPbkContactOperationBase& aOperation, 
       
   344         TInt aError )
       
   345     {
       
   346     if ( iContactRetriever == &aOperation )
       
   347         {
       
   348         delete iContactRetriever;
       
   349         iContactRetriever = NULL;
       
   350         
       
   351         CCoeEnv::Static()->HandleError(aError);
       
   352         }    
       
   353     }
       
   354 
       
   355 // --------------------------------------------------------------------------
       
   356 // CPsu2FixedDialingInfoView::ContactEditingCompletebasL
       
   357 // --------------------------------------------------------------------------
       
   358 //
       
   359 void CPsu2FixedDialingInfoView::ContactEditingComplete(
       
   360         MVPbkStoreContact* aEditedContact )
       
   361     {  
       
   362     PBK2_DEBUG_PRINT(PBK2_DEBUG_STRING
       
   363         ("CPsu2FixedDialingInfoView(%x)::ContactEditingComplete()"), 
       
   364         this);
       
   365         
       
   366     iContact = aEditedContact;                      
       
   367     }
       
   368     
       
   369 // --------------------------------------------------------------------------
       
   370 // CPsu2FixedDialingInfoView::ContactEditingDeletedContact
       
   371 // --------------------------------------------------------------------------
       
   372 //        
       
   373 void CPsu2FixedDialingInfoView::ContactEditingDeletedContact(
       
   374         MVPbkStoreContact* aEditedContact )
       
   375     {
       
   376     PBK2_DEBUG_PRINT(PBK2_DEBUG_STRING
       
   377         ("CPsu2FixedDialingInfoView(%x)::ContactEditingDeletedContact()"), 
       
   378         this);
       
   379     
       
   380     delete aEditedContact; // not needed anymore
       
   381     }
       
   382     
       
   383 // --------------------------------------------------------------------------
       
   384 // CPsu2FixedDialingInfoView::ContactEditingAborted
       
   385 // --------------------------------------------------------------------------
       
   386 //        
       
   387 void CPsu2FixedDialingInfoView::ContactEditingAborted()
       
   388     {
       
   389     // Do nothing
       
   390     }
       
   391 
       
   392 // --------------------------------------------------------------------------
       
   393 // CPsu2FixedDialingInfoView::ContactOperationCompleted
       
   394 // --------------------------------------------------------------------------
       
   395 //     
       
   396 void CPsu2FixedDialingInfoView::ContactOperationCompleted(
       
   397         TContactOpResult /*aResult*/ )
       
   398     {
       
   399     TRAPD(result, EditFdnContactL());
       
   400         
       
   401     if (result != KErrNone)
       
   402         {
       
   403         CCoeEnv::Static()->HandleError(result);
       
   404         }
       
   405     }
       
   406 
       
   407 // --------------------------------------------------------------------------
       
   408 // CPsu2FixedDialingInfoView::ContactOperationFailed
       
   409 // --------------------------------------------------------------------------
       
   410 //     
       
   411 void CPsu2FixedDialingInfoView::ContactOperationFailed(
       
   412         TContactOp /*aOpCode*/, 
       
   413         TInt aErrorCode, 
       
   414         TBool /*aErrorNotified*/ )
       
   415     {
       
   416     CCoeEnv::Static()->HandleError(aErrorCode);
       
   417     }
       
   418 
       
   419 // --------------------------------------------------------------------------
       
   420 // CPsu2FixedDialingInfoView::CreateCallL
       
   421 // --------------------------------------------------------------------------
       
   422 //
       
   423 void CPsu2FixedDialingInfoView::CreateCallL( TInt aCommand )
       
   424     {
       
   425     if ( !iFdnCall )
       
   426         {
       
   427         iFdnCall = CPsu2FixedDialingCall::NewL
       
   428             ( Phonebook2::Pbk2AppUi()->ApplicationServices().ContactManager(),
       
   429               *Phonebook2::Pbk2AppUi()->ApplicationServices().
       
   430                 CommandHandlerL(),
       
   431               iExtensionView );
       
   432         }
       
   433 
       
   434     MVPbkContactLink* contactLink =
       
   435         iControl->FocusedContactL()->CreateLinkLC();
       
   436     CleanupStack::Pop(); // CreateCallL takes contactLink
       
   437     iFdnCall->CreateCallL( contactLink, aCommand );
       
   438     }
       
   439 
       
   440 // --------------------------------------------------------------------------
       
   441 // CPsu2FixedDialingInfoView::EditFdnContactL
       
   442 // --------------------------------------------------------------------------
       
   443 //    
       
   444 void CPsu2FixedDialingInfoView::EditFdnContactL()
       
   445     {
       
   446     PBK2_DEBUG_PRINT(PBK2_DEBUG_STRING
       
   447         ("CPsu2FixedDialingInfoView(%x)::EditFdnContactL()"), this);
       
   448          
       
   449     // adjust focus
       
   450     TInt focusedFieldIndex = KErrNotFound;
       
   451     if (iControl)
       
   452         {
       
   453         focusedFieldIndex = iControl->FocusedFieldIndex();
       
   454         }
       
   455         
       
   456     TPbk2ContactEditorParams params;
       
   457     if ( focusedFieldIndex != KErrNotFound )
       
   458         {
       
   459         params.iFocusedContactField = 
       
   460             FocusedFieldLC( *iContact );
       
   461         }
       
   462 
       
   463     TCoeHelpContext helpContext;
       
   464     helpContext.iMajor.iUid = KPbk2UID3;
       
   465     helpContext.iContext = KFDN_HLP_FDN_NUM_EDIT_VIEW;
       
   466     params.iHelpContext = &helpContext;
       
   467         
       
   468     // create and execute editing dialog
       
   469     CPbk2ContactEditorDlg* dlg =
       
   470         CPbk2ContactEditorDlg::NewL( params, iContact, *this );
       
   471     iContact = NULL; // ownership went to editor
       
   472     iDlgEliminator = dlg;
       
   473     dlg->ExecuteLD();
       
   474     iDlgEliminator = NULL;
       
   475     
       
   476     // clean after dialog execution
       
   477     if ( focusedFieldIndex != KErrNotFound )
       
   478         {
       
   479         CleanupStack::PopAndDestroy(); //params.iFocusedContactField
       
   480         }    
       
   481     
       
   482     if ( iControl )
       
   483         {        
       
   484         // If editing has been aborted we don't set focused contact.
       
   485         if ( iContact )
       
   486             {
       
   487             // It is possible that the contact got changed while in edit
       
   488             iControl->SetFocusedFieldIndex( params.iFocusedIndex );
       
   489             iControl->SetFocusedContactL( *iContact );
       
   490             delete iContact;
       
   491             iContact = NULL;
       
   492             }
       
   493 
       
   494         // If contact got deleted in the editor, this call ensures
       
   495         // that the contact info view is switched to the names list
       
   496         iControl->UpdateAfterCommandExecution();        
       
   497         }
       
   498     }
       
   499 
       
   500 // --------------------------------------------------------------------------
       
   501 // CPsu2FixedDialingInfoView::FocusedFieldLC
       
   502 // --------------------------------------------------------------------------
       
   503 //    
       
   504 MVPbkStoreContactField* CPsu2FixedDialingInfoView::FocusedFieldLC( 
       
   505         MVPbkStoreContact& aStoreContact )
       
   506     {
       
   507     CPbk2PresentationContact* presentationContact = 
       
   508       CPbk2PresentationContact::NewL( aStoreContact, 
       
   509         Phonebook2::Pbk2AppUi()->ApplicationServices().FieldProperties() );
       
   510     CleanupStack::PushL( presentationContact );
       
   511 
       
   512     TInt index = KErrNotFound;
       
   513     if (iControl)
       
   514         {
       
   515         index = presentationContact->PresentationFields().StoreIndexOfField( 
       
   516                 iControl->FocusedFieldIndex() );
       
   517         }
       
   518 
       
   519     CleanupStack::PopAndDestroy( presentationContact );
       
   520     
       
   521     if ( index != KErrNotFound )
       
   522         {
       
   523         // Use FieldAtLC to avoid the unvalidity of the field after new
       
   524         // FieldAt call.        
       
   525         return aStoreContact.Fields().FieldAtLC( index );
       
   526         }
       
   527     return NULL;
       
   528     }     
       
   529 
       
   530 // --------------------------------------------------------------------------
       
   531 // CPsu2FixedDialingInfoView::HandleControlEventL
       
   532 // --------------------------------------------------------------------------
       
   533 //    
       
   534 void CPsu2FixedDialingInfoView::HandleControlEventL(
       
   535         MPbk2ContactUiControl& aControl,
       
   536         const TPbk2ControlEvent& aEvent )
       
   537     {
       
   538     switch ( aEvent.iEventType )
       
   539         {
       
   540         case TPbk2ControlEvent::EContactTapped:
       
   541         case TPbk2ControlEvent::EContactDoubleTapped:
       
   542         case TPbk2ControlEvent::EControlEnterKeyPressed:
       
   543             {
       
   544             HandleCommandL( EPbk2CmdEditMe );
       
   545             break;
       
   546             }
       
   547         default:
       
   548             {
       
   549             CPsu2InfoViewBase::HandleControlEventL( aControl, aEvent );
       
   550             break;
       
   551             }
       
   552         }
       
   553     }
       
   554 
       
   555 // End of File