wvuing/wvuiprocess/Src/CCAMainViewArrayPC.cpp
changeset 0 094583676ce7
equal deleted inserted replaced
-1:000000000000 0:094583676ce7
       
     1 /*
       
     2 * Copyright (c) 2006 Nokia Corporation and/or its subsidiary(-ies). 
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description:  Main view array interface to get  the array items to be displayed
       
    15 				 via the listbox for the Single View
       
    16 *
       
    17 */
       
    18 
       
    19 
       
    20 //platform includes
       
    21 #include <aknview.h>
       
    22 #include <eiklbo.h>
       
    23 #include <badesca.h>
       
    24 #include <bldvariant.hrh>
       
    25 #include <e32cmn.h>
       
    26 #include <e32def.h>
       
    27 #include <aknenv.h>
       
    28 #include <StringLoader.h>
       
    29 #include <barsread.h>
       
    30 #include <chatNG.rsg>
       
    31 #include <collate.h>
       
    32 
       
    33 
       
    34 #include "ImpsCSPAllErrors.h"
       
    35 #include "chatdefinitions.h"
       
    36 #include "ChatDebugPrint.h"
       
    37 #include "CCAArrayItemPC.h"
       
    38 #include "MCAStoredContacts.h"
       
    39 #include "MCAContactLists.h"
       
    40 #include "MCAContactList.h"
       
    41 #include "ChatDebugAssert.h"
       
    42 #include "MCAStoredContactsObserver.h"
       
    43 #include "CCAStorageManagerFactory.h"
       
    44 #include "MCASettingsObserver.h"
       
    45 #include "CAPresenceManager.h"
       
    46 #include "MCAChatInterface.h"
       
    47 #include "IMUtils.h"
       
    48 #include "CCAMainViewArrayPC.h"
       
    49 #include "MCAMessageContainerInfo.h"
       
    50 
       
    51 #include <cimpspresenceconnectionuing.h>
       
    52 #include <CIMPSSAPSettingsStore.h>
       
    53 #include <CIMPSSAPSettings.h>
       
    54 #include <CPEngNWSessionSlotID2.h>
       
    55 
       
    56 #include "CCAPCUtils.h"
       
    57 #include "PublicEngineDefinitions.h"
       
    58 #include "CCAEngine.h"
       
    59 #include "MCAInvite.h"
       
    60 #include "MCAInvitation.h"
       
    61 #include "ChatDebugPrint.h"
       
    62 #include "CCAServerContactsArrayPC.h"
       
    63 
       
    64 #include "MCAStoredContact.h"
       
    65 #include "MCAStoredGroups.h"
       
    66 #include "MCAStoredGroup.h"
       
    67 #include "MCASingleListViewCB.h"
       
    68 #include "CAUtils.h"
       
    69 #include "MCAMessage.h"
       
    70 #include "CCAGroupListArrayPC.h"
       
    71 
       
    72 // The Settings have been moved to Cenrep (also retained in the Resource file),
       
    73 // so the enums for keys and central repository header is added here
       
    74 #include 	"VariantKeys.h"
       
    75 #include "MCABlocking.h"
       
    76 
       
    77 const TInt KGranularity = 2;    //array granularity
       
    78 
       
    79 _LIT( KContactOnlineIconA,      "12\t" );
       
    80 _LIT( KEmptyIconB,              "11\t" );
       
    81 _LIT( KContactWatcherIcon,      "\t2" );
       
    82 #ifdef RD_MESSAGE_INDICATION_NEW
       
    83 _LIT( KContactMsgPendingIcon,   "3\t" );
       
    84 #else
       
    85 _LIT( KContactMsgPendingIcon,   "\t3" );
       
    86 #endif
       
    87 
       
    88 // ============================ MEMBER FUNCTIONS ===============================
       
    89 
       
    90 // -----------------------------------------------------------------------------
       
    91 // CCAMainViewArrayPC::CCAMainViewArrayPC
       
    92 // -----------------------------------------------------------------------------
       
    93 
       
    94 CCAMainViewArrayPC::CCAMainViewArrayPC( CCAEngine& aEngine, MCAContactListModel& aContactListModel,
       
    95                                         MCAChatInterface& aChatInterface )
       
    96         : iEngine( aEngine ),
       
    97         iContactListModel( aContactListModel ),
       
    98         iChatInterface( aChatInterface ),
       
    99         iInviteInterface( *iEngine.GetInvitationInterface() ),
       
   100         iOwnDataIndex( KOwnDataIndex ),	//	starting index of Owndata, it's 0 as per ui spec
       
   101         iOpenChatsIndex( KOpenChatsIndex ),//	starting index of OpenChats, it's 1 as per ui spec
       
   102         iContactListIndex( KOwnDataIndex ),	//	starting index of all the contactlists......
       
   103         iOpenChatListItemExpanded( EFalse ),// initially the convesation in collapsed state..
       
   104         iSelectionMode( /*EFalse*/TEnumsPC::ESingleListViewSelect ),
       
   105         iExpandAll( EFalse ),
       
   106         iSettings( aEngine.GetInternalSettingsInterface() )
       
   107 // inializing the settings
       
   108     {
       
   109 
       
   110     iGroupCountDown = EFalse;
       
   111     iOnlySavedGroups = 0;
       
   112 
       
   113     iForceExpandDone = ETrue; // set this to false initially
       
   114     iPToPChatCount = 0;
       
   115     iItemDetails.aItemID.Copy( KNullDesC );
       
   116     iItemDetails.aItemID.Copy( KNullDesC );
       
   117     iItemDetails.aItem = TEnumsPC::EInvalid;
       
   118     }
       
   119 
       
   120 // -----------------------------------------------------------------------------
       
   121 // CCAMainViewArrayPC::NewL
       
   122 // -----------------------------------------------------------------------------
       
   123 
       
   124 CCAMainViewArrayPC* CCAMainViewArrayPC::NewL( CCAEngine& aEngine,
       
   125                                               MCAContactListModel& aContactListModel,
       
   126                                               MCAChatInterface& aChatInterface )
       
   127     {
       
   128     CCAMainViewArrayPC* self = new ( ELeave ) CCAMainViewArrayPC( aEngine,
       
   129                                                                   aContactListModel,
       
   130                                                                   aChatInterface );
       
   131     CleanupStack::PushL( self );
       
   132     self->ConstructL();
       
   133     CleanupStack::Pop( self );
       
   134     return self;
       
   135     }
       
   136 
       
   137 // -----------------------------------------------------------------------------
       
   138 // CCAMainViewArrayPC::ConstructL
       
   139 // -----------------------------------------------------------------------------
       
   140 void CCAMainViewArrayPC::ConstructL()
       
   141     {
       
   142     iMaxLengthOfIcons =
       
   143         KEmptyIconB().Length() + // longest B-column icon
       
   144         KContactOnlineIconA().Length() + // longest A-Column icon
       
   145         KContactWatcherIcon().Length() +
       
   146         KContactMsgPendingIcon().Length();
       
   147     iData = HBufC::NewL( KFriendsListMaxIdentificationLength );
       
   148     iContactInterface = CCAStorageManagerFactory::ContactListInterfaceL();
       
   149     iContactInterface->AddObserverL( this );// listen these events..
       
   150     CAPresenceManager::InstanceL()->SetWatcherObserver( this );
       
   151     iOwnDataAdded = false;
       
   152 
       
   153     iEngine.GetInvitationInterface()->AddInviteObserver( this );
       
   154 
       
   155     iSettings->AddObserverL( this );  //register with engine
       
   156     // Register this as chat observer
       
   157     iChatInterface.RegisterChatObserver( this );
       
   158 
       
   159     // This callback is required when ever the server is added or deleted
       
   160     // we get a callback and update the singlelist
       
   161 
       
   162     iSAPSettingsStore = CIMPSSAPSettingsStore::NewL();
       
   163     iSAPSettingsStore->AddObserverL( this, EIMPSIMAccessGroup );
       
   164     iGroupArray =  CCAGroupListArrayPC::NewL();
       
   165     //register for stored groups observer event
       
   166     iChatGroups = CCAStorageManagerFactory::GroupListInterfaceL();
       
   167     iChatGroups->AddObserverL( this );
       
   168     iLastloggedinUserId = NULL;
       
   169     iConnectionUI = CIMPSPresenceConnectionUi::NewL( EIMPSConnClientIM );
       
   170 
       
   171     }
       
   172 
       
   173 // -----------------------------------------------------------------------------
       
   174 // CCAMainViewArrayPC::SetSkipStorageEvents
       
   175 // -----------------------------------------------------------------------------
       
   176 
       
   177 void CCAMainViewArrayPC::SetSkipStorageEvents( TBool aSkip )
       
   178     {
       
   179     iSkipStorageEvents = aSkip;
       
   180     }
       
   181 
       
   182 // -----------------------------------------------------------------------------
       
   183 // CCAMainViewArrayPC::GetSkipStorageEvents
       
   184 // -----------------------------------------------------------------------------
       
   185 
       
   186 TBool CCAMainViewArrayPC::GetSkipStorageEvents()
       
   187     {
       
   188     return iSkipStorageEvents;
       
   189     }
       
   190 
       
   191 // -----------------------------------------------------------------------------
       
   192 // CCAMainViewArrayPC::~CCAMainViewArrayPC
       
   193 // -----------------------------------------------------------------------------
       
   194 
       
   195 CCAMainViewArrayPC::~CCAMainViewArrayPC()
       
   196     {
       
   197     delete iData;
       
   198     //ignore codescanner warning
       
   199     // because dest is getting called
       
   200     MCAPresence* presenceManager = NULL;
       
   201     TRAP_IGNORE( presenceManager = CAPresenceManager::InstanceL() );
       
   202     if ( presenceManager )
       
   203         {
       
   204         presenceManager->SetWatcherObserver( NULL );
       
   205         }
       
   206     iChatInterface.UnregisterChatObserver( this );
       
   207     iMainViewListItemArray.ResetAndDestroy();
       
   208     iMainViewListItemArray.Close();
       
   209     iOpenChatsArray.ResetAndDestroy();
       
   210     iOpenChatsArray.Close();
       
   211     iMainViewObservers.ResetAndDestroy();
       
   212     iMainViewObservers.Close();
       
   213     iInvitationsArray.Reset();
       
   214     iInvitationsArray.Close();
       
   215     if ( iContactInterface )
       
   216         {
       
   217         iContactInterface->RemoveObserver( this );
       
   218         }
       
   219     if ( iEngine.GetInvitationInterface() )
       
   220         {
       
   221         iEngine.GetInvitationInterface()->RemoveInviteObserver( this );
       
   222         }
       
   223 
       
   224 
       
   225     // Note : remove the observer before the set value since after setting the
       
   226     // value we get callback which we are not intrested as the application is exited
       
   227     // no point in calling the reset array and trying to fill the data
       
   228     if ( iSettings )
       
   229         {
       
   230         iSettings->RemoveObserver( this ); // remove from engine
       
   231         }
       
   232 
       
   233 
       
   234     //unregister for stored groups observer event
       
   235     if ( iChatGroups )
       
   236         {
       
   237         iChatGroups->RemoveObserver( this );
       
   238         }
       
   239 
       
   240     iSAPSettingsStore->RemoveObserver( this );
       
   241     delete iSAPSettingsStore;
       
   242     delete iGroupArray;
       
   243     delete iLastloggedinUserId;
       
   244     delete iConnectionUI;
       
   245 
       
   246 
       
   247     iRefreshConvArray.ResetAndDestroy();
       
   248 
       
   249     }
       
   250 
       
   251 // -----------------------------------------------------------------------------
       
   252 // CCAMainViewArrayPC::IsForceExpanded
       
   253 // -----------------------------------------------------------------------------
       
   254 
       
   255 TBool CCAMainViewArrayPC::IsForceExpanded() const
       
   256     {
       
   257     return iContactListModel.IsForceExpanded();
       
   258     }
       
   259 
       
   260 // -----------------------------------------------------------------------------
       
   261 // CCAMainViewArrayPC::SetMsgPending
       
   262 // -----------------------------------------------------------------------------
       
   263 
       
   264 void CCAMainViewArrayPC::SetMsgPending( TInt aPendingMsgs, TInt aIndex )
       
   265     {
       
   266 
       
   267     TInt index = aIndex - iContactListIndex <= 0 ? 0 : aIndex - iContactListIndex ;
       
   268 
       
   269     if ( GetType( aIndex ) == TEnumsPC::EContactItem  )
       
   270         {
       
   271         MCAContactListModel::SItem item = iContactListModel.Item( index );
       
   272         MCAStoredContact* Contact = item.iContact;
       
   273         if ( Contact )
       
   274             {
       
   275             Contact->SetPendingMessages( aPendingMsgs );
       
   276             }
       
   277         }
       
   278     }
       
   279 
       
   280 // -----------------------------------------------------------------------------
       
   281 // CCAMainViewArrayPC::GetItemNameTextL
       
   282 // -----------------------------------------------------------------------------
       
   283 
       
   284 TPtrC CCAMainViewArrayPC::GetItemNameText( TInt aIndex )
       
   285     {
       
   286     TEnumsPC::TItem itemtype = GetType( aIndex );
       
   287 
       
   288 
       
   289     /* Codescanner warning is ignored, since Bound check is done
       
   290      * inside the GetType()
       
   291      * method*/
       
   292     /*aIndex >= iOpenChatsIndex*/
       
   293     switch ( itemtype )
       
   294 
       
   295         {
       
   296         case TEnumsPC::EOwnStatusItem:
       
   297             {
       
   298             MCAArrayItemPC *arrayItemPC = ( MCAArrayItemPC * )iMainViewListItemArray[aIndex];
       
   299             return arrayItemPC->GetItemNameText();
       
   300             }
       
   301         case TEnumsPC::EOpenChatsListItem:
       
   302         case TEnumsPC::EGroupItem:
       
   303         case TEnumsPC::EConversationItem:
       
   304         case TEnumsPC::EInviteItem:
       
   305             {
       
   306             if ( aIndex <= iContactListIndex )
       
   307                 {
       
   308                 MCAArrayItemPC *arrayItemPC = ( MCAArrayItemPC * )iOpenChatsArray[aIndex - iOpenChatsIndex];
       
   309                 return arrayItemPC->GetItemNameText();
       
   310                 }
       
   311             break;
       
   312             }
       
   313         case TEnumsPC::EContactListItem:
       
   314         case TEnumsPC::EContactItem:
       
   315             {
       
   316             TPtrC itemNameText( KNullDesC );
       
   317             TRAP_IGNORE( itemNameText.Set( GetFormattedItemNameTextL( aIndex ) ) );
       
   318             return itemNameText;
       
   319             }
       
   320         case TEnumsPC::EInvalid:
       
   321         default:
       
   322             {
       
   323             return KNullDesC();
       
   324             }
       
   325         }
       
   326     return KNullDesC();
       
   327     }
       
   328 // -----------------------------------------------------------------------------
       
   329 // CCAMainViewArrayPC::GetFormattedItemNameTextL
       
   330 // -----------------------------------------------------------------------------
       
   331 TPtr CCAMainViewArrayPC::GetFormattedItemNameTextL( TInt aIndex )
       
   332     {
       
   333     TEnumsPC::TItem itemType = GetType( aIndex );
       
   334 
       
   335     TInt index = GetItemEngineIndex( aIndex ) ;
       
   336     MCAContactListModel::SItem item = iContactListModel.Item( index );
       
   337     MCAContactList* list = item.iContactList;
       
   338     TPtr buffer( iData->Des() );
       
   339     buffer.Zero();
       
   340     switch ( itemType )
       
   341         {
       
   342         case TEnumsPC::EContactListItem:
       
   343             {
       
   344             if ( list )
       
   345                 {
       
   346                 // C-column
       
   347                 // append "number of online contacts / total number
       
   348                 // of contacts" after identification
       
   349                 CArrayFix<TInt>* intArray = new ( ELeave ) CArrayFixFlat<TInt>( KGranularity );
       
   350                 CleanupStack::PushL( intArray );
       
   351                 // Append number of online contacts
       
   352                 TStorageManagerGlobals::TFilterType filterType
       
   353                 = GetFilterConverterUITOEngine( GetSingleListArrayFilter() );
       
   354                 intArray->AppendL( list->FilteredCount( filterType ) );
       
   355                 // Append total number of contacts, depends on how blocked contacts are handled
       
   356                 if ( IMUtils::IntResourceValueL( RSC_CHAT_VARIATION_BLOCKING ) != 2 )
       
   357                     {
       
   358                     // Blocked contacts are hidden or removed, do not include to total count.
       
   359                     // Removed is also handled here because user may log in with different clients
       
   360                     // that handle blocked contacts differently.
       
   361                     intArray->AppendL( list->FilteredCount(
       
   362                                            TStorageManagerGlobals::EFilterNonBlocked ) );
       
   363                     }
       
   364                 else
       
   365                     {
       
   366                     // Blocked contacs are shown, Count() returns correct value
       
   367                     intArray->AppendL( list->Count() );
       
   368                     }
       
   369                 CDesCArray* array = new( ELeave ) CDesCArrayFlat( 1 ); // one items
       
   370                 CleanupStack::PushL( array );
       
   371                 array->AppendL( KNullDesC );
       
   372 
       
   373                 HBufC* textNumbers = StringLoader::LoadLC( R_QTN_CHAT_CONTACTLIST_CONTACTLIST,
       
   374                                                            *array, *intArray );
       
   375                 array->Reset();
       
   376 
       
   377                 TPtr textNumbersPtr( textNumbers->Des() );
       
   378 
       
   379                 TPtrC identification ( list->DisplayName() );
       
   380 
       
   381                 array->AppendL( identification.Left( buffer.MaxLength() -
       
   382                                                      iMaxLengthOfIcons - textNumbersPtr.Length() ) );
       
   383 
       
   384                 HBufC* listString = StringLoader::LoadLC( R_QTN_CHAT_CONTACTLIST_CONTACTLIST,
       
   385                                                           *array, *intArray );
       
   386                 TPtr listStringPtr( listString->Des() );
       
   387 
       
   388                 buffer.Append( listStringPtr );
       
   389                 //Code scanner warning ignored
       
   390                 CleanupStack::PopAndDestroy( 4, intArray ); //array,textNumbers,listString,intArray
       
   391                 }
       
   392             break;
       
   393             }
       
   394         case TEnumsPC::EOwnStatusItem:
       
   395         case TEnumsPC::EContactItem:
       
   396             {
       
   397             buffer.Append( iContactListModel.MdcaPoint( index ) );
       
   398             break;
       
   399             }
       
   400         default:
       
   401             {
       
   402             break;
       
   403             }
       
   404         }
       
   405     return buffer;
       
   406     }
       
   407 // -----------------------------------------------------------------------------
       
   408 // CCAMainViewArrayPC::Filter
       
   409 // (other items were commented in a header).
       
   410 // -----------------------------------------------------------------------------
       
   411 //
       
   412 
       
   413 TEnumsPC::TFilterType CCAMainViewArrayPC::Filter()
       
   414     {
       
   415     return iFilter;
       
   416     }
       
   417 // -----------------------------------------------------------------------------
       
   418 // CCAMainViewArrayPC::GetDefaultFilter
       
   419 // -----------------------------------------------------------------------------
       
   420 
       
   421 TEnumsPC::TFilterType CCAMainViewArrayPC::GetDefaultFilter() const
       
   422     {
       
   423     return iDefaultFilter;
       
   424     }
       
   425 
       
   426 
       
   427 // -----------------------------------------------------------------------------
       
   428 // CCAMainViewArrayPC::SetDefaultFilter
       
   429 // -----------------------------------------------------------------------------
       
   430 
       
   431 void CCAMainViewArrayPC::SetDefaultFilter( TEnumsPC::TFilterType aFilter )
       
   432     {
       
   433     iDefaultFilter = aFilter;
       
   434     iContactListModel.SetDefaultFilter( GetFilterConverterUITOEngine( aFilter ) );
       
   435     }
       
   436 // -----------------------------------------------------------------------------
       
   437 // CCAMainViewArrayPC::SetDefaultFilter
       
   438 // -----------------------------------------------------------------------------
       
   439 
       
   440 void CCAMainViewArrayPC::SetFilter( TEnumsPC::TFilterType aFilter )
       
   441     {
       
   442     iFilter = aFilter;
       
   443     iContactListModel.SetFilter( GetFilterConverterUITOEngine( aFilter ) );
       
   444     }
       
   445 
       
   446 // -----------------------------------------------------------------------------
       
   447 // CCAMainViewArrayPC::GetFilterConverterUITOEngine
       
   448 // (other items were commented in a header).
       
   449 // -----------------------------------------------------------------------------
       
   450 //
       
   451 TStorageManagerGlobals::TFilterType
       
   452 CCAMainViewArrayPC::GetFilterConverterUITOEngine( TEnumsPC::TFilterType aFilter )
       
   453     {
       
   454 
       
   455     TStorageManagerGlobals::TFilterType filter;
       
   456     switch ( aFilter )
       
   457         {
       
   458 
       
   459         case TEnumsPC::EFilterAll:
       
   460             {
       
   461             filter = TStorageManagerGlobals::EFilterAll;
       
   462             break;
       
   463             }
       
   464         case TEnumsPC::EFilterAndOperation:
       
   465             {
       
   466             filter = TStorageManagerGlobals::EFilterAndOperation;
       
   467             break;
       
   468             }
       
   469         case TEnumsPC::EFilterOnline:
       
   470             {
       
   471             filter = TStorageManagerGlobals::EFilterOnline;
       
   472             break;
       
   473             }
       
   474         case TEnumsPC::EFilterAway:
       
   475             {
       
   476             filter = TStorageManagerGlobals::EFilterAway;
       
   477             break;
       
   478             }
       
   479         case TEnumsPC::EFilterNonOffline:
       
   480             {
       
   481             filter = TStorageManagerGlobals::EFilterNonOffline;
       
   482             break;
       
   483             }
       
   484         case TEnumsPC::EFilterNonBlocked:
       
   485             {
       
   486             filter = TStorageManagerGlobals::EFilterNonBlocked;
       
   487             break;
       
   488             }
       
   489 
       
   490         case TEnumsPC::EFilterNonOfflineNonBlockedAndOperation:
       
   491             {
       
   492             filter = TStorageManagerGlobals::TFilterType
       
   493                      (
       
   494                          TStorageManagerGlobals::EFilterNonOffline |
       
   495                          TStorageManagerGlobals::EFilterNonBlocked +
       
   496                          TStorageManagerGlobals::EFilterAndOperation
       
   497                      );
       
   498             break;
       
   499             }
       
   500         case TEnumsPC::EFilterAllNonBlockedAndOperation:
       
   501             {
       
   502             filter = TStorageManagerGlobals::TFilterType
       
   503                      (
       
   504                          TStorageManagerGlobals::EFilterAll |
       
   505                          TStorageManagerGlobals::EFilterNonBlocked +
       
   506                          TStorageManagerGlobals::EFilterAndOperation
       
   507                      );
       
   508             break;
       
   509             }
       
   510 
       
   511         case TEnumsPC::EFilterNonOfflineNonBlockedNonOfflineOperation:
       
   512             {
       
   513             filter = TStorageManagerGlobals::TFilterType
       
   514                      (
       
   515                          ( TStorageManagerGlobals::EFilterNonOffline
       
   516                            | TStorageManagerGlobals::EFilterNonBlocked
       
   517                            + TStorageManagerGlobals::EFilterAndOperation
       
   518                          )
       
   519                          | TStorageManagerGlobals::EFilterNonOffline
       
   520                          + TStorageManagerGlobals::EFilterAndOperation
       
   521                      );
       
   522 
       
   523             break;
       
   524             }
       
   525 
       
   526         case TEnumsPC::EFilterAllNonBlockedNonOfflineOperation:
       
   527             {
       
   528             filter = TStorageManagerGlobals::TFilterType
       
   529                      (
       
   530                          (
       
   531                              TStorageManagerGlobals::EFilterAll
       
   532                              | TStorageManagerGlobals::EFilterNonBlocked
       
   533                              + TStorageManagerGlobals::EFilterAndOperation
       
   534                          )
       
   535                          | TStorageManagerGlobals::EFilterNonOffline
       
   536                          + TStorageManagerGlobals::EFilterAndOperation
       
   537                      );
       
   538             break;
       
   539             }
       
   540 
       
   541         default:
       
   542             {
       
   543             filter = TStorageManagerGlobals::EFilterNotDefined;
       
   544             break;
       
   545             }
       
   546         }
       
   547     return filter;
       
   548     }
       
   549 
       
   550 // -----------------------------------------------------------------------------
       
   551 // CCAMainViewArrayPC::ResetDefaultFilter
       
   552 // -----------------------------------------------------------------------------
       
   553 
       
   554 void CCAMainViewArrayPC::ResetDefaultFilter()
       
   555     {
       
   556     iFilter = iDefaultFilter;
       
   557     iContactListModel.ResetDefaultFilter();
       
   558     }
       
   559 
       
   560 
       
   561 // -----------------------------------------------------------------------------
       
   562 // CCAMainViewArrayPC::IsAllSynchronised
       
   563 // -----------------------------------------------------------------------------
       
   564 
       
   565 TEnumsPC::TSyncStatus CCAMainViewArrayPC::IsAllSynchronised()
       
   566     {
       
   567 
       
   568     TBool allSynchronised 	= ETrue;
       
   569     TBool failedFromAll 	= EFalse;
       
   570 
       
   571     allSynchronised = iContactInterface->IsAllSynchronised( failedFromAll );
       
   572 
       
   573     if ( allSynchronised && failedFromAll )
       
   574         return TEnumsPC::ESyncFailed;
       
   575     else if ( allSynchronised )
       
   576         return TEnumsPC::ESyncSuccess;
       
   577     else
       
   578 
       
   579         return TEnumsPC::ESyncNotDone;
       
   580 
       
   581     }
       
   582 // -----------------------------------------------------------------------------
       
   583 // CCAMainViewArrayPC::SetSingleListArrayFilter
       
   584 // -----------------------------------------------------------------------------
       
   585 //
       
   586 void CCAMainViewArrayPC::SetSingleListArrayFilter( TEnumsPC::TFilterType aFilter )
       
   587     {
       
   588     iSingleListArrayFilter = aFilter;
       
   589     }
       
   590 
       
   591 // -----------------------------------------------------------------------------
       
   592 // CCAMainViewArrayPC::GetSingleListArrayFilter
       
   593 // -----------------------------------------------------------------------------
       
   594 //
       
   595 TEnumsPC::TFilterType CCAMainViewArrayPC::GetSingleListArrayFilter()
       
   596     {
       
   597     return iSingleListArrayFilter;
       
   598     }
       
   599 
       
   600 
       
   601 // -----------------------------------------------------------------------------
       
   602 // CCAMainViewArrayPC::Synchronised
       
   603 // -----------------------------------------------------------------------------
       
   604 
       
   605 TEnumsPC::TSyncStatus CCAMainViewArrayPC::Synchronised( TInt aIndex )
       
   606     {
       
   607 
       
   608     // don't operate this function other than contactlists..
       
   609     TEnumsPC::TItem itemtype = GetType( aIndex );
       
   610     if ( itemtype != TEnumsPC::EContactListItem )
       
   611         {
       
   612         return 	TEnumsPC::ESyncUnknown; // return unknowncode...
       
   613         }
       
   614     TInt index = GetItemEngineIndex( aIndex );
       
   615 
       
   616     MCAContactListModel::SItem item = iContactListModel.Item( index );
       
   617 
       
   618     //invalid index
       
   619     if ( item.iType == MCAContactListModel::EInvalid && !item.iContactList )
       
   620         {
       
   621         return TEnumsPC::ESyncUnknown;
       
   622         }
       
   623 
       
   624     TEnumsPC::TSyncStatus statustype;
       
   625 
       
   626     switch ( item.iContactList->Synchronised() )
       
   627         {
       
   628         case MCAContactList::ESynchroniseDone:
       
   629             {
       
   630             statustype = TEnumsPC::ESyncSuccess;
       
   631             break;
       
   632             }
       
   633         case MCAContactList::ESynchroniseFailed:
       
   634             {
       
   635             statustype = TEnumsPC::ESyncFailed;
       
   636             break;
       
   637             }
       
   638         // ESynchroniseNotDone is different from
       
   639         // ESynchroniseFailed, so check what exactly difference and
       
   640         // return the corssponding variable....
       
   641         case MCAContactList::ESynchroniseNotDone:
       
   642             {
       
   643             statustype = TEnumsPC::ESyncNotDone;
       
   644             break;
       
   645             }
       
   646         default:
       
   647             {
       
   648             statustype = TEnumsPC::ESyncUnknown;
       
   649             break;
       
   650             }
       
   651         }
       
   652     return statustype;
       
   653     }
       
   654 
       
   655 // -----------------------------------------------------------------------------
       
   656 // CCAMainViewArrayPC::ClientType
       
   657 // -----------------------------------------------------------------------------
       
   658 
       
   659 TEnumsPC::TClientType CCAMainViewArrayPC::ClientType( TInt aIndex )
       
   660     {
       
   661     TInt index = GetItemEngineIndex( aIndex );
       
   662 
       
   663     TEnumsPC::TItem itemtype = GetType( aIndex );
       
   664     TEnumsPC::TClientType clienttype = TEnumsPC::EUnknownClient ;
       
   665 
       
   666     if ( itemtype == TEnumsPC::EContactItem  )
       
   667         {
       
   668         MCAContactListModel::SItem item = iContactListModel.Item( index );
       
   669         MCAStoredContact* Contact = item.iContact;
       
   670         if ( Contact )
       
   671             {
       
   672 
       
   673             switch ( Contact->ClientType() )
       
   674                 {
       
   675                 case TStorageManagerGlobals::EMobile:
       
   676                     clienttype = TEnumsPC::EMobile;
       
   677                     break;
       
   678                 case TStorageManagerGlobals::EPC:
       
   679                     clienttype = TEnumsPC::EPC;
       
   680                     break;
       
   681                 default:
       
   682                     clienttype = TEnumsPC::EUnknownClient;
       
   683                     break;
       
   684                 }
       
   685             }
       
   686         }
       
   687     return clienttype;
       
   688     }
       
   689 
       
   690 // -----------------------------------------------------------------------------
       
   691 // CCAMainViewArrayPC::Selected
       
   692 // -----------------------------------------------------------------------------
       
   693 
       
   694 TBool CCAMainViewArrayPC::Selected( TInt aIndex )
       
   695     {
       
   696     TInt index = GetItemEngineIndex( aIndex );
       
   697 
       
   698     TEnumsPC::TItem itemtype = GetType( aIndex );
       
   699 
       
   700     MCAContactListModel::SItem item = iContactListModel.Item( index );
       
   701     MCAStoredContact* contact = item.iContact;
       
   702     MCAContactList* list = item.iContactList;
       
   703     if ( itemtype == TEnumsPC::EContactItem && contact  && list )
       
   704         {
       
   705         return ( contact->Selected() || list->Selected() ) ;
       
   706         }
       
   707     else if ( itemtype == TEnumsPC::EContactListItem && list )
       
   708         {
       
   709         return list->Selected();
       
   710         }
       
   711     return EFalse;
       
   712     }
       
   713 
       
   714 // -----------------------------------------------------------------------------
       
   715 // CCAMainViewArrayPC::IsWatched
       
   716 // -----------------------------------------------------------------------------
       
   717 
       
   718 TBool CCAMainViewArrayPC::IsWatched( TInt aIndex )
       
   719     {
       
   720     // map this index to correct list and give the correct index to engine..
       
   721     TInt index = GetItemEngineIndex( aIndex );
       
   722 
       
   723     TEnumsPC::TItem itemtype = GetType( aIndex );
       
   724 
       
   725     MCAContactListModel::SItem item = iContactListModel.Item( index );
       
   726     MCAStoredContact* contact = item.iContact;
       
   727     if ( itemtype == TEnumsPC::EContactItem  && contact )
       
   728         {
       
   729         return contact->IsWatched();
       
   730         }
       
   731     return EFalse;
       
   732     }
       
   733 
       
   734 // -----------------------------------------------------------------------------
       
   735 // CCAMainViewArrayPC::AddWatcher
       
   736 // -----------------------------------------------------------------------------
       
   737 
       
   738 void CCAMainViewArrayPC::AddWatcherL( TPtrC aContact )
       
   739     {
       
   740     CAPresenceManager::InstanceL()->AddWatcherL( aContact );
       
   741     }
       
   742 
       
   743 // -----------------------------------------------------------------------------
       
   744 // CCAMainViewArrayPC::IsWatched
       
   745 // -----------------------------------------------------------------------------
       
   746 
       
   747 void CCAMainViewArrayPC::RemoveWatcherL( TPtrC aContact )
       
   748     {
       
   749     CAPresenceManager::InstanceL()->RemoveWatcherL( aContact );
       
   750     }
       
   751 
       
   752 // -----------------------------------------------------------------------------
       
   753 // CCAMainViewArrayPC::RefreshFriendsL
       
   754 // -----------------------------------------------------------------------------
       
   755 
       
   756 void CCAMainViewArrayPC::RefreshFriendsL()
       
   757     {
       
   758     CAPresenceManager::InstanceL()->RefreshFriendsL();
       
   759     }
       
   760 // -----------------------------------------------------------------------------
       
   761 // CCAMainViewArrayPC::GetOnlineUsersL
       
   762 // -----------------------------------------------------------------------------
       
   763 
       
   764 void CCAMainViewArrayPC::GetOnlineUsersL( const CDesCArray *aUsers,
       
   765                                           CDesCArray* aOnlineList,
       
   766                                           CDesCArray* aOfflineList,
       
   767                                           TBool aUpdateStorage )
       
   768     {
       
   769     MCAPresence* presence = CAPresenceManager::InstanceL();
       
   770     presence->GetOnlineUsersL( *aUsers, aOnlineList, aOfflineList, aUpdateStorage );
       
   771     }
       
   772 
       
   773 
       
   774 // -----------------------------------------------------------------------------
       
   775 // CCAMainViewArrayPC::GetOnlineStatus
       
   776 // -----------------------------------------------------------------------------
       
   777 
       
   778 TEnumsPC::TOnlineStatus CCAMainViewArrayPC::GetOnlineStatus( TInt aIndex )
       
   779     {
       
   780     TInt index = GetItemEngineIndex( aIndex );
       
   781 
       
   782     TEnumsPC::TItem itemtype = GetType( aIndex );
       
   783 
       
   784     MCAContactListModel::SItem item = iContactListModel.Item( index );
       
   785     MCAStoredContact* contact = item.iContact;
       
   786     if ( contact && ( itemtype == TEnumsPC::EContactItem ||
       
   787                       itemtype == TEnumsPC::EOwnStatusItem ) )
       
   788         {
       
   789         return GetOnlineStatusConverter( contact->OnlineStatus() );
       
   790         }
       
   791     else
       
   792         {
       
   793         return TEnumsPC::EUnknown;
       
   794         }
       
   795     }
       
   796 
       
   797 // -----------------------------------------------------------------------------
       
   798 // CCAMainViewArrayPC::GetOnlineStatusConverter
       
   799 // -----------------------------------------------------------------------------
       
   800 
       
   801 TEnumsPC::TOnlineStatus CCAMainViewArrayPC::GetOnlineStatusConverter(
       
   802     TStorageManagerGlobals::TPresenceStatus aEngOnlineStatus )
       
   803     {
       
   804     switch ( aEngOnlineStatus )
       
   805         {
       
   806         case TStorageManagerGlobals::EOffline:
       
   807             return TEnumsPC::EOffline;
       
   808         case TStorageManagerGlobals::EOnline:
       
   809             return TEnumsPC::EOnline;
       
   810         case TStorageManagerGlobals::EInvisible:
       
   811             return TEnumsPC::EInvisible;
       
   812         case TStorageManagerGlobals::EAway:
       
   813             return TEnumsPC::EAway;
       
   814         case TStorageManagerGlobals::EBusy:
       
   815             return TEnumsPC::EBusy;
       
   816         default:
       
   817             return TEnumsPC::EUnknown;
       
   818         }
       
   819     }
       
   820 
       
   821 // -----------------------------------------------------------------------------
       
   822 // CCAMainViewArrayPC::SetBlocked
       
   823 // -----------------------------------------------------------------------------
       
   824 
       
   825 void CCAMainViewArrayPC::SetBlocked( TBool aBlockStatus, TInt aIndex )
       
   826     {
       
   827 
       
   828     TInt index = GetItemEngineIndex( aIndex );
       
   829     TEnumsPC::TItem itemtype = GetType( aIndex );
       
   830 
       
   831     MCAContactListModel::SItem item = iContactListModel.Item( index );
       
   832     MCAStoredContact* contact = item.iContact;
       
   833     if ( itemtype == TEnumsPC::EContactItem  && contact )
       
   834         {
       
   835         contact->SetBlocked( aBlockStatus );
       
   836         }
       
   837     }
       
   838 // -----------------------------------------------------------------------------
       
   839 // CCAMainViewArrayPC::ForceExpanded
       
   840 // -----------------------------------------------------------------------------
       
   841 //
       
   842 void CCAMainViewArrayPC::ForceExpanded( TBool aAllExpanded )
       
   843     {
       
   844     iContactListModel.ForceExpanded( aAllExpanded );
       
   845     iExpandAll = aAllExpanded;
       
   846     ResetArray( EFalse );
       
   847     }
       
   848 
       
   849 // -----------------------------------------------------------------------------
       
   850 // CCAMainViewArrayPC::SetOnlineStatus
       
   851 // -----------------------------------------------------------------------------
       
   852 
       
   853 void CCAMainViewArrayPC::SetOnlineStatus( TEnumsPC::TOnlineStatus aStatus, TInt aIndex )
       
   854     {
       
   855     TInt index = GetItemEngineIndex( aIndex );
       
   856     TEnumsPC::TItem itemtype = GetType( aIndex );
       
   857 
       
   858     MCAContactListModel::SItem item = iContactListModel.Item( index );
       
   859     MCAStoredContact* contact = item.iContact;
       
   860     if ( itemtype == TEnumsPC::EContactItem  && contact )
       
   861         {
       
   862         TStorageManagerGlobals::TPresenceStatus status;
       
   863         switch ( aStatus )
       
   864             {
       
   865             case TEnumsPC::EOffline:
       
   866                 {
       
   867                 status = TStorageManagerGlobals::EOffline;
       
   868                 break;
       
   869                 }
       
   870             case TEnumsPC::EOnline:
       
   871                 {
       
   872                 status = TStorageManagerGlobals::EOnline;
       
   873                 break;
       
   874                 }
       
   875             case TEnumsPC::EInvisible:
       
   876                 {
       
   877                 status = TStorageManagerGlobals::EInvisible;
       
   878                 break;
       
   879                 }
       
   880 
       
   881             case TEnumsPC::EAway:
       
   882                 {
       
   883                 status = TStorageManagerGlobals::EAway;
       
   884                 break;
       
   885                 }
       
   886             case TEnumsPC::EBusy:
       
   887                 {
       
   888                 status = TStorageManagerGlobals::EBusy;
       
   889                 break;
       
   890                 }
       
   891             default:
       
   892                 {
       
   893                 status = TStorageManagerGlobals::EUnknown;
       
   894                 }
       
   895             }
       
   896         contact->SetOnlineStatus( status );
       
   897         }
       
   898     }
       
   899 
       
   900 
       
   901 // -----------------------------------------------------------------------------
       
   902 // CCAMainViewArrayPC::Count
       
   903 // -----------------------------------------------------------------------------
       
   904 
       
   905 TInt CCAMainViewArrayPC::Count() const
       
   906     {
       
   907     // return the total count here.
       
   908 
       
   909     return iMainViewListItemArray.Count() + iContactListIndex;
       
   910     }
       
   911 
       
   912 
       
   913 // -----------------------------------------------------------------------------
       
   914 // CCAMainViewArrayPC::GetTypeConverter
       
   915 // Get the type from engine and return the TEnumsPC type
       
   916 // -----------------------------------------------------------------------------
       
   917 TEnumsPC::TItem CCAMainViewArrayPC::GetTypeConverter(
       
   918     MCAContactListModel::TItemType aItemType ) const
       
   919     {
       
   920     TEnumsPC::TItem type = TEnumsPC::EInvalid;
       
   921     switch ( aItemType )
       
   922         {
       
   923         case MCAContactListModel::EInvalid:
       
   924             {
       
   925             type = TEnumsPC::EInvalid;
       
   926             break;
       
   927             }
       
   928         case MCAContactListModel::EOwnStatus:
       
   929             {
       
   930             type = TEnumsPC::EOwnStatusItem;
       
   931             break;
       
   932             }
       
   933         case MCAContactListModel::EContactList:
       
   934             {
       
   935             type = TEnumsPC::EContactListItem;
       
   936             break;
       
   937             }
       
   938         case MCAContactListModel::EContactItem:
       
   939             {
       
   940             type = TEnumsPC::EContactItem;
       
   941             break;
       
   942             }
       
   943         case MCAContactListModel::EAll:
       
   944             {
       
   945             type = TEnumsPC::EAll;
       
   946             break;
       
   947             }
       
   948         }
       
   949     return type;
       
   950     }
       
   951 
       
   952 
       
   953 // -----------------------------------------------------------------------------
       
   954 // CCAMainViewArrayPC::GetOpenChatType
       
   955 // Get the type from engine and return the type
       
   956 // -----------------------------------------------------------------------------
       
   957 
       
   958 TEnumsPC::TItem CCAMainViewArrayPC::GetOpenChatType( TInt aIndex ) const
       
   959     {
       
   960     TInt openChatArrayCount = iOpenChatsArray.Count();
       
   961     if ( SingleListViewSelectMode() &&
       
   962          ( aIndex >= iOpenChatsIndex && aIndex <= openChatArrayCount ) )
       
   963         {
       
   964         MCAArrayItemPC* item = iOpenChatsArray[ aIndex - 1 ];
       
   965         return item->Type();
       
   966         }
       
   967     else
       
   968         {
       
   969         return TEnumsPC::EInvalid;
       
   970         }
       
   971     }
       
   972 // -----------------------------------------------------------------------------
       
   973 // CCAMainViewArrayPC::GetType
       
   974 // Get the type from engine and return the type
       
   975 // -----------------------------------------------------------------------------
       
   976 
       
   977 TEnumsPC::TItem CCAMainViewArrayPC::GetType( TInt aIndex ) const
       
   978     {
       
   979     TInt totalCount = Count();
       
   980     TInt itemArrayCount = iMainViewListItemArray.Count();
       
   981     TInt openChatArrayCount = iOpenChatsArray.Count();
       
   982     if ( totalCount <= 0 || ( aIndex < 0 || aIndex >= totalCount ) )
       
   983         {
       
   984         return TEnumsPC::EInvalid;
       
   985         }
       
   986     if ( SingleListViewSelectMode() &&
       
   987          ( aIndex >= iOpenChatsIndex && aIndex <= iContactListIndex ) )
       
   988         {
       
   989         MCAArrayItemPC* item = iOpenChatsArray[ aIndex - 1 ];
       
   990         return item->Type();
       
   991         }
       
   992     else if ( iMainViewListItemArray.Count() > 0 &&
       
   993               aIndex <= iContactListIndex + iMainViewListItemArray.Count() )
       
   994         {
       
   995         TInt index = aIndex - iContactListIndex <= 0 ? 0 : aIndex - iContactListIndex;
       
   996         MCAArrayItemPC* item = iMainViewListItemArray[ index ];
       
   997         return item->Type();
       
   998         }
       
   999     else
       
  1000         {
       
  1001         return TEnumsPC::EInvalid;
       
  1002         }
       
  1003     }
       
  1004 // -----------------------------------------------------------------------------
       
  1005 // CCAMainViewArrayPC::SingleListViewSelectMode
       
  1006 // -----------------------------------------------------------------------------
       
  1007 //
       
  1008 TBool CCAMainViewArrayPC::SingleListViewSelectMode() const
       
  1009     {
       
  1010     if ( iSelectionMode == TEnumsPC::ESingleListViewSelect )
       
  1011         {
       
  1012         return ETrue;
       
  1013         }
       
  1014     else
       
  1015         {
       
  1016         return EFalse;
       
  1017         }
       
  1018     }
       
  1019 
       
  1020 // -----------------------------------------------------------------------------
       
  1021 // CCAMainViewArrayPC::IsCollapsed
       
  1022 // -----------------------------------------------------------------------------
       
  1023 
       
  1024 TBool CCAMainViewArrayPC::IsCollapsed( TInt aIndex ) const
       
  1025     {
       
  1026     // this operation should be on list only..otherwise throw exception..
       
  1027     TBool iscollapsed = EFalse;
       
  1028     TEnumsPC::TItem itemtype = GetType( aIndex );
       
  1029 
       
  1030     TInt index = GetItemEngineIndex( aIndex );
       
  1031 
       
  1032     MCAContactListModel::SItem item;
       
  1033     MCAContactList* list = NULL;
       
  1034 
       
  1035     //check the correct type and send the status
       
  1036     switch ( itemtype )
       
  1037         {
       
  1038         case TEnumsPC::EContactListItem:
       
  1039         case TEnumsPC::EContactItem:
       
  1040             {
       
  1041             if ( iSelectionMode == TEnumsPC::ESingleListMultiSelect )
       
  1042                 {
       
  1043                 index = index  + iSelectedListIndex;
       
  1044                 }
       
  1045             item = iContactListModel.Item( index );
       
  1046             list =  item.iContactList;
       
  1047             if ( list )
       
  1048                 {
       
  1049                 iscollapsed = list->Collapsed();
       
  1050                 }
       
  1051             break;
       
  1052             }
       
  1053         case TEnumsPC::EOpenChatsListItem:
       
  1054         case TEnumsPC::EConversationItem:
       
  1055         case TEnumsPC::EInviteItem:
       
  1056         case TEnumsPC::EGroupItem:
       
  1057             {
       
  1058             return !iOpenChatListItemExpanded;
       
  1059             }
       
  1060 
       
  1061         default:
       
  1062             {
       
  1063             iscollapsed = EFalse;
       
  1064             break;
       
  1065             }
       
  1066         }
       
  1067     return iscollapsed;
       
  1068     }
       
  1069 
       
  1070 // -----------------------------------------------------------------------------
       
  1071 // CCAMainViewArrayPC::SetCollapsed
       
  1072 // -----------------------------------------------------------------------------
       
  1073 
       
  1074 
       
  1075 void CCAMainViewArrayPC::SetCollapsed( TBool aStatus , TInt aIndex )
       
  1076     {
       
  1077     //This operation should be on list only..otherwise throw exception..
       
  1078     TEnumsPC::TItem itemtype = GetType( aIndex );
       
  1079 
       
  1080     MCAContactListModel::SItem item;
       
  1081     switch ( itemtype )
       
  1082         {
       
  1083         case TEnumsPC::EContactListItem:
       
  1084         case TEnumsPC::EContactItem:
       
  1085             {
       
  1086             TInt index = GetItemEngineIndex( aIndex );
       
  1087             item = iContactListModel.Item( index );
       
  1088             if ( item.iType == MCAContactListModel::EContactList ||
       
  1089                  item.iType == MCAContactListModel::EContactItem )
       
  1090                 {
       
  1091                 // there's a contact list or contact in current position
       
  1092                 MCAContactList& list = *item.iContactList;
       
  1093                 list.SetCollapsed( aStatus );
       
  1094 
       
  1095                 // this is actually heavy call, becoz the array has
       
  1096                 // to be refreshed completely. To do this in optimized way.
       
  1097                 ResetArray( EFalse );
       
  1098                 }
       
  1099             break;
       
  1100             }
       
  1101         case TEnumsPC::EOpenChatsListItem:
       
  1102         case TEnumsPC::EConversationItem:
       
  1103         case TEnumsPC::EInviteItem:
       
  1104         case TEnumsPC::EGroupItem:
       
  1105             {
       
  1106             // inverse the expanded state
       
  1107 
       
  1108             iOpenChatListItemExpanded = !iOpenChatListItemExpanded;
       
  1109             if ( iOpenChatListItemExpanded )
       
  1110                 {
       
  1111                 iContactListIndex = iOpenChatsArray.Count();
       
  1112                 }
       
  1113             else
       
  1114                 {
       
  1115                 iContactListIndex = iOpenChatsIndex;
       
  1116                 }
       
  1117             break;
       
  1118             }
       
  1119         default:
       
  1120             {
       
  1121             break;
       
  1122             }
       
  1123         }
       
  1124 
       
  1125     }
       
  1126 
       
  1127 // -----------------------------------------------------------------------------
       
  1128 // CCAMainViewArrayPC::IsMsgPending
       
  1129 // -----------------------------------------------------------------------------
       
  1130 //
       
  1131 TBool CCAMainViewArrayPC::IsMsgPending( TInt aIndex )
       
  1132     {
       
  1133 
       
  1134     // this operation should be on list only..otherwise throw exception..
       
  1135 
       
  1136     TInt index = GetItemEngineIndex( aIndex );
       
  1137     TBool isMsgPending = EFalse;
       
  1138     MCAContactListModel::SItem item;
       
  1139     MCAStoredContact* contact = NULL;
       
  1140     MCAContactList *list = NULL;
       
  1141     //check the correct type and send the status
       
  1142     switch ( GetType( aIndex ) )
       
  1143         {
       
  1144         case TEnumsPC::EContactItem :
       
  1145             {
       
  1146             item = iContactListModel.Item( index );
       
  1147             contact = item.iContact;
       
  1148             if ( contact )
       
  1149                 {
       
  1150                 isMsgPending = contact->PendingMessages() > 0 ? ETrue : EFalse;
       
  1151                 }
       
  1152             break;
       
  1153             }
       
  1154         case TEnumsPC::EContactListItem:
       
  1155             {
       
  1156             item = iContactListModel.Item( index );
       
  1157             list = item.iContactList;
       
  1158             if ( list )
       
  1159                 {
       
  1160                 TBool status = list->PendingMessages() > 0 &&
       
  1161                                list->Synchronised() == MCAContactList::ESynchroniseDone;
       
  1162                 isMsgPending = status ? ETrue : EFalse;
       
  1163                 }
       
  1164 
       
  1165             break;
       
  1166             }
       
  1167         case TEnumsPC::EInviteItem:
       
  1168             {
       
  1169             //get the pair to the invitation item here.
       
  1170             /* Codescanner warning is ignored, since Bound check is done
       
  1171              * inside the GetType()
       
  1172              * method*/
       
  1173             CCAInviteItemPC* invItemPC =
       
  1174                 dynamic_cast<CCAInviteItemPC*>( iOpenChatsArray[index] );
       
  1175             TPtrC invId = invItemPC->GetInviteID();
       
  1176 
       
  1177             isMsgPending = IsOpenChatsMsgPending( TEnumsPC::EInviteItem, invId );
       
  1178 
       
  1179             break;
       
  1180             }
       
  1181         case TEnumsPC::EConversationItem:
       
  1182             {
       
  1183             //get the pair to the conversationItem here.
       
  1184             /* Codescanner warning is ignored, since Bound check is done
       
  1185              * inside the GetType()
       
  1186              * method*/
       
  1187             CCAConversationItemPC* convItemPC =
       
  1188                 dynamic_cast<CCAConversationItemPC*>( iOpenChatsArray[index] );
       
  1189             TPtrC userId = convItemPC->UserId();
       
  1190 
       
  1191             isMsgPending = IsOpenChatsMsgPending( TEnumsPC::EConversationItem, userId );
       
  1192 
       
  1193             break;
       
  1194             }
       
  1195         case TEnumsPC::EGroupItem:
       
  1196             {
       
  1197             TArrayPairs pair;
       
  1198 
       
  1199             /* Codescanner warning is ignored, since Bound check is done
       
  1200              * inside the GetType()
       
  1201              * method*/
       
  1202             CCAGroupItemPC* groupItem = dynamic_cast< CCAGroupItemPC* >
       
  1203                                         ( iOpenChatsArray[ index ] );
       
  1204 
       
  1205             isMsgPending = IsOpenChatsMsgPending( TEnumsPC::EGroupItem, groupItem->GroupId() );
       
  1206 
       
  1207             break;
       
  1208             }
       
  1209 
       
  1210         default:
       
  1211             {
       
  1212             break;
       
  1213             }
       
  1214         }
       
  1215 
       
  1216     return isMsgPending;
       
  1217     }
       
  1218 
       
  1219 // -----------------------------------------------------------------------------
       
  1220 // CCAMainViewArrayPC::IsBlocked
       
  1221 // -----------------------------------------------------------------------------
       
  1222 
       
  1223 TBool CCAMainViewArrayPC::IsBlocked( TInt aIndex ) const
       
  1224     {
       
  1225     // this operation should be on list only..otherwise throw exception..
       
  1226 
       
  1227     TBool status;
       
  1228     MCAContactListModel::SItem item;
       
  1229     MCAStoredContact* contact = NULL;
       
  1230     TInt index = GetItemEngineIndex( aIndex );
       
  1231     //check the correct type and send the status
       
  1232     TEnumsPC::TItem itemtype = GetType( aIndex );
       
  1233     switch ( itemtype )
       
  1234         {
       
  1235 
       
  1236         case TEnumsPC::EContactItem:
       
  1237         case TEnumsPC::EContactListItem:
       
  1238             {
       
  1239             if ( iSelectionMode == TEnumsPC::ESingleListMultiSelect )
       
  1240                 {
       
  1241                 index =   aIndex + iSelectedListIndex ;
       
  1242                 }
       
  1243             item =  iContactListModel.Item( index );
       
  1244             if ( item.iType == MCAContactListModel::EContactItem )
       
  1245                 {
       
  1246                 contact = item.iContact;
       
  1247                 status =  contact->IsBlocked();
       
  1248                 }
       
  1249             else
       
  1250                 {
       
  1251                 status =  EFalse;
       
  1252                 }
       
  1253             break;
       
  1254             }
       
  1255 
       
  1256         case TEnumsPC::EConversationItem:
       
  1257             {
       
  1258             /* Codescanner warning is ignored, since Bound check is done
       
  1259               * inside the GetType()
       
  1260              * method*/
       
  1261             CCAConversationItemPC* conversationItem =
       
  1262                 dynamic_cast< CCAConversationItemPC* > ( iOpenChatsArray[ index] );
       
  1263 
       
  1264             status = iEngine.GetBlockingInterface()->IsContactBlocked( conversationItem->UserId() );
       
  1265             break;
       
  1266             }
       
  1267         case TEnumsPC::EInviteItem:
       
  1268             {
       
  1269             /* Codescanner warning is ignored, since Bound check is done
       
  1270              * inside the GetType()
       
  1271              * method*/
       
  1272             CCAInviteItemPC* inviteItem =
       
  1273                 dynamic_cast< CCAInviteItemPC* > ( iOpenChatsArray[ index] );
       
  1274 
       
  1275             status = iEngine.GetBlockingInterface()->IsContactBlocked( inviteItem->UserId() );
       
  1276             break;
       
  1277             }
       
  1278 
       
  1279         default: //Could be a open chat list or open chat item
       
  1280             {
       
  1281             status =  EFalse;
       
  1282             break;
       
  1283             }
       
  1284         }
       
  1285     return status;
       
  1286     }
       
  1287 
       
  1288 // -----------------------------------------------------------------------------
       
  1289 // CCAMainViewArrayPC::FillArrayL
       
  1290 // -----------------------------------------------------------------------------
       
  1291 
       
  1292 void CCAMainViewArrayPC::FillArrayL( TBool aFillOpenChatsArray )
       
  1293     {
       
  1294 
       
  1295     // now fill remaining details with all contact details..
       
  1296     if ( iSelectionMode == TEnumsPC::ESingleListMultiSelect )
       
  1297         {
       
  1298         FillSelectedContactListL();
       
  1299         }
       
  1300     else
       
  1301         {
       
  1302         // first fill the owndata item..
       
  1303         if ( iSelectionMode == TEnumsPC::ESingleListViewSelect )
       
  1304             {
       
  1305             if ( FillOwnDataL() && aFillOpenChatsArray )
       
  1306                 {
       
  1307                 FillOpenChatsL();    // then fill the conversations..or open chats....
       
  1308                 }
       
  1309             }
       
  1310         else
       
  1311             {
       
  1312             iContactListIndex = 0; // we have not added any thing to main array..so index is zero...
       
  1313             }
       
  1314         FillContactListsL();
       
  1315         }
       
  1316     }
       
  1317 
       
  1318 // -----------------------------------------------------------------------------
       
  1319 // CCAMainViewArrayPC::FillContactListsL
       
  1320 // -----------------------------------------------------------------------------
       
  1321 
       
  1322 void CCAMainViewArrayPC::FillContactListsL()
       
  1323     {
       
  1324 
       
  1325     // the index is starting from 1, because we already added owndata item to the list.......
       
  1326     for ( TInt iIndex = 0; iIndex < iContactListModel.Count(); iIndex++ )
       
  1327         {
       
  1328         FillItemL( iIndex );
       
  1329         }
       
  1330 
       
  1331 
       
  1332     }
       
  1333 // -----------------------------------------------------------------------------
       
  1334 // CCAMainViewArrayPC::FillSelectedContactListL
       
  1335 // -----------------------------------------------------------------------------
       
  1336 
       
  1337 void CCAMainViewArrayPC::FillSelectedContactListL( )
       
  1338     {
       
  1339 
       
  1340     MCAContactListModel::SItem item = iContactListModel.Item( iSelectedListIndex );
       
  1341     MCAContactList* list = item.iContactList;
       
  1342     if ( !list )
       
  1343         {
       
  1344         return;
       
  1345         }
       
  1346     TInt count( 0 );
       
  1347     if ( !list->Collapsed() )
       
  1348         {
       
  1349         count = list->FilteredCount( GetFilterConverterUITOEngine( Filter() ) );
       
  1350         }
       
  1351 
       
  1352     for ( TInt index = iSelectedListIndex ; index <= iSelectedListIndex + count ; index++ )
       
  1353         {
       
  1354         FillItemL( index );
       
  1355         }
       
  1356 
       
  1357     }
       
  1358 // -----------------------------------------------------------------------------
       
  1359 // CCAMainViewArrayPC::ResetArray
       
  1360 // -----------------------------------------------------------------------------
       
  1361 
       
  1362 void CCAMainViewArrayPC::ResetArray( TBool aClearOpenChatsArray )
       
  1363     {
       
  1364     //Clear the array and then fill the array agian with fresh data
       
  1365     ClearArray( aClearOpenChatsArray );
       
  1366     TRAPD( err, FillArrayL( aClearOpenChatsArray ) );
       
  1367 
       
  1368     if ( err != KErrNone )
       
  1369         {
       
  1370         CHAT_DP( D_CHAT_LIT( "CCAMainViewArrayPC::ResetArray - Unexpected, \
       
  1371                               left with %d" ), err );
       
  1372         CActiveScheduler::Current()->Error( err );
       
  1373         }
       
  1374 
       
  1375     }
       
  1376 
       
  1377 // -----------------------------------------------------------------------------
       
  1378 // CCAMainViewArrayPC::ClearArray
       
  1379 // -----------------------------------------------------------------------------
       
  1380 
       
  1381 void CCAMainViewArrayPC::ClearArray( TBool aClearOpenChatsArray )
       
  1382     {
       
  1383     //clear the array
       
  1384     iOwnDataAdded = false;
       
  1385     iMainViewListItemArray.ResetAndDestroy();
       
  1386     if ( aClearOpenChatsArray )
       
  1387         {
       
  1388         iOpenChatsArray.ResetAndDestroy();
       
  1389         }
       
  1390     }
       
  1391 
       
  1392 
       
  1393 // -----------------------------------------------------------------------------
       
  1394 // CCAMainViewArrayPC::FillItemL
       
  1395 // Fill up the complete array one item at a time
       
  1396 // -----------------------------------------------------------------------------
       
  1397 
       
  1398 void CCAMainViewArrayPC::FillItemL( TInt aIndex )
       
  1399     {
       
  1400     //Get the type of item here based on index......
       
  1401 
       
  1402     TPtr dataPtr( iData->Des() );
       
  1403     dataPtr.Zero();
       
  1404 
       
  1405 
       
  1406     // fetch the item and process correct type
       
  1407     MCAContactListModel::SItem item = iContactListModel.Item( aIndex );
       
  1408     switch ( item.iType )
       
  1409         {
       
  1410         case MCAContactListModel::EContactList:
       
  1411             {
       
  1412             // contact list
       
  1413             MCAContactList* list = item.iContactList;
       
  1414             __CHAT_ASSERT_DEBUG( list );
       
  1415 
       
  1416             //  add this items to contact list item -- CONTACTLIST
       
  1417             //  create an object of this type and append this to the rpointerarray
       
  1418             //  get the online stauts from engine-  switch( contactItem->OnlineStatus() )
       
  1419 
       
  1420             CCAContactListItemPC* contactListItem = CCAContactListItemPC::NewL();
       
  1421             // to avoid the code scanner warning
       
  1422             CleanupStack::PushL( contactListItem );
       
  1423             //initialize the item here..
       
  1424             MCAContactList::TSynchroniseState syncState = list->Synchronised();
       
  1425             TStorageManagerGlobals::TFilterType filterType
       
  1426             = GetFilterConverterUITOEngine( GetSingleListArrayFilter() );
       
  1427 
       
  1428             if ( syncState == MCAContactList::ESynchroniseDone )
       
  1429                 {
       
  1430                 TInt countOne = list->FilteredCount( filterType );
       
  1431                 TInt countTwo = 0;
       
  1432 
       
  1433                 if ( IMUtils::IntResourceValueL( RSC_CHAT_VARIATION_BLOCKING ) != 2 )
       
  1434 
       
  1435                     {
       
  1436                     // Blocked contacts are hidden or removed, do not include to total count.
       
  1437                     // Removed is also handled here because user may log in with different clients
       
  1438                     // that handle blocked contacts differently.
       
  1439                     countTwo  = list->FilteredCount( TStorageManagerGlobals::EFilterNonBlocked );
       
  1440                     }
       
  1441                 else
       
  1442                     {
       
  1443                     // Blocked contacs are shown, Count() returns correct value
       
  1444                     countTwo = list->Count();
       
  1445                     }
       
  1446 
       
  1447 
       
  1448 
       
  1449                 CArrayFix<TInt>* intArray = new ( ELeave ) CArrayFixFlat<TInt>( KGranularity );
       
  1450                 CleanupStack::PushL( intArray );
       
  1451 
       
  1452                 // Append number of online contacts
       
  1453                 intArray->AppendL( countOne );
       
  1454                 intArray->AppendL( countTwo );
       
  1455 
       
  1456                 CDesCArray* array = new( ELeave ) CDesCArrayFlat( 1 ); // one items
       
  1457                 CleanupStack::PushL( array );
       
  1458                 array->AppendL( KNullDesC );
       
  1459 
       
  1460                 HBufC* textNumbers = StringLoader::LoadLC( R_QTN_CHAT_CONTACTLIST_CONTACTLIST,
       
  1461                                                            *array, *intArray );
       
  1462                 TPtr textNumbersPtr( textNumbers->Des() );
       
  1463 
       
  1464                 TPtrC identification ( list->DisplayName() );
       
  1465 
       
  1466                 array->Reset();
       
  1467 
       
  1468                 array->AppendL( identification.Left( dataPtr.MaxLength() -
       
  1469                                                      iMaxLengthOfIcons - textNumbersPtr.Length() ) );
       
  1470 
       
  1471                 HBufC* listString = StringLoader::LoadLC( R_QTN_CHAT_CONTACTLIST_CONTACTLIST,
       
  1472                                                           *array, *intArray );
       
  1473                 TPtr listStringPtr( listString->Des() );
       
  1474 
       
  1475                 dataPtr.Append( listStringPtr );
       
  1476 
       
  1477                 //Code scanner warning ignored
       
  1478                 CleanupStack::PopAndDestroy( 4, intArray ); //array,textNumbers,listString,intArray
       
  1479 
       
  1480                 }
       
  1481 
       
  1482             // so append both and append the string to array...
       
  1483             contactListItem->SetItemNameText( dataPtr );
       
  1484 
       
  1485             contactListItem->SetItemEngineIndex( aIndex );
       
  1486 
       
  1487             //append this to the array
       
  1488             if ( iSelectionMode == TEnumsPC::ESingleListMultiSelect )
       
  1489                 {
       
  1490                 TInt arrayIndex =  aIndex - iSelectedListIndex ;
       
  1491                 iMainViewListItemArray.Insert( contactListItem, arrayIndex );
       
  1492                 }
       
  1493             else
       
  1494                 {
       
  1495                 iMainViewListItemArray.Insert( contactListItem,
       
  1496                                                aIndex );
       
  1497                 }
       
  1498             CleanupStack::Pop();// contactListItem
       
  1499             break;
       
  1500             }
       
  1501         case MCAContactListModel::EContactItem:
       
  1502             {
       
  1503             // contact item
       
  1504             // add this items to contact item -- CONTACT
       
  1505             // create an object of this type and append this to the rpointerarray
       
  1506             CCAContactItemPC* contactItem = CCAContactItemPC::NewL();
       
  1507             MCAStoredContact* contact = item.iContact;
       
  1508 
       
  1509             // so append the name string to this...
       
  1510 
       
  1511             contactItem->SetItemNameText( contact->Identification() );
       
  1512             contactItem->SetItemEngineIndex( aIndex );
       
  1513 
       
  1514 
       
  1515             //append this to the array
       
  1516             if ( iSelectionMode == TEnumsPC::ESingleListMultiSelect )
       
  1517                 {
       
  1518                 TInt arrayIndex =  aIndex - iSelectedListIndex ;
       
  1519                 iMainViewListItemArray.Insert( contactItem, arrayIndex );
       
  1520                 }
       
  1521             else
       
  1522                 {
       
  1523                 iMainViewListItemArray.Insert( contactItem, aIndex );
       
  1524                 }
       
  1525 
       
  1526             break;
       
  1527             }
       
  1528         default:
       
  1529             {
       
  1530             // the call shouldn't be here
       
  1531             break;
       
  1532             }
       
  1533         }
       
  1534     // set font if we have listbox data
       
  1535     }
       
  1536 
       
  1537 // -----------------------------------------------------------------------------
       
  1538 // CCAMainViewArrayPC::FillOwnDataL
       
  1539 // FillOwnDataL implementation
       
  1540 // -----------------------------------------------------------------------------
       
  1541 // fill the owndata at the begining of array.....
       
  1542 TBool CCAMainViewArrayPC::FillOwnDataL()
       
  1543     {
       
  1544     TBool ownDataAdded = EFalse;
       
  1545     TBool isLoggedIn( EFalse );
       
  1546 
       
  1547     // Check whether the user has logged in before, if has
       
  1548     // then dont update anything just return
       
  1549 
       
  1550     TPtrC identification( KNullDesC );
       
  1551     TPtrC loggedInUid( KNullDesC );
       
  1552 
       
  1553 
       
  1554     CIMPSSAPSettings* sap = CIMPSSAPSettings::NewLC();
       
  1555 
       
  1556 
       
  1557     TRAPD( err, isLoggedIn = iConnectionUI->LoggedInL( EIMPSConnClientIM ) )
       
  1558 
       
  1559     if ( err )
       
  1560         {
       
  1561         isLoggedIn = EFalse;
       
  1562         //Code scanner warning ignored
       
  1563         CleanupStack::PopAndDestroy();
       
  1564         return ownDataAdded;
       
  1565         }
       
  1566     // if there are no servers then it just returns
       
  1567 
       
  1568     if ( iSAPSettingsStore->SAPCountL( EIMPSIMAccessGroup ) == 0 )
       
  1569         {
       
  1570         //Code scanner warning ignored
       
  1571         CleanupStack::PopAndDestroy();  // sessionSlotId
       
  1572         iContactListIndex = 0;
       
  1573         return ownDataAdded;
       
  1574         }
       
  1575 
       
  1576     if ( !isLoggedIn )
       
  1577         {
       
  1578         //
       
  1579         // if i logged in and logged out it should show the last logged id
       
  1580         if ( iLastloggedinUserId )
       
  1581             {
       
  1582             identification.Set( CCAPCUtils::DisplayId( iLastloggedinUserId->Des() ) );
       
  1583             }
       
  1584         else
       
  1585             {
       
  1586             //the default sap settings have to be read when the apllication opens
       
  1587             iSAPSettingsStore->GetDefaultL( sap, EIMPSIMAccessGroup );
       
  1588 
       
  1589             CHAT_DP( D_CHAT_LIT( "CCAUISessionManager::CurrentSAPLC sap uid %d" ),
       
  1590                      sap->SAPUserId() );
       
  1591             loggedInUid.Set( sap->SAPUserId() );
       
  1592             if ( loggedInUid.Length() == 0 )
       
  1593                 {
       
  1594                 CleanupStack::PopAndDestroy();
       
  1595                 iContactListIndex = 0;
       
  1596                 return ownDataAdded;
       
  1597                 }
       
  1598             identification.Set( CCAPCUtils::DisplayId( loggedInUid ) );
       
  1599             }
       
  1600         }
       
  1601 
       
  1602     else
       
  1603         {
       
  1604         MCAContactListModel::SItem item = iContactListModel.Item( iOwnDataIndex );
       
  1605         if ( item.iType == MCAContactListModel::EOwnStatus )
       
  1606             {
       
  1607             MCAStoredContact* contact = item.iContact;
       
  1608             __CHAT_ASSERT_DEBUG( contact );
       
  1609             identification.Set( contact->Identification() );
       
  1610             if ( iLastloggedinUserId )
       
  1611                 {
       
  1612                 delete iLastloggedinUserId;
       
  1613                 iLastloggedinUserId = NULL;
       
  1614                 }
       
  1615             iLastloggedinUserId = ( contact->Identification() ).AllocL();
       
  1616             }
       
  1617         // This is required as the engine's contactlistmodel
       
  1618         // is not yet initialized immediately after login.
       
  1619         // so get the identification from the connection UI.
       
  1620         else
       
  1621             {
       
  1622             CPEngNWSessionSlotID2* sessionSlotId = NULL;
       
  1623             sessionSlotId = iConnectionUI->GetActiveNWSessionSlotIDL( EIMPSConnClientIM );
       
  1624             CleanupStack::PushL( sessionSlotId );
       
  1625             iConnectionUI->GetLoggedInSapL( *sessionSlotId, *sap );
       
  1626             identification.Set( CCAPCUtils::DisplayId( sap->SAPUserId() ) );
       
  1627             CleanupStack::PopAndDestroy( sessionSlotId );
       
  1628             }
       
  1629         }
       
  1630 
       
  1631     // add this items to contact item -- OWNDATA
       
  1632     // create an object of this type and append this to the rpointerarray
       
  1633 
       
  1634     //create the object here
       
  1635     CCAOwnDataItemPC* ownDataItem = CCAOwnDataItemPC::NewL();
       
  1636 
       
  1637     // so append the name string to this...
       
  1638     ownDataItem->SetItemNameText( identification );
       
  1639 
       
  1640 
       
  1641     ownDataItem->SetItemEngineIndex( iOwnDataIndex );
       
  1642 
       
  1643     //append this to the array
       
  1644     iMainViewListItemArray.Insert( ownDataItem, iOwnDataIndex );
       
  1645     // if this insertion is sucess then only insert open chats folder @ 2nd position..
       
  1646 
       
  1647     ownDataAdded = ETrue;
       
  1648 
       
  1649     //Code scanner warning ignored
       
  1650     CleanupStack::PopAndDestroy(); //  sap
       
  1651 
       
  1652     return ownDataAdded;
       
  1653     }
       
  1654 
       
  1655 #ifdef RD_CHAT_GROUP_MESSAGE_INDICATION_NEW
       
  1656 //-----------------------------------------------------------------------------
       
  1657 // CCAMainViewArrayPC::ChatGroupMessagesPendingCount
       
  1658 // This method is a tweaking of the engine code to return the correct number of
       
  1659 // pending count per user (ie.., all the unread msgs for a single user is equal to one
       
  1660 // pending count.
       
  1661 // ( Other items commented in header )
       
  1662 //-----------------------------------------------------------------------------
       
  1663 TInt CCAMainViewArrayPC::ChatGroupMessagesPendingCount() const
       
  1664     {
       
  1665     TInt count = iChatInterface.GroupCount();
       
  1666     TInt pendingCount = 0;
       
  1667 
       
  1668     for ( TInt i = 0; i < count; ++i )
       
  1669         {
       
  1670         TInt unreadCount = iChatInterface.GroupAt( i ).UnreadCount(
       
  1671                                MCAMessagesReadInterface::EUnreadReceived );
       
  1672         if ( unreadCount > 0 )
       
  1673             {
       
  1674             ++pendingCount;
       
  1675             }
       
  1676         }
       
  1677     return pendingCount;
       
  1678     }
       
  1679 #endif  // RD_CHAT_GROUP_MESSAGE_INDICATION_NEW
       
  1680 // -----------------------------------------------------------------------------
       
  1681 // CCAMainViewArrayPC::RefreshOpenChatsListItemL
       
  1682 // FillOwnDataL implementation
       
  1683 // -----------------------------------------------------------------------------
       
  1684 //
       
  1685 void CCAMainViewArrayPC::RefreshOpenChatsListItemL()
       
  1686     {
       
  1687     // iOpenChatsArray[iOpenChatsIndex -1] make sure that
       
  1688     // we dont pass negative values.
       
  1689 
       
  1690 
       
  1691     if ( iOpenChatsIndex <= 0 )
       
  1692         {
       
  1693         return;
       
  1694         }
       
  1695     CCAOpenChatsListItemPC* openchatsListItem
       
  1696     = dynamic_cast<CCAOpenChatsListItemPC*> (
       
  1697           iOpenChatsArray[iOpenChatsIndex -1] );
       
  1698 
       
  1699     HBufC* textOpenChats = StringLoader::LoadLC(
       
  1700                                R_QTN_CHAT_CONTACTLIST_CHATS );
       
  1701     TPtr openChatsPtr( textOpenChats->Des() );
       
  1702 
       
  1703     // so append the name string to this...
       
  1704     openchatsListItem->SetItemNameText( openChatsPtr );
       
  1705 
       
  1706     CleanupStack::PopAndDestroy( textOpenChats ); // textOpenChats
       
  1707 
       
  1708 
       
  1709     }
       
  1710 // -----------------------------------------------------------------------------
       
  1711 // CCAMainViewArrayPC::FillOpenChatsL
       
  1712 // FillOwnDataL implementation
       
  1713 // -----------------------------------------------------------------------------
       
  1714 // fill the owndata at the begining of array.....
       
  1715 void CCAMainViewArrayPC::FillOpenChatsL()
       
  1716     {
       
  1717     //Populates the list with currently unhandled invitations
       
  1718     TInt chatIndex( 0 );
       
  1719     CCAOpenChatsListItemPC* openchatsListItem = CCAOpenChatsListItemPC::NewL();
       
  1720     //append this to the array and increase to next item here
       
  1721     iOpenChatsArray.Insert( openchatsListItem, chatIndex++ );
       
  1722     openchatsListItem->SetItemEngineIndex( 0/*KInitIndex*/ );
       
  1723 
       
  1724 
       
  1725 
       
  1726     RefreshOpenChatsListItemL();
       
  1727 
       
  1728     TInt groupCount( 0 );
       
  1729     if ( !iGroupCountDown )
       
  1730         {
       
  1731         groupCount = 0;
       
  1732         }
       
  1733     else
       
  1734         {
       
  1735         groupCount = iGroupArray->MdcaCount();
       
  1736         }
       
  1737 
       
  1738     // if openchats is expanded from user or forced expanded.
       
  1739     // if openchats is expanded from user or forced expanded...
       
  1740     if ( !( iOpenChatListItemExpanded || iExpandAll ) )
       
  1741         {
       
  1742         iContactListIndex = 1;
       
  1743         return;
       
  1744         }
       
  1745 
       
  1746     for ( ; chatIndex < iChatInterface.ChatCount() ; chatIndex++ )
       
  1747         {
       
  1748         // check the order in ascending order or not....
       
  1749 
       
  1750         TArrayPairs pair;
       
  1751         pair.iReadInterface = &iChatInterface.ChatAt( chatIndex );
       
  1752 
       
  1753         const TDesC& userId ( pair.iReadInterface->TargetId().Target() );
       
  1754 
       
  1755         TPtrC identification( iContactInterface->Identification( userId ) );
       
  1756         pair.iIdentification.Copy( identification.Left(
       
  1757                                        pair.iIdentification.MaxLength() ) );
       
  1758 
       
  1759         CCAConversationItemPC* conversationItem = CCAConversationItemPC::NewL( userId );
       
  1760 
       
  1761         // so append both and append the string to array...
       
  1762         conversationItem->SetItemNameText( identification );
       
  1763 
       
  1764         conversationItem->SetItemEngineIndex( 0 );
       
  1765 
       
  1766         //append this to the array
       
  1767         iOpenChatsArray.Insert( conversationItem, chatIndex );
       
  1768 
       
  1769         }
       
  1770 
       
  1771     iOpenChatsInActiveIndex = iOpenChatsArray.Count() - 1;
       
  1772 
       
  1773 
       
  1774 
       
  1775     for ( TInt index( 0 ); index < groupCount ; index++, chatIndex++ )
       
  1776         {
       
  1777 
       
  1778         CCAGroupItemPC* groupItem = CCAGroupItemPC::NewL(
       
  1779                                         iChatGroups->FindGroup( iGroupArray->Array()[index]->GroupId() )->GroupId() );
       
  1780 
       
  1781         groupItem->SetItemNameText( iGroupArray->MdcaPoint( index ) );
       
  1782         groupItem->SetItemEngineIndex( 0 );
       
  1783         iOpenChatsArray.Insert( groupItem, chatIndex );
       
  1784         }
       
  1785     /*iContactListIndex = iChatInterface.ChatCount() + iInvitationsArray.Count()
       
  1786                         + groupCount  + 1; // OwnData,Open Chats,chat list if any*/
       
  1787     iContactListIndex = iOpenChatsArray.Count();
       
  1788     }
       
  1789 
       
  1790 
       
  1791 // -----------------------------------------------------------------------------
       
  1792 // CCAMainViewArrayPC::HandleContactDelete
       
  1793 // MCAStoredContactsObserver implementation
       
  1794 // -----------------------------------------------------------------------------
       
  1795 
       
  1796 void CCAMainViewArrayPC::HandleContactDelete( const TDesC& aContactId )
       
  1797     {
       
  1798     CHAT_DP_TXT( "CCAMainViewArrayPC::HandleDelete" );
       
  1799     if ( iSkipStorageEvents )
       
  1800         {
       
  1801         return;
       
  1802         }
       
  1803     RefreshConversationItemText( aContactId );
       
  1804     TRAP_IGNORE ( RefreshInvitationItemTextL( aContactId ) );
       
  1805     ResetArray( EFalse );
       
  1806     for ( TInt index = 0; index < iMainViewObservers.Count(); index++ )
       
  1807         {
       
  1808         iMainViewObservers[index]->HandleDelete( aContactId, TEnumsPC::EContactItem );
       
  1809         }
       
  1810     }
       
  1811 
       
  1812 // -----------------------------------------------------------------------------
       
  1813 // CCAMainViewArrayPC::SetSkipStorageEvents
       
  1814 // MCAStoredContactsObserver implementation
       
  1815 // -----------------------------------------------------------------------------
       
  1816 
       
  1817 void CCAMainViewArrayPC::HandleError( TInt aError )
       
  1818     {
       
  1819     CHAT_DP( D_CHAT_LIT( "CCAMainViewArrayPC::HandleError, aError = %d" ), aError );
       
  1820     if ( ( aError > Imps_ERROR_BASE ) && ( aError < KErrNone ) )
       
  1821         {
       
  1822         // propagate system errors to current active scheduler,
       
  1823         // it should show a note
       
  1824         CActiveScheduler::Current()->Error( aError );
       
  1825         }
       
  1826 
       
  1827     // imps errors are ignored at the moment as we don't have any
       
  1828     // notes specified for them
       
  1829     }
       
  1830 
       
  1831 // -----------------------------------------------------------------------------
       
  1832 // CCAMainViewArrayPC::HandleAddition
       
  1833 // MCAStoredContactsObserver implementation
       
  1834 // -----------------------------------------------------------------------------
       
  1835 
       
  1836 void CCAMainViewArrayPC::HandleAddition( MCAContactList& aList, MCAStoredContact& aContact )
       
  1837     {
       
  1838     if ( iSkipStorageEvents )
       
  1839         {
       
  1840         return;
       
  1841         }
       
  1842     aList.SetCollapsed( EFalse );
       
  1843     RefreshConversationItemText( aContact.UserId() );
       
  1844     TRAP_IGNORE ( RefreshInvitationItemTextL( aContact.UserId() ) );
       
  1845     TInt indexofcontact = iContactListModel.IndexOfContact( &aContact );
       
  1846     ResetArray( EFalse );
       
  1847     for ( TInt index = 0; index < iMainViewObservers.Count(); index++ )
       
  1848         {
       
  1849         iMainViewObservers[index]->HandleAddition( TEnumsPC::EContactItem,
       
  1850                                                    indexofcontact + iContactListIndex );
       
  1851         }
       
  1852     }
       
  1853 // -----------------------------------------------------------------------------
       
  1854 // CCAMainViewArrayPC::HandleChange
       
  1855 // MCAStoredContactsObserver implementation
       
  1856 // Codescanner warning of calling leaving functions inside non-leaving function
       
  1857 // HandleChange is ignored , since we are inheritting the interface MCStoredContactsObserver
       
  1858 // defined on the engine component
       
  1859 // -----------------------------------------------------------------------------
       
  1860 
       
  1861 void CCAMainViewArrayPC::HandleChange( MCAContactList* aList, MCAStoredContact* /*aContact*/,
       
  1862                                        TStorageManagerGlobals::TCAObserverEventType aEventType,
       
  1863                                        TBool /*aUserIdChanged */ )
       
  1864     {
       
  1865     // we need to handle the change here..from storage manager...
       
  1866     CHAT_DP_FUNC_ENTER( "HandleChange" );
       
  1867 
       
  1868 
       
  1869     MCAContactLists* listInterface = NULL;
       
  1870     TRAP_IGNORE( listInterface = CAPresenceManager::InstanceL()->ContactLists() );
       
  1871 
       
  1872     if ( listInterface )
       
  1873         {
       
  1874         TBool isSyncDone = listInterface->IsSyncDone();
       
  1875         TBool ignoreFailed;
       
  1876         MCAStoredContacts* contacts = NULL;
       
  1877         TRAPD( error, contacts = CCAStorageManagerFactory::ContactListInterfaceL() );
       
  1878 
       
  1879         if ( error != KErrNone )
       
  1880             {
       
  1881             return;
       
  1882             }
       
  1883 
       
  1884         if ( contacts )
       
  1885             {
       
  1886             if ( contacts->IsAllSynchronised( ignoreFailed ) && isSyncDone && !iForceExpandDone )
       
  1887                 {
       
  1888                 NotifySyncCompleted();
       
  1889                 //check if there only 1 list or not.......
       
  1890                 if ( contacts->ListCount() == 1 )
       
  1891                     {
       
  1892                     // now forcefully expand....the list..
       
  1893                     // get the correct list count....
       
  1894                     TInt contactListIndex = KInitIndex;
       
  1895                     if ( iSelectionMode == TEnumsPC::ESingleListViewSelect )
       
  1896                         {
       
  1897                         contactListIndex = iOwnDataIndex + 1; // it's 1 if there is only list....
       
  1898                         }
       
  1899                     else
       
  1900                         {
       
  1901                         contactListIndex = iContactListIndex; // should be zero
       
  1902                         }
       
  1903                     MCAContactListModel::SItem item = iContactListModel.Item( contactListIndex );
       
  1904 
       
  1905                     if ( item.iType == MCAContactListModel::EContactList )
       
  1906                         {
       
  1907                         MCAContactList* list = item.iContactList;
       
  1908                         if ( list )
       
  1909                             {
       
  1910 
       
  1911                             list->SetCollapsed( EFalse );
       
  1912                             iForceExpandDone = ETrue;
       
  1913                             }
       
  1914                         }
       
  1915                     }
       
  1916                 }
       
  1917             }
       
  1918         }
       
  1919 
       
  1920     TEnumsPC::TChange eventtype = TEnumsPC::EUnknownEvent;
       
  1921     if ( iSkipStorageEvents )
       
  1922         {
       
  1923         return;
       
  1924         }
       
  1925 
       
  1926     TInt error( KErrNone );
       
  1927     switch ( aEventType )
       
  1928         {
       
  1929         case TStorageManagerGlobals::EStorageEventPreChange:
       
  1930             {
       
  1931             /*CHAT_DP_TXT("CCAMainViewArrayPC::HandleChange ignoring pre-change event");
       
  1932             TEnumsPC::TItem itemType = ( aList && aContact == NULL)?
       
  1933                                                TEnumsPC::EContactListItem:
       
  1934                                                           TEnumsPC::EContactItem;
       
  1935             TInt indexoflist
       
  1936             if( TEnumsPC::EContactListItem ==  itemType )
       
  1937                 {
       
  1938                 indexoflist = iContactListModel.IndexOfList(aList,EFalse,ETrue);
       
  1939                 }
       
  1940             else if( TEnumsPC::EContactItem ==  itemType  )
       
  1941                 {
       
  1942                 indexoflist = iContactListModel.IndexOfContact( aContact )
       
  1943                 }
       
  1944 
       
  1945             for (TInt index=0; index<iMainViewObservers.Count(); index++)
       
  1946             	{
       
  1947             	iMainViewObservers[index]->HandleChange( itemType
       
  1948                	 			         iContactListIndex + indexoflist,
       
  1949                	 			         TEnumsPC::EPreChange );
       
  1950             	}
       
  1951             */
       
  1952             // ignore the pre-change events
       
  1953             return;
       
  1954             }
       
  1955         case TStorageManagerGlobals::EStorageEventListDelete:
       
  1956         case TStorageManagerGlobals::EStorageEventMultipleChanges:
       
  1957             {
       
  1958             // When logged out, items are removed from list. So for to be sure
       
  1959             // call handleItemRemoval.
       
  1960             ResetArray( EFalse );
       
  1961             TInt indexoflist = iContactListModel.IndexOfList( aList, EFalse, ETrue );
       
  1962             eventtype = aEventType == TStorageManagerGlobals::EStorageEventListDelete
       
  1963                         ? TEnumsPC::EDelete : TEnumsPC::EMultipleChanges;
       
  1964             for ( TInt index = 0; index < iMainViewObservers.Count(); index++ )
       
  1965                 {
       
  1966                 iMainViewObservers[index]->HandleChange( TEnumsPC::EContactListItem,
       
  1967                                                          iContactListIndex + indexoflist, eventtype );
       
  1968                 }
       
  1969 
       
  1970             break;
       
  1971             }
       
  1972         case TStorageManagerGlobals::EStorageEventPostChange:
       
  1973             {
       
  1974             // there might be new or removed contacts
       
  1975             ResetArray( EFalse );
       
  1976 
       
  1977 
       
  1978             // call back the UI with HandleChange here....
       
  1979             TInt indexoflist = iContactListModel.IndexOfList( aList, EFalse, ETrue );
       
  1980             for ( TInt index = 0; index < iMainViewObservers.Count(); index++ )
       
  1981                 {
       
  1982                 iMainViewObservers[index]->HandleChange( TEnumsPC::EContactItem,
       
  1983                                                          iContactListIndex + indexoflist, TEnumsPC::EChanged );
       
  1984                 }
       
  1985             break;
       
  1986             }
       
  1987         case TStorageManagerGlobals::EStorageEventListAddition:
       
  1988         case TStorageManagerGlobals::EStorageEventListChanged:
       
  1989             {
       
  1990             if ( aEventType == TStorageManagerGlobals::EStorageEventListAddition )
       
  1991                 {
       
  1992 
       
  1993                 // call back the UI with HandleChange here....
       
  1994 
       
  1995                 iForceExpandDone = EFalse;
       
  1996                 }
       
  1997 
       
  1998             ResetArray( EFalse );
       
  1999 
       
  2000             TInt indexoflist = iContactListModel.IndexOfList( aList, EFalse, ETrue );
       
  2001             eventtype = aEventType == TStorageManagerGlobals::EStorageEventListAddition
       
  2002                         ? TEnumsPC::EAddition : TEnumsPC::EChanged;
       
  2003             for ( TInt index = 0; index < iMainViewObservers.Count(); index++ )
       
  2004                 {
       
  2005                 iMainViewObservers[index]->HandleChange( TEnumsPC::EContactListItem,
       
  2006                                                          iContactListIndex + indexoflist, eventtype );
       
  2007                 }
       
  2008             break;
       
  2009             }
       
  2010         default:
       
  2011             {
       
  2012             break;
       
  2013             }
       
  2014         }
       
  2015 
       
  2016     if ( error )
       
  2017         {
       
  2018         CActiveScheduler::Current()->Error( error );
       
  2019         }
       
  2020 
       
  2021     }
       
  2022 
       
  2023 // ---------------------------------------------------------
       
  2024 // CCAMainViewArrayPC::HandleWatcherEvent
       
  2025 // @see MCAWatcherObserver
       
  2026 // MCAwatcherobserver events..
       
  2027 // ---------------------------------------------------------
       
  2028 
       
  2029 void CCAMainViewArrayPC::HandleWatcherEvent( const MCAStoredContact* aContact )
       
  2030     {
       
  2031     if ( !aContact  || ( aContact->OnlineStatus() == TStorageManagerGlobals::EUnknown ) )
       
  2032         {
       
  2033         return;
       
  2034         }
       
  2035 
       
  2036     // now call back UI....with onlinestatus......
       
  2037     // first parameter is text and second parameter is online status...
       
  2038     for ( TInt observer( 0 ) ; observer < iMainViewObservers.Count(); observer++ )
       
  2039         {
       
  2040         iMainViewObservers[observer]->HandleWatcherEvent( aContact->Identification(),
       
  2041                                                           GetOnlineStatusConverter( aContact->OnlineStatus() ) );
       
  2042         }
       
  2043     }
       
  2044 
       
  2045 
       
  2046 // ---------------------------------------------------------
       
  2047 // CCAMainViewArrayPC::HandleWatcherEvent
       
  2048 // @see MCASettingsObserver
       
  2049 // ---------------------------------------------------------
       
  2050 
       
  2051 void CCAMainViewArrayPC::HandleSettingsChangeL( TInt aChangedSettingEnum )
       
  2052     {
       
  2053 
       
  2054     ResetArray( EFalse );
       
  2055     TInt count = iMainViewObservers.Count();
       
  2056     for ( TInt obs = 0; obs < count; obs++  )
       
  2057         {
       
  2058         TEnumsPC::TCASettingValues settings = ConvertToEnumsPC( aChangedSettingEnum );
       
  2059 
       
  2060         iMainViewObservers[obs]->HandleSettingsChangeL( settings );
       
  2061         }
       
  2062 
       
  2063     }
       
  2064 
       
  2065 // ---------------------------------------------------------
       
  2066 // CCAMainViewArrayPC::GetResourceValueL
       
  2067 // remove this from here and place it in common utils dll.
       
  2068 // ---------------------------------------------------------
       
  2069 
       
  2070 TInt CCAMainViewArrayPC::GetResourceValueL( TInt aResourceID )
       
  2071     {
       
  2072     TInt value( KErrNone );
       
  2073     TResourceReader reader;
       
  2074     CCoeEnv::Static()->CreateResourceReaderLC( reader, aResourceID );
       
  2075     value = ResourceUtils::ReadTInt32L( reader );
       
  2076     //Codescanner warning ignored
       
  2077     CleanupStack::PopAndDestroy(); // reader
       
  2078 
       
  2079     return value;
       
  2080     }
       
  2081 // ---------------------------------------------------------
       
  2082 // CCAMainViewArrayPC::AddObserverL
       
  2083 // From MCAMainViewObserverManagerPC
       
  2084 // ---------------------------------------------------------
       
  2085 
       
  2086 void CCAMainViewArrayPC::AddObserverL( MCAMainViewObserverPC* aObserver )
       
  2087     {
       
  2088 
       
  2089     ASSERT( aObserver );
       
  2090 
       
  2091     TInt status( iMainViewObservers.Find( aObserver ) );
       
  2092     if ( status == KErrNotFound )
       
  2093         {
       
  2094         status = iMainViewObservers.Append( aObserver ) ;
       
  2095         User::LeaveIfError( status );
       
  2096         }
       
  2097     }
       
  2098 // ---------------------------------------------------------
       
  2099 // CCAMainViewArrayPC::RemoveObserver
       
  2100 // From MCAMainViewObserverManagerPC
       
  2101 // ---------------------------------------------------------
       
  2102 
       
  2103 void CCAMainViewArrayPC::RemoveObserver( MCAMainViewObserverPC* aObserver )
       
  2104     {
       
  2105 
       
  2106     ASSERT( aObserver );
       
  2107 
       
  2108     const TInt status( iMainViewObservers.Find( aObserver ) );
       
  2109     if ( status != KErrNotFound )
       
  2110         {
       
  2111         iMainViewObservers.Remove( status );
       
  2112         iMainViewObservers.Compress();
       
  2113         }
       
  2114     }
       
  2115 
       
  2116 
       
  2117 // ---------------------------------------------------------
       
  2118 // CCAMainViewArrayPC::AddObserverL
       
  2119 // From MCAMainViewObserverManagerPC
       
  2120 // ---------------------------------------------------------
       
  2121 
       
  2122 void CCAMainViewArrayPC::AddObserver( MCASyncObserverPC* aObserver )
       
  2123     {
       
  2124     ASSERT( aObserver );
       
  2125     iSyncObserver = aObserver;
       
  2126     }
       
  2127 // ---------------------------------------------------------
       
  2128 // CCAMainViewArrayPC::RemoveObserver
       
  2129 // From MCAMainViewObserverManagerPC
       
  2130 // ---------------------------------------------------------
       
  2131 
       
  2132 void CCAMainViewArrayPC::RemoveObserver( )
       
  2133     {
       
  2134     if ( iSyncObserver )
       
  2135         {
       
  2136         iSyncObserver = NULL;
       
  2137         }
       
  2138     }
       
  2139 
       
  2140 
       
  2141 // ---------------------------------------------------------
       
  2142 // CCAMainViewArrayPC::GetSelectedContactAlias
       
  2143 // ---------------------------------------------------------
       
  2144 
       
  2145 const TDesC& CCAMainViewArrayPC::GetSelectedContactAlias( TInt aIndex )
       
  2146     {
       
  2147     TInt index = GetItemEngineIndex( aIndex );
       
  2148     TEnumsPC::TItem itemtype = GetType( aIndex );
       
  2149     MCAContactListModel::SItem item;
       
  2150     if ( itemtype == TEnumsPC::EContactItem  )
       
  2151         {
       
  2152         item = iContactListModel.Item( index );
       
  2153         MCAStoredContact* contact = item.iContact;
       
  2154         return contact->Alias();
       
  2155         }
       
  2156     return KNullDesC;
       
  2157     }
       
  2158 
       
  2159 // ---------------------------------------------------------
       
  2160 // CCAMainViewArrayPC::GetSelectedContactNickname
       
  2161 // ---------------------------------------------------------
       
  2162 
       
  2163 const TDesC& CCAMainViewArrayPC::GetSelectedContactNickname( TInt aIndex )
       
  2164     {
       
  2165 
       
  2166     TInt index = GetItemEngineIndex( aIndex );
       
  2167     TEnumsPC::TItem itemtype = GetType( aIndex );
       
  2168 
       
  2169     MCAContactListModel::SItem item;
       
  2170     if ( itemtype == TEnumsPC::EContactItem  )
       
  2171         {
       
  2172         item = iContactListModel.Item( index );
       
  2173         MCAStoredContact* contact = item.iContact;
       
  2174         return contact->Nickname();
       
  2175         }
       
  2176     return KNullDesC;
       
  2177     }
       
  2178 
       
  2179 // ---------------------------------------------------------
       
  2180 // CCAMainViewArrayPC::GetSelectedContactUserId
       
  2181 // ---------------------------------------------------------
       
  2182 
       
  2183 const TDesC& CCAMainViewArrayPC::GetSelectedContactUserId( TInt aIndex )
       
  2184     {
       
  2185     TEnumsPC::TItem itemtype = GetType( aIndex );
       
  2186     TInt index = GetItemEngineIndex( aIndex );
       
  2187     switch ( itemtype )
       
  2188         {
       
  2189         case TEnumsPC::EContactItem:
       
  2190             {
       
  2191             MCAContactListModel::SItem item = iContactListModel.Item( index );
       
  2192             MCAStoredContact* contact = item.iContact;
       
  2193             return contact->UserId();
       
  2194             }
       
  2195 
       
  2196         case TEnumsPC::EConversationItem:
       
  2197             {
       
  2198             /* Codescanner warning is ignored, since Bound check is done
       
  2199               * inside the GetType()
       
  2200              * method*/
       
  2201             TInt chatIndex = aIndex - ( iOpenChatsIndex );
       
  2202             CCAConversationItemPC* conversationItem =
       
  2203                 dynamic_cast< CCAConversationItemPC* > ( iOpenChatsArray[ chatIndex ] );
       
  2204             return conversationItem->UserId();
       
  2205             }
       
  2206         case TEnumsPC::EInviteItem:
       
  2207             {
       
  2208             /* Codescanner warning is ignored, since Bound check is done
       
  2209              * inside the GetType()
       
  2210              * method*/
       
  2211             TInt chatIndex = aIndex - ( iOpenChatsIndex );
       
  2212             CCAInviteItemPC* inviteItem =
       
  2213                 dynamic_cast< CCAInviteItemPC* > ( iOpenChatsArray[ chatIndex ] );
       
  2214             return inviteItem->UserId();
       
  2215             }
       
  2216         case TEnumsPC::EGroupItem:
       
  2217             {
       
  2218             /* Codescanner warning is ignored, since Bound check is done
       
  2219              * inside the GetType()
       
  2220              * method*/
       
  2221             TInt chatIndex = aIndex - ( iOpenChatsIndex );
       
  2222             CCAGroupItemPC* groupItem =
       
  2223                 dynamic_cast< CCAGroupItemPC* > ( iOpenChatsArray[ chatIndex ] );
       
  2224             return groupItem->GroupId();
       
  2225             }
       
  2226         default:
       
  2227             break;
       
  2228         }
       
  2229 
       
  2230     return KNullDesC;
       
  2231     }
       
  2232 
       
  2233 // ---------------------------------------------------------
       
  2234 // CCAMainViewArrayPC::GetSelectedListId
       
  2235 // ---------------------------------------------------------
       
  2236 const TDesC& CCAMainViewArrayPC::GetSelectedListId( TInt aIndex )
       
  2237     {
       
  2238     TEnumsPC::TItem itemType = GetType( aIndex );
       
  2239 
       
  2240     TInt index = GetItemEngineIndex( aIndex );
       
  2241 
       
  2242     MCAContactListModel::SItem item = iContactListModel.Item( index );
       
  2243     MCAContactList* list = NULL;
       
  2244 
       
  2245     switch ( itemType )
       
  2246         {
       
  2247         case TEnumsPC::EContactItem:
       
  2248             {
       
  2249             list = item.iContactList;
       
  2250             break;
       
  2251             }
       
  2252 
       
  2253         case TEnumsPC::EContactListItem:
       
  2254             {
       
  2255             list = item.iContactList;
       
  2256             break;
       
  2257             }
       
  2258         case TEnumsPC::EInviteItem:
       
  2259         case TEnumsPC::EConversationItem:
       
  2260         case TEnumsPC::EGroupItem:
       
  2261         case TEnumsPC::EOpenChatsListItem:
       
  2262             {
       
  2263 
       
  2264             break;
       
  2265             }
       
  2266 
       
  2267         default:
       
  2268             break;
       
  2269 
       
  2270         }
       
  2271 
       
  2272     if ( list )
       
  2273         {
       
  2274         return list->ListId();
       
  2275         }
       
  2276     return KNullDesC;
       
  2277     }
       
  2278 
       
  2279 // ---------------------------------------------------------
       
  2280 // CCAMainViewArrayPC::GetSelectedContactIdentification
       
  2281 // ---------------------------------------------------------
       
  2282 const TDesC& CCAMainViewArrayPC::GetSelectedContactIdentification( TInt aIndex )
       
  2283     {
       
  2284     TEnumsPC::TItem itemtype = GetType( aIndex );
       
  2285 
       
  2286     TInt index = GetItemEngineIndex( aIndex );
       
  2287     switch ( itemtype )
       
  2288         {
       
  2289         case TEnumsPC::EContactItem:
       
  2290         case TEnumsPC::EOwnStatusItem:
       
  2291             {
       
  2292             MCAContactListModel::SItem item = iContactListModel.Item( index );
       
  2293             MCAStoredContact* contact = item.iContact;
       
  2294             return contact->Identification();
       
  2295             }
       
  2296         /*case TEnumsPC::EContactListItem:
       
  2297         		{
       
  2298         		MCAContactListModel::SItem item = iContactListModel.Item( index );
       
  2299         		MCAContactList& list = *item.iContactList;
       
  2300         		list
       
  2301         		}*/
       
  2302         case TEnumsPC::EConversationItem:
       
  2303             {
       
  2304             /* Codescanner warning is ignored, since Bound check is done
       
  2305              * inside the GetType()
       
  2306              * method*/
       
  2307             CCAConversationItemPC* conversationItem =
       
  2308                 dynamic_cast< CCAConversationItemPC* > ( iOpenChatsArray[ index ] );
       
  2309             return conversationItem->Identification();
       
  2310             }
       
  2311         case TEnumsPC::EInviteItem:
       
  2312             {
       
  2313             /* Codescanner warning is ignored, since Bound check is done
       
  2314              * inside the GetType()
       
  2315              * method*/
       
  2316             CCAInviteItemPC* inviteItem =
       
  2317                 dynamic_cast< CCAInviteItemPC* > ( iOpenChatsArray[ index] );
       
  2318             return inviteItem->Identification();
       
  2319             }
       
  2320         case TEnumsPC::EGroupItem:
       
  2321             {
       
  2322             /* Codescanner warning is ignored, since Bound check is done
       
  2323              * inside the GetType()
       
  2324              * method*/
       
  2325             CCAGroupItemPC* groupItem =
       
  2326                 dynamic_cast< CCAGroupItemPC* > ( iOpenChatsArray[ index] );
       
  2327             return groupItem->Identification();
       
  2328             }
       
  2329         default:
       
  2330             break;
       
  2331         }
       
  2332 
       
  2333     return KNullDesC;
       
  2334     }
       
  2335 
       
  2336 //-----------------------------------------------------------
       
  2337 //CCAMainViewArrayPC::IgnoreOfflineStatusL
       
  2338 //-----------------------------------------------------------
       
  2339 TInt CCAMainViewArrayPC::IgnoreOfflineStatusL( TInt aIndex )
       
  2340     {
       
  2341     TInt index = GetItemEngineIndex( aIndex );
       
  2342     TEnumsPC::TItem itemtype = GetType( aIndex );
       
  2343     if ( itemtype != TEnumsPC::EOwnStatusItem && itemtype != TEnumsPC::EContactItem )
       
  2344         {
       
  2345         return TEnumsPC::EUnknown;
       
  2346         }
       
  2347 
       
  2348     MCAContactListModel::SItem item = iContactListModel.Item( index );
       
  2349     MCAStoredContact* contact = item.iContact;
       
  2350     if ( !contact )
       
  2351         {
       
  2352         User::Leave( KErrNotFound );
       
  2353         }
       
  2354     TStorageManagerGlobals::TPresenceStatus onlineStatus(
       
  2355         contact->OnlineStatus() );
       
  2356     TBool contactOnline( onlineStatus == TStorageManagerGlobals::EOnline ||
       
  2357                          onlineStatus == TStorageManagerGlobals::EAway ||
       
  2358                          onlineStatus == TStorageManagerGlobals::EBusy );
       
  2359 
       
  2360     if ( contactOnline )
       
  2361         {
       
  2362         return TEnumsPC::EOnline;
       
  2363         }
       
  2364 
       
  2365     return TEnumsPC::EUnknown;
       
  2366     }
       
  2367 
       
  2368 //-----------------------------------------------------------
       
  2369 //CCAMainViewArrayPC::MessageReadInterfaceL
       
  2370 //-----------------------------------------------------------
       
  2371 void CCAMainViewArrayPC::SetMessageReadInterfaceL( TInt aIndex )
       
  2372     {
       
  2373     TInt index = GetItemEngineIndex( aIndex );
       
  2374     TEnumsPC::TItem itemtype = GetType( aIndex );
       
  2375     if ( itemtype != TEnumsPC::EOwnStatusItem && itemtype != TEnumsPC::EContactItem )
       
  2376         {
       
  2377         return;
       
  2378         }
       
  2379     MCAContactListModel::SItem item = iContactListModel.Item( index );
       
  2380     MCAStoredContact* contact = item.iContact;
       
  2381 
       
  2382     if ( !contact )
       
  2383         {
       
  2384         User::Leave( KErrNotFound );
       
  2385         }
       
  2386 
       
  2387     TPtrC userId( contact->UserId() );
       
  2388 
       
  2389     CHAT_DP( D_CHAT_LIT( " Trying to find chat data for %S" ), &userId );
       
  2390 
       
  2391     iChatInterface.MessageReadInterfaceL( KNullDesC, KNullDesC, userId );
       
  2392     }
       
  2393 
       
  2394 //-----------------------------------------------------------
       
  2395 //CCAMainViewArrayPC::ChatExistsL
       
  2396 //-----------------------------------------------------------
       
  2397 TBool CCAMainViewArrayPC::ChatExistsL( TInt aIndex )
       
  2398     {
       
  2399     TPtrC userId( KNullDesC() );
       
  2400 
       
  2401     TInt index = GetItemEngineIndex( aIndex );
       
  2402 
       
  2403     TEnumsPC::TItem itemtype = GetType( aIndex );
       
  2404 
       
  2405     switch ( itemtype )
       
  2406         {
       
  2407         case TEnumsPC::EConversationItem:
       
  2408             {
       
  2409             /*if (aIndex - iOpenChatsIndex >= iChatInterface.ChatCount())
       
  2410             	{
       
  2411             	User::Leave( KErrNotFound );
       
  2412             	}*/
       
  2413             /* Codescanner warning is ignored, since Bound check is done
       
  2414              * inside the GetType()
       
  2415              * method*/
       
  2416             CCAConversationItemPC* conversationItem =
       
  2417                 dynamic_cast< CCAConversationItemPC* > ( iOpenChatsArray[ index] );
       
  2418             userId.Set( conversationItem->UserId() );
       
  2419             break;
       
  2420             }
       
  2421         case TEnumsPC::EContactItem:
       
  2422             {
       
  2423             MCAContactListModel::SItem item = iContactListModel.Item( index );
       
  2424 
       
  2425             MCAStoredContact* contact = item.iContact;
       
  2426 
       
  2427             if ( !contact )
       
  2428                 {
       
  2429                 User::Leave( KErrNotFound );
       
  2430                 }
       
  2431 
       
  2432             userId.Set( contact->UserId() );
       
  2433 
       
  2434             break;
       
  2435             }
       
  2436         default:
       
  2437             break;
       
  2438         }
       
  2439 
       
  2440     CHAT_DP( D_CHAT_LIT( " Trying to find chat data for %S" ), &userId );
       
  2441 
       
  2442     MCAMessagesReadInterface* messageReadInterface
       
  2443     =  iChatInterface.ChatExistsL( KNullDesC, KNullDesC, userId );
       
  2444 
       
  2445     if ( !messageReadInterface )
       
  2446         {
       
  2447         return EFalse;
       
  2448         }
       
  2449     else
       
  2450         {
       
  2451         return ETrue;
       
  2452         }
       
  2453     }
       
  2454 
       
  2455 //-----------------------------------------------------------
       
  2456 //CCAMainViewArrayPC::IndexOfList
       
  2457 //-----------------------------------------------------------
       
  2458 
       
  2459 TInt CCAMainViewArrayPC::IndexOfList( TInt aIndex, TBool aIgnoreOwnItem,
       
  2460                                       TBool aIgnoreEmptyLists ) const
       
  2461     {
       
  2462     TInt curIndex = 0;
       
  2463 
       
  2464 
       
  2465     TEnumsPC::TItem itemtype = GetType( aIndex );
       
  2466 
       
  2467     switch ( itemtype )
       
  2468         {
       
  2469         case TEnumsPC::EContactItem:
       
  2470             {
       
  2471             TInt index( 0 );
       
  2472             if ( iSelectionMode == TEnumsPC::ESingleListMultiSelect )
       
  2473                 {
       
  2474                 index =   aIndex <= 0 ? 0 : ( aIndex  + iSelectedListIndex ) ;
       
  2475                 }
       
  2476             else
       
  2477                 {
       
  2478                 index = GetItemEngineIndex( aIndex );
       
  2479 
       
  2480                 }
       
  2481             MCAContactListModel::SItem item = iContactListModel.Item( index );
       
  2482             MCAContactList& list = *item.iContactList;
       
  2483             curIndex = iContactListModel.IndexOfList( &list, aIgnoreOwnItem, aIgnoreEmptyLists )
       
  2484                        + iContactListIndex - iSelectedListIndex; // 1 for open chats folder
       
  2485             if ( curIndex < 0 || curIndex >= Count() )
       
  2486                 {
       
  2487                 return 0;
       
  2488                 }
       
  2489             break;
       
  2490             }	// return the curindex of contac list items
       
  2491         case TEnumsPC::EContactListItem:
       
  2492             {
       
  2493             return aIndex; // this is index of contact list
       
  2494             }
       
  2495         case TEnumsPC::EOpenChatsListItem:
       
  2496         case TEnumsPC::EConversationItem:
       
  2497         case TEnumsPC::EInviteItem:
       
  2498         case TEnumsPC::EGroupItem:
       
  2499             {
       
  2500             curIndex = iOpenChatsIndex; // this is index of open chats list
       
  2501             // return the index of open chats from here..
       
  2502             break;
       
  2503             }
       
  2504 
       
  2505         default:
       
  2506             {
       
  2507             break;
       
  2508             }
       
  2509         }
       
  2510     return curIndex;
       
  2511     }
       
  2512 //-----------------------------------------------------------
       
  2513 //CCAMainViewArrayPC:: FindContactListIndexL
       
  2514 //-----------------------------------------------------------
       
  2515 TInt CCAMainViewArrayPC::FindContactListIndexL( const TDesC& aListId )
       
  2516     {
       
  2517     MCAStoredContacts* contacts = CCAStorageManagerFactory::ContactListInterfaceL();
       
  2518     // check the display id's of local lists
       
  2519     MCAContactList* contactList = contacts->FindContactList( aListId );
       
  2520 
       
  2521     // now get the index of this list...
       
  2522     return iContactListIndex + iContactListModel.IndexOfList( contactList ); // return the index of list..
       
  2523     }
       
  2524 //-----------------------------------------------------------
       
  2525 //CCAMainViewArrayPC::IsSyncDoneL
       
  2526 //-----------------------------------------------------------
       
  2527 
       
  2528 TBool CCAMainViewArrayPC::IsSyncDoneL()
       
  2529     {
       
  2530     MCAContactLists* listInterface =
       
  2531         CAPresenceManager::InstanceL()->ContactLists();
       
  2532 
       
  2533     return listInterface->IsSyncDone();
       
  2534     }
       
  2535 
       
  2536 //-----------------------------------------------------------
       
  2537 //CCAMainViewArrayPC::CreateContactListL
       
  2538 //-----------------------------------------------------------
       
  2539 TInt CCAMainViewArrayPC::CreateContactListL( const TDesC& aDisplayName , TInt& aIndex )
       
  2540     {
       
  2541     MCAPresence* presence = CAPresenceManager::InstanceL();
       
  2542     MCAContactLists* contactLists = presence->ContactLists();
       
  2543     TInt err = contactLists->CreateContactListL( aDisplayName );
       
  2544 
       
  2545     if ( err != KErrNone )
       
  2546         {
       
  2547         return err;
       
  2548         }
       
  2549     else
       
  2550         {
       
  2551         MCAStoredContacts* contacts = CCAStorageManagerFactory::ContactListInterfaceL();
       
  2552 
       
  2553         contacts->SortContactLists();
       
  2554 
       
  2555         TInt listCount = contacts->ListCount();
       
  2556 
       
  2557         for ( TInt index( 0 ); index < listCount; ++index )
       
  2558             {
       
  2559             MCAContactList& contactList = contacts->ListAt( index ) ;
       
  2560             if ( contactList.DisplayName() == aDisplayName )
       
  2561                 {
       
  2562                 aIndex = FindContactListIndexL( contactList.ListId() );
       
  2563                 break;
       
  2564                 }
       
  2565 
       
  2566             }
       
  2567         }
       
  2568     return err;
       
  2569     }
       
  2570 
       
  2571 //-----------------------------------------------------------
       
  2572 //CCAMainViewArrayPC::ListAlreadyExistsL
       
  2573 //-----------------------------------------------------------
       
  2574 TInt CCAMainViewArrayPC::ListAlreadyExistsL( const TPtr aNamePtr )
       
  2575     {
       
  2576     // check the display id's of local lists
       
  2577     MCAStoredContacts* contacts = CCAStorageManagerFactory::ContactListInterfaceL();
       
  2578     if ( !contacts )
       
  2579         {
       
  2580         return KErrUnknown;
       
  2581         }
       
  2582     TInt count( contacts->ListCount() );
       
  2583     TInt err( KErrNone );
       
  2584 
       
  2585     // get the standard method
       
  2586     TCollationMethod m = *Mem::CollationMethodByIndex( 0 );
       
  2587     // dont ignore punctuation and spaces
       
  2588     m.iFlags |= TCollationMethod::EIgnoreNone;
       
  2589 
       
  2590     for ( TInt i( 0 ); i < count && err == KErrNone; ++i )
       
  2591         {
       
  2592 
       
  2593         TPtrC displayName = contacts->ListAt( i ).DisplayName();
       
  2594         if ( displayName.CompareC( aNamePtr, KCollationLevel, &m ) == 0 )
       
  2595             {
       
  2596             // list with this name already exists
       
  2597             err = KErrAlreadyExists;
       
  2598             }
       
  2599         }
       
  2600     return err;
       
  2601     }
       
  2602 
       
  2603 //-----------------------------------------------------------
       
  2604 //CCAMainViewArrayPC::ContactListsExistL
       
  2605 //-----------------------------------------------------------
       
  2606 TInt CCAMainViewArrayPC::ContactListsExistL()
       
  2607     {
       
  2608     MCAPresence* presence = CAPresenceManager::InstanceL();
       
  2609     MCAContactLists* contactLists = presence->ContactLists();
       
  2610 
       
  2611     if ( !contactLists )
       
  2612         {
       
  2613         return KErrGeneral;
       
  2614         }
       
  2615     else
       
  2616         {
       
  2617         return KErrNone;
       
  2618         }
       
  2619     }
       
  2620 //-----------------------------------------------------------
       
  2621 //CCAMainViewArrayPC::CountOfContactsInList
       
  2622 //-----------------------------------------------------------
       
  2623 TInt CCAMainViewArrayPC::CountOfContactsInList( TInt aIndex )
       
  2624     {
       
  2625     TInt count = 0;
       
  2626     TInt index = GetItemEngineIndex( aIndex );
       
  2627 
       
  2628     TEnumsPC::TItem itemtype = GetType( aIndex );
       
  2629 
       
  2630     switch ( itemtype )
       
  2631         {
       
  2632         case TEnumsPC::EContactListItem:
       
  2633             {
       
  2634 
       
  2635             MCAContactListModel::SItem item = iContactListModel.Item( index );
       
  2636             MCAContactList& list = *item.iContactList;
       
  2637             count = list.Count();
       
  2638             break;
       
  2639             }	// return the curindex of contac list items..
       
  2640         case TEnumsPC::EOpenChatsListItem:
       
  2641             {
       
  2642             count = iOpenChatsArray.Count() - 1;
       
  2643 
       
  2644             // return the index of open chats from here..
       
  2645             break;
       
  2646             }
       
  2647         default:
       
  2648             {
       
  2649             break;
       
  2650             }
       
  2651         }
       
  2652 
       
  2653     return count;
       
  2654     }
       
  2655 
       
  2656 //-----------------------------------------------------------
       
  2657 //CCAMainViewArrayPC::ListCountL
       
  2658 //-----------------------------------------------------------
       
  2659 TInt CCAMainViewArrayPC::ListCountL() const
       
  2660     {
       
  2661     MCAStoredContacts* contacts =
       
  2662         CCAStorageManagerFactory::ContactListInterfaceL();
       
  2663     TInt count( contacts->ListCount() );
       
  2664 
       
  2665     return count;
       
  2666     }
       
  2667 
       
  2668 //-----------------------------------------------------------
       
  2669 //MCAMainViewArrayPC::DeleteContactListL
       
  2670 //-----------------------------------------------------------
       
  2671 TInt CCAMainViewArrayPC::DeleteContactListL( TInt aIndex )
       
  2672     {
       
  2673     TInt err = KErrNone;
       
  2674 
       
  2675     MCAPresence* presence = CAPresenceManager::InstanceL();
       
  2676     MCAContactLists* contactLists = presence->ContactLists();
       
  2677     if ( !contactLists )
       
  2678         {
       
  2679         return KErrGeneral;
       
  2680         }
       
  2681 
       
  2682     TInt index = GetItemEngineIndex( aIndex );
       
  2683 
       
  2684     MCAContactListModel::SItem item = iContactListModel.Item( index );
       
  2685     MCAContactList& list = *item.iContactList;
       
  2686 
       
  2687 #ifdef IMPS_CONTACT_FETCH_BACKGROUND
       
  2688     TBool failedList = list.Synchronised() != MCAContactList::ESynchroniseDone;
       
  2689 #endif // IMPS_CONTACT_FETCH_BACKGROUND   
       
  2690 
       
  2691     err = contactLists->DeleteContactListL( list.ListId()
       
  2692 #ifdef IMPS_CONTACT_FETCH_BACKGROUND
       
  2693                                             , failedList
       
  2694 #endif
       
  2695                                           );
       
  2696 
       
  2697     //This code may not be needed if the server contact deletion
       
  2698     //will do a handledelete callback. Then it will do a refresharray entirely.
       
  2699     if ( err == KErrNone )
       
  2700         {
       
  2701 #ifdef IMPS_CONTACT_FETCH_BACKGROUND
       
  2702         // need to check in  IMPS_CONTACT_FETCH_BACKGROUND disabled state
       
  2703         ResetArray( EFalse );
       
  2704 
       
  2705 #endif
       
  2706         }
       
  2707     return err;
       
  2708 
       
  2709     }
       
  2710 
       
  2711 //-----------------------------------------------------------
       
  2712 //CCAMainViewArrayPC::DeleteServerContactL
       
  2713 //-----------------------------------------------------------
       
  2714 TInt CCAMainViewArrayPC::DeleteServerContactL( TInt aIndex )
       
  2715     {
       
  2716     TInt index = GetItemEngineIndex( aIndex );
       
  2717 
       
  2718     TEnumsPC::TItem itemtype = GetType( aIndex );
       
  2719     TInt err = KErrGeneral;
       
  2720     if ( itemtype == TEnumsPC::EContactListItem || itemtype == TEnumsPC::EContactItem )
       
  2721         {
       
  2722         MCAPresence* presence = CAPresenceManager::InstanceL();
       
  2723         MCAContactLists* contactLists = presence->ContactLists();
       
  2724 
       
  2725         if ( !contactLists )
       
  2726             {
       
  2727             return KErrGeneral;
       
  2728             }
       
  2729 
       
  2730         MCAContactListModel::SItem item = iContactListModel.Item( index );
       
  2731         MCAStoredContact& contact = *item.iContact;
       
  2732         MCAContactList& list = *item.iContactList;
       
  2733 
       
  2734         TRAP( err, contactLists->DeleteServerContactL( list.ListId(),
       
  2735                                                        contact.UserId() ) );
       
  2736         }
       
  2737 
       
  2738     return err;
       
  2739     }
       
  2740 
       
  2741 //-----------------------------------------------------------
       
  2742 //CCAMainViewArrayPC::FindContactL
       
  2743 //-----------------------------------------------------------
       
  2744 TInt CCAMainViewArrayPC::FindContactL( const TDesC& aContactListId,
       
  2745                                        const TDesC& aId )
       
  2746     {
       
  2747     MCAStoredContacts* contacts =
       
  2748         CCAStorageManagerFactory::ContactListInterfaceL();
       
  2749     if ( contacts )
       
  2750         {
       
  2751         MCAStoredContact* newContact = contacts->FindContact( aContactListId, aId );
       
  2752         if ( newContact )
       
  2753             {
       
  2754             // return the index of contact rather bool value..
       
  2755             return ( iContactListIndex + iContactListModel.IndexOfContact( newContact ) );
       
  2756             }
       
  2757 
       
  2758         }
       
  2759     return KErrNotFound;
       
  2760     }
       
  2761 
       
  2762 
       
  2763 //-----------------------------------------------------------
       
  2764 //CCAMainViewArrayPC::GetContactForContactEditor
       
  2765 //-----------------------------------------------------------
       
  2766 //
       
  2767 MCAStoredContact* CCAMainViewArrayPC::GetContactForContactEditor( TInt aIndex )
       
  2768     {
       
  2769     TInt index = GetItemEngineIndex( aIndex );
       
  2770 
       
  2771     TEnumsPC::TItem itemtype = GetType( aIndex );
       
  2772     if ( itemtype == TEnumsPC::EOwnStatusItem || itemtype == TEnumsPC::EContactItem )
       
  2773         {
       
  2774 
       
  2775         MCAStoredContact* contact = NULL;
       
  2776         MCAContactListModel::SItem item = iContactListModel.Item( index );
       
  2777         if ( ( item.iType == MCAContactListModel::EContactItem ) ||
       
  2778              ( item.iType == MCAContactListModel::EOwnStatus ) )
       
  2779             {
       
  2780             contact = item.iContact;
       
  2781             }
       
  2782         return contact;
       
  2783         }
       
  2784     return NULL;
       
  2785     }
       
  2786 
       
  2787 //-----------------------------------------------------------
       
  2788 //CCAMainViewArrayPC::StatusText
       
  2789 //-----------------------------------------------------------
       
  2790 //
       
  2791 const TDesC& CCAMainViewArrayPC::StatusText( TInt aIndex ) const
       
  2792     {
       
  2793     TInt index = GetItemEngineIndex( aIndex );
       
  2794     // get correct index of this..
       
  2795 
       
  2796     TEnumsPC::TItem itemtype = GetType( aIndex );
       
  2797 
       
  2798     MCAContactListModel::SItem item = iContactListModel.Item( index );
       
  2799     MCAStoredContact* contact = item.iContact;
       
  2800     if ( contact )
       
  2801         {
       
  2802         return contact->StatusText();
       
  2803         }
       
  2804     else
       
  2805         {
       
  2806         return KNullDesC();
       
  2807         }
       
  2808     }
       
  2809 
       
  2810 //-----------------------------------------------------------
       
  2811 //CCAMainViewArrayPC::MapContactListPositions
       
  2812 //-----------------------------------------------------------
       
  2813 //
       
  2814 void CCAMainViewArrayPC::MapContactListPositions( RArray<TInt>& aPos )
       
  2815     {
       
  2816     // add conversation also this list ..and return..
       
  2817     RArray<TInt> listPos;
       
  2818 
       
  2819     iContactListModel.MapContactListPositions( listPos );
       
  2820     TInt positionIndex = 0;
       
  2821     // if count is more than 0..fill the maparray...
       
  2822     if ( iMainViewListItemArray.Count()  + iContactListIndex > 0 )
       
  2823         {
       
  2824         // we've some openchats items.. so add them to the list..
       
  2825         if ( iContactListIndex > 0 && SingleListViewSelectMode() )
       
  2826             {
       
  2827             // open chats index(value), position in array
       
  2828             aPos.Insert( iOpenChatsIndex, positionIndex );
       
  2829             positionIndex++;	 // increase the index, as we added the open chats folder..
       
  2830             }
       
  2831         TInt count = listPos.Count();
       
  2832 
       
  2833         for ( TInt posIndex = 0; posIndex < count; posIndex++, positionIndex++ )
       
  2834             {
       
  2835             aPos.Append( listPos[posIndex] + iContactListIndex );
       
  2836             }
       
  2837         }
       
  2838     listPos.Close();
       
  2839     }
       
  2840 
       
  2841 //-----------------------------------------------------------
       
  2842 //CCAMainViewArrayPC::DisplayName
       
  2843 //-----------------------------------------------------------
       
  2844 //
       
  2845 TPtrC CCAMainViewArrayPC::DisplayName( TInt aIndex )
       
  2846     {
       
  2847     TInt index = GetItemEngineIndex( aIndex );
       
  2848 
       
  2849     TEnumsPC::TItem itemtype = GetType( aIndex );
       
  2850 
       
  2851 
       
  2852     switch ( itemtype )
       
  2853         {
       
  2854         case TEnumsPC::EContactListItem:
       
  2855             {
       
  2856             MCAContactListModel::SItem item = iContactListModel.Item( index );
       
  2857             MCAContactList* list = item.iContactList;
       
  2858             if ( list )
       
  2859                 {
       
  2860                 return list->DisplayName();
       
  2861                 }
       
  2862             }
       
  2863         case TEnumsPC::EInviteItem:
       
  2864         case TEnumsPC::EConversationItem:
       
  2865         case TEnumsPC::EGroupItem:
       
  2866         case TEnumsPC::EOpenChatsListItem:
       
  2867             {
       
  2868             break;
       
  2869             }
       
  2870         }
       
  2871     return KNullDesC();
       
  2872     }
       
  2873 
       
  2874 
       
  2875 //-----------------------------------------------------------
       
  2876 //CCAMainViewArrayPC::SetDisplayName
       
  2877 //-----------------------------------------------------------
       
  2878 //
       
  2879 TInt CCAMainViewArrayPC::SetDisplayNameL( TInt aIndex, const TPtrC aItemName )
       
  2880     {
       
  2881     //CURRENTLY TO RENAME A LIST ITEM
       
  2882     MCAPresence* presence = CAPresenceManager::InstanceL();
       
  2883     MCAContactLists* contactLists = presence->ContactLists();
       
  2884 
       
  2885     TInt index = GetItemEngineIndex( aIndex );
       
  2886 
       
  2887     TEnumsPC::TItem itemtype = GetType( aIndex );
       
  2888 
       
  2889     MCAContactListModel::SItem item = iContactListModel.Item( index );
       
  2890 
       
  2891     TInt err = KErrNone;
       
  2892     if ( item.iContactList )
       
  2893         {
       
  2894         MCAContactList& list = *item.iContactList;
       
  2895         err = contactLists->SetDisplayNameL( list.ListId(), aItemName ) ;
       
  2896         return err;
       
  2897         }
       
  2898     return KErrGeneral;
       
  2899     }
       
  2900 
       
  2901 //-----------------------------------------------------------
       
  2902 //CCAMainViewArrayPC::FetchContactsL
       
  2903 //-----------------------------------------------------------
       
  2904 //
       
  2905 void CCAMainViewArrayPC::FetchContactsL()
       
  2906     {
       
  2907     CAPresenceManager::InstanceL()->ContactLists()->FetchContactsL();
       
  2908     }
       
  2909 
       
  2910 // -----------------------------------------------------------------------------
       
  2911 // CCAMainViewArrayPC::StatusL
       
  2912 // (other items were commented in a header).
       
  2913 // -----------------------------------------------------------------------------
       
  2914 //
       
  2915 TEnumsPC::TOnlineStatus CCAMainViewArrayPC::StatusL()
       
  2916     {
       
  2917     MCAPresence::TPresenceStatus  presenceStatus =
       
  2918         CAPresenceManager::InstanceL()->StatusL();
       
  2919     return GetOwnStatusConverter( presenceStatus );
       
  2920     }
       
  2921 // -----------------------------------------------------------------------------
       
  2922 // CCAMainViewArrayPC::GetOwnStatusConverter
       
  2923 // -----------------------------------------------------------------------------
       
  2924 
       
  2925 TEnumsPC::TOnlineStatus CCAMainViewArrayPC::GetOwnStatusConverter(
       
  2926     MCAPresence::TPresenceStatus  aPresenceStatus )
       
  2927     {
       
  2928     switch ( aPresenceStatus )
       
  2929         {
       
  2930         case MCAPresence::EOffline:
       
  2931             {
       
  2932             return TEnumsPC::EOffline;
       
  2933             }
       
  2934         case MCAPresence::EAway:
       
  2935             {
       
  2936             return TEnumsPC::EAway;
       
  2937             }
       
  2938         case MCAPresence::EBusy:
       
  2939             {
       
  2940             return TEnumsPC::EBusy;
       
  2941             }
       
  2942         case MCAPresence::EOnline: // Flowthrough
       
  2943         default:
       
  2944             {
       
  2945             return TEnumsPC::EOnline;
       
  2946             }
       
  2947         }
       
  2948 
       
  2949     }
       
  2950 // -----------------------------------------------------------------------------
       
  2951 // CCAMainViewArrayPC::ChangeStatusL
       
  2952 // (other items were commented in a header).
       
  2953 // -----------------------------------------------------------------------------
       
  2954 //
       
  2955 TInt CCAMainViewArrayPC::ChangeStatusL( TEnumsPC::TOnlineStatus aStatus,
       
  2956                                         const TDesC& aStatusMessage )
       
  2957     {
       
  2958     TInt error( KErrNone );
       
  2959 
       
  2960     MCAPresence* presence = CAPresenceManager::InstanceL();
       
  2961 
       
  2962     switch ( aStatus )
       
  2963         {
       
  2964         case TEnumsPC::EOnline:
       
  2965             {
       
  2966             error = presence->ChangeStatusL( MCAPresence::EOnline ,
       
  2967                                              aStatusMessage );
       
  2968             break;
       
  2969             }
       
  2970         case TEnumsPC::EAway:
       
  2971             {
       
  2972             error = presence->ChangeStatusL( MCAPresence::EAway ,
       
  2973                                              aStatusMessage );
       
  2974             break;
       
  2975             }
       
  2976         case TEnumsPC::EOffline:
       
  2977             {
       
  2978             error = presence->ChangeStatusL( MCAPresence::EOffline ,
       
  2979                                              aStatusMessage );
       
  2980             break;
       
  2981             }
       
  2982         case TEnumsPC::EBusy:
       
  2983             {
       
  2984             error = presence->ChangeStatusL( MCAPresence::EBusy ,
       
  2985                                              aStatusMessage );
       
  2986             break;
       
  2987             }
       
  2988         default:
       
  2989             {
       
  2990             error = presence->ChangeStatusL( MCAPresence::EUnknown ,
       
  2991                                              aStatusMessage );
       
  2992             break;
       
  2993             }
       
  2994 
       
  2995         }
       
  2996 
       
  2997     return error;
       
  2998 
       
  2999     }
       
  3000 
       
  3001 
       
  3002 // -----------------------------------------------------------------------------
       
  3003 // CCAMainViewArrayPC::ChangeStatusMessageL
       
  3004 // (other items were commented in a header).
       
  3005 // -----------------------------------------------------------------------------
       
  3006 //
       
  3007 TInt CCAMainViewArrayPC::ChangeStatusMessageL( const TDesC& aStatusMessage )
       
  3008 
       
  3009     {
       
  3010     return CAPresenceManager::InstanceL()->ChangeStatusMessageL( aStatusMessage );
       
  3011     }
       
  3012 
       
  3013 
       
  3014 //-----------------------------------------------------------
       
  3015 // CCAMainViewArrayPC::SetContactSelectionL
       
  3016 // used by contactselectiondialog
       
  3017 //-----------------------------------------------------------
       
  3018 //
       
  3019 void CCAMainViewArrayPC::SetContactSelectionL(
       
  3020     TEnumsPC::TListSelectionType aSelectionMode,
       
  3021     TInt aSelectedListIndex )
       
  3022     {
       
  3023     iSelectionMode = aSelectionMode;
       
  3024 
       
  3025     if ( iSelectionMode == TEnumsPC::ESingleListMultiSelect )
       
  3026         {
       
  3027         MCAStoredContacts* storedContacts =
       
  3028             CCAStorageManagerFactory::ContactListInterfaceL();
       
  3029         iSelectedListIndex = aSelectedListIndex <= 0 ? 0 : (
       
  3030                                  aSelectedListIndex - iContactListIndex ) ;
       
  3031         SetContactListIndex();
       
  3032         MCAContactListModel::SItem item = iContactListModel.Item(
       
  3033                                               iSelectedListIndex );
       
  3034 
       
  3035         if ( item.iType == MCAContactListModel::EContactList )
       
  3036             {
       
  3037             MCAContactList& list = *item.iContactList;
       
  3038             if ( list.Collapsed() )
       
  3039                 {
       
  3040                 list.SetCollapsed( EFalse );
       
  3041                 iSetListCollapsedFlag = ETrue;
       
  3042                 ResetArray( EFalse );
       
  3043                 }
       
  3044             TInt count = list.FilteredCount( GetFilterConverterUITOEngine( Filter() ) );
       
  3045 
       
  3046             for ( TInt index = iSelectedListIndex + 1 ; index <=
       
  3047                   iSelectedListIndex + count ; index++ )
       
  3048                 {
       
  3049                 MCAContactListModel::SItem itemContact = iContactListModel.Item( index );
       
  3050                 if ( itemContact.iType == MCAContactListModel::EContactItem )
       
  3051                     {
       
  3052                     MCAStoredContact& contact = *itemContact.iContact;
       
  3053                     contact.SetSelected( ETrue );
       
  3054                     }
       
  3055                 }
       
  3056             }
       
  3057 
       
  3058         }
       
  3059     else
       
  3060         {
       
  3061         SetContactListIndex();
       
  3062         iContactListModel.SetSelectionMode( ETrue );
       
  3063         iContactListModel.SetPrimaryContactLists( EFalse );
       
  3064         }
       
  3065 
       
  3066     }
       
  3067 //-----------------------------------------------------------
       
  3068 //CCAMainViewArrayPC::ResetContactSelectionL
       
  3069 //-----------------------------------------------------------
       
  3070 //
       
  3071 void CCAMainViewArrayPC::ResetContactSelectionL()
       
  3072     {
       
  3073 
       
  3074     if ( iSetListCollapsedFlag  &&
       
  3075          iSelectionMode == TEnumsPC::ESingleListMultiSelect )
       
  3076         {
       
  3077         SetContactListIndex();
       
  3078         MCAContactListModel::SItem item =
       
  3079             iContactListModel.Item( iSelectedListIndex );
       
  3080         if ( item.iType == MCAContactListModel::EContactList  )
       
  3081             {
       
  3082             MCAContactList& list = *item.iContactList;
       
  3083             list.SetCollapsed( ETrue );
       
  3084             iSetListCollapsedFlag = EFalse;
       
  3085             ResetArray( EFalse );
       
  3086             }
       
  3087 
       
  3088         }
       
  3089     iSelectedListIndex = 0;
       
  3090     iSelectionMode = TEnumsPC::ESingleListViewSelect;
       
  3091     SetContactListIndex();
       
  3092     iContactListModel.ShowAll( EFalse );
       
  3093     ClearSelectedL();
       
  3094     ResetDefaultFilter();
       
  3095     iContactListModel.SetSelectionMode( EFalse );
       
  3096     ForceExpanded( EFalse );
       
  3097     iContactListModel.SetPrimaryContactLists( ETrue );
       
  3098 
       
  3099     }
       
  3100 
       
  3101 
       
  3102 // -----------------------------------------------------------------------------
       
  3103 // CCAMainViewArrayPC::ShowAll
       
  3104 // Sets the visibility of "all" item
       
  3105 // (other items were commented in a header).
       
  3106 // -----------------------------------------------------------------------------
       
  3107 //
       
  3108 void CCAMainViewArrayPC::ShowAll( TBool aShow )
       
  3109     {
       
  3110     iShowAll = aShow;
       
  3111     }
       
  3112 
       
  3113 
       
  3114 // -----------------------------------------------------------------------------
       
  3115 // CCAMainViewArrayPC::FilteredCount
       
  3116 // (other items were commented in a header).
       
  3117 // -----------------------------------------------------------------------------
       
  3118 //
       
  3119 TInt CCAMainViewArrayPC::GetFilteredCount( TEnumsPC::TFilterType aFilter,
       
  3120                                            TInt aIndex )
       
  3121     {
       
  3122     TInt count( 0 );
       
  3123     TInt index = GetItemEngineIndex( aIndex ) ;
       
  3124 
       
  3125     TEnumsPC::TItem itemType = GetType( aIndex );
       
  3126 
       
  3127     switch ( itemType )
       
  3128         {
       
  3129         case TEnumsPC::EContactItem:
       
  3130         case TEnumsPC::EContactListItem:
       
  3131             {
       
  3132             //  add the resloving of array index and pass it to engine
       
  3133             // now get the type of index for this list...
       
  3134             MCAContactListModel::SItem item = iContactListModel.Item( index );
       
  3135             MCAContactList& list = *item.iContactList;
       
  3136 
       
  3137             // convert the filter from UI to engine and pass that filter
       
  3138             count =  list.FilteredCount( GetFilterConverterUITOEngine( aFilter ) );
       
  3139 
       
  3140             break;
       
  3141             }
       
  3142         case TEnumsPC::EInviteItem:
       
  3143         case TEnumsPC::EConversationItem:
       
  3144         case TEnumsPC::EGroupItem:
       
  3145         case TEnumsPC::EOpenChatsListItem:
       
  3146             {
       
  3147             count =	iOpenChatsArray.Count() - 1;
       
  3148             /*count = iChatInterface.ChatCount() + iInvitationsArray.Count()
       
  3149                     + iGroupArray->MdcaCount();  */
       
  3150 
       
  3151             // return the index of open chats from here..
       
  3152             break;
       
  3153             }
       
  3154         default:
       
  3155             {
       
  3156             break;
       
  3157             }
       
  3158 
       
  3159         }
       
  3160     return count;
       
  3161     }
       
  3162 
       
  3163 
       
  3164 
       
  3165 // -----------------------------------------------------------------------------
       
  3166 // CCAMainViewArrayPC::SetSelected
       
  3167 // (other items were commented in a header).
       
  3168 // -----------------------------------------------------------------------------
       
  3169 //
       
  3170 void CCAMainViewArrayPC::SetSelected( TBool aSelected, TInt aIndex )
       
  3171     {
       
  3172     TInt index = GetItemEngineIndex( aIndex ) ;
       
  3173 
       
  3174     MCAContactListModel::SItem item = iContactListModel.Item( index );
       
  3175     MCAStoredContact& contact = *item.iContact;
       
  3176     contact.SetSelected( aSelected );
       
  3177     }
       
  3178 
       
  3179 // -----------------------------------------------------------------------------
       
  3180 // CCAMainViewArrayPC::GetSelectedL
       
  3181 // (other items were commented in a header).
       
  3182 // -----------------------------------------------------------------------------
       
  3183 //
       
  3184 void CCAMainViewArrayPC::GetSelectedL( CDesCArray& aSelectedContact,
       
  3185                                        CDesCArray* aSelectedIdentifications,
       
  3186                                        TEnumsPC::TFilterType aFilter )
       
  3187     {
       
  3188     RPointerArray<MCAStoredContact> selectedContacts;
       
  3189     CleanupClosePushL( selectedContacts );
       
  3190 
       
  3191     TStorageManagerGlobals::TFilterType filter = TStorageManagerGlobals::EFilterNotDefined;
       
  3192     filter = GetFilterConverterUITOEngine( aFilter );
       
  3193 
       
  3194     MCAStoredContacts* storedContact = CCAStorageManagerFactory::ContactListInterfaceL();
       
  3195     storedContact->GetSelectedL( selectedContacts, filter );
       
  3196 
       
  3197     TInt count = selectedContacts.Count();
       
  3198     for ( TInt i( 0 ); i < count; ++i )
       
  3199         {
       
  3200         MCAStoredContact* contact = selectedContacts[i];
       
  3201         aSelectedContact.AppendL( contact->UserId() );
       
  3202         if ( aSelectedIdentifications )
       
  3203             {
       
  3204             aSelectedIdentifications->AppendL( contact->Identification() );
       
  3205             }
       
  3206         }
       
  3207     //Codescanner warning ignored
       
  3208     CleanupStack::PopAndDestroy();
       
  3209     }
       
  3210 
       
  3211 // -----------------------------------------------------------------------------
       
  3212 // CCAMainViewArrayPC::ClearSelectedL
       
  3213 // (other items were commented in a header).
       
  3214 // -----------------------------------------------------------------------------
       
  3215 //
       
  3216 void CCAMainViewArrayPC::ClearSelectedL( )
       
  3217     {
       
  3218     MCAStoredContacts* storedContacts = CCAStorageManagerFactory::ContactListInterfaceL();
       
  3219     storedContacts->ClearSelected();
       
  3220     }
       
  3221 
       
  3222 // ---------------------------------------------------------
       
  3223 // CCAMainViewArrayPC::InsertInviteItemL()
       
  3224 // (other items were commented in a header).
       
  3225 // ---------------------------------------------------------
       
  3226 //
       
  3227 void CCAMainViewArrayPC::InsertInviteItemL( const MCAInvitation* aInvitation )
       
  3228     {
       
  3229     MCAStoredContacts* contacts = CCAStorageManagerFactory::ContactListInterfaceL();
       
  3230 
       
  3231     const TDesC& userId = aInvitation->UserID();
       
  3232 
       
  3233     CCAInviteItemPC* inviteItem = CCAInviteItemPC::NewL( userId,
       
  3234                                                          aInvitation->InviteID() );
       
  3235     HBufC* inviteName = StringLoader::LoadLC(
       
  3236                             R_QTN_CHAT_CONTACTLIST_INVITATION,
       
  3237                             contacts->Identification( userId ) );
       
  3238     inviteItem->SetItemNameText( *inviteName );
       
  3239 
       
  3240     inviteItem->SetInvitation( aInvitation );
       
  3241 
       
  3242     inviteItem->SetItemEngineIndex( 0 );
       
  3243     iOpenChatsArray.Insert( inviteItem, iOpenChatsIndex );
       
  3244 
       
  3245     SetContactListIndex();
       
  3246     iOpenChatsInActiveIndex++;
       
  3247     CleanupStack::PopAndDestroy( inviteName );
       
  3248     }
       
  3249 
       
  3250 // ---------------------------------------------------------
       
  3251 // CCAMainViewArrayPC::InsertGroupItemL)
       
  3252 // (other items were commented in a header).
       
  3253 // ---------------------------------------------------------
       
  3254 //
       
  3255 void CCAMainViewArrayPC::InsertGroupItemL( MCAStoredGroup* aGroup )
       
  3256     {
       
  3257     CCAGroupItemPC* groupItem = CCAGroupItemPC::NewL( aGroup->GroupId() );
       
  3258     groupItem->SetItemNameText( aGroup->GroupName() );
       
  3259     groupItem->SetItemEngineIndex( 0 );
       
  3260     if ( !aGroup->IsJoined() )
       
  3261         {
       
  3262         iOpenChatsArray.Insert( groupItem, iOpenChatsArray.Count() );
       
  3263         //Set the fresh iContactListIndex before calling InsertIntoInactiveOpenChats()
       
  3264         //to sort the non joined groups. The methods inside  the sort is dependant
       
  3265         //on the fresh iContactListIndex
       
  3266         SetContactListIndex();
       
  3267         InsertIntoInactiveOpenChats( ETrue );
       
  3268         }
       
  3269     else
       
  3270         {
       
  3271         iOpenChatsArray.Insert( groupItem, iOpenChatsIndex );
       
  3272         iOpenChatsInActiveIndex++;
       
  3273         SetContactListIndex();
       
  3274         }
       
  3275     }
       
  3276 // ---------------------------------------------------------
       
  3277 // CCAMainViewArrayPC::RefreshGroupItem()
       
  3278 // (other items were commented in a header).
       
  3279 // ---------------------------------------------------------
       
  3280 //
       
  3281 void CCAMainViewArrayPC::RefreshGroupItem( MCAStoredGroup* aGroup, TInt aFoundIndex )
       
  3282     {
       
  3283     /* Codescanner warning is ignored, since Bound check is done
       
  3284      * inside the FindIndexOfOpenChats() method, where the foundIndex is passed*/
       
  3285 
       
  3286     CCAGroupItemPC* foundGroupItem = dynamic_cast<CCAGroupItemPC*>(
       
  3287                                          iOpenChatsArray[aFoundIndex] );
       
  3288     foundGroupItem->SetItemNameText( aGroup->GroupName() );
       
  3289     }
       
  3290 // ---------------------------------------------------------
       
  3291 // CCAMainViewArrayPC::GetInviteItemID()
       
  3292 // (other items were commented in a header).
       
  3293 // ---------------------------------------------------------
       
  3294 //
       
  3295 const TDesC& CCAMainViewArrayPC::GetInviteItemID( TInt aIndex )
       
  3296     {
       
  3297     if ( GetType( aIndex ) != TEnumsPC::EInviteItem )
       
  3298         {
       
  3299         return KNullDesC;
       
  3300         }
       
  3301     CCAInviteItemPC* inviteItem =
       
  3302         dynamic_cast< CCAInviteItemPC* > (
       
  3303             iOpenChatsArray[ aIndex - iOpenChatsIndex ] );
       
  3304     return inviteItem->GetInviteID();
       
  3305     }
       
  3306 // ---------------------------------------------------------
       
  3307 // CCAMainViewArrayPC::HandleInvitationEventL()
       
  3308 // (other items were commented in a header).
       
  3309 // ---------------------------------------------------------
       
  3310 //
       
  3311 void CCAMainViewArrayPC::HandleInvitationEventL(
       
  3312     TInviteEventType aEvent, const MCAInvitation* aInvitation )
       
  3313     {
       
  3314     switch ( aEvent )
       
  3315         {
       
  3316         case ENewInvite:
       
  3317             {
       
  3318             TInt currentItemIndex = iSingleViewCB->GetCurrentItemIndex();
       
  3319             iItemDetails = GetArrayItemIdDetails( currentItemIndex );
       
  3320             InsertInviteItemL( aInvitation );
       
  3321             if ( iSelectionMode != TEnumsPC::ESingleListViewSelect )
       
  3322                 {
       
  3323                 return;
       
  3324                 }
       
  3325             RefreshOpenChatsListItemL();
       
  3326             for ( TInt index = 0; index < iMainViewObservers.Count(); index++ )
       
  3327                 {
       
  3328                 iMainViewObservers[index]->HandleChange( TEnumsPC::EOpenChatsListItem,
       
  3329                                                          iOpenChatsIndex , \
       
  3330                                                          TEnumsPC::EAddition );
       
  3331                 }
       
  3332 
       
  3333             break;
       
  3334             }
       
  3335         case EInviteCancel: // Flowthrough
       
  3336         case EInviteExpired:
       
  3337             {
       
  3338             TInt currentItemIndex = iSingleViewCB->GetCurrentItemIndex();
       
  3339             TInt indexOfList = IndexOfList( currentItemIndex );
       
  3340             TInt countOfContactsInList = CountOfContactsInList( indexOfList );
       
  3341 
       
  3342             //Find the invitation and delete.
       
  3343             TInt deletedIndex = FindInvitationAndDelete( aInvitation->InviteID()  );
       
  3344             if ( ( indexOfList + countOfContactsInList ) == currentItemIndex  )
       
  3345                 {
       
  3346                 --currentItemIndex;
       
  3347                 }
       
  3348             iItemDetails = GetArrayItemIdDetails( currentItemIndex );
       
  3349             //Check if singlelistview is active. If it is then give a callback.
       
  3350             //else no need.
       
  3351             if ( iSelectionMode != TEnumsPC::ESingleListViewSelect )
       
  3352                 {
       
  3353                 return;
       
  3354                 }
       
  3355             RefreshOpenChatsListItemL();
       
  3356             for ( TInt index = 0; index < iMainViewObservers.Count(); index++ )
       
  3357                 {
       
  3358                 iMainViewObservers[index]->HandleChange( TEnumsPC::EOpenChatsListItem,
       
  3359                                                          deletedIndex, TEnumsPC::EDelete );
       
  3360                 }
       
  3361 
       
  3362             break;
       
  3363             }
       
  3364         default:
       
  3365             {
       
  3366             break;
       
  3367             }
       
  3368         }
       
  3369     }
       
  3370 
       
  3371 // ---------------------------------------------------------
       
  3372 // CCAMainViewArrayPC::HandleInvitationResponse()
       
  3373 // (other items were commented in a header).
       
  3374 // ---------------------------------------------------------
       
  3375 //
       
  3376 void CCAMainViewArrayPC::HandleInvitationResponse(
       
  3377     TBool aAcceptance,
       
  3378     const TDesC& aUserId,
       
  3379     const TDesC& aGroupName,
       
  3380     const TDesC& aResponse )
       
  3381     {
       
  3382     for ( TInt index = 0; index < iMainViewObservers.Count(); index++ )
       
  3383         {
       
  3384         iMainViewObservers[index]->HandleInvitationResponse( aAcceptance,
       
  3385                                                              aUserId,
       
  3386                                                              aGroupName,
       
  3387                                                              aResponse );
       
  3388         }
       
  3389     }
       
  3390 
       
  3391 
       
  3392 //-----------------------------------------------------------------------------
       
  3393 // CCAMainViewArrayPC::ToUpdatePresence
       
  3394 // (other items were commented in a header).
       
  3395 // -----------------------------------------------------------------------------
       
  3396 //
       
  3397 TBool CCAMainViewArrayPC::ToUpdatePresence( TEnumsPC::TFilterType aFilter1,
       
  3398                                             TEnumsPC::TFilterType aFilter2 )
       
  3399     {
       
  3400     TBool updatepresence = EFalse;
       
  3401     TStorageManagerGlobals::TFilterType filtertype =
       
  3402         GetFilterConverterUITOEngine( aFilter2 );
       
  3403     if ( TEnumsPC::EFilterNonOfflineNonBlockedAndOperation == aFilter1 )
       
  3404         {
       
  3405         updatepresence =  TStorageManagerGlobals::EFilterNonOffline |
       
  3406                           TStorageManagerGlobals::EFilterNonBlocked +
       
  3407                           TStorageManagerGlobals::EFilterAndOperation
       
  3408                           & filtertype;
       
  3409         }
       
  3410     else if ( TEnumsPC::EFilterAllNonBlockedAndOperation == aFilter1 )
       
  3411         {
       
  3412         updatepresence = TStorageManagerGlobals::EFilterAll |
       
  3413                          TStorageManagerGlobals::EFilterNonBlocked +
       
  3414                          TStorageManagerGlobals::EFilterAndOperation
       
  3415                          & filtertype;
       
  3416         }
       
  3417     if ( updatepresence )
       
  3418         {
       
  3419         return  ETrue;
       
  3420         }
       
  3421     else
       
  3422         {
       
  3423         return  EFalse;
       
  3424         }
       
  3425     }
       
  3426 
       
  3427 //-----------------------------------------------------------------------------
       
  3428 // CCAMainViewArrayPC::GetItemEngineIndex
       
  3429 // (other items were commented in a header).
       
  3430 // -----------------------------------------------------------------------------
       
  3431 //
       
  3432 TInt CCAMainViewArrayPC::GetItemEngineIndex( TInt aIndex ) const
       
  3433     {
       
  3434     TInt itemIndex = KErrNone;
       
  3435     TInt index = aIndex - iContactListIndex <= 0 ? 0 : aIndex - iContactListIndex;
       
  3436     //codescanner warning ignored. as the check for aIndex is made in gettype.
       
  3437     switch ( GetType( aIndex ) )
       
  3438         {
       
  3439         case TEnumsPC::EContactItem:
       
  3440             {
       
  3441             /* Codescanner warning is ignored, since Bound check is done
       
  3442              * inside the GetType
       
  3443              * method*/
       
  3444 
       
  3445             CCAContactItemPC* contactItem =
       
  3446                 dynamic_cast< CCAContactItemPC* > ( iMainViewListItemArray[ index ] );
       
  3447             itemIndex = contactItem->GetItemEngineIndex();
       
  3448             break;
       
  3449             }
       
  3450         case TEnumsPC::EContactListItem:
       
  3451             {
       
  3452             /* Codescanner warning is ignored, since Bound check is done
       
  3453              * inside the GetType
       
  3454              * method*/
       
  3455             CCAContactListItemPC* contactListItem =
       
  3456                 dynamic_cast< CCAContactListItemPC* > ( iMainViewListItemArray[ index ] );
       
  3457             itemIndex = contactListItem->GetItemEngineIndex();
       
  3458             break;
       
  3459             }
       
  3460         case TEnumsPC::EOwnStatusItem:
       
  3461             {
       
  3462             /* Codescanner warning is ignored, since Bound check is done
       
  3463              * inside the GetType
       
  3464              * method*/
       
  3465             CCAOwnDataItemPC* owndataItem =
       
  3466                 dynamic_cast< CCAOwnDataItemPC* > ( iMainViewListItemArray[ index ] );
       
  3467             itemIndex = owndataItem->GetItemEngineIndex();
       
  3468             break;
       
  3469             }
       
  3470         case TEnumsPC::EConversationItem:
       
  3471         case TEnumsPC::EGroupItem:
       
  3472         case TEnumsPC::EInviteItem:
       
  3473         case TEnumsPC::EOpenChatsListItem:
       
  3474             {
       
  3475             itemIndex = aIndex - iOpenChatsIndex; //openchatsarray index
       
  3476             break;
       
  3477             }
       
  3478         default:
       
  3479             {
       
  3480             itemIndex = KErrNotFound;
       
  3481             break;
       
  3482             }
       
  3483         }
       
  3484     return itemIndex;
       
  3485     }
       
  3486 
       
  3487 
       
  3488 // -----------------------------------------------------------------------------
       
  3489 // CCAMainViewArrayPC::FindInvitationAndDelete
       
  3490 // (other items were commented in a header).
       
  3491 // -----------------------------------------------------------------------------
       
  3492 //
       
  3493 TInt CCAMainViewArrayPC::FindInvitationAndDelete( const TDesC& aInviteID )
       
  3494     {
       
  3495     TInt currentItemIndex = iSingleViewCB->GetCurrentItemIndex();
       
  3496 
       
  3497     TInt index = iOpenChatsIndex;
       
  3498     for ( ; index < iOpenChatsArray.Count() ; index++ )
       
  3499         {
       
  3500         MCAArrayItemPC *arrayItemPC = ( MCAArrayItemPC * )iOpenChatsArray[index];
       
  3501 
       
  3502         if ( arrayItemPC->Type() == TEnumsPC::EInviteItem )
       
  3503             {
       
  3504             CCAInviteItemPC* inviteItem =
       
  3505                 dynamic_cast< CCAInviteItemPC* > ( iOpenChatsArray[ index ] );
       
  3506 
       
  3507             if ( CAUtils::NeutralCompare( inviteItem->GetInviteID(), aInviteID ) == 0 )
       
  3508                 {
       
  3509                 iOpenChatsArray.Remove( index  );
       
  3510                 delete arrayItemPC;
       
  3511                 SetContactListIndex();
       
  3512                 iOpenChatsInActiveIndex--;
       
  3513                 break;
       
  3514                 }
       
  3515             }
       
  3516         }
       
  3517     if ( iOpenChatsArray.Count() + 1 == currentItemIndex  )
       
  3518         {
       
  3519         --currentItemIndex;
       
  3520         }
       
  3521     iItemDetails = GetArrayItemIdDetails( currentItemIndex );
       
  3522     return index;
       
  3523     }
       
  3524 
       
  3525 // -----------------------------------------------------------------------------
       
  3526 // CCAMainViewArrayPC:::SetContactListIndex
       
  3527 // Based on index from single list view
       
  3528 // -----------------------------------------------------------------------------
       
  3529 //
       
  3530 void CCAMainViewArrayPC::SetContactListIndex()
       
  3531     {
       
  3532     if ( !SingleListViewSelectMode() )
       
  3533         {
       
  3534         iContactListIndex = 0;
       
  3535         }
       
  3536     else if ( !( iOpenChatListItemExpanded || iExpandAll ) )
       
  3537         {
       
  3538         iContactListIndex = 1;
       
  3539         }
       
  3540     else
       
  3541         {
       
  3542         iContactListIndex = iOpenChatsArray.Count();
       
  3543         }
       
  3544     }
       
  3545 // -----------------------------------------------------------------------------
       
  3546 // CCAMainViewArrayPC::FindInvitationAndDelete
       
  3547 // Based on index from single list view
       
  3548 // -----------------------------------------------------------------------------
       
  3549 //
       
  3550 TInt CCAMainViewArrayPC::FindInvitationAndDelete( TInt aIndex )
       
  3551     {
       
  3552     TInt currentItemIndex = iSingleViewCB->GetCurrentItemIndex();
       
  3553     TInt index = iOpenChatsIndex;
       
  3554 
       
  3555     if ( GetType( aIndex ) == TEnumsPC::EInviteItem )
       
  3556         {
       
  3557         CCAInviteItemPC* inviteItem =
       
  3558             dynamic_cast< CCAInviteItemPC* > ( iOpenChatsArray[ aIndex - iOpenChatsIndex ] );
       
  3559 
       
  3560         iOpenChatsArray.Remove( aIndex - iOpenChatsIndex );
       
  3561         delete inviteItem;
       
  3562         iOpenChatsInActiveIndex--;
       
  3563         SetContactListIndex();
       
  3564         if ( iOpenChatsArray.Count() + 1 == currentItemIndex  )
       
  3565             {
       
  3566             --currentItemIndex;
       
  3567             }
       
  3568         iItemDetails = GetArrayItemIdDetails( currentItemIndex );
       
  3569         return index;
       
  3570         }
       
  3571     return KErrNotFound;
       
  3572     }
       
  3573 
       
  3574 
       
  3575 // -----------------------------------------------------------------------------
       
  3576 // CCAMainViewArrayPC: FindAnyContactL
       
  3577 // -----------------------------------------------------------------------------
       
  3578 //
       
  3579 TBool CCAMainViewArrayPC::FindAnyContactL( const TDesC& aContactId )
       
  3580     {
       
  3581     MCAStoredContacts* contacts =
       
  3582         CCAStorageManagerFactory::ContactListInterfaceL();
       
  3583     if ( contacts->FindAnyContact( aContactId ) )
       
  3584         {
       
  3585         return ETrue;
       
  3586         }
       
  3587     return EFalse;
       
  3588     }
       
  3589 
       
  3590 
       
  3591 
       
  3592 // ---------------------------------------------------------
       
  3593 // CCAMainViewArrayPC::ConvertToTCASettingStrings
       
  3594 // (other items were commented in a header).
       
  3595 // ---------------------------------------------------------
       
  3596 //
       
  3597 TEnumsPC::TCASettingValues CCAMainViewArrayPC::ConvertToEnumsPC(
       
  3598     TInt aStatus )
       
  3599     {
       
  3600     MCASettings::TCASettingFlags engineFlags = ( MCASettings::TCASettingFlags )aStatus;
       
  3601 
       
  3602     TEnumsPC::TCASettingValues setValue = TEnumsPC::EUnknownValue;
       
  3603 
       
  3604     // Map status to setting item
       
  3605     switch ( engineFlags )
       
  3606         {
       
  3607         case MCASettings::EDefaultScreenNameInUse :
       
  3608             {
       
  3609             setValue =  TEnumsPC::EDefaultScreenNameInUse;
       
  3610             break;
       
  3611             }
       
  3612         case MCASettings::EAutomaticPresenceUpdate :
       
  3613             {
       
  3614             setValue =  TEnumsPC::EAutomaticPresenceUpdate;
       
  3615             break;
       
  3616             }
       
  3617 
       
  3618         case MCASettings::EShowOffline :
       
  3619             {
       
  3620             setValue =  TEnumsPC::EShowOffline;
       
  3621             break;
       
  3622             }
       
  3623         case MCASettings::EShowTimeStamps :
       
  3624             {
       
  3625             setValue =  TEnumsPC::EShowTimeStamps;
       
  3626             break;
       
  3627             }
       
  3628         default:
       
  3629             {
       
  3630             break;
       
  3631             }
       
  3632         }
       
  3633     return setValue ;
       
  3634     }
       
  3635 
       
  3636 // -----------------------------------------------------------------------------
       
  3637 // CCAMainViewArrayPC: InsertConversationItemL
       
  3638 // -----------------------------------------------------------------------------
       
  3639 //
       
  3640 void CCAMainViewArrayPC::InsertConversationItemL( const TDesC& aUserId,
       
  3641                                                   const TDesC& aIdentification )
       
  3642     {
       
  3643 
       
  3644     MCAPresence* presence = CAPresenceManager::InstanceL();
       
  3645     MCAContactLists* contactLists = presence->ContactLists();
       
  3646 
       
  3647     if ( contactLists && ( !contactLists->IsContactFetchingCompleted() ) )
       
  3648         {
       
  3649         contactLists->AddMainViewProcessObserver( this );
       
  3650         iRefreshConvArray.Append( aUserId.Alloc() );
       
  3651         }
       
  3652 
       
  3653     TInt index = FindIndexOfOpenChatsItem( TEnumsPC::EConversationItem, aUserId );
       
  3654     if ( index != KErrNotFound )
       
  3655         {
       
  3656         return;
       
  3657         }
       
  3658 
       
  3659     CCAConversationItemPC* conversationItem = CCAConversationItemPC::NewL( aUserId );
       
  3660     // so append both and append the string to array...
       
  3661     if ( aIdentification.Compare( KNullDesC ) )
       
  3662         {
       
  3663         //if not KNullDesC
       
  3664         conversationItem->SetItemNameText( aIdentification );
       
  3665         }
       
  3666     else
       
  3667         {
       
  3668         conversationItem->SetItemNameText( iContactInterface->Identification( aUserId ) );
       
  3669         }
       
  3670     conversationItem->SetItemEngineIndex( 0 );
       
  3671     iOpenChatsArray.Insert( conversationItem, iOpenChatsIndex );
       
  3672     SetContactListIndex();
       
  3673     iOpenChatsInActiveIndex++;
       
  3674     RefreshOpenChatsListItemL();
       
  3675     }
       
  3676 // -----------------------------------------------------------------------------
       
  3677 // CCAMainViewArrayPC: RemoveConversationItem
       
  3678 // -----------------------------------------------------------------------------
       
  3679 //
       
  3680 void CCAMainViewArrayPC::RemoveConversationItem( const TDesC& aUserId )
       
  3681     {
       
  3682     TInt index = FindIndexOfOpenChatsItem( TEnumsPC::EConversationItem, aUserId );
       
  3683     if ( index == KErrNotFound )
       
  3684         {
       
  3685         return;
       
  3686         }
       
  3687     //Codescanner wanring ignored sicne boundcheck is done in gettype() method
       
  3688     // used in findindexofopenchats() method
       
  3689     CCAConversationItemPC* convItem
       
  3690     = dynamic_cast<CCAConversationItemPC*> ( iOpenChatsArray[index] );
       
  3691     iOpenChatsArray.Remove( index );
       
  3692     SetContactListIndex();
       
  3693     delete convItem;
       
  3694     iOpenChatsInActiveIndex--;
       
  3695 
       
  3696     /*since a delete and subsequent focus on the correct open chats item
       
  3697     has not yet been done on the openchats array in HandleChatEvent(),
       
  3698     we have to set iItemdetails correctly after closing a conversation. This
       
  3699     will ensure that after the RemoveConversationItem() call in the
       
  3700     conversationview, iItemDetails is pointing to the correct detail.*/
       
  3701 
       
  3702     //Subtract one, since the item is already removed from the open chats array
       
  3703     //And the index of list considers the fresh openchatsarray
       
  3704     TInt currentItemIndex = iSingleViewCB->GetCurrentItemIndex();
       
  3705     TInt indexOfList = IndexOfList( currentItemIndex - 1 );
       
  3706     TInt countOfContactsInList = CountOfContactsInList( indexOfList );
       
  3707     if ( indexOfList + countOfContactsInList + 1 == currentItemIndex  )
       
  3708         {
       
  3709         --currentItemIndex;
       
  3710         }
       
  3711     iItemDetails = GetArrayItemIdDetails( currentItemIndex );
       
  3712 
       
  3713     return;
       
  3714     }
       
  3715 // -----------------------------------------------------------------------------
       
  3716 // CCAMainViewArrayPC: RemoveGroupItem
       
  3717 // -----------------------------------------------------------------------------
       
  3718 //
       
  3719 TInt CCAMainViewArrayPC::RemoveGroupItem( const TDesC& aGroupId )
       
  3720     {
       
  3721     TInt openchatsindex( FindIndexOfOpenChatsItem( TEnumsPC::EGroupItem, aGroupId ) );
       
  3722     if ( openchatsindex == KErrNotFound )
       
  3723         {
       
  3724         return KErrNotFound;
       
  3725         }
       
  3726 
       
  3727     if ( openchatsindex <= iOpenChatsInActiveIndex )
       
  3728         {
       
  3729         iOpenChatsInActiveIndex--;
       
  3730         }
       
  3731     CCAGroupItemPC* groupItem = dynamic_cast <CCAGroupItemPC*>( iOpenChatsArray[openchatsindex] );
       
  3732     iOpenChatsArray.Remove( openchatsindex );
       
  3733     SetContactListIndex();
       
  3734     delete groupItem;
       
  3735 
       
  3736     return openchatsindex;
       
  3737     }
       
  3738 // -----------------------------------------------------------------------------
       
  3739 // CCAMainViewArrayPC: ResetOpenChatsArrayL
       
  3740 // -----------------------------------------------------------------------------
       
  3741 //
       
  3742 void CCAMainViewArrayPC::ResetOpenChatsArrayL( TEnumsPC::TItem aItem )
       
  3743     {
       
  3744     switch ( aItem )
       
  3745         {
       
  3746         case TEnumsPC::EConversationItem:
       
  3747             {
       
  3748             //Refresh the iopenchats array
       
  3749             for ( TInt index = 0; index < iChatInterface.ChatCount(); index++ )
       
  3750                 {
       
  3751                 MCAMessagesReadInterface& readInterface
       
  3752                 = iChatInterface.ChatAt( index );
       
  3753                 TInt foundIndex = FindIndexOfOpenChatsItem( TEnumsPC::EConversationItem,
       
  3754                                                             readInterface.TargetId().Target() );
       
  3755                 const TDesC& wvId ( readInterface.TargetId().Target() );
       
  3756 
       
  3757                 if ( foundIndex == KErrNotFound )
       
  3758                     {
       
  3759                     InsertConversationItemL( wvId, iContactInterface->Identification( wvId ) );
       
  3760                     }
       
  3761                 }
       
  3762             break;
       
  3763             }
       
  3764         case TEnumsPC::EGroupItem:
       
  3765             {
       
  3766             //Refresh the iopenchats array
       
  3767             for ( TInt index = 0; index < iGroupArray->MdcaCount(); index++ )
       
  3768                 {
       
  3769                 MCAStoredGroup* group = iGroupArray->GroupAt( index );
       
  3770 
       
  3771                 TInt foundIndex = FindIndexOfOpenChatsItem( TEnumsPC::EGroupItem, group->GroupId() );
       
  3772 
       
  3773                 if ( foundIndex != KErrNotFound )
       
  3774                     {
       
  3775                     MoveGroupItem( group, foundIndex );
       
  3776                     }
       
  3777                 else
       
  3778                     {
       
  3779                     InsertGroupItemL( group );
       
  3780                     }
       
  3781                 }
       
  3782             break;
       
  3783             }
       
  3784         default:
       
  3785             {
       
  3786             break;
       
  3787             }
       
  3788         }
       
  3789     }
       
  3790 // -----------------------------------------------------------------------------
       
  3791 // CCAMainViewArrayPC: HandleChatEvent
       
  3792 // -----------------------------------------------------------------------------
       
  3793 //
       
  3794 void CCAMainViewArrayPC::HandleChatEvent( TChatEventType aEvent,
       
  3795                                           MCAMessage* aMessage )
       
  3796     {
       
  3797     TEnumsPC::TChange changetype = TEnumsPC::EUnknownEvent;
       
  3798     TInt currentItemIndex = iSingleViewCB->GetCurrentItemIndex();
       
  3799     switch ( aEvent )
       
  3800         {
       
  3801         case MCAChatObserver::EChatListChanged:
       
  3802         case MCAChatObserver::ESendListChanged:
       
  3803 
       
  3804             {
       
  3805             if ( !IsCollapsed( iOpenChatsIndex ) )
       
  3806                 {
       
  3807                 if ( iPToPChatCount < iChatInterface.ChatCount() )
       
  3808                     {
       
  3809                     iItemDetails = GetArrayItemIdDetails( currentItemIndex );
       
  3810                     changetype = TEnumsPC::EAddition;
       
  3811                     iPToPChatCount = iChatInterface.ChatCount() ;
       
  3812                     }
       
  3813                 else if ( iPToPChatCount > iChatInterface.ChatCount() )
       
  3814                     {
       
  3815                     //Subtract one, since the item is already removed from the open chats array
       
  3816                     //And the index of list considers the fresh openchatsarray
       
  3817                     TInt indexOfList = IndexOfList( currentItemIndex - 1 );
       
  3818                     TInt countOfContactsInList = CountOfContactsInList(
       
  3819                                                      indexOfList );
       
  3820                     iPToPChatCount = iChatInterface.ChatCount() ;
       
  3821                     if ( indexOfList + countOfContactsInList + 1 == currentItemIndex  )
       
  3822                         {
       
  3823                         --currentItemIndex;
       
  3824                         }
       
  3825                     iItemDetails = GetArrayItemIdDetails( currentItemIndex );
       
  3826                     changetype = TEnumsPC::EDelete;
       
  3827                     }
       
  3828                 else
       
  3829                     {
       
  3830                     iItemDetails = GetArrayItemIdDetails( currentItemIndex );
       
  3831                     changetype = TEnumsPC::EChanged;
       
  3832                     iPToPChatCount = iChatInterface.ChatCount() ;
       
  3833                     }
       
  3834                 }
       
  3835             else
       
  3836                 {
       
  3837                 iItemDetails = GetArrayItemIdDetails( currentItemIndex );
       
  3838                 changetype = TEnumsPC::EChanged;
       
  3839                 iPToPChatCount = iChatInterface.ChatCount();
       
  3840                 }
       
  3841 
       
  3842             if ( iSelectionMode != TEnumsPC::ESingleListViewSelect )
       
  3843                 {
       
  3844                 return;
       
  3845                 }
       
  3846             TRAP_IGNORE( RefreshOpenChatsListItemL() );
       
  3847             for ( TInt index = 0; index < iMainViewObservers.Count() ; index++ )
       
  3848                 {
       
  3849                 iMainViewObservers[index]->HandleChange(
       
  3850                     TEnumsPC::EOpenChatsListItem,
       
  3851                     iOpenChatsIndex, changetype );
       
  3852                 }
       
  3853             break;
       
  3854             }
       
  3855         case MCAChatObserver::EUnreadCountChanged:
       
  3856             {
       
  3857             iItemDetails = GetArrayItemIdDetails( currentItemIndex );
       
  3858             changetype = TEnumsPC::EUnReadCountChanged;
       
  3859             iPToPChatCount = iChatInterface.ChatCount();
       
  3860 
       
  3861             if ( aMessage && aMessage->MessageType() == MCAMessage::EMessagePTOP
       
  3862                  && aMessage->Recipient().Compare( KNullDesC ) )
       
  3863                 {
       
  3864                 TInt foundIndex = FindIndexOfOpenChatsItem(
       
  3865                                       TEnumsPC::EConversationItem,
       
  3866                                       aMessage->Recipient() );
       
  3867 
       
  3868                 const TDesC& wvId ( aMessage->Recipient() );
       
  3869 
       
  3870                 if ( foundIndex == KErrNotFound )
       
  3871                     {
       
  3872                     TRAP_IGNORE( InsertConversationItemL( wvId,
       
  3873                                                           iContactInterface->Identification( wvId ) ) ) ;
       
  3874                     changetype = TEnumsPC::EChanged;
       
  3875                     }
       
  3876 
       
  3877                 }
       
  3878 
       
  3879             if ( iSelectionMode != TEnumsPC::ESingleListViewSelect )
       
  3880                 {
       
  3881                 return;
       
  3882                 }
       
  3883             TRAP_IGNORE( RefreshOpenChatsListItemL() );
       
  3884             for ( TInt index = 0; index < iMainViewObservers.Count() ; index++ )
       
  3885                 {
       
  3886                 iMainViewObservers[index]->HandleChange(
       
  3887                     TEnumsPC::EOpenChatsListItem,
       
  3888                     iOpenChatsIndex, changetype );
       
  3889                 }
       
  3890             break;
       
  3891             }
       
  3892         case MCAChatObserver::EGroupListChanged:
       
  3893             {
       
  3894             iItemDetails = GetArrayItemIdDetails( currentItemIndex );
       
  3895             changetype = TEnumsPC::EChanged;
       
  3896             iPToPChatCount = iChatInterface.ChatCount();
       
  3897             iGroupArray->Sort();
       
  3898             TRAP_IGNORE( ResetOpenChatsArrayL( TEnumsPC::EGroupItem ) );
       
  3899             if ( iSelectionMode != TEnumsPC::ESingleListViewSelect )
       
  3900                 {
       
  3901                 return;
       
  3902                 }
       
  3903             TRAP_IGNORE( RefreshOpenChatsListItemL() );
       
  3904 
       
  3905             for ( TInt index = 0; index < iMainViewObservers.Count() ; index++ )
       
  3906                 {
       
  3907                 iMainViewObservers[index]->HandleChange(
       
  3908                     TEnumsPC::EOpenChatsListItem,
       
  3909                     iOpenChatsIndex, TEnumsPC::EChanged );
       
  3910                 }
       
  3911             break;
       
  3912             }
       
  3913         case MCAChatObserver::EMemoryLow:
       
  3914         case MCAChatObserver::EEventNotSpecified:
       
  3915         default:
       
  3916             {
       
  3917             //nothing to do
       
  3918             break;
       
  3919             }
       
  3920         }
       
  3921     }
       
  3922 
       
  3923 // -----------------------------------------------------------------------------
       
  3924 // CCAMainViewArrayPC:: GetOnlineContactsL
       
  3925 // -----------------------------------------------------------------------------
       
  3926 //
       
  3927 void CCAMainViewArrayPC::GetOnlineContactsL( CDesCArray& aOnlineList,
       
  3928                                              TBool aFetchFromNetwork )
       
  3929     {
       
  3930     CAPresenceManager::InstanceL()->GetOnlineFriendsL( aOnlineList, aFetchFromNetwork );
       
  3931     }
       
  3932 
       
  3933 // This callback is required when ever the server is added or deleted
       
  3934 // we get a callback and update the singlelist
       
  3935 
       
  3936 // ---------------------------------------------------------
       
  3937 // CCAMainViewArrayPC::HandleActiveDbEvent()
       
  3938 // (other items were commented in a header).
       
  3939 // ---------------------------------------------------------
       
  3940 
       
  3941 void CCAMainViewArrayPC::HandleSAPEvent( TSAPEvent aEvent )
       
  3942     {
       
  3943     if ( MIMPSSAPObserver::ESAPSettingChanged == aEvent )
       
  3944         {
       
  3945         if ( iLastloggedinUserId )
       
  3946             {
       
  3947             delete iLastloggedinUserId;
       
  3948             iLastloggedinUserId = NULL;
       
  3949             }
       
  3950 
       
  3951 
       
  3952         // If the iOpenChatsArray is empty, reset the array to fill it.
       
  3953         if ( iOpenChatsArray.Count() < iOpenChatsIndex )
       
  3954             {
       
  3955             ResetArray( ETrue );
       
  3956             }
       
  3957         else ResetArray( EFalse );
       
  3958 
       
  3959         TInt index = 0;
       
  3960         // this is always 0 for own data
       
  3961         if ( iMainViewObservers.Count() )
       
  3962             {
       
  3963             iMainViewObservers[index]->HandleChange(
       
  3964                 TEnumsPC::EOwnStatusItem,
       
  3965                 index, TEnumsPC::EChanged );
       
  3966 
       
  3967             }
       
  3968         }
       
  3969     }
       
  3970 
       
  3971 
       
  3972 // ---------------------------------------------------------
       
  3973 // CCAMainViewArrayPC::HandleDelete
       
  3974 // Group delete
       
  3975 // ---------------------------------------------------------
       
  3976 //
       
  3977 void CCAMainViewArrayPC::HandleDelete( const TDesC&  aId )
       
  3978     {
       
  3979     TInt currentItemIndex = iSingleViewCB->GetCurrentItemIndex();
       
  3980 
       
  3981     TInt indexOfList = IndexOfList( currentItemIndex );
       
  3982     TInt countOfContactsInList = CountOfContactsInList( indexOfList );
       
  3983 
       
  3984     //find index of the list and count before deleting the item
       
  3985     TInt groupIndex( iGroupArray->Find( aId ) );
       
  3986     if ( groupIndex != KErrNotFound )
       
  3987         {
       
  3988         iGroupArray->Remove( groupIndex );
       
  3989         groupIndex = RemoveGroupItem( aId );
       
  3990         }
       
  3991     //dont call populatelist here it wd give wrong count
       
  3992     // as in leave group case that count is still not updated
       
  3993     //resetarray is required as else iMainViewListItemArray would not be refreshed
       
  3994     TInt cnt = iGroupArray->MdcaCount();
       
  3995 
       
  3996     if ( cnt == iOnlySavedGroups && !iGroupCountDown )
       
  3997         {
       
  3998         iGroupCountDown = ETrue;
       
  3999         }
       
  4000     else if ( !iGroupCountDown )
       
  4001         {
       
  4002         return;
       
  4003         }
       
  4004 
       
  4005     if ( ( indexOfList + countOfContactsInList ) == currentItemIndex )
       
  4006         {
       
  4007         --currentItemIndex;
       
  4008         }
       
  4009     else if ( iChatGroups->IsGroupDeleted() &&
       
  4010               TEnumsPC::EContactListItem == GetType( currentItemIndex ) )
       
  4011         {
       
  4012 
       
  4013         // focus should be the chat folder then
       
  4014         --currentItemIndex;
       
  4015         }
       
  4016 
       
  4017     iItemDetails = GetArrayItemIdDetails( currentItemIndex );
       
  4018     TEnumsPC::TChange changetype = TEnumsPC::EUnknownEvent;
       
  4019     if ( !IsCollapsed( iOpenChatsIndex ) )
       
  4020         {
       
  4021         changetype = TEnumsPC::EDelete;
       
  4022         }
       
  4023     else
       
  4024         {
       
  4025         changetype = TEnumsPC::EChanged;
       
  4026         }
       
  4027     if ( iSelectionMode != TEnumsPC::ESingleListViewSelect )
       
  4028         {
       
  4029         return;
       
  4030         }
       
  4031 
       
  4032     TRAP_IGNORE( RefreshOpenChatsListItemL() );
       
  4033     //itemIndex is not being used
       
  4034     for ( TInt index = 0; index < iMainViewObservers.Count(); index++ )
       
  4035         {
       
  4036         iMainViewObservers[index]->HandleChange( TEnumsPC::EOpenChatsListItem,
       
  4037                                                  groupIndex/*itemIndex*/ ,
       
  4038                                                  changetype );
       
  4039         }
       
  4040     }
       
  4041 
       
  4042 // ---------------------------------------------------------
       
  4043 // CCAMainViewArrayPC::HandleAddition
       
  4044 // Group addition
       
  4045 // ---------------------------------------------------------
       
  4046 //
       
  4047 void CCAMainViewArrayPC::HandleAddition( const TDesC&  aId )
       
  4048     {
       
  4049     iItemDetails = GetArrayItemIdDetails( iSingleViewCB->GetCurrentItemIndex() );
       
  4050     MCAStoredGroup* group = iChatGroups->FindGroup( aId );
       
  4051     if ( group )
       
  4052         {
       
  4053         if ( iGroupArray->Find( aId ) != KErrNotFound )
       
  4054             {
       
  4055             // the group is already in the list, so let's not proceed
       
  4056             return;
       
  4057             }
       
  4058 
       
  4059         iGroupArray->Add( group );
       
  4060 
       
  4061         //After the item has been added to the iGroupArray only then call this.
       
  4062         if ( FindIndexOfOpenChatsItem( TEnumsPC::EGroupItem, aId ) == KErrNotFound )
       
  4063             {
       
  4064             TRAP_IGNORE( InsertGroupItemL( group ) );
       
  4065             }
       
  4066         }
       
  4067     TInt itemIndex = iOpenChatsArray.Count();
       
  4068 
       
  4069     TEnumsPC::TChange changetype = TEnumsPC::EUnknownEvent;
       
  4070     if ( !IsCollapsed( iOpenChatsIndex ) )
       
  4071         {
       
  4072         changetype = TEnumsPC::EAddition;
       
  4073         }
       
  4074     else
       
  4075         {
       
  4076         changetype = TEnumsPC::EChanged;
       
  4077         }
       
  4078     if ( iSelectionMode != TEnumsPC::ESingleListViewSelect )
       
  4079         {
       
  4080         return;
       
  4081         }
       
  4082     TRAP_IGNORE( RefreshOpenChatsListItemL() );
       
  4083     for ( TInt index = 0; index < iMainViewObservers.Count(); index++ )
       
  4084         {
       
  4085         iMainViewObservers[index]->HandleChange( TEnumsPC::EOpenChatsListItem,
       
  4086                                                  itemIndex,
       
  4087                                                  changetype );
       
  4088         }
       
  4089     }
       
  4090 
       
  4091 // ---------------------------------------------------------
       
  4092 // CCAMainViewArrayPC::HandleChange
       
  4093 // Group Change events
       
  4094 // ---------------------------------------------------------
       
  4095 //
       
  4096 void CCAMainViewArrayPC::HandleChange( const TDesC& aId )
       
  4097     {
       
  4098     iItemDetails = GetArrayItemIdDetails( iSingleViewCB->GetCurrentItemIndex() );
       
  4099     MCAStoredGroup* group = iChatGroups->FindGroup( aId );
       
  4100     if ( group )
       
  4101         {
       
  4102         TInt indexOfGroup = FindIndexOfOpenChatsItem( TEnumsPC::EGroupItem, aId );
       
  4103         /*if( indexOfGroup == KErrNotFound)
       
  4104         	{
       
  4105         	InsertGroupItemL(group);
       
  4106         	}*/
       
  4107 
       
  4108         if ( indexOfGroup != KErrNotFound )
       
  4109             {
       
  4110             RefreshGroupItem( group, indexOfGroup );
       
  4111             MoveGroupItem( group, indexOfGroup );
       
  4112             }
       
  4113         }
       
  4114 
       
  4115     iGroupArray->Sort();
       
  4116     //check if this reset is reqd
       
  4117     if ( iSelectionMode != TEnumsPC::ESingleListViewSelect )
       
  4118         {
       
  4119         return;
       
  4120         }
       
  4121     TRAP_IGNORE( RefreshOpenChatsListItemL() );
       
  4122     for ( TInt index = 0; index < iMainViewObservers.Count(); index++ )
       
  4123         {
       
  4124         iMainViewObservers[index]->HandleChange( TEnumsPC::EOpenChatsListItem,
       
  4125                                                  iOpenChatsIndex,
       
  4126                                                  TEnumsPC::EChanged );
       
  4127         }
       
  4128     }
       
  4129 
       
  4130 // ---------------------------------------------------------
       
  4131 // CCAMainViewArrayPC::HandleBackupRestoreEvent
       
  4132 // Group backup / restore events
       
  4133 // ---------------------------------------------------------
       
  4134 //
       
  4135 void CCAMainViewArrayPC::HandleBackupRestoreEvent(
       
  4136     const TStorageManagerGlobals::TCAObserverEventType /*aEventType*/ )
       
  4137     {
       
  4138 
       
  4139     TRAPD( restErr, PopulateGroupsListL() );
       
  4140 
       
  4141     if ( restErr )
       
  4142         {
       
  4143         CActiveScheduler::Current()->Error( restErr );
       
  4144         }
       
  4145     }
       
  4146 
       
  4147 // ---------------------------------------------------------
       
  4148 // CCAMainViewArrayPC::IsAnyContactFound
       
  4149 // (other items were commented in a header).
       
  4150 // ---------------------------------------------------------
       
  4151 
       
  4152 TBool CCAMainViewArrayPC::IsAnyContactFound( )
       
  4153     {
       
  4154 
       
  4155     TInt count( Count() );
       
  4156     TInt index = iContactListIndex;
       
  4157     TBool isContactFound( EFalse );
       
  4158     for (   ; index < count ; index++ )
       
  4159         {
       
  4160         TEnumsPC::TItem itemType = GetType( index );
       
  4161         if ( TEnumsPC::EContactListItem == itemType )
       
  4162             {
       
  4163             if ( CountOfContactsInList( index )	> 0 )
       
  4164                 {
       
  4165                 isContactFound = ETrue;
       
  4166                 break;
       
  4167                 }
       
  4168             }
       
  4169         }
       
  4170     return isContactFound;
       
  4171     }
       
  4172 
       
  4173 // ---------------------------------------------------------
       
  4174 // CCAMainViewArrayPC::PopulateGroupsListL
       
  4175 // (other items were commented in a header).
       
  4176 // ---------------------------------------------------------
       
  4177 
       
  4178 void CCAMainViewArrayPC::PopulateGroupsListL( )
       
  4179     {
       
  4180     RPointerArray<MCAStoredGroup> groupArray;
       
  4181     CleanupClosePushL( groupArray );
       
  4182 
       
  4183     iChatGroups->PopulateGroupsListL( groupArray );
       
  4184 
       
  4185     TInt groupCount = groupArray.Count();
       
  4186     iOnlySavedGroups = 0;
       
  4187     for ( TInt index = 0; index < groupCount; index++ )
       
  4188         {
       
  4189         if ( !groupArray[ index ]->IsOwnGroup() )
       
  4190             {
       
  4191             iOnlySavedGroups++;
       
  4192             }
       
  4193 
       
  4194         MCAStoredGroup* group = groupArray[ index ];
       
  4195 
       
  4196         //if it is already found then just update the read interface
       
  4197         //because addition is done based on insertinorder. As a result of
       
  4198         //which if the group is already in the list, the readinterface
       
  4199         //data will not be changed
       
  4200 
       
  4201         TInt found = iGroupArray->Find( group->GroupId() );
       
  4202         if ( found == KErrNotFound && !iChatGroups->IsGroupDeleted() )
       
  4203             {
       
  4204             iGroupArray->Add( group );
       
  4205             InsertGroupItemL( group );
       
  4206             }
       
  4207         }
       
  4208     RefreshOpenChatsListItemL();
       
  4209     iGroupArray->Sort();
       
  4210     CleanupStack::PopAndDestroy( );	//groupArray
       
  4211     }
       
  4212 // ---------------------------------------------------------
       
  4213 // CCAMainViewArrayPC::MoveGroupItem
       
  4214 // (other items were commented in a header).
       
  4215 // ---------------------------------------------------------
       
  4216 //
       
  4217 void CCAMainViewArrayPC::MoveGroupItem( MCAStoredGroup* aGroup, TInt aFoundIndex )
       
  4218     {
       
  4219 
       
  4220     //Codescanner wanring ignored since boundcheck is done in gettype() method
       
  4221     // in the returned foundIndex value from findindexofopenchats() method
       
  4222 
       
  4223     CCAGroupItemPC* groupItem = dynamic_cast< CCAGroupItemPC* > ( iOpenChatsArray[aFoundIndex] );
       
  4224 
       
  4225     if ( !aGroup->IsJoined() && aFoundIndex <= iOpenChatsInActiveIndex )
       
  4226         {
       
  4227         iOpenChatsArray.Remove( aFoundIndex );
       
  4228         //since the item is removed dont add plus 1 to the insertion position
       
  4229         iOpenChatsArray.Insert( groupItem, iOpenChatsInActiveIndex /*+ 1*/ );
       
  4230         iOpenChatsInActiveIndex--;
       
  4231         InsertIntoInactiveOpenChats( EFalse );
       
  4232         }
       
  4233 
       
  4234     else if ( aGroup->IsJoined() && aFoundIndex > iOpenChatsInActiveIndex )
       
  4235         {
       
  4236         iOpenChatsArray.Remove( aFoundIndex );
       
  4237         iOpenChatsArray.Insert( groupItem, iOpenChatsIndex );
       
  4238         iOpenChatsInActiveIndex++;
       
  4239         }
       
  4240     SetContactListIndex();
       
  4241     }
       
  4242 // ---------------------------------------------------------
       
  4243 // CCAMainViewArrayPC::InsertIntoInactiveOpenChats
       
  4244 // (other items were commented in a header).
       
  4245 // ---------------------------------------------------------
       
  4246 //
       
  4247 void CCAMainViewArrayPC::InsertIntoInactiveOpenChats( TBool aEnd )
       
  4248     {
       
  4249 
       
  4250     TInt openChatsCount = iOpenChatsArray.Count();
       
  4251     TInt indexInGroupArray1( 0 );
       
  4252     TInt indexInGroupArray2( 0 );
       
  4253     TInt position( 0 );
       
  4254     if ( aEnd )//latest item added at the the end of open chats array
       
  4255         {
       
  4256 
       
  4257         //To find the position of the most recently inserted non -joined
       
  4258         //group item in the iGroupArray
       
  4259         if ( ( openChatsCount > iOpenChatsIndex + 1 )
       
  4260              && ( GetOpenChatType( openChatsCount ) == TEnumsPC::EGroupItem ) )
       
  4261             {
       
  4262             CCAGroupItemPC *arrayItemPC =
       
  4263                 dynamic_cast<CCAGroupItemPC *>( iOpenChatsArray[openChatsCount - 1] );
       
  4264             indexInGroupArray1 = iGroupArray->Find( arrayItemPC->GroupId() );
       
  4265             }
       
  4266         else
       
  4267             {
       
  4268             return;
       
  4269             }
       
  4270         //Get the first item of the sorted inactive groups array
       
  4271         if ( GetOpenChatType( openChatsCount - 1 ) == TEnumsPC::EGroupItem )
       
  4272             {
       
  4273             CCAGroupItemPC *arrayItemPC =
       
  4274                 dynamic_cast<CCAGroupItemPC *>( iOpenChatsArray[openChatsCount - 2] );
       
  4275             indexInGroupArray2 = iGroupArray->Find( arrayItemPC->GroupId() );
       
  4276             }
       
  4277         else
       
  4278             {
       
  4279             return;
       
  4280             }
       
  4281         if ( indexInGroupArray1 > indexInGroupArray2 )
       
  4282             {
       
  4283             //already in sorted position. simply return
       
  4284             return;
       
  4285             }
       
  4286         position = 	openChatsCount -
       
  4287                     ( indexInGroupArray2 - indexInGroupArray1 ) - iOpenChatsIndex;
       
  4288         }
       
  4289     else//latest item added at the first index below iOpenChatsInActiveIndex
       
  4290         {
       
  4291         //To find the position of the most recently inserted non -joined
       
  4292         //group item in the iGroupArray
       
  4293         if ( iOpenChatsInActiveIndex + 1 == openChatsCount - 1 )
       
  4294             {
       
  4295             return;
       
  4296             }
       
  4297         if ( GetOpenChatType( iOpenChatsInActiveIndex + 2 ) == TEnumsPC::EGroupItem )
       
  4298             {
       
  4299             CCAGroupItemPC *arrayItemPC =
       
  4300                 dynamic_cast<CCAGroupItemPC *>( iOpenChatsArray[iOpenChatsInActiveIndex + 1] );
       
  4301             indexInGroupArray1 = iGroupArray->Find( arrayItemPC->GroupId() );
       
  4302             }
       
  4303         else
       
  4304             {
       
  4305             return;
       
  4306             }
       
  4307         //Get the first item of the sorted inactive groups array
       
  4308         if ( GetOpenChatType( iOpenChatsInActiveIndex + 3 ) == TEnumsPC::EGroupItem )
       
  4309             {
       
  4310             CCAGroupItemPC *arrayItemPC =
       
  4311                 dynamic_cast<CCAGroupItemPC *>( iOpenChatsArray[iOpenChatsInActiveIndex + 2] );
       
  4312             indexInGroupArray2 = iGroupArray->Find( arrayItemPC->GroupId() );
       
  4313             }
       
  4314         else
       
  4315             {
       
  4316             return;
       
  4317             }
       
  4318         if ( indexInGroupArray1 < indexInGroupArray2 )
       
  4319             {
       
  4320             //already in sorted position. simply return
       
  4321             return;
       
  4322             }
       
  4323         position = iOpenChatsInActiveIndex +
       
  4324                    ( indexInGroupArray1 - indexInGroupArray2 )  + iOpenChatsIndex ;
       
  4325         }
       
  4326 
       
  4327 
       
  4328     MCAStoredGroup* group = iGroupArray->GroupAt( indexInGroupArray1 );
       
  4329     TInt foundIndex = FindIndexOfOpenChatsItem( TEnumsPC::EGroupItem, group->GroupId() );
       
  4330     if ( foundIndex != KErrNotFound )
       
  4331         {
       
  4332         CCAGroupItemPC* groupItem = dynamic_cast< CCAGroupItemPC* > ( iOpenChatsArray[foundIndex] );
       
  4333         iOpenChatsArray.Remove( foundIndex );
       
  4334         //since the item is removed dont add plus 1 to the insertion position
       
  4335         iOpenChatsArray.Insert( groupItem, position );
       
  4336         SetContactListIndex();
       
  4337         }
       
  4338     }
       
  4339 // ---------------------------------------------------------
       
  4340 // CCAMainViewArrayPC::GetArrayItemIdDetails
       
  4341 // (other items were commented in a header).
       
  4342 // ---------------------------------------------------------
       
  4343 //
       
  4344 TCAItemDetails CCAMainViewArrayPC::GetArrayItemIdDetails( TInt aIndex )
       
  4345     {
       
  4346     if ( aIndex == KErrNotFound )
       
  4347         {
       
  4348         return iItemDetails;
       
  4349         }
       
  4350     TCAItemDetails itemDetails;
       
  4351     TInt index = GetItemEngineIndex( aIndex );
       
  4352 
       
  4353     switch ( GetType( aIndex ) )
       
  4354         {
       
  4355         case TEnumsPC::EContactItem:
       
  4356             {
       
  4357             /* Codescanner warning is ignored, since Bound check is done
       
  4358              * inside the GetType()
       
  4359              * method*/
       
  4360             MCAContactListModel::SItem item = iContactListModel.Item( index );
       
  4361             MCAStoredContact* contact = item.iContact;
       
  4362             if ( contact )
       
  4363                 {
       
  4364                 itemDetails.aItemID.Copy( contact->UserId().Left(
       
  4365                                               itemDetails.aItemID.MaxLength() ) );
       
  4366 
       
  4367                 itemDetails.aListID.Copy( item.iContactList->ListId().Left(
       
  4368                                               itemDetails.aListID.MaxLength() ) );
       
  4369                 itemDetails.aItem = TEnumsPC::EContactItem;
       
  4370                 }
       
  4371             break;
       
  4372             }
       
  4373         case TEnumsPC::EContactListItem:
       
  4374             {
       
  4375             /* Codescanner warning is ignored, since Bound check is done
       
  4376              * inside the GetType()
       
  4377              * method*/
       
  4378             MCAContactListModel::SItem item = iContactListModel.Item( index );
       
  4379             if ( item.iContactList )
       
  4380                 {
       
  4381                 itemDetails.aItemID.Copy( KNullDesC );
       
  4382                 itemDetails.aListID.Copy( item.iContactList->ListId().Left(
       
  4383                                               itemDetails.aListID.MaxLength() ) );
       
  4384                 itemDetails.aItem  = TEnumsPC::EContactListItem;
       
  4385                 }
       
  4386             break;
       
  4387             }
       
  4388         case TEnumsPC::EOpenChatsListItem:
       
  4389             {
       
  4390             /* Codescanner warning is ignored, since Bound check is done
       
  4391              * inside the GetType()
       
  4392              * method*/
       
  4393             MCAArrayItemPC *arrayItemPC = ( MCAArrayItemPC * )iOpenChatsArray[index];
       
  4394             itemDetails.aItemID.Copy( KNullDesC );
       
  4395             itemDetails.aListID.Copy( arrayItemPC->GetItemNameText().Left(
       
  4396                                           itemDetails.aListID.MaxLength() ) );
       
  4397             itemDetails.aItem = TEnumsPC::EOpenChatsListItem;
       
  4398             break;
       
  4399             }
       
  4400         case TEnumsPC::EConversationItem:
       
  4401             {
       
  4402             /* Codescanner warning is ignored, since Bound check is done
       
  4403              * inside the GetType()
       
  4404              * method*/
       
  4405             CCAConversationItemPC* conversationItem =
       
  4406                 dynamic_cast< CCAConversationItemPC* > ( iOpenChatsArray[index] );
       
  4407             itemDetails.aItemID.Copy( conversationItem->UserId().Left(
       
  4408                                           itemDetails.aItemID.MaxLength() ) );
       
  4409             itemDetails.aListID.Copy( KNullDesC );
       
  4410             itemDetails.aItem  = TEnumsPC::EConversationItem;
       
  4411             break;
       
  4412             }
       
  4413         case TEnumsPC::EInviteItem:
       
  4414             {
       
  4415             /* Codescanner warning is ignored, since Bound check is done
       
  4416              * inside the GetType()
       
  4417              * method*/
       
  4418             CCAInviteItemPC* inviteItem =
       
  4419                 dynamic_cast< CCAInviteItemPC* > ( iOpenChatsArray[ index ] );
       
  4420             itemDetails.aItemID.Copy( inviteItem->GetInviteID().Left(
       
  4421                                           itemDetails.aItemID.MaxLength() ) );
       
  4422             itemDetails.aListID.Copy( KNullDesC );
       
  4423             itemDetails.aItem  = TEnumsPC::EInviteItem;
       
  4424             break;
       
  4425             }
       
  4426         case TEnumsPC::EGroupItem:
       
  4427             {
       
  4428             /* Codescanner warning is ignored, since Bound check is done
       
  4429              * inside the GetType()
       
  4430              * method*/
       
  4431             CCAGroupItemPC* groupItem =
       
  4432                 dynamic_cast< CCAGroupItemPC* > ( iOpenChatsArray[ index ] );
       
  4433             itemDetails.aItemID.Copy( groupItem->GroupId().Left(
       
  4434                                           itemDetails.aItemID.MaxLength() ) );
       
  4435             itemDetails.aListID.Copy( KNullDesC );
       
  4436             itemDetails.aItem = TEnumsPC::EGroupItem;
       
  4437             break;
       
  4438             }
       
  4439         case TEnumsPC::EOwnStatusItem:
       
  4440             {
       
  4441             /* Codescanner warning is ignored, since Bound check is done
       
  4442              * inside the GetType()
       
  4443              * method*/
       
  4444             CCAOwnDataItemPC* ownDataItem =
       
  4445                 dynamic_cast< CCAOwnDataItemPC* > ( iMainViewListItemArray[ index ] );
       
  4446             itemDetails.aItemID.Copy( ownDataItem->GetItemNameText().Left(
       
  4447                                           itemDetails.aItemID.MaxLength() ) );
       
  4448             itemDetails.aListID.Copy( KNullDesC );
       
  4449             itemDetails.aItem = TEnumsPC::EOwnStatusItem;
       
  4450             break;
       
  4451             }
       
  4452         default:
       
  4453             {
       
  4454             //should never be here.
       
  4455             //set the iItemDetails to null/invalid
       
  4456             break;
       
  4457             }
       
  4458         }
       
  4459     return itemDetails;
       
  4460     }
       
  4461 
       
  4462 
       
  4463 // ---------------------------------------------------------
       
  4464 // CCAMainViewArrayPC::GetArrayItemIdIndexL
       
  4465 // (other items were commented in a header).
       
  4466 // ---------------------------------------------------------
       
  4467 //
       
  4468 TInt CCAMainViewArrayPC::GetArrayItemIdIndexL( const TCAItemDetails& aItemDetails )
       
  4469     {
       
  4470     TInt arrayIndex = KErrNotFound;
       
  4471     switch (  aItemDetails.aItem )
       
  4472         {
       
  4473         case TEnumsPC::EOwnStatusItem:
       
  4474             {
       
  4475             arrayIndex = KOwnDataIndex;
       
  4476             break;
       
  4477             }
       
  4478         case TEnumsPC::EContactItem:
       
  4479             {
       
  4480             arrayIndex = FindContactL( aItemDetails.aListID ,
       
  4481                                        aItemDetails.aItemID );
       
  4482             break;
       
  4483             }
       
  4484         case TEnumsPC::EContactListItem:
       
  4485             {
       
  4486             arrayIndex = FindContactListIndexL( aItemDetails.aListID );
       
  4487             break;
       
  4488             }
       
  4489         case TEnumsPC::EConversationItem:
       
  4490         case TEnumsPC::EInviteItem:
       
  4491         case TEnumsPC::EGroupItem:
       
  4492             {
       
  4493             arrayIndex = FindIndexOfOpenChatsItem( aItemDetails.aItem, aItemDetails.aItemID );
       
  4494             if ( arrayIndex != KErrNotFound )
       
  4495                 {
       
  4496                 arrayIndex = iOpenChatsIndex + arrayIndex;
       
  4497                 }
       
  4498             break;
       
  4499             }
       
  4500         case TEnumsPC::EOpenChatsListItem:
       
  4501             {
       
  4502             arrayIndex = iOpenChatsIndex;
       
  4503             }
       
  4504         default:
       
  4505             {
       
  4506             break;
       
  4507             }
       
  4508         }
       
  4509     if ( KErrNotFound ==	arrayIndex )
       
  4510         {
       
  4511         arrayIndex = iOpenChatsIndex +
       
  4512                      FindIndexOfOpenChatsItem( iItemDetails.aItem , iItemDetails.aItemID );
       
  4513         }
       
  4514     return arrayIndex;
       
  4515     }
       
  4516 
       
  4517 // ---------------------------------------------------------
       
  4518 // CCAMainViewArrayPC::RegisterCallBack
       
  4519 // (other items were commented in a header).
       
  4520 // ---------------------------------------------------------
       
  4521 //
       
  4522 void CCAMainViewArrayPC::RegisterCallBack( MCASingleListViewCB* aSingleViewCB )
       
  4523     {
       
  4524 
       
  4525     ASSERT( aSingleViewCB );
       
  4526 
       
  4527     iSingleViewCB = aSingleViewCB;
       
  4528     }
       
  4529 
       
  4530 // ---------------------------------------------------------
       
  4531 // CCAMainViewArrayPC::UnRegisterCallBack
       
  4532 // From MCAMainViewObserverManagerPC
       
  4533 // ---------------------------------------------------------
       
  4534 //
       
  4535 void CCAMainViewArrayPC::UnRegisterCallBack( )
       
  4536     {
       
  4537     ASSERT( iSingleViewCB );
       
  4538     iSingleViewCB = NULL;
       
  4539     }
       
  4540 
       
  4541 // ---------------------------------------------------------
       
  4542 // CCAMainViewArrayPC::FindIndexOfOpenChatsItem
       
  4543 // From MCAMainViewObserverManagerPC
       
  4544 // ---------------------------------------------------------
       
  4545 //
       
  4546 TInt CCAMainViewArrayPC::FindIndexOfOpenChatsItem( TEnumsPC::TItem aItemType,
       
  4547                                                    const TDesC& aId )
       
  4548     {
       
  4549     TInt itemIndex = KErrNotFound;
       
  4550     switch ( aItemType )
       
  4551         {
       
  4552         case TEnumsPC::EConversationItem:
       
  4553             {
       
  4554             for ( TInt index = 1; index < iOpenChatsArray.Count(); index++ )
       
  4555                 {
       
  4556                 if ( GetOpenChatType( index + iOpenChatsIndex ) == TEnumsPC::EConversationItem )
       
  4557                     {
       
  4558                     CCAConversationItemPC* convItem =
       
  4559                         dynamic_cast< CCAConversationItemPC* > ( iOpenChatsArray[ index ] );
       
  4560                     if ( CAUtils::NeutralCompare( convItem->UserId(), aId ) == 0 )
       
  4561                         {
       
  4562                         itemIndex = index;// + iOpenChatsIndex	;
       
  4563                         break;
       
  4564                         }
       
  4565                     }
       
  4566                 }
       
  4567             break;
       
  4568             }
       
  4569         case TEnumsPC::EInviteItem:
       
  4570             {
       
  4571             for ( TInt index = 1; index < iOpenChatsArray.Count(); index++ )
       
  4572                 {
       
  4573                 if ( GetOpenChatType( index + iOpenChatsIndex ) == TEnumsPC::EInviteItem )
       
  4574                     {
       
  4575                     CCAInviteItemPC* inviteItem =
       
  4576                         dynamic_cast< CCAInviteItemPC* > ( iOpenChatsArray[ index ] );
       
  4577                     if ( CAUtils::NeutralCompare( inviteItem->GetInviteID() , aId ) == 0  )
       
  4578                         {
       
  4579                         itemIndex = index;// + iOpenChatsIndex;
       
  4580                         break;
       
  4581                         }
       
  4582                     }
       
  4583                 }
       
  4584             break;
       
  4585             }
       
  4586         case TEnumsPC::EGroupItem:
       
  4587             {
       
  4588             for ( TInt index = 1; index < iOpenChatsArray.Count(); index++ )
       
  4589                 {
       
  4590                 if ( GetOpenChatType( index + iOpenChatsIndex ) == TEnumsPC::EGroupItem )
       
  4591                     {
       
  4592                     TCollationMethod collation =
       
  4593                         *Mem::CollationMethodByIndex( 0 );
       
  4594                     collation.iFlags |= TCollationMethod::EIgnoreNone;
       
  4595 
       
  4596                     CCAGroupItemPC* groupItem =
       
  4597                         dynamic_cast< CCAGroupItemPC* > ( iOpenChatsArray[ index ] );
       
  4598                     if ( groupItem->GroupId().CompareC( aId, KCollationLevel, &collation ) == 0 )
       
  4599                         {
       
  4600                         itemIndex = index;// + iOpenChatsIndex;
       
  4601                         break;
       
  4602                         }
       
  4603                     }
       
  4604                 }
       
  4605             break;
       
  4606             }
       
  4607         case TEnumsPC::EOpenChatsListItem:
       
  4608             {
       
  4609             itemIndex = iOpenChatsIndex - 1;
       
  4610             break;
       
  4611             }
       
  4612         default:
       
  4613             {
       
  4614             itemIndex = KErrNotFound;
       
  4615             break;
       
  4616             }
       
  4617         }
       
  4618 
       
  4619     return itemIndex;
       
  4620     }
       
  4621 // ---------------------------------------------------------
       
  4622 // CCAMainViewArrayPC::ResetGroupCountDownOnLogout
       
  4623 // ---------------------------------------------------------
       
  4624 //
       
  4625 void CCAMainViewArrayPC::ResetGroupCountDownOnLogout()
       
  4626     {
       
  4627     iGroupCountDown = EFalse;
       
  4628     }
       
  4629 
       
  4630 // ---------------------------------------------------------
       
  4631 // CCAMainViewArrayPC::SetcurrentItemIndex
       
  4632 // ---------------------------------------------------------
       
  4633 //
       
  4634 void CCAMainViewArrayPC::SetCurrentItemIndexL( TBool aFreshLogin )
       
  4635     {
       
  4636     if ( iSingleViewCB )
       
  4637         {
       
  4638         iSingleViewCB->SetCurrentItemIndexL( aFreshLogin );
       
  4639         }
       
  4640     }
       
  4641 
       
  4642 // ---------------------------------------------------------
       
  4643 // CCAMainViewArrayPC::SortContactListAfterRenameL
       
  4644 //
       
  4645 // ---------------------------------------------------------
       
  4646 //
       
  4647 TInt CCAMainViewArrayPC::SortContactListAfterRenameL( const TDesC& aListId )
       
  4648     {
       
  4649     MCAStoredContacts* contacts = CCAStorageManagerFactory::ContactListInterfaceL();
       
  4650 
       
  4651     TInt newIndex = KErrNotFound;
       
  4652     if ( contacts )
       
  4653         {
       
  4654         contacts->SortContactLists();
       
  4655         newIndex = FindContactListIndexL( aListId );
       
  4656         }
       
  4657     return newIndex;
       
  4658     }
       
  4659 
       
  4660 
       
  4661 const RPointerArray<MCAArrayItemPC>& CCAMainViewArrayPC::GetOpenChatsArray()const
       
  4662     {
       
  4663     return iOpenChatsArray;
       
  4664     }
       
  4665 
       
  4666 TInt CCAMainViewArrayPC::GetOpenChatsActiveIndex()const
       
  4667     {
       
  4668     return iOpenChatsInActiveIndex;
       
  4669 
       
  4670     }
       
  4671 
       
  4672 
       
  4673 TBool CCAMainViewArrayPC::IsOpenChatsMsgPending(
       
  4674     const TEnumsPC::TItem aType,
       
  4675     const TDesC& aId )
       
  4676     {
       
  4677     TInt high, mid( 0 ), low( 0 );
       
  4678 
       
  4679     TBool isMsgPending = EFalse;
       
  4680 
       
  4681     switch ( aType )
       
  4682         {
       
  4683         case TEnumsPC::EConversationItem:
       
  4684             {
       
  4685             high = iChatInterface.ChatCount() - 1;
       
  4686 
       
  4687             while ( low <= high )
       
  4688                 {
       
  4689                 mid = ( high + low ) / 2;
       
  4690 
       
  4691                 MCAMessagesReadInterface& readInterface = iChatInterface.ChatAt( mid );
       
  4692 
       
  4693                 if ( CAUtils::NeutralCompare( readInterface.TargetId().Target(), aId ) == 0 )
       
  4694                     {
       
  4695                     isMsgPending = readInterface.UnreadCount(
       
  4696                                        MCAMessagesReadInterface::EUnreadReceived ) != 0;
       
  4697                     break;
       
  4698                     }
       
  4699                 else if ( CAUtils::NeutralCompare( readInterface.TargetId().Target(), aId ) < 0 )
       
  4700                     {
       
  4701                     low = mid + 1;
       
  4702                     }
       
  4703                 else
       
  4704                     {
       
  4705                     high = mid - 1;
       
  4706                     }
       
  4707                 }
       
  4708 
       
  4709             break;
       
  4710             }
       
  4711         case TEnumsPC::EGroupItem:
       
  4712             {
       
  4713 
       
  4714             high = iChatInterface.GroupCount() - 1;
       
  4715 
       
  4716             // Create custom collation method to ignore punctuations
       
  4717             // index 0 gets the default method
       
  4718             TCollationMethod collation =
       
  4719                 *Mem::CollationMethodByIndex( 0 );
       
  4720             collation.iFlags |= TCollationMethod::EIgnoreNone;
       
  4721 
       
  4722             while ( low <= high )
       
  4723                 {
       
  4724                 mid = ( high + low ) / 2;
       
  4725 
       
  4726                 MCAMessagesReadInterface& readInterface = iChatInterface.GroupAt( mid );
       
  4727 
       
  4728                 if ( readInterface.TargetId().Target().CompareC(
       
  4729                          aId, KCollationLevel, &collation ) == 0 )
       
  4730                     {
       
  4731                     isMsgPending = readInterface.UnreadCount(
       
  4732                                        MCAMessagesReadInterface::EUnreadReceived ) != 0;
       
  4733                     break;
       
  4734                     }
       
  4735                 else if ( readInterface.TargetId().Target().CompareC(
       
  4736                               aId, KCollationLevel, &collation ) < 0 )
       
  4737                     {
       
  4738                     low = mid + 1;
       
  4739                     }
       
  4740                 else
       
  4741                     {
       
  4742                     high = mid - 1;
       
  4743                     }
       
  4744                 }
       
  4745             break;
       
  4746             }
       
  4747         case TEnumsPC::EInviteItem:
       
  4748             {
       
  4749             for ( TInt indx = 1; indx < iOpenChatsArray.Count(); indx++ )
       
  4750                 {
       
  4751                 if ( GetOpenChatType( indx + iOpenChatsIndex ) == TEnumsPC::EInviteItem )
       
  4752                     {
       
  4753                     CCAInviteItemPC* inviteItem =
       
  4754                         dynamic_cast< CCAInviteItemPC* > ( iOpenChatsArray[ indx ] );
       
  4755                     if ( 0 == aId.Compare( inviteItem->GetInviteID() ) )
       
  4756                         {
       
  4757                         MCAInvitation* inv = inviteItem->GetInvitation();
       
  4758                         isMsgPending = inv->IsRead();
       
  4759 
       
  4760                         // This is required 'coz teh IsRead() method returns
       
  4761                         // EFalse if the invitation is not read.
       
  4762                         isMsgPending = !isMsgPending;
       
  4763                         }
       
  4764 
       
  4765                     }
       
  4766                 }
       
  4767             break;
       
  4768             }
       
  4769         default:
       
  4770             {
       
  4771             break;
       
  4772             }
       
  4773         }
       
  4774 
       
  4775     return isMsgPending;
       
  4776 
       
  4777     }
       
  4778 
       
  4779 // ---------------------------------------------------------
       
  4780 // CCAMainViewArrayPC::NotifySyncCompleted
       
  4781 // ---------------------------------------------------------
       
  4782 //
       
  4783 void CCAMainViewArrayPC::NotifySyncCompleted()
       
  4784     {
       
  4785     if ( iSyncObserver )
       
  4786         {
       
  4787         iSyncObserver->NotifySyncCompleted();
       
  4788         }
       
  4789     }
       
  4790 
       
  4791 
       
  4792 // ---------------------------------------------------------
       
  4793 // CCAMainViewArrayPC::PendingMessageInfo
       
  4794 // ---------------------------------------------------------
       
  4795 //
       
  4796 const TDesC& CCAMainViewArrayPC::PendingMessageInfo()
       
  4797     {
       
  4798 
       
  4799     MCAMessageContainerInfo* info = iChatInterface.PendingMessageInfo();
       
  4800 
       
  4801     return info->Target();
       
  4802 
       
  4803     }
       
  4804 
       
  4805 // ---------------------------------------------------------
       
  4806 // CCAMainViewArrayPC::ChatGroupPendingMessageInfo
       
  4807 // ---------------------------------------------------------
       
  4808 //
       
  4809 const TDesC& CCAMainViewArrayPC::ChatGroupPendingMessageInfo( TDesC& aGroupName )
       
  4810     {
       
  4811 
       
  4812     MCAMessageContainerInfo* info = iChatInterface.ChatGroupPendingMessageInfo();
       
  4813 
       
  4814     MCAStoredGroup* group = iChatGroups->FindGroup( info->Target() );
       
  4815     if ( group )
       
  4816         {
       
  4817         aGroupName = group->GroupName();
       
  4818         }
       
  4819 
       
  4820     return info->Target();
       
  4821     }
       
  4822 // ---------------------------------------------------------
       
  4823 // CCAMainViewArrayPC::AddObserver
       
  4824 // From MCAMainViewArrayPC
       
  4825 // ---------------------------------------------------------
       
  4826 
       
  4827 
       
  4828 void CCAMainViewArrayPC::RegisterObserverL( MCAListInitObserver* aObserver )
       
  4829     {
       
  4830     MCAPresence* presence = CAPresenceManager::InstanceL();
       
  4831     MCAContactLists* contactLists = presence->ContactLists();
       
  4832     if ( contactLists )
       
  4833         {
       
  4834         contactLists->AddObserver( aObserver );
       
  4835         }
       
  4836     }
       
  4837 // ---------------------------------------------------------
       
  4838 // CCAMainViewArrayPC::RemoveObserver
       
  4839 // From MCAMainViewArrayPC
       
  4840 // ---------------------------------------------------------
       
  4841 
       
  4842 void CCAMainViewArrayPC::UnRegisterObserverL( )
       
  4843     {
       
  4844     MCAPresence* presence = CAPresenceManager::InstanceL();
       
  4845     MCAContactLists* contactLists = presence->ContactLists();
       
  4846     if ( contactLists )
       
  4847         {
       
  4848         contactLists->RemoveObserver();
       
  4849         }
       
  4850     }
       
  4851 // ---------------------------------------------------------
       
  4852 // CCAMainViewArrayPC::IsListInitialization
       
  4853 // From MCAMainViewArrayPC
       
  4854 // ---------------------------------------------------------
       
  4855 TBool CCAMainViewArrayPC::IsListInitializationCompletedL()
       
  4856     {
       
  4857     MCAPresence* presence = CAPresenceManager::InstanceL();
       
  4858     MCAContactLists* contactLists = presence->ContactLists();
       
  4859     if ( contactLists )
       
  4860         {
       
  4861         return contactLists->IsListInitializationCompleted();
       
  4862         }
       
  4863     else
       
  4864         {
       
  4865         return ETrue;
       
  4866         }
       
  4867     }
       
  4868 
       
  4869 // ---------------------------------------------------------
       
  4870 // CCAMainViewArrayPC::RefreshConversationItemText
       
  4871 // (other items were commented in a header).
       
  4872 // ---------------------------------------------------------
       
  4873 void CCAMainViewArrayPC::RefreshConversationItemText( const TDesC& aContactId )
       
  4874     {
       
  4875     TInt index = KErrNotFound;
       
  4876     index = FindIndexOfOpenChatsItem( TEnumsPC::EConversationItem, aContactId );
       
  4877     if ( KErrNotFound != index )
       
  4878         {
       
  4879         CCAConversationItemPC* convItemPC =
       
  4880             dynamic_cast<CCAConversationItemPC*>( iOpenChatsArray[index] );
       
  4881         convItemPC->SetItemNameText( iContactInterface->Identification( aContactId ) );
       
  4882         }
       
  4883     }
       
  4884 
       
  4885 // ---------------------------------------------------------
       
  4886 // CCAMainViewArrayPC::RefreshInvitationItemTextL
       
  4887 // (other items were commented in a header).
       
  4888 // ---------------------------------------------------------
       
  4889 void CCAMainViewArrayPC::RefreshInvitationItemTextL( const TDesC& aContactId )
       
  4890     {
       
  4891 
       
  4892     HBufC* inviteName = NULL;
       
  4893 
       
  4894     for ( TInt indx = 1; indx < iOpenChatsArray.Count(); indx++ )
       
  4895         {
       
  4896         if ( GetOpenChatType( indx + iOpenChatsIndex ) == TEnumsPC::EInviteItem )
       
  4897             {
       
  4898             CCAInviteItemPC* inviteItem =
       
  4899                 dynamic_cast< CCAInviteItemPC* > ( iOpenChatsArray[ indx ] );
       
  4900             if ( CAUtils::NeutralCompare( inviteItem->UserId() , aContactId ) == 0  )
       
  4901                 {
       
  4902                 //Only create once, as this is heavy call
       
  4903                 if ( !inviteName )
       
  4904                     {
       
  4905                     inviteName = StringLoader::LoadLC(
       
  4906                                      R_QTN_CHAT_CONTACTLIST_INVITATION,
       
  4907                                      iContactInterface->Identification( aContactId ) );
       
  4908 
       
  4909                     }
       
  4910                 //the below api makes a copy of the invite name
       
  4911                 inviteItem->SetItemNameText( *inviteName );
       
  4912 
       
  4913                 }
       
  4914             }
       
  4915         }
       
  4916 
       
  4917     //clear the created invite name
       
  4918     if ( inviteName )
       
  4919         {
       
  4920         CleanupStack::PopAndDestroy();
       
  4921         }
       
  4922     }
       
  4923 
       
  4924 // ---------------------------------------------------------
       
  4925 // CCAMainViewArrayPC::GetIndexOfTopPendingMessage
       
  4926 // ---------------------------------------------------------
       
  4927 //
       
  4928 TInt CCAMainViewArrayPC::GetIndexOfTopPendingMessage()
       
  4929     {
       
  4930     TInt count = iOpenChatsArray.Count();
       
  4931 
       
  4932     for ( TInt index = iOpenChatsIndex ; ( index < count ) ; ++index )
       
  4933         {
       
  4934         if ( IsMsgPending( index ) )
       
  4935             {
       
  4936             return index;
       
  4937             }
       
  4938         }
       
  4939 
       
  4940     // Fix warning: #940-D: missing return statement at end of non-void function
       
  4941     return iOpenChatsIndex;
       
  4942     }
       
  4943 
       
  4944 // ---------------------------------------------------------
       
  4945 // CCASingleListView::HandleInitChange
       
  4946 // (other items were commented in a header).
       
  4947 // ---------------------------------------------------------
       
  4948 //
       
  4949 void CCAMainViewArrayPC::HandleListInitChange( TBool aCompleted )
       
  4950     {
       
  4951     TInt refreshConvCount = iRefreshConvArray.Count();
       
  4952     for ( TInt index = 0; index < refreshConvCount; index++ )
       
  4953         {
       
  4954         HBufC* buf = iRefreshConvArray[index];
       
  4955         if ( buf )
       
  4956             {
       
  4957             RefreshConversationItemText( *buf );
       
  4958             }
       
  4959         }
       
  4960 
       
  4961     iRefreshConvArray.ResetAndDestroy();
       
  4962 
       
  4963 
       
  4964     MCAPresence* presence = CAPresenceManager::InstanceL();
       
  4965     MCAContactLists* contactLists = presence->ContactLists();
       
  4966 
       
  4967     if ( contactLists )
       
  4968         {
       
  4969         contactLists->RemoveMainViewProcessObserver();
       
  4970         }
       
  4971     }
       
  4972 
       
  4973 // End of File