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