wvuing/wvuiave/AppSrc/CCAContactDetailsDialog.cpp
changeset 0 094583676ce7
equal deleted inserted replaced
-1:000000000000 0:094583676ce7
       
     1 /*
       
     2 * Copyright (c) 2006 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:  Contact details dialog.
       
    15  *
       
    16 */
       
    17 
       
    18 
       
    19 // INCLUDE FILES
       
    20 #include	"CCAContactDetailsDialog.h"
       
    21 #include	"chatngclient.hrh"
       
    22 #include	"CCAAppUi.h"
       
    23 #include    "CCAUISessionManager.h"
       
    24 #include	"CCAAccessArray.h"
       
    25 #include	"CCAStatusPaneHandler.h"
       
    26 #include    "ChatDefinitions.h"
       
    27 #include    "CAExternalInterface.h"
       
    28 #include    "ChatDebugPrint.h"
       
    29 #include    "ChatDebugAssert.h"
       
    30 #include    "IMUtils.h"
       
    31 #include    "IMDialogUtils.h"
       
    32 #include    "IMNoteMapper.h"
       
    33 #include    "CAUtils.h"
       
    34 #include    "CCAContactEditor.h"
       
    35 #include    "ccafetchwaiter.h"
       
    36 #include    "ccasyncchecker.h"
       
    37 #include    "CCAApp.h"
       
    38 #include    "CCAContactSelectionDialog.h"
       
    39 #include 	"MCAContactEditPC.h"
       
    40 #include	"MCAProcessManager.h"
       
    41 #include    "CCAPCUtils.h"
       
    42 #include    "CCABlockingUI.h"
       
    43 #include    "MCABlockingPC.h"
       
    44 
       
    45 // The Settings have been moved to Cenrep (also retained in the Resource file),
       
    46 // so the enums for keys and central repository header is added here
       
    47 #include 	"VariantKeys.h"
       
    48 
       
    49 
       
    50 #include	<aknlists.h>
       
    51 #include	<ChatNG.rsg>
       
    52 #include	<aknpopup.h>
       
    53 #include	<AknMessageQueryDialog.h>
       
    54 #include	<stringloader.h>
       
    55 #include	<eikmenub.h>
       
    56 #include    <hlplch.h>
       
    57 #include    <csxhelp/imng.hlp.hrh>
       
    58 #include    <featmgr.h>
       
    59 #include    <IMPSerrors.H>
       
    60 
       
    61 // ================= MEMBER FUNCTIONS =======================
       
    62 
       
    63 // C++ default constructor can NOT contain any code, that
       
    64 // might leave.
       
    65 //
       
    66 CCAContactDetailsDialog::CCAContactDetailsDialog(
       
    67     TBool& aWasSaved,
       
    68     const HBufC* aListId,
       
    69     const TDesC& aNickname,
       
    70     TInt aIndex )
       
    71         :   iListId( aListId ),
       
    72         iNickname( aNickname ),
       
    73         iWasSaved( aWasSaved ),
       
    74         iOwnData( EFalse ),
       
    75         iValidContact( ETrue ),
       
    76     iIndexOfContact(aIndex),
       
    77     iMovingFlag( EFalse )
       
    78     {
       
    79     // nothing..
       
    80     }
       
    81 
       
    82 // ---------------------------------------------------------
       
    83 // CCAContactDetailsDialog::NewL
       
    84 // (other items were commented in a header).
       
    85 // ---------------------------------------------------------
       
    86 //
       
    87 CCAContactDetailsDialog* CCAContactDetailsDialog::NewL(
       
    88     TBool& aWasSaved,
       
    89     TInt aIndex,
       
    90     const TDesC& aListId,
       
    91     const TDesC& aNickname /* = KNullDesC */
       
    92 )
       
    93     {
       
    94     HBufC* list = aListId.AllocLC();
       
    95 
       
    96     CCAContactDetailsDialog* temp = new ( ELeave ) CCAContactDetailsDialog(
       
    97         aWasSaved,
       
    98         list,
       
    99         aNickname,
       
   100         aIndex
       
   101     );
       
   102 
       
   103     CleanupStack::Pop( list );
       
   104 
       
   105     CleanupStack::PushL( temp );
       
   106     temp->ConstructL();
       
   107     CleanupStack::Pop( temp );
       
   108     return temp;
       
   109     }
       
   110 
       
   111 // ---------------------------------------------------------
       
   112 // CCAContactDetailsDialog::ConstructL
       
   113 // (other items were commented in a header).
       
   114 // ---------------------------------------------------------
       
   115 //
       
   116 void CCAContactDetailsDialog::ConstructL()
       
   117     {
       
   118     CAknDialog::ConstructL( R_CHAT_CDETAILS_MENUBAR );
       
   119 
       
   120     CCAAppUi* appUi = static_cast<CCAAppUi*>( CCoeEnv::Static()->AppUi() );
       
   121     iTitlePane = appUi->CAStatusPane();
       
   122 
       
   123     iItemTextArray = new ( ELeave ) CDesCArrayFlat( 5 );
       
   124 
       
   125     iAliasEnabled = IMUtils::IntResourceValueL( RSC_CHAT_VARIATION_HAVE_ALIAS );
       
   126     iNicknameEnabled = IMUtils::IntResourceValueL( RSC_CHAT_VARIATION_HAVE_NICKNAME );
       
   127 
       
   128 
       
   129     iCCAContactEditPC = appUi->GetProcessManager().GetContactEditInterface();
       
   130 
       
   131     iCCAContactEditPC->InitialiseL( *appUi->GetProcessManager().GetArrayInterface(),
       
   132                                     iIndexOfContact, iOwnData ) ;
       
   133 
       
   134 
       
   135     //contact should have been initialised
       
   136     if ( ! iCCAContactEditPC->IsContact() )
       
   137         {
       
   138         // can't be NULL. you should use ContactEditor in this case.
       
   139         __CHAT_ASSERT_DEBUG( iCCAContactEditPC->IsContact() );
       
   140         }
       
   141 
       
   142     // store contactid so it's possible to verify the contact
       
   143     // without iContact pointer.
       
   144     iContactId = iCCAContactEditPC->GetCurrentContactUserId().AllocL();
       
   145     }
       
   146 
       
   147 // Destructor
       
   148 CCAContactDetailsDialog::~CCAContactDetailsDialog()
       
   149     {
       
   150     // dialog will be gone, so tab groups can be drawn again
       
   151     if ( iTitlePane )
       
   152         {
       
   153         iTitlePane->RestoreNaviPane();
       
   154         }
       
   155 
       
   156     if ( iItemTextArray )
       
   157         {
       
   158         iItemTextArray->Reset();
       
   159         }
       
   160     delete iItemTextArray;
       
   161     delete iListId;
       
   162     delete iContactId;
       
   163 
       
   164     iIndexToControlIdMapping.Close();
       
   165 
       
   166     // reset the iContact and iOwnData
       
   167     iCCAContactEditPC->ReleaseResources();
       
   168     }
       
   169 
       
   170 // ---------------------------------------------------------
       
   171 // CCAContactDetailsDialog::ProcessCommandL( TInt aCommand )
       
   172 // This method catches commands
       
   173 // (other items were commented in a header).
       
   174 // ---------------------------------------------------------
       
   175 //
       
   176 void CCAContactDetailsDialog::ProcessCommandL( TInt aCommand )
       
   177     {
       
   178     HideMenu();
       
   179 
       
   180     // Verify that contact is still logged in
       
   181     switch ( aCommand )
       
   182         {
       
   183             // commands which require login
       
   184         case EChatClientDetailsEdit:
       
   185         case EChatClientDetailsDelete: // fallthrough
       
   186             {
       
   187             CCAAppUi* appUi = static_cast<CCAAppUi*>( CCoeEnv::Static()->AppUi() );
       
   188 
       
   189             if ( !appUi->UISessionManager().LoginL( MCAUiLoginCmdCB::EQueryLogin ) )
       
   190                 {
       
   191                 // Login unsuccessfull. Cannot process command, so returning.
       
   192                 // Do not leave because this can happen when login is failed
       
   193                 // for some reason like cancel pressed by user etc.
       
   194                 return;
       
   195                 }
       
   196 
       
   197 
       
   198             // wait for background fetch
       
   199             if ( !CCASyncChecker::CheckSyncStateL() )
       
   200                 {
       
   201                 // canceled or not logged in
       
   202                 return;
       
   203                 }
       
   204 
       
   205             break;
       
   206             }
       
   207         default:
       
   208             {
       
   209             break;
       
   210             }
       
   211         }
       
   212 
       
   213     switch ( aCommand )
       
   214         {
       
   215         case EEikCmdExit:	// falltrough
       
   216         case EChatClientCmdExit:
       
   217             {
       
   218             iEikonEnv->EikAppUi()->HandleCommandL( EAknSoftkeyExit );
       
   219             break;
       
   220             }
       
   221 
       
   222         case EChatClientCmdHelp:
       
   223             {
       
   224             HlpLauncher::LaunchHelpApplicationL( CEikonEnv::Static()->WsSession(),
       
   225                                                  ( CCoeEnv::Static()->AppUi() )->AppHelpContextL () );
       
   226             break;
       
   227             }
       
   228 
       
   229         case EChatClientDetailsEdit:
       
   230             {
       
   231             // launch contact editor to edit contact
       
   232             // with highlight in the given field
       
   233             LaunchContactEditorL();
       
   234             break;
       
   235             }
       
   236 
       
   237         case EChatClientDetailsDelete:
       
   238             {
       
   239             // This will close the dialog on success.
       
   240             DeleteCurrentContactL();
       
   241             break;
       
   242             }
       
   243 
       
   244         default:
       
   245             {
       
   246             iEikonEnv->EikAppUi()->HandleCommandL( aCommand );
       
   247             break;
       
   248             }
       
   249         }
       
   250     }
       
   251 
       
   252 // ---------------------------------------------------------
       
   253 // CCAContactDetailsDialog::DynInitMenuPaneL
       
   254 // Dynamically initialises menu pane
       
   255 // (other items were commented in a header).
       
   256 // ---------------------------------------------------------
       
   257 //
       
   258 void CCAContactDetailsDialog::DynInitMenuPaneL( TInt aResourceId,
       
   259                                                 CEikMenuPane* aMenuPane )
       
   260     {
       
   261     CHAT_DP_TXT( "CCAContactDetailsDialog::DynInitMenuPaneL" );
       
   262 
       
   263     if ( !iCCAContactEditPC->IsContact() ||
       
   264          ( aResourceId == R_CHAT_CDETAILS_MENUPANE && iOwnData ) )
       
   265         {
       
   266         // hide Delete menu option
       
   267         aMenuPane->SetItemDimmed( EChatClientDetailsDelete, ETrue );
       
   268         }
       
   269 
       
   270     // dim the help menu if it's not supported
       
   271     if ( aResourceId == R_CHATCLIENT_GENERAL_MENU &&
       
   272          !FeatureManager::FeatureSupported( KFeatureIdHelp ) )
       
   273         {
       
   274         // dim the help menu item
       
   275         aMenuPane->SetItemDimmed( EChatClientCmdHelp, ETrue );
       
   276         }
       
   277 
       
   278     CHAT_DP_TXT( "CCAContactDetailsDialog::DynInitMenuPaneL ENDS" );
       
   279     }
       
   280 
       
   281 // ---------------------------------------------------------
       
   282 // CCAContactDetailsDialog::PreLayoutDynInitL()
       
   283 // Sets the layout for dialog
       
   284 // (other items were commented in a header).
       
   285 // ---------------------------------------------------------
       
   286 //
       
   287 void CCAContactDetailsDialog::PreLayoutDynInitL()
       
   288     {
       
   289     // create the listbox
       
   290     CAknDoubleStyleListBox* listBox = static_cast< CAknDoubleStyleListBox* >
       
   291                                       ( Control( EChatClientControlIdDetails ) );
       
   292 
       
   293     listBox->SetListBoxObserver( this );
       
   294 
       
   295     listBox->CreateScrollBarFrameL( ETrue );
       
   296     listBox->ScrollBarFrame()->SetScrollBarVisibilityL(
       
   297         CEikScrollBarFrame::EOff, CEikScrollBarFrame::EAuto );
       
   298 
       
   299     listBox->HandleItemAdditionL();
       
   300     listBox->UpdateScrollBarsL();
       
   301 
       
   302     listBox->Model()->SetItemTextArray( iItemTextArray );
       
   303     listBox->Model()->SetOwnershipType( ELbmDoesNotOwnItemArray );
       
   304 
       
   305     // enable marquee
       
   306     listBox->ItemDrawer()->ColumnData()->EnableMarqueeL( ETrue );
       
   307 
       
   308     UpdateItemTextArrayL();
       
   309 
       
   310     UpdateTitleBarL();
       
   311     }
       
   312 
       
   313 // ---------------------------------------------------------
       
   314 // CCAContactDetailsDialog::OkToExitL( TInt aButtonId )
       
   315 // Handles buttonids
       
   316 // (other items were commented in a header).
       
   317 // ---------------------------------------------------------
       
   318 //
       
   319 TBool CCAContactDetailsDialog::OkToExitL( TInt aButtonId )
       
   320     {
       
   321     if ( aButtonId == EAknSoftkeyOptions )
       
   322         {
       
   323         DisplayMenuL();
       
   324         return EFalse;
       
   325         }
       
   326     if ( aButtonId == EAknSoftkeyContextOptions )   // MSK command, show context
       
   327         // sensitive options menu
       
   328         {
       
   329         // Currently open contact editor with MSK
       
   330         ProcessCommandL( EChatClientDetailsEdit );
       
   331         return EFalse;
       
   332         }
       
   333     return ETrue;
       
   334     }
       
   335 
       
   336 // ---------------------------------------------------------
       
   337 // CCAContactDetailsDialog::OfferKeyEventL
       
   338 // (other items were commented in a header).
       
   339 // ---------------------------------------------------------
       
   340 //
       
   341 TKeyResponse CCAContactDetailsDialog::OfferKeyEventL( const TKeyEvent& aKeyEvent,
       
   342                                                       TEventCode aType )
       
   343     {
       
   344     switch ( aKeyEvent.iCode )
       
   345         {
       
   346         case EKeyEscape:    // Handle dialog shutdown
       
   347             {
       
   348             TryExitL( EAknSoftkeyExit );
       
   349             return EKeyWasNotConsumed;
       
   350             }
       
   351         case EKeyEnter:     // Flowthrough
       
   352         case EKeyOK:
       
   353             {
       
   354             ProcessCommandL( EChatClientDetailsEdit );
       
   355             return EKeyWasConsumed;
       
   356             }
       
   357         case EKeyBackspace:
       
   358             {
       
   359             // This will close the dialog on success.
       
   360             ProcessCommandL( EChatClientDetailsDelete );
       
   361             return EKeyWasConsumed;
       
   362             }
       
   363         case EKeyPhoneSend:
       
   364             {
       
   365             return EKeyWasConsumed;
       
   366             }
       
   367         default:
       
   368             {
       
   369             break;
       
   370             }
       
   371         }
       
   372 
       
   373     CAknDoubleStyleListBox* listBox = static_cast< CAknDoubleStyleListBox* >
       
   374                                       ( Control( EChatClientControlIdDetails ) );
       
   375 
       
   376     // pass to the listbox
       
   377     return listBox->OfferKeyEventL( aKeyEvent, aType );
       
   378     }
       
   379 
       
   380 // ---------------------------------------------------------
       
   381 // CCAContactDetailsDialog::HandleListBoxEventL
       
   382 // (other items were commented in a header).
       
   383 // ---------------------------------------------------------
       
   384 //
       
   385 void CCAContactDetailsDialog::HandleListBoxEventL( CEikListBox* /*aListBox*/,
       
   386                                                    TListBoxEvent /*aEventType*/ )
       
   387     {
       
   388     }
       
   389 
       
   390 // -----------------------------------------------------------------------------
       
   391 // CCAContactDetailsDialog::UpdateItemTextArrayL
       
   392 // -----------------------------------------------------------------------------
       
   393 //
       
   394 void CCAContactDetailsDialog::UpdateItemTextArrayL()
       
   395     {
       
   396     // The contact given as parameter for us exists always, because we are
       
   397     // viewing or editing it.  If it didn't exist (NULL) we should be in
       
   398     // Contact Editor and Contact Details Dialog should not have been
       
   399     // invoked.
       
   400     // The contact can never be NULL once we reach this method
       
   401     __CHAT_ASSERT_DEBUG( iCCAContactEditPC->IsContact() );
       
   402 
       
   403     iItemTextArray->Reset();
       
   404     iIndexToControlIdMapping.Reset();
       
   405 
       
   406     // online status - can't be empty
       
   407     HBufC* statusString = NULL;
       
   408 
       
   409     switch ( iCCAContactEditPC->GetOnlineStatus() )
       
   410         {
       
   411         case TEnumsPC::EUnknown :
       
   412             {
       
   413             statusString =
       
   414                 iEikonEnv->AllocReadResourceLC( R_QTN_CHAT_CD_STATUS_UNKNOWN );
       
   415             break;
       
   416             }
       
   417 
       
   418         case TEnumsPC::EOffline :
       
   419             {
       
   420             statusString =
       
   421                 iEikonEnv->AllocReadResourceLC( R_QTN_CHAT_CD_STATUS_OFFLINE );
       
   422             break;
       
   423             }
       
   424 
       
   425         case TEnumsPC::EOnline :
       
   426             {
       
   427             statusString =
       
   428                 iEikonEnv->AllocReadResourceLC( R_QTN_CHAT_CD_STATUS_ONLINE );
       
   429             break;
       
   430             }
       
   431 
       
   432         case TEnumsPC::EInvisible :
       
   433             {
       
   434             // this can only come for own status item, no need to check since
       
   435             // for other contacts this state is impossible
       
   436             statusString =
       
   437                 iEikonEnv->AllocReadResourceLC( R_QTN_CHAT_CD_STATUS_APPEAR_OFFLINE );
       
   438             break;
       
   439             }
       
   440 
       
   441         case TEnumsPC::EAway :
       
   442             {
       
   443             statusString =
       
   444                 iEikonEnv->AllocReadResourceLC( R_QTN_CHAT_CD_STATUS_AWAY );
       
   445             break;
       
   446             }
       
   447 
       
   448         case TEnumsPC::EBusy :
       
   449             {
       
   450             statusString =
       
   451                 iEikonEnv->AllocReadResourceLC( R_QTN_CHAT_CD_STATUS_BUSY );
       
   452             break;
       
   453             }
       
   454 
       
   455 
       
   456         default :
       
   457             {
       
   458             // can't get here
       
   459             break;
       
   460             }
       
   461         }
       
   462     AppendToItemArrayL( *iItemTextArray, R_QTN_CHAT_CD_STATUS, *statusString );
       
   463     iIndexToControlIdMapping.Append( EChatEditDummy ); // no control for changing presence
       
   464     CleanupStack::PopAndDestroy( statusString );
       
   465 
       
   466     // status message
       
   467     TPtrC temp( iCCAContactEditPC->GetStatusText() );
       
   468     if ( temp.Length() > 0 )
       
   469         {
       
   470         // show non-empty message
       
   471         AppendToItemArrayL( *iItemTextArray, R_QTN_CHAT_CD_MESSAGE, temp );
       
   472         iIndexToControlIdMapping.Append( EChatEditDummy ); // no control for changing message
       
   473         }
       
   474 
       
   475     // device type - can't be empty
       
   476     HBufC* deviceString = NULL;
       
   477 
       
   478     switch ( iCCAContactEditPC->GetClientType() )
       
   479         {
       
   480         case TEnumsPC::EUnknownClient :
       
   481             {
       
   482             deviceString =
       
   483                 iEikonEnv->AllocReadResourceLC( R_QTN_CHAT_CD_DEVICE_UNKNOWN );
       
   484             break;
       
   485             }
       
   486 
       
   487         case TEnumsPC::EMobile :
       
   488             {
       
   489             deviceString =
       
   490                 iEikonEnv->AllocReadResourceLC( R_QTN_CHAT_CD_DEVICE_MOBILE );
       
   491             break;
       
   492             }
       
   493 
       
   494         case TEnumsPC::EPC :
       
   495             {
       
   496             deviceString =
       
   497                 iEikonEnv->AllocReadResourceLC( R_QTN_CHAT_CD_DEVICE_PC );
       
   498             break;
       
   499             }
       
   500 
       
   501         default :
       
   502             {
       
   503             // can't get here
       
   504             break;
       
   505             }
       
   506         }
       
   507     AppendToItemArrayL( *iItemTextArray, R_QTN_CHAT_CD_DEVICE, *deviceString );
       
   508     iIndexToControlIdMapping.Append( EChatEditDummy ); // no control for changing device
       
   509     CleanupStack::PopAndDestroy( deviceString );
       
   510 
       
   511     // WVID - we always have this
       
   512 
       
   513     //To Remove wv and domain part from "WV User Id" Field in Contact Details Dialog
       
   514     TPtrC userIdName = CCAPCUtils::DisplayId( iCCAContactEditPC->GetCurrentContactUserId() );
       
   515     HBufC16* wvID = userIdName.AllocLC();
       
   516     AppendToItemArrayL( *iItemTextArray, R_QTN_CHAT_CD_WV_ID, *wvID );
       
   517     CleanupStack::PopAndDestroy( wvID );
       
   518     iIndexToControlIdMapping.Append( EChatEditWV );
       
   519 
       
   520     // alias
       
   521     if ( iAliasEnabled )
       
   522         {
       
   523         temp.Set( iCCAContactEditPC->GetCurrentContactAlias() );
       
   524         if ( temp.Length() > 0 )
       
   525             {
       
   526             // show non-empty alias
       
   527             AppendToItemArrayL( *iItemTextArray, R_QTN_CHAT_CD_ALIAS, temp );
       
   528             iIndexToControlIdMapping.Append( EChatEditAlias );
       
   529             }
       
   530         }
       
   531 
       
   532     // nickname
       
   533     if ( ! iOwnData && iNicknameEnabled )
       
   534         {
       
   535         // nickname is not available for "own data" view
       
   536         temp.Set( iCCAContactEditPC->GetCurrentContactNickname() );
       
   537         if ( temp.Length() > 0 )
       
   538             {
       
   539             // show non-empty nickname
       
   540             AppendToItemArrayL( *iItemTextArray, R_QTN_CHAT_CD_NICK,
       
   541                                 iCCAContactEditPC->GetCurrentContactNickname() );
       
   542             iIndexToControlIdMapping.Append( EChatEditNick );
       
   543             }
       
   544         }
       
   545     }
       
   546 
       
   547 // -----------------------------------------------------------------------------
       
   548 // CCAContactDetailsDialog::AppendToItemArrayL
       
   549 // -----------------------------------------------------------------------------
       
   550 //
       
   551 void CCAContactDetailsDialog::AppendToItemArrayL(
       
   552     CDesCArray& aItemTextArray,
       
   553     TInt aStringResource,
       
   554     const TDesC& aText )
       
   555     {
       
   556     // the length should be enough for every string used here. e.g. 50 is
       
   557     // nickname max length. at the same time, it should be generic enough for
       
   558     // alias, nickname, wvid, etc. so let's choose 120
       
   559     HBufC* temp = HBufC::NewLC( 120 );
       
   560     HBufC* label = iEikonEnv->AllocReadResourceLC( aStringResource );
       
   561     TPtr pTemp( temp->Des() );
       
   562     // format properly for the list box
       
   563     pTemp.Append( KTab );
       
   564     pTemp.Append( *label );
       
   565     pTemp.Append( KTab );
       
   566     pTemp.Append( aText );
       
   567     CleanupStack::PopAndDestroy( label );
       
   568     aItemTextArray.AppendL( *temp );
       
   569     CleanupStack::PopAndDestroy( temp );
       
   570     }
       
   571 
       
   572 // -----------------------------------------------------------------------------
       
   573 // CCAContactDetailsDialog::ShowLD
       
   574 // -----------------------------------------------------------------------------
       
   575 //
       
   576 void CCAContactDetailsDialog::ShowLD()
       
   577     {
       
   578     // show and die
       
   579     ExecuteLD( R_CHAT_CEDITOR_DETAILS );
       
   580     }
       
   581 
       
   582 // -----------------------------------------------------------------------------
       
   583 // CCAContactDetailsDialog::MapIndexToControlId
       
   584 // -----------------------------------------------------------------------------
       
   585 //
       
   586 TInt CCAContactDetailsDialog::MapIndexToControlId( TInt aItemIndex )
       
   587     {
       
   588     TInt maxArrayIndex = iIndexToControlIdMapping.Count();
       
   589     TInt index = aItemIndex;
       
   590 
       
   591     // sanity
       
   592     __CHAT_ASSERT_DEBUG( index < maxArrayIndex );
       
   593 
       
   594     // find suitable position
       
   595     TInt iter = 0;
       
   596     do
       
   597         {
       
   598         if ( iIndexToControlIdMapping[ index ] != EChatEditDummy )
       
   599             {
       
   600             // found a valid id, use it
       
   601             return iIndexToControlIdMapping[ index ];
       
   602             }
       
   603 
       
   604         // no available mapping, try to focus on next one
       
   605 
       
   606         // wrap to start of array if necessary
       
   607         index = ( index + 1 ) % maxArrayIndex;
       
   608         iter++;
       
   609         }
       
   610     while ( iter < maxArrayIndex ); // prevent infinite loop
       
   611 
       
   612     // didn't find it so let the editor decide
       
   613     return EChatEditDummy;
       
   614     }
       
   615 
       
   616 // -----------------------------------------------------------------------------
       
   617 // CCAContactDetailsDialog::UpdateTitleBarL
       
   618 // -----------------------------------------------------------------------------
       
   619 //
       
   620 void CCAContactDetailsDialog::UpdateTitleBarL()
       
   621     {
       
   622     iTitlePane->ClearNaviPaneL();
       
   623 
       
   624     // set correct title
       
   625     HBufC* title = NULL;
       
   626     if ( iOwnData )
       
   627         {
       
   628         // "own data"
       
   629         title = iEikonEnv->AllocReadResourceLC( R_QTN_CHAT_CD_OWN_DATA_TITLE );
       
   630         }
       
   631     else
       
   632         {
       
   633         // identification
       
   634         title = iCCAContactEditPC->GetCurrentContactIdentification().AllocLC();
       
   635         }
       
   636 
       
   637     iTitlePane->SetTitleL( *title );
       
   638     CleanupStack::PopAndDestroy( title );
       
   639 
       
   640     // set own status, but for landscape mode only
       
   641     CCAAppUi* appUi = static_cast<CCAAppUi*>( CCoeEnv::Static()->AppUi() );
       
   642     appUi->UISessionManager().SetStatusPaneIconsL();
       
   643 
       
   644     // when the dialog is active, do not show any tabs even if the underlying
       
   645     // view would like to show them
       
   646     iTitlePane->ProhibitTabGroup();
       
   647     }
       
   648 
       
   649 // -----------------------------------------------------------------------------
       
   650 // CCAContactDetailsDialog::DeleteCurrentContactL
       
   651 // -----------------------------------------------------------------------------
       
   652 //
       
   653 TInt CCAContactDetailsDialog::DeleteCurrentContactL()
       
   654     {
       
   655     // can't delete self
       
   656     if ( iOwnData )
       
   657         {
       
   658         return KErrAccessDenied;
       
   659         }
       
   660 
       
   661     if ( !iCCAContactEditPC->IsContactValidL( *iListId ) )
       
   662         {
       
   663         // user does not exist anymore
       
   664         IMNoteMapper::ShowNoteL( KErrArgument );
       
   665         return KErrArgument;
       
   666         }
       
   667 
       
   668     iMovingFlag = ETrue;
       
   669     CCAAppUi* appUi = static_cast<CCAAppUi*>( CCoeEnv::Static()->AppUi() );
       
   670 
       
   671     // Get the name of the friend to be deleted
       
   672     HBufC* contactId = iCCAContactEditPC->GetCurrentContactIdentification().AllocLC();
       
   673 
       
   674     // Load and format confirmation string from resource
       
   675     HBufC* prompt = StringLoader::LoadLC( RSC_CHAT_DELETE_CONFIRMATION, *contactId );
       
   676 
       
   677     TInt ret( IMDialogUtils::DisplayQueryDialogL(
       
   678                   R_GENERIC_YES_NO_CONFIRMATION_QUERY, *prompt ) );
       
   679 
       
   680     TInt error( KErrCancel );
       
   681 
       
   682     // Check what the user responded
       
   683     if ( ( ret == EAknSoftkeyOk ) || ( ret == EAknSoftkeyYes ) )
       
   684         {
       
   685         // accepted, lets delete the contact
       
   686         appUi->ShowWaitDialogLC( R_QTN_CHAT_DELETING_CONTACT );
       
   687 
       
   688         HBufC* contactUserId = iCCAContactEditPC->GetCurrentContactUserId().AllocLC();
       
   689         // delete contact
       
   690         error = iCCAContactEditPC->RemoveContactL( *iListId,
       
   691                                                    *contactUserId );
       
   692 
       
   693         // Dismiss the delete waiting dailog
       
   694         appUi->DismissWaitDialogL( KErrNone );
       
   695 
       
   696         if ( error <= Imps_ERROR_BASE )
       
   697             {
       
   698             // server error
       
   699             IMNoteMapper::ShowNoteL( error );
       
   700             }
       
   701 
       
   702         if ( error == KErrNone )
       
   703             {
       
   704             // Start
       
   705 #ifdef IMPS_BLOCK_AFTER_DELETE
       
   706             TBool blockVariation( IMUtils::IntResourceValueL(
       
   707                                       RSC_CHAT_VARIATION_BLOCK_QUERY ) );
       
   708             if ( blockVariation )
       
   709                 {
       
   710                 HBufC* deletePrompt = StringLoader::LoadLC( R_QTN_CHAT_BLOCKING_QUERY, *contactId );
       
   711                 // no error and it's a contact
       
   712                 TInt block = IMDialogUtils::DisplayYesNoConfirmationDialogL( *deletePrompt );
       
   713                 if ( block )
       
   714                     {
       
   715                     MCABlockingPC* blockingPC = appUi->GetProcessManager().GetBlockingInterface( );
       
   716                     CCABlockingUI* blockingUI = CCABlockingUI::NewLC( blockingPC );
       
   717                     // block after delete requested
       
   718                     blockingUI->BlockUserL( *contactUserId );
       
   719                     CleanupStack::PopAndDestroy( blockingUI );
       
   720                     }
       
   721                 //CodeScanner warning to be ignored
       
   722                 CleanupStack::PopAndDestroy(  deletePrompt ); // deletePrompt
       
   723                 }
       
   724 #endif // IMPS_BLOCK_AFTER_DELETE
       
   725             // End
       
   726             // contact was successfully deleted, try to exit this dialog
       
   727             iWasSaved = EFalse;
       
   728             TryExitL( EAknSoftkeyCancel );
       
   729             }
       
   730         CleanupStack::PopAndDestroy(  contactUserId ); // contactUserId
       
   731         CleanupStack::PopAndDestroy(); //appUi->DismissWaitDialogL()
       
   732         }
       
   733     CleanupStack::PopAndDestroy( prompt );
       
   734     CleanupStack::PopAndDestroy( contactId );
       
   735     iMovingFlag = EFalse;
       
   736     return error;
       
   737     }
       
   738 
       
   739 // -----------------------------------------------------------------------------
       
   740 // CCAContactDetailsDialog::LaunchContactEditorL
       
   741 // -----------------------------------------------------------------------------
       
   742 //
       
   743 void CCAContactDetailsDialog::LaunchContactEditorL()
       
   744     {
       
   745     if ( !iCCAContactEditPC->IsContactValidL( *iListId ) )
       
   746         {
       
   747         // user does not exist anymore
       
   748         IMNoteMapper::ShowNoteL( KErrArgument );
       
   749         return;
       
   750         }
       
   751     if( iMovingFlag )
       
   752     	{
       
   753     	return;
       
   754     	}
       
   755     CAknDoubleStyleListBox* listBox = static_cast< CAknDoubleStyleListBox* >
       
   756                                       ( Control( EChatClientControlIdDetails ) );
       
   757     TInt controlId = MapIndexToControlId( listBox->CurrentItemIndex() );
       
   758 
       
   759     // Use local variable in case we get deleted.
       
   760     TBool wasSaved( EFalse );
       
   761 
       
   762     //The contact details dialog already intialised the PC component related to ContactEdit
       
   763     //so contact editor need'nt initialise/release PC coponent resources
       
   764     CCAContactEditor* editor = CCAContactEditor::NewL( iIndexOfContact, wasSaved, EFalse );
       
   765     TInt retVal = editor->EditContactLD( controlId, TEnumsPC::EEditContact, *iListId );
       
   766 
       
   767     // Don't do anything if we have cancel
       
   768     if ( retVal != 0 )
       
   769         {
       
   770 
       
   771         if ( !iCCAContactEditPC->IsContact() )
       
   772             {
       
   773             // contact was deleted -> exit details dialog
       
   774             iWasSaved = EFalse;
       
   775             TryExitL( EAknSoftkeyCancel );
       
   776             }
       
   777 
       
   778         // Only update if we have saved. If we got shut down by dialog shutter
       
   779         // we can't use any internal variables.
       
   780         if ( wasSaved )
       
   781             {
       
   782             iWasSaved = wasSaved;
       
   783 
       
   784             // Update ID
       
   785             HBufC* id = iCCAContactEditPC->GetCurrentContactUserId().AllocL();
       
   786             delete iContactId;
       
   787             iContactId = id;
       
   788 
       
   789             UpdateItemTextArrayL();
       
   790 
       
   791             // Ui was getting distorted here
       
   792 
       
   793             CAknDoubleStyleListBox* listBox = static_cast< CAknDoubleStyleListBox* >
       
   794                                               ( Control( EChatClientControlIdDetails ) );
       
   795 
       
   796             listBox->HandleItemAdditionL();
       
   797             listBox->UpdateScrollBarsL();
       
   798             listBox->Model()->SetItemTextArray( iItemTextArray );
       
   799             listBox->Model()->SetOwnershipType( ELbmDoesNotOwnItemArray );
       
   800 
       
   801             UpdateTitleBarL();
       
   802             DrawNow();
       
   803             }
       
   804         }
       
   805     }
       
   806 
       
   807 // ---------------------------------------------------------
       
   808 // CCAContactDetailsDialog::SetSizeAndPosition
       
   809 // ---------------------------------------------------------
       
   810 //
       
   811 void CCAContactDetailsDialog::SetSizeAndPosition( const TSize& /* aSize*/ )
       
   812     {
       
   813 
       
   814     TRect rect;
       
   815     AknLayoutUtils::LayoutMetricsRect( AknLayoutUtils::EMainPane, rect );
       
   816     SetRect( rect );
       
   817 
       
   818     }
       
   819 
       
   820 /**
       
   821  * Help Key Support
       
   822  * This function is called by the Framework to get the context to launch
       
   823  * Help
       
   824  *
       
   825  * @param aContext	The context that contains the appid and the help id.
       
   826  */
       
   827 void CCAContactDetailsDialog::GetHelpContext(
       
   828     TCoeHelpContext& aContext ) const
       
   829     {
       
   830     aContext.iMajor = KUidChatClient;
       
   831     if ( iOwnData )
       
   832         {
       
   833         aContext.iContext = KIMNG_HLP_CONT_OWN_DATA ;
       
   834         }
       
   835     else
       
   836         {
       
   837         aContext.iContext = KIMNG_HLP_CONTACTDETAILS ;
       
   838         }
       
   839     }
       
   840 //  End of File