wvuing/wvuiave/AppSrc/CCASearchViewContainer.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:  Container class for search view
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 
       
    20 // INCLUDE FILES
       
    21 #include    "CCASearchViewContainer.h"
       
    22 #include    "ChatDefinitions.h"
       
    23 #include    "CCAStatusPaneHandler.h"
       
    24 #include    "MCAViewSwitcher.h"
       
    25 #include    "CCAAppUi.h"
       
    26 #include    "ChatDebugPrint.h"
       
    27 #include    "IMNoteMapper.h"
       
    28 #include	"CCAUINGUtils.h"
       
    29 #include    "IMDialogUtils.h"
       
    30 #include    "CCAGroupUtils.h"
       
    31 #include    "IMUtils.h"
       
    32 #include    "MCARecipientObserver.h"
       
    33 #include    "CCAMultiLineDataQueryDialog.h"
       
    34 #include    "CCABlockingUI.h"
       
    35 #include    "CCAInviteEditor.h"
       
    36 #include    "CCAContactEditor.h"
       
    37 #include    "CCAChatListView.h"
       
    38 #include    "CAExternalInterface.h"
       
    39 #include    "MCAServerContactsArrayPC.h"
       
    40 #include    "MCASearchInterfacePC.h"
       
    41 #include    "MCABlockingPC.h"
       
    42 #include 	"MCASessionHandlerCmd.h"
       
    43 #include    "CCACommandManagerFactory.h"
       
    44 #include    "CCACommandManager.h"
       
    45 #include    "MCASearchDataPC.h"
       
    46 #include 	"MCAProcessManager.h"
       
    47 #include    "chatngclient.hrh"
       
    48 #include	"CATouchUtils.h"
       
    49 
       
    50 #include    <aknlists.h>
       
    51 #include    <aknlistquerydialog.h>
       
    52 #include    <stringloader.h>
       
    53 #include	<chatNG.rsg>
       
    54 #include    <csxhelp/imng.hlp.hrh>
       
    55 #include    <aknenv.h>
       
    56 #include    <cntdef.h>
       
    57 
       
    58 // The Settings have been moved to Cenrep (also retained in the Resource file),
       
    59 // so the enums for keys and central repository header is added here
       
    60 #include   "CAUtils.h"
       
    61 #include 	"VariantKeys.h"
       
    62 
       
    63 // CONSTANTS
       
    64 const TInt KChatMaxSearchCritAmount = 4;
       
    65 const TInt KGranularity = 2;
       
    66 const TInt KTabSpace = 3;
       
    67 
       
    68 // ================= MEMBER FUNCTIONS =======================
       
    69 
       
    70 
       
    71 // -----------------------------------------------------------------------------
       
    72 // CCASearchViewContainer::NewL
       
    73 // Two-phased constructor.
       
    74 // -----------------------------------------------------------------------------
       
    75 //
       
    76 CCASearchViewContainer* CCASearchViewContainer::NewL(
       
    77     MCASearchInterfacePC* aSearchInterfacePC,
       
    78     const TRect& aRect,
       
    79     MCAViewSwitcher& aViewSwitcher,
       
    80     MCARecipientObserver& aMenuObserver,
       
    81     TBool aSearchUsers,
       
    82     TBool aGroupSyncDone,
       
    83     const TDesC& aListId )
       
    84     {
       
    85     CCASearchViewContainer* self = new ( ELeave ) CCASearchViewContainer(
       
    86         aSearchInterfacePC,
       
    87         aViewSwitcher,
       
    88         aMenuObserver,
       
    89         aSearchUsers,
       
    90         aGroupSyncDone );
       
    91     CleanupStack::PushL( self );
       
    92     self->ConstructL( aRect, aListId );
       
    93     CleanupStack::Pop( self );
       
    94     return self;
       
    95     }
       
    96 
       
    97 // -----------------------------------------------------------------------------
       
    98 // CCASearchViewContainer::CCASearchViewContainer
       
    99 // C++ default constructor can NOT contain any code, that
       
   100 // might leave.
       
   101 // -----------------------------------------------------------------------------
       
   102 //
       
   103 CCASearchViewContainer::CCASearchViewContainer(
       
   104     MCASearchInterfacePC* aSearchInterfacePC,
       
   105     MCAViewSwitcher& aViewSwitcher,
       
   106     MCARecipientObserver& aMenuObserver,
       
   107     TBool aSearchUsers,
       
   108     TBool aGroupSyncDone )
       
   109         : iSearchInterfacePC( aSearchInterfacePC ),
       
   110         iViewSwitcher( aViewSwitcher ),
       
   111         iMenuObserver( aMenuObserver ),
       
   112         iDeleteFlag( EFalse ),
       
   113         iTaskComplete( ETrue ),
       
   114         iSearchUsers( aSearchUsers ),
       
   115         iGroupSyncDone( aGroupSyncDone )
       
   116     {
       
   117     }
       
   118 
       
   119 // -----------------------------------------------------------------------------
       
   120 // CCASearchViewContainer::ConstructL
       
   121 // Symbian 2nd phase constructor can leave.
       
   122 // -----------------------------------------------------------------------------
       
   123 //
       
   124 void CCASearchViewContainer::ConstructL( const TRect& aRect,
       
   125                                          const TDesC& aListId )
       
   126     {
       
   127     CHAT_DP( D_CHAT_LIT( "CCASearchViewContainer::ConstructL" ) );
       
   128     CreateWindowL();
       
   129 
       
   130     iListId = aListId.AllocL();
       
   131 
       
   132     iAppUi = static_cast<CCAAppUi*>( CEikonEnv::Static()->AppUi() );
       
   133     iAppUi->AddLayoutChangeObserver( this );
       
   134 
       
   135     // To get online/offline events
       
   136 
       
   137     iCommandManager
       
   138     = CCACommandManagerFactory::InstanceL()->GetCommandManager();
       
   139     MCASessionHandlerCmd* sessHandlerCmd
       
   140     = iCommandManager->GetSessionHandlerCmd() ;
       
   141     if ( sessHandlerCmd )
       
   142         {
       
   143         sessHandlerCmd->AddServiceStateObserversL( this );
       
   144         }
       
   145 
       
   146 
       
   147     iItemArray = new ( ELeave ) CDesCArrayFlat( KArrayGranularity );
       
   148 
       
   149     iListBox = new ( ELeave ) CAknDoubleStyleListBox;
       
   150     iListBox->ConstructL( this, EAknListBoxSelectionList );
       
   151 
       
   152     iListBox->SetContainerWindowL( *this );
       
   153     iListBox->SetListBoxObserver( this );
       
   154     iListBox->CreateScrollBarFrameL( ETrue );
       
   155     iListBox->ScrollBarFrame()->SetScrollBarVisibilityL(
       
   156         CEikScrollBarFrame::EOff, CEikScrollBarFrame::EAuto );
       
   157 
       
   158     iListBox->Model()->SetItemTextArray( iItemArray );
       
   159     iListBox->Model()->SetOwnershipType( ELbmDoesNotOwnItemArray );
       
   160     iListBox->ItemDrawer()->ColumnData()->EnableMarqueeL( ETrue );
       
   161 
       
   162     // Get search interface
       
   163     iSearchDataPC = iAppUi->GetProcessManager().GetSearchDataInterface();
       
   164 
       
   165     iOnlinePresenceList = new ( ELeave ) CDesCArrayFlat( KArrayGranularity );
       
   166 
       
   167     iBlockingUI = CCABlockingUI::NewL(
       
   168                       iAppUi->GetProcessManager().GetBlockingInterface() );
       
   169 
       
   170     SetRect( aRect );
       
   171     ActivateL();
       
   172     // This sets correct results to navi pane
       
   173     UpdateNaviPaneTextL( ETrue );
       
   174 
       
   175     // Something to title
       
   176     HBufC* title = StringLoader::LoadLC( R_CHATCLIENT_SEARCH_RESULTS_TITLE,
       
   177                                          KNullDesC );
       
   178     iViewSwitcher.CAStatusPane()->SetTitleL( *title );
       
   179     CleanupStack::PopAndDestroy( title );
       
   180 
       
   181 
       
   182     // Idle loop for starting login sequence login
       
   183     iIdle = CIdle::NewL( CActive::EPriorityIdle );
       
   184     iTaskComplete = EFalse;
       
   185     iIdle->Start( TCallBack( BackgroundTasks, this ) );
       
   186     }
       
   187 
       
   188 // -----------------------------------------------------------------------------
       
   189 // CCASearchViewContainer::Destructor
       
   190 // -----------------------------------------------------------------------------
       
   191 //
       
   192 CCASearchViewContainer::~CCASearchViewContainer()
       
   193     {
       
   194     if ( iAppUi && !iAppUi->IsUnderDestruction() )
       
   195         {
       
   196         iAppUi->RemoveLayoutChangeObserver( this );
       
   197         if ( iWaitVisible )
       
   198             {
       
   199             TInt err;
       
   200             TRAP( err, iAppUi->DismissWaitDialogL( KErrNone ) );
       
   201             }
       
   202 
       
   203         MCASessionHandlerCmd* sessHandlerCmd
       
   204         =  iCommandManager->GetSessionHandlerCmd() ;
       
   205         if ( sessHandlerCmd )
       
   206             {
       
   207             sessHandlerCmd->RemoveServiceStateObservers( this );
       
   208             }
       
   209         }
       
   210 
       
   211     iOnlineArray.Close();
       
   212     delete iOnlinePresenceList;
       
   213     delete iItemArray;
       
   214     delete iListBox;
       
   215     delete iBlockingUI;
       
   216 
       
   217     if ( iIdle )
       
   218         {
       
   219         iIdle->Deque();
       
   220         }
       
   221     delete iIdle;
       
   222 
       
   223     delete iListId;
       
   224     }
       
   225 
       
   226 // ---------------------------------------------------------
       
   227 // CCASearchViewContainer::DisplaySearchTypeDlgL()
       
   228 // Displays search type dialog with radiobuttons
       
   229 // (other items were commented in a header).
       
   230 // ---------------------------------------------------------
       
   231 //
       
   232 TBool CCASearchViewContainer::DisplaySearchTypeDlgL()
       
   233     {
       
   234     iPreviousSearchType = iSearchType;
       
   235     CHAT_DP( D_CHAT_LIT( "CCASearchViewContainer::DisplaySearchTypeDlgL" ) );
       
   236     iSearchType = iSearchUsers ? ESearchUsers : ESearchGroups;
       
   237     return DisplaySearchCriteriaDlgL( iSearchType );
       
   238     }
       
   239 
       
   240 // ---------------------------------------------------------
       
   241 // CCASearchViewContainer::DisplaySearchCriteriaDlgL()
       
   242 // Displays search criteria dialog
       
   243 // (other items were commented in a header).
       
   244 // ---------------------------------------------------------
       
   245 //
       
   246 TBool CCASearchViewContainer::DisplaySearchCriteriaDlgL(
       
   247     const TSearchType aSearchType )
       
   248     {
       
   249     CHAT_DP( D_CHAT_LIT(
       
   250                  "CCASearchViewContainer::DisplaySearchCriteriaDlgL( %d )" ),
       
   251              aSearchType );
       
   252 
       
   253     TInt searchCriteria( 0 );
       
   254     TInt result( 0 );
       
   255 
       
   256     RArray< TEnumsPC::TSearchCriteria > indexArray; // to map return value of query to correct enum
       
   257     CleanupClosePushL( indexArray );
       
   258 
       
   259     CAknListQueryDialog* dlg = new ( ELeave )
       
   260     CAknListQueryDialog( &searchCriteria );
       
   261     dlg->PrepareLC( R_CHATCLIENT_SEARCH_CRITERIA );
       
   262 
       
   263     CDesCArray* textArray = new ( ELeave ) CDesCArrayFlat( KChatMaxSearchCritAmount );
       
   264     CleanupStack::PushL( textArray );
       
   265 
       
   266     switch ( aSearchType )
       
   267         {
       
   268         case ESearchUsers:
       
   269             {
       
   270             // Dynamically create the array of search criteria, according to
       
   271             // the brand variation flags
       
   272             if ( IMUtils::IntResourceValueL(
       
   273                      RSC_CHAT_VARIATION_SEARCH_NAME ) )
       
   274                 {
       
   275                 HBufC* txtUserName = CCoeEnv::Static()->AllocReadResourceLC(
       
   276                                          R_QTN_CHAT_SEARCH_CRITER_USER_NAME );
       
   277                 textArray->AppendL( *txtUserName );
       
   278                 CleanupStack::PopAndDestroy( txtUserName );
       
   279                 indexArray.AppendL( TEnumsPC::ESearchUserName );
       
   280                 }
       
   281 
       
   282             if ( IMUtils::IntResourceValueL(
       
   283                      RSC_CHAT_VARIATION_SEARCH_USERID ) )
       
   284                 {
       
   285                 HBufC* txtWVId = CCoeEnv::Static()->AllocReadResourceLC(
       
   286                                      R_QTN_CHAT_SEARCH_CRITER_USER_WV );
       
   287                 textArray->AppendL( *txtWVId );
       
   288                 CleanupStack::PopAndDestroy( txtWVId );
       
   289                 indexArray.AppendL( TEnumsPC::ESearchUserID );
       
   290                 }
       
   291 
       
   292             if ( IMUtils::IntResourceValueL( RSC_CHAT_VARIATION_SEARCH_PHONE ) )
       
   293                 {
       
   294                 HBufC* txtTelNumber = CCoeEnv::Static()->AllocReadResourceLC(
       
   295                                           R_QTN_CHAT_SEARCH_CRITER_USER_PUH );
       
   296                 textArray->AppendL( *txtTelNumber  );
       
   297                 CleanupStack::PopAndDestroy( txtTelNumber );
       
   298                 indexArray.AppendL( TEnumsPC::ESearchUserMobileNumber );
       
   299                 }
       
   300 
       
   301             if ( IMUtils::IntResourceValueL( RSC_CHAT_VARIATION_SEARCH_EMAIL ) )
       
   302                 {
       
   303                 HBufC* txtEmail = CCoeEnv::Static()->AllocReadResourceLC(
       
   304                                       R_QTN_CHAT_SEARCH_CRITER_USER_EMAIL );
       
   305                 textArray->AppendL( *txtEmail );
       
   306                 CleanupStack::PopAndDestroy( txtEmail );
       
   307                 indexArray.AppendL( TEnumsPC::ESearchUserEmailAddress );
       
   308                 }
       
   309             break;
       
   310             }
       
   311         case ESearchGroups:
       
   312             {
       
   313             // Dynamically create the array of search criteria, according to
       
   314             // the brand variation flags
       
   315             if ( IMUtils::IntResourceValueL(
       
   316                      RSC_CHAT_VARIATION_SEARCH_GROUPNAME ) )
       
   317                 {
       
   318                 HBufC* txtGroupName = CCoeEnv::Static()->AllocReadResourceLC(
       
   319                                           R_QTN_CHAT_SEARCH_CRITER_GRP_NAME );
       
   320                 textArray->AppendL( *txtGroupName );
       
   321                 CleanupStack::PopAndDestroy( txtGroupName );
       
   322                 indexArray.AppendL( TEnumsPC::ESearchGroupName );
       
   323                 }
       
   324 
       
   325             if ( IMUtils::IntResourceValueL(
       
   326                      RSC_CHAT_VARIATION_SEARCH_GROUPTOPIC ) )
       
   327                 {
       
   328                 HBufC* txtUserWVId = CCoeEnv::Static()->AllocReadResourceLC(
       
   329                                          R_QTN_CHAT_SEARCH_CRITER_GRP_TOPIC );
       
   330                 textArray->AppendL( *txtUserWVId );
       
   331                 CleanupStack::PopAndDestroy( txtUserWVId );
       
   332                 indexArray.AppendL( TEnumsPC::ESearchGroupTopic );
       
   333                 }
       
   334 
       
   335             if ( IMUtils::IntResourceValueL(
       
   336                      RSC_CHAT_VARIATION_SEARCH_GROUPMEMBER ) )
       
   337                 {
       
   338                 HBufC* txtGroupMember = CCoeEnv::Static()->AllocReadResourceLC(
       
   339                                             R_QTN_CHAT_SEARCH_CRITER_GRP_USER );
       
   340                 textArray->AppendL( *txtGroupMember );
       
   341                 CleanupStack::PopAndDestroy( txtGroupMember );
       
   342                 indexArray.AppendL( TEnumsPC::ESearchGroupUserIDJoined );
       
   343                 }
       
   344             break;
       
   345             }
       
   346         default:
       
   347             {
       
   348             User::Leave( KErrNotSupported );
       
   349             break;
       
   350             }
       
   351         }
       
   352 
       
   353     dlg->SetOwnershipType( ELbmOwnsItemArray );
       
   354     dlg->SetItemTextArray( textArray );
       
   355     CleanupStack::Pop( textArray );
       
   356 
       
   357     HBufC* heading = CCoeEnv::Static()->AllocReadResourceLC(
       
   358                          R_CHATCLIENT_SEARCH_CRITERIA_USER_HEADING );
       
   359     dlg->SetHeaderTextL( *heading );
       
   360 
       
   361     CleanupStack::PopAndDestroy( heading );
       
   362 
       
   363     result = dlg->RunLD();
       
   364 
       
   365     TBool returnValue( EFalse );
       
   366 
       
   367     if ( ( result == EAknSoftkeyOk ) || ( result == EAknSoftkeyYes ) )
       
   368         {
       
   369         // map the returned index to real index
       
   370         TEnumsPC::TSearchCriteria resolvedSearchCrit = indexArray[ searchCriteria ];
       
   371 
       
   372         switch ( resolvedSearchCrit )
       
   373             {
       
   374             case TEnumsPC::ESearchGroupName:
       
   375             case TEnumsPC::ESearchGroupTopic:
       
   376             case TEnumsPC::ESearchGroupUserIDJoined:
       
   377             case TEnumsPC::ESearchUserID:
       
   378             case TEnumsPC::ESearchUserMobileNumber:
       
   379             case TEnumsPC::ESearchUserEmailAddress:
       
   380                 {
       
   381                 returnValue = DisplaySearchStringQueryL( resolvedSearchCrit );
       
   382                 break;
       
   383                 }
       
   384             case TEnumsPC::ESearchUserName:
       
   385                 {
       
   386                 CHAT_DP_TXT( "SEARCH criteria is EImpsUserFirstName" );
       
   387                 returnValue = DisplayMultiLineDataQueryL( );
       
   388                 break;
       
   389                 }
       
   390 
       
   391             default:
       
   392                 {
       
   393                 break;
       
   394                 }
       
   395             }
       
   396         }
       
   397 
       
   398     CleanupStack::PopAndDestroy(); // indexArray.Close()
       
   399 
       
   400     return returnValue;
       
   401     }
       
   402 
       
   403 // ---------------------------------------------------------
       
   404 // CCASearchViewContainer::DisplaySearchStringQueryL()
       
   405 // Displays search string query
       
   406 // (other items were commented in a header).
       
   407 // ---------------------------------------------------------
       
   408 //
       
   409 TBool CCASearchViewContainer::DisplaySearchStringQueryL(
       
   410     TEnumsPC::TSearchCriteria aSearchCriteria )
       
   411     {
       
   412     CHAT_DP( D_CHAT_LIT( "CCASearchViewContainer::DisplaySearchStringQueryL" ) );
       
   413 
       
   414     HBufC* searchString = HBufC::NewLC( KMaxSearchStringLength );
       
   415     TPtr searchStringPtr( searchString->Des() );
       
   416 
       
   417     CAknQueryDialog* dlg = CAknQueryDialog::NewL( searchStringPtr );
       
   418     if ( aSearchCriteria == TEnumsPC::ESearchUserMobileNumber )
       
   419         {
       
   420         dlg->PrepareLC( R_CHATCLIENT_SEARCH_MOBNMB_QUERY );
       
   421         }
       
   422     else if ( aSearchCriteria == TEnumsPC::ESearchGroupUserIDJoined
       
   423               || aSearchCriteria == TEnumsPC::ESearchUserID )
       
   424         {
       
   425         // AH neutral queries for WVID also have a special label resource
       
   426         CleanupStack::PushL( dlg );
       
   427         TBool textualInputMode = IMUtils::IntResourceValueL( RSC_CHAT_VARIATION_USERID_TEXTUAL_INPUTMODE );
       
   428         CleanupStack::Pop( dlg );
       
   429         dlg->PrepareLC( textualInputMode ?
       
   430                         R_CHATCLIENT_SEARCH_WVID_QUERY :
       
   431                         R_CHATCLIENT_SEARCH_WVID_QUERY2 );
       
   432         }
       
   433     else if ( aSearchCriteria == TEnumsPC::ESearchUserEmailAddress )
       
   434         {
       
   435         // General queries which always demand latin characters
       
   436         // even in AH build and others.
       
   437         dlg->PrepareLC( R_CHATCLIENT_SEARCH_STRING_QUERY_AH_NEUTRAL );
       
   438         }
       
   439     else
       
   440         {
       
   441         dlg->PrepareLC( R_CHATCLIENT_SEARCH_STRING_QUERY );
       
   442         }
       
   443 
       
   444     // enable T9
       
   445     dlg->SetPredictiveTextInputPermitted( ETrue );
       
   446 
       
   447     TInt result( dlg->RunLD() );
       
   448     if ( ( result == EAknSoftkeyOk ) || ( result == EAknSoftkeyYes ) )
       
   449         {
       
   450         // Build the search pairs//////////////////////////////////////////////
       
   451 
       
   452         RArray<TEnumsPC::TSearchCriteria>  searchCriteriaArray;
       
   453         CleanupClosePushL( searchCriteriaArray );
       
   454 
       
   455         CDesCArray* searchStringArray =  new ( ELeave ) CDesCArrayFlat( 1 );
       
   456         CleanupStack::PushL( searchStringArray );
       
   457 
       
   458         if ( searchStringPtr.Length() > 0 )
       
   459             {
       
   460             searchCriteriaArray.Append( aSearchCriteria );
       
   461             searchStringArray->AppendL( searchStringPtr );
       
   462             CCAAppUi* appUi = static_cast <CCAAppUi*> ( CCoeEnv::Static()->AppUi() );
       
   463             MCASearchInterfacePC* searchInterfacePC
       
   464             = appUi->GetProcessManager().GetSearchInterface();
       
   465             searchInterfacePC->SetRequestL( searchCriteriaArray,
       
   466                                             *searchStringArray );
       
   467             }
       
   468 
       
   469         CleanupStack::PopAndDestroy( searchStringArray ); //searchStringArray
       
   470         CleanupStack::PopAndDestroy( ); // searchCriteriaArray.Close()
       
   471         CleanupStack::PopAndDestroy( searchString );
       
   472         return ETrue;
       
   473         }
       
   474 
       
   475     CleanupStack::PopAndDestroy( searchString );
       
   476 
       
   477     return EFalse;
       
   478     }
       
   479 
       
   480 
       
   481 // ---------------------------------------------------------
       
   482 // CCASearchViewContainer::DisplayMultiLineDataQueryL()
       
   483 // Displays multiline data query. First line is for firsname
       
   484 // and second line is for surname.
       
   485 // (other items were commented in a header).
       
   486 // ---------------------------------------------------------
       
   487 //
       
   488 TBool CCASearchViewContainer::DisplayMultiLineDataQueryL( )
       
   489     {
       
   490     CHAT_DP( D_CHAT_LIT( "CCASearchViewContainer::DisplayMultiLineDataQueryL" ) );
       
   491 
       
   492     HBufC* firstName = HBufC::NewLC( KMaxFirstNameLength );
       
   493     HBufC* surname = HBufC::NewLC( KMaxSurnameLength );
       
   494 
       
   495     HBufC* searchString = HBufC::NewLC( KMaxFirstNameLength +
       
   496                                         KMaxSurnameLength + KSpace().Length() );
       
   497 
       
   498     TPtr firstNamePtr( firstName->Des() );
       
   499     TPtr surnamePtr( surname->Des() );
       
   500 
       
   501     CCAMultiLineDataQueryDialog* dlg =
       
   502         CCAMultiLineDataQueryDialog::NewL( firstNamePtr, surnamePtr );
       
   503 
       
   504     dlg->PrepareLC( R_CHATCLIENT_SEARCH_NAME_QUERY );
       
   505     // enable T9
       
   506     dlg->SetPredictiveTextInputPermitted( ETrue );
       
   507     TInt result( dlg->RunLD() );
       
   508 
       
   509     TPtr searchStringPtr( searchString->Des() );
       
   510     searchStringPtr.Append( *firstName );
       
   511     searchStringPtr.Append( KEmptyDesC );
       
   512     searchStringPtr.Append( *surname );
       
   513 
       
   514     CHAT_DP_TXT( "Before query" );
       
   515 
       
   516     if ( ( result == EAknSoftkeyOk ) || ( result == EAknSoftkeyYes ) )
       
   517         {
       
   518         // Build the search pairs//////////////////////////////////////////////
       
   519 
       
   520         RArray<TEnumsPC::TSearchCriteria>  searchCriteriaArray;
       
   521         CleanupClosePushL( searchCriteriaArray );
       
   522 
       
   523         CDesCArray* searchStringArray =  new ( ELeave ) CDesCArrayFlat( KGranularity );
       
   524         CleanupStack::PushL( searchStringArray );
       
   525 
       
   526 
       
   527         // Append firstname
       
   528         if ( firstNamePtr.Length() > 0 )
       
   529             {
       
   530             searchCriteriaArray.Append( TEnumsPC::ESearchUserName );
       
   531             searchStringArray->AppendL( firstNamePtr );
       
   532             }
       
   533 
       
   534         if ( surnamePtr.Length() > 0 )
       
   535             {
       
   536             searchCriteriaArray.Append( TEnumsPC::ESearchUserLastName );
       
   537             searchStringArray->AppendL( surnamePtr );
       
   538             }
       
   539 
       
   540         if ( firstNamePtr.Length() > 0 ||  surnamePtr.Length() > 0 )
       
   541             {
       
   542             CCAAppUi* appUi = static_cast <CCAAppUi*> ( CCoeEnv::Static()->AppUi() );
       
   543             MCASearchInterfacePC* searchInterfacePC
       
   544             = appUi->GetProcessManager().GetSearchInterface();
       
   545             searchInterfacePC->SetRequestL( searchCriteriaArray, *searchStringArray );
       
   546             }
       
   547 
       
   548 
       
   549         CleanupStack::PopAndDestroy( searchStringArray ); //searchStringArray
       
   550         CleanupStack::PopAndDestroy(  ); // searchCriteriaArray.Close()
       
   551 
       
   552         CleanupStack::PopAndDestroy( 3, firstName ); // searchString, surname, firstName
       
   553         return ETrue;
       
   554         }
       
   555 
       
   556     CleanupStack::PopAndDestroy( 3, firstName ); // searchString, surname, firstName
       
   557     return EFalse;
       
   558     }
       
   559 
       
   560 // ---------------------------------------------------------
       
   561 // CCASearchViewContainer::SearchType() const
       
   562 // returns searchtype
       
   563 // (other items were commented in a header).
       
   564 // ---------------------------------------------------------
       
   565 //
       
   566 CCASearchViewContainer::TSearchType CCASearchViewContainer::SearchType() const
       
   567     {
       
   568     return iSearchType;
       
   569     }
       
   570 
       
   571 // ---------------------------------------------------------
       
   572 // CCASearchViewContainer::SearchMoreL()
       
   573 // ---------------------------------------------------------
       
   574 //
       
   575 void CCASearchViewContainer::SearchMoreL()
       
   576     {
       
   577     CHAT_DP_TXT( "CCASearchViewContainer::SearchMoreL" );
       
   578     //If error happens then we need old indexes
       
   579     TInt oldSearchIndex( iNextSearchIndex );
       
   580     TInt oldCurrentResultPage( iCurrentResultPage );
       
   581     iNextSearchIndex += KMaxSearchResults;
       
   582     TInt searchCount( iSearchDataPC->HowManyResultsAvailable() );
       
   583     //Next searchIndex cannot be bigger than search count
       
   584     if ( iNextSearchIndex > searchCount )
       
   585         {
       
   586         iNextSearchIndex = searchCount - 1;
       
   587         }
       
   588 
       
   589 
       
   590     ++iCurrentResultPage;
       
   591     //If currentresultpage is bigger than total result page then
       
   592     //currentresultpage is total resultpage
       
   593     if ( iCurrentResultPage > iTotalResultPages )
       
   594         {
       
   595         iCurrentResultPage = iTotalResultPages;
       
   596         }
       
   597     CHAT_DP( D_CHAT_LIT( " iCurrentResultPage = %d iTotalResultPages = %d" ),
       
   598              iCurrentResultPage, iTotalResultPages );
       
   599     CHAT_DP( D_CHAT_LIT( " iNextSearchIndex = %d " ), iNextSearchIndex );
       
   600 
       
   601 
       
   602     iAppUi->ShowWaitDialogL( R_QTN_CHAT_WNOTE_SEARCHING );
       
   603     TInt err( KErrNone );
       
   604     TRAPD( nextErr, err = iSearchInterfacePC->SearchNextL( iNextSearchIndex,
       
   605                                                            NULL ) );
       
   606 
       
   607     //If search fails dialog is dismissed and index are set as previous state
       
   608     if ( nextErr )
       
   609         {
       
   610         iAppUi->DismissWaitDialogL( nextErr );
       
   611         iNextSearchIndex = oldSearchIndex;
       
   612         iCurrentResultPage = oldCurrentResultPage;
       
   613         }
       
   614 
       
   615     //If search fails dialog is dismissed and index are set as previous state
       
   616     if ( err )
       
   617         {
       
   618         iAppUi->DismissWaitDialogL( err );
       
   619         iNextSearchIndex = oldSearchIndex;
       
   620         iCurrentResultPage = oldCurrentResultPage;
       
   621         }
       
   622     else
       
   623         {
       
   624         TInt maxDataCount( iSearchDataPC->SearchDataCount() );
       
   625 
       
   626         iLowIndex = iNextSearchIndex;
       
   627 
       
   628         iHighIndex = iLowIndex + ( KMaxSearchResults - 1 );
       
   629 
       
   630         if ( iHighIndex >= maxDataCount )
       
   631             {
       
   632             iHighIndex = maxDataCount - 1;
       
   633             }
       
   634         if ( iSearchType == ESearchUsers )
       
   635             {
       
   636             //If searching users and presence fetch fails dialog is dismissed
       
   637             TRAPD( fetchErr, FetchPresenceL( iLowIndex, iHighIndex ) );
       
   638             if ( fetchErr != KErrNone )
       
   639                 {
       
   640                 iAppUi->DismissWaitDialogL( fetchErr );
       
   641                 }
       
   642             }
       
   643         //Is view update fails dialog is dismissed
       
   644         TRAPD( updateErr, UpdateListBoxL( !iSearchUsers ) );
       
   645         if ( updateErr )
       
   646             {
       
   647             iAppUi->DismissWaitDialogL( updateErr );
       
   648             }
       
   649 
       
   650         CHAT_DP( D_CHAT_LIT(
       
   651                      "CCASearchViewContainer::SearchMoreL HideWaitNoteL" ) );
       
   652         iAppUi->DismissWaitDialogL( KErrNone );
       
   653         }
       
   654 
       
   655 
       
   656     }
       
   657 
       
   658 // ---------------------------------------------------------
       
   659 // CCASearchViewContainer::SearchPreviousL()
       
   660 // ---------------------------------------------------------
       
   661 //
       
   662 void CCASearchViewContainer::SearchPreviousL()
       
   663     {
       
   664     CHAT_DP_TXT( "CCASearchViewContainer::SearchPreviousL" );
       
   665 
       
   666     TInt oldSearchIndex( iNextSearchIndex );
       
   667     TInt oldCurrentResultPage( iCurrentResultPage );
       
   668     //Setting up search indexes
       
   669     iNextSearchIndex -= KMaxSearchResults;
       
   670     if ( iNextSearchIndex < 0 )
       
   671         {
       
   672         iNextSearchIndex = 0;
       
   673         }
       
   674 
       
   675     //Setting up result page numbers that are shown in navipane
       
   676     --iCurrentResultPage;
       
   677     if ( iCurrentResultPage < 1 )
       
   678         {
       
   679         iCurrentResultPage = 1;
       
   680         }
       
   681     CHAT_DP( D_CHAT_LIT( " iCurrentResultPage = %d iTotalResultPages = %d" ),
       
   682              iCurrentResultPage, iTotalResultPages );
       
   683     CHAT_DP( D_CHAT_LIT( " iNextSearchIndex = %d " ), iNextSearchIndex );
       
   684 
       
   685     iAppUi->ShowWaitDialogL( R_QTN_CHAT_WNOTE_SEARCHING );
       
   686 
       
   687     TInt err( KErrNone );
       
   688     TRAPD( nextErr, err = iSearchInterfacePC->SearchNextL( iNextSearchIndex,
       
   689                                                            NULL ) );
       
   690     if ( nextErr )
       
   691         {
       
   692         iAppUi->DismissWaitDialogL( nextErr );
       
   693         iNextSearchIndex = oldSearchIndex;
       
   694         iCurrentResultPage = oldCurrentResultPage;
       
   695         }
       
   696 
       
   697     if ( err )
       
   698         {
       
   699         iAppUi->DismissWaitDialogL( err );
       
   700         iNextSearchIndex = oldSearchIndex;
       
   701         iCurrentResultPage = oldCurrentResultPage;
       
   702         }
       
   703     else
       
   704         {
       
   705         TInt maxDataCount( iSearchDataPC->SearchDataCount() );
       
   706 
       
   707         iLowIndex = iNextSearchIndex;
       
   708 
       
   709         iHighIndex = iLowIndex + ( KMaxSearchResults - 1 );
       
   710 
       
   711         if ( iHighIndex >= maxDataCount )
       
   712             {
       
   713             iHighIndex = maxDataCount - 1;
       
   714             }
       
   715 
       
   716         if ( iSearchType == ESearchUsers )
       
   717             {
       
   718             TRAPD( fetchErr, FetchPresenceL( iLowIndex, iHighIndex ) );
       
   719             if ( fetchErr != KErrNone )
       
   720                 {
       
   721                 iAppUi->DismissWaitDialogL( fetchErr );
       
   722                 }
       
   723             }
       
   724         TRAPD( updateErr, UpdateListBoxL( !iSearchUsers ) );
       
   725         if ( updateErr )
       
   726             {
       
   727             iAppUi->DismissWaitDialogL( updateErr );
       
   728             }
       
   729         CHAT_DP( D_CHAT_LIT(
       
   730                      "CCASearchViewContainer::SearchPreviousL HideWaitNoteL" ) );
       
   731         iAppUi->DismissWaitDialogL( KErrNone );
       
   732         }
       
   733     }
       
   734 
       
   735 // ---------------------------------------------------------
       
   736 // CCASearchViewContainer::SetObserverToNull()
       
   737 // ---------------------------------------------------------
       
   738 //
       
   739 void CCASearchViewContainer::SetObserverToNull()
       
   740     {
       
   741     }
       
   742 
       
   743 // ---------------------------------------------------------
       
   744 // CCASearchViewContainer::SaveAsFavouriteL()
       
   745 // (other items were commented in a header).
       
   746 // ---------------------------------------------------------
       
   747 //
       
   748 void CCASearchViewContainer::SaveAsFavouriteL()
       
   749     {
       
   750     HBufC* groupId = SearchData().AllocLC();
       
   751 
       
   752     iSearchInterfacePC->CreateGroupL( *groupId );
       
   753 
       
   754     iAppUi->ShowWaitDialogL( R_QTN_CHAT_CLIST_WAIT_SAVING );
       
   755 
       
   756     TInt err( KErrNone );
       
   757 
       
   758     TBool hasCommonProps( EFalse );
       
   759     TEnumsPC::TImpsCSPAllErrors impsError = TEnumsPC::EImpsErrNone;
       
   760     TPtrC groupName( KNullDesC() );
       
   761     TRAPD( leave, groupName.Set( iSearchInterfacePC->GetGroupNameL(
       
   762                                      *groupId, hasCommonProps, impsError ) ) );
       
   763     if ( impsError == TEnumsPC::EImpsErrNone )
       
   764         {
       
   765         iAppUi->DismissWaitDialogL( leave );
       
   766         if ( ( err != KErrNone ) || ( !hasCommonProps ) )
       
   767             {
       
   768             // Filter out the insufficient priviledges message,
       
   769             // since it's not an error if server doesn't allow us
       
   770             // to see the name of the group.
       
   771             if ( err != ( TInt ) TEnumsPC::ECSPInsufficientGroupPrivileges )
       
   772                 {
       
   773                 IMNoteMapper::ShowNoteL( err );
       
   774                 }
       
   775             }
       
   776         else
       
   777             {
       
   778             iSearchInterfacePC->SetGroupNameL( *groupId, groupName );
       
   779             }
       
   780         iSearchInterfacePC->SaveChangesL( *groupId );
       
   781 
       
   782         }
       
   783     else
       
   784         {
       
   785         iAppUi->DismissWaitDialogL( leave );
       
   786         }
       
   787 
       
   788     CHAT_DP_FUNC_DP( "SaveAsFavouriteL", "Group saved" );
       
   789 
       
   790 
       
   791     CleanupStack::PopAndDestroy( groupId );
       
   792     }
       
   793 
       
   794 // ---------------------------------------------------------
       
   795 // CCASearchViewContainer::AddToFriendsL()
       
   796 // (other items were commented in a header).
       
   797 // ---------------------------------------------------------
       
   798 //
       
   799 void CCASearchViewContainer::AddToFriendsL()
       
   800     {
       
   801     // Make sure we have contact list
       
   802     if ( CCAUINGUtils::VerifyContactlistL() == CCAUINGUtils::EChatNoContactList )
       
   803         {
       
   804         return;
       
   805         }
       
   806 
       
   807     HBufC* wvuidBuf = SearchData().AllocLC();
       
   808 
       
   809     CCAStatusPaneHandler& statusPane = *iViewSwitcher.CAStatusPane();
       
   810     HBufC* titleText = statusPane.Title()->AllocLC();
       
   811 
       
   812     TBool contactSaved( EFalse );
       
   813 
       
   814     CCAContactEditor* contactEditor = CCAContactEditor::NewL( -1,
       
   815                                                               contactSaved );
       
   816 
       
   817     TRAPD( err, contactEditor->EditContactLD( TEnumsPC::EAddToContact, KNullDesC, *wvuidBuf,
       
   818                                               KNullDesC ) );
       
   819     if ( err )
       
   820         {
       
   821         statusPane.SetTitleL( *titleText );
       
   822         User::Leave( err );
       
   823         }
       
   824 
       
   825     statusPane.SetTitleL( *titleText );
       
   826 
       
   827     CleanupStack::PopAndDestroy( 2, wvuidBuf ); // titleText, wvuidBuf
       
   828     }
       
   829 
       
   830 // ---------------------------------------------------------
       
   831 // CCASearchViewContainer::StartConversationL()
       
   832 // (other items were commented in a header).
       
   833 // ---------------------------------------------------------
       
   834 //
       
   835 void CCASearchViewContainer::StartConversationL()
       
   836     {
       
   837     // Check status of contact
       
   838     if ( !IsOnline() )
       
   839         {
       
   840         // Check if user wants to start conversation with offline contact
       
   841         if ( IMUtils::IgnoreOfflineStatusL(
       
   842                  iSearchDataPC->IdentificationL( SearchData() ) ) < 0 )
       
   843             {
       
   844             return;
       
   845             }
       
   846         }
       
   847 
       
   848     //Add the conversation item to open chats array before switching the view
       
   849     MCAMainViewArrayPC* mainViewArrayPC = iAppUi->GetProcessManager().GetArrayInterface();
       
   850     TPtrC wvid( SearchData() );
       
   851     mainViewArrayPC->InsertConversationItemL( wvid, iSearchDataPC->IdentificationL( wvid ) );
       
   852 
       
   853     TCADnlConvView dnlConView;
       
   854 
       
   855     //collecting only first KMaxWVIDLength character in iWVID.
       
   856     dnlConView.iWVID = ( CAUtils::DisplayId( SearchData() ) ).Left( KMaxWVIDLength );
       
   857     dnlConView.iIsForwarded = EFalse;
       
   858     dnlConView.iSAPChanged = EFalse;
       
   859     dnlConView.iSwitchTab = EFalse;
       
   860     TCADnlConvViewBuf convMsgBuf( dnlConView );
       
   861 
       
   862     CHAT_DP( D_CHAT_LIT( "start conversation with %S" ), &dnlConView.iWVID );
       
   863     iViewSwitcher.SwitchViewL( KUidConversationsView, KUidConvViewMsgId,
       
   864                                convMsgBuf );
       
   865     }
       
   866 
       
   867 // ---------------------------------------------------------
       
   868 // CCASearchViewContainer::InviteL()
       
   869 // (other items were commented in a header).
       
   870 // ---------------------------------------------------------
       
   871 //
       
   872 void CCASearchViewContainer::InviteL()
       
   873     {
       
   874 
       
   875     /**
       
   876     * 1) PairsArray is Owned. Ownership is transferred from
       
   877     * 2) There's no need to skip groups in this case. but we do need to make sure
       
   878          the pairs are in correct order after sorting
       
   879     * 3) We can use CCAServerContactsArray, as we deal with descriptor tuple
       
   880          just as with contacts. the class naming is a bit misleading
       
   881     */
       
   882     MCAServerContactsArrayPC* pairsArray
       
   883     = iSearchInterfacePC->GetPairArrayForServerContactsArrayLC();
       
   884 
       
   885 
       
   886     TInt selectedIndex( 0 );
       
   887 
       
   888     // Check status of contact
       
   889     if ( !IsOnline() )
       
   890         {
       
   891         // Check if user wants to invite offline contact
       
   892         if ( IMUtils::IgnoreOfflineStatusL(
       
   893                  iSearchDataPC->IdentificationL( SearchData() ) ) < 0 )
       
   894             {
       
   895             // Stop invitation process
       
   896             CleanupStack::PopAndDestroy(); // pairsArray
       
   897 
       
   898             return;
       
   899             }
       
   900         }
       
   901 
       
   902     TInt retVal = IMDialogUtils::DisplayListQueryDialogL( &selectedIndex,
       
   903                                                           pairsArray,
       
   904                                                           R_SEARCHVIEW_SELECT_INVITE_GROUP_DLG );
       
   905 
       
   906     if ( retVal == EAknSoftkeyOk || retVal == EAknSoftkeyDone )
       
   907         {
       
   908         if ( selectedIndex == KErrNotFound )
       
   909             {
       
   910             User::Leave( KErrNotFound );
       
   911             }
       
   912         CCAInviteEditor* editor = CCAInviteEditor::NewL(
       
   913                                       pairsArray->WVIDArray().MdcaPoint( selectedIndex ) );
       
   914 
       
   915         editor->CreateAndSendInvitation(  *( iAppUi->GroupUtils() ) , SearchData() );
       
   916         delete editor;
       
   917         }
       
   918 
       
   919     CleanupStack::PopAndDestroy(); // pairsArray
       
   920 
       
   921     }
       
   922 
       
   923 // ---------------------------------------------------------
       
   924 // CCASearchViewContainer::EndSearchL()
       
   925 // (other items were commented in a header).
       
   926 // ---------------------------------------------------------
       
   927 //
       
   928 void CCASearchViewContainer::EndSearchL()
       
   929     {
       
   930     iTotalResultPages = 0;
       
   931     iCurrentResultPage = 0;
       
   932     iNextSearchIndex = 0;
       
   933     iLowIndex = 0;
       
   934     iPreviousResultsShowing = EFalse;
       
   935     iHighIndex = 0;
       
   936     iOnlinePresenceList->Reset();
       
   937     UpdateNaviPaneTextL( ETrue );
       
   938     }
       
   939 
       
   940 // ---------------------------------------------------------
       
   941 // CCASearchViewContainer::NewSearchL()
       
   942 // (other items were commented in a header).
       
   943 // ---------------------------------------------------------
       
   944 //
       
   945 void CCASearchViewContainer::NewSearchL()
       
   946     {
       
   947     CHAT_DP( D_CHAT_LIT( "CCASearchViewContainer::NewSearchL" ) );
       
   948     if ( DisplaySearchTypeDlgL() )
       
   949         {
       
   950         if ( iSearchInterfacePC->IsSearchPairsSet() )
       
   951             {
       
   952             StartSearchL( );
       
   953             }
       
   954 
       
   955         }
       
   956     }
       
   957 
       
   958 // ---------------------------------------------------------
       
   959 // CCASearchViewContainer::JoinToGroupL
       
   960 // (other items were commented in a header).
       
   961 // ---------------------------------------------------------
       
   962 //
       
   963 void CCASearchViewContainer::JoinToGroupL()
       
   964     {
       
   965     HBufC* groupId = SearchData().AllocLC();
       
   966     static_cast <CCAAppUi*> ( iEikonEnv->AppUi() )
       
   967     ->GroupUtils()->JoinGroupL( EFalse, *groupId );
       
   968     CleanupStack::PopAndDestroy( groupId );
       
   969     }
       
   970 
       
   971 // ---------------------------------------------------------
       
   972 // CCASearchViewContainer::BlockUserL()
       
   973 // (other items were commented in a header).
       
   974 // ---------------------------------------------------------
       
   975 //
       
   976 void CCASearchViewContainer::BlockUserL()
       
   977     {
       
   978     iBlockingUI->BlockUserL( SearchData() );
       
   979     }
       
   980 
       
   981 // ---------------------------------------------------------
       
   982 // CCASearchViewContainer::IsBlocked()
       
   983 // (other items were commented in a header).
       
   984 // ---------------------------------------------------------
       
   985 //
       
   986 TBool CCASearchViewContainer::IsBlocked() const
       
   987     {
       
   988     TPtrC searchedData ( SearchData() );
       
   989     MCABlockingPC* blockingPC = iAppUi->GetProcessManager().GetBlockingInterface();
       
   990     return blockingPC->IsContactBlocked( searchedData );
       
   991     }
       
   992 
       
   993 // ---------------------------------------------------------
       
   994 // CCASearchViewContainer::ListBox()
       
   995 // (other items were commented in a header).
       
   996 // ---------------------------------------------------------
       
   997 //
       
   998 CEikListBox* CCASearchViewContainer::ListBox() const
       
   999     {
       
  1000     return iListBox;
       
  1001     }
       
  1002 
       
  1003 // ---------------------------------------------------------
       
  1004 // CCASearchViewContainer::SearchData()
       
  1005 // (other items were commented in a header).
       
  1006 // ---------------------------------------------------------
       
  1007 //
       
  1008 TPtrC CCASearchViewContainer::SearchData() const
       
  1009     {
       
  1010     CHAT_DP( D_CHAT_LIT( "CCASearchViewContainer::SearchData" ) );
       
  1011     TInt curIndex = iListBox->CurrentItemIndex();
       
  1012     TInt dataCount = iSearchDataPC->SearchDataCount();
       
  1013     if ( curIndex < 0 || dataCount == 0 )
       
  1014         {
       
  1015         return KNullDesC();
       
  1016         }
       
  1017     else
       
  1018         {
       
  1019         TInt searchDataIndex( curIndex + ( ( iCurrentResultPage - 1 ) *
       
  1020                                            KMaxSearchResults ) );
       
  1021         if ( searchDataIndex >= dataCount )
       
  1022             {
       
  1023             searchDataIndex = dataCount - 1;
       
  1024             }
       
  1025         if ( searchDataIndex < 0 )
       
  1026             {
       
  1027             searchDataIndex = 0;
       
  1028             }
       
  1029         return iSearchDataPC->SearchData( searchDataIndex );
       
  1030         }
       
  1031     }
       
  1032 
       
  1033 // ---------------------------------------------------------
       
  1034 // CCASearchViewContainer::IsOnline()
       
  1035 // (other items were commented in a header).
       
  1036 // ---------------------------------------------------------
       
  1037 //
       
  1038 TBool CCASearchViewContainer::IsOnline() const
       
  1039     {
       
  1040     TInt curIndex( iListBox->CurrentItemIndex() );
       
  1041 
       
  1042     if ( ( curIndex < 0 ) || ( curIndex >= iOnlineArray.Count() ) )
       
  1043         {
       
  1044         return EFalse;
       
  1045         }
       
  1046     return iOnlineArray[ curIndex ];
       
  1047     }
       
  1048 
       
  1049 // ---------------------------------------------------------
       
  1050 // CCASearchViewContainer::BlockUserWVIdL()
       
  1051 // (other items were commented in a header).
       
  1052 // ---------------------------------------------------------
       
  1053 //
       
  1054 void CCASearchViewContainer::BlockUserWVIdL()
       
  1055     {
       
  1056     iBlockingUI->DisplayBlockTextQueryL();
       
  1057     }
       
  1058 // ---------------------------------------------------------
       
  1059 // CCASearchViewContainer::UnBlockL()
       
  1060 // ---------------------------------------------------------
       
  1061 void CCASearchViewContainer::UnBlockL()
       
  1062     {
       
  1063     iBlockingUI->DisplayUnblockListQueryL();
       
  1064     }
       
  1065 // ---------------------------------------------------------
       
  1066 // CCASearchViewContainer::DisplayBlockedListL()
       
  1067 // ---------------------------------------------------------
       
  1068 //
       
  1069 void CCASearchViewContainer::DisplayBlockedListL()
       
  1070     {
       
  1071     iBlockingUI->DisplayBlockedListL( ETrue );
       
  1072     UpdateNaviPaneTextL( EFalse );
       
  1073     }
       
  1074 
       
  1075 // ---------------------------------------------------------
       
  1076 // CCASearchViewContainer::MoreResultsAvailableL() const
       
  1077 // (other items were commented in a header).
       
  1078 // ---------------------------------------------------------
       
  1079 //
       
  1080 TBool CCASearchViewContainer::MoreResultsAvailable() const
       
  1081     {
       
  1082     return ( iCurrentResultPage < iTotalResultPages );
       
  1083     }
       
  1084 
       
  1085 // ---------------------------------------------------------
       
  1086 // CCASearchViewContainer::PrevResultsAvailableL() const
       
  1087 // (other items were commented in a header).
       
  1088 // ---------------------------------------------------------
       
  1089 //
       
  1090 TBool CCASearchViewContainer::PrevResultsAvailable() const
       
  1091     {
       
  1092     return ( iCurrentResultPage != 1 );
       
  1093     }
       
  1094 
       
  1095 // ---------------------------------------------------------
       
  1096 // CCASearchViewContainer::IsFavouriteChatGroupL()
       
  1097 // (other items were commented in a header).
       
  1098 // ---------------------------------------------------------
       
  1099 //
       
  1100 TBool CCASearchViewContainer::IsFavouriteChatGroup() const
       
  1101     {
       
  1102     TBool isFavourite = iSearchInterfacePC->IsFavouriteChatGroup( SearchData() );
       
  1103     return isFavourite;
       
  1104     }
       
  1105 
       
  1106 
       
  1107 // ---------------------------------------------------------
       
  1108 // CCASearchViewContainer::HandleError()
       
  1109 // ---------------------------------------------------------
       
  1110 //
       
  1111 void CCASearchViewContainer::HandleSearchError( TInt aErrorCode )
       
  1112     {
       
  1113     CHAT_DP( D_CHAT_LIT( "CCASearchViewContainer::HandleError( %d )" ),
       
  1114              aErrorCode );
       
  1115     // CodeScanner warning ignored because CS does not regognize TRAP being used
       
  1116     // after line break
       
  1117     TRAPD( err, ( iAppUi->DismissWaitDialogL( aErrorCode ) ) );  // CSI: 42 # See comment above
       
  1118     if ( err )
       
  1119         {
       
  1120         CActiveScheduler::Current()->Error( err );
       
  1121         }
       
  1122     }
       
  1123 
       
  1124 
       
  1125 // ---------------------------------------------------------
       
  1126 // CCASearchViewContainer::HandleSearchFinished()
       
  1127 // ---------------------------------------------------------
       
  1128 //
       
  1129 void CCASearchViewContainer::HandleSearchFinished( )
       
  1130     {
       
  1131     }
       
  1132 
       
  1133 // ---------------------------------------------------------
       
  1134 // CCASearchViewContainer::StartSearchL()
       
  1135 // (other items were commented in a header).
       
  1136 // ---------------------------------------------------------
       
  1137 //
       
  1138 void CCASearchViewContainer::StartSearchL( )
       
  1139     {
       
  1140     // Construct string for status pane title from aSearchPairs
       
  1141 
       
  1142     HBufC* searchString = iSearchInterfacePC->GetSearchStringLC();
       
  1143 
       
  1144     iViewSwitcher.CAStatusPane()->SetTitleL(
       
  1145         R_CHATCLIENT_SEARCH_RESULTS_TITLE, *searchString );
       
  1146 
       
  1147     CleanupStack::PopAndDestroy( searchString );
       
  1148 
       
  1149     // Check iSearchDataPC->SearchDataCount() > 0
       
  1150     // it is more reliable because app engine keeps previous results
       
  1151 
       
  1152 
       
  1153     CHAT_DP( D_CHAT_LIT( "CCASearchViewContainer::StartSearchL" ) );
       
  1154     if ( iPreviousResultsShowing || iSearchDataPC->SearchDataCount() > 0 )
       
  1155         {
       
  1156         ClearListBoxContents();
       
  1157 
       
  1158         iAppUi->ShowWaitDialogL( R_QTN_CHAT_WNOTE_SEARCHING );
       
  1159         TRAPD( endErr, EndSearchL() );
       
  1160         if ( endErr )
       
  1161             {
       
  1162             iAppUi->DismissWaitDialogL( endErr );
       
  1163             User::Leave( endErr );
       
  1164             }
       
  1165         }
       
  1166     else
       
  1167         {
       
  1168         iAppUi->ShowWaitDialogL( R_QTN_CHAT_WNOTE_SEARCHING );
       
  1169         }
       
  1170 
       
  1171     TInt err( KErrNone );
       
  1172     TRAPD( startErr, err = iSearchInterfacePC->StartSearchL(
       
  1173                                KMaxSearchResults, NULL , NULL ) );
       
  1174 
       
  1175     if ( startErr )
       
  1176         {
       
  1177         iAppUi->DismissWaitDialogL( startErr );
       
  1178         User::Leave( startErr );
       
  1179         }
       
  1180 
       
  1181     if ( err )
       
  1182         {
       
  1183         CHAT_DP( D_CHAT_LIT( "CCASearchViewContainer::StartSearchL err=%d " ), err );
       
  1184 
       
  1185         if ( err == TEnumsPC::ECSPNotSupported || err == TEnumsPC::ECSPInvalidParameter )
       
  1186             {
       
  1187             // map 402 and 405 to "search criteria not supported"
       
  1188             iAppUi->DismissWaitDialogL( KErrNone );
       
  1189             IMDialogUtils::DisplayInformationNoteL(
       
  1190                 R_QTN_CHAT_SEARCH_NOT_SUPPORTED );
       
  1191             }
       
  1192         else
       
  1193             {
       
  1194             iAppUi->DismissWaitDialogL( err );
       
  1195             }
       
  1196         }
       
  1197     else
       
  1198         {
       
  1199         iPreviousResultsShowing = ETrue;
       
  1200 
       
  1201         TInt maxDataCount( iSearchDataPC->SearchDataCount() );
       
  1202         CHAT_DP( D_CHAT_LIT(
       
  1203                      "CCASearchViewContainer::StartSearchL maxDataCount = %d " ),
       
  1204                  maxDataCount );
       
  1205 
       
  1206         if ( maxDataCount > 0 )
       
  1207             {
       
  1208             iCurrentResultPage = 1;
       
  1209             iLowIndex = 0;
       
  1210 
       
  1211             iHighIndex = iLowIndex + ( KMaxSearchResults - 1 ); //-1 because of array
       
  1212 
       
  1213             if ( iHighIndex >= maxDataCount )
       
  1214                 {
       
  1215                 iHighIndex = maxDataCount - 1;
       
  1216                 }
       
  1217 
       
  1218             if ( iSearchType == ESearchUsers )
       
  1219                 {
       
  1220                 // Presence fetching failed => not a big problem
       
  1221                 TRAPD( fetchErr, FetchPresenceL( iLowIndex, iHighIndex ) );
       
  1222                 if ( fetchErr != KErrNone )
       
  1223                     {
       
  1224                     CHAT_DP( D_CHAT_LIT(
       
  1225                                  "CCASearchViewContainer::StartSearchL FetchPresenceL() err=%d " ),
       
  1226                              fetchErr );
       
  1227                     iAppUi->DismissWaitDialogL( fetchErr );
       
  1228                     User::Leave( fetchErr );
       
  1229                     }
       
  1230                 }
       
  1231 
       
  1232             CHAT_DP( D_CHAT_LIT(
       
  1233                          "CCASearchViewContainer::StartSearchL UpdateListBoxL() " ) );
       
  1234             TRAPD( updateErr, UpdateListBoxL(
       
  1235                        iSearchType == ESearchUsers ? EFalse : ETrue ) );
       
  1236             if ( updateErr )
       
  1237                 {
       
  1238                 iAppUi->DismissWaitDialogL( updateErr );
       
  1239                 User::Leave( updateErr );
       
  1240                 }
       
  1241 
       
  1242             CHAT_DP( D_CHAT_LIT(
       
  1243                          "CCASearchViewContainer::StartSearchL HideWaitNoteL" ) );
       
  1244             iAppUi->DismissWaitDialogL( KErrNone );
       
  1245             }
       
  1246         else
       
  1247             {
       
  1248             // no search results
       
  1249             iAppUi->DismissWaitDialogL( KErrNone );
       
  1250 
       
  1251             }
       
  1252         }
       
  1253     }
       
  1254 
       
  1255 // ---------------------------------------------------------------------------
       
  1256 // CCASearchViewContainer::SetEmptyTextsToListboxL()
       
  1257 // See header for details.
       
  1258 // ---------------------------------------------------------------------------
       
  1259 //
       
  1260 void CCASearchViewContainer::SetEmptyTextsToListboxL()
       
  1261     {
       
  1262     HBufC* emptyFinal = IMUtils::CombineStringFromResourceLC
       
  1263                         ( R_QTN_CHAT_EMPTY_SEARCH_PRIMARY,
       
  1264                           R_QTN_CHAT_EMPTY_SEARCH );
       
  1265 
       
  1266     iListBox->View()->SetListEmptyTextL( *emptyFinal );
       
  1267     CleanupStack::PopAndDestroy(); // emptyFinal
       
  1268     }
       
  1269 
       
  1270 
       
  1271 // ---------------------------------------------------------
       
  1272 // CCASearchViewContainer::HandleListBoxEventL
       
  1273 // Handles list box events
       
  1274 // (other items were commented in a header).
       
  1275 // ---------------------------------------------------------
       
  1276 //
       
  1277 void CCASearchViewContainer::HandleListBoxEventL( CEikListBox* /*aListBox*/,
       
  1278                                                   TListBoxEvent aEventType )
       
  1279     {
       
  1280     if ( aEventType == EEventItemDoubleClicked )
       
  1281         {
       
  1282         iMenuObserver.ShowPopUpMenuL();
       
  1283         }
       
  1284     }
       
  1285 
       
  1286 // ---------------------------------------------------------
       
  1287 // CCASearchViewContainer::SizeChanged()
       
  1288 // Called by framework
       
  1289 // (other items were commented in a header).
       
  1290 // ---------------------------------------------------------
       
  1291 //
       
  1292 void CCASearchViewContainer::SizeChanged()
       
  1293     {
       
  1294     iListBox->SetRect( Rect() );
       
  1295     }
       
  1296 
       
  1297 // ---------------------------------------------------------
       
  1298 // CCASearchViewContainer::CountComponentControls()
       
  1299 // Returns number of controls
       
  1300 // (other items were commented in a header).
       
  1301 // ---------------------------------------------------------
       
  1302 //
       
  1303 TInt CCASearchViewContainer::CountComponentControls() const
       
  1304     {
       
  1305     //Only one compound control so returning 1
       
  1306     return 1;
       
  1307     }
       
  1308 
       
  1309 // ---------------------------------------------------------
       
  1310 // CCASearchViewContainer::ComponentControl( TInt aIndex )
       
  1311 // Returns control for given index
       
  1312 // (other items were commented in a header).
       
  1313 // ---------------------------------------------------------
       
  1314 //
       
  1315 CCoeControl* CCASearchViewContainer::ComponentControl( TInt aIndex ) const
       
  1316     {
       
  1317     if ( aIndex == 0 )
       
  1318         {
       
  1319         return iListBox;
       
  1320         }
       
  1321     else
       
  1322         {
       
  1323         return NULL;
       
  1324         }
       
  1325     }
       
  1326 
       
  1327 // ---------------------------------------------------------
       
  1328 // CCASearchViewContainer::OfferKeyEventL()
       
  1329 // Handles user key inputs
       
  1330 // (other items were commented in a header).
       
  1331 // ---------------------------------------------------------
       
  1332 //
       
  1333 TKeyResponse CCASearchViewContainer::OfferKeyEventL( const TKeyEvent& aEvent,
       
  1334                                                      TEventCode aType )
       
  1335     {
       
  1336     if ( aEvent.iCode == EKeyEnter || aEvent.iCode == EKeyOK )
       
  1337         {
       
  1338         iMenuObserver.ShowPopUpMenuL();
       
  1339         return EKeyWasConsumed;
       
  1340         }
       
  1341     return iListBox->OfferKeyEventL( aEvent, aType );
       
  1342     }
       
  1343 
       
  1344 // ---------------------------------------------------------
       
  1345 // CCASearchViewContainer::GetHelpContext
       
  1346 // This function is called when Help application is launched
       
  1347 // (other items were commented in a header).
       
  1348 // ---------------------------------------------------------
       
  1349 //
       
  1350 void CCASearchViewContainer::GetHelpContext( TCoeHelpContext& aContext ) const
       
  1351     {
       
  1352     aContext.iMajor = KUidChatClient;
       
  1353     aContext.iContext = KIMNG_HLP_SEARCHCHAT ;
       
  1354     }
       
  1355 
       
  1356 // ---------------------------------------------------------
       
  1357 // CCASearchViewContainer::FocusChanged
       
  1358 // (other items were commented in a header).
       
  1359 // ---------------------------------------------------------
       
  1360 //
       
  1361 void CCASearchViewContainer::FocusChanged( TDrawNow /* aDrawNow */ )
       
  1362     {
       
  1363     if ( iListBox )
       
  1364         {
       
  1365         // give focus to list box so that highlight animations
       
  1366         // are done properly
       
  1367         iListBox->SetFocus( IsFocused() );
       
  1368         }
       
  1369     }
       
  1370 
       
  1371 // ---------------------------------------------------------
       
  1372 // CCASearchViewContainer::FetchPresenceL()
       
  1373 // ---------------------------------------------------------
       
  1374 //
       
  1375 void CCASearchViewContainer::FetchPresenceL( const TInt aLowIndex,
       
  1376                                              const TInt aHighIndex )
       
  1377     {
       
  1378 
       
  1379     CHAT_DP_TXT( "CCASearchViewContainer::FetchPresenceL" );
       
  1380     CHAT_DP( D_CHAT_LIT( "   aLowIndex %d aHighIndex %d" ), aLowIndex,
       
  1381              aHighIndex );
       
  1382 
       
  1383 
       
  1384 
       
  1385     // Calculate optimal granularity, which is from low index to high index.
       
  1386     TInt gran = aHighIndex - aLowIndex + 1;
       
  1387     // Creating array with granularity 0 crashes, make sure gran is > 0
       
  1388     if ( gran == 0 )
       
  1389         {
       
  1390         gran = 1;
       
  1391         }
       
  1392     CDesCArrayFlat* userIDs = new ( ELeave ) CDesCArrayFlat( gran );
       
  1393     CleanupStack::PushL( userIDs );
       
  1394 
       
  1395     for ( TInt arrayIndex( aLowIndex ); arrayIndex <= aHighIndex;
       
  1396           ++arrayIndex )
       
  1397         {
       
  1398         userIDs->AppendL( iSearchDataPC->SearchData( arrayIndex ) );
       
  1399         }
       
  1400 
       
  1401     CHAT_DP_TXT( "Getting online users..." );
       
  1402 
       
  1403     MCAMainViewArrayPC* mainViewArrayPC =
       
  1404         iAppUi->GetProcessManager().GetArrayInterface();
       
  1405     mainViewArrayPC->GetOnlineUsersL( userIDs, iOnlinePresenceList, NULL );
       
  1406 
       
  1407 
       
  1408 
       
  1409     CHAT_DP_TXT( "...got online users" );
       
  1410 
       
  1411     CleanupStack::PopAndDestroy( userIDs );
       
  1412     }
       
  1413 
       
  1414 // ---------------------------------------------------------
       
  1415 // CCASearchViewContainer::UpdateNaviPaneTextL()
       
  1416 // ---------------------------------------------------------
       
  1417 //
       
  1418 void CCASearchViewContainer::UpdateNaviPaneTextL( TBool aEndSearch )
       
  1419     {
       
  1420     // Else this is zero
       
  1421     if ( !aEndSearch )
       
  1422         {
       
  1423         iTotalResultPages = ( iSearchDataPC->HowManyResultsAvailable() /
       
  1424                               KMaxSearchResults );
       
  1425         if ( ( iSearchDataPC->HowManyResultsAvailable() %
       
  1426                KMaxSearchResults ) != 0 )
       
  1427             {
       
  1428             ++iTotalResultPages; // 1 / 5 = 0 -> add 1
       
  1429             }
       
  1430 
       
  1431         if ( iSearchDataPC->HowManyResultsAvailable() > 0 &&
       
  1432              iTotalResultPages == 0 )
       
  1433             {
       
  1434             iTotalResultPages = 1;
       
  1435             }
       
  1436         }
       
  1437     // Only two items in array, so 2 should be enough
       
  1438 
       
  1439     CArrayFix<TInt>* intArray = new ( ELeave ) CArrayFixFlat<TInt>( KGranularity );
       
  1440     CleanupStack::PushL( intArray );
       
  1441     intArray->AppendL( iCurrentResultPage );
       
  1442     intArray->AppendL( iTotalResultPages );
       
  1443     HBufC* naviText = StringLoader::LoadLC( R_CHATCLIENT_SEARCH_NAVI,
       
  1444                                             *intArray );
       
  1445     TPtrC naviTextPtr( naviText->Des() );
       
  1446     CHAT_DP( D_CHAT_LIT( "*setting navi pane text to %S" ), &naviTextPtr );
       
  1447     iViewSwitcher.CAStatusPane()->SetNaviLabelL( naviTextPtr );
       
  1448     CleanupStack::PopAndDestroy( 2, intArray ); // naviText, intArray
       
  1449     }
       
  1450 
       
  1451 // ---------------------------------------------------------
       
  1452 // CCASearchViewContainer::UpdateListBoxL()
       
  1453 // ---------------------------------------------------------
       
  1454 //
       
  1455 void CCASearchViewContainer::UpdateListBoxL( TBool aGroup )
       
  1456     {
       
  1457 
       
  1458     TInt granularity( iItemArray->Count() );
       
  1459 
       
  1460     if ( granularity == 0 )
       
  1461         {
       
  1462         ++granularity;
       
  1463         }
       
  1464 
       
  1465     CDesCArray* tempArray = new ( ELeave ) CDesCArrayFlat( granularity );
       
  1466     CleanupStack::PushL( tempArray );
       
  1467     TInt loopCount( iItemArray->Count() );
       
  1468     for ( TInt i( 0 ); i < loopCount; ++i )
       
  1469         {
       
  1470         tempArray->AppendL( iItemArray->MdcaPoint( i ) );
       
  1471         }
       
  1472     ClearListBoxContents();
       
  1473     iListBox->Model()->SetItemTextArray( tempArray );
       
  1474     iListBox->Model()->SetOwnershipType( ELbmDoesNotOwnItemArray );
       
  1475     iListBox->HandleItemAdditionL();
       
  1476 
       
  1477     TInt arrayIndex( iLowIndex );
       
  1478     HBufC* online = iEikonEnv->AllocReadResourceLC(
       
  1479                         R_SEARCHVIEW_USER_ONLINE );
       
  1480 
       
  1481     HBufC* offline = iEikonEnv->AllocReadResourceLC(
       
  1482                          R_SEARCHVIEW_USER_OFFLINE );
       
  1483     do
       
  1484         {
       
  1485         CHAT_DP( D_CHAT_LIT( "Update list box..." ) );
       
  1486 
       
  1487         if ( aGroup )
       
  1488             {
       
  1489             TPtrC wvid( iSearchDataPC->SearchData( arrayIndex ) );
       
  1490             TBool tempGroup( EFalse );
       
  1491             TBool foundGroup = iSearchInterfacePC->FindGroup( wvid );
       
  1492             if ( !foundGroup )
       
  1493                 {
       
  1494                 // we must create a temporary group for groupmanager
       
  1495                 // Ownership not transferred to caller
       
  1496                 iSearchInterfacePC->CreateGroupL( wvid ); // CSI: 35 # See comment above
       
  1497                 tempGroup = ETrue;
       
  1498                 }
       
  1499 
       
  1500             // now we have the group so we can fetch the properties for it
       
  1501             TBool hasCommonProps( EFalse );
       
  1502             TEnumsPC::TImpsCSPAllErrors impsError = TEnumsPC::EImpsErrNone;
       
  1503             TPtrC groupName =  iSearchInterfacePC->GetGroupNameL( wvid, hasCommonProps, impsError );
       
  1504             TPtrC firstLine( KEmptyDesC );
       
  1505             TPtrC secondLine( KEmptyDesC );
       
  1506 
       
  1507             // if properties are not get, then set only wvid
       
  1508             if ( impsError == TEnumsPC::EImpsErrNone && hasCommonProps )
       
  1509                 {
       
  1510                 firstLine.Set( groupName );
       
  1511                 secondLine.Set( CCAAppUi::DisplayId(
       
  1512                                     iSearchDataPC->SearchData( arrayIndex ) ) );
       
  1513                 }
       
  1514             else
       
  1515                 {
       
  1516                 firstLine.Set( CCAAppUi::DisplayId(
       
  1517                                    iSearchDataPC->SearchData( arrayIndex ) ) );
       
  1518                 }
       
  1519 
       
  1520             // Construct list item text
       
  1521             HBufC* groupText = HBufC::NewLC( firstLine.Length() +
       
  1522                                              secondLine.Length() +
       
  1523                                              KTabSpace ); // 3 for tabulators
       
  1524             TPtr groupTextPtr( groupText->Des() );
       
  1525             groupTextPtr.Append( KTabulator );
       
  1526             groupTextPtr.Append( firstLine );
       
  1527             groupTextPtr.Append( KTabulator );
       
  1528             groupTextPtr.Append( secondLine );
       
  1529             groupTextPtr.Append( KTabulator );
       
  1530 
       
  1531             // now we can delete our temporary group (do not delete
       
  1532             // from server) we can ignore the error as it can only
       
  1533             // come from server
       
  1534             if ( tempGroup )
       
  1535                 {
       
  1536                 iSearchInterfacePC->DeleteGroupL( wvid, EFalse );
       
  1537                 }
       
  1538 
       
  1539             iItemArray->AppendL( groupTextPtr );
       
  1540             CleanupStack::PopAndDestroy( groupText );
       
  1541             }
       
  1542         else
       
  1543             {
       
  1544             HBufC* itemText = HBufC::NewLC( KMaxFirstNameLength +
       
  1545                                             KMaxSurnameLength );
       
  1546             TPtr itemTextPtr( itemText->Des() );
       
  1547 
       
  1548             itemTextPtr.Append( KTabulator );
       
  1549 
       
  1550             TPtrC searchedData = iSearchDataPC->SearchData( arrayIndex );
       
  1551             itemTextPtr.Append( iSearchDataPC->IdentificationL( searchedData ) );
       
  1552             itemTextPtr.Append( KTabulator );
       
  1553 
       
  1554             // Now we should get the presence of this guy
       
  1555             TInt ignoreIndex( 0 );
       
  1556             // We found online presence
       
  1557             if ( iOnlinePresenceList->Find( searchedData, ignoreIndex ) == 0 )
       
  1558                 {
       
  1559                 itemTextPtr.Append( *online );
       
  1560                 iOnlineArray.Append( ETrue );
       
  1561                 }
       
  1562             else
       
  1563                 {
       
  1564                 itemTextPtr.Append( *offline );
       
  1565                 iOnlineArray.Append( EFalse );
       
  1566                 }
       
  1567 
       
  1568             itemTextPtr.Append( KTabulator );
       
  1569             iItemArray->AppendL( itemTextPtr );
       
  1570             CleanupStack::PopAndDestroy( itemText );
       
  1571             }
       
  1572 
       
  1573         ++arrayIndex;
       
  1574         } while ( arrayIndex <= iHighIndex );
       
  1575 
       
  1576     CleanupStack::PopAndDestroy( 3, tempArray ); // offline, online, itemText
       
  1577     iListBox->Model()->SetItemTextArray( iItemArray );
       
  1578     iListBox->Model()->SetOwnershipType( ELbmDoesNotOwnItemArray );
       
  1579     CHAT_DP( D_CHAT_LIT(
       
  1580                  "CCASearchViewContainer::UpdateListBoxL Item array count %d" ),
       
  1581              iItemArray->Count() );
       
  1582     CHAT_DP( D_CHAT_LIT(
       
  1583                  "CCASearchViewContainer::UpdateListBoxL Reseting online presence list" ) );
       
  1584     iOnlinePresenceList->Reset();
       
  1585 
       
  1586     iListBox->HandleItemAdditionL();
       
  1587     UpdateNaviPaneTextL( EFalse );
       
  1588     if ( iItemArray->MdcaCount() > 0 )
       
  1589         {
       
  1590         iListBox->SetCurrentItemIndexAndDraw( 0 );
       
  1591         }
       
  1592     iListBox->UpdateScrollBarsL();
       
  1593 
       
  1594     }
       
  1595 
       
  1596 // ---------------------------------------------------------
       
  1597 // CCASearchViewContainer::SetGroupSyncDone
       
  1598 // ---------------------------------------------------------
       
  1599 //
       
  1600 void CCASearchViewContainer::SetGroupSyncDone()
       
  1601     {
       
  1602     CHAT_DP_TXT( "CCASearchViewContainer::SetGroupSyncDone - Group sync done" );
       
  1603     iGroupSyncDone = ETrue;
       
  1604     }
       
  1605 
       
  1606 // ---------------------------------------------------------
       
  1607 // CCASearchViewContainer::ClearListBoxContents()
       
  1608 // ---------------------------------------------------------
       
  1609 //
       
  1610 void CCASearchViewContainer::ClearListBoxContents()
       
  1611     {
       
  1612     iItemArray->Reset();
       
  1613     iOnlineArray.Reset();
       
  1614     TRAPD( err, iListBox->HandleItemRemovalL() );
       
  1615     if ( err != KErrNone )
       
  1616         {
       
  1617         CActiveScheduler::Current()->Error( err );
       
  1618         }
       
  1619     iListBox->DrawNow();
       
  1620     }
       
  1621 
       
  1622 // -----------------------------------------------------------------------------
       
  1623 // CCAAppUi::BackgroundTasks
       
  1624 // (other items were commented in a header).
       
  1625 // -----------------------------------------------------------------------------
       
  1626 //
       
  1627 TInt CCASearchViewContainer::BackgroundTasks( TAny *aInstance )
       
  1628     {
       
  1629     return static_cast<CCASearchViewContainer*>( aInstance )->DoBackgroundTasks();
       
  1630     }
       
  1631 
       
  1632 // -----------------------------------------------------------------------------
       
  1633 // CCAAppUi::DoBackgroundTasks
       
  1634 // (other items were commented in a header).
       
  1635 // -----------------------------------------------------------------------------
       
  1636 //
       
  1637 TInt CCASearchViewContainer::DoBackgroundTasks()
       
  1638     {
       
  1639     TBool retVal( EFalse );
       
  1640     TRAPD( err, retVal = ContainerStartL() );
       
  1641 
       
  1642     if ( err )
       
  1643         {
       
  1644         CActiveScheduler::Current()->Error( err );
       
  1645         }
       
  1646 
       
  1647     // if the task is completed...
       
  1648     if ( !retVal )
       
  1649         {
       
  1650         if ( iDeleteFlag )
       
  1651             {
       
  1652             // delete self and cancel callback
       
  1653             delete this;
       
  1654             return EFalse;
       
  1655             }
       
  1656 
       
  1657         iTaskComplete = ETrue;
       
  1658         }
       
  1659     return retVal;
       
  1660     }
       
  1661 
       
  1662 // -----------------------------------------------------------------------------
       
  1663 // CCASearchViewContainer::ContainerStartL
       
  1664 // (other items were commented in a header).
       
  1665 // -----------------------------------------------------------------------------
       
  1666 //
       
  1667 TBool CCASearchViewContainer::ContainerStartL()
       
  1668     {
       
  1669     iSearchType = iSearchUsers ? ESearchUsers : ESearchGroups;
       
  1670 
       
  1671 
       
  1672     // if groups are not supported, just show the search type dialog and that's
       
  1673     // it. DON'T show any notes.
       
  1674     TBool groupsSupported = iAppUi->UISessionManager().IsSupported(
       
  1675                                 CCAUISessionManager::EGroup );
       
  1676 
       
  1677     if ( ! groupsSupported )
       
  1678         {
       
  1679         if ( iSearchInterfacePC->IsSearchPairsSet() )
       
  1680             {
       
  1681             StartSearchL( );
       
  1682             }
       
  1683         else
       
  1684             {
       
  1685             NewSearchL();
       
  1686             }
       
  1687         return EFalse;  // that's it, one-shot
       
  1688         }
       
  1689 
       
  1690     if ( ! iWaitVisible && ! iGroupSyncDone )
       
  1691         {
       
  1692         CHAT_DP_TXT(
       
  1693             "CCASearchViewContainer::ContainerStartL - ! iWaitVisible && ! iGroupSyncDone" );
       
  1694         // launch the wait note
       
  1695         iWaitVisible = ETrue;
       
  1696 
       
  1697         iAppUi->ShowWaitDialogL( R_QTN_CHAT_SEARCHVIEW_PROCESSING, ETrue );
       
  1698 
       
  1699         return ETrue;
       
  1700         }
       
  1701 
       
  1702     if ( iGroupSyncDone )
       
  1703         {
       
  1704         CHAT_DP_TXT( "CCASearchViewContainer::ContainerStartL - iGroupSyncDone" );
       
  1705 
       
  1706         // hide wait note
       
  1707         if ( iWaitVisible )
       
  1708             {
       
  1709             CHAT_DP_TXT( "CCASearchViewContainer::ContainerStartL - iWaitVisible" );
       
  1710 
       
  1711             TRAPD( err, iAppUi->DismissWaitDialogL( KErrNone ) );
       
  1712             if ( err != KErrNone )
       
  1713                 {
       
  1714                 CActiveScheduler::Current()->Error( err );
       
  1715                 }
       
  1716 
       
  1717             // group has been synched
       
  1718             iWaitVisible = EFalse;
       
  1719             }
       
  1720 
       
  1721         CHAT_DP_TXT( "CCASearchViewContainer::ContainerStartL - No more wait note, show search type dialog" );
       
  1722         // that's it, out of here
       
  1723 
       
  1724         if ( iSearchInterfacePC->IsSearchPairsSet() )
       
  1725             {
       
  1726             StartSearchL( );
       
  1727             }
       
  1728         else
       
  1729             {
       
  1730             NewSearchL();
       
  1731             }
       
  1732         return EFalse;
       
  1733         }
       
  1734 
       
  1735     // nothing interesting, do nothing, but come back here
       
  1736     return ETrue;
       
  1737     }
       
  1738 
       
  1739 // -----------------------------------------------------------------------------
       
  1740 // CCASearchViewContainer::ListId
       
  1741 // (other items were commented in a header).
       
  1742 // -----------------------------------------------------------------------------
       
  1743 //
       
  1744 const TDesC& CCASearchViewContainer::ListId() const
       
  1745     {
       
  1746     if ( iListId )
       
  1747         {
       
  1748         return *iListId;
       
  1749         }
       
  1750     return KNullDesC;
       
  1751     }
       
  1752 
       
  1753 // ---------------------------------------------------------
       
  1754 // CCASearchViewContainer::DeleteSelfD
       
  1755 // (other items were commented in a header).
       
  1756 // ---------------------------------------------------------
       
  1757 //
       
  1758 void CCASearchViewContainer::DeleteSelfD()
       
  1759     {
       
  1760     iDeleteFlag = ETrue;
       
  1761 
       
  1762     // if task is already completed -> delete immediately
       
  1763     if ( iTaskComplete )
       
  1764         {
       
  1765         delete this;
       
  1766         }
       
  1767     }
       
  1768 
       
  1769 // ---------------------------------------------------------
       
  1770 // CCASearchViewContainer::LayoutChangedL
       
  1771 // (other items were commented in a header).
       
  1772 // ---------------------------------------------------------
       
  1773 //
       
  1774 void CCASearchViewContainer::LayoutChangedL( TInt aType )
       
  1775     {
       
  1776     // updates tabgroup
       
  1777     iViewSwitcher.CAStatusPane()->ShowTabGroupL( KUidSearchView );
       
  1778 
       
  1779     TRect mainPaneRect;
       
  1780     AknLayoutUtils::LayoutMetricsRect( AknLayoutUtils::EMainPane, mainPaneRect );
       
  1781     SetRect( mainPaneRect );
       
  1782     UpdateNaviPaneTextL( ETrue );
       
  1783     CCoeControl::HandleResourceChange( aType );
       
  1784     }
       
  1785 
       
  1786 // ---------------------------------------------------------
       
  1787 // CCASearchViewContainer::HandleServiceStateChangeL
       
  1788 // (other items were commented in a header).
       
  1789 // ---------------------------------------------------------
       
  1790 //
       
  1791 void CCASearchViewContainer::HandleServiceStateChangeL( TServiceState aState )
       
  1792     {
       
  1793     if ( aState == EOffline )
       
  1794         {
       
  1795         // Clear search results if we got disconnected.
       
  1796         EndSearchL();
       
  1797         ClearListBoxContents();
       
  1798         iGroupSyncDone = EFalse;
       
  1799         }
       
  1800     }
       
  1801 
       
  1802 // ---------------------------------------------------------
       
  1803 // CCASearchViewContainer::HandlePointerEventL
       
  1804 // ---------------------------------------------------------
       
  1805 //
       
  1806 void CCASearchViewContainer::HandlePointerEventL( const TPointerEvent& aPointerEvent )
       
  1807     {
       
  1808     if ( !iItemArray->Count() == 0 )
       
  1809         {
       
  1810         iListBox->HandlePointerEventL( aPointerEvent );
       
  1811         return;
       
  1812         }
       
  1813 
       
  1814 
       
  1815     if ( !CATouchUtils::PenEnabled() )
       
  1816         {
       
  1817         return;
       
  1818         }
       
  1819     // Single tap on main pane (not on scroll bar)
       
  1820     if ( aPointerEvent.iType == TPointerEvent::EButton1Up )
       
  1821         {
       
  1822         iMenuObserver.ShowPopUpMenuL();
       
  1823         }
       
  1824     }
       
  1825 //  End of File