uiservicetab/vimpstui/src/cvimpstuidoublelistboxtabviewcontrol.cpp
branchRCL_3
changeset 28 3104fc151679
parent 27 2b7283837edb
child 29 9a48e301e94b
equal deleted inserted replaced
27:2b7283837edb 28:3104fc151679
     1 /*
       
     2 * Copyright (c) 2008 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:  Implementation for CVIMPSTUiDoubleListBoxTabViewControl.
       
    15 *
       
    16 */
       
    17 
       
    18 // INCLUDE FILES
       
    19 #include "cvimpstuidoublelistboxtabviewcontrol.h"
       
    20 
       
    21 #include "cvimpstuidoublelistboxarray.h"
       
    22 #include "tvimpstenums.h"
       
    23 #include "mvimpstcmdhandler.h"
       
    24 #include "cvimpstuibranddata.h"
       
    25 #include "imcvuiliterals.h"
       
    26 #include "cvimpstuilistboxmodel.h"
       
    27 #include "vimpstutilsdialog.h"
       
    28 #include "vimpstui.hrh"
       
    29 #include "cvimpstuitabbedview.h"
       
    30 #include "mvimpstengine.h"
       
    31 #include "cvimpststoragemanagerfactory.h"
       
    32 #include "mvimpststorageserviceview.h"
       
    33 #include "cvimpstsettingsstore.h" // settings store in cenrep used for own avatar data
       
    34 #include "cvimpstengineimagehandler.h"
       
    35 // system include
       
    36 #include 	<aknenv.h>
       
    37 #include	<aknlists.h>
       
    38 #include    <AknIconArray.h>
       
    39 #include	<eikclbd.h> 
       
    40 #include	<aknsfld.h> 
       
    41 #include 	<AknUtils.h> 
       
    42 #include	<AknLayout.lag>   
       
    43 #include 	<StringLoader.h>
       
    44 // Pbk2
       
    45 #include <MPbk2KeyEventHandler.h>
       
    46 #include <vimpstuires.rsg>
       
    47 
       
    48 #include <aknlayoutscalable_avkon.cdl.h>
       
    49 #include "uiservicetabtracer.h"
       
    50 // imlauncher
       
    51 #include <imcvlauncher.h>
       
    52 const TInt KTextLimit( 40 ); // Text-limit for find-field
       
    53 
       
    54 const TInt KMinContact(1);   // minmimum number of contacts to show findpane
       
    55 
       
    56 // ================= MEMBER FUNCTIONS =======================
       
    57 
       
    58 inline CVIMPSTUiDoubleStyleListBox& CVIMPSTUiDoubleListBoxTabViewControl::ListBox() const
       
    59     {
       
    60     return(*iListBox);
       
    61     }
       
    62 // --------------------------------------------------------------------------
       
    63 // CVIMPSTUiDoubleListBoxTabViewControl::CVIMPSTUiDoubleListBoxTabViewControl
       
    64 // --------------------------------------------------------------------------
       
    65 //
       
    66 CVIMPSTUiDoubleListBoxTabViewControl::CVIMPSTUiDoubleListBoxTabViewControl(CVIMPSTUiTabbedView& aTabbedView, MPbk2KeyEventHandler* aKeyEventHandler,
       
    67 														MVIMPSTCmdHandler& aCommandHandler,
       
    68 														TUint32 aServiceId,
       
    69 														CVIMPSTUiBrandData& aBrandHandler,
       
    70 														MVIMPSTEngine& aEngine,
       
    71 														CEikButtonGroupContainer* aCba)
       
    72 	:iTabbedView(aTabbedView),
       
    73 	 iKeyEventHandler(aKeyEventHandler),
       
    74 	 iCommandHandler(aCommandHandler),
       
    75 	 iArrayProcess(iCommandHandler.GetProcessInterface()),
       
    76 	 iServiceId(aServiceId),
       
    77 	 iBrandHandler(aBrandHandler),
       
    78 	 iEngine(aEngine),
       
    79 	 iCba(aCba)
       
    80     {
       
    81 
       
    82     }
       
    83 
       
    84 
       
    85 // --------------------------------------------------------------------------
       
    86 // CVIMPSTUiDoubleListBoxTabViewControl::ConstructL
       
    87 // --------------------------------------------------------------------------
       
    88 //
       
    89 void CVIMPSTUiDoubleListBoxTabViewControl::ConstructL()
       
    90     {
       
    91 	TRACER_AUTO;
       
    92     CreateWindowL();
       
    93     // register to get the call back for any array data change
       
    94     iArrayProcess.AddObserver(this);  
       
    95     // this to make sure that if user id changed storage should be refresh with new user id
       
    96     // Initialize the listbox
       
    97     // Create and construct listbox
       
    98     iListBox = new ( ELeave ) CVIMPSTUiDoubleStyleListBox;
       
    99  
       
   100     iListBox->ConstructL(this , EAknListBoxSelectionList);
       
   101     
       
   102     iListBox->SetContactListModelL(iArrayProcess);
       
   103     
       
   104     iListBox->SetListBoxObserver( this );
       
   105     
       
   106     iListBox->SetContainerWindowL(*this);
       
   107     iListBox->CreateScrollBarFrameL(ETrue);
       
   108     iListBox->ScrollBarFrame()->SetScrollBarVisibilityL
       
   109         (CEikScrollBarFrame::EOff, CEikScrollBarFrame::EAuto);
       
   110 	// set marquee on
       
   111     iListBox->ItemDrawer()->FormattedCellData()->EnableMarqueeL( ETrue );
       
   112     // If engine is uninstalled, do not construct the list view.
       
   113     // Display empty message
       
   114     if (iEngine.IsUnInstalled())
       
   115         {
       
   116         SetListEmptyTextL( R_QTN_SERVTAB_SWUPDATE_RESTART );
       
   117         return;
       
   118         }
       
   119     else
       
   120         {
       
   121     // Construction of the listbox view. Engine is not uninstalled.
       
   122         CVIMPSTUiDoubleListboxArray* friendsArray =
       
   123                 CVIMPSTUiDoubleListboxArray::NewL(iArrayProcess,
       
   124                         iListBox->ItemDrawer()->ColumnData(), *iListBox,
       
   125                         *this);
       
   126         // now set the array
       
   127         iListBox->Model()->SetItemTextArray(friendsArray);
       
   128 
       
   129         iListBox->Model()->SetOwnershipType(ELbmOwnsItemArray);
       
   130         // if there is any contact other than owndata , show findpane
       
   131         if (iListBox->Model()->NumberOfItems() > KMinContact)
       
   132             {
       
   133             // Create find-pane
       
   134             ActivateFindPaneL();
       
   135             }
       
   136         LoadBitmapsL();
       
   137         SetCbaLockL(EFalse);
       
   138         }
       
   139 
       
   140     }
       
   141 // --------------------------------------------------------------------------
       
   142 // CVIMPSTUiDoubleListBoxTabViewControl::NewL
       
   143 // --------------------------------------------------------------------------
       
   144 //
       
   145 CVIMPSTUiDoubleListBoxTabViewControl* CVIMPSTUiDoubleListBoxTabViewControl::NewL
       
   146         (CVIMPSTUiTabbedView& aTabbedView,MPbk2KeyEventHandler* aKeyEventHandler, 
       
   147         MVIMPSTCmdHandler& aCommandHandler, TUint32 aServiceId,
       
   148         CVIMPSTUiBrandData& aBrandHandler,
       
   149         MVIMPSTEngine& aEngine,
       
   150         CEikButtonGroupContainer* aCba)
       
   151     {
       
   152 	TRACER_AUTO;
       
   153     CVIMPSTUiDoubleListBoxTabViewControl* self = NewLC(aTabbedView,aKeyEventHandler,
       
   154     			aCommandHandler, aServiceId, aBrandHandler,aEngine,aCba);
       
   155     CleanupStack::Pop(self);
       
   156     return self;
       
   157     }
       
   158 
       
   159 
       
   160 // --------------------------------------------------------------------------
       
   161 // CVIMPSTUiDoubleListBoxTabViewControl::NewLC
       
   162 // --------------------------------------------------------------------------
       
   163 //
       
   164 CVIMPSTUiDoubleListBoxTabViewControl* CVIMPSTUiDoubleListBoxTabViewControl::NewLC
       
   165         (CVIMPSTUiTabbedView& aTabbedView,MPbk2KeyEventHandler* aKeyEventHandler,
       
   166         MVIMPSTCmdHandler& aCommandHandler, TUint32 aServiceId,
       
   167         CVIMPSTUiBrandData& aBrandHandler,
       
   168         MVIMPSTEngine& aEngine,
       
   169         CEikButtonGroupContainer* aCba)
       
   170     {
       
   171 	TRACER_AUTO;
       
   172     CVIMPSTUiDoubleListBoxTabViewControl* self =
       
   173         new (ELeave) CVIMPSTUiDoubleListBoxTabViewControl(aTabbedView,aKeyEventHandler,
       
   174         aCommandHandler, aServiceId, aBrandHandler,aEngine,aCba);
       
   175     CleanupStack::PushL(self);
       
   176     self->ConstructL();
       
   177     return self;
       
   178     }
       
   179 
       
   180 
       
   181 // --------------------------------------------------------------------------
       
   182 // CVIMPSTUiDoubleListBoxTabViewControl::~CVIMPSTUiDoubleListBoxTabViewControl
       
   183 // --------------------------------------------------------------------------
       
   184 //
       
   185 CVIMPSTUiDoubleListBoxTabViewControl::~CVIMPSTUiDoubleListBoxTabViewControl()
       
   186     {
       
   187     delete iListBox;
       
   188     iArrayProcess.RemoveObserver();
       
   189     if( iFindbox )
       
   190     	{
       
   191     	delete iFindbox;
       
   192     	iFindbox = NULL;
       
   193     	}
       
   194     }
       
   195 
       
   196 // --------------------------------------------------------------------------
       
   197 // CVIMPSTUiDoubleListBoxTabViewControl::HandleAvatarChangeL
       
   198 // --------------------------------------------------------------------------
       
   199 //
       
   200 void CVIMPSTUiDoubleListBoxTabViewControl::HandleAvatarChangeL( const TDesC& aUserId ) 
       
   201     {
       
   202 	TRACER_AUTO;
       
   203     TRACE( "aUserId = %S ", &aUserId );
       
   204     CFormattedCellListBoxData* listBoxData = iListBox->ItemDrawer()->ColumnData();
       
   205     TPtrC loginUserId = iArrayProcess.LoginUserIdFromStoreL();
       
   206     TInt Avindex = 0;
       
   207     CGulIcon* newIcon = NULL;
       
   208     TRACE( "loginUserId = %S ", &loginUserId );
       
   209     if( KErrNone == loginUserId.Compare( aUserId ) )
       
   210         {
       
   211         TRACE( "inside if ownuserid" );
       
   212         TPtrC8 avatardata = iArrayProcess.OwnAvatarContentL();
       
   213         TRACE( "after iArrayProcess.OwnAvatarContentL()" );
       
   214         Avindex = iArrayProcess.OwnAvatarIndexL();
       
   215         if( avatardata.Length() )
       
   216             {
       
   217             TRACE( "avatardata.Length()" );
       
   218             newIcon = AvatarToIconL( avatardata );
       
   219             }
       
   220         if( newIcon ) // there is a new avatar icon 
       
   221             {
       
   222             TRACE("newIcon" );
       
   223             CArrayPtr<CGulIcon>* currentIconArray = listBoxData->IconArray();
       
   224             if( Avindex ) // if there is old icon already
       
   225                 {
       
   226                 TRACE( "Avindex " );
       
   227                 // delete the old icon compress the array and insert at the same position
       
   228                 currentIconArray->Delete( Avindex );
       
   229                 currentIconArray->Compress();
       
   230                 currentIconArray->InsertL( Avindex , newIcon);
       
   231                 }
       
   232             else 
       
   233                 { 
       
   234                 TRACE( "else of Avindex " );
       
   235                 // if there is no old icon append at the last
       
   236                 currentIconArray->AppendL( newIcon);
       
   237                 // set the index to cenrep
       
   238                 TRACE( " currentIconArray->Count()-1 = %d ",currentIconArray->Count()-1  );
       
   239                 iArrayProcess.SetOwnAvatarIndexL( currentIconArray->Count()-1 );
       
   240                 }
       
   241             }
       
   242         else 
       
   243             {
       
   244             TRACE( "else of avatar got cleared." );
       
   245             // avatar got cleared just  set the icon index to '0'
       
   246             // icon what was added still remains in the  listbox icon array
       
   247             // dont delete the old icon, because that needs to modify the whole 
       
   248             // indexes of the  other contacts. 
       
   249             // "keeping the icon is better than changing all contacts indexes"
       
   250             // The icons will be deleted by listbox, when list box got destructed.
       
   251             iArrayProcess.SetOwnAvatarIndexL( KErrNone );
       
   252             }
       
   253         }
       
   254     else
       
   255         {
       
   256         TRACE( " else  not own id" );
       
   257         TRACE( " else  not own id aUserId = %S",&aUserId );
       
   258         TInt index = iArrayProcess.GetSelectedItemIndex( aUserId );//Get the index from storage.
       
   259         
       
   260         TRACE( " after GetSelectedItemIndex" );
       
   261         TPtrC8 avatardata = iArrayProcess.AvatarContent( index );
       
   262         TRACE("after iArrayProcess.AvatarContent" );
       
   263         Avindex = iArrayProcess.AvatarIndex(index);
       
   264         TRACE( " after Avindex = %d",Avindex );
       
   265         if( avatardata.Length() )
       
   266             {
       
   267             TRACE( "inside if avatardata.Length()" );
       
   268             newIcon = AvatarToIconL( avatardata );
       
   269             }
       
   270         if( newIcon ) // there is a new avatar icon 
       
   271             {
       
   272             TRACE( "inside if newIcon" );
       
   273             CArrayPtr<CGulIcon>* currentIconArray = listBoxData->IconArray();
       
   274             if( Avindex ) // if there is old icon already
       
   275                 {
       
   276                 TRACE( " inside Avindex" );
       
   277                 // delete the old icon compress the array and insert at the same position
       
   278                 currentIconArray->Delete( Avindex );
       
   279                 currentIconArray->Compress();
       
   280                 currentIconArray->InsertL( Avindex , newIcon);
       
   281                 }
       
   282             else 
       
   283                 { 
       
   284                 TRACE( " inside Avindex else" );
       
   285                 // if there is no old icon append at the last
       
   286                 currentIconArray->AppendL( newIcon);
       
   287                 // set the index to cenrep
       
   288                 iArrayProcess.SetAvatarIndex(index, currentIconArray->Count()-1 );
       
   289                 }
       
   290             }
       
   291         else 
       
   292             {
       
   293             TRACE( " avatar got cleared" );
       
   294             // avatar got cleared just  set the icon index to '0'
       
   295             // icon what was added still remains in the  listbox icon array
       
   296             // dont delete the old icon, because that needs to modify the whole 
       
   297             // indexes of the  other contacts. 
       
   298             // "keeping the icon is better than changing all contacts indexes"
       
   299             // The icons will be deleted by listbox, when list box got destructed.
       
   300             iArrayProcess.SetAvatarIndex( index , KErrNone );
       
   301             }
       
   302         }
       
   303 
       
   304     iListBox->DrawNow();
       
   305     
       
   306     }	
       
   307 // ---------------------------------------------------------
       
   308 // CVIMPSTUiDoubleListBoxTabViewControl::HandleAddition
       
   309 // ---------------------------------------------------------
       
   310 //
       
   311 void CVIMPSTUiDoubleListBoxTabViewControl::HandleAdditionL(TVIMPSTEnums::TItem aType, TInt aIndex)
       
   312 	{
       
   313 	if(iListBox )
       
   314 		{
       
   315 		iListBox->HandleItemAdditionL();
       
   316 		UpdateViewL(aIndex,aType) ;
       
   317 		}
       
   318 	}
       
   319 
       
   320 // ---------------------------------------------------------
       
   321 // CVIMPSTUiDoubleListBoxTabViewControl::HandleAddition
       
   322 // ---------------------------------------------------------
       
   323 //
       
   324 void CVIMPSTUiDoubleListBoxTabViewControl::HandleDeletionL(TVIMPSTEnums::TItem aType , TInt aIndex )
       
   325 	{
       
   326 	TRACER_AUTO;
       
   327 	if(iListBox)
       
   328 		{
       
   329 		iListBox->HandleItemRemovalL();  
       
   330 		TInt count = iListBox->Model()->NumberOfItems();
       
   331 		if( count == aIndex )
       
   332 			{
       
   333 			aIndex = 0;	
       
   334 			}
       
   335 		UpdateViewL(aIndex,aType) ;
       
   336 		}
       
   337 	}
       
   338 
       
   339 // --------------------------------------------------------------------------
       
   340 // CVIMPSTUiDoubleListBoxTabViewControl::HandleItemAdditionL
       
   341 // --------------------------------------------------------------------------
       
   342 //
       
   343 void CVIMPSTUiDoubleListBoxTabViewControl::HandleItemAdditionL()
       
   344     {
       
   345 	TRACER_AUTO;
       
   346     if(iListBox)
       
   347   	 	{
       
   348         iListBox->HandleItemAdditionL();  
       
   349         TInt index  = CurrentItemIndex();
       
   350     	TVIMPSTEnums::TItem type = iArrayProcess.GetType(index);
       
   351        	UpdateViewL(index,type) ;  
       
   352    		}
       
   353     }
       
   354 
       
   355 
       
   356 // --------------------------------------------------------------------------
       
   357 // CVIMPSTUiDoubleListBoxTabViewControl::HandleItemRemovalL
       
   358 // --------------------------------------------------------------------------
       
   359 //
       
   360 void CVIMPSTUiDoubleListBoxTabViewControl::HandleItemRemovalL()
       
   361     {
       
   362     if(iListBox)
       
   363   	 	{
       
   364         iListBox->HandleItemRemovalL();  
       
   365         TInt index  = CurrentItemIndex();
       
   366     	TVIMPSTEnums::TItem type = iArrayProcess.GetType(index);
       
   367        	UpdateViewL(index,type) ;  
       
   368     	}
       
   369     }
       
   370 
       
   371 // --------------------------------------------------------------------------
       
   372 // CVIMPSTUiDoubleListBoxTabViewControl::SizeChanged
       
   373 // --------------------------------------------------------------------------
       
   374 //
       
   375 void CVIMPSTUiDoubleListBoxTabViewControl::SizeChanged()
       
   376     {
       
   377     SetLayout(); //layouting controls
       
   378     if ( iFindbox && iFindPaneIsVisible  )
       
   379         {
       
   380         iFindbox->MakeVisible( ETrue );
       
   381         }
       
   382     }
       
   383 
       
   384 
       
   385 // --------------------------------------------------------------------------
       
   386 // CVIMPSTUiDoubleListBoxTabViewControl::CountComponentControls
       
   387 // --------------------------------------------------------------------------
       
   388 //
       
   389 TInt CVIMPSTUiDoubleListBoxTabViewControl::CountComponentControls() const
       
   390     { 
       
   391      // return number of controls inside this container
       
   392     if( !iFindbox )
       
   393         {
       
   394         // Find-pane does not exist when there is no data in listbox,
       
   395         // so only one control exists (listbox)
       
   396         return 1; //Ignore CodeScanner warning
       
   397         }
       
   398     else
       
   399         {
       
   400         // listbox and findbox exists. that makes it two
       
   401         return 2; //Ignore CodeScanner warning
       
   402         }
       
   403     }
       
   404 
       
   405 // --------------------------------------------------------------------------
       
   406 // CVIMPSTUiDoubleListBoxTabViewControl::FocusChanged
       
   407 // --------------------------------------------------------------------------
       
   408 //
       
   409 void CVIMPSTUiDoubleListBoxTabViewControl::FocusChanged( TDrawNow aDrawNow )
       
   410     {
       
   411     if ( iFindbox && iFindbox->IsVisible() )
       
   412             {
       
   413             iFindbox->SetFocus( IsFocused(), aDrawNow );
       
   414             if ( aDrawNow == EDrawNow && IsFocused() )
       
   415                 {
       
   416                 iFindbox->DrawDeferred();
       
   417                 }
       
   418             }
       
   419     }
       
   420 
       
   421 // --------------------------------------------------------------------------
       
   422 // CVIMPSTUiDoubleListBoxTabViewControl::ComponentControl
       
   423 // --------------------------------------------------------------------------
       
   424 //
       
   425 CCoeControl* CVIMPSTUiDoubleListBoxTabViewControl::ComponentControl(TInt aIndex) const
       
   426     {
       
   427 	TRACER_AUTO;
       
   428    // return iListBox;
       
   429     switch ( aIndex )
       
   430         {
       
   431         // the caller wants to have the first control
       
   432         // so it's always listbox
       
   433         case 0:
       
   434             {
       
   435 			return iListBox;
       
   436             }
       
   437         // the caller wants to have the second control
       
   438         // so it's always the findbox if it exists
       
   439         case 1:
       
   440             {
       
   441             if( iFindbox )
       
   442                 {
       
   443                 return iFindbox;
       
   444                 }
       
   445             return NULL;
       
   446             }
       
   447         default:
       
   448             {
       
   449             return NULL;
       
   450             }
       
   451         }
       
   452     }
       
   453 
       
   454 
       
   455 // --------------------------------------------------------------------------
       
   456 // CVIMPSTUiDoubleListBoxTabViewControl::OfferKeyEventL
       
   457 // --------------------------------------------------------------------------
       
   458 //
       
   459 TKeyResponse CVIMPSTUiDoubleListBoxTabViewControl::OfferKeyEventL
       
   460         (const TKeyEvent& aKeyEvent,TEventCode aType)
       
   461     {
       
   462 	TRACER_AUTO;
       
   463     if ( !aKeyEvent.iCode ) 
       
   464         {
       
   465         //The character code generated 
       
   466         //for an EEventKey, or 0 for a down or up event.
       
   467         //For down or up key return key consumed.. handle only the events
       
   468         
       
   469         if((EEventKeyDown == aType) && (EStdKeyDevice3 == aKeyEvent.iScanCode))
       
   470             {
       
   471             //for setting the command to be executed for the "Selection key"
       
   472             //in case of selection key, container's OfferKeyEventL() is called only for EEventKeyDown and EEventKeyUp
       
   473             //and not for EEventKey
       
   474             UpdateCbaL();
       
   475             }
       
   476         return EKeyWasConsumed;	    	
       
   477         }
       
   478     UpdateCbaL();
       
   479     TKeyResponse ret = EKeyWasNotConsumed;
       
   480     // Offer key event first to the key event handler
       
   481     if ( iKeyEventHandler && iKeyEventHandler->Pbk2ProcessKeyEventL
       
   482             ( aKeyEvent, aType ) )
       
   483         {
       
   484         ret = EKeyWasConsumed;
       
   485         }
       
   486     switch ( aKeyEvent.iCode )
       
   487            {
       
   488            case EKeyBackspace:
       
   489                {
       
   490                if ( iFindbox )  
       
   491                    {
       
   492                    if( iFindbox->TextLength() == 0 )
       
   493                        {
       
   494                        TInt index = CurrentItemIndex();
       
   495                        if( iArrayProcess.IsConversationExist(index) )
       
   496                            {
       
   497                            iTabbedView.CloseConversationL();
       
   498                            ret = EKeyWasConsumed;
       
   499                            }
       
   500                        else if(TVIMPSTEnums::EContactItem == iArrayProcess.GetType(  index ) )
       
   501                            {
       
   502                            if( TVIMPSTEnums::ESVCERegistered == iArrayProcess.GetLoginState()  )                          
       
   503                                {
       
   504                                iTabbedView.DeleteContactL();
       
   505                                }
       
   506                            ret = EKeyWasConsumed;
       
   507                            }
       
   508                        }
       
   509                    }
       
   510                break;
       
   511                }
       
   512 	           // Case to handle send key press consumption.
       
   513            case EKeyYes:
       
   514                {
       
   515                TInt index = iListBox->CurrentItemIndex();
       
   516                if( TVIMPSTEnums::EOwnStatusItem == iArrayProcess.GetType( index ) )
       
   517                    {
       
   518                    ret = EKeyWasConsumed;
       
   519                    }
       
   520                break;
       
   521                }
       
   522            default:
       
   523                break;
       
   524            }
       
   525    if( EKeyPhoneSend == aKeyEvent.iCode  && ret != EKeyWasConsumed )
       
   526     	{
       
   527     	if( iEngine.IsSubServiceSupportedL(TVIMPSTEnums::EVoip))
       
   528 		    {
       
   529 		    iTabbedView.MakeVoipCallL();
       
   530 		   	ret = EKeyWasConsumed;
       
   531 		    }
       
   532 	
       
   533     	}
       
   534     if( ret == EKeyWasConsumed )
       
   535 	    {
       
   536 	    // user might has choosen back/end key/application key etc
       
   537 	    // application might switch to background 
       
   538 	    // return from here
       
   539 	    return ret;	
       
   540 	    }
       
   541     if (iFindPaneIsVisible && iFindbox ) 
       
   542 	    {
       
   543 	    ret = iFindbox->OfferKeyEventL( aKeyEvent, aType )	;
       
   544 	    }
       
   545     // Not consumed by the key handler and findpane , offer to the control next
       
   546     if ( ret == EKeyWasNotConsumed )
       
   547         {
       
   548         ret = iListBox->OfferKeyEventL( aKeyEvent, aType );
       
   549         }
       
   550     iTabbedView.UpdateToolbarL();	
       
   551     return ret;
       
   552     }
       
   553 
       
   554 
       
   555 // --------------------------------------------------------------------------
       
   556 // CVIMPSTUiDoubleListBoxTabViewControl::CurrentItemIndex
       
   557 // --------------------------------------------------------------------------
       
   558 //
       
   559 TInt CVIMPSTUiDoubleListBoxTabViewControl::CurrentItemIndex() const
       
   560     {
       
   561 	TRACER_AUTO;
       
   562     if( !iListBox )
       
   563         {
       
   564         return KErrNotFound;
       
   565         }
       
   566     if( !iListBox->View() )
       
   567         {
       
   568         // CurrentItemIndex panics if the listbox has no view
       
   569         return KErrNotFound;
       
   570         }
       
   571 
       
   572     TInt curIndex( iListBox->CurrentItemIndex() );
       
   573     if ( curIndex < 0 )
       
   574         {
       
   575         return KErrNotFound;
       
   576         }
       
   577     CVIMPSTUiListBoxModel* model =
       
   578         static_cast<CVIMPSTUiListBoxModel*>( iListBox->Model() );
       
   579 
       
   580     if( model )
       
   581         {
       
   582         return model->FilteredItemIndex( curIndex );
       
   583         }
       
   584     return KErrNotFound;
       
   585     }
       
   586 
       
   587 
       
   588 
       
   589 // --------------------------------------------------------------------------
       
   590 // CVIMPSTUiDoubleListBoxTabViewControl::SetCurrentItemIndex
       
   591 // --------------------------------------------------------------------------
       
   592 //
       
   593 void CVIMPSTUiDoubleListBoxTabViewControl::SetCurrentItemIndex(TInt aIndex)
       
   594     {
       
   595 	TRACER_AUTO;
       
   596     if (iListBox->CurrentItemIndex() != aIndex &&
       
   597         aIndex >= 0 &&
       
   598         aIndex < iListBox->Model()->NumberOfItems() )
       
   599         {
       
   600         iListBox->SetCurrentItemIndex(aIndex);
       
   601         TRAP_IGNORE(UpdateCbaL());
       
   602         }
       
   603     }
       
   604 
       
   605 
       
   606 // --------------------------------------------------------------------------
       
   607 // CVIMPSTUiDoubleListBoxTabViewControl::SetCurrentItemIndexAndDraw
       
   608 // --------------------------------------------------------------------------
       
   609 //
       
   610 void CVIMPSTUiDoubleListBoxTabViewControl::SetCurrentItemIndexAndDraw(TInt aIndex)
       
   611     {
       
   612     SetCurrentItemIndex(aIndex);
       
   613     this->DrawDeferred();
       
   614     }
       
   615 
       
   616 
       
   617 // --------------------------------------------------------------------------
       
   618 // CVIMPSTUiDoubleListBoxTabViewControl::SetListEmptyTextL
       
   619 // --------------------------------------------------------------------------
       
   620 //
       
   621 void CVIMPSTUiDoubleListBoxTabViewControl::SetListEmptyTextL(TInt aResourceId)
       
   622     {
       
   623     HBufC* msgText;
       
   624     TRACER_AUTO;  
       
   625     // Get Service Name from Engine , load string from resource and display.
       
   626     // This text is shown to tell the user to restart phone to get the service again.
       
   627     TPtrC serviceNamePtr(iEngine.ServiceName());
       
   628     msgText = StringLoader::LoadLC(aResourceId, serviceNamePtr, iCoeEnv);
       
   629     iListBox->View()->SetListEmptyTextL(*msgText);
       
   630     TRACE("Display Text %S", msgText );
       
   631     
       
   632     CleanupStack::PopAndDestroy(msgText);
       
   633     }
       
   634 
       
   635 // ---------------------------------------------------------
       
   636 // CVIMPSTUiDoubleListBoxTabViewControl::LoadBitmapsL
       
   637 // Called by framework when the view size is changed
       
   638 // ---------------------------------------------------------
       
   639 //
       
   640 void CVIMPSTUiDoubleListBoxTabViewControl::LoadBitmapsL()
       
   641     {
       
   642   
       
   643 	TRACER_AUTO;
       
   644 	CFormattedCellListBoxData* listBoxData = iListBox->ItemDrawer()->ColumnData();
       
   645 	if ( !listBoxData )
       
   646 		{
       
   647 		//No listbox data
       
   648 		User::Leave( KErrNotFound );
       
   649 		}
       
   650 	
       
   651 	CAknIconArray* icons = iBrandHandler.LoadIconsLC( );
       
   652 	
       
   653     CArrayPtr<CGulIcon>* oldIconArray = listBoxData->IconArray();
       
   654     if( oldIconArray )
       
   655         {
       
   656         oldIconArray->ResetAndDestroy();
       
   657 		delete oldIconArray;
       
   658         listBoxData->SetIconArray( NULL );
       
   659         }
       
   660     TPtrC8 avatardata = iArrayProcess.OwnAvatarContentL();
       
   661     CGulIcon* newIcon = NULL;
       
   662     if( avatardata.Length() )
       
   663         {
       
   664         newIcon = AvatarToIconL( avatardata );
       
   665         }
       
   666     if( newIcon )
       
   667         {  
       
   668         // if icon creation from avatar is successful then append icon 
       
   669         // set the index 
       
   670         icons->AppendL(newIcon);
       
   671         iArrayProcess.SetOwnAvatarIndexL( icons->Count()-1 );    
       
   672         }
       
   673     else
       
   674         { // set the index to '0'
       
   675           // index=0 means default icon
       
   676         iArrayProcess.SetOwnAvatarIndexL( KErrNone );
       
   677         }
       
   678     
       
   679     TInt count = iArrayProcess.Count();
       
   680     // loop all the items in the array and get the avatar data 
       
   681     for (TInt i=0 ;i< count ;++i)
       
   682         {
       
   683         TPtrC8 avatarContent = iArrayProcess.AvatarContent(i);
       
   684         newIcon = NULL;//  make this as NULL since the icon 
       
   685                       //ownership will be taken from LIstbox
       
   686         if( avatarContent.Length())
       
   687             {
       
   688             // if that contact has any avatar data then process and create the icon
       
   689             newIcon = AvatarToIconL( avatarContent );
       
   690             }
       
   691         if ( newIcon )
       
   692             {
       
   693             // if the icon is created successfully the append to icon array
       
   694             icons->AppendL(newIcon);
       
   695             // set the icon index to the storage 
       
   696             iArrayProcess.SetAvatarIndex( i , icons->Count()-1);
       
   697             }
       
   698         else
       
   699             {
       
   700             //if icon not found. set the default for buddies
       
   701             iArrayProcess.SetAvatarIndex( i , KErrNone);
       
   702             }
       
   703         }
       
   704     // Set icon-array to listbox's drawer
       
   705     listBoxData->SetIconArray( icons );
       
   706     CleanupStack::Pop( icons );
       
   707     }
       
   708 
       
   709 // ---------------------------------------------------------
       
   710 // CVIMPSTUiDoubleListBoxTabViewControl::HandleListBoxEventL(
       
   711 //			CEikListBox* /*aListBox*/, TListBoxEvent /*aEventType*/ )
       
   712 // From MEikListBoxObserver, Handles event's generated by listbox
       
   713 // (other items were commented in a header).
       
   714 // ---------------------------------------------------------
       
   715 //
       
   716 void CVIMPSTUiDoubleListBoxTabViewControl::HandleListBoxEventL(
       
   717         CEikListBox* /*aListBox*/, TListBoxEvent aEventType )
       
   718     {
       
   719 	TRACER_AUTO;
       
   720     iTabbedView.UpdateToolbarL();
       
   721     switch(aEventType)
       
   722         {
       
   723         case EEventItemSingleClicked:
       
   724 
       
   725             {
       
   726             TInt index = CurrentItemIndex();
       
   727             TVIMPSTEnums::TItem itemType = iArrayProcess.GetType(index);
       
   728             TBool presenceEnabled = iEngine.IsSubServiceEnabled(TVIMPSTEnums::EPresence);
       
   729             TBool imEnabled = iEngine.IsSubServiceEnabled(TVIMPSTEnums::EIM);
       
   730             TBool voipEnabled = iEngine.IsSubServiceEnabled(TVIMPSTEnums::EVoip);
       
   731             TVIMPSTEnums::TVIMPSTRegistrationState serviceState = iTabbedView.GetServiceState();
       
   732             TVIMPSTEnums::TOnlineStatus onlinestatus = iArrayProcess.GetOnlineStatusL(index);
       
   733 
       
   734             if(TVIMPSTEnums::EOwnStatusItem == itemType && 
       
   735                     TVIMPSTEnums::ESVCENotRegistered ==  serviceState)
       
   736                 {
       
   737             iTabbedView.HandleCommandL( ECmdLogin );
       
   738                 }
       
   739             else if(TVIMPSTEnums::EOwnStatusItem == itemType &&
       
   740                                             TVIMPSTEnums::ESVCEWaitingForNetwork == serviceState)
       
   741                 {
       
   742                 iTabbedView.HandleCommandL( ECmdChangeConnectioninWaitingState);
       
   743                 }
       
   744             else if(TVIMPSTEnums::EOwnStatusItem == itemType 
       
   745                     && presenceEnabled &&
       
   746                     TVIMPSTEnums::ESVCERegistered ==  serviceState )
       
   747                 {
       
   748             iTabbedView.HandleCommandL( ECmdChangeStatus );
       
   749                 }
       
   750             else if( ( TVIMPSTEnums::EContactItem == itemType || 
       
   751                     TVIMPSTEnums::EUnknonContactItem == itemType )&& imEnabled &&
       
   752                     TVIMPSTEnums::ESVCERegistered == serviceState && 
       
   753                     TVIMPSTEnums::EServiceOut != onlinestatus )
       
   754                 {
       
   755             iTabbedView.HandleCommandL( ECmdOpenConversation );
       
   756                 }
       
   757             else if ( itemType == TVIMPSTEnums::EFriendRequestItem
       
   758                     && TVIMPSTEnums::ESVCERegistered == serviceState)
       
   759                 {
       
   760             iTabbedView.HandleCommandL( ECmdOpenFriendRequest );    		                    
       
   761                 }
       
   762             else if( TVIMPSTEnums::EContactItem == itemType )
       
   763                 {
       
   764                 if((TVIMPSTEnums::EPending != onlinestatus) && 
       
   765                         !(TVIMPSTEnums::ESVCEUpdatingContacts ==  serviceState ||
       
   766                                 TVIMPSTEnums::ESVCENetworkConnecting ==  serviceState || 
       
   767                                 TVIMPSTEnums::ESVCENetworkDisConnecting ==  serviceState))
       
   768                     {
       
   769                     iTabbedView.HandleCommandL( ECmdContactDetails );
       
   770                     }
       
   771                 }
       
   772             break;
       
   773 
       
   774             }
       
   775             // Add enter key handling
       
   776         case EEventEnterKeyPressed:
       
   777             {
       
   778             CEikButtonGroupContainer* cba = CEikButtonGroupContainer::Current();
       
   779             TInt commandId( iCba->ButtonGroup()->CommandId( CEikButtonGroupContainer::EMiddleSoftkeyPosition));
       
   780 
       
   781             iTabbedView.HandleCommandL(commandId);
       
   782             break;
       
   783             }
       
   784         default:
       
   785             {
       
   786             break;
       
   787             }
       
   788         }
       
   789   
       
   790        }
       
   791 // ---------------------------------------------------------
       
   792 // CVIMPSTUiDoubleListBoxTabViewControl::SendMessageL(
       
   793 //			CEikListBox* /*aListBox*/, TListBoxEvent /*aEventType*/ )
       
   794 // From MEikListBoxObserver, Handles event's generated by listbox
       
   795 // (other items were commented in a header).
       
   796 // ---------------------------------------------------------
       
   797 //
       
   798 void CVIMPSTUiDoubleListBoxTabViewControl::SendMessageL()
       
   799 	{
       
   800 	TRACER_AUTO;
       
   801 //	TInt index = iListBox->CurrentItemIndex();
       
   802 	TInt index = CurrentItemIndex();        
       
   803 	if( index< 0 )
       
   804 		{
       
   805 		// return if item not found
       
   806 		return;	
       
   807 		}
       
   808 	TPtrC seletctedItem = iArrayProcess.GetItemUserId(index) ;
       
   809 	if(seletctedItem.Length())
       
   810 	    {
       
   811 	    TInt result = EAknSoftkeyOk;
       
   812         //get the status from engine.
       
   813         TVIMPSTEnums::TOnlineStatus status = iArrayProcess.GetOnlineStatusL(index);
       
   814         
       
   815         if( status == TVIMPSTEnums::EOffline )
       
   816             {
       
   817             TBool isConvExist = iArrayProcess.IsConversationExist(index);
       
   818             if( !isConvExist)
       
   819                 {
       
   820                 // TODO : need to show only once if conversation not exist
       
   821                 // handling of error message need to be done in cv also ,waiting for ximp changes
       
   822                 // Show note about offline contact
       
   823                 HBufC* msg = StringLoader::LoadLC(
       
   824                         R_QTN_CHAT_CONTACT_MAY_NOT_RECEIVE_MESSAGE,
       
   825                         seletctedItem );                    
       
   826 
       
   827                  result = VIMPSTUtilsDialog::DisplayQueryDialogL(
       
   828                         R_CHAT_CONTACT_MAY_NOT_RECEIVE_MESSAGE_DIALOG,
       
   829                         msg->Des() );
       
   830                 CleanupStack::PopAndDestroy( msg );
       
   831                 }
       
   832             }
       
   833         
       
   834         if( ( result == EAknSoftkeyOk ) || ( result == EAknSoftkeyYes ) )
       
   835             {
       
   836             TPtrC itemName = iArrayProcess.GetItemNameText(index) ;
       
   837             // not own this p
       
   838             MVPbkContactLink* contactLink = iArrayProcess.ContactLink( index );
       
   839         
       
   840             TVwsViewId activeViewId;
       
   841             CCoeEnv::Static()->AppUi()->GetActiveViewId( activeViewId );
       
   842             UpdateCbaL();
       
   843             // imlauncher call for luanching the conversationview with seletced user id
       
   844             IMCVLauncher::LaunchImConversationViewL(activeViewId, iServiceId, seletctedItem, itemName, contactLink);
       
   845             }
       
   846 	    }
       
   847 	else
       
   848 		{
       
   849 	     //When there is no XSP Id present it comes to here
       
   850 	     //Displaying a note that there is no XSP ID
       
   851 			HBufC* note = NULL;
       
   852 	        note = StringLoader::LoadLC( R_QTN_SERVTAB_NOXSP_ERROR );
       
   853 	        VIMPSTUtilsDialog::DisplayNoteDialogL( *note );
       
   854 	        CleanupStack::PopAndDestroy( note );
       
   855 		}
       
   856 	
       
   857 	}
       
   858 // ---------------------------------------------------------
       
   859 // CVIMPSTUiDoubleListBoxTabViewControl::UpdateViewL
       
   860 // (other items were commented in a header).
       
   861 // ---------------------------------------------------------
       
   862 //
       
   863 void CVIMPSTUiDoubleListBoxTabViewControl::UpdateViewL( 
       
   864 				TInt aIndex, TVIMPSTEnums::TItem aType)
       
   865     {
       
   866 	TRACER_AUTO;
       
   867     TInt index = KErrNotFound;
       
   868      if( aIndex < 0 )
       
   869     	{
       
   870     	aIndex = CurrentItemIndex()<0?0:CurrentItemIndex();	
       
   871     	}
       
   872     switch(aType)
       
   873 	    {
       
   874 	    case TVIMPSTEnums::EContactItem:
       
   875 	    case TVIMPSTEnums::EOwnStatusItem:
       
   876 	    	{
       
   877 	    	/*Not attempting to get the index of contact because aIndex is the 
       
   878 	    	same as this index and we pass it on to the contactlistboxmodel's 
       
   879 	    	visibleitem method*/
       
   880 	    	CVIMPSTUiListBoxModel* list =
       
   881 	    	        static_cast<CVIMPSTUiListBoxModel*>( iListBox->Model() );
       
   882 	    	index = list->VisibleItemIndex(aIndex); 
       
   883 	    	if( index != KErrNotFound && iFindbox )
       
   884 				{
       
   885 			    if(iClrFindPaneFlag)
       
   886 			        {
       
   887 			        iFindbox->SetSearchTextL( KNullDesC );
       
   888 			        iFindbox->DrawNow();
       
   889 			        iClrFindPaneFlag = EFalse;
       
   890 			     	}
       
   891 			    else
       
   892 					{
       
   893 					TBuf<KTextLimit> temp;
       
   894 					iFindbox->GetSearchText(temp);
       
   895 					if(0 != temp.Compare(KNullDesC))
       
   896 					    {
       
   897 					    ((CAknFilteredTextListBoxModel*) iListBox->Model() )
       
   898 					            ->Filter()->HandleOfferkeyEventL();
       
   899 					    }
       
   900 					}
       
   901 				}
       
   902 			break;
       
   903 			}
       
   904 		default:
       
   905 			{
       
   906 			//nothing to do
       
   907 			break;
       
   908 			}    	
       
   909 	    }
       
   910 	iListBox->DrawNow();
       
   911 	SetCurrentItemIndex(aIndex);
       
   912 	SetFocusAndMakeItemVisible();
       
   913 	TInt count = iArrayProcess.Count();
       
   914 	if(count > KMinContact && ! iFindPaneIsVisible)  
       
   915 		{
       
   916 		ActivateFindPaneL();		
       
   917 		}
       
   918     else if(count <= KMinContact && iFindPaneIsVisible) // extra check needed here to improve performance
       
   919 	    {
       
   920 	    DeactivateFindPaneL();	    
       
   921 	    }
       
   922     
       
   923 	//Update the Toolbar after moving the focus to the current item.
       
   924 	iTabbedView.UpdateToolbarL();   
       
   925 	UpdateCbaL();		
       
   926     }
       
   927 // ---------------------------------------------------------
       
   928 // CVIMPSTUiDoubleListBoxTabViewControl::ActivateFindPaneL()
       
   929 // Activates find-pane
       
   930 // (other items were commented in a header).
       
   931 // ---------------------------------------------------------
       
   932 //
       
   933 void CVIMPSTUiDoubleListBoxTabViewControl::ActivateFindPaneL()
       
   934     {
       
   935 	TRACER_AUTO;
       
   936     if( !iFindbox )
       
   937         {
       
   938         // Use EAdaptiveSearch so that we can search according to columns.
       
   939         iFindbox = CAknSearchField::NewL( *this,
       
   940                 CAknSearchField::EAdaptiveSearch,
       
   941                 NULL, KTextLimit );
       
   942 
       
   943     // This is to filter the presence status from the search
       
   944     // username(0)/presencestatus(1) - 1 is to filter the presence status
       
   945     // column out of the search. In this case there are only two columns.
       
   946     TBitFlags32 columnFilterFlag; 
       
   947     columnFilterFlag.Set(1);
       
   948     iFindbox->SetListColumnFilterFlags(columnFilterFlag);
       
   949         static_cast<CAknFilteredTextListBoxModel*>( iListBox->Model() )
       
   950             ->CreateFilterL( iListBox, iFindbox );
       
   951         }
       
   952     iFindbox->SetObserver( this );
       
   953     iFindbox->ActivateL();
       
   954     iFindbox->ResetL();
       
   955     iFindbox->SetSearchTextL( KNullDesC );    
       
   956    
       
   957     iFindPaneIsVisible = ETrue;
       
   958     SetLayout();
       
   959 
       
   960     if( IsActivated() )
       
   961         {
       
   962         iFindbox->MakeVisible( ETrue );
       
   963         iFindbox->SetFocus( ETrue );
       
   964         iListBox->SizeChanged();
       
   965         DrawNow();
       
   966         }
       
   967     }
       
   968 
       
   969 // ---------------------------------------------------------
       
   970 // CVIMPSTUiDoubleListBoxTabViewControl::DeactivateFindPaneL()
       
   971 // De-activates find-pane
       
   972 // (other items were commented in a header).
       
   973 // ---------------------------------------------------------
       
   974 //
       
   975 void CVIMPSTUiDoubleListBoxTabViewControl::DeactivateFindPaneL()
       
   976     {
       
   977 	TRACER_AUTO;
       
   978     if( !iFindbox )
       
   979 	    {
       
   980 	    return;	
       
   981 	    }
       
   982     static_cast<CAknFilteredTextListBoxModel*>( iListBox->Model() )
       
   983         ->Filter()->ResetFilteringL();
       
   984 
       
   985 
       
   986     iFindbox->MakeVisible( EFalse );
       
   987     iFindbox->SetFocus( EFalse );
       
   988 
       
   989     iFindPaneIsVisible = EFalse;
       
   990     SetLayout();
       
   991 
       
   992     if( IsActivated() )
       
   993         {
       
   994         DrawNow();
       
   995         }
       
   996     }
       
   997  
       
   998  // ---------------------------------------------------------
       
   999 // CVIMPSTUiDoubleListBoxTabViewControl::GetFocussedId()
       
  1000 // To get the pointer to the iFocussedID
       
  1001 // ---------------------------------------------------------
       
  1002 TPtrC CVIMPSTUiDoubleListBoxTabViewControl::GetFocussedId()
       
  1003     {
       
  1004     TInt index = CurrentItemIndex();
       
  1005     if( index < 0 )
       
  1006 	    {
       
  1007 	    index = 0;	
       
  1008 	    }
       
  1009     return iCommandHandler.GetProcessInterface().GetItemUserId( index  );
       
  1010     }
       
  1011 // ---------------------------------------------------------
       
  1012 // CVIMPSTUiDoubleListBoxTabViewControl::SetFocussedId()
       
  1013 // Saves the Contact ID in iFocussedID
       
  1014 // ---------------------------------------------------------
       
  1015 void CVIMPSTUiDoubleListBoxTabViewControl::SetFocussedId(const TDesC& aContact)
       
  1016     {
       
  1017     TInt index = iCommandHandler.GetProcessInterface().GetSelectedItemIndex( aContact );
       
  1018     if( index < 0 )
       
  1019 	    {
       
  1020 	    index = 0;	
       
  1021 	    }
       
  1022     SetCurrentItemIndex( index );
       
  1023     SetFocusAndMakeItemVisible();
       
  1024     } 
       
  1025 // ---------------------------------------------------------
       
  1026 // CVIMPSTUiDoubleListBoxTabViewControl::SetLayout()
       
  1027 // Layouts current components according to AVKON LAF
       
  1028 // (other items were commented in a header).
       
  1029 // ---------------------------------------------------------
       
  1030 //
       
  1031 void CVIMPSTUiDoubleListBoxTabViewControl::SetLayout()
       
  1032     {
       
  1033 	TRACER_AUTO;
       
  1034     const TRect rect( Rect() );
       
  1035     if( iListBox && iFindPaneIsVisible )
       
  1036         {
       
  1037 
       
  1038         TAknWindowLineLayout empty;
       
  1039         empty.iC = 0;
       
  1040         empty.il = 0;
       
  1041         empty.it = 0;
       
  1042         empty.ir = 0;
       
  1043         empty.ib = 0;
       
  1044         empty.iW = ELayoutEmpty;
       
  1045         empty.iH = ELayoutEmpty;
       
  1046 
       
  1047         TAknWindowLineLayout findPane = AknLayoutScalable_Avkon::find_pane().LayoutLine();
       
  1048         TAknWindowLineLayout listPane;
       
  1049 
       
  1050         // listPane should equal to parent's rect
       
  1051         listPane.il = Rect().iTl.iX;
       
  1052         listPane.ir = ELayoutEmpty;
       
  1053         listPane.it = Rect().iTl.iY;
       
  1054         listPane.ib = ELayoutEmpty;
       
  1055         // this check is required since it's not guaranteed that listbox's SetRect
       
  1056         // has been called when this code is executed
       
  1057         if ( Size().iWidth > 0 )
       
  1058             {
       
  1059             listPane.iW = Size().iWidth;
       
  1060             listPane.ir = ELayoutEmpty;
       
  1061             }
       
  1062         else
       
  1063             {
       
  1064             listPane.iW = ELayoutEmpty;
       
  1065             listPane.ir = 0;
       
  1066             }
       
  1067         // but findpane's height should be subtracted
       
  1068         listPane.iH = Size().iHeight - findPane.iH;
       
  1069 
       
  1070         // findPane's width should equal to listPane's width
       
  1071         findPane.iW = listPane.iW;
       
  1072         CAknFilteredTextListBoxModel* m = static_cast <CAknFilteredTextListBoxModel*> ( iListBox->Model() );
       
  1073         if ( m->Filter() )
       
  1074             {
       
  1075             m->Filter()->SetParentControl( this );
       
  1076             }
       
  1077         TAknLayoutRect lrect;
       
  1078         lrect.LayoutRect( Rect(), empty );
       
  1079         AknLayoutUtils::LayoutControl( iFindbox, lrect.Rect(), findPane );
       
  1080         AknLayoutUtils::LayoutControl( iListBox, Rect(), listPane );
       
  1081                                       
       
  1082         }
       
  1083     else if( iListBox )
       
  1084         {
       
  1085         AknLayoutUtils::LayoutControl( iListBox,
       
  1086                                        rect,
       
  1087                                        AKN_LAYOUT_WINDOW_list_gen_pane( 0 ) );
       
  1088         }
       
  1089     }
       
  1090     
       
  1091 // ---------------------------------------------------------
       
  1092 // CVIMPSTUiDoubleListBoxTabViewControl::HandleControlEventL
       
  1093 // ---------------------------------------------------------
       
  1094 //
       
  1095 void CVIMPSTUiDoubleListBoxTabViewControl::HandleControlEventL(CCoeControl* /*aControl*/,TCoeEvent aEventType)
       
  1096     {
       
  1097     // We only observe iFindbox
       
  1098     if( EEventStateChanged == aEventType )
       
  1099         {
       
  1100 
       
  1101       	((CAknFilteredTextListBoxModel*) iListBox->Model() )
       
  1102             ->Filter()->HandleOfferkeyEventL();        
       
  1103         
       
  1104         }
       
  1105     iListBox->DrawNow(); 
       
  1106     iTabbedView.UpdateToolbarL();
       
  1107     }
       
  1108 
       
  1109 // ---------------------------------------------------------
       
  1110 
       
  1111 // ---------------------------------------------------------
       
  1112 // CVIMPSTUiDoubleListBoxTabViewControl::CheckAndSetLastItemFlag()
       
  1113 // Checks if the last contact is focused and Sets the iLastItemFlag
       
  1114 // ---------------------------------------------------------
       
  1115 void CVIMPSTUiDoubleListBoxTabViewControl::CheckAndSetLastItemFlag()
       
  1116     {
       
  1117     if(iListBox->CurrentItemIndex() == (iArrayProcess.Count() - 1))
       
  1118         {
       
  1119         iLastItemFlag = ETrue;
       
  1120         }
       
  1121     else
       
  1122         {
       
  1123         iLastItemFlag = EFalse;
       
  1124         }
       
  1125     }
       
  1126 // ---------------------------------------------------------
       
  1127 // CVIMPSTUiDoubleListBoxTabViewControl::SetFocusAndMakeItemVisible()
       
  1128 // Compares the Saved Contact in iFocussedID with the contacts in the List and focuses if it is found 
       
  1129 // ---------------------------------------------------------
       
  1130 void CVIMPSTUiDoubleListBoxTabViewControl::SetFocusAndMakeItemVisible()
       
  1131     { 
       
  1132 	TRACER_AUTO;
       
  1133     TInt count = iArrayProcess.Count();
       
  1134     TInt index = CurrentItemIndex();
       
  1135     if( index == count )
       
  1136         {   
       
  1137         if( iLastItemFlag )
       
  1138             {
       
  1139             index = count - 1;
       
  1140             iLastItemFlag = EFalse;
       
  1141             }
       
  1142         }
       
  1143     CVIMPSTUiListBoxModel* model =
       
  1144         static_cast<CVIMPSTUiListBoxModel*>( iListBox->Model() );
       
  1145 
       
  1146     if( model )
       
  1147         {
       
  1148         index = model->VisibleItemIndex( index );
       
  1149         }
       
  1150     iListBox->ScrollToMakeItemVisible(index );
       
  1151     SetCurrentItemIndex(index);
       
  1152     iListBox->DrawDeferred();
       
  1153     }
       
  1154 
       
  1155 // ---------------------------------------------------------------------
       
  1156 // CVIMPSTUiDoubleListBoxTabViewControl::SetClrFindPaneFlag(TBool aFlag)
       
  1157 // ---------------------------------------------------------------------
       
  1158 
       
  1159 void CVIMPSTUiDoubleListBoxTabViewControl::SetClrFindPaneFlag(TBool aFlag)
       
  1160     {
       
  1161     iClrFindPaneFlag = aFlag;
       
  1162     }
       
  1163 
       
  1164 // ---------------------------------------------------------
       
  1165 // CVIMPSTUiDoubleListBoxTabViewControl::CoeControl()
       
  1166 // ---------------------------------------------------------
       
  1167 
       
  1168 CCoeControl* CVIMPSTUiDoubleListBoxTabViewControl::CoeControl()
       
  1169     {
       
  1170     return  this; // return this pointer since its a parent class pointer of  CCoeControl
       
  1171     }
       
  1172 // ------------------------------------------------------------------------
       
  1173 // CVIMPSTUiDoubleListBoxTabViewControl::AvatarToIconL
       
  1174 // 
       
  1175 // ------------------------------------------------------------------------
       
  1176 CGulIcon* CVIMPSTUiDoubleListBoxTabViewControl::AvatarToIconL( const TDesC8& aAvatarContent )
       
  1177     {
       
  1178 	TRACER_AUTO;
       
  1179     CGulIcon* newIcon = NULL;
       
  1180     CVIMPSTEngineImageHandler* imageHandler = CVIMPSTEngineImageHandler::NewL();
       
  1181     CleanupStack::PushL( imageHandler );
       
  1182     // pass the avatar content and mimetype as NULL
       
  1183     // mimetype will be recognised by the UTILS  class
       
  1184     HBufC8* content = imageHandler->ProcessImageFromDataL( aAvatarContent , KNullDesC8);
       
  1185     if ( iAvatarError == KErrNone)
       
  1186         {
       
  1187         newIcon = CGulIcon ::NewL( &(imageHandler->Bitmap()) ); 
       
  1188         newIcon->SetBitmapsOwnedExternally( EFalse );              
       
  1189         }
       
  1190     CleanupStack::PopAndDestroy(); // imageHandler 
       
  1191     if(content)
       
  1192         {
       
  1193         delete content;
       
  1194         content = NULL;
       
  1195         }
       
  1196     return  newIcon; 
       
  1197     }
       
  1198 // ---------------------------------------------------------
       
  1199 // CVIMPSTUiDoubleListBoxTabViewControl::SetCbaLockL()
       
  1200 // Sets the lock status of cba keys.
       
  1201 // ---------------------------------------------------------
       
  1202 //
       
  1203 void CVIMPSTUiDoubleListBoxTabViewControl::SetCbaLockL( TBool aLock )
       
  1204     {
       
  1205     iCbaLock = aLock;
       
  1206     if( !aLock )
       
  1207         {
       
  1208         UpdateCbaL();
       
  1209         }
       
  1210     }
       
  1211 // ---------------------------------------------------------
       
  1212 // CVIMPSTUiDoubleListBoxTabViewControl::UpdateCbaL()
       
  1213 // Updates Softkeys according to current focus.
       
  1214 // ---------------------------------------------------------
       
  1215 //
       
  1216 void CVIMPSTUiDoubleListBoxTabViewControl::UpdateCbaL( TBool aUseDefaultCba /*= EFalse*/ )
       
  1217     {
       
  1218 	TRACER_AUTO;
       
  1219     TInt cbaRes = R_SERVTAB_SOFTKEYS_OPTIONS_EXIT__EMPTY;
       
  1220     iCurrentCmdToExe = -1;
       
  1221     if( !iCbaLock )
       
  1222         {
       
  1223         TInt index = CurrentItemIndex();
       
  1224         //if invalid index then dont set any command
       
  1225         if(KErrNotFound == index)
       
  1226             {
       
  1227             if ( iCba )
       
  1228                 {               
       
  1229                 iCba->SetCommandSetL( cbaRes );
       
  1230                 iCba->DrawNow();                
       
  1231                 }
       
  1232             return; 
       
  1233             }
       
  1234         
       
  1235         TVIMPSTEnums::TItem itemtype = iArrayProcess.GetType(index);
       
  1236         TVIMPSTEnums::TOnlineStatus onlinestatus = iCommandHandler.GetProcessInterface().GetOnlineStatusL(index);        
       
  1237         TVIMPSTEnums::TVIMPSTRegistrationState servicestate = iEngine.ServiceState();
       
  1238         TBool updateinvalid( iLastFocusedItemType == TVIMPSTEnums::EInvalid );
       
  1239 //         if ( !iCba )
       
  1240 //            {
       
  1241 //            iCba = CEikButtonGroupContainer::Current();        	
       
  1242 //            }
       
  1243 
       
  1244         // default softkeys
       
  1245          if(iCba)
       
  1246              {
       
  1247              if( aUseDefaultCba || updateinvalid )
       
  1248                  {
       
  1249                  if( aUseDefaultCba )
       
  1250                      {
       
  1251                      iLastFocusedItemType = TVIMPSTEnums::EOwnStatusItem;
       
  1252                      }
       
  1253                  else
       
  1254                      {
       
  1255                      iLastFocusedItemType = itemtype;
       
  1256                      }
       
  1257             
       
  1258                  if ( itemtype == TVIMPSTEnums::EOwnStatusItem  )
       
  1259                      {
       
  1260                      // Own status
       
  1261                      if(TVIMPSTEnums::ESVCERegistered == servicestate)
       
  1262                          {
       
  1263                          // Options/Back/Change status
       
  1264                           cbaRes = R_SERVTAB_SOFTKEYS_OPTIONS_EXIT__CHANGESTATUS;
       
  1265                           iCurrentCmdToExe = ECmdChangeStatus;
       
  1266                          }
       
  1267                      else if(TVIMPSTEnums::ESVCENetworkConnecting == servicestate)
       
  1268                          {
       
  1269                          if(iTabbedView.CancelLoginSupportedL())
       
  1270                               {
       
  1271                               cbaRes = R_SERVTAB_SOFTKEYS_OPTION_CANCEL__EXIT;
       
  1272                               iCurrentCmdToExe = ECmdCancelLogin;
       
  1273                               }
       
  1274                           else
       
  1275                               {
       
  1276                               cbaRes = R_SERVTAB_SOFTKEYS_OPTIONS_EXIT__EMPTY;
       
  1277                               iCurrentCmdToExe = -1;
       
  1278                               }
       
  1279                          }
       
  1280                      else if(TVIMPSTEnums::ESVCEWaitingForNetwork == servicestate)
       
  1281                          {
       
  1282                          cbaRes = R_SERVTAB_SOFTKEYS_OPTION_CHANGECONN__EXIT;
       
  1283                          iCurrentCmdToExe = ECmdChangeConnectioninWaitingState;
       
  1284                          }
       
  1285                     else if(TVIMPSTEnums::ESVCEUpdatingContacts != servicestate)
       
  1286 		                    {
       
  1287 		                    cbaRes = R_SERVTAB_SOFTKEYS_OPTION_LOGIN__EXIT;
       
  1288 		                    iCurrentCmdToExe = ECmdLogin;
       
  1289 		                    }
       
  1290                      }
       
  1291                  
       
  1292                  iCba->SetCommandSetL( cbaRes );
       
  1293                  iCba->DrawNow();
       
  1294                  }
       
  1295             
       
  1296              // collapse softkey ( when focus is on contact )
       
  1297              else if(  itemtype == TVIMPSTEnums::EContactItem  )
       
  1298                  {
       
  1299                  iLastFocusedItemType = itemtype;
       
  1300                  if(TVIMPSTEnums::ESVCERegistered == servicestate)
       
  1301                      {
       
  1302                      // im is supported
       
  1303                      if(iEngine.IsSubServiceSupportedL(TVIMPSTEnums::EIM))
       
  1304                          {
       
  1305                          iCba->SetCommandSetL( R_SERVTAB_SOFTKEYS_OPTION_OPENCONV__EXIT );
       
  1306                          iCurrentCmdToExe = ECmdOpenConversation;
       
  1307                          }
       
  1308                      else //im is not supporteed
       
  1309                          {
       
  1310                          iCba->SetCommandSetL( R_SERVTAB_SOFTKEYS_OPTIONS_DETAILS__EXIT );
       
  1311                          iCurrentCmdToExe = ECmdContactDetails;
       
  1312                          }                     
       
  1313                      }
       
  1314                  else if(TVIMPSTEnums::ESVCENotRegistered == servicestate)
       
  1315                      {
       
  1316                      iCba->SetCommandSetL( R_SERVTAB_SOFTKEYS_OPTIONS_DETAILS__EXIT );                  
       
  1317                      iCurrentCmdToExe = ECmdContactDetails;
       
  1318                      }
       
  1319                  iCba->DrawNow();	
       
  1320                  }
       
  1321              else if(  itemtype == TVIMPSTEnums::EUnknonContactItem  )
       
  1322                  {
       
  1323                  iLastFocusedItemType = itemtype;
       
  1324                  if(TVIMPSTEnums::ESVCERegistered == servicestate && 
       
  1325                          iEngine.IsSubServiceSupportedL(TVIMPSTEnums::EIM))
       
  1326                      {
       
  1327                      iCba->SetCommandSetL( R_SERVTAB_SOFTKEYS_OPTION_OPENCONV__EXIT );
       
  1328                      iCurrentCmdToExe = ECmdOpenConversation;
       
  1329                      }
       
  1330                  else //im is not supporteed
       
  1331                      {
       
  1332                      iCba->SetCommandSetL( R_SERVTAB_SOFTKEYS_OPTIONS_EXIT__EMPTY );
       
  1333                      iCurrentCmdToExe = -1;
       
  1334                      }                     
       
  1335                  iCba->DrawNow();   
       
  1336                  }
       
  1337              // Focus on own contact item
       
  1338              else if( itemtype == TVIMPSTEnums::EOwnStatusItem )
       
  1339                  {
       
  1340                  iLastFocusedItemType = itemtype;
       
  1341                  if ( itemtype == TVIMPSTEnums::EOwnStatusItem  )
       
  1342                      {
       
  1343                      // Own status
       
  1344                      if(TVIMPSTEnums::ESVCERegistered == servicestate)
       
  1345                          {
       
  1346                          // Options/Back/Change status
       
  1347                           cbaRes = R_SERVTAB_SOFTKEYS_OPTIONS_EXIT__CHANGESTATUS;
       
  1348                           iCurrentCmdToExe = ECmdChangeStatus;
       
  1349                          }
       
  1350                      else if(TVIMPSTEnums::ESVCENetworkConnecting == servicestate)
       
  1351                          {
       
  1352                          if(iTabbedView.CancelLoginSupportedL())
       
  1353                               {
       
  1354                               cbaRes = R_SERVTAB_SOFTKEYS_OPTION_CANCEL__EXIT;
       
  1355                               iCurrentCmdToExe = ECmdCancelLogin;                         
       
  1356                               }
       
  1357                           else
       
  1358                               {
       
  1359                               cbaRes = R_SERVTAB_SOFTKEYS_OPTIONS_EXIT__EMPTY;
       
  1360                               iCurrentCmdToExe = -1;
       
  1361                               }
       
  1362                          }
       
  1363                      else if(TVIMPSTEnums::ESVCEWaitingForNetwork == servicestate)
       
  1364                          {
       
  1365                          cbaRes = R_SERVTAB_SOFTKEYS_OPTION_CHANGECONN__EXIT;
       
  1366                          iCurrentCmdToExe = ECmdChangeConnectioninWaitingState;
       
  1367                          }
       
  1368                     else if(TVIMPSTEnums::ESVCEUpdatingContacts != servicestate)
       
  1369 		                    {
       
  1370 		                    cbaRes = R_SERVTAB_SOFTKEYS_OPTION_LOGIN__EXIT;
       
  1371 		                    iCurrentCmdToExe = ECmdLogin;
       
  1372 		                    }
       
  1373                      }
       
  1374                  //add for connecting state and waiting for connection state.
       
  1375                  iCba->SetCommandSetL( cbaRes );
       
  1376                  iCba->DrawNow();
       
  1377                  }
       
  1378              // Focus on invitation item
       
  1379              else if( itemtype == TVIMPSTEnums::EFriendRequestItem )
       
  1380                  {
       
  1381                  iLastFocusedItemType = itemtype;
       
  1382                  if(TVIMPSTEnums::ESVCERegistered == servicestate)
       
  1383                      {
       
  1384                      iCurrentCmdToExe = ECmdOpenFriendRequest;	
       
  1385                      iCba->SetCommandSetL( R_SERVTAB_SOFTKEYS_OPTION_OPENFRNDREQ__EXIT );
       
  1386                      iCba->DrawNow();
       
  1387                      }
       
  1388                     
       
  1389                  }  
       
  1390              }
       
  1391           
       
  1392         }
       
  1393     }
       
  1394 
       
  1395 // ---------------------------------------------------------
       
  1396 // CVIMPSTUiDoubleListBoxTabViewControl::HandleAvatarRefreshL()
       
  1397 // Saves the Contact ID in iFocussedID
       
  1398 // ---------------------------------------------------------
       
  1399 void CVIMPSTUiDoubleListBoxTabViewControl::HandleAvatarRefreshL( const TDesC& aUserId,TBool aBlock )
       
  1400 	{
       
  1401 	TRACER_AUTO;
       
  1402 	if(aBlock)
       
  1403 	{
       
  1404       TRACE("inside blocking");		   
       
  1405 	TInt index = iArrayProcess.GetSelectedItemIndex(aUserId );//Get the index from storage.
       
  1406 	if(index >= 0)
       
  1407 		{
       
  1408 		CFormattedCellListBoxData* listBoxData = iListBox->ItemDrawer()->ColumnData();
       
  1409 		CArrayPtr<CGulIcon>* currentIconArray = listBoxData->IconArray();
       
  1410 		TInt avIndex = iArrayProcess.AvatarIndex(index);
       
  1411 
       
  1412 		    if( avIndex ) // if there is old icon already
       
  1413 		        {
       
  1414 		        // delete the old icon compress the array and insert at the same position
       
  1415 		        currentIconArray->Delete( avIndex );
       
  1416 		        currentIconArray->Compress();
       
  1417 		        }
       
  1418 
       
  1419 		    // avatar got cleared just  set the icon index to '0'
       
  1420 		    // icon what was added still remains in the  listbox icon array
       
  1421 		    // dont delete the old icon, because that needs to modify the whole 
       
  1422 		    // indexes of the  other contacts. 
       
  1423 		    // "keeping the icon is better than changing all contacts indexes"
       
  1424 		    // The icons will be deleted by listbox, when list box got destructed.
       
  1425 		    iArrayProcess.SetAvatarIndex( index , KErrNone );
       
  1426 
       
  1427 		}
       
  1428 	}
       
  1429 
       
  1430 	else
       
  1431 	{
       
  1432           TRACE("inside unblocking calling handleavatarchangel");
       
  1433 	   HandleAvatarChangeL(aUserId);
       
  1434 	}
       
  1435 
       
  1436 	}
       
  1437 
       
  1438 
       
  1439 // End of File