uiservicetab/vimpstcmdprocess/src/cvimpstprocessArray.cpp
changeset 0 5e5d6b214f4f
child 11 bef90b82da71
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 command process array
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 // INCLUDE FILES
       
    20 #include <coemain.h>
       
    21 #include    "vimpstdebugprint.h" 
       
    22 
       
    23 #include "cvimpstprocessarray.h"
       
    24 
       
    25 #include "mvimpstprocessarrayobserver.h"
       
    26 #include "cvimpststoragemanagerfactory.h"
       
    27 #include "mvimpststorageserviceview.h"
       
    28 #include "TVIMPSTEnums.h"
       
    29 #include "cvimpstprocessarrayitem.h"
       
    30 #include "mvimpststorageitemmodel.h"
       
    31 #include "tvimpstconsts.h"
       
    32 #include "mvimpststoragecontactlist.h"
       
    33 #include "mvimpststoragevpbkstorehandler.h"
       
    34 #include "mvimpstengine.h"
       
    35 #include "cvimpstprocessfriendrequestitem.h"
       
    36 #include "mvimpstenginesubservice.h"
       
    37 #include <mvpbkfieldtype.h>
       
    38 #include <mvpbkcontactfielduridata.h>
       
    39 #include <MVPbkContactFieldTextData.h>
       
    40 //rsg file for resource id
       
    41 #include <vimpstuires.rsg>
       
    42 #include "vimpstutils.h"
       
    43 #include <mvpbkcontactlink.h>
       
    44 #include <vpbkeng.rsg>
       
    45 #include "mvimpstengineimsubservice.h"
       
    46 #include "mvimpstenginepresencesubservice.h"
       
    47 #include "vimpstdebugtrace.h"
       
    48 #include <APGTASK.H> 
       
    49 #include "imcvuiparams.h"
       
    50 
       
    51 // --------------------------------------------------------------------------
       
    52 // CVIMPSTProcessArray::CIMArrayProcess
       
    53 // --------------------------------------------------------------------------
       
    54 //
       
    55 CVIMPSTProcessArray::CVIMPSTProcessArray( MVIMPSTEngine& aEngine)
       
    56 :iOwnDataIndex(KOwnDataIndex),
       
    57 iContactListIndex(KOwnDataIndex),
       
    58 iEngine(aEngine)
       
    59         {
       
    60         iServiceId = iEngine.ServiceId();
       
    61         }
       
    62 
       
    63 // --------------------------------------------------------------------------
       
    64 // CVIMPSTProcessArray::~CVIMPSTProcessArray
       
    65 // --------------------------------------------------------------------------
       
    66 //
       
    67 CVIMPSTProcessArray::~CVIMPSTProcessArray()
       
    68     {
       
    69     TRACE( T_LIT("CVIMPSTProcessArray::~CVIMPSTProcessArray Start") );
       
    70     if(iContactInterface)
       
    71         {
       
    72         iContactInterface->RemoveObserver( this );	
       
    73         }
       
    74     iItemArray.ResetAndDestroy();
       
    75     //iItemArray.Close();
       
    76     
       
    77     
       
    78     iUnKnownContactArray.Close();
       
    79     iAddRequestArray.Close();
       
    80     
       
    81     if(iData)
       
    82         {
       
    83         delete iData;
       
    84         iData = NULL;
       
    85         }
       
    86     //Get IM SubService     
       
    87     MVIMPSTEngineSubService* subService1 =    	   
       
    88     (iEngine.SubService(TVIMPSTEnums::EIM));
       
    89 
       
    90     if(subService1)
       
    91         {
       
    92         MVIMPSTEngineIMSubService& imSubService = 
       
    93         MVIMPSTEngineIMSubService::Cast (*subService1);
       
    94         imSubService.UnRegisterChatObserver(this);
       
    95         }
       
    96 
       
    97     //subscribe for ownpresencechangeevent    			
       
    98     MVIMPSTEngineSubService* subService =    	   
       
    99     (iEngine.SubService(TVIMPSTEnums::EPresence));
       
   100 
       
   101     if(subService)
       
   102         {
       
   103         MVIMPSTEnginePresenceSubService& presence = 
       
   104         MVIMPSTEnginePresenceSubService::Cast (*subService);
       
   105         presence.UnRegisterPresenceEventObserver(this);
       
   106         } 
       
   107 
       
   108     TRACE( T_LIT("CVIMPSTProcessArray::~CVIMPSTProcessArray End") );
       
   109     }
       
   110 
       
   111 // --------------------------------------------------------------------------
       
   112 // CVIMPSTProcessArray::NewL
       
   113 // --------------------------------------------------------------------------
       
   114 //
       
   115 CVIMPSTProcessArray* CVIMPSTProcessArray::NewL(
       
   116         MVIMPSTEngine& aEngine)
       
   117     {
       
   118     TRACE( T_LIT("CVIMPSTProcessArray::NewL Start") );
       
   119     CVIMPSTProcessArray* self = new(ELeave) CVIMPSTProcessArray(aEngine);
       
   120     CleanupStack::PushL(self);
       
   121     self->ConstructL();
       
   122     CleanupStack::Pop(self);
       
   123     TRACE( T_LIT("CVIMPSTProcessArray::NewL End") );
       
   124     return self;
       
   125     
       
   126     }
       
   127 
       
   128 // --------------------------------------------------------------------------
       
   129 // CVIMPSTProcessArray::ConstructL
       
   130 // --------------------------------------------------------------------------
       
   131 //
       
   132 void CVIMPSTProcessArray::ConstructL()
       
   133     {
       
   134     TRACE( T_LIT("CVIMPSTProcessArray::ConstructL Start") );
       
   135     iContactInterface = CVIMPSTStorageManagerFactory::ContactListInterfaceL(iServiceId);
       
   136     if(iContactInterface)
       
   137         {        
       
   138         iContactInterface->AddObserverL( this );// listen these events..        
       
   139         }
       
   140     HBufC* unnamed = VIMPSTUtils::LoadResourceL( R_SERVTAB_UNNAMED );
       
   141     if( unnamed )
       
   142 	    {
       
   143 	    CleanupStack::PushL( unnamed );
       
   144 	    iContactInterface->SetUnnamedTextL(unnamed); // takes ownership
       
   145 	    CleanupStack::Pop( unnamed );	
       
   146 	    }
       
   147     iContactListModel = CVIMPSTStorageManagerFactory::ItemModelInterfaceL(iServiceId);
       
   148     iLoginState = iEngine.ServiceState();
       
   149     
       
   150     iIMSupported = EFalse;
       
   151     iPresenceSupported = EFalse;
       
   152     //Get IM SubService     
       
   153     MVIMPSTEngineSubService* subService1 =(iEngine.SubService(TVIMPSTEnums::EIM));
       
   154     if(subService1)
       
   155         {
       
   156         MVIMPSTEngineIMSubService& imSubService = 
       
   157         MVIMPSTEngineIMSubService::Cast (*subService1);
       
   158         imSubService.RegisterChatObserver(this);
       
   159         iIMSupported = ETrue;
       
   160         }
       
   161     iData = HBufC::NewL(512);
       
   162     iAddRequestArray.Reset();
       
   163     iUnKnownContactArray.Reset();
       
   164     //subscribe for ownpresencechangeevent
       
   165     MVIMPSTEngineSubService* subService =    	   
       
   166     (iEngine.SubService(TVIMPSTEnums::EPresence));
       
   167     if(subService)
       
   168         {        
       
   169         MVIMPSTEnginePresenceSubService& presence = 
       
   170         MVIMPSTEnginePresenceSubService::Cast (*subService);
       
   171         presence.RegisterPresenceEventObserverL(this);     
       
   172         iPresenceSupported = ETrue;
       
   173         }
       
   174 	ResetArray();
       
   175 	TRACE( T_LIT("CVIMPSTProcessArray::ConstructL end") );
       
   176     }
       
   177 // --------------------------------------------------------------------------
       
   178 // CVIMPSTProcessArray::HandleStorageChangeL
       
   179 // --------------------------------------------------------------------------
       
   180 //
       
   181 void CVIMPSTProcessArray::HandleStorageChangeL( TVIMPSTEnums::TVIMPSTStorgaeEventType aEventType,
       
   182 			         							MVIMPSTStorageContactList* /*aList*/, 
       
   183 				        						MVIMPSTStorageContact* aContact,
       
   184 				        						TInt aContactIndex )
       
   185     {
       
   186     TRACE( T_LIT("CVIMPSTProcessArray::HandleStorageChangeL Function Start") );
       
   187     // 0th index OwnItem + unknow contacts + add request
       
   188     aContactIndex = aContactIndex + 1 + iUnKnownContactArray.Count() + iAddRequestArray.Count();
       
   189     
       
   190     switch( aEventType )
       
   191         {
       
   192         case TVIMPSTEnums::EStorageContactReadComplete:
       
   193             {
       
   194             TRACE( T_LIT("CVIMPSTProcessArray::HandleStorageChangeL EStorageContactReadComplete Start") );
       
   195             if(iProcessObservers)
       
   196                 {
       
   197                 /* passing 0 so that the focus is on owndata item */
       
   198                 iProcessObservers->HandleAdditionL(TVIMPSTEnums::EOwnStatusItem, 0 ); // focus own item
       
   199                 }
       
   200             TRACE( T_LIT("CVIMPSTProcessArray::HandleStorageChangeL EStorageContactReadComplete End") );
       
   201             break;
       
   202             }
       
   203         case TVIMPSTEnums::EStorageContactFetchComplete:
       
   204             {
       
   205             TRACE( T_LIT("CVIMPSTProcessArray::HandleStorageChangeL EStorageContactFetchComplete Start") );
       
   206             TRACE( T_LIT("HandleStorageChangeL EStorageContactFetchComplete iItemArray Count: %d"), iItemArray.Count() );
       
   207 
       
   208             if(iProcessObservers)
       
   209                 {
       
   210                 /* passing 0 so that the focus is on owndata item */
       
   211                 iProcessObservers->HandleAdditionL(TVIMPSTEnums::EOwnStatusItem, 0 ); // focus own item
       
   212                 }
       
   213 
       
   214             ResetArray();
       
   215             iFetchCompleted = ETrue;
       
   216             GetAndCreateOpenChatListL();
       
   217             TRACE( T_LIT("CVIMPSTProcessArray::HandleStorageChangeL EStorageContactFetchComplete End") );
       
   218             break; 	
       
   219             }
       
   220         case TVIMPSTEnums::EStorageContactReading:
       
   221         case TVIMPSTEnums::EStorageContactFetching:
       
   222         case TVIMPSTEnums::EStorageContactSynchronizing:
       
   223             {
       
   224             TRACE( T_LIT("CVIMPSTProcessArray::HandleStorageChangeL EStorageContactFetching/EStorageContactFetching Start") );
       
   225             /*
       
   226              *	This event occurs whenever we have contacts added to contactlist. This happens in the following scenarios
       
   227              *	1. At the time of login, when we fetch contacts, contact-by-contact is added to the storage. so we get this event.
       
   228              * 	2. When we add a contact manually (either from phonebook, or manu adding etc.. ) we get this callback.
       
   229              */
       
   230             TRACE( T_LIT("contactindex = %d"),aContactIndex );
       
   231             CVIMPSTProcessContactItem* contactItem = CVIMPSTProcessContactItem::NewL (*this, const_cast<TDesC&>(aContact->Name() ),
       
   232                     const_cast<TDesC&>(aContact->UserId() ),
       
   233                     aContact->ContactLink(),
       
   234                     const_cast<TDesC&>(aContact->StatusText()),
       
   235                     aContact->OnlineStatus());
       
   236             
       
   237             contactItem->SetAvatarIndex(aContact->AvatarIndex());
       
   238 
       
   239             /* All the time the index should be less than the item array's count, but during the fetch of contacts from cdb file to the view, 
       
   240              * if we havent got a contactviewready, and during that if I get contactaddition, before getting contactFetchComplete, we should keep 
       
   241              * appending the items to the array for display, once we get the entire list, its sorted anyway while insertion, and when presence occurs
       
   242              * the contacts are re-sorted. 
       
   243              */
       
   244             TRACE( T_LIT("itemarraycount = %d"),iItemArray.Count() );
       
   245             if (aContactIndex >= iItemArray.Count() )
       
   246                 {
       
   247                 TRACE( T_LIT("append contact item %d"), contactItem);
       
   248                 iItemArray.Append(contactItem);
       
   249                 }
       
   250             else
       
   251                 {
       
   252                 TRACE( T_LIT("Insert at index = %d"), aContactIndex);
       
   253                 iItemArray.Insert(contactItem, aContactIndex );
       
   254                 }               
       
   255             if(iProcessObservers)
       
   256                 {
       
   257                 /* passing 0 so that the focus is on owndata item */
       
   258                 iProcessObservers->HandleAdditionL(TVIMPSTEnums::EOwnStatusItem, 0);
       
   259                 }
       
   260             if( aContact->AvatarContent().Length() && iProcessObservers )
       
   261                 {
       
   262                 iProcessObservers->HandleAvatarChangeL( aContact->UserId() );
       
   263                 }
       
   264             TRACE( T_LIT("CVIMPSTProcessArray::HandleStorageChangeL EStorageContactFetching/EStorageContactFetching End") );
       
   265             break;
       
   266             }
       
   267         case TVIMPSTEnums::EStorageEventContactAddition:
       
   268             {
       
   269             TRACE( T_LIT("CVIMPSTProcessArray::HandleStorageChangeL EStorageEventContactAddition Start") );
       
   270 
       
   271             TBool removed = RemoveFromUnknonOrInvitationListL( aContact->UserId(), EFalse );
       
   272             if( removed )
       
   273                 {
       
   274                 aContactIndex = aContactIndex - 1; // one contact is removed from iUnknownContactArray 
       
   275                 }
       
   276             /*
       
   277              *	This event occurs whenever we have contacts added to contactlist. This happens in the following scenarios
       
   278              *	1. At the time of login, when we fetch contacts, contact-by-contact is added to the storage. so we get this event.
       
   279              * 	2. When we add a contact manually (either from phonebook, or manu adding etc.. ) we get this callback.
       
   280                  */
       
   281             TPtrC userId = aContact->UserId();
       
   282                 TRACE( T_LIT("contactindex = %d"),aContactIndex );
       
   283                 CVIMPSTProcessContactItem* contactItem = CVIMPSTProcessContactItem::NewL ( *this, aContact->Name() ,
       
   284                                                                                             userId,
       
   285                                                                                             aContact->ContactLink(),
       
   286                                                                                             const_cast<TDesC&>(aContact->StatusText()),
       
   287                                                                                             aContact->OnlineStatus() );
       
   288 
       
   289                 contactItem->SetAvatarIndex(aContact->AvatarIndex());
       
   290             /* All the time the index should be less than the item array's count, but during the fetch of contacts from cdb file to the view, 
       
   291              * if we havent got a contactviewready, and during that if I get contactaddition, before getting contactFetchComplete, we should keep 
       
   292              * appending the items to the array for display, once we get the entire list, its sorted anyway while insertion, and when presence occurs
       
   293              * the contacts are re-sorted. 
       
   294              */
       
   295             TRACE( T_LIT("itemarraycount = %d"),iItemArray.Count() );
       
   296             if (aContactIndex >= iItemArray.Count() )
       
   297                 {
       
   298                 TRACE( T_LIT("append contact item = %d"), contactItem);
       
   299                 iItemArray.Append(contactItem);
       
   300                 }                
       
   301             else
       
   302                 {
       
   303                 TRACE( T_LIT("Insert at index = %d"), aContactIndex);
       
   304                 iItemArray.Insert(contactItem, aContactIndex );
       
   305                 }                
       
   306              // check if  pending message exist
       
   307             if( TVIMPSTEnums::ESVCERegistered == iLoginState && userId.Length() )
       
   308                 {
       
   309                 if( IsConversationExistL( userId ) )
       
   310                     {
       
   311                     contactItem->SetConversationOpen(ETrue);
       
   312                     }
       
   313                 if( IsUnreadMessageExistsL( userId ) )
       
   314                     {
       
   315                     contactItem->SetMsgPending(ETrue);
       
   316                     }
       
   317                 }
       
   318 
       
   319             if(iProcessObservers)
       
   320                 {
       
   321                 /* passing aContactIndex so that the focus is on owndata item */
       
   322                 iProcessObservers->HandleAdditionL(TVIMPSTEnums::EContactItem, aContactIndex );
       
   323                 }   
       
   324             TRACE( T_LIT("CVIMPSTProcessArray::HandleStorageChangeL EStorageEventContactAddition End") );
       
   325             break;
       
   326             }
       
   327         case TVIMPSTEnums::EStorageEventContactDelete:
       
   328             {
       
   329             TRACE( T_LIT("CVIMPSTProcessArray::HandleStorageChangeL EStorageEventContactDelete Start") );
       
   330             TRACE( T_LIT("contactindex = %d"),aContactIndex );
       
   331             TRACE( T_LIT("itemarraycount = %d"),iItemArray.Count() );
       
   332             if( aContactIndex < iItemArray.Count() )
       
   333                 {
       
   334                 MVIMPSTProcessArrayItem* deletedItem = iItemArray[ aContactIndex ]; 
       
   335                 TRACE( T_LIT("contact removed in item array of index = %d"),aContactIndex );
       
   336                 iItemArray.Remove (aContactIndex);
       
   337                 delete deletedItem;
       
   338                 iItemArray.Compress();
       
   339                 TRACE( T_LIT("contactindex = %d"),aContactIndex );
       
   340                 }
       
   341             if(iProcessObservers)
       
   342                 {
       
   343                 iProcessObservers->HandleDeletionL(TVIMPSTEnums::EContactItem, aContactIndex);
       
   344                 }
       
   345             TRACE( T_LIT("CVIMPSTProcessArray::HandleStorageChangeL EStorageEventContactDelete End") );
       
   346             break;
       
   347             }
       
   348         case TVIMPSTEnums::EStorageAvatarChange:
       
   349             {
       
   350             TRACE( T_LIT("CVIMPSTProcessArray::HandleStorageChangeL EStorageAvatarChange Start") );
       
   351             if(iProcessObservers  && aContact )
       
   352                 {
       
   353                 TRACE( T_LIT("CVIMPSTProcessArray::HandleStorageChangeL EStorageAvatarChange inside if") );
       
   354                 TPtrC aUserId = aContact->UserId();
       
   355                 TRACE( T_LIT("CVIMPSTProcessArray::HandleStorageChangeL EStorageAvatarChange aUserId = %S"), &aUserId );
       
   356                 iProcessObservers->HandleAvatarChangeL( aContact->UserId() );
       
   357                 }
       
   358             TRACE( T_LIT("CVIMPSTProcessArray::HandleStorageChangeL EStorageAvatarChange End") );
       
   359             break;            
       
   360             }
       
   361         case TVIMPSTEnums::EStorageOwnPresenceChange:
       
   362             {
       
   363             TRACE( T_LIT("CVIMPSTProcessArray::HandleStorageChangeL EStorageAvatarChange Start") );
       
   364             if(iProcessObservers)
       
   365                 {
       
   366                 /* passing index as 0, so thta focus remains at the owndata item */
       
   367                 iProcessObservers->HandleAdditionL(TVIMPSTEnums::EOwnStatusItem, KErrNotFound );
       
   368                 }
       
   369             TRACE( T_LIT("CVIMPSTProcessArray::HandleStorageChangeL EStorageAvatarChange End") );
       
   370             break;
       
   371             }
       
   372         case TVIMPSTEnums::EStorageMultiplePresenceChange:
       
   373 	        {
       
   374 	        TRACE( T_LIT("CVIMPSTProcessArray::HandleStorageChangeL EStorageAvatarChange Start") );
       
   375 	        // mostly this will get called after just login and fetch time
       
   376 	        ResetArray();
       
   377             if(iProcessObservers )
       
   378                 {
       
   379                 iProcessObservers->HandleAdditionL(TVIMPSTEnums::EContactItem, KErrNotFound );
       
   380                 }
       
   381             TRACE( T_LIT("CVIMPSTProcessArray::HandleStorageChangeL EStorageAvatarChange End") );
       
   382 	        break;	
       
   383 	        }
       
   384         case TVIMPSTEnums::EStoragePresenceChange:
       
   385             {
       
   386             TRACE( T_LIT("CVIMPSTProcessArray::HandleStorageChangeL EStoragePresenceChange Start") );
       
   387             /* 
       
   388              *	After Sort we get the new index... So first we need to remove the contact from the old position, 
       
   389              *	and then re-insert it at the correct obtained position (newIndex in this case)
       
   390              */
       
   391             TRACE( T_LIT("contactindex = %d"),aContactIndex );
       
   392             TRACE( T_LIT("itemarraycount = %d"),iItemArray.Count() );
       
   393             if( aContactIndex < iItemArray.Count() )
       
   394                 {                
       
   395                 TInt newIndex = iContactListModel->IndexOfContact( aContact );
       
   396                 TRACE( T_LIT("new index = %d"),newIndex );
       
   397                 CVIMPSTProcessContactItem* newItem = CVIMPSTProcessContactItem::NewL(*this, const_cast<TDesC&>(aContact->Name() ),
       
   398                         const_cast<TDesC&>(aContact->UserId() ),
       
   399                         aContact->ContactLink(),
       
   400                         const_cast<TDesC&>(aContact->StatusText()),
       
   401                         aContact->OnlineStatus() );
       
   402                 
       
   403                 
       
   404                 MVIMPSTProcessArrayItem* oldItem = iItemArray[ aContactIndex ]; 
       
   405                 newItem->SetAvatarIndex(aContact->AvatarIndex()); // copy the avatar index too.
       
   406                 
       
   407                 TBool isOldConversationExists(EFalse);
       
   408                 TBool isOldMsgPending(EFalse);
       
   409                 // checking if previously chat/msgs were existing
       
   410                 if( TVIMPSTEnums::ESVCERegistered == iLoginState && aContact->UserId().Length() )
       
   411                     {
       
   412 
       
   413                     if( IsConversationExistL( aContact->UserId() ) )
       
   414                         {
       
   415                         isOldConversationExists = ETrue;
       
   416                         }
       
   417                     if( IsUnreadMessageExistsL( aContact->UserId() ) )
       
   418                         {
       
   419                         isOldMsgPending = ETrue;
       
   420                         }
       
   421                    }
       
   422                 TRACE( T_LIT("contact removed in item array of index = %d"),aContactIndex );
       
   423                 iItemArray.Remove(aContactIndex );
       
   424                 delete oldItem;
       
   425                 iItemArray.Compress();
       
   426                 
       
   427                 // restoring if previously chat/msgs were existing
       
   428                 if( TVIMPSTEnums::ESVCERegistered == iLoginState && aContact->UserId().Length() )
       
   429                     {
       
   430                     if( isOldConversationExists )
       
   431                         {
       
   432                         newItem->SetConversationOpen(ETrue);
       
   433                         }
       
   434                     if( isOldMsgPending )
       
   435                         {
       
   436                         newItem->SetMsgPending(ETrue);
       
   437                         }
       
   438                     }
       
   439                 // Add it in the new index
       
   440                 newIndex = newIndex + 1 + iUnKnownContactArray.Count()+ iAddRequestArray.Count();
       
   441                 if (newIndex >= iItemArray.Count())
       
   442                     {
       
   443                     TRACE( T_LIT("append contact item = %d"), newIndex);
       
   444                     iItemArray.Append (newItem);
       
   445                     }
       
   446                 else
       
   447                     {
       
   448                     TRACE( T_LIT("Insert at index = %d"), newItem);
       
   449                     iItemArray.Insert (newItem, newIndex);
       
   450                     }   
       
   451                 }
       
   452             if(iProcessObservers )
       
   453                 {
       
   454                 iProcessObservers->HandleAdditionL(TVIMPSTEnums::EContactItem, KErrNotFound );
       
   455                 }
       
   456             TRACE( T_LIT("CVIMPSTProcessArray::HandleStorageChangeL EStoragePresenceChange End") );
       
   457             break;
       
   458             }
       
   459         case TVIMPSTEnums::EStorageEventOwnUserChanged:
       
   460             {
       
   461             TRACE( T_LIT("CVIMPSTProcessArray::HandleStorageChangeL EStorageEventOwnUserChanged Start") );
       
   462             TRACE( T_LIT("CVIMPSTProcessArray::HandleStorageChangeL start Event = %d"),aEventType );
       
   463             ResetArray();
       
   464             if(iProcessObservers )
       
   465                 {
       
   466                 iProcessObservers->HandleDeletionL(TVIMPSTEnums::EOwnStatusItem, 0 ); // focus own item
       
   467 
       
   468                 if( aContact )
       
   469                     {
       
   470                     iProcessObservers->HandleAvatarChangeL( aContact->UserId() );
       
   471                     }
       
   472                 }
       
   473             TRACE( T_LIT("CVIMPSTProcessArray::HandleStorageChangeL EStorageEventOwnUserChanged End") );
       
   474 
       
   475             break;
       
   476             }
       
   477         case TVIMPSTEnums::EStorageAllContactRemoved:
       
   478             {
       
   479             TRACE( T_LIT("CVIMPSTProcessArray::HandleStorageChangeL EStorageAllContactRemoved Start") );
       
   480             TRACE( T_LIT("CVIMPSTProcessArray::HandleStorageChangeL EStorageAllContactRemoved count = %d"), iItemArray.Count() );
       
   481             ResetArray();
       
   482             if(iProcessObservers )
       
   483                 {
       
   484                 iProcessObservers->HandleDeletionL(TVIMPSTEnums::EOwnStatusItem, 0 ); // focus own item
       
   485                 }
       
   486             TRACE( T_LIT("CVIMPSTProcessArray::HandleStorageChangeL EStorageAllContactRemoved End") );
       
   487             break;
       
   488             }
       
   489         case TVIMPSTEnums::EStorageEventContactChange: 
       
   490 	        {
       
   491 	        TRACE( T_LIT("CVIMPSTProcessArray::HandleStorageChangeL EStorageEventContactChange Start") );
       
   492 	        // display name is changed ,might be contact is re-arranged
       
   493             TRACE( T_LIT("contactindex = %d"),aContactIndex );
       
   494             TRACE( T_LIT("itemarraycount = %d"),iItemArray.Count() );
       
   495             if( aContactIndex < iItemArray.Count() )
       
   496                 {
       
   497                 CVIMPSTProcessContactItem* newItem = CVIMPSTProcessContactItem::NewL(*this, const_cast<TDesC&>(aContact->Name() ),
       
   498                         const_cast<TDesC&>(aContact->UserId() ),
       
   499                         aContact->ContactLink(),
       
   500                         const_cast<TDesC&>(aContact->StatusText()),
       
   501                         aContact->OnlineStatus() );
       
   502                 
       
   503                 
       
   504                 MVIMPSTProcessArrayItem* oldItem = iItemArray[ aContactIndex ];
       
   505                 newItem->SetAvatarIndex(aContact->AvatarIndex()); // copy the avatar index too.
       
   506                 TRACE( T_LIT("contact removed in item array of index = %d"),aContactIndex );
       
   507                 // set the conversation open flag from old contact, as only the display name would have changed.
       
   508                 newItem->SetConversationOpen(oldItem->IsConversationOpen());
       
   509                 newItem->SetMsgPending( oldItem->IsMsgPending() );
       
   510                 iItemArray.Remove(aContactIndex );
       
   511                 delete oldItem;
       
   512                 iItemArray.Compress();
       
   513                 TRACE( T_LIT("Insert at index = %d"), aContactIndex);
       
   514                 TInt newIndex = iContactListModel->IndexOfContact( aContact );
       
   515                  // Add it in the new index
       
   516                 newIndex = newIndex + 1 + iUnKnownContactArray.Count() + iAddRequestArray.Count();
       
   517                 if (newIndex >= iItemArray.Count())
       
   518                     {
       
   519                     TRACE( T_LIT("append contact item = %d"), newIndex);
       
   520                     iItemArray.Append (newItem);
       
   521                     }
       
   522                 else
       
   523                     {
       
   524                     TRACE( T_LIT("Insert at index = %d"), newItem);
       
   525                     iItemArray.Insert(newItem, newIndex);
       
   526                     } 
       
   527                 // inform the cv about the display name changes
       
   528                 if(aContact && aContact->UserId().Length() && newItem->IsConversationOpen())
       
   529                     {
       
   530                     TRACE( T_LIT("CVIMPSTProcessArray::HandleStorageChangeL EStorageEventContactChange "));
       
   531                     TApaTaskList taskList( CCoeEnv::Static()->WsSession() );
       
   532                     TApaTask task( taskList.FindApp( KConversationViewAppUid ) );
       
   533 
       
   534                     if ( task.Exists() )
       
   535                         {
       
   536                         TRACE( T_LIT("CVIMPSTProcessArray::HandleStorageChangeL EStorageEventContactChange:task exists"));
       
   537                         // packing of data ,passed to conversation view
       
   538                         TPckgBuf< TIMCVUiParams > params;
       
   539                         params().iBuddyId = aContact->UserId();
       
   540                         params().iBuddyName = aContact->Name();
       
   541                         params().iServiceId = iServiceId;
       
   542                         params().iUpdate = ETrue;
       
   543                         task.SendMessage( 
       
   544                                 TUid::Uid( KUidApaMessageSwitchOpenFileValue ), params );
       
   545                         }
       
   546                     }
       
   547                 }
       
   548             if(iProcessObservers )
       
   549                 {
       
   550                 iProcessObservers->HandleAdditionL(TVIMPSTEnums::EContactItem, aContactIndex );
       
   551                 }
       
   552             TRACE( T_LIT("CVIMPSTProcessArray::HandleStorageChangeL EStorageEventContactChange End") );
       
   553 	        break;	
       
   554 	        }          
       
   555         case TVIMPSTEnums::EStorageEventUserIdPostChange:
       
   556             {
       
   557             TRACE( T_LIT("CVIMPSTProcessArray::HandleStorageChangeL EStorageEventUserIdPostChange Start") );
       
   558             TRACE( T_LIT("contactindex = %d"),aContactIndex );
       
   559             TRACE( T_LIT("itemarraycount = %d"),iItemArray.Count() );
       
   560             if( aContactIndex < iItemArray.Count() )
       
   561                 {
       
   562                 CVIMPSTProcessContactItem* newItem = CVIMPSTProcessContactItem::NewL(*this, const_cast<TDesC&>(aContact->Name() ),
       
   563                         const_cast<TDesC&>(aContact->UserId() ),
       
   564                         aContact->ContactLink(),
       
   565                         const_cast<TDesC&>(aContact->StatusText()),
       
   566                         aContact->OnlineStatus() );
       
   567                 
       
   568                 
       
   569                 MVIMPSTProcessArrayItem* oldItem = iItemArray[ aContactIndex ];
       
   570                 newItem->SetAvatarIndex(aContact->AvatarIndex()); // copy the avatar index too.
       
   571                 TRACE( T_LIT("contact removed in item array of index = %d"),aContactIndex );
       
   572                 iItemArray.Remove(aContactIndex );
       
   573                 delete oldItem;
       
   574                 iItemArray.Compress();
       
   575                 TRACE( T_LIT("Insert at index = %d"), aContactIndex);
       
   576                 iItemArray.InsertL (newItem, aContactIndex);
       
   577                 }
       
   578             if(iProcessObservers )
       
   579                 {
       
   580                 iProcessObservers->HandleAdditionL(TVIMPSTEnums::EContactItem, aContactIndex );
       
   581                 }
       
   582             TRACE( T_LIT("CVIMPSTProcessArray::HandleStorageChangeL EStorageEventUserIdPostChange End") );
       
   583             break;
       
   584             }
       
   585         default:
       
   586             {
       
   587             TRACE( T_LIT("CVIMPSTProcessArray::HandleStorageChangeL Event default") );
       
   588             break;
       
   589             }
       
   590         }
       
   591     TRACE( T_LIT("CVIMPSTProcessArray::HandleStorageChangeL Function End") );
       
   592     }
       
   593 
       
   594 // --------------------------------------------------------------------------
       
   595 // CVIMPSTProcessArray::AddObserver
       
   596 // --------------------------------------------------------------------------
       
   597 //
       
   598 void CVIMPSTProcessArray::AddObserver( MVIMPSTProcessArrayObserver* aObserver ) 
       
   599     {
       
   600     iProcessObservers = aObserver;
       
   601     }
       
   602 // --------------------------------------------------------------------------
       
   603 // CVIMPSTProcessArray::RemoveObserver
       
   604 // --------------------------------------------------------------------------
       
   605 //
       
   606 void CVIMPSTProcessArray::RemoveObserver( ) 
       
   607     {
       
   608     iProcessObservers = NULL;
       
   609     }
       
   610 
       
   611 // -----------------------------------------------------------------------------
       
   612 // CVIMPSTProcessArray::GetItemNameTextL
       
   613 // -----------------------------------------------------------------------------
       
   614 
       
   615 TPtrC CVIMPSTProcessArray::GetItemNameText(TInt aIndex)
       
   616     {
       
   617     TVIMPSTEnums::TItem itemtype = GetType( aIndex );
       
   618 	MVIMPSTProcessArrayItem* arrayItem = NULL;
       
   619     /* Codescanner warning is ignored, since Bound check is done 
       
   620      * inside the GetType()
       
   621      * method*/
       
   622     switch(itemtype)
       
   623         {
       
   624         case TVIMPSTEnums::EOwnStatusItem:
       
   625             {
       
   626             MVIMPSTProcessArrayItem *arrayItem = (MVIMPSTProcessArrayItem *)iItemArray[aIndex];
       
   627             return arrayItem->GetItemUserId(); // no name for own user	
       
   628             }
       
   629         case TVIMPSTEnums::EContactListItem:
       
   630         case TVIMPSTEnums::EContactItem:
       
   631             { 
       
   632             arrayItem = (MVIMPSTProcessArrayItem *)iItemArray[aIndex];
       
   633            	break;	
       
   634             }
       
   635         case TVIMPSTEnums::EFriendRequestItem:
       
   636             {
       
   637             arrayItem = (MVIMPSTProcessArrayItem *)iItemArray[aIndex];
       
   638             break;
       
   639             }
       
   640        case TVIMPSTEnums::EUnknonContactItem:
       
   641            {
       
   642            arrayItem = (MVIMPSTProcessArrayItem *)iItemArray[aIndex];
       
   643            break;
       
   644            }
       
   645         case TVIMPSTEnums::EInvalid:
       
   646         default:
       
   647             {
       
   648             break;
       
   649             }
       
   650         }
       
   651 	if( arrayItem )
       
   652 		{
       
   653 		return arrayItem->GetItemNameText();	
       
   654 		}
       
   655 	return KNullDesC();
       
   656     }
       
   657 
       
   658 // -----------------------------------------------------------------------------
       
   659 // CVIMPSTProcessArray::GetItemUserId
       
   660 // -----------------------------------------------------------------------------
       
   661 
       
   662 TPtrC CVIMPSTProcessArray::GetItemUserId(TInt aIndex)
       
   663     {
       
   664     TVIMPSTEnums::TItem itemtype = GetType( aIndex );
       
   665 
       
   666     /* Codescanner warning is ignored, since Bound check is done 
       
   667      * inside the GetType()
       
   668      * method*/
       
   669     switch(itemtype)    
       
   670         {
       
   671         case TVIMPSTEnums::EContactItem:
       
   672         case TVIMPSTEnums::EFriendRequestItem:
       
   673         case TVIMPSTEnums::EUnknonContactItem:
       
   674         case TVIMPSTEnums::EOwnStatusItem:
       
   675             {
       
   676             MVIMPSTProcessArrayItem *arrayItem = (MVIMPSTProcessArrayItem *)iItemArray[aIndex];
       
   677             return arrayItem->GetItemUserId(); // no name for own user	
       
   678             }
       
   679         default:
       
   680             {
       
   681             return KNullDesC(); 
       
   682             }
       
   683         }
       
   684     }
       
   685 
       
   686 // -----------------------------------------------------------------------------
       
   687 // CVIMPSTProcessArray::ContactLink
       
   688 // -----------------------------------------------------------------------------
       
   689 
       
   690 MVPbkContactLink* CVIMPSTProcessArray::ContactLink(TInt aIndex)
       
   691     {
       
   692     TVIMPSTEnums::TItem itemtype = GetType( aIndex );
       
   693 
       
   694     /* Codescanner warning is ignored, since Bound check is done 
       
   695      * inside the GetType()
       
   696      * method*/
       
   697     switch(itemtype)
       
   698         {
       
   699         case TVIMPSTEnums::EOwnStatusItem:
       
   700             {
       
   701             return NULL;	
       
   702             }
       
   703         case TVIMPSTEnums::EContactListItem:
       
   704         case TVIMPSTEnums::EContactItem:
       
   705             { 	
       
   706             MVIMPSTProcessArrayItem *arrayItem = (MVIMPSTProcessArrayItem *)iItemArray[aIndex];
       
   707             return arrayItem->ContactLink();	
       
   708             }
       
   709         case TVIMPSTEnums::EInvalid:
       
   710         default:
       
   711             {
       
   712             }
       
   713         }
       
   714     return NULL;
       
   715     }
       
   716 
       
   717 // -----------------------------------------------------------------------------
       
   718 // CVIMPSTProcessArray::Count
       
   719 // -----------------------------------------------------------------------------
       
   720 
       
   721 TInt CVIMPSTProcessArray::Count() const
       
   722 	{
       
   723 	// return the total count here.
       
   724 	return iItemArray.Count() ;
       
   725 	}
       
   726 // -----------------------------------------------------------------------------
       
   727 // CVIMPSTProcessArray::IsSubServiceSupportedL
       
   728 // -----------------------------------------------------------------------------
       
   729 
       
   730 TBool CVIMPSTProcessArray::IsSubServiceSupportedL(TVIMPSTEnums::SubServiceType aType ) const
       
   731 	{
       
   732 	return iEngine.IsSubServiceSupportedL(aType );
       
   733 	}
       
   734 
       
   735 // -----------------------------------------------------------------------------
       
   736 // CVIMPSTProcessArray::IsIMSupported
       
   737 // -----------------------------------------------------------------------------
       
   738 TBool CVIMPSTProcessArray::IsIMSupported()
       
   739     {
       
   740     return iIMSupported;
       
   741     }
       
   742 
       
   743 // -----------------------------------------------------------------------------
       
   744 // CVIMPSTProcessArray::IsPresenceSupported
       
   745 // -----------------------------------------------------------------------------
       
   746 TBool CVIMPSTProcessArray::IsPresenceSupported()
       
   747     {
       
   748     return iPresenceSupported;
       
   749     }
       
   750 
       
   751 // -----------------------------------------------------------------------------
       
   752 // CVIMPSTProcessArray::GetType
       
   753 // Get the type from engine and return the type
       
   754 // -----------------------------------------------------------------------------
       
   755 
       
   756 TVIMPSTEnums::TItem CVIMPSTProcessArray::GetType(TInt aIndex) const
       
   757 	{
       
   758 	TInt itemArrayCount = iItemArray.Count();
       
   759 	if(itemArrayCount <=0 || (aIndex < 0 || aIndex >= itemArrayCount) )
       
   760 	    {
       
   761 	    return TVIMPSTEnums::EInvalid;
       
   762 	    }
       
   763 
       
   764 	else if(itemArrayCount>0)
       
   765 	    {
       
   766 	    TInt index = aIndex <= 0 ? 0 : aIndex;
       
   767 	    MVIMPSTProcessArrayItem* item = iItemArray[ index ];	
       
   768 	    return item->Type();
       
   769 	    }
       
   770 	else
       
   771 	    {
       
   772 	    return TVIMPSTEnums::EInvalid;
       
   773 	    }	
       
   774 	}
       
   775 // -----------------------------------------------------------------------------
       
   776 // CVIMPSTProcessArray::FillItemL
       
   777 // Fill up the complete array one item at a time
       
   778 // -----------------------------------------------------------------------------
       
   779 
       
   780 void CVIMPSTProcessArray::FillItemL()
       
   781     {
       
   782     TInt count = 0;
       
   783     if(iContactListModel)
       
   784         {
       
   785         count = iContactListModel->Count();
       
   786         }
       
   787 
       
   788     // the index is starting from 1, because we already added owndata item to the list.......
       
   789     for ( TInt index = 0; index < count ; index++)
       
   790         {
       
   791         // fetch the item and process correct type
       
   792         MVIMPSTStorageItemModel::SItem item = iContactListModel->Item( index );
       
   793         switch( item.iType )
       
   794             {
       
   795             case MVIMPSTStorageItemModel::EContactList:
       
   796                 break;
       
   797             case MVIMPSTStorageItemModel::EContactItem:
       
   798                 {
       
   799                 // contact item
       
   800                 // add this items to contact item -- CONTACT 
       
   801                 // create an object of this type and append this to the rpointerarray
       
   802                 MVIMPSTStorageContact* contact = item.iContact;							   
       
   803                 TPtrC userId = contact->UserId();
       
   804                 CVIMPSTProcessContactItem* contactItem = 
       
   805                 CVIMPSTProcessContactItem::NewL(*this, contact->Name(),
       
   806                 								userId ,
       
   807                         						contact->ContactLink(),
       
   808                         			            const_cast<TDesC&>(contact->StatusText()),
       
   809                         			            contact->OnlineStatus() );
       
   810                 
       
   811                 contactItem->SetAvatarIndex(contact->AvatarIndex());
       
   812                 
       
   813                 TInt otherCount = 1 + iUnKnownContactArray.Count() + iAddRequestArray.Count();
       
   814                 contactItem->SetItemIndex(index + otherCount );
       
   815                 //append this to the array
       
   816                 iItemArray.AppendL(contactItem);
       
   817                 if( TVIMPSTEnums::ESVCERegistered == iLoginState && userId.Length() )
       
   818                     {
       
   819                     if( IsUnreadMessageExistsL( userId ) )
       
   820                         {
       
   821                         contactItem->SetMsgPending(ETrue);
       
   822                         }
       
   823                     if( IsConversationExistL( userId ) )
       
   824                         {
       
   825                         contactItem->SetConversationOpen(ETrue);
       
   826                         }
       
   827                     }
       
   828                 break;
       
   829                 }
       
   830             default:
       
   831                 {
       
   832                 // the call shouldn't be here
       
   833                 break;
       
   834                 }
       
   835             }
       
   836         }
       
   837 
       
   838     }
       
   839 
       
   840 // -----------------------------------------------------------------------------
       
   841 // CVIMPSTProcessArray::FillOwnDataL
       
   842 // FillOwnDataL implementation
       
   843 // -----------------------------------------------------------------------------
       
   844 // fill the owndata at the begining of array.....
       
   845 TBool CVIMPSTProcessArray::FillOwnDataL()
       
   846     {
       
   847     TBool ownDataAdded = EFalse;
       
   848     TPtr dataPtr = iData->Des();    
       
   849     // Check whether the user has logged in before, if has
       
   850     // then dont update anything just return   
       
   851     //check if its logged in or not.
       
   852     // 1. if not logged in append 
       
   853     switch(iLoginState)
       
   854         {
       
   855         case TVIMPSTEnums::ESVCERegistered:
       
   856             {
       
   857             TPtrC userId = iContactInterface->OwnContactL().UserId();
       
   858             dataPtr.Copy(userId);
       
   859             break;
       
   860             }
       
   861         case TVIMPSTEnums::ESVCENetworkConnecting:
       
   862             {
       
   863             HBufC* tempStr = VIMPSTUtils::LoadResourceL( R_QTN_SERVTAB_LOGGING_LIST_ITEM );
       
   864             if(tempStr)
       
   865                 {
       
   866                 dataPtr.Copy(*tempStr);     
       
   867                 delete tempStr; 
       
   868                 }
       
   869 
       
   870             break;
       
   871             }
       
   872         case TVIMPSTEnums::ESVCEUpdatingContacts:
       
   873             {
       
   874             HBufC* tempStr = VIMPSTUtils::LoadResourceL( R_QTN_SERVTAB_UPDATING_LIST_ITEM );
       
   875             if(tempStr)
       
   876                 {
       
   877                 dataPtr.Copy(*tempStr);     
       
   878                 delete tempStr; 
       
   879                 }
       
   880 
       
   881             break;
       
   882             }
       
   883         case TVIMPSTEnums::ESVCEWaitingForNetwork:
       
   884             {
       
   885             HBufC* tempStr = VIMPSTUtils::LoadResourceL( R_QTN_SERVTAB_WAITING_LIST_ITEM );
       
   886             if(tempStr)
       
   887                 {
       
   888                 dataPtr.Copy(*tempStr);     
       
   889                 delete tempStr; 
       
   890                 }
       
   891 			break;	
       
   892             }
       
   893         case TVIMPSTEnums::ESVCENetworkDisConnecting:
       
   894             {
       
   895             HBufC* tempStr = NULL;
       
   896             if ( iEngine.IsSubServiceSupportedL(TVIMPSTEnums::EPresence) ) 
       
   897                 {
       
   898                 // if presence enabled use double line listbox string
       
   899                 tempStr= VIMPSTUtils::LoadResourceL( R_QTN_SERVTAB_LOGGINGOUT_LIST_ITEM );
       
   900                 }
       
   901             else
       
   902                 { 
       
   903                 // if  presence is not enabled use  single line listbox string
       
   904                 tempStr= VIMPSTUtils::LoadResourceL( R_QTN_SERVTAB_SINGLE_LINE_LOGGINGOUT_LIST_ITEM );
       
   905                 }
       
   906 
       
   907             if(tempStr)
       
   908                 {
       
   909                 dataPtr.Copy(*tempStr);     
       
   910                 delete tempStr;
       
   911                 }			
       
   912 
       
   913             break;
       
   914             }
       
   915         case TVIMPSTEnums::ESVCENotRegistered:
       
   916         default:
       
   917             {
       
   918             HBufC* str = NULL;
       
   919             if ( iEngine.SubService( TVIMPSTEnums::EPresence) ) 
       
   920                 {
       
   921                 // if presence enabled use double line listbox string
       
   922                 str = VIMPSTUtils::LoadResourceL( R_QTN_SERVTAB_LOGIN_LIST_ITEM );
       
   923                 }
       
   924             else
       
   925                 { 
       
   926                 // if  presence is not enabled use  single line listbox string
       
   927                 // get  the username from settings
       
   928                 TPtrC ownUserId = iContactInterface->OwnContactL().UserId();
       
   929                 if ( ownUserId.Length() )
       
   930                     { 
       
   931                     // if username is available then show with login item
       
   932                     // remove domain part and give it to resource laoder
       
   933                     str= VIMPSTUtils::LoadResourceL( R_QTN_SERVTAB_SINGLE_LINE_LOGIN_LIST_ITEM_WITH_USERNAME , VIMPSTUtils::DisplayId( ownUserId ) );
       
   934                     }
       
   935                 else
       
   936                     {
       
   937                     // this condition occures when there is allocated memory for username with NO data (length =0 )
       
   938                     // just make sure "no memory leak" without depending on the Function  LoginUserNameFromSettingsL()
       
   939                     // since that would return the allocated memory without Data (length=0 ) 
       
   940                     // just show login item since no username is available in the settings
       
   941                     str= VIMPSTUtils::LoadResourceL( R_QTN_SERVTAB_SINGLE_LINE_LOGIN_LIST_ITEM );
       
   942                     }
       
   943                 }
       
   944             if( str )
       
   945                 {
       
   946                 dataPtr.Copy(*str);		
       
   947                 delete str;		
       
   948                 }
       
   949             break;
       
   950             }
       
   951         }
       
   952     if( iItemArray.Count() )
       
   953 	    {
       
   954 	    // own item is already exist delete it before adding a fresh one
       
   955 	    MVIMPSTProcessArrayItem* arrayItem = iItemArray[ 0 ]; // should be own data
       
   956 	    if( arrayItem->Type() == TVIMPSTEnums::EOwnStatusItem )
       
   957 		    {
       
   958 	    	iItemArray.Remove(0);   //iItemArray takes ownership of owndataItem, do not delete here
       
   959 	    	delete arrayItem;
       
   960 	    	iItemArray.Compress();
       
   961 	    	}
       
   962 	    }
       
   963     //common code for all the above cases to update the owndata item to list at index 0
       
   964     CVIMPSTProcessOwnDataItem* owndataItem = CVIMPSTProcessOwnDataItem::NewL(*this, *iData);
       
   965     owndataItem->SetItemIndex(0);
       
   966     //append this to the array
       
   967     iItemArray.InsertL( owndataItem,0 );   //iItemArray takes ownership of owndataItem, do not delete here
       
   968     iContactListIndex = 0;
       
   969     ownDataAdded = ETrue;     
       
   970     return ownDataAdded;
       
   971     }
       
   972 
       
   973 // -----------------------------------------------------------------------------
       
   974 // CVIMPSTProcessArray::FillArrayL
       
   975 // -----------------------------------------------------------------------------
       
   976 
       
   977 void CVIMPSTProcessArray::FillArrayL()
       
   978     {
       
   979     if(FillOwnDataL() )
       
   980         {
       
   981         // then fill the conversations..or open chats....	
       
   982         }
       
   983     else
       
   984         {
       
   985         iContactListIndex = 0; // we have not added any thing to main array..so index is zero...
       
   986         }
       
   987     FillUnknownContactsL(); //will fill all unknown contact from iUnknownContactArray to iItemArray.
       
   988     FillAddRequestDataL();//will fill all requests from iAddRequestArray to iItemArray.
       
   989     FillItemL();   
       
   990     }
       
   991 
       
   992 
       
   993 // -----------------------------------------------------------------------------
       
   994 // CVIMPSTProcessArray::ResetArray
       
   995 // -----------------------------------------------------------------------------
       
   996 
       
   997 void CVIMPSTProcessArray::ResetArray()
       
   998     {
       
   999     RemoveUnKnownContacts(); //will remove all the unknown contacts from iItemArray.
       
  1000     RemoveAddRequestData();//will remove all the requests from iItemArray.
       
  1001     iItemArray.ResetAndDestroy();
       
  1002     TRAPD( err, FillArrayL());
       
  1003     if ( err != KErrNone )
       
  1004         {
       
  1005         CActiveScheduler::Current()->Error( err );
       
  1006         }
       
  1007     }
       
  1008 
       
  1009 // -----------------------------------------------------------------------------
       
  1010 // CVIMPSTProcessArray::SetLoginState
       
  1011 // -----------------------------------------------------------------------------
       
  1012 
       
  1013 void CVIMPSTProcessArray::SetLoginStateL(TVIMPSTEnums::TVIMPSTRegistrationState aLoginState)
       
  1014     {
       
  1015     iLoginState = aLoginState;
       
  1016     if(aLoginState != TVIMPSTEnums::ESVCERegistered )
       
  1017         {
       
  1018         iFetchCompleted = EFalse;
       
  1019         RemoveUnKnownContacts();
       
  1020         RemoveAddRequestData();
       
  1021         iUnKnownContactArray.ResetAndDestroy();// delete all items
       
  1022         iUnKnownContactArray.Reset();
       
  1023         iAddRequestArray.ResetAndDestroy();// delete all items
       
  1024         iAddRequestArray.Reset();
       
  1025         }
       
  1026     FillOwnDataL(); // this will change the own item based on connection status
       
  1027     }
       
  1028 // -----------------------------------------------------------------------------
       
  1029 // CVIMPSTProcessArray::GetLoginState
       
  1030 // -----------------------------------------------------------------------------
       
  1031 
       
  1032 TVIMPSTEnums::TVIMPSTRegistrationState CVIMPSTProcessArray::GetLoginState()
       
  1033     {
       
  1034     return iLoginState;
       
  1035     }
       
  1036 
       
  1037 // -----------------------------------------------------------------------------
       
  1038 // CVIMPSTProcessArray::GetOnlineStatus
       
  1039 // -----------------------------------------------------------------------------
       
  1040 
       
  1041 TVIMPSTEnums::TOnlineStatus CVIMPSTProcessArray::GetOnlineStatusL(TInt aIndex)
       
  1042     {
       
  1043     TVIMPSTEnums::TItem itemtype = GetType( aIndex );
       
  1044     TVIMPSTEnums::TOnlineStatus status = TVIMPSTEnums::EUnknown;
       
  1045     switch(itemtype)
       
  1046         {
       
  1047         case TVIMPSTEnums::EOwnStatusItem:
       
  1048             {
       
  1049             if( iContactInterface )
       
  1050 	            {
       
  1051                  status = iContactInterface->OwnContactL().OnlineStatus();
       
  1052 	            }
       
  1053             break;
       
  1054             }
       
  1055         case TVIMPSTEnums::EContactItem:
       
  1056             { 
       
  1057 
       
  1058             status = iItemArray[aIndex]->OnlineStatus();
       
  1059             break;
       
  1060             }
       
  1061         case TVIMPSTEnums::EInvalid:
       
  1062         default:
       
  1063             {
       
  1064             break;
       
  1065             }
       
  1066         }
       
  1067     return status;
       
  1068     }
       
  1069 //-----------------------------------------------------------
       
  1070 //CVIMPSTProcessArray::StatusText
       
  1071 //-----------------------------------------------------------
       
  1072 // 
       
  1073 const TDesC&  CVIMPSTProcessArray::StatusTextL(TInt aIndex ) 
       
  1074     {
       
  1075     TVIMPSTEnums::TItem itemtype = GetType( aIndex );
       
  1076     switch(itemtype)
       
  1077         {
       
  1078         case TVIMPSTEnums::EOwnStatusItem:
       
  1079             {
       
  1080             if( iContactInterface )
       
  1081 	            {
       
  1082 	            return iContactInterface->OwnContactL().StatusText();	
       
  1083 	            }
       
  1084             break;
       
  1085             }
       
  1086         case TVIMPSTEnums::EContactItem:
       
  1087             { 
       
  1088             return iItemArray[aIndex]->StatusText();
       
  1089             }
       
  1090         case TVIMPSTEnums::EInvalid:
       
  1091         default:
       
  1092             {
       
  1093             break;
       
  1094             }
       
  1095         }
       
  1096     return KNullDesC;
       
  1097     }
       
  1098 //-----------------------------------------------------------
       
  1099 //CVIMPSTProcessArray::RemoveFromUnknonOrInvitationListL
       
  1100 //-----------------------------------------------------------
       
  1101 //
       
  1102 TBool CVIMPSTProcessArray::RemoveFromUnknonOrInvitationListL( const TDesC& aAddedUserId ,TBool aBlocked )
       
  1103     {
       
  1104     TBool found = RemoveFromUnknonListL( aAddedUserId );
       
  1105     if( !found )
       
  1106         {
       
  1107         found = RemoveFromInvitationListL( aAddedUserId );
       
  1108         }
       
  1109     //Get IM SubService  
       
  1110     if( aBlocked && found && aAddedUserId.Length() )
       
  1111         {
       
  1112         MVIMPSTEngineSubService* subService =         
       
  1113         (iEngine.SubService(TVIMPSTEnums::EIM));
       
  1114 
       
  1115         if(subService )
       
  1116             {
       
  1117             MVIMPSTEngineIMSubService& imSubService = 
       
  1118             MVIMPSTEngineIMSubService::Cast (*subService);
       
  1119             imSubService.CloseConversationL( aAddedUserId );
       
  1120             }
       
  1121         }
       
  1122     return found;
       
  1123     }
       
  1124 //-----------------------------------------------------------
       
  1125 //CVIMPSTProcessArray::RemoveFromUnknonListL
       
  1126 //-----------------------------------------------------------
       
  1127 //
       
  1128 TBool CVIMPSTProcessArray::RemoveFromUnknonListL( const TDesC& aAddedUserId )
       
  1129     {
       
  1130     TRACE( T_LIT("CVIMPSTProcessArray::RemoveFromUnknonListL start ") );
       
  1131     TPtrC addedUserId = VIMPSTUtils::DisplayId( aAddedUserId );
       
  1132     TBool found = EFalse;
       
  1133     TInt count = iUnKnownContactArray.Count();
       
  1134     CVIMPSTProcessUnknownContactItem* unknownItem = NULL;
       
  1135     TInt index = KErrNotFound;
       
  1136     TInt itemIndex = KErrNotFound;
       
  1137     // check in unknon array
       
  1138     for(index = 0 ; index < count ; index++)
       
  1139         {
       
  1140         unknownItem = iUnKnownContactArray[index];
       
  1141         TPtrC contactId = VIMPSTUtils::DisplayId( unknownItem->GetItemUserId() );
       
  1142         if( addedUserId.Compare(  contactId ) == 0 )
       
  1143             {
       
  1144             itemIndex = iItemArray.Find(unknownItem);
       
  1145             if( itemIndex > -1 )
       
  1146                 {
       
  1147                 found = ETrue;
       
  1148                 }
       
  1149             break;
       
  1150             }
       
  1151         TRACE( T_LIT("CVIMPSTProcessArray::RemoveFromUnknonListL  for ends") );
       
  1152         }
       
  1153     if( found )
       
  1154         {
       
  1155         iItemArray.Remove(itemIndex);
       
  1156         iUnKnownContactArray.Remove( index );
       
  1157         delete unknownItem;
       
  1158         unknownItem = NULL;
       
  1159         iItemArray.Compress();
       
  1160         iUnKnownContactArray.Compress();
       
  1161         if( iProcessObservers )
       
  1162             {
       
  1163             // this is to refresh the list box
       
  1164             // KErrNotFound , focus remain at same position
       
  1165             iProcessObservers->HandleDeletionL(TVIMPSTEnums::EUnknonContactItem, KErrNotFound );
       
  1166             }
       
  1167         }
       
  1168     TRACE( T_LIT("CVIMPSTProcessArray::RemoveFromUnknonListL end ") );
       
  1169     return found;
       
  1170     }
       
  1171 //-----------------------------------------------------------
       
  1172 //CVIMPSTProcessArray::RemoveFromInvitationListL
       
  1173 //-----------------------------------------------------------
       
  1174 //
       
  1175 TBool CVIMPSTProcessArray::RemoveFromInvitationListL( const TDesC& aAddedUserId )
       
  1176     {
       
  1177     TPtrC addedUserId = VIMPSTUtils::DisplayId( aAddedUserId );
       
  1178     TBool found = EFalse;
       
  1179     TInt index = KErrNotFound;
       
  1180     TInt itemIndex = KErrNotFound;
       
  1181     // item not foun in unknown list
       
  1182     // check in invitation item array
       
  1183     TInt count = iAddRequestArray.Count();
       
  1184     CVIMPSTProcessFriendRequestItem* requestItem = NULL;
       
  1185     for(index = 0 ; index < count ; index++)
       
  1186         {
       
  1187         requestItem = iAddRequestArray[index];
       
  1188         TPtrC contactId = VIMPSTUtils::DisplayId( requestItem->GetItemUserId() );
       
  1189         if( addedUserId.Compare( contactId ) == 0 )
       
  1190             {
       
  1191             itemIndex = iItemArray.Find(requestItem);
       
  1192             if( itemIndex > -1 )
       
  1193                 {
       
  1194                 found = ETrue;
       
  1195                 }
       
  1196             break;
       
  1197             }
       
  1198         }
       
  1199     if( found )
       
  1200         {
       
  1201         iItemArray.Remove(itemIndex);
       
  1202         iAddRequestArray.Remove( index );
       
  1203         delete requestItem;
       
  1204         requestItem = NULL;
       
  1205         iItemArray.Compress();
       
  1206         iAddRequestArray.Compress();
       
  1207         if( iProcessObservers )
       
  1208             {
       
  1209             // this is to refresh the list box
       
  1210             // KErrNotFound , focus remain at same position
       
  1211             iProcessObservers->HandleDeletionL(TVIMPSTEnums::EFriendRequestItem, KErrNotFound );
       
  1212             }
       
  1213         }
       
  1214     return found;
       
  1215     }
       
  1216 //-----------------------------------------------------------
       
  1217 //CVIMPSTProcessArray::MapContactListPositions
       
  1218 //-----------------------------------------------------------
       
  1219 //
       
  1220 void CVIMPSTProcessArray::MapContactListPositions(RArray<TInt>& aPos )
       
  1221     {
       
  1222     // add conversation also this list ..and return..
       
  1223     RArray<TInt> listPos; 
       
  1224 
       
  1225     //	iContactListModel->MapContactListPositions(listPos);
       
  1226     TInt positionIndex = 0;
       
  1227     // if count is more than 0..fill the maparray...
       
  1228     if(iItemArray.Count()  + iContactListIndex > 0) 
       
  1229         {
       
  1230 
       
  1231         TInt count = listPos.Count();
       
  1232 
       
  1233         for(TInt posIndex = 0; posIndex < count; posIndex++, positionIndex++)
       
  1234             {
       
  1235             aPos.Append( listPos[posIndex] + iContactListIndex );
       
  1236             }
       
  1237         }
       
  1238     listPos.Close();	
       
  1239     }
       
  1240 // -----------------------------------------------------------------------------
       
  1241 // CVIMPSTProcessArray::GetAndCreateOpenChatListL
       
  1242 // return contact index including friend request.
       
  1243 // -----------------------------------------------------------------------------
       
  1244 void CVIMPSTProcessArray::GetAndCreateOpenChatListL() 
       
  1245     {
       
  1246     //Get IM SubService     
       
  1247     MVIMPSTEngineSubService* subService =         
       
  1248                 (iEngine.SubService(TVIMPSTEnums::EIM));
       
  1249     RArray<SIMCacheChatItem> openChats;
       
  1250     openChats.Reset();
       
  1251     if(subService)
       
  1252         {
       
  1253         MVIMPSTEngineIMSubService& imSubService = 
       
  1254             MVIMPSTEngineIMSubService::Cast (*subService);
       
  1255         openChats = imSubService.GetOpenChatListL();
       
  1256         }
       
  1257     while( openChats.Count() )
       
  1258         {
       
  1259         SIMCacheChatItem chat = openChats[ 0 ]; // first item 
       
  1260         TPtrC contactId = *chat.iBuddyId;
       
  1261         MVIMPSTProcessArrayItem* arrayItem = FindArrayItem( contactId );
       
  1262         TBool msgPending = EFalse;
       
  1263         if( contactId.Length() )
       
  1264             {
       
  1265             if( IsUnreadMessageExistsL( contactId ) )
       
  1266                 {
       
  1267                 msgPending = ETrue;
       
  1268                 }
       
  1269             }
       
  1270         if( arrayItem )
       
  1271             {
       
  1272             arrayItem->SetConversationOpen( ETrue );
       
  1273             arrayItem->SetMsgPending( msgPending );
       
  1274             }
       
  1275         else
       
  1276             {
       
  1277             // not in buddy List
       
  1278             DoHandleUnKnownContactMessageL( contactId ,msgPending );
       
  1279             }
       
  1280         openChats.Remove( 0 );
       
  1281         delete chat.iBuddyId;
       
  1282         chat.iBuddyId = NULL;
       
  1283         openChats.Compress();
       
  1284         }
       
  1285     }
       
  1286 //-----------------------------------------------------------
       
  1287 //CVIMPSTProcessArray::FindArrayItem
       
  1288 //-----------------------------------------------------------
       
  1289 // 
       
  1290 MVIMPSTProcessArrayItem* CVIMPSTProcessArray::FindArrayItem( const TDesC& aSenderId )
       
  1291     {
       
  1292     TPtrC senderId = VIMPSTUtils::DisplayId( aSenderId );
       
  1293     MVIMPSTProcessArrayItem* arrayItem = NULL;
       
  1294     TInt count = iItemArray.Count();
       
  1295     for( TInt i = 1; i < count; i++ )
       
  1296         {
       
  1297         MVIMPSTProcessArrayItem* contactItem = (MVIMPSTProcessArrayItem *)iItemArray[i];
       
  1298         TPtrC contactId = VIMPSTUtils::DisplayId( contactItem->GetItemUserId() );
       
  1299         if( senderId.Compare(  contactId ) == 0 )
       
  1300             {
       
  1301             arrayItem = contactItem;
       
  1302             break;
       
  1303             }
       
  1304         }
       
  1305     return arrayItem;
       
  1306     }
       
  1307 //-----------------------------------------------------------
       
  1308 //CVIMPSTProcessArray::HandleChatMessageEventL
       
  1309 //-----------------------------------------------------------
       
  1310 // 
       
  1311 void CVIMPSTProcessArray::HandleChatMessageEventL( TVIMPSTEnums::TIMEventType aEventType ,
       
  1312                                                     const TDesC& aSender )
       
  1313     {
       
  1314     if( !iFetchCompleted )
       
  1315         {
       
  1316         // contact matching will not be correct until fetching completed
       
  1317         // hence return 
       
  1318         return;
       
  1319         }
       
  1320     switch( aEventType )
       
  1321         {
       
  1322         case TVIMPSTEnums::EIMUnreadMessage:
       
  1323             {
       
  1324             if( FindAndMarkContactAsOpenChat( aSender , ETrue ) )
       
  1325                 {
       
  1326                 if(iProcessObservers)
       
  1327                     {
       
  1328                     iProcessObservers->HandleAdditionL(TVIMPSTEnums::EContactItem, KErrNotFound );
       
  1329                     }
       
  1330                 }
       
  1331             else 
       
  1332                 {
       
  1333                 DoHandleUnKnownContactMessageL( aSender , ETrue );
       
  1334                 }
       
  1335             break;
       
  1336             }
       
  1337         case TVIMPSTEnums::EIMUnreadChange:
       
  1338             {
       
  1339             FindAndMarkContactAsOpenChat( aSender , EFalse ) ;
       
  1340             if(iProcessObservers)
       
  1341                 {
       
  1342                 iProcessObservers->HandleAdditionL(TVIMPSTEnums::EContactItem,KErrNotFound );
       
  1343                 }
       
  1344             break;
       
  1345             }
       
  1346         case TVIMPSTEnums::EIMChatStarted:
       
  1347             {
       
  1348             if( FindAndMarkContactAsOpenChat( aSender , EFalse ) )
       
  1349                 {
       
  1350                 if(iProcessObservers)
       
  1351                     {
       
  1352                     iProcessObservers->HandleAdditionL(TVIMPSTEnums::EContactItem, KErrNotFound );
       
  1353                     }
       
  1354                 }
       
  1355             else 
       
  1356                 {
       
  1357                 DoHandleUnKnownContactMessageL( aSender, EFalse );
       
  1358                 }
       
  1359             break;
       
  1360             }
       
  1361         case TVIMPSTEnums::EIMChatClosed:
       
  1362             {
       
  1363             if( !RemoveFromUnknonListL( aSender ) )
       
  1364                 {
       
  1365                 MVIMPSTProcessArrayItem* arrayItem = FindArrayItem( aSender );
       
  1366                 if( arrayItem )
       
  1367                     {
       
  1368                     arrayItem->SetConversationOpen( EFalse );
       
  1369                     arrayItem->SetMsgPending( EFalse );
       
  1370                     }
       
  1371                 }
       
  1372             if(iProcessObservers)
       
  1373                 {
       
  1374                 iProcessObservers->HandleAdditionL(TVIMPSTEnums::EContactItem, KErrNotFound );
       
  1375                 }
       
  1376             break;
       
  1377             }
       
  1378         case TVIMPSTEnums::EIMAllChatClosed:
       
  1379             {
       
  1380             RemoveUnKnownContacts();
       
  1381             iUnKnownContactArray.ResetAndDestroy();// delete all items
       
  1382             ResetOpenConversationPendingMsg();
       
  1383             if(iProcessObservers)
       
  1384                 {
       
  1385                 iProcessObservers->HandleAdditionL(TVIMPSTEnums::EContactItem, KErrNotFound );
       
  1386                 }
       
  1387             break;
       
  1388             }
       
  1389         case TVIMPSTEnums::EIMRequestCompleted:
       
  1390             {
       
  1391             if(iProcessObservers)
       
  1392                 {
       
  1393                 iProcessObservers->HandleAdditionL(TVIMPSTEnums::EContactItem, KErrNotFound );
       
  1394                 }
       
  1395             break;
       
  1396             }
       
  1397         default:
       
  1398             {
       
  1399             // do nothing
       
  1400             }
       
  1401         }
       
  1402     }
       
  1403 //-----------------------------------------------------------
       
  1404 //CVIMPSTProcessArray::HandleAddRequestEventL
       
  1405 //-----------------------------------------------------------
       
  1406 // 
       
  1407 void  CVIMPSTProcessArray::HandleAddRequestEventL(TVIMPSTEnums::TOperationType aType, const TDesC& aRequesterId,
       
  1408                                                     const TDesC& aRequestorDisplayName )
       
  1409     {
       
  1410   	//add new add request item at top of list(i.e at index 1, as 0 is own id).
       
  1411     //when request is entertained remove item from list.
       
  1412     switch( aType )
       
  1413 	    {
       
  1414 		case TVIMPSTEnums::EAddItem :
       
  1415 			{
       
  1416 			if( (!FindAnyAddRequest(aRequesterId ) )&& ( !FindAnyContactServiceField( aRequesterId ) ) && !(IsContactBlocked( aRequesterId )) )
       
  1417 				{
       
  1418 				CVIMPSTProcessFriendRequestItem* addRequestItem = CVIMPSTProcessFriendRequestItem::NewL(*this, aRequesterId,aRequestorDisplayName);
       
  1419 				/* Add it as the first Item of IAddRequestARray as its like stack */
       
  1420 				iAddRequestArray.Insert(addRequestItem,0); 
       
  1421 				/*
       
  1422 				*	always the new friend request will be shown in the beginning, so 0th item is own item, 1st item is new friendrequest
       
  1423 				*	and remaining remains same.. 
       
  1424 				*/
       
  1425 				// ownership is in iItemArray
       
  1426 				TInt invitationIndex = iUnKnownContactArray.Count()+1;
       
  1427 				iItemArray.Insert(addRequestItem, invitationIndex); 
       
  1428 				if(iProcessObservers)
       
  1429 					{
       
  1430 					iProcessObservers->HandleAdditionL( TVIMPSTEnums::EFriendRequestItem ,KErrNotFound );
       
  1431 					}
       
  1432 				}
       
  1433 			break;
       
  1434 			}
       
  1435 		case TVIMPSTEnums::ERemoveItem :
       
  1436 			{
       
  1437 			TInt count = iAddRequestArray.Count();
       
  1438 			CVIMPSTProcessFriendRequestItem* requestItem = NULL;
       
  1439 			for(TInt i = 0 ; i < count ; i++)
       
  1440 				{
       
  1441 				requestItem = iAddRequestArray[i];
       
  1442 				if( aRequesterId.Compare(requestItem->GetItemUserId()) == 0 )
       
  1443 					{
       
  1444 					TInt index = iItemArray.Find(requestItem);
       
  1445 					if(index != KErrNotFound)
       
  1446 						{
       
  1447 						iItemArray.Remove(index);
       
  1448 						iItemArray.Compress();
       
  1449 						}
       
  1450 					iAddRequestArray.Remove(i);        
       
  1451 					delete requestItem;
       
  1452 					iAddRequestArray.Compress();
       
  1453 					break;
       
  1454 					}        
       
  1455 				}    
       
  1456 			if(iProcessObservers)
       
  1457 				{
       
  1458 				iProcessObservers->HandleDeletionL(TVIMPSTEnums::EFriendRequestItem, KErrNotFound );
       
  1459 				}
       
  1460 			break;
       
  1461 			} 
       
  1462 		default :
       
  1463 			break;
       
  1464 		}
       
  1465     }
       
  1466 //-----------------------------------------------------------
       
  1467 //CVIMPSTProcessArray::DoHandleUnKnownContactMessageL
       
  1468 //-----------------------------------------------------------
       
  1469 // 
       
  1470 void CVIMPSTProcessArray::DoHandleUnKnownContactMessageL( const TDesC& aSenderId ,TBool aIsMsgPending )
       
  1471     {
       
  1472     TBool contactExist = EFalse ;
       
  1473     TInt count = iUnKnownContactArray.Count();
       
  1474     CVIMPSTProcessUnknownContactItem* unknownItem = NULL;
       
  1475     for( TInt i=0; i<count; i++ )
       
  1476         {
       
  1477         unknownItem = iUnKnownContactArray[i];
       
  1478         if( aSenderId.Compare( unknownItem->GetItemUserId() ) == 0 )
       
  1479             {
       
  1480             contactExist = ETrue;
       
  1481             unknownItem->SetConversationOpen(ETrue);
       
  1482             unknownItem->SetMsgPending( aIsMsgPending );
       
  1483             break;
       
  1484             }
       
  1485         }
       
  1486     if( !contactExist )
       
  1487         {
       
  1488         CVIMPSTProcessUnknownContactItem* addItem = CVIMPSTProcessUnknownContactItem::NewL(*this, aSenderId);
       
  1489         /* Add it as the first Item of IAddRequestARray as its like stack */
       
  1490         iUnKnownContactArray.Insert(addItem,0); 
       
  1491         // ownership is in iItemArray
       
  1492         iItemArray.Insert(addItem, 1);  // just after own Item
       
  1493         addItem->SetMsgPending( aIsMsgPending );
       
  1494         addItem->SetConversationOpen(ETrue);
       
  1495         }
       
  1496     if(iProcessObservers)
       
  1497         {
       
  1498         iProcessObservers->HandleAdditionL( TVIMPSTEnums::EUnknonContactItem ,KErrNotFound );
       
  1499         }
       
  1500     }
       
  1501 //-----------------------------------------------------------
       
  1502 //CVIMPSTProcessArray::IsMsgPending
       
  1503 //-----------------------------------------------------------
       
  1504 // 
       
  1505 TBool CVIMPSTProcessArray::IsMsgPending(TInt aIndex)
       
  1506     {
       
  1507     if( aIndex < iItemArray.Count() && aIndex >= 0 )
       
  1508         {
       
  1509         MVIMPSTProcessArrayItem* item = (MVIMPSTProcessArrayItem *)iItemArray[aIndex];
       
  1510         if(item)
       
  1511             {   
       
  1512             return item->IsMsgPending();
       
  1513             }   
       
  1514         }
       
  1515     return EFalse;
       
  1516     }
       
  1517 
       
  1518 //-----------------------------------------------------------
       
  1519 //CVIMPSTProcessArray::IsConversationExist
       
  1520 //-----------------------------------------------------------
       
  1521 // 
       
  1522 TBool CVIMPSTProcessArray::IsConversationExist(TInt aIndex)
       
  1523     {
       
  1524     if( aIndex < iItemArray.Count() && aIndex >= 0 )
       
  1525         {
       
  1526         MVIMPSTProcessArrayItem* item = (MVIMPSTProcessArrayItem *)iItemArray[aIndex];
       
  1527         if(item)
       
  1528             {   
       
  1529             return item->IsConversationOpen();
       
  1530             }   
       
  1531         }
       
  1532     return EFalse;
       
  1533     }
       
  1534 
       
  1535 //-----------------------------------------------------------
       
  1536 //CVIMPSTProcessArray::ResetPendingMsg
       
  1537 //-----------------------------------------------------------
       
  1538 // 
       
  1539 void CVIMPSTProcessArray::ResetPendingMsg(TInt aIndex)
       
  1540     {
       
  1541     if( aIndex < iItemArray.Count() && aIndex >= 0 )
       
  1542         {
       
  1543         MVIMPSTProcessArrayItem* item = (MVIMPSTProcessArrayItem *)iItemArray[aIndex];
       
  1544         if(item)
       
  1545             {   
       
  1546             item->SetMsgPending( EFalse );
       
  1547             }   
       
  1548         }
       
  1549     }
       
  1550 //-----------------------------------------------------------
       
  1551 //CVIMPSTProcessArray::ResetOpenConversationPendingMsg
       
  1552 //-----------------------------------------------------------
       
  1553 // 
       
  1554 void CVIMPSTProcessArray::ResetOpenConversationPendingMsg()
       
  1555     {
       
  1556     for( TInt index  = 0; index < iItemArray.Count() ;index++ )
       
  1557         {
       
  1558         MVIMPSTProcessArrayItem* item = (MVIMPSTProcessArrayItem *)iItemArray[index];
       
  1559         if(item)
       
  1560             {   
       
  1561             item->SetConversationOpen( EFalse );
       
  1562             item->SetMsgPending( EFalse );
       
  1563             }   
       
  1564         }
       
  1565     }
       
  1566 // -----------------------------------------------------------------------------
       
  1567 // CVIMPSTProcessArray::FindAnyContact
       
  1568 // Try to load with given ID, return NULL if not found.
       
  1569 // -----------------------------------------------------------------------------
       
  1570 TBool CVIMPSTProcessArray::FindAnyContact( const TDesC& aContactId )
       
  1571     {
       
  1572     if(aContactId.Length() != 0)
       
  1573         {
       
  1574         MVIMPSTStorageContact* contact = iContactInterface->FindContactByUserId(aContactId);
       
  1575         if( contact )
       
  1576             {
       
  1577             return ETrue;
       
  1578             }
       
  1579         }
       
  1580     return EFalse;
       
  1581     }
       
  1582 
       
  1583 // -----------------------------------------------------------------------------
       
  1584 // CVIMPSTProcessArray::FindAnyContactServiceField
       
  1585 // Try to load with given ID, return NULL if not found.
       
  1586 // -----------------------------------------------------------------------------
       
  1587 TBool CVIMPSTProcessArray::FindAnyContactServiceField( const TDesC& aContactId )
       
  1588     {
       
  1589     if(aContactId.Length() != 0)
       
  1590         {
       
  1591         MVIMPSTStorageContact* contact = iContactInterface->FindContactByUserId(aContactId);
       
  1592         if( contact )
       
  1593             {
       
  1594             return ETrue;
       
  1595             }
       
  1596         }
       
  1597     return EFalse;
       
  1598     }
       
  1599 // -----------------------------------------------------------------------------
       
  1600 // CVIMPSTProcessArray::FindAndMarkContactAsOpenChat
       
  1601 // Try to load with given ID, return NULL if not found.
       
  1602 // -----------------------------------------------------------------------------
       
  1603 TBool CVIMPSTProcessArray::FindAndMarkContactAsOpenChat( const TDesC& aContactId, TBool aMesssagePending )
       
  1604     {
       
  1605     TPtrC senderId = VIMPSTUtils::DisplayId( aContactId );
       
  1606     TBool ret = EFalse;
       
  1607     TInt count = iItemArray.Count();
       
  1608     for( TInt i = 1; i < count; i++ )
       
  1609         {
       
  1610         MVIMPSTProcessArrayItem* contactItem = (MVIMPSTProcessArrayItem *)iItemArray[i];
       
  1611         TPtrC contactId = VIMPSTUtils::DisplayId( contactItem->GetItemUserId() );
       
  1612         if( senderId.Compare(  contactId ) == 0 )
       
  1613             {
       
  1614             contactItem->SetConversationOpen( ETrue );
       
  1615             contactItem->SetMsgPending( aMesssagePending );
       
  1616             ret = ETrue;
       
  1617             break;
       
  1618             }
       
  1619         }
       
  1620     return ret;
       
  1621     }
       
  1622 //-----------------------------------------------------------------------------
       
  1623 // CVIMPSTProcessArray::IsUnreadMessageExists
       
  1624 // ( Other items commented in header )
       
  1625 //-----------------------------------------------------------------------------    
       
  1626 TBool CVIMPSTProcessArray::IsUnreadMessageExistsL(const TDesC& aRecipientId) 
       
  1627     {
       
  1628     TBool ret = EFalse;
       
  1629     TInt unreaMsgCount = KErrNone;
       
  1630     //Get IM SubService     
       
  1631     MVIMPSTEngineSubService* subService =         
       
  1632             (iEngine.SubService(TVIMPSTEnums::EIM));
       
  1633     if(subService)
       
  1634         {
       
  1635         MVIMPSTEngineIMSubService& imSubService = 
       
  1636         MVIMPSTEngineIMSubService::Cast (*subService);
       
  1637         unreaMsgCount = imSubService.GetUnreadCountL( aRecipientId );
       
  1638         }
       
  1639     if( unreaMsgCount )
       
  1640         {
       
  1641         ret = ETrue;
       
  1642         }
       
  1643     return ret; 
       
  1644     }
       
  1645 //-----------------------------------------------------------------------------
       
  1646 // CVIMPSTProcessArray::IsConversationExistL
       
  1647 // ( Other items commented in header )
       
  1648 //-----------------------------------------------------------------------------    
       
  1649 TBool CVIMPSTProcessArray::IsConversationExistL(const TDesC& aRecipientId) 
       
  1650     {
       
  1651     //Get IM SubService     
       
  1652     MVIMPSTEngineSubService* subService1 =    	   
       
  1653                 (iEngine.SubService(TVIMPSTEnums::EIM));
       
  1654     if(subService1)
       
  1655         {
       
  1656         MVIMPSTEngineIMSubService& imSubService = 
       
  1657                     MVIMPSTEngineIMSubService::Cast (*subService1);
       
  1658         return imSubService.IsConversationExistL( aRecipientId );
       
  1659         }
       
  1660     return EFalse; 
       
  1661     }
       
  1662 //-----------------------------------------------------------------------------
       
  1663 // CVIMPSTProcessArray::FindContactIndexL
       
  1664 // ( Other items commented in header )
       
  1665 //-----------------------------------------------------------------------------    
       
  1666 TInt CVIMPSTProcessArray::FindContactIndexL( const TDesC& aContactId )
       
  1667     {
       
  1668     MVIMPSTStorageContact* newContact = iContactInterface->FindContactByUserId( aContactId );
       
  1669     if(newContact)
       
  1670         {
       
  1671         // return the index of contact rather bool value..
       
  1672         // 1 is for own data item.
       
  1673         return (iContactListIndex + 1 + iContactListModel->IndexOfContact( newContact ));
       
  1674         }
       
  1675     return KErrNotFound;
       
  1676     }
       
  1677 
       
  1678 
       
  1679 //-----------------------------------------------------------------------------
       
  1680 // CVIMPSTProcessArray::FillUnknownContactsL
       
  1681 // ( Other items commented in header )
       
  1682 //------------------------------------------------------------------------------
       
  1683 void CVIMPSTProcessArray::FillUnknownContactsL()
       
  1684     {
       
  1685     TInt count = iUnKnownContactArray.Count();
       
  1686     /* 
       
  1687      * Index = 1 cos 0th index will be OwnData, and 1 - n where n is the number of friend requests, will be friend requests 
       
  1688      */
       
  1689     TInt index = 1; 
       
  1690     for(TInt i = 0 ; i < count ; i++)
       
  1691         {
       
  1692         // all friend request item ownership is transfered to iItemArray
       
  1693         CVIMPSTProcessUnknownContactItem* unknownItem = iUnKnownContactArray[i];
       
  1694         unknownItem->SetItemIndex(index);        
       
  1695         iItemArray.Insert(unknownItem, index);        
       
  1696         index ++;
       
  1697         }
       
  1698     }
       
  1699 
       
  1700 //-----------------------------------------------------------------------------
       
  1701 // CVIMPSTProcessArray::FillAddRequestDataL
       
  1702 // ( Other items commented in header )
       
  1703 //------------------------------------------------------------------------------
       
  1704 void CVIMPSTProcessArray::FillAddRequestDataL()
       
  1705     {
       
  1706     TInt count = iAddRequestArray.Count();
       
  1707 	/* 
       
  1708 	 * Index = unknowncontacts are tops so after that 1 cos 0th index will be OwnData, and 1 - n where n is the number of friend requests, will be friend requests 
       
  1709 	 */
       
  1710 	TInt index = iUnKnownContactArray.Count() +1 ; 
       
  1711     for(TInt i = 0 ; i < count ; i++)
       
  1712         {
       
  1713         // all friend request item ownership is transfered to iItemArray
       
  1714         CVIMPSTProcessFriendRequestItem* requestItem = iAddRequestArray[i];
       
  1715         requestItem->SetItemIndex(index );        
       
  1716         iItemArray.Insert(requestItem, index);        
       
  1717 		index ++;
       
  1718         }
       
  1719     }
       
  1720 
       
  1721 //-----------------------------------------------------------------------------
       
  1722 // CVIMPSTProcessArray::RemoveUnKnownContacts
       
  1723 // ( Other items commented in header )
       
  1724 //------------------------------------------------------------------------------
       
  1725 void CVIMPSTProcessArray::RemoveUnKnownContacts()
       
  1726     {
       
  1727     TInt count = iUnKnownContactArray.Count();
       
  1728     for(TInt i = 0 ; i < count ; i++)
       
  1729         {
       
  1730         CVIMPSTProcessUnknownContactItem* unknownItem = iUnKnownContactArray[i];
       
  1731         TInt index = iItemArray.Find(unknownItem);
       
  1732         if(index > -1)
       
  1733             {            
       
  1734             iItemArray.Remove(index);
       
  1735             iItemArray.Compress();
       
  1736             }       
       
  1737         }
       
  1738     }
       
  1739 //-----------------------------------------------------------------------------
       
  1740 // CVIMPSTProcessArray::RemoveAddRequestData
       
  1741 // ( Other items commented in header )
       
  1742 //------------------------------------------------------------------------------
       
  1743 void CVIMPSTProcessArray::RemoveAddRequestData()
       
  1744     {
       
  1745     TInt count = iAddRequestArray.Count();
       
  1746     for(TInt i = 0 ; i < count ; i++)
       
  1747         {
       
  1748         CVIMPSTProcessFriendRequestItem* requestItem = iAddRequestArray[i];
       
  1749         TInt index = iItemArray.Find(requestItem);
       
  1750         if(index > -1)
       
  1751             {            
       
  1752             iItemArray.Remove(index);
       
  1753             iItemArray.Compress();
       
  1754             }       
       
  1755         }
       
  1756     
       
  1757     }
       
  1758 //-----------------------------------------------------------------------------
       
  1759 // CVIMPSTProcessArray::LoginUserIdFromStoreL
       
  1760 // ( Other items commented in header )
       
  1761 //------------------------------------------------------------------------------
       
  1762 
       
  1763 const TDesC& CVIMPSTProcessArray::LoginUserIdFromStoreL() const
       
  1764     {
       
  1765     if( iContactInterface )
       
  1766 		{
       
  1767 		// most of the time this get called 
       
  1768 		return iContactInterface->OwnContactL().UserId();
       
  1769 		}
       
  1770     return KNullDesC;
       
  1771     }
       
  1772 
       
  1773 //-----------------------------------------------------------------------------
       
  1774 // CVIMPSTProcessArray::AvatarIndex
       
  1775 // ( Other items commented in header )
       
  1776 //------------------------------------------------------------------------------
       
  1777 
       
  1778 TInt CVIMPSTProcessArray::AvatarIndex(TInt aContactIndex)
       
  1779     {
       
  1780     TVIMPSTEnums::TItem itemtype = GetType( aContactIndex );
       
  1781     /* Codescanner warning is ignored, since Bound check is done 
       
  1782      * inside the GetType()   method*/
       
  1783 
       
  1784     if( TVIMPSTEnums::EContactItem == itemtype )
       
  1785         {
       
  1786        // if the type is a contact item then return the index
       
  1787         MVIMPSTStorageContact* contact = iContactInterface->FindContactByUserId( GetItemUserId(aContactIndex) );
       
  1788         if(contact)
       
  1789             {
       
  1790             // if any contact is found then return the index
       
  1791             return contact->AvatarIndex();
       
  1792             }
       
  1793         }
       
  1794     return KErrNone;
       
  1795     }
       
  1796 //-----------------------------------------------------------------------------
       
  1797 // CVIMPSTProcessArray::SetAvatarIndex
       
  1798 // ( Other items commented in header )
       
  1799 //------------------------------------------------------------------------------
       
  1800 
       
  1801 void CVIMPSTProcessArray::SetAvatarIndex( TInt aContactIndex ,TInt aAvatarIndex )
       
  1802     {
       
  1803     TVIMPSTEnums::TItem itemtype = GetType( aContactIndex );
       
  1804     if( TVIMPSTEnums::EContactItem == itemtype )
       
  1805         {
       
  1806         // if the type is a contact item then set the index 
       
  1807         MVIMPSTStorageContact* contact = iContactInterface->FindContactByUserId(GetItemUserId(aContactIndex));
       
  1808         if(contact)
       
  1809             {
       
  1810             // if any contact is found then set the index
       
  1811             contact->SetAvatarIndex( aAvatarIndex );
       
  1812             }           
       
  1813             
       
  1814         iItemArray[aContactIndex]->SetAvatarIndex(aAvatarIndex);
       
  1815         }
       
  1816 
       
  1817     }
       
  1818 
       
  1819 //-----------------------------------------------------------------------------
       
  1820 // CVIMPSTProcessArray::AvatarContent
       
  1821 // ( Other items commented in header )
       
  1822 //------------------------------------------------------------------------------
       
  1823 
       
  1824 const TDesC8& CVIMPSTProcessArray::AvatarContent(TInt aContactIndex)
       
  1825     {   
       
  1826     TVIMPSTEnums::TItem itemtype = GetType( aContactIndex );
       
  1827 
       
  1828     if(  itemtype == TVIMPSTEnums::EContactItem )
       
  1829         {
       
  1830         // if the type is a contact item then get the avatar content from strorage
       
  1831         MVIMPSTStorageContact* contact = iContactInterface->FindContactByUserId(GetItemUserId(aContactIndex));
       
  1832         if(contact)
       
  1833             {
       
  1834             // if any contact is found then get the content
       
  1835             return contact->AvatarContent();
       
  1836             }
       
  1837         }
       
  1838     return KNullDesC8();
       
  1839     }
       
  1840 //-----------------------------------------------------------------------------
       
  1841 // CVIMPSTProcessArray::OwnAvatarContentL
       
  1842 // ( Other items commented in header )
       
  1843 //------------------------------------------------------------------------------
       
  1844 
       
  1845 const TDesC8& CVIMPSTProcessArray::OwnAvatarContentL( ) const
       
  1846 	{   
       
  1847     MVIMPSTStorageContact& contact = iContactInterface->OwnContactL();             
       
  1848     // if any contact is found then get the content
       
  1849     return contact.AvatarContent();
       
  1850 	}
       
  1851 //-----------------------------------------------------------------------------
       
  1852 // CVIMPSTProcessArray::OwnAvatarIndexL
       
  1853 // ( Other items commented in header )
       
  1854 //------------------------------------------------------------------------------
       
  1855 
       
  1856 TInt CVIMPSTProcessArray::OwnAvatarIndexL( )
       
  1857     {
       
  1858     MVIMPSTStorageContact& contact = iContactInterface->OwnContactL();  
       
  1859     return contact.AvatarIndex();           
       
  1860     }
       
  1861 //-----------------------------------------------------------------------------
       
  1862 // CVIMPSTProcessArray::SetOwnAvatarIndexL
       
  1863 // ( Other items commented in header )
       
  1864 //------------------------------------------------------------------------------
       
  1865 
       
  1866 void CVIMPSTProcessArray::SetOwnAvatarIndexL( TInt aAvatarIndex )
       
  1867     {
       
  1868     MVIMPSTStorageContact& contact = iContactInterface->OwnContactL();             
       
  1869     contact.SetAvatarIndex( aAvatarIndex );
       
  1870     }
       
  1871 
       
  1872 //-----------------------------------------------------------------------------
       
  1873 // CVIMPSTProcessArray::FindAnyAddRequest
       
  1874 // ( Other items commented in header )
       
  1875 //------------------------------------------------------------------------------
       
  1876 
       
  1877 TInt CVIMPSTProcessArray::FindAnyAddRequest( const TDesC& aRequesterId )
       
  1878     {
       
  1879     TInt count = iAddRequestArray.Count();
       
  1880     for(TInt i=0; i<count; i++)
       
  1881         {   
       
  1882         if((aRequesterId.Compare(iAddRequestArray[i]->GetItemUserId()))==0 )                
       
  1883             {
       
  1884             return ETrue;
       
  1885             }
       
  1886         }
       
  1887     return EFalse;
       
  1888     }
       
  1889 
       
  1890 // -----------------------------------------------------------------------------
       
  1891 // CVIMPSTProcessArray::GetSelectedItemIndex
       
  1892 // return contact index including friend request.
       
  1893 // -----------------------------------------------------------------------------
       
  1894 TInt CVIMPSTProcessArray::GetSelectedItemIndex(const TDesC& aContactId) 
       
  1895 	{
       
  1896 	TInt itemArrayCount = iItemArray.Count();
       
  1897 	for(TInt index=0; index<itemArrayCount; index++)
       
  1898 		{
       
  1899 		MVIMPSTProcessArrayItem* item = iItemArray[ index ];
       
  1900 		if(0 == aContactId.Compare(item->GetItemUserId()))
       
  1901 		    {
       
  1902 		    return index; 
       
  1903 		    }
       
  1904 		}
       
  1905 	return KErrNotFound;
       
  1906 	}
       
  1907 
       
  1908 // --------------------------------------------------------------------------
       
  1909 // CVIMPSTProcessArray::IsContactBlocked
       
  1910 // --------------------------------------------------------------------------
       
  1911 TBool CVIMPSTProcessArray::IsContactBlocked(const TDesC& aUserId)
       
  1912     {
       
  1913     MVIMPSTEngineSubService* subService =          
       
  1914                         (iEngine.SubService(TVIMPSTEnums::EPresence));
       
  1915     if(subService)
       
  1916         {
       
  1917         MVIMPSTEnginePresenceSubService& presence = 
       
  1918                 MVIMPSTEnginePresenceSubService::Cast (*subService);
       
  1919                 
       
  1920         RPointerArray<HBufC> *blockedlist = presence .GetBlockedList();
       
  1921         
       
  1922         if(blockedlist)
       
  1923             {
       
  1924             for(TInt i=0; i<blockedlist->Count(); ++i)
       
  1925                 {
       
  1926                 if(0 == aUserId.CompareC((*blockedlist)[i]->Des()))
       
  1927                     {
       
  1928                     return ETrue;
       
  1929                     }
       
  1930                 }
       
  1931             }
       
  1932         }
       
  1933     return EFalse;  
       
  1934     }       
       
  1935 
       
  1936 
       
  1937 // --------------------------------------------------------------------------
       
  1938 // CVIMPSTProcessArray::GetFormattedString
       
  1939 // --------------------------------------------------------------------------
       
  1940 TPtrC16 CVIMPSTProcessArray::GetFormattedString(TInt aIndex)
       
  1941     {
       
  1942     if((aIndex >= 0) && (aIndex< iItemArray.Count()))
       
  1943         return iItemArray[aIndex]->FormattedItemString();
       
  1944     else
       
  1945         return KNullDesC();
       
  1946     }
       
  1947 
       
  1948 //END OF FILE