phonebookui/Phonebook2/USIMExtension/src/CPsu2FixedDialingView.cpp
changeset 0 e686773b3f54
child 21 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 names list view.
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 // INCLUDE FILES
       
    20 #include "CPsu2FixedDialingView.h"
       
    21 
       
    22 // Phonebook 2
       
    23 #include "CPsu2FixedDialingCall.h"
       
    24 #include "CPsu2ViewManager.h"
       
    25 #include "CPsu2SecUi.h"
       
    26 #include <MPbk2ContactUiControl.h>
       
    27 #include <CPbk2UIExtensionView.h>
       
    28 #include <MPbk2ViewActivationTransaction.h>
       
    29 #include <CPbk2AppUiBase.h>
       
    30 #include <MPbk2ViewExplorer.h>
       
    31 #include <TPbk2ContactEditorParams.h>
       
    32 #include <CPbk2ContactEditorDlg.h>
       
    33 #include <CPbk2FieldPropertyArray.h>
       
    34 #include <MPbk2FieldProperty.h>
       
    35 #include <Pbk2USimUIRes.rsg>
       
    36 #include <Pbk2UIControls.rsg>
       
    37 #include <CPbk2NamesListControl.h>
       
    38 #include <CPbk2ControlContainer.h>
       
    39 #include <CPbk2ViewState.h>
       
    40 #include <MPbk2CommandHandler.h>
       
    41 #include <MPbk2ApplicationServices.h>
       
    42 #include <Pbk2UID.h>
       
    43 #include <csxhelp/phob.hlp.hrh>
       
    44 
       
    45 // Virtual Phonebook
       
    46 #include <MVPbkSimPhone.h>
       
    47 #include <CVPbkContactManager.h>
       
    48 #include <MVPbkContactStoreList.h>
       
    49 #include <VPbkContactStoreUris.h>
       
    50 #include <TVPbkContactStoreUriPtr.h>
       
    51 #include <MVPbkContactStore.h>
       
    52 #include <MVPbkContactStoreInfo.h>
       
    53 #include <MVPbkStoreContact.h>
       
    54 #include <MVPbkContactFieldData.h>
       
    55 #include <MVPbkContactFieldTextData.h>
       
    56 #include <CVPbkFieldTypeSelector.h>
       
    57 #include <MVPbkContactLink.h>
       
    58 #include <MVPbkContactOperationBase.h>
       
    59 
       
    60 // System includes
       
    61 #include <aknnavide.h>
       
    62 #include <aknnavi.h>
       
    63 #include <StringLoader.h>
       
    64 #include <eikmenup.h>
       
    65 #include <barsread.h>
       
    66 #include <aknnotewrappers.h>
       
    67 #include <AknUtils.h>
       
    68 #include <AiwCommon.hrh>
       
    69 #include <avkon.hrh>
       
    70 
       
    71 /// Unnamed namespace for local definitions
       
    72 namespace {
       
    73 
       
    74 #ifdef _DEBUG
       
    75 
       
    76 enum TPanicCode
       
    77     {
       
    78     EAddFindTextL_Logic = 0
       
    79     };
       
    80 
       
    81 void Panic(TInt aReason)
       
    82     {
       
    83     _LIT(KPanicText, "CPbk2CreateNewContactCmd");
       
    84     User::Panic(KPanicText, aReason);
       
    85     }
       
    86 #endif // _DEBUG
       
    87 
       
    88 /**
       
    89  * Checks is the given field type included in
       
    90  * the given selection.
       
    91  *
       
    92  * @param aResourceId   Selector's resource id.
       
    93  * @param aFieldType    The field type to check.
       
    94  * @param aManager      Virtual Phonebook contact manager.
       
    95  * @return  ETrue if field type is included.
       
    96  */
       
    97 TBool IsFieldTypeIncludedL(
       
    98         const MVPbkFieldType& aFieldType,
       
    99         const CVPbkContactManager& aManager,
       
   100         const TInt aResourceId )
       
   101     {
       
   102     // Get the field type
       
   103     TResourceReader resReader;
       
   104     CCoeEnv::Static()->CreateResourceReaderLC
       
   105         (resReader, aResourceId);
       
   106 
       
   107     CVPbkFieldTypeSelector* selector =
       
   108         CVPbkFieldTypeSelector::NewL(resReader, aManager.FieldTypes());
       
   109     CleanupStack::PopAndDestroy(); // resReader
       
   110 
       
   111     TBool ret = selector->IsFieldTypeIncluded(aFieldType);
       
   112     delete selector;
       
   113     return ret;
       
   114     }
       
   115 
       
   116 /**
       
   117  * Displays a note.
       
   118  *
       
   119  * @param aResourceId   Note resource.
       
   120  */
       
   121 void ShowNoteL( TInt aResourceId )
       
   122     {
       
   123     HBufC* prompt = StringLoader::LoadLC( aResourceId );
       
   124     CAknInformationNote* dlg = new ( ELeave ) CAknInformationNote( EFalse );
       
   125     dlg->ExecuteLD( *prompt );
       
   126     CleanupStack::PopAndDestroy(); // prompt
       
   127     }
       
   128 
       
   129 /**
       
   130  * Returns ETrue if shift is depressed in given key event.
       
   131  *
       
   132  * @param aKeyEvent     Key event.
       
   133  * @return  ETrue if shift is pressed.
       
   134  */
       
   135 inline TBool ShiftDown
       
   136         (const TKeyEvent& aKeyEvent)
       
   137     {
       
   138     return (aKeyEvent.iModifiers &
       
   139         (EModifierShift | EModifierLeftShift | EModifierRightShift)) != 0;
       
   140     }
       
   141 
       
   142 } /// namespace
       
   143 
       
   144 // --------------------------------------------------------------------------
       
   145 // CPsu2FixedDialingView::CPsu2FixedDialingView
       
   146 // --------------------------------------------------------------------------
       
   147 //
       
   148 CPsu2FixedDialingView::CPsu2FixedDialingView(
       
   149         CPbk2UIExtensionView& aExtensionView,
       
   150         CPsu2ViewManager& aViewManager ) :
       
   151     CPsu2NameListViewBase( aExtensionView, aViewManager ),
       
   152     iShowFdnNotActiveNote( ETrue )
       
   153     {
       
   154     }
       
   155 
       
   156 // --------------------------------------------------------------------------
       
   157 // CPsu2FixedDialingView::~CPsu2FixedDialingView
       
   158 // --------------------------------------------------------------------------
       
   159 //
       
   160 CPsu2FixedDialingView::~CPsu2FixedDialingView()
       
   161     {
       
   162     delete iFdnCall;
       
   163     delete iContactLink;
       
   164     delete iContact;
       
   165     delete iContactRetriever;
       
   166     delete iWaitOtherComplete;
       
   167     }
       
   168 
       
   169 // --------------------------------------------------------------------------
       
   170 // CPsu2FixedDialingView::NewL
       
   171 // --------------------------------------------------------------------------
       
   172 //
       
   173 CPsu2FixedDialingView* CPsu2FixedDialingView::NewL(
       
   174         CPbk2UIExtensionView& aExtensionView,
       
   175         CPsu2ViewManager& aViewManager )
       
   176     {
       
   177     CPsu2FixedDialingView* self = new (ELeave) CPsu2FixedDialingView(
       
   178             aExtensionView, aViewManager );
       
   179     CleanupStack::PushL( self );
       
   180     self->ConstructL();
       
   181     CleanupStack::Pop( self );
       
   182     return self;
       
   183     }
       
   184 
       
   185 // --------------------------------------------------------------------------
       
   186 // CPsu2FixedDialingView::ConstructL
       
   187 // --------------------------------------------------------------------------
       
   188 //
       
   189 void CPsu2FixedDialingView::ConstructL()
       
   190     {
       
   191     iFdnStore =
       
   192         Phonebook2::Pbk2AppUi()->ApplicationServices().ContactManager().
       
   193             ContactStoresL().Find
       
   194                 ( VPbkContactStoreUris::SimGlobalFdnUri() );
       
   195     }
       
   196 
       
   197 // --------------------------------------------------------------------------
       
   198 // CPsu2FixedDialingView::HandleCommandKeyL
       
   199 // --------------------------------------------------------------------------
       
   200 //
       
   201 TBool CPsu2FixedDialingView::HandleCommandKeyL
       
   202         ( const TKeyEvent& aKeyEvent, TEventCode aType )
       
   203     {
       
   204     const TInt count = iControl->NumberOfContacts();
       
   205     const TBool marked = iControl->ContactsMarked();
       
   206     TBool itemSpecCommEnabled = Phonebook2::Pbk2AppUi()->ActiveView()->MenuBar()->ItemSpecificCommandsEnabled();
       
   207     
       
   208     if ( aType == EEventKey )
       
   209         {
       
   210         if ( itemSpecCommEnabled && ( aKeyEvent.iCode == EKeyOK || aKeyEvent.iCode == EKeyEnter ) )
       
   211             {
       
   212             if (!ShiftDown(aKeyEvent))  // pure OK/Enter key
       
   213                 {
       
   214                 if ( marked || count <= 0 )
       
   215                     {
       
   216                     iExtensionView.LaunchPopupMenuL(
       
   217                         R_PSU2_FIXED_DIALING_CONTEXT_MENUBAR );
       
   218                     }
       
   219                 else
       
   220                     {
       
   221                     if ( iControl->NumberOfContacts() > 0 )
       
   222                         {
       
   223                         OpenInfoViewCmdL( *iControl );
       
   224                         }
       
   225                     }
       
   226                 return ETrue;
       
   227                 }
       
   228             }
       
   229         // Send key
       
   230         if ( itemSpecCommEnabled && aKeyEvent.iCode == EKeyPhoneSend )
       
   231             {
       
   232             if ( count > 0 && !marked )
       
   233                 {
       
   234                 CreateCallL( EPbk2CmdCall );
       
   235                 }
       
   236             return ETrue;
       
   237             }
       
   238         // Delete key
       
   239         else if ( ( itemSpecCommEnabled || marked ) && aKeyEvent.iCode == EKeyBackspace )
       
   240             {
       
   241              if ( iControl->FindTextL() == KNullDesC )
       
   242                 {
       
   243                 HandleCommandL( EPbk2CmdDeleteMe );
       
   244                 return ETrue;
       
   245                 }
       
   246             }
       
   247         else if ( aKeyEvent.iScanCode == EStdKeyNo )
       
   248             {
       
   249             // 'Red' button pressed, clear PIN2 query info
       
   250             iViewManager.SecUi().Reset();
       
   251             iShowFdnNotActiveNote = ETrue;
       
   252             }
       
   253         else { /* Empty to make PC-lint happy */ }
       
   254         }
       
   255         
       
   256     if ( ShiftDown( aKeyEvent ) )
       
   257         {
       
   258         // Update cbas when shift and msk is pressed.
       
   259         UpdateCbasL();
       
   260         }
       
   261 
       
   262     return CPsu2NameListViewBase::HandleCommandKeyL( aKeyEvent, aType );
       
   263     }
       
   264 
       
   265 // --------------------------------------------------------------------------
       
   266 // CPsu2FixedDialingView::HandlePointerEventL
       
   267 // --------------------------------------------------------------------------
       
   268 //
       
   269 void CPsu2FixedDialingView::HandlePointerEventL(
       
   270         const TPointerEvent& /*aPointerEvent*/ )
       
   271     {
       
   272     // nothing to do
       
   273     }
       
   274 
       
   275 // --------------------------------------------------------------------------
       
   276 // CPsu2FixedDialingView::DoActivateL
       
   277 // --------------------------------------------------------------------------
       
   278 //
       
   279 void CPsu2FixedDialingView::DoActivateL(
       
   280         const TVwsViewId& aPrevViewId,
       
   281         TUid aCustomMessageId,
       
   282         const TDesC8& aCustomMessage)
       
   283     {
       
   284     // Load FDN title
       
   285     HBufC* title = StringLoader::LoadLC(R_TEXT_FDN_LIST);
       
   286     // Create FDN application context pane icon
       
   287     TContextPaneIcon icon(EPsu2qgn_menu_simfdn);
       
   288     CEikImage* image = icon.CreateLC();
       
   289 
       
   290     // Set up view
       
   291     MPbk2ViewActivationTransaction* viewActivationTransaction =
       
   292         Phonebook2::Pbk2AppUi()->Pbk2ViewExplorer()->
       
   293             HandleViewActivationLC
       
   294                 ( iExtensionView.Id(), aPrevViewId, title, image,
       
   295                   Phonebook2::EUpdateNaviPane |
       
   296                   Phonebook2::EUpdateContextPane |
       
   297                   Phonebook2::EUpdateTitlePane );
       
   298 
       
   299     // Call base class
       
   300     CPsu2NameListViewBase::DoActivateL(
       
   301             aPrevViewId, aCustomMessageId, aCustomMessage );
       
   302 
       
   303     viewActivationTransaction->Commit();
       
   304     CleanupStack::PopAndDestroy(3, title); // viewActivationTransaction,
       
   305 
       
   306     // Update navi pane                    // icon, title
       
   307     UpdateNaviPaneTextL();
       
   308    
       
   309     if( aPrevViewId.iViewUid != TUid::Uid( EPsu2FixedDialingInfoViewId ) )
       
   310     	{
       
   311     	iShowFdnNotActiveNote = ETrue;
       
   312     	// Clear PIN2 query info
       
   313     	iViewManager.SecUi().Reset();
       
   314     	}
       
   315     // Don't show note here, because there are many controls intializing, drawing and layouting 
       
   316     // will make the note flash. So delay the note pop up time to aviod the problem.
       
   317     iWaitOtherComplete = CIdle::NewL( CActive::EPriorityIdle );
       
   318     TCallBack callback( WaitOtherCompleteL, this );
       
   319     iWaitOtherComplete->Start( callback );
       
   320     }
       
   321 
       
   322 // --------------------------------------------------------------------------
       
   323 // CPsu2FixedDialingView::WaitOtherComplete
       
   324 // --------------------------------------------------------------------------
       
   325 //
       
   326 TInt CPsu2FixedDialingView::WaitOtherCompleteL( TAny* object )
       
   327     {
       
   328     STATIC_CAST( CPsu2FixedDialingView*, object )->CheckFDNActivityL();
       
   329     return 0;
       
   330     }
       
   331 
       
   332 // --------------------------------------------------------------------------
       
   333 // CPsu2FixedDialingView::CheckFDNActivity
       
   334 // --------------------------------------------------------------------------
       
   335 //
       
   336 void CPsu2FixedDialingView::CheckFDNActivityL()
       
   337     {
       
   338     if ( iShowFdnNotActiveNote )
       
   339         {
       
   340         if ( !iViewManager.SecUi().IsFDNActive() )
       
   341             {
       
   342             ShowNoteL( R_QTN_FDN_NOTE_NOT_ACTIVE );
       
   343             }
       
   344         iShowFdnNotActiveNote = EFalse;
       
   345         }
       
   346     }
       
   347 
       
   348 // --------------------------------------------------------------------------
       
   349 // CPsu2FixedDialingView::DoDeactivate
       
   350 // --------------------------------------------------------------------------
       
   351 //
       
   352 void CPsu2FixedDialingView::DoDeactivate()
       
   353     {
       
   354     DestroyNaviPaneText();
       
   355     CPsu2NameListViewBase::DoDeactivate();
       
   356     
       
   357     delete iWaitOtherComplete;
       
   358     iWaitOtherComplete = NULL;
       
   359     }
       
   360 
       
   361 // --------------------------------------------------------------------------
       
   362 // CPsu2FixedDialingView::HandleCommandL
       
   363 // --------------------------------------------------------------------------
       
   364 //
       
   365 void CPsu2FixedDialingView::HandleCommandL(TInt aCommand)
       
   366     {
       
   367     iCommandIsBeingHandled = ETrue;
       
   368     if ( Phonebook2::Pbk2AppUi()->ApplicationServices().CommandHandlerL()->
       
   369             ServiceCmdByMenuCmd ( aCommand ) == KAiwCmdCall )
       
   370         {
       
   371         CreateCallL( aCommand );
       
   372         }
       
   373     else
       
   374         {
       
   375         switch( aCommand )
       
   376             {
       
   377             case EPsu2CmdOpenFixedDialingInfoView: // FALLTHROUGH
       
   378             case EPsu2CmdActivateFDN: // FALLTHROUGH
       
   379             case EPsu2CmdDeactivateFDN: // FALLTHROUGH
       
   380             case EPsu2CmdNewContact: // FALLTHROUGH
       
   381             case EPsu2CmdCopyFromContacts: // FALLTHROUGH
       
   382             case EPbk2CmdEditMe:        // FALLTHROUGH
       
   383             case EPbk2CmdDeleteMe:
       
   384                 {
       
   385                 if ( iViewManager.StoreAvailableL() )
       
   386                     {
       
   387                     switch( aCommand )
       
   388                         {
       
   389                         case EPsu2CmdOpenFixedDialingInfoView:
       
   390                             {
       
   391                             OpenInfoViewCmdL( *iControl );
       
   392                             break;
       
   393                             }
       
   394                         case EPsu2CmdActivateFDN:
       
   395                             {
       
   396                             ActivateFDNCmdL();
       
   397                             break;
       
   398                             }
       
   399                         case EPsu2CmdDeactivateFDN:
       
   400                             {
       
   401                             DeactivateFDNCmdL();
       
   402                             break;
       
   403                             }
       
   404                         case EPsu2CmdNewContact:
       
   405                             {
       
   406                             if ( !FdnStoreFullL() &&
       
   407                                 iViewManager.SecUi().ConfirmPin2L() )
       
   408                                 {
       
   409                                 CreateNewFdnContactL();
       
   410                                 }
       
   411                             break;
       
   412                             }
       
   413                         case EPsu2CmdCopyFromContacts:
       
   414                             {
       
   415                             if ( !FdnStoreFullL() &&
       
   416                                     iViewManager.SecUi().ConfirmPin2L() )
       
   417                                 {
       
   418                                 CPsu2NameListViewBase::HandleCommandL( aCommand );
       
   419                                 }
       
   420                             break;
       
   421                             }
       
   422                         case EPbk2CmdEditMe:
       
   423                             {
       
   424                             if ( iViewManager.SecUi().ConfirmPin2L() )
       
   425                                 {
       
   426                                 delete iContactLink;
       
   427                                 iContactLink = NULL;
       
   428                                 iContactLink = 
       
   429                                     iControl->FocusedContactL()->CreateLinkLC();
       
   430                                 CleanupStack::Pop();
       
   431                                 iContactRetriever = 
       
   432                                     Phonebook2::Pbk2AppUi()->ApplicationServices().
       
   433                                         ContactManager().RetrieveContactL(
       
   434                                             *iContactLink, *this );
       
   435                                 }
       
   436                             break;
       
   437                             }
       
   438                         default: 
       
   439                             {
       
   440                             if ( iViewManager.SecUi().ConfirmPin2L() )
       
   441                                 {
       
   442                                 CPsu2NameListViewBase::HandleCommandL( aCommand );
       
   443                                 }
       
   444                             break;
       
   445                             }
       
   446                         }
       
   447                     }
       
   448                 break;
       
   449                 }
       
   450             case EPbk2CmdExit:          // FALLTHROUGH
       
   451             case EAknSoftkeyBack:
       
   452             case EAknCmdHideInBackground:
       
   453                 {
       
   454                 // Clear PIN2 query info
       
   455                 iViewManager.SecUi().Reset();
       
   456                 // If the note has not popped up, cancel the popping up of the note.
       
   457                 if( iWaitOtherComplete->IsActive() )
       
   458                     {
       
   459                     iWaitOtherComplete->Cancel();
       
   460                     }
       
   461                 iShowFdnNotActiveNote = ETrue;
       
   462                 
       
   463                 if ( aCommand == EAknCmdHideInBackground && iDlgEliminator )
       
   464                     {
       
   465                     iDlgEliminator->RequestExitL( EKeyEscape );
       
   466                     }
       
   467                 
       
   468                 CPsu2NameListViewBase::HandleCommandL( aCommand );
       
   469                 break;
       
   470                 }
       
   471             default:
       
   472                 {
       
   473                 CPsu2NameListViewBase::HandleCommandL( aCommand );
       
   474                 break;
       
   475                 }
       
   476             }
       
   477         }
       
   478     // Update CBAs, if command handler is consuming the command
       
   479     // postcommandexecution is updating cbas
       
   480     UpdateCbasL();
       
   481     iCommandIsBeingHandled = EFalse;
       
   482     }
       
   483 
       
   484 // --------------------------------------------------------------------------
       
   485 // CPsu2FixedDialingView::DynInitMenuPaneL
       
   486 // --------------------------------------------------------------------------
       
   487 //
       
   488 void CPsu2FixedDialingView::DynInitMenuPaneL(
       
   489         TInt aResourceId,
       
   490         CEikMenuPane* aMenuPane)
       
   491     {
       
   492     const TInt count = iControl->NumberOfContacts();
       
   493     const TBool marked = iControl->ContactsMarked();
       
   494 
       
   495     switch( aResourceId )
       
   496         {
       
   497         case R_PSU2_FIXED_DIALING_OPEN_MENUPANE:
       
   498             {
       
   499             if ( count <= 0 || marked )
       
   500                 {
       
   501                 aMenuPane->SetItemDimmed
       
   502                     ( EPsu2CmdOpenFixedDialingInfoView , ETrue );
       
   503                 }
       
   504             break;
       
   505             }
       
   506         case R_PSU2_FIXED_DIALING_MENUPANE:
       
   507             {
       
   508             if ( iViewManager.SecUi().IsFDNActive() )
       
   509                 {
       
   510                 aMenuPane->SetItemDimmed( EPsu2CmdActivateFDN, ETrue );
       
   511                 }
       
   512             else
       
   513                 {
       
   514                 aMenuPane->SetItemDimmed( EPsu2CmdDeactivateFDN, ETrue );
       
   515                 }
       
   516             if ( count <= 0 )
       
   517                 {
       
   518                 aMenuPane->SetItemDimmed( EPbk2CmdEditMe , ETrue );
       
   519                 aMenuPane->SetItemDimmed( EPbk2CmdDeleteMe , ETrue );
       
   520                 }
       
   521             else
       
   522                 {
       
   523                 if( marked )
       
   524                     {
       
   525                     aMenuPane->SetItemDimmed( EPsu2CmdNewContact , ETrue );
       
   526                     aMenuPane->SetItemDimmed( EPbk2CmdEditMe , ETrue );
       
   527                     aMenuPane->SetItemSpecific( EPbk2CmdDeleteMe, EFalse );
       
   528                     }
       
   529                 else
       
   530                     {
       
   531                     aMenuPane->SetItemSpecific( EPbk2CmdDeleteMe, ETrue );
       
   532                     }
       
   533                 }
       
   534             break;
       
   535             }
       
   536         case R_PSU2_FIXED_DIALING_COPY_MENUPANE:        // FALLTHROUGH
       
   537         case R_PSU2_FIXED_DIALING_COPY_CONTEXT_MENUPANE:
       
   538             {
       
   539             if ( count <= 0 )
       
   540                 {
       
   541                 aMenuPane->SetItemDimmed( EPbk2CmdCopy, ETrue );
       
   542                 }
       
   543             if ( marked )
       
   544                 {
       
   545                 aMenuPane->SetItemSpecific( EPbk2CmdCopy, EFalse );
       
   546                 aMenuPane->SetItemDimmed( EPsu2CmdCopyFromContacts, ETrue );
       
   547                 }
       
   548             else
       
   549                 {
       
   550                 aMenuPane->SetItemSpecific( EPbk2CmdCopy, ETrue);
       
   551                 }
       
   552             break;
       
   553             }
       
   554         case R_PSU2_FIXED_DIALING_DELETE_MENUPANE:
       
   555             {
       
   556             if ( count <= 0 )
       
   557                 {
       
   558                 aMenuPane->SetItemDimmed( EPbk2CmdDeleteMe , ETrue );
       
   559                 }
       
   560             break;
       
   561             }
       
   562         case R_PSU2_FIXED_DIALING_NEWCONTACT_MENUPANE:
       
   563             {
       
   564             if ( count > 0 )
       
   565                 {
       
   566                 aMenuPane->SetItemDimmed( EPsu2CmdNewContact , ETrue );
       
   567                 }
       
   568             break;
       
   569             }
       
   570         default:
       
   571             {
       
   572             CPsu2NameListViewBase::DynInitMenuPaneL
       
   573                 ( aResourceId, aMenuPane );
       
   574             break;
       
   575             }
       
   576         };
       
   577     }
       
   578 
       
   579 // --------------------------------------------------------------------------
       
   580 // CPsu2FixedDialingView::UpdateCbasL
       
   581 // --------------------------------------------------------------------------
       
   582 //
       
   583 void CPsu2FixedDialingView::UpdateCbasL()
       
   584     {
       
   585     if ( iControl )
       
   586         {
       
   587         if ( iControl->NumberOfContacts() > 0 && !iControl->ContactsMarked() )
       
   588             {
       
   589             // Set middle softkey as Open.
       
   590             iExtensionView.Cba()->SetCommandSetL(
       
   591                     R_PSU_FDN_SOFTKEYS_OPTIONS_BACK_OPEN );
       
   592             iExtensionView.Cba()->DrawDeferred();
       
   593             }
       
   594         else
       
   595             {
       
   596             // Set middle softkey as Context menu.
       
   597             iExtensionView.Cba()->SetCommandSetL(
       
   598                     R_PSU_SOFTKEYS_OPTIONS_BACK_CONTEXT );
       
   599             iExtensionView.Cba()->DrawDeferred();
       
   600             // Change context menu when marked items
       
   601             iExtensionView.MenuBar()->SetContextMenuTitleResourceId(
       
   602                     R_PSU2_FIXED_DIALING_CONTEXT_MENUBAR );
       
   603             }
       
   604         }
       
   605     }
       
   606 
       
   607 // --------------------------------------------------------------------------
       
   608 // CPsu2FixedDialingView::NameListControlResourceId
       
   609 // --------------------------------------------------------------------------
       
   610 //
       
   611 TInt CPsu2FixedDialingView::NameListControlResourceId() const
       
   612     {
       
   613     return R_PSU2_FIXED_DIALING_NAME_LIST_CONTROL;
       
   614     }
       
   615 
       
   616 // --------------------------------------------------------------------------
       
   617 // CPsu2FixedDialingView::ContactEditingComplete
       
   618 // --------------------------------------------------------------------------
       
   619 //
       
   620 void CPsu2FixedDialingView::ContactEditingComplete(
       
   621         MVPbkStoreContact* aEditedContact)
       
   622     {
       
   623     if( iControl )
       
   624         {
       
   625         // Reset Find before setting the focus because if new contact is created
       
   626         // through find box, ResetFindL corrupts the focus.
       
   627         TRAP_IGNORE( iControl->ResetFindL() );
       
   628         if (aEditedContact)
       
   629             {
       
   630             // Focus the created contact
       
   631             TRAPD( error, iControl->SetFocusedContactL( *aEditedContact ) );
       
   632             if ( error != KErrNone )
       
   633                 {
       
   634                 CCoeEnv::Static()->HandleError( error );
       
   635                 }
       
   636             }
       
   637         }
       
   638     delete aEditedContact; // not needed anymore
       
   639     }
       
   640 
       
   641 // --------------------------------------------------------------------------
       
   642 // CPsu2FixedDialingView::ContactEditingDeletedContact
       
   643 // --------------------------------------------------------------------------
       
   644 //
       
   645 void CPsu2FixedDialingView::ContactEditingDeletedContact(
       
   646         MVPbkStoreContact* aEditedContact)
       
   647     {
       
   648     delete aEditedContact; // not needed anymore
       
   649     }
       
   650 
       
   651 // --------------------------------------------------------------------------
       
   652 // CPsu2FixedDialingView::ContactEditingAborted
       
   653 // --------------------------------------------------------------------------
       
   654 //
       
   655 void CPsu2FixedDialingView::ContactEditingAborted()
       
   656     {
       
   657     // Do nothing
       
   658     }
       
   659     
       
   660 // --------------------------------------------------------------------------
       
   661 // CPsu2FixedDialingView::VPbkSingleContactOperationComplete
       
   662 // --------------------------------------------------------------------------
       
   663 //    
       
   664 void CPsu2FixedDialingView::VPbkSingleContactOperationComplete(
       
   665         MVPbkContactOperationBase& aOperation,
       
   666         MVPbkStoreContact* aContact )
       
   667     {
       
   668     
       
   669     if ( iContactRetriever == &aOperation && aContact)
       
   670         {
       
   671         delete iContactRetriever;
       
   672         iContactRetriever = NULL;
       
   673         
       
   674         delete iContact;    
       
   675         iContact = aContact;     
       
   676                
       
   677         TRAPD( error, iContact->LockL(*this) );
       
   678         if ( error != KErrNone )
       
   679             {
       
   680             CCoeEnv::Static()->HandleError(error);
       
   681             } 
       
   682         }      
       
   683     }
       
   684         
       
   685 // --------------------------------------------------------------------------
       
   686 // CPsu2FixedDialingView::VPbkSingleContactOperationFailed
       
   687 // --------------------------------------------------------------------------
       
   688 //        
       
   689 void CPsu2FixedDialingView::VPbkSingleContactOperationFailed(
       
   690         MVPbkContactOperationBase& aOperation, 
       
   691         TInt aError )
       
   692     {
       
   693     if ( iContactRetriever == &aOperation )
       
   694         {
       
   695         delete iContactRetriever;
       
   696         iContactRetriever = NULL;
       
   697         
       
   698         CCoeEnv::Static()->HandleError(aError);
       
   699         }    
       
   700     }    
       
   701     
       
   702 // --------------------------------------------------------------------------
       
   703 // CPsu2FixedDialingView::ContactOperationCompleted
       
   704 // --------------------------------------------------------------------------
       
   705 //     
       
   706 void CPsu2FixedDialingView::ContactOperationCompleted(
       
   707         TContactOpResult /*aResult*/ )
       
   708     {
       
   709     TRAPD(result, EditFdnContactL());
       
   710         
       
   711     if (result != KErrNone)
       
   712         {
       
   713         CCoeEnv::Static()->HandleError(result);
       
   714         }
       
   715     }
       
   716 
       
   717 // --------------------------------------------------------------------------
       
   718 // CPsu2FixedDialingView::ContactOperationFailed
       
   719 // --------------------------------------------------------------------------
       
   720 //     
       
   721 void CPsu2FixedDialingView::ContactOperationFailed(
       
   722         TContactOp /*aOpCode*/, 
       
   723         TInt aErrorCode, 
       
   724         TBool /*aErrorNotified*/ )
       
   725     {
       
   726     CCoeEnv::Static()->HandleError(aErrorCode);
       
   727     }    
       
   728 
       
   729 // --------------------------------------------------------------------------
       
   730 // CPsu2FixedDialingView::UpdateNaviPaneTextL
       
   731 // --------------------------------------------------------------------------
       
   732 //
       
   733 void CPsu2FixedDialingView::UpdateNaviPaneTextL()
       
   734     {
       
   735     HBufC* text = NULL;
       
   736     if (iViewManager.SecUi().IsFDNActive())
       
   737         {
       
   738         text = StringLoader::LoadLC(R_QTN_FDN_ACTIVE);
       
   739         }
       
   740     else
       
   741         {
       
   742         text = StringLoader::LoadLC(R_QTN_FDN_DEACTIVE);
       
   743         }
       
   744 
       
   745     DestroyNaviPaneText();
       
   746     if (!iNaviPane)
       
   747         {
       
   748         iNaviPane = static_cast<CAknNavigationControlContainer*>(
       
   749             iAvkonAppUi->StatusPane()->ControlL(
       
   750             TUid::Uid(EEikStatusPaneUidNavi)));
       
   751         }
       
   752     iNaviDecorator = iNaviPane->CreateNavigationLabelL(*text);
       
   753     iNaviPane->PushL(*iNaviDecorator);
       
   754 
       
   755     CleanupStack::PopAndDestroy(); // text
       
   756     }
       
   757 
       
   758 // --------------------------------------------------------------------------
       
   759 // CPsu2FixedDialingView::DestroyNaviPaneText
       
   760 // --------------------------------------------------------------------------
       
   761 //
       
   762 void CPsu2FixedDialingView::DestroyNaviPaneText()
       
   763     {
       
   764     if (iNaviPane && iNaviDecorator)
       
   765         {
       
   766         iNaviPane->Pop(iNaviDecorator);
       
   767         }
       
   768     delete iNaviDecorator;
       
   769     iNaviDecorator = NULL;
       
   770     }
       
   771 
       
   772 // --------------------------------------------------------------------------
       
   773 // CPsu2FixedDialingView::OpenInfoViewCmdL
       
   774 // --------------------------------------------------------------------------
       
   775 //
       
   776 void CPsu2FixedDialingView::OpenInfoViewCmdL
       
   777         (MPbk2ContactUiControl& aUiControl) const
       
   778     {
       
   779     if (!aUiControl.ContactsMarked())
       
   780         {
       
   781         CPbk2ViewState* state = aUiControl.ControlStateL();
       
   782         CleanupStack::PushL(state);
       
   783         Phonebook2::Pbk2AppUi()->Pbk2ViewExplorer()->
       
   784             ActivatePhonebook2ViewL
       
   785                 (TUid::Uid(EPsu2FixedDialingInfoViewId), state);
       
   786         CleanupStack::PopAndDestroy( state );  // state
       
   787         aUiControl.UpdateAfterCommandExecution();
       
   788         }
       
   789     }
       
   790 
       
   791 // --------------------------------------------------------------------------
       
   792 // CPsu2FixedDialingView::ActivateFDNCmdL
       
   793 // --------------------------------------------------------------------------
       
   794 //
       
   795 void CPsu2FixedDialingView::ActivateFDNCmdL()
       
   796     {
       
   797     if ( !iViewManager.SecUi().IsFDNActive() )
       
   798         {
       
   799         iViewManager.SecUi().ActivateFDNL();
       
   800         UpdateNaviPaneTextL();
       
   801         }
       
   802     }
       
   803 
       
   804 // --------------------------------------------------------------------------
       
   805 // CPsu2FixedDialingView::DeactivateFDNCmdL
       
   806 // --------------------------------------------------------------------------
       
   807 //
       
   808 void CPsu2FixedDialingView::DeactivateFDNCmdL()
       
   809     {
       
   810     if ( iViewManager.SecUi().IsFDNActive() )
       
   811         {
       
   812         iViewManager.SecUi().DeactivateFDNL();
       
   813         UpdateNaviPaneTextL();
       
   814         }
       
   815     }
       
   816 
       
   817 // --------------------------------------------------------------------------
       
   818 // CPsu2FixedDialingView::CreateNewFdnContactL
       
   819 // --------------------------------------------------------------------------
       
   820 //
       
   821 void CPsu2FixedDialingView::CreateNewFdnContactL()
       
   822     {
       
   823     MVPbkStoreContact* newFdnContact = iFdnStore->CreateNewContactLC();
       
   824 
       
   825     // Add find text to last name field, if any
       
   826     AddFindTextL(*newFdnContact);
       
   827 
       
   828     TUint32 flags = TPbk2ContactEditorParams::ENewContact;
       
   829     
       
   830     TCoeHelpContext helpContext;
       
   831     helpContext.iMajor.iUid = KPbk2UID3;
       
   832     helpContext.iContext = KFDN_HLP_FDN_NUM_EDIT_VIEW;
       
   833         
       
   834     TPbk2ContactEditorParams params( flags, NULL, &helpContext );
       
   835     CPbk2ContactEditorDlg* editor =
       
   836         CPbk2ContactEditorDlg::NewL(params, newFdnContact, *this);
       
   837     CleanupStack::Pop(); // newFdnContact, whose ownership was taken away
       
   838     
       
   839     iDlgEliminator = editor;
       
   840     editor->ExecuteLD();
       
   841     iDlgEliminator = NULL;
       
   842     }
       
   843 
       
   844 
       
   845 // --------------------------------------------------------------------------
       
   846 // CPsu2FixedDialingView::AddFindTextL
       
   847 // --------------------------------------------------------------------------
       
   848 //
       
   849 void CPsu2FixedDialingView::AddFindTextL(MVPbkStoreContact& aContact)
       
   850     {
       
   851     const TDesC& findText = iControl->FindTextL();
       
   852 
       
   853     if (findText != KNullDesC)
       
   854         {
       
   855         CPbk2FieldPropertyArray& fieldProperties =
       
   856             Phonebook2::Pbk2AppUi()->ApplicationServices().FieldProperties();
       
   857 
       
   858         const TInt fieldCount = fieldProperties.Count();
       
   859         for (TInt i=0; i<fieldCount; ++i)
       
   860             {
       
   861             const MPbk2FieldProperty& prop = fieldProperties.At(i);
       
   862 
       
   863             if (IsFieldTypeIncludedL(prop.FieldType(),
       
   864                     Phonebook2::Pbk2AppUi()->ApplicationServices().
       
   865                         ContactManager(),
       
   866                     R_PHONEBOOK2_LAST_NAME_SELECTOR))
       
   867                 {
       
   868                 MVPbkStoreContactField* field = aContact.CreateFieldLC
       
   869                     (prop.FieldType());
       
   870 
       
   871                 __ASSERT_DEBUG(field->FieldData().DataType() ==
       
   872                     EVPbkFieldStorageTypeText, Panic(EAddFindTextL_Logic));
       
   873 
       
   874                 MVPbkContactFieldTextData* fieldData =
       
   875                     &MVPbkContactFieldTextData::Cast(field->FieldData());
       
   876                 //The max length of a name in the Sim Card
       
   877                 TInt maxLength = fieldData->MaxLength();
       
   878                 fieldData->SetTextL( findText.Left( maxLength ));
       
   879 
       
   880                 TInt index = aContact.AddFieldL(field);
       
   881                 CleanupStack::Pop(); // field
       
   882                 break;
       
   883                 }
       
   884             }
       
   885         }
       
   886     }
       
   887 
       
   888 // --------------------------------------------------------------------------
       
   889 // CPsu2FixedDialingView::FdnStoreFullL
       
   890 // --------------------------------------------------------------------------
       
   891 //
       
   892 TBool CPsu2FixedDialingView::FdnStoreFullL()
       
   893     {
       
   894     TBool ret = EFalse;
       
   895     const MVPbkContactStoreInfo& storeInfo = iFdnStore->StoreInfo();
       
   896     if ( storeInfo.MaxNumberOfContactsL() <= storeInfo.NumberOfContactsL() )
       
   897         {
       
   898         ret = ETrue;
       
   899         ShowNoteL( R_QTN_FDN_LIST_FULL );
       
   900         }
       
   901     return ret;
       
   902     }
       
   903 
       
   904 // --------------------------------------------------------------------------
       
   905 // CPsu2FixedDialingView::CreateCallL
       
   906 // --------------------------------------------------------------------------
       
   907 //
       
   908 void CPsu2FixedDialingView::CreateCallL( TInt aCommand )
       
   909     {
       
   910     if ( !iFdnCall )
       
   911         {
       
   912         iFdnCall = CPsu2FixedDialingCall::NewL
       
   913             ( Phonebook2::Pbk2AppUi()->ApplicationServices().ContactManager(),
       
   914               *Phonebook2::Pbk2AppUi()->ApplicationServices().
       
   915                 CommandHandlerL(),
       
   916               iExtensionView );
       
   917         }
       
   918 
       
   919     MVPbkContactLink* contactLink =
       
   920         iControl->FocusedContactL()->CreateLinkLC();
       
   921     CleanupStack::Pop(); // CreateCall takes contactLink ownership
       
   922     iFdnCall->CreateCallL( contactLink, aCommand );
       
   923     }
       
   924     
       
   925 // --------------------------------------------------------------------------
       
   926 // CPsu2FixedDialingView::EditFdnContactL
       
   927 // --------------------------------------------------------------------------
       
   928 //    
       
   929 void CPsu2FixedDialingView::EditFdnContactL()
       
   930     {
       
   931     TCoeHelpContext helpContext;
       
   932     helpContext.iMajor.iUid = KPbk2UID3;
       
   933     helpContext.iContext = KFDN_HLP_FDN_NUM_EDIT_VIEW;
       
   934     
       
   935     TPbk2ContactEditorParams params;
       
   936     params.iHelpContext = &helpContext;
       
   937         
       
   938     // create and execute editing dialog
       
   939     CPbk2ContactEditorDlg* dlg =
       
   940         CPbk2ContactEditorDlg::NewL( params, iContact, *this );
       
   941     iContact = NULL; // ownership went to editor
       
   942     
       
   943     iDlgEliminator = dlg;
       
   944     dlg->ExecuteLD();      
       
   945     iDlgEliminator = NULL;
       
   946     }    
       
   947 
       
   948 // --------------------------------------------------------------------------
       
   949 // CPsu2FixedDialingView::HandleControlEventL
       
   950 // --------------------------------------------------------------------------
       
   951 //    
       
   952 void CPsu2FixedDialingView::HandleControlEventL(
       
   953         MPbk2ContactUiControl& aControl,
       
   954         const TPbk2ControlEvent& aEvent )
       
   955     {
       
   956     const TInt count = iControl->NumberOfContacts();
       
   957     const TBool marked = iControl->ContactsMarked();
       
   958     
       
   959     switch ( aEvent.iEventType )
       
   960         {
       
   961         case TPbk2ControlEvent::EContactTapped:
       
   962         case TPbk2ControlEvent::EContactDoubleTapped:
       
   963             {
       
   964             if ( marked )
       
   965                 {
       
   966                 iExtensionView.LaunchPopupMenuL(
       
   967                     R_PSU2_FIXED_DIALING_CONTEXT_MENUBAR );
       
   968                 }
       
   969             else
       
   970                 {
       
   971                 // Open contact
       
   972                 HandleCommandL( EPsu2CmdOpenFixedDialingInfoView );
       
   973                 }
       
   974             break;
       
   975             }
       
   976         default:
       
   977             {
       
   978             CPsu2NameListViewBase::HandleControlEventL( aControl, aEvent );
       
   979             break;
       
   980             }
       
   981         }
       
   982     }
       
   983 
       
   984 //  End of File