wvuing/wvuiave/AppSrc/CCABlockingUI.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:  UI side blocker class
       
    15  *
       
    16 */
       
    17 
       
    18 
       
    19 // INCLUDE FILES
       
    20 #include    "CCABlockingUI.h"
       
    21 #include    "IMNoteMapper.h"
       
    22 #include	"IMDialogUtils.h"
       
    23 #include    "ChatDefinitions.h"
       
    24 #include    "chatdebugprint.h"
       
    25 #include    "avkon.hrh"
       
    26 #include    "ImpsCSPAllErrors.h"
       
    27 #include    "CCAAppUi.h"
       
    28 #include    "MCAServerContactsArrayPC.h"
       
    29 #include    "CAArrayUtils.h"
       
    30 #include    "IMUtils.h"
       
    31 #include    "CAUtils.h"
       
    32 #include    "CCAPCUtils.h"
       
    33 
       
    34 #include	"CCABlockingDialog.h"
       
    35 #include	"chatngclient.hrh"
       
    36 #include	"CCAAppUi.h"
       
    37 #include    "CCAApp.h"
       
    38 #include	"CCAStatusPaneHandler.h"
       
    39 
       
    40 #include    "CCAContactEditor.h"
       
    41 #include	"CCAVariantFactory.h"
       
    42 #include	"CCAContactSelectionDialog.h"
       
    43 
       
    44 #include    "ccasyncchecker.h"
       
    45 #include    "impsbuilddefinitions.h"
       
    46 
       
    47 #include    <chatNG.rsg>
       
    48 #include    <eikenv.h>
       
    49 #include	<hlplch.h>
       
    50 #include    <StringLoader.h>
       
    51 #include    <aknnotewrappers.h>
       
    52 #include    "CCAServerContactsArrayPC.h"
       
    53 #include    "MCASettingsPC.h"
       
    54 #include 	"MCAProcessManager.h"
       
    55 #include  	"MCABlockingPC.h"
       
    56 
       
    57 #include <csxhelp/imng.hlp.hrh>
       
    58 
       
    59 // The Settings have been moved to Cenrep (also retained in the Resource file),
       
    60 // so the enums for keys and central repository header is added here
       
    61 #include 	"VariantKeys.h"
       
    62 
       
    63 // ============================ MEMBER FUNCTIONS ===============================
       
    64 _LIT( KMyTab, "\t" );
       
    65 
       
    66 // C++ default constructor can NOT contain any code, that
       
    67 // might leave.
       
    68 CCABlockingUI::CCABlockingUI( MCABlockingPC* aBlockingPC )
       
    69         : iBlockingPC( aBlockingPC ),
       
    70         iDialogShutter( EFalse )
       
    71     {
       
    72 
       
    73     }
       
    74 
       
    75 
       
    76 
       
    77 // -----------------------------------------------------------------------------
       
    78 // CCABlockingUI::ConstructL
       
    79 // Symbian 2nd phase constructor can leave.
       
    80 // -----------------------------------------------------------------------------
       
    81 //
       
    82 void CCABlockingUI::ConstructL()
       
    83     {
       
    84     iAppUi = static_cast< CCAAppUi* >( CCoeEnv::Static()->AppUi() );
       
    85 
       
    86     iMainViewArrayPC = iAppUi->GetProcessManager().GetArrayInterface();
       
    87 
       
    88     iBlockingPC->RegisterBackgroundObserver( this );
       
    89 
       
    90     iTextualInputMode = IMUtils::IntResourceValueL( RSC_CHAT_VARIATION_USERID_TEXTUAL_INPUTMODE );
       
    91     }
       
    92 
       
    93 // -----------------------------------------------------------------------------
       
    94 // CCABlockingUI::NewL
       
    95 // Two-phased constructor.
       
    96 // -----------------------------------------------------------------------------
       
    97 //
       
    98 CCABlockingUI* CCABlockingUI::NewL( MCABlockingPC* aBlockingPC )
       
    99     {
       
   100     CCABlockingUI* self = new( ELeave ) CCABlockingUI( aBlockingPC );
       
   101 
       
   102     CleanupStack::PushL( self );
       
   103     self->ConstructL();
       
   104     CleanupStack::Pop();
       
   105 
       
   106     return self;
       
   107     }
       
   108 
       
   109 // -----------------------------------------------------------------------------
       
   110 // CCABlockingUI::NewL
       
   111 // Two-phased constructor.
       
   112 // -----------------------------------------------------------------------------
       
   113 //
       
   114 CCABlockingUI* CCABlockingUI::NewLC( MCABlockingPC* aBlockingPC )
       
   115     {
       
   116     CCABlockingUI* self = new( ELeave ) CCABlockingUI( aBlockingPC );
       
   117 
       
   118     CleanupStack::PushL( self );
       
   119     self->ConstructL();
       
   120     return self;
       
   121     }
       
   122 
       
   123 // -----------------------------------------------------------------------------
       
   124 // CCABlockingUI::~CCABlockingUI
       
   125 // -----------------------------------------------------------------------------
       
   126 //
       
   127 CCABlockingUI::~CCABlockingUI()
       
   128     {
       
   129 
       
   130     CHAT_DP( D_CHAT_LIT( "CCABlockingUI::~CCABlockingUI \
       
   131                                      before delete iBlockingDialog:%d" ),
       
   132              iBlockingDialog );
       
   133 
       
   134     if ( iBlockingPC )
       
   135         {
       
   136         iBlockingPC->UnRegisterBackgroundObserver( );
       
   137         }
       
   138     delete iOldTitle;
       
   139     }
       
   140 
       
   141 // ---------------------------------------------------------
       
   142 // CCABlockingUI::DisplayBlockedListL
       
   143 // (other items were commented in a header).
       
   144 // ---------------------------------------------------------
       
   145 //
       
   146 void CCABlockingUI::DisplayBlockedListL( TBool aDontShowTabGroup /*= EFalse */ )
       
   147     {
       
   148     CHAT_DP_FUNC_ENTER( "DisplayBlockedListL" );
       
   149 
       
   150     switch ( iBlockingPC->GetBackgroundStatus() )
       
   151         {
       
   152         case TEnumsPC::ECompleted:
       
   153             {
       
   154             //we have a list
       
   155             break;
       
   156             }
       
   157 
       
   158 
       
   159         case TEnumsPC::EFailedStatus:
       
   160         case TEnumsPC::EUnknownStatus:
       
   161         case TEnumsPC::ECancelled:
       
   162             {
       
   163             //we dont have a list, but we can try again
       
   164             //show the wait dialog immediately
       
   165             iAppUi->ShowWaitDialogL( R_CHAT_BLOCK_FETCHING, ETrue );
       
   166             // Getting blocked members
       
   167             // We have to trap the get-method, because we need to propagate the
       
   168             // CSP errors forward to the wait dialog dismissal logic.
       
   169 
       
   170             TRAPD( err, iBlockingPC->GetBlockedListFromServerL() );
       
   171             iAppUi->DismissWaitDialogL( err );
       
   172             break;
       
   173             }
       
   174 
       
   175         case KErrNotFound:
       
   176         case TEnumsPC::EIdleStarted:
       
   177         case TEnumsPC::EStarting:
       
   178         case TEnumsPC::EWaiting:
       
   179             {
       
   180             //we have are getting the list, its time to wait
       
   181             //show the wait dialog immediately
       
   182             iAppUi->ShowWaitDialogL( R_CHAT_BLOCK_FETCHING, ETrue );
       
   183 
       
   184 #ifdef _DEBUG
       
   185             if ( iFetchOperation != CCABlockingUI::EUnknown )
       
   186                 {
       
   187                 CHAT_DP( D_CHAT_LIT( "CCABlockingUI::DisplayBlockedListL \
       
   188                                  previous operation is waiting:%d" ),
       
   189                          iFetchOperation );
       
   190                 }
       
   191 #endif // _DEBUG
       
   192 
       
   193             iFetchOperation = EShowBlockList;
       
   194             iWaiting = ETrue;
       
   195             return;
       
   196 
       
   197             }
       
   198         default:
       
   199             {
       
   200             //we should not be here
       
   201             break;
       
   202             }
       
   203         }
       
   204 
       
   205     // dismiss the wait dialog
       
   206     iAppUi->DismissWaitDialogL( KErrNone );
       
   207     iWaiting = EFalse;
       
   208 
       
   209     iBlockingPC->GetBlockedMembersL( KMyTab );
       
   210 
       
   211     iSelectedItem = KErrNotFound;
       
   212 
       
   213     if ( iBlockingDialog )
       
   214         {
       
   215         delete iBlockingDialog;
       
   216         iBlockingDialog = NULL;
       
   217         }
       
   218 
       
   219     //preserve title pane text
       
   220     BackupTitleL();
       
   221     CleanupStack::PushL( TCleanupItem( CCABlockingUI::RestoreTitle, this ) );
       
   222 
       
   223 
       
   224 
       
   225     iBlockingArray = &( iBlockingPC->GetServerContactsArray() );
       
   226     iBlockingDialog = CCABlockingDialog::NewL( iSelectedItem, iBlockingArray,
       
   227                                                R_CHATCLIENT_MENUBAR_BLOCKING_DIALOG,
       
   228                                                R_CHATCLIENT_MENUBAR_BLOCKING_DIALOG2,
       
   229                                                this,
       
   230                                                aDontShowTabGroup
       
   231                                              );
       
   232 
       
   233     // CodeScanner warning ignored because iBlockingDailog is not owned by us
       
   234     // and it is destroyed automatically in ExecuteLD
       
   235     if ( iBlockingDialog->ExecuteLD( R_BLOCK_DIALOG ) == EChatClientCmdExit ) // CSI: 50 # See comment above
       
   236         {
       
   237         // Handle exit command
       
   238         iBlockingDialog = NULL;
       
   239         iAppUi->HandleCommandL( EChatClientCmdExit );
       
   240         }
       
   241 
       
   242     iBlockingDialog = NULL;
       
   243     CleanupStack::PopAndDestroy();
       
   244 
       
   245     CHAT_DP_FUNC_DONE( "DisplayBlockedListL" );
       
   246     }
       
   247 
       
   248 // ---------------------------------------------------------
       
   249 // CCABlockingUI::DisplayUnblockListQueryL
       
   250 // (other items were commented in a header).
       
   251 // ---------------------------------------------------------
       
   252 //
       
   253 void CCABlockingUI::DisplayUnblockListQueryL()
       
   254     {
       
   255     CHAT_DP_FUNC_ENTER( "DisplayUnblockListQueryL" );
       
   256 
       
   257     switch ( iBlockingPC->GetBackgroundStatus( ) )
       
   258         {
       
   259         case TEnumsPC::ECompleted:
       
   260             {
       
   261             //we have a list
       
   262             break;
       
   263             }
       
   264 
       
   265         case TEnumsPC::EFailedStatus:
       
   266         case TEnumsPC::EUnknownStatus:
       
   267         case TEnumsPC::ECancelled:
       
   268             {
       
   269             //we dont have a list, but we can try again
       
   270             //display the wait dialog immediately
       
   271             iAppUi->ShowWaitDialogL( R_CHAT_BLOCK_FETCHING, ETrue );
       
   272             //Getting blocked members
       
   273             // We have to trap the get-method, because we need to propagate the
       
   274             // CSP errors forward to the wait dialog dismissal logic.
       
   275 
       
   276             TRAPD( err, iBlockingPC->GetBlockedListFromServerL() );
       
   277             iAppUi->DismissWaitDialogL( err );
       
   278             break;
       
   279             }
       
   280 
       
   281         case KErrNotFound:
       
   282         case TEnumsPC::EIdleStarted:
       
   283         case TEnumsPC::EStarting:
       
   284         case TEnumsPC::EWaiting:
       
   285             {
       
   286             //we are getting the list, its time to wait
       
   287             //display the wait dialog immediately
       
   288             iAppUi->ShowWaitDialogL( R_CHAT_BLOCK_FETCHING, ETrue );
       
   289 
       
   290 #ifdef _DEBUG
       
   291             if ( iFetchOperation != CCABlockingUI::EUnknown )
       
   292                 {
       
   293                 CHAT_DP( D_CHAT_LIT( "CCABlockingUI::DisplayUnblockListQueryL \
       
   294                                  previous operation is waiting:%d" ),
       
   295                          iFetchOperation );
       
   296                 }
       
   297 #endif // _DEBUG
       
   298 
       
   299             iFetchOperation = EShowUnblockList;
       
   300             iWaiting = ETrue;
       
   301             return;
       
   302 
       
   303 
       
   304             }
       
   305         default:
       
   306             {
       
   307             //we should not be here
       
   308             break;
       
   309             }
       
   310         }
       
   311 
       
   312     // dismiss the wait dialog
       
   313     iAppUi->DismissWaitDialogL( KErrNone );
       
   314     iWaiting = EFalse;
       
   315 
       
   316     MCAServerContactsArrayPC* blockedMembers = iBlockingPC->GetBlockedMembersLC( KIconTabulator );
       
   317 
       
   318     //Creating index array that tells what indexes are selected or not
       
   319     CArrayFixFlat<TInt>* indexArray =
       
   320         new ( ELeave ) CArrayFixFlat<TInt>( KArrayGranularity );
       
   321     CleanupStack::PushL( indexArray );
       
   322 
       
   323     //Creating list of unblocked users
       
   324     CDesCArrayFlat* unBlockList =
       
   325         new ( ELeave ) CDesCArrayFlat( KArrayGranularity );
       
   326     CleanupStack::PushL( unBlockList );
       
   327 
       
   328     //Display pop up list
       
   329     TInt result( IMDialogUtils::DisplayListQueryDialogL( indexArray,
       
   330                                                          blockedMembers,
       
   331                                                          R_CHAT_UNBLOCK_LIST_QUERY ) );
       
   332 
       
   333     if ( result == EAknSoftkeyOk )
       
   334         {
       
   335         TInt blockedMembersCount( blockedMembers->MdcaCount() );
       
   336         TInt count( indexArray->Count() );
       
   337         for ( TInt i( 0 ); i < count; ++i )
       
   338             {
       
   339             TInt deletedIndex( indexArray->At( i ) );
       
   340             if ( deletedIndex >= blockedMembersCount )
       
   341                 {
       
   342                 deletedIndex = blockedMembersCount - 1;
       
   343                 }
       
   344             // unBlockList is those persons who are going to be unblocked
       
   345             unBlockList->AppendL( iBlockingPC->GetWvIdL( KIconTabulator,
       
   346                                                          deletedIndex ) );
       
   347             }
       
   348 
       
   349         // just a check
       
   350         if ( unBlockList->MdcaCount() > 0 )
       
   351             {
       
   352             iAppUi->ShowWaitDialogL( R_CHAT_BLOCK_REMOVING );
       
   353             TInt errorCode( KErrNone );
       
   354             TRAPD( err, errorCode = iBlockingPC->RemoveL( unBlockList, NULL ) );
       
   355 
       
   356             iAppUi->DismissWaitDialogL( err );
       
   357             if ( errorCode != KErrNone )
       
   358                 {
       
   359                 IMDialogUtils::DisplayErrorNoteL( errorCode );
       
   360                 }
       
   361             }
       
   362         }
       
   363 
       
   364     CleanupStack::PopAndDestroy( 3 ); // unBlockList, indexArray, blockedMembers
       
   365     CHAT_DP_FUNC_DONE( "DisplayUnblockListQueryL" );
       
   366     }
       
   367 
       
   368 // ---------------------------------------------------------
       
   369 // CCABlockingUI::DisplayBlockTextQueryL
       
   370 // (other items were commented in a header).
       
   371 // ---------------------------------------------------------
       
   372 //
       
   373 void CCABlockingUI::DisplayBlockTextQueryL()
       
   374     {
       
   375     //Data pointer
       
   376     HBufC* data = HBufC::NewLC( KMaxWVIDLength );
       
   377     TPtr dataPtr( data->Des() );
       
   378 
       
   379     //Displaying text query dialog
       
   380     TInt result( IMDialogUtils::DisplayTextQueryDialogL( dataPtr,
       
   381                                                          R_CHATCLIENT_BLOCK_ENTER_PROMPT,
       
   382                                                          iTextualInputMode ? R_CHATCLIENT_BLOCK_ENTER : R_CHATCLIENT_BLOCK_ENTER2,
       
   383                                                          ETrue // T9
       
   384                                                        ) );
       
   385 
       
   386     if ( result == EAknSoftkeyOk || result == EAknSoftkeyDone )
       
   387         {
       
   388         // don't add a user which is already in our list
       
   389 
       
   390         const CDesCArray* blockList = iBlockingPC->GetBlockedList();
       
   391         TInt count = blockList->Count();
       
   392         for ( TInt i = 0; i < count; i++ )
       
   393             {
       
   394             if ( 0 == CAUtils::NeutralCompare( *data,
       
   395                                                blockList->MdcaPoint( i ) ) )
       
   396                 {
       
   397                 CleanupStack::PopAndDestroy(); // data
       
   398                 return;
       
   399                 }
       
   400             }
       
   401 
       
   402         BlockUserL( *data );
       
   403 
       
   404         }
       
   405     CleanupStack::PopAndDestroy( data );
       
   406     }
       
   407 
       
   408 // ---------------------------------------------------------
       
   409 // CCABlockingUI::BlockUserL
       
   410 // (other items were commented in a header).
       
   411 // ---------------------------------------------------------
       
   412 //
       
   413 void CCABlockingUI::BlockUserL( const TDesC& aUserId )
       
   414     {
       
   415     // this cannot be called when the user is already on the list, because the
       
   416     // menu option will not be visible in such a case
       
   417     CDesCArray* blockArray = new ( ELeave ) CDesCArrayFlat( KArrayGranularity );
       
   418     CleanupStack::PushL( blockArray );
       
   419     blockArray->AppendL( aUserId );
       
   420 
       
   421     BlockMultipleUsersL( blockArray );
       
   422 
       
   423     CleanupStack::PopAndDestroy( blockArray );
       
   424 
       
   425     }
       
   426 // ---------------------------------------------------------
       
   427 // CCABlockingUI::BlockUserL
       
   428 // (other items were commented in a header).
       
   429 // ---------------------------------------------------------
       
   430 //
       
   431 
       
   432 void CCABlockingUI::BlockMultipleUsersL( const CDesCArray* aUserIds )
       
   433     {
       
   434     // If we go to block someone, we can not close the dialog
       
   435     if ( iBlockingDialog )
       
   436         iBlockingDialog->SetExitEnabled( EFalse );
       
   437 
       
   438     if ( !aUserIds )
       
   439         {
       
   440         // Set the value back when operation failed
       
   441         if ( iBlockingDialog )
       
   442             iBlockingDialog->SetExitEnabled( ETrue );
       
   443 
       
   444         User::Leave( KErrArgument );
       
   445         }
       
   446 
       
   447     TInt errorCode( KErrNone );
       
   448 
       
   449     // If contact list synch is not done. Wait for it.
       
   450     TInt removeBlocked = ( IMUtils::IntResourceValueL( RSC_CHAT_VARIATION_BLOCKING ) == 0 );
       
   451 
       
   452     if ( removeBlocked && !CCASyncChecker::CheckSyncStateL() )
       
   453         {
       
   454         if ( iBlockingDialog )
       
   455             iBlockingDialog->SetExitEnabled( ETrue );
       
   456 
       
   457         return;
       
   458         }
       
   459 
       
   460     iAppUi->ShowWaitDialogL( R_CHAT_BLOCK_ADDING );
       
   461 
       
   462     if ( removeBlocked )
       
   463         {
       
   464         //we have to remove ids from the list first.
       
   465         TRAPD( err, RemoveIDsL( aUserIds ) );
       
   466 
       
   467         if ( err != KErrNone )
       
   468             {
       
   469             iAppUi->DismissWaitDialogL( err );
       
   470 
       
   471             if ( iBlockingDialog )
       
   472                 iBlockingDialog->SetExitEnabled( ETrue );
       
   473 
       
   474             User::Leave( err );
       
   475             }
       
   476         }
       
   477 
       
   478     TRAPD( err, errorCode = iBlockingPC->InsertL( aUserIds, NULL ) );
       
   479     iAppUi->DismissWaitDialogL( err );
       
   480 
       
   481     // Set the value back when operation finished
       
   482     if ( iBlockingDialog )
       
   483         iBlockingDialog->SetExitEnabled( ETrue );
       
   484 
       
   485     CHAT_DP( D_CHAT_LIT( "CCABlockinManager::BlockUserL() err==%d" ), errorCode );
       
   486 
       
   487     if ( errorCode == KErrNone )
       
   488         {
       
   489         IMDialogUtils::DisplayNoteDialogL( R_CHATCLIENT_CNOTE_BLOCK );
       
   490         }
       
   491     else
       
   492         {
       
   493         if ( errorCode == ECSPInvalidParameter )
       
   494             {
       
   495             errorCode = ECSPUnknownUserId;
       
   496             }
       
   497         if ( aUserIds->MdcaCount() == 1 )
       
   498             {
       
   499             IMNoteMapper::ShowNoteL( errorCode, CCAPCUtils::DisplayId( aUserIds->MdcaPoint( 0 ) ) );
       
   500             }
       
   501         else
       
   502             {
       
   503             IMNoteMapper::ShowNoteL( errorCode );
       
   504             }
       
   505         }
       
   506 
       
   507     iBlockingPC->GetBlockedMembersL( KMyTab );
       
   508 
       
   509     if ( iBlockingDialog )
       
   510         {
       
   511         iBlockingDialog->HandleItemAdditionL();
       
   512         SetIndexAfterBlocking( aUserIds->Count() > 1,
       
   513                                aUserIds->MdcaPoint( 0 ) );
       
   514         }
       
   515     }
       
   516 
       
   517 // -----------------------------------------------------------------------------
       
   518 // CCAAppUi::CloseDialog
       
   519 // -----------------------------------------------------------------------------
       
   520 //
       
   521 void CCABlockingUI::RestoreTitle( TAny* aInstance )
       
   522     {
       
   523 
       
   524     TRAPD( leave, static_cast<CCABlockingUI*>( aInstance )->DoRestoreTitleL() );
       
   525     if ( leave != KErrNone )
       
   526         {
       
   527         CActiveScheduler::Current()->Error( leave );
       
   528         }
       
   529 
       
   530     }
       
   531 
       
   532 // -----------------------------------------------------------------------------
       
   533 // CCAAppUi::CloseDialog
       
   534 // -----------------------------------------------------------------------------
       
   535 //
       
   536 void CCABlockingUI::DoRestoreTitleL()
       
   537     {
       
   538     if ( iOldTitle )
       
   539         {
       
   540         CCAStatusPaneHandler* statusPane = iAppUi->CAStatusPane();
       
   541 
       
   542         statusPane->SetTitleL( *iOldTitle );
       
   543         delete iOldTitle;
       
   544         iOldTitle = NULL;
       
   545         }
       
   546     }
       
   547 // ---------------------------------------------------------
       
   548 // CCABlockingUI::HandleBackgroundEventPC
       
   549 // (other items were commented in a header).
       
   550 // ---------------------------------------------------------
       
   551 //
       
   552 void CCABlockingUI::HandleBackgroundEventPC(
       
   553     TEnumsPC::TCABackgroundTasks aEventSource,
       
   554     TEnumsPC::TCABackgroundStatus aStatus,
       
   555     TInt aSubTaskNumber,
       
   556     TInt aLeaveCode
       
   557 )
       
   558     {
       
   559     CHAT_DP_FUNC_ENTER( "HandleBackgroundEvent" );
       
   560     CHAT_DP( D_CHAT_LIT( "CCABlockingUI::HandleBackgroundEvent() source:%d \
       
   561                         status:%d subtask:%d leave:%d" ),
       
   562              aEventSource, aStatus, aSubTaskNumber, aLeaveCode );
       
   563 
       
   564     switch ( iFetchOperation )
       
   565         {
       
   566         case CCABlockingUI::EShowBlockList:
       
   567             {
       
   568             if ( iWaiting )
       
   569                 {
       
   570                 switch ( aStatus )
       
   571                     {
       
   572                     case TEnumsPC::ECompleted:
       
   573                         {
       
   574                         TRAPD( err, DisplayBlockedListL() );
       
   575 
       
   576                         if ( err != KErrNone )
       
   577                             {
       
   578                             // just to make sure.
       
   579                             TInt ignore;
       
   580                             TRAP( ignore,
       
   581                                   iAppUi->DismissWaitDialogL( KErrNone ) );
       
   582 
       
   583                             // let the activescheduler handle it
       
   584                             CActiveScheduler::Current()->Error( err );
       
   585                             }
       
   586                         break;
       
   587                         }
       
   588 
       
   589                     default:
       
   590                         {
       
   591                         TRAPD( err, iAppUi->DismissWaitDialogL( KErrNone ) );
       
   592                         iWaiting = EFalse;
       
   593                         if ( err != KErrNone )
       
   594                             {
       
   595                             // let the activescheduler handle it
       
   596                             CActiveScheduler::Current()->Error( err );
       
   597                             }
       
   598                         break;
       
   599                         }
       
   600                     }
       
   601                 }
       
   602             break;
       
   603             }
       
   604         case CCABlockingUI::EShowUnblockList:
       
   605             {
       
   606             if ( iWaiting )
       
   607                 {
       
   608                 switch ( aStatus )
       
   609                     {
       
   610                     case TEnumsPC::ECompleted:
       
   611                         {
       
   612                         TRAPD( err, DisplayUnblockListQueryL() );
       
   613 
       
   614                         if ( err != KErrNone )
       
   615                             {
       
   616                             // just to make sure..
       
   617                             TInt ignore;
       
   618                             TRAP( ignore,
       
   619                                   iAppUi->DismissWaitDialogL( KErrNone ) );
       
   620 
       
   621                             // let the activescheduler handle it
       
   622                             CActiveScheduler::Current()->Error( err );
       
   623                             }
       
   624                         break;
       
   625                         }
       
   626 
       
   627                     default:
       
   628                         {
       
   629                         TRAPD( err, iAppUi->DismissWaitDialogL( KErrNone ) );
       
   630                         iWaiting = EFalse;
       
   631 
       
   632                         if ( err != KErrNone )
       
   633                             {
       
   634                             // let the activescheduler handle it
       
   635                             CActiveScheduler::Current()->Error( err );
       
   636                             }
       
   637                         break;
       
   638                         }
       
   639                     }
       
   640                 }
       
   641             break;
       
   642             }
       
   643 
       
   644         case CCABlockingUI::EUnknown:
       
   645             {
       
   646             break;
       
   647             }
       
   648 
       
   649         default:
       
   650             {
       
   651             //we shouldnt be here
       
   652             }
       
   653         }
       
   654 
       
   655     iFetchOperation = CCABlockingUI::EUnknown;
       
   656 
       
   657     CHAT_DP_FUNC_DONE( "HandleBackgroundEvent" );
       
   658     }
       
   659 
       
   660 // ---------------------------------------------------------
       
   661 // CCABlockingUI::ProcessCommandL
       
   662 // (other items were commented in a header).
       
   663 // ---------------------------------------------------------
       
   664 //
       
   665 void CCABlockingUI::ProcessCommandL( TInt aCommandId )
       
   666     {
       
   667     switch ( aCommandId )
       
   668         {
       
   669         case EChatClientBlockingUnblock:
       
   670             {
       
   671             UnBlockL();
       
   672 
       
   673             if ( !iDialogShutter )
       
   674                 {
       
   675                 iBlockingDialog->RefreshDialogTitleL();
       
   676                 }
       
   677             else
       
   678                 {
       
   679                 iDialogShutter = EFalse;
       
   680                 }
       
   681 
       
   682             break;
       
   683             }
       
   684 
       
   685         case EChatClientBlockingBlock:
       
   686             {
       
   687             DisplayBlockListQueryL();
       
   688             break;
       
   689             }
       
   690 
       
   691         case EChatClientBlockingBlockEnter:
       
   692             {
       
   693             DisplayBlockTextQuery2L();
       
   694             break;
       
   695             }
       
   696 
       
   697         case EChatClientCmdExit :
       
   698             {
       
   699             iDialogShutter = ETrue;
       
   700             break;
       
   701             }
       
   702 
       
   703         // Help key support EChatClientCmdHelp is assigned EAknCmdHelp in
       
   704         // chatngclient.hrh
       
   705         case EChatClientCmdHelp:
       
   706             {
       
   707             HlpLauncher::LaunchHelpApplicationL(
       
   708                 CEikonEnv::Static()->WsSession(),
       
   709                 iAppUi->AppHelpContextL() );
       
   710             break;
       
   711             }
       
   712 
       
   713         default:
       
   714             {
       
   715             iBlockingDialog->SelectionListProcessCommandL( aCommandId );
       
   716             break;
       
   717             }
       
   718         }
       
   719 
       
   720     }
       
   721 
       
   722 // ---------------------------------------------------------
       
   723 // CCABlockingUI::CreateCustomCommandControlL
       
   724 // (other items were commented in a header).
       
   725 // ---------------------------------------------------------
       
   726 //
       
   727 CCoeControl* CCABlockingUI::CreateCustomCommandControlL( TInt //aControlType
       
   728                                                        )
       
   729     {
       
   730     //we don`t have any
       
   731     return NULL;
       
   732     }
       
   733 
       
   734 // ---------------------------------------------------------
       
   735 // CCABlockingUI::UnBlockL
       
   736 // ---------------------------------------------------------
       
   737 //
       
   738 void CCABlockingUI::UnBlockL()
       
   739     {
       
   740     if ( iBlockingDialog && iBlockingArray && iSelectedItem >= 0 &&
       
   741          iSelectedItem < iBlockingArray->MdcaCount() )
       
   742         {
       
   743         iBlockingDialog->SetExitEnabled( EFalse );
       
   744 
       
   745         const TDesC& findPaneTxt ( iBlockingDialog->GetFindBoxTextL() );
       
   746 
       
   747         //Creating list of unblocked users
       
   748         CDesCArrayFlat* unBlockList = iBlockingPC->GetUnBlockListL( iSelectedItem,
       
   749                                                                     findPaneTxt );
       
   750 
       
   751         CleanupStack::PushL( unBlockList );
       
   752 
       
   753         // unBlockList is those persons who are going to be unblocked*/
       
   754         // Simulate the findPane functionality when getting the iSelectedItem
       
   755         // from the blockingArray structure
       
   756         const TCAServerContact* unblocked = iBlockingArray->WVIdL( iSelectedItem, findPaneTxt );
       
   757 
       
   758         iAppUi->ShowWaitDialogLC( R_CHAT_BLOCK_REMOVING );
       
   759 
       
   760         TInt errorCode( KErrNone );
       
   761 
       
   762         if ( IMUtils::IntResourceValueL( RSC_CHAT_VARIATION_BLOCKING ) == 1 )
       
   763             {
       
   764             errorCode = iBlockingPC->DeleteContactL( iSelectedItem, findPaneTxt );
       
   765             }
       
   766         HBufC* title = CEikonEnv::Static()->AllocReadResourceLC( R_QTN_CHAT_BLOCKED_CONTACTS_TITLE );
       
   767         iAppUi->CAStatusPane()->SetTitleL( *title );
       
   768         CleanupStack::PopAndDestroy( title );
       
   769 
       
   770         if ( errorCode ) // Some error happened -> Unblock failed.
       
   771             {
       
   772             iAppUi->DismissWaitDialogL( errorCode );
       
   773 
       
   774             iBlockingDialog->SetExitEnabled( ETrue );
       
   775 
       
   776             CleanupStack::Pop(); //wait dialog
       
   777             CleanupStack::PopAndDestroy( unBlockList );
       
   778             return;
       
   779             }
       
   780 
       
   781         TRAPD( err, errorCode =
       
   782                    iBlockingPC->RemoveL( unBlockList, NULL ) );
       
   783 
       
   784         iAppUi->DismissWaitDialogL( err );
       
   785 
       
   786         iBlockingDialog->SetExitEnabled( ETrue );
       
   787 
       
   788         CleanupStack::Pop(); //wait dialog
       
   789         if ( errorCode != KErrNone )
       
   790             {
       
   791             IMNoteMapper::ShowNoteL( errorCode );
       
   792             CleanupStack::PopAndDestroy( unBlockList );
       
   793             return;
       
   794             }
       
   795 
       
   796         IMDialogUtils::DisplayNoteDialogL( R_QTN_CHAT_UNBLOCKING_CONFNOTE2 );
       
   797 
       
   798         if ( IMUtils::IntResourceValueL( RSC_CHAT_VARIATION_BLOCKING ) != 2 )
       
   799             {
       
   800 
       
   801             HBufC* prompt = StringLoader::LoadLC( R_CHAT_UNBLOCKING_QUERY,
       
   802                                                   unblocked->iIdentification );
       
   803 
       
   804             // Show confirmation
       
   805             CAknQueryDialog* dlg = new ( ELeave ) CAknQueryDialog(
       
   806                 CAknQueryDialog::ENoTone );
       
   807 
       
   808             CleanupStack::PushL( dlg );
       
   809             dlg->SetPromptL( prompt->Des() );
       
   810             CleanupStack::Pop( dlg );
       
   811             TInt ret( dlg->ExecuteLD( R_GENERIC_YES_NO_CONFIRMATION_QUERY ) );
       
   812             CleanupStack::PopAndDestroy( prompt );
       
   813 
       
   814             if ( ( ret == EAknSoftkeyOk ) || ( ret == EAknSoftkeyYes )  )
       
   815                 {
       
   816                 //we have to add id to some list.
       
   817                 TPtrC listId( KNullDesC() );
       
   818                 //-1 is item fix for index related to mainviewarray.
       
   819                 TBool contactSaved( EFalse );
       
   820                 CCAContactEditor* editor =
       
   821                     CCAContactEditor::NewL( -1 , contactSaved );
       
   822 
       
   823                 editor->EditContactLD( TEnumsPC::EAddToContact, listId, unblocked->iWVID, unblocked->iNickName );
       
   824                 }
       
   825             }
       
   826 
       
   827         CleanupStack::PopAndDestroy( unBlockList );
       
   828 
       
   829         if ( !iDialogShutter )
       
   830             {
       
   831             iBlockingPC->GetBlockedMembersL( KMyTab );
       
   832             iBlockingDialog->HandleItemRemovalL();
       
   833             }
       
   834         }
       
   835 
       
   836     }
       
   837 
       
   838 // ---------------------------------------------------------
       
   839 // CCABlockingUI::BackupTitleL
       
   840 // ---------------------------------------------------------
       
   841 //
       
   842 void CCABlockingUI::BackupTitleL()
       
   843     {
       
   844     CCAStatusPaneHandler* statusPane = iAppUi->CAStatusPane();
       
   845 
       
   846     HBufC* tempTitle = statusPane->Title()->AllocL();
       
   847     delete iOldTitle;
       
   848     iOldTitle = NULL;
       
   849     iOldTitle = tempTitle;
       
   850     }
       
   851 
       
   852 // ---------------------------------------------------------
       
   853 // CCABlockingUI::DisplayBlockTextQuery2L
       
   854 // ---------------------------------------------------------
       
   855 //
       
   856 void CCABlockingUI::DisplayBlockTextQuery2L()
       
   857     {
       
   858     DisplayBlockTextQueryL();
       
   859     iBlockingPC->GetBlockedMembersL( KMyTab );
       
   860     }
       
   861 
       
   862 // ---------------------------------------------------------
       
   863 // CCABlockingUI::RemoveIDsL
       
   864 // ---------------------------------------------------------
       
   865 //
       
   866 void CCABlockingUI::RemoveIDsL( const CDesCArray* aUserIds ) const
       
   867     {
       
   868     iBlockingPC->RemoveIDsL( aUserIds );
       
   869     }
       
   870 
       
   871 // ---------------------------------------------------------
       
   872 // CCABlockingUI::SetIndexAfterBlocking
       
   873 // ---------------------------------------------------------
       
   874 //
       
   875 void CCABlockingUI::SetIndexAfterBlocking( TBool aMultipleBlocked /*= EFalse*/,
       
   876                                            const TDesC& aBlockedId /*= KNullDesC*/ )
       
   877     {
       
   878     if ( !iBlockingDialog )
       
   879         {
       
   880         // No dialog
       
   881         return;
       
   882         }
       
   883 
       
   884     if ( aMultipleBlocked )
       
   885         {
       
   886         // Multiple contacts blocked, set focus to first item
       
   887         iBlockingDialog->ListBox()->SetCurrentItemIndexAndDraw( 0 );
       
   888         return;
       
   889         }
       
   890 
       
   891     if ( aBlockedId.Length() > 0 )
       
   892         {
       
   893         // One id blocked, set focus to that
       
   894         if ( iBlockingArray )
       
   895             {
       
   896             TInt index = iBlockingArray->Find( aBlockedId );
       
   897             if ( index != KErrNotFound )
       
   898                 {
       
   899                 iBlockingDialog->ListBox()->SetCurrentItemIndexAndDraw( index );
       
   900                 }
       
   901             else
       
   902                 {
       
   903                 // Handle errors by setting focus to first item
       
   904                 iBlockingDialog->ListBox()->SetCurrentItemIndexAndDraw( 0 );
       
   905                 }
       
   906             }
       
   907         }
       
   908     }
       
   909 // ---------------------------------------------------------
       
   910 // CCABlockingUI::DisplayBlockListQueryL
       
   911 // ---------------------------------------------------------
       
   912 //
       
   913 void CCABlockingUI::DisplayBlockListQueryL()
       
   914     {
       
   915     CDesCArray* blockArray = new ( ELeave ) CDesCArrayFlat( KArrayGranularity );
       
   916     CleanupStack::PushL( blockArray );
       
   917     MCASkinVariant* skinVar = static_cast<CCAApp*>( iAppUi->Application() )
       
   918                               ->VariantFactory()->SkinVariantL();
       
   919 
       
   920 
       
   921     CCAStatusPaneHandler* titlePane = iAppUi->CAStatusPane();
       
   922 
       
   923 
       
   924     MCASettingsPC& settings = *iAppUi->GetProcessManager().GetSettingsInterface();
       
   925 
       
   926     // show selection dialog
       
   927     TBool contacts( CCAContactSelectionDialog::ShowDialogL( *blockArray, *iMainViewArrayPC,
       
   928                                                             *skinVar, settings,
       
   929                                                             iAppUi->MbmFullPath(),
       
   930                                                             TEnumsPC::EMultiSelect,
       
   931                                                             R_CONTACT_SELECTION_DIALOG,
       
   932                                                             *iAppUi->CAStatusPane(),
       
   933                                                             NULL,
       
   934                                                             TEnumsPC::EFilterNotDefined,
       
   935                                                             TEnumsPC::EFilterNotDefined,
       
   936                                                             ETrue ) );
       
   937 
       
   938     // contact selection dialog allowed tabs..
       
   939     titlePane->ProhibitTabGroup( ETrue );
       
   940     if ( !contacts )
       
   941         {
       
   942         // no contacts
       
   943         CleanupStack::PopAndDestroy();
       
   944         return;
       
   945         }
       
   946 
       
   947     // handle selected contacts (if any)
       
   948     TInt count( blockArray->MdcaCount() );
       
   949     CHAT_DP( D_CHAT_LIT( "selection count %d" ), count );
       
   950 
       
   951 
       
   952     for ( TInt i( 0 ); i < count; ++i )
       
   953         {
       
   954         TPtrC wvid( blockArray->MdcaPoint( i ) );
       
   955         CHAT_DP( D_CHAT_LIT( "..adding %S to blocking list" ), &wvid );
       
   956         }
       
   957 
       
   958     BlockMultipleUsersL( blockArray );
       
   959 
       
   960     CleanupStack::PopAndDestroy( blockArray );
       
   961     }
       
   962 
       
   963 // ---------------------------------------------------------
       
   964 // CCABlockingUI::UnblockUserL
       
   965 // ---------------------------------------------------------
       
   966 //
       
   967 void CCABlockingUI::UnblockUserL( const TDesC& aUserId )
       
   968     {
       
   969     // 1 id is going to be unblocked, 1 for granularity
       
   970     CDesCArrayFlat* unBlockList = new( ELeave ) CDesCArrayFlat( 1 );
       
   971     CleanupStack::PushL( unBlockList );
       
   972     unBlockList->AppendL( aUserId );
       
   973 
       
   974     iAppUi->ShowWaitDialogL( R_CHAT_BLOCK_REMOVING );
       
   975 
       
   976     TInt errorCode = KErrNone;
       
   977     TRAPD( err, errorCode = iBlockingPC->RemoveL( unBlockList, NULL ) );
       
   978     iAppUi->DismissWaitDialogL( err );
       
   979     if ( errorCode != KErrNone )
       
   980         {
       
   981         IMDialogUtils::DisplayErrorNoteL( errorCode );
       
   982         }
       
   983 
       
   984     CleanupStack::PopAndDestroy( unBlockList );
       
   985     }
       
   986 
       
   987 /**
       
   988  * Help Key Support
       
   989  * This function is called by the Framework to get the context to launch
       
   990  * Help
       
   991  *
       
   992  * @param aContext	The context that contains the appid and the help id.
       
   993  */
       
   994 void CCABlockingUI::GetHelpContext( TCoeHelpContext& aContext ) const
       
   995     {
       
   996     aContext.iMajor = KUidChatClient;
       
   997     aContext.iContext = KIMNG_HLP_BLOCKED_VIEW ;
       
   998     }
       
   999 //  End of File