uiservicetab/vimpstcmdprocess/src/cvimpstprocessArray.cpp
branchRCL_3
changeset 11 bef90b82da71
parent 0 5e5d6b214f4f
child 14 9fdee5e1da30
equal deleted inserted replaced
10:78867dafe7eb 11:bef90b82da71
    20 #include <coemain.h>
    20 #include <coemain.h>
    21 #include    "vimpstdebugprint.h" 
    21 #include    "vimpstdebugprint.h" 
    22 
    22 
    23 #include "cvimpstprocessarray.h"
    23 #include "cvimpstprocessarray.h"
    24 
    24 
    25 #include "mvimpstprocessarrayobserver.h"
    25 #include "mvimpstprocessArrayobserver.h"
    26 #include "cvimpststoragemanagerfactory.h"
    26 #include "cvimpststoragemanagerfactory.h"
    27 #include "mvimpststorageserviceview.h"
    27 #include "mvimpststorageserviceview.h"
    28 #include "TVIMPSTEnums.h"
    28 #include "tvimpstenums.h"
    29 #include "cvimpstprocessarrayitem.h"
    29 #include "cvimpstprocessarrayitem.h"
    30 #include "mvimpststorageitemmodel.h"
    30 #include "mvimpststorageitemmodel.h"
    31 #include "tvimpstconsts.h"
    31 #include "tvimpstconsts.h"
    32 #include "mvimpststoragecontactlist.h"
    32 #include "mvimpststoragecontactlist.h"
    33 #include "mvimpststoragevpbkstorehandler.h"
    33 #include "mvimpststoragevpbkstorehandler.h"
    34 #include "mvimpstengine.h"
    34 #include "mvimpstengine.h"
    35 #include "cvimpstprocessfriendrequestitem.h"
    35 #include "cvimpstprocessfriendrequestitem.h"
    36 #include "mvimpstenginesubservice.h"
    36 #include "mvimpstenginesubservice.h"
    37 #include <mvpbkfieldtype.h>
    37 #include <MVPbkFieldType.h>
    38 #include <mvpbkcontactfielduridata.h>
    38 #include <MVPbkContactFieldUriData.h>
    39 #include <MVPbkContactFieldTextData.h>
    39 #include <MVPbkContactFieldTextData.h>
    40 //rsg file for resource id
    40 //rsg file for resource id
    41 #include <vimpstuires.rsg>
    41 #include <vimpstuires.rsg>
    42 #include "vimpstutils.h"
    42 #include "vimpstutils.h"
    43 #include <mvpbkcontactlink.h>
    43 #include <MVPbkContactLink.h>
    44 #include <vpbkeng.rsg>
    44 #include <VPbkEng.rsg>
    45 #include "mvimpstengineimsubservice.h"
    45 #include "mvimpstengineimsubservice.h"
    46 #include "mvimpstenginepresencesubservice.h"
    46 #include "mvimpstenginepresencesubservice.h"
    47 #include "vimpstdebugtrace.h"
    47 #include "vimpstdebugtrace.h"
    48 #include <APGTASK.H> 
    48 #include <apgtask.h> 
    49 #include "imcvuiparams.h"
    49 #include "imcvuiparams.h"
    50 
    50 
    51 // --------------------------------------------------------------------------
    51 // --------------------------------------------------------------------------
    52 // CVIMPSTProcessArray::CIMArrayProcess
    52 // CVIMPSTProcessArray::CIMArrayProcess
    53 // --------------------------------------------------------------------------
    53 // --------------------------------------------------------------------------
   134     TRACE( T_LIT("CVIMPSTProcessArray::ConstructL Start") );
   134     TRACE( T_LIT("CVIMPSTProcessArray::ConstructL Start") );
   135     iContactInterface = CVIMPSTStorageManagerFactory::ContactListInterfaceL(iServiceId);
   135     iContactInterface = CVIMPSTStorageManagerFactory::ContactListInterfaceL(iServiceId);
   136     if(iContactInterface)
   136     if(iContactInterface)
   137         {        
   137         {        
   138         iContactInterface->AddObserverL( this );// listen these events..        
   138         iContactInterface->AddObserverL( this );// listen these events..        
   139         }
   139         HBufC* unnamed = VIMPSTUtils::LoadResourceL( R_SERVTAB_UNNAMED );
   140     HBufC* unnamed = VIMPSTUtils::LoadResourceL( R_SERVTAB_UNNAMED );
   140         if( unnamed )
   141     if( unnamed )
   141             {
   142 	    {
   142             CleanupStack::PushL( unnamed );
   143 	    CleanupStack::PushL( unnamed );
   143             iContactInterface->SetUnnamedTextL(unnamed); // takes ownership
   144 	    iContactInterface->SetUnnamedTextL(unnamed); // takes ownership
   144             CleanupStack::Pop( unnamed );	
   145 	    CleanupStack::Pop( unnamed );	
   145             }
   146 	    }
   146         }
   147     iContactListModel = CVIMPSTStorageManagerFactory::ItemModelInterfaceL(iServiceId);
   147     iContactListModel = CVIMPSTStorageManagerFactory::ItemModelInterfaceL(iServiceId);
   148     iLoginState = iEngine.ServiceState();
   148     iLoginState = iEngine.ServiceState();
   149     
   149     
   150     iIMSupported = EFalse;
   150     iIMSupported = EFalse;
   151     iPresenceSupported = EFalse;
   151     iPresenceSupported = EFalse;
   492 	        // display name is changed ,might be contact is re-arranged
   492 	        // display name is changed ,might be contact is re-arranged
   493             TRACE( T_LIT("contactindex = %d"),aContactIndex );
   493             TRACE( T_LIT("contactindex = %d"),aContactIndex );
   494             TRACE( T_LIT("itemarraycount = %d"),iItemArray.Count() );
   494             TRACE( T_LIT("itemarraycount = %d"),iItemArray.Count() );
   495             if( aContactIndex < iItemArray.Count() )
   495             if( aContactIndex < iItemArray.Count() )
   496                 {
   496                 {
   497                 CVIMPSTProcessContactItem* newItem = CVIMPSTProcessContactItem::NewL(*this, const_cast<TDesC&>(aContact->Name() ),
   497                 if ( aContact )
   498                         const_cast<TDesC&>(aContact->UserId() ),
   498                      {
   499                         aContact->ContactLink(),
   499                     CVIMPSTProcessContactItem* newItem = CVIMPSTProcessContactItem::NewL(*this, const_cast<TDesC&>(aContact->Name() ),
   500                         const_cast<TDesC&>(aContact->StatusText()),
   500                             const_cast<TDesC&>(aContact->UserId() ),
   501                         aContact->OnlineStatus() );
   501                             aContact->ContactLink(),
       
   502                             const_cast<TDesC&>(aContact->StatusText()),
       
   503                             aContact->OnlineStatus() );
       
   504                     
       
   505                     
       
   506                     MVIMPSTProcessArrayItem* oldItem = iItemArray[ aContactIndex ];
       
   507                     newItem->SetAvatarIndex(aContact->AvatarIndex()); // copy the avatar index too.
       
   508                     TRACE( T_LIT("contact removed in item array of index = %d"),aContactIndex );
       
   509                     // set the conversation open flag from old contact, as only the display name would have changed.
       
   510                     newItem->SetConversationOpen(oldItem->IsConversationOpen());
       
   511                     newItem->SetMsgPending( oldItem->IsMsgPending() );
       
   512                     iItemArray.Remove(aContactIndex );
       
   513                     delete oldItem;
       
   514                     iItemArray.Compress();
       
   515                     TRACE( T_LIT("Insert at index = %d"), aContactIndex);
       
   516                     TInt newIndex = iContactListModel->IndexOfContact( aContact );
       
   517                      // Add it in the new index
       
   518                     newIndex = newIndex + 1 + iUnKnownContactArray.Count() + iAddRequestArray.Count();
       
   519                     if (newIndex >= iItemArray.Count())
       
   520                         {
       
   521                         TRACE( T_LIT("append contact item = %d"), newIndex);
       
   522                         iItemArray.Append (newItem);
       
   523                         }
       
   524                     else
       
   525                         {
       
   526                         TRACE( T_LIT("Insert at index = %d"), newItem);
       
   527                         iItemArray.Insert(newItem, newIndex);
       
   528                         } 
       
   529                     // inform the cv about the display name changes
       
   530                     if(aContact && aContact->UserId().Length() && newItem->IsConversationOpen())
       
   531                         {
       
   532                         TRACE( T_LIT("CVIMPSTProcessArray::HandleStorageChangeL EStorageEventContactChange "));
       
   533                         TApaTaskList taskList( CCoeEnv::Static()->WsSession() );
       
   534                         TApaTask task( taskList.FindApp( KConversationViewAppUid ) );
       
   535                     
       
   536                         if ( task.Exists() )
       
   537                             {
       
   538                             TRACE( T_LIT("CVIMPSTProcessArray::HandleStorageChangeL EStorageEventContactChange:task exists"));
       
   539                             // packing of data ,passed to conversation view
       
   540                             TPckgBuf< TIMCVUiParams > params;
       
   541                             params().iBuddyId = aContact->UserId();
       
   542                             params().iBuddyName = aContact->Name();
       
   543                             params().iServiceId = iServiceId;
       
   544                             params().iUpdate = ETrue;
       
   545                             task.SendMessage( 
       
   546                                     TUid::Uid( KUidApaMessageSwitchOpenFileValue ), params );
       
   547                             }
       
   548                         }
       
   549                     } 
   502                 
   550                 
   503                 
   551               }
   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 )
   552             if(iProcessObservers )
   549                 {
   553                 {
   550                 iProcessObservers->HandleAdditionL(TVIMPSTEnums::EContactItem, aContactIndex );
   554                 iProcessObservers->HandleAdditionL(TVIMPSTEnums::EContactItem, aContactIndex );
   551                 }
   555                 }
   552             TRACE( T_LIT("CVIMPSTProcessArray::HandleStorageChangeL EStorageEventContactChange End") );
   556             TRACE( T_LIT("CVIMPSTProcessArray::HandleStorageChangeL EStorageEventContactChange End") );